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 "fieldMapper.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const pointPatch& p,
36  const dictionary& dict
37 )
38 :
39  genericFieldBase(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  << "\n token following 'nonuniform' "
84  "is not a compound"
85  << "\n on patch " << this->patch().name()
86  << " of field "
87  << this->internalField().name()
88  << " in file "
89  << this->internalField().objectPath()
90  << exit(FatalIOError);
91  }
92  }
93 
94  #define ReadTypeField(Type, nullArg) \
95  else if \
96  ( \
97  fieldToken.compoundToken().type() \
98  == token::Compound<List<Type>>::typeName \
99  ) \
100  { \
101  Field<Type>* fPtr = new Field<Type>; \
102  fPtr->transfer \
103  ( \
104  dynamicCast<token::Compound<List<Type>>> \
105  ( \
106  fieldToken.transferCompoundToken(is) \
107  ) \
108  ); \
109  \
110  if (fPtr->size() != this->size()) \
111  { \
112  FatalIOErrorInFunction(dict) \
113  << "\n size of field " \
114  << iter().keyword() \
115  << " (" << fPtr->size() << ')' \
116  << " is not the same size as the patch (" \
117  << this->size() << ')' \
118  << "\n on patch " \
119  << this->patch().name() \
120  << " of field " \
121  << this->internalField().name() \
122  << " in file " \
123  << this->internalField().objectPath() \
124  << exit(FatalIOError); \
125  } \
126  \
127  Type##Fields_.insert(iter().keyword(), fPtr); \
128  }
129  FOR_ALL_FIELD_TYPES(ReadTypeField)
130  #undef ReadTypeField
131  }
132  }
133  }
134  }
135 }
136 
137 
138 template<class Type>
140 (
141  const genericPointPatchField<Type>& ptf,
142  const pointPatch& p,
144  const fieldMapper& mapper
145 )
146 :
147  genericFieldBase(ptf),
148  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
149  dict_(ptf.dict_)
150 {
151  #define MapTypeFields(Type, nullArg) \
152  forAllConstIter(HashPtrTable<Field<Type>>, ptf.Type##Fields_, iter) \
153  { \
154  Type##Fields_.insert \
155  ( \
156  iter.key(), \
157  mapper(*iter()).ptr() \
158  ); \
159  }
160  FOR_ALL_FIELD_TYPES(MapTypeFields);
161  #undef MapTypeFields
162 }
163 
164 
165 template<class Type>
167 (
168  const genericPointPatchField<Type>& ptf,
170 )
171 :
172  genericFieldBase(ptf),
173  calculatedPointPatchField<Type>(ptf, iF),
174  dict_(ptf.dict_),
175  scalarFields_(ptf.scalarFields_),
176  vectorFields_(ptf.vectorFields_),
177  sphericalTensorFields_(ptf.sphericalTensorFields_),
178  symmTensorFields_(ptf.symmTensorFields_),
179  tensorFields_(ptf.tensorFields_)
180 {}
181 
182 
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 
185 template<class Type>
187 (
188  const pointPatchField<Type>& ptf,
189  const fieldMapper& mapper
190 )
191 {
192  const genericPointPatchField<Type>& dptf =
193  refCast<const genericPointPatchField<Type>>(ptf);
194 
195  #define MapTypeFields(Type, nullArg) \
196  forAllIter(HashPtrTable<Field<Type>>, Type##Fields_, iter) \
197  { \
198  HashPtrTable<Field<Type>>::const_iterator dptfIter = \
199  dptf.Type##Fields_.find(iter.key()); \
200  \
201  if (dptfIter != dptf.Type##Fields_.end()) \
202  { \
203  mapper(*iter(), *dptfIter()); \
204  } \
205  }
207  #undef MapTypeFields
208 }
209 
210 
211 template<class Type>
213 (
214  const pointPatchField<Type>& ptf
215 )
216 {
217  const genericPointPatchField<Type>& dptf =
218  refCast<const genericPointPatchField<Type>>(ptf);
219 
220  #define ResetTypeFields(Type, nullArg) \
221  forAllIter(HashPtrTable<Field<Type>>, Type##Fields_, iter) \
222  { \
223  HashPtrTable<Field<Type>>::const_iterator dptfIter = \
224  dptf.Type##Fields_.find(iter.key()); \
225  \
226  if (dptfIter != dptf.Type##Fields_.end()) \
227  { \
228  iter()->reset(*dptfIter()); \
229  } \
230  }
232  #undef ResetTypeFields
233 }
234 
235 
236 template<class Type>
238 {
239  writeEntry(os, "type", actualTypeName());
240 
241  forAllConstIter(dictionary, dict_, iter)
242  {
243  if (iter().keyword() != "type")
244  {
245  if
246  (
247  iter().isStream()
248  && iter().stream().size()
249  && iter().stream()[0].isWord()
250  && iter().stream()[0].wordToken() == "nonuniform"
251  )
252  {
253  #define WriteTypeFieldEntry(Type, nullArg) \
254  else if (Type##Fields_.found(iter().keyword())) \
255  { \
256  writeEntry \
257  ( \
258  os, \
259  iter().keyword(), \
260  *Type##Fields_.find(iter().keyword())() \
261  ); \
262  }
264  #undef WriteTypeFieldEntry
265  }
266  else
267  {
268  iter().write(os);
269  }
270  }
271  }
272 }
273 
274 
275 // ************************************************************************* //
#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...
Input token stream.
Definition: ITstream.H:53
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:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Base class for generic field types. Facilitates down-casting so that the actual type can be queried.
This boundary condition provides a generic version of the calculated condition, useful as a fallback ...
virtual void write(Ostream &) const
Write.
virtual void reset(const pointPatchField< Type > &)
Reset the pointPatchField to the given pointPatchField.
virtual void map(const pointPatchField< Type > &, const fieldMapper &)
Map the given pointPatchField onto this pointPatchField.
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
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 token holds items read from Istream.
Definition: token.H:73
bool isLabel() const
Definition: tokenI.H:571
label labelToken() const
Definition: tokenI.H:590
bool isCompound() const
Definition: tokenI.H:784
bool isWord() const
Definition: tokenI.H:298
const word & wordToken() const
Definition: tokenI.H:303
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define WriteTypeFieldEntry(Type, nullArg)
#define ResetTypeFields(Type, nullArg)
#define MapTypeFields(Type, nullArg)
#define ReadTypeField(Type, nullArg)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
IOerror FatalIOError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
dictionary dict
volScalarField & p