00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef STRUCTURED_3D_MESH_HPP
00023 #define STRUCTURED_3D_MESH_HPP
00024
00025 #include <Mesh.hpp>
00026
00027 #include <TinyVector.hpp>
00028
00029 #include <Domain.hpp>
00030 #include <CartesianHexahedron.hpp>
00031
00032 #include <SurfaceMeshOfQuadrangles.hpp>
00033 #include <FacesSet.hpp>
00034
00035 #include <Connectivity.hpp>
00036
00037 #include <Index.hpp>
00038
00039 #include <Structured3DMeshShape.hpp>
00040
00041 #include <Structured3DVector.hpp>
00042
00043 class MeshOfHexahedra;
00044
00051 class Structured3DMesh
00052 : public Mesh
00053 {
00054 public:
00055 typedef CartesianHexahedron CellType;
00056 typedef Quadrangle FaceType;
00057
00062 typedef MeshOfHexahedra Transformed;
00063 typedef SurfaceMeshOfQuadrangles BorderMeshType;
00064
00065 enum {
00066 family = Mesh::volume
00067 };
00068 private:
00070 const Structured3DMeshShape __verticesShape;
00071
00073 const Array3DShape __cellShape;
00074
00076 Vector<CartesianHexahedron> __cells;
00077
00078 ReferenceCounting<BorderMeshType>
00079 __borderMesh;
00081 ReferenceCounting<FacesSet<FaceType> >
00082 __facesSet;
00084 Connectivity<Structured3DMesh> __connectivity;
00090 Structured3DMesh(const Structured3DMesh& M);
00091
00092 public:
00093 std::string typeName() const
00094 {
00095 return "cartesian mesh of hedrahedra";
00096 }
00097
00102 void buildEdges();
00103
00104 bool hasBorderMesh() const
00105 {
00106 return (__borderMesh != 0);
00107 }
00108
00109 ConstReferenceCounting<BorderMeshType> borderMesh() const
00110 {
00111 return __borderMesh;
00112 }
00113
00114 ConstReferenceCounting<Mesh> borderBaseMesh() const
00115 {
00116 return static_cast<const BorderMeshType*>(__borderMesh);
00117 }
00118
00123 void buildFaces();
00124
00130 inline bool hasFaces() const
00131 {
00132 return __facesSet != 0;
00133 }
00134
00142 const FaceType& face(const size_t& i) const
00143 {
00144 return (*__facesSet)[i];
00145 }
00146
00147 size_t faceNumber(const FaceType& f) const
00148 {
00149 return (*__facesSet).number(f);
00150 }
00151
00153 inline const size_t& numberOfFaces() const
00154 {
00155 return (*__facesSet).numberOfFaces();
00156 }
00157
00159 inline const size_t& numberOfCells() const
00160 {
00161 return __cells.size();
00162 }
00163
00164 size_t cellNumber(const CartesianHexahedron& h) const
00165 {
00166 return __cells.number(h);
00167 }
00168
00169 typedef Mesh::T_iterator<Structured3DMesh, CartesianHexahedron> iterator;
00170 typedef Mesh::T_iterator<const Structured3DMesh, const CartesianHexahedron> const_iterator;
00171
00172 inline Structured3DMesh::const_iterator find(const double& x,
00173 const double& y,
00174 const double& z) const;
00175
00176 inline Structured3DMesh::const_iterator find(const TinyVector<3>& X) const
00177 {
00178 return find(X[0],X[1],X[2]);
00179 }
00180
00182 const Structured3DMeshShape& shape()const
00183 {
00184 return __verticesShape;
00185 }
00186
00188 inline Vertex& vertex(const size_t& i,
00189 const size_t& j,
00190 const size_t& k);
00191
00193 inline const Vertex& vertex(const size_t& i,
00194 const size_t& j,
00195 const size_t& k) const;
00196
00198 inline CartesianHexahedron& cell(const size_t& i,
00199 const size_t& j,
00200 const size_t& k);
00201
00203 inline const CartesianHexahedron& cell(const size_t& i,
00204 const size_t& j,
00205 const size_t& k) const;
00206
00208 inline CartesianHexahedron& cell(const size_t& i)
00209 {
00210 return __cells[i];
00211 }
00212
00218 const Connectivity<Structured3DMesh>& connectivity() const
00219 {
00220 return __connectivity;
00221 }
00222
00228 Connectivity<Structured3DMesh>& connectivity()
00229 {
00230 return __connectivity;
00231 }
00232
00234 inline const CartesianHexahedron& cell(const size_t& i) const
00235 {
00236 return __cells[i];
00237 }
00238
00243 inline Vertex& vertex(const size_t& i)
00244 {
00245 return Mesh::vertex(i);
00246 }
00247
00252 inline const Vertex& vertex(const size_t& i) const
00253 {
00254 return Mesh::vertex(i);
00255 }
00256
00258 inline Vertex& vertex(const Index& I);
00259
00261 inline const Vertex& vertex(const Index& I) const;
00262
00264 inline CartesianHexahedron& cell(const Index& I);
00265
00267 inline const CartesianHexahedron& cell(const Index& I) const;
00268
00272 inline Index cellIndex(const Vertex& V) const;
00273
00277 inline Index cellIndex(const TinyVector<3>& V) const;
00278
00282 inline Index vertexIndex(const Vertex& V) const;
00283
00285 inline bool inside(const real_t& x, const real_t& y, const real_t& z) const
00286 {
00287 return ((x>=__verticesShape.a(0))&&
00288 (x<=__verticesShape.b(0))&&
00289 (y>=__verticesShape.a(1))&&
00290 (y<=__verticesShape.b(1))&&
00291 (z>=__verticesShape.a(2))&&
00292 (z<=__verticesShape.b(2)));
00293 }
00294
00296 inline bool inside(const TinyVector<3>& p) const
00297 {
00298 return this->inside(p[0], p[1], p[2]);
00299 }
00300
00306 Structured3DMesh(const Structured3DMeshShape& s3dM,
00307 ReferenceCounting<VerticesCorrespondance> correspondance);
00308
00309 };
00310
00312 inline Vertex& Structured3DMesh::vertex(const size_t& i,
00313 const size_t& j,
00314 const size_t& k)
00315 {
00316 return (*__verticesSet)[__verticesShape(i, j, k)];
00317 }
00318
00320 inline const Vertex& Structured3DMesh::vertex(const size_t& i,
00321 const size_t& j,
00322 const size_t& k) const
00323 {
00324 return (*__verticesSet)[__verticesShape(i, j, k)];
00325 }
00326
00328 inline CartesianHexahedron& Structured3DMesh::cell(const size_t& i,
00329 const size_t& j,
00330 const size_t& k)
00331 {
00332 return (__cells[__cellShape(i, j, k)]);
00333 }
00334
00336 inline const CartesianHexahedron& Structured3DMesh::cell(const size_t& i,
00337 const size_t& j,
00338 const size_t& k) const
00339 {
00340 return (__cells[__cellShape(i, j, k)]);
00341 }
00343 inline Vertex& Structured3DMesh::vertex(const Index& I)
00344 {
00345 return (*__verticesSet)[__verticesShape(I[0], I[1], I[2])];
00346 }
00347
00349 inline const Vertex& Structured3DMesh::vertex(const Index& I) const
00350 {
00351 return (*__verticesSet)[__verticesShape(I[0], I[1], I[2])];
00352 }
00353
00355 inline CartesianHexahedron& Structured3DMesh::cell(const Index& I)
00356 {
00357 return (__cells[__cellShape(I[0], I[1], I[2])]);
00358 }
00359
00361 inline const CartesianHexahedron& Structured3DMesh::cell(const Index& I) const
00362 {
00363 return (__cells[__cellShape(I[0], I[1], I[2])]);
00364 }
00365
00369 inline Index Structured3DMesh::cellIndex(const TinyVector<3>& V) const
00370 {
00371 const real_t& x = V[0];
00372 const real_t& y = V[1];
00373 const real_t& z = V[2];
00374
00375 const real_t& x0 = __verticesShape.a(0);
00376 const real_t& y0 = __verticesShape.a(1);
00377 const real_t& z0 = __verticesShape.a(2);
00378
00379 int i = int(std::floor((x - x0)/__verticesShape.hx()));
00380 int j = int(std::floor((y - y0)/__verticesShape.hy()));
00381 int k = int(std::floor((z - z0)/__verticesShape.hz()));
00382
00383 bool foundCell = inside(x,y,z);
00384
00385 if (!foundCell) {
00386 i = (i<0) ? 0 : i;
00387 j = (j<0) ? 0 : j;
00388 k = (k<0) ? 0 : k;
00389 }
00390
00391 int nx_1 = __cellShape.nx() - 1;
00392 int ny_1 = __cellShape.ny() - 1;
00393 int nz_1 = __cellShape.nz() - 1;
00394
00395 i = (i>nx_1) ? nx_1 : i;
00396 j = (j>ny_1) ? ny_1 : j;
00397 k = (k>nz_1) ? nz_1 : k;
00398
00399 Index I(i,j,k);
00400
00401 return I;
00402 }
00403
00407 inline Index Structured3DMesh::vertexIndex(const Vertex& V) const
00408 {
00409 const real_t& x = V.x();
00410 const real_t& y = V.y();
00411 const real_t& z = V.z();
00412
00413 const real_t& x0 = __verticesShape.a(0);
00414 const real_t& y0 = __verticesShape.a(1);
00415 const real_t& z0 = __verticesShape.a(2);
00416
00417 int i = int((x - x0)/__verticesShape.hx()+0.5);
00418 int j = int((y - y0)/__verticesShape.hy()+0.5);
00419 int k = int((z - z0)/__verticesShape.hz()+0.5);
00420
00421 Index I(i,j,k);
00422
00423 return I;
00424 }
00425
00426 inline Structured3DMesh::const_iterator
00427 Structured3DMesh::find(const double& x,
00428 const double& y,
00429 const double& z) const
00430 {
00431 bool foundCell = inside(x,y,z);
00432
00433 if (!foundCell)
00434 return Structured3DMesh::const_iterator(*this,
00435 Structured3DMesh::const_iterator::End);
00436
00437 const real_t& x0 = __verticesShape.a(0);
00438 const real_t& y0 = __verticesShape.a(1);
00439 const real_t& z0 = __verticesShape.a(2);
00440
00441 int i = int(std::floor((x - x0)/__verticesShape.hx()));
00442 int j = int(std::floor((y - y0)/__verticesShape.hy()));
00443 int k = int(std::floor((z - z0)/__verticesShape.hz()));
00444
00445 {
00446 int nx_1 = __cellShape.nx() - 1;
00447 int ny_1 = __cellShape.ny() - 1;
00448 int nz_1 = __cellShape.nz() - 1;
00449
00450
00451
00452
00453 i = (i>nx_1) ? nx_1 : i;
00454 j = (j>ny_1) ? ny_1 : j;
00455 k = (k>nz_1) ? nz_1 : k;
00456 }
00457
00458 return Structured3DMesh::const_iterator(*this,
00459 __cellShape(i, j, k));
00460 }
00461
00462 #endif // STRUCTURED_3D_MESH_HPP