1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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 // Get the directMappedPatchBase
170 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
172 directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
174 const mapDistribute& distMap = mpp.map();
175 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
176 const word& fieldName = dimensionedInternalField().name();
177 const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
182 surfaceScalarField& phiField = const_cast<surfaceScalarField&>
184 nbrMesh.lookupObject<surfaceScalarField>(phiName_)
187 vectorField newUValues;
188 scalarField newPhiValues;
192 case directMappedPolyPatch::NEARESTFACE:
194 vectorField allUValues(nbrMesh.nFaces(), vector::zero);
195 scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
197 forAll(UField.boundaryField(), patchI)
199 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
200 const scalarField& phipf = phiField.boundaryField()[patchI];
202 label faceStart = Upf.patch().start();
206 allUValues[faceStart + faceI] = Upf[faceI];
207 allPhiValues[faceStart + faceI] = phipf[faceI];
211 distMap.distribute(allUValues);
212 newUValues.transfer(allUValues);
214 distMap.distribute(allPhiValues);
215 newPhiValues.transfer(allPhiValues);
219 case directMappedPolyPatch::NEARESTPATCHFACE:
221 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
226 newUValues = UField.boundaryField()[nbrPatchID];
227 distMap.distribute(newUValues);
229 newPhiValues = phiField.boundaryField()[nbrPatchID];
230 distMap.distribute(newPhiValues);
238 "directMappedVelocityFluxFixedValueFvPatchField::"
240 ) << "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
241 << "mode" << nl << abort(FatalError);
245 operator==(newUValues);
246 phiField.boundaryField()[patch().index()] == newPhiValues;
248 fixedValueFvPatchVectorField::updateCoeffs();
252 void Foam::directMappedVelocityFluxFixedValueFvPatchField::write
257 fvPatchVectorField::write(os);
258 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
259 this->writeEntry("value", os);
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 directMappedVelocityFluxFixedValueFvPatchField
275 // ************************************************************************* //