parPointFieldDistributorTemplates.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"
30#include "IOobjectList.H"
34#include "pointFields.H"
35
36// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37
38template<class Type>
41(
42 const GeometricField<Type, pointPatchField, pointMesh>& fld
43) const
44{
45 if (!tgtMeshRef_ || !distMapRef_)
46 {
48 << "Cannot map field without target mesh and/or distribution!"
49 << abort(FatalError);
50 }
51 if (!hasPatchPointMaps())
52 {
53 const_cast<parPointFieldDistributor&>(*this).createPatchPointMaps();
54 }
55
56 const auto& tgtMesh = tgtMeshRef_();
57 const auto& distMap = distMapRef_();
58
59 // Create internalField by remote mapping
61 (
63 distMap.pointMap()
64 );
65
66 DimensionedField<Type, pointMesh> internalField
67 (
68 IOobject
69 (
70 fld.name(),
71 tgtMesh.time().timeName(),
72 fld.local(),
73 tgtMesh.thisDb(),
76 ),
77 tgtMesh,
78 fld.dimensions(),
79 Field<Type>(fld.internalField(), mapper)
80 );
81
82 internalField.oriented() = fld.oriented();
83
84
85 // Create patchFields by remote mapping
86
87 PtrList<pointPatchField<Type>> newPatchFields(tgtMesh.boundary().size());
88
89 const auto& bfld = fld.boundaryField();
90
91 forAll(bfld, patchi)
92 {
93 if (patchPointMaps_.set(patchi))
94 {
95 // Clone local patch field
96
98 (
100 patchPointMaps_[patchi]
101 );
102
103 // Map into local copy
104 newPatchFields.set
105 (
106 patchi,
108 (
109 bfld[patchi],
110 tgtMesh.boundary()[patchi], // pointPatch
111 DimensionedField<Type, pointMesh>::null(),
112 mapper
113 )
114 );
115
116 // Note: below alternative, 'clone' method will not work since
117 // there is no clone to reset both internalField reference and
118 // patch reference. TBD.
119 //newPatchFields.set
120 //(
121 // patchi,
122 // bfld[patchi].clone
123 // (
124 // tgtMesh.boundary()[patchi],
125 // DimensionedField<Type, pointMesh>::null(),
126 // mapper
127 // )
128 //);
129 }
130 }
131
132 // Add some empty patchFields on remaining patches (this also handles
133 // e.g. processorPatchFields or any other constraint type patches)
134 forAll(newPatchFields, patchi)
135 {
136 if (!newPatchFields.set(patchi))
137 {
138 newPatchFields.set
139 (
140 patchi,
142 (
144 tgtMesh.boundary()[patchi],
145 DimensionedField<Type, pointMesh>::null()
146 )
147 );
148 }
149 }
150
151 return
152 tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
153 (
154 std::move(internalField),
155 newPatchFields
156 );
157}
158
159
160template<class Type>
163(
164 const IOobject& fieldObject
165) const
166{
167 // Read field
168 GeometricField<Type, pointPatchField, pointMesh> fld
169 (
170 fieldObject,
171 srcMesh_
172 );
173
174 // Redistribute
175 return distributeField(fld);
176}
177
178
179template<class Type>
181(
182 const IOobjectList& objects,
183 const wordRes& selectedFields
184) const
185{
186 typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
187
188 UPtrList<const IOobject> fieldObjects
189 (
190 selectedFields.empty()
191 ? objects.sorted<fieldType>()
192 : objects.sorted<fieldType>(selectedFields)
193 );
194
195 label nFields = 0;
196 for (const IOobject& io : fieldObjects)
197 {
198 if (verbose_)
199 {
200 if (!nFields)
201 {
202 Info<< " Reconstructing "
203 << fieldType::typeName << "s\n" << nl;
204 }
205 Info<< " " << io.name() << nl;
206 }
207 ++nFields;
208
209 tmp<fieldType> tfld(distributePointField<Type>(io));
210 if (isWriteProc_)
211 {
212 tfld().write();
213 }
214 }
215
216 if (nFields && verbose_) Info<< endl;
217 return nFields;
218}
219
220
221template<class Type>
223(
224 const PtrList<GeometricField<Type, pointPatchField, pointMesh>>& fields
225) const
226{
227 for (const auto& fld : fields)
228 {
229 // Distribute and store
230 auto tfld = distributeField(fld);
231
232 tfld.ref().writeOpt(IOobject::AUTO_WRITE);
233
234 tfld().mesh().thisDb().store(tfld);
235 }
236}
237
238
239// ************************************************************************* //
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))
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static const UList< label > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:53
bool hasPatchPointMaps() const
True if patch maps (per boundary) exist.
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributePointField(const IOobject &fieldObject) const
Read and distribute point field.
void distributeAndStore(const PtrList< GeometricField< Type, pointPatchField, pointMesh > > &) const
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributeField(const GeometricField< Type, pointPatchField, pointMesh > &fld) const
Distribute point field.
label distributePointFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point fields.
A class for managing temporary objects.
Definition: tmp.H:65
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
DistributedFieldMapper< directFieldMapper > distributedFieldMapper
A directFieldMapper with distributed (with local or remote) quantities.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
error FatalError
DistributedFieldMapper< directPointPatchFieldMapper > distributedPointPatchFieldMapper
A directPointPatchFieldMapper with direct mapping from local or remote quantities.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
static const char *const typeName
The type name used in ensight case files.