1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 directMappedVelocityFluxFixedValueFvPatchField::
41 directMappedVelocityFluxFixedValueFvPatchField
44 const DimensionedField<vector, volMesh>& iF
47 fixedValueFvPatchVectorField(p, iF),
48 phiName_("undefinedPhi")
52 directMappedVelocityFluxFixedValueFvPatchField::
53 directMappedVelocityFluxFixedValueFvPatchField
55 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
57 const DimensionedField<vector, volMesh>& iF,
58 const fvPatchFieldMapper& mapper
61 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
62 phiName_(ptf.phiName_)
64 if (!isA<directMappedPatchBase>(this->patch().patch()))
68 "directMappedVelocityFluxFixedValueFvPatchField::"
69 "directMappedVelocityFluxFixedValueFvPatchField\n"
71 " const directMappedVelocityFluxFixedValueFvPatchField&,\n"
73 " const DimensionedField<vector, volMesh>&,\n"
74 " const fvPatchFieldMapper&\n"
76 ) << "\n patch type '" << p.type()
77 << "' not type '" << directMappedPatchBase::typeName << "'"
78 << "\n for patch " << p.name()
79 << " of field " << dimensionedInternalField().name()
80 << " in file " << dimensionedInternalField().objectPath()
86 directMappedVelocityFluxFixedValueFvPatchField::
87 directMappedVelocityFluxFixedValueFvPatchField
90 const DimensionedField<vector, volMesh>& iF,
91 const dictionary& dict
94 fixedValueFvPatchVectorField(p, iF, dict),
95 phiName_(dict.lookup("phi"))
97 if (!isA<directMappedPatchBase>(this->patch().patch()))
101 "directMappedVelocityFluxFixedValueFvPatchField::"
102 "directMappedVelocityFluxFixedValueFvPatchField\n"
104 " const fvPatch& p,\n"
105 " const DimensionedField<vector, volMesh>& iF,\n"
106 " const dictionary& dict\n"
108 ) << "\n patch type '" << p.type()
109 << "' not type '" << directMappedPatchBase::typeName << "'"
110 << "\n for patch " << p.name()
111 << " of field " << dimensionedInternalField().name()
112 << " in file " << dimensionedInternalField().objectPath()
116 // Force calculation of schedule (uses parallel comms)
117 const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
121 (void)mpp.map().schedule();
125 directMappedVelocityFluxFixedValueFvPatchField::
126 directMappedVelocityFluxFixedValueFvPatchField
128 const directMappedVelocityFluxFixedValueFvPatchField& ptf
131 fixedValueFvPatchVectorField(ptf),
132 phiName_(ptf.phiName_)
136 directMappedVelocityFluxFixedValueFvPatchField::
137 directMappedVelocityFluxFixedValueFvPatchField
139 const directMappedVelocityFluxFixedValueFvPatchField& ptf,
140 const DimensionedField<vector, volMesh>& iF
143 fixedValueFvPatchVectorField(ptf, iF),
144 phiName_(ptf.phiName_)
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
157 // Get the directMappedPatchBase
158 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
160 directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
162 const mapDistribute& distMap = mpp.map();
163 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
164 const word& fieldName = dimensionedInternalField().name();
165 const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
170 surfaceScalarField& phiField = const_cast<surfaceScalarField&>
172 nbrMesh.lookupObject<surfaceScalarField>(phiName_)
175 vectorField newUValues;
176 scalarField newPhiValues;
180 case directMappedPolyPatch::NEARESTFACE:
182 vectorField allUValues(nbrMesh.nFaces(), vector::zero);
183 scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
185 forAll(UField.boundaryField(), patchI)
187 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
188 const scalarField& phipf = phiField.boundaryField()[patchI];
190 label faceStart = Upf.patch().patch().start();
194 allUValues[faceStart++] = Upf[faceI];
195 allPhiValues[faceStart] = phipf[faceI];
199 mapDistribute::distribute
201 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
203 distMap.constructSize(),
205 distMap.constructMap(),
208 newUValues = patch().patchSlice(newUValues);
210 mapDistribute::distribute
212 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
214 distMap.constructSize(),
216 distMap.constructMap(),
219 newPhiValues = patch().patchSlice(newPhiValues);
223 case directMappedPolyPatch::NEARESTPATCHFACE:
225 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
230 newUValues = UField.boundaryField()[nbrPatchID];
232 mapDistribute::distribute
234 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
236 distMap.constructSize(),
238 distMap.constructMap(),
242 newPhiValues = phiField.boundaryField()[nbrPatchID];
244 mapDistribute::distribute
246 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
248 distMap.constructSize(),
250 distMap.constructMap(),
260 "directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()"
261 )<< "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
262 << "mode" << nl << abort(FatalError);
266 operator==(newUValues);
267 phiField.boundaryField()[patch().index()] == newPhiValues;
269 fixedValueFvPatchVectorField::updateCoeffs();
273 void directMappedVelocityFluxFixedValueFvPatchField::write(Ostream& os) const
275 fvPatchVectorField::write(os);
276 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
277 this->writeEntry("value", os);
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 directMappedVelocityFluxFixedValueFvPatchField
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 } // End namespace Foam
292 // ************************************************************************* //