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 "directMappedVelocityFluxFixedValueFvPatchField.H"
28 #include "fvPatchFieldMapper.H"
29 #include "directMappedPatchBase.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 directMappedVelocityFluxFixedValueFvPatchField::
42 directMappedVelocityFluxFixedValueFvPatchField
45 const DimensionedField<vector, volMesh>& iF
48 fixedValueFvPatchVectorField(p, iF),
49 phiName_("undefinedPhi")
53 directMappedVelocityFluxFixedValueFvPatchField::
54 directMappedVelocityFluxFixedValueFvPatchField
56 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
58 const DimensionedField<vector, volMesh>& iF,
59 const fvPatchFieldMapper& mapper
62 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
63 phiName_(ptf.phiName_)
65 if (!isA<directMappedPatchBase>(this->patch().patch()))
69 "directMappedVelocityFluxFixedValueFvPatchField::"
70 "directMappedVelocityFluxFixedValueFvPatchField\n"
72 " const directMappedVelocityFluxFixedValueFvPatchField&,\n"
74 " const DimensionedField<vector, volMesh>&,\n"
75 " const fvPatchFieldMapper&\n"
77 ) << "\n patch type '" << p.type()
78 << "' not type '" << directMappedPatchBase::typeName << "'"
79 << "\n for patch " << p.name()
80 << " of field " << dimensionedInternalField().name()
81 << " in file " << dimensionedInternalField().objectPath()
87 directMappedVelocityFluxFixedValueFvPatchField::
88 directMappedVelocityFluxFixedValueFvPatchField
91 const DimensionedField<vector, volMesh>& iF,
92 const dictionary& dict
95 fixedValueFvPatchVectorField(p, iF, dict),
96 phiName_(dict.lookup("phi"))
98 if (!isA<directMappedPatchBase>(this->patch().patch()))
102 "directMappedVelocityFluxFixedValueFvPatchField::"
103 "directMappedVelocityFluxFixedValueFvPatchField\n"
105 " const fvPatch& p,\n"
106 " const DimensionedField<vector, 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 " << dimensionedInternalField().name()
113 << " in file " << dimensionedInternalField().objectPath()
117 // Force calculation of schedule (uses parallel comms)
118 const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
122 (void)mpp.map().schedule();
126 directMappedVelocityFluxFixedValueFvPatchField::
127 directMappedVelocityFluxFixedValueFvPatchField
129 const directMappedVelocityFluxFixedValueFvPatchField& ptf
132 fixedValueFvPatchVectorField(ptf),
133 phiName_(ptf.phiName_)
137 directMappedVelocityFluxFixedValueFvPatchField::
138 directMappedVelocityFluxFixedValueFvPatchField
140 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
141 const DimensionedField<vector, volMesh>& iF
144 fixedValueFvPatchVectorField(ptf, iF),
145 phiName_(ptf.phiName_)
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
158 // Get the directMappedPatchBase
159 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
161 directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
163 const mapDistribute& distMap = mpp.map();
164 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
165 const word& fieldName = dimensionedInternalField().name();
166 const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
171 surfaceScalarField& phiField = const_cast<surfaceScalarField&>
173 nbrMesh.lookupObject<surfaceScalarField>(phiName_)
176 vectorField newUValues;
177 scalarField newPhiValues;
181 case directMappedPolyPatch::NEARESTFACE:
183 vectorField allUValues(nbrMesh.nFaces(), vector::zero);
184 scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
186 forAll(UField.boundaryField(), patchI)
188 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
189 const scalarField& phipf = phiField.boundaryField()[patchI];
191 label faceStart = Upf.patch().patch().start();
195 allUValues[faceStart++] = Upf[faceI];
196 allPhiValues[faceStart] = phipf[faceI];
200 mapDistribute::distribute
202 Pstream::defaultCommsType,
204 distMap.constructSize(),
206 distMap.constructMap(),
209 newUValues = patch().patchSlice(newUValues);
211 mapDistribute::distribute
213 Pstream::defaultCommsType,
215 distMap.constructSize(),
217 distMap.constructMap(),
220 newPhiValues = patch().patchSlice(newPhiValues);
224 case directMappedPolyPatch::NEARESTPATCHFACE:
226 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
231 newUValues = UField.boundaryField()[nbrPatchID];
233 mapDistribute::distribute
235 Pstream::defaultCommsType,
237 distMap.constructSize(),
239 distMap.constructMap(),
243 newPhiValues = phiField.boundaryField()[nbrPatchID];
245 mapDistribute::distribute
247 Pstream::defaultCommsType,
249 distMap.constructSize(),
251 distMap.constructMap(),
261 "directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()"
262 )<< "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
263 << "mode" << nl << abort(FatalError);
267 operator==(newUValues);
268 phiField.boundaryField()[patch().index()] == newPhiValues;
270 fixedValueFvPatchVectorField::updateCoeffs();
274 void directMappedVelocityFluxFixedValueFvPatchField::write(Ostream& os) const
276 fvPatchVectorField::write(os);
277 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
278 this->writeEntry("value", os);
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 directMappedVelocityFluxFixedValueFvPatchField
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 } // End namespace Foam
293 // ************************************************************************* //