MeshToMeshMapGeometricFields.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::MeshToMeshMapGeometricFields
26 
27 Description
28  Generic internal field mapper. For "real" mapping, add template
29  specialisations for mapping of internal fields depending on mesh
30  type.
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef MeshToMeshMapGeometricFields_H
35 #define MeshToMeshMapGeometricFields_H
36 
37 #include "polyMesh.H"
38 #include "meshToMesh.H"
39 #include "fvPatchFieldMapper.H"
40 #include "pointPatchFieldMapper.H"
41 #include "setSizeFieldMapper.H"
42 #include "processorPolyPatch.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 template<class Type>
51 {
53  Boundary& fldBf = fld.boundaryFieldRef();
54 
55  if
56  (
59  )
60  {
61  label nReq = Pstream::nRequests();
62 
63  forAll(fldBf, patchi)
64  {
65  fvPatchField<Type>& tgtField = fldBf[patchi];
66 
67  if
68  (
69  tgtField.type() == tgtField.patch().patch().type()
70  && polyPatch::constraintType(tgtField.patch().patch().type())
71  )
72  {
74  }
75  }
76 
77  // Block for any outstanding requests
78  if
79  (
82  )
83  {
85  }
86 
87  forAll(fldBf, patchi)
88  {
89  fvPatchField<Type>& tgtField = fldBf[patchi];
90 
91  if
92  (
93  tgtField.type() == tgtField.patch().patch().type()
94  && polyPatch::constraintType(tgtField.patch().patch().type())
95  )
96  {
98  }
99  }
100  }
102  {
103  const lduSchedule& patchSchedule =
104  fld.mesh().globalData().patchSchedule();
105 
106  forAll(patchSchedule, patchEvali)
107  {
108  label patchi = patchSchedule[patchEvali].patch;
109  fvPatchField<Type>& tgtField = fldBf[patchi];
110 
111  if
112  (
113  tgtField.type() == tgtField.patch().patch().type()
114  && polyPatch::constraintType(tgtField.patch().patch().type())
115  )
116  {
117  if (patchSchedule[patchEvali].init)
118  {
120  }
121  else
122  {
124  }
125  }
126  }
127  }
128 }
129 
130 
131 template<class Type>
133 (
134  const meshToMesh& mapper
135 )
136 {
138  (
139  mapper.srcRegion().objectRegistry::template
140  lookupClass<GeometricField<Type, fvPatchField, volMesh>>()
141  );
142 
143  // Deleted old time fields
144  for
145  (
147  iterator fieldIter = fields.begin();
148  fieldIter != fields.end();
149  ++fieldIter
150  )
151  {
154  (*fieldIter());
155 
156  field.clearOldTimes();
157  }
158 
159  fields =
160  (
161  mapper.srcRegion().objectRegistry::template
162  lookupClass<GeometricField<Type, fvPatchField, volMesh>>()
163  );
164 
165  for
166  (
168  iterator fieldIter = fields.begin();
169  fieldIter != fields.end();
170  ++fieldIter
171  )
172  {
175  (*fieldIter());
176 
177  if (meshToMesh::debug)
178  {
179  Info<< "Mapping " << field.typeName << ' ' << field.name()
180  << endl;
181  }
182 
183  field.reset(mapper.mapSrcToTgt(field));
185  field.instance() = field.time().timeName();
186  }
187 }
188 
189 
190 template
191 <
192  class Type,
193  template<class> class PatchField,
194  class GeoMesh,
195  class PatchMapper
196 >
198 (
199  const meshToMesh& mapper
200 )
201 {
203 
204  //- Mapper for sizing only - does not do any actual mapping.
205  class patchFieldResizeMapper
206  :
207  public PatchMapper,
208  public setSizeFieldMapper
209  {
210  public:
211 
212  // Constructors
213 
214  //- Construct given size
215  patchFieldResizeMapper(const label size)
216  :
217  setSizeFieldMapper(size)
218  {}
219  };
220 
222  (
223  mapper.srcRegion().objectRegistry::template lookupClass<Gfield>()
224  );
225 
226  // Deleted old time fields
227  for
228  (
229  typename HashTable<const Gfield*>::
230  iterator fieldIter = fields.begin();
231  fieldIter != fields.end();
232  ++fieldIter
233  )
234  {
235  Gfield& field = const_cast<Gfield&>(*fieldIter());
236  field.clearOldTimes();
237  }
238 
239  fields =
240  mapper.srcRegion().objectRegistry::template lookupClass<Gfield>();
241 
242  Type NaN;
243 
244  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
245  {
246  setComponent(NaN, cmpt) = std::numeric_limits<scalar>::signaling_NaN();
247  }
248 
249  for
250  (
251  typename HashTable<const Gfield*>::iterator fieldIter = fields.begin();
252  fieldIter != fields.end();
253  ++fieldIter
254  )
255  {
256  Gfield& field = const_cast<Gfield&>(*fieldIter());
257 
258  if (meshToMesh::debug)
259  {
260  Info<< "Setting to NaN " << field.typeName << ' ' << field.name()
261  << endl;
262  }
263 
264  const typename Gfield::Mesh& mesh = field.mesh();
265 
266  field.primitiveFieldRef().setSize(GeoMesh::size(mesh));
267  field.primitiveFieldRef() = NaN;
268 
269  field.boundaryFieldRef().setSize(mesh.boundary().size());
270 
271  forAll(mesh.boundary(), patchi)
272  {
273  if (isA<processorPolyPatch>(mesh().boundaryMesh()[patchi]))
274  {
275  field.boundaryFieldRef().set
276  (
277  patchi,
279  (
281  mesh.boundary()[patchi],
282  field
283  )
284  );
285  }
286  else
287  {
288  typename Gfield::Patch& pf = field.boundaryFieldRef()[patchi];
289  pf.autoMap(patchFieldResizeMapper(pf.patch().size()));
290  }
291 
292  field.boundaryFieldRef()[patchi] == NaN;
293  }
294 
295  field.instance() = field.time().timeName();
296  }
297 }
298 
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 } // End namespace Foam
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 #endif
307 
308 // ************************************************************************* //
Field sizing mapper which sets the field size and does not map values.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
Definition: IOobject.H:315
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
static const char *const typeName
Definition: Field.H:105
void clearOldTimes()
Delete old time and previous iteration fields.
const polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:30
void MeshToMeshMapVolFields(const meshToMesh &mapper)
uint8_t direction
Definition: direction.H:45
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: fvPatchField.H:444
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:137
Generic GeometricField class.
Class to calculate the cell-addressing between two overlapping meshes.
Definition: meshToMesh.H:60
void mapSrcToTgt(const UList< Type > &srcFld, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
fvMesh & mesh
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:265
An STL-conforming iterator.
Definition: HashTable.H:426
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void reset(const tmp< GeometricField< Type, PatchField, GeoMesh >> &)
Reset the field contents to the given field.
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:139
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
iterator begin()
Iterator set to the beginning of the HashTable.
Definition: HashTableI.H:411
An STL-conforming hash table.
Definition: HashTable.H:61
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:351
void NaNGeometricFields(const meshToMesh &mapper)
const Mesh & mesh() const
Return mesh.
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:147
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:223
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:272
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
Info<< "Reading field p_rgh\"<< endl;volScalarField p_rgh(IOobject("p_rgh", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);pressureReference pressureReference(p, p_rgh, pimple.dict(), thermo.incompressible());mesh.schemes().setFluxRequired(p_rgh.name());hydrostaticInitialisation(p_rgh, p, rho, U, gh, ghf, pRef, thermo, pimple.dict());Info<< "Creating field dpdt\"<< endl;volScalarField dpdt(IOobject("dpdt", runTime.timeName(), mesh), mesh, dimensionedScalar(p.dimensions()/dimTime, 0));Info<< "Creating field kinetic energy K\"<< endl;volScalarField K("K", 0.5 *magSqr(U));dimensionedScalar initialMass=fvc::domainIntegrate(rho);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:131
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const Time & time() const
Return time.
Definition: IOobject.C:318
messageStream Info
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Definition: IOobject.C:355
rDeltaTY field()
label & setComponent(label &l, const direction)
Definition: label.H:86
Namespace for OpenFOAM.