1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "volFields.H"
28 #include "surfaceFields.H"
29 #include "slicedVolFields.H"
30 #include "slicedSurfaceFields.H"
32 #include "demandDrivenData.H"
33 #include "fvMeshLduAddressing.H"
34 #include "emptyPolyPatch.H"
35 #include "mapPolyMesh.H"
36 #include "MapFvFields.H"
37 #include "fvMeshMapper.H"
38 #include "mapClouds.H"
40 #include "volPointInterpolation.H"
42 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 defineTypeNameAndDebug(Foam::fvMesh, 0);
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 void Foam::fvMesh::clearGeomNotOldVol()
51 deleteDemandDrivenData(VPtr_);
53 deleteDemandDrivenData(SfPtr_);
54 deleteDemandDrivenData(magSfPtr_);
55 deleteDemandDrivenData(CPtr_);
56 deleteDemandDrivenData(CfPtr_);
60 void Foam::fvMesh::clearGeom()
64 deleteDemandDrivenData(V0Ptr_);
65 deleteDemandDrivenData(V00Ptr_);
67 // Mesh motion flux cannot be deleted here because the old-time flux
70 // Geometry dependent object updated through call-back
71 // and handled by polyMesh
76 void Foam::fvMesh::clearAddressing()
78 deleteDemandDrivenData(lduPtr_);
80 // Geometry dependent object updated through call-back
81 // and handled by polyMesh
86 void Foam::fvMesh::clearOut()
89 surfaceInterpolation::clearOut();
93 // Clear mesh motion flux
94 deleteDemandDrivenData(phiPtr_);
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 Foam::fvMesh::fvMesh(const IOobject& io)
105 surfaceInterpolation(*this),
106 boundary_(*this, boundaryMesh()),
108 curTimeIndex_(time().timeIndex()),
120 Info<< "Constructing fvMesh from IOobject"
124 // Check the existance of the cell volumes and read if present
125 // and set the storage of V00
126 if (isFile(time().timePath()/"V0"))
130 Info<< "Reading old cell volumes" << endl;
133 V0Ptr_ = new DimensionedField<scalar, volMesh>
149 // Check the existance of the mesh fluxes, read if present and set the
151 if (isFile(time().timePath()/"meshPhi"))
155 Info<< "Reading motion fluxes" << endl;
158 phiPtr_ = new surfaceScalarField
171 // The mesh is now considered moving so the old-time cell volumes
172 // will be required for the time derivatives so if they haven't been
173 // read initialise to the current cell volumes
176 V0Ptr_ = new DimensionedField<scalar, volMesh>
199 const Xfer<pointField>& points,
200 const Xfer<faceList>& faces,
201 const Xfer<labelList>& allOwner,
202 const Xfer<labelList>& allNeighbour,
206 polyMesh(io, points, faces, allOwner, allNeighbour, syncPar),
207 surfaceInterpolation(*this),
210 curTimeIndex_(time().timeIndex()),
222 Info<< "Constructing fvMesh from components" << endl;
230 const Xfer<pointField>& points,
231 const Xfer<faceList>& faces,
232 const Xfer<cellList>& cells,
236 polyMesh(io, points, faces, cells, syncPar),
237 surfaceInterpolation(*this),
240 curTimeIndex_(time().timeIndex()),
252 Info<< "Constructing fvMesh from components" << endl;
260 const Xfer<pointField>& points,
261 const cellShapeList& shapes,
262 const faceListList& boundaryFaces,
263 const wordList& boundaryPatchNames,
264 const wordList& boundaryPatchTypes,
265 const word& defaultBoundaryPatchName,
266 const word& defaultBoundaryPatchType,
267 const wordList& boundaryPatchPhysicalTypes,
279 defaultBoundaryPatchName,
280 defaultBoundaryPatchType,
281 boundaryPatchPhysicalTypes,
284 surfaceInterpolation(*this),
287 curTimeIndex_(time().timeIndex()),
299 Info<< "Constructing fvMesh from components" << endl;
304 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
306 Foam::fvMesh::~fvMesh()
312 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
314 void Foam::fvMesh::addFvPatches
316 const List<polyPatch*> & p,
317 const bool validBoundary
320 if (boundary().size())
324 "fvMesh::addFvPatches(const List<polyPatch*>&, const bool)"
325 ) << " boundary already exists"
326 << abort(FatalError);
329 // first add polyPatches
330 addPatches(p, validBoundary);
331 boundary_.addPatches(boundaryMesh());
335 void Foam::fvMesh::removeFvBoundary()
339 Info<< "void fvMesh::removeFvBoundary(): "
340 << "Removing boundary patches."
344 // Remove fvBoundaryMesh data first.
346 boundary_.setSize(0);
347 polyMesh::removeBoundary();
353 Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate()
357 Info<< "polyMesh::readUpdateState fvMesh::readUpdate() : "
358 << "Updating fvMesh. ";
361 // Note: issues with update: should meshObject update happen
362 // in polyMesh or fvMesh? HJ, 18/Feb/2011
363 polyMesh::readUpdateState state = polyMesh::readUpdate();
365 if (state == polyMesh::TOPO_PATCH_CHANGE)
369 Info << "Boundary and topological update" << endl;
372 boundary_.readUpdate(boundaryMesh());
377 else if (state == polyMesh::TOPO_CHANGE)
381 Info << "Topological update" << endl;
386 else if (state == polyMesh::POINTS_MOVED)
390 Info << "Point motion update" << endl;
399 Info << "No update" << endl;
407 const Foam::fvBoundaryMesh& Foam::fvMesh::boundary() const
413 const Foam::lduAddressing& Foam::fvMesh::lduAddr() const
417 lduPtr_ = new fvMeshLduAddressing(*this);
424 void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap) const
428 Info<< "void fvMesh::mapFields(const mapPolyMesh& meshMap) const: "
429 << "Mapping fv fields."
434 const fvMeshMapper mapper(*this, meshMap);
436 // Map all the volFields in the objectRegistry
437 MapGeometricFields<scalar, fvPatchField, fvMeshMapper, volMesh>(mapper);
438 MapGeometricFields<vector, fvPatchField, fvMeshMapper, volMesh>(mapper);
439 MapGeometricFields<sphericalTensor, fvPatchField, fvMeshMapper, volMesh>
442 MapGeometricFields<symmTensor, fvPatchField, fvMeshMapper, volMesh>
445 MapGeometricFields<symmTensor4thOrder, fvPatchField, fvMeshMapper, volMesh>
448 MapGeometricFields<diagTensor, fvPatchField, fvMeshMapper, volMesh>
451 MapGeometricFields<tensor, fvPatchField, fvMeshMapper, volMesh>(mapper);
453 // Map all the surfaceFields in the objectRegistry
454 MapGeometricFields<scalar, fvsPatchField, fvMeshMapper, surfaceMesh>
457 MapGeometricFields<vector, fvsPatchField, fvMeshMapper, surfaceMesh>
461 <sphericalTensor, fvsPatchField, fvMeshMapper, surfaceMesh>(mapper);
462 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
465 MapGeometricFields<symmTensor4thOrder, fvsPatchField, fvMeshMapper, surfaceMesh>
468 MapGeometricFields<diagTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
471 MapGeometricFields<tensor, fvsPatchField, fvMeshMapper, surfaceMesh>
474 // Map all the clouds in the objectRegistry
475 mapClouds(*this, meshMap);
479 void Foam::fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)
481 const labelList& cellMap = meshMap.cellMap();
483 // Map the old volume. Just map to new cell labels.
488 InfoIn("void fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)")
489 << "Mapping old cell volumes." << endl;
492 scalarField& V0 = *V0Ptr_;
494 scalarField savedV0(V0);
495 V0.setSize(nCells());
501 V0[i] = savedV0[cellMap[i]];
510 // Map the old-old volume. Just map to new cell labels.
515 InfoIn("void fvMesh::mapOldVolumes(const mapPolyMesh& meshMap)")
516 << "Mapping old-old cell volumes." << endl;
519 scalarField& V00 = *V00Ptr_;
521 scalarField savedV00(V00);
522 V00.setSize(nCells());
528 V00[i] = savedV00[cellMap[i]];
539 void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
541 // Update polyMesh. This needs to keep volume existent!
542 polyMesh::updateMesh(mpm);
544 surfaceInterpolation::clearOut();
545 clearGeomNotOldVol();
555 // Mesh morphing should also clear out the surfaceInterpolation.
556 // This is a temporary solution
557 surfaceInterpolation::movePoints();
559 // Function object update moved to polyMesh
564 void Foam::fvMesh::syncUpdateMesh()
566 // Update polyMesh. This needs to keep volume existent!
567 polyMesh::syncUpdateMesh();
569 // Not sure how much clean-up is needed here. HJ, 27/Nov/2009
571 surfaceInterpolation::clearOut();
572 clearGeomNotOldVol();
576 // handleMorph() should also clear out the surfaceInterpolation.
577 // This is a temporary solution
578 surfaceInterpolation::movePoints();
580 // Function object update moved to polyMesh
585 Foam::tmp<Foam::scalarField> Foam::fvMesh::movePoints(const pointField& p)
587 // Grab old time volumes if the time has been incremented
588 if (curTimeIndex_ < time().timeIndex())
590 if (V00Ptr_ && V0Ptr_)
594 InfoIn("void fvMesh::movePoints(const pointField& p)")
595 << "Grabbing old-old cell volumes." << endl;
605 InfoIn("void fvMesh::movePoints(const pointField& p)")
606 << "Grabbing old cell volumes." << endl;
615 InfoIn("void fvMesh::movePoints(const pointField& p)")
616 << "Creating old cell volumes." << endl;
619 V0Ptr_ = new DimensionedField<scalar, volMesh>
633 curTimeIndex_ = time().timeIndex();
637 // Delete out of date geometrical information
638 clearGeomNotOldVol();
643 // Create mesh motion flux
646 InfoIn("tmp<scalarField> fvMesh::movePoints(const pointField& p)")
647 << "Creating new mesh motion fluxes" << endl;
650 phiPtr_ = new surfaceScalarField
655 this->time().timeName(),
666 // Grab old time mesh motion fluxes if the time has been incremented
667 if (phiPtr_->timeIndex() < time().timeIndex())
673 // Move the polyMesh and set the mesh motion fluxes to the swept-volumes
674 tmp<scalarField> tsweptVols = polyMesh::movePoints(p);
676 updatePhi(tsweptVols());
678 boundary_.movePoints();
679 surfaceInterpolation::movePoints();
681 // Function object update moved to polyMesh
688 bool Foam::fvMesh::writeObjects
690 IOstream::streamFormat fmt,
691 IOstream::versionNumber ver,
692 IOstream::compressionType cmp
695 return polyMesh::writeObject(fmt, ver, cmp);
699 //- Write mesh using IO settings from the time
700 bool Foam::fvMesh::write() const
702 return polyMesh::write();
706 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
708 bool Foam::fvMesh::operator!=(const fvMesh& bm) const
714 bool Foam::fvMesh::operator==(const fvMesh& bm) const
720 // ************************************************************************* //