BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_GM_EoS_Methane.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#ifndef BELFEM_CL_GM_HELMHOLTZ_METHANE_HPP
13#define BELFEM_CL_GM_HELMHOLTZ_METHANE_HPP
14
15#include "en_Helmholtz.hpp"
16#include "cl_GM_Helmholtz.hpp"
17#include "cl_Vector.hpp"
18
19namespace belfem
20{
21 namespace gasmodels
22 {
29 class EoS_Methane : public Helmholtz
30 {
31 // ideal gas table
33 Vector< real > mB ; // theta in Paper
34
35 // real gas table
41 Vector< real > mAlpha ;
42 Vector< real > mBeta ;
43 Vector< real > mPsi ;
44 Vector< real > mGamma ;
45
49
50 // containers
51 mutable Vector< real > mDeltaPowD ;
52
55 mutable Vector< real > mDeltaPowC ;
56
57 mutable Vector< real > mTauPowT ;
58 mutable Vector< real > mE ;
59 mutable Vector< real > mF ;
60 mutable Vector< real > mG ;
61
62//----------------------------------------------------------------------------
63 public:
64//----------------------------------------------------------------------------
65
66 EoS_Methane( Gas & aParent ) ;
67
69
70//----------------------------------------------------------------------------
71 protected:
72//----------------------------------------------------------------------------
73
74 real
75 compute_phi0() const ;
76
77//----------------------------------------------------------------------------
78
79 real
80 compute_phi0_t() const ;
81
82//----------------------------------------------------------------------------
83
84 real
85 compute_phi0_tt() const ;
86
87//----------------------------------------------------------------------------
88
89 real
90 compute_phir() const ;
91
92//----------------------------------------------------------------------------
93
94 real
95 compute_phir_d() const ;
96
97//----------------------------------------------------------------------------
98
99 real
100 compute_phir_dd() const ;
101
102//----------------------------------------------------------------------------
103
104 real
105 compute_phir_t() const ;
106
107//----------------------------------------------------------------------------
108
109 real
110 compute_phir_tt() const ;
111
112//----------------------------------------------------------------------------
113
114 real
115 compute_phir_dt() const ;
116
117//----------------------------------------------------------------------------
118 private:
119//----------------------------------------------------------------------------
120
121 void
122 init_tables() ;
123
124//----------------------------------------------------------------------------
125// help functions
126//----------------------------------------------------------------------------
127
128 void
129 update_e() const ;
130
131//----------------------------------------------------------------------------
132 void
133 update_f() const ;
134
135//----------------------------------------------------------------------------
136
137 void
138 update_g() const;
139
140//----------------------------------------------------------------------------
141
142 void
143 update_delta_pow_d() const;
144
145//----------------------------------------------------------------------------
146
147 void
148 update_tau_pow_theta() const;
149
150//----------------------------------------------------------------------------
151 };
152
153//----------------------------------------------------------------------------
154// help functions for real gas contribution to helmholtz function
155//----------------------------------------------------------------------------
156
157 inline void
158 EoS_Methane::update_e() const
159 {
160 if( mTau != mE( 0 ) )
161 {
162 mE( 0 ) = mTau ;
163 mE( 3 ) = std::exp( mB( 3 ) * mTau ) ;
164 mE( 4 ) = std::exp( mB( 4 ) * mTau ) ;
165 mE( 5 ) = std::exp( mB( 5 ) * mTau ) ;
166 mE( 6 ) = std::exp( mB( 6 ) * mTau ) ;
167 mE( 7 ) = std::exp( mB( 7 ) * mTau ) ;
168 }
169 }
170
171//----------------------------------------------------------------------------
172
173 inline void
174 EoS_Methane::update_f() const
175 {
176 this->update_tau_pow_theta() ;
177 this->update_delta_pow_d() ;
178
179 if( mTau != mF( 40 ) || mDelta != mF( 41 ) )
180 {
181 for( uint k=0; k<40; ++k )
182 {
183 mF( k ) = mN( k ) * mDeltaPowD( k ) * mTauPowT( k ) ;
184 }
185
186 mF( 40 ) = mTau ;
187 mF( 41 ) = mDelta ;
188 }
189 }
190
191//----------------------------------------------------------------------------
192
193 inline void
194 EoS_Methane::update_g() const
195 {
196 if( mTau != mG( 40 ) || mDelta != mG( 41 ) )
197 {
198 if ( mDelta != mG( 41 ) )
199 {
200 mG( 13 ) = std::exp( -mDelta );
201 mG( 14 ) = mG( 13 );
202 mG( 15 ) = mG( 13 );
203 mG( 16 ) = mG( 13 );
204 mG( 17 ) = mG( 13 );
205 mG( 18 ) = mG( 13 );
206 mG( 19 ) = mG( 13 );
207
208 mG( 20 ) = std::exp( -mDelta * mDelta );
209 mG( 21 ) = mG( 20 );
210 mG( 22 ) = mG( 20 );
211 mG( 23 ) = mG( 20 );
212 mG( 24 ) = mG( 20 );
213
214 mG( 25 ) = std::exp( -mDelta * mDelta * mDelta );
215 mG( 26 ) = mG( 25 );
216 mG( 27 ) = mG( 25 );
217 mG( 28 ) = mG( 25 );
218
219 mG( 29 ) = std::exp( -mDelta * mDelta * mDelta * mDelta );
220 mG( 30 ) = mG( 29 );
221 mG( 31 ) = mG( 29 );
222 mG( 32 ) = mG( 29 );
223 mG( 33 ) = mG( 29 );
224 mG( 34 ) = mG( 29 );
225 mG( 35 ) = mG( 29 );
226 }
227
228 for( uint k=36; k<40; ++k )
229 {
230 mG( k ) = std::exp(
231 mAlpha( k ) * std::pow( mDelta - mPsi( k ) , 2 )
232 + mBeta( k ) * std::pow( mTau - mGamma( k ), 2 ) );
233 }
234
235 mG( 40 ) = mTau ;
236 mG( 41 ) = mDelta ;
237 }
238 }
239
240//----------------------------------------------------------------------------
241
242 inline void
243 EoS_Methane::update_delta_pow_d() const
244 {
245 if( mDelta != mDeltaPowD( 40 ) )
246 {
247 /* the exponents are integers, so repeated multiplication
248 * replaces std::pow( real, real ). Note that mD is zero for the
249 * last three terms, hence the accumulator starts at one. */
250 for( uint k=0; k<40; ++k )
251 {
252 real tPow = 1.0 ;
253
254 for( uint i=0; i<mD( k ); ++i )
255 {
256 tPow *= mDelta ;
257 }
258
259 mDeltaPowD( k ) = tPow ;
260
261 // delta^c for the exponential of the residual terms
262 mDeltaPowC( k ) = ipow( mDelta, mC( k ) ) ;
263 }
264
265 mDeltaPowD( 40 ) = mDelta ;
266 }
267 }
268
269//----------------------------------------------------------------------------
270
271 inline void
272 EoS_Methane::update_tau_pow_theta() const
273 {
274 if( mTau != mTauPowT( 40 ) )
275 {
276 /* every tabulated tau exponent is a multiple of one half, so
277 * 2*mT is an integer and hpow() replaces std::pow. The doubled
278 * exponent is derived from mT rather than tabulated a second
279 * time, so the two can never disagree. */
280 const real tSqrtTau = std::sqrt( mTau ) ;
281
282 for( uint k=0; k<40; ++k )
283 {
284 const int tN = static_cast< int >( std::lround( 2.0 * mT( k ) ) );
285
286 BELFEM_ASSERT( std::abs( 2.0 * mT( k ) - tN ) < 1e-9,
287 "tau exponent %f of term %u is not a multiple of one half",
288 ( float ) mT( k ), ( unsigned int ) k );
289
290 mTauPowT( k ) = hpow( mTau, tSqrtTau, tN );
291 }
292
293 mTauPowT( 40 ) = mTau ;
294 }
295 }
296
297//----------------------------------------------------------------------------
298
299 }
300}
301
302#endif //BELFEM_CL_GM_HELMHOLTZ_METHANE_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
The gas class that provides the fluid model.
Definition cl_Gas.hpp:81
real compute_phi0() const
Definition cl_GM_EoS_Methane.cpp:142
EoS_Methane(Gas &aParent)
Definition cl_GM_EoS_Methane.cpp:22
real compute_phir() const
Definition cl_GM_EoS_Methane.cpp:191
real compute_phir_dd() const
Definition cl_GM_EoS_Methane.cpp:245
real compute_phi0_t() const
Definition cl_GM_EoS_Methane.cpp:159
real compute_phi0_tt() const
Definition cl_GM_EoS_Methane.cpp:175
real compute_phir_t() const
Definition cl_GM_EoS_Methane.cpp:285
real compute_phir_dt() const
Definition cl_GM_EoS_Methane.cpp:351
real compute_phir_d() const
Definition cl_GM_EoS_Methane.cpp:214
real compute_phir_tt() const
Definition cl_GM_EoS_Methane.cpp:315
Helmholtz(Gas &aParent, const string &aLabel)
Definition cl_GM_Helmholtz.cpp:25
const real & mTau
Definition cl_GM_Helmholtz.hpp:115
static real ipow(real x, uint n)
integer power by binary exponentiation, for the coefficient tables of the residual functions.
Definition cl_GM_Helmholtz.hpp:512
static real hpow(const real x, const real sqrt_x, const int n)
x^( n / 2 ) for a signed half integer exponent given as n = 2j.
Definition cl_GM_Helmholtz.hpp:538
const real & mDelta
Definition cl_GM_Helmholtz.hpp:116
Definition cl_Gas.hpp:42
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
double real
Definition typedefs.hpp:36
i
Definition main.py:48