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) 2011 OpenFOAM Foundation
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 
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "surfaceFields.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  const scalarField& p0p,
159  const vectorField& Up
160 )
161 {
162  if (updated())
163  {
164  return;
165  }
166 
167  const fvsPatchField<scalar>& phip =
168  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
169 
170  if (psiName_ == "none" && rhoName_ == "none")
171  {
172  operator==(p0p - 0.5*(1.0 - pos(phip))*magSqr(Up));
173  }
174  else if (rhoName_ == "none")
175  {
176  const fvPatchField<scalar>& psip =
177  patch().lookupPatchField<volScalarField, scalar>(psiName_);
178 
179  if (gamma_ > 1.0)
180  {
181  scalar gM1ByG = (gamma_ - 1.0)/gamma_;
182 
183  operator==
184  (
185  p0p
186  /pow
187  (
188  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
189  1.0/gM1ByG
190  )
191  );
192  }
193  else
194  {
195  operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
196  }
197  }
198  else if (psiName_ == "none")
199  {
200  const fvPatchField<scalar>& rho =
201  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
202 
203  operator==(p0p - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
204  }
205  else
206  {
208  (
209  "totalPressureFvPatchScalarField::updateCoeffs()"
210  ) << " rho or psi set inconsistently, rho = " << rhoName_
211  << ", psi = " << psiName_ << ".\n"
212  << " Set either rho or psi or neither depending on the "
213  "definition of total pressure." << nl
214  << " Set the unused variable(s) to 'none'.\n"
215  << " on patch " << this->patch().name()
216  << " of field " << this->dimensionedInternalField().name()
217  << " in file " << this->dimensionedInternalField().objectPath()
218  << exit(FatalError);
219  }
220 
221  fixedValueFvPatchScalarField::updateCoeffs();
222 }
223 
224 
226 {
228  (
229  p0(),
230  patch().lookupPatchField<volVectorField, vector>(UName())
231  );
232 }
233 
234 
236 {
238  writeEntryIfDifferent<word>(os, "U", "U", UName_);
239  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
240  os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
241  os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
242  os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
243  p0_.writeEntry("p0", os);
244  writeEntry("value", os);
245 }
246 
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 namespace Foam
251 {
253  (
256  );
257 }
258 
259 // ************************************************************************* //
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Foam::surfaceFields.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
#define readScalar
Definition: doubleScalar.C:38
dimensioned< scalar > magSqr(const dimensioned< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
This boundary condition provides a total pressure condition. Four variants are possible: ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::fvPatchFieldMapper.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
totalPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:354
Namespace for OpenFOAM.
static const char nl
Definition: Ostream.H:260
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:634
Macros for easy insertion into run-time selection tables.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
rDeltaT dimensionedInternalField()
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const scalarField & p0() const
Return the total pressure.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
dimensionedScalar pos(const dimensionedScalar &ds)
makePatchTypeField(fvPatchVectorField, SRFFreestreamVelocityFvPatchVectorField)
volScalarField scalarField(fieldObject, mesh)
virtual label size() const
Return size.
Definition: fvPatch.H:161
const word & UName() const
Return the name of the velocity field.
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65