LagrangianEqn.H
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-2026 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 Class
25  Foam::LagrangianEqn
26 
27 Description
28  This class stores the coefficients of a Lagrangian equation, and
29  facilitates solving that equation and updating the associated field. It is
30  designed to behave and be used similarly to fvMatrix.
31 
32 SourceFiles
33  LagrangianEqn.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef LagrangianEqn_H
38 #define LagrangianEqn_H
39 
40 #include "LagrangianSp.H"
41 #include "LagrangianEqnBase.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class LagrangianEqn Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class Type>
53 class LagrangianEqn
54 :
55  public tmp<LagrangianEqn<Type>>::refCount,
56  public LagrangianEqnBase
57 {
58  // Private Classes
59 
60  //- Helper class to create the psiSub/psiSubSub references
61  template<template<class> class PrimitiveField>
62  struct PsiRef;
63 
64 
65  // Private Data
66 
67  //- The time-step field
69 
70  //- Non-const reference to the sub-sub field. Might be null.
71  LagrangianSubSubField<Type>& psiSubSubRef_;
72 
73  //- Reference to the sub-sub-field. Might be null.
74  const LagrangianSubSubField<Type>& psiSubSub_;
75 
76  //- Reference to the sub-field. Might be null.
77  const LagrangianSubField<Type>& psiSub_;
78 
79  //- Previous implicit time coefficient field into which to cache the
80  // implicit time coefficient on destruction. Might be null.
81  LagrangianDynamicField<scalar>* deltaTSp0Ptr_;
82 
83  //- Previous source field into which to cache the source on
84  // destruction. Might be null.
86 
87 
88  // Private Member Functions
89 
90  //- Check an operation between the given equations is valid
91  template<class TypeB>
92  void preOpCheck
93  (
94  const tmp<LagrangianEqn<Type>>& tA,
95  const tmp<LagrangianEqn<TypeB>>& tB
96  ) const;
97 
98  //- Copy/check the time-step field from/against another equation as
99  // part of an operation
100  template<class OtherType>
101  void opDeltaT(const tmp<LagrangianEqn<OtherType>>& tOther);
102 
103  //- Clear an equation as part of an operation
104  template<class OtherType>
105  static void opClear(LagrangianEqn<OtherType>& other);
106 
107  //- Clear a temporary equation as part of an operation
108  template<class OtherType>
109  static void opClear(const tmp<LagrangianEqn<OtherType>>& tOther);
110 
111  //- Finalise an equation before its consumption by an operation
112  template<class OtherType>
113  static void opFinalise(LagrangianEqn<OtherType>& other);
114 
115  //- Finalise a temporary equation before its consumption by an operation
116  template<class OtherType>
117  static void opFinalise(const tmp<LagrangianEqn<OtherType>>& tOther);
118 
119 
120 public:
121 
122  //- Declare friendship with Lagrangian equations of different types
123  template<class OtherType>
124  friend class LagrangianEqn;
125 
126 
127  // Public Data
128 
129  //- Explicit time-coefficient
131 
132  //- Implicit time-coefficient
134 
135  //- Explicit coefficient
137 
138  //- Implicit coefficient
140 
141 
142  // Constructors
143 
144  //- Construct for a const field and a tmp time-step with a name
145  template<template<class> class PrimitiveField>
147  (
148  const word& name,
149  const tmp<LagrangianSubScalarField>& tDeltaT,
151  LagrangianDynamicField<scalar>& deltaTSp0 =
155  );
156 
157  //- Construct for a const field and a time-step with a name
158  template<template<class> class PrimitiveField>
160  (
161  const word& name,
162  const LagrangianSubScalarField& deltaT,
164  LagrangianDynamicField<scalar>& deltaTSp0 =
168  );
169 
170  //- Construct for a const field with a name
171  template<template<class> class PrimitiveField>
173  (
174  const word& name,
176  LagrangianDynamicField<scalar>& deltaTSp0 =
180  );
181 
182  //- Construct for a const field and a tmp time-step. Name will be null.
183  template<template<class> class PrimitiveField>
185  (
186  const tmp<LagrangianSubScalarField>& tDeltaT,
188  LagrangianDynamicField<scalar>& deltaTSp0 =
192  );
193 
194  //- Construct for a const field and a time-step. Name will be null.
195  template<template<class> class PrimitiveField>
197  (
198  const LagrangianSubScalarField& deltaT,
200  LagrangianDynamicField<scalar>& deltaTSp0 =
204  );
205 
206  //- Construct for a const field. Name will be null.
207  template<template<class> class PrimitiveField>
209  (
211  LagrangianDynamicField<scalar>& deltaTSp0 =
215  );
216 
217  //- Construct for a non-const field and a tmp time-step. Will be named
218  // automatically as the field name plus the suffix "Eqn".
220  (
221  const tmp<LagrangianSubScalarField>& tDeltaT,
223  LagrangianDynamicField<scalar>& deltaTSp0 =
227  );
228 
229  //- Construct for a non-const field and a time-step. Will be named
230  // automatically as the field name plus the suffix "Eqn".
232  (
233  const LagrangianSubScalarField& deltaT,
235  LagrangianDynamicField<scalar>& deltaTSp0 =
239  );
240 
241  //- Construct for a non-const field. Will be named
242  // automatically as the field name plus the suffix "Eqn".
244  (
246  LagrangianDynamicField<scalar>& deltaTSp0 =
250  );
251 
252  //- Construct field-less equation. Essentially just a cache of
253  // coefficients.
255 
256  //- Copy construct
258 
259  //- Construct from tmp
260  LagrangianEqn(const tmp<LagrangianEqn<Type>>& tEqn);
261 
262  //- Move construct
264 
265  //- Construct from a binary operation of two equations
266  template<class EqOp>
268  (
269  const tmp<LagrangianEqn<Type>>& tA,
270  const tmp<LagrangianEqn<Type>>& tB,
271  const EqOp& eqOp
272  );
273 
274  //- Construct from a binary operation of two equations
275  template<class EqOp, class TypeB>
277  (
278  const tmp<LagrangianEqn<Type>>& tA,
279  const tmp<LagrangianEqn<TypeB>>& tB,
280  const EqOp& eqOp
281  );
282 
283 
284  //- Destructor
285  ~LagrangianEqn();
286 
287 
288  // Member Functions
289 
290  //- Construct from another equation, with empty coefficients
292 
293  //- Return the field
295 
296  //- Return the field name
297  const word& psiName() const;
298 
299  //- Return the field group
300  word psiGroup() const;
301 
302  //- Return whether the given field is that of the equation
303  template<template<class> class PrimitiveField>
305 
306  //- Determine whether this matrix has any valid coefficients
307  bool valid() const;
308 
309  //- Return the combined time and non-time explicit coefficient
311 
312  //- Return the combined time and non-time implicit coefficient
313  tmp<LagrangianSp<Type>> allSp() const;
314 
315  //- Return the combined time and non-time explicit diagonal
316  // coefficient; i.e., with the off-diagonal parts of any tensor Sp
317  // coefficients converted into explicit values
319 
320  //- Return the combined time and non-time implicit diagonal
321  // coefficient; i.e., with the off-diagonal parts of any tensor Sp
322  // coefficients removed
324 
325  //- Solve
326  void solve(const bool final);
327 
328 
329  // Member Operators
330 
331  //- Addition assignment
332  template<class OtherType>
333  void operator+=(const LagrangianEqn<OtherType>& other);
334 
335  //- Addition assignment
336  template<class OtherType>
337  void operator+=(const tmp<LagrangianEqn<OtherType>>& tOther);
338 
339  //- Subtraction assignment
340  template<class OtherType>
341  void operator-=(const LagrangianEqn<OtherType>& other);
342 
343  //- Subtraction assignment
344  template<class OtherType>
345  void operator-=(const tmp<LagrangianEqn<OtherType>>& tOther);
346 
347  //- Multiply assignment
348  template<template<class> class PrimitiveField>
350 
351  //- Multiply assignment
352  template<template<class> class PrimitiveField>
354 
355  //- Multiply assignment
356  void operator*=(const dimensioned<scalar>&);
357 
358  //- Multiply assignment
359  void operator*=(const zero&);
360 
361  //- Division assignment
362  template<template<class> class PrimitiveField>
364 
365  //- Division assignment
366  template<template<class> class PrimitiveField>
368 
369  //- Division assignment
370  void operator/=(const dimensioned<scalar>& dt);
371 };
372 
373 
374 //- Negation
375 template<class Type>
377 
378 //- Negation
379 template<class Type>
381 
382 #define LAGRANGIAN_EQN_EQN_OPERATOR(Op) \
383  \
384  template<class Type, class TypeB> \
385  tmp<LagrangianEqn<Type>> operator Op \
386  ( \
387  const LagrangianEqn<Type>& a, \
388  const LagrangianEqn<TypeB>& b \
389  ); \
390  \
391  template<class Type, class TypeB> \
392  tmp<LagrangianEqn<Type>> operator Op \
393  ( \
394  const tmp<LagrangianEqn<Type>>& tA, \
395  const LagrangianEqn<TypeB>& b \
396  ); \
397  \
398  template<class Type, class TypeB> \
399  tmp<LagrangianEqn<Type>> operator Op \
400  ( \
401  const tmp<LagrangianEqn<Type>>& tA, \
402  const tmp<LagrangianEqn<TypeB>>& tB \
403  ); \
404  \
405  template<class Type, class TypeB> \
406  tmp<LagrangianEqn<Type>> operator Op \
407  ( \
408  const LagrangianEqn<Type>& a, \
409  const tmp<LagrangianEqn<TypeB>>& tB \
410  );
411 
412 #define LAGRANGIAN_COMMUTATIVE_EQN_EQN_OPERATOR(Op) \
413  \
414  LAGRANGIAN_EQN_EQN_OPERATOR(Op) \
415  \
416  template<class Type> \
417  tmp<LagrangianEqn<Type>> operator Op \
418  ( \
419  const LagrangianEqn<Type>& a, \
420  const tmp<LagrangianEqn<Type>>& tB \
421  );
422 
423 //- Addition
425 
426 //- Subtraction
428 
429 //- Set-equal-to
431 
432 #undef LAGRANGIAN_EQN_EQN_OPERATOR
433 #undef LAGRANGIAN_COMMUTATIVE_EQN_EQN_OPERATOR
434 
435 #define LAGRANGIAN_EQN_FIELD_OPERATOR(Op, LagrangianSubField) \
436  \
437  template<class Type> \
438  tmp<LagrangianEqn<Type>> operator Op \
439  ( \
440  const LagrangianEqn<Type>& eqn, \
441  const LagrangianSubField<Type>& field \
442  ); \
443  \
444  template<class Type> \
445  tmp<LagrangianEqn<Type>> operator Op \
446  ( \
447  const tmp<LagrangianEqn<Type>>& tEqn, \
448  const LagrangianSubField<Type>& field \
449  ); \
450  \
451  template<class Type> \
452  tmp<LagrangianEqn<Type>> operator Op \
453  ( \
454  const tmp<LagrangianEqn<Type>>& tEqn, \
455  const tmp<LagrangianSubField<Type>>& tField \
456  ); \
457  \
458  template<class Type> \
459  tmp<LagrangianEqn<Type>> operator Op \
460  ( \
461  const LagrangianEqn<Type>& eqn, \
462  const tmp<LagrangianSubField<Type>>& tField \
463  );
464 
465 #define LAGRANGIAN_FIELD_EQN_OPERATOR(Op, LagrangianSubField) \
466  \
467  template<class Type> \
468  tmp<LagrangianEqn<Type>> operator Op \
469  ( \
470  const LagrangianSubField<Type>& field, \
471  const LagrangianEqn<Type>& eqn \
472  ); \
473  \
474  template<class Type> \
475  tmp<LagrangianEqn<Type>> operator Op \
476  ( \
477  const LagrangianSubField<Type>& field, \
478  const tmp<LagrangianEqn<Type>>& tEqn \
479  ); \
480  \
481  template<class Type> \
482  tmp<LagrangianEqn<Type>> operator Op \
483  ( \
484  const tmp<LagrangianSubField<Type>>& tField, \
485  const tmp<LagrangianEqn<Type>>& tEqn \
486  ); \
487  \
488  template<class Type> \
489  tmp<LagrangianEqn<Type>> operator Op \
490  ( \
491  const tmp<LagrangianSubField<Type>>& tField, \
492  const LagrangianEqn<Type>& eqn \
493  );
494 
495 //- Addition
500 
501 //- Subtraction
506 
507 //- Set-equal-to
512 
513 #undef LAGRANGIAN_EQN_FIELD_OPERATOR
514 #undef LAGRANGIAN_FIELD_EQN_OPERATOR
515 
516 #define LAGRANGIAN_EQN_SCALAR_FIELD_OPERATOR(Op, LagrangianSubField) \
517  \
518  template<class Type> \
519  tmp<LagrangianEqn<Type>> operator Op \
520  ( \
521  const LagrangianEqn<Type>& eqn, \
522  const LagrangianSubField<scalar>& field \
523  ); \
524  \
525  template<class Type> \
526  tmp<LagrangianEqn<Type>> operator Op \
527  ( \
528  const tmp<LagrangianEqn<Type>>& tEqn, \
529  const LagrangianSubField<scalar>& field \
530  ); \
531  \
532  template<class Type> \
533  tmp<LagrangianEqn<Type>> operator Op \
534  ( \
535  const tmp<LagrangianEqn<Type>>& tEqn, \
536  const tmp<LagrangianSubField<scalar>>& tField \
537  ); \
538  \
539  template<class Type> \
540  tmp<LagrangianEqn<Type>> operator Op \
541  ( \
542  const LagrangianEqn<Type>& eqn, \
543  const tmp<LagrangianSubField<scalar>>& tField \
544  );
545 
546 #define LAGRANGIAN_SCALAR_FIELD_EQN_OPERATOR(Op, LagrangianSubField) \
547  \
548  template<class Type> \
549  tmp<LagrangianEqn<Type>> operator Op \
550  ( \
551  const LagrangianSubField<scalar>& field, \
552  const LagrangianEqn<Type>& eqn \
553  ); \
554  \
555  template<class Type> \
556  tmp<LagrangianEqn<Type>> operator Op \
557  ( \
558  const LagrangianSubField<scalar>& field, \
559  const tmp<LagrangianEqn<Type>>& tEqn \
560  ); \
561  \
562  template<class Type> \
563  tmp<LagrangianEqn<Type>> operator Op \
564  ( \
565  const tmp<LagrangianSubField<scalar>>& tField, \
566  const tmp<LagrangianEqn<Type>>& tEqn \
567  ); \
568  \
569  template<class Type> \
570  tmp<LagrangianEqn<Type>> operator Op \
571  ( \
572  const tmp<LagrangianSubField<scalar>>& tField, \
573  const LagrangianEqn<Type>& eqn \
574  );
575 
576 //- Multiplication
581 
582 //- Division
585 
586 #undef LAGRANGIAN_EQN_SCALAR_FIELD_OPERATOR
587 #undef LAGRANGIAN_SCALAR_FIELD_EQN_OPERATOR
588 
589 
590 /*---------------------------------------------------------------------------*\
591  Class LagrangianEqn::PsiRef Declaration
592 \*---------------------------------------------------------------------------*/
593 
594 template<class Type>
595 template<template<class> class PrimitiveField>
596 struct Foam::LagrangianEqn<Type>::PsiRef
597 {
598  //- Primitive field types match. Return a valid reference.
599  inline static const LagrangianSubField<Type, PrimitiveField>& ref
600  (
602  )
603  {
604  return psi;
605  };
606 
607  //- Primitive field types do not match. Return a null reference.
608  template<template<class> class OtherPrimitiveField>
609  inline static const LagrangianSubField<Type, PrimitiveField>& ref
610  (
612  )
613  {
614  return NullObjectRef<LagrangianSubField<Type, PrimitiveField>>();
615  };
616 };
617 
618 
619 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
620 
621 } // End namespace Foam
622 
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
624 
625 #ifdef NoRepository
626  #include "LagrangianEqn.C"
627 #endif
628 
629 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
630 
631 #endif
632 
633 // ************************************************************************* //
#define LAGRANGIAN_COMMUTATIVE_EQN_EQN_OPERATOR(Op)
#define LAGRANGIAN_SCALAR_FIELD_EQN_OPERATOR(Op, LagrangianSubField)
#define LAGRANGIAN_EQN_SCALAR_FIELD_OPERATOR(Op, LagrangianSubField)
#define LAGRANGIAN_FIELD_EQN_OPERATOR(Op, LagrangianSubField)
#define LAGRANGIAN_EQN_EQN_OPERATOR(Op)
#define LAGRANGIAN_EQN_FIELD_OPERATOR(Op, LagrangianSubField)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
Non-templated base class for Lagrangian equations.
const LagrangianSubMesh & mesh() const
Return the mesh.
const word & name() const
Return the equation name.
This class stores the coefficients of a Lagrangian equation, and facilitates solving that equation an...
Definition: LagrangianEqn.H:56
LagrangianCoeff< scalar, true > deltaTSp
Implicit time-coefficient.
LagrangianSp< Type > Sp
Implicit coefficient.
LagrangianCoeff< Type, false > Su
Explicit coefficient.
word psiGroup() const
Return the field group.
void solve(const bool final)
Solve.
tmp< LagrangianSp< Type > > allSp() const
Return the combined time and non-time implicit coefficient.
bool valid() const
Determine whether this matrix has any valid coefficients.
bool isPsi(const LagrangianSubField< Type, PrimitiveField > &) const
Return whether the given field is that of the equation.
tmp< LagrangianCoeff< scalar, true > > allDiagonalSp() const
Return the combined time and non-time implicit diagonal.
void operator-=(const LagrangianEqn< OtherType > &other)
Subtraction assignment.
~LagrangianEqn()
Destructor.
friend class LagrangianEqn
Declare friendship with Lagrangian equations of different types.
void operator/=(const LagrangianSubField< scalar, PrimitiveField > &)
Division assignment.
void operator+=(const LagrangianEqn< OtherType > &other)
Addition assignment.
tmp< LagrangianCoeff< Type, false > > allDiagonalSu() const
Return the combined time and non-time explicit diagonal.
tmp< LagrangianSubSubField< Type > > psi() const
Return the field.
void operator*=(const LagrangianSubField< scalar, PrimitiveField > &)
Multiply assignment.
static tmp< LagrangianEqn< Type > > NewEmpty(const LagrangianEqn< Type > &)
Construct from another equation, with empty coefficients.
LagrangianCoeff< Type, false > deltaTSu
Explicit time-coefficient.
const word & psiName() const
Return the field name.
tmp< LagrangianCoeff< Type, false > > allSu() const
Return the combined time and non-time explicit coefficient.
Wrapper around LagrangianCoeff to specialise for the implicit coefficient. Trivial at present....
Definition: LagrangianSp.H:71
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
Definition: ops.H:70
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
trAU ref().rename("rAU")
Namespace for OpenFOAM.
tmp< DimensionedField< Type, GeoMesh, Field > > operator-(const DimensionedField< Type, GeoMesh, PrimitiveField > &df1)
T & NullObjectNonConstRef()
Return non-const reference to the nullObject of type T.
Definition: nullObjectI.H:33
#define EqOp(opName, op)
Definition: ops.H:46