mappedPatchBaseTemplates.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29template<class Type>
31{
32 const label myComm = getCommunicator(); // Get or create
33 const label oldWarnComm(Pstream::warnComm);
34 Pstream::warnComm = myComm;
35
36 switch (mode_)
37 {
39 {
40 const label oldWorldComm(Pstream::worldComm);
41 Pstream::worldComm = myComm;
42
43 if (sameWorld())
44 {
45 // lst is the other side's values
46 lst = AMI().interpolateToSource(Field<Type>(std::move(lst)));
47 }
48 else
49 {
50 // lst is my local data. Now the mapping in the AMI is
51 // from my side to other side. Each processor contains either
52 // faces from one side or from the other side.
53
54 if (masterWorld())
55 {
56 // I have lst.size() faces on my side, zero of the other
57 // side
58
59 tmp<Field<Type>> tmasterFld
60 (
61 AMI().interpolateToSource(Field<Type>(0))
62 );
64 (
65 Field<Type>(std::move(lst))
66 );
67
68 // We've received in our interpolateToSource the
69 // contribution from the other side
70 lst = tmasterFld;
71 }
72 else
73 {
75 (
76 Field<Type>(std::move(lst))
77 );
78 tmp<Field<Type>> tmasterFld
79 (
80 AMI().interpolateToTarget(Field<Type>(0))
81 );
82
83 // We've received in our interpolateToTarget the
84 // contribution from the other side
85 lst = tmasterFld;
86 }
87 }
88 Pstream::worldComm = oldWorldComm;
89 break;
90 }
91 default:
92 {
93 map().distribute(lst);
94 }
95 }
96
97 Pstream::warnComm = oldWarnComm;
98}
99
100
101template<class Type, class CombineOp>
103(
104 List<Type>& lst,
105 const CombineOp& cop
106) const
107{
108 const label myComm = getCommunicator(); // Get or create
109 const label oldWarnComm(Pstream::warnComm);
110 Pstream::warnComm = myComm;
111
112 switch (mode_)
113 {
114 case NEARESTPATCHFACEAMI:
115 {
116 const label oldWorldComm(Pstream::worldComm);
117 Pstream::worldComm = myComm;
118 lst = AMI().interpolateToSource(Field<Type>(std::move(lst)), cop);
119 Pstream::worldComm = oldWorldComm;
120 break;
121 }
122 default:
123 {
124 mapDistributeBase::distribute
125 (
127 map().schedule(),
128 map().constructSize(),
129 map().subMap(),
130 false,
131 map().constructMap(),
132 false,
133 lst,
134 Type(Zero),
135 cop,
136 flipOp(),
138 myComm
139 );
140 }
141 }
142
143 Pstream::warnComm = oldWarnComm;
144}
145
146
147template<class Type>
149{
150 const label myComm = getCommunicator(); // Get or create
151 const label oldWarnComm(Pstream::warnComm);
152 Pstream::warnComm = myComm;
153
154 switch (mode_)
155 {
156 case NEARESTPATCHFACEAMI:
157 {
158 const label oldWorldComm(Pstream::worldComm);
159 Pstream::worldComm = myComm;
160 lst = AMI().interpolateToTarget(Field<Type>(std::move(lst)));
161 Pstream::worldComm = oldWorldComm;
162 break;
163 }
164 default:
165 {
166 map().reverseDistribute(sampleSize(), lst);
167 break;
168 }
169 }
170
171 Pstream::warnComm = oldWarnComm;
172}
173
174
175template<class Type, class CombineOp>
177(
178 List<Type>& lst,
179 const CombineOp& cop
180) const
181{
182 const label myComm = getCommunicator(); // Get or create
183 const label oldWarnComm(Pstream::warnComm);
184 Pstream::warnComm = myComm;
185
186 switch (mode_)
187 {
188 case NEARESTPATCHFACEAMI:
189 {
190 const label oldWorldComm(Pstream::worldComm);
191 Pstream::worldComm = myComm;
192 lst = AMI().interpolateToTarget(Field<Type>(std::move(lst)), cop);
193 Pstream::worldComm = oldWorldComm;
194 break;
195 }
196 default:
197 {
198 label cSize = sampleSize();
199 mapDistributeBase::distribute
200 (
202 map().schedule(),
203 cSize,
204 map().constructMap(),
205 false,
206 map().subMap(),
207 false,
208 lst,
209 Type(Zero),
210 cop,
211 flipOp(),
213 myComm
214 );
215 break;
216 }
217 }
218
219 Pstream::warnComm = oldWarnComm;
220}
221
222
223template<class Type>
225(
226 const regIOobject& obj,
228)
229{
230 const auto* fldPtr = isA<IOField<Type>>(obj);
231 if (fldPtr)
232 {
233 const auto& fld = *fldPtr;
234
235 token tok;
237
238 primitiveEntry* pePtr = new primitiveEntry
239 (
240 fld.name(),
242 (
243 one(),
244 std::move(tok)
245 )
246 );
247
248 dict.set(pePtr);
249 return true;
250 }
251 else
252 {
253 return false;
254 }
255}
256
257
258template<class Type>
260(
261 const word& name,
262 token& tok,
263 Istream& is,
264 objectRegistry& obr
265)
266{
267 const word tag = "List<" + word(pTraits<Type>::typeName) + '>';
268
269 if (tok.isCompound() && tok.compoundToken().type() == tag)
270 {
272 if (fldPtr)
273 {
274 fldPtr->transfer
275 (
277 (
279 )
280 );
281 }
282 else
283 {
284 IOField<Type>* fldPtr = new IOField<Type>
285 (
287 (
288 name,
289 obr,
292 ),
293 label(0)
294 );
295 fldPtr->transfer
296 (
298 (
300 )
301 );
302 objectRegistry::store(fldPtr);
303 }
304 return true;
305 }
306 else
307 {
308 return false;
309 }
310}
311
312
313template<class Type>
315(
316 objectRegistry& obr,
317 const word& fieldName,
318 const Field<Type>& values
319)
320{
321 IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(fieldName);
322 if (fldPtr)
323 {
324 *fldPtr = values;
325 }
326 else
327 {
328 fldPtr = new IOField<Type>
329 (
331 (
332 fieldName,
333 obr,
336 ),
337 values
338 );
339 objectRegistry::store(fldPtr);
340 }
341}
342
343
344// ************************************************************************* //
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))
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Generic templated field type.
Definition: Field.H:82
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void transfer(List< T > &list)
Definition: List.C:447
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:281
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
const mapDistribute & map() const
Return reference to the parallel distribution map.
void reverseDistribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
@ NEARESTPATCHFACEAMI
nearest patch face + AMI interpolation
const sampleMode mode_
What to sample.
static bool writeIOField(const regIOobject &obj, dictionary &dict)
Attempt to detect an IOField<Type> and write to dictionary.
bool masterWorld() const
Is my world ordered before the sampleWorld?
label getCommunicator() const
Get the communicator (worldComm or world-to-world)
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
static bool constructIOField(const word &name, token &tok, Istream &is, objectRegistry &obr)
Attempt to read an IOField<Type> and store on objectRegistry.
static void storeField(objectRegistry &obr, const word &fieldName, const Field< Type > &values)
Store an IOField on the objectRegistry relative to obr.
bool sameWorld() const
Is sample world the local world?
Registry of regIOobjects.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for managing temporary objects.
Definition: tmp.H:65
A templated class for holding compound tokens.
Definition: token.H:250
A token holds an item read from Istream.
Definition: token.H:69
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
const compound & compoundToken() const
Read access for compound token.
Definition: tokenI.H:722
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:716
A class for handling words, derived from Foam::string.
Definition: word.H:68
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
To & dynamicCast(From &r)
Definition: typeInfo.H:88
dictionary dict
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:69