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 LagrangianSp<vector>& coeff
55 )
56 :
57  tmp<LagrangianSp<vector>>::refCount(),
58  scalarCoeff_(coeff.scalarCoeff_),
59  tensorCoeff_(coeff.tensorCoeff_)
60 {}
61 
62 
64 (
65  LagrangianSp<vector>& coeff,
66  const bool reuse
67 )
68 :
69  scalarCoeff_(coeff.scalarCoeff_, reuse),
70  tensorCoeff_(coeff.tensorCoeff_, reuse)
71 {}
72 
73 
74 Foam::LagrangianSp<Foam::vector>::LagrangianSp(LagrangianSp<vector>&& coeff)
75 :
76  tmp<LagrangianSp<vector>>::refCount(),
77  scalarCoeff_(move(coeff.scalarCoeff_)),
78  tensorCoeff_(move(coeff.tensorCoeff_))
79 {}
80 
81 
82 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
83 
85 {
86  return scalarCoeff_.eqn();
87 }
88 
89 
91 {
92  return
93  scalarCoeff_.valid()
94  || tensorCoeff_.valid();
95 }
96 
97 
99 {
100  scalarCoeff_.negate();
101  tensorCoeff_.negate();
102 }
103 
104 
107 {
108  return
109  tensorCoeff_.valid()
110  ? tmp<LagrangianCoeff<scalar, true>>
111  (
112  new LagrangianCoeff<scalar, true>
113  (
114  eqn(),
115  (1.0/3.0)*tr(tensorCoeff_.S())
116  )
117  )
118  : tmp<LagrangianCoeff<scalar, true>>(scalarCoeff_);
119 }
120 
121 
124 {
125  const LagrangianEqn<vector>& eqn =
126  static_cast<const LagrangianEqn<vector>&>(this->eqn());
127 
128  return
129  tmp<LagrangianCoeff<vector, false>>
130  (
131  tensorCoeff_.valid()
132  ? new LagrangianCoeff<vector, false>
133  (
134  eqn,
135  dev2(tensorCoeff_.S()) & eqn.psi()
136  )
137  : new LagrangianCoeff<vector, false>(eqn)
138  );
139 }
140 
141 
144 {
145  return Su(static_cast<const LagrangianEqn<vector>&>(this->eqn()));
146 }
147 
148 
150 Foam::LagrangianSp<Foam::vector>::Su(const LagrangianEqn<vector>& eqn) const
151 {
152  return
153  tmp<LagrangianCoeff<vector, false>>
154  (
155  valid()
156  ? new LagrangianCoeff<vector, false>
157  (
158  eqn,
159  tensorCoeff_.valid()
160  ? tensorCoeff_.S() & eqn.psi()
161  : scalarCoeff_.S()*eqn.psi()
162  )
163  : new LagrangianCoeff<vector, false>(eqn)
164  );
165 }
166 
167 
168 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
169 
171 (
172  const LagrangianCoeff<scalar, true>& coeff
173 )
174 {
175  if (!coeff.valid()) return;
176  operator+=(coeff.S());
177 }
178 
179 
181 (
182  const LagrangianCoeff<tensor, true>& coeff
183 )
184 {
185  if (!coeff.valid()) return;
186  operator+=(coeff.S());
187 }
188 
189 
191 (
192  const LagrangianSp<vector>& Sp
193 )
194 {
195  if (Sp.tensorCoeff_.valid())
196  {
197  operator+=(Sp.tensorCoeff_.S());
198  }
199  if (Sp.scalarCoeff_.valid())
200  {
201  operator+=(Sp.scalarCoeff_.S());
202  }
203 }
204 
205 
206 void Foam::LagrangianSp<Foam::vector>::operator+=(const dimensioned<scalar>& dt)
207 {
208  if (tensorCoeff_.valid())
209  {
210  tensorCoeff_ += tensor::I*dt;
211  }
212  else
213  {
214  scalarCoeff_ += dt;
215  }
216 }
217 
218 
219 void Foam::LagrangianSp<Foam::vector>::operator+=(const dimensioned<tensor>& dt)
220 {
221  makeTensor();
222  tensorCoeff_ += dt;
223 }
224 
225 
227 {}
228 
229 
231 (
232  const LagrangianCoeff<scalar, true>& coeff
233 )
234 {
235  if (!coeff.valid()) return;
236  operator-=(coeff.S());
237 }
238 
239 
241 (
242  const LagrangianCoeff<tensor, true>& coeff
243 )
244 {
245  if (!coeff.valid()) return;
246  operator-=(coeff.S());
247 }
248 
249 
251 (
252  const LagrangianSp<vector>& Sp
253 )
254 {
255  if (Sp.tensorCoeff_.valid())
256  {
257  operator-=(Sp.tensorCoeff_.S());
258  }
259  if (Sp.scalarCoeff_.valid())
260  {
261  operator-=(Sp.scalarCoeff_.S());
262  }
263 }
264 
265 
266 void Foam::LagrangianSp<Foam::vector>::operator-=(const dimensioned<scalar>& dt)
267 {
268  if (tensorCoeff_.valid())
269  {
270  tensorCoeff_ -= tensor::I*dt;
271  }
272  else
273  {
274  scalarCoeff_ -= dt;
275  }
276 }
277 
278 
279 void Foam::LagrangianSp<Foam::vector>::operator-=(const dimensioned<tensor>& dt)
280 {
281  makeTensor();
282  tensorCoeff_ -= dt;
283 }
284 
285 
287 {}
288 
289 
290 void Foam::LagrangianSp<Foam::vector>::operator*=(const dimensioned<scalar>& dt)
291 {
292  scalarCoeff_ *= dt;
293  tensorCoeff_ *= dt;
294 }
295 
296 
297 void Foam::LagrangianSp<Foam::vector>::operator/=(const dimensioned<scalar>& dt)
298 {
299  scalarCoeff_ /= dt;
300  tensorCoeff_ /= dt;
301 }
302 
303 
304 // * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
305 
307 (
309  const LagrangianSp<vector>& Sp
310 )
311 {
312  if (Sp.tensorCoeff_.valid())
313  {
314  return inv(Sp.tensorCoeff_.S()) & Su.S();
315  }
316  else
317  {
318  return Su.S()/Sp.scalarCoeff_.S();
319  }
320 }
321 
322 
323 // ************************************************************************* //
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.
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:63
LagrangianSp(const LagrangianSp< Type > &Sp)
Construct as copy.
Definition: LagrangianSp.C:31
void operator-=(const LagrangianSp< Type > &Sp)
Subtraction assignment.
Definition: LagrangianSp.C:105
tmp< LagrangianCoeff< Type, false > > Su() const
Return the equivalent explicit coefficient.
Definition: LagrangianSp.C:75
tmp< LagrangianCoeff< scalar, true > > A() const
Return the scalar diagonal coefficient.
Definition: LagrangianSp.C:55
void operator+=(const LagrangianSp< Type > &Sp)
Addition assignment.
Definition: LagrangianSp.C:98
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(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
static const Identity< scalar > I
Definition: Identity.H:93
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void tr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< tensor > &f1)
void inv(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
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