OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

genericPointPatchField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "genericPointPatchField.H"
00028 #include "pointPatchFieldMapper.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 template<class Type>
00038 genericPointPatchField<Type>::genericPointPatchField
00039 (
00040     const pointPatch& p,
00041     const DimensionedField<Type, pointMesh>& iF
00042 )
00043 :
00044     calculatedPointPatchField<Type>(p, iF)
00045 {
00046     notImplemented
00047     (
00048         "genericPointPatchField<Type>::genericPointPatchField"
00049         "(const pointPatch& p, const DimensionedField<Type, volMesh>& iF)"
00050     );
00051 }
00052 
00053 
00054 template<class Type>
00055 genericPointPatchField<Type>::genericPointPatchField
00056 (
00057     const pointPatch& p,
00058     const DimensionedField<Type, pointMesh>& iF,
00059     const dictionary& dict
00060 )
00061 :
00062     calculatedPointPatchField<Type>(p, iF, dict),
00063     actualTypeName_(dict.lookup("type")),
00064     dict_(dict)
00065 {
00066     for
00067     (
00068         dictionary::const_iterator iter = dict_.begin();
00069         iter != dict_.end();
00070         ++iter
00071     )
00072     {
00073         if (iter().keyword() != "type")
00074         {
00075             if
00076             (
00077                 iter().isStream()
00078              && iter().stream().size()
00079             )
00080             {
00081                 ITstream& is = iter().stream();
00082 
00083                 // Read first token
00084                 token firstToken(is);
00085 
00086                 if
00087                 (
00088                     firstToken.isWord()
00089                  && firstToken.wordToken() == "nonuniform"
00090                 )
00091                 {
00092                     token fieldToken(is);
00093 
00094                     if (!fieldToken.isCompound())
00095                     {
00096                         if
00097                         (
00098                             fieldToken.isLabel()
00099                          && fieldToken.labelToken() == 0
00100                         )
00101                         {
00102                             scalarFields_.insert
00103                             (
00104                                 iter().keyword(),
00105                                 new scalarField(0)
00106                             );
00107                         }
00108                         else
00109                         {
00110                             FatalIOErrorIn
00111                             (
00112                                 "genericPointPatchField<Type>::"
00113                                 "genericPointPatchField"
00114                                 "(const pointPatch&, const Field<Type>&, "
00115                                 "const dictionary&)",
00116                                 dict
00117                             )   << "\n    token following 'nonuniform' "
00118                                   "is not a compound"
00119                                 << "\n    on patch " << this->patch().name()
00120                                 << " of field "
00121                                 << this->dimensionedInternalField().name()
00122                                 << " in file "
00123                                 << this->dimensionedInternalField().objectPath()
00124                             << exit(FatalIOError);
00125                         }
00126                     }
00127                     else if
00128                     (
00129                         fieldToken.compoundToken().type()
00130                      == token::Compound<List<scalar> >::typeName
00131                     )
00132                     {
00133                         scalarField* fPtr = new scalarField;
00134                         fPtr->transfer
00135                         (
00136                             dynamicCast<token::Compound<List<scalar> > >
00137                             (
00138                                 fieldToken.transferCompoundToken()
00139                             )
00140                         );
00141 
00142                         if (fPtr->size() != this->size())
00143                         {
00144                             FatalIOErrorIn
00145                             (
00146                                 "genericPointPatchField<Type>::"
00147                                 "genericPointPatchField"
00148                                 "(const pointPatch&, const Field<Type>&, "
00149                                 "const dictionary&)",
00150                                 dict
00151                             )   << "\n    size of field " << iter().keyword()
00152                                 << " (" << fPtr->size() << ')'
00153                                 << " is not the same size as the patch ("
00154                                 << this->size() << ')'
00155                                 << "\n    on patch " << this->patch().name()
00156                                 << " of field "
00157                                 << this->dimensionedInternalField().name()
00158                                 << " in file "
00159                                 << this->dimensionedInternalField().objectPath()
00160                                 << exit(FatalIOError);
00161                         }
00162 
00163                         scalarFields_.insert(iter().keyword(), fPtr);
00164                     }
00165                     else if
00166                     (
00167                         fieldToken.compoundToken().type()
00168                      == token::Compound<List<vector> >::typeName
00169                     )
00170                     {
00171                         vectorField* fPtr = new vectorField;
00172                         fPtr->transfer
00173                         (
00174                             dynamicCast<token::Compound<List<vector> > >
00175                             (
00176                                 fieldToken.transferCompoundToken()
00177                             )
00178                         );
00179 
00180                         if (fPtr->size() != this->size())
00181                         {
00182                             FatalIOErrorIn
00183                             (
00184                                 "genericPointPatchField<Type>::"
00185                                 "genericPointPatchField"
00186                                 "(const pointPatch&, const Field<Type>&, "
00187                                 "const dictionary&)",
00188                                 dict
00189                             )   << "\n    size of field " << iter().keyword()
00190                                 << " (" << fPtr->size() << ')'
00191                                 << " is not the same size as the patch ("
00192                                 << this->size() << ')'
00193                                 << "\n    on patch " << this->patch().name()
00194                                 << " of field "
00195                                 << this->dimensionedInternalField().name()
00196                                 << " in file "
00197                                 << this->dimensionedInternalField().objectPath()
00198                                 << exit(FatalIOError);
00199                         }
00200 
00201                         vectorFields_.insert(iter().keyword(), fPtr);
00202                     }
00203                     else if
00204                     (
00205                         fieldToken.compoundToken().type()
00206                      == token::Compound<List<sphericalTensor> >::typeName
00207                     )
00208                     {
00209                         sphericalTensorField* fPtr = new sphericalTensorField;
00210                         fPtr->transfer
00211                         (
00212                             dynamicCast
00213                             <
00214                                 token::Compound<List<sphericalTensor> >
00215                             >
00216                             (
00217                                 fieldToken.transferCompoundToken()
00218                             )
00219                         );
00220 
00221                         if (fPtr->size() != this->size())
00222                         {
00223                             FatalIOErrorIn
00224                             (
00225                                 "genericPointPatchField<Type>::"
00226                                 "genericPointPatchField"
00227                                 "(const pointPatch&, const Field<Type>&, "
00228                                 "const dictionary&)",
00229                                 dict
00230                             )   << "\n    size of field " << iter().keyword()
00231                                 << " (" << fPtr->size() << ')'
00232                                 << " is not the same size as the patch ("
00233                                 << this->size() << ')'
00234                                 << "\n    on patch " << this->patch().name()
00235                                 << " of field "
00236                                 << this->dimensionedInternalField().name()
00237                                 << " in file "
00238                                 << this->dimensionedInternalField().objectPath()
00239                                 << exit(FatalIOError);
00240                         }
00241 
00242                         sphericalTensorFields_.insert(iter().keyword(), fPtr);
00243                     }
00244                     else if
00245                     (
00246                         fieldToken.compoundToken().type()
00247                      == token::Compound<List<symmTensor> >::typeName
00248                     )
00249                     {
00250                         symmTensorField* fPtr = new symmTensorField;
00251                         fPtr->transfer
00252                         (
00253                             dynamicCast
00254                             <
00255                                 token::Compound<List<symmTensor> >
00256                             >
00257                             (
00258                                 fieldToken.transferCompoundToken()
00259                             )
00260                         );
00261 
00262                         if (fPtr->size() != this->size())
00263                         {
00264                             FatalIOErrorIn
00265                             (
00266                                 "genericPointPatchField<Type>::"
00267                                 "genericPointPatchField"
00268                                 "(const pointPatch&, const Field<Type>&, "
00269                                 "const dictionary&)",
00270                                 dict
00271                             )   << "\n    size of field " << iter().keyword()
00272                                 << " (" << fPtr->size() << ')'
00273                                 << " is not the same size as the patch ("
00274                                 << this->size() << ')'
00275                                 << "\n    on patch " << this->patch().name()
00276                                 << " of field "
00277                                 << this->dimensionedInternalField().name()
00278                                 << " in file "
00279                                 << this->dimensionedInternalField().objectPath()
00280                                 << exit(FatalIOError);
00281                         }
00282 
00283                         symmTensorFields_.insert(iter().keyword(), fPtr);
00284                     }
00285                     else if
00286                     (
00287                         fieldToken.compoundToken().type()
00288                      == token::Compound<List<tensor> >::typeName
00289                     )
00290                     {
00291                         tensorField* fPtr = new tensorField;
00292                         fPtr->transfer
00293                         (
00294                             dynamicCast<token::Compound<List<tensor> > >
00295                             (
00296                                 fieldToken.transferCompoundToken()
00297                             )
00298                         );
00299 
00300                         if (fPtr->size() != this->size())
00301                         {
00302                             FatalIOErrorIn
00303                             (
00304                                 "genericPointPatchField<Type>::"
00305                                 "genericPointPatchField"
00306                                 "(const pointPatch&, const Field<Type>&, "
00307                                 "const dictionary&)",
00308                                 dict
00309                             )   << "\n    size of field " << iter().keyword()
00310                                 << " (" << fPtr->size() << ')'
00311                                 << " is not the same size as the patch ("
00312                                 << this->size() << ')'
00313                                 << "\n    on patch " << this->patch().name()
00314                                 << " of field "
00315                                 << this->dimensionedInternalField().name()
00316                                 << " in file "
00317                                 << this->dimensionedInternalField().objectPath()
00318                                 << exit(FatalIOError);
00319                         }
00320 
00321                         tensorFields_.insert(iter().keyword(), fPtr);
00322                     }
00323                     else
00324                     {
00325                         FatalIOErrorIn
00326                         (
00327                             "genericPointPatchField<Type>::"
00328                             "genericPointPatchField"
00329                             "(const pointPatch&, const Field<Type>&, "
00330                             "const dictionary&)",
00331                             dict
00332                         )   << "\n    compound " << fieldToken.compoundToken()
00333                             << " not supported"
00334                             << "\n    on patch " << this->patch().name()
00335                             << " of field "
00336                             << this->dimensionedInternalField().name()
00337                             << " in file "
00338                             << this->dimensionedInternalField().objectPath()
00339                             << exit(FatalIOError);
00340                     }
00341                 }
00342             }
00343         }
00344     }
00345 }
00346 
00347 
00348 template<class Type>
00349 genericPointPatchField<Type>::genericPointPatchField
00350 (
00351     const genericPointPatchField<Type>& ptf,
00352     const pointPatch& p,
00353     const DimensionedField<Type, pointMesh>& iF,
00354     const pointPatchFieldMapper& mapper
00355 )
00356 :
00357     calculatedPointPatchField<Type>(ptf, p, iF, mapper),
00358     actualTypeName_(ptf.actualTypeName_),
00359     dict_(ptf.dict_)
00360 {
00361     for
00362     (
00363         HashPtrTable<scalarField>::const_iterator iter =
00364             ptf.scalarFields_.begin();
00365         iter != ptf.scalarFields_.end();
00366         ++iter
00367     )
00368     {
00369         scalarFields_.insert(iter.key(), new scalarField(*iter(), mapper));
00370     }
00371 
00372     for
00373     (
00374         HashPtrTable<vectorField>::const_iterator iter =
00375             ptf.vectorFields_.begin();
00376         iter != ptf.vectorFields_.end();
00377         ++iter
00378     )
00379     {
00380         vectorFields_.insert(iter.key(), new vectorField(*iter(), mapper));
00381     }
00382 
00383     for
00384     (
00385         HashPtrTable<sphericalTensorField>::const_iterator iter =
00386             ptf.sphericalTensorFields_.begin();
00387         iter != ptf.sphericalTensorFields_.end();
00388         ++iter
00389     )
00390     {
00391         sphericalTensorFields_.insert
00392         (
00393             iter.key(),
00394             new sphericalTensorField(*iter(), mapper)
00395         );
00396     }
00397 
00398     for
00399     (
00400         HashPtrTable<symmTensorField>::const_iterator iter =
00401             ptf.symmTensorFields_.begin();
00402         iter != ptf.symmTensorFields_.end();
00403         ++iter
00404     )
00405     {
00406         symmTensorFields_.insert
00407         (
00408             iter.key(),
00409             new symmTensorField(*iter(), mapper)
00410         );
00411     }
00412 
00413     for
00414     (
00415         HashPtrTable<tensorField>::const_iterator iter =
00416             ptf.tensorFields_.begin();
00417         iter != ptf.tensorFields_.end();
00418         ++iter
00419     )
00420     {
00421         tensorFields_.insert(iter.key(), new tensorField(*iter(), mapper));
00422     }
00423 }
00424 
00425 
00426 template<class Type>
00427 genericPointPatchField<Type>::genericPointPatchField
00428 (
00429     const genericPointPatchField<Type>& ptf,
00430     const DimensionedField<Type, pointMesh>& iF
00431 )
00432 :
00433     calculatedPointPatchField<Type>(ptf, iF),
00434     actualTypeName_(ptf.actualTypeName_),
00435     dict_(ptf.dict_),
00436     scalarFields_(ptf.scalarFields_),
00437     vectorFields_(ptf.vectorFields_),
00438     sphericalTensorFields_(ptf.sphericalTensorFields_),
00439     symmTensorFields_(ptf.symmTensorFields_),
00440     tensorFields_(ptf.tensorFields_)
00441 {}
00442 
00443 
00444 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00445 
00446 template<class Type>
00447 void genericPointPatchField<Type>::autoMap
00448 (
00449     const pointPatchFieldMapper& m
00450 )
00451 {
00452     for
00453     (
00454         HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
00455         iter != scalarFields_.end();
00456         ++iter
00457     )
00458     {
00459         iter()->autoMap(m);
00460     }
00461 
00462     for
00463     (
00464         HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
00465         iter != vectorFields_.end();
00466         ++iter
00467     )
00468     {
00469         iter()->autoMap(m);
00470     }
00471 
00472     for
00473     (
00474         HashPtrTable<sphericalTensorField>::iterator iter =
00475             sphericalTensorFields_.begin();
00476         iter != sphericalTensorFields_.end();
00477         ++iter
00478     )
00479     {
00480         iter()->autoMap(m);
00481     }
00482 
00483     for
00484     (
00485         HashPtrTable<symmTensorField>::iterator iter =
00486             symmTensorFields_.begin();
00487         iter != symmTensorFields_.end();
00488         ++iter
00489     )
00490     {
00491         iter()->autoMap(m);
00492     }
00493 
00494     for
00495     (
00496         HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
00497         iter != tensorFields_.end();
00498         ++iter
00499     )
00500     {
00501         iter()->autoMap(m);
00502     }
00503 }
00504 
00505 
00506 template<class Type>
00507 void genericPointPatchField<Type>::rmap
00508 (
00509     const pointPatchField<Type>& ptf,
00510     const labelList& addr
00511 )
00512 {
00513     const genericPointPatchField<Type>& dptf =
00514         refCast<const genericPointPatchField<Type> >(ptf);
00515 
00516     for
00517     (
00518         HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
00519         iter != scalarFields_.end();
00520         ++iter
00521     )
00522     {
00523         HashPtrTable<scalarField>::const_iterator dptfIter =
00524             dptf.scalarFields_.find(iter.key());
00525 
00526         if (dptfIter != scalarFields_.end())
00527         {
00528             iter()->rmap(*dptfIter(), addr);
00529         }
00530     }
00531 
00532     for
00533     (
00534         HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
00535         iter != vectorFields_.end();
00536         ++iter
00537     )
00538     {
00539         HashPtrTable<vectorField>::const_iterator dptfIter =
00540             dptf.vectorFields_.find(iter.key());
00541 
00542         if (dptfIter != vectorFields_.end())
00543         {
00544             iter()->rmap(*dptfIter(), addr);
00545         }
00546     }
00547 
00548     for
00549     (
00550         HashPtrTable<sphericalTensorField>::iterator iter =
00551             sphericalTensorFields_.begin();
00552         iter != sphericalTensorFields_.end();
00553         ++iter
00554     )
00555     {
00556         HashPtrTable<sphericalTensorField>::const_iterator dptfIter =
00557             dptf.sphericalTensorFields_.find(iter.key());
00558 
00559         if (dptfIter != sphericalTensorFields_.end())
00560         {
00561             iter()->rmap(*dptfIter(), addr);
00562         }
00563     }
00564 
00565     for
00566     (
00567         HashPtrTable<symmTensorField>::iterator iter =
00568             symmTensorFields_.begin();
00569         iter != symmTensorFields_.end();
00570         ++iter
00571     )
00572     {
00573         HashPtrTable<symmTensorField>::const_iterator dptfIter =
00574             dptf.symmTensorFields_.find(iter.key());
00575 
00576         if (dptfIter != symmTensorFields_.end())
00577         {
00578             iter()->rmap(*dptfIter(), addr);
00579         }
00580     }
00581 
00582     for
00583     (
00584         HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
00585         iter != tensorFields_.end();
00586         ++iter
00587     )
00588     {
00589         HashPtrTable<tensorField>::const_iterator dptfIter =
00590             dptf.tensorFields_.find(iter.key());
00591 
00592         if (dptfIter != tensorFields_.end())
00593         {
00594             iter()->rmap(*dptfIter(), addr);
00595         }
00596     }
00597 }
00598 
00599 
00600 template<class Type>
00601 void genericPointPatchField<Type>::write(Ostream& os) const
00602 {
00603     os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
00604 
00605     for
00606     (
00607         dictionary::const_iterator iter = dict_.begin();
00608         iter != dict_.end();
00609         ++iter
00610     )
00611     {
00612         if (iter().keyword() != "type")
00613         {
00614             if
00615             (
00616                 iter().isStream()
00617              && iter().stream().size()
00618              && iter().stream()[0].isWord()
00619              && iter().stream()[0].wordToken() == "nonuniform"
00620             )
00621             {
00622                 if (scalarFields_.found(iter().keyword()))
00623                 {
00624                     scalarFields_.find(iter().keyword())()
00625                         ->writeEntry(iter().keyword(), os);
00626                 }
00627                 else if (vectorFields_.found(iter().keyword()))
00628                 {
00629                     vectorFields_.find(iter().keyword())()
00630                         ->writeEntry(iter().keyword(), os);
00631                 }
00632                 else if (sphericalTensorFields_.found(iter().keyword()))
00633                 {
00634                     sphericalTensorFields_.find(iter().keyword())()
00635                         ->writeEntry(iter().keyword(), os);
00636                 }
00637                 else if (symmTensorFields_.found(iter().keyword()))
00638                 {
00639                     symmTensorFields_.find(iter().keyword())()
00640                         ->writeEntry(iter().keyword(), os);
00641                 }
00642                 else if (tensorFields_.found(iter().keyword()))
00643                 {
00644                     tensorFields_.find(iter().keyword())()
00645                         ->writeEntry(iter().keyword(), os);
00646                 }
00647             }
00648             else
00649             {
00650                iter().write(os);
00651             }
00652         }
00653     }
00654 }
00655 
00656 
00657 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00658 
00659 } // End namespace Foam
00660 
00661 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd