fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedVelocityFluxFixedValue / directMappedVelocityFluxFixedValueFvPatchField.C
blobf6edf6ecb944daf9b8317e7286bf2d72b7dc59cd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 directMappedVelocityFluxFixedValueFvPatchField::
42 directMappedVelocityFluxFixedValueFvPatchField
44     const fvPatch& p,
45     const DimensionedField<vector, volMesh>& iF
48     fixedValueFvPatchVectorField(p, iF),
49     phiName_("undefinedPhi")
53 directMappedVelocityFluxFixedValueFvPatchField::
54 directMappedVelocityFluxFixedValueFvPatchField
56     const directMappedVelocityFluxFixedValueFvPatchField& ptf,
57     const fvPatch& p,
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()))
66     {
67         FatalErrorIn
68         (
69             "directMappedVelocityFluxFixedValueFvPatchField::"
70             "directMappedVelocityFluxFixedValueFvPatchField\n"
71             "(\n"
72             "    const directMappedVelocityFluxFixedValueFvPatchField&,\n"
73             "    const fvPatch&,\n"
74             "    const DimensionedField<vector, volMesh>&,\n"
75             "    const fvPatchFieldMapper&\n"
76             ")\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()
82             << exit(FatalError);
83     }
87 directMappedVelocityFluxFixedValueFvPatchField::
88 directMappedVelocityFluxFixedValueFvPatchField
90     const fvPatch& p,
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()))
99     {
100         FatalErrorIn
101         (
102             "directMappedVelocityFluxFixedValueFvPatchField::"
103             "directMappedVelocityFluxFixedValueFvPatchField\n"
104             "(\n"
105             "    const fvPatch& p,\n"
106             "    const DimensionedField<vector, volMesh>& iF,\n"
107             "    const dictionary& dict\n"
108             ")\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()
114             << exit(FatalError);
115     }
117     // Force calculation of schedule (uses parallel comms)
118     const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
119     (
120         patch().patch()
121     );
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()
153     if (updated())
154     {
155         return;
156     }
158     // Get the directMappedPatchBase
159     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
160     (
161         directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
162     );
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>
167     (
168         fieldName
169     );
171     surfaceScalarField& phiField = const_cast<surfaceScalarField&>
172     (
173         nbrMesh.lookupObject<surfaceScalarField>(phiName_)
174     );
176     vectorField newUValues;
177     scalarField newPhiValues;
179     switch (mpp.mode())
180     {
181         case directMappedPolyPatch::NEARESTFACE:
182         {
183             vectorField allUValues(nbrMesh.nFaces(), vector::zero);
184             scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
186             forAll(UField.boundaryField(), patchI)
187             {
188                 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
189                 const scalarField& phipf = phiField.boundaryField()[patchI];
191                 label faceStart = Upf.patch().patch().start();
193                 forAll(Upf, faceI)
194                 {
195                     allUValues[faceStart++] = Upf[faceI];
196                     allPhiValues[faceStart] = phipf[faceI];
197                 }
198             }
200             mapDistribute::distribute
201             (
202                 Pstream::defaultCommsType,
203                 distMap.schedule(),
204                 distMap.constructSize(),
205                 distMap.subMap(),
206                 distMap.constructMap(),
207                 allUValues
208             );
209             newUValues = patch().patchSlice(newUValues);
211             mapDistribute::distribute
212             (
213                 Pstream::defaultCommsType,
214                 distMap.schedule(),
215                 distMap.constructSize(),
216                 distMap.subMap(),
217                 distMap.constructMap(),
218                 newPhiValues
219             );
220             newPhiValues = patch().patchSlice(newPhiValues);
222             break;
223         }
224         case directMappedPolyPatch::NEARESTPATCHFACE:
225         {
226             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
227             (
228                 mpp.samplePatch()
229             );
231             newUValues = UField.boundaryField()[nbrPatchID];
233             mapDistribute::distribute
234             (
235                 Pstream::defaultCommsType,
236                 distMap.schedule(),
237                 distMap.constructSize(),
238                 distMap.subMap(),
239                 distMap.constructMap(),
240                 newUValues
241             );
243             newPhiValues = phiField.boundaryField()[nbrPatchID];
245             mapDistribute::distribute
246             (
247                 Pstream::defaultCommsType,
248                 distMap.schedule(),
249                 distMap.constructSize(),
250                 distMap.subMap(),
251                 distMap.constructMap(),
252                 newPhiValues
253             );
255             break;
256         }
257         default:
258         {
259             FatalErrorIn
260             (
261                 "directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()"
262             )<< "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
263              << "mode" << nl << abort(FatalError);
264         }
265     }
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 makePatchTypeField
285     fvPatchVectorField,
286     directMappedVelocityFluxFixedValueFvPatchField
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 } // End namespace Foam
293 // ************************************************************************* //