LagrangianFieldSourceBaseTemplates.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 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 
27 #include "LagrangianModel.H"
28 
29 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
30 
31 template<class OtherFieldSourceType>
32 const OtherFieldSourceType&
34 (
35  const LagrangianModel& model
36 ) const
37 {
38  if (!isA<OtherFieldSourceType>(*this))
39  {
41  << "The '" << type() << "' source of field '"
42  << (db().dbDir()/internalIo_.name()).c_str()
43  << "' for the '" << model.type() << "' Lagrangian model '"
44  << model.name() << "' requires the corresponding source of field '"
45  << (db().dbDir()/internalName()).c_str()
46  << "' to be of type '" << OtherFieldSourceType::typeName
47  << "' (or a derivation thereof), rather than '" << type()
48  << "'" << exit(FatalError);
49  }
50 
51  return refCast<const OtherFieldSourceType>(*this);
52 }
53 
54 
55 template<class OtherType>
58 (
59  const word& name,
60  const LagrangianModel& model
61 ) const
62 {
64  db().template lookupObject<LagrangianDynamicField<OtherType>>(name);
65 
66  return lf.sources()[model.name()];
67 }
68 
69 
70 template<class OtherType, class OtherFieldSourceType>
72 (
73  const word& name,
74  const LagrangianModel& model
75 ) const
76 {
78  fieldSource<OtherType>(name, model);
79 
80  if (!isA<OtherFieldSourceType>(lfs))
81  {
83  << "The '" << type() << "' source of field '"
84  << (db().dbDir()/internalIo_.name()).c_str()
85  << "' for the '" << model.type() << "' Lagrangian model '"
86  << model.name() << "' requires the corresponding source of field '"
87  << (db().dbDir()/name).c_str()
88  << "' to be of type '" << OtherFieldSourceType::typeName
89  << "' (or a derivation thereof), rather than '" << lfs.type()
90  << "'" << exit(FatalError);
91  }
92 
93  return refCast<const OtherFieldSourceType>(lfs);
94 }
95 
96 
97 template<class OtherModelType>
99 (
100  const LagrangianModel& model
101 ) const
102 {
103  if (!isA<OtherModelType>(model))
104  {
106  << "The '" << type() << "' source of field '"
107  << (db().dbDir()/internalIo_.name()).c_str()
108  << "' for the Lagrangian model '" << model.name()
109  << "' requires a model of type '" << OtherModelType::typeName
110  << "' (or a derivation thereof), rather than '" << model.type()
111  << "'" << exit(FatalError);
112  }
113 
114  return refCast<const OtherModelType>(model);
115 }
116 
117 
118 template<class OtherType>
121 (
122  const word& name,
123  const LagrangianSource& source,
124  const LagrangianSubMesh& subMesh
125 ) const
126 {
127  return fieldSource<OtherType>(name, source).value(source, subMesh);
128 }
129 
130 
131 template<class OtherType>
134 (
135  const word& name,
136  const LagrangianInjection& injection,
137  const LagrangianSubMesh& subMesh
138 ) const
139 {
140  return fieldSource<OtherType>(name, injection).value(injection, subMesh);
141 }
142 
143 
144 // ************************************************************************* //
Generic GeometricField class.
const Sources & sources() const
Return const-reference to the sources.
const word & name() const
Return name.
Definition: IOobject.H:307
const word & internalName() const
Return internal field name.
const regIOobject & internalIo_
Reference to the internal IO object.
const OtherFieldSourceType & fieldSourceCast(const LagrangianModel &) const
Cast a to the specified type. Handle errors.
const objectRegistry & db() const
Return local objectRegistry.
const OtherModelType & modelCast(const LagrangianModel &) const
Cast a model to the specified type. Handle errors.
tmp< LagrangianSubField< OtherType > > value(const word &name, const LagrangianSource &, const LagrangianSubMesh &) const
Lookup and return the value of another field source.
const LagrangianFieldSource< OtherType > & fieldSource(const word &name, const LagrangianModel &) const
Lookup and return another field source.
Base class for Lagrangian source conditions.
Base class for Lagrangian injections. Minimal wrapper over LagrangianSource. Implements some utility ...
Base class for Lagrangian models.
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...
const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
A class for managing temporary objects.
Definition: tmp.H:55
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488