faMeshDistributorTemplates.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "Time.H"
29#include "emptyFaPatchField.H"
30#include "emptyFaePatchField.H"
31#include "IOobjectList.H"
32#include "polyMesh.H"
33#include "polyPatch.H"
34#include "processorFaPatch.H"
35#include "mapDistribute.H"
37#include "areaFields.H"
38#include "edgeFields.H"
39
42
43// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44
45template<class Type>
48(
50) const
51{
52 typedef typename
54 PatchFieldType;
55
56 if (tgtMesh_.boundary().size() && patchEdgeMaps_.empty())
57 {
58 createPatchMaps();
59 }
60
61 // Create internalField by remote mapping
62
63 const distributedFieldMapper mapper
64 (
66 distMap_.cellMap() // area: faceMap (volume: cellMap)
67 );
68
70 (
72 (
73 fld.name(),
74 tgtMesh_.time().timeName(),
75 fld.local(),
76 tgtMesh_.thisDb(),
79 ),
80 tgtMesh_,
81 fld.dimensions(),
82 Field<Type>(fld.internalField(), mapper)
83 );
84
85 internalField.oriented() = fld.oriented();
86
87
88 // Create patchFields by remote mapping
89
90 PtrList<PatchFieldType> newPatchFields(tgtMesh_.boundary().size());
91
92 const auto& bfld = fld.boundaryField();
93
94 forAll(bfld, patchi)
95 {
96 if (patchEdgeMaps_.set(patchi))
97 {
98 // Clone local patch field
99
101 (
103 patchEdgeMaps_[patchi]
104 );
105
106 // Map into local copy
107 newPatchFields.set
108 (
109 patchi,
110 PatchFieldType::New
111 (
112 bfld[patchi],
113 tgtMesh_.boundary()[patchi],
115 mapper
116 )
117 );
118 }
119 }
120
121 // Add empty patchFields on remaining patches (this also handles
122 // e.g. processorPatchFields or any other constraint type patches)
123 forAll(newPatchFields, patchi)
124 {
125 if (!newPatchFields.set(patchi))
126 {
127 newPatchFields.set
128 (
129 patchi,
130 PatchFieldType::New
131 (
133 tgtMesh_.boundary()[patchi],
135 )
136 );
137 }
138 }
139
140
142 (
143 std::move(internalField),
144 newPatchFields
145 );
146 auto& result = tresult.ref();
147
148 result.boundaryFieldRef().template evaluateCoupled<processorFaPatch>();
149
150 return tresult;
151}
152
153
154template<class Type>
157(
159) const
160{
161 typedef typename
163 PatchFieldType;
164
165 if (!internalEdgeMap_)
166 {
167 createInternalEdgeMap();
168 }
169
170
171 // Create internalField by remote mapping
172
173 const distributedFieldMapper mapper
174 (
176 *(internalEdgeMap_)
177 );
178
180 (
182 (
183 fld.name(),
184 tgtMesh_.time().timeName(),
185 fld.local(),
186 tgtMesh_.thisDb(),
189 ),
190 tgtMesh_,
191 fld.dimensions(),
192 Field<Type>(fld.internalField(), mapper)
193 );
194
195 internalField.oriented() = fld.oriented();
196
197
198 // Create patchFields by remote mapping
199
200 PtrList<PatchFieldType> newPatchFields(tgtMesh_.boundary().size());
201
202 const auto& bfld = fld.boundaryField();
203
204 forAll(bfld, patchi)
205 {
206 if (patchEdgeMaps_.set(patchi))
207 {
208 // Clone local patch field
209
211 (
213 patchEdgeMaps_[patchi]
214 );
215
216 // Map into local copy
217 newPatchFields.set
218 (
219 patchi,
220 PatchFieldType::New
221 (
222 bfld[patchi],
223 tgtMesh_.boundary()[patchi],
225 mapper
226 )
227 );
228 }
229 }
230
231 // Add empty patchFields on remaining patches (this also handles
232 // e.g. processorPatchFields or any other constraint type patches)
233 forAll(newPatchFields, patchi)
234 {
235 if (!newPatchFields.set(patchi))
236 {
237 newPatchFields.set
238 (
239 patchi,
240 PatchFieldType::New
241 (
243 tgtMesh_.boundary()[patchi],
245 )
246 );
247 }
248 }
249
250
252 (
253 std::move(internalField),
254 newPatchFields
255 );
256}
257
258
259template<class Type>
262(
263 const IOobject& fieldObject
264) const
265{
266 // Read field
268 (
269 fieldObject,
270 srcMesh_
271 );
272
273 // Redistribute
274 return distributeField(fld);
275}
276
277
278template<class Type>
281(
282 const IOobject& fieldObject
283) const
284{
285 // Read field
287 (
288 fieldObject,
289 srcMesh_
290 );
291
292 // Redistribute
293 return distributeField(fld);
294}
295
296
297template<class Type>
299(
300 const IOobjectList& objects,
301 const wordRes& selectedFields
302) const
303{
305
306 label nFields = 0;
307
308 for
309 (
310 const IOobject& io :
311 (
312 selectedFields.empty()
313 ? objects.sorted<fieldType>()
314 : objects.sorted<fieldType>(selectedFields)
315 )
316 )
317 {
318 if (verbose_)
319 {
320 if (!nFields)
321 {
322 Info<< " Reconstructing "
323 << fieldType::typeName << "s\n" << nl;
324 }
325 Info<< " " << io.name() << nl;
326 }
327 ++nFields;
328
329 tmp<fieldType> tfld(distributeAreaField<Type>(io));
330 if (isWriteProc_)
331 {
332 tfld().write();
333 }
334 }
335
336 if (nFields && verbose_) Info<< endl;
337 return nFields;
338}
339
340
341template<class Type>
343(
344 const IOobjectList& objects,
345 const wordRes& selectedFields
346) const
347{
349
350 label nFields = 0;
351
352 for
353 (
354 const IOobject& io :
355 (
356 selectedFields.empty()
357 ? objects.sorted<fieldType>()
358 : objects.sorted<fieldType>(selectedFields)
359 )
360 )
361 {
362 if (verbose_)
363 {
364 if (!nFields)
365 {
366 Info<< " Reconstructing "
367 << fieldType::typeName << "s\n" << nl;
368 }
369 Info<< " " << io.name() << nl;
370 }
371 ++nFields;
372
373 tmp<fieldType> tfld(distributeEdgeField<Type>(io));
374 if (isWriteProc_)
375 {
376 tfld().write();
377 }
378 }
379
380 if (nFields && verbose_) Info<< endl;
381 return nFields;
382}
383
384
385
386#if 0
387template<class Type>
388void Foam::faMeshDistributor::redistributeAndWrite
389(
391) const
392{
393 for (auto& fld : flds)
394 {
395 Pout<< "process: " << fld.name() << endl;
396
398 this->distributeField(fld);
399
400 if (isWriteProc_)
401 {
402 tfld().write();
403 }
404 }
405}
406
407
408template<class Type>
409void Foam::faMeshDistributor::redistributeAndWrite
410(
411 PtrList<GeometricField<Type, faePatchField, edgeMesh>>& flds
412) const
413{
414 for (auto& fld : flds)
415 {
416 tmp<GeometricField<Type, faePatchField, edgeMesh>> tfld =
417 this->distributeField(fld);
418
419 if (isWriteProc_)
420 {
421 tfld().write();
422 }
423 }
424}
425#endif
426
427
428// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const orientedType & oriented() const noexcept
Return oriented type.
A templated field mapper with direct mapping from local or remote quantities.
Generic templated field type.
Definition: Field.H:82
Generic GeometricField class.
PatchField< Type > Patch
The patch field type for the GeometricBoundaryField.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
UPtrList< const IOobject > sorted() const
The sorted list of IOobjects.
Definition: IOobjectList.C:336
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
const T * set(const label i) const
Definition: PtrList.H:138
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
tmp< GeometricField< Type, faPatchField, areaMesh > > distributeAreaField(const IOobject &fieldObject) const
Read and distribute area field.
tmp< GeometricField< Type, faPatchField, areaMesh > > distributeField(const GeometricField< Type, faPatchField, areaMesh > &fld) const
Distribute area field.
tmp< GeometricField< Type, faePatchField, edgeMesh > > distributeEdgeField(const IOobject &fieldObject) const
Read and distribute edge field.
label distributeEdgeFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected area fields.
label distributeAreaFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected area fields.
const Time & time() const
Return reference to time.
Definition: faMesh.C:673
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
Definition: faMeshI.H:38
virtual const objectRegistry & thisDb() const
Return reference to the mesh database.
Definition: faMesh.C:697
const mapDistribute & cellMap() const noexcept
Cell distribute map.
A class for managing temporary objects.
Definition: tmp.H:65
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333