initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / pointPatchFields / basic / generic / genericPointPatchField.C
blob7268125855caf2bc5059357500e03626db2a1a1a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "genericPointPatchField.H"
28 #include "pointPatchFieldMapper.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
37 template<class Type>
38 genericPointPatchField<Type>::genericPointPatchField
40     const pointPatch& p,
41     const DimensionedField<Type, pointMesh>& iF
44     calculatedPointPatchField<Type>(p, iF)
46     notImplemented
47     (
48         "genericPointPatchField<Type>::genericPointPatchField"
49         "(const pointPatch& p, const DimensionedField<Type, volMesh>& iF)"
50     );
54 template<class Type>
55 genericPointPatchField<Type>::genericPointPatchField
57     const pointPatch& p,
58     const DimensionedField<Type, pointMesh>& iF,
59     const dictionary& dict
62     calculatedPointPatchField<Type>(p, iF, dict),
63     actualTypeName_(dict.lookup("type")),
64     dict_(dict)
66     for
67     (
68         dictionary::const_iterator iter = dict_.begin();
69         iter != dict_.end();
70         ++iter
71     )
72     {
73         if (iter().keyword() != "type")
74         {
75             if
76             (
77                 iter().isStream()
78              && iter().stream().size()
79             )
80             {
81                 ITstream& is = iter().stream();
83                 // Read first token
84                 token firstToken(is);
86                 if
87                 (
88                     firstToken.isWord()
89                  && firstToken.wordToken() == "nonuniform"
90                 )
91                 {
92                     token fieldToken(is);
94                     if (!fieldToken.isCompound())
95                     {
96                         if
97                         (
98                             fieldToken.isLabel()
99                          && fieldToken.labelToken() == 0
100                         )
101                         {
102                             scalarFields_.insert
103                             (
104                                 iter().keyword(),
105                                 new scalarField(0)
106                             );
107                         }
108                         else
109                         {
110                             FatalIOErrorIn
111                             (
112                                 "genericPointPatchField<Type>::"
113                                 "genericPointPatchField"
114                                 "(const pointPatch&, const Field<Type>&, "
115                                 "const dictionary&)",
116                                 dict
117                             )   << "\n    token following 'nonuniform' "
118                                   "is not a compound"
119                                 << "\n    on patch " << this->patch().name()
120                                 << " of field "
121                                 << this->dimensionedInternalField().name()
122                                 << " in file "
123                                 << this->dimensionedInternalField().objectPath()
124                             << exit(FatalIOError);
125                         }
126                     }
127                     else if
128                     (
129                         fieldToken.compoundToken().type()
130                      == token::Compound<List<scalar> >::typeName
131                     )
132                     {
133                         scalarField* fPtr = new scalarField;
134                         fPtr->transfer
135                         (
136                             dynamicCast<token::Compound<List<scalar> > >
137                             (
138                                 fieldToken.transferCompoundToken()
139                             )
140                         );
142                         if (fPtr->size() != this->size())
143                         {
144                             FatalIOErrorIn
145                             (
146                                 "genericPointPatchField<Type>::"
147                                 "genericPointPatchField"
148                                 "(const pointPatch&, const Field<Type>&, "
149                                 "const dictionary&)",
150                                 dict
151                             )   << "\n    size of field " << iter().keyword()
152                                 << " (" << fPtr->size() << ')'
153                                 << " is not the same size as the patch ("
154                                 << this->size() << ')'
155                                 << "\n    on patch " << this->patch().name()
156                                 << " of field "
157                                 << this->dimensionedInternalField().name()
158                                 << " in file "
159                                 << this->dimensionedInternalField().objectPath()
160                                 << exit(FatalIOError);
161                         }
163                         scalarFields_.insert(iter().keyword(), fPtr);
164                     }
165                     else if
166                     (
167                         fieldToken.compoundToken().type()
168                      == token::Compound<List<vector> >::typeName
169                     )
170                     {
171                         vectorField* fPtr = new vectorField;
172                         fPtr->transfer
173                         (
174                             dynamicCast<token::Compound<List<vector> > >
175                             (
176                                 fieldToken.transferCompoundToken()
177                             )
178                         );
180                         if (fPtr->size() != this->size())
181                         {
182                             FatalIOErrorIn
183                             (
184                                 "genericPointPatchField<Type>::"
185                                 "genericPointPatchField"
186                                 "(const pointPatch&, const Field<Type>&, "
187                                 "const dictionary&)",
188                                 dict
189                             )   << "\n    size of field " << iter().keyword()
190                                 << " (" << fPtr->size() << ')'
191                                 << " is not the same size as the patch ("
192                                 << this->size() << ')'
193                                 << "\n    on patch " << this->patch().name()
194                                 << " of field "
195                                 << this->dimensionedInternalField().name()
196                                 << " in file "
197                                 << this->dimensionedInternalField().objectPath()
198                                 << exit(FatalIOError);
199                         }
201                         vectorFields_.insert(iter().keyword(), fPtr);
202                     }
203                     else if
204                     (
205                         fieldToken.compoundToken().type()
206                      == token::Compound<List<sphericalTensor> >::typeName
207                     )
208                     {
209                         sphericalTensorField* fPtr = new sphericalTensorField;
210                         fPtr->transfer
211                         (
212                             dynamicCast
213                             <
214                                 token::Compound<List<sphericalTensor> >
215                             >
216                             (
217                                 fieldToken.transferCompoundToken()
218                             )
219                         );
221                         if (fPtr->size() != this->size())
222                         {
223                             FatalIOErrorIn
224                             (
225                                 "genericPointPatchField<Type>::"
226                                 "genericPointPatchField"
227                                 "(const pointPatch&, const Field<Type>&, "
228                                 "const dictionary&)",
229                                 dict
230                             )   << "\n    size of field " << iter().keyword()
231                                 << " (" << fPtr->size() << ')'
232                                 << " is not the same size as the patch ("
233                                 << this->size() << ')'
234                                 << "\n    on patch " << this->patch().name()
235                                 << " of field "
236                                 << this->dimensionedInternalField().name()
237                                 << " in file "
238                                 << this->dimensionedInternalField().objectPath()
239                                 << exit(FatalIOError);
240                         }
242                         sphericalTensorFields_.insert(iter().keyword(), fPtr);
243                     }
244                     else if
245                     (
246                         fieldToken.compoundToken().type()
247                      == token::Compound<List<symmTensor> >::typeName
248                     )
249                     {
250                         symmTensorField* fPtr = new symmTensorField;
251                         fPtr->transfer
252                         (
253                             dynamicCast
254                             <
255                                 token::Compound<List<symmTensor> >
256                             >
257                             (
258                                 fieldToken.transferCompoundToken()
259                             )
260                         );
262                         if (fPtr->size() != this->size())
263                         {
264                             FatalIOErrorIn
265                             (
266                                 "genericPointPatchField<Type>::"
267                                 "genericPointPatchField"
268                                 "(const pointPatch&, const Field<Type>&, "
269                                 "const dictionary&)",
270                                 dict
271                             )   << "\n    size of field " << iter().keyword()
272                                 << " (" << fPtr->size() << ')'
273                                 << " is not the same size as the patch ("
274                                 << this->size() << ')'
275                                 << "\n    on patch " << this->patch().name()
276                                 << " of field "
277                                 << this->dimensionedInternalField().name()
278                                 << " in file "
279                                 << this->dimensionedInternalField().objectPath()
280                                 << exit(FatalIOError);
281                         }
283                         symmTensorFields_.insert(iter().keyword(), fPtr);
284                     }
285                     else if
286                     (
287                         fieldToken.compoundToken().type()
288                      == token::Compound<List<tensor> >::typeName
289                     )
290                     {
291                         tensorField* fPtr = new tensorField;
292                         fPtr->transfer
293                         (
294                             dynamicCast<token::Compound<List<tensor> > >
295                             (
296                                 fieldToken.transferCompoundToken()
297                             )
298                         );
300                         if (fPtr->size() != this->size())
301                         {
302                             FatalIOErrorIn
303                             (
304                                 "genericPointPatchField<Type>::"
305                                 "genericPointPatchField"
306                                 "(const pointPatch&, const Field<Type>&, "
307                                 "const dictionary&)",
308                                 dict
309                             )   << "\n    size of field " << iter().keyword()
310                                 << " (" << fPtr->size() << ')'
311                                 << " is not the same size as the patch ("
312                                 << this->size() << ')'
313                                 << "\n    on patch " << this->patch().name()
314                                 << " of field "
315                                 << this->dimensionedInternalField().name()
316                                 << " in file "
317                                 << this->dimensionedInternalField().objectPath()
318                                 << exit(FatalIOError);
319                         }
321                         tensorFields_.insert(iter().keyword(), fPtr);
322                     }
323                     else
324                     {
325                         FatalIOErrorIn
326                         (
327                             "genericPointPatchField<Type>::"
328                             "genericPointPatchField"
329                             "(const pointPatch&, const Field<Type>&, "
330                             "const dictionary&)",
331                             dict
332                         )   << "\n    compound " << fieldToken.compoundToken()
333                             << " not supported"
334                             << "\n    on patch " << this->patch().name()
335                             << " of field "
336                             << this->dimensionedInternalField().name()
337                             << " in file "
338                             << this->dimensionedInternalField().objectPath()
339                             << exit(FatalIOError);
340                     }
341                 }
342             }
343         }
344     }
348 template<class Type>
349 genericPointPatchField<Type>::genericPointPatchField
351     const genericPointPatchField<Type>& ptf,
352     const pointPatch& p,
353     const DimensionedField<Type, pointMesh>& iF,
354     const pointPatchFieldMapper& mapper
357     calculatedPointPatchField<Type>(ptf, p, iF, mapper),
358     actualTypeName_(ptf.actualTypeName_),
359     dict_(ptf.dict_)
361     for
362     (
363         HashPtrTable<scalarField>::const_iterator iter =
364             ptf.scalarFields_.begin();
365         iter != ptf.scalarFields_.end();
366         ++iter
367     )
368     {
369         scalarFields_.insert(iter.key(), new scalarField(*iter(), mapper));
370     }
372     for
373     (
374         HashPtrTable<vectorField>::const_iterator iter =
375             ptf.vectorFields_.begin();
376         iter != ptf.vectorFields_.end();
377         ++iter
378     )
379     {
380         vectorFields_.insert(iter.key(), new vectorField(*iter(), mapper));
381     }
383     for
384     (
385         HashPtrTable<sphericalTensorField>::const_iterator iter =
386             ptf.sphericalTensorFields_.begin();
387         iter != ptf.sphericalTensorFields_.end();
388         ++iter
389     )
390     {
391         sphericalTensorFields_.insert
392         (
393             iter.key(),
394             new sphericalTensorField(*iter(), mapper)
395         );
396     }
398     for
399     (
400         HashPtrTable<symmTensorField>::const_iterator iter =
401             ptf.symmTensorFields_.begin();
402         iter != ptf.symmTensorFields_.end();
403         ++iter
404     )
405     {
406         symmTensorFields_.insert
407         (
408             iter.key(),
409             new symmTensorField(*iter(), mapper)
410         );
411     }
413     for
414     (
415         HashPtrTable<tensorField>::const_iterator iter =
416             ptf.tensorFields_.begin();
417         iter != ptf.tensorFields_.end();
418         ++iter
419     )
420     {
421         tensorFields_.insert(iter.key(), new tensorField(*iter(), mapper));
422     }
426 template<class Type>
427 genericPointPatchField<Type>::genericPointPatchField
429     const genericPointPatchField<Type>& ptf,
430     const DimensionedField<Type, pointMesh>& iF
433     calculatedPointPatchField<Type>(ptf, iF),
434     actualTypeName_(ptf.actualTypeName_),
435     dict_(ptf.dict_),
436     scalarFields_(ptf.scalarFields_),
437     vectorFields_(ptf.vectorFields_),
438     sphericalTensorFields_(ptf.sphericalTensorFields_),
439     symmTensorFields_(ptf.symmTensorFields_),
440     tensorFields_(ptf.tensorFields_)
444 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
446 template<class Type>
447 void genericPointPatchField<Type>::autoMap
449     const pointPatchFieldMapper& m
452     for
453     (
454         HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
455         iter != scalarFields_.end();
456         ++iter
457     )
458     {
459         iter()->autoMap(m);
460     }
462     for
463     (
464         HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
465         iter != vectorFields_.end();
466         ++iter
467     )
468     {
469         iter()->autoMap(m);
470     }
472     for
473     (
474         HashPtrTable<sphericalTensorField>::iterator iter =
475             sphericalTensorFields_.begin();
476         iter != sphericalTensorFields_.end();
477         ++iter
478     )
479     {
480         iter()->autoMap(m);
481     }
483     for
484     (
485         HashPtrTable<symmTensorField>::iterator iter =
486             symmTensorFields_.begin();
487         iter != symmTensorFields_.end();
488         ++iter
489     )
490     {
491         iter()->autoMap(m);
492     }
494     for
495     (
496         HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
497         iter != tensorFields_.end();
498         ++iter
499     )
500     {
501         iter()->autoMap(m);
502     }
506 template<class Type>
507 void genericPointPatchField<Type>::rmap
509     const pointPatchField<Type>& ptf,
510     const labelList& addr
513     const genericPointPatchField<Type>& dptf =
514         refCast<const genericPointPatchField<Type> >(ptf);
516     for
517     (
518         HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
519         iter != scalarFields_.end();
520         ++iter
521     )
522     {
523         HashPtrTable<scalarField>::const_iterator dptfIter =
524             dptf.scalarFields_.find(iter.key());
526         if (dptfIter != scalarFields_.end())
527         {
528             iter()->rmap(*dptfIter(), addr);
529         }
530     }
532     for
533     (
534         HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
535         iter != vectorFields_.end();
536         ++iter
537     )
538     {
539         HashPtrTable<vectorField>::const_iterator dptfIter =
540             dptf.vectorFields_.find(iter.key());
542         if (dptfIter != vectorFields_.end())
543         {
544             iter()->rmap(*dptfIter(), addr);
545         }
546     }
548     for
549     (
550         HashPtrTable<sphericalTensorField>::iterator iter =
551             sphericalTensorFields_.begin();
552         iter != sphericalTensorFields_.end();
553         ++iter
554     )
555     {
556         HashPtrTable<sphericalTensorField>::const_iterator dptfIter =
557             dptf.sphericalTensorFields_.find(iter.key());
559         if (dptfIter != sphericalTensorFields_.end())
560         {
561             iter()->rmap(*dptfIter(), addr);
562         }
563     }
565     for
566     (
567         HashPtrTable<symmTensorField>::iterator iter =
568             symmTensorFields_.begin();
569         iter != symmTensorFields_.end();
570         ++iter
571     )
572     {
573         HashPtrTable<symmTensorField>::const_iterator dptfIter =
574             dptf.symmTensorFields_.find(iter.key());
576         if (dptfIter != symmTensorFields_.end())
577         {
578             iter()->rmap(*dptfIter(), addr);
579         }
580     }
582     for
583     (
584         HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
585         iter != tensorFields_.end();
586         ++iter
587     )
588     {
589         HashPtrTable<tensorField>::const_iterator dptfIter =
590             dptf.tensorFields_.find(iter.key());
592         if (dptfIter != tensorFields_.end())
593         {
594             iter()->rmap(*dptfIter(), addr);
595         }
596     }
600 template<class Type>
601 void genericPointPatchField<Type>::write(Ostream& os) const
603     os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
605     for
606     (
607         dictionary::const_iterator iter = dict_.begin();
608         iter != dict_.end();
609         ++iter
610     )
611     {
612         if (iter().keyword() != "type")
613         {
614             if
615             (
616                 iter().isStream()
617              && iter().stream().size()
618              && iter().stream()[0].isWord()
619              && iter().stream()[0].wordToken() == "nonuniform"
620             )
621             {
622                 if (scalarFields_.found(iter().keyword()))
623                 {
624                     scalarFields_.find(iter().keyword())()
625                         ->writeEntry(iter().keyword(), os);
626                 }
627                 else if (vectorFields_.found(iter().keyword()))
628                 {
629                     vectorFields_.find(iter().keyword())()
630                         ->writeEntry(iter().keyword(), os);
631                 }
632                 else if (sphericalTensorFields_.found(iter().keyword()))
633                 {
634                     sphericalTensorFields_.find(iter().keyword())()
635                         ->writeEntry(iter().keyword(), os);
636                 }
637                 else if (symmTensorFields_.found(iter().keyword()))
638                 {
639                     symmTensorFields_.find(iter().keyword())()
640                         ->writeEntry(iter().keyword(), os);
641                 }
642                 else if (tensorFields_.found(iter().keyword()))
643                 {
644                     tensorFields_.find(iter().keyword())()
645                         ->writeEntry(iter().keyword(), os);
646                 }
647             }
648             else
649             {
650                iter().write(os);
651             }
652         }
653     }
657 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
659 } // End namespace Foam
661 // ************************************************************************* //