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-2015 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 
48 
49 template<class Type>
51 (
52  const pointPatch& p,
54  const dictionary& dict
55 )
56 :
58  actualTypeName_(dict.lookup("type")),
59  dict_(dict)
60 {
61  forAllConstIter(dictionary, dict_, iter)
62  {
63  if (iter().keyword() != "type")
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->dimensionedInternalField().name()
108  << " in file "
109  << this->dimensionedInternalField().objectPath()
110  << exit(FatalIOError);
111  }
112  }
113  else if
114  (
115  fieldToken.compoundToken().type()
116  == token::Compound<List<scalar> >::typeName
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->dimensionedInternalField().name()
140  << " in file "
141  << this->dimensionedInternalField().objectPath()
142  << exit(FatalIOError);
143  }
144 
145  scalarFields_.insert(iter().keyword(), fPtr);
146  }
147  else if
148  (
149  fieldToken.compoundToken().type()
150  == token::Compound<List<vector> >::typeName
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->dimensionedInternalField().name()
174  << " in file "
175  << this->dimensionedInternalField().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->dimensionedInternalField().name()
211  << " in file "
212  << this->dimensionedInternalField().objectPath()
213  << exit(FatalIOError);
214  }
215 
216  sphericalTensorFields_.insert(iter().keyword(), fPtr);
217  }
218  else if
219  (
220  fieldToken.compoundToken().type()
221  == token::Compound<List<symmTensor> >::typeName
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->dimensionedInternalField().name()
248  << " in file "
249  << this->dimensionedInternalField().objectPath()
250  << exit(FatalIOError);
251  }
252 
253  symmTensorFields_.insert(iter().keyword(), fPtr);
254  }
255  else if
256  (
257  fieldToken.compoundToken().type()
258  == token::Compound<List<tensor> >::typeName
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->dimensionedInternalField().name()
282  << " in file "
283  << this->dimensionedInternalField().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->dimensionedInternalField().name()
299  << " in file "
300  << this->dimensionedInternalField().objectPath()
301  << exit(FatalIOError);
302  }
303  }
304  }
305  }
306  }
307 }
308 
309 
310 template<class Type>
312 (
313  const genericPointPatchField<Type>& ptf,
314  const pointPatch& p,
316  const pointPatchFieldMapper& mapper
317 )
318 :
319  calculatedPointPatchField<Type>(ptf, p, iF, mapper),
320  actualTypeName_(ptf.actualTypeName_),
321  dict_(ptf.dict_)
322 {
324  (
326  ptf.scalarFields_,
327  iter
328  )
329  {
330  scalarFields_.insert
331  (
332  iter.key(),
333  new scalarField(*iter(), mapper)
334  );
335  }
336 
338  (
340  ptf.vectorFields_,
341  iter
342  )
343  {
344  vectorFields_.insert
345  (
346  iter.key(),
347  new vectorField(*iter(), mapper)
348  );
349  }
350 
352  (
355  iter
356  )
357  {
358  sphericalTensorFields_.insert
359  (
360  iter.key(),
361  new sphericalTensorField(*iter(), mapper)
362  );
363  }
364 
366  (
368  ptf.symmTensorFields_,
369  iter
370  )
371  {
372  symmTensorFields_.insert
373  (
374  iter.key(),
375  new symmTensorField(*iter(), mapper)
376  );
377  }
378 
380  (
382  ptf.tensorFields_,
383  iter
384  )
385  {
386  tensorFields_.insert
387  (
388  iter.key(),
389  new tensorField(*iter(), mapper)
390  );
391  }
392 }
393 
394 
395 template<class Type>
397 (
398  const genericPointPatchField<Type>& ptf,
400 )
401 :
403  actualTypeName_(ptf.actualTypeName_),
404  dict_(ptf.dict_),
405  scalarFields_(ptf.scalarFields_),
406  vectorFields_(ptf.vectorFields_),
407  sphericalTensorFields_(ptf.sphericalTensorFields_),
408  symmTensorFields_(ptf.symmTensorFields_),
409  tensorFields_(ptf.tensorFields_)
410 {}
411 
412 
413 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
414 
415 template<class Type>
417 (
418  const pointPatchFieldMapper& m
419 )
420 {
421  forAllIter
422  (
424  scalarFields_,
425  iter
426  )
427  {
428  iter()->autoMap(m);
429  }
430 
431  forAllIter
432  (
434  vectorFields_,
435  iter
436  )
437  {
438  iter()->autoMap(m);
439  }
440 
441  forAllIter
442  (
444  sphericalTensorFields_,
445  iter
446  )
447  {
448  iter()->autoMap(m);
449  }
450 
451  forAllIter
452  (
454  symmTensorFields_,
455  iter
456  )
457  {
458  iter()->autoMap(m);
459  }
460 
461  forAllIter
462  (
464  tensorFields_,
465  iter
466  )
467  {
468  iter()->autoMap(m);
469  }
470 }
471 
472 
473 template<class Type>
475 (
476  const pointPatchField<Type>& ptf,
477  const labelList& addr
478 )
479 {
480  const genericPointPatchField<Type>& dptf =
481  refCast<const genericPointPatchField<Type> >(ptf);
482 
483  forAllIter
484  (
486  scalarFields_,
487  iter
488  )
489  {
491  dptf.scalarFields_.find(iter.key());
492 
493  if (dptfIter != scalarFields_.end())
494  {
495  iter()->rmap(*dptfIter(), addr);
496  }
497  }
498 
499  forAllIter
500  (
502  vectorFields_,
503  iter
504  )
505  {
507  dptf.vectorFields_.find(iter.key());
508 
509  if (dptfIter != vectorFields_.end())
510  {
511  iter()->rmap(*dptfIter(), addr);
512  }
513  }
514 
515  forAllIter
516  (
518  sphericalTensorFields_,
519  iter
520  )
521  {
523  dptf.sphericalTensorFields_.find(iter.key());
524 
525  if (dptfIter != sphericalTensorFields_.end())
526  {
527  iter()->rmap(*dptfIter(), addr);
528  }
529  }
530 
531  forAllIter
532  (
534  symmTensorFields_,
535  iter
536  )
537  {
539  dptf.symmTensorFields_.find(iter.key());
540 
541  if (dptfIter != symmTensorFields_.end())
542  {
543  iter()->rmap(*dptfIter(), addr);
544  }
545  }
546 
547  forAllIter
548  (
550  tensorFields_,
551  iter
552  )
553  {
555  dptf.tensorFields_.find(iter.key());
556 
557  if (dptfIter != tensorFields_.end())
558  {
559  iter()->rmap(*dptfIter(), addr);
560  }
561  }
562 }
563 
564 
565 template<class Type>
567 {
568  os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
569 
570  forAllConstIter(dictionary, dict_, iter)
571  {
572  if (iter().keyword() != "type")
573  {
574  if
575  (
576  iter().isStream()
577  && iter().stream().size()
578  && iter().stream()[0].isWord()
579  && iter().stream()[0].wordToken() == "nonuniform"
580  )
581  {
582  if (scalarFields_.found(iter().keyword()))
583  {
584  scalarFields_.find(iter().keyword())()
585  ->writeEntry(iter().keyword(), os);
586  }
587  else if (vectorFields_.found(iter().keyword()))
588  {
589  vectorFields_.find(iter().keyword())()
590  ->writeEntry(iter().keyword(), os);
591  }
592  else if (sphericalTensorFields_.found(iter().keyword()))
593  {
594  sphericalTensorFields_.find(iter().keyword())()
595  ->writeEntry(iter().keyword(), os);
596  }
597  else if (symmTensorFields_.found(iter().keyword()))
598  {
599  symmTensorFields_.find(iter().keyword())()
600  ->writeEntry(iter().keyword(), os);
601  }
602  else if (tensorFields_.found(iter().keyword()))
603  {
604  tensorFields_.find(iter().keyword())()
605  ->writeEntry(iter().keyword(), os);
606  }
607  }
608  else
609  {
610  iter().write(os);
611  }
612  }
613  }
614 }
615 
616 
617 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
618 
619 } // End namespace Foam
620 
621 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
p
p
Definition: pEqn.H:62
Foam::token::Compound
A templated class for holding compound tokens.
Definition: token.H:213
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
dimensionedInternalField
rDeltaT dimensionedInternalField()
Foam::token::wordToken
const word & wordToken() const
Definition: tokenI.H:226
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition: HashTable.H:470
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::genericPointPatchField::actualTypeName_
word actualTypeName_
Definition: genericPointPatchField.H:57
Foam::genericPointPatchField::symmTensorFields_
HashPtrTable< symmTensorField > symmTensorFields_
Definition: genericPointPatchField.H:63
pointPatchFieldMapper.H
Foam::tensorField
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
Definition: primitiveFieldsFwd.H:52
Foam::FatalIOError
IOerror FatalIOError
Foam::genericPointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: genericPointPatchField.C:566
Foam::token
A token holds items read from Istream.
Definition: token.H:67
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Foam::token::compoundToken
const compound & compoundToken() const
Definition: tokenI.H:367
Foam::token::isCompound
bool isCompound() const
Definition: tokenI.H:362
Foam::genericPointPatchField::autoMap
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: genericPointPatchField.C:417
Foam::pointPatchField< Type >
Foam::genericPointPatchField::scalarFields_
HashPtrTable< scalarField > scalarFields_
Definition: genericPointPatchField.H:60
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:46
Foam::token::isLabel
bool isLabel() const
Definition: tokenI.H:262
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::symmTensorField
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
Definition: primitiveFieldsFwd.H:51
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:49
Foam::genericPointPatchField::genericPointPatchField
genericPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: genericPointPatchField.C:38
Foam::genericPointPatchField::dict_
dictionary dict_
Definition: genericPointPatchField.H:58
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::ITstream
Input token stream.
Definition: ITstream.H:49
Foam::calculatedPointPatchField
A calculated boundary condition for pointField.
Definition: calculatedPointPatchField.H:49
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::token::transferCompoundToken
compound & transferCompoundToken(const Istream &is)
Definition: token.C:93
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::token::isWord
bool isWord() const
Definition: tokenI.H:221
genericPointPatchField.H
Foam::sphericalTensorField
Field< sphericalTensor > sphericalTensorField
Specialisation of Field<T> for sphericalTensor.
Definition: primitiveFieldsFwd.H:50
Foam::genericPointPatchField::rmap
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
Definition: genericPointPatchField.C:475
Foam::genericPointPatchField
A generic version of calculatedPointPatchField, useful as a fallback for handling unknown patch types...
Definition: genericPointPatchField.H:51
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::genericPointPatchField::tensorFields_
HashPtrTable< tensorField > tensorFields_
Definition: genericPointPatchField.H:64
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::genericPointPatchField::sphericalTensorFields_
HashPtrTable< sphericalTensorField > sphericalTensorFields_
Definition: genericPointPatchField.H:62
Foam::dynamicCast
To & dynamicCast(From &r)
Reference type cast template function,.
Definition: typeInfo.H:85
Foam::List< scalar >
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::genericPointPatchField::vectorFields_
HashPtrTable< vectorField > vectorFields_
Definition: genericPointPatchField.H:61
Foam::token::labelToken
label labelToken() const
Definition: tokenI.H:267
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51