genericFvPatchField.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 "genericFvPatchField.H"
27 #include "fvPatchFieldMapper.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvPatch& p,
36  const dictionary& dict
37 )
38 :
39  genericPatchField(dict.lookup("type")),
40  calculatedFvPatchField<Type>(p, iF, dict),
41  dict_(dict)
42 {
43  if (!dict.found("value"))
44  {
46  (
47  dict
48  ) << "\n Cannot find 'value' entry"
49  << " on patch " << this->patch().name()
50  << " of field " << this->internalField().name()
51  << " in file " << this->internalField().objectPath()
52  << nl
53  << " which is required to set the"
54  " values of the generic patch field." << nl
55  << " (Actual type " << actualTypeName() << ")" << nl
56  << "\n Please add the 'value' entry to the write function "
57  "of the user-defined boundary-condition\n"
58  << exit(FatalIOError);
59  }
60 
61  forAllConstIter(dictionary, dict_, iter)
62  {
63  if (iter().keyword() != "type" && iter().keyword() != "value")
64  {
65  if
66  (
67  iter().isStream()
68  && iter().stream().size()
69  )
70  {
71  ITstream& is = iter().stream();
72 
73  // Read first token
74  token firstToken(is);
75 
76  if
77  (
78  firstToken.isWord()
79  && firstToken.wordToken() == "nonuniform"
80  )
81  {
82  token fieldToken(is);
83 
84  if (!fieldToken.isCompound())
85  {
86  if
87  (
88  fieldToken.isLabel()
89  && fieldToken.labelToken() == 0
90  )
91  {
92  scalarFields_.insert
93  (
94  iter().keyword(),
95  new scalarField(0)
96  );
97  }
98  else
99  {
101  (
102  dict
103  ) << "\n token following 'nonuniform' "
104  "is not a compound"
105  << "\n on patch " << this->patch().name()
106  << " of field "
107  << this->internalField().name()
108  << " in file "
109  << this->internalField().objectPath()
110  << exit(FatalIOError);
111  }
112  }
113  else if
114  (
115  fieldToken.compoundToken().type()
117  )
118  {
119  scalarField* fPtr = new scalarField;
120  fPtr->transfer
121  (
123  (
124  fieldToken.transferCompoundToken(is)
125  )
126  );
127 
128  if (fPtr->size() != this->size())
129  {
131  (
132  dict
133  ) << "\n size of field " << iter().keyword()
134  << " (" << fPtr->size() << ')'
135  << " is not the same size as the patch ("
136  << this->size() << ')'
137  << "\n on patch " << this->patch().name()
138  << " of field "
139  << this->internalField().name()
140  << " in file "
141  << this->internalField().objectPath()
142  << exit(FatalIOError);
143  }
144 
145  scalarFields_.insert(iter().keyword(), fPtr);
146  }
147  else if
148  (
149  fieldToken.compoundToken().type()
151  )
152  {
153  vectorField* fPtr = new vectorField;
154  fPtr->transfer
155  (
157  (
158  fieldToken.transferCompoundToken(is)
159  )
160  );
161 
162  if (fPtr->size() != this->size())
163  {
165  (
166  dict
167  ) << "\n size of field " << iter().keyword()
168  << " (" << fPtr->size() << ')'
169  << " is not the same size as the patch ("
170  << this->size() << ')'
171  << "\n on patch " << this->patch().name()
172  << " of field "
173  << this->internalField().name()
174  << " in file "
175  << this->internalField().objectPath()
176  << exit(FatalIOError);
177  }
178 
179  vectorFields_.insert(iter().keyword(), fPtr);
180  }
181  else if
182  (
183  fieldToken.compoundToken().type()
185  )
186  {
188  fPtr->transfer
189  (
191  <
193  >
194  (
195  fieldToken.transferCompoundToken(is)
196  )
197  );
198 
199  if (fPtr->size() != this->size())
200  {
202  (
203  dict
204  ) << "\n size of field " << iter().keyword()
205  << " (" << fPtr->size() << ')'
206  << " is not the same size as the patch ("
207  << this->size() << ')'
208  << "\n on patch " << this->patch().name()
209  << " of field "
210  << this->internalField().name()
211  << " in file "
212  << this->internalField().objectPath()
213  << exit(FatalIOError);
214  }
215 
216  sphericalTensorFields_.insert(iter().keyword(), fPtr);
217  }
218  else if
219  (
220  fieldToken.compoundToken().type()
222  )
223  {
224  symmTensorField* fPtr = new symmTensorField;
225  fPtr->transfer
226  (
228  <
230  >
231  (
232  fieldToken.transferCompoundToken(is)
233  )
234  );
235 
236  if (fPtr->size() != this->size())
237  {
239  (
240  dict
241  ) << "\n size of field " << iter().keyword()
242  << " (" << fPtr->size() << ')'
243  << " is not the same size as the patch ("
244  << this->size() << ')'
245  << "\n on patch " << this->patch().name()
246  << " of field "
247  << this->internalField().name()
248  << " in file "
249  << this->internalField().objectPath()
250  << exit(FatalIOError);
251  }
252 
253  symmTensorFields_.insert(iter().keyword(), fPtr);
254  }
255  else if
256  (
257  fieldToken.compoundToken().type()
259  )
260  {
261  tensorField* fPtr = new tensorField;
262  fPtr->transfer
263  (
265  (
266  fieldToken.transferCompoundToken(is)
267  )
268  );
269 
270  if (fPtr->size() != this->size())
271  {
273  (
274  dict
275  ) << "\n size of field " << iter().keyword()
276  << " (" << fPtr->size() << ')'
277  << " is not the same size as the patch ("
278  << this->size() << ')'
279  << "\n on patch " << this->patch().name()
280  << " of field "
281  << this->internalField().name()
282  << " in file "
283  << this->internalField().objectPath()
284  << exit(FatalIOError);
285  }
286 
287  tensorFields_.insert(iter().keyword(), fPtr);
288  }
289  else
290  {
292  (
293  dict
294  ) << "\n compound " << fieldToken.compoundToken()
295  << " not supported"
296  << "\n on patch " << this->patch().name()
297  << " of field "
298  << this->internalField().name()
299  << " in file "
300  << this->internalField().objectPath()
301  << exit(FatalIOError);
302  }
303  }
304  else if
305  (
306  firstToken.isWord()
307  && firstToken.wordToken() == "uniform"
308  )
309  {
310  token fieldToken(is);
311 
312  if (!fieldToken.isPunctuation())
313  {
314  scalarFields_.insert
315  (
316  iter().keyword(),
317  new scalarField
318  (
319  this->size(),
320  fieldToken.number()
321  )
322  );
323  }
324  else
325  {
326  // Read as scalarList.
327  is.putBack(fieldToken);
328 
329  scalarList l(is);
330 
331  if (l.size() == vector::nComponents)
332  {
333  vector vs(l[0], l[1], l[2]);
334 
335  vectorFields_.insert
336  (
337  iter().keyword(),
338  new vectorField(this->size(), vs)
339  );
340  }
341  else if (l.size() == sphericalTensor::nComponents)
342  {
343  sphericalTensor vs(l[0]);
344 
345  sphericalTensorFields_.insert
346  (
347  iter().keyword(),
348  new sphericalTensorField(this->size(), vs)
349  );
350  }
351  else if (l.size() == symmTensor::nComponents)
352  {
353  symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
354 
355  symmTensorFields_.insert
356  (
357  iter().keyword(),
358  new symmTensorField(this->size(), vs)
359  );
360  }
361  else if (l.size() == tensor::nComponents)
362  {
363  tensor vs
364  (
365  l[0], l[1], l[2],
366  l[3], l[4], l[5],
367  l[6], l[7], l[8]
368  );
369 
370  tensorFields_.insert
371  (
372  iter().keyword(),
373  new tensorField(this->size(), vs)
374  );
375  }
376  else
377  {
379  (
380  dict
381  ) << "\n unrecognised native type " << l
382  << "\n on patch " << this->patch().name()
383  << " of field "
384  << this->internalField().name()
385  << " in file "
386  << this->internalField().objectPath()
387  << exit(FatalIOError);
388  }
389  }
390  }
391  }
392  }
393  }
394 }
395 
396 
397 template<class Type>
399 (
400  const genericFvPatchField<Type>& ptf,
401  const fvPatch& p,
403  const fvPatchFieldMapper& mapper
404 )
405 :
406  genericPatchField(ptf),
407  calculatedFvPatchField<Type>(ptf, p, iF, mapper),
408  dict_(ptf.dict_)
409 {
411  (
413  ptf.scalarFields_,
414  iter
415  )
416  {
417  scalarFields_.insert
418  (
419  iter.key(),
420  mapper(*iter()).ptr()
421  );
422  }
423 
425  (
427  ptf.vectorFields_,
428  iter
429  )
430  {
431  vectorFields_.insert
432  (
433  iter.key(),
434  mapper(*iter()).ptr()
435  );
436  }
437 
439  (
441  ptf.sphericalTensorFields_,
442  iter
443  )
444  {
445  sphericalTensorFields_.insert
446  (
447  iter.key(),
448  mapper(*iter()).ptr()
449  );
450  }
451 
453  (
455  ptf.symmTensorFields_,
456  iter
457  )
458  {
459  symmTensorFields_.insert
460  (
461  iter.key(),
462  mapper(*iter()).ptr()
463  );
464  }
465 
467  (
469  ptf.tensorFields_,
470  iter
471  )
472  {
473  tensorFields_.insert
474  (
475  iter.key(),
476  mapper(*iter()).ptr()
477  );
478  }
479 }
480 
481 
482 template<class Type>
484 (
485  const genericFvPatchField<Type>& ptf,
487 )
488 :
489  genericPatchField(ptf),
490  calculatedFvPatchField<Type>(ptf, iF),
491  dict_(ptf.dict_),
492  scalarFields_(ptf.scalarFields_),
493  vectorFields_(ptf.vectorFields_),
494  sphericalTensorFields_(ptf.sphericalTensorFields_),
495  symmTensorFields_(ptf.symmTensorFields_),
496  tensorFields_(ptf.tensorFields_)
497 {}
498 
499 
500 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
501 
502 template<class Type>
504 (
505  const fvPatchField<Type>& ptf,
506  const fvPatchFieldMapper& mapper
507 )
508 {
510 
511  const genericFvPatchField<Type>& dptf =
512  refCast<const genericFvPatchField<Type>>(ptf);
513 
514  forAllIter
515  (
517  scalarFields_,
518  iter
519  )
520  {
522  dptf.scalarFields_.find(iter.key());
523 
524  if (dptfIter != dptf.scalarFields_.end())
525  {
526  mapper(*iter(), *dptfIter());
527  }
528  }
529 
530  forAllIter
531  (
533  vectorFields_,
534  iter
535  )
536  {
538  dptf.vectorFields_.find(iter.key());
539 
540  if (dptfIter != dptf.vectorFields_.end())
541  {
542  mapper(*iter(), *dptfIter());
543  }
544  }
545 
546  forAllIter
547  (
549  sphericalTensorFields_,
550  iter
551  )
552  {
554  dptf.sphericalTensorFields_.find(iter.key());
555 
556  if (dptfIter != dptf.sphericalTensorFields_.end())
557  {
558  mapper(*iter(), *dptfIter());
559  }
560  }
561 
562  forAllIter
563  (
565  symmTensorFields_,
566  iter
567  )
568  {
570  dptf.symmTensorFields_.find(iter.key());
571 
572  if (dptfIter != dptf.symmTensorFields_.end())
573  {
574  mapper(*iter(), *dptfIter());
575  }
576  }
577 
578  forAllIter
579  (
581  tensorFields_,
582  iter
583  )
584  {
586  dptf.tensorFields_.find(iter.key());
587 
588  if (dptfIter != dptf.tensorFields_.end())
589  {
590  mapper(*iter(), *dptfIter());
591  }
592  }
593 }
594 
595 
596 template<class Type>
598 (
599  const fvPatchField<Type>& ptf
600 )
601 {
603 
604  const genericFvPatchField<Type>& dptf =
605  refCast<const genericFvPatchField<Type>>(ptf);
606 
607  forAllIter
608  (
610  scalarFields_,
611  iter
612  )
613  {
615  dptf.scalarFields_.find(iter.key());
616 
617  if (dptfIter != dptf.scalarFields_.end())
618  {
619  iter()->reset(*dptfIter());
620  }
621  }
622 
623  forAllIter
624  (
626  vectorFields_,
627  iter
628  )
629  {
631  dptf.vectorFields_.find(iter.key());
632 
633  if (dptfIter != dptf.vectorFields_.end())
634  {
635  iter()->reset(*dptfIter());
636  }
637  }
638 
639  forAllIter
640  (
642  sphericalTensorFields_,
643  iter
644  )
645  {
647  dptf.sphericalTensorFields_.find(iter.key());
648 
649  if (dptfIter != dptf.sphericalTensorFields_.end())
650  {
651  iter()->reset(*dptfIter());
652  }
653  }
654 
655  forAllIter
656  (
658  symmTensorFields_,
659  iter
660  )
661  {
663  dptf.symmTensorFields_.find(iter.key());
664 
665  if (dptfIter != dptf.symmTensorFields_.end())
666  {
667  iter()->reset(*dptfIter());
668  }
669  }
670 
671  forAllIter
672  (
674  tensorFields_,
675  iter
676  )
677  {
679  dptf.tensorFields_.find(iter.key());
680 
681  if (dptfIter != dptf.tensorFields_.end())
682  {
683  iter()->reset(*dptfIter());
684  }
685  }
686 }
687 
688 
689 template<class Type>
692 (
693  const tmp<scalarField>&
694 ) const
695 {
697  << "cannot be called for a genericFvPatchField"
698  " (actual type " << actualTypeName() << ")"
699  << "\n on patch " << this->patch().name()
700  << " of field " << this->internalField().name()
701  << " in file " << this->internalField().objectPath()
702  << "\n You are probably trying to solve for a field with a "
703  "generic boundary condition."
704  << abort(FatalError);
705 
706  return *this;
707 }
708 
709 
710 template<class Type>
713 (
714  const tmp<scalarField>&
715 ) const
716 {
718  << "cannot be called for a genericFvPatchField"
719  " (actual type " << actualTypeName() << ")"
720  << "\n on patch " << this->patch().name()
721  << " of field " << this->internalField().name()
722  << " in file " << this->internalField().objectPath()
723  << "\n You are probably trying to solve for a field with a "
724  "generic boundary condition."
725  << abort(FatalError);
726 
727  return *this;
728 }
729 
730 
731 template<class Type>
734 {
736  << "cannot be called for a genericFvPatchField"
737  " (actual type " << actualTypeName() << ")"
738  << "\n on patch " << this->patch().name()
739  << " of field " << this->internalField().name()
740  << " in file " << this->internalField().objectPath()
741  << "\n You are probably trying to solve for a field with a "
742  "generic boundary condition."
743  << abort(FatalError);
744 
745  return *this;
746 }
747 
748 template<class Type>
751 {
753  << "cannot be called for a genericFvPatchField"
754  " (actual type " << actualTypeName() << ")"
755  << "\n on patch " << this->patch().name()
756  << " of field " << this->internalField().name()
757  << " in file " << this->internalField().objectPath()
758  << "\n You are probably trying to solve for a field with a "
759  "generic boundary condition."
760  << abort(FatalError);
761 
762  return *this;
763 }
764 
765 
766 template<class Type>
768 {
769  writeEntry(os, "type", actualTypeName());
770 
771  forAllConstIter(dictionary, dict_, iter)
772  {
773  if (iter().keyword() != "type" && iter().keyword() != "value")
774  {
775  if
776  (
777  iter().isStream()
778  && iter().stream().size()
779  && iter().stream()[0].isWord()
780  && iter().stream()[0].wordToken() == "nonuniform"
781  )
782  {
783  if (scalarFields_.found(iter().keyword()))
784  {
785  writeEntry
786  (
787  os,
788  iter().keyword(),
789  *scalarFields_.find(iter().keyword())()
790  );
791  }
792  else if (vectorFields_.found(iter().keyword()))
793  {
794  writeEntry
795  (
796  os,
797  iter().keyword(),
798  *vectorFields_.find(iter().keyword())()
799  );
800  }
801  else if (sphericalTensorFields_.found(iter().keyword()))
802  {
803  writeEntry
804  (
805  os,
806  iter().keyword(),
807  *sphericalTensorFields_.find(iter().keyword())()
808  );
809  }
810  else if (symmTensorFields_.found(iter().keyword()))
811  {
812  writeEntry
813  (
814  os,
815  iter().keyword(),
816  *symmTensorFields_.find(iter().keyword())()
817  );
818  }
819  else if (tensorFields_.found(iter().keyword()))
820  {
821  writeEntry
822  (
823  os,
824  iter().keyword(),
825  *tensorFields_.find(iter().keyword())()
826  );
827  }
828  }
829  else
830  {
831  iter().write(os);
832  }
833  }
834  }
835 
836  writeEntry(os, "value", *this);
837 }
838 
839 
840 // ************************************************************************* //
#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...
static const char *const typeName
Definition: Field.H:105
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 putBack(const token &)
Put back token.
Definition: Istream.C:30
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
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
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Foam::fvPatchFieldMapper.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:87
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:361
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:197
virtual void map(const fvPatchField< Type > &, const fvPatchFieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:187
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:355
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
virtual const word & name() const
Return name.
Definition: fvPatch.H:146
This boundary condition provides a generic version of the calculated condition, useful as a fallback ...
virtual void write(Ostream &) const
Write.
tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
genericFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
virtual void map(const fvPatchField< Type > &, const fvPatchFieldMapper &)
Map the given fvPatchField onto this fvPatchField.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
word actualTypeName() const
Return the actual type name.
A class for managing temporary objects.
Definition: tmp.H:55
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
bool isPunctuation() const
Definition: tokenI.H:243
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
scalar number() const
Definition: tokenI.H:503
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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.
error FatalError
static const char nl
Definition: Ostream.H:260
dictionary dict
volScalarField & p