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
29 Implementation of topoMapper
33 University of Massachusetts Amherst
36 \*----------------------------------------------------------------------------*/
38 #include "topoMapper.H"
39 #include "fluxCorrector.H"
40 #include "topoCellMapper.H"
41 #include "topoSurfaceMapper.H"
42 #include "topoBoundaryMeshMapper.H"
43 #include "fixedValueFvPatchFields.H"
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 //- Store gradients prior to mesh reset
51 void topoMapper::storeGradients() const
53 storeGradients<scalar>(sGrads_);
54 storeGradients<vector>(vGrads_);
58 Info<< "Registered volScalarFields: " << scalarGrads() << endl;
59 Info<< "Registered volVectorFields: " << vectorGrads() << endl;
64 //- Store geometric information
65 void topoMapper::storeGeometry() const
67 // Wipe out existing information
68 deleteDemandDrivenData(cellCentresPtr_);
70 vectorField Cv(mesh_.cellCentres());
71 vectorField Cf(mesh_.faceCentres());
73 // Create and map the patch field values
74 label nPatches = mesh_.boundary().size();
77 PtrList<fvPatchField<vector> > volCentrePatches(nPatches);
79 // Over-ride and set all patches to fixedValue
80 for (label patchI = 0; patchI < nPatches; patchI++)
85 new fixedValueFvPatchField<vector>
87 mesh_.boundary()[patchI],
88 DimensionedField<vector, volMesh>::null()
92 // Slice field to patch (forced assignment)
93 volCentrePatches[patchI] ==
95 mesh_.boundaryMesh()[patchI].patchSlice(Cf)
99 // Set the cell-centres pointer.
107 mesh_.time().timeName(),
115 SubField<vector>(Cv, mesh_.nCells()),
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 //- Construct from mesh and dictionary
124 topoMapper::topoMapper
127 const dictionary& dict
135 fluxCorrector_(fluxCorrector::New(mesh, dict)),
136 cellCentresPtr_(NULL)
140 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
142 topoMapper::~topoMapper()
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 //- Return reference to the mesh
150 const fvMesh& topoMapper::mesh() const
156 //- Return reference to objectRegistry storing fields.
157 const objectRegistry& topoMapper::thisDb() const
163 //- Set mapping information
164 void topoMapper::setMapper(const mapPolyMesh& mpm) const
169 surfaceMap_.valid() ||
175 "void topoMapper::setMapper() const"
176 ) << nl << " Mapper has already been set. "
177 << abort(FatalError);
181 cellMap_.set(new topoCellMapper(mpm, *this));
182 surfaceMap_.set(new topoSurfaceMapper(mpm, *this));
183 boundaryMap_.set(new topoBoundaryMeshMapper(mesh(), mpm, *this));
187 //- Set face weighting information
188 void topoMapper::setFaceWeights
190 const Xfer<List<scalarField> >& weights,
191 const Xfer<List<vectorField> >& centres
194 faceWeights_.transfer(weights());
195 faceCentres_.transfer(centres());
199 //- Set cell weighting information
200 void topoMapper::setCellWeights
202 const Xfer<List<scalarField> >& weights,
203 const Xfer<List<vectorField> >& centres
206 cellWeights_.transfer(weights());
207 cellCentres_.transfer(centres());
211 //- Set cell / patch offset information
212 void topoMapper::setOffsets
214 const labelList& cellSizes,
215 const labelList& cellStarts,
216 const labelList& faceSizes,
217 const labelList& faceStarts,
218 const labelListList& patchSizes,
219 const labelListList& patchStarts
222 cellSizes_ = cellSizes;
223 cellStarts_ = cellStarts;
224 faceSizes_ = faceSizes;
225 faceStarts_ = faceStarts;
226 patchSizes_ = patchSizes;
227 patchStarts_ = patchStarts;
231 //- Fetch face weights
232 const List<scalarField>& topoMapper::faceWeights() const
238 //- Fetch cell weights
239 const List<scalarField>& topoMapper::cellWeights() const
245 //- Fetch face centres
246 const List<vectorField>& topoMapper::faceCentres() const
252 //- Fetch cell centres
253 const List<vectorField>& topoMapper::cellCentres() const
260 const labelList& topoMapper::cellSizes() const
267 const labelList& topoMapper::faceSizes() const
273 //- Fetch patch sizes
274 const labelListList& topoMapper::patchSizes() const
280 //- Fetch cell starts
281 const labelList& topoMapper::cellStarts() const
287 //- Fetch face starts
288 const labelList& topoMapper::faceStarts() const
294 //- Fetch patch starts
295 const labelListList& topoMapper::patchStarts() const
301 //- Store mesh information for the mapping stage
302 void topoMapper::storeMeshInformation() const
304 // Store field-gradients
311 //- Return non-const access to cell centres
312 volVectorField& topoMapper::volCentres() const
314 if (!cellCentresPtr_)
318 "const vectorField& topoMapper::volCentres() const"
319 ) << nl << " Pointer has not been set. "
320 << abort(FatalError);
323 return *cellCentresPtr_;
327 //- Return stored cell centre information
328 const vectorField& topoMapper::internalCentres() const
330 if (!cellCentresPtr_)
334 "const vectorField& topoMapper::internalCentres() const"
335 ) << nl << " Pointer has not been set. "
336 << abort(FatalError);
339 return *cellCentresPtr_;
343 //- Return stored patch centre information
344 const vectorField& topoMapper::patchCentres(const label i) const
346 if (!cellCentresPtr_)
350 "const vectorField& topoMapper::patchCentres"
351 "(const label i) const"
352 ) << nl << " Pointer has not been set. index: " << i
353 << abort(FatalError);
356 return (*cellCentresPtr_).boundaryField()[i];
360 //- Return names of stored scalar gradients
361 const wordList topoMapper::scalarGrads() const
363 return sGrads_.toc();
367 //- Return names of stored vector gradients
368 const wordList topoMapper::vectorGrads() const
370 return vGrads_.toc();
374 //- Fetch the gradient field (template specialisation)
376 volVectorField& topoMapper::gradient(const word& name) const
378 if (!sGrads_.found(name))
382 "volVectorField& topoMapper::gradient(const word& name) const"
383 ) << nl << " Gradient for: " << name
384 << " has not been stored."
385 << abort(FatalError);
388 return sGrads_[name]();
392 //- Fetch the gradient field (template specialisation)
394 volTensorField& topoMapper::gradient(const word& name) const
396 if (!vGrads_.found(name))
400 "volTensorField& topoMapper::gradient(const word& name) const"
401 ) << nl << " Gradient for: " << name
402 << " has not been stored."
403 << abort(FatalError);
406 return vGrads_[name]();
410 //- Correct fluxes after topology changes, if required
411 void topoMapper::correctFluxes() const
413 if (surfaceFluxCorrector().required())
415 // Supply a list of inserted faces for interpolation
416 surfaceFluxCorrector().interpolateFluxes
418 surfaceMap().insertedObjectLabels()
422 surfaceFluxCorrector().updateFluxes();
427 //- Return volume mapper
428 const topoCellMapper& topoMapper::volMap() const
430 if (!cellMap_.valid())
434 "const topoCellMapper& topoMapper::volMap() const"
435 ) << nl << " Volume mapper has not been set. "
436 << abort(FatalError);
443 //- Return surface mapper
444 const topoSurfaceMapper& topoMapper::surfaceMap() const
446 if (!surfaceMap_.valid())
450 "const topoSurfaceMapper& topoMapper::surfaceMap() const"
451 ) << nl << " Surface mapper has not been set. "
452 << abort(FatalError);
455 return surfaceMap_();
459 //- Return boundary mapper
460 const topoBoundaryMeshMapper& topoMapper::boundaryMap() const
462 if (!boundaryMap_.valid())
466 "const topoBoundaryMeshMapper& topoMapper::boundaryMap() const"
467 ) << nl << " Boundary mapper has not been set. "
468 << abort(FatalError);
471 return boundaryMap_();
475 //- Return flux-corrector
476 const fluxCorrector& topoMapper::surfaceFluxCorrector() const
478 if (!fluxCorrector_.valid())
482 "const fluxCorrector& topoMapper::surfaceFluxCorrector() const"
483 ) << nl << " fluxCorrector has not been set. "
484 << abort(FatalError);
487 return fluxCorrector_();
491 //- Clear out member data
492 void topoMapper::clear() const
497 boundaryMap_.clear();
499 // Clear stored gradients
503 // Wipe out geomtry information
504 deleteDemandDrivenData(cellCentresPtr_);
507 faceWeights_.clear();
508 cellWeights_.clear();
510 faceCentres_.clear();
511 cellCentres_.clear();
513 // Clear sizes / offsets
521 patchStarts_.clear();
525 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
526 void topoMapper::operator=(const topoMapper& rhs)
528 // Check for assignment to self
533 "topoMapper::operator=(const topoMapper&)"
535 << "Attempted assignment to self"
536 << abort(FatalError);
540 } // End namespace Foam
542 // ************************************************************************* //