1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
48 defineTypeNameAndDebug(fvMesh, 0);
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 void fvMesh::clearGeomNotOldVol()
54 slicedVolScalarField::DimensionedInternalField* VPtr =
55 static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
56 deleteDemandDrivenData(VPtr);
59 deleteDemandDrivenData(SfPtr_);
60 deleteDemandDrivenData(magSfPtr_);
61 deleteDemandDrivenData(CPtr_);
62 deleteDemandDrivenData(CfPtr_);
66 void fvMesh::clearGeom()
70 deleteDemandDrivenData(V0Ptr_);
71 deleteDemandDrivenData(V00Ptr_);
73 // Mesh motion flux cannot be deleted here because the old-time flux
78 void fvMesh::clearAddressing()
80 deleteDemandDrivenData(lduPtr_);
84 void fvMesh::clearOut()
87 surfaceInterpolation::clearOut();
91 // Clear mesh motion flux
92 deleteDemandDrivenData(phiPtr_);
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 fvMesh::fvMesh(const IOobject& io)
103 surfaceInterpolation(*this),
104 boundary_(*this, boundaryMesh()),
106 curTimeIndex_(time().timeIndex()),
118 Info<< "Constructing fvMesh from IOobject"
122 // Check the existance of the cell volumes and read if present
123 // and set the storage of V00
124 if (file(time().timePath()/"V0"))
126 V0Ptr_ = new DimensionedField<scalar, volMesh>
142 // Check the existance of the mesh fluxes, read if present and set the
144 if (file(time().timePath()/"meshPhi"))
146 phiPtr_ = new surfaceScalarField
159 // The mesh is now considered moving so the old-time cell volumes
160 // will be required for the time derivatives so if they haven't been
161 // read initialise to the current cell volumes
164 V0Ptr_ = new DimensionedField<scalar, volMesh>
187 const pointField& points,
188 const faceList& faces,
189 const labelList& allOwner,
190 const labelList& allNeighbour,
194 polyMesh(io, points, faces, allOwner, allNeighbour, syncPar),
195 surfaceInterpolation(*this),
198 curTimeIndex_(time().timeIndex()),
210 Info<< "Constructing fvMesh from components"
219 const pointField& points,
220 const faceList& faces,
221 const cellList& cells,
225 polyMesh(io, points, faces, cells, syncPar),
226 surfaceInterpolation(*this),
229 curTimeIndex_(time().timeIndex()),
241 Info<< "Constructing fvMesh from components"
247 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
255 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
257 // Helper function for construction from pieces
258 void fvMesh::addFvPatches(const List<polyPatch*> & p, const bool validBoundary)
260 if (boundary().size() > 0)
264 "fvMesh::addFvPatches(const List<polyPatch*>&, const bool)"
265 ) << " boundary already exists"
266 << abort(FatalError);
269 // first add polyPatches
270 addPatches(p, validBoundary);
271 boundary_.addPatches(boundaryMesh());
275 void fvMesh::removeFvBoundary()
279 Info<< "void fvMesh::removeFvBoundary(): "
280 << "Removing boundary patches."
284 // Remove fvBoundaryMesh data first.
286 boundary_.setSize(0);
287 polyMesh::removeBoundary();
293 polyMesh::readUpdateState fvMesh::readUpdate()
297 Info<< "polyMesh::readUpdateState fvMesh::readUpdate() : "
298 << "Updating fvMesh. ";
301 polyMesh::readUpdateState state = polyMesh::readUpdate();
303 if (state == polyMesh::TOPO_PATCH_CHANGE)
307 Info << "Boundary and topological update" << endl;
310 boundary_.readUpdate(boundaryMesh());
315 else if (state == polyMesh::TOPO_CHANGE)
319 Info << "Topological update" << endl;
324 else if (state == polyMesh::POINTS_MOVED)
328 Info << "Point motion update" << endl;
337 Info << "No update" << endl;
345 const fvBoundaryMesh& fvMesh::boundary() const
351 const lduAddressing& fvMesh::lduAddr() const
355 lduPtr_ = new fvMeshLduAddressing(*this);
362 void fvMesh::mapFields(const mapPolyMesh& meshMap)
365 const fvMeshMapper mapper(*this, meshMap);
367 // Map all the volFields in the objectRegistry
368 MapGeometricFields<scalar, fvPatchField, fvMeshMapper, volMesh>
370 MapGeometricFields<vector, fvPatchField, fvMeshMapper, volMesh>
372 MapGeometricFields<sphericalTensor, fvPatchField, fvMeshMapper, volMesh>
374 MapGeometricFields<symmTensor, fvPatchField, fvMeshMapper, volMesh>
376 MapGeometricFields<tensor, fvPatchField, fvMeshMapper, volMesh>
379 // Map all the surfaceFields in the objectRegistry
380 MapGeometricFields<scalar, fvsPatchField, fvMeshMapper, surfaceMesh>
382 MapGeometricFields<vector, fvsPatchField, fvMeshMapper, surfaceMesh>
384 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
386 MapGeometricFields<symmTensor, fvsPatchField, fvMeshMapper, surfaceMesh>
388 MapGeometricFields<tensor, fvsPatchField, fvMeshMapper, surfaceMesh>
391 // Map all the clouds in the objectRegistry
392 mapClouds(*this, meshMap);
395 const labelList& cellMap = meshMap.cellMap();
397 // Map the old volume. Just map to new cell labels.
400 scalarField& V0 = *V0Ptr_;
402 scalarField savedV0(V0);
403 V0.setSize(nCells());
409 V0[i] = savedV0[cellMap[i]];
418 // Map the old-old volume. Just map to new cell labels.
421 scalarField& V00 = *V00Ptr_;
423 scalarField savedV00(V00);
424 V00.setSize(nCells());
430 V00[i] = savedV00[cellMap[i]];
441 tmp<scalarField> fvMesh::movePoints(const pointField& p)
443 // Grab old time volumes if the time has been incremented
444 if (curTimeIndex_ < time().timeIndex())
446 if (V00Ptr_ && V0Ptr_)
457 V0Ptr_ = new DimensionedField<scalar, volMesh>
471 curTimeIndex_ = time().timeIndex();
475 // delete out of date geometrical information
476 clearGeomNotOldVol();
481 // Create mesh motion flux
482 phiPtr_ = new surfaceScalarField
487 this->time().timeName(),
498 // Grab old time mesh motion fluxes if the time has been incremented
499 if (phiPtr_->timeIndex() != time().timeIndex())
505 surfaceScalarField& phi = *phiPtr_;
507 // Move the polyMesh and set the mesh motion fluxes to the swept-volumes
509 scalar rDeltaT = 1.0/time().deltaT().value();
511 tmp<scalarField> tsweptVols = polyMesh::movePoints(p);
512 scalarField& sweptVols = tsweptVols();
514 phi.internalField() = scalarField::subField(sweptVols, nInternalFaces());
515 phi.internalField() *= rDeltaT;
517 const fvPatchList& patches = boundary();
519 forAll (patches, patchI)
521 phi.boundaryField()[patchI] = patches[patchI].patchSlice(sweptVols);
522 phi.boundaryField()[patchI] *= rDeltaT;
525 boundary_.movePoints();
526 surfaceInterpolation::movePoints();
532 void fvMesh::updateMesh(const mapPolyMesh& mpm)
534 // Update polyMesh. This needs to keep volume existent!
535 polyMesh::updateMesh(mpm);
537 // Clear the sliced fields
538 clearGeomNotOldVol();
540 // Map all fields using current (i.e. not yet mapped) volume
543 // Clear the current volume and other geometry factors
544 surfaceInterpolation::clearOut();
548 // handleMorph() should also clear out the surfaceInterpolation.
549 // This is a temporary solution
550 surfaceInterpolation::movePoints();
554 bool fvMesh::writeObjects
556 IOstream::streamFormat fmt,
557 IOstream::versionNumber ver,
558 IOstream::compressionType cmp
561 return polyMesh::writeObject(fmt, ver, cmp);
565 //- Write mesh using IO settings from the time
566 bool fvMesh::write() const
568 return polyMesh::write();
572 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
574 bool fvMesh::operator!=(const fvMesh& bm) const
580 bool fvMesh::operator==(const fvMesh& bm) const
586 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
588 } // End namespace Foam
590 // ************************************************************************* //