fvMeshToFvMeshTemplates.C
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-2026 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 \*---------------------------------------------------------------------------*/
25 
26 #include "fvMeshToFvMesh.H"
27 #include "setSizeFieldMapper.H"
28 #include "identityFieldMapper.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
35 void Foam::fvMeshToFvMesh::evaluateConstraintTypes(VolField<Type>& fld)
36 {
37  typename VolField<Type>::Boundary& fldBf = fld.boundaryFieldRef();
38 
39  if
40  (
43  )
44  {
45  label nReq = Pstream::nRequests();
46 
47  forAll(fldBf, patchi)
48  {
49  fvPatchField<Type>& tgtField = fldBf[patchi];
50 
51  if
52  (
53  tgtField.type() == tgtField.patch().poly().type()
54  && tgtField.patch().poly().constraint()
55  )
56  {
57  tgtField.initEvaluate(Pstream::defaultCommsType);
58  }
59  }
60 
61  // Block for any outstanding requests
62  if
63  (
66  )
67  {
69  }
70 
71  forAll(fldBf, patchi)
72  {
73  fvPatchField<Type>& tgtField = fldBf[patchi];
74 
75  if
76  (
77  tgtField.type() == tgtField.patch().poly().type()
78  && tgtField.patch().poly().constraint()
79  )
80  {
81  tgtField.evaluate(Pstream::defaultCommsType);
82  }
83  }
84  }
86  {
87  const lduSchedule& patchSchedule =
88  fld.mesh().globalData().patchSchedule();
89 
90  forAll(patchSchedule, patchEvali)
91  {
92  label patchi = patchSchedule[patchEvali].patch;
93  fvPatchField<Type>& tgtField = fldBf[patchi];
94 
95  if
96  (
97  tgtField.type() == tgtField.patch().poly().type()
98  && tgtField.patch().poly().constraint()
99  )
100  {
101  if (patchSchedule[patchEvali].init)
102  {
103  tgtField.initEvaluate(Pstream::commsTypes::scheduled);
104  }
105  else
106  {
107  tgtField.evaluate(Pstream::commsTypes::scheduled);
108  }
109  }
110  }
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
116 
117 template<class Type>
119 (
120  const VolField<Type>& srcFld
121 ) const
122 {
123  // Construct target patch fields as copies of source patch fields, but do
124  // not map values yet
125  PtrList<fvPatchField<Type>> tgtPatchFields(tgtMesh_.boundary().size());
126  forAll(patchIndices(), i)
127  {
128  const label srcPatchi = patchIndices()[i].first();
129  const label tgtPatchi = patchIndices()[i].second();
130 
131  if (!tgtPatchFields.set(tgtPatchi))
132  {
133  tgtPatchFields.set
134  (
135  tgtPatchi,
137  (
138  srcFld.boundaryField()[srcPatchi],
139  tgtMesh_.boundary()[tgtPatchi],
141  setSizeFieldMapper(tgtMesh_.boundary()[tgtPatchi].size())
142  )
143  );
144  }
145  }
146 
147  // Create calculated patch fields for any unset target patches. Use
148  // fvPatchField<Type>::New to construct these, rather than using the
149  // calculated constructor directly, so that constraints are maintained.
150  labelList tgtPatchFieldIsUnMapped(tgtPatchFields.size(), false);
151  forAll(tgtPatchFields, tgtPatchi)
152  {
153  if (!tgtPatchFields.set(tgtPatchi))
154  {
155  tgtPatchFields.set
156  (
157  tgtPatchi,
159  (
161  tgtMesh_.boundary()[tgtPatchi],
163  )
164  );
165 
166  tgtPatchFieldIsUnMapped[tgtPatchi] =
167  tgtMesh_.boundary()[tgtPatchi].poly().constraint();
168  }
169  }
170 
171  // Construct the result field
172  tmp<VolField<Type>> ttgtFld =
174  (
175  typedName("interpolate(" + srcFld.name() + ")"),
176  srcToTgt<Type>(srcFld.internalField())(),
177  tgtPatchFields
178  );
179  typename VolField<Type>::Boundary& tgtBfld =
180  ttgtFld.ref().boundaryFieldRef();
181 
182  // Mapped patches
183  forAll(patchIndices(), i)
184  {
185  const label srcPatchi = patchIndices()[i].first();
186  const label tgtPatchi = patchIndices()[i].second();
187 
188  tgtBfld[tgtPatchi].map
189  (
190  srcFld.boundaryField()[srcPatchi],
192  (
193  patchInterpolation(i),
194  tgtPatchStabilisation(i)
195  )
196  );
197  }
198 
199  // Un-mapped patches. Set values to that of the internal cell field.
200  forAll(tgtBfld, patchi)
201  {
202  if (tgtPatchFieldIsUnMapped[patchi])
203  {
204  fvPatchField<Type>& tgtPfld = tgtBfld[patchi];
205  tgtPfld == tgtPfld.patchInternalField();
206  }
207  }
208 
209  // Evaluate constraints
210  evaluateConstraintTypes(ttgtFld.ref());
211 
212  return ttgtFld;
213 }
214 
215 
216 template<class Type>
218 (
219  const VolField<Type>& srcFld,
220  const VolField<Type>& leftOverTgtFld,
221  const UList<wordRe>& tgtCuttingPatchNames
222 ) const
223 {
224  // Construct the result field
225  tmp<VolField<Type>> ttgtFld =
227  (
228  typedName("interpolate(" + srcFld.name() + ")"),
229  srcToTgt<Type>(srcFld.v(), leftOverTgtFld.v())(),
230  leftOverTgtFld.boundaryField()
231  );
232  typename VolField<Type>::Boundary& tgtBfld =
233  ttgtFld.ref().boundaryFieldRef();
234 
235  // Mapped patches
236  forAll(patchIndices(), i)
237  {
238  const label srcPatchi = patchIndices()[i].first();
239  const label tgtPatchi = patchIndices()[i].second();
240 
241  tgtBfld[tgtPatchi].map
242  (
243  leftOverTgtFld.boundaryField()[tgtPatchi],
245  );
246  tgtBfld[tgtPatchi].map
247  (
248  srcFld.boundaryField()[srcPatchi],
249  patchToPatchLeftOverFieldMapper(patchInterpolation(i))
250  );
251  }
252 
253  // Cutting patches. Set values to that of the internal cell field.
254  const labelHashSet tgtCuttingPatchIDs =
255  leftOverTgtFld.mesh().poly().boundary().patchSet(tgtCuttingPatchNames);
256  forAllConstIter(labelHashSet, tgtCuttingPatchIDs, iter)
257  {
258  tgtBfld[iter.key()] == tgtBfld[iter.key()].patchInternalField();
259  }
260 
261  // Evaluate constraints
262  evaluateConstraintTypes(ttgtFld.ref());
263 
264  return ttgtFld;
265 }
266 
267 
268 template<class Type>
270 (
271  const VolInternalField<Type>& srcFld
272 ) const
273 {
274  tmp<VolInternalField<Type>> ttgtFld =
276  (
277  typedName("interpolate(" + srcFld.name() + ")"),
278  tgtMesh_,
279  srcFld.dimensions(),
280  cellsInterpolation().srcToTgt(srcFld)
281  );
282 
283  tgtCellsStabilisation().stabilise(ttgtFld.ref());
284 
285  return ttgtFld;
286 }
287 
288 
289 template<class Type>
291 (
292  const VolInternalField<Type>& srcFld,
293  const VolInternalField<Type>& leftOverTgtFld
294 ) const
295 {
296  return
298  (
299  typedName("interpolate(" + srcFld.name() + ")"),
300  tgtMesh_,
301  leftOverTgtFld.dimensions(),
302  cellsInterpolation().srcToTgt(srcFld, leftOverTgtFld)
303  );
304 }
305 
306 
307 template<class Type>
310 (
311  const SurfaceFieldBoundary<Type>& srcBfld
312 ) const
313 {
314  // Map all patch fields
315  PtrList<fvsPatchField<Type>> tgtPatchFields(tgtMesh_.boundary().size());
316  forAll(patchIndices(), i)
317  {
318  const label srcPatchi = patchIndices()[i].first();
319  const label tgtPatchi = patchIndices()[i].second();
320 
321  if (!tgtPatchFields.set(tgtPatchi))
322  {
323  tgtPatchFields.set
324  (
325  tgtPatchi,
327  (
328  srcBfld[srcPatchi],
329  tgtMesh_.boundary()[tgtPatchi],
332  (
333  patchInterpolation(i),
334  tgtPatchStabilisation(i)
335  )
336  )
337  );
338  }
339  }
340 
341  // Create any patch fields not explicitly mapped; e.g., constraints
342  forAll(tgtPatchFields, tgtPatchi)
343  {
344  if (!tgtPatchFields.set(tgtPatchi))
345  {
346  tgtPatchFields.set
347  (
348  tgtPatchi,
350  (
352  tgtMesh_.boundary()[tgtPatchi],
354  )
355  );
356  }
357  }
358 
359  return
361  (
363  (
364  tgtMesh_.boundary(),
366  tgtPatchFields
367  )
368  );
369 }
370 
371 
372 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const GeoMesh & mesh() const
Return mesh.
Generic GeometricBoundaryField class.
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
GeometricBoundaryField< Type, GeoMesh, PrimitiveField > Boundary
Type of the boundary field.
const Internal & v() const
Return a const-reference to the dimensioned internal field.
Definition: volFieldsI.H:29
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
const word & name() const
Return name.
Definition: IOobject.H:307
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:137
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:147
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:272
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
tmp< VolField< Type > > srcToTgt(const VolField< Type > &srcFld) const
Interpolate a source vol field to the target with no left.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:90
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: fvPatchField.C:176
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:86
Identity field mapper.
Patch-to-patch fieldMapper which retains values in the target field for parts of the patch that do no...
Patch-to-patch fieldMapper which fills values for non-overlapping parts of the target patch by normal...
Mapper which sets the field size. It does not actually map values.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
label patchi
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
List< lduScheduleEntry > lduSchedule
Definition: lduSchedule.H:74
typename VolField< Type >::Internal VolInternalField
Definition: volFieldsFwd.H:59
word typedName(Name name)
Return the name of the object within the given type.
Definition: typeInfo.H:188
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)