00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "primitiveMesh.H"
00028 #include "demandDrivenData.H"
00029
00030
00031
00032
00033
00034 defineTypeNameAndDebug(Foam::primitiveMesh, 0);
00035
00036
00037
00038
00039 Foam::primitiveMesh::primitiveMesh()
00040 :
00041 nInternalPoints_(0),
00042 nPoints_(0),
00043 nInternal0Edges_(-1),
00044 nInternal1Edges_(-1),
00045 nInternalEdges_(-1),
00046 nEdges_(-1),
00047 nInternalFaces_(0),
00048 nFaces_(0),
00049 nCells_(0),
00050
00051 cellShapesPtr_(NULL),
00052 edgesPtr_(NULL),
00053 ccPtr_(NULL),
00054 ecPtr_(NULL),
00055 pcPtr_(NULL),
00056
00057 cfPtr_(NULL),
00058 efPtr_(NULL),
00059 pfPtr_(NULL),
00060
00061 cePtr_(NULL),
00062 fePtr_(NULL),
00063 pePtr_(NULL),
00064 ppPtr_(NULL),
00065 cpPtr_(NULL),
00066
00067 labels_(0),
00068
00069 cellCentresPtr_(NULL),
00070 faceCentresPtr_(NULL),
00071 cellVolumesPtr_(NULL),
00072 faceAreasPtr_(NULL)
00073 {}
00074
00075
00076
00077
00078 Foam::primitiveMesh::primitiveMesh
00079 (
00080 const label nPoints,
00081 const label nInternalFaces,
00082 const label nFaces,
00083 const label nCells
00084 )
00085 :
00086 nInternalPoints_(-1),
00087 nPoints_(nPoints),
00088 nEdges_(-1),
00089 nInternalFaces_(nInternalFaces),
00090 nFaces_(nFaces),
00091 nCells_(nCells),
00092
00093 cellShapesPtr_(NULL),
00094 edgesPtr_(NULL),
00095 ccPtr_(NULL),
00096 ecPtr_(NULL),
00097 pcPtr_(NULL),
00098
00099 cfPtr_(NULL),
00100 efPtr_(NULL),
00101 pfPtr_(NULL),
00102
00103 cePtr_(NULL),
00104 fePtr_(NULL),
00105 pePtr_(NULL),
00106 ppPtr_(NULL),
00107 cpPtr_(NULL),
00108
00109 labels_(0),
00110
00111 cellCentresPtr_(NULL),
00112 faceCentresPtr_(NULL),
00113 cellVolumesPtr_(NULL),
00114 faceAreasPtr_(NULL)
00115 {}
00116
00117
00118
00119
00120 Foam::primitiveMesh::~primitiveMesh()
00121 {
00122 clearOut();
00123 }
00124
00125
00126
00127
00128 bool Foam::primitiveMesh::calcPointOrder
00129 (
00130 label& nInternalPoints,
00131 labelList& oldToNew,
00132 const faceList& faces,
00133 const label nInternalFaces,
00134 const label nPoints
00135 )
00136 {
00137
00138
00139
00140 oldToNew.setSize(nPoints);
00141 oldToNew = -1;
00142
00143
00144
00145
00146
00147 label nBoundaryPoints = 0;
00148 for (label faceI = nInternalFaces; faceI < faces.size(); faceI++)
00149 {
00150 const face& f = faces[faceI];
00151
00152 forAll(f, fp)
00153 {
00154 label pointI = f[fp];
00155
00156 if (oldToNew[pointI] == -1)
00157 {
00158 oldToNew[pointI] = nBoundaryPoints++;
00159 }
00160 }
00161 }
00162
00163
00164
00165 nInternalPoints = nPoints - nBoundaryPoints;
00166
00167
00168 forAll(oldToNew, pointI)
00169 {
00170 if (oldToNew[pointI] != -1)
00171 {
00172 oldToNew[pointI] += nInternalPoints;
00173 }
00174 }
00175
00176
00177
00178
00179
00180 label internalPointI = 0;
00181
00182 bool ordered = true;
00183
00184 for (label faceI = 0; faceI < nInternalFaces; faceI++)
00185 {
00186 const face& f = faces[faceI];
00187
00188 forAll(f, fp)
00189 {
00190 label pointI = f[fp];
00191
00192 if (oldToNew[pointI] == -1)
00193 {
00194 if (pointI >= nInternalPoints)
00195 {
00196 ordered = false;
00197 }
00198 oldToNew[pointI] = internalPointI++;
00199 }
00200 }
00201 }
00202
00203 return ordered;
00204 }
00205
00206
00207 void Foam::primitiveMesh::reset
00208 (
00209 const label nPoints,
00210 const label nInternalFaces,
00211 const label nFaces,
00212 const label nCells
00213 )
00214 {
00215 clearOut();
00216
00217 nPoints_ = nPoints;
00218 nEdges_ = -1;
00219 nInternal0Edges_ = -1;
00220 nInternal1Edges_ = -1;
00221 nInternalEdges_ = -1;
00222
00223 nInternalFaces_ = nInternalFaces;
00224 nFaces_ = nFaces;
00225 nCells_ = nCells;
00226
00227
00228 label nInternalPoints;
00229 labelList pointMap;
00230
00231 bool isOrdered = calcPointOrder
00232 (
00233 nInternalPoints,
00234 pointMap,
00235 faces(),
00236 nInternalFaces_,
00237 nPoints_
00238 );
00239
00240 if (isOrdered)
00241 {
00242 nInternalPoints_ = nInternalPoints;
00243 }
00244 else
00245 {
00246 nInternalPoints_ = -1;
00247 }
00248
00249 if (debug)
00250 {
00251 Pout<< "primitiveMesh::reset : mesh reset to"
00252 << " nInternalPoints:" << nInternalPoints_
00253 << " nPoints:" << nPoints_
00254 << " nEdges:" << nEdges_
00255 << " nInternalFaces:" << nInternalFaces_
00256 << " nFaces:" << nFaces_
00257 << " nCells:" << nCells_
00258 << endl;
00259 }
00260 }
00261
00262
00263 void Foam::primitiveMesh::reset
00264 (
00265 const label nPoints,
00266 const label nInternalFaces,
00267 const label nFaces,
00268 const label nCells,
00269 cellList& clst
00270 )
00271 {
00272 reset
00273 (
00274 nPoints,
00275 nInternalFaces,
00276 nFaces,
00277 nCells
00278 );
00279
00280 cfPtr_ = new cellList(clst, true);
00281 }
00282
00283
00284 void Foam::primitiveMesh::reset
00285 (
00286 const label nPoints,
00287 const label nInternalFaces,
00288 const label nFaces,
00289 const label nCells,
00290 const Xfer<cellList>& clst
00291 )
00292 {
00293 reset
00294 (
00295 nPoints,
00296 nInternalFaces,
00297 nFaces,
00298 nCells
00299 );
00300
00301 cfPtr_ = new cellList(clst);
00302 }
00303
00304
00305 Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints
00306 (
00307 const pointField& newPoints,
00308 const pointField& oldPoints
00309 )
00310 {
00311 if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
00312 {
00313 FatalErrorIn
00314 (
00315 "primitiveMesh::movePoints(const pointField& newPoints, "
00316 "const pointField& oldPoints)"
00317 ) << "Cannot move points: size of given point list smaller "
00318 << "than the number of active points"
00319 << abort(FatalError);
00320 }
00321
00322
00323 const faceList& f = faces();
00324
00325 tmp<scalarField> tsweptVols(new scalarField(f.size()));
00326 scalarField& sweptVols = tsweptVols();
00327
00328 forAll(f, faceI)
00329 {
00330 sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
00331 }
00332
00333
00334 clearGeom();
00335
00336 return tsweptVols;
00337 }
00338
00339
00340 const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
00341 {
00342 if (!cellShapesPtr_)
00343 {
00344 calcCellShapes();
00345 }
00346
00347 return *cellShapesPtr_;
00348 }
00349
00350
00351