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 "directMappedVelocityFluxFixedValueFvPatchField.H"
27 #include "fvPatchFieldMapper.H"
28 #include "directMappedPatchBase.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::directMappedVelocityFluxFixedValueFvPatchField::
37 directMappedVelocityFluxFixedValueFvPatchField
40 const DimensionedField<vector, volMesh>& iF
43 fixedValueFvPatchVectorField(p, iF),
48 Foam::directMappedVelocityFluxFixedValueFvPatchField::
49 directMappedVelocityFluxFixedValueFvPatchField
51 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
53 const DimensionedField<vector, volMesh>& iF,
54 const fvPatchFieldMapper& mapper
57 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
58 phiName_(ptf.phiName_)
60 if (!isA<directMappedPatchBase>(this->patch().patch()))
64 "directMappedVelocityFluxFixedValueFvPatchField::"
65 "directMappedVelocityFluxFixedValueFvPatchField"
67 "const directMappedVelocityFluxFixedValueFvPatchField&, "
69 "const DimensionedField<vector, volMesh>&, "
70 "const fvPatchFieldMapper&"
72 ) << "Patch type '" << p.type()
73 << "' not type '" << directMappedPatchBase::typeName << "'"
74 << " for patch " << p.name()
75 << " of field " << dimensionedInternalField().name()
76 << " in file " << dimensionedInternalField().objectPath()
82 Foam::directMappedVelocityFluxFixedValueFvPatchField::
83 directMappedVelocityFluxFixedValueFvPatchField
86 const DimensionedField<vector, volMesh>& iF,
87 const dictionary& dict
90 fixedValueFvPatchVectorField(p, iF, dict),
91 phiName_(dict.lookupOrDefault<word>("phi", "phi"))
93 if (!isA<directMappedPatchBase>(this->patch().patch()))
97 "directMappedVelocityFluxFixedValueFvPatchField::"
98 "directMappedVelocityFluxFixedValueFvPatchField"
101 "const DimensionedField<vector, volMesh>&, "
104 ) << "Patch type '" << p.type()
105 << "' not type '" << directMappedPatchBase::typeName << "'"
106 << " for patch " << p.name()
107 << " of field " << dimensionedInternalField().name()
108 << " in file " << dimensionedInternalField().objectPath()
112 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
114 this->patch().patch()
116 if (mpp.mode() == directMappedPolyPatch::NEARESTCELL)
120 "directMappedVelocityFluxFixedValueFvPatchField::"
121 "directMappedVelocityFluxFixedValueFvPatchField"
124 "const DimensionedField<vector, volMesh>&, "
127 ) << "Patch " << p.name()
128 << " of type '" << p.type()
129 << "' can not be used in 'nearestCell' mode"
130 << " of field " << dimensionedInternalField().name()
131 << " in file " << dimensionedInternalField().objectPath()
137 Foam::directMappedVelocityFluxFixedValueFvPatchField::
138 directMappedVelocityFluxFixedValueFvPatchField
140 const directMappedVelocityFluxFixedValueFvPatchField& ptf
143 fixedValueFvPatchVectorField(ptf),
144 phiName_(ptf.phiName_)
148 Foam::directMappedVelocityFluxFixedValueFvPatchField::
149 directMappedVelocityFluxFixedValueFvPatchField
151 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
152 const DimensionedField<vector, volMesh>& iF
155 fixedValueFvPatchVectorField(ptf, iF),
156 phiName_(ptf.phiName_)
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 void Foam::directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
169 // Since we're inside initEvaluate/evaluate there might be processor
170 // comms underway. Change the tag we use.
171 int oldTag = UPstream::msgType();
172 UPstream::msgType() = oldTag+1;
174 // Get the directMappedPatchBase
175 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
177 directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
179 const mapDistribute& distMap = mpp.map();
180 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
181 const word& fieldName = dimensionedInternalField().name();
182 const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
187 surfaceScalarField& phiField = const_cast<surfaceScalarField&>
189 nbrMesh.lookupObject<surfaceScalarField>(phiName_)
192 vectorField newUValues;
193 scalarField newPhiValues;
197 case directMappedPolyPatch::NEARESTFACE:
199 vectorField allUValues(nbrMesh.nFaces(), vector::zero);
200 scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
202 forAll(UField.boundaryField(), patchI)
204 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
205 const scalarField& phipf = phiField.boundaryField()[patchI];
207 label faceStart = Upf.patch().start();
211 allUValues[faceStart + faceI] = Upf[faceI];
212 allPhiValues[faceStart + faceI] = phipf[faceI];
216 distMap.distribute(allUValues);
217 newUValues.transfer(allUValues);
219 distMap.distribute(allPhiValues);
220 newPhiValues.transfer(allPhiValues);
224 case directMappedPolyPatch::NEARESTPATCHFACE:
226 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
231 newUValues = UField.boundaryField()[nbrPatchID];
232 distMap.distribute(newUValues);
234 newPhiValues = phiField.boundaryField()[nbrPatchID];
235 distMap.distribute(newPhiValues);
243 "directMappedVelocityFluxFixedValueFvPatchField::"
245 ) << "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
246 << "mode" << nl << abort(FatalError);
250 operator==(newUValues);
251 phiField.boundaryField()[patch().index()] == newPhiValues;
254 UPstream::msgType() = oldTag;
256 fixedValueFvPatchVectorField::updateCoeffs();
260 void Foam::directMappedVelocityFluxFixedValueFvPatchField::write
265 fvPatchVectorField::write(os);
266 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
267 this->writeEntry("value", os);
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 directMappedVelocityFluxFixedValueFvPatchField
283 // ************************************************************************* //