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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "fvPatchFieldMapper.H"
31 #include "volFields.H"
32 #include "surfaceFields.H"
33 
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
38 (
39  const fvPatch& p,
41 )
42 :
43  fixedValueFvPatchScalarField(p, iF),
44  UName_("U"),
45  phiName_("phi"),
46  rhoName_("rho"),
47  psiName_("none"),
48  gamma_(0.0),
49  p0_(p.size(), Zero)
50 {}
51 
52 
54 (
55  const fvPatch& p,
57  const dictionary& dict
58 )
59 :
60  fixedValueFvPatchScalarField(p, iF, dict, false),
61  UName_(dict.lookupOrDefault<word>("U", "U")),
62  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
63  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
64  psiName_(dict.lookupOrDefault<word>("psi", "none")),
65  gamma_(psiName_ != "none" ? dict.get<scalar>("gamma") : 1),
66  p0_("p0", dict, p.size())
67 {
68  if (dict.found("value"))
69  {
71  (
72  scalarField("value", dict, p.size())
73  );
74  }
75  else
76  {
78  }
79 }
80 
81 
83 (
85  const fvPatch& p,
87  const fvPatchFieldMapper& mapper
88 )
89 :
90  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
91  UName_(ptf.UName_),
92  phiName_(ptf.phiName_),
93  rhoName_(ptf.rhoName_),
94  psiName_(ptf.psiName_),
95  gamma_(ptf.gamma_),
96  p0_(ptf.p0_, mapper)
97 {}
98 
99 
101 (
103 )
104 :
105  fixedValueFvPatchScalarField(tppsf),
106  UName_(tppsf.UName_),
107  phiName_(tppsf.phiName_),
108  rhoName_(tppsf.rhoName_),
109  psiName_(tppsf.psiName_),
110  gamma_(tppsf.gamma_),
111  p0_(tppsf.p0_)
112 {}
113 
114 
116 (
117  const totalPressureFvPatchScalarField& tppsf,
119 )
120 :
121  fixedValueFvPatchScalarField(tppsf, iF),
122  UName_(tppsf.UName_),
123  phiName_(tppsf.phiName_),
124  rhoName_(tppsf.rhoName_),
125  psiName_(tppsf.psiName_),
126  gamma_(tppsf.gamma_),
127  p0_(tppsf.p0_)
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
135  const fvPatchFieldMapper& m
136 )
137 {
138  fixedValueFvPatchScalarField::autoMap(m);
139  p0_.autoMap(m);
140 }
141 
142 
144 (
145  const fvPatchScalarField& ptf,
146  const labelList& addr
147 )
148 {
149  fixedValueFvPatchScalarField::rmap(ptf, addr);
150 
151  const totalPressureFvPatchScalarField& tiptf =
152  refCast<const totalPressureFvPatchScalarField>(ptf);
153 
154  p0_.rmap(tiptf.p0_, addr);
155 }
156 
157 
159 (
160  const scalarField& p0p,
161  const vectorField& Up
162 )
163 {
164  if (updated())
165  {
166  return;
167  }
168 
169  const fvsPatchField<scalar>& phip =
170  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
171 
172  if (internalField().dimensions() == dimPressure)
173  {
174  if (psiName_ == "none")
175  {
176  // Variable density and low-speed compressible flow
177 
178  const fvPatchField<scalar>& rho =
179  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
180 
181  operator==(p0p - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
182  }
183  else
184  {
185  // High-speed compressible flow
186 
187  const fvPatchField<scalar>& psip =
188  patch().lookupPatchField<volScalarField, scalar>(psiName_);
189 
190  if (gamma_ > 1)
191  {
192  scalar gM1ByG = (gamma_ - 1)/gamma_;
193 
194  operator==
195  (
196  p0p
197  /pow
198  (
199  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
200  1.0/gM1ByG
201  )
202  );
203  }
204  else
205  {
206  operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
207  }
208  }
209 
210  }
211  else if (internalField().dimensions() == dimPressure/dimDensity)
212  {
213  // Incompressible flow
214  operator==(p0p - 0.5*(1.0 - pos0(phip))*magSqr(Up));
215  }
216  else
217  {
219  << " Incorrect pressure dimensions " << internalField().dimensions()
220  << nl
221  << " Should be " << dimPressure
222  << " for compressible/variable density flow" << nl
223  << " or " << dimPressure/dimDensity
224  << " for incompressible flow," << nl
225  << " on patch " << this->patch().name()
226  << " of field " << this->internalField().name()
227  << " in file " << this->internalField().objectPath()
228  << exit(FatalError);
229  }
230 
231  fixedValueFvPatchScalarField::updateCoeffs();
232 }
233 
234 
236 {
238  (
239  p0(),
240  patch().lookupPatchField<volVectorField, vector>(UName())
241  );
242 }
243 
244 
246 {
248  os.writeEntryIfDifferent<word>("U", "U", UName_);
249  os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
250  os.writeEntry("rho", rhoName_);
251  os.writeEntry("psi", psiName_);
252  os.writeEntry("gamma", gamma_);
253  p0_.writeEntry("p0", os);
254  writeEntry("value", os);
255 }
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 namespace Foam
261 {
263  (
266  );
267 }
268 
269 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
Foam::fvPatchField< scalar >::write
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:364
Foam::dimPressure
const dimensionSet dimPressure
Foam::Ostream::writeEntryIfDifferent
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:231
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dimDensity
const dimensionSet dimDensity
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
totalPressureFvPatchScalarField.H
surfaceFields.H
Foam::surfaceFields.
fvPatchFieldMapper.H
Foam::pos0
dimensionedScalar pos0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:188
rho
rho
Definition: readInitialConditions.H:96
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::totalPressureFvPatchScalarField
This boundary condition provides a total pressure condition. Four variants are possible:
Definition: totalPressureFvPatchScalarField.H:256
Foam::Field< scalar >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::totalPressureFvPatchScalarField::autoMap
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: totalPressureFvPatchScalarField.C:134
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Foam::totalPressureFvPatchScalarField::UName
const word & UName() const
Return the name of the velocity field.
Definition: totalPressureFvPatchScalarField.H:355
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:75
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::totalPressureFvPatchScalarField::p0
const scalarField & p0() const
Return the total pressure.
Definition: totalPressureFvPatchScalarField.H:419
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::totalPressureFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: totalPressureFvPatchScalarField.C:235
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
Foam::totalPressureFvPatchScalarField::write
virtual void write(Ostream &) const
Write.
Definition: totalPressureFvPatchScalarField.C:245
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
totalPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: totalPressureFvPatchScalarField.C:38
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::totalPressureFvPatchScalarField::rmap
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: totalPressureFvPatchScalarField.C:144