totalPressureVelocityMagnitudeLagrangianScalarFieldSource.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 
30 #include "LagrangianFieldSource.H"
31 #include "massive.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
38 (
39  const LagrangianFieldSourceBase& field,
40  const cloudLagrangianFieldSource& cloudField,
41  const dictionary& dict
42 )
43 :
44  field_(field),
45  cloudField_(cloudField),
46  p0Entry_(dict.lookupEntry("p0", false, true).clone()),
47  p0_(nullptr),
48  rhocName_
49  (
50  dict.lookupOrDefault<word>
51  (
52  clouds::carried::nameToCarrierName("rho"),
53  "rho"
54  )
55  ),
56  pcName_
57  (
58  dict.lookupOrDefault<word>
59  (
60  clouds::carried::nameToCarrierName("p"),
61  "p"
62  )
63  )
64 {}
65 
66 
69 (
71  const LagrangianFieldSourceBase& field,
72  const cloudLagrangianFieldSource& cloudField
73 )
74 :
75  field_(field),
76  cloudField_(cloudField),
77  p0Entry_(tpvmlsfs.p0Entry_, false),
78  p0_(tpvmlsfs.p0_, false),
79  rhocName_(tpvmlsfs.rhocName_),
80  pcName_(tpvmlsfs.pcName_)
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
85 
88 {}
89 
90 
91 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
92 
95 (
96  const LagrangianInjection& injection,
97  const LagrangianSubMesh& subMesh
98 ) const
99 {
100  // Get the carrier pressure
101  const volScalarField& pcVf =
102  subMesh.mesh().poly().lookupObject<volScalarField>(pcName_);
103  const CarrierField<scalar>& pc =
104  cloudField_.cloud<clouds::carried>(injection).carrierField(pcVf);
105 
106  // Construct the total pressure function now we know the dimensions
107  if (p0Entry_.valid())
108  {
109  p0_ =
111  (
112  field_.time().userUnits(),
113  pcVf.dimensions(),
114  p0Entry_()
115  ).ptr();
116 
117  p0Entry_.clear();
118  }
119 
120  // Evaluate the pressure drop
121  const LagrangianSubScalarField deltaP
122  (
123  max
124  (
126  (
127  subMesh,
128  pcVf.dimensions(),
129  p0_()
130  ) - pc(subMesh),
131  dimensionedScalar(pcVf.dimensions(), scalar(0))
132  )
133  );
134 
135  // Return the direction multiplied by the velocity magnitude associated
136  // with the dynamic head
137  if (pcVf.dimensions() == dimKinematicPressure)
138  {
139  const clouds::coupledToConstantDensityFluid& ctcdfCloud =
140  cloudField_.cloud<clouds::coupledToConstantDensityFluid>
141  (
142  injection
143  );
144 
145  return sqrt(2*deltaP/ctcdfCloud.rhoByRhoc);
146  }
147  else if (pcVf.dimensions() == dimPressure)
148  {
149  cloudField_.assertCloud
150  <
153  >(injection);
154 
155  if (cloudField_.isCloud<clouds::coupledToConstantDensityFluid>())
156  {
157  const clouds::coupledToConstantDensityFluid& ctcdfCloud =
158  cloudField_.cloud<clouds::coupledToConstantDensityFluid>
159  (
160  injection
161  );
162 
163  // Get the carrier density
164  const volScalarField& rhocVf =
165  subMesh.mesh().poly().lookupObject<volScalarField>(rhocName_);
166  const CarrierField<scalar>& rhoc =
167  cloudField_
168  .cloud<clouds::carried>(injection)
169  .carrierField(rhocVf);
170 
171  return sqrt(2*deltaP/(ctcdfCloud.rhoByRhoc*rhoc(subMesh)));
172  }
173  else // if (isCloud<clouds::massive>())
174  {
175  const clouds::massive& mCloud =
176  cloudField_.cloud<clouds::massive>(injection);
177 
178  return sqrt(2*deltaP/mCloud.rho(subMesh));
179  }
180  }
181  else
182  {
184  << "Dimensions of field " << pcVf.name()
185  << " not recognised as pressure"
186  << exit(FatalError);
187 
188  return tmp<LagrangianSubScalarField>(nullptr);
189  }
190 }
191 
192 
194 (
195  Ostream& os
196 ) const
197 {
198  if (p0Entry_.valid())
199  {
200  p0Entry_->write(os);
201  }
202  else
203  {
204  writeEntry(os, field_.time().userUnits(), units::any, p0_());
205  }
206 
207  writeEntryIfDifferent<word>
208  (
209  os,
211  "rho",
212  rhocName_
213  );
214 
215  writeEntryIfDifferent<word>
216  (
217  os,
219  "p",
220  pcName_
221  );
222 }
223 
224 
225 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
tmp< LagrangianSubField< Type > > value(const LagrangianSubMesh &subMesh, const Function1< Type > &function) const
Return the source value.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Generic GeometricField class.
const word & name() const
Return name.
Definition: IOobject.H:307
Base class for Lagrangian source conditions.
Base class for Lagrangian injections. Minimal wrapper over LagrangianSource. Implements some utility ...
const polyMesh & poly() const
Access the poly mesh.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
const LagrangianMesh & mesh() const
Return the mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Mix-in for source conditions that refer to a cloud.
Base class for clouds which are carried by a fluid.
Definition: carried.H:57
static word nameToCarrierName(const word &name)
Convert a name to its disambiguated carrier equivalent name. I.e.,.
Definition: carried.C:273
Base class for clouds which are coupled to a constant density fluid.
const dimensionedScalar rhoByRhoc
Cloud/carrier density ratio.
Base class for clouds with particles with mass.
Definition: massive.H:51
CloudStateFieldRef< scalar > rho
Density.
Definition: massive.H:75
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
A class for managing temporary objects.
Definition: tmp.H:55
Mix-in for source conditions that compute the velocity magnitude from the difference between a specif...
tmp< LagrangianSubScalarField > Umag(const LagrangianInjection &, const LagrangianSubMesh &) const
Return the value for an instantaneous injection.
totalPressureVelocityMagnitudeLagrangianScalarFieldSource(const LagrangianFieldSourceBase &, const cloudLagrangianFieldSource &, const dictionary &dict)
Construct from a dictionary.
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const unitSet any
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
T clone(const T &t)
Definition: List.H:55
const dimensionSet & dimPressure
Definition: dimensions.C:163
error FatalError
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet & dimKinematicPressure
Definition: dimensions.C:164
dictionary dict