ThermoRefPair.H
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) 2023-2024 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 Class
25  Foam::ThermoRefPair
26 
27 Description
28  Class containing a pair of thermo references. Handles down-casting to more
29  specific thermo types by constructing one pair from another (e.g.,
30  constructing a multicomponentThermo reference pair from a basicThermo
31  pair). Tracks validity of the references.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef ThermoRefPair_H
36 #define ThermoRefPair_H
37 
38 #include "physicalProperties.H"
39 #include "objectRegistry.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class ThermoRefPair Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template<class ThermoType>
51 class ThermoRefPair
52 {
53  // Private Member Data
54 
55  //- Validity flags
56  const Pair<bool> valid_;
57 
58  //- The first thermo
59  const ThermoType& first_;
60 
61  //- The second thermo
62  const ThermoType& second_;
63 
64 
65 public:
66 
67  // Constructors
68 
69  //- Construct from a database and phase names
71  (
72  const objectRegistry& db,
73  const Pair<word>& phaseNames
74  )
75  :
76  valid_(true, true),
77  first_
78  (
79  db.lookupObject<ThermoType>
80  (
81  IOobject::groupName
82  (
83  physicalProperties::typeName,
84  phaseNames.first()
85  )
86  )
87  ),
88  second_
89  (
90  db.lookupObject<ThermoType>
91  (
92  IOobject::groupName
93  (
94  physicalProperties::typeName,
95  phaseNames.second()
96  )
97  )
98  )
99  {}
100 
101  //- Construct by casting a more primitive thermo type
102  template<class BasicThermoType>
104  :
105  valid_
106  (
107  isA<ThermoType>(basicThermos.first()),
108  isA<ThermoType>(basicThermos.second())
109  ),
110  first_
111  (
112  valid_.first()
113  ? refCast<const ThermoType>(basicThermos.first())
114  : NullObjectRef<ThermoType>()
115  ),
116  second_
117  (
118  valid_.second()
119  ? refCast<const ThermoType>(basicThermos.second())
120  : NullObjectRef<ThermoType>()
121  )
122  {}
123 
124 
125  // Member Functions
126 
127  //- Access the validity flags
128  const Pair<bool>& valid() const
129  {
130  return valid_;
131  }
132 
133  //- Access the first thermo
134  const ThermoType& first() const
135  {
136  return first_;
137  }
138 
139  //- Access the second thermo
140  const ThermoType& second() const
141  {
142  return second_;
143  }
144 
145 
146  // Member Operators
147 
148  //- Access a thermo by index
149  const ThermoType& operator[](const label i) const
150  {
151  return
152  i == 0 ? first()
153  : i == 1 ? second()
154  : NullObjectRef<ThermoType>();
155  }
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Class containing a pair of thermo references. Handles down-casting to more specific thermo types by c...
Definition: ThermoRefPair.H:51
const ThermoType & second() const
Access the second thermo.
ThermoRefPair(const objectRegistry &db, const Pair< word > &phaseNames)
Construct from a database and phase names.
Definition: ThermoRefPair.H:70
const Pair< bool > & valid() const
Access the validity flags.
const ThermoType & operator[](const label i) const
Access a thermo by index.
const ThermoType & first() const
Access the first thermo.
Registry of regIOobjects.
A base class for physical properties.
Namespace for OpenFOAM.
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
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:129
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:166
const T & NullObjectRef()
Return const reference to the nullObject of type T.
Definition: nullObjectI.H:27