Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
40// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42namespace Foam
43{
44namespace functionObjects
45{
47
49 (
53 );
54}
55}
56
57
60{
61 if (pRefName_ == "none")
62 {
64 }
65 else if (pRefName_ == "pInf")
66 {
68 }
69 else
70 {
71 return mesh_.lookupObject<uniformDimensionedScalarField>(pRefName_);
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 =
187 (
189 (
191 runTime.timeName(),
192 mesh_,
194 IOobject::AUTO_WRITE, // To enable restart
196 ),
197 mesh_
198 );
199
201
202 bool reInitialise = dict.getOrDefault("reInitialise", false);
203
204 if (runTime.timeIndex() == 0 || reInitialise)
205 {
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
243}
244
245
247{
248 return true;
249}
250
251
252// ************************************************************************* //
#define Log
Definition PDRblock.C:28
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
volScalarField & p_rgh
const surfaceScalarField & ghf
const volScalarField & gh
@ REGISTER
Request registration (bool: true).
@ MUST_READ
Reading required.
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Abstract base-class for fluid and solid thermodynamic properties.
Definition basicThermo.H:62
static const word dictName
The dictionary name ("thermophysicalProperties").
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Calculates and outputs the pressure fields p_rgh and ph_rgh.
void calculateAndWrite()
Calculate the fields and write.
word ph_rghName_
Name of p_hydrostatic - rho*g*h field, default is "ph_rgh".
word UName_
Name of velocity field, default is "ph_rgh".
word pRefName_
Name of uniform pressure reference field, default is "pRef".
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
word rhoName_
Name of density field, default is "rho".
dimensionedScalar pRef() const
Helper function to return the reference pressure.
word p_rghName_
Name of p - rho*g*h field, default is "p_rgh".
word ghfName_
Name of g*h surface field, default is "ghf".
scalar pRefValue_
Reference pressure if pRefName is set to "pInf".
virtual bool execute()
Execute the function-object operations.
label nCorrectors_
Number of correctors when solving for ph_rgh.
virtual bool write()
Write the function-object results.
hydrostaticPressure(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
word ghName_
Name of g*h volume field, default is "gh".
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
Definition fvMatrix.C:1094
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
bool store()
Register object with its registry and transfer ownership to the registry.
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
U
Definition pEqn.H:72
volScalarField & p
surfaceScalarField phig("phig", -rhorAUf *ghf *fvc::snGrad(rho) *mesh.magSf())
engineTime & runTime
Calculate the divergence of the given field.
Calculate the snGrad of the given volField.
Calculate the matrix for the laplacian of the field.
surfaceScalarField rhof(fvc::interpolate(rho, "div(phi,rho)"))
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
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.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition fvcSnGrad.C:40
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcDiv.C:42
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Namespace for OpenFOAM.
const dimensionSet dimPressure
void constrainPressure(volScalarField &p, const RhoType &rho, const volVectorField &U, const surfaceScalarField &phiHbyA, const RAUType &rhorAU, const MRFType &MRF)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
GeometricField< vector, fvPatchField, volMesh > volVectorField
fvMatrix< scalar > fvScalarMatrix
GeometricField< scalar, fvPatchField, volMesh > volScalarField
UniformDimensionedField< scalar > uniformDimensionedScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
psiReactionThermo & thermo
Various UniformDimensionedField types.