00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CELL_HPP
00022 #define CELL_HPP
00023
00024 #include <Vertex.hpp>
00025
00026 #include <Stringify.hpp>
00027 #include <ErrorHandler.hpp>
00028
00038 class Cell {
00039 public:
00040 enum Type {
00041 hexahedron,
00042 cartesianHexahedron,
00043 hexahedronByEdge,
00044 tetrahedron,
00045 triangle3d,
00046 quadrangle3d
00047 };
00048
00049 protected:
00051 size_t __reference;
00052
00054 real_t __volume;
00055
00057 Vertex** __vertices;
00058
00060 mutable bool __isFictitious;
00061
00062 public:
00069 inline bool find(const Vertex * P) {
00070 for(size_t i=0 ; i<numberOfVertices() ; ++i) {
00071 if(__vertices[i]==P) {
00072 return true;
00073 }
00074 }
00075 return false;
00076 }
00077
00083 inline const real_t& volume() const
00084 {
00085 return __volume;
00086 }
00087
00094 inline void replace(Vertex* v0, Vertex* v1)
00095 {
00096 for (size_t i = 0; i<numberOfVertices(); ++i) {
00097 if (__vertices[i] == v0) {
00098 __vertices[i] = v1;
00099 return;
00100 }
00101 }
00102
00103 const std::string errorMsg
00104 = "vertex "+stringify(v0)+" was not found while replacing "+stringify(v1);
00105
00106 throw ErrorHandler(__FILE__,__LINE__,
00107 errorMsg,
00108 ErrorHandler::unexpected);
00109 }
00110
00116 const bool& isFictitious() const
00117 {
00118 return __isFictitious;
00119 }
00120
00127 void setFictitious(const bool& b) const
00128 {
00129 __isFictitious = b;
00130 }
00131
00137 virtual size_t numberOfVertices() const = 0;
00138
00144 virtual Cell::Type type() const = 0;
00145
00151 inline const size_t& reference() const
00152 {
00153 return __reference;
00154 }
00155
00161 inline size_t& reference()
00162 {
00163 return __reference;
00164 }
00165
00173 inline Vertex& operator () (const size_t& i)
00174 {
00175 ASSERT (i<numberOfVertices());
00176 return *__vertices[i];
00177 }
00178
00186 inline const Vertex& operator () (const size_t& i) const
00187 {
00188 ASSERT (i<numberOfVertices());
00189 return *(__vertices[i]);
00190 }
00191
00199 inline const Cell& operator=(const Cell& C)
00200 {
00201 __reference = C.__reference;
00202 __volume = C.__volume;
00203
00204 for (size_t i=0; i<C.numberOfVertices(); ++i)
00205 __vertices[i] = C.__vertices[i];
00206
00207 return *this;
00208 }
00209
00215 Cell(const size_t& numberOfVertices)
00216 : __reference(0),
00217 __volume(0),
00218 __isFictitious(false)
00219 {
00220 ASSERT(numberOfVertices > 0);
00221 __vertices = new Vertex*[numberOfVertices];
00222 }
00223
00231 Cell(const size_t& numberOfVertices, const size_t& reference)
00232 : __reference(reference),
00233 __volume(0),
00234 __isFictitious(false)
00235 {
00236 ASSERT(numberOfVertices > 0);
00237 __vertices = new Vertex*[numberOfVertices];
00238 }
00239
00245 Cell(const Cell& C)
00246 : __reference(C.__reference),
00247 __volume(C.__volume),
00248 __isFictitious(C.__isFictitious)
00249 {
00250 __vertices = new Vertex*[C.numberOfVertices()];
00251 for (size_t i=0; i<C.numberOfVertices(); ++i)
00252 __vertices[i] = C.__vertices[i];
00253 }
00254
00259 virtual ~Cell()
00260 {
00261 delete [] __vertices;
00262 }
00263 };
00264
00265 #endif // CELL_HPP
00266