dynamicPressureFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 
27 #include "fvPatchFieldMapper.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(dynamicPressureFvPatchScalarField, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const fvPatch& p,
46 )
47 :
48  fixedValueFvPatchScalarField(p, iF),
49  rhoName_("rho"),
50  psiName_("none"),
51  gamma_(0),
52  p0_(p.size(), 0)
53 {}
54 
55 
57 (
58  const fvPatch& p,
60  const dictionary& dict
61 )
62 :
63  fixedValueFvPatchScalarField(p, iF, dict, false),
64  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
65  psiName_(dict.lookupOrDefault<word>("psi", "none")),
66  gamma_(psiName_ != "none" ? dict.lookup<scalar>("gamma") : 1),
67  p0_("p0", dict, p.size())
68 {
69  if (dict.found("value"))
70  {
72  (
73  scalarField("value", dict, p.size())
74  );
75  }
76  else
77  {
79  }
80 }
81 
82 
84 (
86  const fvPatch& p,
88  const fvPatchFieldMapper& mapper
89 )
90 :
91  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
92  rhoName_(ptf.rhoName_),
93  psiName_(ptf.psiName_),
94  gamma_(ptf.gamma_),
95  p0_(mapper(ptf.p0_))
96 {}
97 
98 
100 (
103 )
104 :
105  fixedValueFvPatchScalarField(tppsf, iF),
106  rhoName_(tppsf.rhoName_),
107  psiName_(tppsf.psiName_),
108  gamma_(tppsf.gamma_),
109  p0_(tppsf.p0_)
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 (
117  const fvPatchFieldMapper& m
118 )
119 {
120  fixedValueFvPatchScalarField::autoMap(m);
121  m(p0_, p0_);
122 }
123 
124 
126 (
127  const fvPatchScalarField& ptf,
128  const labelList& addr
129 )
130 {
131  fixedValueFvPatchScalarField::rmap(ptf, addr);
132 
133  const dynamicPressureFvPatchScalarField& tiptf =
134  refCast<const dynamicPressureFvPatchScalarField>(ptf);
135 
136  p0_.rmap(tiptf.p0_, addr);
137 }
138 
139 
141 (
142  const scalarField& p0p,
143  const scalarField& Kp
144 )
145 {
146  if (updated())
147  {
148  return;
149  }
150 
151  if (internalField().dimensions() == dimPressure)
152  {
153  if (psiName_ == "none")
154  {
155  // Variable density and low-speed compressible flow
156 
157  const fvPatchField<scalar>& rho =
158  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
159 
160  operator==(p0p - rho*Kp);
161  }
162  else
163  {
164  // High-speed compressible flow
165 
166  const fvPatchField<scalar>& psip =
167  patch().lookupPatchField<volScalarField, scalar>(psiName_);
168 
169  if (gamma_ > 1)
170  {
171  scalar gM1ByG = (gamma_ - 1)/gamma_;
172 
173  operator==(p0p/pow(scalar(1) + psip*gM1ByG*Kp, 1/gM1ByG));
174  }
175  else
176  {
177  operator==(p0p/(scalar(1) + psip*Kp));
178  }
179  }
180 
181  }
182  else if (internalField().dimensions() == dimPressure/dimDensity)
183  {
184  // Incompressible flow
185 
186  operator==(p0p - Kp);
187  }
188  else
189  {
191  << " Incorrect pressure dimensions " << internalField().dimensions()
192  << nl
193  << " Should be " << dimPressure
194  << " for compressible/variable density flow" << nl
195  << " or " << dimPressure/dimDensity
196  << " for incompressible flow," << nl
197  << " on patch " << this->patch().name()
198  << " of field " << this->internalField().name()
199  << " in file " << this->internalField().objectPath()
200  << exit(FatalError);
201  }
202 
203  fixedValueFvPatchScalarField::updateCoeffs();
204 }
205 
206 
208 {
210  writeEntry(os, "rho", rhoName_);
211  writeEntry(os, "psi", psiName_);
212  writeEntry(os, "gamma", gamma_);
213  writeEntry(os, "p0", p0_);
214  writeEntry(os, "value", *this);
215 }
216 
217 
218 // ************************************************************************* //
Foam::surfaceFields.
const word psiName_
Name of the compressibility field used to calculate the wave speed.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
const dimensionSet dimPressure
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
This boundary condition provides a dynamic pressure condition. It subtracts a kinetic energy term fro...
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:260
void updateCoeffs(const scalarField &p0p, const scalarField &Kp)
Update the coefficients associated with the patch field.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Foam::fvPatchFieldMapper.
const dimensionSet dimDensity
virtual label size() const
Return size.
Definition: fvPatch.H:156
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
const word rhoName_
Name of the density field used to normalise the mass flux.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:275
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dynamicPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844