carried.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 "carried.H"
27 #include "fvcCurl.H"
28 #include "fvcDdt.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace clouds
35 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 #define ACCESS_CARRIER_FIELDS(Type, nullArg) \
44 namespace Foam \
45 { \
46  namespace clouds \
47  { \
48  template<> \
49  HashPtrTable<CarrierField<Type>>& carried::carrierFields() const \
50  { \
51  return CAT3(carrier, CAPITALIZE(Type), Fields_); \
52  } \
53  } \
54 }
56 #undef ACCESS_CARRIER_FIELDS
57 
58 
59 Foam::autoPtr<Foam::volVectorField> Foam::clouds::carried::readDUdtc
60 (
61  const cloud& c
62 ) const
63 {
64  typeIOobject<volVectorField> io
65  (
66  "ddt(" + Uc.psi().name() + ")",
67  Uc.psi().mesh().time().name(),
68  Uc.psi().mesh(),
71  );
72 
73  return
74  autoPtr<volVectorField>
75  (
76  io.headerOk()
77  ? new volVectorField(io, Uc.psi().mesh())
78  : nullptr
79  );
80 }
81 
82 
83 const Foam::volVectorField& Foam::clouds::carried::dUdtc() const
84 {
85  if (Uc.psi().hasStoredOldTimes())
86  {
87  dUdtcPtr_.reset(fvc::ddt(Uc.psi()).ptr());
88  }
89  else if (!dUdtcPtr_.valid())
90  {
91  dUdtcPtr_.set
92  (
93  new volVectorField
94  (
95  IOobject
96  (
97  "ddt(" + Uc.psi().name() + ")",
98  Uc.psi().mesh().time().name(),
99  Uc.psi().mesh(),
102  ),
103  Uc.psi().mesh(),
105  )
106  );
107  }
108 
109  return dUdtcPtr_();
110 }
111 
112 
113 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
114 
116 {
117  #define CLEAR_TYPE_CARRIER_FIELDS(Type, nullArg) \
118  forAllIter \
119  ( \
120  HashPtrTable<CarrierField<Type>>, \
121  carrierFields<Type>(), \
122  iter \
123  ) \
124  { \
125  iter()->clear(true); \
126  }
128  #undef CLEAR_TYPE_CARRIER_FIELDS
129 }
130 
131 
133 {
134  #define RESET_TYPE_CARRIER_FIELDS(Type, nullArg) \
135  forAllIter \
136  ( \
137  HashPtrTable<CarrierField<Type>>, \
138  carrierFields<Type>(), \
139  iter \
140  ) \
141  { \
142  iter()->reset(initial); \
143  }
145  #undef RESET_TYPE_CARRIER_FIELDS
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
152 :
153  cloud_(c),
154  carrierPhaseName_
155  (
156  dict.found("phase") || dict.found("carrierPhase")
157  ? dict.lookup<word>("carrierPhase")
158  : word::null
159  ),
160  phaseName_
161  (
162  dict.lookupOrDefault<word>("phase", word::null)
163  ),
164  Uc
165  (
166  carrierField<vector>
167  (
168  c.mesh().poly().lookupObject<volVectorField>
169  (
170  c.mesh().poly().foundObject<volVectorField>
171  (
172  IOobject::groupName("U", carrierPhaseName())
173  )
174  ? IOobject::groupName("U", carrierPhaseName())
175  : c.mesh().poly().foundObject<volVectorField>
176  (
177  "U"
178  )
179  ? "U"
180  : IOobject::groupName("U", carrierPhaseName())
181  )
182  )
183  ),
184  curlUc
185  (
186  carrierField<vector>
187  (
188  IOobject::groupName("curlUc", carrierPhaseName()),
189  [&]()
190  {
191  return fvc::curl(Uc.psi());
192  }
193  )
194  ),
195  dUdtcPtr_(readDUdtc(c)),
196  DUDtc
197  (
198  carrierField<vector>
199  (
200  IOobject::groupName("DUDtc", carrierPhaseName()),
201  [&]()
202  {
203  return dUdtc() + (Uc.psi() & fvc::grad(Uc.psi()));
204  }
205  )
206  ),
207  UcPhase
208  (
209  hasPhase()
210  ? Uc.psi().group() == word::null
211  ? Uc
212  : carrierField<vector>
213  (
214  c.mesh().poly().lookupObject<volVectorField>
215  (
216  IOobject::groupName("U", phaseName())
217  )
218  )
219  : carrierField<vector>
220  (
221  IOobject::groupName("Uc", phaseName(false)),
222  [&]()
223  {
225  << "Cloud " << c.name() << " does not have a corresponding "
226  << "Eulerian phase velocity" << exit(FatalError);
227  return tmp<volVectorField>(nullptr);
228  }
229  )
230  )
231 {}
232 
233 
234 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
235 
237 {}
238 
239 
240 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
241 
243 {
244  return carrierPhaseName_;
245 }
246 
247 
248 const Foam::word& Foam::clouds::carried::phaseName(const bool strict) const
249 {
250  if (hasPhase())
251  {
252  return phaseName_;
253  }
254 
255  if (strict)
256  {
258  << "Cloud " << cloud_.name() << " does not have a corresponding "
259  << "Eulerian phase" << exit(FatalError);
260  }
261 
262  static const word nonePhaseName = "<none>";
263  return nonePhaseName;
264 }
265 
266 
268 {
269  return phaseName_ != word::null;
270 }
271 
272 
274 {
275  return
277  (
278  IOobject::member(name) + 'c',
280  );
281 }
282 
283 
285 (
286  const word& name,
287  const word& group
288 )
289 {
291  {
293  << "Cannot construct an equivalent carrier name with a specified "
294  << "group for the name '" << name << "' because this name already "
295  << "has a group" << exit(FatalError);
296  }
297 
298  return
300  (
301  name + 'c',
302  group
303  );
304 }
305 
306 
308 {
309  const word memberc = IOobject::member(namec);
310 
311  if (memberc[memberc.size() - 1] != 'c')
312  {
314  << "Name " << namec << " is not a carrier name"
315  << exit(FatalError);
316  }
317 
318  return
320  (
321  memberc(memberc.size() - 1),
322  IOobject::group(namec)
323  );
324 }
325 
326 
327 // ************************************************************************* //
bool found
#define RESET_TYPE_CARRIER_FIELDS(Type, nullArg)
#define CLEAR_TYPE_CARRIER_FIELDS(Type, nullArg)
#define ACCESS_CARRIER_FIELDS(Type, nullArg)
Definition: carried.C:43
Generic GeometricField class.
void reset(const GeometricField< Type, GeoMesh, PrimitiveField2 > &)
Reset the field contents to the given field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
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
static word groupName(Name name, const word &group)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Base class for clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:61
Base class for clouds which are carried by a fluid.
Definition: carried.H:57
carried(const cloud &c, const dictionary &dict)
Construct from a reference to the cloud.
Definition: carried.C:151
void clearCarrierFields()
Clear the carrier fields.
Definition: carried.C:115
void resetCarrierFields(const bool initial)
Reset the carrier fields.
Definition: carried.C:132
static word carrierNameToName(const word &namec)
Convert a disambiguated carrier name to its equivalent name. I.e.,.
Definition: carried.C:307
const word & carrierPhaseName() const
Return the name of the carrier phase.
Definition: carried.C:242
bool hasPhase() const
Return whether this cloud has a corresponding Eulerian phase.
Definition: carried.C:267
static word nameToCarrierName(const word &name)
Convert a name to its disambiguated carrier equivalent name. I.e.,.
Definition: carried.C:273
const word & phaseName(const bool strict=true) const
Return the name of the corresponding Eulerian phase.
Definition: carried.C:248
const CarrierField< vector > & Uc
Carrier velocity.
Definition: carried.H:114
virtual ~carried()
Destructor.
Definition: carried.C:236
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return const reference to name.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define FOR_ALL_FIELD_TYPES(Macro,...)
Definition: fieldTypes.H:51
Calculate the curl of the given volField by constructing the Hodge-dual of the symmetric part of the ...
Calculate the first temporal derivative.
defineTypeNameAndDebug(carried, 0)
const char *const group
Group name for atomic constants.
const dimensionedScalar c
Speed of light in a vacuum.
tmp< VolField< Type > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:45
tmp< VolField< Type > > curl(const VolField< Type > &vf)
Definition: fvcCurl.C:45
tmp< VolField< typename outerProduct< vector, Type >::type > > grad(const SurfaceField< Type > &ssf)
Definition: fvcGrad.C:46
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
VolField< vector > volVectorField
Definition: volFieldsFwd.H:63
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
const dimensionSet & dimVelocity
Definition: dimensions.C:154
const dimensionSet & dimTime
Definition: dimensions.C:142
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
dictionary dict