1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 "directMappedFixedValueFvPatchField.H"
28 #include "directMappedPatchBase.H"
29 #include "volFields.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
42 const DimensionedField<Type, volMesh>& iF
45 fixedValueFvPatchField<Type>(p, iF),
47 average_(pTraits<Type>::zero)
52 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
54 const directMappedFixedValueFvPatchField<Type>& ptf,
56 const DimensionedField<Type, volMesh>& iF,
57 const fvPatchFieldMapper& mapper
60 fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
61 setAverage_(ptf.setAverage_),
62 average_(ptf.average_)
64 if (!isA<directMappedPatchBase>(this->patch().patch()))
68 "directMappedFixedValueFvPatchField<Type>::"
69 "directMappedFixedValueFvPatchField\n"
71 " const directMappedFixedValueFvPatchField<Type>&,\n"
73 " const Field<Type>&,\n"
74 " const fvPatchFieldMapper&\n"
76 ) << "\n patch type '" << p.type()
77 << "' not type '" << directMappedPatchBase::typeName << "'"
78 << "\n for patch " << p.name()
79 << " of field " << this->dimensionedInternalField().name()
80 << " in file " << this->dimensionedInternalField().objectPath()
87 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
90 const DimensionedField<Type, volMesh>& iF,
91 const dictionary& dict
94 fixedValueFvPatchField<Type>(p, iF, dict),
95 setAverage_(readBool(dict.lookup("setAverage"))),
96 average_(pTraits<Type>(dict.lookup("average")))
98 if (!isA<directMappedPatchBase>(this->patch().patch()))
102 "directMappedFixedValueFvPatchField<Type>::"
103 "directMappedFixedValueFvPatchField\n"
105 " const fvPatch& p,\n"
106 " const DimensionedField<Type, volMesh>& iF,\n"
107 " const dictionary& dict\n"
109 ) << "\n patch type '" << p.type()
110 << "' not type '" << directMappedPatchBase::typeName << "'"
111 << "\n for patch " << p.name()
112 << " of field " << this->dimensionedInternalField().name()
113 << " in file " << this->dimensionedInternalField().objectPath()
120 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
122 const directMappedFixedValueFvPatchField<Type>& ptf
125 fixedValueFvPatchField<Type>(ptf),
126 setAverage_(ptf.setAverage_),
127 average_(ptf.average_)
132 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
134 const directMappedFixedValueFvPatchField<Type>& ptf,
135 const DimensionedField<Type, volMesh>& iF
138 fixedValueFvPatchField<Type>(ptf, iF),
139 setAverage_(ptf.setAverage_),
140 average_(ptf.average_)
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
154 typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
156 // Get the scheduling information from the directMappedPatchBase
157 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
159 directMappedFixedValueFvPatchField<Type>::patch().patch()
161 const mapDistribute& distMap = mpp.map();
163 // Force recalculation of schedule
166 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
167 const word& fldName = this->dimensionedInternalField().name();
169 // Result of obtaining remote values
170 Field<Type> newValues;
174 case directMappedPatchBase::NEARESTCELL:
176 if (mpp.sameRegion())
178 newValues = this->internalField();
182 newValues = nbrMesh.lookupObject<fieldType>
187 mapDistribute::distribute
189 Pstream::defaultCommsType,
191 distMap.constructSize(),
193 distMap.constructMap(),
199 case directMappedPatchBase::NEARESTPATCHFACE:
201 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
209 "void directMappedFixedValueFvPatchField<Type>::"
211 )<< "Unable to find sample patch " << mpp.samplePatch()
212 << " in region " << mpp.sampleRegion()
213 << " for patch " << this->patch().name() << nl
214 << abort(FatalError);
217 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
221 newValues = nbrField.boundaryField()[nbrPatchID];
222 mapDistribute::distribute
224 Pstream::defaultCommsType,
226 distMap.constructSize(),
228 distMap.constructMap(),
234 case directMappedPatchBase::NEARESTFACE:
236 Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
238 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
242 forAll(nbrField.boundaryField(), patchI)
244 const fvPatchField<Type>& pf =
245 nbrField.boundaryField()[patchI];
246 label faceStart = pf.patch().patch().start();
250 allValues[faceStart++] = pf[faceI];
254 mapDistribute::distribute
256 Pstream::defaultCommsType,
258 distMap.constructSize(),
260 distMap.constructMap(),
264 newValues = this->patch().patchSlice(allValues);
272 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
273 )<< "Unknown sampling mode: " << mpp.mode()
274 << nl << abort(FatalError);
281 gSum(this->patch().magSf()*newValues)
282 /gSum(this->patch().magSf());
284 if (mag(averagePsi)/mag(average_) > 0.5)
286 newValues *= mag(average_)/mag(averagePsi);
290 newValues += (average_ - averagePsi);
294 this->operator==(newValues);
298 Info<< "directMapped on field:" << fldName
299 << " patch:" << this->patch().name()
300 << " avg:" << gAverage(*this)
301 << " min:" << gMin(*this)
302 << " max:" << gMax(*this)
306 fixedValueFvPatchField<Type>::updateCoeffs();
311 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
313 fvPatchField<Type>::write(os);
314 os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
315 os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
316 this->writeEntry("value", os);
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 } // End namespace Foam
324 // ************************************************************************* //