FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

directMappedFixedValueFvPatchField.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "directMappedFixedValueFvPatchField.H"
00027 #include <meshTools/directMappedPatchBase.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <OpenFOAM/mapDistribute.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 template<class Type>
00039 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00040 (
00041     const fvPatch& p,
00042     const DimensionedField<Type, volMesh>& iF
00043 )
00044 :
00045     fixedValueFvPatchField<Type>(p, iF),
00046     setAverage_(false),
00047     average_(pTraits<Type>::zero)
00048 {}
00049 
00050 
00051 template<class Type>
00052 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00053 (
00054     const directMappedFixedValueFvPatchField<Type>& ptf,
00055     const fvPatch& p,
00056     const DimensionedField<Type, volMesh>& iF,
00057     const fvPatchFieldMapper& mapper
00058 )
00059 :
00060     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
00061     setAverage_(ptf.setAverage_),
00062     average_(ptf.average_)
00063 {
00064     if (!isA<directMappedPatchBase>(this->patch().patch()))
00065     {
00066         FatalErrorIn
00067         (
00068             "directMappedFixedValueFvPatchField<Type>::"
00069             "directMappedFixedValueFvPatchField\n"
00070             "(\n"
00071             "    const directMappedFixedValueFvPatchField<Type>&,\n"
00072             "    const fvPatch&,\n"
00073             "    const Field<Type>&,\n"
00074             "    const fvPatchFieldMapper&\n"
00075             ")\n"
00076         )   << "\n    patch type '" << p.type()
00077             << "' not type '" << directMappedPatchBase::typeName << "'"
00078             << "\n    for patch " << p.name()
00079             << " of field " << this->dimensionedInternalField().name()
00080             << " in file " << this->dimensionedInternalField().objectPath()
00081             << exit(FatalError);
00082     }
00083 }
00084 
00085 
00086 template<class Type>
00087 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00088 (
00089     const fvPatch& p,
00090     const DimensionedField<Type, volMesh>& iF,
00091     const dictionary& dict
00092 )
00093 :
00094     fixedValueFvPatchField<Type>(p, iF, dict),
00095     setAverage_(readBool(dict.lookup("setAverage"))),
00096     average_(pTraits<Type>(dict.lookup("average")))
00097 {
00098     if (!isA<directMappedPatchBase>(this->patch().patch()))
00099     {
00100         FatalErrorIn
00101         (
00102             "directMappedFixedValueFvPatchField<Type>::"
00103             "directMappedFixedValueFvPatchField\n"
00104             "(\n"
00105             "    const fvPatch& p,\n"
00106             "    const DimensionedField<Type, volMesh>& iF,\n"
00107             "    const dictionary& dict\n"
00108             ")\n"
00109         )   << "\n    patch type '" << p.type()
00110             << "' not type '" << directMappedPatchBase::typeName << "'"
00111             << "\n    for patch " << p.name()
00112             << " of field " << this->dimensionedInternalField().name()
00113             << " in file " << this->dimensionedInternalField().objectPath()
00114             << exit(FatalError);
00115     }
00116 
00118     //const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
00119     //(
00120     //    this->patch().patch()
00121     //);
00122     //(void)mpp.map().schedule();
00123 }
00124 
00125 
00126 template<class Type>
00127 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00128 (
00129     const directMappedFixedValueFvPatchField<Type>& ptf
00130 )
00131 :
00132     fixedValueFvPatchField<Type>(ptf),
00133     setAverage_(ptf.setAverage_),
00134     average_(ptf.average_)
00135 {}
00136 
00137 
00138 template<class Type>
00139 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00140 (
00141     const directMappedFixedValueFvPatchField<Type>& ptf,
00142     const DimensionedField<Type, volMesh>& iF
00143 )
00144 :
00145     fixedValueFvPatchField<Type>(ptf, iF),
00146     setAverage_(ptf.setAverage_),
00147     average_(ptf.average_)
00148 {}
00149 
00150 
00151 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00152 
00153 template<class Type>
00154 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
00155 {
00156     if (this->updated())
00157     {
00158         return;
00159     }
00160 
00161     typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
00162 
00163     // Get the scheduling information from the directMappedPatchBase
00164     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
00165     (
00166         directMappedFixedValueFvPatchField<Type>::patch().patch()
00167     );
00168     const mapDistribute& distMap = mpp.map();
00169 
00170     // Force recalculation of schedule
00171     (void)distMap.schedule();
00172 
00173     const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
00174     const word& fldName = this->dimensionedInternalField().name();
00175 
00176     // Result of obtaining remote values
00177     Field<Type> newValues;
00178 
00179     switch (mpp.mode())
00180     {
00181         case directMappedPatchBase::NEARESTCELL:
00182         {
00183             if (mpp.sameRegion())
00184             {
00185                 newValues = this->internalField();
00186             }
00187             else
00188             {
00189                 newValues = nbrMesh.lookupObject<fieldType>
00190                 (
00191                     fldName
00192                 ).internalField();
00193             }
00194             mapDistribute::distribute
00195             (
00196                 Pstream::defaultCommsType,
00197                 distMap.schedule(),
00198                 distMap.constructSize(),
00199                 distMap.subMap(),
00200                 distMap.constructMap(),
00201                 newValues
00202             );
00203 
00204             break;
00205         }
00206         case directMappedPatchBase::NEARESTPATCHFACE:
00207         {
00208             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
00209             (
00210                 mpp.samplePatch()
00211             );
00212             if (nbrPatchID < 0)
00213             {
00214                 FatalErrorIn
00215                 (
00216                     "void directMappedFixedValueFvPatchField<Type>::"
00217                     "updateCoeffs()"
00218                 )<< "Unable to find sample patch " << mpp.samplePatch()
00219                  << " in region " << mpp.sampleRegion()
00220                  << " for patch " << this->patch().name() << nl
00221                  << abort(FatalError);
00222             }
00223 
00224             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
00225             (
00226                 fldName
00227             );
00228             newValues = nbrField.boundaryField()[nbrPatchID];
00229             mapDistribute::distribute
00230             (
00231                 Pstream::defaultCommsType,
00232                 distMap.schedule(),
00233                 distMap.constructSize(),
00234                 distMap.subMap(),
00235                 distMap.constructMap(),
00236                 newValues
00237             );
00238 
00239             break;
00240         }
00241         case directMappedPatchBase::NEARESTFACE:
00242         {
00243             Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
00244 
00245             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
00246             (
00247                 fldName
00248             );
00249             forAll(nbrField.boundaryField(), patchI)
00250             {
00251                 const fvPatchField<Type>& pf =
00252                     nbrField.boundaryField()[patchI];
00253                 label faceStart = pf.patch().patch().start();
00254 
00255                 forAll(pf, faceI)
00256                 {
00257                     allValues[faceStart++] = pf[faceI];
00258                 }
00259             }
00260 
00261             mapDistribute::distribute
00262             (
00263                 Pstream::defaultCommsType,
00264                 distMap.schedule(),
00265                 distMap.constructSize(),
00266                 distMap.subMap(),
00267                 distMap.constructMap(),
00268                 allValues
00269             );
00270 
00271             newValues.transfer(allValues);
00272 
00273             break;
00274         }
00275         default:
00276         {
00277             FatalErrorIn
00278             (
00279                 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
00280             )<< "Unknown sampling mode: " << mpp.mode()
00281              << nl << abort(FatalError);
00282         }
00283     }
00284 
00285     if (setAverage_)
00286     {
00287         Type averagePsi =
00288             gSum(this->patch().magSf()*newValues)
00289            /gSum(this->patch().magSf());
00290 
00291         if (mag(averagePsi)/mag(average_) > 0.5)
00292         {
00293             newValues *= mag(average_)/mag(averagePsi);
00294         }
00295         else
00296         {
00297             newValues += (average_ - averagePsi);
00298         }
00299     }
00300 
00301     this->operator==(newValues);
00302 
00303     if (debug)
00304     {
00305         Info<< "directMapped on field:" << fldName
00306             << " patch:" << this->patch().name()
00307             << "  avg:" << gAverage(*this)
00308             << "  min:" << gMin(*this)
00309             << "  max:" << gMax(*this)
00310             << endl;
00311     }
00312 
00313     fixedValueFvPatchField<Type>::updateCoeffs();
00314 }
00315 
00316 
00317 template<class Type>
00318 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
00319 {
00320     fvPatchField<Type>::write(os);
00321     os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
00322     os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
00323     this->writeEntry("value", os);
00324 }
00325 
00326 
00327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00328 
00329 } // End namespace Foam
00330 
00331 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines