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  const dictionary& dict
119 )
120 {
121  pName_ = dict.lookupOrDefault<word>("p", "p");
122 
123  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
124 
125  p_.reset
126  (
128  (
129  "pressure",
130  mesh().time().userUnits(),
131  dimPressure,
132  dict
133  ).ptr()
134  );
135 }
136 
137 
138 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
139 
142 (
143  const word& name,
144  const word& modelType,
145  const fvMesh& mesh,
146  const dictionary& dict
147 )
148 :
149  fvConstraint(name, modelType, mesh, dict),
150  pName_(word::null),
151  rhoName_(word::null),
152  p_(nullptr),
153  sourcePtr_(nullptr)
154 {
155  if (mesh.nGeometricD() != 0)
156  {
158  << "Zero-dimensional fvConstraint applied to a "
159  << mesh.nGeometricD() << "-dimensional mesh"
160  << exit(FatalIOError);
161  }
162 
163  readCoeffs(coeffs(dict));
164 }
165 
166 
167 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
168 
171 {}
172 
173 
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 
178 {
179  return wordList(1, pName_);
180 }
181 
182 
185 (
186  const volScalarField& rho,
187  fvMatrix<scalar>& pEqn
188 ) const
189 {
190  // Ensure the corresponding fvModel exits
191  model();
192 
193  // Return zero if the source does not yet exist
194  if (!sourcePtr_.valid())
195  {
196  return
198  (
199  typedName("source"),
200  mesh(),
202  );
203  }
204 
205  // Return the source, multiplying by density if needed
206  if (sourcePtr_->dimensions() == pEqn.dimensions()/dimVolume)
207  {
208  return sourcePtr_();
209  }
210  else if (sourcePtr_->dimensions() == pEqn.dimensions()/dimMass)
211  {
212  return rho()*sourcePtr_();
213  }
214  else
215  {
217  << "Dimensions of equation for pressure "
218  << pEqn.psi().name() << " not recognised"
219  << exit(FatalError);
220 
221  return tmp<volScalarField::Internal>(nullptr);
222  }
223 }
224 
225 
227 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
228 (
230 ) const
231 {
233 }
234 
235 
237 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
238 (
241 ) const
242 {
244 }
245 
246 
248 (
249  fvMatrix<scalar>& pEqn,
250  const word& fieldName
251 ) const
252 {
253  // Create the source field if it does not already exist
254  if (!sourcePtr_.valid())
255  {
256  sourcePtr_.set
257  (
259  (
260  IOobject
261  (
262  typedName("source"),
263  mesh().time().name(),
264  mesh(),
267  ),
268  mesh(),
270  )
271  );
272  }
273 
274  // Remove the previous iteration's source from the pressure equation
275  pEqn += sourcePtr_();
276 
277  // Set the source as the residual of the pressure equation when evaluated
278  // at the desired pressure
279  sourcePtr_() =
280  pEqn
282  (
283  "p",
284  mesh(),
286  (
287  dimPressure,
288  p_->value(mesh().time().value())
289  )
290  );
291 
292  // Add the source to the pressure equation to force the pressure towards
293  // the desired value
294  pEqn -= sourcePtr_();
295 
296  return true;
297 }
298 
299 
301 {
302  return true;
303 }
304 
305 
307 (
308  const polyTopoChangeMap& map
309 )
310 {}
311 
312 
314 (
315  const polyMeshMap& map
316 )
317 {}
318 
319 
321 (
322  const polyDistributionMap& map
323 )
324 {}
325 
326 
328 (
329  const dictionary& dict
330 )
331 {
333  {
334  readCoeffs(coeffs(dict));
335  return true;
336  }
337  else
338  {
339  return false;
340  }
341 }
342 
343 
344 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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, PrimitiveField > > New(const word &name, const Mesh &mesh, const dimensionSet &, const PrimitiveField< 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
const unitConversion & userUnits() const
Return the user-time unit conversion.
Definition: Time.C:858
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:103
Finite volume options abstract base class.
Definition: fvConstraint.H:57
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:164
const dictionary & coeffs(const dictionary &) const
Return the coefficients sub-dictionary.
Definition: fvConstraintI.H:41
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:96
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
This fvModel applies a mass source to the continuity equation and to all field equations....
Definition: massSource.H:100
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:1023
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))
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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
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:181
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const dimensionSet dimMass
error FatalError
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
labelList fv(nPoints)
dictionary dict