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 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(Function1<scalar>::New("pressure", coeffs()).ptr());
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127 
130 (
131  const word& name,
132  const word& modelType,
133  const fvMesh& mesh,
134  const dictionary& dict
135 )
136 :
137  fvConstraint(name, modelType, mesh, dict),
138  pName_(word::null),
139  rhoName_(word::null),
140  p_(nullptr),
141  sourcePtr_(nullptr)
142 {
143  if (mesh.nGeometricD() != 0)
144  {
146  << "Zero-dimensional fvConstraint applied to a "
147  << mesh.nGeometricD() << "-dimensional mesh"
148  << exit(FatalIOError);
149  }
150 
151  readCoeffs();
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
166 {
167  return wordList(1, pName_);
168 }
169 
170 
173 (
174  fvMatrix<scalar>& pEqn
175 ) const
176 {
177  // Ensure the corresponding fvModel exits
178  model();
179 
180  // Construct the source if it does not yet exist
181  if (!sourcePtr_.valid())
182  {
183  sourcePtr_.set
184  (
186  (
187  IOobject
188  (
189  typedName("source"),
190  mesh().time().timeName(),
191  mesh(),
194  ),
195  mesh(),
197  )
198  );
199  }
200 
201  return sourcePtr_();
202 }
203 
204 
206 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
207 (
209 ) const
210 {
212 }
213 
214 
216 Foam::fv::zeroDimensionalFixedPressureConstraint::massSource
217 (
220 ) const
221 {
223 }
224 
225 
227 (
228  fvMatrix<scalar>& pEqn,
229  const word& fieldName
230 ) const
231 {
232  // Construct the source if it does not yet exist
233  pEqnSource(pEqn);
234 
235  // Check the dimensions have not changed
236  sourcePtr_->dimensions() = pEqn.dimensions()/dimVolume;
237 
238  // Remove the previous iteration's source from the pressure equation
239  pEqn += sourcePtr_();
240 
241  // Set the source as the residual of the pressure equation when evaluated
242  // at the desired pressure
243  sourcePtr_() =
244  pEqn
246  (
247  "p",
248  mesh(),
250  (
251  dimPressure,
252  p_->value(mesh().time().userTimeValue())
253  )
254  );
255 
256  // Add the source to the pressure equation to force the pressure towards
257  // the desired value
258  pEqn -= sourcePtr_();
259 
260  return true;
261 }
262 
263 
265 {
266  return true;
267 }
268 
269 
271 (
272  const polyTopoChangeMap& map
273 )
274 {}
275 
276 
278 (
279  const polyMeshMap& map
280 )
281 {}
282 
283 
285 (
286  const polyDistributionMap& map
287 )
288 {}
289 
290 
292 (
293  const dictionary& dict
294 )
295 {
297  {
298  readCoeffs();
299  return true;
300  }
301  else
302  {
303  return false;
304  }
305 }
306 
307 
308 // ************************************************************************* //
#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:64
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:160
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
const dimensionSet & dimensions() const
Definition: fvMatrix.H:302
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
This fvModel applies a mass source to the continuity equation and to all field equations.
Definition: massSource.H:250
Zero-dimensional fixed pressure constraint. Should be used in conjunction with the zeroDimensionalFix...
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.
const volScalarField::Internal & pEqnSource(fvMatrix< scalar > &pEqn) const
Return the mass or volume source for the pressure equation.
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:1055
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:318
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
word timeName
Definition: getTimeIndex.H:3
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
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:149
IOerror FatalIOError
const dimensionSet dimMass
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList fv(nPoints)
dictionary dict