LagrangianModelsTemplates.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 "LagrangianModels.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template
31 <
32  class Type,
33  template<class> class PrimitiveField,
34  class ... AlphaRhoFieldTypes
35 >
36 Foam::tmp<Foam::LagrangianEqn<Type>> Foam::LagrangianModels::sourceTerm
37 (
39  const LagrangianSubScalarField& deltaT,
40  const AlphaRhoFieldTypes& ... alphaRhoFields
41 ) const
42 {
43  checkApplied();
44 
46  (
48  (
49  "S(" + LagrangianModel::fieldsName(alphaRhoFields ...) + ")",
50  eqnField
51  )
52  );
53  LagrangianEqn<Type>& eqn = tEqn.ref();
54 
55  const PtrListDictionary<LagrangianModel>& modelList(*this);
56 
57  const word fieldName = LagrangianModel::fieldName(alphaRhoFields ...);
58 
59  forAll(modelList, i)
60  {
61  const LagrangianModel& model = modelList[i];
62 
63  if (model.addsSupToField(fieldName))
64  {
65  addSupFields_[i].insert(fieldName);
66 
67  model.addSup(deltaT, toSubField(alphaRhoFields)() ..., eqn);
68  }
69  }
70 
71  return tEqn;
72 }
73 
74 
75 template
76 <
77  class ModelType,
78  class FieldSourceType,
79  class ... ModelAndFieldSourceTypes
80 >
81 struct Foam::LagrangianModels::modelTypeFieldSourceType
82 <
83  ModelType,
84  FieldSourceType,
85  ModelAndFieldSourceTypes ...
86 >
87 {
88  static void insert(const LagrangianModel& model, HashTable<word>& result)
89  {
90  if (isA<ModelType>(model))
91  {
92  result.insert(model.name(), FieldSourceType::typeName);
93  }
94  else
95  {
97  (
98  model,
99  result
100  );
101  }
102  }
103 };
104 
105 
106 template<>
107 struct Foam::LagrangianModels::modelTypeFieldSourceType<>
108 {
109  static void insert(const LagrangianModel& model, HashTable<word>& result)
110  {}
111 };
112 
113 
114 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
115 
116 template<class Type, template<class> class PrimitiveField>
118 (
120 ) const
121 {
122  return addsSupToField(LagrangianModel::fieldName(field));
123 }
124 
125 
126 template<class ... ModelAndFieldSourceTypes>
129 {
130  const PtrListDictionary<LagrangianModel>& modelList(*this);
131 
132  HashTable<word> result;
133  forAll(modelList, i)
134  {
136  (
137  modelList[i],
138  result
139  );
140  }
141 
142  return result;
143 }
144 
145 
146 template<class Type, template<class> class PrimitiveField>
148 (
149  const LagrangianSubScalarField& deltaT,
151 ) const
152 {
153  return sourceTerm(field, deltaT, field);
154 }
155 
156 
157 template
158 <
159  class Type,
160  template<class> class PrimitiveField,
161  template<class> class PrimitiveEqnField
162 >
164 (
165  const LagrangianSubScalarField& deltaT,
168 ) const
169 {
170  return sourceTerm(eqnField, deltaT, field);
171 }
172 
173 
174 template<class Type, template<class> class PrimitiveField>
176 (
177  const LagrangianSubScalarField& deltaT,
180 ) const
181 {
182  return sourceTerm(field, deltaT, m, field);
183 }
184 
185 
186 template
187 <
188  class Type,
189  template<class> class PrimitiveField,
190  template<class> class PrimitiveEqnField
191 >
193 (
194  const LagrangianSubScalarField& deltaT,
198 ) const
199 {
200  return sourceTerm(eqnField, deltaT, m, field);
201 }
202 
203 
204 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An STL-conforming hash table.
Definition: HashTable.H:127
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
This class stores the coefficients of a Lagrangian equation, and facilitates solving that equation an...
Definition: LagrangianEqn.H:56
Base class for Lagrangian models.
virtual void addSup(const LagrangianSubScalarField &deltaT, LagrangianSubScalarField &S) const
Add a fractional source term.
virtual bool addsSupToField(const word &) const
Return true if the LagrangianModel adds a source term to the.
static word fieldsName(const AlphaRhoFieldType &alphaRhoField, const AlphaRhoFieldTypes &... alphaRhoFields)
Return the name of the product of the fields associated with a.
static word fieldName(const AlphaRhoFieldType &alphaRhoField, const AlphaRhoFieldTypes &... alphaRhoFields)
Return the name of the field associated with a source term.
const word & name() const
The source name.
tmp< LagrangianSubScalarField > source(const LagrangianSubScalarField &deltaT) const
Return the fractional source.
bool addsSupToField(const word &) const
Return true if the LagrangianModels adds a source term to the.
HashTable< word > modelTypeFieldSourceTypes() const
Return a table of field source types that are chosen to match given.
tmp< LagrangianEqn< Type > > sourceProxy(const LagrangianSubScalarField &deltaT, const LagrangianSubField< Type, PrimitiveField > &field, const LagrangianSubField< Type, PrimitiveEqnField > &eqnField) const
Return source for an equation.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:62
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
tmp< DimensionedField< Type, GeoMesh, SubField > > toSubField(const DimensionedField< Type, GeoMesh, Field > &)
Return a temporary sub-field from a reference to a field.
static void insert(const LagrangianModel &model, HashTable< word > &result)