uniformTotalPressureFvPatchScalarField.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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
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_()
50 {}
51 
52 
55 (
56  const fvPatch& p,
58  const dictionary& dict
59 )
60 :
61  fixedValueFvPatchScalarField(p, iF, dict, false),
62  UName_(dict.lookupOrDefault<word>("U", "U")),
63  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
64  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
65  psiName_(dict.lookupOrDefault<word>("psi", "none")),
66  gamma_(psiName_ != "none" ? dict.get<scalar>("gamma") : 1),
67  p0_(Function1<scalar>::New("p0", dict))
68 {
69  if (dict.found("value"))
70  {
72  (
73  scalarField("value", dict, p.size())
74  );
75  }
76  else
77  {
78  const scalar t = this->db().time().timeOutputValue();
79  fvPatchScalarField::operator==(p0_->value(t));
80  }
81 }
82 
83 
86 (
88  const fvPatch& p,
90  const fvPatchFieldMapper& mapper
91 )
92 :
93  fixedValueFvPatchScalarField(p, iF), // Don't map
94  UName_(ptf.UName_),
95  phiName_(ptf.phiName_),
96  rhoName_(ptf.rhoName_),
97  psiName_(ptf.psiName_),
98  gamma_(ptf.gamma_),
99  p0_(ptf.p0_.clone())
100 {
101  patchType() = ptf.patchType();
102 
103  // Set the patch pressure to the current total pressure
104  // This is not ideal but avoids problems with the creation of patch faces
105  const scalar t = this->db().time().timeOutputValue();
106  fvPatchScalarField::operator==(p0_->value(t));
107 }
108 
109 
112 (
114 )
115 :
116  fixedValueFvPatchScalarField(ptf),
117  UName_(ptf.UName_),
118  phiName_(ptf.phiName_),
119  rhoName_(ptf.rhoName_),
120  psiName_(ptf.psiName_),
121  gamma_(ptf.gamma_),
122  p0_(ptf.p0_.clone())
123 {}
124 
125 
128 (
131 )
132 :
133  fixedValueFvPatchScalarField(ptf, iF),
134  UName_(ptf.UName_),
135  phiName_(ptf.phiName_),
136  rhoName_(ptf.rhoName_),
137  psiName_(ptf.psiName_),
138  gamma_(ptf.gamma_),
139  p0_(ptf.p0_.clone())
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 (
147  const vectorField& Up
148 )
149 {
150  if (updated())
151  {
152  return;
153  }
154 
155  scalar p0 = p0_->value(this->db().time().timeOutputValue());
156 
157  const fvsPatchField<scalar>& phip =
158  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
159 
160  if (internalField().dimensions() == dimPressure)
161  {
162  if (psiName_ == "none")
163  {
164  // Variable density and low-speed compressible flow
165 
166  const fvPatchField<scalar>& rho =
167  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
168 
169  operator==(p0 - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
170  }
171  else
172  {
173  // High-speed compressible flow
174 
175  const fvPatchField<scalar>& psip =
176  patch().lookupPatchField<volScalarField, scalar>(psiName_);
177 
178  if (gamma_ > 1)
179  {
180  scalar gM1ByG = (gamma_ - 1)/gamma_;
181 
182  operator==
183  (
184  p0
185  /pow
186  (
187  (1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
188  1.0/gM1ByG
189  )
190  );
191  }
192  else
193  {
194  operator==(p0/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
195  }
196  }
197 
198  }
199  else if (internalField().dimensions() == dimPressure/dimDensity)
200  {
201  // Incompressible flow
202  operator==(p0 - 0.5*(1.0 - pos0(phip))*magSqr(Up));
203  }
204  else
205  {
207  << " Incorrect pressure dimensions " << internalField().dimensions()
208  << nl
209  << " Should be " << dimPressure
210  << " for compressible/variable density flow" << nl
211  << " or " << dimPressure/dimDensity
212  << " for incompressible flow," << nl
213  << " on patch " << this->patch().name()
214  << " of field " << this->internalField().name()
215  << " in file " << this->internalField().objectPath()
216  << exit(FatalError);
217  }
218 
219  fixedValueFvPatchScalarField::updateCoeffs();
220 }
221 
222 
224 {
225  updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
226 }
227 
228 
230 {
232  os.writeEntryIfDifferent<word>("U", "U", UName_);
233  os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
234  os.writeEntry("rho", rhoName_);
235  os.writeEntry("psi", psiName_);
236  os.writeEntry("gamma", gamma_);
237  p0_->writeData(os);
238  writeEntry("value", os);
239 }
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 namespace Foam
245 {
247  (
250  );
251 }
252 
253 // ************************************************************************* //
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
Foam::uniformTotalPressureFvPatchScalarField::uniformTotalPressureFvPatchScalarField
uniformTotalPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: uniformTotalPressureFvPatchScalarField.C:38
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::uniformTotalPressureFvPatchScalarField::write
virtual void write(Ostream &) const
Write.
Definition: uniformTotalPressureFvPatchScalarField.C:229
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
Foam::uniformTotalPressureFvPatchScalarField
This boundary condition provides a time-varying form of the uniform total pressure boundary condition...
Definition: uniformTotalPressureFvPatchScalarField.H:118
surfaceFields.H
Foam::surfaceFields.
fvPatchFieldMapper.H
Foam::pos0
dimensionedScalar pos0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:188
rho
rho
Definition: readInitialConditions.H:96
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:56
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Field< vector >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: uniformTotalPressureFvPatchScalarField.C:223
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::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
uniformTotalPressureFvPatchScalarField.H
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::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
p0
const volScalarField & p0
Definition: EEqn.H:36
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