genericPointPatchField.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) 2016-2019 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 #include "genericPointPatchField.H"
30 #include "pointPatchFieldMapper.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const pointPatch& p,
39 )
40 :
42 {
44 }
45 
46 
47 template<class Type>
49 (
50  const pointPatch& p,
52  const dictionary& dict
53 )
54 :
56  actualTypeName_(dict.get<word>("type")),
57  dict_(dict)
58 {
59  const label patchSize = this->size();
60 
61  for (const entry& dEntry : dict_)
62  {
63  const keyType& key = dEntry.keyword();
64 
65  if
66  (
67  key == "type"
68  || !dEntry.isStream() || dEntry.stream().empty()
69  )
70  {
71  continue;
72  }
73 
74 
75  ITstream& is = dEntry.stream();
76 
77  // Read first token
78  token firstToken(is);
79 
80  if
81  (
82  firstToken.isWord()
83  && firstToken.wordToken() == "nonuniform"
84  )
85  {
86  token fieldToken(is);
87 
88  if (!fieldToken.isCompound())
89  {
90  if
91  (
92  fieldToken.isLabel()
93  && fieldToken.labelToken() == 0
94  )
95  {
96  scalarFields_.insert(key, autoPtr<scalarField>::New());
97  }
98  else
99  {
101  << "\n token following 'nonuniform' "
102  "is not a compound"
103  << "\n on patch " << this->patch().name()
104  << " of field "
105  << this->internalField().name()
106  << " in file "
107  << this->internalField().objectPath() << nl
108  << exit(FatalIOError);
109  }
110  }
111  else if
112  (
113  fieldToken.compoundToken().type()
114  == token::Compound<List<scalar>>::typeName
115  )
116  {
117  auto fPtr = autoPtr<scalarField>::New();
118 
119  fPtr->transfer
120  (
122  (
123  fieldToken.transferCompoundToken(is)
124  )
125  );
126 
127  if (fPtr->size() != patchSize)
128  {
130  << "\n size of field " << key
131  << " (" << fPtr->size() << ')'
132  << " is not the same size as the patch ("
133  << patchSize << ')'
134  << "\n on patch " << this->patch().name()
135  << " of field "
136  << this->internalField().name()
137  << " in file "
138  << this->internalField().objectPath() << nl
139  << exit(FatalIOError);
140  }
141 
142  scalarFields_.insert(key, fPtr);
143  }
144  else if
145  (
146  fieldToken.compoundToken().type()
147  == token::Compound<List<vector>>::typeName
148  )
149  {
150  auto fPtr = autoPtr<vectorField>::New();
151 
152  fPtr->transfer
153  (
155  (
156  fieldToken.transferCompoundToken(is)
157  )
158  );
159 
160  if (fPtr->size() != patchSize)
161  {
163  << "\n size of field " << key
164  << " (" << fPtr->size() << ')'
165  << " is not the same size as the patch ("
166  << patchSize << ')'
167  << "\n on patch " << this->patch().name()
168  << " of field "
169  << this->internalField().name()
170  << " in file "
171  << this->internalField().objectPath() << nl
172  << exit(FatalIOError);
173  }
174 
175  vectorFields_.insert(key, fPtr);
176  }
177  else if
178  (
179  fieldToken.compoundToken().type()
181  )
182  {
184 
185  fPtr->transfer
186  (
188  (
189  fieldToken.transferCompoundToken(is)
190  )
191  );
192 
193  if (fPtr->size() != patchSize)
194  {
196  << "\n size of field " << key
197  << " (" << fPtr->size() << ')'
198  << " is not the same size as the patch ("
199  << patchSize << ')'
200  << "\n on patch " << this->patch().name()
201  << " of field "
202  << this->internalField().name()
203  << " in file "
204  << this->internalField().objectPath() << nl
205  << exit(FatalIOError);
206  }
207 
208  sphTensorFields_.insert(key, fPtr);
209  }
210  else if
211  (
212  fieldToken.compoundToken().type()
214  )
215  {
216  auto fPtr = autoPtr<symmTensorField>::New();
217 
218  fPtr->transfer
219  (
221  (
222  fieldToken.transferCompoundToken(is)
223  )
224  );
225 
226  if (fPtr->size() != patchSize)
227  {
229  << "\n size of field " << key
230  << " (" << fPtr->size() << ')'
231  << " is not the same size as the patch ("
232  << patchSize << ')'
233  << "\n on patch " << this->patch().name()
234  << " of field "
235  << this->internalField().name()
236  << " in file "
237  << this->internalField().objectPath() << nl
238  << exit(FatalIOError);
239  }
240 
241  symmTensorFields_.insert(key, fPtr);
242  }
243  else if
244  (
245  fieldToken.compoundToken().type()
246  == token::Compound<List<tensor>>::typeName
247  )
248  {
249  auto fPtr = autoPtr<tensorField>::New();
250 
251  fPtr->transfer
252  (
254  (
255  fieldToken.transferCompoundToken(is)
256  )
257  );
258 
259  if (fPtr->size() != patchSize)
260  {
262  << "\n size of field " << key
263  << " (" << fPtr->size() << ')'
264  << " is not the same size as the patch ("
265  << patchSize << ')'
266  << "\n on patch " << this->patch().name()
267  << " of field "
268  << this->internalField().name()
269  << " in file "
270  << this->internalField().objectPath() << nl
271  << exit(FatalIOError);
272  }
273 
274  tensorFields_.insert(key, fPtr);
275  }
276  else
277  {
279  << "\n compound " << fieldToken.compoundToken()
280  << " not supported"
281  << "\n on patch " << this->patch().name()
282  << " of field "
283  << this->internalField().name()
284  << " in file "
285  << this->internalField().objectPath() << nl
286  << exit(FatalIOError);
287  }
288  }
289  }
290 }
291 
292 
293 template<class Type>
295 (
296  const genericPointPatchField<Type>& ptf,
297  const pointPatch& p,
299  const pointPatchFieldMapper& mapper
300 )
301 :
302  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
303  actualTypeName_(ptf.actualTypeName_),
304  dict_(ptf.dict_)
305 {
306  forAllConstIters(ptf.scalarFields_, iter)
307  {
308  scalarFields_.insert
309  (
310  iter.key(),
311  autoPtr<scalarField>::New(*iter(), mapper)
312  );
313  }
314 
315  forAllConstIters(ptf.vectorFields_, iter)
316  {
317  vectorFields_.insert
318  (
319  iter.key(),
320  autoPtr<vectorField>::New(*iter(), mapper)
321  );
322  }
323 
324  forAllConstIters(ptf.sphTensorFields_, iter)
325  {
326  sphTensorFields_.insert
327  (
328  iter.key(),
329  autoPtr<sphericalTensorField>::New(*iter(), mapper)
330  );
331  }
332 
333  forAllConstIters(ptf.symmTensorFields_, iter)
334  {
335  symmTensorFields_.insert
336  (
337  iter.key(),
338  autoPtr<symmTensorField>::New(*iter(), mapper)
339  );
340  }
341 
342  forAllConstIters(ptf.tensorFields_, iter)
343  {
344  tensorFields_.insert
345  (
346  iter.key(),
347  autoPtr<tensorField>::New(*iter(), mapper)
348  );
349  }
350 }
351 
352 
353 template<class Type>
355 (
356  const genericPointPatchField<Type>& ptf,
358 )
359 :
361  actualTypeName_(ptf.actualTypeName_),
362  dict_(ptf.dict_),
363  scalarFields_(ptf.scalarFields_),
364  vectorFields_(ptf.vectorFields_),
365  sphTensorFields_(ptf.sphTensorFields_),
366  symmTensorFields_(ptf.symmTensorFields_),
367  tensorFields_(ptf.tensorFields_)
368 {}
369 
370 
371 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
372 
373 template<class Type>
375 (
376  const pointPatchFieldMapper& m
377 )
378 {
379  forAllIters(scalarFields_, iter)
380  {
381  (*iter)->autoMap(m);
382  }
383 
384  forAllIters(vectorFields_, iter)
385  {
386  (*iter)->autoMap(m);
387  }
388 
389  forAllIters(sphTensorFields_, iter)
390  {
391  (*iter)->autoMap(m);
392  }
393 
394  forAllIters(symmTensorFields_, iter)
395  {
396  (*iter)->autoMap(m);
397  }
398 
399  forAllIters(tensorFields_, iter)
400  {
401  (*iter)->autoMap(m);
402  }
403 }
404 
405 
406 template<class Type>
408 (
409  const pointPatchField<Type>& ptf,
410  const labelList& addr
411 )
412 {
413  const genericPointPatchField<Type>& dptf =
414  refCast<const genericPointPatchField<Type>>(ptf);
415 
416  forAllIters(scalarFields_, iter)
417  {
418  const auto iter2 = dptf.scalarFields_.cfind(iter.key());
419 
420  if (iter2.found())
421  {
422  (*iter)->rmap(*iter2(), addr);
423  }
424  }
425 
426  forAllIters(vectorFields_, iter)
427  {
428  const auto iter2 = dptf.vectorFields_.cfind(iter.key());
429 
430  if (iter2.found())
431  {
432  (*iter)->rmap(*iter2(), addr);
433  }
434  }
435 
436  forAllIters(sphTensorFields_, iter)
437  {
438  const auto iter2 = dptf.sphTensorFields_.find(iter.key());
439 
440  if (iter2.found())
441  {
442  (*iter)->rmap(*iter2(), addr);
443  }
444  }
445 
446  forAllIters(symmTensorFields_, iter)
447  {
448  const auto iter2 = dptf.symmTensorFields_.find(iter.key());
449 
450  if (iter2.found())
451  {
452  (*iter)->rmap(*iter2(), addr);
453  }
454  }
455 
456  forAllIters(tensorFields_, iter)
457  {
458  const auto iter2 = dptf.tensorFields_.find(iter.key());
459 
460  if (iter2.found())
461  {
462  (*iter)->rmap(*iter2(), addr);
463  }
464  }
465 }
466 
467 
468 template<class Type>
470 {
471  return actualTypeName_;
472 }
473 
474 
475 template<class Type>
477 {
478  os.writeEntry("type", actualTypeName_);
479 
480  for (const entry& dEntry : dict_)
481  {
482  const keyType& key = dEntry.keyword();
483 
484  if (key == "type")
485  {
486  // NB: "type" written first, no special treatment for "value"
487  continue;
488  }
489  else if
490  (
491  dEntry.isStream()
492  && dEntry.stream().size()
493  && dEntry.stream()[0].isWord()
494  && dEntry.stream()[0].wordToken() == "nonuniform"
495  )
496  {
497  if (scalarFields_.found(key))
498  {
499  scalarFields_.cfind(key)()->writeEntry(key, os);
500  }
501  else if (vectorFields_.found(key))
502  {
503  vectorFields_.cfind(key)()->writeEntry(key, os);
504  }
505  else if (sphTensorFields_.found(key))
506  {
507  sphTensorFields_.cfind(key)()->writeEntry(key, os);
508  }
509  else if (symmTensorFields_.found(key))
510  {
511  symmTensorFields_.cfind(key)()->writeEntry(key, os);
512  }
513  else if (tensorFields_.found(key))
514  {
515  tensorFields_.cfind(key)()->writeEntry(key, os);
516  }
517  }
518  else
519  {
520  dEntry.write(os);
521  }
522  }
523 }
524 
525 
526 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::token::labelToken
label labelToken() const
Return label value.
Definition: tokenI.H:487
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::token::isLabel
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:481
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
pointPatchFieldMapper.H
Foam::FatalIOError
IOerror FatalIOError
Foam::genericPointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: genericPointPatchField.C:476
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::token::compoundToken
const compound & compoundToken() const
Read access for compound token.
Definition: tokenI.H:676
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::genericPointPatchField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: genericPointPatchField.C:375
Foam::pointPatchField
Abstract base class for point-mesh patch fields.
Definition: pointMVCWeight.H:60
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
Foam::token::isWord
bool isWord() const noexcept
Token is WORD or DIRECTIVE word.
Definition: tokenI.H:583
Foam::genericPointPatchField::genericPointPatchField
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: genericPointPatchField.C:36
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::calculatedPointPatchField
A calculated boundary condition for pointField.
Definition: calculatedPointPatchField.H:51
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
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:121
genericPointPatchField.H
Foam::genericPointPatchField::rmap
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
Definition: genericPointPatchField.C:408
Foam::genericPointPatchField
A generic version of calculatedPointPatchField, useful as a fallback for handling unknown patch types...
Definition: genericPointPatchField.H:54
Foam::token::transferCompoundToken
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
Foam::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:599
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:385
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::dynamicCast
To & dynamicCast(From &r)
Definition: typeInfo.H:88
Foam::List< scalar >
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::token::isCompound
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:670
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::genericPointPatchField::actualType
const word & actualType() const
Return the actual type.
Definition: genericPointPatchField.C:469
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54