47 character(len=std_len) :: AMRVAC_DIR
70 procedure(convert_condition),
pointer :: to_primitive_impl => null(), &
71 to_conserved_impl => null()
72 procedure(update_eos_spaces),
pointer :: update_eos_impl => null()
73 procedure(get_eos_variable_alt),
pointer :: pthermal_impl => null(), csound2_impl => null(), &
74 tfromei_impl => null()
81 subroutine eos_read_params(files)
82 character(len=*),
intent(in) :: files(:)
89 character(len=std_len) :: eos_type, table_location
90 character(len=20) :: eos_method, gamma1_method, p2eint_method, pi_table
91 double precision :: He_abundance, gamma
94 namelist /eos_list/ eos_type, table_location, ione, he_abundance, gamma, &
95 eos_method, gamma1_method, p2eint_method, pi_table
99 eos_method =
'entropy'
100 pi_table =
'chromosphere'
101 gamma1_method =
'exact'
102 p2eint_method =
'table'
110 do n = 1,
size(files)
111 open(
unitpar, file=trim(files(n)), status=
"old")
112 read(
unitpar, eos_list,
end=111)
118 if (len_trim(table_location) == 0)
then
119 call get_environment_variable(
"AMRVAC_DIR", amrvac_dir)
120 if (trim(eos_method) ==
'entropy')
then
121 table_location = trim(amrvac_dir)//
"/src/tables/eos_tables/entropy128/"
123 table_location = trim(amrvac_dir)//
"/src/tables/eos_tables/uniform256/"
128 eos%eos_type = eos_type
129 eos%method = eos_method
130 eos%pi_table = pi_table
131 eos%gamma1_method = gamma1_method
132 eos%p2eint_method = p2eint_method
133 eos%table_location = table_location
134 eos%He_abundance = he_abundance
139 eos%gamma_minus_1 =
eos%gamma - 1.0d0
140 eos%inv_gamma = 1.0d0 /
eos%gamma
141 if (abs(
eos%gamma_minus_1) > 1.0
d-12)
then
142 eos%inv_gamma_minus_1 = 1.0d0 /
eos%gamma_minus_1
144 eos%inv_gamma_minus_1 = 0.0d0
146 eos%nH2rhoFactor = 1.0d0
147 select case (
eos%method)
152 select case (
eos%eos_type)
160 write(*,*)
"EoS type: "//trim(
eos%eos_type)
161 if (
eos%eos_type ==
'LTE') &
162 write(*,*)
"EoS table location: "//trim(
eos%table_location)
166 call eos_validate_params()
168 end subroutine eos_read_params
174 subroutine eos_validate_params()
177 if (eos%eos_type ==
'FI' .and. eos%ionE)
then
179 if(mype==0)
write(*,*)
"WARNING: eos_type = 'FI' requires ionE = .false."
183 if (eos%eos_type ==
'PI')
then
186 call mpistop(
"eos_type='PI' is not yet fully consistently implemented, "// &
187 "use eos_type='FI' or 'LTE'")
188 select case (trim(eos%pi_table))
189 case (
'chromosphere',
'flare',
'prominence')
192 call mpistop(
"eos_type='PI': pi_table must be "// &
193 "'chromosphere', 'flare', or 'prominence'")
202 if (eos%ionE .and. trim(eos%pi_table) ==
'prominence')
then
203 call mpistop(
"eos_type='PI' with ionE=T requires a T-only table "// &
204 "(chromosphere or flare); prominence is no-energy only")
206 if(mype==0)
write(*,*)
"EoS PI table: "//trim(eos%pi_table)// &
212 if (eos%method /=
'analytic' .and. eos%method /=
'state' &
213 .and. eos%method /=
'tables' .and. eos%method_id /= eos_entropy)
then
214 call mpistop(
"Unknown eos_method: "//trim(eos%method)// &
215 " (expected 'state', 'analytic', or 'entropy')")
217 if (eos%eos_type ==
'FI' .and. eos%method_id == eos_analytic)
then
218 call mpistop(
"eos_method='analytic' requires eos_type='LTE'")
222 if (eos%gamma1_method /=
'exact' .and. eos%gamma1_method /=
'effective' &
223 .and. eos%gamma1_method /=
'constant')
then
224 call mpistop(
"Unknown gamma1_method: "//trim(eos%gamma1_method)// &
225 " (expected 'exact', 'effective', or 'constant')")
229 if (eos%method_id == eos_analytic)
then
230 if (eos%He_abundance > 0.0d0 .and. mype == 0)
write(*,*) &
231 "eos_method='analytic' keeps helium neutral, He_abundance=", eos%He_abundance
233 if (eos%gamma1_method ==
'effective')
then
234 if (mype == 0)
write(*,*) &
235 "WARNING: gamma1_method='effective' not applicable with analytic EoS."
236 if (mype == 0)
write(*,*) &
237 " Falling back to gamma1_method='exact' (closed form)."
238 eos%gamma1_method =
'exact'
240 if (.not. eos%ionE .and. mype == 0)
then
241 write(*,*)
"WARNING: eos_method='analytic' without ionE"
242 write(*,*)
" reduces to ideal gas. Consider eos_type='FI'."
247 if (eos%eos_type ==
'LTE' .and. eos%ionE .and. &
248 eos%gamma1_method ==
'effective')
then
249 if (mype == 0)
write(*,*) &
250 "NOTE: gamma1_method='effective' builds gamma_eff = 1+p/eint table."
253 end subroutine eos_validate_params
260 call eos_read_params(par_files)
263 eos%get_rho => get_rho
265 eos%get_ne_nH => get_ne_nh
270 select case (eos%eos_type)
271 case (
'FI');
call eos_init_fi()
272 case (
'LTE');
call eos_init_lte()
273 case (
'PI');
call eos_init_pi()
275 call mpistop(
'eos_init: eos_type '//trim(eos%eos_type)//
' not recognised')
289 if (.not.
allocated(eos)) &
290 call mpistop(
'eos_finalise: eos not allocated')
294 eos%p2eint_bisect = (eos%p2eint_method ==
'bisect')
296 select case (eos%eos_type)
298 call eos_finalise_lte()
300 call eos_finalise_fi()
302 call eos_finalise_pi()
304 call mpistop(
'eos_finalise: eos_type '//trim(eos%eos_type)//
' not recognised')
307 eos%get_temperature_from_etot => get_temperature_from_etot
310 if (eos%type_id == eos_type_lte)
then
311 if (eos%method_id == eos_analytic)
then
312 eos%eint_nH_min = eos%inv_gamma_minus_1 * 100.0d0 / unit_temperature
314 eos%eint_nH_min = 10.0d0**eos%T%var2_min
317 call eos_time_dispatch()
323 subroutine eos_time_dispatch()
326 if (
associated(eos%to_primitive))
then
327 to_primitive_impl => eos%to_primitive
328 eos%to_primitive => timed_to_primitive
332 if (
associated(eos%to_conserved))
then
333 to_conserved_impl => eos%to_conserved
334 eos%to_conserved => timed_to_conserved
338 if (
associated(eos%get_thermal_pressure))
then
339 pthermal_impl => eos%get_thermal_pressure
340 eos%get_thermal_pressure => timed_pthermal
343 if (
associated(eos%update_eos))
then
344 update_eos_impl => eos%update_eos
345 eos%update_eos => timed_update_eos
347 if (
associated(eos%get_csound2))
then
348 csound2_impl => eos%get_csound2
349 eos%get_csound2 => timed_csound2
351 if (
associated(eos%get_temperature_from_eint))
then
352 tfromei_impl => eos%get_temperature_from_eint
353 eos%get_temperature_from_eint => timed_tfromei
355 end subroutine eos_time_dispatch
358 subroutine timed_to_primitive(ixI^L, ixO^L, w, x)
360 integer,
intent(in) :: ixi^l, ixo^l
361 double precision,
intent(inout) :: w(ixi^s,
nw)
362 double precision,
intent(in) :: x(ixi^s, 1:ndim)
363 call eos_timer_start()
364 call to_primitive_impl(ixi^l, ixo^l, w, x)
365 call eos_timer_stop(timeeos_conv)
366 end subroutine timed_to_primitive
368 subroutine timed_to_conserved(ixI^L, ixO^L, w, x)
370 integer,
intent(in) :: ixi^l, ixo^l
371 double precision,
intent(inout) :: w(ixi^s,
nw)
372 double precision,
intent(in) :: x(ixi^s, 1:ndim)
373 call eos_timer_start()
374 call to_conserved_impl(ixi^l, ixo^l, w, x)
375 call eos_timer_stop(timeeos_conv)
376 end subroutine timed_to_conserved
378 subroutine timed_update_eos(ixI^L, ixO^L, w, x)
380 integer,
intent(in) :: ixi^l, ixo^l
381 double precision,
intent(inout) :: w(ixi^s,
nw)
382 double precision,
intent(in) :: x(ixi^s, 1:ndim)
383 call eos_timer_start()
384 call update_eos_impl(ixi^l, ixo^l, w, x)
385 call eos_timer_stop(timeeos_update)
386 end subroutine timed_update_eos
388 subroutine timed_pthermal(w, x, ixI^L, ixO^L, res)
390 integer,
intent(in) :: ixi^l, ixo^l
391 double precision,
intent(in) :: w(ixi^s,
nw), x(ixi^s, 1:ndim)
392 double precision,
intent(out) :: res(ixi^s)
393 call eos_timer_start()
394 call pthermal_impl(w, x, ixi^l, ixo^l, res)
395 call eos_timer_stop(timeeos_pthermal)
396 end subroutine timed_pthermal
398 subroutine timed_csound2(w, x, ixI^L, ixO^L, res)
400 integer,
intent(in) :: ixi^l, ixo^l
401 double precision,
intent(in) :: w(ixi^s,
nw), x(ixi^s, 1:ndim)
402 double precision,
intent(out) :: res(ixi^s)
403 call eos_timer_start()
404 call csound2_impl(w, x, ixi^l, ixo^l, res)
405 call eos_timer_stop(timeeos_csound)
406 end subroutine timed_csound2
408 subroutine timed_tfromei(w, x, ixI^L, ixO^L, res)
410 integer,
intent(in) :: ixi^l, ixo^l
411 double precision,
intent(in) :: w(ixi^s,
nw), x(ixi^s, 1:ndim)
412 double precision,
intent(out) :: res(ixi^s)
413 call eos_timer_start()
414 call tfromei_impl(w, x, ixi^l, ixo^l, res)
415 call eos_timer_stop(timeeos_tfromei)
416 end subroutine timed_tfromei
420 type(state),
intent(inout) :: psx(:)
421 integer :: iigrid, igrid
425 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
426 call eos%update_eos(ixg^ll,ixg^ll,psx(igrid)%w,psx(igrid)%x)
436 fl%get_temperature_from_conserved => eos%get_temperature_from_etot
437 if (eos%eos_type ==
'LTE' .and. eos%ionE)
then
439 fl%get_temperature_from_eint => get_temperature_from_eint_fast_lte
441 fl%get_temperature_from_eint => eos%get_temperature_from_eint
442 fl%frozen_ion = .false.
445 if (eos%eos_type ==
'LTE')
then
446 fl%sat_fac = (eos%n_per_nH_FI/eos%nH2rhoFactor)**1.5d0
448 fl%neOnH_FI = eos%neOnH_FI
450 fl%get_rho => eos%get_rho
451 fl%get_ne_nH => eos%get_ne_nH
452 fl%get_var_Rfactor => eos%get_Rfactor
453 fl%inv_gamma_minus_1 = eos%inv_gamma_minus_1
454 fl%nH2rhoFactor = eos%nH2rhoFactor
455 fl%log_T_floor = eos_get_log_t_floor()
456 fl%eint_from_T => eint_nh_from_t
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
EoS state container – the single thermodynamic authority for AMRVAC.
integer, parameter, public eos_analytic
integer, parameter, public eos_type_pi
integer, parameter, public eos_type_fi
EoS-type selector, decoded once from eoseos_type into eostype_id. Used by the mode-specific kernels t...
integer, parameter, public eos_state
slot interfaces, for routines that hold or wrap an EoS slot
integer, parameter, public eos_entropy
type(eos_container), allocatable, public eos
The single EoS state object, allocated in eos_init and shared (read-mostly) across all EoS sub-module...
integer, parameter, public eos_type_lte
integer, public iw_log_nh
wextra index for the cached log10(nH) used during STS substeps (-1 = not allocated)....
FI (fully-ionised, constant-gamma) EoS kernels for the eos% family.
subroutine, public get_gamma1_fi(w, x, ixil, ixol, gamma1)
Gamma_1 for the fully-ionised ideal gas: constant eosgamma.
Interpolation kernels for the EoS tables (pure math; no EoS state).
Analytic hydrogen Saha EoS with neutral helium (eos_method == 'analytic').
Shared LTE lookup-table infrastructure (build/IO; not on the hot path).
LTE (Saha-table) EoS kernels and finalise for the eos% family.
PI (partial-ionisation, eos_type='PI') arm of the eos% family.
subroutine, public eos_finalise_pi()
PI arm of eos_finalise (after unit_* are set): ride FI's ideal-gas getter set and RR=1 normalisation ...
subroutine, public eos_init_pi()
Lifecycle (PI arms of the eos_init / eos_finalise dispatchers). The eos% block getters (update_eos_PI...
Shared EoS accessors (EoS-type-agnostic) for the eos% family.
subroutine, public get_ne_nh(ixil, ixol, w, x, ne, nh)
Return electron and hydrogen number densities in code units. For LTE (iw_ne allocated): ne from Saha ...
double precision function, public eos_get_log_t_floor()
Lower log10(T) bound for the (rho,T) inverse table; FI (no tables) floors at log10(smalldouble)....
Equation of state for AMRVAC, handled through a single eos_container object.
subroutine, public eos_init()
Phase 'create' (before units are known): allocate the EoS object, read its &eos_list parameters,...
subroutine, public prepare_eos_w_fields(psx)
subroutine, public eos_finalise()
Phase 'commit' (after units are known): finalise the dispatch for the loaded physics – wire the metho...
subroutine, public eos_bind_tc(fl)
The EoS hooks of the conduction fluid fl.
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer, parameter unitpar
file handle for IO
integer mype
The rank of the current MPI task.
double precision, dimension(:), allocatable, parameter d
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_convert), pointer phys_to_primitive
procedure(sub_get_pthermal), pointer phys_get_pthermal
procedure(sub_convert), pointer phys_to_conserved
Thermal conduction for HD and MHD or RHD and RMHD or twofl (plasma-neutral) module Adaptation of mod_...
subroutine eos_timer_start()
Open an EoS timing window; inside an OpenMP parallel region the EoS is not timed.
double precision timeeos_update
double precision timeeos_pthermal
double precision timeeos_conv
subroutine eos_timer_stop(acc)
Close an EoS timing window, adding its time to acc when it is the outermost.
double precision timeeos_csound
double precision timeeos_tfromei
integer nw
Total number of variables.