46 character(len=std_len) :: AMRVAC_DIR
71 subroutine eos_read_params(files)
72 character(len=*),
intent(in) :: files(:)
79 character(len=std_len) :: eos_type, table_location
80 character(len=20) :: eos_method, gamma1_method, p2eint_method, pi_table
81 double precision :: He_abundance, gamma
84 namelist /eos_list/ eos_type, table_location, ione, he_abundance, gamma, &
85 eos_method, gamma1_method, p2eint_method, pi_table
90 pi_table =
'chromosphere'
91 gamma1_method =
'exact'
92 p2eint_method =
'table'
96 call get_environment_variable(
"AMRVAC_DIR", amrvac_dir)
97 table_location = trim(amrvac_dir)//
"/src/tables/eos_tables/uniform256/"
100 do n = 1,
size(files)
101 open(
unitpar, file=trim(files(n)), status=
"old")
102 read(
unitpar, eos_list,
end=111)
107 eos%eos_type = eos_type
108 eos%method = eos_method
109 eos%pi_table = pi_table
110 eos%gamma1_method = gamma1_method
111 eos%p2eint_method = p2eint_method
112 eos%table_location = table_location
113 eos%He_abundance = he_abundance
118 eos%gamma_minus_1 =
eos%gamma - 1.0d0
119 eos%inv_gamma = 1.0d0 /
eos%gamma
120 if (abs(
eos%gamma_minus_1) > 1.0
d-12)
then
121 eos%inv_gamma_minus_1 = 1.0d0 /
eos%gamma_minus_1
123 eos%inv_gamma_minus_1 = 0.0d0
125 eos%nH2rhoFactor = 1.0d0
126 select case (
eos%method)
131 select case (
eos%eos_type)
139 write(*,*)
"EoS type: "//trim(
eos%eos_type)
140 if (
eos%eos_type ==
'LTE') &
141 write(*,*)
"EoS table location: "//trim(
eos%table_location)
145 call eos_validate_params()
147 end subroutine eos_read_params
153 subroutine eos_validate_params()
156 if (eos%eos_type ==
'FI' .and. eos%ionE)
then
158 if(mype==0)
write(*,*)
"WARNING: eos_type = 'FI' requires ionE = .false."
162 if (eos%eos_type ==
'PI')
then
163 select case (trim(eos%pi_table))
164 case (
'chromosphere',
'flare',
'prominence')
167 call mpistop(
"eos_type='PI': pi_table must be "// &
168 "'chromosphere', 'flare', or 'prominence'")
177 if (eos%ionE .and. trim(eos%pi_table) ==
'prominence')
then
178 call mpistop(
"eos_type='PI' with ionE=T requires a T-only table "// &
179 "(chromosphere or flare); prominence is no-energy only")
181 if(mype==0)
write(*,*)
"EoS PI table: "//trim(eos%pi_table)// &
187 if (eos%method /=
'analytic' .and. eos%method /=
'state' &
188 .and. eos%method /=
'tables' .and. eos%method_id /= eos_entropy)
then
189 call mpistop(
"Unknown eos_method: "//trim(eos%method)// &
190 " (expected 'state', 'analytic', or 'entropy')")
192 if (eos%eos_type ==
'FI' .and. eos%method_id == eos_analytic)
then
193 call mpistop(
"eos_method='analytic' requires eos_type='LTE'")
197 if (eos%gamma1_method /=
'exact' .and. eos%gamma1_method /=
'effective' &
198 .and. eos%gamma1_method /=
'constant')
then
199 call mpistop(
"Unknown gamma1_method: "//trim(eos%gamma1_method)// &
200 " (expected 'exact', 'effective', or 'constant')")
204 if (eos%method_id == eos_analytic)
then
205 if (eos%He_abundance > 0.0d0 .and. mype == 0)
write(*,*) &
206 "WARNING: eos_method='analytic' is H-only. He_abundance=", &
207 eos%He_abundance,
" used in pressure law but not in Saha ionization."
209 if (eos%gamma1_method ==
'effective')
then
210 if (mype == 0)
write(*,*) &
211 "WARNING: gamma1_method='effective' not applicable with analytic EoS."
212 if (mype == 0)
write(*,*) &
213 " Falling back to gamma1_method='exact' (analytic 2D table)."
214 eos%gamma1_method =
'exact'
216 if (.not. eos%ionE .and. mype == 0)
then
217 write(*,*)
"WARNING: eos_method='analytic' without ionE"
218 write(*,*)
" reduces to ideal gas. Consider eos_type='FI'."
223 if (eos%eos_type ==
'LTE' .and. eos%ionE .and. &
224 eos%gamma1_method ==
'effective')
then
225 if (mype == 0)
write(*,*) &
226 "NOTE: gamma1_method='effective' builds gamma_eff = 1+p/eint table."
229 end subroutine eos_validate_params
236 call eos_read_params(par_files)
239 eos%get_rho => get_rho
241 eos%get_ne_nH => get_ne_nh
246 select case (eos%eos_type)
247 case (
'FI');
call eos_init_fi()
248 case (
'LTE');
call eos_init_lte()
249 case (
'PI');
call eos_init_pi()
251 call mpistop(
'eos_init: eos_type '//trim(eos%eos_type)//
' not recognised')
265 if (.not.
allocated(eos)) &
266 call mpistop(
'eos_finalise: eos not allocated')
268 select case (eos%eos_type)
270 call eos_finalise_lte()
272 call eos_finalise_fi()
274 call eos_finalise_pi()
276 call mpistop(
'eos_finalise: eos_type '//trim(eos%eos_type)//
' not recognised')
279 eos%get_temperature_from_etot => get_temperature_from_etot
283 integer :: iigrid, igrid
286 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
287 call eos%update_eos(ixg^ll,ixg^ll,ps(igrid)%w,ps(igrid)%x)
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
LTE method selector, decoded once from eosmethod into eosmethod_id so the runtime kernels dispatch on...
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 H-only Saha EoS (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, 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 eos_finalise()
Phase 'commit' (after units are known): finalise the dispatch for the loaded physics – wire the metho...
subroutine, public prepare_eos_w_fields()
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