fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedFixedValue / directMappedFixedValueFvPatchField.C
blob9146919d0a744c4fba1af8c8dd6cb746f41150ce
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
37 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
39 template<class Type>
40 void directMappedFixedValueFvPatchField<Type>::mapField()
42     typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
44     // Get the scheduling information from the directMappedPatchBase
45     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
46     (
47         directMappedFixedValueFvPatchField<Type>::patch().patch()
48     );
49     const mapDistribute& distMap = mpp.map();
51     // Force recalculation of schedule
52     distMap.schedule();
54     const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
55     const word& fldName = this->dimensionedInternalField().name();
57     // Result of obtaining remote values
58     if (debug)
59     {
60         Info<< "direct mapping field "
61             << this->dimensionedInternalField().name() << endl;
62     }
64     switch (mpp.mode())
65     {
66         case directMappedPatchBase::NEARESTCELL:
67         {
68             if (mpp.sameRegion())
69             {
70                 newValues_ = this->internalField();
71             }
72             else
73             {
74                 newValues_ = nbrMesh.lookupObject<fieldType>
75                 (
76                     fldName
77                 ).internalField();
78             }
79             mapDistribute::distribute
80             (
81                 Pstream::defaultCommsType,
82                 distMap.schedule(),
83                 distMap.constructSize(),
84                 distMap.subMap(),
85                 distMap.constructMap(),
86                 newValues_
87             );
89             break;
90         }
91         case directMappedPatchBase::NEARESTPATCHFACE:
92         {
93             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
94             (
95                 mpp.samplePatch()
96             );
97             if (nbrPatchID < 0)
98             {
99                 FatalErrorIn
100                 (
101                     "void directMappedFixedValueFvPatchField<Type>::"
102                     "updateCoeffs()"
103                 )<< "Unable to find sample patch " << mpp.samplePatch()
104                  << " in region " << mpp.sampleRegion()
105                  << " for patch " << this->patch().name() << nl
106                  << abort(FatalError);
107             }
109             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
110             (
111                 fldName
112             );
113             newValues_ = nbrField.boundaryField()[nbrPatchID];
114             mapDistribute::distribute
115             (
116                 Pstream::defaultCommsType,
117                 distMap.schedule(),
118                 distMap.constructSize(),
119                 distMap.subMap(),
120                 distMap.constructMap(),
121                 newValues_
122             );
124             break;
125         }
126         case directMappedPatchBase::NEARESTFACE:
127         {
128             Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
130             const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
131             (
132                 fldName
133             );
134             forAll(nbrField.boundaryField(), patchI)
135             {
136                 const fvPatchField<Type>& pf =
137                     nbrField.boundaryField()[patchI];
138                 label faceStart = pf.patch().patch().start();
140                 forAll(pf, faceI)
141                 {
142                     allValues[faceStart++] = pf[faceI];
143                 }
144             }
146             mapDistribute::distribute
147             (
148                 Pstream::defaultCommsType,
149                 distMap.schedule(),
150                 distMap.constructSize(),
151                 distMap.subMap(),
152                 distMap.constructMap(),
153                 allValues
154             );
156             newValues_ = this->patch().patchSlice(allValues);
158             break;
159         }
160         default:
161         {
162             FatalErrorIn
163             (
164                 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
165             )<< "Unknown sampling mode: " << mpp.mode()
166              << nl << abort(FatalError);
167         }
168     }
170     if (setAverage_)
171     {
172         Type averagePsi =
173             gSum(this->patch().magSf()*newValues_)
174            /gSum(this->patch().magSf());
176         if (mag(averagePsi)/mag(average_) > 0.5)
177         {
178             newValues_ *= mag(average_)/mag(averagePsi);
179         }
180         else
181         {
182             newValues_ += (average_ - averagePsi);
183         }
184     }
186     if (debug)
187     {
188         Info<< "directMapped on field:" << fldName
189             << " patch:" << this->patch().name()
190             << "  avg:" << gAverage(newValues_)
191             << "  min:" << gMin(newValues_)
192             << "  max:" << gMax(newValues_)
193             << endl;
194     }
198 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
200 template<class Type>
201 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
203     const fvPatch& p,
204     const DimensionedField<Type, volMesh>& iF
207     fixedValueFvPatchField<Type>(p, iF),
208     setAverage_(false),
209     average_(pTraits<Type>::zero),
210     curTimeIndex_(-1)
214 template<class Type>
215 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
217     const fvPatch& p,
218     const DimensionedField<Type, volMesh>& iF,
219     const dictionary& dict
222     fixedValueFvPatchField<Type>(p, iF, dict),
223     setAverage_(readBool(dict.lookup("setAverage"))),
224     average_(pTraits<Type>(dict.lookup("average"))),
225     curTimeIndex_(-1)
227     if (!isA<directMappedPatchBase>(this->patch().patch()))
228     {
229         FatalErrorIn
230         (
231             "directMappedFixedValueFvPatchField<Type>::"
232             "directMappedFixedValueFvPatchField\n"
233             "(\n"
234             "    const fvPatch& p,\n"
235             "    const DimensionedField<Type, volMesh>& iF,\n"
236             "    const dictionary& dict\n"
237             ")\n"
238         )   << "\n    patch type '" << p.type()
239             << "' not type '" << directMappedPatchBase::typeName << "'"
240             << "\n    for patch " << p.name()
241             << " of field " << this->dimensionedInternalField().name()
242             << " in file " << this->dimensionedInternalField().objectPath()
243             << exit(FatalError);
244     }
248 template<class Type>
249 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
251     const directMappedFixedValueFvPatchField<Type>& ptf,
252     const fvPatch& p,
253     const DimensionedField<Type, volMesh>& iF,
254     const fvPatchFieldMapper& mapper
257     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
258     setAverage_(ptf.setAverage_),
259     average_(ptf.average_),
260     curTimeIndex_(-1)
262     if (!isA<directMappedPatchBase>(this->patch().patch()))
263     {
264         FatalErrorIn
265         (
266             "directMappedFixedValueFvPatchField<Type>::"
267             "directMappedFixedValueFvPatchField\n"
268             "(\n"
269             "    const directMappedFixedValueFvPatchField<Type>&,\n"
270             "    const fvPatch&,\n"
271             "    const Field<Type>&,\n"
272             "    const fvPatchFieldMapper&\n"
273             ")\n"
274         )   << "\n    patch type '" << p.type()
275             << "' not type '" << directMappedPatchBase::typeName << "'"
276             << "\n    for patch " << p.name()
277             << " of field " << this->dimensionedInternalField().name()
278             << " in file " << this->dimensionedInternalField().objectPath()
279             << exit(FatalError);
280     }
284 template<class Type>
285 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
287     const directMappedFixedValueFvPatchField<Type>& ptf
290     fixedValueFvPatchField<Type>(ptf),
291     setAverage_(ptf.setAverage_),
292     average_(ptf.average_),
293     curTimeIndex_(-1)
297 template<class Type>
298 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
300     const directMappedFixedValueFvPatchField<Type>& ptf,
301     const DimensionedField<Type, volMesh>& iF
304     fixedValueFvPatchField<Type>(ptf, iF),
305     setAverage_(ptf.setAverage_),
306     average_(ptf.average_),
307     curTimeIndex_(-1)
311 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
313 template<class Type>
314 void directMappedFixedValueFvPatchField<Type>::initEvaluate
316     const Pstream::commsTypes commsType
319     // Note: All parallel comms need to happen at this stage
320     // HJ, 13/Mar/2012
322     // Only map
323     if (curTimeIndex_ != this->db().time().timeIndex())
324     {
325         mapField();
327         curTimeIndex_ = this->db().time().timeIndex();
328     }
332 template<class Type>
333 void directMappedFixedValueFvPatchField<Type>::evaluate
335     const Pstream::commsTypes commsType
338     this->operator==(newValues_);
340     fixedValueFvPatchField<Type>::evaluate();
344 template<class Type>
345 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
347     fvPatchField<Type>::write(os);
348     os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
349     os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
350     this->writeEntry("value", os);
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 } // End namespace Foam
358 // ************************************************************************* //