genericPointPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "genericPointPatchField.H"
27 #include "pointPatchFieldMapper.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const pointPatch& p,
36  const dictionary& dict
37 )
38 :
39  genericPatchField(dict.lookup("type")),
40  calculatedPointPatchField<Type>(p, iF, dict),
41  dict_(dict)
42 {
43  forAllConstIter(dictionary, dict_, iter)
44  {
45  if (iter().keyword() != "type")
46  {
47  if
48  (
49  iter().isStream()
50  && iter().stream().size()
51  )
52  {
53  ITstream& is = iter().stream();
54 
55  // Read first token
56  token firstToken(is);
57 
58  if
59  (
60  firstToken.isWord()
61  && firstToken.wordToken() == "nonuniform"
62  )
63  {
64  token fieldToken(is);
65 
66  if (!fieldToken.isCompound())
67  {
68  if
69  (
70  fieldToken.isLabel()
71  && fieldToken.labelToken() == 0
72  )
73  {
74  scalarFields_.insert
75  (
76  iter().keyword(),
77  new scalarField(0)
78  );
79  }
80  else
81  {
83  (
84  dict
85  ) << "\n token following 'nonuniform' "
86  "is not a compound"
87  << "\n on patch " << this->patch().name()
88  << " of field "
89  << this->internalField().name()
90  << " in file "
91  << this->internalField().objectPath()
92  << exit(FatalIOError);
93  }
94  }
95  else if
96  (
97  fieldToken.compoundToken().type()
98  == token::Compound<List<scalar>>::typeName
99  )
100  {
101  scalarField* fPtr = new scalarField;
102  fPtr->transfer
103  (
105  (
106  fieldToken.transferCompoundToken(is)
107  )
108  );
109 
110  if (fPtr->size() != this->size())
111  {
113  (
114  dict
115  ) << "\n size of field " << iter().keyword()
116  << " (" << fPtr->size() << ')'
117  << " is not the same size as the patch ("
118  << this->size() << ')'
119  << "\n on patch " << this->patch().name()
120  << " of field "
121  << this->internalField().name()
122  << " in file "
123  << this->internalField().objectPath()
124  << exit(FatalIOError);
125  }
126 
127  scalarFields_.insert(iter().keyword(), fPtr);
128  }
129  else if
130  (
131  fieldToken.compoundToken().type()
132  == token::Compound<List<vector>>::typeName
133  )
134  {
135  vectorField* fPtr = new vectorField;
136  fPtr->transfer
137  (
139  (
140  fieldToken.transferCompoundToken(is)
141  )
142  );
143 
144  if (fPtr->size() != this->size())
145  {
147  (
148  dict
149  ) << "\n size of field " << iter().keyword()
150  << " (" << fPtr->size() << ')'
151  << " is not the same size as the patch ("
152  << this->size() << ')'
153  << "\n on patch " << this->patch().name()
154  << " of field "
155  << this->internalField().name()
156  << " in file "
157  << this->internalField().objectPath()
158  << exit(FatalIOError);
159  }
160 
161  vectorFields_.insert(iter().keyword(), fPtr);
162  }
163  else if
164  (
165  fieldToken.compoundToken().type()
167  )
168  {
170  fPtr->transfer
171  (
173  <
175  >
176  (
177  fieldToken.transferCompoundToken(is)
178  )
179  );
180 
181  if (fPtr->size() != this->size())
182  {
184  (
185  dict
186  ) << "\n size of field " << iter().keyword()
187  << " (" << fPtr->size() << ')'
188  << " is not the same size as the patch ("
189  << this->size() << ')'
190  << "\n on patch " << this->patch().name()
191  << " of field "
192  << this->internalField().name()
193  << " in file "
194  << this->internalField().objectPath()
195  << exit(FatalIOError);
196  }
197 
198  sphericalTensorFields_.insert(iter().keyword(), fPtr);
199  }
200  else if
201  (
202  fieldToken.compoundToken().type()
203  == token::Compound<List<symmTensor>>::typeName
204  )
205  {
206  symmTensorField* fPtr = new symmTensorField;
207  fPtr->transfer
208  (
210  <
212  >
213  (
214  fieldToken.transferCompoundToken(is)
215  )
216  );
217 
218  if (fPtr->size() != this->size())
219  {
221  (
222  dict
223  ) << "\n size of field " << iter().keyword()
224  << " (" << fPtr->size() << ')'
225  << " is not the same size as the patch ("
226  << this->size() << ')'
227  << "\n on patch " << this->patch().name()
228  << " of field "
229  << this->internalField().name()
230  << " in file "
231  << this->internalField().objectPath()
232  << exit(FatalIOError);
233  }
234 
235  symmTensorFields_.insert(iter().keyword(), fPtr);
236  }
237  else if
238  (
239  fieldToken.compoundToken().type()
240  == token::Compound<List<tensor>>::typeName
241  )
242  {
243  tensorField* fPtr = new tensorField;
244  fPtr->transfer
245  (
247  (
248  fieldToken.transferCompoundToken(is)
249  )
250  );
251 
252  if (fPtr->size() != this->size())
253  {
255  (
256  dict
257  ) << "\n size of field " << iter().keyword()
258  << " (" << fPtr->size() << ')'
259  << " is not the same size as the patch ("
260  << this->size() << ')'
261  << "\n on patch " << this->patch().name()
262  << " of field "
263  << this->internalField().name()
264  << " in file "
265  << this->internalField().objectPath()
266  << exit(FatalIOError);
267  }
268 
269  tensorFields_.insert(iter().keyword(), fPtr);
270  }
271  else
272  {
274  (
275  dict
276  ) << "\n compound " << fieldToken.compoundToken()
277  << " not supported"
278  << "\n on patch " << this->patch().name()
279  << " of field "
280  << this->internalField().name()
281  << " in file "
282  << this->internalField().objectPath()
283  << exit(FatalIOError);
284  }
285  }
286  }
287  }
288  }
289 }
290 
291 
292 template<class Type>
294 (
295  const genericPointPatchField<Type>& ptf,
296  const pointPatch& p,
298  const pointPatchFieldMapper& mapper
299 )
300 :
301  genericPatchField(ptf),
302  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
303  dict_(ptf.dict_)
304 {
306  (
308  ptf.scalarFields_,
309  iter
310  )
311  {
312  scalarFields_.insert
313  (
314  iter.key(),
315  mapper(*iter()).ptr()
316  );
317  }
318 
320  (
322  ptf.vectorFields_,
323  iter
324  )
325  {
326  vectorFields_.insert
327  (
328  iter.key(),
329  mapper(*iter()).ptr()
330  );
331  }
332 
334  (
336  ptf.sphericalTensorFields_,
337  iter
338  )
339  {
340  sphericalTensorFields_.insert
341  (
342  iter.key(),
343  mapper(*iter()).ptr()
344  );
345  }
346 
348  (
350  ptf.symmTensorFields_,
351  iter
352  )
353  {
354  symmTensorFields_.insert
355  (
356  iter.key(),
357  mapper(*iter()).ptr()
358  );
359  }
360 
362  (
364  ptf.tensorFields_,
365  iter
366  )
367  {
368  tensorFields_.insert
369  (
370  iter.key(),
371  mapper(*iter()).ptr()
372  );
373  }
374 }
375 
376 
377 template<class Type>
379 (
380  const genericPointPatchField<Type>& ptf,
382 )
383 :
384  genericPatchField(ptf),
385  calculatedPointPatchField<Type>(ptf, iF),
386  dict_(ptf.dict_),
387  scalarFields_(ptf.scalarFields_),
388  vectorFields_(ptf.vectorFields_),
389  sphericalTensorFields_(ptf.sphericalTensorFields_),
390  symmTensorFields_(ptf.symmTensorFields_),
391  tensorFields_(ptf.tensorFields_)
392 {}
393 
394 
395 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
396 
397 template<class Type>
399 (
400  const pointPatchField<Type>& ptf,
401  const pointPatchFieldMapper& mapper
402 )
403 {
404  const genericPointPatchField<Type>& dptf =
405  refCast<const genericPointPatchField<Type>>(ptf);
406 
407  forAllIter
408  (
410  scalarFields_,
411  iter
412  )
413  {
415  dptf.scalarFields_.find(iter.key());
416 
417  if (dptfIter != scalarFields_.end())
418  {
419  mapper(*iter(), *dptfIter());
420  }
421  }
422 
423  forAllIter
424  (
426  vectorFields_,
427  iter
428  )
429  {
431  dptf.vectorFields_.find(iter.key());
432 
433  if (dptfIter != vectorFields_.end())
434  {
435  mapper(*iter(), *dptfIter());
436  }
437  }
438 
439  forAllIter
440  (
442  sphericalTensorFields_,
443  iter
444  )
445  {
447  dptf.sphericalTensorFields_.find(iter.key());
448 
449  if (dptfIter != sphericalTensorFields_.end())
450  {
451  mapper(*iter(), *dptfIter());
452  }
453  }
454 
455  forAllIter
456  (
458  symmTensorFields_,
459  iter
460  )
461  {
463  dptf.symmTensorFields_.find(iter.key());
464 
465  if (dptfIter != symmTensorFields_.end())
466  {
467  mapper(*iter(), *dptfIter());
468  }
469  }
470 
471  forAllIter
472  (
474  tensorFields_,
475  iter
476  )
477  {
479  dptf.tensorFields_.find(iter.key());
480 
481  if (dptfIter != tensorFields_.end())
482  {
483  mapper(*iter(), *dptfIter());
484  }
485  }
486 }
487 
488 
489 template<class Type>
491 (
492  const pointPatchField<Type>& ptf
493 )
494 {
495  const genericPointPatchField<Type>& dptf =
496  refCast<const genericPointPatchField<Type>>(ptf);
497 
498  forAllIter
499  (
501  scalarFields_,
502  iter
503  )
504  {
506  dptf.scalarFields_.find(iter.key());
507 
508  if (dptfIter != scalarFields_.end())
509  {
510  iter()->reset(*dptfIter());
511  }
512  }
513 
514  forAllIter
515  (
517  vectorFields_,
518  iter
519  )
520  {
522  dptf.vectorFields_.find(iter.key());
523 
524  if (dptfIter != vectorFields_.end())
525  {
526  iter()->reset(*dptfIter());
527  }
528  }
529 
530  forAllIter
531  (
533  sphericalTensorFields_,
534  iter
535  )
536  {
538  dptf.sphericalTensorFields_.find(iter.key());
539 
540  if (dptfIter != sphericalTensorFields_.end())
541  {
542  iter()->reset(*dptfIter());
543  }
544  }
545 
546  forAllIter
547  (
549  symmTensorFields_,
550  iter
551  )
552  {
554  dptf.symmTensorFields_.find(iter.key());
555 
556  if (dptfIter != symmTensorFields_.end())
557  {
558  iter()->reset(*dptfIter());
559  }
560  }
561 
562  forAllIter
563  (
565  tensorFields_,
566  iter
567  )
568  {
570  dptf.tensorFields_.find(iter.key());
571 
572  if (dptfIter != tensorFields_.end())
573  {
574  iter()->reset(*dptfIter());
575  }
576  }
577 }
578 
579 
580 template<class Type>
582 {
583  writeEntry(os, "type", actualTypeName());
584 
585  forAllConstIter(dictionary, dict_, iter)
586  {
587  if (iter().keyword() != "type")
588  {
589  if
590  (
591  iter().isStream()
592  && iter().stream().size()
593  && iter().stream()[0].isWord()
594  && iter().stream()[0].wordToken() == "nonuniform"
595  )
596  {
597  if (scalarFields_.found(iter().keyword()))
598  {
599  writeEntry
600  (
601  os,
602  iter().keyword(),
603  *scalarFields_.find(iter().keyword())()
604  );
605  }
606  else if (vectorFields_.found(iter().keyword()))
607  {
608  writeEntry
609  (
610  os,
611  iter().keyword(),
612  *vectorFields_.find(iter().keyword())()
613  );
614  }
615  else if (sphericalTensorFields_.found(iter().keyword()))
616  {
617  writeEntry
618  (
619  os,
620  iter().keyword(),
621  *sphericalTensorFields_.find(iter().keyword())()
622  );
623  }
624  else if (symmTensorFields_.found(iter().keyword()))
625  {
626  writeEntry
627  (
628  os,
629  iter().keyword(),
630  *symmTensorFields_.find(iter().keyword())()
631  );
632  }
633  else if (tensorFields_.found(iter().keyword()))
634  {
635  writeEntry
636  (
637  os,
638  iter().keyword(),
639  *tensorFields_.find(iter().keyword())()
640  );
641  }
642  }
643  else
644  {
645  iter().write(os);
646  }
647  }
648  }
649 }
650 
651 
652 // ************************************************************************* //
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
An STL-conforming const_iterator.
Definition: HashTable.H:484
Input token stream.
Definition: ITstream.H:53
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A calculated boundary condition for pointField.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A generic version of calculatedPointPatchField, useful as a fallback for handling unknown patch types...
virtual void write(Ostream &) const
Write.
virtual void reset(const pointPatchField< Type > &)
Reset the pointPatchField to the given pointPatchField.
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void map(const pointPatchField< Type > &, const pointPatchFieldMapper &)
Map the given pointPatchField onto this pointPatchField.
Foam::pointPatchFieldMapper.
Abstract base class for point-mesh patch fields.
const DimensionedField< Type, pointMesh > & internalField() const
Return dimensioned internal field reference.
const pointPatch & patch() const
Return patch.
label size() const
Return size.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:57
virtual const word & name() const =0
Return name.
A templated class for holding compound tokens.
Definition: token.H:213
A token holds items read from Istream.
Definition: token.H:73
bool isLabel() const
Definition: tokenI.H:392
compound & transferCompoundToken(const Istream &is)
Definition: token.C:92
label labelToken() const
Definition: tokenI.H:397
bool isCompound() const
Definition: tokenI.H:520
const compound & compoundToken() const
Definition: tokenI.H:525
bool isWord() const
Definition: tokenI.H:261
const word & wordToken() const
Definition: tokenI.H:266
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
To & dynamicCast(From &r)
Reference type cast template function,.
Definition: typeInfo.H:90
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Field< sphericalTensor > sphericalTensorField
Specialisation of Field<T> for sphericalTensor.
Field< vector > vectorField
Specialisation of Field<T> for vector.
IOerror FatalIOError
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
dictionary dict
volScalarField & p