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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 void directMappedFixedValueFvPatchField<Type>::mapField()
42 typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
44 // Get the scheduling information from the directMappedPatchBase
45 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
47 directMappedFixedValueFvPatchField<Type>::patch().patch()
49 const mapDistribute& distMap = mpp.map();
51 // Force recalculation of schedule
54 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
55 const word& fldName = this->dimensionedInternalField().name();
57 // Result of obtaining remote values
60 Info<< "direct mapping field "
61 << this->dimensionedInternalField().name() << endl;
66 case directMappedPatchBase::NEARESTCELL:
70 newValues_ = this->internalField();
74 newValues_ = nbrMesh.lookupObject<fieldType>
79 mapDistribute::distribute
81 Pstream::defaultCommsType,
83 distMap.constructSize(),
85 distMap.constructMap(),
91 case directMappedPatchBase::NEARESTPATCHFACE:
93 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
101 "void directMappedFixedValueFvPatchField<Type>::"
103 )<< "Unable to find sample patch " << mpp.samplePatch()
104 << " in region " << mpp.sampleRegion()
105 << " for patch " << this->patch().name() << nl
106 << abort(FatalError);
109 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
113 newValues_ = nbrField.boundaryField()[nbrPatchID];
114 mapDistribute::distribute
116 Pstream::defaultCommsType,
118 distMap.constructSize(),
120 distMap.constructMap(),
126 case directMappedPatchBase::NEARESTFACE:
128 Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
130 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
134 forAll(nbrField.boundaryField(), patchI)
136 const fvPatchField<Type>& pf =
137 nbrField.boundaryField()[patchI];
138 label faceStart = pf.patch().patch().start();
142 allValues[faceStart++] = pf[faceI];
146 mapDistribute::distribute
148 Pstream::defaultCommsType,
150 distMap.constructSize(),
152 distMap.constructMap(),
156 newValues_ = this->patch().patchSlice(allValues);
164 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
165 )<< "Unknown sampling mode: " << mpp.mode()
166 << nl << abort(FatalError);
173 gSum(this->patch().magSf()*newValues_)
174 /gSum(this->patch().magSf());
176 if (mag(averagePsi)/mag(average_) > 0.5)
178 newValues_ *= mag(average_)/mag(averagePsi);
182 newValues_ += (average_ - averagePsi);
188 Info<< "directMapped on field:" << fldName
189 << " patch:" << this->patch().name()
190 << " avg:" << gAverage(newValues_)
191 << " min:" << gMin(newValues_)
192 << " max:" << gMax(newValues_)
198 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
201 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
204 const DimensionedField<Type, volMesh>& iF
207 fixedValueFvPatchField<Type>(p, iF),
209 average_(pTraits<Type>::zero),
215 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
218 const DimensionedField<Type, volMesh>& iF,
219 const dictionary& dict
222 fixedValueFvPatchField<Type>(p, iF, dict),
223 setAverage_(readBool(dict.lookup("setAverage"))),
224 average_(pTraits<Type>(dict.lookup("average"))),
227 if (!isA<directMappedPatchBase>(this->patch().patch()))
231 "directMappedFixedValueFvPatchField<Type>::"
232 "directMappedFixedValueFvPatchField\n"
234 " const fvPatch& p,\n"
235 " const DimensionedField<Type, volMesh>& iF,\n"
236 " const dictionary& dict\n"
238 ) << "\n patch type '" << p.type()
239 << "' not type '" << directMappedPatchBase::typeName << "'"
240 << "\n for patch " << p.name()
241 << " of field " << this->dimensionedInternalField().name()
242 << " in file " << this->dimensionedInternalField().objectPath()
249 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
251 const directMappedFixedValueFvPatchField<Type>& ptf,
253 const DimensionedField<Type, volMesh>& iF,
254 const fvPatchFieldMapper& mapper
257 fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
258 setAverage_(ptf.setAverage_),
259 average_(ptf.average_),
262 if (!isA<directMappedPatchBase>(this->patch().patch()))
266 "directMappedFixedValueFvPatchField<Type>::"
267 "directMappedFixedValueFvPatchField\n"
269 " const directMappedFixedValueFvPatchField<Type>&,\n"
271 " const Field<Type>&,\n"
272 " const fvPatchFieldMapper&\n"
274 ) << "\n patch type '" << p.type()
275 << "' not type '" << directMappedPatchBase::typeName << "'"
276 << "\n for patch " << p.name()
277 << " of field " << this->dimensionedInternalField().name()
278 << " in file " << this->dimensionedInternalField().objectPath()
285 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
287 const directMappedFixedValueFvPatchField<Type>& ptf
290 fixedValueFvPatchField<Type>(ptf),
291 setAverage_(ptf.setAverage_),
292 average_(ptf.average_),
298 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
300 const directMappedFixedValueFvPatchField<Type>& ptf,
301 const DimensionedField<Type, volMesh>& iF
304 fixedValueFvPatchField<Type>(ptf, iF),
305 setAverage_(ptf.setAverage_),
306 average_(ptf.average_),
311 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
314 void directMappedFixedValueFvPatchField<Type>::initEvaluate
316 const Pstream::commsTypes commsType
319 // Note: All parallel comms need to happen at this stage
323 if (curTimeIndex_ != this->db().time().timeIndex())
327 curTimeIndex_ = this->db().time().timeIndex();
333 void directMappedFixedValueFvPatchField<Type>::evaluate
335 const Pstream::commsTypes commsType
338 this->operator==(newValues_);
340 fixedValueFvPatchField<Type>::evaluate();
345 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
347 fvPatchField<Type>::write(os);
348 os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
349 os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
350 this->writeEntry("value", os);
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 } // End namespace Foam
358 // ************************************************************************* //