Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / genericPatchFields / genericPointPatchField / genericPointPatchField.C
blobbb8fe3f6fe38581f3de9dd720cd852d4bc2b60c6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "genericPointPatchField.H"
27 #include "pointPatchFieldMapper.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 template<class Type>
37 genericPointPatchField<Type>::genericPointPatchField
39     const pointPatch& p,
40     const DimensionedField<Type, pointMesh>& iF
43     calculatedPointPatchField<Type>(p, iF)
45     notImplemented
46     (
47         "genericPointPatchField<Type>::genericPointPatchField"
48         "(const pointPatch& p, const DimensionedField<Type, volMesh>& iF)"
49     );
53 template<class Type>
54 genericPointPatchField<Type>::genericPointPatchField
56     const pointPatch& p,
57     const DimensionedField<Type, pointMesh>& iF,
58     const dictionary& dict
61     calculatedPointPatchField<Type>(p, iF, dict),
62     actualTypeName_(dict.lookup("type")),
63     dict_(dict)
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();
77                 // Read first token
78                 token firstToken(is);
80                 if
81                 (
82                     firstToken.isWord()
83                  && firstToken.wordToken() == "nonuniform"
84                 )
85                 {
86                     token fieldToken(is);
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                         {
104                             FatalIOErrorIn
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                         (
130                             dynamicCast<token::Compound<List<scalar> > >
131                             (
132                                 fieldToken.transferCompoundToken()
133                             )
134                         );
136                         if (fPtr->size() != this->size())
137                         {
138                             FatalIOErrorIn
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                         }
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                         (
168                             dynamicCast<token::Compound<List<vector> > >
169                             (
170                                 fieldToken.transferCompoundToken()
171                             )
172                         );
174                         if (fPtr->size() != this->size())
175                         {
176                             FatalIOErrorIn
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                         }
195                         vectorFields_.insert(iter().keyword(), fPtr);
196                     }
197                     else if
198                     (
199                         fieldToken.compoundToken().type()
200                      == token::Compound<List<sphericalTensor> >::typeName
201                     )
202                     {
203                         sphericalTensorField* fPtr = new sphericalTensorField;
204                         fPtr->transfer
205                         (
206                             dynamicCast
207                             <
208                                 token::Compound<List<sphericalTensor> >
209                             >
210                             (
211                                 fieldToken.transferCompoundToken()
212                             )
213                         );
215                         if (fPtr->size() != this->size())
216                         {
217                             FatalIOErrorIn
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                         }
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                         (
247                             dynamicCast
248                             <
249                                 token::Compound<List<symmTensor> >
250                             >
251                             (
252                                 fieldToken.transferCompoundToken()
253                             )
254                         );
256                         if (fPtr->size() != this->size())
257                         {
258                             FatalIOErrorIn
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                         }
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                         (
288                             dynamicCast<token::Compound<List<tensor> > >
289                             (
290                                 fieldToken.transferCompoundToken()
291                             )
292                         );
294                         if (fPtr->size() != this->size())
295                         {
296                             FatalIOErrorIn
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                         }
315                         tensorFields_.insert(iter().keyword(), fPtr);
316                     }
317                     else
318                     {
319                         FatalIOErrorIn
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     }
342 template<class Type>
343 genericPointPatchField<Type>::genericPointPatchField
345     const genericPointPatchField<Type>& ptf,
346     const pointPatch& p,
347     const DimensionedField<Type, pointMesh>& iF,
348     const pointPatchFieldMapper& mapper
351     calculatedPointPatchField<Type>(ptf, p, iF, mapper),
352     actualTypeName_(ptf.actualTypeName_),
353     dict_(ptf.dict_)
355     forAllConstIter
356     (
357         HashPtrTable<scalarField>,
358         ptf.scalarFields_,
359         iter
360     )
361     {
362         scalarFields_.insert
363         (
364             iter.key(),
365             new scalarField(*iter(), mapper)
366         );
367     }
369     forAllConstIter
370     (
371         HashPtrTable<vectorField>,
372         ptf.vectorFields_,
373         iter
374     )
375     {
376         vectorFields_.insert
377         (
378             iter.key(),
379             new vectorField(*iter(), mapper)
380         );
381     }
383     forAllConstIter
384     (
385         HashPtrTable<sphericalTensorField>,
386         ptf.sphericalTensorFields_,
387         iter
388     )
389     {
390         sphericalTensorFields_.insert
391         (
392             iter.key(),
393             new sphericalTensorField(*iter(), mapper)
394         );
395     }
397     forAllConstIter
398     (
399         HashPtrTable<symmTensorField>,
400         ptf.symmTensorFields_,
401         iter
402     )
403     {
404         symmTensorFields_.insert
405         (
406             iter.key(),
407             new symmTensorField(*iter(), mapper)
408         );
409     }
411     forAllConstIter
412     (
413         HashPtrTable<tensorField>,
414         ptf.tensorFields_,
415         iter
416     )
417     {
418         tensorFields_.insert
419         (
420             iter.key(),
421             new tensorField(*iter(), mapper)
422         );
423     }
427 template<class Type>
428 genericPointPatchField<Type>::genericPointPatchField
430     const genericPointPatchField<Type>& ptf,
431     const DimensionedField<Type, pointMesh>& iF
434     calculatedPointPatchField<Type>(ptf, iF),
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_)
445 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
447 template<class Type>
448 void genericPointPatchField<Type>::autoMap
450     const pointPatchFieldMapper& m
453     forAllIter
454     (
455         HashPtrTable<scalarField>,
456         scalarFields_,
457         iter
458     )
459     {
460         iter()->autoMap(m);
461     }
463     forAllIter
464     (
465         HashPtrTable<vectorField>,
466         vectorFields_,
467         iter
468     )
469     {
470         iter()->autoMap(m);
471     }
473     forAllIter
474     (
475         HashPtrTable<sphericalTensorField>,
476         sphericalTensorFields_,
477         iter
478     )
479     {
480         iter()->autoMap(m);
481     }
483     forAllIter
484     (
485         HashPtrTable<symmTensorField>,
486         symmTensorFields_,
487         iter
488     )
489     {
490         iter()->autoMap(m);
491     }
493     forAllIter
494     (
495         HashPtrTable<tensorField>,
496         tensorFields_,
497         iter
498     )
499     {
500         iter()->autoMap(m);
501     }
505 template<class Type>
506 void genericPointPatchField<Type>::rmap
508     const pointPatchField<Type>& ptf,
509     const labelList& addr
512     const genericPointPatchField<Type>& dptf =
513         refCast<const genericPointPatchField<Type> >(ptf);
515     forAllIter
516     (
517         HashPtrTable<scalarField>,
518         scalarFields_,
519         iter
520     )
521     {
522         HashPtrTable<scalarField>::const_iterator dptfIter =
523             dptf.scalarFields_.find(iter.key());
525         if (dptfIter != scalarFields_.end())
526         {
527             iter()->rmap(*dptfIter(), addr);
528         }
529     }
531     forAllIter
532     (
533         HashPtrTable<vectorField>,
534         vectorFields_,
535         iter
536     )
537     {
538         HashPtrTable<vectorField>::const_iterator dptfIter =
539             dptf.vectorFields_.find(iter.key());
541         if (dptfIter != vectorFields_.end())
542         {
543             iter()->rmap(*dptfIter(), addr);
544         }
545     }
547     forAllIter
548     (
549         HashPtrTable<sphericalTensorField>,
550         sphericalTensorFields_,
551         iter
552     )
553     {
554         HashPtrTable<sphericalTensorField>::const_iterator dptfIter =
555             dptf.sphericalTensorFields_.find(iter.key());
557         if (dptfIter != sphericalTensorFields_.end())
558         {
559             iter()->rmap(*dptfIter(), addr);
560         }
561     }
563     forAllIter
564     (
565         HashPtrTable<symmTensorField>,
566         symmTensorFields_,
567         iter
568     )
569     {
570         HashPtrTable<symmTensorField>::const_iterator dptfIter =
571             dptf.symmTensorFields_.find(iter.key());
573         if (dptfIter != symmTensorFields_.end())
574         {
575             iter()->rmap(*dptfIter(), addr);
576         }
577     }
579     forAllIter
580     (
581         HashPtrTable<tensorField>,
582         tensorFields_,
583         iter
584     )
585     {
586         HashPtrTable<tensorField>::const_iterator dptfIter =
587             dptf.tensorFields_.find(iter.key());
589         if (dptfIter != tensorFields_.end())
590         {
591             iter()->rmap(*dptfIter(), addr);
592         }
593     }
597 template<class Type>
598 void genericPointPatchField<Type>::write(Ostream& os) const
600     os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
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     }
649 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
651 } // End namespace Foam
653 // ************************************************************************* //