uniformTotalPressureFvPatchScalarField.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-2021 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
36 (
37  const fvPatch& p,
39 )
40 :
41  fixedValueFvPatchScalarField(p, iF),
42  UName_("U"),
43  phiName_("phi"),
44  rhoName_("rho"),
45  psiName_("none"),
46  gamma_(0.0),
47  p0_()
48 {}
49 
50 
53 (
54  const fvPatch& p,
56  const dictionary& dict
57 )
58 :
59  fixedValueFvPatchScalarField(p, iF, dict, false),
60  UName_(dict.lookupOrDefault<word>("U", "U")),
61  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
62  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
63  psiName_(dict.lookupOrDefault<word>("psi", "none")),
64  gamma_(psiName_ != "none" ? dict.lookup<scalar>("gamma") : 1),
65  p0_(Function1<scalar>::New("p0", dict))
66 {
67  if (dict.found("value"))
68  {
70  (
71  scalarField("value", dict, p.size())
72  );
73  }
74  else
75  {
76  const scalar t = this->db().time().timeOutputValue();
77  fvPatchScalarField::operator==(p0_->value(t));
78  }
79 }
80 
81 
84 (
86  const fvPatch& p,
88  const fvPatchFieldMapper& mapper
89 )
90 :
91  fixedValueFvPatchScalarField(ptf, p, iF, mapper, false), // Don't map
92  UName_(ptf.UName_),
93  phiName_(ptf.phiName_),
94  rhoName_(ptf.rhoName_),
95  psiName_(ptf.psiName_),
96  gamma_(ptf.gamma_),
97  p0_(ptf.p0_, false)
98 {
99  // Set the patch pressure to the current total pressure
100  // This is not ideal but avoids problems with the creation of patch faces
101  const scalar t = this->db().time().timeOutputValue();
102  fvPatchScalarField::operator==(p0_->value(t));
103 }
104 
105 
108 (
111 )
112 :
113  fixedValueFvPatchScalarField(ptf, iF),
114  UName_(ptf.UName_),
115  phiName_(ptf.phiName_),
116  rhoName_(ptf.rhoName_),
117  psiName_(ptf.psiName_),
118  gamma_(ptf.gamma_),
119  p0_(ptf.p0_, false)
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
126 (
127  const vectorField& Up
128 )
129 {
130  if (updated())
131  {
132  return;
133  }
134 
135  scalar p0 = p0_->value(this->db().time().timeOutputValue());
136 
137  const fvsPatchField<scalar>& phip =
138  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
139 
140  if (internalField().dimensions() == dimPressure)
141  {
142  if (psiName_ == "none")
143  {
144  // Variable density and low-speed compressible flow
145 
146  const fvPatchField<scalar>& rho =
147  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
148 
149  operator==(p0 - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
150  }
151  else
152  {
153  // High-speed compressible flow
154 
155  const fvPatchField<scalar>& psip =
156  patch().lookupPatchField<volScalarField, scalar>(psiName_);
157 
158  if (gamma_ > 1)
159  {
160  scalar gM1ByG = (gamma_ - 1)/gamma_;
161 
162  operator==
163  (
164  p0
165  /pow
166  (
167  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
168  1.0/gM1ByG
169  )
170  );
171  }
172  else
173  {
174  operator==(p0/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
175  }
176  }
177 
178  }
179  else if (internalField().dimensions() == dimPressure/dimDensity)
180  {
181  // Incompressible flow
182  operator==(p0 - 0.5*(1.0 - pos0(phip))*magSqr(Up));
183  }
184  else
185  {
187  << " Incorrect pressure dimensions " << internalField().dimensions()
188  << nl
189  << " Should be " << dimPressure
190  << " for compressible/variable density flow" << nl
191  << " or " << dimPressure/dimDensity
192  << " for incompressible flow," << nl
193  << " on patch " << this->patch().name()
194  << " of field " << this->internalField().name()
195  << " in file " << this->internalField().objectPath()
196  << exit(FatalError);
197  }
198 
199  fixedValueFvPatchScalarField::updateCoeffs();
200 }
201 
202 
204 {
205  updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
206 }
207 
208 
210 {
212  writeEntryIfDifferent<word>(os, "U", "U", UName_);
213  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
214  writeEntry(os, "rho", rhoName_);
215  writeEntry(os, "psi", psiName_);
216  writeEntry(os, "gamma", gamma_);
217  writeEntry(os, p0_());
218  writeEntry(os, "value", *this);
219 }
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 namespace Foam
225 {
227  (
230  );
231 }
232 
233 // ************************************************************************* //
Foam::surfaceFields.
Run-time selectable general function of one variable.
Definition: Function1.H:52
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
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:260
Macros for easy insertion into run-time selection tables.
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
Foam::fvPatchFieldMapper.
const dimensionSet dimDensity
virtual label size() const
Return size.
Definition: fvPatch.H:156
dimensioned< scalar > magSqr(const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
volScalarField scalarField(fieldObject, mesh)
dimensionedScalar pos0(const dimensionedScalar &ds)
uniformTotalPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
static const char nl
Definition: Ostream.H:260
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
This boundary condition provides a time-varying form of the uniform total pressure boundary condition...
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,.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
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