hydrostaticPressure.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) 2018-2024 OpenCFD Ltd.
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 
28 #include "hydrostaticPressure.H"
29 #include "basicThermo.H"
31 #include "volFields.H"
32 #include "surfaceInterpolate.H"
33 #include "fvcDiv.H"
34 #include "fvmLaplacian.H"
35 #include "fvcSnGrad.H"
36 #include "constrainPressure.H"
37 
39 
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 namespace functionObjects
45 {
46  defineTypeNameAndDebug(hydrostaticPressure, 0);
47 
49  (
50  functionObject,
51  hydrostaticPressure,
53  );
54 }
55 }
56 
57 
60 {
61  if (pRefName_ == "none")
62  {
64  }
65  else if (pRefName_ == "pInf")
66  {
67  return dimensionedScalar("pRef", dimPressure, pRefValue_);
68  }
69  else
70  {
72  }
73 }
74 
75 
77 {
78  const auto& pRef = this->pRef();
79  const auto& U = mesh_.lookupObject<volVectorField>(UName_);
80  const auto& gh = mesh_.lookupObject<volScalarField>(ghName_);
81  const auto& ghf = mesh_.lookupObject<surfaceScalarField>(ghfName_);
82  auto& rho = mesh_.lookupObjectRef<volScalarField>(rhoName_);
83  auto& thermo = mesh_.lookupObjectRef<basicThermo>(basicThermo::dictName);
84  auto& p_rgh = mesh_.lookupObjectRef<volScalarField>(p_rghName_);
85  auto& ph_rgh = mesh_.lookupObjectRef<volScalarField>(ph_rghName_);
86 
87  auto& p = thermo.p();
88 
89  Info<< "Performing hydrostatic pressure initialisation";
90  if (!mesh_.regionName().empty())
91  {
92  Info<< " region=" << mesh_.name();
93  }
94 
95 
96  if (thermo.incompressible())
97  {
98  Info<< ": incompressible" << endl;
99 
100  // Constant density and temperature
101 
102  thermo.correct();
103  rho = thermo.rho();
104  p = ph_rgh + rho*gh + pRef;
105  p_rgh = ph_rgh;
106  }
107  else
108  {
109  Info<< ": compressible" << endl;
110 
111  p = ph_rgh + rho*gh + pRef;
112  thermo.correct();
113  rho = thermo.rho();
114 
115  for (label i=0; i<nCorrectors_; ++i)
116  {
118 
120  (
121  "phig",
122  -rhof*ghf*fvc::snGrad(rho)*mesh_.magSf()
123  );
124 
125  // Update the pressure BCs to ensure flux consistency
126  constrainPressure(ph_rgh, rho, U, phig, rhof);
127 
128  fvScalarMatrix ph_rghEqn
129  (
130  fvm::laplacian(rhof, ph_rgh) == fvc::div(phig)
131  );
132 
133  ph_rghEqn.relax();
134 
135  ph_rghEqn.solve();
136 
137  p = ph_rgh + rho*gh + pRef;
138  thermo.correct();
139  rho = thermo.rho();
140 
141  Info<< "Hydrostatic pressure variation "
142  << (max(ph_rgh) - min(ph_rgh)).value() << endl;
143  }
144 
145  p_rgh = ph_rgh;
146 
147  Log << " writing field " << ph_rgh.name() << nl;
148  ph_rgh.write();
149  }
150 
151  Log << " writing field " << rho.name() << nl;
152  rho.write();
153 
154  Log << " writing field " << p_rgh.name() << nl;
155  p_rgh.write();
156 
157  Log << " writing field " << p.name() << nl;
158  p.write();
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
163 
165 (
166  const word& name,
167  const Time& runTime,
168  const dictionary& dict
169 )
170 :
172  p_rghName_("p_rgh"),
173  ph_rghName_("ph_rgh"),
174  pRefName_("pRef"),
175  pRefValue_(0),
176  rhoName_("rho"),
177  UName_("U"),
178  ghName_("gh"),
179  ghfName_("ghf"),
180  nCorrectors_(5)
181 {
182  if (read(dict))
183  {
184  // Read and store the initial ph_rgh field
185  volScalarField* ptr =
186  new volScalarField
187  (
188  IOobject
189  (
190  ph_rghName_,
191  runTime.timeName(),
192  mesh_,
194  IOobject::AUTO_WRITE, // To enable restart
196  ),
197  mesh_
198  );
199 
200  regIOobject::store(ptr);
201 
202  bool reInitialise = dict.getOrDefault("reInitialise", false);
203 
204  if (runTime.timeIndex() == 0 || reInitialise)
205  {
207  }
208  }
209 }
210 
211 
212 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
213 
215 {
217  {
218  dict.readIfPresent("p_rgh", p_rghName_);
219  dict.readIfPresent("ph_rgh", ph_rghName_);
220  dict.readIfPresent("pRef", pRefName_);
221  dict.readIfPresent("rho", rhoName_);
222  dict.readIfPresent("U", UName_);
223  dict.readIfPresent("gh", ghName_);
224  dict.readIfPresent("ghf", ghfName_);
225  dict.readIfPresent("nCorrectors", nCorrectors_);
226 
227  pRefValue_ = 0;
228  if (pRefName_ == "pInf")
229  {
230  pRefValue_ = dict.get<scalar>("pRefValue");
231  }
232 
233  return true;
234  }
235 
236  return false;
237 }
238 
241 {
242  return true;
243 }
244 
245 
247 {
248  return true;
249 }
250 
251 
252 // ************************************************************************* //
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
dictionary dict
defineTypeNameAndDebug(ObukhovLength, 0)
fvMatrix< scalar > fvScalarMatrix
Definition: fvMatricesFwd.H:37
word pRefName_
Name of uniform pressure reference field, default is "pRef".
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
virtual bool execute()
Calculate the p_rgh field.
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:59
word ph_rghName_
Name of p_hydrostatic - rho*g*h field, default is "ph_rgh".
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:42
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
surfaceScalarField phig("phig", -rhorAUf *ghf *fvc::snGrad(rho) *mesh.magSf())
Various UniformDimensionedField types.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool write()
Write the p_rgh and derived fields.
Calculate the matrix for the laplacian of the field.
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
Calculate the snGrad of the given volField.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
const surfaceScalarField & ghf
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
psiReactionThermo & thermo
Definition: createFields.H:28
hydrostaticPressure(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
scalar pRefValue_
Reference pressure if pRefName is set to "pInf".
void calculateAndWrite()
Calculate the fields and write.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
const dimensionSet dimPressure
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Calculate the divergence of the given field.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
void constrainPressure(volScalarField &p, const RhoType &rho, const volVectorField &U, const surfaceScalarField &phiHbyA, const RAUType &rhorAU, const MRFType &MRF)
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
U
Definition: pEqn.H:72
virtual bool read(const dictionary &dict)
Read the hydrostaticPressure data.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:41
dimensionedScalar pRef() const
Helper function to return the reference pressure.
Automatically write from objectRegistry::writeObject()
#define Log
Definition: PDRblock.C:28
const volScalarField & gh
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
volScalarField & p
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Request registration (bool: true)
const fvMesh & mesh_
Reference to the fvMesh.
surfaceScalarField rhof(fvc::interpolate(rho, "div(phi,rho)"))
volScalarField & p_rgh
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:40
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127