ThermoRefPairI.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) 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 "ThermoRefPair.H"
27 #include "physicalProperties.H"
28 
29 // * * * * * * * * * * * * * Private Constructors * * * * * * * * * * * * * //
30 
31 template<class ThermoType>
33 (
34  Pair<bool> valid,
35  const ThermoType& first,
36  const ThermoType& second
37 )
38 :
39  valid_(valid),
40  first_(first),
41  second_(second)
42 {}
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 template<class ThermoType>
49 (
50  const objectRegistry& db,
51  const Pair<word>& phaseNames
52 )
53 :
54  valid_(true, true),
55  first_
56  (
57  db.lookupObject<ThermoType>
58  (
59  IOobject::groupName
60  (
61  physicalProperties::typeName,
62  phaseNames.first()
63  )
64  )
65  ),
66  second_
67  (
68  db.lookupObject<ThermoType>
69  (
70  IOobject::groupName
71  (
72  physicalProperties::typeName,
73  phaseNames.second()
74  )
75  )
76  )
77 {}
78 
79 
80 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
81 
82 template<class ThermoType>
84 {
85  return valid_;
86 }
87 
88 
89 template<class ThermoType>
91 {
92  return valid_.first() || valid_.second();
93 }
94 
95 
96 template<class ThermoType>
98 {
99  return valid_.first() && valid_.second();
100 }
101 
102 
103 template<class ThermoType>
104 inline const ThermoType& Foam::ThermoRefPair<ThermoType>::first() const
105 {
106  return first_;
107 }
108 
109 
110 template<class ThermoType>
111 inline const ThermoType& Foam::ThermoRefPair<ThermoType>::second() const
112 {
113  return second_;
114 }
115 
116 
117 template<class ThermoType>
118 template<class OtherThermoType>
121 {
123  (
124  this->valid().first() && isA<OtherThermoType>(first()),
125  this->valid().second() && isA<OtherThermoType>(second())
126  );
127 
128  return
130  (
131  valid,
132  valid.first()
133  ? refCast<const OtherThermoType>(first())
134  : NullObjectRef<OtherThermoType>(),
135  valid.second()
136  ? refCast<const OtherThermoType>(second())
137  : NullObjectRef<OtherThermoType>()
138  );
139 }
140 
141 
142 template<class ThermoType>
143 template<class OtherThermoType>
146 (
147  const Pair<bool> required,
148  const fvModel& model,
149  const word& thermoType
150 ) const
151 {
152  ThermoRefPair<OtherThermoType> result = thermos<OtherThermoType>();
153 
154  forAll(result.valid(), i)
155  {
156  if (!result.valid()[i] && required[i])
157  {
159  << "Model " << model.name() << " of type "
160  << model.type() << " requires a " << thermoType
161  << " thermo for phase " << operator[](i).phaseName()
162  << exit(FatalError);
163  }
164  }
165 
166  return result;
167 }
168 
169 
170 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
171 
172 template<class ThermoType>
173 inline const ThermoType&
175 {
176  return
177  i == 0 ? first()
178  : i == 1 ? second()
179  : NullObjectRef<ThermoType>();
180 }
181 
182 
183 // ************************************************************************* //
#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
Class containing a pair of thermo references. Handles down-casting to more specific thermo types by c...
Definition: ThermoRefPair.H:51
const Pair< bool > & valid() const
Access the validity flags.
const ThermoType & operator[](const label i) const
Access a thermo by index.
bool either() const
Return if either validity flag is set.
ThermoRefPair< OtherThermoType > thermos() const
Cast to a different thermo type, with error checking.
const ThermoType & first() const
Access the first thermo.
const ThermoType & second() const
Access the second thermo.
bool both() const
Return if both validity flags are set.
friend class ThermoRefPair
Declare friendship with other thermo reference pairs.
Definition: ThermoRefPair.H:79
Finite volume model abstract base class.
Definition: fvModel.H:60
const word & name() const
Return const access to the source name.
Definition: fvModelI.H:57
Registry of regIOobjects.
A base class for physical properties.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
bool valid(const PtrList< ModelType > &l)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
labelList second(const UList< labelPair > &p)
Definition: patchToPatch.C:49
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:39
error FatalError