flowRateNumberLagrangianScalarFieldSource.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 
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
33 (
34  const regIOobject& iIo,
35  const dictionary& dict
36 )
37 :
39  volumetricFlowRate_
40  (
41  dict.found("volumetricFlowRate")
42  ? Function1<scalar>::New
43  (
44  "volumetricFlowRate",
45  time().userUnits(),
47  dict
48  ).ptr()
49  : nullptr
50  ),
51  massFlowRate_
52  (
53  dict.found("massFlowRate")
54  ? Function1<scalar>::New
55  (
56  "massFlowRate",
57  time().userUnits(),
59  dict
60  ).ptr()
61  : nullptr
62  )
63 {
64  if (volumetricFlowRate_.valid() == massFlowRate_.valid())
65  {
67  << "keywords volumetricFlowRate and massFlowRate both "
68  << (volumetricFlowRate_.valid() ? "" : "un") << "defined in "
69  << "dictionary " << dict.name()
70  << exit(FatalIOError);
71  }
72 }
73 
74 
77 (
79  const regIOobject& iIo
80 )
81 :
83  volumetricFlowRate_(field.volumetricFlowRate_, false),
84  massFlowRate_(field.massFlowRate_, false)
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
92 {}
93 
94 
95 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
96 
98 (
99  const LagrangianInjection& injection,
100  const LagrangianSubMesh& subMesh
101 ) const
102 {
103  // Get the range of the time-step
104  const scalar t1 = time().value();
105  const scalar t0 = t1 - time().deltaTValue();
106 
107  if (volumetricFlowRate_.valid())
108  {
109  // Evaluate the volumetric flow rate directly
110  return
112  (
114  volumetricFlowRate_->integral(t0, t1)
115  );
116  }
117  else
118  {
119  // Calculate the necessary sizes
121  calcSizes
122  (
123  injection, subMesh,
124  size,
125  true, v,
126  true, m
127  );
128 
129  // Convert the mass flow rate to a volumetric flow rate
130  return
132  (
133  dimMassFlux,
134  massFlowRate_->integral(t0, t1)
135  )*sum(v/size())/sum(m/size());
136  }
137 }
138 
139 
142 (
143  const LagrangianInjection& injection,
144  const LagrangianSubMesh& subMesh
145 ) const
146 {
147  // Get the range of the time-step
148  const scalar t1 = time().value();
149  const scalar t0 = t1 - time().deltaTValue();
150 
151  // Calculate the necessary sizes
153  calcSizes
154  (
155  injection, subMesh,
156  size,
157  volumetricFlowRate_.valid(), v,
158  massFlowRate_.valid(), m
159  );
160 
161  // Return the numbers that equalise the sizes on all parcels and recover
162  // the specified flow rate
163  if (volumetricFlowRate_.valid())
164  {
165  const dimensionedScalar V
166  (
167  dimVolume,
168  volumetricFlowRate_->integral(t0, t1)
169  );
170 
171  return V/size()/sum(v()/size());
172  }
173  else
174  {
175  const dimensionedScalar M
176  (
177  dimMass,
178  massFlowRate_->integral(t0, t1)
179  );
180 
181  return M/size()/sum(m()/size());
182  }
183 }
184 
185 
187 {
189 
190  if (volumetricFlowRate_.valid())
191  {
192  writeEntry(os, volumetricFlowRate_());
193  }
194  else
195  {
196  writeEntry(os, massFlowRate_());
197  }
198 }
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 namespace Foam
204 {
206  (
207  LagrangianScalarFieldSource,
209  );
210 }
211 
212 // ************************************************************************* //
#define M(I)
bool found
Macros for easy insertion into run-time selection tables.
Run-time selectable general function of one variable.
Definition: Function1.H:62
Base class for Lagrangian injections. Minimal wrapper over LagrangianSource. Implements some utility ...
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
This source condition sets the values of the number field to recover a specified volumetric or mass f...
virtual tmp< LagrangianSubScalarField > value(const LagrangianInjection &, const LagrangianSubMesh &) const
Return the value for an instantaneous injection.
dimensionedScalar Q(const LagrangianInjection &, const LagrangianSubMesh &) const
Return the volumetric flow rate for this time-step.
flowRateNumberLagrangianScalarFieldSource(const regIOobject &, const dictionary &dict)
Construct from internal field and dictionary.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
bool valid() const
Is this temporary object valid,.
Definition: tmpI.H:183
Base class for Lagrangian source conditions that calculate the number field from a total (e....
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
const dimensionSet time
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet & dimMass
Definition: dimensions.C:140
const dimensionSet & dimMassFlux
Definition: dimensions.C:179
const dimensionSet & dimVolume
Definition: dimensions.C:150
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
IOerror FatalIOError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
makeLagrangianTypeFieldSource(LagrangianVectorFieldSource, coneDiskVelocityLagrangianVectorFieldSource)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet & dimVolumetricFlux
Definition: dimensions.C:178
dictionary dict