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 -------------------------------------------------------------------------------
11 License
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 
29 template<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  );
63  (void)AMI().interpolateToTarget
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  {
74  (void)AMI().interpolateToSource
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 
101 template<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  {
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 
147 template<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 
175 template<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();
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 
223 template<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;
236  tok = new token::Compound<List<Type>>(fld);
237 
238  primitiveEntry* pePtr = new primitiveEntry
239  (
240  fld.name(),
241  tokenList
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 
258 template<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  {
271  IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(name);
272  if (fldPtr)
273  {
274  fldPtr->transfer
275  (
277  (
278  tok.transferCompoundToken(is)
279  )
280  );
281  }
282  else
283  {
284  IOField<Type>* fldPtr = new IOField<Type>
285  (
286  IOobject
287  (
288  name,
289  obr,
292  ),
293  label(0)
294  );
295  fldPtr->transfer
296  (
298  (
299  tok.transferCompoundToken(is)
300  )
301  );
302  objectRegistry::store(fldPtr);
303  }
304  return true;
305  }
306  else
307  {
308  return false;
309  }
310 }
311 
312 
313 template<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  (
330  IOobject
331  (
332  fieldName,
333  obr,
336  ),
337  values
338  );
339  objectRegistry::store(fldPtr);
340  }
341 }
342 
343 
344 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::UPstream::warnComm
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::mappedPatchBase::writeIOField
static bool writeIOField(const regIOobject &obj, dictionary &dict)
Attempt to detect an IOField<Type> and write to dictionary.
Definition: mappedPatchBaseTemplates.C:225
Foam::primitiveEntry
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Definition: primitiveEntry.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::token::Compound
A templated class for holding compound tokens.
Definition: token.H:246
Foam::mappedPatchBase::NEARESTPATCHFACEAMI
nearest patch face + AMI interpolation
Definition: mappedPatchBase.H:123
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::mappedPatchBase::map
const mapDistribute & map() const
Return reference to the parallel distribution map.
Definition: mappedPatchBaseI.H:199
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::mappedPatchBase::storeField
static void storeField(objectRegistry &obr, const word &fieldName, const Field< Type > &values)
Store an IOField on the objectRegistry relative to obr.
Definition: mappedPatchBaseTemplates.C:315
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::mappedPatchBase::mode_
const sampleMode mode_
What to sample.
Definition: mappedPatchBase.H:235
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::mappedPatchBase::sameWorld
bool sameWorld() const
Is sample world the local world?
Definition: mappedPatchBaseI.H:169
Foam::UPstream::defaultCommsType
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:281
Foam::token::compoundToken
const compound & compoundToken() const
Read access for compound token.
Definition: tokenI.H:722
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
Foam::AMIInterpolation::interpolateToTarget
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolationTemplates.C:36
Foam::regIOobject::store
bool store()
Definition: regIOobjectI.H:37
Foam::mappedPatchBase::constructIOField
static bool constructIOField(const word &name, token &tok, Istream &is, objectRegistry &obr)
Attempt to read an IOField<Type> and store on objectRegistry.
Definition: mappedPatchBaseTemplates.C:260
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::AMIInterpolation::interpolateToSource
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolationTemplates.C:122
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::mappedPatchBase::getCommunicator
label getCommunicator() const
Get the communicator (worldComm or world-to-world)
Definition: mappedPatchBaseI.H:147
Foam::mapDistributeBase::distribute
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &, const negateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute data. Note:schedule only used for.
Definition: mapDistributeBaseTemplates.C:122
Foam::mappedPatchBase::distribute
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:30
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:152
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::mappedPatchBase::masterWorld
bool masterWorld() const
Is my world ordered before the sampleWorld?
Definition: mappedPatchBaseI.H:180
Foam::token::transferCompoundToken
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
Foam::tokenList
List< token > tokenList
List of tokens, used for a IOdictionary entry.
Definition: tokenList.H:44
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::UPstream::msgType
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:540
Foam::objectRegistry::findObject
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:401
Foam::dynamicCast
To & dynamicCast(From &r)
Definition: typeInfo.H:88
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
Foam::List< Type >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::mappedPatchBase::AMI
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Definition: mappedPatchBaseI.H:221
Foam::token::isCompound
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:716
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::flipOp
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:53
Foam::mappedPatchBase::reverseDistribute
void reverseDistribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:148