initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedFixedValue / directMappedFixedValueFvPatchField.C
blob3c4768855f6e6a9d01bd78c4608fb518ab130948
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 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 "directMappedFvPatch.H"
29 #include "fvBoundaryMesh.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 (!isType<directMappedFvPatch>(this->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 '" << 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 (!isType<directMappedFvPatch>(this->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 '" << 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     // Get the directMappedPolyPatch
155     const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
156     (
157         directMappedFixedValueFvPatchField<Type>::patch().patch()
158     );
160     // Get the scheduling information
161     const List<labelPair>& schedule = mpp.schedule();
162     const labelListList& sendCellLabels = mpp.sendCellLabels();
163     const labelListList& receiveFaceLabels = mpp.receiveFaceLabels();
166     Field<Type> newValues(this->size());
168     forAll(schedule, i)
169     {
170         const labelPair& twoProcs = schedule[i];
171         label sendProc = twoProcs[0];
172         label recvProc = twoProcs[1];
174         if (Pstream::myProcNo() == sendProc)
175         {
176             OPstream toProc(Pstream::blocking, recvProc);
177             toProc<< IndirectList<Type>
178             (
179                 this->internalField(),
180                 sendCellLabels[recvProc]
181             )();
182         }
183         else
184         {
185             // I am receiver. Receive from sendProc.
186             IPstream fromProc(Pstream::blocking, sendProc);
188             Field<Type> fromFld(fromProc);
190             // Destination faces
191             const labelList& faceLabels = receiveFaceLabels[sendProc];
193             forAll(fromFld, i)
194             {
195                 label patchFaceI = faceLabels[i];
197                 newValues[patchFaceI] = fromFld[i];
198             }
199         }
200     }
202     // Do data from myself
203     {
204         IndirectList<Type> fromFld
205         (
206             this->internalField(),
207             sendCellLabels[Pstream::myProcNo()]
208         );
209     
210         // Destination faces
211         const labelList& faceLabels = receiveFaceLabels[Pstream::myProcNo()];
213         forAll(fromFld, i)
214         {
215             label patchFaceI = faceLabels[i];
217             newValues[patchFaceI] = fromFld[i];
218         }
219     }
221     if (setAverage_)
222     {
223         Type averagePsi = 
224             gSum(this->patch().magSf()*newValues)
225            /gSum(this->patch().magSf());
227         if (mag(averagePsi)/mag(average_) > 0.5)
228         {
229             newValues *= mag(average_)/mag(averagePsi);
230         }
231         else
232         {
233             newValues += (average_ - averagePsi);
234         }
235     }
237     this->operator==(newValues);
239     fixedValueFvPatchField<Type>::updateCoeffs();
243 template<class Type>
244 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
246     fvPatchField<Type>::write(os);
247     os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
248     os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
249     this->writeEntry("value", os);
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 } // End namespace Foam
257 // ************************************************************************* //