1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
42 const DimensionedField<Type, volMesh>& iF
45 fixedValueFvPatchField<Type>(p, iF),
47 average_(pTraits<Type>::zero)
52 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
54 const directMappedFixedValueFvPatchField<Type>& ptf,
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()))
68 "directMappedFixedValueFvPatchField<Type>::"
69 "directMappedFixedValueFvPatchField\n"
71 " const directMappedFixedValueFvPatchField<Type>&,\n"
73 " const Field<Type>&,\n"
74 " const fvPatchFieldMapper&\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()
87 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
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()))
102 "directMappedFixedValueFvPatchField<Type>::"
103 "directMappedFixedValueFvPatchField\n"
105 " const fvPatch& p,\n"
106 " const DimensionedField<Type, volMesh>& iF,\n"
107 " const dictionary& dict\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()
120 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
122 const directMappedFixedValueFvPatchField<Type>& ptf
125 fixedValueFvPatchField<Type>(ptf),
126 setAverage_(ptf.setAverage_),
127 average_(ptf.average_)
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 * * * * * * * * * * * * * //
147 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
154 // Get the directMappedPolyPatch
155 const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
157 directMappedFixedValueFvPatchField<Type>::patch().patch()
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());
170 const labelPair& twoProcs = schedule[i];
171 label sendProc = twoProcs[0];
172 label recvProc = twoProcs[1];
174 if (Pstream::myProcNo() == sendProc)
176 OPstream toProc(Pstream::blocking, recvProc);
177 toProc<< IndirectList<Type>
179 this->internalField(),
180 sendCellLabels[recvProc]
185 // I am receiver. Receive from sendProc.
186 IPstream fromProc(Pstream::blocking, sendProc);
188 Field<Type> fromFld(fromProc);
191 const labelList& faceLabels = receiveFaceLabels[sendProc];
195 label patchFaceI = faceLabels[i];
197 newValues[patchFaceI] = fromFld[i];
202 // Do data from myself
204 IndirectList<Type> fromFld
206 this->internalField(),
207 sendCellLabels[Pstream::myProcNo()]
211 const labelList& faceLabels = receiveFaceLabels[Pstream::myProcNo()];
215 label patchFaceI = faceLabels[i];
217 newValues[patchFaceI] = fromFld[i];
224 gSum(this->patch().magSf()*newValues)
225 /gSum(this->patch().magSf());
227 if (mag(averagePsi)/mag(average_) > 0.5)
229 newValues *= mag(average_)/mag(averagePsi);
233 newValues += (average_ - averagePsi);
237 this->operator==(newValues);
239 fixedValueFvPatchField<Type>::updateCoeffs();
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 // ************************************************************************* //