coupledToFluid.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 "coupledToFluid.H"
27 #include "fluidThermo.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace clouds
34 {
36 }
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 Foam::clouds::coupledToFluid::getRhocVf(const word& phaseName) const
44 {
45  const word rhocName = IOobject::groupName("rho", phaseName);
46 
47  if (mesh_.poly().foundObject<volScalarField>(rhocName))
48  {
49  return mesh_.poly().lookupObject<volScalarField>(rhocName);
50  }
51 
52  const word thermocName =
54 
55  if (mesh_.poly().foundObject<basicThermo>(thermocName))
56  {
57  return mesh_.poly().lookupObject<basicThermo>(thermocName).rho();
58  }
59 
61  << "Could not determine the carrier density"
62  << exit(FatalError);
63 
64  return tmp<volScalarField>(nullptr);
65 }
66 
67 
69 Foam::clouds::coupledToFluid::getMucVf(const word& phaseName) const
70 {
71  const word mucName = IOobject::groupName("mu", phaseName);
72 
73  if (mesh_.poly().foundObject<volScalarField>(mucName))
74  {
75  return mesh_.poly().lookupObject<volScalarField>(mucName);
76  }
77 
78  const word thermocName =
80 
81  if (mesh_.poly().foundObject<fluidThermo>(thermocName))
82  {
83  return mesh_.poly().lookupObject<fluidThermo>(thermocName).mu();
84  }
85 
86  return NullObjectRef<volScalarField>();
87 }
88 
89 
91 Foam::clouds::coupledToFluid::calcNuc
92 (
93  const LagrangianModelRef& model,
94  const LagrangianSubMesh& subMesh
95 ) const
96 {
97  return muc(model, subMesh)/rhoc(model, subMesh);
98 }
99 
100 
101 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
102 
104 {
106 
107  if (trhocVf_.isTmp())
108  {
109  trhocVf_.ref() = getRhocVf(carriedCloud_.carrierPhaseName());
110  }
111 
112  if (trhocPhaseVf_.isTmp())
113  {
114  trhocPhaseVf_.ref() = getRhocVf(carriedCloud_.phaseName());
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
120 
122 (
123  const cloud& c,
124  const carried& carriedCloud
125 )
126 :
127  coupled(c, carriedCloud),
128  mesh_(c.mesh()),
129  carriedCloud_(carriedCloud),
130  trhocVf_(getRhocVf(carriedCloud.carrierPhaseName())),
131  trhocPhaseVf_
132  (
133  carriedCloud.hasPhase()
134  ? getRhocVf(carriedCloud.phaseName())
136  ),
137  mucVf_(getMucVf(carriedCloud.carrierPhaseName())),
138  rhoc(carriedCloud.carrierField<scalar>(trhocVf_())),
139  rhocPhase
140  (
141  carriedCloud.hasPhase()
142  ? carriedCloud.carrierField<scalar>(trhocPhaseVf_())
143  : carriedCloud.noCarrierField<scalar>("rho", "density", true)
144  ),
145  muc
146  (
147  isNull(mucVf_)
148  ? c.derivedField<scalar>
149  (
150  [&]
151  (
152  const LagrangianModelRef& model,
153  const LagrangianSubMesh& subMesh
154  )
155  {
156  return rhoc(model, subMesh)*nuc(model, subMesh);
157  }
158  )
159  : carriedCloud.carrierField<scalar>(mucVf_)
160  )
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 
167 {}
168 
169 
170 // ************************************************************************* //
Generic GeometricField class.
static word groupName(Name name, const word &group)
const polyMesh & poly() const
Access the poly mesh.
Simple wrapper to provide an optional reference to a Lagrangian model.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
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
Base class for clouds which are coupled to a variable density fluid.
const CarrierField< scalar > & rhoc
Carrier density.
virtual ~coupledToFluid()
Destructor.
coupledToFluid(const cloud &c, const carried &)
Construct from a reference to the cloud.
void updateCarrier()
Update the cached carrier fields.
Base class for clouds which are coupled to a carrier.
Definition: coupled.H:55
const CloudDerivedField< scalar > & nuc
Carrier kinematic viscosity.
Definition: coupled.H:156
void updateCarrier()
Update the cached carrier fields.
Definition: coupled.C:101
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
bool foundObject(const word &name) const
Is the named Type in registry.
A class for managing temporary objects.
Definition: tmp.H:55
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
rho
Definition: pEqn.H:1
defineTypeNameAndDebug(carried, 0)
const dimensionedScalar mu
Atomic mass unit.
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
const T & NullObjectRef()
Return const reference to the nullObject of type T.
Definition: nullObjectI.H:27
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:58
error FatalError