MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_ffhd_eos.t
Go to the documentation of this file.
1!=============================================================================
2!> FFHD <-> EoS seam: binds the eos% authority into force-free hydrodynamics.
3!>
4!> Mirrors mod_hd_eos.t, adapted to FFHD's structure: a single field-aligned
5!> momentum component mom(1) and NO magnetic energy (force-free, frozen B0), so
6!> every kinetic-energy term is half*rho*mom(1)**2. The B0 projection lives in
7!> the flux/cmax/velocity layer (mod_ffhd_phys.t) and is orthogonal to the EoS
8!> seam, so the thermodynamic conversions are HD-like with one momentum
9!> component.
10!>
11!> ffhd_link_eos -- wires eos%/phys_ pointers per eos_type (FI now;
12!> LTE/PI guarded until milestones 2/3).
13!> ffhd_bind_eos_to_source -- wires the thermal-conduction (tc_fl), radiative-
14!> cooling (rc_fl) and thermal-emission (te_fl_ffhd)
15!> fluid-port callbacks from eos%. This is what the
16!> pre-eos% hand-wiring was missing (rc_fl%get_Te /
17!> get_ne_nH), which caused the cooling SIGSEGV.
18!=============================================================================
21 use mod_physics
22 use mod_eos
23 !> Mode-specific kernels come from their sub-modules (the facade no longer
24 !> re-exports them); each mpistops if called under the wrong eos_type/method.
25 use mod_eos_lte
27 use mod_eos_pi
32
33 use mod_comm_lib, only: mpistop
34
35 implicit none
36 private
37
38 public :: ffhd_link_eos
39
40contains
41
42 !> Link the appropriate EoS conversion/closure routines per eos_type.
43 !> Called from ffhd_activate after ffhd_phys_init (mirrors hd_activate).
44 subroutine ffhd_link_eos()
46
47 ! Isothermal FFHD (no energy equation) has no thermodynamic state for
48 ! the EoS to close -- only FI is meaningful there.
49 if (.not. ffhd_energy .and. eos%eos_type /= 'FI') &
50 call mpistop("FFHD: ffhd_energy=.false. requires eos_type='FI'")
51
52 ! FI / PI base conversions = ffhd's origin routines (single-component
53 ! KE). PI energy mode overrides them below (milestone 3). LTE routes
54 ! primitive<->conserved through ffhd_p_to_e / table inversion.
55 if (eos%eos_type == 'FI' .or. eos%eos_type == 'PI') then
56 eos%to_conserved => ffhd_to_conserved_origin
57 eos%to_primitive => ffhd_to_primitive_origin
58 else if (eos%eos_type == 'LTE') then
59 eos%to_conserved => ffhd_to_conserved_lte
60 eos%to_primitive => ffhd_to_primitive_lte
61 else
62 call mpistop("Unknown FFHD EOS type: " // trim(eos%eos_type))
63 end if
64
65 phys_to_primitive => eos%to_primitive
66 phys_to_conserved => eos%to_conserved
67 ffhd_to_primitive => eos%to_primitive
68 ffhd_to_conserved => eos%to_conserved
69 phys_get_rho => eos%get_rho
70
71 ! suitable for both FI (origin inlines it) and LTE (conversions call it)
72 eos%p_to_e => ffhd_p_to_e
73
74 ! pthermal: the isothermal (no-energy) pointer is wired in phys_init and
75 ! left untouched; for the energy equation route through eos%. LTE reads
76 ! the stored Te_/Ne_ aux state; FI/PI use (gamma-1)*(e-KE).
77 if (ffhd_energy) then
78 if (eos%eos_type == 'LTE') then
79 phys_get_pthermal => ffhd_get_pthermal_lte
80 ffhd_get_pthermal => ffhd_get_pthermal_lte
81 eos%get_thermal_pressure => ffhd_get_pthermal_lte
82 else
85 eos%get_thermal_pressure => ffhd_get_pthermal_origin
86 end if
87 end if
88
89 phys_bind_eos_to_source => ffhd_bind_eos_to_source
90
91 ! Energy<->internal heads: ffhd previously handed these only to the TC
92 ! STS via set_conversion_methods_to_head; the LTE fast-T kernel and
93 ! phys_update_temperature also need the module-level phys_ pointers.
96 phys_get_ei => ffhd_get_ei ! LTE+ionE cooling recovers eint via this
97
98 ! sound speed / gamma1. LTE+ionE: Gamma_1(nH,p) from the EoS tables and
99 ! EoS-aware AMR prolongation (interpolate in (rho,v,T) to avoid Jensen's
100 ! inequality across the ionisation plateau). Otherwise FI: cs2=gamma*p/rho.
101 if (eos%eos_type == 'LTE' .and. eos%ionE) then
102 eos%get_csound2 => ffhd_get_csound2_lte
103 phys_get_gamma1 => ffhd_get_gamma1_lte
104 phys_to_prolong => ffhd_to_prolong_lte
105 phys_from_prolong => ffhd_from_prolong_lte
106 else
107 eos%get_csound2 => ffhd_get_csound2
108 phys_get_gamma1 => get_gamma1_fi
109 end if
110
111 ! ffhd_get_temperature (phys pointer) by eos_type: PI reads the cached
112 ! Te_, the others recompute from etot.
113 if (eos%eos_type == 'PI') then
115 else
117 end if
118 ! Rfactor: only the FI case is physics-dependent (usr_Rfactor). LTE and PI
119 ! bind pure eos% routines in eos_finalise_{LTE,PI} (run after this, before
120 ! ffhd_bind_eos_to_source -> targets stay private). usr_Rfactor thus applies
121 ! to FI only, consistent with mhd/hd.
122 if (associated(usr_rfactor)) then
123 eos%get_Rfactor => usr_rfactor
124 else
125 eos%get_Rfactor => rfactor_from_constant_ionization
126 end if
127 ! ffhd_get_Rfactor (runtime alias) captured in ffhd_bind_eos_to_source,
128 ! AFTER eos_finalise has set eos%get_Rfactor for LTE/PI.
129
130 !> PI energy-mode overrides (eos_type='PI', ionE=.true.). Energy mode
131 !> differs from no-energy PI only in the eint<->p relation (eint carries
132 !> the ionisation energy), so override exactly the routines touching it,
133 !> all via the portable mod_eos_pi backend. get_Rfactor stays the
134 !> Te_-addressed routine above (Te_ refreshed each step by
135 !> ffhd_update_temperature_PI).
136 if (eos%eos_type == 'PI' .and. eos%ionE) then
137 if (.not. ffhd_energy) &
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
141 phys_to_primitive => eos%to_primitive
142 phys_to_conserved => eos%to_conserved
143 ffhd_to_primitive => eos%to_primitive
144 ffhd_to_conserved => eos%to_conserved
145 eos%p_to_e => ffhd_p_to_e_pi
146 phys_get_pthermal => ffhd_get_pthermal_pi
147 ffhd_get_pthermal => ffhd_get_pthermal_pi
148 eos%get_thermal_pressure => ffhd_get_pthermal_pi
149 !> eos%get_csound2 => get_csound2_PI set in eos_finalise_PI (private target)
151 end if
152
153 end subroutine ffhd_link_eos
154
155 !> Wire the source-term fluid ports from eos%. Called from eos_finalise via
156 !> phys_bind_eos_to_source, AFTER eos_finalise has set eos%get_Te,
157 !> get_ne_nH, eion_per_nH, n_per_nH_FI/neOnH_FI, get_temperature_from_*.
158 subroutine ffhd_bind_eos_to_source()
159
160 !> Runtime R-factor alias: eos%get_Rfactor is fully set by now
161 !> (eos_finalise ran before phys_bind_eos_to_source), incl. the LTE/PI
162 !> bindings done in eos_finalise_{LTE,PI}.
163 ffhd_get_rfactor => eos%get_Rfactor
164
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
168 ! the fast bilinear T lookup of the STS substeps
169 tc_fl%get_temperature_from_eint => get_temperature_from_eint_fast_lte
170 else
171 tc_fl%get_temperature_from_eint => eos%get_temperature_from_eint
172 tc_fl%frozen_ion = .false.
173 end if
174 tc_fl%get_rho => eos%get_rho
175 tc_fl%get_ne_nH => eos%get_ne_nH
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()
180 tc_fl%eint_from_T => eint_nh_from_t
181 tc_fl%neOnH_FI = eos%neOnH_FI
182 tc_fl%n_per_nH_FI = eos%n_per_nH_FI
183 tc_fl%mass_per_nH = eos%mass_per_nH
184 tc_fl%eos_lte = (eos%eos_type == 'LTE')
185 call tc_set_saturation(tc_fl,.true.)
186 end if
187
188 if (allocated(rc_fl)) then
189 rc_fl%get_rho => eos%get_rho
190 rc_fl%get_pthermal => eos%get_thermal_pressure
191 rc_fl%get_var_Rfactor => eos%get_Rfactor
192 rc_fl%get_Te => eos%get_Te
193 rc_fl%get_ne_nH => eos%get_ne_nH
194 rc_fl%ionE = eos%ionE
195 rc_fl%method_analytic = (eos%method_id == eos_analytic)
196 rc_fl%inv_gamma_minus_1 = eos%inv_gamma_minus_1
197 rc_fl%nH2rhoFactor = eos%nH2rhoFactor
198 rc_fl%eion_per_nH = eos%eion_per_nH
199 rc_fl%eint_from_T => eint_nh_from_t
200 rc_fl%p2eint => p2eint_from_nh_p
201 rc_fl%T_from_eint => t_from_nh_eint
202 rc_fl%y_from_eint => y_from_nh_eint
203 rc_fl%log_T_floor = eos_get_log_t_floor()
205 if (eos%ionE .and. eos%eos_type == 'LTE') then
206 call eos_get_eintt_grid(rc_fl%Y_mod_n_nH, &
207 rc_fl%Y_mod_lg_nH_min, rc_fl%Y_mod_lg_nH_max)
209 end if
210 end if
211
212 !> PI energy-mode: repoint eint<->p kernels at the portable backend.
213 if (eos%eos_type == 'PI' .and. eos%ionE) then
214 if (allocated(tc_fl)) tc_fl%eint_from_T => eint_from_t_pi
215 if (allocated(rc_fl)) then
216 rc_fl%eint_from_T => eint_from_t_pi
217 rc_fl%p2eint => p2eint_pi
218 rc_fl%T_from_eint => t_from_eint_pi
219 rc_fl%y_from_eint => y_from_eint_pi
220 end if
221 end if
222
223 {^ifthreed
224 if (allocated(te_fl_ffhd)) then
225 te_fl_ffhd%get_rho => eos%get_rho
226 te_fl_ffhd%get_pthermal => eos%get_thermal_pressure
227 te_fl_ffhd%get_var_Rfactor => eos%get_Rfactor
228 te_fl_ffhd%get_ne_nH => eos%get_ne_nH
229 end if
230 }
231
232 end subroutine ffhd_bind_eos_to_source
233
234 !=========================================================================
235 !> LTE (Saha table) thermodynamics for FFHD. Mirrors mod_hd_eos.t adapted
236 !> to FFHD's single field-aligned momentum mom(1) and total-energy-only
237 !> ("origin") formulation; no dust, no magnetic energy.
238 !=========================================================================
239
240 !> LTE primitive -> conserved. On entry rho/v/p; on exit rho/mom/E.
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)
246
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
250
251 !> Convert pressure to total energy: E = eint(rho, p) + KE.
252 !> On entry rho/v/p; on exit w(e_) = total energy (rho, mom unchanged).
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)
258
259 integer :: ix^d
260 double precision :: nh(ixi^s), log_nh(ixi^s)
261
262 if (.not. ffhd_energy) return
263
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))
267
268 {do ix^db=ixomin^db,ixomax^db\}
269 w(ix^d,e_) = lte_eint_from_p(w(ix^d,p_), nh(ix^d), log_nh(ix^d), w(ix^d,rho_)) &
270 + half*w(ix^d,mom(1))**2*w(ix^d,rho_)
271 {end do\}
272 end subroutine ffhd_p_to_e
273
274 !> LTE conserved -> primitive. On entry rho/mom/E; on exit rho/v/p.
275 !> Pressure is energy-consistent from actual eint (stored Ne_/Te_ may be
276 !> stale after AMR prolong/coarsen on the nonlinear EoS).
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)
282
283 double precision :: inv_rho
284 double precision :: nh(ixi^s), log_nh(ixi^s)
285 double precision :: eint_val
286 integer :: ix^d
287
288 if (fix_small_values) then
289 call ffhd_handle_small_values(.false., w, x, ixi^l, ixo^l, &
290 'ffhd_to_primitive_LTE')
291 end if
292
293 call eos%get_nH(w, x, ixi^l, ixo^l, nh)
294 if (eos%ionE) log_nh(ixo^s) = dlog10(nh(ixo^s))
295
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)
302 end if
303 {end do\}
304 end subroutine ffhd_to_primitive_lte
305
306 !> LTE thermal pressure from the stored aux state: p = nH(1+He+ne/nH)*Te.
307 !> Mirrors the LTE branch of hd_get_pthermal (small-value guards from
308 !> ffhd_get_pthermal_origin).
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)
316 integer :: iw, ix^d
317 double precision :: nh(ixi^s)
318
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)
323 else
324 pth(ixo^s) = ffhd_adiab * w(ixo^s, rho_)**eos%gamma
325 end if
326
327 if (fix_small_values) then
328 {do ix^db= ixo^lim^db\}
329 if(pth(ix^d)<small_pressure) pth(ix^d)=small_pressure
330 {end do^D&\}
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
339 do iw=1,nw
340 write(*,*) trim(cons_wnames(iw)),": ",w(ix^d,iw)
341 end do
342 if(trace_small_values) write(*,*) dsqrt(pth(ix^d)-bigdouble)
343 write(*,*) "Saving status at the previous time step"
344 crash=.true.
345 end if
346 {end do^D&\}
347 end if
348 end subroutine ffhd_get_pthermal_lte
349
350 !> cs2 = Gamma_1(LTE) * p/rho.
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)
357 integer :: ix^d
358
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_)
362 {end do\}
363 end subroutine ffhd_get_csound2_lte
364
365 !> Effective Gamma_1 for LTE+IonE (dispatch on gamma1_method / eos%method).
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)
372 integer :: ix^d
373
374 if (eos%gamma1_method == 'constant') then
375 gamma1(ixo^s) = eos%gamma
376 return
377 end if
378
379 {do ix^db=ixomin^db,ixomax^db\}
380 gamma1(ix^d) = lte_gamma1_from_p(w(ix^d,p_), w(ix^d,rho_))
381 {end do\}
382 end subroutine ffhd_get_gamma1_lte
383
384 !> Conserved (rho, rho*v, E) -> prolong form (rho, v, T); T in the e_ slot.
385 !> Interpolating in (rho, v, T) avoids Jensen's inequality across the
386 !> ionisation plateau. Mirrors hd_to_prolong_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)
391
392 double precision :: inv_rho, eint_val, nh_val, log_nh, t_loc, y_loc
393 integer :: ix^d
394
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)
399
400 w(ix^d,mom(1)) = w(ix^d,mom(1))*inv_rho
401
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)
404
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)
411 w(ix^d, e_) = t_loc
412 else
413 w(ix^d, e_) = t_from_nh_eint(log_nh, &
414 dlog10(eint_val) - log_nh)
415 end if
416 {end do\}
417 end subroutine ffhd_to_prolong_lte
418
419 !> Prolong form (rho, v, T) -> conserved (rho, rho*v, E); T read from e_.
420 !> Mirrors hd_from_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)
425
426 double precision :: t_val, eint_val, t_fi, nh_val, log_nh, log_t_min
427 integer :: ix^d
428
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
432
433 if (eos%method_id == eos_entropy) then
434 log_t_min = eos%eintT%var2_min
435 else
436 log_t_min = eos%eint_from_T%var2_min
437 end if
438
439 {do ix^db=ixomin^db,ixomax^db\}
440 t_val = w(ix^d, e_)
441 nh_val = w(ix^d, rho_) / eos%nH2rhoFactor
442 log_nh = dlog10(nh_val)
443
444 if (t_val > t_fi) then
445 eint_val = nh_val &
446 * (eos%n_per_nH_FI * t_val * eos%inv_gamma_minus_1 &
447 + eos%eion_per_nH)
448 else if (eos%method_id == eos_analytic) then
449 eint_val = saha_eint_from_nh_t(nh_val, t_val) * nh_val
450 else
451 eint_val = eint_nh_from_t(log_nh, &
452 dlog10(max(t_val, 10.0d0**log_t_min))) * nh_val
453 end if
454
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))
457 {end do\}
458 end subroutine ffhd_from_prolong_lte
459
460 !=========================================================================
461 !> PI energy-mode (eos_type='PI', ionE=.true.) thermodynamics for FFHD.
462 !> eint carries the ionisation-energy term, so p=(gamma-1)*eint no longer
463 !> holds; the eint<->p relation is delegated to the portable scalar backend
464 !> (mod_eos_pi). Single momentum, total-energy only. Mirrors the
465 !> hd PI-energy family.
466 !=========================================================================
467
468 !> Primitive pressure -> total energy via backend (mom(1) is velocity here).
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
475 integer :: ix^d
476
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_)
481 end if
482 {end do\}
483 end subroutine ffhd_p_to_e_pi
484
485 !> Primitive -> conserved (PI energy).
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)
491
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
495
496 !> Conserved -> primitive (PI energy): KE removed -> eint, backend -> p.
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
503 integer :: ix^d
504
505 if (fix_small_values) then
506 call ffhd_handle_small_values(.false., w, x, ixi^l, ixo^l, &
507 'ffhd_to_primitive_PI')
508 end if
509
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, &
517 t, w(ix^d,p_), rfac)
518 end if
519 {end do\}
520 end subroutine ffhd_to_primitive_pi
521
522 !> PI-energy thermal pressure: eint (= e-KE) -> p via the backend.
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
529 integer :: ix^d
530
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)
534 {end do\}
535 end subroutine ffhd_get_pthermal_pi
536
537 !> Rfactor = p/(rho*T) for constant ionisation degree (FI/PI no-energy).
538 !> Stays in the seam: RR is the physics module's gas-constant factor, not
539 !> visible to mod_eos. Rfactor_from_LTE lives in mod_eos (no RR).
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)
546
547 rfactor(ixo^s)=rr
548
549 end subroutine rfactor_from_constant_ionization
550
551 !> Adiabatic sound speed^2 from primitive (rho, p) via the backend.
552
553 !> Effective Gamma_1 = cs2 * rho / p (PI energy).
554
555 !> PI-energy Te_ refresh: eint (= e-KE) -> T via the backend.
556
557 !> Prominence (T,p table) R-factor from (rho, pth) -- no-energy only, so
558 !> pth=(gamma-1)*eint and R is independent of it. Mirrors hd_Rfactor_prominence.
559
560 !> Prominence (T,p) Te_ update from (rho, pth).
561
562end module mod_ffhd_eos
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.
Definition mod_eos_lte.t:12
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.
Definition mod_eos_pi.t:27
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).
Definition mod_eos_pi.t:323
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).
Definition mod_eos_pi.t:316
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...
Definition mod_eos_pi.t:341
subroutine, public get_gamma1_pi(w, x, ixil, ixol, gamma1)
Effective Gamma1 = cs2 * rho / p for the same primitive state.
Definition mod_eos_pi.t:144
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.
Definition mod_eos_pi.t:332
Equation of state for AMRVAC, handled through a single eos_container object.
Definition mod_eos.t:30
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...
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...
Definition mod_physics.t:4
procedure(sub_check_params), pointer phys_bind_eos_to_source
Definition mod_physics.t:55
procedure(sub_convert), pointer phys_to_primitive
Definition mod_physics.t:54
procedure(sub_e_to_ei), pointer phys_e_to_ei
Definition mod_physics.t:68
procedure(sub_e_to_ei), pointer phys_ei_to_e
Definition mod_physics.t:69
procedure(sub_get_pthermal), pointer phys_get_gamma1
Definition mod_physics.t:80
procedure(sub_get_pthermal), pointer phys_get_pthermal
Definition mod_physics.t:79
procedure(sub_get_ei), pointer phys_get_ei
Definition mod_physics.t:70
procedure(sub_convert), pointer phys_to_prolong
Definition mod_physics.t:57
procedure(sub_convert), pointer phys_to_conserved
Definition mod_physics.t:53
procedure(sub_convert), pointer phys_from_prolong
Definition mod_physics.t:58
procedure(sub_get_rho), pointer phys_get_rho
Definition mod_physics.t:72
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