manualInjection.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 "manualInjection.H"
27 #include "LagrangianFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace Lagrangian
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::Lagrangian::manualInjection::readCoeffs(const dictionary& modelDict)
45 {
46  const bool havePositions = modelDict.found("positions");
47  const bool haveFile = modelDict.found("file");
48  const bool haveUnits = modelDict.found("units");
49 
50  if (havePositions == haveFile)
51  {
52  FatalIOErrorInFunction(modelDict)
53  << (haveFile ? "both keywords" : "neither keyword")
54  << " positions " << (haveFile ? "and" : "nor")
55  << " file defined in dictionary " << modelDict.name()
56  << exit(FatalIOError);
57  }
58 
59  if (havePositions && haveUnits)
60  {
61  FatalIOErrorInFunction(modelDict)
62  << "both keywords positions and units defined in dictionary "
63  << modelDict.name() << exit(FatalIOError);
64  }
65 
66  if (havePositions)
67  {
68  positions_ = modelDict.lookup<List<point>>("positions", dimLength);
69  }
70 
71  if (haveFile)
72  {
73  fileName_ = modelDict.lookup<fileName>("file");
74 
75  units_.readIfPresent("units", modelDict);
76  }
77 
78  time_ =
79  modelDict.lookupOrDefault<scalar>
80  (
81  "time",
82  mesh().time().userUnits(),
83  mesh().time().beginTime().value()
84  );
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
91 (
92  const word& name,
93  const LagrangianMesh& mesh,
94  const dictionary& modelDict,
95  const dictionary& stateDict
96 )
97 :
99  positions_(),
100  fileName_(fileName::null),
101  units_(dimLength),
102  time_(NaN)
103 {
104  readCoeffs(modelDict);
105 }
106 
107 
108 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
109 
111 (
113  const LagrangianSubMesh&
114 ) const
115 {
116  const scalar t1 = mesh.time().value();
117  const scalar t0 = t1 - mesh.time().deltaT().value();
118 
119  if (!(t0 <= time_ && time_ < t1)) return mesh.subNone();
120 
121  // Read and unit convert the positions if specified in a file
122  tmp<pointField> tpositions;
123  if (fileName_ == fileName::null)
124  {
125  tpositions = tmp<pointField>(positions_);
126  }
127  else
128  {
129  tpositions =
130  new pointField
131  (
133  (
134  IOobject
135  (
136  fileName_,
137  mesh.time().constant(),
138  mesh,
141  )
142  )
143  );
144 
145  units_.makeStandard(tpositions.ref());
146  }
147  const pointField& positions = tpositions();
148 
149  const label number = positions.size();
150 
151  scalarField fraction(number, (time_ - t0)/(t1 - t0));
152 
153  // Locate within the mesh
155  labelField celli(number, -1), facei(number), faceTrii(number);
156  const List<LagrangianMesh::location> locations =
157  mesh.locate
158  (
159  positions,
160  coordinates,
161  celli,
162  facei,
163  faceTrii,
164  fraction
165  );
166 
167  // Check for any failures
168  checkLocation(locations, positions);
169 
170  // Remove particles not on this process
171  filter(coordinates, celli, facei, faceTrii, fraction);
172 
173  // Inject particles
174  return
175  mesh.inject
176  (
177  *this,
178  coordinates,
179  celli,
180  facei,
181  faceTrii,
183  fraction
184  );
185 }
186 
187 
189 {
190  if (LagrangianInjection::read(modelDict))
191  {
192  readCoeffs(modelDict);
193  return true;
194  }
195  else
196  {
197  return false;
198  }
199 }
200 
201 
202 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
A primitive field of type <Type> with automated input and output.
Definition: GlobalIOField.H:50
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Base class for Lagrangian injections. Minimal wrapper over LagrangianSource. Implements some utility ...
Class containing Lagrangian geometry and topology.
const Time & time() const
Return time.
static const word fractionName
Name of the tracked fraction field.
Base class for Lagrangian models.
virtual bool read(const dictionary &modelDict)
Read dictionary.
const LagrangianMesh & mesh() const
The mesh.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
Manual injection model. This injects particles instantaneously at a list of positions specified in a ...
LagrangianSubMesh modify(LagrangianMesh &mesh, const LagrangianSubMesh &) const
Create new elements in the Lagrangian mesh.
virtual bool read(const dictionary &modelDict)
Read dictionary.
manualInjection(const word &name, const LagrangianMesh &mesh, const dictionary &modelDict, const dictionary &stateDict)
Construct from components.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
static const word & constant()
Return constant name.
Definition: TimePaths.H:122
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:46
virtual dimensionedScalar beginTime() const
Return begin time (initial start time)
Definition: Time.C:799
const unitSet & userUnits() const
Return the user-time unit conversion.
Definition: Time.C:877
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Type & value() const
Return const reference to value.
A class for handling file names.
Definition: fileName.H:82
static const fileName null
An empty fileName.
Definition: fileName.H:97
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
Motion of the mesh specified as a list of pointMeshMovers.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
bool readIfPresent(const word &keyword, const dictionary &)
Update if found in the dictionary.
Definition: unitSetIO.C:106
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
defineTypeNameAndDebug(collisionPhaseTransfer, 0)
addToRunTimeSelectionTable(LagrangianModel, collisionPhaseTransfer, dictionary)
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1258
const unitSet fraction
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const dimensionSet & dimLength
Definition: dimensions.C:141
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.