50 call mpistop(
"FFHD: ffhd_energy=.false. requires eos_type='FI'")
55 if (
eos%eos_type ==
'FI' .or.
eos%eos_type ==
'PI')
then
58 else if (
eos%eos_type ==
'LTE')
then
59 eos%to_conserved => ffhd_to_conserved_lte
60 eos%to_primitive => ffhd_to_primitive_lte
62 call mpistop(
"Unknown FFHD EOS type: " // trim(
eos%eos_type))
72 eos%p_to_e => ffhd_p_to_e
78 if (
eos%eos_type ==
'LTE')
then
81 eos%get_thermal_pressure => ffhd_get_pthermal_lte
101 if (
eos%eos_type ==
'LTE' .and.
eos%ionE)
then
102 eos%get_csound2 => ffhd_get_csound2_lte
113 if (
eos%eos_type ==
'PI')
then
125 eos%get_Rfactor => rfactor_from_constant_ionization
136 if (
eos%eos_type ==
'PI' .and.
eos%ionE)
then
138 call mpistop(
'FFHD PI energy EoS requires ffhd_energy=.true.')
139 eos%to_conserved => ffhd_to_conserved_pi
140 eos%to_primitive => ffhd_to_primitive_pi
145 eos%p_to_e => ffhd_p_to_e_pi
148 eos%get_thermal_pressure => ffhd_get_pthermal_pi
158 subroutine ffhd_bind_eos_to_source()
165 if (
allocated(
tc_fl))
then
166 tc_fl%get_temperature_from_conserved =>
eos%get_temperature_from_etot
167 if (
eos%eos_type ==
'LTE' .and.
eos%ionE)
then
171 tc_fl%get_temperature_from_eint =>
eos%get_temperature_from_eint
172 tc_fl%frozen_ion = .false.
176 tc_fl%get_var_Rfactor =>
eos%get_Rfactor
177 tc_fl%inv_gamma_minus_1 =
eos%inv_gamma_minus_1
178 tc_fl%nH2rhoFactor =
eos%nH2rhoFactor
179 tc_fl%log_T_floor = eos_get_log_t_floor()
184 tc_fl%eos_lte = (
eos%eos_type ==
'LTE')
188 if (
allocated(
rc_fl))
then
190 rc_fl%get_pthermal =>
eos%get_thermal_pressure
191 rc_fl%get_var_Rfactor =>
eos%get_Rfactor
196 rc_fl%inv_gamma_minus_1 =
eos%inv_gamma_minus_1
197 rc_fl%nH2rhoFactor =
eos%nH2rhoFactor
203 rc_fl%log_T_floor = eos_get_log_t_floor()
205 if (
eos%ionE .and.
eos%eos_type ==
'LTE')
then
213 if (
eos%eos_type ==
'PI' .and.
eos%ionE)
then
215 if (
allocated(
rc_fl))
then
232 end subroutine ffhd_bind_eos_to_source
241 subroutine ffhd_to_conserved_lte(ixI^L, ixO^L, w, x)
243 integer,
intent(in) :: ixi^
l, ixo^
l
244 double precision,
intent(inout) :: w(ixi^s, nw)
245 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
247 call ffhd_p_to_e(ixi^
l, ixo^
l, w, x)
248 w(ixo^s,
mom(1)) = w(ixo^s,
rho_)*w(ixo^s,
mom(1))
249 end subroutine ffhd_to_conserved_lte
253 subroutine ffhd_p_to_e(ixI^L, ixO^L, w, x)
255 integer,
intent(in) :: ixi^
l, ixo^
l
256 double precision,
intent(inout) :: w(ixi^s, nw)
257 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
260 double precision :: nh(ixi^s), log_nh(ixi^s)
264 call eos%get_nH(w, x, ixi^
l, ixo^
l, nh)
265 log_nh(ixo^s) = 0.0d0
266 if (
eos%ionE) log_nh(ixo^s) = dlog10(nh(ixo^s))
268 {
do ix^db=ixomin^db,ixomax^db\}
272 end subroutine ffhd_p_to_e
277 subroutine ffhd_to_primitive_lte(ixI^L, ixO^L, w, x)
279 integer,
intent(in) :: ixi^
l, ixo^
l
280 double precision,
intent(inout) :: w(ixi^s, nw)
281 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
283 double precision :: inv_rho
284 double precision :: nh(ixi^s), log_nh(ixi^s)
285 double precision :: eint_val
289 call ffhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l, &
290 'ffhd_to_primitive_LTE')
293 call eos%get_nH(w, x, ixi^
l, ixo^
l, nh)
294 if (eos%ionE) log_nh(ixo^s) = dlog10(nh(ixo^s))
296 {
do ix^db=ixomin^db,ixomax^db\}
297 inv_rho = 1.d0/w(ix^
d,rho_)
298 w(ix^
d,mom(1)) = w(ix^
d,mom(1))*inv_rho
299 if (ffhd_energy)
then
300 eint_val = w(ix^
d,e_) - half*w(ix^
d,rho_)*w(ix^
d,mom(1))**2
301 w(ix^
d,p_) = lte_p_from_eint(eint_val, nh(ix^
d), log_nh(ix^
d), inv_rho)
304 end subroutine ffhd_to_primitive_lte
309 subroutine ffhd_get_pthermal_lte(w, x, ixI^L, ixO^L, pth)
312 integer,
intent(in) :: ixi^
l, ixo^
l
313 double precision,
intent(in) :: w(ixi^s, 1:nw)
314 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
315 double precision,
intent(out):: pth(ixi^s)
317 double precision :: nh(ixi^s)
319 if (ffhd_energy)
then
320 call eos%get_nH(w, x, ixi^
l, ixo^
l, nh)
321 pth(ixo^s) = nh(ixo^s) * (1.0d0 + eos%He_abundance &
322 + (w(ixo^s,iw_ne) / nh(ixo^s))) * w(ixo^s,iw_te)
324 pth(ixo^s) = ffhd_adiab * w(ixo^s, rho_)**eos%gamma
328 {
do ix^db= ixo^lim^db\}
331 else if (check_small_values)
then
332 {
do ix^db= ixo^lim^db\}
333 if(pth(ix^d)<small_pressure)
then
334 write(*,*)
"Error: small value of gas pressure",pth(ix^d),&
335 " encountered when call ffhd_get_pthermal_LTE"
336 write(*,*)
"Iteration: ", it,
" Time: ", global_time
337 write(*,*)
"Location: ", x(ix^d,:)
338 write(*,*)
"Cell number: ", ix^d
340 write(*,*) trim(cons_wnames(iw)),
": ",w(ix^d,iw)
342 if(trace_small_values)
write(*,*) dsqrt(pth(ix^d)-bigdouble)
343 write(*,*)
"Saving status at the previous time step"
348 end subroutine ffhd_get_pthermal_lte
351 subroutine ffhd_get_csound2_lte(w, x, ixI^L, ixO^L, cs2)
353 integer,
intent(in) :: ixi^
l, ixo^
l
354 double precision,
intent(in) :: w(ixi^s, nw)
355 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
356 double precision,
intent(out) :: cs2(ixi^s)
359 call ffhd_get_gamma1_lte(w, x, ixi^
l, ixo^
l, cs2)
360 {
do ix^db=ixomin^db,ixomax^db\}
361 cs2(ix^
d) = cs2(ix^
d) * w(ix^
d, p_) / w(ix^
d, rho_)
363 end subroutine ffhd_get_csound2_lte
366 subroutine ffhd_get_gamma1_lte(w, x, ixI^L, ixO^L, gamma1)
368 integer,
intent(in) :: ixi^
l, ixo^
l
369 double precision,
intent(in) :: w(ixi^s, nw)
370 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
371 double precision,
intent(out) :: gamma1(ixi^s)
374 if (eos%gamma1_method ==
'constant')
then
375 gamma1(ixo^s) = eos%gamma
379 {
do ix^db=ixomin^db,ixomax^db\}
380 gamma1(ix^
d) = lte_gamma1_from_p(w(ix^
d,p_), w(ix^
d,rho_))
382 end subroutine ffhd_get_gamma1_lte
387 subroutine ffhd_to_prolong_lte(ixI^L, ixO^L, w, x)
388 integer,
intent(in) :: ixi^l, ixo^l
389 double precision,
intent(inout) :: w(ixi^s, nw)
390 double precision,
intent(in) :: x(ixi^s, 1:ndim)
392 double precision :: inv_rho, eint_val, nh_val, log_nh, t_loc, y_loc
395 {
do ix^db=ixomin^db,ixomax^db\}
396 inv_rho = 1.d0 / w(ix^d, rho_)
397 nh_val = w(ix^d, rho_) / eos%nH2rhoFactor
398 log_nh = dlog10(nh_val)
400 w(ix^d,mom(1)) = w(ix^d,mom(1))*inv_rho
402 eint_val = w(ix^d, e_) - half*w(ix^d, rho_)*w(ix^d,mom(1))**2
403 eint_val = max(eint_val, nh_val*eos%eint_nH_min, smalldouble)
405 if (eint_val * inv_rho > eos%eint_rho_FI_threshold)
then
406 w(ix^d, e_) = eos%gamma_minus_1 &
407 * (eint_val - eos%eion_per_nH * nh_val) &
408 / (nh_val * eos%n_per_nH_FI)
409 else if (eos%method_id == eos_analytic)
then
410 call saha_t_from_nh_eint(nh_val, eint_val / nh_val, t_loc, y_loc)
413 w(ix^d, e_) = t_from_nh_eint(log_nh, &
414 dlog10(eint_val) - log_nh)
417 end subroutine ffhd_to_prolong_lte
421 subroutine ffhd_from_prolong_lte(ixI^L, ixO^L, w, x)
422 integer,
intent(in) :: ixi^l, ixo^l
423 double precision,
intent(inout) :: w(ixi^s, nw)
424 double precision,
intent(in) :: x(ixi^s, 1:ndim)
426 double precision :: t_val, eint_val, t_fi, nh_val, log_nh, log_t_min
429 t_fi = (eos%eint_rho_FI_threshold &
430 * eos%nH2rhoFactor - eos%eion_per_nH) &
431 * eos%gamma_minus_1 / eos%n_per_nH_FI
433 if (eos%method_id == eos_entropy)
then
434 log_t_min = eos%eintT%var2_min
436 log_t_min = eos%eint_from_T%var2_min
439 {
do ix^db=ixomin^db,ixomax^db\}
441 nh_val = w(ix^d, rho_) / eos%nH2rhoFactor
442 log_nh = dlog10(nh_val)
444 if (t_val > t_fi)
then
446 * (eos%n_per_nH_FI * t_val * eos%inv_gamma_minus_1 &
448 else if (eos%method_id == eos_analytic)
then
449 eint_val = saha_eint_from_nh_t(nh_val, t_val) * nh_val
451 eint_val = eint_nh_from_t(log_nh, &
452 dlog10(max(t_val, 10.0d0**log_t_min))) * nh_val
455 w(ix^d, e_) = eint_val + half*w(ix^d, rho_)*w(ix^d,mom(1))**2
456 w(ix^d,mom(1)) = w(ix^d,rho_)*w(ix^d,mom(1))
458 end subroutine ffhd_from_prolong_lte
469 subroutine ffhd_p_to_e_pi(ixI^L, ixO^L, w, x)
471 integer,
intent(in) :: ixi^
l, ixo^
l
472 double precision,
intent(inout) :: w(ixi^s, nw)
473 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
474 double precision :: eint
477 {
do ix^db=ixomin^db,ixomax^db\}
478 if (ffhd_energy)
then
479 call eint_from_rho_p_pi(w(ix^
d,rho_), w(ix^
d,p_), eint)
480 w(ix^
d,e_) = eint + half*w(ix^
d,mom(1))**2*w(ix^
d,rho_)
483 end subroutine ffhd_p_to_e_pi
486 subroutine ffhd_to_conserved_pi(ixI^L, ixO^L, w, x)
488 integer,
intent(in) :: ixi^
l, ixo^
l
489 double precision,
intent(inout) :: w(ixi^s, nw)
490 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
492 call ffhd_p_to_e_pi(ixi^
l, ixo^
l, w, x)
493 w(ixo^s,mom(1)) = w(ixo^s,rho_)*w(ixo^s,mom(1))
494 end subroutine ffhd_to_conserved_pi
497 subroutine ffhd_to_primitive_pi(ixI^L, ixO^L, w, x)
499 integer,
intent(in) :: ixi^
l, ixo^
l
500 double precision,
intent(inout) :: w(ixi^s, nw)
501 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
502 double precision :: inv_rho, eint_val, t, rfac
506 call ffhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l, &
507 'ffhd_to_primitive_PI')
510 {
do ix^db=ixomin^db,ixomax^db\}
511 inv_rho = 1.d0/w(ix^
d,rho_)
512 w(ix^
d,mom(1)) = w(ix^
d,mom(1))*inv_rho
513 if (ffhd_energy)
then
514 eint_val = w(ix^
d,e_) - half*w(ix^
d,rho_)*w(ix^
d,mom(1))**2
515 eint_val = max(eint_val, smalldouble)
516 call state_from_eint_pi(w(ix^
d,rho_), eint_val, &
520 end subroutine ffhd_to_primitive_pi
523 subroutine ffhd_get_pthermal_pi(w, x, ixI^L, ixO^L, pth)
525 integer,
intent(in) :: ixi^
l, ixo^
l
526 double precision,
intent(in) :: w(ixi^s, 1:nw), x(ixi^s, 1:
ndim)
527 double precision,
intent(out):: pth(ixi^s)
528 double precision :: ei(ixi^s), tpi, rpi
531 ei(ixo^s) = ffhd_get_ei(w, ixi^
l, ixo^
l)
532 {
do ix^db=ixomin^db,ixomax^db\}
533 call state_from_eint_pi(w(ix^
d,rho_), ei(ix^
d), tpi, pth(ix^
d), rpi)
535 end subroutine ffhd_get_pthermal_pi
540 subroutine rfactor_from_constant_ionization(w,x,ixI^L,ixO^L,Rfactor)
542 integer,
intent(in) :: ixi^
l, ixo^
l
543 double precision,
intent(in) :: w(ixi^s,1:nw)
544 double precision,
intent(in) :: x(ixi^s,1:
ndim)
545 double precision,
intent(out):: rfactor(ixi^s)
549 end subroutine rfactor_from_constant_ionization
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
type(eos_container), allocatable, public eos
The single EoS state object, allocated in eos_init and shared (read-mostly) across all EoS sub-module...
Analytic hydrogen Saha EoS with neutral helium (eos_method == 'analytic').
LTE (Saha-table) EoS kernels and finalise for the eos% family.
double precision function, public lte_eint_from_p(pres, nh_val, log_nh_val, rho_val)
LTE internal energy from pressure in one cell: FI bypass, else eint(nH, p).
double precision function, public p2eint_from_nh_p(nh, ponh)
Ratio eint/p from (log10 nH, log10 p/nH).
double precision function, public eint_nh_from_t(log_nh, log_t)
eint/nH from (log10 nH, log10 T), from the inverse table when one is built and the Saha solve otherwi...
double precision function, public y_from_nh_eint(nh, eint_nh)
Scalar EoS kernels: one cell on (log10 nH, log10 eint/nH) or (log10 nH, log10 p/nH),...
subroutine, public get_temperature_from_eint_fast_lte(w, x, ixil, ixol, res)
subroutine, public eos_get_eintt_grid(n_nh, lg_nh_min, lg_nh_max)
####################################################################### Table-metadata helpers: expos...
double precision function, public t_from_nh_eint(nh, eint_nh)
Temperature from (log10 nH, log10 eint/nH).
PI (partial-ionisation, eos_type='PI') arm of the eos% family.
double precision function, dimension(log_nh, log_p_nh), public p2eint_pi(log_nh, log_p_nh)
eint/p factor from pressure per H: maps p -> eint = p * (this).
double precision function, dimension(log_nh, log_t), public eint_from_t_pi(log_nh, log_t)
Internal energy per H from temperature: eint/nH(T).
double precision function, dimension(log_nh, log_eint_nh), public y_from_eint_pi(log_nh, log_eint_nh)
Electron-to-hydrogen ratio ne/nH from internal energy per H. ne/nH = iz_H + A_He*iz_He*(1+iz_He) (mat...
subroutine, public get_gamma1_pi(w, x, ixil, ixol, gamma1)
Effective Gamma1 = cs2 * rho / p for the same primitive state.
double precision function, dimension(log_nh, log_eint_nh), public t_from_eint_pi(log_nh, log_eint_nh)
Temperature from internal energy per H.
Equation of state for AMRVAC, handled through a single eos_container object.
FFHD <-> EoS seam: binds the eos% authority into force-free hydrodynamics.
subroutine, public ffhd_link_eos()
Link the appropriate EoS conversion/closure routines per eos_type. Called from ffhd_activate after ff...
Frozen-field hydrodynamics module.
integer, public, protected e_
Index of the energy density (-1 if not present).
subroutine, public ffhd_to_primitive_origin(ixil, ixol, w, x)
procedure(sub_get_pthermal), pointer, public ffhd_get_rfactor
procedure(sub_get_pthermal), pointer, public ffhd_get_temperature
type(rc_fluid), allocatable, public rc_fl
type of fluid for radiative cooling
integer, public, protected rho_
Whether plasma is partially ionized.
procedure(sub_get_pthermal), pointer, public ffhd_get_pthermal
procedure(sub_convert), pointer, public ffhd_to_conserved
integer, dimension(:), allocatable, public, protected mom
Indices of the momentum density.
subroutine, public ffhd_get_temperature_from_etot(w, x, ixil, ixol, res)
subroutine, public ffhd_get_csound2(w, x, ixil, ixol, csound2)
logical, public, protected ffhd_energy
Whether an energy equation is used.
type(tc_fluid), allocatable, public tc_fl
type of fluid for thermal conduction
double precision function, dimension(ixo^s), public ffhd_get_ei(w, ixil, ixol)
Internal energy eint = E_total - E_kinetic (single field-aligned momentum). Wired to phys_get_ei; the...
type(te_fluid), allocatable, public te_fl_ffhd
type of fluid for thermal emission synthesis
subroutine, public ffhd_get_pthermal_origin(w, x, ixil, ixol, pth)
procedure(sub_convert), pointer, public ffhd_to_primitive
subroutine, public ffhd_get_temperature_from_te(w, x, ixil, ixol, res)
subroutine, public ffhd_to_conserved_origin(ixil, ixol, w, x)
subroutine, public ffhd_ei_to_e(ixil, ixol, w, x)
integer, public, protected p_
Index of the gas pressure (-1 if not present) should equal e_.
subroutine, public ffhd_e_to_ei(ixil, ixol, w, x)
This module contains definitions of global parameters and variables and some generic functions/subrou...
double precision small_pressure
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision, dimension(:), allocatable, parameter d
double precision unit_temperature
Physical scaling factor for temperature.
logical fix_small_values
fix small values with average or replace methods
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_check_params), pointer phys_bind_eos_to_source
procedure(sub_convert), pointer phys_to_primitive
procedure(sub_e_to_ei), pointer phys_e_to_ei
procedure(sub_e_to_ei), pointer phys_ei_to_e
procedure(sub_get_pthermal), pointer phys_get_gamma1
procedure(sub_get_pthermal), pointer phys_get_pthermal
procedure(sub_get_ei), pointer phys_get_ei
procedure(sub_convert), pointer phys_to_prolong
procedure(sub_convert), pointer phys_to_conserved
procedure(sub_convert), pointer phys_from_prolong
procedure(sub_get_rho), pointer phys_get_rho
module radiative cooling – add optically thin radiative cooling
double precision, parameter rc_t_ymod_max_k
Temperature in K above which c_V is constant, the upper end of the Y_mod path.
subroutine build_y_mod_table(fl)
===================================================================
Module for handling problematic values in simulations, such as negative pressures.
logical, public trace_small_values
trace small values in the source file using traceback flag of compiler
Thermal conduction for HD and MHD or RHD and RMHD or twofl (plasma-neutral) module Adaptation of mod_...
subroutine, public tc_set_saturation(fl, report)
Saturated flux factor. q_sat = 5 phi rho c**3 (Cowie & McKee 1977 eq 8), c**2 = xt kT/m_p with xt the...
Module with all the methods that users can customize in AMRVAC.
procedure(rfactor), pointer usr_rfactor