FreeFOAM The Cross-Platform CFD Toolkit
totalPressureFvPatchScalarField.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 
36 (
37  const fvPatch& p,
39 )
40 :
41  fixedValueFvPatchScalarField(p, iF),
42  UName_("U"),
43  phiName_("phi"),
44  rhoName_("none"),
45  psiName_("none"),
46  gamma_(0.0),
47  p0_(p.size(), 0.0)
48 {}
49 
50 
52 (
53  const fvPatch& p,
55  const dictionary& dict
56 )
57 :
58  fixedValueFvPatchScalarField(p, iF),
59  UName_(dict.lookupOrDefault<word>("U", "U")),
60  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
61  rhoName_(dict.lookupOrDefault<word>("rho", "none")),
62  psiName_(dict.lookupOrDefault<word>("psi", "none")),
63  gamma_(readScalar(dict.lookup("gamma"))),
64  p0_("p0", dict, p.size())
65 {
66  if (dict.found("value"))
67  {
69  (
70  scalarField("value", dict, p.size())
71  );
72  }
73  else
74  {
76  }
77 }
78 
79 
81 (
83  const fvPatch& p,
85  const fvPatchFieldMapper& mapper
86 )
87 :
88  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
89  UName_(ptf.UName_),
90  phiName_(ptf.phiName_),
91  rhoName_(ptf.rhoName_),
92  psiName_(ptf.psiName_),
93  gamma_(ptf.gamma_),
94  p0_(ptf.p0_, mapper)
95 {}
96 
97 
99 (
101 )
102 :
103  fixedValueFvPatchScalarField(tppsf),
104  UName_(tppsf.UName_),
105  phiName_(tppsf.phiName_),
106  rhoName_(tppsf.rhoName_),
107  psiName_(tppsf.psiName_),
108  gamma_(tppsf.gamma_),
109  p0_(tppsf.p0_)
110 {}
111 
112 
114 (
115  const totalPressureFvPatchScalarField& tppsf,
117 )
118 :
119  fixedValueFvPatchScalarField(tppsf, iF),
120  UName_(tppsf.UName_),
121  phiName_(tppsf.phiName_),
122  rhoName_(tppsf.rhoName_),
123  psiName_(tppsf.psiName_),
124  gamma_(tppsf.gamma_),
125  p0_(tppsf.p0_)
126 {}
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
132 (
133  const fvPatchFieldMapper& m
134 )
135 {
136  fixedValueFvPatchScalarField::autoMap(m);
137  p0_.autoMap(m);
138 }
139 
140 
142 (
143  const fvPatchScalarField& ptf,
144  const labelList& addr
145 )
146 {
147  fixedValueFvPatchScalarField::rmap(ptf, addr);
148 
149  const totalPressureFvPatchScalarField& tiptf =
150  refCast<const totalPressureFvPatchScalarField>(ptf);
151 
152  p0_.rmap(tiptf.p0_, addr);
153 }
154 
155 
157 {
158  if (updated())
159  {
160  return;
161  }
162 
163  const fvsPatchField<scalar>& phip =
164  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
165 
166  if (psiName_ == "none" && rhoName_ == "none")
167  {
168  operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
169  }
170  else if (rhoName_ == "none")
171  {
172  const fvPatchField<scalar>& psip =
173  patch().lookupPatchField<volScalarField, scalar>(psiName_);
174 
175  if (gamma_ > 1.0)
176  {
177  scalar gM1ByG = (gamma_ - 1.0)/gamma_;
178 
179  operator==
180  (
181  p0_
182  /pow
183  (
184  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
185  1.0/gM1ByG
186  )
187  );
188  }
189  else
190  {
191  operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
192  }
193  }
194  else if (psiName_ == "none")
195  {
196  const fvPatchField<scalar>& rho =
197  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
198 
199  operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
200  }
201  else
202  {
204  (
205  "totalPressureFvPatchScalarField::updateCoeffs()"
206  ) << " rho or psi set inconsistently, rho = " << rhoName_
207  << ", psi = " << psiName_ << ".\n"
208  << " Set either rho or psi or neither depending on the "
209  "definition of total pressure." << nl
210  << " Set the unused variable(s) to 'none'.\n"
211  << " on patch " << this->patch().name()
212  << " of field " << this->dimensionedInternalField().name()
213  << " in file " << this->dimensionedInternalField().objectPath()
214  << exit(FatalError);
215  }
216 
218 }
219 
220 
222 {
223  updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
224 }
225 
226 
228 {
230  writeEntryIfDifferent<word>(os, "U", "U", UName_);
231  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
232  os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
233  os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
234  os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
235  p0_.writeEntry("p0", os);
236  writeEntry("value", os);
237 }
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 namespace Foam
243 {
245  (
248  );
249 }
250 
251 // ************************ vim: set sw=4 sts=4 et: ************************ //