LagrangianVectorSp.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 "LagrangianSp.H"
27 #include "LagrangianEqn.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
32 {
33  if (tensorCoeff_.valid()) return;
34 
35  if (!scalarCoeff_.valid()) return;
36 
37  tensorCoeff_ += tensor::I*scalarCoeff_.S();
38 
39  scalarCoeff_ *= Zero;
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
45 Foam::LagrangianSp<Foam::vector>::LagrangianSp(const LagrangianEqn<vector>& eqn)
46 :
47  scalarCoeff_(eqn),
48  tensorCoeff_(eqn)
49 {}
50 
51 
53 (
54  const LagrangianEqnBase& eqn,
55  const LagrangianSp<vector>& coeff
56 )
57 :
58  tmp<LagrangianSp<vector>>::refCount(),
59  scalarCoeff_(eqn, coeff.scalarCoeff_),
60  tensorCoeff_(eqn, coeff.tensorCoeff_)
61 {}
62 
63 
65 (
66  const LagrangianEqnBase& eqn,
67  LagrangianSp<vector>& coeff,
68  const bool reuse
69 )
70 :
71  scalarCoeff_(eqn, coeff.scalarCoeff_, reuse),
72  tensorCoeff_(eqn, coeff.tensorCoeff_, reuse)
73 {}
74 
75 
76 Foam::LagrangianSp<Foam::vector>::LagrangianSp(LagrangianSp<vector>&& coeff)
77 :
78  tmp<LagrangianSp<vector>>::refCount(),
79  scalarCoeff_(move(coeff.scalarCoeff_)),
80  tensorCoeff_(move(coeff.tensorCoeff_))
81 {}
82 
83 
84 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
85 
87 {
88  return scalarCoeff_.eqn();
89 }
90 
91 
93 {
94  return
95  scalarCoeff_.valid()
96  || tensorCoeff_.valid();
97 }
98 
99 
101 {
102  scalarCoeff_.negate();
103  tensorCoeff_.negate();
104 }
105 
106 
109 {
110  return
111  tensorCoeff_.valid()
112  ? tmp<LagrangianCoeff<scalar, true>>
113  (
114  new LagrangianCoeff<scalar, true>
115  (
116  eqn(),
117  (1.0/3.0)*tr(tensorCoeff_.S())
118  )
119  )
120  : tmp<LagrangianCoeff<scalar, true>>(scalarCoeff_);
121 }
122 
123 
126 {
127  const LagrangianEqn<vector>& eqn =
128  static_cast<const LagrangianEqn<vector>&>(this->eqn());
129 
130  return
131  tmp<LagrangianCoeff<vector, false>>
132  (
133  tensorCoeff_.valid()
134  ? new LagrangianCoeff<vector, false>
135  (
136  eqn,
137  dev2(tensorCoeff_.S()) & eqn.psi()
138  )
139  : new LagrangianCoeff<vector, false>(eqn)
140  );
141 }
142 
143 
146 {
147  return Su(static_cast<const LagrangianEqn<vector>&>(this->eqn()));
148 }
149 
150 
152 Foam::LagrangianSp<Foam::vector>::Su(const LagrangianEqn<vector>& eqn) const
153 {
154  return
155  tmp<LagrangianCoeff<vector, false>>
156  (
157  valid()
158  ? new LagrangianCoeff<vector, false>
159  (
160  eqn,
161  tensorCoeff_.valid()
162  ? tensorCoeff_.S() & eqn.psi()
163  : scalarCoeff_.S()*eqn.psi()
164  )
165  : new LagrangianCoeff<vector, false>(eqn)
166  );
167 }
168 
169 
170 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
171 
173 (
174  const LagrangianCoeff<scalar, true>& coeff
175 )
176 {
177  if (!coeff.valid()) return;
178  operator+=(coeff.S());
179 }
180 
181 
183 (
184  const LagrangianCoeff<tensor, true>& coeff
185 )
186 {
187  if (!coeff.valid()) return;
188  operator+=(coeff.S());
189 }
190 
191 
193 (
194  const LagrangianSp<vector>& Sp
195 )
196 {
197  if (Sp.tensorCoeff_.valid())
198  {
199  operator+=(Sp.tensorCoeff_.S());
200  }
201  if (Sp.scalarCoeff_.valid())
202  {
203  operator+=(Sp.scalarCoeff_.S());
204  }
205 }
206 
207 
208 void Foam::LagrangianSp<Foam::vector>::operator+=(const dimensioned<scalar>& dt)
209 {
210  if (tensorCoeff_.valid())
211  {
212  tensorCoeff_ += tensor::I*dt;
213  }
214  else
215  {
216  scalarCoeff_ += dt;
217  }
218 }
219 
220 
221 void Foam::LagrangianSp<Foam::vector>::operator+=(const dimensioned<tensor>& dt)
222 {
223  makeTensor();
224  tensorCoeff_ += dt;
225 }
226 
227 
229 {}
230 
231 
233 (
234  const LagrangianCoeff<scalar, true>& coeff
235 )
236 {
237  if (!coeff.valid()) return;
238  operator-=(coeff.S());
239 }
240 
241 
243 (
244  const LagrangianCoeff<tensor, true>& coeff
245 )
246 {
247  if (!coeff.valid()) return;
248  operator-=(coeff.S());
249 }
250 
251 
253 (
254  const LagrangianSp<vector>& Sp
255 )
256 {
257  if (Sp.tensorCoeff_.valid())
258  {
259  operator-=(Sp.tensorCoeff_.S());
260  }
261  if (Sp.scalarCoeff_.valid())
262  {
263  operator-=(Sp.scalarCoeff_.S());
264  }
265 }
266 
267 
268 void Foam::LagrangianSp<Foam::vector>::operator-=(const dimensioned<scalar>& dt)
269 {
270  if (tensorCoeff_.valid())
271  {
272  tensorCoeff_ -= tensor::I*dt;
273  }
274  else
275  {
276  scalarCoeff_ -= dt;
277  }
278 }
279 
280 
281 void Foam::LagrangianSp<Foam::vector>::operator-=(const dimensioned<tensor>& dt)
282 {
283  makeTensor();
284  tensorCoeff_ -= dt;
285 }
286 
287 
289 {}
290 
291 
292 void Foam::LagrangianSp<Foam::vector>::operator*=(const dimensioned<scalar>& dt)
293 {
294  scalarCoeff_ *= dt;
295  tensorCoeff_ *= dt;
296 }
297 
298 
299 void Foam::LagrangianSp<Foam::vector>::operator/=(const dimensioned<scalar>& dt)
300 {
301  scalarCoeff_ /= dt;
302  tensorCoeff_ /= dt;
303 }
304 
305 
306 // * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
307 
309 (
311  const LagrangianSp<vector>& Sp
312 )
313 {
314  if (Sp.tensorCoeff_.valid())
315  {
316  return inv(Sp.tensorCoeff_.S()) & Su.S();
317  }
318  else
319  {
320  return Su.S()/Sp.scalarCoeff_.S();
321  }
322 }
323 
324 
325 // ************************************************************************* //
Class to store a coefficient of a Lagrangian equation.
bool valid() const
Determine whether this coefficient has values or not.
const LagrangianEqnBase & eqn() const
Access the equation.
void operator/=(const LagrangianSubField< scalar, PrimitiveField > &)
Division assignment.
void operator*=(const LagrangianSubField< scalar, PrimitiveField > &)
Multiply assignment.
Non-templated base class for Lagrangian equations.
Wrapper around LagrangianCoeff to specialise for the implicit coefficient. Trivial at present....
Definition: LagrangianSp.H:71
tmp< LagrangianCoeff< Type, false > > H() const
Return the scalar off-diagonal coefficients.
Definition: LagrangianSp.C:72
tmp< LagrangianCoeff< Type, false > > Su() const
Return the equivalent explicit coefficient.
Definition: LagrangianSp.C:84
tmp< LagrangianCoeff< scalar, true > > A() const
Return the scalar diagonal coefficient.
Definition: LagrangianSp.C:64
void operator+=(const LagrangianSp< OtherType > &)
Addition assignment.
Definition: LagrangianSp.C:108
LagrangianSp(const LagrangianEqnBase &, const LagrangianSp< Type > &Sp)
Construct as copy.
Definition: LagrangianSp.C:32
void operator-=(const LagrangianSp< OtherType > &Sp)
Subtraction assignment.
Definition: LagrangianSp.C:116
A class for managing temporary objects.
Definition: tmp.H:55
bool valid(const PtrList< ModelType > &l)
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
static const zero Zero
Definition: zero.H:97
void dev2(pointPatchField< tensor > &, const pointPatchField< tensor > &)
static const Identity< scalar > I
Definition: Identity.H:93
void tr(pointPatchField< scalar > &, const pointPatchField< tensor > &)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
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