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 (
71 )
72 :
73  tmp<LagrangianCoeff<Type, Implicit>>::refCount(),
74  eqn_(coeff.eqn_),
75  S_(coeff.S_, false)
76 {}
77 
78 
79 template<class Type, bool Implicit>
81 (
83  const bool reuse
84 )
85 :
86  eqn_(coeff.eqn_),
87  S_(coeff.S_, reuse)
88 {}
89 
90 
91 template<class Type, bool Implicit>
93 (
95 )
96 :
97  tmp<LagrangianCoeff<Type, Implicit>>::refCount(),
98  eqn_(coeff.eqn_),
99  S_(coeff.S_, true)
100 {}
101 
102 
103 template<class Type, bool Implicit>
104 template<template<class> class PrimitiveField>
106 (
107  const LagrangianEqnBase& eqn,
109 )
110 :
111  eqn_(eqn),
112  S_(S.clone())
113 {}
114 
115 
116 template<class Type, bool Implicit>
117 template<template<class> class PrimitiveField>
119 (
120  const LagrangianEqnBase& eqn,
122 )
123 :
124  eqn_(eqn),
125  S_(tS.isTmp() ? tS.ptr() : tS().clone().ptr())
126 {}
127 
128 
129 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
130 
131 template<class Type, bool Implicit>
134 {
135  return eqn_;
136 }
137 
138 
139 template<class Type, bool Implicit>
141 {
142  return S_.valid();
143 }
144 
145 
146 template<class Type, bool Implicit>
149 {
150  return S_();
151 }
152 
153 
154 template<class Type, bool Implicit>
156 {
157  if (valid()) S_() = -S_();
158 }
159 
160 
161 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
162 
163 template<class Type, bool Implicit>
164 template<template<class> class PrimitiveField>
166 (
168 )
169 {
170  initialise(S.dimensions());
171  S_() += S;
172 }
173 
174 
175 template<class Type, bool Implicit>
176 template<template<class> class PrimitiveField>
178 (
180 )
181 {
182  operator+=(tS());
183  tS.clear();
184 }
185 
186 
187 template<class Type, bool Implicit>
189 (
190  const LagrangianCoeff& coeff
191 )
192 {
193  if (!coeff.valid()) return;
194  operator+=(coeff.S_());
195 }
196 
197 
198 template<class Type, bool Implicit>
200 (
201  const dimensioned<Type>& dt
202 )
203 {
204  initialise(dt.dimensions());
205  S_() += dt;
206 }
207 
208 
209 template<class Type, bool Implicit>
211 {}
212 
213 
214 template<class Type, bool Implicit>
215 template<template<class> class PrimitiveField>
217 (
219 )
220 {
221  initialise(S.dimensions());
222  S_() -= S;
223 }
224 
225 
226 template<class Type, bool Implicit>
227 template<template<class> class PrimitiveField>
229 (
231 )
232 {
233  operator-=(tS());
234  tS.clear();
235 }
236 
237 
238 template<class Type, bool Implicit>
240 (
241  const LagrangianCoeff& coeff
242 )
243 {
244  if (!coeff.valid()) return;
245  operator-=(coeff.S_());
246 }
247 
248 
249 template<class Type, bool Implicit>
251 (
252  const dimensioned<Type>& dt
253 )
254 {
255  initialise(dt.dimensions());
256  S_() -= dt;
257 }
258 
259 
260 template<class Type, bool Implicit>
262 {}
263 
264 
265 template<class Type, bool Implicit>
266 template<template<class> class PrimitiveField>
268 (
270 )
271 {
272  if (!valid()) return;
273  S_() *= S;
274 }
275 
276 
277 template<class Type, bool Implicit>
278 template<template<class> class PrimitiveField>
280 (
282 )
283 {
284  if (!valid()) return;
285  S_() *= tS();
286  tS.clear();
287 }
288 
289 
290 template<class Type, bool Implicit>
292 (
293  const dimensioned<scalar>& dt
294 )
295 {
296  if (!valid()) return;
297  S_() *= dt;
298 }
299 
300 
301 template<class Type, bool Implicit>
303 {
304  S_.clear();
305 }
306 
307 
308 template<class Type, bool Implicit>
309 template<template<class> class PrimitiveField>
311 (
313 )
314 {
315  if (!valid()) return;
316  S_() /= S;
317 }
318 
319 
320 template<class Type, bool Implicit>
321 template<template<class> class PrimitiveField>
323 (
325 )
326 {
327  if (!valid()) return;
328  S_() /= tS();
329  tS.clear();
330 }
331 
332 
333 template<class Type, bool Implicit>
335 (
336  const dimensioned<scalar>& dt
337 )
338 {
339  if (!valid()) return;
340  S_() /= dt;
341 }
342 
343 
344 // ************************************************************************* //
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 from a reference to the equation.
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.
Generic dimensioned Type class.
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
bool valid(const PtrList< ModelType > &l)
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
static const zero Zero
Definition: zero.H:97
T clone(const T &t)
Definition: List.H:55
void operator+=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Add to a finite-volume equation.
Definition: CarrierEqn.C:71
void operator-=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Subtract from a finite-volume equation.
Definition: CarrierEqn.C:94