LagrangianCoeff.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 "LagrangianCoeff.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Type, bool Implicit>
31 void Foam::LagrangianCoeff<Type, Implicit>::initialise(const dimensionSet& dims)
32 {
33  if (valid()) return;
34 
35  S_.set
36  (
37  new LagrangianSubField<Type>
38  (
39  IOobject
40  (
41  eqn_.name() + ":S" + (Implicit ? 'p' : 'u'),
42  eqn_.mesh().mesh().time().name(),
43  eqn_.mesh().mesh(),
44  IOobject::NO_READ,
45  IOobject::NO_WRITE,
46  false
47  ),
48  eqn_.mesh(),
49  dimensioned<Type>(dims, Zero)
50  )
51  );
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 template<class Type, bool Implicit>
59 (
60  const LagrangianEqnBase& eqn
61 )
62 :
63  eqn_(eqn)
64 {}
65 
66 
67 template<class Type, bool Implicit>
69 (
70  const LagrangianEqnBase& eqn,
72 )
73 :
74  tmp<LagrangianCoeff<Type, Implicit>>::refCount(),
75  eqn_(eqn),
76  S_(coeff.S_, false)
77 {}
78 
79 
80 template<class Type, bool Implicit>
82 (
83  const LagrangianEqnBase& eqn,
85  const bool reuse
86 )
87 :
88  eqn_(eqn),
89  S_(coeff.S_, reuse)
90 {}
91 
92 
93 template<class Type, bool Implicit>
95 (
97 )
98 :
99  tmp<LagrangianCoeff<Type, Implicit>>::refCount(),
100  eqn_(coeff.eqn_),
101  S_(coeff.S_, true)
102 {}
103 
104 
105 template<class Type, bool Implicit>
106 template<template<class> class PrimitiveField>
108 (
109  const LagrangianEqnBase& eqn,
111 )
112 :
113  eqn_(eqn),
114  S_(S.clone())
115 {}
116 
117 
118 template<class Type, bool Implicit>
119 template<template<class> class PrimitiveField>
121 (
122  const LagrangianEqnBase& eqn,
124 )
125 :
126  eqn_(eqn),
127  S_(tS.isTmp() ? tS.ptr() : tS().clone().ptr())
128 {}
129 
130 
131 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
132 
133 template<class Type, bool Implicit>
136 {
137  return eqn_;
138 }
139 
140 
141 template<class Type, bool Implicit>
143 {
144  return S_.valid();
145 }
146 
147 
148 template<class Type, bool Implicit>
151 {
152  return S_();
153 }
154 
155 
156 template<class Type, bool Implicit>
158 {
159  if (valid()) S_() = -S_();
160 }
161 
162 
163 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
164 
165 template<class Type, bool Implicit>
166 template<template<class> class PrimitiveField>
168 (
170 )
171 {
172  initialise(S.dimensions());
173  S_() += S;
174 }
175 
176 
177 template<class Type, bool Implicit>
178 template<template<class> class PrimitiveField>
180 (
182 )
183 {
184  operator+=(tS());
185  tS.clear();
186 }
187 
188 
189 template<class Type, bool Implicit>
191 (
192  const LagrangianCoeff& coeff
193 )
194 {
195  if (!coeff.valid()) return;
196  operator+=(coeff.S_());
197 }
198 
199 
200 template<class Type, bool Implicit>
201 template<class OtherType>
203 (
205 )
206 {
207  if (!coeff.valid()) return;
208 
210  << "Cannot add a " << pTraits<OtherType>::typeName
211  << (Implicit ? "implicit" : "explicit")
212  << " coefficient to equation " << eqn().name()
213  << exit(FatalError);
214 }
215 
216 
217 template<class Type, bool Implicit>
219 (
220  const dimensioned<Type>& dt
221 )
222 {
223  initialise(dt.dimensions());
224  S_() += dt;
225 }
226 
227 
228 template<class Type, bool Implicit>
230 {}
231 
232 
233 template<class Type, bool Implicit>
234 template<template<class> class PrimitiveField>
236 (
238 )
239 {
240  initialise(S.dimensions());
241  S_() -= S;
242 }
243 
244 
245 template<class Type, bool Implicit>
246 template<template<class> class PrimitiveField>
248 (
250 )
251 {
252  operator-=(tS());
253  tS.clear();
254 }
255 
256 
257 template<class Type, bool Implicit>
259 (
260  const LagrangianCoeff& coeff
261 )
262 {
263  if (!coeff.valid()) return;
264  operator-=(coeff.S_());
265 }
266 
267 
268 template<class Type, bool Implicit>
269 template<class OtherType>
271 (
273 )
274 {
275  if (!coeff.valid()) return;
276 
278  << "Cannot subtract a " << pTraits<OtherType>::typeName
279  << (Implicit ? "implicit" : "explicit")
280  << " coefficient from equation " << eqn().name()
281  << exit(FatalError);
282 }
283 
284 
285 template<class Type, bool Implicit>
287 (
288  const dimensioned<Type>& dt
289 )
290 {
291  initialise(dt.dimensions());
292  S_() -= dt;
293 }
294 
295 
296 template<class Type, bool Implicit>
298 {}
299 
300 
301 template<class Type, bool Implicit>
302 template<template<class> class PrimitiveField>
304 (
306 )
307 {
308  if (!valid()) return;
309  S_() *= S;
310 }
311 
312 
313 template<class Type, bool Implicit>
314 template<template<class> class PrimitiveField>
316 (
318 )
319 {
320  if (!valid()) return;
321  S_() *= tS();
322  tS.clear();
323 }
324 
325 
326 template<class Type, bool Implicit>
328 (
329  const dimensioned<scalar>& dt
330 )
331 {
332  if (!valid()) return;
333  S_() *= dt;
334 }
335 
336 
337 template<class Type, bool Implicit>
339 {
340  S_.clear();
341 }
342 
343 
344 template<class Type, bool Implicit>
345 template<template<class> class PrimitiveField>
347 (
349 )
350 {
351  if (!valid()) return;
352  S_() /= S;
353 }
354 
355 
356 template<class Type, bool Implicit>
357 template<template<class> class PrimitiveField>
359 (
361 )
362 {
363  if (!valid()) return;
364  S_() /= tS();
365  tS.clear();
366 }
367 
368 
369 template<class Type, bool Implicit>
371 (
372  const dimensioned<scalar>& dt
373 )
374 {
375  if (!valid()) return;
376  S_() /= dt;
377 }
378 
379 
380 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Class to store a coefficient of a Lagrangian equation.
bool valid() const
Determine whether this coefficient has values or not.
LagrangianCoeff(const LagrangianEqnBase &eqn)
Construct empty.
void operator-=(const LagrangianSubField< Type, PrimitiveField > &)
Subtraction assignment.
const LagrangianEqnBase & eqn() const
Access the equation.
void operator*=(const LagrangianSubField< scalar, PrimitiveField > &)
Multiply assignment.
void operator+=(const LagrangianSubField< Type, PrimitiveField > &)
Addition assignment.
void negate()
In-place negation.
const LagrangianSubField< Type > & S() const
Access the coefficient.
Non-templated base class for Lagrangian equations.
const word & name() const
Return the equation name.
Generic dimensioned Type class.
Traits class for primitives.
Definition: pTraits.H:53
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
bool valid(const PtrList< ModelType > &l)
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
T clone(const T &t)
Definition: List.H:55
error FatalError
void operator+=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Add to a finite-volume equation.
Definition: CarrierEqn.C:271
void operator-=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Subtract from a finite-volume equation.
Definition: CarrierEqn.C:299