LagrangianFieldSource.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 "LagrangianFieldSource.H"
27 #include "LagrangianMesh.H"
28 #include "LagrangianSubMesh.H"
29 #include "LagrangianSource.H"
30 #include "LagrangianInjection.H"
31 #include "dictionary.H"
32 #include "dlLibraryTable.H"
33 #include "regIOobject.H"
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 template<class Type>
39 (
40  const regIOobject& iIo
41 )
42 :
44  libs_(fileNameList::null()),
45  internalField_
46  (
48  ),
49  internalNonDynamicField_
50  (
51  refCastNull<const LagrangianInternalField<Type>>(iIo)
52  )
53 {}
54 
55 
56 template<class Type>
58 (
59  const regIOobject& iIo,
60  const dictionary& dict
61 )
62 :
64  libs_(dict.lookupOrDefault("libs", fileNameList::null())),
65  internalField_
66  (
68  ),
69  internalNonDynamicField_
70  (
71  refCastNull<const LagrangianInternalField<Type>>(iIo)
72  )
73 {}
74 
75 
76 template<class Type>
78 (
79  const LagrangianFieldSource<Type>& field,
80  const regIOobject& iIo
81 )
82 :
84  libs_(field.libs_),
85  internalField_
86  (
88  ),
89  internalNonDynamicField_
90  (
91  refCastNull<const LagrangianInternalField<Type>>(iIo)
92  )
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
97 
98 template<class Type>
101 (
102  const word& fieldSourceType,
103  const regIOobject& iIo
104 )
105 {
106  typename nullConstructorTable::iterator cstrIter =
107  nullConstructorTablePtr_->find(fieldSourceType);
108 
109  if (cstrIter == nullConstructorTablePtr_->end())
110  {
112  << "Unknown null-constructable fieldSource type " << fieldSourceType
113  << nl << nl << "Valid fieldSource types are :" << endl
114  << nullConstructorTablePtr_->sortedToc()
115  << exit(FatalError);
116  }
117 
118  return cstrIter()(iIo);
119 }
120 
121 
122 template<class Type>
125 (
126  const regIOobject& iIo,
127  const dictionary& dict
128 )
129 {
130  const word fieldSourceType(dict.lookup("type"));
131 
132  libs.open(dict, "libs", dictionaryConstructorTablePtr_);
133 
134  typename dictionaryConstructorTable::iterator cstrIter =
135  dictionaryConstructorTablePtr_->find(fieldSourceType);
136 
137  if (cstrIter == dictionaryConstructorTablePtr_->end())
138  {
139  if (!disallowGenericLagrangianFieldSource)
140  {
141  cstrIter = dictionaryConstructorTablePtr_->find("generic");
142  }
143 
144  if (cstrIter == dictionaryConstructorTablePtr_->end())
145  {
147  << "Unknown fieldSource type " << fieldSourceType
148  << " for model " << dict.dictName() << nl << nl
149  << "Valid fieldSource types are :" << endl
150  << dictionaryConstructorTablePtr_->sortedToc()
151  << exit(FatalIOError);
152  }
153  }
154 
155  return cstrIter()(iIo, dict);
156 }
157 
158 
159 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
160 
161 template<class Type>
163 {}
164 
165 
166 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
167 
168 template<class Type>
169 const Foam::dimensionSet&
171 {
172  if (notNull(internalField_))
173  {
174  return internalField_.dimensions();
175  }
176 
177  if (notNull(internalNonDynamicField_))
178  {
179  return internalNonDynamicField_.dimensions();
180  }
181 
183  << "Dimensions of internal object " << internalIo_.name()
184  << " could not be determined"
185  << exit(FatalError);
186 
187  return NullObjectRef<dimensionSet>();
188 }
189 
190 
191 template<class Type>
194 {
195  if (notNull(internalField_))
196  {
197  return internalField_;
198  }
199 
201  << "Internal field " << internalIo_.name() << " is not of type "
203  << exit(FatalError);
204 
205  return NullObjectRef<LagrangianInternalDynamicField<Type>>();
206 }
207 
208 
209 template<class Type>
212 (
213  const LagrangianSource& source,
214  const LagrangianSubMesh& subMesh
215 ) const
216 {
218  << "The " << type() << " condition for source " << source.name()
219  << " of field " << this->internalName()
220  << " does not define a value for a continuous source "
221  << exit(FatalError);
222 
223  return tmp<LagrangianSubField<Type>>(nullptr);
224 }
225 
226 
227 template<class Type>
230 (
231  const LagrangianSource& source,
232  const LagrangianSubMesh& subMesh
233 ) const
234 {
236  << "The " << type() << " condition for source " << source.name()
237  << " of field " << this->internalName()
238  << " does not define a value for a continuous source "
239  << exit(FatalError);
240 
241  return tmp<LagrangianSubScalarField>(nullptr);
242 }
243 
244 
245 template<class Type>
248 (
249  const LagrangianSource& source,
250  const LagrangianSubMesh& subMesh
251 ) const
252 {
253  return (1 - internalCoeff(source, subMesh))*sourceValue(source, subMesh);
254 }
255 
256 
257 template<class Type>
260 (
261  const LagrangianSource& source,
262  const LagrangianSubMesh& subMesh
263 ) const
264 {
265  return
266  sourceCoeff(source, subMesh)
267  + internalCoeff(source, subMesh)*subMesh.sub(internalField());
268 }
269 
270 
271 template<class Type>
274 (
275  const LagrangianInjection& injection,
276  const LagrangianSubMesh& subMesh
277 ) const
278 {
280  << "The " << type() << " condition for injection " << injection.name()
281  << " of field " << this->internalName()
282  << " does not define a value for an instantaneous injection"
283  << exit(FatalError);
284 
285  return tmp<LagrangianSubField<Type>>(nullptr);
286 }
287 
288 
289 template<class Type>
292 (
293  const LagrangianSubMesh& subMesh
294 ) const
295 {
297  << "The " << type() << " condition for field "
298  << this->internalName() << " does not define a value without a model"
299  << exit(FatalError);
300 
301  return tmp<LagrangianSubField<Type>>(nullptr);
302 }
303 
304 
305 template<class Type>
307 {
308  writeEntry(os, "type", type());
309 }
310 
311 
312 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
313 
314 template<class Type>
315 Foam::Ostream& Foam::operator<<
316 (
317  Ostream& os,
318  const LagrangianFieldSource<Type>& ptf
319 )
320 {
321  ptf.write(os);
322 
323  os.check
324  (
325  "Ostream& operator<<(Ostream&, const LagrangianFieldSource<Type>&)"
326  );
327 
328  return os;
329 }
330 
331 
332 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:108
Base class for Lagrangian source conditions.
Base class for Lagrangian source conditions.
virtual const dimensionSet & internalDimensions() const
Return internal dimensions reference.
virtual void write(Ostream &) const
Write.
static autoPtr< LagrangianFieldSource< Type > > New(const word &fieldSourceType, const regIOobject &)
Return a pointer to a new field source.
tmp< LagrangianSubField< Type > > value(const LagrangianSource &, const LagrangianSubMesh &) const
Return the value for a continuous source.
tmp< LagrangianSubField< Type > > sourceCoeff(const LagrangianSource &, const LagrangianSubMesh &) const
Return the source coefficient.
virtual tmp< LagrangianSubField< Type > > sourceValue(const LagrangianSource &, const LagrangianSubMesh &) const
Return the source value.
virtual ~LagrangianFieldSource()
Destructor.
virtual tmp< LagrangianSubScalarField > internalCoeff(const LagrangianSource &, const LagrangianSubMesh &) const
Return the internal coefficient.
LagrangianFieldSource(const regIOobject &)
Construct from internal field.
const LagrangianInternalDynamicField< Type > & internalField() const
Return internal field reference.
Base class for Lagrangian injections. Minimal wrapper over LagrangianSource. Implements some utility ...
const word & name() const
The source name.
Base class for Lagrangian sources. Minimal wrapper over LagrangianModel that provides an interface to...
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
word sub(const word &fieldName) const
Return the name of a field corresponding to this sub-mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:123
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
Dimension set for the base types.
Definition: dimensionSet.H:125
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
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
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
To & refCastNull(From &r)
Reference type cast template function,.
Definition: typeInfo.H:162
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
IOerror FatalIOError
error FatalError
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict