1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "directMappedFixedValueFvPatchField.H"
27 #include "directMappedPatchBase.H"
28 #include "volFields.H"
29 #include "interpolationCell.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
42 const DimensionedField<Type, volMesh>& iF
45 fixedValueFvPatchField<Type>(p, iF),
46 fieldName_(iF.name()),
48 average_(pTraits<Type>::zero),
49 interpolationScheme_(interpolationCell<Type>::typeName)
54 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
56 const directMappedFixedValueFvPatchField<Type>& ptf,
58 const DimensionedField<Type, volMesh>& iF,
59 const fvPatchFieldMapper& mapper
62 fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
63 fieldName_(ptf.fieldName_),
64 setAverage_(ptf.setAverage_),
65 average_(ptf.average_),
66 interpolationScheme_(ptf.interpolationScheme_)
68 if (!isA<directMappedPatchBase>(this->patch().patch()))
72 "directMappedFixedValueFvPatchField<Type>::"
73 "directMappedFixedValueFvPatchField\n"
75 " const directMappedFixedValueFvPatchField<Type>&,\n"
77 " const Field<Type>&,\n"
78 " const fvPatchFieldMapper&\n"
80 ) << "\n patch type '" << p.type()
81 << "' not type '" << directMappedPatchBase::typeName << "'"
82 << "\n for patch " << p.name()
83 << " of field " << this->dimensionedInternalField().name()
84 << " in file " << this->dimensionedInternalField().objectPath()
91 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
94 const DimensionedField<Type, volMesh>& iF,
95 const dictionary& dict
98 fixedValueFvPatchField<Type>(p, iF, dict),
99 fieldName_(dict.lookupOrDefault<word>("fieldName", iF.name())),
100 setAverage_(readBool(dict.lookup("setAverage"))),
101 average_(pTraits<Type>(dict.lookup("average"))),
102 interpolationScheme_(interpolationCell<Type>::typeName)
104 if (!isA<directMappedPatchBase>(this->patch().patch()))
108 "directMappedFixedValueFvPatchField<Type>::"
109 "directMappedFixedValueFvPatchField\n"
111 " const fvPatch& p,\n"
112 " const DimensionedField<Type, volMesh>& iF,\n"
113 " const dictionary& dict\n"
115 ) << "\n patch type '" << p.type()
116 << "' not type '" << directMappedPatchBase::typeName << "'"
117 << "\n for patch " << p.name()
118 << " of field " << this->dimensionedInternalField().name()
119 << " in file " << this->dimensionedInternalField().objectPath()
123 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
125 directMappedFixedValueFvPatchField<Type>::patch().patch()
127 if (mpp.mode() == directMappedPatchBase::NEARESTCELL)
129 dict.lookup("interpolationScheme") >> interpolationScheme_;
135 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
137 const directMappedFixedValueFvPatchField<Type>& ptf
140 fixedValueFvPatchField<Type>(ptf),
141 fieldName_(ptf.fieldName_),
142 setAverage_(ptf.setAverage_),
143 average_(ptf.average_),
144 interpolationScheme_(ptf.interpolationScheme_)
149 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
151 const directMappedFixedValueFvPatchField<Type>& ptf,
152 const DimensionedField<Type, volMesh>& iF
155 fixedValueFvPatchField<Type>(ptf, iF),
156 fieldName_(ptf.fieldName_),
157 setAverage_(ptf.setAverage_),
158 average_(ptf.average_),
159 interpolationScheme_(ptf.interpolationScheme_)
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 const GeometricField<Type, fvPatchField, volMesh>&
167 directMappedFixedValueFvPatchField<Type>::sampleField() const
169 typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
171 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
173 directMappedFixedValueFvPatchField<Type>::patch().patch()
175 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
177 if (mpp.sameRegion())
179 if (fieldName_ == this->dimensionedInternalField().name())
181 // Optimisation: bypass field lookup
183 dynamic_cast<const fieldType&>
185 this->dimensionedInternalField()
190 const fvMesh& thisMesh = this->patch().boundaryMesh().mesh();
191 return thisMesh.lookupObject<fieldType>(fieldName_);
196 return nbrMesh.lookupObject<fieldType>(fieldName_);
202 const interpolation<Type>&
203 directMappedFixedValueFvPatchField<Type>::interpolator() const
205 if (!interpolator_.valid())
207 interpolator_ = interpolation<Type>::New
209 interpolationScheme_,
213 return interpolator_();
218 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
225 typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
227 // Get the scheduling information from the directMappedPatchBase
228 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
230 directMappedFixedValueFvPatchField<Type>::patch().patch()
232 const mapDistribute& distMap = mpp.map();
234 const fvMesh& thisMesh = this->patch().boundaryMesh().mesh();
235 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
237 // Result of obtaining remote values
238 Field<Type> newValues;
242 case directMappedPatchBase::NEARESTCELL:
244 if (interpolationScheme_ != interpolationCell<Type>::typeName)
246 // Send back sample points to the processor that holds the cell
247 vectorField samples(mpp.samplePoints());
248 distMap.reverseDistribute
250 (mpp.sameRegion() ? thisMesh.nCells() : nbrMesh.nCells()),
255 const interpolation<Type>& interp = interpolator();
257 newValues.setSize(samples.size(), pTraits<Type>::max);
258 forAll(samples, cellI)
260 if (samples[cellI] != point::max)
262 newValues[cellI] = interp.interpolate
272 newValues = sampleField();
275 distMap.distribute(newValues);
279 case directMappedPatchBase::NEARESTPATCHFACE:
281 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
289 "void directMappedFixedValueFvPatchField<Type>::"
291 )<< "Unable to find sample patch " << mpp.samplePatch()
292 << " in region " << mpp.sampleRegion()
293 << " for patch " << this->patch().name() << nl
294 << abort(FatalError);
297 const fieldType& nbrField = sampleField();
299 newValues = nbrField.boundaryField()[nbrPatchID];
300 distMap.distribute(newValues);
304 case directMappedPatchBase::NEARESTFACE:
306 Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
308 const fieldType& nbrField = sampleField();
310 forAll(nbrField.boundaryField(), patchI)
312 const fvPatchField<Type>& pf =
313 nbrField.boundaryField()[patchI];
314 label faceStart = pf.patch().start();
318 allValues[faceStart++] = pf[faceI];
322 distMap.distribute(allValues);
323 newValues.transfer(allValues);
331 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
332 )<< "Unknown sampling mode: " << mpp.mode()
333 << nl << abort(FatalError);
340 gSum(this->patch().magSf()*newValues)
341 /gSum(this->patch().magSf());
343 if (mag(averagePsi)/mag(average_) > 0.5)
345 newValues *= mag(average_)/mag(averagePsi);
349 newValues += (average_ - averagePsi);
353 this->operator==(newValues);
357 Info<< "directMapped on field:"
358 << this->dimensionedInternalField().name()
359 << " patch:" << this->patch().name()
360 << " avg:" << gAverage(*this)
361 << " min:" << gMin(*this)
362 << " max:" << gMax(*this)
366 fixedValueFvPatchField<Type>::updateCoeffs();
371 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
373 fvPatchField<Type>::write(os);
374 os.writeKeyword("fieldName") << fieldName_ << token::END_STATEMENT << nl;
375 os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
376 os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
377 os.writeKeyword("interpolationScheme") << interpolationScheme_
378 << token::END_STATEMENT << nl;
379 this->writeEntry("value", os);
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 } // End namespace Foam
387 // ************************************************************************* //