semiImplicitSource.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) 2011-2026 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 
26 #include "semiImplicitSource.H"
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "fvmSup.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  namespace fv
37  {
39 
41  (
42  fvModel,
45  );
46  }
47 }
48 
51 {
52  "absolute",
53  "specific"
54 };
55 
56 
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 
59 void Foam::fv::semiImplicitSource::readCoeffs(const dictionary& dict)
60 {
61  // Get the volume mode
62  volumeMode_ = volumeModeNames_.read(dict.lookup("volumeMode"));
63 
64  // Set field source terms
65  fieldSu_.clear();
66  fieldSp_.clear();
67  forAllConstIter(dictionary, dict.subDict("sources"), iter)
68  {
69  fieldSu_.set
70  (
71  iter().keyword(),
72  new unknownTypeFunction1
73  (
74  "explicit",
75  mesh().time().userUnits(),
76  iter().dict()
77  )
78  );
79  fieldSp_.set
80  (
81  iter().keyword(),
82  new unknownTypeFunction1
83  (
84  "implicit",
85  mesh().time().userUnits(),
86  iter().dict()
87  )
88  );
89  }
90 }
91 
92 
93 template<class Type>
94 void Foam::fv::semiImplicitSource::addSupType
95 (
96  const VolField<Type>& field,
97  fvMatrix<Type>& eqn
98 ) const
99 {
100  // Set the value units for the functions
101  fieldSu_[field.name()].template setValueUnits<Type>
102  (
103  eqn.dimensions()
104  );
105  fieldSp_[field.name()].template setValueUnits<scalar>
106  (
107  eqn.dimensions()/eqn.psi().dimensions()
108  );
109 
110  const scalar t = mesh().time().value();
111 
112  const VolField<Type>& psi = eqn.psi();
113 
114  zone_.regenerate();
115 
116  VolInternalField<Type> Su
117  (
118  IOobject
119  (
120  name() + field.name() + "Su",
121  mesh().time().name(),
122  mesh(),
125  ),
126  mesh(),
127  dimensioned<Type>
128  (
129  "zero",
130  eqn.dimensions()/dimVolume,
131  Zero
132  ),
133  false
134  );
135 
136  // Set volume normalisation
137  scalar VDash = NaN;
138  switch (volumeMode_)
139  {
141  VDash = zone_.V();
142  break;
143  case volumeMode::specific:
144  VDash = 1;
145  break;
146  }
147 
148  // Explicit source function for the field
149  UIndirectList<Type>(Su, zone_.zone()) =
150  fieldSu_[field.name()].template value<Type>(t)/VDash;
151 
153  (
154  IOobject
155  (
156  name() + field.name() + "Sp",
157  mesh().time().name(),
158  mesh(),
161  ),
162  mesh(),
163  dimensioned<scalar>
164  (
165  "zero",
166  Su.dimensions()/psi.dimensions(),
167  0
168  ),
169  false
170  );
171 
172  // Implicit source function for the field
173  UIndirectList<scalar>(Sp, zone_.zone()) =
174  fieldSp_[field.name()].template value<scalar>(t)/VDash;
175 
176  eqn += Su - fvm::SuSp(-Sp, psi);
177 }
178 
179 
180 template<class Type>
181 void Foam::fv::semiImplicitSource::addSupType
182 (
183  const volScalarField& rho,
184  const VolField<Type>& field,
185  fvMatrix<Type>& eqn
186 ) const
187 {
188  return addSup(field, eqn);
189 }
190 
191 
192 template<class Type>
193 void Foam::fv::semiImplicitSource::addSupType
194 (
195  const volScalarField& alpha,
196  const volScalarField& rho,
197  const VolField<Type>& field,
198  fvMatrix<Type>& eqn
199 ) const
200 {
201  return addSup(field, eqn);
202 }
203 
204 
205 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
206 
208 (
209  const word& name,
210  const word& modelType,
211  const fvMesh& mesh,
212  const dictionary& dict
213 )
214 :
215  fvModel(name, modelType, mesh, dict),
216  zone_(mesh, coeffs(dict)),
217  volumeMode_(volumeMode::absolute)
218 {
219  readCoeffs(coeffs(dict));
220 }
221 
222 
223 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
224 
226 {}
227 
228 
229 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
230 
232 {
233  return fieldSu_.toc();
234 }
235 
236 
238 (
240  fv::semiImplicitSource
241 )
242 
243 
245 (
247  fv::semiImplicitSource
248 )
249 
250 
252 (
254  fv::semiImplicitSource
255 )
256 
257 
259 {
260  zone_.movePoints();
261  return true;
262 }
263 
264 
266 {
267  zone_.topoChange(map);
268 }
269 
270 
272 {
273  zone_.mapMesh(map);
274 }
275 
276 
278 (
279  const polyDistributionMap& map
280 )
281 {
282  zone_.distribute(map);
283 }
284 
285 
287 {
288  if (fvModel::read(dict))
289  {
290  zone_.read(coeffs(dict));
291  readCoeffs(coeffs(dict));
292  return true;
293  }
294  else
295  {
296  return false;
297  }
298 }
299 
300 
301 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
DimensionedField< Type, GeoMesh, PrimitiveField > Internal
Type of the internal field from which this GeometricField is derived.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
Definition: NamedEnum.C:55
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Type & value() const
Return const reference to value.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
Finite volume model abstract base class.
Definition: fvModel.H:60
static const dictionary & coeffs(const word &modelType, const dictionary &)
Return the coefficients sub-dictionary for a given model type.
Definition: fvModelI.H:31
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:196
const word & keyword() const
Return name as the keyword.
Definition: fvModelI.H:63
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:69
Semi-implicit source, described using an input dictionary. The injection rate coefficients are specif...
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
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 bool read(const dictionary &dict)
Read source dictionary.
virtual ~semiImplicitSource()
Destructor.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
volumeMode
Enumeration for volume types.
semiImplicitSource(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
static const NamedEnum< volumeMode, 2 > volumeModeNames_
Property type names.
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
A special matrix type and solver, designed for finite volume solutions of scalar equations.
#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.
const volScalarField & psi
rho
Definition: pEqn.H:1
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
const dimensionSet time
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
tmp< VolField< Type > > Su(const VolField< Type > &su, const VolField< Type > &vf)
Definition: fvcSup.C:44
tmp< VolField< Type > > Sp(const volScalarField &sp, const VolField< Type > &vf)
Definition: fvcSup.C:67
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
Definition: fvcMeshPhi.C:202
tmp< fvMatrix< Type > > SuSp(const volScalarField::Internal &, const VolField< Type > &)
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
const dimensionSet & dimVolume
Definition: dimensions.C:150
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList fv(nPoints)
dictionary dict