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/>.
28 Implementation of topoMapper
32 University of Massachusetts Amherst
35 \*----------------------------------------------------------------------------*/
37 #include "topoMapper.H"
38 #include "fluxCorrector.H"
39 #include "topoCellMapper.H"
40 #include "topoSurfaceMapper.H"
41 #include "topoBoundaryMeshMapper.H"
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 //- Store gradients prior to mesh reset
49 void topoMapper::storeGradients() const
51 // Go in order of highest to lowest rank,
52 // to avoid double storage
53 storeGradients<vector>(gradTable_, vGradPtrs_);
54 storeGradients<scalar>(gradTable_, sGradPtrs_);
58 Info<< "Registered gradients: " << gradientTable() << endl;
63 //- Store geometric information
64 void topoMapper::storeGeometry() const
66 typedef volVectorField::PatchFieldType PatchFieldType;
67 typedef volVectorField::GeometricBoundaryField GeomBdyFieldType;
68 typedef volVectorField::DimensionedInternalField DimInternalField;
70 // Wipe out existing information
71 deleteDemandDrivenData(cellCentresPtr_);
73 vectorField Cv(mesh_.cellCentres());
74 vectorField Cf(mesh_.faceCentres());
76 // Create and map the patch field values
77 label nPatches = mesh_.boundary().size();
80 PtrList<PatchFieldType> volCentrePatches(nPatches);
82 // Define patch type names
83 word emptyType("empty");
84 word fixedValueType("fixedValue");
86 // Create dummy types for initial field creation
87 forAll(volCentrePatches, patchI)
89 if (mesh_.boundary()[patchI].type() == emptyType)
97 mesh_.boundary()[patchI],
98 DimInternalField::null()
110 mesh_.boundary()[patchI],
111 DimInternalField::null()
117 // Set the cell-centres pointer.
125 mesh_.time().timeName(),
133 SubField<vector>(Cv, mesh_.nCells()),
138 // Alias for convenience
139 volVectorField& centres = *cellCentresPtr_;
141 // Set correct references for patch internal fields
142 GeomBdyFieldType& bf = centres.boundaryField();
146 if (mesh_.boundary()[patchI].type() == emptyType)
154 mesh_.boundary()[patchI],
155 centres.dimensionedInternalField()
167 mesh_.boundary()[patchI],
168 centres.dimensionedInternalField()
172 // Slice field to patch (forced assignment)
173 bf[patchI] == mesh_.boundaryMesh()[patchI].patchSlice(Cf);
177 // Set the cell-volumes pointer
178 cellVolumesPtr_ = new scalarField(mesh_.cellVolumes());
181 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
183 //- Construct from mesh and dictionary
184 topoMapper::topoMapper
187 const dictionary& dict
195 fluxCorrector_(fluxCorrector::New(mesh, dict)),
196 cellVolumesPtr_(NULL),
197 cellCentresPtr_(NULL)
201 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
203 topoMapper::~topoMapper()
208 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
210 //- Return reference to the mesh
211 const fvMesh& topoMapper::mesh() const
217 //- Return reference to objectRegistry storing fields.
218 const objectRegistry& topoMapper::thisDb() const
224 //- Set mapping information
225 void topoMapper::setMapper(const mapPolyMesh& mpm) const
230 surfaceMap_.valid() ||
236 "void topoMapper::setMapper() const"
237 ) << nl << " Mapper has already been set. "
238 << abort(FatalError);
242 cellMap_.set(new topoCellMapper(mpm, *this));
243 surfaceMap_.set(new topoSurfaceMapper(mpm, *this));
244 boundaryMap_.set(new topoBoundaryMeshMapper(mesh(), mpm, *this));
248 //- Set face weighting information
249 void topoMapper::setFaceWeights
251 const Xfer<List<scalarField> >& weights,
252 const Xfer<List<vectorField> >& centres
255 faceWeights_.transfer(weights());
256 faceCentres_.transfer(centres());
260 //- Set cell weighting information
261 void topoMapper::setCellWeights
263 const Xfer<List<scalarField> >& weights,
264 const Xfer<List<vectorField> >& centres
267 cellWeights_.transfer(weights());
268 cellCentres_.transfer(centres());
272 //- Set cell / patch offset information
273 void topoMapper::setOffsets
275 const labelList& cellSizes,
276 const labelList& cellStarts,
277 const labelList& faceSizes,
278 const labelList& faceStarts,
279 const labelListList& patchSizes,
280 const labelListList& patchStarts
283 cellSizes_ = cellSizes;
284 cellStarts_ = cellStarts;
285 faceSizes_ = faceSizes;
286 faceStarts_ = faceStarts;
287 patchSizes_ = patchSizes;
288 patchStarts_ = patchStarts;
292 //- Fetch face weights
293 const List<scalarField>& topoMapper::faceWeights() const
299 //- Fetch cell weights
300 const List<scalarField>& topoMapper::cellWeights() const
306 //- Fetch face centres
307 const List<vectorField>& topoMapper::faceCentres() const
313 //- Fetch cell centres
314 const List<vectorField>& topoMapper::cellCentres() const
321 const labelList& topoMapper::cellSizes() const
328 const labelList& topoMapper::faceSizes() const
334 //- Fetch patch sizes
335 const labelListList& topoMapper::patchSizes() const
341 //- Fetch cell starts
342 const labelList& topoMapper::cellStarts() const
348 //- Fetch face starts
349 const labelList& topoMapper::faceStarts() const
355 //- Fetch patch starts
356 const labelListList& topoMapper::patchStarts() const
362 //- Store mesh information for the mapping stage
363 void topoMapper::storeMeshInformation() const
365 // Store field-gradients
372 //- Return non-const access to cell centres
373 volVectorField& topoMapper::volCentres() const
375 if (!cellCentresPtr_)
379 "const vectorField& topoMapper::volCentres() const"
380 ) << nl << " Pointer has not been set. "
381 << abort(FatalError);
384 return *cellCentresPtr_;
388 //- Return stored cell centre information
389 const vectorField& topoMapper::internalCentres() const
391 if (!cellCentresPtr_)
395 "const vectorField& topoMapper::internalCentres() const"
396 ) << nl << " Pointer has not been set. "
397 << abort(FatalError);
400 return *cellCentresPtr_;
404 //- Return non-const access to cell volumes
405 scalarField& topoMapper::internalVolumes() const
407 if (!cellVolumesPtr_)
411 "scalarField& topoMapper::internalVolumes() const"
412 ) << nl << " Pointer has not been set. "
413 << abort(FatalError);
416 return *cellVolumesPtr_;
420 //- Return stored patch centre information
421 const vectorField& topoMapper::patchCentres(const label i) const
423 if (!cellCentresPtr_)
427 "const vectorField& topoMapper::patchCentres"
428 "(const label i) const"
429 ) << nl << " Pointer has not been set. index: " << i
430 << abort(FatalError);
433 return (*cellCentresPtr_).boundaryField()[i];
437 //- Return names of stored gradients
438 const wordList topoMapper::gradientTable() const
440 return gradTable_.toc();
444 //- Fetch the gradient field (template specialisation)
446 volVectorField& topoMapper::gradient(const word& name) const
448 if (!gradTable_.found(name))
452 "volVectorField& topoMapper::gradient(const word& name) const"
453 ) << nl << " Gradient for: " << name
454 << " has not been stored."
455 << abort(FatalError);
458 return sGradPtrs_[gradTable_[name].second()];
462 //- Fetch the gradient field (template specialisation)
464 volTensorField& topoMapper::gradient(const word& name) const
466 if (!gradTable_.found(name))
470 "volTensorField& topoMapper::gradient(const word& name) const"
471 ) << nl << " Gradient for: " << name
472 << " has not been stored."
473 << abort(FatalError);
476 return vGradPtrs_[gradTable_[name].second()];
480 //- Deregister gradient fields and centres,
481 // but retain for mapping
482 void topoMapper::deregisterMeshInformation() const
484 // Check out scalar gradients
485 forAll(sGradPtrs_, fieldI)
487 mesh_.objectRegistry::checkOut(sGradPtrs_[fieldI]);
490 // Check out vector gradients
491 forAll(vGradPtrs_, fieldI)
493 mesh_.objectRegistry::checkOut(vGradPtrs_[fieldI]);
496 // Check out cell centres
497 mesh_.objectRegistry::checkOut(*cellCentresPtr_);
501 //- Correct fluxes after topology changes, if required
502 void topoMapper::correctFluxes() const
504 if (surfaceFluxCorrector().required())
506 // Supply a list of inserted faces for interpolation
507 surfaceFluxCorrector().interpolateFluxes
509 surfaceMap().insertedObjectLabels()
513 surfaceFluxCorrector().updateFluxes();
518 //- Return volume mapper
519 const topoCellMapper& topoMapper::volMap() const
521 if (!cellMap_.valid())
525 "const topoCellMapper& topoMapper::volMap() const"
526 ) << nl << " Volume mapper has not been set. "
527 << abort(FatalError);
534 //- Return surface mapper
535 const topoSurfaceMapper& topoMapper::surfaceMap() const
537 if (!surfaceMap_.valid())
541 "const topoSurfaceMapper& topoMapper::surfaceMap() const"
542 ) << nl << " Surface mapper has not been set. "
543 << abort(FatalError);
546 return surfaceMap_();
550 //- Return boundary mapper
551 const topoBoundaryMeshMapper& topoMapper::boundaryMap() const
553 if (!boundaryMap_.valid())
557 "const topoBoundaryMeshMapper& topoMapper::boundaryMap() const"
558 ) << nl << " Boundary mapper has not been set. "
559 << abort(FatalError);
562 return boundaryMap_();
566 //- Return flux-corrector
567 const fluxCorrector& topoMapper::surfaceFluxCorrector() const
569 if (!fluxCorrector_.valid())
573 "const fluxCorrector& topoMapper::surfaceFluxCorrector() const"
574 ) << nl << " fluxCorrector has not been set. "
575 << abort(FatalError);
578 return fluxCorrector_();
582 //- Clear out member data
583 void topoMapper::clear() const
588 boundaryMap_.clear();
593 // Clear stored gradients
597 // Wipe out geomtry information
598 deleteDemandDrivenData(cellVolumesPtr_);
599 deleteDemandDrivenData(cellCentresPtr_);
602 faceWeights_.clear();
603 cellWeights_.clear();
605 faceCentres_.clear();
606 cellCentres_.clear();
608 // Clear sizes / offsets
616 patchStarts_.clear();
620 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
621 void topoMapper::operator=(const topoMapper& rhs)
623 // Check for assignment to self
628 "topoMapper::operator=(const topoMapper&)"
630 << "Attempted assignment to self"
631 << abort(FatalError);
635 } // End namespace Foam
637 // ************************************************************************* //