mapFieldsTemplates.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) 2016-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 "fvMesh.H"
29#include "polyPatch.H"
30#include "lduSchedule.H"
31#include "meshToMesh.H"
32
33template<class Type>
34void Foam::functionObjects::mapFields::evaluateConstraintTypes
35(
36 GeometricField<Type, fvPatchField, volMesh>& fld
37) const
38{
39 auto& fldBf = fld.boundaryFieldRef();
40
42
43 if
44 (
47 )
48 {
49 const label startOfRequests = UPstream::nRequests();
50
51 forAll(fldBf, patchi)
52 {
53 fvPatchField<Type>& tgtField = fldBf[patchi];
54
55 if
56 (
57 tgtField.type() == tgtField.patch().patch().type()
58 && polyPatch::constraintType(tgtField.patch().patch().type())
59 )
60 {
61 tgtField.initEvaluate(commsType);
62 }
63 }
64
65 // Wait for outstanding requests
66 if
67 (
70 )
71 {
72 UPstream::waitRequests(startOfRequests);
73 }
74
75 forAll(fldBf, patchi)
76 {
77 fvPatchField<Type>& tgtField = fldBf[patchi];
78
79 if
80 (
81 tgtField.type() == tgtField.patch().patch().type()
82 && polyPatch::constraintType(tgtField.patch().patch().type())
83 )
84 {
85 tgtField.evaluate(commsType);
86 }
87 }
88 }
89 else if (commsType == UPstream::commsTypes::scheduled)
90 {
91 const lduSchedule& patchSchedule =
92 fld.mesh().globalData().patchSchedule();
93
94 for (const auto& schedEval : patchSchedule)
95 {
96 const label patchi = schedEval.patch;
97
98 fvPatchField<Type>& tgtField = fldBf[patchi];
99
100 if
101 (
102 tgtField.type() == tgtField.patch().patch().type()
103 && polyPatch::constraintType(tgtField.patch().patch().type())
104 )
105 {
106 if (schedEval.init)
107 {
108 tgtField.initEvaluate(commsType);
109 }
110 else
111 {
112 tgtField.evaluate(commsType);
113 }
114 }
115 }
116 }
117}
118
119
120template<class Type>
121bool Foam::functionObjects::mapFields::mapFieldType() const
122{
123 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
124
125 const fvMesh& mapRegion = mapRegionPtr_();
126
127 wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
128
129 const labelList selected(fieldNames_.matching(fieldNames));
130
131 for (const label fieldi : selected)
132 {
133 const word& fieldName = fieldNames[fieldi];
134
135 const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
136
137 if (!mapRegion.foundObject<VolFieldType>(fieldName))
138 {
139 VolFieldType* tmappedField =
140 new VolFieldType
141 (
142 IOobject
143 (
144 fieldName,
145 time_.timeName(),
146 mapRegion,
149 ),
150 mapRegion,
151 dimensioned<Type>(field.dimensions(), Zero)
152 );
153
154 tmappedField->store();
155 }
156
157 VolFieldType& mappedField =
158 mapRegion.template lookupObjectRef<VolFieldType>(fieldName);
159
160 mappedField = interpPtr_->mapTgtToSrc(field);
161
162 Log << " " << fieldName << ": interpolated";
163
164 evaluateConstraintTypes(mappedField);
165 }
166
167 return !selected.empty();
168}
169
170
171template<class Type>
172bool Foam::functionObjects::mapFields::writeFieldType() const
173{
174 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
175
176 const fvMesh& mapRegion = mapRegionPtr_();
177
178 wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
179
180 const labelList selected(fieldNames_.matching(fieldNames));
181
182 for (const label fieldi : selected)
183 {
184 const word& fieldName = fieldNames[fieldi];
185
186 const VolFieldType& mappedField =
187 mapRegion.template lookupObject<VolFieldType>(fieldName);
188
189 mappedField.write();
190
191 Log << " " << fieldName << ": written";
192 }
193
194 return !selected.empty();
195}
196
197
198// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
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))
commsTypes
Types of communications.
Definition: UPstream.H:67
@ nonBlocking
"nonBlocking"
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:90
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:100
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:281
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
virtual const word & constraintType() const
Return the constraint type this pointPatch implements.
rDeltaTY field()
List< word > wordList
A List of words.
Definition: fileName.H:63
List< label > labelList
A List of labels.
Definition: List.H:66
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition: lduSchedule.H:50
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:42
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333