FreeFOAM The Cross-Platform CFD Toolkit
timeVaryingMappedTotalPressureFvPatchScalarField.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>
31 
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
37 (
38  const fvPatch& p,
40 )
41 :
42  timeVaryingMappedFixedValueFvPatchScalarField(p, iF),
43  UName_("U"),
44  phiName_("phi"),
45  rhoName_("none"),
46  rho_(1),
47  psiName_("none"),
48  gamma_(0.0)
49 {}
50 
51 
54 (
55  const fvPatch& p,
57  const dictionary& dict
58 )
59 :
60  timeVaryingMappedFixedValueFvPatchScalarField(p, iF, dict),
61  UName_(dict.lookupOrDefault<word>("UName", "U")),
62  phiName_(dict.lookupOrDefault<word>("phiName", "phi")),
63  rhoName_(dict.lookupOrDefault<word>("rhoName", "none")),
64  rho_
65  (
66  iF.dimensions() == dimPressure/dimDensity && rhoName_ == "rho"
67  ? readScalar(dict.lookup("rho"))
68  : 1
69  ),
70  psiName_(dict.lookupOrDefault<word>("psiName", "none")),
71  gamma_
72  (
73  iF.dimensions() == dimPressure && psiName_ != "none"
74  ? readScalar(dict.lookup("gamma"))
75  : 1
76  )
77 {}
78 
79 
82 (
84  const fvPatch& p,
86  const fvPatchFieldMapper& mapper
87 )
88 :
89  timeVaryingMappedFixedValueFvPatchScalarField(ptf, p, iF, mapper),
90  UName_(ptf.UName_),
91  phiName_(ptf.phiName_),
92  rhoName_(ptf.rhoName_),
93  rho_(ptf.rho_),
94  psiName_(ptf.psiName_),
95  gamma_(ptf.gamma_)
96 {}
97 
98 
101 (
103 )
104 :
105  timeVaryingMappedFixedValueFvPatchScalarField(tppsf),
106  UName_(tppsf.UName_),
107  phiName_(tppsf.phiName_),
108  rhoName_(tppsf.rhoName_),
109  rho_(tppsf.rho_),
110  psiName_(tppsf.psiName_),
111  gamma_(tppsf.gamma_)
112 {}
113 
114 
117 (
120 )
121 :
122  timeVaryingMappedFixedValueFvPatchScalarField(tppsf, iF),
123  UName_(tppsf.UName_),
124  phiName_(tppsf.phiName_),
125  rhoName_(tppsf.rhoName_),
126  rho_(tppsf.rho_),
127  psiName_(tppsf.psiName_),
128  gamma_(tppsf.gamma_)
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 (
136  const fvPatchFieldMapper& m
137 )
138 {
139  timeVaryingMappedFixedValueFvPatchScalarField::autoMap(m);
140 }
141 
142 
144 (
145  const fvPatchScalarField& ptf,
146  const labelList& addr
147 )
148 {
149  timeVaryingMappedFixedValueFvPatchScalarField::rmap(ptf, addr);
150 }
151 
152 
154 (
155  const vectorField& Up
156 )
157 {
158  if (updated())
159  {
160  return;
161  }
162 
163  // Map the total-pressure field onto this field
164  timeVaryingMappedFixedValueFvPatchScalarField::updateCoeffs();
165  const scalarField p0 = *this;
166 
167  const fvsPatchField<scalar>& phip =
168  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
169 
170  if (dimensionedInternalField().dimensions() == dimPressure/dimDensity)
171  {
172  if (rhoName_ == "none")
173  {
174  operator==(p0 - 0.5*(1.0 - pos(phip))*magSqr(Up));
175  }
176  else if (rhoName_ == "rho")
177  {
178  operator==(p0/rho_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
179  }
180  else
181  {
183  (
184  "timeVaryingMappedTotalPressureFvPatchScalarField::"
185  "updateCoeffs()"
186  ) << " rhoName set inconsistently, rhoName = " << rhoName_
187  << ".\n"
188  << " Set rhoName to 'rho' or 'none' depending on the "
189  "definition of total pressure." << nl
190  << " on patch " << this->patch().name()
191  << " of field " << this->dimensionedInternalField().name()
192  << " in file " << this->dimensionedInternalField().objectPath()
193  << exit(FatalError);
194  }
195  }
196  else if (dimensionedInternalField().dimensions() == dimPressure)
197  {
198  if (rhoName_ != "none")
199  {
200  const fvPatchField<scalar>& rho =
201  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
202 
203  operator==(p0 - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
204  }
205  else if (psiName_ != "none")
206  {
207  const fvPatchField<scalar>& psip =
208  patch().lookupPatchField<volScalarField, scalar>(psiName_);
209 
210  if (gamma_ > 1.0)
211  {
212  scalar gM1ByG = (gamma_ - 1.0)/gamma_;
213 
214  operator==
215  (
216  p0
217  /pow
218  (
219  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
220  1.0/gM1ByG
221  )
222  );
223  }
224  else
225  {
226  operator==(p0/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
227  }
228  }
229  else
230  {
232  (
233  "timeVaryingMappedTotalPressureFvPatchScalarField::"
234  "updateCoeffs()"
235  ) << " rhoName or psiName set inconsistently, rhoName = "
236  << rhoName_ << ", psiName = " << psiName_ << ".\n"
237  << " Set either rhoName or psiName depending on the "
238  "definition of total pressure." << nl
239  << " Set the unused variable(s) to 'none'.\n"
240  << " on patch " << this->patch().name()
241  << " of field " << this->dimensionedInternalField().name()
242  << " in file " << this->dimensionedInternalField().objectPath()
243  << exit(FatalError);
244  }
245  }
246  else
247  {
249  (
250  "timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()"
251  ) << "Incorrect dimensions for pressure "
252  << dimensionedInternalField().dimensions()
253  << " Should be either " << dimPressure
254  << " for compressible/variable density flow\n"
255  << " or " << dimPressure/dimDensity
256  << " for incompressible flow.\n"
257  << " on patch " << this->patch().name()
258  << " of field " << this->dimensionedInternalField().name()
259  << " in file " << this->dimensionedInternalField().objectPath()
260  << exit(FatalError);
261  }
262 }
263 
264 
266 {
267  updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
268 }
269 
270 
272 (
273  Ostream& os
274 ) const
275 {
276  writeEntryIfDifferent<word>(os, "UName", "U", UName_);
277  writeEntryIfDifferent<word>(os, "phiName", "phi", phiName_);
278  os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
279  os.writeKeyword("rho") << rho_ << token::END_STATEMENT << nl;
280  os.writeKeyword("psiName") << psiName_ << token::END_STATEMENT << nl;
281  os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
282  timeVaryingMappedFixedValueFvPatchScalarField::write(os);
283 }
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 namespace Foam
289 {
291  (
294  );
295 }
296 
297 // ************************ vim: set sw=4 sts=4 et: ************************ //