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 | Copyright (C) 2011-2016 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 )
37 :
39 {
41 }
42 
43 
44 template<class Type>
46 (
47  const pointPatch& p,
49  const dictionary& dict
50 )
51 :
53  actualTypeName_(dict.lookup("type")),
54  dict_(dict)
55 {
56  forAllConstIter(dictionary, dict_, iter)
57  {
58  if (iter().keyword() != "type")
59  {
60  if
61  (
62  iter().isStream()
63  && iter().stream().size()
64  )
65  {
66  ITstream& is = iter().stream();
67 
68  // Read first token
69  token firstToken(is);
70 
71  if
72  (
73  firstToken.isWord()
74  && firstToken.wordToken() == "nonuniform"
75  )
76  {
77  token fieldToken(is);
78 
79  if (!fieldToken.isCompound())
80  {
81  if
82  (
83  fieldToken.isLabel()
84  && fieldToken.labelToken() == 0
85  )
86  {
87  scalarFields_.insert
88  (
89  iter().keyword(),
90  new scalarField(0)
91  );
92  }
93  else
94  {
96  (
97  dict
98  ) << "\n token following 'nonuniform' "
99  "is not a compound"
100  << "\n on patch " << this->patch().name()
101  << " of field "
102  << this->internalField().name()
103  << " in file "
104  << this->internalField().objectPath()
105  << exit(FatalIOError);
106  }
107  }
108  else if
109  (
110  fieldToken.compoundToken().type()
111  == token::Compound<List<scalar>>::typeName
112  )
113  {
114  scalarField* fPtr = new scalarField;
115  fPtr->transfer
116  (
118  (
119  fieldToken.transferCompoundToken(is)
120  )
121  );
122 
123  if (fPtr->size() != this->size())
124  {
126  (
127  dict
128  ) << "\n size of field " << iter().keyword()
129  << " (" << fPtr->size() << ')'
130  << " is not the same size as the patch ("
131  << this->size() << ')'
132  << "\n on patch " << this->patch().name()
133  << " of field "
134  << this->internalField().name()
135  << " in file "
136  << this->internalField().objectPath()
137  << exit(FatalIOError);
138  }
139 
140  scalarFields_.insert(iter().keyword(), fPtr);
141  }
142  else if
143  (
144  fieldToken.compoundToken().type()
145  == token::Compound<List<vector>>::typeName
146  )
147  {
148  vectorField* fPtr = new vectorField;
149  fPtr->transfer
150  (
152  (
153  fieldToken.transferCompoundToken(is)
154  )
155  );
156 
157  if (fPtr->size() != this->size())
158  {
160  (
161  dict
162  ) << "\n size of field " << iter().keyword()
163  << " (" << fPtr->size() << ')'
164  << " is not the same size as the patch ("
165  << this->size() << ')'
166  << "\n on patch " << this->patch().name()
167  << " of field "
168  << this->internalField().name()
169  << " in file "
170  << this->internalField().objectPath()
171  << exit(FatalIOError);
172  }
173 
174  vectorFields_.insert(iter().keyword(), fPtr);
175  }
176  else if
177  (
178  fieldToken.compoundToken().type()
180  )
181  {
183  fPtr->transfer
184  (
186  <
188  >
189  (
190  fieldToken.transferCompoundToken(is)
191  )
192  );
193 
194  if (fPtr->size() != this->size())
195  {
197  (
198  dict
199  ) << "\n size of field " << iter().keyword()
200  << " (" << fPtr->size() << ')'
201  << " is not the same size as the patch ("
202  << this->size() << ')'
203  << "\n on patch " << this->patch().name()
204  << " of field "
205  << this->internalField().name()
206  << " in file "
207  << this->internalField().objectPath()
208  << exit(FatalIOError);
209  }
210 
211  sphericalTensorFields_.insert(iter().keyword(), fPtr);
212  }
213  else if
214  (
215  fieldToken.compoundToken().type()
217  )
218  {
219  symmTensorField* fPtr = new symmTensorField;
220  fPtr->transfer
221  (
223  <
225  >
226  (
227  fieldToken.transferCompoundToken(is)
228  )
229  );
230 
231  if (fPtr->size() != this->size())
232  {
234  (
235  dict
236  ) << "\n size of field " << iter().keyword()
237  << " (" << fPtr->size() << ')'
238  << " is not the same size as the patch ("
239  << this->size() << ')'
240  << "\n on patch " << this->patch().name()
241  << " of field "
242  << this->internalField().name()
243  << " in file "
244  << this->internalField().objectPath()
245  << exit(FatalIOError);
246  }
247 
248  symmTensorFields_.insert(iter().keyword(), fPtr);
249  }
250  else if
251  (
252  fieldToken.compoundToken().type()
253  == token::Compound<List<tensor>>::typeName
254  )
255  {
256  tensorField* fPtr = new tensorField;
257  fPtr->transfer
258  (
260  (
261  fieldToken.transferCompoundToken(is)
262  )
263  );
264 
265  if (fPtr->size() != this->size())
266  {
268  (
269  dict
270  ) << "\n size of field " << iter().keyword()
271  << " (" << fPtr->size() << ')'
272  << " is not the same size as the patch ("
273  << this->size() << ')'
274  << "\n on patch " << this->patch().name()
275  << " of field "
276  << this->internalField().name()
277  << " in file "
278  << this->internalField().objectPath()
279  << exit(FatalIOError);
280  }
281 
282  tensorFields_.insert(iter().keyword(), fPtr);
283  }
284  else
285  {
287  (
288  dict
289  ) << "\n compound " << fieldToken.compoundToken()
290  << " not supported"
291  << "\n on patch " << this->patch().name()
292  << " of field "
293  << this->internalField().name()
294  << " in file "
295  << this->internalField().objectPath()
296  << exit(FatalIOError);
297  }
298  }
299  }
300  }
301  }
302 }
303 
304 
305 template<class Type>
307 (
308  const genericPointPatchField<Type>& ptf,
309  const pointPatch& p,
311  const pointPatchFieldMapper& mapper
312 )
313 :
314  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
315  actualTypeName_(ptf.actualTypeName_),
316  dict_(ptf.dict_)
317 {
319  (
321  ptf.scalarFields_,
322  iter
323  )
324  {
325  scalarFields_.insert
326  (
327  iter.key(),
328  new scalarField(*iter(), mapper)
329  );
330  }
331 
333  (
335  ptf.vectorFields_,
336  iter
337  )
338  {
339  vectorFields_.insert
340  (
341  iter.key(),
342  new vectorField(*iter(), mapper)
343  );
344  }
345 
347  (
349  ptf.sphericalTensorFields_,
350  iter
351  )
352  {
353  sphericalTensorFields_.insert
354  (
355  iter.key(),
356  new sphericalTensorField(*iter(), mapper)
357  );
358  }
359 
361  (
363  ptf.symmTensorFields_,
364  iter
365  )
366  {
367  symmTensorFields_.insert
368  (
369  iter.key(),
370  new symmTensorField(*iter(), mapper)
371  );
372  }
373 
375  (
377  ptf.tensorFields_,
378  iter
379  )
380  {
381  tensorFields_.insert
382  (
383  iter.key(),
384  new tensorField(*iter(), mapper)
385  );
386  }
387 }
388 
389 
390 template<class Type>
392 (
393  const genericPointPatchField<Type>& ptf,
395 )
396 :
398  actualTypeName_(ptf.actualTypeName_),
399  dict_(ptf.dict_),
400  scalarFields_(ptf.scalarFields_),
401  vectorFields_(ptf.vectorFields_),
402  sphericalTensorFields_(ptf.sphericalTensorFields_),
403  symmTensorFields_(ptf.symmTensorFields_),
404  tensorFields_(ptf.tensorFields_)
405 {}
406 
407 
408 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
409 
410 template<class Type>
412 (
413  const pointPatchFieldMapper& m
414 )
415 {
416  forAllIter
417  (
419  scalarFields_,
420  iter
421  )
422  {
423  iter()->autoMap(m);
424  }
425 
426  forAllIter
427  (
429  vectorFields_,
430  iter
431  )
432  {
433  iter()->autoMap(m);
434  }
435 
436  forAllIter
437  (
439  sphericalTensorFields_,
440  iter
441  )
442  {
443  iter()->autoMap(m);
444  }
445 
446  forAllIter
447  (
449  symmTensorFields_,
450  iter
451  )
452  {
453  iter()->autoMap(m);
454  }
455 
456  forAllIter
457  (
459  tensorFields_,
460  iter
461  )
462  {
463  iter()->autoMap(m);
464  }
465 }
466 
467 
468 template<class Type>
470 (
471  const pointPatchField<Type>& ptf,
472  const labelList& addr
473 )
474 {
475  const genericPointPatchField<Type>& dptf =
476  refCast<const genericPointPatchField<Type>>(ptf);
477 
478  forAllIter
479  (
481  scalarFields_,
482  iter
483  )
484  {
486  dptf.scalarFields_.find(iter.key());
487 
488  if (dptfIter != scalarFields_.end())
489  {
490  iter()->rmap(*dptfIter(), addr);
491  }
492  }
493 
494  forAllIter
495  (
497  vectorFields_,
498  iter
499  )
500  {
502  dptf.vectorFields_.find(iter.key());
503 
504  if (dptfIter != vectorFields_.end())
505  {
506  iter()->rmap(*dptfIter(), addr);
507  }
508  }
509 
510  forAllIter
511  (
513  sphericalTensorFields_,
514  iter
515  )
516  {
518  dptf.sphericalTensorFields_.find(iter.key());
519 
520  if (dptfIter != sphericalTensorFields_.end())
521  {
522  iter()->rmap(*dptfIter(), addr);
523  }
524  }
525 
526  forAllIter
527  (
529  symmTensorFields_,
530  iter
531  )
532  {
534  dptf.symmTensorFields_.find(iter.key());
535 
536  if (dptfIter != symmTensorFields_.end())
537  {
538  iter()->rmap(*dptfIter(), addr);
539  }
540  }
541 
542  forAllIter
543  (
545  tensorFields_,
546  iter
547  )
548  {
550  dptf.tensorFields_.find(iter.key());
551 
552  if (dptfIter != tensorFields_.end())
553  {
554  iter()->rmap(*dptfIter(), addr);
555  }
556  }
557 }
558 
559 
560 template<class Type>
562 {
563  os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
564 
565  forAllConstIter(dictionary, dict_, iter)
566  {
567  if (iter().keyword() != "type")
568  {
569  if
570  (
571  iter().isStream()
572  && iter().stream().size()
573  && iter().stream()[0].isWord()
574  && iter().stream()[0].wordToken() == "nonuniform"
575  )
576  {
577  if (scalarFields_.found(iter().keyword()))
578  {
579  scalarFields_.find(iter().keyword())()
580  ->writeEntry(iter().keyword(), os);
581  }
582  else if (vectorFields_.found(iter().keyword()))
583  {
584  vectorFields_.find(iter().keyword())()
585  ->writeEntry(iter().keyword(), os);
586  }
587  else if (sphericalTensorFields_.found(iter().keyword()))
588  {
589  sphericalTensorFields_.find(iter().keyword())()
590  ->writeEntry(iter().keyword(), os);
591  }
592  else if (symmTensorFields_.found(iter().keyword()))
593  {
594  symmTensorFields_.find(iter().keyword())()
595  ->writeEntry(iter().keyword(), os);
596  }
597  else if (tensorFields_.found(iter().keyword()))
598  {
599  tensorFields_.find(iter().keyword())()
600  ->writeEntry(iter().keyword(), os);
601  }
602  }
603  else
604  {
605  iter().write(os);
606  }
607  }
608  }
609 }
610 
611 
612 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:254
virtual void write(Ostream &) const
Write.
dictionary dict
bool isWord() const
Definition: tokenI.H:213
Field< sphericalTensor > sphericalTensorField
Specialisation of Field<T> for sphericalTensor.
compound & transferCompoundToken(const Istream &is)
Definition: token.C:93
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
To & dynamicCast(From &r)
Reference type cast template function,.
Definition: typeInfo.H:85
An STL-conforming const_iterator.
Definition: HashTable.H:481
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
const word & wordToken() const
Definition: tokenI.H:218
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
A token holds items read from Istream.
Definition: token.H:69
Foam::pointPatchFieldMapper.
volVectorField vectorField(fieldObject, mesh)
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
A calculated boundary condition for pointField.
bool isCompound() const
Definition: tokenI.H:354
Abstract base class for point-mesh patch fields.
A templated class for holding compound tokens.
Definition: token.H:215
A generic version of calculatedPointPatchField, useful as a fallback for handling unknown patch types...
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
const compound & compoundToken() const
Definition: tokenI.H:359
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
volScalarField scalarField(fieldObject, mesh)
static const char nl
Definition: Ostream.H:262
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
label labelToken() const
Definition: tokenI.H:259
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
volScalarField & p
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Input token stream.
Definition: ITstream.H:49
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
IOerror FatalIOError