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

pointPatchField.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 "pointPatchField.H"
00028 #include "pointMesh.H"
00029 #include "dictionary.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 template<class Type>
00039 pointPatchField<Type>::pointPatchField
00040 (
00041     const pointPatch& p,
00042     const DimensionedField<Type, pointMesh>& iF
00043 )
00044 :
00045     patch_(p),
00046     internalField_(iF),
00047     updated_(false),
00048     patchType_(word::null)
00049 {}
00050 
00051 
00052 template<class Type>
00053 pointPatchField<Type>::pointPatchField
00054 (
00055     const pointPatch& p,
00056     const DimensionedField<Type, pointMesh>& iF,
00057     const dictionary& dict
00058 )
00059 :
00060     patch_(p),
00061     internalField_(iF),
00062     updated_(false),
00063     patchType_(dict.lookupOrDefault<word>("patchType", word::null))
00064 {}
00065 
00066 
00067 template<class Type>
00068 pointPatchField<Type>::pointPatchField
00069 (
00070     const pointPatchField<Type>& ptf
00071 )
00072 :
00073     patch_(ptf.patch_),
00074     internalField_(ptf.internalField_),
00075     updated_(false),
00076     patchType_(ptf.patchType_)
00077 {}
00078 
00079 
00080 template<class Type>
00081 pointPatchField<Type>::pointPatchField
00082 (
00083     const pointPatchField<Type>& ptf,
00084     const DimensionedField<Type, pointMesh>& iF
00085 )
00086 :
00087     patch_(ptf.patch_),
00088     internalField_(iF),
00089     updated_(false),
00090     patchType_(ptf.patchType_)
00091 {}
00092 
00093 
00094 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00095 
00096 template<class Type>
00097 const objectRegistry& pointPatchField<Type>::db() const
00098 {
00099     return patch_.boundaryMesh().mesh()();
00100 }
00101 
00102 
00103 template<class Type>
00104 void pointPatchField<Type>::write(Ostream& os) const
00105 {
00106     os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
00107 
00108     if (patchType_.size())
00109     {
00110         os.writeKeyword("patchType") << patchType_
00111             << token::END_STATEMENT << nl;
00112     }
00113 }
00114 
00115 
00116 template<class Type>
00117 tmp<Field<Type> > pointPatchField<Type>::patchInternalField() const
00118 {
00119     return patchInternalField(internalField());
00120 }
00121 
00122 
00123 template<class Type>
00124 template<class Type1>
00125 tmp<Field<Type1> > pointPatchField<Type>::patchInternalField
00126 (
00127     const Field<Type1>& iF
00128 ) const
00129 {
00130     // Check size
00131     if (iF.size() != internalField().size())
00132     {
00133         FatalErrorIn
00134         (
00135             "tmp<Field<Type1> > pointPatchField<"
00136             "Type>::"
00137             "patchInternalField(const Field<Type1>& iF) const"
00138         )   << "given internal field does not correspond to the mesh. "
00139             << "Field size: " << iF.size()
00140             << " mesh size: " << internalField().size()
00141             << abort(FatalError);
00142     }
00143 
00144     // get addressing
00145     const labelList& meshPoints = patch().meshPoints();
00146 
00147     tmp<Field<Type1> > tvalues(new Field<Type1>(meshPoints.size()));
00148     Field<Type1>& values = tvalues();
00149 
00150     forAll (meshPoints, pointI)
00151     {
00152         values[pointI] = iF[meshPoints[pointI]];
00153     }
00154 
00155     return tvalues;
00156 }
00157 
00158 
00159 template<class Type>
00160 template<class Type1>
00161 void pointPatchField<Type>::addToInternalField
00162 (
00163     Field<Type1>& iF,
00164     const Field<Type1>& pF
00165 ) const
00166 {
00167     // Check size
00168     if (iF.size() != internalField().size())
00169     {
00170         FatalErrorIn
00171         (
00172             "void pointPatchField<Type>::"
00173             "addToInternalField("
00174             "Field<Type1>& iF, const Field<Type1>& iF) const"
00175         )   << "given internal field does not correspond to the mesh. "
00176             << "Field size: " << iF.size()
00177             << " mesh size: " << internalField().size()
00178             << abort(FatalError);
00179     }
00180 
00181     if (pF.size() != size())
00182     {
00183         FatalErrorIn
00184         (
00185             "void pointPatchField<Type>::"
00186             "addToInternalField("
00187             "Field<Type1>& iF, const Field<Type1>& iF) const"
00188         )   << "given patch field does not correspond to the mesh. "
00189             << "Field size: " << pF.size()
00190             << " mesh size: " << size()
00191             << abort(FatalError);
00192     }
00193 
00194     // Get the addressing
00195     const labelList& mp = patch().meshPoints();
00196 
00197     forAll (mp, pointI)
00198     {
00199         iF[mp[pointI]] += pF[pointI];
00200     }
00201 }
00202 
00203 
00204 template<class Type>
00205 template<class Type1>
00206 void pointPatchField<Type>::setInInternalField
00207 (
00208     Field<Type1>& iF,
00209     const Field<Type1>& pF,
00210     const labelList& meshPoints
00211 ) const
00212 {
00213     // Check size
00214     if (iF.size() != internalField().size())
00215     {
00216         FatalErrorIn
00217         (
00218             "void pointPatchField<Type>::"
00219             "setInInternalField("
00220             "Field<Type1>& iF, const Field<Type1>& iF) const"
00221         )   << "given internal field does not correspond to the mesh. "
00222             << "Field size: " << iF.size()
00223             << " mesh size: " << internalField().size()
00224             << abort(FatalError);
00225     }
00226 
00227     if (pF.size() != meshPoints.size())
00228     {
00229         FatalErrorIn
00230         (
00231             "void pointPatchField<Type>::"
00232             "setInInternalField("
00233             "Field<Type1>& iF, const Field<Type1>& iF) const"
00234         )   << "given patch field does not correspond to the meshPoints. "
00235             << "Field size: " << pF.size()
00236             << " meshPoints size: " << size()
00237             << abort(FatalError);
00238     }
00239 
00240     forAll (meshPoints, pointI)
00241     {
00242         iF[meshPoints[pointI]] = pF[pointI];
00243     }
00244 }
00245 
00246 
00247 template<class Type>
00248 template<class Type1>
00249 void pointPatchField<Type>::setInInternalField
00250 (
00251     Field<Type1>& iF,
00252     const Field<Type1>& pF
00253 ) const
00254 {
00255     setInInternalField(iF, pF, patch().meshPoints());
00256 }
00257 
00258 
00259 template<class Type>
00260 void pointPatchField<Type>::evaluate(const Pstream::commsTypes)
00261 {
00262     if (!updated_)
00263     {
00264         updateCoeffs();
00265     }
00266 
00267     updated_ = false;
00268 }
00269 
00270 
00271 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00272 
00273 template<class Type>
00274 Ostream& operator<<
00275 (
00276     Ostream& os,
00277     const pointPatchField<Type>& ptf
00278 )
00279 {
00280     ptf.write(os);
00281 
00282     os.check("Ostream& operator<<(Ostream&, const pointPatchField<Type>&)");
00283 
00284     return os;
00285 }
00286 
00287 
00288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00289 
00290 } // End namespace Foam
00291 
00292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00293 
00294 #include "newPointPatchField.C"
00295 
00296 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd