zeroDimensionalFixedPressureConstraint.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-2024 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 "fvModels.H"
29 #include "fvMatrix.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
40  (
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
52 Foam::fv::zeroDimensionalFixedPressureConstraint::model() const
53 {
54  const fvModels& models = fvModels::New(mesh());
55 
56  forAll(models, i)
57  {
58  if (isA<zeroDimensionalFixedPressureModel>(models[i]))
59  {
60  return refCast<const zeroDimensionalFixedPressureModel>
61  (
62  models[i]
63  );
64  }
65  }
66 
68  << "The " << typeName << " fvConstraint requires a corresponding "
69  << zeroDimensionalFixedPressureModel::typeName << " fvModel"
70  << exit(FatalError);
71 
72  return NullObjectRef<zeroDimensionalFixedPressureModel>();
73 }
74 
75 
76 template<class AlphaFieldType>
78 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
79 (
80  const AlphaFieldType& alpha,
82 ) const
83 {
84  // Source does not exist yet. Return zero.
85  if (!sourcePtr_.valid())
86  {
87  return
89  (
90  typedName("source"),
91  mesh(),
93  );
94  }
95 
96  // Source for mass-based pressure equations
97  if (sourcePtr_->dimensions() == dimMass/dimVolume/dimTime)
98  {
99  return alpha*sourcePtr_();
100  }
101 
102  // Source for volume-based pressure equations
103  if (sourcePtr_->dimensions() == dimless/dimTime)
104  {
105  return alpha*rho*sourcePtr_();
106  }
107 
109  << "Pressure equation dimensions not recognised"
110  << exit(FatalError);
111 
112  return tmp<volScalarField::Internal>(nullptr);
113 }
114 
115 
116 void Foam::fv::zeroDimensionalFixedPressureConstraint::readCoeffs()
117 {
118  pName_ = coeffs().lookupOrDefault<word>("p", "p");
119 
120  rhoName_ = coeffs().lookupOrDefault<word>("rho", "rho");
121 
122  p_.reset
123  (
125  (
126  "pressure",
127  mesh().time().userUnits(),
128  dimPressure,
129  coeffs()
130  ).ptr()
131  );
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
136 
139 (
140  const word& name,
141  const word& modelType,
142  const fvMesh& mesh,
143  const dictionary& dict
144 )
145 :
146  fvConstraint(name, modelType, mesh, dict),
147  pName_(word::null),
148  rhoName_(word::null),
149  p_(nullptr),
150  sourcePtr_(nullptr)
151 {
152  if (mesh.nGeometricD() != 0)
153  {
155  << "Zero-dimensional fvConstraint applied to a "
156  << mesh.nGeometricD() << "-dimensional mesh"
157  << exit(FatalIOError);
158  }
159 
160  readCoeffs();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
175 {
176  return wordList(1, pName_);
177 }
178 
179 
182 (
183  const volScalarField& rho,
184  fvMatrix<scalar>& pEqn
185 ) const
186 {
187  // Ensure the corresponding fvModel exits
188  model();
189 
190  // Return zero if the source does not yet exist
191  if (!sourcePtr_.valid())
192  {
193  return
195  (
196  typedName("source"),
197  mesh(),
199  );
200  }
201 
202  // Return the source, multiplying by density if needed
203  if (sourcePtr_->dimensions() == pEqn.dimensions()/dimVolume)
204  {
205  return sourcePtr_();
206  }
207  else if (sourcePtr_->dimensions() == pEqn.dimensions()/dimMass)
208  {
209  return rho()*sourcePtr_();
210  }
211  else
212  {
214  << "Dimensions of equation for pressure "
215  << pEqn.psi().name() << " not recognised"
216  << exit(FatalError);
217 
218  return tmp<volScalarField::Internal>(nullptr);
219  }
220 }
221 
222 
224 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
225 (
227 ) const
228 {
230 }
231 
232 
234 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
235 (
238 ) const
239 {
241 }
242 
243 
245 (
246  fvMatrix<scalar>& pEqn,
247  const word& fieldName
248 ) const
249 {
250  // Create the source field if it does not already exist
251  if (!sourcePtr_.valid())
252  {
253  sourcePtr_.set
254  (
256  (
257  IOobject
258  (
259  typedName("source"),
260  mesh().time().name(),
261  mesh(),
264  ),
265  mesh(),
267  )
268  );
269  }
270 
271  // Remove the previous iteration's source from the pressure equation
272  pEqn += sourcePtr_();
273 
274  // Set the source as the residual of the pressure equation when evaluated
275  // at the desired pressure
276  sourcePtr_() =
277  pEqn
279  (
280  "p",
281  mesh(),
283  (
284  dimPressure,
285  p_->value(mesh().time().value())
286  )
287  );
288 
289  // Add the source to the pressure equation to force the pressure towards
290  // the desired value
291  pEqn -= sourcePtr_();
292 
293  return true;
294 }
295 
296 
298 {
299  return true;
300 }
301 
302 
304 (
305  const polyTopoChangeMap& map
306 )
307 {}
308 
309 
311 (
312  const polyMeshMap& map
313 )
314 {}
315 
316 
318 (
319  const polyDistributionMap& map
320 )
321 {}
322 
323 
325 (
326  const dictionary& dict
327 )
328 {
330  {
331  readCoeffs();
332  return true;
333  }
334  else
335  {
336  return false;
337  }
338 }
339 
340 
341 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &, const Field< Type > &)
Return a temporary field constructed from name, mesh,.
Run-time selectable general function of one variable.
Definition: Function1.H:125
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
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
Finite volume options abstract base class.
Definition: fvConstraint.H:57
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:166
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvConstraintI.H:34
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
VolField< Type > & psi()
Definition: fvMatrix.H:289
const dimensionSet & dimensions() const
Definition: fvMatrix.H:302
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
This fvModel applies a mass source to the continuity equation and to all field equations....
Definition: massSource.H:97
Zero-dimensional fixed pressure constraint. Should be used in conjunction with the zeroDimensionalFix...
tmp< volScalarField::Internal > pEqnSource(const volScalarField &rho, fvMatrix< scalar > &pEqn) const
Return the mass or volume source for the pressure equation.
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 read(const dictionary &dict)
Read dictionary.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
virtual bool constrain(fvMatrix< scalar > &pEqn, const word &fieldName) const
Apply the constraint to the pressure equation.
zeroDimensionalFixedPressureConstraint(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from dictionary.
Zero-dimensional fixed pressure source. Should be used in conjunction with the zeroDimensionalFixedPr...
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
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 managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvModels & fvModels(Foam::fvModels::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
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)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
const dimensionSet dimPressure
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const dimensionSet dimless
const dimensionSet dimTime
const dimensionSet dimVolume
word typedName(Name name)
Return the name of the object within the given type.
Definition: typeInfo.H:176
IOerror FatalIOError
const dimensionSet dimMass
error FatalError
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
labelList fv(nPoints)
dictionary dict