Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedVelocityFluxFixedValue / directMappedVelocityFluxFixedValueFvPatchField.C
blobfe178ff0fb1f702fe995b4814f46e9dc9f83fe1a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
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
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
19     for more details.
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
39     const fvPatch& p,
40     const DimensionedField<vector, volMesh>& iF
43     fixedValueFvPatchVectorField(p, iF),
44     phiName_("phi")
48 Foam::directMappedVelocityFluxFixedValueFvPatchField::
49 directMappedVelocityFluxFixedValueFvPatchField
51     const directMappedVelocityFluxFixedValueFvPatchField& ptf,
52     const fvPatch& p,
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()))
61     {
62         FatalErrorIn
63         (
64             "directMappedVelocityFluxFixedValueFvPatchField::"
65             "directMappedVelocityFluxFixedValueFvPatchField"
66             "("
67                 "const directMappedVelocityFluxFixedValueFvPatchField&, "
68                 "const fvPatch&, "
69                 "const DimensionedField<vector, volMesh>&, "
70                 "const fvPatchFieldMapper&"
71             ")"
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()
77             << exit(FatalError);
78     }
82 Foam::directMappedVelocityFluxFixedValueFvPatchField::
83 directMappedVelocityFluxFixedValueFvPatchField
85     const fvPatch& p,
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()))
94     {
95         FatalErrorIn
96         (
97             "directMappedVelocityFluxFixedValueFvPatchField::"
98             "directMappedVelocityFluxFixedValueFvPatchField"
99             "("
100                 "const fvPatch&, "
101                 "const DimensionedField<vector, volMesh>&, "
102                 "const dictionary&"
103             ")"
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()
109             << exit(FatalError);
110     }
112     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
113     (
114         this->patch().patch()
115     );
116     if (mpp.mode() == directMappedPolyPatch::NEARESTCELL)
117     {
118         FatalErrorIn
119         (
120             "directMappedVelocityFluxFixedValueFvPatchField::"
121             "directMappedVelocityFluxFixedValueFvPatchField"
122             "("
123                 "const fvPatch&, "
124                 "const DimensionedField<vector, volMesh>&, "
125                 "const dictionary&"
126             ")"
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()
132             << exit(FatalError);
133     }
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()
164     if (updated())
165     {
166         return;
167     }
169     // Get the directMappedPatchBase
170     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
171     (
172         directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
173     );
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>
178     (
179         fieldName
180     );
182     surfaceScalarField& phiField = const_cast<surfaceScalarField&>
183     (
184         nbrMesh.lookupObject<surfaceScalarField>(phiName_)
185     );
187     vectorField newUValues;
188     scalarField newPhiValues;
190     switch (mpp.mode())
191     {
192         case directMappedPolyPatch::NEARESTFACE:
193         {
194             vectorField allUValues(nbrMesh.nFaces(), vector::zero);
195             scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
197             forAll(UField.boundaryField(), patchI)
198             {
199                 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
200                 const scalarField& phipf = phiField.boundaryField()[patchI];
202                 label faceStart = Upf.patch().start();
204                 forAll(Upf, faceI)
205                 {
206                     allUValues[faceStart + faceI] = Upf[faceI];
207                     allPhiValues[faceStart + faceI] = phipf[faceI];
208                 }
209             }
211             distMap.distribute(allUValues);
212             newUValues.transfer(allUValues);
214             distMap.distribute(allPhiValues);
215             newPhiValues.transfer(allPhiValues);
217             break;
218         }
219         case directMappedPolyPatch::NEARESTPATCHFACE:
220         {
221             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
222             (
223                 mpp.samplePatch()
224             );
226             newUValues = UField.boundaryField()[nbrPatchID];
227             distMap.distribute(newUValues);
229             newPhiValues = phiField.boundaryField()[nbrPatchID];
230             distMap.distribute(newPhiValues);
232             break;
233         }
234         default:
235         {
236             FatalErrorIn
237             (
238                 "directMappedVelocityFluxFixedValueFvPatchField::"
239                 "updateCoeffs()"
240             )   << "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
241                 << "mode" << nl << abort(FatalError);
242         }
243     }
245     operator==(newUValues);
246     phiField.boundaryField()[patch().index()] == newPhiValues;
248     fixedValueFvPatchVectorField::updateCoeffs();
252 void Foam::directMappedVelocityFluxFixedValueFvPatchField::write
254     Ostream& os
255 ) const
257     fvPatchVectorField::write(os);
258     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
259     this->writeEntry("value", os);
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 namespace Foam
267     makePatchTypeField
268     (
269         fvPatchVectorField,
270         directMappedVelocityFluxFixedValueFvPatchField
271     );
275 // ************************************************************************* //