Line data Source code
1 : module test_eos_support
2 :
3 : use eos_def
4 : use eos_lib
5 : use chem_lib
6 : use chem_def
7 : use const_def
8 : use eos_support
9 : use math_lib
10 :
11 : implicit none
12 :
13 : contains
14 :
15 1 : subroutine test1_eosPT_for_ck(quietly)
16 : logical, intent(in) :: quietly
17 : real(dp) :: Z, X, logPgas, logT, logRho, logP
18 : ! pick args for test so that use both HELM and tables to get results.
19 1 : Z = 0.02d0
20 1 : X = 0.7d0
21 1 : logT = 3.0d0
22 1 : logPgas = 4.2d0
23 1 : call test1_eosPT(Z, X, logPgas, logT, .false., quietly, logRho, logP)
24 1 : end subroutine test1_eosPT_for_ck
25 :
26 0 : subroutine test_eosPT(which)
27 : integer, intent(in) :: which
28 : real(dp) :: Z, X, logPgas, logT, logRho, logP
29 0 : Z = 0.02d0
30 0 : X = 0.6d0
31 0 : logT = 4d0
32 0 : logPgas = 5d0
33 0 : call test1_eosPT(Z, X, logPgas, logT, .false., .false., logRho, logP)
34 0 : end subroutine test_eosPT
35 :
36 1 : subroutine test1_eosPT(Z, X, logPgas, logT, do_compare, quietly, logRho, logP)
37 : logical, intent(in) :: quietly
38 : real(dp), intent(in) :: Z, X, logPgas, logT
39 : real(dp), intent(out) :: logRho, logP
40 : logical, intent(in) :: do_compare
41 : real(dp) :: &
42 : P, Pgas, Prad, T, Rho, dlnRho_dlnPgas_c_T, dlnRho_dlnT_c_Pgas, &
43 : res(num_eos_basic_results), d_dlnd(num_eos_basic_results), &
44 : d_dlnT(num_eos_basic_results), &
45 : res2(num_eos_basic_results), d_dlnd2(num_eos_basic_results), &
46 : d_dxa2(num_eos_d_dxa_results, species), &
47 : d_dlnT2(num_eos_basic_results)
48 : integer:: ierr, i
49 : character(len=eos_name_length) :: names(num_eos_basic_results)
50 :
51 : include 'formats'
52 :
53 : ierr = 0
54 :
55 1 : call Init_Composition(X, Z, 0d0, 0d0) ! sets abar and zbar
56 :
57 : !if (.false.) then ! TESTING
58 : ! Z = 0d0
59 : ! X = 0.72d0
60 : ! call Init_Composition(X, Z, 0d0, 0d0) ! sets abar and zbar
61 : ! abar = 1.2966413082679851D+00
62 : ! zbar = 1.1021433867453336D+00
63 : ! logPgas = 4.8066181993619859D+00
64 : ! logT = 3.7569035961895620D+00
65 : !end if
66 :
67 1 : T = exp10(logT)
68 1 : Pgas = exp10(logPgas)
69 :
70 1 : if (.not. quietly) then
71 1 : write (*, *) 'test1_eosPT'
72 1 : write (*, 1) 'logT', logT
73 1 : write (*, 1) 'logPgas', logPgas
74 1 : write (*, 1) 'T', T
75 1 : write (*, 1) 'Pgas', Pgas
76 1 : write (*, 1) 'Z', Z
77 1 : write (*, 1) 'X', X
78 1 : write (*, 1) 'abar', abar
79 1 : write (*, 1) 'zbar', zbar
80 1 : write (*, '(A)')
81 : end if
82 :
83 : call eosPT_get( &
84 : handle, &
85 : species, chem_id, net_iso, xa, &
86 : Pgas, logPgas, T, logT, &
87 : Rho, logRho, dlnRho_dlnPgas_c_T, dlnRho_dlnT_c_Pgas, &
88 1 : res, d_dlnd, d_dlnT, d_dxa, ierr)
89 1 : if (ierr /= 0) then
90 0 : write (*, *) 'ierr in eosPT_get for test1_eosPT'
91 0 : call mesa_error(__FILE__, __LINE__)
92 : end if
93 :
94 1 : Prad = crad*T*T*T*T/3
95 1 : P = Pgas + Prad
96 1 : logP = log10(P)
97 :
98 2 : if (quietly) return
99 :
100 1 : write (*, '(A)')
101 1 : write (*, 1) 'rho', rho
102 1 : write (*, 1) 'logRho', logRho
103 1 : write (*, 1) 'logT', logT
104 1 : write (*, 1) 'logPgas', logPgas
105 1 : write (*, '(A)')
106 :
107 27 : names = eosDT_result_names
108 :
109 1 : if (.not. do_compare) then ! simple form of output
110 1 : write (*, 1) 'dlnRho_dlnPgas_c_T', dlnRho_dlnPgas_c_T
111 1 : write (*, 1) 'dlnRho_dlnT_c_Pgas', dlnRho_dlnT_c_Pgas
112 1 : write (*, '(A)')
113 1 : write (*, 1) 'P', P
114 1 : write (*, 1) 'E', exp(res(i_lnE))
115 1 : write (*, 1) 'S', exp(res(i_lnS))
116 1 : write (*, '(A)')
117 24 : do i = 4, num_eos_basic_results
118 24 : write (*, 1) trim(names(i)), res(i)
119 : end do
120 1 : write (*, '(A)')
121 1 : return
122 : end if
123 :
124 : call eosDT_get( &
125 : handle, &
126 : species, chem_id, net_iso, xa, &
127 : rho, logRho, T, logT, &
128 0 : res2, d_dlnd2, d_dlnT2, d_dxa2, ierr)
129 0 : if (ierr /= 0) then
130 0 : write (*, *) 'ierr in eosDT_get for test1_eosPT'
131 0 : call mesa_error(__FILE__, __LINE__)
132 : end if
133 :
134 0 : write (*, '(A)')
135 :
136 0 : write (*, 1) 'dlnRho_dlnPgas_c_T', dlnRho_dlnPgas_c_T
137 0 : write (*, 1) 'dlnRho_dlnT_c_Pgas', dlnRho_dlnT_c_Pgas
138 0 : do i = 1, num_eos_basic_results
139 0 : write (*, 1) trim(names(i)), res(i), res2(i), &
140 0 : (res(i) - res2(i))/max(1d0, abs(res(i)), abs(res2(i)))
141 : end do
142 0 : write (*, '(A)')
143 :
144 0 : do i = 1, num_eos_basic_results
145 0 : write (*, 1) 'd_dlnd '//trim(names(i)), d_dlnd(i), d_dlnd2(i), &
146 0 : (d_dlnd(i) - d_dlnd2(i))/max(1d0, abs(d_dlnd(i)), abs(d_dlnd2(i)))
147 : end do
148 0 : write (*, '(A)')
149 :
150 0 : do i = 1, num_eos_basic_results
151 0 : write (*, 1) 'd_dlnT '//trim(names(i)), d_dlnT(i), &
152 0 : d_dlnT2(i), (d_dlnT(i) - d_dlnT2(i))/max(1d0, abs(d_dlnT(i)), abs(d_dlnT2(i)))
153 : end do
154 0 : write (*, '(A)')
155 :
156 : end subroutine test1_eosPT
157 :
158 1 : subroutine Do_One(quietly)
159 : logical, intent(in) :: quietly
160 : real(dp) :: T, rho
161 : real(dp), dimension(num_eos_basic_results) :: res
162 : real(dp) :: dXC
163 :
164 : if (.true.) then
165 : ! pure Helium
166 1 : X = 0.00d0
167 1 : Zinit = 0.00d0
168 1 : dXO = 0.00d0
169 1 : dXC = 0.00d0
170 1 : call doit('pure Helium')
171 : ! pure Hydrogen
172 1 : X = 1.00d0
173 1 : Zinit = 0.00d0
174 1 : dXO = 0.00d0
175 1 : dXC = 0.00d0
176 1 : call doit('pure Hydrogen')
177 : ! mixed Z with H&He 3:1 ratio
178 1 : Zinit = 0.03d0
179 1 : X = 0.75d0*(1 - Zinit)
180 1 : dXO = 0.00d0
181 1 : dXC = 0.00d0
182 1 : call doit('mixed Z with H&He 3:1 ratio')
183 : ! solar
184 1 : X = 0.70d0
185 1 : Zinit = 0.02d0
186 1 : dXO = 0.00d0
187 1 : dXC = 0.00d0
188 1 : call doit('solar')
189 : end if
190 :
191 1 : if (.true.) then ! do get_Rho and get_T
192 1 : X = 0.70d+00
193 1 : Zinit = 0.02d0
194 1 : dXO = 0.00d0
195 1 : dXC = 0.00d0
196 1 : T = exp10(4.8d0)
197 1 : rho = 1d-7
198 1 : Z = Zinit + dXC + dXO
199 1 : Y = 1 - (X + Z)
200 1 : call Init_Composition(X, Zinit, dXC, dXO)
201 1 : res(i_lnS) = log(2.9680645120000000d+09)
202 1 : call test_get_Rho_T
203 1 : if (.not. quietly) write (*, *)
204 : end if
205 :
206 : contains
207 :
208 20 : subroutine doit(str)
209 : character(len=*), intent(in) :: str
210 :
211 : if (.false.) then
212 : T = 2d8; rho = 100d0
213 : call Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res) ! scvh
214 : stop
215 : end if
216 :
217 4 : if (.not. quietly) write (*, *) trim(str)
218 :
219 4 : T = 1d6; rho = 1d-2
220 4 : call Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res) ! opal
221 4 : T = 1d4; rho = 1d-1
222 4 : call Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res) ! scvh
223 4 : T = 1d5; rho = 1d-1
224 4 : call Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res) ! opal-scvh overlap
225 4 : T = 2d8; rho = 1d2
226 4 : call Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res) ! helm
227 :
228 4 : if (.not. quietly) write (*, *)
229 :
230 4 : end subroutine doit
231 :
232 1 : subroutine test_get_Rho_T ! using most recent values from subroutine Do_One_TRho
233 : real(dp) :: tol, othertol, &
234 : result, result_log10, log10_T, log10_rho, lnS, Prad, Pgas, logP, &
235 : logRho_guess, logRho_bnd1, logRho_bnd2, other_at_bnd1, other_at_bnd2, &
236 : logT_guess, logT_bnd1, logT_bnd2
237 : integer :: max_iter, eos_calls, ierr
238 : real(dp), dimension(num_eos_basic_results) :: &
239 : d_dlnd, d_dlnT
240 : real(dp), dimension(num_eos_d_dxa_results, species) :: &
241 : d_dxa
242 :
243 1 : if (.not. quietly) write (*, *)
244 :
245 1 : log10_rho = log10(rho)
246 1 : log10_T = log10(T)
247 1 : lnS = res(i_lnS)
248 :
249 : ierr = 0
250 1 : max_iter = 100
251 1 : tol = 1d-5
252 1 : othertol = 1d-12
253 :
254 : 1 format(a30, 1pe24.16)
255 : 2 format(a30, i8)
256 :
257 1 : if (.not. quietly) then
258 1 : write (*, '(A)')
259 1 : write (*, 1) ' tolerance', tol
260 : end if
261 1 : if (.not. quietly) write (*, *)
262 1 : result = rho*0.5d0 ! initial guess
263 1 : result_log10 = log10(result)
264 1 : res = 0
265 1 : logRho_guess = result_log10
266 1 : logRho_bnd1 = arg_not_provided
267 1 : logRho_bnd2 = arg_not_provided
268 1 : other_at_bnd1 = arg_not_provided
269 1 : other_at_bnd2 = arg_not_provided
270 : call eosDT_get_Rho( &
271 : handle, &
272 : species, chem_id, net_iso, xa, &
273 : log10_T, i_lnS, lnS, &
274 : tol, othertol, max_iter, logRho_guess, &
275 : logRho_bnd1, logRho_bnd2, other_at_bnd1, other_at_bnd2, &
276 : result_log10, res, d_dlnd, d_dlnT, &
277 1 : d_dxa, eos_calls, ierr)
278 1 : result = exp10(result_log10)
279 1 : if (ierr /= 0) then
280 0 : write (*, *) 'ierr in test_get_Rho_T'
281 0 : call mesa_error(__FILE__, __LINE__)
282 : end if
283 1 : if (.not. quietly) then
284 1 : write (*, 1) 'actual logRho', log10_rho
285 1 : write (*, 1) ' guess logRho', logRho_guess
286 1 : write (*, 1) ' found logRho', result_log10
287 1 : write (*, 1) ' wanted logS', lnS/ln10
288 1 : write (*, 1) ' got logS', res(i_lnS)/ln10
289 1 : write (*, '(A)')
290 : end if
291 :
292 1 : result = T*2d0 ! initial guess
293 1 : result_log10 = log10(result)
294 1 : res = 0
295 1 : logT_guess = result_log10
296 1 : logT_bnd1 = 3
297 1 : logT_bnd2 = 9
298 : call eosDT_get_T( &
299 : handle, &
300 : species, chem_id, net_iso, xa, &
301 : log10_rho, i_lnS, lnS, &
302 : tol, othertol, max_iter, logT_guess, &
303 : logT_bnd1, logT_bnd2, other_at_bnd1, other_at_bnd2, &
304 : result_log10, res, d_dlnd, d_dlnT, &
305 1 : d_dxa, eos_calls, ierr)
306 1 : result = exp10(result_log10)
307 1 : if (ierr /= 0) then
308 0 : write (*, *) 'ierr in test_get_Rho_T'
309 0 : call mesa_error(__FILE__, __LINE__)
310 : end if
311 1 : if (.not. quietly) then
312 1 : write (*, '(A)')
313 1 : write (*, 1) 'actual logT', log10_T
314 1 : write (*, 1) ' guess logT', logT_guess
315 1 : write (*, 1) ' found logT', result_log10
316 1 : write (*, 1) ' wanted logS', lnS/ln10
317 1 : write (*, 1) ' got logS', res(i_lnS)/ln10
318 1 : write (*, '(A)')
319 : end if
320 :
321 1 : T = exp10(log10_T)
322 1 : Prad = crad*T*T*T*T/3
323 1 : Pgas = exp(res(i_lnPgas))
324 1 : logP = log10(Prad + Pgas)
325 1 : result = T*2d0 ! initial guess
326 1 : result_log10 = log10(result)
327 1 : res = 0
328 1 : logT_guess = result_log10
329 : logT_bnd1 = 3
330 : logT_bnd2 = 9
331 : call eosDT_get_T( &
332 : handle, &
333 : species, chem_id, net_iso, xa, &
334 : log10_rho, i_logPtot, logP, &
335 : tol, othertol, max_iter, logT_guess, &
336 : logT_bnd1, logT_bnd2, other_at_bnd1, other_at_bnd2, &
337 : result_log10, res, d_dlnd, d_dlnT, &
338 1 : d_dxa, eos_calls, ierr)
339 1 : result = exp10(result_log10)
340 1 : if (ierr /= 0) then
341 0 : write (*, *) 'ierr in test_get_Rho_T (eosDT_get_T_given_Ptotal)'
342 0 : call mesa_error(__FILE__, __LINE__)
343 : end if
344 1 : if (.not. quietly) then
345 1 : write (*, '(A)')
346 1 : write (*, 1) 'actual logT', log10_T
347 1 : write (*, 1) ' guess logT', logT_guess
348 1 : write (*, 1) ' found logT', result_log10
349 1 : write (*, 1) ' wanted logP', logP
350 1 : T = exp10(result_log10)
351 1 : Prad = crad*T*T*T*T/3
352 1 : Pgas = exp(res(i_lnPgas))
353 1 : logP = log10(Prad + Pgas)
354 1 : write (*, 1) ' got logP', logP
355 1 : write (*, 2) ' eos calls', eos_calls
356 1 : write (*, '(A)')
357 : end if
358 :
359 1 : end subroutine test_get_Rho_T
360 :
361 : end subroutine Do_One
362 :
363 0 : subroutine test1_eosPT_get_T
364 :
365 : real(dp) :: &
366 : energy, abar, zbar, X, Z, logPgas, logT_tol, other_tol, other, &
367 : logT_guess, logT_bnd1, logT_bnd2, other_at_bnd1, other_at_bnd2, &
368 : logT_result, &
369 : res(num_eos_basic_results), d_dlnd(num_eos_basic_results), &
370 : d_dxa(num_eos_d_dxa_results, species), &
371 : d_dlnT(num_eos_basic_results), &
372 : Rho, log10Rho, dlnRho_dlnPgas_const_T, dlnRho_dlnT_const_Pgas
373 : integer:: ierr, which_other, eos_calls, max_iter
374 :
375 : 1 format(a40, 1pe26.16)
376 :
377 0 : call Setup_eos
378 :
379 : ierr = 0
380 :
381 0 : write (*, *) 'test1_eosPT_get_T'
382 :
383 0 : Z = 0.02d0
384 0 : X = 0.70d0
385 0 : abar = 1.2966353559153956d0
386 0 : zbar = 1.1021400447995373d0
387 0 : logPgas = 15d0
388 0 : energy = exp(3.5034294596213336d+01)
389 0 : logT_tol = 1d-6
390 0 : other_tol = ln10*1d-6
391 0 : logT_guess = 7d0
392 0 : logT_bnd1 = arg_not_provided
393 0 : logT_bnd2 = arg_not_provided
394 0 : other_at_bnd1 = arg_not_provided
395 0 : other_at_bnd2 = arg_not_provided
396 :
397 0 : which_other = i_lnE
398 0 : other = log(energy)
399 0 : max_iter = 100
400 :
401 0 : write (*, 1) 'logPgas', logPgas
402 0 : write (*, 1) 'logT_guess', logT_guess
403 0 : write (*, 1) 'logT_bnd1', logT_bnd1
404 0 : write (*, 1) 'logT_bnd2', logT_bnd2
405 0 : write (*, 1) 'energy', energy
406 0 : write (*, 1) 'other', other
407 0 : write (*, 1) 'Z', Z
408 0 : write (*, 1) 'X', X
409 0 : write (*, 1) 'abar', abar
410 0 : write (*, 1) 'zbar', zbar
411 0 : write (*, 1) 'logT_tol', logT_tol
412 0 : write (*, 1) 'other_tol', other_tol
413 0 : write (*, '(A)')
414 :
415 : call eosPT_get_T( &
416 : handle, &
417 : species, chem_id, net_iso, xa, &
418 : logPgas, which_other, other, &
419 : logT_tol, other_tol, max_iter, logT_guess, &
420 : logT_bnd1, logT_bnd2, other_at_bnd1, other_at_bnd2, &
421 : logT_result, Rho, log10Rho, dlnRho_dlnPgas_const_T, dlnRho_dlnT_const_Pgas, &
422 : res, d_dlnd, d_dlnT, d_dxa, &
423 0 : eos_calls, ierr)
424 0 : if (ierr /= 0) then
425 0 : write (*, *) 'ierr in test1_eosPT_get_T'
426 0 : call mesa_error(__FILE__, __LINE__)
427 : end if
428 0 : write (*, '(A)')
429 0 : write (*, 1) 'guess logT', logT_guess
430 0 : write (*, 1) 'found logT', logT_result
431 0 : write (*, 1) 'wanted logE', other/ln10
432 0 : write (*, 1) 'got logE', res(i_lnE)/ln10
433 0 : write (*, '(A)')
434 0 : write (*, *) 'eos_calls', eos_calls
435 0 : write (*, '(A)')
436 :
437 0 : end subroutine test1_eosPT_get_T
438 :
439 0 : subroutine test_components
440 : real(dp) :: &
441 : X_test, Z, XC_test, XO_test, &
442 : logT, logRho, Pgas, energy, entropy
443 : real(dp), dimension(num_eos_basic_results) :: &
444 : res, d_dlnd, d_dlnT
445 : integer:: ierr
446 : include 'formats'
447 :
448 0 : write (*, *) 'test_components'
449 :
450 0 : call Setup_eos
451 :
452 0 : ierr = 0
453 :
454 0 : X_test = 0.12d0
455 0 : Z = 0.03d0
456 0 : XC_test = 0d0
457 0 : XO_test = 0d0
458 :
459 0 : call Init_Composition(X_test, Z, XC_test, XO_test)
460 :
461 0 : logT = 6.0d0
462 0 : logRho = 3.5d0
463 :
464 0 : write (*, 1) 'logT', logT
465 0 : write (*, 1) 'logRho', logRho
466 0 : write (*, '(A)')
467 0 : write (*, 1) 'xa h1', xa(h1)
468 0 : write (*, 1) 'xa he4', xa(he4)
469 0 : write (*, 1) 'xa c12', xa(c12)
470 0 : write (*, 1) 'xa n14', xa(n14)
471 0 : write (*, 1) 'xa o16', xa(o16)
472 0 : write (*, 1) 'xa ne20', xa(ne20)
473 0 : write (*, 1) 'xa mg24', xa(mg24)
474 0 : write (*, '(A)')
475 0 : write (*, 1) 'X', X
476 0 : write (*, 1) 'Y', 1d0 - (X + Z)
477 0 : write (*, 1) 'Z', Z
478 0 : write (*, '(A)')
479 0 : write (*, 1) 'abar', abar
480 0 : write (*, 1) 'zbar', zbar
481 0 : write (*, '(A)')
482 0 : write (*, '(a55,9a26)') ' ', 'Pgas', 'energy', 'entropy'
483 0 : call test1(1, 'opal_scvh')
484 0 : call test1(2, 'helm')
485 0 : call test1(4, 'pc')
486 0 : write (*, '(A)')
487 :
488 : contains
489 :
490 0 : subroutine test1(which_eos, str)
491 : integer, intent(in) :: which_eos
492 : character(len=*), intent(in) :: str
493 : include 'formats'
494 : call eosDT_get_component( &
495 : handle, which_eos, &
496 : species, chem_id, net_iso, xa, &
497 : exp10(logRho), logRho, exp10(logT), logT, &
498 0 : res, d_dlnd, d_dlnT, d_dxa, ierr)
499 0 : if (ierr /= 0) then
500 0 : write (*, 1) trim(str)//' no results'
501 : else
502 0 : write (*, 1) trim(str), Pgas, energy, entropy
503 : end if
504 0 : end subroutine test1
505 :
506 : end subroutine test_components
507 :
508 0 : subroutine test1_eosDT_get_T_given_egas
509 :
510 : real(dp) :: &
511 : X, Z, abar, zbar, logRho, egas_want, egas_tol, logT_tol, logT_guess, &
512 : logT_bnd1, logT_bnd2, egas_at_bnd1, egas_at_bnd2, logT_result, erad, egas, energy, &
513 : res(num_eos_basic_results), d_dlnd(num_eos_basic_results), &
514 : d_dxa(num_eos_d_dxa_results, species), &
515 : d_dlnT(num_eos_basic_results)
516 : integer:: ierr, eos_calls, max_iter
517 :
518 : 1 format(a40, 1pe26.16)
519 :
520 0 : call Setup_eos
521 :
522 : ierr = 0
523 :
524 0 : Z = 0.7D-02
525 0 : X = 7.3D-01
526 :
527 0 : call Init_Composition(X, Z, 0d0, 0d0) ! sets abar and zbar
528 :
529 0 : write (*, *) 'test1_eosDT_get_T_given_egas'
530 :
531 0 : abar = 1.2559567378472252D+00
532 0 : zbar = 1.0864043570945732D+00
533 0 : logRho = -9.4201625429594529D+00
534 :
535 0 : egas_want = 2.0596457989663662D+12
536 0 : egas_tol = egas_want*1d-11
537 0 : logT_tol = 1d-11
538 0 : logT_guess = 3.6962155439999007D+00
539 :
540 0 : logT_bnd1 = arg_not_provided
541 0 : logT_bnd2 = arg_not_provided
542 0 : egas_at_bnd1 = arg_not_provided
543 0 : egas_at_bnd2 = arg_not_provided
544 :
545 0 : max_iter = 100
546 :
547 0 : write (*, 1) 'logRho', logRho
548 0 : write (*, 1) 'logT_guess', logT_guess
549 0 : write (*, 1) 'egas_want', egas_want
550 0 : write (*, 1) 'Z', Z
551 0 : write (*, 1) 'X', X
552 0 : write (*, 1) 'abar', abar
553 0 : write (*, 1) 'zbar', zbar
554 0 : write (*, 1) 'logT_tol', logT_tol
555 0 : write (*, 1) 'egas_tol', egas_tol
556 0 : write (*, '(A)')
557 :
558 : call eosDT_get_T( &
559 : handle, &
560 : species, chem_id, net_iso, xa, &
561 : logRho, i_egas, egas_want, &
562 : logT_tol, egas_tol, max_iter, logT_guess, &
563 : logT_bnd1, logT_bnd2, egas_at_bnd1, egas_at_bnd2, &
564 : logT_result, res, d_dlnd, d_dlnT, d_dxa, &
565 0 : eos_calls, ierr)
566 0 : if (ierr /= 0) then
567 0 : write (*, *) 'ierr in eosDT_get_T_given_egas'
568 0 : call mesa_error(__FILE__, __LINE__)
569 : end if
570 0 : energy = exp(res(i_lnE))
571 0 : erad = crad*exp10(logT_result)**4/exp10(logRho)
572 0 : egas = energy - erad
573 0 : write (*, '(A)')
574 0 : write (*, 1) 'guess logT', logT_guess
575 0 : write (*, 1) 'found logT', logT_result
576 0 : write (*, 1) 'wanted egas', egas_want
577 0 : write (*, 1) 'got egas', egas
578 0 : write (*, 1) '(want - got)/got', (egas_want - egas)/egas
579 0 : write (*, '(A)')
580 0 : write (*, *) 'eos_calls', eos_calls
581 0 : write (*, '(A)')
582 :
583 0 : end subroutine test1_eosDT_get_T_given_egas
584 :
585 16 : subroutine Do_One_TRho(quietly, T, Rho, X, Zinit, dXC, dXO, Y, Z, res)
586 : logical, intent(in) :: quietly
587 : real(dp), intent(in) :: T, Rho, X, Zinit, dXC, dXO
588 : real(dp), intent(out) :: Y, Z
589 : real(dp), intent(out), dimension(num_eos_basic_results) :: res
590 :
591 : real(dp), dimension(num_eos_basic_results) :: &
592 : d_dlnd, d_dlnT
593 : real(dp), dimension(num_eos_d_dxa_results, species) :: &
594 : d_dxa
595 : integer :: info, i
596 : real(dp) :: Prad, Pgas, P
597 :
598 : 101 format(a30, 4x, 1pe24.16)
599 : 102 format(a30, 3x, 1pe24.16)
600 :
601 16 : Z = Zinit + dXC + dXO
602 16 : Y = 1 - (X + Z)
603 :
604 16 : call Init_Composition(X, Zinit, dXC, dXO)
605 :
606 16 : if (.not. quietly) then
607 16 : write (*, '(A)')
608 16 : write (*, '(A)')
609 16 : write (*, 102) 'X', X
610 16 : write (*, 102) 'Y', Y
611 16 : write (*, 102) 'Z', Z
612 16 : write (*, 102) 'abar', abar
613 16 : write (*, 102) 'zbar', zbar
614 16 : write (*, 102) 'logRho', log10(Rho)
615 16 : write (*, 102) 'logT', log10(T)
616 16 : write (*, 102) 'T6', T*1d-6
617 16 : write (*, '(A)')
618 : end if
619 :
620 : call eosDT_get( &
621 : handle, &
622 : species, chem_id, net_iso, xa, &
623 : Rho, arg_not_provided, T, arg_not_provided, &
624 16 : res, d_dlnd, d_dlnT, d_dxa, info)
625 16 : if (info /= 0) then
626 0 : write (*, *) 'info', info, 'Rho', Rho, 'T', T
627 0 : write (*, *) 'failed in Do_One_TRho'
628 0 : call mesa_error(__FILE__, __LINE__)
629 : end if
630 :
631 16 : if (.not. quietly) then
632 :
633 16 : write (*, *) 'eosDT_get'
634 16 : Prad = crad*T*T*T*T/3
635 16 : Pgas = exp(res(i_lnPgas))
636 16 : P = Pgas + Prad
637 16 : write (*, 101) 'P', P
638 16 : write (*, 101) 'E', exp(res(i_lnE))
639 16 : write (*, 101) 'S', exp(res(i_lnS))
640 112 : do i = 4, 9
641 112 : write (*, 101) trim(eos_names(i)), res(i)
642 : end do
643 16 : write (*, 101) trim(eos_names(i_gamma1)), res(i_gamma1)
644 16 : write (*, 101) trim(eos_names(i_gamma3)), res(i_gamma3)
645 16 : write (*, 101) trim(eos_names(i_eta)), res(i_eta)
646 :
647 : if (.false.) then ! debugging
648 : do i = 1, num_eos_basic_results
649 : write (*, 101) 'd_dlnd '//trim(eos_names(i)), d_dlnd(i)
650 : end do
651 : write (*, '(A)')
652 : do i = 1, num_eos_basic_results
653 : write (*, 101) 'd_dlnT '//trim(eos_names(i)), d_dlnT(i)
654 : end do
655 : write (*, '(A)')
656 : end if
657 :
658 : end if
659 :
660 16 : end subroutine Do_One_TRho
661 :
662 0 : subroutine test_dirac_integrals
663 : real(dp) :: T, eta, theta, fdph, fdmh, fdeta, fdtheta, theta_e
664 : 1 format(a40, 1pe26.16)
665 0 : eta = 1.46722890948893d0
666 0 : T = 11327678.5183021d0
667 0 : theta = (kerg*T)/(me*clight*clight)
668 : !zt 1.55623520289424d0
669 0 : theta_e = 0.929542529701454d0
670 0 : call eos_fermi_dirac_integral(-0.5d0, eta, theta, fdmh, fdeta, fdtheta)
671 0 : call eos_fermi_dirac_integral(0.5d0, eta, theta, fdph, fdeta, fdtheta)
672 0 : write (*, '(A)')
673 0 : write (*, *) 'test_dirac_integrals'
674 0 : write (*, 1) 'calculated theta_e', fdmh/fdph
675 0 : write (*, '(A)')
676 0 : stop
677 : end subroutine test_dirac_integrals
678 :
679 : end module test_eos_support
|