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 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const pointPatch& p,
41 )
42 :
44 {
46  (
47  "genericPointPatchField<Type>::genericPointPatchField"
48  "(const pointPatch& p, const DimensionedField<Type, volMesh>& iF)"
49  );
50 }
51 
52 
53 template<class Type>
55 (
56  const pointPatch& p,
58  const dictionary& dict
59 )
60 :
62  actualTypeName_(dict.lookup("type")),
63  dict_(dict)
64 {
65  forAllConstIter(dictionary, dict_, iter)
66  {
67  if (iter().keyword() != "type")
68  {
69  if
70  (
71  iter().isStream()
72  && iter().stream().size()
73  )
74  {
75  ITstream& is = iter().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
97  (
98  iter().keyword(),
99  new scalarField(0)
100  );
101  }
102  else
103  {
105  (
106  "genericPointPatchField<Type>::"
107  "genericPointPatchField"
108  "(const pointPatch&, const Field<Type>&, "
109  "const dictionary&)",
110  dict
111  ) << "\n token following 'nonuniform' "
112  "is not a compound"
113  << "\n on patch " << this->patch().name()
114  << " of field "
115  << this->dimensionedInternalField().name()
116  << " in file "
117  << this->dimensionedInternalField().objectPath()
118  << exit(FatalIOError);
119  }
120  }
121  else if
122  (
123  fieldToken.compoundToken().type()
124  == token::Compound<List<scalar> >::typeName
125  )
126  {
127  scalarField* fPtr = new scalarField;
128  fPtr->transfer
129  (
131  (
132  fieldToken.transferCompoundToken(is)
133  )
134  );
135 
136  if (fPtr->size() != this->size())
137  {
139  (
140  "genericPointPatchField<Type>::"
141  "genericPointPatchField"
142  "(const pointPatch&, const Field<Type>&, "
143  "const dictionary&)",
144  dict
145  ) << "\n size of field " << iter().keyword()
146  << " (" << fPtr->size() << ')'
147  << " is not the same size as the patch ("
148  << this->size() << ')'
149  << "\n on patch " << this->patch().name()
150  << " of field "
151  << this->dimensionedInternalField().name()
152  << " in file "
153  << this->dimensionedInternalField().objectPath()
154  << exit(FatalIOError);
155  }
156 
157  scalarFields_.insert(iter().keyword(), fPtr);
158  }
159  else if
160  (
161  fieldToken.compoundToken().type()
162  == token::Compound<List<vector> >::typeName
163  )
164  {
165  vectorField* fPtr = new vectorField;
166  fPtr->transfer
167  (
169  (
170  fieldToken.transferCompoundToken(is)
171  )
172  );
173 
174  if (fPtr->size() != this->size())
175  {
177  (
178  "genericPointPatchField<Type>::"
179  "genericPointPatchField"
180  "(const pointPatch&, const Field<Type>&, "
181  "const dictionary&)",
182  dict
183  ) << "\n size of field " << iter().keyword()
184  << " (" << fPtr->size() << ')'
185  << " is not the same size as the patch ("
186  << this->size() << ')'
187  << "\n on patch " << this->patch().name()
188  << " of field "
189  << this->dimensionedInternalField().name()
190  << " in file "
191  << this->dimensionedInternalField().objectPath()
192  << exit(FatalIOError);
193  }
194 
195  vectorFields_.insert(iter().keyword(), fPtr);
196  }
197  else if
198  (
199  fieldToken.compoundToken().type()
201  )
202  {
204  fPtr->transfer
205  (
207  <
209  >
210  (
211  fieldToken.transferCompoundToken(is)
212  )
213  );
214 
215  if (fPtr->size() != this->size())
216  {
218  (
219  "genericPointPatchField<Type>::"
220  "genericPointPatchField"
221  "(const pointPatch&, const Field<Type>&, "
222  "const dictionary&)",
223  dict
224  ) << "\n size of field " << iter().keyword()
225  << " (" << fPtr->size() << ')'
226  << " is not the same size as the patch ("
227  << this->size() << ')'
228  << "\n on patch " << this->patch().name()
229  << " of field "
230  << this->dimensionedInternalField().name()
231  << " in file "
232  << this->dimensionedInternalField().objectPath()
233  << exit(FatalIOError);
234  }
235 
236  sphericalTensorFields_.insert(iter().keyword(), fPtr);
237  }
238  else if
239  (
240  fieldToken.compoundToken().type()
241  == token::Compound<List<symmTensor> >::typeName
242  )
243  {
244  symmTensorField* fPtr = new symmTensorField;
245  fPtr->transfer
246  (
248  <
250  >
251  (
252  fieldToken.transferCompoundToken(is)
253  )
254  );
255 
256  if (fPtr->size() != this->size())
257  {
259  (
260  "genericPointPatchField<Type>::"
261  "genericPointPatchField"
262  "(const pointPatch&, const Field<Type>&, "
263  "const dictionary&)",
264  dict
265  ) << "\n size of field " << iter().keyword()
266  << " (" << fPtr->size() << ')'
267  << " is not the same size as the patch ("
268  << this->size() << ')'
269  << "\n on patch " << this->patch().name()
270  << " of field "
271  << this->dimensionedInternalField().name()
272  << " in file "
273  << this->dimensionedInternalField().objectPath()
274  << exit(FatalIOError);
275  }
276 
277  symmTensorFields_.insert(iter().keyword(), fPtr);
278  }
279  else if
280  (
281  fieldToken.compoundToken().type()
282  == token::Compound<List<tensor> >::typeName
283  )
284  {
285  tensorField* fPtr = new tensorField;
286  fPtr->transfer
287  (
289  (
290  fieldToken.transferCompoundToken(is)
291  )
292  );
293 
294  if (fPtr->size() != this->size())
295  {
297  (
298  "genericPointPatchField<Type>::"
299  "genericPointPatchField"
300  "(const pointPatch&, const Field<Type>&, "
301  "const dictionary&)",
302  dict
303  ) << "\n size of field " << iter().keyword()
304  << " (" << fPtr->size() << ')'
305  << " is not the same size as the patch ("
306  << this->size() << ')'
307  << "\n on patch " << this->patch().name()
308  << " of field "
309  << this->dimensionedInternalField().name()
310  << " in file "
311  << this->dimensionedInternalField().objectPath()
312  << exit(FatalIOError);
313  }
314 
315  tensorFields_.insert(iter().keyword(), fPtr);
316  }
317  else
318  {
320  (
321  "genericPointPatchField<Type>::"
322  "genericPointPatchField"
323  "(const pointPatch&, const Field<Type>&, "
324  "const dictionary&)",
325  dict
326  ) << "\n compound " << fieldToken.compoundToken()
327  << " not supported"
328  << "\n on patch " << this->patch().name()
329  << " of field "
330  << this->dimensionedInternalField().name()
331  << " in file "
332  << this->dimensionedInternalField().objectPath()
333  << exit(FatalIOError);
334  }
335  }
336  }
337  }
338  }
339 }
340 
341 
342 template<class Type>
344 (
345  const genericPointPatchField<Type>& ptf,
346  const pointPatch& p,
348  const pointPatchFieldMapper& mapper
349 )
350 :
351  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
352  actualTypeName_(ptf.actualTypeName_),
353  dict_(ptf.dict_)
354 {
356  (
358  ptf.scalarFields_,
359  iter
360  )
361  {
362  scalarFields_.insert
363  (
364  iter.key(),
365  new scalarField(*iter(), mapper)
366  );
367  }
368 
370  (
372  ptf.vectorFields_,
373  iter
374  )
375  {
376  vectorFields_.insert
377  (
378  iter.key(),
379  new vectorField(*iter(), mapper)
380  );
381  }
382 
384  (
386  ptf.sphericalTensorFields_,
387  iter
388  )
389  {
390  sphericalTensorFields_.insert
391  (
392  iter.key(),
393  new sphericalTensorField(*iter(), mapper)
394  );
395  }
396 
398  (
400  ptf.symmTensorFields_,
401  iter
402  )
403  {
404  symmTensorFields_.insert
405  (
406  iter.key(),
407  new symmTensorField(*iter(), mapper)
408  );
409  }
410 
412  (
414  ptf.tensorFields_,
415  iter
416  )
417  {
418  tensorFields_.insert
419  (
420  iter.key(),
421  new tensorField(*iter(), mapper)
422  );
423  }
424 }
425 
426 
427 template<class Type>
429 (
430  const genericPointPatchField<Type>& ptf,
432 )
433 :
435  actualTypeName_(ptf.actualTypeName_),
436  dict_(ptf.dict_),
437  scalarFields_(ptf.scalarFields_),
438  vectorFields_(ptf.vectorFields_),
439  sphericalTensorFields_(ptf.sphericalTensorFields_),
440  symmTensorFields_(ptf.symmTensorFields_),
441  tensorFields_(ptf.tensorFields_)
442 {}
443 
444 
445 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
446 
447 template<class Type>
449 (
450  const pointPatchFieldMapper& m
451 )
452 {
453  forAllIter
454  (
456  scalarFields_,
457  iter
458  )
459  {
460  iter()->autoMap(m);
461  }
462 
463  forAllIter
464  (
466  vectorFields_,
467  iter
468  )
469  {
470  iter()->autoMap(m);
471  }
472 
473  forAllIter
474  (
476  sphericalTensorFields_,
477  iter
478  )
479  {
480  iter()->autoMap(m);
481  }
482 
483  forAllIter
484  (
486  symmTensorFields_,
487  iter
488  )
489  {
490  iter()->autoMap(m);
491  }
492 
493  forAllIter
494  (
496  tensorFields_,
497  iter
498  )
499  {
500  iter()->autoMap(m);
501  }
502 }
503 
504 
505 template<class Type>
507 (
508  const pointPatchField<Type>& ptf,
509  const labelList& addr
510 )
511 {
512  const genericPointPatchField<Type>& dptf =
513  refCast<const genericPointPatchField<Type> >(ptf);
514 
515  forAllIter
516  (
518  scalarFields_,
519  iter
520  )
521  {
523  dptf.scalarFields_.find(iter.key());
524 
525  if (dptfIter != scalarFields_.end())
526  {
527  iter()->rmap(*dptfIter(), addr);
528  }
529  }
530 
531  forAllIter
532  (
534  vectorFields_,
535  iter
536  )
537  {
539  dptf.vectorFields_.find(iter.key());
540 
541  if (dptfIter != vectorFields_.end())
542  {
543  iter()->rmap(*dptfIter(), addr);
544  }
545  }
546 
547  forAllIter
548  (
550  sphericalTensorFields_,
551  iter
552  )
553  {
555  dptf.sphericalTensorFields_.find(iter.key());
556 
557  if (dptfIter != sphericalTensorFields_.end())
558  {
559  iter()->rmap(*dptfIter(), addr);
560  }
561  }
562 
563  forAllIter
564  (
566  symmTensorFields_,
567  iter
568  )
569  {
571  dptf.symmTensorFields_.find(iter.key());
572 
573  if (dptfIter != symmTensorFields_.end())
574  {
575  iter()->rmap(*dptfIter(), addr);
576  }
577  }
578 
579  forAllIter
580  (
582  tensorFields_,
583  iter
584  )
585  {
587  dptf.tensorFields_.find(iter.key());
588 
589  if (dptfIter != tensorFields_.end())
590  {
591  iter()->rmap(*dptfIter(), addr);
592  }
593  }
594 }
595 
596 
597 template<class Type>
599 {
600  os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
601 
602  forAllConstIter(dictionary, dict_, iter)
603  {
604  if (iter().keyword() != "type")
605  {
606  if
607  (
608  iter().isStream()
609  && iter().stream().size()
610  && iter().stream()[0].isWord()
611  && iter().stream()[0].wordToken() == "nonuniform"
612  )
613  {
614  if (scalarFields_.found(iter().keyword()))
615  {
616  scalarFields_.find(iter().keyword())()
617  ->writeEntry(iter().keyword(), os);
618  }
619  else if (vectorFields_.found(iter().keyword()))
620  {
621  vectorFields_.find(iter().keyword())()
622  ->writeEntry(iter().keyword(), os);
623  }
624  else if (sphericalTensorFields_.found(iter().keyword()))
625  {
626  sphericalTensorFields_.find(iter().keyword())()
627  ->writeEntry(iter().keyword(), os);
628  }
629  else if (symmTensorFields_.found(iter().keyword()))
630  {
631  symmTensorFields_.find(iter().keyword())()
632  ->writeEntry(iter().keyword(), os);
633  }
634  else if (tensorFields_.found(iter().keyword()))
635  {
636  tensorFields_.find(iter().keyword())()
637  ->writeEntry(iter().keyword(), os);
638  }
639  }
640  else
641  {
642  iter().write(os);
643  }
644  }
645  }
646 }
647 
648 
649 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
650 
651 } // End namespace Foam
652 
653 // ************************************************************************* //
A generic version of calculatedPointPatchField, useful as a fallback for handling unknown patch types...
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
bool isWord() const
Definition: tokenI.H:221
bool isLabel() const
Definition: tokenI.H:262
Input token stream.
Definition: ITstream.H:49
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
An STL-conforming const_iterator.
Definition: HashTable.H:470
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
#define forAllIter(Container, container, iter)
Definition: UList.H:440
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
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
const word & wordToken() const
Definition: tokenI.H:226
const compound & compoundToken() const
Definition: tokenI.H:367
Namespace for OpenFOAM.
virtual void write(Ostream &) const
Write.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
dictionary dict
Abstract base class for point-mesh patch fields.
static const char nl
Definition: Ostream.H:260
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
IOerror FatalIOError
volScalarField & p
Definition: createFields.H:51
A calculated boundary condition for pointField.
Field< vector > vectorField
Specialisation of Field<T> for vector.
A templated class for holding compound tokens.
Definition: token.H:213
A token holds items read from Istream.
Definition: token.H:67
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::pointPatchFieldMapper.
rDeltaT dimensionedInternalField()
compound & transferCompoundToken(const Istream &is)
Definition: token.C:93
label labelToken() const
Definition: tokenI.H:267
bool isCompound() const
Definition: tokenI.H:362
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
To & dynamicCast(From &r)
Reference type cast template function,.
Definition: typeInfo.H:85
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
Field< sphericalTensor > sphericalTensorField
Specialisation of Field<T> for sphericalTensor.
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50