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