00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <fstream>
00024 #include <cmath>
00025
00026 #include <ConnectivityBuilder.hpp>
00027
00028 #include <CartesianHexahedron.hpp>
00029 #include <Structured3DMesh.hpp>
00030 #include <Scene.hpp>
00031
00032 #include <FacesBuilder.hpp>
00033 #include <EdgesBuilder.hpp>
00034
00035 void Structured3DMesh::
00036 buildEdges()
00037 {
00038 EdgesBuilder<Structured3DMesh> edgesBuilder(*this);
00039 __edgesSet = edgesBuilder.edgesSet();
00040 }
00041
00042 void Structured3DMesh::
00043 buildFaces()
00044 {
00045 FacesBuilder<Structured3DMesh> facesBuilder(*this);
00046 __facesSet = facesBuilder.facesSet();
00047 }
00048
00055 Structured3DMesh::
00056 Structured3DMesh(const Structured3DMeshShape& SMShape,
00057 ReferenceCounting<VerticesCorrespondance> correspondances)
00058 : Mesh(Mesh::cartesianHexahedraMesh,
00059 Mesh::volume,
00060 new VerticesSet(SMShape.numberOfVertices()),
00061 correspondances),
00062 __verticesShape(SMShape),
00063 __cellShape(__verticesShape.shape()-1),
00064 __cells(SMShape.numberOfCells()),
00065 __facesSet(0),
00066 __connectivity(*this)
00067 {
00068
00069
00070
00071
00072
00073 const size_t nx = __verticesShape.nx();
00074 const size_t ny = __verticesShape.ny();
00075 const size_t nz = __verticesShape.nz();
00076
00077 const size_t nx_1 = __cellShape.nx();
00078 const size_t ny_1 = __cellShape.ny();
00079 const size_t nz_1 = __cellShape.nz();
00080
00081 for (size_t i=0; i<nx; i++) {
00082 real_t wi0 = static_cast<real_t>(i) / static_cast<real_t>(nx_1);
00083 real_t wi1 = static_cast<real_t>(nx_1-i) / static_cast<real_t>(nx_1);;
00084 for (size_t j=0; j<ny; j++) {
00085 real_t wj0 = static_cast<real_t>(j) / static_cast<real_t>(ny_1);
00086 real_t wj1 = static_cast<real_t>(ny_1-j) / static_cast<real_t>(ny_1);
00087 for (size_t k=0; k<nz; k++) {
00088 real_t wk0 = static_cast<real_t>(k) / static_cast<real_t>(nz_1);
00089 real_t wk1 = static_cast<real_t>(nz_1-k)/static_cast<real_t>(nz_1);
00090 Vertex& v = vertex(i,j,k);
00091 v.x() = wi0 * __verticesShape.b(0) + wi1 * __verticesShape.a(0);
00092 v.y() = wj0 * __verticesShape.b(1) + wj1 * __verticesShape.a(1);
00093 v.z() = wk0 * __verticesShape.b(2) + wk1 * __verticesShape.a(2);
00094 }
00095 }
00096 }
00097
00098
00099
00100
00101
00102 size_t n=0;
00103 for (size_t i=0; i<nx_1; i++) {
00104 for (size_t j=0; j<ny_1; j++) {
00105 for (size_t k=0; k<nz_1; k++) {
00106 __cells[n] = CartesianHexahedron(vertex( i, j, k),
00107 vertex(i+1, j, k),
00108 vertex(i+1,j+1, k),
00109 vertex( i,j+1, k),
00110 vertex( i, j,k+1),
00111 vertex(i+1, j,k+1),
00112 vertex(i+1,j+1,k+1),
00113 vertex( i,j+1,k+1));
00114 n++;
00115 }
00116 }
00117 }
00118
00123 Vector<Quadrangle>* pQuadrangles
00124 = new Vector<Quadrangle>(2*ny_1*nz_1+2*nx_1*nz_1+2*nx_1*ny_1);
00125 Vector<Quadrangle>& quadrangles = *pQuadrangles;
00126
00127 size_t currentCell = 0;
00129 for (size_t j=0; j<ny_1; j++) {
00130 for (size_t k=0; k<nz_1; k++) {
00131 const Vertex& V0 = vertex(0, j, k);
00132 const Vertex& V1 = vertex(0, j,k+1);
00133 const Vertex& V2 = vertex(0,j+1,k+1);
00134 const Vertex& V3 = vertex(0,j+1, k);
00135 Quadrangle& Q = quadrangles[currentCell];
00136
00137 Q = Quadrangle(V0, V1, V2, V3, 0);
00138 Q.setMother(&(cell(0,j,k)),4);
00139
00140 currentCell++;
00141 }
00142 }
00143
00145 for (size_t j=0; j<ny_1; j++) {
00146 for (size_t k=0; k<nz_1; k++) {
00147 const Vertex& V0 = vertex(nx_1, j, k);
00148 const Vertex& V1 = vertex(nx_1,j+1, k);
00149 const Vertex& V2 = vertex(nx_1,j+1,k+1);
00150 const Vertex& V3 = vertex(nx_1, j,k+1);
00151 Quadrangle& Q = quadrangles[currentCell];
00152
00153 Q = Quadrangle(V0, V1, V2, V3, 1);
00154 Q.setMother(&(cell(nx_1-1,j,k)),2);
00155
00156 currentCell++;
00157 }
00158 }
00159
00161 for (size_t i=0; i<nx_1; i++) {
00162 for (size_t k=0; k<nz_1; k++) {
00163 const Vertex& V0 = vertex( i,0, k);
00164 const Vertex& V1 = vertex(i+1,0, k);
00165 const Vertex& V2 = vertex(i+1,0,k+1);
00166 const Vertex& V3 = vertex( i,0,k+1);
00167 Quadrangle& Q = quadrangles[currentCell];
00168
00169 Q = Quadrangle(V0, V1, V2, V3, 2);
00170 Q.setMother(&(cell(i,0,k)),1);
00171
00172 currentCell++;
00173 }
00174 }
00175
00177 for (size_t i=0; i<nx_1; i++) {
00178 for (size_t k=0; k<nz_1; k++) {
00179 const Vertex& V0 = vertex( i,ny_1, k);
00180 const Vertex& V1 = vertex( i,ny_1,k+1);
00181 const Vertex& V2 = vertex(i+1,ny_1,k+1);
00182 const Vertex& V3 = vertex(i+1,ny_1, k);
00183 Quadrangle& Q = quadrangles[currentCell];
00184
00185 Q = Quadrangle(V0, V1, V2, V3, 3);
00186 Q.setMother(&(cell(i,ny_1-1,k)),3);
00187
00188 currentCell++;
00189 }
00190 }
00191
00193 for (size_t i=0; i<nx_1; i++) {
00194 for (size_t j=0; j<ny_1; j++) {
00195 const Vertex& V0 = vertex( i, j,0);
00196 const Vertex& V1 = vertex( i,j+1,0);
00197 const Vertex& V2 = vertex(i+1,j+1,0);
00198 const Vertex& V3 = vertex(i+1, j,0);
00199 Quadrangle& Q = quadrangles[currentCell];
00200
00201 Q = Quadrangle(V0, V1, V2, V3, 4);
00202 Q.setMother(&(cell(i,j,0)),0);
00203
00204 currentCell++;
00205 }
00206 }
00207
00208
00210 for (size_t i=0; i<nx_1; i++) {
00211 for (size_t j=0; j<ny_1; j++) {
00212 const Vertex& V0 = vertex( i, j,nz_1);
00213 const Vertex& V1 = vertex(i+1, j,nz_1);
00214 const Vertex& V2 = vertex(i+1,j+1,nz_1);
00215 const Vertex& V3 = vertex( i,j+1,nz_1);
00216 Quadrangle& Q = quadrangles[currentCell];
00217
00218 Q = Quadrangle(V0, V1, V2, V3, 5);
00219 Q.setMother(&(cell(i,j,nz_1-1)),5);
00220 currentCell++;
00221 }
00222 }
00223 __borderMesh = new SurfaceMeshOfQuadrangles(__verticesSet,
00224 __verticesCorrespondance,
00225 pQuadrangles);
00226 __borderMesh->setBackgroundMesh(this);
00227 }