FreeFOAM The Cross-Platform CFD Toolkit
directMappedVelocityFluxFixedValueFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
29 #include <finiteVolume/volFields.H>
32 #include <OpenFOAM/mapDistribute.H>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
43 (
44  const fvPatch& p,
46 )
47 :
48  fixedValueFvPatchVectorField(p, iF),
49  phiName_("undefinedPhi")
50 {}
51 
52 
55 (
57  const fvPatch& p,
59  const fvPatchFieldMapper& mapper
60 )
61 :
62  fixedValueFvPatchVectorField(ptf, p, iF, mapper),
63  phiName_(ptf.phiName_)
64 {
65  if (!isA<directMappedPatchBase>(this->patch().patch()))
66  {
68  (
69  "directMappedVelocityFluxFixedValueFvPatchField::"
70  "directMappedVelocityFluxFixedValueFvPatchField\n"
71  "(\n"
72  " const directMappedVelocityFluxFixedValueFvPatchField&,\n"
73  " const fvPatch&,\n"
74  " const DimensionedField<vector, volMesh>&,\n"
75  " const fvPatchFieldMapper&\n"
76  ")\n"
77  ) << "\n patch type '" << p.type()
78  << "' not type '" << directMappedPatchBase::typeName << "'"
79  << "\n for patch " << p.name()
80  << " of field " << dimensionedInternalField().name()
81  << " in file " << dimensionedInternalField().objectPath()
82  << exit(FatalError);
83  }
84 }
85 
86 
89 (
90  const fvPatch& p,
92  const dictionary& dict
93 )
94 :
95  fixedValueFvPatchVectorField(p, iF, dict),
96  phiName_(dict.lookup("phi"))
97 {
98  if (!isA<directMappedPatchBase>(this->patch().patch()))
99  {
101  (
102  "directMappedVelocityFluxFixedValueFvPatchField::"
103  "directMappedVelocityFluxFixedValueFvPatchField\n"
104  "(\n"
105  " const fvPatch& p,\n"
106  " const DimensionedField<vector, 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 " << dimensionedInternalField().name()
113  << " in file " << dimensionedInternalField().objectPath()
114  << exit(FatalError);
115  }
116 }
117 
118 
121 (
123 )
124 :
125  fixedValueFvPatchVectorField(ptf),
126  phiName_(ptf.phiName_)
127 {}
128 
129 
132 (
135 )
136 :
137  fixedValueFvPatchVectorField(ptf, iF),
138  phiName_(ptf.phiName_)
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 {
146  if (updated())
147  {
148  return;
149  }
150 
151  // Get the directMappedPatchBase
152  const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
153  (
154  directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
155  );
156  const mapDistribute& distMap = mpp.map();
157  const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
158  const word& fieldName = dimensionedInternalField().name();
159  const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
160  (
161  fieldName
162  );
163 
164  surfaceScalarField& phiField = const_cast<surfaceScalarField&>
165  (
166  nbrMesh.lookupObject<surfaceScalarField>(phiName_)
167  );
168 
169  vectorField newUValues;
170  scalarField newPhiValues;
171 
172  switch (mpp.mode())
173  {
175  {
176  vectorField allUValues(nbrMesh.nFaces(), vector::zero);
177  scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
178 
179  forAll(UField.boundaryField(), patchI)
180  {
181  const fvPatchVectorField& Upf = UField.boundaryField()[patchI];
182  const scalarField& phipf = phiField.boundaryField()[patchI];
183 
184  label faceStart = Upf.patch().patch().start();
185 
186  forAll(Upf, faceI)
187  {
188  allUValues[faceStart + faceI] = Upf[faceI];
189  allPhiValues[faceStart + faceI] = phipf[faceI];
190  }
191  }
192 
194  (
196  distMap.schedule(),
197  distMap.constructSize(),
198  distMap.subMap(),
199  distMap.constructMap(),
200  allUValues
201  );
202  newUValues.transfer(allUValues);
203 
205  (
207  distMap.schedule(),
208  distMap.constructSize(),
209  distMap.subMap(),
210  distMap.constructMap(),
211  allPhiValues
212  );
213  newPhiValues.transfer(allPhiValues);
214 
215  break;
216  }
218  {
219  const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
220  (
221  mpp.samplePatch()
222  );
223 
224  newUValues = UField.boundaryField()[nbrPatchID];
225 
227  (
229  distMap.schedule(),
230  distMap.constructSize(),
231  distMap.subMap(),
232  distMap.constructMap(),
233  newUValues
234  );
235 
236  newPhiValues = phiField.boundaryField()[nbrPatchID];
237 
239  (
241  distMap.schedule(),
242  distMap.constructSize(),
243  distMap.subMap(),
244  distMap.constructMap(),
245  newPhiValues
246  );
247 
248  break;
249  }
250  default:
251  {
253  (
254  "directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()"
255  )<< "patch can only be used in NEARESTPATCHFACE or NEARESTFACE "
256  << "mode" << nl << abort(FatalError);
257  }
258  }
259 
260  operator==(newUValues);
261  phiField.boundaryField()[patch().index()] == newPhiValues;
262 
264 }
265 
266 
268 {
270  os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
271  this->writeEntry("value", os);
272 }
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
277 (
280 );
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // ************************ vim: set sw=4 sts=4 et: ************************ //