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 "fvMesh.H"
00028 #include "volFields.H"
00029 #include "surfaceFields.H"
00030 #include "slicedVolFields.H"
00031 #include "slicedSurfaceFields.H"
00032 #include "SubField.H"
00033 #include "demandDrivenData.H"
00034 #include "fvMeshLduAddressing.H"
00035 #include "emptyPolyPatch.H"
00036 #include "mapPolyMesh.H"
00037 #include "MapFvFields.H"
00038 #include "fvMeshMapper.H"
00039 #include "mapClouds.H"
00040
00041 #include "volPointInterpolation.H"
00042 #include "extendedLeastSquaresVectors.H"
00043 #include "extendedLeastSquaresVectors.H"
00044 #include "leastSquaresVectors.H"
00045 #include "CentredFitData.H"
00046 #include "linearFitPolynomial.H"
00047 #include "quadraticFitPolynomial.H"
00048 #include "quadraticLinearFitPolynomial.H"
00049
00050 #include "skewCorrectionVectors.H"
00051
00052
00053 #include "centredCECCellToFaceStencilObject.H"
00054 #include "centredCFCCellToFaceStencilObject.H"
00055 #include "centredCPCCellToFaceStencilObject.H"
00056 #include "centredFECCellToFaceStencilObject.H"
00057 #include "upwindCECCellToFaceStencilObject.H"
00058 #include "upwindCFCCellToFaceStencilObject.H"
00059 #include "upwindCPCCellToFaceStencilObject.H"
00060 #include "upwindFECCellToFaceStencilObject.H"
00061
00062 #include "centredCFCFaceToCellStencilObject.H"
00063
00064
00065
00066 defineTypeNameAndDebug(Foam::fvMesh, 0);
00067
00068
00069
00070 void Foam::fvMesh::clearGeomNotOldVol()
00071 {
00072 slicedVolScalarField::DimensionedInternalField* VPtr =
00073 static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
00074 deleteDemandDrivenData(VPtr);
00075 VPtr_ = NULL;
00076
00077 deleteDemandDrivenData(SfPtr_);
00078 deleteDemandDrivenData(magSfPtr_);
00079 deleteDemandDrivenData(CPtr_);
00080 deleteDemandDrivenData(CfPtr_);
00081 }
00082
00083
00084 void Foam::fvMesh::clearGeom()
00085 {
00086 clearGeomNotOldVol();
00087
00088 deleteDemandDrivenData(V0Ptr_);
00089 deleteDemandDrivenData(V00Ptr_);
00090
00091
00092
00093
00094
00095 volPointInterpolation::Delete(*this);
00096 extendedLeastSquaresVectors::Delete(*this);
00097 leastSquaresVectors::Delete(*this);
00098 CentredFitData<linearFitPolynomial>::Delete(*this);
00099 CentredFitData<quadraticFitPolynomial>::Delete(*this);
00100 CentredFitData<quadraticLinearFitPolynomial>::Delete(*this);
00101 skewCorrectionVectors::Delete(*this);
00102
00103 }
00104
00105
00106 void Foam::fvMesh::clearAddressing()
00107 {
00108 deleteDemandDrivenData(lduPtr_);
00109
00110
00111
00112 volPointInterpolation::Delete(*this);
00113 extendedLeastSquaresVectors::Delete(*this);
00114 leastSquaresVectors::Delete(*this);
00115 CentredFitData<linearFitPolynomial>::Delete(*this);
00116 CentredFitData<quadraticFitPolynomial>::Delete(*this);
00117 CentredFitData<quadraticLinearFitPolynomial>::Delete(*this);
00118 skewCorrectionVectors::Delete(*this);
00119
00120
00121 centredCECCellToFaceStencilObject::Delete(*this);
00122 centredCFCCellToFaceStencilObject::Delete(*this);
00123 centredCPCCellToFaceStencilObject::Delete(*this);
00124 centredFECCellToFaceStencilObject::Delete(*this);
00125
00126 upwindCECCellToFaceStencilObject::Delete(*this);
00127 upwindCFCCellToFaceStencilObject::Delete(*this);
00128 upwindCPCCellToFaceStencilObject::Delete(*this);
00129 upwindFECCellToFaceStencilObject::Delete(*this);
00130
00131 centredCFCFaceToCellStencilObject::Delete(*this);
00132 }
00133
00134
00135 void Foam::fvMesh::clearOut()
00136 {
00137 clearGeom();
00138 surfaceInterpolation::clearOut();
00139
00140 clearAddressing();
00141
00142
00143 deleteDemandDrivenData(phiPtr_);
00144
00145 polyMesh::clearOut();
00146 }
00147
00148
00149
00150
00151 Foam::fvMesh::fvMesh(const IOobject& io)
00152 :
00153 polyMesh(io),
00154 surfaceInterpolation(*this),
00155 boundary_(*this, boundaryMesh()),
00156 lduPtr_(NULL),
00157 curTimeIndex_(time().timeIndex()),
00158 VPtr_(NULL),
00159 V0Ptr_(NULL),
00160 V00Ptr_(NULL),
00161 SfPtr_(NULL),
00162 magSfPtr_(NULL),
00163 CPtr_(NULL),
00164 CfPtr_(NULL),
00165 phiPtr_(NULL)
00166 {
00167 if (debug)
00168 {
00169 Info<< "Constructing fvMesh from IOobject"
00170 << endl;
00171 }
00172
00173
00174
00175 if (isFile(time().timePath()/"V0"))
00176 {
00177 V0Ptr_ = new DimensionedField<scalar, volMesh>
00178 (
00179 IOobject
00180 (
00181 "V0",
00182 time().timeName(),
00183 *this,
00184 IOobject::MUST_READ,
00185 IOobject::NO_WRITE
00186 ),
00187 *this
00188 );
00189
00190 V00();
00191 }
00192
00193
00194
00195 if (isFile(time().timePath()/"meshPhi"))
00196 {
00197 phiPtr_ = new surfaceScalarField
00198 (
00199 IOobject
00200 (
00201 "meshPhi",
00202 time().timeName(),
00203 *this,
00204 IOobject::MUST_READ,
00205 IOobject::AUTO_WRITE
00206 ),
00207 *this
00208 );
00209
00210
00211
00212
00213 if (!V0Ptr_)
00214 {
00215 V0Ptr_ = new DimensionedField<scalar, volMesh>
00216 (
00217 IOobject
00218 (
00219 "V0",
00220 time().timeName(),
00221 *this,
00222 IOobject::NO_READ,
00223 IOobject::NO_WRITE,
00224 false
00225 ),
00226 V()
00227 );
00228 }
00229
00230 moving(true);
00231 }
00232 }
00233
00234
00235 Foam::fvMesh::fvMesh
00236 (
00237 const IOobject& io,
00238 const Xfer<pointField>& points,
00239 const Xfer<faceList>& faces,
00240 const Xfer<labelList>& allOwner,
00241 const Xfer<labelList>& allNeighbour,
00242 const bool syncPar
00243 )
00244 :
00245 polyMesh(io, points, faces, allOwner, allNeighbour, syncPar),
00246 surfaceInterpolation(*this),
00247 boundary_(*this),
00248 lduPtr_(NULL),
00249 curTimeIndex_(time().timeIndex()),
00250 VPtr_(NULL),
00251 V0Ptr_(NULL),
00252 V00Ptr_(NULL),
00253 SfPtr_(NULL),
00254 magSfPtr_(NULL),
00255 CPtr_(NULL),
00256 CfPtr_(NULL),
00257 phiPtr_(NULL)
00258 {
00259 if (debug)
00260 {
00261 Info<< "Constructing fvMesh from components" << endl;
00262 }
00263 }
00264
00265
00266 Foam::fvMesh::fvMesh
00267 (
00268 const IOobject& io,
00269 const Xfer<pointField>& points,
00270 const Xfer<faceList>& faces,
00271 const Xfer<cellList>& cells,
00272 const bool syncPar
00273 )
00274 :
00275 polyMesh(io, points, faces, cells, syncPar),
00276 surfaceInterpolation(*this),
00277 boundary_(*this),
00278 lduPtr_(NULL),
00279 curTimeIndex_(time().timeIndex()),
00280 VPtr_(NULL),
00281 V0Ptr_(NULL),
00282 V00Ptr_(NULL),
00283 SfPtr_(NULL),
00284 magSfPtr_(NULL),
00285 CPtr_(NULL),
00286 CfPtr_(NULL),
00287 phiPtr_(NULL)
00288 {
00289 if (debug)
00290 {
00291 Info<< "Constructing fvMesh from components" << endl;
00292 }
00293 }
00294
00295
00296
00297
00298 Foam::fvMesh::~fvMesh()
00299 {
00300 clearOut();
00301 }
00302
00303
00304
00305
00306 void Foam::fvMesh::addFvPatches
00307 (
00308 const List<polyPatch*> & p,
00309 const bool validBoundary
00310 )
00311 {
00312 if (boundary().size())
00313 {
00314 FatalErrorIn
00315 (
00316 "fvMesh::addFvPatches(const List<polyPatch*>&, const bool)"
00317 ) << " boundary already exists"
00318 << abort(FatalError);
00319 }
00320
00321
00322 addPatches(p, validBoundary);
00323 boundary_.addPatches(boundaryMesh());
00324 }
00325
00326
00327 void Foam::fvMesh::removeFvBoundary()
00328 {
00329 if (debug)
00330 {
00331 Info<< "void fvMesh::removeFvBoundary(): "
00332 << "Removing boundary patches."
00333 << endl;
00334 }
00335
00336
00337 boundary_.clear();
00338 boundary_.setSize(0);
00339 polyMesh::removeBoundary();
00340
00341 clearOut();
00342 }
00343
00344
00345 Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate()
00346 {
00347 if (debug)
00348 {
00349 Info<< "polyMesh::readUpdateState fvMesh::readUpdate() : "
00350 << "Updating fvMesh. ";
00351 }
00352
00353 polyMesh::readUpdateState state = polyMesh::readUpdate();
00354
00355 if (state == polyMesh::TOPO_PATCH_CHANGE)
00356 {
00357 if (debug)
00358 {
00359 Info << "Boundary and topological update" << endl;
00360 }
00361
00362 boundary_.readUpdate(boundaryMesh());
00363
00364 clearOut();
00365
00366 }
00367 else if (state == polyMesh::TOPO_CHANGE)
00368 {
00369 if (debug)
00370 {
00371 Info << "Topological update" << endl;
00372 }
00373
00374 clearOut();
00375 }
00376 else if (state == polyMesh::POINTS_MOVED)
00377 {
00378 if (debug)
00379 {
00380 Info << "Point motion update" << endl;
00381 }
00382
00383 clearGeom();
00384 }
00385 else
00386 {
00387 if (debug)
00388 {
00389 Info << "No update" << endl;
00390 }
00391 }
00392
00393 return state;
00394 }
00395
00396
00397 const Foam::fvBoundaryMesh& Foam::fvMesh::boundary() const
00398 {
00399 return boundary_;
00400 }
00401
00402
00403 const Foam::lduAddressing& Foam::fvMesh::lduAddr() const
00404 {
00405 if (!lduPtr_)
00406 {
00407 lduPtr_ = new fvMeshLduAddressing(*this);
00408 }
00409
00410 return *lduPtr_;
00411 }
00412
00413
00414 void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap)
00415 {
00416
00417 const fvMeshMapper mapper(*this, meshMap);
00418
00419
00420 MapGeometricFields<scalar, fvPatchField, fvMeshMapper, volMesh>
00421 (mapper);
00422 MapGeometricFields<vector, fvPatchField, fvMeshMapper, volMesh>
00423 (mapper);
00424 MapGeometricFields<sphericalTensor, fvPatchField, fvMeshMapper, volMesh>
00425 (mapper);
00426 MapGeometricFields<symmTensor, fvPatchField, fvMeshMapper, volMesh>
00427 (mapper);
00428 MapGeometricFields<tensor, fvPatchField, fvMeshMapper, volMesh>
00429 (mapper);
00430
00431
00432 MapGeometricFields<scalar, fvsPatchField, fvMeshMapper, surfaceMesh>
00433 (mapper);
00434 MapGeometricFields<vector, fvsPatchField, fvMeshMapper, surfaceMesh>
00435 (mapper);
00436 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
00437 (mapper);
00438 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
00439 (mapper);
00440 MapGeometricFields<tensor, fvsPatchField, fvMeshMapper, surfaceMesh>
00441 (mapper);
00442
00443
00444 mapClouds(*this, meshMap);
00445
00446
00447 const labelList& cellMap = meshMap.cellMap();
00448
00449
00450 if (V0Ptr_)
00451 {
00452 scalarField& V0 = *V0Ptr_;
00453
00454 scalarField savedV0(V0);
00455 V0.setSize(nCells());
00456
00457 forAll(V0, i)
00458 {
00459 if (cellMap[i] > -1)
00460 {
00461 V0[i] = savedV0[cellMap[i]];
00462 }
00463 else
00464 {
00465 V0[i] = 0.0;
00466 }
00467 }
00468 }
00469
00470
00471 if (V00Ptr_)
00472 {
00473 scalarField& V00 = *V00Ptr_;
00474
00475 scalarField savedV00(V00);
00476 V00.setSize(nCells());
00477
00478 forAll(V00, i)
00479 {
00480 if (cellMap[i] > -1)
00481 {
00482 V00[i] = savedV00[cellMap[i]];
00483 }
00484 else
00485 {
00486 V00[i] = 0.0;
00487 }
00488 }
00489 }
00490 }
00491
00492
00493
00494
00495 template<class Type>
00496 void MeshObjectMovePoints(const Foam::fvMesh& mesh)
00497 {
00498 if (mesh.thisDb().foundObject<Type>(Type::typeName))
00499 {
00500 const_cast<Type&>
00501 (
00502 mesh.thisDb().lookupObject<Type>
00503 (
00504 Type::typeName
00505 )
00506 ).movePoints();
00507 }
00508 }
00509
00510
00511 Foam::tmp<Foam::scalarField> Foam::fvMesh::movePoints(const pointField& p)
00512 {
00513
00514 if (curTimeIndex_ < time().timeIndex())
00515 {
00516 if (V00Ptr_ && V0Ptr_)
00517 {
00518 *V00Ptr_ = *V0Ptr_;
00519 }
00520
00521 if (V0Ptr_)
00522 {
00523 *V0Ptr_ = V();
00524 }
00525 else
00526 {
00527 V0Ptr_ = new DimensionedField<scalar, volMesh>
00528 (
00529 IOobject
00530 (
00531 "V0",
00532 time().timeName(),
00533 *this,
00534 IOobject::NO_READ,
00535 IOobject::NO_WRITE
00536 ),
00537 V()
00538 );
00539 }
00540
00541 curTimeIndex_ = time().timeIndex();
00542 }
00543
00544
00545
00546 clearGeomNotOldVol();
00547
00548
00549 if (!phiPtr_)
00550 {
00551
00552 phiPtr_ = new surfaceScalarField
00553 (
00554 IOobject
00555 (
00556 "meshPhi",
00557 this->time().timeName(),
00558 *this,
00559 IOobject::NO_READ,
00560 IOobject::AUTO_WRITE
00561 ),
00562 *this,
00563 dimVolume/dimTime
00564 );
00565 }
00566 else
00567 {
00568
00569 if (phiPtr_->timeIndex() != time().timeIndex())
00570 {
00571 phiPtr_->oldTime();
00572 }
00573 }
00574
00575 surfaceScalarField& phi = *phiPtr_;
00576
00577
00578
00579 scalar rDeltaT = 1.0/time().deltaT().value();
00580
00581 tmp<scalarField> tsweptVols = polyMesh::movePoints(p);
00582 scalarField& sweptVols = tsweptVols();
00583
00584 phi.internalField() = scalarField::subField(sweptVols, nInternalFaces());
00585 phi.internalField() *= rDeltaT;
00586
00587 const fvPatchList& patches = boundary();
00588
00589 forAll (patches, patchI)
00590 {
00591 phi.boundaryField()[patchI] = patches[patchI].patchSlice(sweptVols);
00592 phi.boundaryField()[patchI] *= rDeltaT;
00593 }
00594
00595 boundary_.movePoints();
00596 surfaceInterpolation::movePoints();
00597
00598
00599
00600
00601 MeshObjectMovePoints<volPointInterpolation>(*this);
00602 MeshObjectMovePoints<extendedLeastSquaresVectors>(*this);
00603 MeshObjectMovePoints<leastSquaresVectors>(*this);
00604 MeshObjectMovePoints<CentredFitData<linearFitPolynomial> >(*this);
00605 MeshObjectMovePoints<CentredFitData<quadraticFitPolynomial> >(*this);
00606 MeshObjectMovePoints<CentredFitData<quadraticLinearFitPolynomial> >(*this);
00607 MeshObjectMovePoints<skewCorrectionVectors>(*this);
00608
00609
00610 return tsweptVols;
00611 }
00612
00613
00614 void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
00615 {
00616
00617 polyMesh::updateMesh(mpm);
00618
00619
00620 clearGeomNotOldVol();
00621
00622
00623 mapFields(mpm);
00624
00625
00626 surfaceInterpolation::clearOut();
00627
00628 clearAddressing();
00629
00630
00631
00632 surfaceInterpolation::movePoints();
00633 }
00634
00635
00636 bool Foam::fvMesh::writeObjects
00637 (
00638 IOstream::streamFormat fmt,
00639 IOstream::versionNumber ver,
00640 IOstream::compressionType cmp
00641 ) const
00642 {
00643 return polyMesh::writeObject(fmt, ver, cmp);
00644 }
00645
00646
00647
00648 bool Foam::fvMesh::write() const
00649 {
00650 return polyMesh::write();
00651 }
00652
00653
00654
00655
00656 bool Foam::fvMesh::operator!=(const fvMesh& bm) const
00657 {
00658 return &bm != this;
00659 }
00660
00661
00662 bool Foam::fvMesh::operator==(const fvMesh& bm) const
00663 {
00664 return &bm == this;
00665 }
00666
00667
00668