SidedInterfacialModel.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) 2014-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 
26 #include "SidedInterfacialModel.H"
27 #include "phaseSystem.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class ModelType>
33 template<class ... Args>
35 (
36  const dictionary& dict,
37  const phaseInterface& interface,
38  const Args& ... args
39 )
40 :
42  (
43  IOobject
44  (
45  IOobject::groupName(typeName, interface.name()),
46  interface.mesh().time().name(),
47  interface.mesh()
48  )
49  ),
50  interface_(interface)
51 {
52  // Construct the models
53  PtrList<phaseInterface> interfaces;
54  PtrList<ModelType> models;
56  <
57  ModelType,
59  >
60  (
61  interfaces,
62  models,
63  interface.fluid(),
64  dict,
65  wordHashSet(),
66  interface,
67  args ...
68  );
69 
70  // Unpack the interface and model lists to populate the models used for
71  // either side of the interface
72  forAll(interfaces, i)
73  {
74  const sidedPhaseInterface& interface =
75  refCast<const sidedPhaseInterface>(interfaces[i]);
76 
77  if (interface_.index(interface.phase()) == 0)
78  {
79  modelInPhase1_.set(models.set(i, nullptr).ptr());
80  }
81  else
82  {
83  modelInPhase2_.set(models.set(i, nullptr).ptr());
84  }
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90 
91 template<class ModelType>
93 {}
94 
95 
96 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
97 
98 template<class ModelType>
101 {
102  return interface_;
103 }
104 
105 
106 template<class ModelType>
108 (
109  const phaseModel& phase
110 ) const
111 {
112  return
113  interface_.index(phase) == 0
114  ? modelInPhase1_.valid()
115  : modelInPhase2_.valid();
116 }
117 
118 
119 template<class ModelType>
121 (
122  const phaseModel& phase
123 ) const
124 {
125  if (!haveModelInThe(phase))
126  {
128  << "There is no " << type() << " active for the "
129  << phase.name() << " side of the "
130  << interface_.name() << " interface"
131  << exit(FatalError);
132  }
133 
134  return
135  interface_.index(phase) == 0
136  ? modelInPhase1_()
137  : modelInPhase2_();
138 }
139 
140 
141 template<class ModelType>
143 (
144  const phaseModel& phase
145 )
146 {
147  if (!haveModelInThe(phase))
148  {
150  << "There is no " << type() << " active for the "
151  << phase.name() << " side of the "
152  << interface_.name() << " interface"
153  << exit(FatalError);
154  }
155 
156  return
157  interface_.index(phase) == 0
158  ? modelInPhase1_()
159  : modelInPhase2_();
160 }
161 
162 
163 template<class ModelType>
165 {
166  return os.good();
167 }
168 
169 
170 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
const phaseInterface & interface() const
Access the interface.
bool writeData(Ostream &os) const
Dummy write for regIOobject.
bool haveModelInThe(const phaseModel &phase) const
Does a model exist in the given phase?
SidedInterfacialModel(const dictionary &dict, const phaseInterface &interface, const Args &... args)
Construct from a dictionary and an interface.
const ModelType & modelInThe(const phaseModel &phase) const
Access the model within the given phase.
void set(T *)
Set pointer to that given.
Definition: autoPtrI.H:99
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Class to represent an interface between phases. Derivations can further specify the configuration of ...
const phaseSystem & fluid() const
Return the phase system.
label index(const phaseModel &phase) const
Return the index of the given phase. Generates a FatalError if.
const word & name() const
Return the name of this phase.
Definition: phaseModel.C:145
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
Class to represent a certain side of an interface between phases.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
void generateInterfacialModels(PtrList< phaseInterface > &interfaces, PtrList< ModelType > &models, const phaseSystem &fluid, const dictionary &dict, const wordHashSet &ignoreKeys, const phaseInterface &interface, const Args &... args)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:134
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:210
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
dictionary dict
Foam::argList args(argc, argv)