BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_GM_Statevals.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#include "GT_globals.hpp"
13
14#ifndef BELFEM_CL_GM_STATAVALS_HPP
15#define BELFEM_CL_GM_STATAVALS_HPP
16
17#define BELFEM_STATEVAL_T 0
18#define BELFEM_STATEVAL_P 1
19#define BELFEM_STATEVAL_V 2
20
21#define BELFEM_STATEVAL_M 3
22#define BELFEM_STATEVAL_R 4
23
24#define BELFEM_STATEVAL_ALPHA 5
25#define BELFEM_STATEVAL_BETA 6
26#define BELFEM_STATEVAL_KAPPA 7
27
28#define BELFEM_STATEVAL_U 8
29#define BELFEM_STATEVAL_H 9
30#define BELFEM_STATEVAL_S 10
31#define BELFEM_STATEVAL_DSDT 11
32#define BELFEM_STATEVAL_DSDP 12
33#define BELFEM_STATEVAL_CP 13
34#define BELFEM_STATEVAL_DHDP 14 // special for tablegas
35#define BELFEM_STATEVAL_DCPDT 15
36#define BELFEM_STATEVAL_CV 16
37#define BELFEM_STATEVAL_GAMMA 17
38#define BELFEM_STATEVAL_C 18
39#define BELFEM_STATEVAL_HVAP 19
40#define BELFEM_STATEVAL_MU 20
41#define BELFEM_STATEVAL_LAMBDA 21
42#define BELFEM_STATEVAL_PR 22
43
44#define BELFEM_STATEVAL_PI 23 // special parameter for tablegas: pi = 1000 * log10( p )
45#define BELFEM_STATEVAL_DMDT 24 // special parameter for tablegas
46#define BELFEM_STATEVAL_DMDP 25 // special parameter for tablegas
47
48#define BELFEM_NSTATEVALS 26
49
50#define BELFEM_T_REF 298.15
51#define BELFEM_P_REF 100000.0
52#define BELFEM_EPSILON_T 1e-7
53#define BELFEM_EPSILON_P 1e-4
54#define BELFEM_EPSILON_S 1e-4
55#define BELFEM_EPSILON_H 1e-4 // for total state
56#define BELFEM_EPSILON_X 1e-6 // for molar fraction
57#define BELFEM_MAXIT 1000
58
59#include "typedefs.hpp"
60#include "assert.hpp"
61#include "cl_Bitset.hpp"
62
63namespace belfem
64{
65 namespace gasmodels
66 {
87 {
88 real mStatevals[BELFEM_NSTATEVALS] = { 0.0 };
90
91//----------------------------------------------------------------------------
92 public:
93//----------------------------------------------------------------------------
94
95 Statevals() = default;
96
97//----------------------------------------------------------------------------
98
99 ~Statevals() = default;
100
101//----------------------------------------------------------------------------
102
106 inline void
107 update_Tp( const real T, const real p );
108
109//----------------------------------------------------------------------------
110
114 inline void
115 update_Tv( const real T, const real v );
116
117//----------------------------------------------------------------------------
118
122 inline void
123 update_pv( const real p, const real v );
124
125//----------------------------------------------------------------------------
126
130 inline void
131 reset();
132
133//----------------------------------------------------------------------------
134
138 inline bool
139 test( const index_t aIndex ) const;
140
141//----------------------------------------------------------------------------
142
146 inline const real &
147 get( const index_t aIndex ) const;
148
149//----------------------------------------------------------------------------
150
154 inline void set( const index_t aIndex, const real aValue );
155
156//------------------------------------------------------------------------------
157 };
158//------------------------------------------------------------------------------
159
160 bool
161 Statevals::test( const index_t aIndex ) const
162 {
163 return mStatebits.test( aIndex );
164 }
165
166//------------------------------------------------------------------------------
167 void
168 Statevals::update_Tp( const real T, const real p )
169 {
170 BELFEM_ASSERT( T > 0, "Invalid Temprerature" );
171 BELFEM_ASSERT( p > 0, "Invalid Pressure" );
172 if( T != mStatevals[ BELFEM_STATEVAL_T ]
173 || p != mStatevals[ BELFEM_STATEVAL_P ] )
174 {
175 mStatebits.reset();
176
177 mStatevals[ BELFEM_STATEVAL_T ] = T;
178 mStatevals[ BELFEM_STATEVAL_P ] = p;
179
180 mStatebits.set( BELFEM_STATEVAL_T );
181 mStatebits.set( BELFEM_STATEVAL_P );
182 }
183 }
184
185//----------------------------------------------------------------------------
186
187 void
188 Statevals::update_Tv( const real T, const real v )
189 {
190 if( T != mStatevals[ BELFEM_STATEVAL_T ]
191 || v != mStatevals[ BELFEM_STATEVAL_V ] )
192 {
193 mStatebits.reset();
194
195 mStatevals[ BELFEM_STATEVAL_T ] = T;
196 mStatevals[ BELFEM_STATEVAL_V ] = v;
197
198 mStatebits.set( BELFEM_STATEVAL_T );
199 mStatebits.set( BELFEM_STATEVAL_V );
200 }
201 }
202
203//----------------------------------------------------------------------------
204
205 void
206 Statevals::update_pv( const real p, const real v )
207 {
208 if( p != mStatevals[ BELFEM_STATEVAL_P ]
209 || v != mStatevals[ BELFEM_STATEVAL_V ] )
210 {
211 mStatebits.reset();
212
213 mStatevals[ BELFEM_STATEVAL_P ] = p;
214 mStatevals[ BELFEM_STATEVAL_V ] = v;
215
216 mStatebits.set( BELFEM_STATEVAL_P );
217 mStatebits.set( BELFEM_STATEVAL_V );
218 }
219 }
220
221//----------------------------------------------------------------------------
222
223 void
225 {
226 mStatebits.reset();
227 }
228
229//----------------------------------------------------------------------------
230
231 const real &
232 Statevals::get( const index_t aIndex ) const
233 {
235 "Invalid State index: %u", ( unsigned int ) aIndex );
236
237 return mStatevals[ aIndex ];
238 }
239
240//----------------------------------------------------------------------------
241
242 void
243 Statevals::set( const index_t aIndex, const real aValue )
244 {
246 "Invalid State index: %u", ( unsigned int ) aIndex );
247
248 // set value
249 mStatevals[ aIndex ] = aValue;
250
251 // update flag
252 mStatebits.set( aIndex );
253 }
254
255//----------------------------------------------------------------------------
256 } /* namespace gasmodels */
257} /* namespace belfem */
258#endif //BELFEM_CL_GM_STATAVALS_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
#define BELFEM_STATEVAL_P
Definition cl_GM_Statevals.hpp:18
#define BELFEM_NSTATEVALS
Definition cl_GM_Statevals.hpp:48
#define BELFEM_STATEVAL_V
Definition cl_GM_Statevals.hpp:19
#define BELFEM_STATEVAL_T
Definition cl_GM_Statevals.hpp:17
Compile-time fixed-size bitset.
Definition cl_Bitset.hpp:32
void update_Tv(const real T, const real v)
update temperature and inverse density
Definition cl_GM_Statevals.hpp:188
void reset()
reset all flags of this state
Definition cl_GM_Statevals.hpp:224
void set(const index_t aIndex, const real aValue)
set a value of the state
Definition cl_GM_Statevals.hpp:243
bool test(const index_t aIndex) const
test if a value is up do date
Definition cl_GM_Statevals.hpp:161
void update_Tp(const real T, const real p)
update temperature and pressure
Definition cl_GM_Statevals.hpp:168
void update_pv(const real p, const real v)
update pressure and inverse density
Definition cl_GM_Statevals.hpp:206
const real & get(const index_t aIndex) const
get a value of the state
Definition cl_GM_Statevals.hpp:232
USER GUIDES:
Definition cl_Capacitor.cpp:16
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36