BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / directMappedVelocityFluxFixedValue / directMappedVelocityFluxFixedValueFvPatchField.C
blobcaf00eff10438ae8e39d2f945592573f3758fe4c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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     // Since we're inside initEvaluate/evaluate there might be processor
170     // comms underway. Change the tag we use.
171     int oldTag = UPstream::msgType();
172     UPstream::msgType() = oldTag+1;
174     // Get the directMappedPatchBase
175     const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
176     (
177         directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
178     );
179     const mapDistribute& distMap = mpp.map();
180     const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
181     const word& fieldName = dimensionedInternalField().name();
182     const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
183     (
184         fieldName
185     );
187     surfaceScalarField& phiField = const_cast<surfaceScalarField&>
188     (
189         nbrMesh.lookupObject<surfaceScalarField>(phiName_)
190     );
192     vectorField newUValues;
193     scalarField newPhiValues;
195     switch (mpp.mode())
196     {
197         case directMappedPolyPatch::NEARESTFACE:
198         {
199             vectorField allUValues(nbrMesh.nFaces(), vector::zero);
200             scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
202             forAll(UField.boundaryField(), patchI)
203             {
204                 const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
205                 const scalarField& phipf = phiField.boundaryField()[patchI];
207                 label faceStart = Upf.patch().start();
209                 forAll(Upf, faceI)
210                 {
211                     allUValues[faceStart + faceI] = Upf[faceI];
212                     allPhiValues[faceStart + faceI] = phipf[faceI];
213                 }
214             }
216             distMap.distribute(allUValues);
217             newUValues.transfer(allUValues);
219             distMap.distribute(allPhiValues);
220             newPhiValues.transfer(allPhiValues);
222             break;
223         }
224         case directMappedPolyPatch::NEARESTPATCHFACE:
225         {
226             const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
227             (
228                 mpp.samplePatch()
229             );
231             newUValues = UField.boundaryField()[nbrPatchID];
232             distMap.distribute(newUValues);
234             newPhiValues = phiField.boundaryField()[nbrPatchID];
235             distMap.distribute(newPhiValues);
237             break;
238         }
239         default:
240         {
241             FatalErrorIn
242             (
243                 "directMappedVelocityFluxFixedValueFvPatchField::"
244                 "updateCoeffs()"
245             )   << "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
246                 << "mode" << nl << abort(FatalError);
247         }
248     }
250     operator==(newUValues);
251     phiField.boundaryField()[patch().index()] == newPhiValues;
253     // Restore tag
254     UPstream::msgType() = oldTag;
256     fixedValueFvPatchVectorField::updateCoeffs();
260 void Foam::directMappedVelocityFluxFixedValueFvPatchField::write
262     Ostream& os
263 ) const
265     fvPatchVectorField::write(os);
266     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
267     this->writeEntry("value", os);
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 namespace Foam
275     makePatchTypeField
276     (
277         fvPatchVectorField,
278         directMappedVelocityFluxFixedValueFvPatchField
279     );
283 // ************************************************************************* //