coupledTemplates.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-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 \*---------------------------------------------------------------------------*/
25 
26 #include "coupled.H"
27 #include "CarrierEqn.H"
28 #include "LagrangianmDdt.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const CloudDerivedField<Type>& psic
36 )
37 {
38  hasCarrierEqns_ = true;
39 
40  const word key = carried::carrierNameToName(psic.name());
41 
42  typename HashPtrTable<CarrierEqn<Type>>::iterator iter =
43  carrierEqns<Type>().find(key);
44 
45  if (iter != carrierEqns<Type>().end()) return **iter;
46 
47  CarrierEqn<Type>* ptr =
48  new CarrierEqn<Type>(key, carriedCloud_.Uc.psi().mesh());
49  carrierEqns<Type>().insert(key, ptr);
50 
51  return *ptr;
52 }
53 
54 
55 template<class Type>
57 (
58  const CarrierField<Type>& psic
59 )
60 {
61  hasCarrierEqns_ = true;
62 
63  typename HashPtrTable<CarrierEqn<Type>>::iterator iter =
64  carrierEqns<Type>().find(psic.psi().name());
65 
66  if (iter != carrierEqns<Type>().end()) return **iter;
67 
68  CarrierEqn<Type>* ptr = new CarrierEqn<Type>(psic.psi());
69  carrierEqns<Type>().insert(psic.psi().name(), ptr);
70 
71  return *ptr;
72 }
73 
74 
75 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
76 
77 template<class Type>
79 (
80  const LagrangianSubScalarSubField& vOrM,
81  const CloudDerivedField<Type>& psic
82 ) const
83 {
84  const LagrangianSubMesh& subMesh = vOrM.mesh();
85 
86  return Lagrangianm::initDdt(vOrM.dimensions(), psic(subMesh));
87 }
88 
89 
90 template<class Type>
92 (
93  const LagrangianSubScalarField& deltaT,
94  const LagrangianSubScalarSubField& vOrM,
96  const CloudDerivedField<Type>& psic
97 ) const
98 {
99  const LagrangianModels& models = cloud_.LagrangianModels();
100  const LagrangianSubMesh& subMesh = deltaT.mesh();
101 
102  return
103  Lagrangianm::noDdt(deltaT, vOrM.dimensions(), psic(subMesh))
104  ==
105  models.sourceProxy(deltaT, vOrM, psi, psic(subMesh));
106 }
107 
108 
109 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
110 
111 template<class Type>
113 {
114  return carrierEqns<Type>().found(key);
115 }
116 
117 
118 template<class Type>
121 {
122  return carrierEqns<Type>()[key];
123 }
124 
125 
126 template<class Type>
128 Foam::clouds::coupled::carrierEqns(const word& key) const
129 {
130  const word member = IOobject::member(key);
131 
133 
135  (
136  typename HashPtrTable<CarrierEqn<Type>>,
137  carrierEqns<Type>(),
138  iter
139  )
140  {
141  if (IOobject::member(iter.key()) == member)
142  {
143  result.set(IOobject::group(iter.key()), iter());
144  }
145  }
146 
147  return result;
148 }
149 
150 
151 template<class Type>
153 {
154  return hasCarrierEqn<Type>(psi.name());
155 }
156 
157 
158 template<class Type>
161 {
162  return carrierEqn<Type>(psi.name());
163 }
164 
165 
166 template<class Type>
168 Foam::clouds::coupled::carrierEqns(const VolField<Type>& psi) const
169 {
170  return carrierEqns<Type>(psi.name());
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Functions for calculating the time derivative for a Lagrangian equation.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Class to store the coefficients of a term in a carrier equation.
Definition: CarrierEqn.H:55
A field interpolated from the carrier to the cloud. Uses CloudDerivedField to provide flexible access...
Definition: CarrierField.H:207
A field derived from other state fields of the cloud. Stores and virtualises a function or a method w...
const word & name() const
Field name.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
const GeoMesh & mesh() const
Return mesh.
Generic GeometricField class.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:68
An STL-conforming hash table.
Definition: HashTable.H:127
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
word group() const
Return group (extension part of name)
Definition: IOobject.C:321
word member() const
Return member (name without the extension)
Definition: IOobject.C:327
List of Lagrangian models, constructed as a (Lagrangian) mesh object. Provides similar functions to t...
tmp< LagrangianEqn< Type > > sourceProxy(const LagrangianSubScalarField &deltaT, const LagrangianSubField< Type, PrimitiveField > &field, const LagrangianSubField< Type, PrimitiveEqnField > &eqnField) const
Return source for an equation.
LagrangianModels(const LagrangianMesh &mesh)
Construct for a mesh.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
static word carrierNameToName(const word &namec)
Convert a disambiguated carrier name to its equivalent name. I.e.,.
Definition: carried.C:307
const CarrierField< vector > & Uc
Carrier velocity.
Definition: carried.H:114
bool hasCarrierEqn(const word &) const
Return if a carrier equation is in the cache.
CarrierEqn< Type > & carrierEqn(const CloudDerivedField< Type > &)
Add/get a carrier equation to/from the cache.
tmp< LagrangianEqn< scalar > > psicEqn(const LagrangianSubScalarField &deltaT, const LagrangianSubScalarSubField &vOrM, const CloudDerivedField< scalar > &oneOrRhoc) const
Return the basic models-only equation for a carrier field.
Definition: coupled.C:130
bool initPsicDdt(const LagrangianSubScalarSubField &vOrM, const CloudDerivedField< Type > &psic) const
Do we need to re-calculate particles that are modified?
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
const volScalarField & psi
bool initDdt(const dimensionSet &mDims, const LagrangianSubSubField< Type > &psi, const bool instantaneousDdt=false)
Initialise time-derivative information. Registers fields used to.
tmp< LagrangianEqn< Type > > noDdt(const LagrangianSubScalarField &deltaT, const dimensionSet &mDims, const LagrangianSubSubField< Type > &psi)
Return the no-time-derivative matrix containing higher-order.