coneDirectionLagrangianVectorFieldSource.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 #include "mathematicalConstants.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
35 (
36  const LagrangianFieldSourceBase& field,
37  const dictionary& dict
38 )
39 :
40  field_(field),
41  thetaInner_
42  (
43  Function1<scalar>::New
44  (
45  "thetaInner",
46  field.time().userUnits(),
47  units::degrees,
48  dict
49  )
50  ),
51  thetaOuter_
52  (
53  Function1<scalar>::New
54  (
55  "thetaOuter",
56  field.time().userUnits(),
57  units::degrees,
58  dict
59  )
60  ),
61  rndGen_
62  (
63  "coneDirectionRndGen",
64  dict,
65  randomGenerator::seed(field.db().name() + ':' + dict.dictName()),
66  false
67  ),
68  timeIndex_(-1)
69 {}
70 
71 
74 (
76  const LagrangianFieldSourceBase& field
77 )
78 :
79  field_(field),
80  thetaInner_(cdlvfs.thetaInner_, false),
81  thetaOuter_(cdlvfs.thetaOuter_, false),
82  rndGen_(cdlvfs.rndGen_),
83  timeIndex_(-1)
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
91 {}
92 
93 
94 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
95 
98 (
99  const LagrangianSubVectorField& axis
100 ) const
101 {
102  const LagrangianSubMesh& subMesh = axis.mesh();
103 
104  // Restart the generator if necessary and set the time index up to date
105  rndGen_.start(timeIndex_ == field_.time().timeIndex());
106  timeIndex_ = field_.time().timeIndex();
107 
108  // Construct a random direction perpendicular to the cone axis
110  const tmp<LagrangianSubVectorField> tt2Dir(axis ^ tt1Dir());
111  const tmp<LagrangianSubScalarField> tphi =
113  (
114  "phi",
115  subMesh,
116  dimless,
117  constant::mathematical::twoPi*rndGen_.scalar01(subMesh.size())
118  );
119  const LagrangianSubVectorField tDir
120  (
121  tt1Dir*cos(tphi()) + tt2Dir*sin(tphi())
122  );
123  tphi.clear();
124 
125  // Pick a random angle within the cone angles
126  const tmp<LagrangianSubScalarField> tthetaInner =
127  Function1LagrangianFieldSource::value(subMesh, dimless, thetaInner_());
128  const tmp<LagrangianSubScalarField> tthetaOuter =
129  Function1LagrangianFieldSource::value(subMesh, dimless, thetaOuter_());
130  const tmp<LagrangianSubScalarField> tfrac =
132  (
133  "frac",
134  subMesh,
135  dimless,
136  rndGen_.scalar01(subMesh.size())
137  );
138  const LagrangianSubScalarField theta
139  (
140  sqrt
141  (
142  (1 - tfrac())*sqr(tthetaInner)
143  + tfrac()*sqr(tthetaOuter)
144  )
145  );
146  tfrac.clear();
147 
148  // Return the direction
149  return cos(theta)*axis + sin(theta)*tDir;
150 }
151 
152 
154 {
155  writeEntry
156  (
157  os,
158  field_.time().userUnits(),
160  thetaInner_()
161  );
162 
163  writeEntry
164  (
165  os,
166  field_.time().userUnits(),
168  thetaOuter_()
169  );
170 
171  writeEntry(os, "coneDirectionRndGen", rndGen_);
172 }
173 
174 
175 // ************************************************************************* //
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...
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const GeoMesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
const GeoMesh & mesh() const
Return mesh.
tmp< LagrangianSubField< Type > > value(const LagrangianSubMesh &subMesh, const Function1< Type > &function) const
Return the source value.
Run-time selectable general function of one variable.
Definition: Function1.H:62
Base class for Lagrangian source conditions.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
label size() const
Return size.
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 provides a random injection direction between two cone angles.
coneDirectionLagrangianVectorFieldSource(const LagrangianFieldSourceBase &, const dictionary &dict)
Construct from a dictionary.
tmp< LagrangianSubVectorField > direction(const LagrangianSubVectorField &axis) const
Return the value for an instantaneous injection.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Random number generator.
A class for managing temporary objects.
Definition: tmp.H:55
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:253
const scalar twoPi(2 *pi)
const dimensionSet time
const unitSet degrees
const dimensionSet & dimless
Definition: dimensions.C:138
dimensionedScalar sin(const dimensionedScalar &ds)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:509
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:515
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
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)
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict