CarrierEqn.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) 2025 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 "CarrierEqn.H"
27 #include "volFieldsFwd.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
32 template<class PsiFieldType>
35 (
36  const dimensionSet& dims,
37  const word& psiName,
38  const PsiFieldType& psi
39 ) const
40 {
41  // Check the dimensions
42  if (Su.valid())
43  {
44  Su.S().dimensions() = dims*dimTime*dimVolume;
45  }
46  if (Sp.valid())
47  {
48  Sp.S().dimensions()*psi.dimensions() = dims*dimTime*dimVolume;
49  }
50 
51  // Build the residual
52  if (Su.valid() && Sp.valid())
53  {
54  return (Su.S() + Sp.S()*psi)/mesh_.time().deltaT()/mesh_.V();
55  }
56  else if (Su.valid())
57  {
58  return Su.S()/mesh_.time().deltaT()/mesh_.V();
59  }
60  else if (Sp.valid())
61  {
62  return Sp.S()*psi/mesh_.time().deltaT()/mesh_.V();
63  }
64  else
65  {
66  return
68  (
69  name_ + "&" + psiName,
70  mesh_,
71  dimensionedScalar(dims, scalar(0))
72  );
73  }
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 template<class Type>
81 :
83  (
84  IOobject::groupName
85  (
86  IOobject::member(psi.name()) + "Eqn",
88  ),
89  psi.mesh()
90  ),
91  psi_(psi),
92  Su(*this),
93  Sp(*this)
94 {}
95 
96 
97 template<class Type>
99 (
100  const word& psiName,
101  const fvMesh& mesh
102 )
103 :
105  (
106  IOobject::groupName
107  (
108  IOobject::member(psiName) + "Eqn",
109  IOobject::group(psiName)
110  ),
111  mesh
112  ),
113  psi_(NullObjectRef<VolField<Type>>()),
114  Su(*this),
115  Sp(*this)
116 {}
117 
118 
119 template<class Type>
121 :
122  CarrierEqnBase(eqn.name(), eqn.mesh()),
123  psi_(eqn.psi_),
124  Su(eqn.Su),
125  Sp(eqn.Sp)
126 {}
127 
128 
129 template<class Type>
131 :
132  CarrierEqnBase(tEqn().name(), tEqn().mesh()),
133  psi_(tEqn().psi_),
134  Su
135  (
136  tEqn.isTmp()
137  ? CarrierCoeff<Type, false>(tEqn.ref().Su, true)
138  : CarrierCoeff<Type, false>(tEqn().Su)
139  ),
140  Sp
141  (
142  tEqn.isTmp()
143  ? CarrierCoeff<scalar, true>(tEqn.ref().Sp, true)
144  : CarrierCoeff<scalar, true>(tEqn().Sp)
145  )
146 {
147  tEqn.clear();
148 }
149 
150 
151 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
152 
153 template<class Type>
155 {
156  Su.clear();
157  Sp.clear();
158 }
159 
160 
161 template<class Type>
164 (
165  const dimensionSet& dims
166 ) const
167 {
168  return
169  notNull(psi_)
170  ? residual(dims, psi_.name(), psi_)
171  : residual(dims, "1", geometricOneField());
172 }
173 
174 
175 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
176 
177 template<class Type>
179 {
180  Su += lEqn.allDiagonalSu();
181  Sp += lEqn.allDiagonalSp();
182 }
183 
184 
185 template<class Type>
187 {
188  operator+=(tlEqn());
189  tlEqn.clear();
190 }
191 
192 
193 template<class Type>
195 {
196  Su -= lEqn.allDiagonalSu();
197  Sp -= lEqn.allDiagonalSp();
198 }
199 
200 
201 template<class Type>
203 {
204  operator-=(tlEqn());
205  tlEqn.clear();
206 }
207 
208 
209 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
210 
211 #define CARRIER_EQN_SCALAR_OPERATOR(Op, EqOp) \
212  \
213  template<class Type> \
214  Foam::tmp<Foam::CarrierEqn<Type>> Foam::operator Op \
215  ( \
216  const CarrierEqn<Type>& eqn, \
217  const dimensionedScalar& s \
218  ) \
219  { \
220  return tmp<CarrierEqn<Type>>(eqn) Op s; \
221  } \
222  \
223  template<class Type> \
224  Foam::tmp<Foam::CarrierEqn<Type>> Foam::operator Op \
225  ( \
226  const tmp<CarrierEqn<Type>>& tEqn, \
227  const dimensionedScalar& s \
228  ) \
229  { \
230  tmp<CarrierEqn<Type>> tResult(new CarrierEqn<Type>(tEqn)); \
231  \
232  tResult.ref().Su EqOp s; \
233  tResult.ref().Sp EqOp s; \
234  \
235  return tResult; \
236  }
237 
238 #define CARRIER_COMMUTATIVE_SCALAR_EQN_OPERATOR(Op, EqOp) \
239  \
240  template<class Type> \
241  Foam::tmp<Foam::CarrierEqn<Type>> Foam::operator Op \
242  ( \
243  const dimensionedScalar& s, \
244  const CarrierEqn<Type>& eqn \
245  ) \
246  { \
247  return eqn Op s; \
248  } \
249  \
250  template<class Type> \
251  Foam::tmp<Foam::CarrierEqn<Type>> Foam::operator Op \
252  ( \
253  const dimensionedScalar& s, \
254  const tmp<CarrierEqn<Type>>& tEqn \
255  ) \
256  { \
257  return tEqn Op s; \
258  }
259 
260 //- Multiplication
263 
264 //- Division
266 
267 #undef CARRIER_EQN_SCALAR_OPERATOR
268 #undef CARRIER_COMMUTATIVE_SCALAR_EQN_OPERATOR
269 
270 template<class Type>
272 {
273  const dimensionedScalar& deltaT = fvEqn.psi().mesh().time().deltaT();
274 
275  if (cEqn.Su.valid())
276  {
277  fvEqn.dimensions() -= cEqn.Su.S().dimensions()/dimTime;
278  fvEqn.source() -= cEqn.Su.S().primitiveField()/deltaT.value();
279  }
280 
281  if (cEqn.Sp.valid())
282  {
283  fvEqn.dimensions() +=
284  cEqn.Sp.S().dimensions()/dimTime*fvEqn.psi().dimensions();
285  fvEqn.diag() += cEqn.Sp.S().primitiveField()/deltaT.value();
286  }
287 }
288 
289 
290 template<class Type>
292 {
293  fvEqn += tcEqn();
294  tcEqn.clear();
295 }
296 
297 
298 template<class Type>
300 {
301  const dimensionedScalar& deltaT = fvEqn.psi().mesh().time().deltaT();
302 
303  if (cEqn.Su.valid())
304  {
305  fvEqn.dimensions() += cEqn.Su.S().dimensions()/dimTime;
306  fvEqn.source() += cEqn.Su.S().primitiveField()/deltaT.value();
307  }
308 
309  if (cEqn.Sp.valid())
310  {
311  fvEqn.dimensions() -=
312  cEqn.Sp.S().dimensions()/dimTime*fvEqn.psi().dimensions();
313  fvEqn.diag() -= cEqn.Sp.S().primitiveField()/deltaT.value();
314  }
315 }
316 
317 
318 template<class Type>
320 {
321  fvEqn -= tcEqn();
322  tcEqn.clear();
323 }
324 
325 
326 // ************************************************************************* //
#define CARRIER_COMMUTATIVE_SCALAR_EQN_OPERATOR(Op, EqOp)
Definition: CarrierEqn.C:238
#define CARRIER_EQN_SCALAR_OPERATOR(Op, EqOp)
Definition: CarrierEqn.C:211
Class to store a coefficient of a carrier equation.
Definition: CarrierCoeff.H:53
bool valid() const
Determine whether this coefficient has values or not.
Definition: CarrierCoeff.C:106
const DimensionedField< Type, fvMesh > & S() const
Access the field.
Definition: CarrierCoeff.C:121
Non-templated base class for carrier equations.
Class to store the coefficients of a term in a carrier equation.
Definition: CarrierEqn.H:55
CarrierCoeff< scalar, true > Sp
Implicit coefficient.
Definition: CarrierEqn.H:82
void operator+=(const LagrangianEqn< Type > &lEqn)
Addition assignment.
Definition: CarrierEqn.C:178
void operator-=(const LagrangianEqn< Type > &lEqn)
Subtraction assignment.
Definition: CarrierEqn.C:194
CarrierEqn(const VolField< Type > &psi)
Construct for a field.
Definition: CarrierEqn.C:80
void clear()
Clear the coefficient values.
Definition: CarrierEqn.C:154
CarrierCoeff< Type, false > Su
Explicit coefficient.
Definition: CarrierEqn.H:79
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
This class stores the coefficients of a Lagrangian equation, and facilitates solving that equation an...
Definition: LagrangianEqn.H:56
tmp< LagrangianCoeff< scalar, true > > allDiagonalSp() const
Return the combined time and non-time implicit diagonal.
tmp< LagrangianCoeff< Type, false > > allDiagonalSu() const
Return the combined time and non-time explicit diagonal.
Dimension set for the base types.
Definition: dimensionSet.H:125
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Field< Type > & source()
Definition: fvMatrix.H:307
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:98
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
scalarField & diag()
Definition: lduMatrix.C:186
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
trAU ref().rename("rAU")
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const volScalarField & psi
const char *const group
Group name for atomic constants.
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
const dimensionSet & dimVolume
Definition: dimensions.C:150
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
const dimensionSet & dimTime
Definition: dimensions.C:142
const T & NullObjectRef()
Return const reference to the nullObject of type T.
Definition: nullObjectI.H:27
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void operator+=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Add to a finite-volume equation.
Definition: CarrierEqn.C:271
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
void operator-=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Subtract from a finite-volume equation.
Definition: CarrierEqn.C:299
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.