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-2023 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"
28 #include "sidedPhaseInterface.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class ModelType>
34 (
35  const dictionary& dict,
36  const phaseInterface& interface
37 )
38 :
40  (
41  IOobject
42  (
43  IOobject::groupName(typeName, interface.name()),
44  interface.mesh().time().name(),
45  interface.mesh()
46  )
47  ),
48  interface_(interface)
49 {
50  // Construct the models
51  PtrList<phaseInterface> interfaces;
52  PtrList<ModelType> models;
54  (
55  dict,
56  interface,
57  interfaces,
58  models
59  );
60 
61  // Unpack the interface and model lists to populate the models used for
62  // either side of the interface
63  forAll(interfaces, i)
64  {
65  const sidedPhaseInterface& interface =
66  refCast<const sidedPhaseInterface>(interfaces[i]);
67 
68  if (interface_.index(interface.phase()) == 0)
69  {
70  modelInPhase1_.set(models.set(i, nullptr).ptr());
71  }
72  else
73  {
74  modelInPhase2_.set(models.set(i, nullptr).ptr());
75  }
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
82 template<class ModelType>
84 {}
85 
86 
87 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
88 
89 template<class ModelType>
92 {
93  return interface_;
94 }
95 
96 
97 template<class ModelType>
99 (
100  const phaseModel& phase
101 ) const
102 {
103  return
104  interface_.index(phase) == 0
105  ? modelInPhase1_.valid()
106  : modelInPhase2_.valid();
107 }
108 
109 
110 template<class ModelType>
112 (
113  const phaseModel& phase
114 ) const
115 {
116  if (!haveModelInThe(phase))
117  {
119  << "There is no " << type() << " active for the "
120  << phase.name() << " side of the "
121  << interface_.name() << " interface"
122  << exit(FatalError);
123  }
124 
125  return
126  interface_.index(phase) == 0
127  ? modelInPhase1_()
128  : modelInPhase2_();
129 }
130 
131 
132 template<class ModelType>
134 (
135  const phaseModel& phase
136 )
137 {
138  if (!haveModelInThe(phase))
139  {
141  << "There is no " << type() << " active for the "
142  << phase.name() << " side of the "
143  << interface_.name() << " interface"
144  << exit(FatalError);
145  }
146 
147  return
148  interface_.index(phase) == 0
149  ? modelInPhase1_()
150  : modelInPhase2_();
151 }
152 
153 
154 template<class ModelType>
156 {
157  return os.good();
158 }
159 
160 
161 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:330
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.
SidedInterfacialModel(const dictionary &dict, const phaseInterface &interface)
Construct from a dictionary and an interface.
bool haveModelInThe(const phaseModel &phase) const
Does a model exist in the given phase?
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 keyword definitions, which are a keyword followed by any number of values (e....
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
void generateInterfacialModels(const dictionary &dict, const phaseInterface &interface, PtrList< phaseInterface > &interfaces, PtrList< ModelType > &models) const
Generate interfacial-model lists.
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.
#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
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:129
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
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