1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "slicedVolFields.H"
31 #include "slicedSurfaceFields.H"
33 #include "demandDrivenData.H"
34 #include "fvMeshLduAddressing.H"
35 #include "emptyPolyPatch.H"
36 #include "mapPolyMesh.H"
37 #include "MapFvFields.H"
38 #include "fvMeshMapper.H"
39 #include "mapClouds.H"
40 #include "meshObjectBase.H"
42 #include "volPointInterpolation.H"
43 #include "extendedLeastSquaresVectors.H"
44 #include "extendedLeastSquaresVectors.H"
45 #include "leastSquaresVectors.H"
46 #include "CentredFitData.H"
47 #include "linearFitPolynomial.H"
48 #include "quadraticFitPolynomial.H"
49 #include "quadraticLinearFitPolynomial.H"
50 //#include "quadraticFitSnGradData.H"
51 #include "skewCorrectionVectors.H"
53 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
55 defineTypeNameAndDebug(Foam::fvMesh, 0);
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
59 void Foam::fvMesh::clearGeomNotOldVol()
61 deleteDemandDrivenData(VPtr_);
63 deleteDemandDrivenData(SfPtr_);
64 deleteDemandDrivenData(magSfPtr_);
65 deleteDemandDrivenData(CPtr_);
66 deleteDemandDrivenData(CfPtr_);
70 void Foam::fvMesh::clearGeom()
74 deleteDemandDrivenData(V0Ptr_);
75 deleteDemandDrivenData(V00Ptr_);
77 // Mesh motion flux cannot be deleted here because the old-time flux
80 // Geometry dependent object updated through call-back
81 // "Reserve" optional delete. Reconsider
83 // meshObjectBase::allDelete(*this);
87 void Foam::fvMesh::clearAddressing()
89 deleteDemandDrivenData(lduPtr_);
91 // Geometry dependent object updated through call-back
92 // "Reserve" optional delete. Reconsider
94 // meshObjectBase::allDelete(*this);
98 void Foam::fvMesh::clearOut()
101 surfaceInterpolation::clearOut();
105 // Clear mesh motion flux
106 deleteDemandDrivenData(phiPtr_);
108 polyMesh::clearOut();
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 Foam::fvMesh::fvMesh(const IOobject& io)
117 surfaceInterpolation(*this),
118 boundary_(*this, boundaryMesh()),
120 curTimeIndex_(time().timeIndex()),
132 Info<< "Constructing fvMesh from IOobject"
136 // Check the existance of the cell volumes and read if present
137 // and set the storage of V00
138 if (isFile(time().timePath()/"V0"))
142 Info<< "Reading old cell volumes" << endl;
145 V0Ptr_ = new DimensionedField<scalar, volMesh>
161 // Check the existance of the mesh fluxes, read if present and set the
163 if (isFile(time().timePath()/"meshPhi"))
167 Info<< "Reading motion fluxes" << endl;
170 phiPtr_ = new surfaceScalarField
183 // The mesh is now considered moving so the old-time cell volumes
184 // will be required for the time derivatives so if they haven't been
185 // read initialise to the current cell volumes
188 V0Ptr_ = new DimensionedField<scalar, volMesh>
211 const Xfer<pointField>& points,
212 const Xfer<faceList>& faces,
213 const Xfer<labelList>& allOwner,
214 const Xfer<labelList>& allNeighbour,
218 polyMesh(io, points, faces, allOwner, allNeighbour, syncPar),
219 surfaceInterpolation(*this),
222 curTimeIndex_(time().timeIndex()),
234 Info<< "Constructing fvMesh from components" << endl;
242 const Xfer<pointField>& points,
243 const Xfer<faceList>& faces,
244 const Xfer<cellList>& cells,
248 polyMesh(io, points, faces, cells, syncPar),
249 surfaceInterpolation(*this),
252 curTimeIndex_(time().timeIndex()),
264 Info<< "Constructing fvMesh from components" << endl;
269 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
271 Foam::fvMesh::~fvMesh()
277 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
279 void Foam::fvMesh::addFvPatches
281 const List<polyPatch*> & p,
282 const bool validBoundary
285 if (boundary().size())
289 "fvMesh::addFvPatches(const List<polyPatch*>&, const bool)"
290 ) << " boundary already exists"
291 << abort(FatalError);
294 // first add polyPatches
295 addPatches(p, validBoundary);
296 boundary_.addPatches(boundaryMesh());
300 void Foam::fvMesh::removeFvBoundary()
304 Info<< "void fvMesh::removeFvBoundary(): "
305 << "Removing boundary patches."
309 // Remove fvBoundaryMesh data first.
311 boundary_.setSize(0);
312 polyMesh::removeBoundary();
318 Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate()
322 Info<< "polyMesh::readUpdateState fvMesh::readUpdate() : "
323 << "Updating fvMesh. ";
326 polyMesh::readUpdateState state = polyMesh::readUpdate();
328 if (state == polyMesh::TOPO_PATCH_CHANGE)
332 Info << "Boundary and topological update" << endl;
335 boundary_.readUpdate(boundaryMesh());
340 else if (state == polyMesh::TOPO_CHANGE)
344 Info << "Topological update" << endl;
349 else if (state == polyMesh::POINTS_MOVED)
353 Info << "Point motion update" << endl;
362 Info << "No update" << endl;
370 const Foam::fvBoundaryMesh& Foam::fvMesh::boundary() const
376 const Foam::lduAddressing& Foam::fvMesh::lduAddr() const
380 lduPtr_ = new fvMeshLduAddressing(*this);
387 void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap) const
391 Info<< "void fvMesh::mapFields(const mapPolyMesh& meshMap) const: "
392 << "Mapping fv fields."
397 const fvMeshMapper mapper(*this, meshMap);
399 // Map all the volFields in the objectRegistry
400 MapGeometricFields<scalar, fvPatchField, fvMeshMapper, volMesh>(mapper);
401 MapGeometricFields<vector, fvPatchField, fvMeshMapper, volMesh>(mapper);
402 MapGeometricFields<sphericalTensor, fvPatchField, fvMeshMapper, volMesh>
405 MapGeometricFields<symmTensor, fvPatchField, fvMeshMapper, volMesh>
408 MapGeometricFields<tensor, fvPatchField, fvMeshMapper, volMesh>(mapper);
410 // Map all the surfaceFields in the objectRegistry
411 MapGeometricFields<scalar, fvsPatchField, fvMeshMapper, surfaceMesh>
414 MapGeometricFields<vector, fvsPatchField, fvMeshMapper, surfaceMesh>
418 <sphericalTensor, fvsPatchField, fvMeshMapper, surfaceMesh>(mapper);
419 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
422 MapGeometricFields<tensor, fvsPatchField, fvMeshMapper, surfaceMesh>
425 // Map all the clouds in the objectRegistry
426 mapClouds(*this, meshMap);
430 void Foam::fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)
432 const labelList& cellMap = meshMap.cellMap();
434 // Map the old volume. Just map to new cell labels.
439 InfoIn("void fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)")
440 << "Mapping old cell volumes." << endl;
443 scalarField& V0 = *V0Ptr_;
445 scalarField savedV0(V0);
446 V0.setSize(nCells());
452 V0[i] = savedV0[cellMap[i]];
461 // Map the old-old volume. Just map to new cell labels.
466 InfoIn("void fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)")
467 << "Mapping old-old cell volumes." << endl;
470 scalarField& V00 = *V00Ptr_;
472 scalarField savedV00(V00);
473 V00.setSize(nCells());
479 V00[i] = savedV00[cellMap[i]];
490 void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
492 // Update polyMesh. This needs to keep volume existent!
493 polyMesh::updateMesh(mpm);
495 surfaceInterpolation::clearOut();
496 clearGeomNotOldVol();
506 // handleMorph() should also clear out the surfaceInterpolation.
507 // This is a temporary solution
508 surfaceInterpolation::movePoints();
510 // Function object update moved to polyMesh
515 void Foam::fvMesh::syncUpdateMesh()
517 // Update polyMesh. This needs to keep volume existent!
518 polyMesh::syncUpdateMesh();
520 // Not sure how much clean-up is needed here. HJ, 27/Nov/2009
522 surfaceInterpolation::clearOut();
523 clearGeomNotOldVol();
527 // handleMorph() should also clear out the surfaceInterpolation.
528 // This is a temporary solution
529 surfaceInterpolation::movePoints();
531 // Instantiate a dummy mapPolyMesh
532 autoPtr<mapPolyMesh> mapPtr(new mapPolyMesh(*this));
534 // Function object update moved to polyMesh
539 Foam::tmp<Foam::scalarField> Foam::fvMesh::movePoints(const pointField& p)
541 // Grab old time volumes if the time has been incremented
542 if (curTimeIndex_ < time().timeIndex())
544 if (V00Ptr_ && V0Ptr_)
548 InfoIn("void fvMesh::movePoints(const mapPolyMesh& meshMap)")
549 << "Grabbing old-old cell volumes." << endl;
559 InfoIn("void fvMesh::movePoints(const mapPolyMesh& meshMap)")
560 << "Grabbing old cell volumes." << endl;
569 InfoIn("void fvMesh::movePoints(const mapPolyMesh& meshMap)")
570 << "Creating old cell volumes." << endl;
573 V0Ptr_ = new DimensionedField<scalar, volMesh>
587 curTimeIndex_ = time().timeIndex();
591 // Delete out of date geometrical information
592 clearGeomNotOldVol();
597 // Create mesh motion flux
600 InfoIn("tmp<scalarField> fvMesh::movePoints(const pointField& p)")
601 << "Creating new mesh motion fluxes" << endl;
604 phiPtr_ = new surfaceScalarField
609 this->time().timeName(),
620 // Grab old time mesh motion fluxes if the time has been incremented
621 if (phiPtr_->timeIndex() < time().timeIndex())
627 // Move the polyMesh and set the mesh motion fluxes to the swept-volumes
628 tmp<scalarField> tsweptVols = polyMesh::movePoints(p);
630 updatePhi(tsweptVols());
632 boundary_.movePoints();
633 surfaceInterpolation::movePoints();
635 // Function object update moved to polyMesh
642 bool Foam::fvMesh::writeObjects
644 IOstream::streamFormat fmt,
645 IOstream::versionNumber ver,
646 IOstream::compressionType cmp
649 return polyMesh::writeObject(fmt, ver, cmp);
653 //- Write mesh using IO settings from the time
654 bool Foam::fvMesh::write() const
656 return polyMesh::write();
660 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
662 bool Foam::fvMesh::operator!=(const fvMesh& bm) const
668 bool Foam::fvMesh::operator==(const fvMesh& bm) const
674 // ************************************************************************* //