zeroDimensionalFixedPressureModel.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) 2023 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 "fvConstraints.H"
29 #include "fvmSup.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
40  (
41  fvModel,
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
52 Foam::fv::zeroDimensionalFixedPressureModel::constraint() const
53 {
54  const fvConstraints& constraints = fvConstraints::New(mesh());
55 
56  forAll(constraints, i)
57  {
58  if (isA<zeroDimensionalFixedPressureConstraint>(constraints[i]))
59  {
60  return refCast<const zeroDimensionalFixedPressureConstraint>
61  (
62  constraints[i]
63  );
64  }
65  }
66 
68  << "The " << typeName << " fvModel requires a corresponding "
69  << zeroDimensionalFixedPressureConstraint::typeName << " fvConstraint"
70  << exit(FatalError);
71 
72  return NullObjectRef<zeroDimensionalFixedPressureConstraint>();
73 }
74 
75 
76 template<class Type>
77 void Foam::fv::zeroDimensionalFixedPressureModel::addSupType
78 (
79  const VolField<Type>& field,
80  fvMatrix<Type>& eqn
81 ) const
82 {
84  << "Cannot add a fixed pressure source for field " << field.name()
85  << " to equation for " << eqn.psi().name() << " because this field's "
86  << "equation was not recognised as being in mass-conservative form"
87  << exit(FatalError);
88 }
89 
90 
91 void Foam::fv::zeroDimensionalFixedPressureModel::addSupType
92 (
93  const volScalarField& rho,
94  fvMatrix<scalar>& eqn
95 ) const
96 {
97  if (IOobject::member(rho.name()) == constraint().rhoName())
98  {
99  if (IOobject::member(eqn.psi().name()) == constraint().pName())
100  {
101  eqn += constraint().pEqnSource(rho, eqn);
102  }
103  else
104  {
105  eqn += constraint().massSource(rho());
106  }
107  }
108  else
109  {
110  // This is actually an incompressible single-phase equation. Rho is
111  // actually a property field. Fall back (and error).
112  addSupType<scalar>(rho, eqn);
113  }
114 }
115 
116 
117 template<class Type>
118 void Foam::fv::zeroDimensionalFixedPressureModel::addSupType
119 (
120  const volScalarField& rho,
121  const VolField<Type>& field,
122  fvMatrix<Type>& eqn
123 ) const
124 {
125  if (&field != &eqn.psi())
126  {
128  << "Cannot add a fixed pressure source of field " << field.name()
129  << " into an equation for field " << eqn.psi().name()
130  << exit(FatalError);
131  }
132 
133  eqn -= fvm::SuSp(-constraint().massSource(rho()), eqn.psi());
134 }
135 
136 
137 void Foam::fv::zeroDimensionalFixedPressureModel::addSupType
138 (
139  const volScalarField& alpha,
140  const volScalarField& rho,
141  fvMatrix<scalar>& eqn
142 ) const
143 {
144  if (IOobject::member(rho.name()) == constraint().rhoName())
145  {
146  if (IOobject::member(eqn.psi().name()) == constraint().pName())
147  {
148  eqn += alpha()*constraint().pEqnSource(rho, eqn);
149  }
150  else
151  {
152  eqn += constraint().massSource(alpha(), rho());
153  }
154  }
155  else
156  {
157  // This is actually a compressible single-phase equation. Alpha is
158  // actually rho, and rho is actually a property field. Fall back.
159  addSupType<scalar>(alpha, rho, eqn);
160  }
161 }
162 
163 
164 template<class Type>
165 void Foam::fv::zeroDimensionalFixedPressureModel::addSupType
166 (
167  const volScalarField& alpha,
168  const volScalarField& rho,
169  const VolField<Type>& field,
170  fvMatrix<Type>& eqn
171 ) const
172 {
173  if (&field != &eqn.psi())
174  {
176  << "Cannot add a fixed pressure source of field " << field.name()
177  << " into an equation for field " << eqn.psi().name()
178  << exit(FatalError);
179  }
180 
181  eqn -= fvm::SuSp(-constraint().massSource(alpha(), rho()), eqn.psi());
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
186 
188 (
189  const word& name,
190  const word& modelType,
191  const fvMesh& mesh,
192  const dictionary& dict
193 )
194 :
195  fvModel(name, modelType, mesh, dict)
196 {
197  if (mesh.nGeometricD() != 0)
198  {
200  << "Zero-dimensional fvModel applied to a "
201  << mesh.nGeometricD() << "-dimensional mesh"
202  << exit(FatalIOError);
203  }
204 }
205 
206 
207 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
208 
211 {}
212 
213 
214 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
215 
217 (
218  const word& fieldName
219 ) const
220 {
221  return true;
222 }
223 
224 
226 (
228  fv::zeroDimensionalFixedPressureModel
229 )
230 
231 
233 (
235  fv::zeroDimensionalFixedPressureModel
236 )
237 
238 
240 (
242  fv::zeroDimensionalFixedPressureModel
243 )
244 
245 
247 {
248  return true;
249 }
250 
251 
253 (
254  const polyTopoChangeMap& map
255 )
256 {}
257 
258 
260 (
261  const polyMeshMap& map
262 )
263 {}
264 
265 
267 (
268  const polyDistributionMap& map
269 )
270 {}
271 
272 
273 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
word member() const
Return member (name without the extension)
Definition: IOobject.C:330
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:100
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
Finite volume model abstract base class.
Definition: fvModel.H:59
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:53
Zero-dimensional fixed pressure constraint. Should be used in conjunction with the zeroDimensionalFix...
Zero-dimensional fixed pressure source. Should be used in conjunction with the zeroDimensionalFixedPr...
zeroDimensionalFixedPressureModel(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from dictionary.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool movePoints()
Add a source term to an equation.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual bool addsSupToField(const word &fieldName) const
Return true if the fvModel adds a source term to the given.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
Definition: polyMesh.C:1000
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvConstraints & fvConstraints(Foam::fvConstraints::New(mesh))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IMPLEMENT_FV_MODEL_ADD_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:33
#define IMPLEMENT_FV_MODEL_ADD_ALPHA_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:71
#define IMPLEMENT_FV_MODEL_ADD_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:51
Calculate the matrix for implicit and explicit sources.
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
tmp< fvMatrix< Type > > SuSp(const volScalarField::Internal &, const VolField< Type > &)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:64
IOerror FatalIOError
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
labelList fv(nPoints)
dictionary dict