Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedFixedValue / directMappedFixedValueFvPatchField.C
blobaaf927849c0fa67bc715dc035a365f08ee9df829
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 "directMappedFixedValueFvPatchField.H"
28 #include "directMappedPatchBase.H"
29 #include "volFields.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 template<class Type>
39 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
41     const fvPatch& p,
42     const DimensionedField<Type, volMesh>& iF
45     fixedValueFvPatchField<Type>(p, iF),
46     setAverage_(false),
47     average_(pTraits<Type>::zero)
51 template<class Type>
52 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
54     const directMappedFixedValueFvPatchField<Type>& ptf,
55     const fvPatch& p,
56     const DimensionedField<Type, volMesh>& iF,
57     const fvPatchFieldMapper& mapper
60     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
61     setAverage_(ptf.setAverage_),
62     average_(ptf.average_)
64     if (!isA<directMappedPatchBase>(this->patch().patch()))
65     {
66         FatalErrorIn
67         (
68             "directMappedFixedValueFvPatchField<Type>::"
69             "directMappedFixedValueFvPatchField\n"
70             "(\n"
71             "    const directMappedFixedValueFvPatchField<Type>&,\n"
72             "    const fvPatch&,\n"
73             "    const Field<Type>&,\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 " << this->dimensionedInternalField().name()
80             << " in file " << this->dimensionedInternalField().objectPath()
81             << exit(FatalError);
82     }
86 template<class Type>
87 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
89     const fvPatch& p,
90     const DimensionedField<Type, volMesh>& iF,
91     const dictionary& dict
94     fixedValueFvPatchField<Type>(p, iF, dict),
95     setAverage_(readBool(dict.lookup("setAverage"))),
96     average_(pTraits<Type>(dict.lookup("average")))
98     if (!isA<directMappedPatchBase>(this->patch().patch()))
99     {
100         FatalErrorIn
101         (
102             "directMappedFixedValueFvPatchField<Type>::"
103             "directMappedFixedValueFvPatchField\n"
104             "(\n"
105             "    const fvPatch& p,\n"
106             "    const DimensionedField<Type, 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 " << this->dimensionedInternalField().name()
113             << " in file " << this->dimensionedInternalField().objectPath()
114             << exit(FatalError);
115     }
119 template<class Type>
120 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
122     const directMappedFixedValueFvPatchField<Type>& ptf
125     fixedValueFvPatchField<Type>(ptf),
126     setAverage_(ptf.setAverage_),
127     average_(ptf.average_)
131 template<class Type>
132 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
134     const directMappedFixedValueFvPatchField<Type>& ptf,
135     const DimensionedField<Type, volMesh>& iF
138     fixedValueFvPatchField<Type>(ptf, iF),
139     setAverage_(ptf.setAverage_),
140     average_(ptf.average_)
144 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
146 template<class Type>
147 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
149     if (this->updated())
150     {
151         return;
152     }
154     typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
156     // Get the scheduling information from the directMappedPatchBase
157     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
158     (
159         directMappedFixedValueFvPatchField<Type>::patch().patch()
160     );
161     const mapDistribute& distMap = mpp.map();
163     // Force recalculation of schedule
164     distMap.schedule();
166     const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
167     const word& fldName = this->dimensionedInternalField().name();
169     // Result of obtaining remote values
170     Field<Type> newValues;
172     switch (mpp.mode())
173     {
174         case directMappedPatchBase::NEARESTCELL:
175         {
176             if (mpp.sameRegion())
177             {
178                 newValues = this->internalField();
179             }
180             else
181             {
182                 newValues = nbrMesh.lookupObject<fieldType>
183                 (
184                     fldName
185                 ).internalField();
186             }
187             mapDistribute::distribute
188             (
189                 Pstream::defaultCommsType,
190                 distMap.schedule(),
191                 distMap.constructSize(),
192                 distMap.subMap(),
193                 distMap.constructMap(),
194                 newValues
195             );
197             break;
198         }
199         case directMappedPatchBase::NEARESTPATCHFACE:
200         {
201             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
202             (
203                 mpp.samplePatch()
204             );
205             if (nbrPatchID < 0)
206             {
207                 FatalErrorIn
208                 (
209                     "void directMappedFixedValueFvPatchField<Type>::"
210                     "updateCoeffs()"
211                 )<< "Unable to find sample patch " << mpp.samplePatch()
212                  << " in region " << mpp.sampleRegion()
213                  << " for patch " << this->patch().name() << nl
214                  << abort(FatalError);
215             }
217             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
218             (
219                 fldName
220             );
221             newValues = nbrField.boundaryField()[nbrPatchID];
222             mapDistribute::distribute
223             (
224                 Pstream::defaultCommsType,
225                 distMap.schedule(),
226                 distMap.constructSize(),
227                 distMap.subMap(),
228                 distMap.constructMap(),
229                 newValues
230             );
232             break;
233         }
234         case directMappedPatchBase::NEARESTFACE:
235         {
236             Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
238             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
239             (
240                 fldName
241             );
242             forAll(nbrField.boundaryField(), patchI)
243             {
244                 const fvPatchField<Type>& pf =
245                     nbrField.boundaryField()[patchI];
246                 label faceStart = pf.patch().patch().start();
248                 forAll(pf, faceI)
249                 {
250                     allValues[faceStart++] = pf[faceI];
251                 }
252             }
254             mapDistribute::distribute
255             (
256                 Pstream::defaultCommsType,
257                 distMap.schedule(),
258                 distMap.constructSize(),
259                 distMap.subMap(),
260                 distMap.constructMap(),
261                 allValues
262             );
264             newValues = this->patch().patchSlice(allValues);
266             break;
267         }
268         default:
269         {
270             FatalErrorIn
271             (
272                 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
273             )<< "Unknown sampling mode: " << mpp.mode()
274              << nl << abort(FatalError);
275         }
276     }
278     if (setAverage_)
279     {
280         Type averagePsi =
281             gSum(this->patch().magSf()*newValues)
282            /gSum(this->patch().magSf());
284         if (mag(averagePsi)/mag(average_) > 0.5)
285         {
286             newValues *= mag(average_)/mag(averagePsi);
287         }
288         else
289         {
290             newValues += (average_ - averagePsi);
291         }
292     }
294     this->operator==(newValues);
296     if (debug)
297     {
298         Info<< "directMapped on field:" << fldName
299             << " patch:" << this->patch().name()
300             << "  avg:" << gAverage(*this)
301             << "  min:" << gMin(*this)
302             << "  max:" << gMax(*this)
303             << endl;
304     }
306     fixedValueFvPatchField<Type>::updateCoeffs();
310 template<class Type>
311 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
313     fvPatchField<Type>::write(os);
314     os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
315     os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
316     this->writeEntry("value", os);
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 } // End namespace Foam
324 // ************************************************************************* //