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 -------------------------------------------------------------------------------
10 License
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 template<class Type>
30 {
31  const label oldComm(Pstream::warnComm);
33  switch (mode_)
34  {
36  {
37  const label oldWorldComm = Pstream::worldComm;
39  lst = AMI().interpolateToSource(Field<Type>(std::move(lst)));
40  Pstream::worldComm = oldWorldComm;
41  break;
42  }
43  default:
44  {
45  map().distribute(lst);
46  }
47  }
48  Pstream::warnComm = oldComm;
49 }
50 
51 
52 template<class Type, class CombineOp>
54 (
55  List<Type>& lst,
56  const CombineOp& cop
57 ) const
58 {
59  const label oldComm(Pstream::warnComm);
60  Pstream::warnComm = comm_;
61  switch (mode_)
62  {
63  case NEARESTPATCHFACEAMI:
64  {
65  const label oldWorldComm = Pstream::worldComm;
66  Pstream::worldComm = comm_;
67  lst = AMI().interpolateToSource(Field<Type>(std::move(lst)), cop);
68  Pstream::worldComm = oldWorldComm;
69  break;
70  }
71  default:
72  {
74  (
76  map().schedule(),
77  map().constructSize(),
78  map().subMap(),
79  false,
80  map().constructMap(),
81  false,
82  lst,
83  Type(Zero),
84  cop,
85  flipOp(),
87  comm_
88  );
89  }
90  }
91  Pstream::warnComm = oldComm;
92 }
93 
94 
95 template<class Type>
97 {
98  const label oldComm(Pstream::warnComm);
99  Pstream::warnComm = map().comm();
100  switch (mode_)
101  {
102  case NEARESTPATCHFACEAMI:
103  {
104  const label oldWorldComm = Pstream::worldComm;
105  Pstream::worldComm = comm_;
106  lst = AMI().interpolateToTarget(Field<Type>(std::move(lst)));
107  Pstream::worldComm = oldWorldComm;
108  break;
109  }
110  default:
111  {
112  map().reverseDistribute(sampleSize(), lst);
113  break;
114  }
115  }
116  Pstream::warnComm = oldComm;
117 }
118 
119 
120 template<class Type, class CombineOp>
122 (
123  List<Type>& lst,
124  const CombineOp& cop
125 ) const
126 {
127  const label oldComm(Pstream::warnComm);
128  Pstream::warnComm = map().comm();
129  switch (mode_)
130  {
131  case NEARESTPATCHFACEAMI:
132  {
133  const label oldWorldComm = Pstream::worldComm;
134  Pstream::worldComm = comm_;
135  lst = AMI().interpolateToTarget(Field<Type>(std::move(lst)), cop);
136  Pstream::worldComm = oldWorldComm;
137  break;
138  }
139  default:
140  {
141  label cSize = sampleSize();
143  (
145  map().schedule(),
146  cSize,
147  map().constructMap(),
148  false,
149  map().subMap(),
150  false,
151  lst,
152  Type(Zero),
153  cop,
154  flipOp(),
156  comm_
157  );
158  break;
159  }
160  }
161  Pstream::warnComm = oldComm;
162 }
163 
164 
165 template<class Type>
167 (
168  const regIOobject& obj,
170 )
171 {
172  const auto* fldPtr = isA<IOField<Type>>(obj);
173  if (fldPtr)
174  {
175  const auto& fld = *fldPtr;
176 
177  token tok;
178  tok = new token::Compound<List<Type>>(fld);
179 
180  primitiveEntry* pePtr = new primitiveEntry
181  (
182  fld.name(),
183  tokenList
184  (
185  one(),
186  std::move(tok)
187  )
188  );
189 
190  dict.set(pePtr);
191  return true;
192  }
193  else
194  {
195  return false;
196  }
197 }
198 
199 
200 template<class Type>
202 (
203  const word& name,
204  token& tok,
205  Istream& is,
206  objectRegistry& obr
207 )
208 {
209  const word tag = "List<" + word(pTraits<Type>::typeName) + '>';
210 
211  if (tok.isCompound() && tok.compoundToken().type() == tag)
212  {
213  IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(name);
214  if (fldPtr)
215  {
216  fldPtr->transfer
217  (
219  (
220  tok.transferCompoundToken(is)
221  )
222  );
223  }
224  else
225  {
226  IOField<Type>* fldPtr = new IOField<Type>
227  (
228  IOobject
229  (
230  name,
231  obr,
234  ),
235  label(0)
236  );
237  fldPtr->transfer
238  (
240  (
241  tok.transferCompoundToken(is)
242  )
243  );
244  objectRegistry::store(fldPtr);
245  }
246  return true;
247  }
248  else
249  {
250  return false;
251  }
252 }
253 
254 
255 template<class Type>
257 (
258  objectRegistry& obr,
259  const word& fieldName,
260  const Field<Type>& values
261 )
262 {
263  IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(fieldName);
264  if (fldPtr)
265  {
266  *fldPtr = values;
267  }
268  else
269  {
270  fldPtr = new IOField<Type>
271  (
272  IOobject
273  (
274  fieldName,
275  obr,
278  ),
279  values
280  );
281  objectRegistry::store(fldPtr);
282  }
283 }
284 
285 
286 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::UPstream::warnComm
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:298
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::mappedPatchBase::writeIOField
static bool writeIOField(const regIOobject &obj, dictionary &dict)
Attempt to detect an IOField<Type> and write to dictionary.
Definition: mappedPatchBaseTemplates.C:167
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:62
Foam::token::Compound
A templated class for holding compound tokens.
Definition: token.H:225
Foam::mappedPatchBase::NEARESTPATCHFACEAMI
nearest patch face + AMI interpolation
Definition: mappedPatchBase.H:124
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.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:167
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:257
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:239
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::UPstream::defaultCommsType
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:283
Foam::token::compoundToken
const compound & compoundToken() const
Read access for compound token.
Definition: tokenI.H:676
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:847
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:202
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::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::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::mappedPatchBase::distribute
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:29
Foam::mappedPatchBase::comm_
label comm_
Communicator.
Definition: mappedPatchBase.H:263
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::mapDistributeBase::comm
label comm() const
Definition: mapDistributeBase.H:336
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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:71
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:541
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:295
Foam::List< Type >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::mappedPatchBase::AMI
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Definition: mappedPatchBaseI.H:189
Foam::token::isCompound
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:670
Foam::IOobject::NO_READ
Definition: IOobject.H:123
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:96