Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedVelocityFluxFixedValue / directMappedVelocityFluxFixedValueFvPatchField.C
blob62673570d12f8b403476601aad3d1e4654ad6192
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 directMappedVelocityFluxFixedValueFvPatchField::
41 directMappedVelocityFluxFixedValueFvPatchField
43     const fvPatch& p,
44     const DimensionedField<vector, volMesh>& iF
47     fixedValueFvPatchVectorField(p, iF),
48     phiName_("undefinedPhi")
52 directMappedVelocityFluxFixedValueFvPatchField::
53 directMappedVelocityFluxFixedValueFvPatchField
55     const directMappedVelocityFluxFixedValueFvPatchField& ptf,
56     const fvPatch& p,
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()))
65     {
66         FatalErrorIn
67         (
68             "directMappedVelocityFluxFixedValueFvPatchField::"
69             "directMappedVelocityFluxFixedValueFvPatchField\n"
70             "(\n"
71             "    const directMappedVelocityFluxFixedValueFvPatchField&,\n"
72             "    const fvPatch&,\n"
73             "    const DimensionedField<vector, volMesh>&,\n"
74             "    const fvPatchFieldMapper&\n"
75             ")\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()
81             << exit(FatalError);
82     }
86 directMappedVelocityFluxFixedValueFvPatchField::
87 directMappedVelocityFluxFixedValueFvPatchField
89     const fvPatch& p,
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()))
98     {
99         FatalErrorIn
100         (
101             "directMappedVelocityFluxFixedValueFvPatchField::"
102             "directMappedVelocityFluxFixedValueFvPatchField\n"
103             "(\n"
104             "    const fvPatch& p,\n"
105             "    const DimensionedField<vector, volMesh>& iF,\n"
106             "    const dictionary& dict\n"
107             ")\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()
113             << exit(FatalError);
114     }
116     // Force calculation of schedule (uses parallel comms)
117     const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
118     (
119         patch().patch()
120     );
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()
152     if (updated())
153     {
154         return;
155     }
157     // Get the directMappedPatchBase
158     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
159     (
160         directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
161     );
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>
166     (
167         fieldName
168     );
170     surfaceScalarField& phiField = const_cast<surfaceScalarField&>
171     (
172         nbrMesh.lookupObject<surfaceScalarField>(phiName_)
173     );
175     vectorField newUValues;
176     scalarField newPhiValues;
178     switch (mpp.mode())
179     {
180         case directMappedPolyPatch::NEARESTFACE:
181         {
182             vectorField allUValues(nbrMesh.nFaces(), vector::zero);
183             scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
185             forAll(UField.boundaryField(), patchI)
186             {
187                 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
188                 const scalarField& phipf = phiField.boundaryField()[patchI];
190                 label faceStart = Upf.patch().patch().start();
192                 forAll(Upf, faceI)
193                 {
194                     allUValues[faceStart++] = Upf[faceI];
195                     allPhiValues[faceStart] = phipf[faceI];
196                 }
197             }
199             mapDistribute::distribute
200             (
201                 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
202                 distMap.schedule(),
203                 distMap.constructSize(),
204                 distMap.subMap(),
205                 distMap.constructMap(),
206                 allUValues
207             );
208             newUValues = patch().patchSlice(newUValues);
210             mapDistribute::distribute
211             (
212                 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
213                 distMap.schedule(),
214                 distMap.constructSize(),
215                 distMap.subMap(),
216                 distMap.constructMap(),
217                 newPhiValues
218             );
219             newPhiValues = patch().patchSlice(newPhiValues);
221             break;
222         }
223         case directMappedPolyPatch::NEARESTPATCHFACE:
224         {
225             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
226             (
227                 mpp.samplePatch()
228             );
230             newUValues = UField.boundaryField()[nbrPatchID];
232             mapDistribute::distribute
233             (
234                 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
235                 distMap.schedule(),
236                 distMap.constructSize(),
237                 distMap.subMap(),
238                 distMap.constructMap(),
239                 newUValues
240             );
242             newPhiValues = phiField.boundaryField()[nbrPatchID];
244             mapDistribute::distribute
245             (
246                 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
247                 distMap.schedule(),
248                 distMap.constructSize(),
249                 distMap.subMap(),
250                 distMap.constructMap(),
251                 newPhiValues
252             );
254             break;
255         }
256         default:
257         {
258             FatalErrorIn
259             (
260                 "directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()"
261             )<< "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
262              << "mode" << nl << abort(FatalError);
263         }
264     }
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 makePatchTypeField
284     fvPatchVectorField,
285     directMappedVelocityFluxFixedValueFvPatchField
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 } // End namespace Foam
292 // ************************************************************************* //