23 double precision,
public ::
mhd_eta = 0.0d0
51 double precision,
public,
protected ::
h_ion_fr=1d0
54 double precision,
public,
protected ::
he_ion_fr=1d0
61 double precision,
public,
protected ::
rr=1d0
63 double precision :: inv_squared_c0=0.d0, inv_squared_c=0.d0
82 integer,
public,
protected ::
rho_
84 integer,
allocatable,
public,
protected ::
mom(:)
86 integer,
public,
protected :: ^
c&m^C_
88 integer,
public,
protected ::
e_
90 integer,
public,
protected :: ^
c&b^C_
92 integer,
public,
protected ::
p_
94 integer,
public,
protected ::
ne_
96 integer,
public,
protected ::
qpar_
100 integer,
public,
protected ::
psi_
102 integer,
public,
protected ::
r_e
104 integer,
public,
protected ::
te_
106 integer,
public,
protected ::
fip_ = -1
108 integer,
parameter :: uawsom_reflection_1d=1, uawsom_reflection_cartesian=2
109 integer :: uawsom_reflection_id=uawsom_reflection_1d
119 integer,
allocatable,
public,
protected ::
tracer(:)
127 integer,
parameter :: divb_none = 0
128 integer,
parameter :: divb_multigrid = -1
129 integer,
parameter :: divb_glm = 1
130 integer,
parameter :: divb_powel = 2
131 integer,
parameter :: divb_janhunen = 3
132 integer,
parameter :: divb_linde = 4
133 integer,
parameter :: divb_lindejanhunen = 5
134 integer,
parameter :: divb_lindepowel = 6
135 integer,
parameter :: divb_lindeglm = 7
136 integer,
parameter :: divb_ct = 8
140 integer,
parameter :: htc_perp_disabled=0, htc_perp_fixed=1, &
141 htc_perp_weak_field=2, htc_perp_electron=3
142 integer :: htc_perp_mode_id=htc_perp_disabled
178 logical,
public,
protected ::
mhd_glm = .false.
211 logical,
public,
protected ::
mhd_fip = .false.
226 logical :: total_energy = .true.
230 logical :: gravity_energy
247 character(len=std_len),
public,
protected ::
typedivbfix =
'linde'
249 character(len=std_len),
public,
protected ::
type_ct =
'uct_contact'
251 character(len=std_len) :: typedivbdiff =
'all'
262 subroutine mask_subroutine(ixI^L,ixO^L,w,x,res)
264 integer,
intent(in) :: ixi^
l, ixo^
l
265 double precision,
intent(in) :: x(ixi^s,1:
ndim)
266 double precision,
intent(in) :: w(ixi^s,1:nw)
267 double precision,
intent(inout) :: res(ixi^s)
268 end subroutine mask_subroutine
275 procedure(
sub_e_to_ei),
pointer :: mhd_e_to_ei_base => null()
318 subroutine mhd_read_params(files)
321 character(len=*),
intent(in) :: files(:)
347 do n = 1,
size(files)
348 open(
unitpar, file=trim(files(n)), status=
"old")
349 read(
unitpar, mhd_list,
end=111)
355 end subroutine mhd_read_params
358 subroutine mhd_write_info(fh)
360 integer,
intent(in) :: fh
363 integer,
parameter :: n_par = 1
364 double precision :: values(n_par)
365 integer,
dimension(MPI_STATUS_SIZE) :: st
366 character(len=name_len) :: names(n_par)
368 call mpi_file_write(fh, n_par, 1, mpi_integer, st, er)
371 values(1) = eos%gamma
372 call mpi_file_write(fh, values, n_par, mpi_double_precision, st, er)
373 call mpi_file_write(fh, names, n_par * name_len, mpi_character, st, er)
374 end subroutine mhd_write_info
403 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_internal_e=T'
407 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_internal_e=T'
414 if(
mype==0)
write(*,*)
'WARNING: set mhd_internal_e=F when mhd_hydrodynamic_e=T'
418 if(
mype==0)
write(*,*)
'WARNING: set B0field=F when mhd_hydrodynamic_e=T'
422 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_hydrodynamic_e=T'
430 call mpistop(
'B0 splitting needs mhd_energy=T when mhd_semirelativistic=T')
433 call mpistop(
'B0 splitting with mhd_semirelativistic=T needs Cartesian geometry')
438 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_semirelativistic=T'
442 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_semirelativistic=T'
449 if(
mype==0)
write(*,*)
'WARNING: set mhd_internal_e=F when mhd_energy=F'
453 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_energy=F'
457 if(
mype==0)
write(*,*)
'WARNING: set mhd_thermal_conduction=F when mhd_energy=F'
461 if(
mype==0)
write(*,*)
'WARNING: set mhd_hyperbolic_tc=F when mhd_energy=F'
465 if(
mype==0)
write(*,*)
'WARNING: set mhd_radiative_cooling=F when mhd_energy=F'
469 if(
mype==0)
write(*,*)
'WARNING: set mhd_trac=F when mhd_energy=F'
473 if(
mype==0)
write(*,*)
'WARNING: set B0field=F when mhd_energy=F'
477 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_energy=F'
483 if(
mype==0)
write(*,*)
'WARNING: set either parabolic TC or hyperbolic TC to F'
484 if(
mype==0)
write(*,*)
'WARNING: defaulting to only mhd_hyperbolic_tc=T'
488 call mpistop(
"mhd_hyperbolic_tc_use_perp is not supported in 1D")
499 phys_gamma = eos%gamma
512 phys_total_energy=total_energy
515 gravity_energy=.false.
517 gravity_energy=.true.
520 gravity_energy=.false.
526 if(
mype==0)
write(*,*)
'WARNING: reset mhd_trac_type=1 for 1D simulation'
531 if(
mype==0)
write(*,*)
'WARNING: set mhd_trac_mask==bigdouble for global TRAC method'
537 call mpistop(
"mhd_trac_type=7 requires usr_get_heating to be set in mod_usr.t")
545 type_divb = divb_none
548 if(
mhd_radiation_fld)
call mpistop(
'To verify whether mg usage for FLD versus divB can be combined')
549 type_divb = divb_multigrid
551 mg%operator_type = mg_laplacian
558 case (
'powel',
'powell')
559 type_divb = divb_powel
561 type_divb = divb_janhunen
563 type_divb = divb_linde
564 case (
'lindejanhunen')
565 type_divb = divb_lindejanhunen
567 type_divb = divb_lindepowel
571 type_divb = divb_lindeglm
576 call mpistop(
'Unknown divB fix')
579 allocate(start_indices(number_species),stop_indices(number_species))
586 mom(:) = var_set_momentum(
ndir)
592 e_ = var_set_energy()
601 mag(:) = var_set_bfield(
ndir)
605 psi_ = var_set_fluxvar(
'psi',
'psi', need_bc=.false.)
611 qpar_ = var_set_fluxvar(
'q',
'q', need_bc=.false.)
613 qperp_ = var_set_fluxvar(
'qperp',
'qperp', need_bc=.false.)
624 fip_ = var_set_fluxvar(
'rho_fip',
'fip', need_bc=.false.)
630 waplus_ = var_set_fluxvar(
'wAplus',
'wAplus')
631 waminus_ = var_set_fluxvar(
'wAminus',
'wAminus')
632 wkplus_ = var_set_fluxvar(
'wkplus',
'wkplus')
633 wkminus_ = var_set_fluxvar(
'wkminus',
'wkminus')
641 tracer(itr) = var_set_fluxvar(
"trc",
"trp", itr, need_bc=.false.)
647 write(*,*)
'Warning: CAK force addition together with FLD radiation'
652 write(*,*)
'Warning: Optically thin cooling together with FLD radiation'
656 call mpistop(
'using FLD implies the use of an energy equation, set mhd_energy=T')
659 call mpistop(
'using FLD not yet with semirelativistic energy formalism')
662 call mpistop(
'using FLD not yet with hydrodynamic or internal energy formalism')
665 call mpistop(
'using FLD not yet with split off rho and p')
669 r_e = var_set_radiation_energy()
674 call fld_init(eos%eos_type, eos%ionE, eos%pi_table)
678 phys_implicit_update => mhd_fld_implicit_update
679 phys_evaluate_implicit => mhd_fld_evaluate_implicit
691 if (eos%eos_type ==
'LTE')
then
694 else if (eos%eos_type ==
'PI')
then
705 if(.not.
mhd_energy)
call mpistop(
"radiative transfer needs mhd_energy=T")
706 call rt_sc_activate()
719 if (iw_ne > 0) nwgc = max(nwgc, iw_ne)
720 if (iw_te > 0) nwgc = max(nwgc, iw_te)
723 stop_indices(1)=nwflux
751 allocate(iw_vector(nvector))
752 iw_vector(1) =
mom(1) - 1
753 iw_vector(2) = mag(1) - 1
756 if (.not.
allocated(flux_type))
then
757 allocate(flux_type(
ndir, nwflux))
758 flux_type = flux_default
759 else if (any(shape(flux_type) /= [
ndir, nwflux]))
then
760 call mpistop(
"phys_check error: flux_type has wrong shape")
763 if(nwflux>mag(
ndir))
then
765 flux_type(:,mag(
ndir)+1:nwflux)=flux_hll
770 flux_type(:,
psi_)=flux_special
772 flux_type(idir,mag(idir))=flux_special
776 flux_type(idir,mag(idir))=flux_tvdlf
782 phys_get_dt => mhd_get_dt
785 phys_get_cmax => mhd_get_cmax_semirelati
787 phys_get_cmax => mhd_get_cmax_semirelati_noe
791 phys_get_cmax => mhd_get_cmax_origin
793 phys_get_cmax => mhd_get_cmax_origin_noe
796 phys_get_tcutoff => mhd_get_tcutoff
797 phys_get_h_speed => mhd_get_h_speed
799 phys_get_cbounds => mhd_get_cbounds_split_rho
801 phys_get_cbounds => mhd_get_cbounds_semirelati
803 phys_get_cbounds => mhd_get_cbounds
813 phys_get_flux => mhd_get_flux_hde
816 phys_get_flux => mhd_get_flux_semirelati
818 phys_get_flux => mhd_get_flux_semirelati_noe
822 phys_get_flux => mhd_get_flux_split
824 phys_get_flux => mhd_get_flux
826 phys_get_flux => mhd_get_flux_noe
831 phys_add_source_geom => mhd_add_source_geom_semirelati
833 phys_add_source_geom => mhd_add_source_geom_split
835 phys_add_source_geom => mhd_add_source_geom
837 phys_add_source => mhd_add_source
838 phys_check_params => mhd_check_params
839 phys_write_info => mhd_write_info
842 phys_handle_small_values => mhd_handle_small_values_inte
843 mhd_handle_small_values => mhd_handle_small_values_inte
844 phys_check_w => mhd_check_w_inte
846 phys_handle_small_values => mhd_handle_small_values_hde
847 mhd_handle_small_values => mhd_handle_small_values_hde
848 phys_check_w => mhd_check_w_hde
850 phys_handle_small_values => mhd_handle_small_values_semirelati
851 mhd_handle_small_values => mhd_handle_small_values_semirelati
852 phys_check_w => mhd_check_w_semirelati
854 phys_handle_small_values => mhd_handle_small_values_split
855 mhd_handle_small_values => mhd_handle_small_values_split
856 phys_check_w => mhd_check_w_split
858 phys_handle_small_values => mhd_handle_small_values_origin
859 mhd_handle_small_values => mhd_handle_small_values_origin
860 phys_check_w => mhd_check_w_origin
862 phys_handle_small_values => mhd_handle_small_values_noe
863 mhd_handle_small_values => mhd_handle_small_values_noe
864 phys_check_w => mhd_check_w_noe
870 phys_set_equi_vars => set_equi_vars_grid
873 if(type_divb==divb_glm)
then
874 phys_modify_wlr => mhd_modify_wlr
885 transverse_ghost_cells = 1
886 phys_get_ct_velocity => mhd_get_ct_velocity_average
887 phys_update_faces => mhd_update_faces_average
889 transverse_ghost_cells = 1
890 phys_get_ct_velocity => mhd_get_ct_velocity_contact
891 phys_update_faces => mhd_update_faces_contact
893 transverse_ghost_cells = 2
894 phys_get_ct_velocity => mhd_get_ct_velocity_hll
895 phys_update_faces => mhd_update_faces_hll
897 call mpistop(
'choose average, uct_contact,or uct_hll for type_ct!')
900 phys_modify_wlr => mhd_modify_wlr
902 phys_boundary_adjust => mhd_boundary_adjust
908 call mpistop(
'To verify whether mg usage for FLD versus divB can be combined')
913 call mhd_physical_units()
933 htc_perp_mode_id=htc_perp_disabled
947 case(
'fixed_reference')
948 htc_perp_mode_id=htc_perp_fixed
958 case(
'weak_field_isotropization')
959 htc_perp_mode_id=htc_perp_weak_field
963 case(
'electron_magnetization')
964 htc_perp_mode_id=htc_perp_electron
966 call mpistop(
"mhd_hyperbolic_tc_coulomb_log must be positive")
969 call mpistop(
"invalid mhd_hyperbolic_tc_perp_mode: "// &
975 call mpistop(
"thermal conduction needs mhd_energy=T")
978 call mpistop(
"hyperbolic thermal conduction needs mhd_energy=T")
981 call mpistop(
"radiative cooling needs mhd_energy=T")
986 iw_log_nh = var_set_wextra()
992 if(
mype==0)
write(*,*)
'WARNING: turning mhd_equi_thermal=F as no splitting or total e in use'
995 if(
mype==0)
write(*,*)
'Will subtract thermal balance in TC or RC with mhd_equi_thermal=T'
998 if(
mype==0)
write(*,*)
'WARNING: turning mhd_equi_thermal=F as no TC or RC in use'
1005 phys_e_to_ei => mhd_ei_unchanged
1006 phys_ei_to_e => mhd_ei_unchanged
1008 phys_e_to_ei => mhd_e_to_ei_hde
1009 phys_ei_to_e => mhd_ei_to_e_hde
1011 phys_e_to_ei => mhd_e_to_ei_semirelati
1012 phys_ei_to_e => mhd_ei_to_e_semirelati
1019 mhd_e_to_ei_base => phys_e_to_ei
1020 phys_e_to_ei => mhd_e_to_ei_cache_log_nh
1058 phys_te_images => mhd_te_images
1064 write(*,*)
'*****Using hyperresistivity: with mhd_eta_hyper :',
mhd_eta_hyper
1068 call mpistop(
"Must have B0field=F when using hyperresistivity")
1072 call mpistop(
"Must have mhd_eta_hyper positive when using hyperresistivity")
1089 call mpistop(
"Must have has_equi_rho_and_p=F when mhd_rotating_frame=T")
1103 call mpistop(
"Must have mhd_hall=F when mhd_semirelativistic=T")
1107 call mpistop(
"Must have Cartesian coordinates for Hall")
1111 phys_wider_stencil = 1
1118 phys_wider_stencil=max(phys_wider_stencil,1)
1125 call add_sts_method(get_ambipolar_dt,sts_set_source_ambipolar,mag(1),&
1136 phys_wider_stencil = 1
1146 call mpistop(
"CAK implementation not available in internal or semirelativistic variants")
1149 call mpistop(
"CAK force implementation not available for split off pressure and density")
1157 phys_get_hd_mom_flux => get_hd_mom_flux
1159 phys_get_hd_mom_flux => get_hd_mom_flux_noe
1166 subroutine mhd_te_images
1171 case(
'EIvtiCCmpi',
'EIvtuCCmpi')
1173 case(
'ESvtiCCmpi',
'ESvtuCCmpi')
1175 case(
'SIvtiCCmpi',
'SIvtuCCmpi')
1177 case(
'WIvtiCCmpi',
'WIvtuCCmpi')
1180 call mpistop(
"Error in synthesize emission: Unknown convert_type")
1182 end subroutine mhd_te_images
1188 subroutine mhd_sts_set_source_tc_mhd(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
1192 integer,
intent(in) :: ixi^
l, ixo^
l, igrid, nflux
1193 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1194 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
1195 double precision,
intent(in) :: my_dt
1196 logical,
intent(in) :: fix_conserve_at_step
1198 end subroutine mhd_sts_set_source_tc_mhd
1200 subroutine mhd_sts_set_source_tc_hd(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
1204 integer,
intent(in) :: ixi^
l, ixo^
l, igrid, nflux
1205 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1206 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
1207 double precision,
intent(in) :: my_dt
1208 logical,
intent(in) :: fix_conserve_at_step
1210 end subroutine mhd_sts_set_source_tc_hd
1212 function mhd_get_tc_dt_mhd(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
1219 integer,
intent(in) :: ixi^
l, ixo^
l
1220 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
1221 double precision,
intent(in) :: w(ixi^s,1:nw)
1222 double precision :: dtnew
1225 end function mhd_get_tc_dt_mhd
1227 function mhd_get_tc_dt_hd(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
1234 integer,
intent(in) :: ixi^
l, ixo^
l
1235 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
1236 double precision,
intent(in) :: w(ixi^s,1:nw)
1237 double precision :: dtnew
1240 end function mhd_get_tc_dt_hd
1242 subroutine mhd_tc_handle_small_e(w, x, ixI^L, ixO^L, step)
1245 integer,
intent(in) :: ixi^
l,ixo^
l
1246 double precision,
intent(inout) :: w(ixi^s,1:nw)
1247 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1248 integer,
intent(in) :: step
1249 character(len=140) :: error_msg
1255 write(error_msg,
"(a,i3)")
"Thermal conduction step ", step
1256 call mhd_handle_small_ei(w,x,ixi^
l,ixo^
l,
e_,error_msg)
1257 end subroutine mhd_tc_handle_small_e
1260 subroutine tc_params_read_mhd(fl)
1262 type(tc_fluid),
intent(inout) :: fl
1264 double precision :: tc_k_para=0d0
1265 double precision :: tc_k_perp=0d0
1268 logical :: tc_perpendicular=.false.
1269 logical :: tc_saturate=.false.
1270 logical :: tc_patch_eint=.false.
1271 logical :: tc_frozen_ion=.true.
1272 double precision :: trac_t_floor=0.d0
1273 character(len=std_len) :: tc_slope_limiter=
"MC"
1275 namelist /tc_list/ tc_perpendicular, tc_saturate, tc_slope_limiter, tc_k_para, tc_k_perp, &
1276 tc_patch_eint, trac_t_floor, tc_frozen_ion
1280 read(
unitpar, tc_list,
end=111)
1284 fl%tc_perpendicular = tc_perpendicular
1285 fl%tc_saturate = tc_saturate
1286 fl%tc_patch_eint = tc_patch_eint
1287 fl%frozen_ion = tc_frozen_ion
1288 fl%tc_k_para = tc_k_para
1289 fl%tc_k_perp = tc_k_perp
1290 fl%trac_T_floor = trac_t_floor / unit_temperature
1291 select case(tc_slope_limiter)
1293 fl%tc_slope_limiter = 0
1296 fl%tc_slope_limiter = 1
1299 fl%tc_slope_limiter = 2
1302 fl%tc_slope_limiter = 3
1305 fl%tc_slope_limiter = 4
1308 fl%tc_slope_limiter = 5
1310 call mpistop(
"Unknown tc_slope_limiter, choose MC, minmod, superbee, koren, vanleer")
1312 end subroutine tc_params_read_mhd
1316 subroutine rc_params_read(fl)
1319 type(rc_fluid),
intent(inout) :: fl
1323 double precision :: rad_damp_height=0.5d0
1324 double precision :: rad_damp_scale=0.15d0
1327 integer :: ncool = 4000
1329 logical :: tfix=.false.
1331 logical :: rc_split=.false.
1332 logical :: rad_damp=.false.
1334 character(len=std_len) :: coolcurve=
'JCcorona'
1335 logical :: rad_newton = .false.
1336 double precision :: rad_newton_trad = 0.006d0
1337 double precision :: rad_newton_rhosurf = 1.d4
1338 double precision :: rad_newton_pthick = 25.d0
1340 double precision :: cfrac=0.1d0
1341 double precision :: rad_cut_hgt=0.5d0
1342 double precision :: rad_cut_dey=0.15d0
1344 character(len=8) :: rc_y_mod_quadrature=
'boole'
1345 integer :: rc_y_mod_n_sub=16
1348 namelist /rc_list/ coolcurve, ncool, cfrac, tlow, tfix, rc_split, &
1349 rad_cut_hgt, rad_cut_dey, &
1350 rc_y_mod_quadrature, rc_y_mod_n_sub, &
1351 rad_newton, rad_newton_trad, rad_newton_rhosurf, &
1352 rad_newton_pthick, rad_damp, rad_damp_height, rad_damp_scale
1356 read(
unitpar, rc_list,
end=111)
1361 fl%coolcurve=coolcurve
1364 fl%rc_split=rc_split
1366 fl%rad_cut_hgt=rad_cut_hgt
1367 fl%rad_cut_dey=rad_cut_dey
1368 fl%Y_mod_quadrature=rc_y_mod_quadrature
1369 fl%Y_mod_N_sub=rc_y_mod_n_sub
1370 fl%rad_damp=rad_damp
1371 fl%rad_damp_height=rad_damp_height
1372 fl%rad_damp_scale=rad_damp_scale
1373 fl%rad_newton=rad_newton
1374 fl%rad_newton_trad=rad_newton_trad
1375 fl%rad_newton_rhosurf=rad_newton_rhosurf
1376 fl%rad_newton_pthick=rad_newton_pthick
1377 end subroutine rc_params_read
1380 subroutine set_equi_vars_grid_faces(igrid,x,ixI^L,ixO^L)
1383 integer,
intent(in) :: igrid, ixi^
l, ixo^
l
1384 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1386 double precision :: delx(ixi^s,1:
ndim)
1387 double precision :: xc(ixi^s,1:
ndim),xshift^
d
1388 integer :: idims, ixc^
l, hxo^
l, ix, idims2
1394 delx(ixi^s,1:
ndim)=ps(igrid)%dx(ixi^s,1:
ndim)
1398 hxo^
l=ixo^
l-
kr(idims,^
d);
1404 ixcmax^
d=ixomax^
d; ixcmin^
d=hxomin^
d;
1407 xshift^
d=half*(one-
kr(^
d,idims));
1414 xc(ix^
d%ixC^s,^
d)=x(ix^
d%ixC^s,^
d)+(half-xshift^
d)*delx(ix^
d%ixC^s,^
d)
1418 call usr_set_equi_vars(ixi^l,ixc^l,xc,ps(igrid)%equi_vars(ixi^s,1:number_equi_vars,idims))
1420 end subroutine set_equi_vars_grid_faces
1423 subroutine set_equi_vars_grid(igrid)
1427 integer,
intent(in) :: igrid
1433 call set_equi_vars_grid_faces(igrid,ps(igrid)%x,ixg^
ll,
ixm^
ll)
1435 end subroutine set_equi_vars_grid
1438 function convert_vars_splitting(ixI^L,ixO^L, w, x, nwc)
result(wnew)
1440 integer,
intent(in) :: ixi^
l,ixo^
l, nwc
1441 double precision,
intent(in) :: w(ixi^s, 1:nw)
1442 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1443 double precision :: wnew(ixo^s, 1:nwc)
1450 wnew(ixo^s,
mom(:))=w(ixo^s,
mom(:))
1456 wnew(ixo^s,mag(1:
ndir))=w(ixo^s,mag(1:
ndir))
1460 wnew(ixo^s,
e_)=w(ixo^s,
e_)
1462 wnew(ixo^s,
e_)=wnew(ixo^s,
e_)+
block%equi_vars(ixo^s,
equi_pe0_,0)*eos%inv_gamma_minus_1
1464 if(
b0field .and. total_energy)
then
1465 wnew(ixo^s,
e_)=wnew(ixo^s,
e_)+0.5d0*sum(
block%B0(ixo^s,:,0)**2,dim=
ndim+1) &
1466 + sum(w(ixo^s,mag(:))*
block%B0(ixo^s,:,0),dim=
ndim+1)
1470 end function convert_vars_splitting
1472 subroutine mhd_check_params
1479 ngridvars,num_particles,physics_type_particles
1482 double precision :: a,
b,xfrac,yfrac
1488 'WARNING: typeboundspeed and H_correction are ignored',
' when mhd_semirelativistic=T'
1489 if(
boundspeed==4)
call mpistop(
"typeboundspeed='pvrs' is not implemented for mhd")
1493 call mpistop(
'mhd_uawsom currently requires a uniform Cartesian grid')
1495 call mpistop(
'mhd_uawsom requires the standard total-energy MHD formulation')
1498 call mpistop(
'mhd_uawsom: unsupported MHD option')
1499 if(trim(eos%eos_type) /=
'FI') &
1500 call mpistop(
"mhd_uawsom currently supports eos_type='FI' only")
1502 call mpistop(
'mhd_uawsom_height_dim must be between 1 and ndim')
1505 call mpistop(
'mhd_uawsom requires zeta0>1 and 0<filling_factor<1')
1509 call mpistop(
'mhd_uawsom: scales must be positive')
1511 call mpistop(
'mhd_uawsom_sigma must be non-negative')
1513 case(
'one_dimensional_gradient')
1514 uawsom_reflection_id=uawsom_reflection_1d
1515 case(
'cartesian_gradient_vorticity')
1516 uawsom_reflection_id=uawsom_reflection_cartesian
1518 call mpistop(
'invalid mhd_uawsom_reflection_mode')
1525 if (particles_eta < zero) particles_eta =
mhd_eta
1526 if (particles_etah < zero) particles_eta =
mhd_etah
1531 if (eos%gamma <= 0.0d0)
call mpistop (
"Error: gamma <= 0")
1532 if (
mhd_adiab < 0.0d0)
call mpistop (
"Error: mhd_adiab < 0")
1535 if (eos%gamma <= 0.0d0 .or. eos%gamma == 1.0d0) &
1536 call mpistop (
"Error: gamma <= 0 or gamma == 1")
1542 call mpistop(
"usr_set_equi_vars has to be implemented in the user file")
1551 call mpistop(
"Must have has_equi_rho_and_p=F with the roe/hllc/hllcd flux schemes")
1555 call mpistop(
"Must have has_equi_rho_and_p=F when mhd_trac=T")
1561 if(
mype .eq. 0) print*,
" add conversion method: split -> full "
1569 call mpistop(
'select IMEX scheme for FLD radiation use')
1572 call phys_set_mg_bounds()
1574 if(.not.
fld_no_mg)
call mpistop(
'multigrid must have BCs for IMEX and FLD radiation use')
1577 write(*,*)
'==FLD SETUP======================'
1578 write(*,*)
'Using FLD with settings:'
1582 write(*,*)
'Using FLD with settings: fld_bound_diff=',
fld_bound_diff
1585 write(*,*)
'Using FLD with settings: fld_kappa0=',
fld_kappa0
1586 write(*,*)
'Using FLD with settings: fld_opal_table=',
fld_opal_table
1588 write(*,*)
'Using FLD with settings: fld_bisect_tol=',
fld_bisect_tol
1589 write(*,*)
'Using FLD with settings: fld_diff_tol=',
fld_diff_tol
1592 write(*,*)
' FLD has fld_no_mg=',
fld_no_mg
1594 print *,
'WARNING: cheating with FLD diffusion ***********************'
1595 print *,
'WARNING: No MG-diffusion for radiative energy at all!!!!!!!'
1596 print *,
'WARNING: cheating with FLD diffusion ***********************'
1599 print *,
'NORMALIZED arad_norm=',
arad_norm
1600 print *,
'NORMALIZED c_norm=',
c_norm
1602 print *,
'WARNING: cheating with c_norm ***********************'
1603 print *,
'WARNING: c_norm reset to=',
fld_cnorm
1605 print *,
'WARNING: cheating with c_norm ***********************'
1613 print *,
'physical fld_kappa (in cgs or SI) =',
fld_kappa0
1616 write(*,*)
'===FLD SETUP====================='
1621 write(*,*)
'====MHD run with settings===================='
1622 write(*,*)
'Using mod_mhd_phys with settings:'
1624 write(*,*)
'Dimensionality :',
ndim
1625 write(*,*)
'vector components:',
ndir
1627 write(*,*)
'number of variables nw=',nw
1628 write(*,*)
' start index iwstart=',iwstart
1629 write(*,*)
'number of vector variables=',nvector
1630 write(*,*)
'number of stagger variables nws=',nws
1631 write(*,*)
'number of variables with BCs=',nwgc
1632 write(*,*)
'number of vars with fluxes=',nwflux
1633 write(*,*)
'number of vars with flux + BC=',nwfluxbc
1634 write(*,*)
'number of auxiliary variables=',nwaux
1635 write(*,*)
'number of extra vars without flux=',nwextra
1636 write(*,*)
'number of extra vars for wextra=',nw_extra
1637 write(*,*)
'number of auxiliary I/O variables=',
nwauxio
1639 write(*,*)
' mhd_energy=',
mhd_energy,
' with total_energy=',total_energy
1644 write(*,*)
' mhd_eta=',
mhd_eta,
' nonzero implies resistivity'
1658 write(*,*)
'*****Using particles: with mhd_eta, mhd_etah :',
mhd_eta,
mhd_etah
1659 write(*,*)
'*****Using particles: particles_eta, particles_etah :', particles_eta, particles_etah
1660 write(*,*)
'*****Using particles: npayload,ngridvars :', npayload,ngridvars
1661 write(*,*)
'*****Using particles: nusrpayload :', nusrpayload
1662 write(*,*)
'*****Using particles: num_particles :', num_particles
1663 write(*,*)
'*****Using particles: physics_type_particles=',physics_type_particles
1666 write(*,*)
'number due to phys_wider_stencil=',phys_wider_stencil
1667 write(*,*)
'==========================================='
1668 print *,
'========EOS and UNITS==========='
1670 print *,
'gamma=',eos%gamma
1671 print *,
'He_abundance =',eos%He_abundance
1673 print *,
'========EOS and UNITS==========='
1695 print *,
' compare this to ',mp_si*(1.d0+4.d0*eos%He_abundance)
1697 print *,
' compare this to ',mp_cgs*(1.d0+4.d0*eos%He_abundance)
1701 print *,
' compare this to ',kb_si*(2.d0+3.d0*eos%He_abundance)
1705 print *,
' compare this to ',kb_cgs*(2.d0+3.d0*eos%He_abundance)
1709 if(eos%eos_type /=
'LTE')
then
1710 print *,
'mean molecular weight mu is =',a/
b,
' = ', (1.d0+4.d0*eos%He_abundance)/(2.d0+3.d0*eos%He_abundance)
1712 yfrac=4.d0*eos%He_abundance/(1.d0+4.d0*eos%He_abundance)
1713 print *,
'mass fraction hydrogen X is =',1/a,
' and this equals ', 1.d0/(1.d0+4.d0*eos%He_abundance)
1714 print *,
'mass fraction helium Y is =',yfrac
1715 print *,
' check that 1/mu',
b/a,
' is equal to 2X+3Y/4=',2.d0*xfrac+3.d0*yfrac/4.d0
1716 print *,
' ratio n_e/n_p=',1.d0+2.0d0*eos%He_abundance
1718 print *,
'========UNITS==========='
1721 end subroutine mhd_check_params
1723 subroutine mhd_physical_units()
1725 double precision :: mp,kb,miu0,c_lightspeed,xfrac,sigma_telectron
1726 double precision :: a,
b
1734 sigma_telectron=sigma_te_si
1740 c_lightspeed=const_c
1741 sigma_telectron=sigma_te_cgs
1746 if (eos%eos_type ==
'LTE')
then
1750 eos%nH2rhoFactor = 1d0+4d0*eos%He_abundance
1751 rr=(2d0+3d0*eos%He_abundance) / (1d0+4d0*eos%He_abundance)
1752 xfrac=1.d0/(1.d0+4.d0*eos%He_abundance)
1756 a=1d0+4d0*eos%He_abundance
1757 if(eos%eos_type==
'PI')
then
1760 b=2d0+3d0*eos%He_abundance
1893 eos%inv_squared_c0 = inv_squared_c0
1894 eos%inv_squared_c = inv_squared_c
1910 end subroutine mhd_physical_units
1912 subroutine mhd_check_w_semirelati(primitive,ixI^L,ixO^L,w,flag)
1915 logical,
intent(in) :: primitive
1916 logical,
intent(inout) :: flag(ixi^s,1:nw)
1917 integer,
intent(in) :: ixi^
l, ixo^
l
1918 double precision,
intent(in) :: w(ixi^s,nw)
1920 double precision :: vel(ixo^s,1:
ndir),emech(ixo^s)
1930 where(w(ixo^s,
e_)-emech(ixo^s) <
small_e) flag(ixo^s,
e_) = .true.
1934 end subroutine mhd_check_w_semirelati
1936 subroutine mhd_check_w_origin(primitive,ixI^L,ixO^L,w,flag)
1939 logical,
intent(in) :: primitive
1940 integer,
intent(in) :: ixi^
l, ixo^
l
1941 double precision,
intent(in) :: w(ixi^s,nw)
1942 logical,
intent(inout) :: flag(ixi^s,1:nw)
1944 integer :: ix^
d, igrp
1947 {
do ix^db=ixomin^db,ixomax^db\}
1967 end subroutine mhd_check_w_origin
1969 subroutine mhd_check_w_split(primitive,ixI^L,ixO^L,w,flag)
1972 logical,
intent(in) :: primitive
1973 integer,
intent(in) :: ixi^
l, ixo^
l
1974 double precision,
intent(in) :: w(ixi^s,nw)
1975 logical,
intent(inout) :: flag(ixi^s,1:nw)
1977 double precision :: tmp
1981 {
do ix^db=ixomin^db,ixomax^db\}
1987 tmp=w(ix^
d,
e_)-half*((^
c&w(ix^
d,
m^
c_)**2+)/tmp+(^
c&w(ix^
d,
b^
c_)**2+))
1992 end subroutine mhd_check_w_split
1994 subroutine mhd_check_w_noe(primitive,ixI^L,ixO^L,w,flag)
1997 logical,
intent(in) :: primitive
1998 integer,
intent(in) :: ixi^
l, ixo^
l
1999 double precision,
intent(in) :: w(ixi^s,nw)
2000 logical,
intent(inout) :: flag(ixi^s,1:nw)
2005 {
do ix^db=ixomin^db,ixomax^db\}
2009 end subroutine mhd_check_w_noe
2011 subroutine mhd_check_w_inte(primitive,ixI^L,ixO^L,w,flag)
2014 logical,
intent(in) :: primitive
2015 integer,
intent(in) :: ixi^
l, ixo^
l
2016 double precision,
intent(in) :: w(ixi^s,nw)
2017 logical,
intent(inout) :: flag(ixi^s,1:nw)
2022 {
do ix^db=ixomin^db,ixomax^db\}
2031 end subroutine mhd_check_w_inte
2033 subroutine mhd_check_w_hde(primitive,ixI^L,ixO^L,w,flag)
2036 logical,
intent(in) :: primitive
2037 integer,
intent(in) :: ixi^
l, ixo^
l
2038 double precision,
intent(in) :: w(ixi^s,nw)
2039 logical,
intent(inout) :: flag(ixi^s,1:nw)
2044 {
do ix^db=ixomin^db,ixomax^db\}
2053 end subroutine mhd_check_w_hde
2055 subroutine mhd_bound_fip(primitive, ixI^L, ixO^L, w)
2057 logical,
intent(in) :: primitive
2058 integer,
intent(in) :: ixi^
l, ixo^
l
2059 double precision,
intent(inout) :: w(ixi^s,1:nw)
2061 double precision :: rho_safe(ixi^s), fip_prim(ixi^s)
2073 fip_prim(ixo^s) = w(ixo^s,
fip_) / rho_safe(ixo^s)
2074 fip_prim(ixo^s) = min(
maxfip, max(
minfip, fip_prim(ixo^s)))
2075 w(ixo^s,
fip_) = rho_safe(ixo^s) * fip_prim(ixo^s)
2077 end subroutine mhd_bound_fip
2081 subroutine mhd_uawsom_get_coefficients(w,x,ixI^L,ixO^L,primitive,zeta,radius,lperp_A)
2084 integer,
intent(in) :: ixi^
l, ixo^
l
2085 double precision,
intent(in) :: w(ixi^s,1:nw), x(ixi^s,1:
ndim)
2086 logical,
intent(in) :: primitive
2087 double precision,
intent(out) :: zeta(ixi^s), radius(ixi^s), lperp_a(ixi^s)
2088 double precision :: bmag(ixi^s), btotal(ixi^s,1:
ndir), height_base
2096 btotal(ixo^s,idir)=w(ixo^s,mag(idir))+
block%B0(ixo^s,idir,
b0i)
2098 btotal(ixo^s,idir)=w(ixo^s,mag(idir))
2101 bmag(ixo^s)=dsqrt(sum(btotal(ixo^s,1:
ndir)**2,dim=
ndim+1))
2104 height_base=xprobmin1
2107 height_base=xprobmin2
2111 height_base=xprobmin3
2122 if(any(zeta(ixo^s)<=one) .or. any(radius(ixo^s)<=zero) .or. &
2123 any(lperp_a(ixo^s)<=zero)) &
2124 call mpistop(
'mhd_uawsom coefficients require zeta>1 and positive lengths')
2125 end subroutine mhd_uawsom_get_coefficients
2129 integer,
intent(in) :: ixi^
l, ixo^
l
2130 double precision,
intent(in) :: w(ixi^s,1:nw), x(ixi^s,1:
ndim)
2131 double precision,
intent(out) :: factor(ixi^s)
2132 double precision :: zeta(ixi^s), radius(ixi^s), lperp_a(ixi^s)
2133 call mhd_uawsom_get_coefficients(w,x,ixi^
l,ixo^
l,.false.,zeta,radius,lperp_a)
2138 double precision,
intent(in) :: zeta
2139 double precision :: f
2146 double precision,
intent(in) :: wcell(:),zeta
2153 double precision,
intent(in) :: wcell(:)
2167 elemental pure double precision function mhd_uawsom_imbalance_factor(wplus,wminus)
2168 double precision,
intent(in) :: wplus,wminus
2170 if(wplus<=0.d0 .or. wminus<=0.d0)
then
2171 mhd_uawsom_imbalance_factor=0.d0
2172 else if(4.d0*wminus<=wplus)
then
2173 mhd_uawsom_imbalance_factor=1.d0-2.d0*dsqrt(wminus/wplus)
2174 else if(4.d0*wplus<=wminus)
then
2175 mhd_uawsom_imbalance_factor=-(1.d0-2.d0*dsqrt(wplus/wminus))
2177 mhd_uawsom_imbalance_factor=0.d0
2179 end function mhd_uawsom_imbalance_factor
2184 subroutine mhd_add_source_uawsom(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
2187 integer,
intent(in) :: ixi^
l, ixo^
l
2188 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), &
2189 wctprim(ixi^s,1:nw), x(ixi^s,1:
ndim)
2190 double precision,
intent(inout) :: w(ixi^s,1:nw)
2191 double precision :: v(ixi^s,1:
ndir), divv(ixi^s)
2192 double precision :: zeta(ixi^s), radius(ixi^s), lperp_a(ixi^s)
2193 double precision :: lperp_k(ixi^s), rho_e(ixi^s)
2194 double precision :: gamma_plus(ixi^s), gamma_minus(ixi^s)
2195 double precision :: gamma_kplus(ixi^s), gamma_kminus(ixi^s)
2196 double precision :: dampap(ixi^s), dampam(ixi^s), dampkp(ixi^s), dampkm(ixi^s)
2197 double precision :: btotal(ixi^s,1:
ndir), bunit(ixi^s,1:
ndir), bmag(ixi^s)
2198 double precision :: va(ixi^s), vk(ixi^s), lnva(ixi^s), lnvk(ixi^s)
2199 double precision :: grad_component(ixi^s), grad_a(ixi^s), grad_k(ixi^s)
2200 double precision :: curlv(ixi^s,1:3), vorticity(ixi^s)
2201 double precision :: rimb_a(ixi^s), rlim_a(ixi^s), rlim_k(ixi^s)
2202 double precision :: refl_rate(ixi^s), donor_reflection(ixi^s)
2203 double precision :: transfer_a(ixi^s), transfer_k(ixi^s), donor(ixi^s)
2204 double precision :: imbalance_a(ixi^s), imbalance_k(ixi^s)
2205 double precision :: wave_plus(ixi^s), wave_minus(ixi^s)
2206 double precision :: wave_kplus(ixi^s), wave_kminus(ixi^s)
2207 double precision :: f, kink_pressure(ixi^s)
2208 integer :: idir, idirmin
2209 logical :: have_reflection, have_alfven_reflection, have_kink_reflection
2215 call mhd_uawsom_get_coefficients(wct,x,ixi^
l,ixi^
l,.false.,zeta,radius,lperp_a)
2218 max(one+f*zeta(ixi^s)-f,smalldouble)
2219 lperp_k(ixi^s)=dsqrt(10.d0)*dsqrt(f*dpi)*radius(ixi^s)*&
2220 (zeta(ixi^s)+one-f)**1.5d0/&
2221 ((zeta(ixi^s)-one)*(one-f**2.5d0))
2222 gamma_plus(ixo^s)=two/lperp_a(ixo^s)*dsqrt(&
2224 gamma_minus(ixo^s)=two/lperp_a(ixo^s)*dsqrt(&
2226 dampap(ixo^s)=gamma_plus(ixo^s)*max(wct(ixo^s,
waplus_),zero)
2227 dampam(ixo^s)=gamma_minus(ixo^s)*max(wct(ixo^s,
waminus_),zero)
2228 dampkp(ixo^s)=max(wct(ixo^s,
wkplus_),zero)**1.5d0/&
2229 (dsqrt(rho_e(ixo^s))*lperp_k(ixo^s))
2230 dampkm(ixo^s)=max(wct(ixo^s,
wkminus_),zero)**1.5d0/&
2231 (dsqrt(rho_e(ixo^s))*lperp_k(ixo^s))
2234 gamma_kplus(ixo^s)=dsqrt(max(wct(ixo^s,
wkplus_),zero)/&
2235 max(rho_e(ixo^s),
small_density))/max(lperp_k(ixo^s),smalldouble)
2236 gamma_kminus(ixo^s)=dsqrt(max(wct(ixo^s,
wkminus_),zero)/&
2237 max(rho_e(ixo^s),
small_density))/max(lperp_k(ixo^s),smalldouble)
2241 half*divv(ixo^s)*wct(ixo^s,
waplus_)+dampap(ixo^s))
2243 half*divv(ixo^s)*wct(ixo^s,
waminus_)+dampam(ixo^s))
2245 half*divv(ixo^s)*wct(ixo^s,
wkplus_)+dampkp(ixo^s))
2247 half*divv(ixo^s)*wct(ixo^s,
wkminus_)+dampkm(ixo^s))
2249 kink_pressure(ixo^s)=quarter*(zeta(ixo^s)+one)*&
2251 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*(zeta(ixo^s)-one)/&
2252 (zeta(ixo^s)+one)*kink_pressure(ixo^s)*divv(ixo^s)
2254 have_alfven_reflection=.false.
2256 select case(uawsom_reflection_id)
2257 case(uawsom_reflection_1d)
2259 case(uawsom_reflection_cartesian)
2260 have_alfven_reflection=.true.
2264 have_reflection=have_alfven_reflection .or. have_kink_reflection
2265 if(have_reflection)
then
2268 btotal(ixi^s,idir)=wct(ixi^s,mag(idir))+
block%B0(ixi^s,idir,
b0i)
2270 btotal(ixi^s,idir)=wct(ixi^s,mag(idir))
2273 bmag(ixi^s)=dsqrt(sum(btotal(ixi^s,1:
ndir)**2,dim=
ndim+1))
2274 if(have_kink_reflection .or. &
2275 (have_alfven_reflection .and. uawsom_reflection_id==uawsom_reflection_cartesian))
then
2277 bunit(ixi^s,idir)=btotal(ixi^s,idir)/max(bmag(ixi^s),smalldouble)
2280 if(have_alfven_reflection)
then
2282 if(uawsom_reflection_id==uawsom_reflection_cartesian) &
2283 lnva(ixi^s)=dlog(max(va(ixi^s),smalldouble))
2285 if(have_kink_reflection)
then
2286 vk(ixi^s)=bmag(ixi^s)/dsqrt(max(rho_e(ixi^s)*&
2287 (zeta(ixi^s)+one)/two,smalldouble))
2288 lnvk(ixi^s)=dlog(max(vk(ixi^s),smalldouble))
2295 if(have_alfven_reflection)
then
2296 wave_plus(ixo^s)=max(wct(ixo^s,
waplus_),zero)
2297 wave_minus(ixo^s)=max(wct(ixo^s,
waminus_),zero)
2299 select case(uawsom_reflection_id)
2300 case(uawsom_reflection_1d)
2306 max(va(ixo^s),smalldouble)*grad_component(ixo^s)
2307 donor_reflection(ixo^s)=merge(max(wct(ixo^s,
waplus_),zero),&
2308 max(wct(ixo^s,
waminus_),zero),refl_rate(ixo^s)>=zero)
2309 transfer_a(ixo^s)=refl_rate(ixo^s)*donor_reflection(ixo^s)
2310 case(uawsom_reflection_cartesian)
2313 call gradient(lnva,ixi^
l,ixo^
l,idir,grad_component)
2314 grad_a(ixo^s)=grad_a(ixo^s)+va(ixo^s)*bunit(ixo^s,idir)*&
2315 grad_component(ixo^s)
2318 vorticity(ixo^s)=zero
2320 vorticity(ixo^s)=vorticity(ixo^s)+bunit(ixo^s,idir)*&
2325 rimb_a(ixo^s)=dsqrt(grad_a(ixo^s)**2+vorticity(ixo^s)**2)
2326 rlim_a(ixo^s)=min(rimb_a(ixo^s),&
2327 max(gamma_plus(ixo^s),gamma_minus(ixo^s)))
2328 imbalance_a(ixo^s)=mhd_uawsom_imbalance_factor(&
2329 wave_plus(ixo^s),wave_minus(ixo^s))
2330 transfer_a(ixo^s)=rlim_a(ixo^s)*imbalance_a(ixo^s)*&
2331 dsqrt(wave_plus(ixo^s)*wave_minus(ixo^s))
2335 donor(ixo^s)=merge(max(w(ixo^s,
waplus_),zero),&
2336 max(w(ixo^s,
waminus_),zero),transfer_a(ixo^s)>=zero)
2337 transfer_a(ixo^s)=sign(min(abs(transfer_a(ixo^s)),&
2338 donor(ixo^s)/qdt),transfer_a(ixo^s))
2340 transfer_a(ixo^s)=zero
2346 if(have_kink_reflection)
then
2347 wave_kplus(ixo^s)=max(wct(ixo^s,
wkplus_),zero)
2348 wave_kminus(ixo^s)=max(wct(ixo^s,
wkminus_),zero)
2351 call gradient(lnvk,ixi^
l,ixo^
l,idir,grad_component)
2352 grad_k(ixo^s)=grad_k(ixo^s)+vk(ixo^s)*bunit(ixo^s,idir)*&
2353 grad_component(ixo^s)
2358 rlim_k(ixo^s)=min(abs(grad_k(ixo^s)),&
2359 max(gamma_kplus(ixo^s),gamma_kminus(ixo^s)))
2360 imbalance_k(ixo^s)=mhd_uawsom_imbalance_factor(&
2361 wave_kplus(ixo^s),wave_kminus(ixo^s))
2362 transfer_k(ixo^s)=rlim_k(ixo^s)*imbalance_k(ixo^s)*&
2363 dsqrt(wave_kplus(ixo^s)*wave_kminus(ixo^s))
2365 donor(ixo^s)=merge(max(w(ixo^s,
wkplus_),zero),&
2366 max(w(ixo^s,
wkminus_),zero),transfer_k(ixo^s)>=zero)
2367 transfer_k(ixo^s)=sign(min(abs(transfer_k(ixo^s)),&
2368 donor(ixo^s)/qdt),transfer_k(ixo^s))
2370 transfer_k(ixo^s)=zero
2376 end subroutine mhd_add_source_uawsom
2381 integer,
intent(in) :: ixi^
l, ixo^
l
2382 double precision,
intent(inout) :: w(ixi^s, nw)
2383 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2388 {
do ix^db=ixomin^db,ixomax^db\}
2391 +half*((^
c&w(ix^
d,
m^
c_)**2+)/&
2393 +(^
c&w(ix^
d,
b^
c_)**2+))
2397 do ix^db=ixomin^db,ixomax^db\}
2399 w(ix^d,
e_)=w(ix^d,
e_)&
2400 +half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)&
2401 +(^
c&w(ix^d,
b^
c_)**2+))&
2408 subroutine mhd_ei_to_e_hde(ixI^L,ixO^L,w,x)
2410 integer,
intent(in) :: ixi^
l, ixo^
l
2411 double precision,
intent(inout) :: w(ixi^s, nw)
2412 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2416 {
do ix^db=ixomin^db,ixomax^db\}
2422 end subroutine mhd_ei_to_e_hde
2430 integer,
intent(in) :: ixi^
l, ixo^
l
2431 double precision,
intent(in) :: w(ixi^s,nw)
2432 double precision,
intent(out) :: vel(ixo^s,1:
ndir)
2433 double precision,
intent(out),
optional :: emech(ixo^s)
2435 double precision :: btot(1:
ndir), efd(1:
ndir)
2436 double precision :: b2, rhoc2, tmp, inv_rho
2439 {
do ix^db=ixomin^db,ixomax^db\}
2440 ^
c&btot(^
c)=w(ix^
d,
b^
c_)\
2445 b2=(^
c&btot(^
c)**2+)
2446 tmp=(^
c&btot(^
c)*w(ix^
d,
m^
c_)+)
2448 inv_rho=1.d0/(w(ix^
d,
rho_)*(rhoc2+b2))
2449 ^
c&vel(ix^
d,^
c)=(rhoc2*w(ix^
d,
m^
c_)+btot(^
c)*tmp)*inv_rho\
2450 if(
present(emech))
then
2456 efd(1)=btot(2)*vel(ix^
d,3)-btot(3)*vel(ix^
d,2)
2457 efd(2)=btot(3)*vel(ix^
d,1)-btot(1)*vel(ix^
d,3)
2458 efd(3)=btot(1)*vel(ix^
d,2)-btot(2)*vel(ix^
d,1)
2462 efd(2)=btot(1)*vel(ix^
d,2)-btot(2)*vel(ix^
d,1)
2467 emech(ix^
d)=half*((^
c&vel(ix^
d,^
c)**2+)*w(ix^
d,
rho_)&
2468 +(^
c&w(ix^
d,
b^
c_)**2+)&
2469 +(^
c&efd(^
c)**2+)*inv_squared_c)
2481 double precision,
intent(in) :: eint, rho
2482 double precision :: nh, t, rfac
2485 nh=rho/
eos%nH2rhoFactor
2490 p=
eos%gamma_minus_1*eint
2500 double precision,
intent(in) :: p, rho
2501 double precision :: nh
2504 nh=rho/
eos%nH2rhoFactor
2509 eint=p*
eos%inv_gamma_minus_1
2515 subroutine mhd_ei_to_e_semirelati(ixI^L,ixO^L,w,x)
2517 integer,
intent(in) :: ixi^
l, ixo^
l
2518 double precision,
intent(inout) :: w(ixi^s, nw)
2519 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2521 double precision :: vel(ixo^s,1:
ndir), emech(ixo^s)
2524 w(ixo^s,
e_)=w(ixo^s,
e_)+emech(ixo^s)
2526 end subroutine mhd_ei_to_e_semirelati
2531 integer,
intent(in) :: ixi^
l, ixo^
l
2532 double precision,
intent(inout) :: w(ixi^s, nw)
2533 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2538 {
do ix^db=ixomin^db,ixomax^db\}
2541 -half*((^
c&w(ix^
d,
m^
c_)**2+)/&
2543 +(^
c&w(ix^
d,
b^
c_)**2+))
2547 do ix^db=ixomin^db,ixomax^db\}
2549 w(ix^d,
e_)=w(ix^d,
e_)&
2550 -half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)&
2551 +(^
c&w(ix^d,
b^
c_)**2+))&
2556 if(fix_small_values)
then
2557 call mhd_handle_small_ei(w,x,ixi^l,ixi^l,
e_,
'mhd_e_to_ei')
2565 subroutine mhd_e_to_ei_cache_log_nh(ixI^L,ixO^L,w,x)
2567 integer,
intent(in) :: ixi^
l, ixo^
l
2568 double precision,
intent(inout) :: w(ixi^s, nw)
2569 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2571 call mhd_e_to_ei_base(ixi^
l,ixo^
l,w,x)
2572 block%wextra(ixo^s, iw_log_nh) = dlog10(w(ixo^s,
rho_) / eos%nH2rhoFactor)
2573 end subroutine mhd_e_to_ei_cache_log_nh
2576 subroutine mhd_ei_unchanged(ixI^L,ixO^L,w,x)
2578 integer,
intent(in) :: ixi^
l, ixo^
l
2579 double precision,
intent(inout) :: w(ixi^s, nw)
2580 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2581 end subroutine mhd_ei_unchanged
2584 subroutine mhd_e_to_ei_hde(ixI^L,ixO^L,w,x)
2586 integer,
intent(in) :: ixi^
l, ixo^
l
2587 double precision,
intent(inout) :: w(ixi^s, nw)
2588 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2592 {
do ix^db=ixomin^db,ixomax^db\}
2598 if(fix_small_values)
then
2599 call mhd_handle_small_ei(w,x,ixi^l,ixi^l,
e_,
'mhd_e_to_ei_hde')
2602 end subroutine mhd_e_to_ei_hde
2605 subroutine mhd_e_to_ei_semirelati(ixI^L,ixO^L,w,x)
2607 integer,
intent(in) :: ixi^
l, ixo^
l
2608 double precision,
intent(inout) :: w(ixi^s, nw)
2609 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2611 double precision :: vel(ixo^s,1:
ndir), emech(ixo^s)
2614 w(ixo^s,
e_)=w(ixo^s,
e_)-emech(ixo^s)
2617 call mhd_handle_small_ei(w,x,ixi^
l,ixo^
l,
e_,
'mhd_e_to_ei_semirelati')
2620 end subroutine mhd_e_to_ei_semirelati
2622 subroutine mhd_handle_small_values_semirelati(primitive, w, x, ixI^L, ixO^L, subname)
2625 logical,
intent(in) :: primitive
2626 integer,
intent(in) :: ixi^
l,ixo^
l
2627 double precision,
intent(inout) :: w(ixi^s,1:nw)
2628 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2629 character(len=*),
intent(in) :: subname
2631 double precision :: v(ixi^s,1:
ndir), emech(ixi^s), small_rho(ixi^s)
2632 double precision,
allocatable :: work(:^
d&,:)
2633 integer :: ix^
d, ixc^
l
2634 logical :: flag(ixi^s,1:nw)
2644 small_rho(ixc^s)=w(ixc^s,
rho_)
2646 flag(ixc^s,
rho_) = .true.
2649 if(.not.primitive)
then
2656 {
do ix^db=ixcmin^db,ixcmax^db\}
2662 if(any(flag(ixo^s,:)))
then
2663 select case (small_values_method)
2665 {
do ix^db=ixomin^db,ixomax^db\}
2666 if(flag(ix^d,
rho_))
then
2667 ^
c&w(ix^d,
m^
c_)=zero\
2671 w(ix^d,
p_) = small_pressure
2673 w(ix^d,
e_) = small_e + emech(ix^d)
2678 call small_values_average(ixi^l,ixo^l,w,x,flag,
rho_)
2681 call small_values_average(ixi^l,ixo^l,w,x,flag,
p_)
2684 w(ixc^s,
e_)=w(ixc^s,
e_)-emech(ixc^s)
2686 call small_values_average(ixi^l,ixo^l,work,x,flag,
e_)
2688 w(ixc^s,
e_)=w(ixc^s,
e_)+emech(ixc^s)
2693 if(.not.primitive)
then
2695 w(ixo^s,
mom(1:ndir))=v(ixo^s,1:ndir)
2698 where(flag(ixc^s,
rho_))
2699 w(ixc^s,
rho_)=small_rho(ixc^s)
2701 call small_values_error(w,x,ixi^l,ixo^l,flag,subname)
2704 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2705 end subroutine mhd_handle_small_values_semirelati
2707 subroutine mhd_handle_small_values_origin(primitive, w, x, ixI^L, ixO^L, subname)
2710 logical,
intent(in) :: primitive
2711 integer,
intent(in) :: ixi^
l,ixo^
l
2712 double precision,
intent(inout) :: w(ixi^s,1:nw)
2713 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2714 character(len=*),
intent(in) :: subname
2716 integer :: ix^
d, igrp
2717 logical :: flag(ixi^s,1:nw)
2719 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2724 {
do ix^db=ixomin^db,ixomax^db\}
2728 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2752 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2754 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2757 call small_values_average(ixi^l,ixo^l,w,x,flag,
waplus_)
2758 call small_values_average(ixi^l,ixo^l,w,x,flag,
waminus_)
2759 call small_values_average(ixi^l,ixo^l,w,x,flag,
wkplus_)
2760 call small_values_average(ixi^l,ixo^l,w,x,flag,
wkminus_)
2763 {
do ix^db=iximin^db,iximax^db\}
2764 w(ix^d,
e_)=w(ix^d,
e_)&
2765 -half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+))&
2768 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2770 {
do ix^db=iximin^db,iximax^db\}
2771 w(ix^d,
e_)=w(ix^d,
e_)&
2772 +half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+))&
2777 call small_values_average(ixi^l, ixo^l, w, x, flag,
r_e)
2780 if(.not.primitive)
then
2782 {
do ix^db=ixomin^db,ixomax^db\}
2784 w(ix^d,
p_)=eos%gamma_minus_1*(w(ix^d,
e_)&
2785 -half*((^
c&w(ix^d,
m^
c_)**2+)*w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+))&
2789 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2792 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2793 end subroutine mhd_handle_small_values_origin
2795 subroutine mhd_handle_small_values_split(primitive, w, x, ixI^L, ixO^L, subname)
2798 logical,
intent(in) :: primitive
2799 integer,
intent(in) :: ixi^
l,ixo^
l
2800 double precision,
intent(inout) :: w(ixi^s,1:nw)
2801 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2802 character(len=*),
intent(in) :: subname
2804 double precision :: rho
2805 integer :: ix^
d, igrp
2806 logical :: flag(ixi^s,1:nw)
2808 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2813 {
do ix^db=ixomin^db,ixomax^db\}
2818 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2831 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2833 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2836 {
do ix^db=iximin^db,iximax^db\}
2838 w(ix^d,
e_)=w(ix^d,
e_)&
2839 -half*((^
c&w(ix^d,
m^
c_)**2+)/rho+(^
c&w(ix^d,
b^
c_)**2+))
2841 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2843 {
do ix^db=iximin^db,iximax^db\}
2845 w(ix^d,
e_)=w(ix^d,
e_)&
2846 +half*((^
c&w(ix^d,
m^
c_)**2+)/rho+(^
c&w(ix^d,
b^
c_)**2+))
2850 if(.not.primitive)
then
2852 {
do ix^db=ixomin^db,ixomax^db\}
2854 ^
c&w(ix^d,
m^
c_)=w(ix^d,
m^
c_)/rho\
2855 w(ix^d,
p_)=eos%gamma_minus_1*(w(ix^d,
e_)&
2856 -half*((^
c&w(ix^d,
m^
c_)**2+)*rho+(^
c&w(ix^d,
b^
c_)**2+)))
2859 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2862 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2863 end subroutine mhd_handle_small_values_split
2865 subroutine mhd_handle_small_values_inte(primitive, w, x, ixI^L, ixO^L, subname)
2868 logical,
intent(in) :: primitive
2869 integer,
intent(in) :: ixi^
l,ixo^
l
2870 double precision,
intent(inout) :: w(ixi^s,1:nw)
2871 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2872 character(len=*),
intent(in) :: subname
2874 integer :: ix^
d, igrp
2875 logical :: flag(ixi^s,1:nw)
2877 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2882 {
do ix^db=ixomin^db,ixomax^db\}
2883 if(flag(ix^
d,
rho_))
then
2885 ^
c&w(ix^
d,
m^
c_)=0.d0\
2895 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2897 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2899 if(.not.primitive)
then
2901 {
do ix^db=ixomin^db,ixomax^db\}
2903 w(ix^d,
p_)=eos%gamma_minus_1*w(ix^d,
e_)
2906 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2909 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2910 end subroutine mhd_handle_small_values_inte
2912 subroutine mhd_handle_small_values_noe(primitive, w, x, ixI^L, ixO^L, subname)
2915 logical,
intent(in) :: primitive
2916 integer,
intent(in) :: ixi^
l,ixo^
l
2917 double precision,
intent(inout) :: w(ixi^s,1:nw)
2918 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2919 character(len=*),
intent(in) :: subname
2921 integer :: ix^
d, igrp
2922 logical :: flag(ixi^s,1:nw)
2924 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2929 {
do ix^db=ixomin^db,ixomax^db\}
2933 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2939 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2941 if(.not.primitive)
then
2943 {
do ix^db=ixomin^db,ixomax^db\}
2947 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2950 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2951 end subroutine mhd_handle_small_values_noe
2953 subroutine mhd_handle_small_values_hde(primitive, w, x, ixI^L, ixO^L, subname)
2956 logical,
intent(in) :: primitive
2957 integer,
intent(in) :: ixi^
l,ixo^
l
2958 double precision,
intent(inout) :: w(ixi^s,1:nw)
2959 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2960 character(len=*),
intent(in) :: subname
2962 integer :: ix^
d, igrp
2963 logical :: flag(ixi^s,1:nw)
2965 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2970 {
do ix^db=ixomin^db,ixomax^db\}
2971 if(flag(ix^
d,
rho_))
then
2973 ^
c&w(ix^
d,
m^
c_)=0.d0\
2983 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2985 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2987 if(.not.primitive)
then
2989 {
do ix^db=ixomin^db,ixomax^db\}
2991 w(ix^d,
p_)=eos%gamma_minus_1*(w(ix^d,
e_)-half*(^
c&w(ix^d,
m^
c_)**2+)*w(ix^d,
rho_))
2994 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2997 if (
mhd_fip)
call mhd_bound_fip(primitive, ixi^l, ixo^l, w)
2998 end subroutine mhd_handle_small_values_hde
3004 integer,
intent(in) :: ixi^
l, ixo^
l
3005 double precision,
intent(in) :: w(ixi^s,nw), x(ixi^s,1:
ndim)
3006 double precision,
intent(out) :: v(ixi^s,
ndir)
3008 double precision :: rho(ixi^s)
3018 rho(ixo^s)=1.d0/rho(ixo^s)
3021 v(ixo^s, idir) = w(ixo^s,
mom(idir))*rho(ixo^s)
3031 subroutine mhd_uawsom_get_signal_speed(w,x,ixI^L,ixO^L,idim,csignal)
3033 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3034 double precision,
intent(in) :: w(ixi^s,nw), x(ixi^s,1:
ndim)
3035 double precision,
intent(out) :: csignal(ixo^s)
3036 double precision :: cs2(ixi^s), zeta(ixi^s), radius(ixi^s), lperp(ixi^s)
3037 double precision :: btotal(1:
ndir), b2, inv_rho, qwave, sound2
3038 double precision :: cfast2, discriminant, cfast, awave, kmax
3041 call eos%get_csound2(w,x,ixi^
l,ixo^
l,cs2)
3042 call mhd_uawsom_get_coefficients(w,x,ixi^
l,ixo^
l,.true.,zeta,radius,lperp)
3045 {
do ix^db=ixomin^db,ixomax^db\}
3046 inv_rho=one/w(ix^
d,
rho_)
3047 ^
c&btotal(^
c)=w(ix^
d,
b^
c_)\
3051 b2=(^
c&btotal(^
c)**2+)
3054 sound2=cs2(ix^
d)+half*qwave
3055 cfast2=b2*inv_rho+sound2
3056 discriminant=max(zero,cfast2**2-4.d0*sound2*btotal(idim)**2*inv_rho)
3057 cfast=sqrt(half*(cfast2+sqrt(discriminant)))
3061 awave=abs(btotal(idim))*sqrt(inv_rho)*max(one,&
3064 csignal(ix^
d)=half*(cfast+awave+sqrt((cfast-awave)**2+4.d0*qwave))
3066 end subroutine mhd_uawsom_get_signal_speed
3069 subroutine mhd_get_cmax_origin(w,x,ixI^L,ixO^L,idim,cmax)
3072 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3073 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3074 double precision,
intent(inout) :: cmax(ixi^s)
3076 double precision :: rho, inv_rho, cfast2, avmincs2, b2, kmax
3077 double precision :: cs2(ixi^s)
3081 call mhd_uawsom_get_signal_speed(w,x,ixi^
l,ixo^
l,idim,cmax(ixo^s))
3082 cmax(ixo^s)=abs(w(ixo^s,
mom(idim)))+cmax(ixo^s)
3089 call eos%get_csound2(w, x, ixi^
l, ixo^
l, cs2)
3092 {
do ix^db=ixomin^db,ixomax^db \}
3101 cfast2=b2*inv_rho+cs2(ix^
d)
3102 avmincs2=cfast2**2-4.0d0*cs2(ix^
d)*(w(ix^
d,mag(idim))+
block%B0(ix^
d,idim,
b0i))**2*inv_rho
3103 if(avmincs2<zero) avmincs2=zero
3104 cmax(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3108 cmax(ix^
d)=max(cmax(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3110 cmax(ix^
d)=abs(w(ix^
d,
mom(idim)))+cmax(ix^
d)
3113 {
do ix^db=ixomin^db,ixomax^db \}
3121 b2=(^
c&w(ix^d,
b^
c_)**2+)
3122 cfast2=b2*inv_rho+cs2(ix^d)
3123 avmincs2=cfast2**2-4.0d0*cs2(ix^d)*w(ix^d,mag(idim))**2*inv_rho
3124 if(avmincs2<zero) avmincs2=zero
3125 cmax(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3129 cmax(ix^d)=max(cmax(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3131 cmax(ix^d)=abs(w(ix^d,
mom(idim)))+cmax(ix^d)
3135 end subroutine mhd_get_cmax_origin
3138 subroutine mhd_get_cmax_origin_noe(w,x,ixI^L,ixO^L,idim,cmax)
3142 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3143 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3144 double precision,
intent(inout) :: cmax(ixi^s)
3146 double precision :: inv_rho, cfast2, avmincs2, b2, kmax
3147 double precision :: adiabs(ixi^s), gammas(ixi^s)
3162 {
do ix^db=ixomin^db,ixomax^db \}
3163 inv_rho=1.d0/w(ix^
d,
rho_)
3165 cmax(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
3167 b2=(^
c&w(ix^
d,
b^
c_)**2+)
3168 cfast2=b2*inv_rho+cmax(ix^
d)
3169 avmincs2=cfast2**2-4.0d0*cmax(ix^
d)*w(ix^
d,mag(idim))**2*inv_rho
3170 if(avmincs2<zero) avmincs2=zero
3171 cmax(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3175 cmax(ix^
d)=max(cmax(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3177 cmax(ix^
d)=abs(w(ix^
d,
mom(idim)))+cmax(ix^
d)
3180 end subroutine mhd_get_cmax_origin_noe
3183 subroutine mhd_get_cmax_semirelati(w,x,ixI^L,ixO^L,idim,cmax)
3186 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3187 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3188 double precision,
intent(inout):: cmax(ixi^s)
3190 double precision :: csound(ixo^s), gamma2(ixo^s)
3192 call mhd_get_csound_semirelati(w,x,ixi^
l,ixo^
l,idim,csound,gamma2)
3194 cmax(ixo^s)=gamma2(ixo^s)*abs(w(ixo^s,
mom(idim)))+csound(ixo^s)
3196 end subroutine mhd_get_cmax_semirelati
3199 subroutine mhd_get_cmax_semirelati_noe(w,x,ixI^L,ixO^L,idim,cmax)
3203 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3204 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3205 double precision,
intent(inout):: cmax(ixi^s)
3207 double precision :: adiabs(ixi^s), gammas(ixi^s)
3208 double precision :: csound, avmincs2, idim_alfven_speed2
3209 double precision :: inv_rho, alfven_speed2, gamma2
3223 {
do ix^db=ixomin^db,ixomax^db \}
3224 inv_rho=1.d0/w(ix^
d,
rho_)
3225 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
3226 gamma2=1.0d0/(1.d0+alfven_speed2*inv_squared_c)
3227 cmax(ix^
d)=1.d0-gamma2*w(ix^
d,
mom(idim))**2*inv_squared_c
3229 csound=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
3230 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
3233 alfven_speed2=alfven_speed2*cmax(ix^
d)+csound*(1.d0+idim_alfven_speed2*inv_squared_c)
3234 avmincs2=(gamma2*alfven_speed2)**2-4.0d0*gamma2*csound*idim_alfven_speed2*cmax(ix^
d)
3235 if(avmincs2<zero) avmincs2=zero
3237 cmax(ix^
d)=gamma2*abs(w(ix^
d,
mom(idim)))+sqrt(half*(gamma2*alfven_speed2+sqrt(avmincs2)))
3240 end subroutine mhd_get_cmax_semirelati_noe
3243 subroutine mhd_get_tcutoff(ixI^L,ixO^L,w,x,Tco_local,Tmax_local)
3248 integer,
intent(in) :: ixi^
l,ixo^
l
3249 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3251 double precision,
intent(inout) :: w(ixi^s,1:nw)
3252 double precision,
intent(out) :: tco_local,tmax_local
3254 double precision,
parameter :: trac_delta=0.25d0
3255 double precision :: te(ixi^s),lts(ixi^s)
3256 double precision,
dimension(1:ndim) :: bdir, bunitvec
3257 double precision,
dimension(ixI^S,1:ndim) :: gradt
3258 double precision :: ltrc,ltrp,altr
3260 double precision :: q_heat(ixi^s), ne(ixi^s), nh_arr(ixi^s)
3261 double precision :: bvec(1:
ndir)
3262 double precision :: bmin_c, bmag, gnorm, bgtd, l_t, dl_eff, vmag, bdotv, binp2
3263 double precision :: v_n, a_coeff, l1, cooling, net_cool
3264 double precision :: kappa_par, disc, dx_over_delta, kappa_trac, kappa_eff, tcoff_eff
3265 integer :: idims,ix^
d,jxo^
l,hxo^
l,ixa^
d,ixb^
d
3266 integer :: jxp^
l,hxp^
l,ixp^
l,ixq^
l
3268 if (eos%eos_type ==
'LTE' .or. eos%eos_type ==
'PI')
then
3269 te(ixi^s) = w(ixi^s,
te_)
3272 call eos%get_Rfactor(w,x,ixi^
l,ixi^
l,te)
3273 te(ixi^s)=w(ixi^s,
p_)/(te(ixi^s)*ne(ixi^s))
3276 tmax_local=maxval(te(ixo^s))
3284 do ix1=ixomin1,ixomax1
3285 lts(ix1)=0.5d0*abs(te(ix1+1)-te(ix1-1))/te(ix1)
3286 if(lts(ix1)>trac_delta)
then
3287 tco_local=max(tco_local,te(ix1))
3299 lts(ixp^s)=0.5d0*abs(te(jxp^s)-te(hxp^s))/te(ixp^s)
3300 lts(ixp^s)=max(one, (exp(lts(ixp^s))/ltrc)**ltrp)
3301 lts(ixo^s)=0.25d0*(lts(jxo^s)+two*lts(ixo^s)+lts(hxo^s))
3302 block%wextra(ixo^s,
tcoff_)=te(ixo^s)*lts(ixo^s)**0.4d0
3304 call mpistop(
"mhd_trac_type not allowed for 1D simulation")
3315 call gradient(te,ixi^
l,ixo^
l,idims,gradt(ixi^s,idims))
3322 ixb^
d=(ixomin^
d+ixomax^
d-1)/2+ixa^
d;
3327 ixb^d=(ixomin^d+ixomax^d-1)/2+ixa^d;
3328 bdir(1:ndim)=bdir(1:ndim)+w(ixb^d,iw_mag(1:ndim))
3332 if(bdir(1)/=0.d0)
then
3333 block%special_values(3)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3335 block%special_values(3)=0.d0
3337 if(bdir(2)/=0.d0)
then
3338 block%special_values(4)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3340 block%special_values(4)=0.d0
3344 if(bdir(1)/=0.d0)
then
3345 block%special_values(3)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+&
3346 (bdir(3)/bdir(1))**2)
3348 block%special_values(3)=0.d0
3350 if(bdir(2)/=0.d0)
then
3351 block%special_values(4)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+&
3352 (bdir(3)/bdir(2))**2)
3354 block%special_values(4)=0.d0
3356 if(bdir(3)/=0.d0)
then
3357 block%special_values(5)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+&
3358 (bdir(2)/bdir(3))**2)
3360 block%special_values(5)=0.d0
3365 block%special_values(1)=zero
3366 {
do ix^db=ixomin^db,ixomax^db\}
3368 ^d&bdir(^d)=w({ix^d},iw_mag(^d))+block%B0({ix^d},^d,0)\
3370 ^d&bdir(^d)=w({ix^d},iw_mag(^d))\
3373 if(bdir(1)/=0.d0)
then
3374 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3378 if(bdir(2)/=0.d0)
then
3379 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3384 lts(ix^d)=min(block%ds(ix^d,1),block%ds(ix^d,2))*&
3385 abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3388 if(bdir(1)/=0.d0)
then
3389 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+(bdir(3)/bdir(1))**2)
3393 if(bdir(2)/=0.d0)
then
3394 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+(bdir(3)/bdir(2))**2)
3398 if(bdir(3)/=0.d0)
then
3399 bunitvec(3)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+(bdir(2)/bdir(3))**2)
3404 lts(ix^d)=min(block%ds(ix^d,1),block%ds(ix^d,2),block%ds(ix^d,3))*&
3405 abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3407 if(lts(ix^d)>trac_delta)
then
3408 block%special_values(1)=max(block%special_values(1),te(ix^d))
3411 block%special_values(2)=tmax_local
3430 call gradient(te,ixi^l,ixq^l,idims,gradt(ixi^s,idims))
3434 call gradientf(te,x,ixi^l,hxp^l,idims,gradt(ixi^s,idims),1,.true.)
3435 call gradientf(te,x,ixi^l,jxp^l,idims,gradt(ixi^s,idims),1,.false.)
3439 {
do ix^db=ixpmin^db,ixpmax^db\}
3440 ^d&bdir(^d)=w({ix^d},iw_mag(^d))+block%B0({ix^d},^d,0)\
3442 if(bdir(1)/=0.d0)
then
3443 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3447 if(bdir(2)/=0.d0)
then
3448 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3454 if(bdir(1)/=0.d0)
then
3455 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+(bdir(3)/bdir(1))**2)
3459 if(bdir(2)/=0.d0)
then
3460 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+(bdir(3)/bdir(2))**2)
3464 if(bdir(3)/=0.d0)
then
3465 bunitvec(3)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+(bdir(2)/bdir(3))**2)
3471 lts(ix^d)=abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3473 lts(ix^d)=min(^d&block%ds({ix^d},^d))*lts(ix^d)
3474 lts(ix^d)=max(one,(exp(lts(ix^d))/ltrc)**ltrp)
3477 {
do ix^db=ixpmin^db,ixpmax^db\}
3479 if(w(ix^d,iw_mag(1))/=0.d0)
then
3480 bunitvec(1)=sign(1.d0,w(ix^d,iw_mag(1)))/dsqrt(1.d0+(w(ix^d,iw_mag(2))/w(ix^d,iw_mag(1)))**2)
3484 if(w(ix^d,iw_mag(2))/=0.d0)
then
3485 bunitvec(2)=sign(1.d0,w(ix^d,iw_mag(2)))/dsqrt(1.d0+(w(ix^d,iw_mag(1))/w(ix^d,iw_mag(2)))**2)
3491 if(w(ix^d,iw_mag(1))/=0.d0)
then
3492 bunitvec(1)=sign(1.d0,w(ix^d,iw_mag(1)))/dsqrt(1.d0+(w(ix^d,iw_mag(2))/w(ix^d,iw_mag(1)))**2+&
3493 (w(ix^d,iw_mag(3))/w(ix^d,iw_mag(1)))**2)
3497 if(w(ix^d,iw_mag(2))/=0.d0)
then
3498 bunitvec(2)=sign(1.d0,w(ix^d,iw_mag(2)))/dsqrt(1.d0+(w(ix^d,iw_mag(1))/w(ix^d,iw_mag(2)))**2+&
3499 (w(ix^d,iw_mag(3))/w(ix^d,iw_mag(2)))**2)
3503 if(w(ix^d,iw_mag(3))/=0.d0)
then
3504 bunitvec(3)=sign(1.d0,w(ix^d,iw_mag(3)))/dsqrt(1.d0+(w(ix^d,iw_mag(1))/w(ix^d,iw_mag(3)))**2+&
3505 (w(ix^d,iw_mag(2))/w(ix^d,iw_mag(3)))**2)
3511 lts(ix^d)=abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3513 lts(ix^d)=min(^d&block%ds({ix^d},^d))*lts(ix^d)
3514 lts(ix^d)=max(one,(exp(lts(ix^d))/ltrc)**ltrp)
3520 {
do ix^db=ixpmin^db,ixpmax^db\}
3522 altr=0.25d0*((lts(ix1-1,ix2)+two*lts(ix^d)+lts(ix1+1,ix2))*bunitvec(1)**2+&
3523 (lts(ix1,ix2-1)+two*lts(ix^d)+lts(ix1,ix2+1))*bunitvec(2)**2)
3524 block%wextra(ix^d,
tcoff_)=te(ix^d)*altr**0.4d0
3527 altr=0.25d0*((lts(ix1-1,ix2,ix3)+two*lts(ix^d)+lts(ix1+1,ix2,ix3))*bunitvec(1)**2+&
3528 (lts(ix1,ix2-1,ix3)+two*lts(ix^d)+lts(ix1,ix2+1,ix3))*bunitvec(2)**2+&
3529 (lts(ix1,ix2,ix3-1)+two*lts(ix^d)+lts(ix1,ix2,ix3+1))*bunitvec(3)**2)
3530 block%wextra(ix^d,
tcoff_)=te(ix^d)*altr**0.4d0
3540 call usr_get_heating(q_heat, ixi^l, ixo^l, w, x)
3541 call eos%get_ne_nH(ixi^l, ixo^l, w, x, ne, nh_arr)
3542 block%wextra(ixi^s,
tcoff_) = te(ixi^s)
3544 call gradient(te,ixi^l,ixo^l,idims,gradt(ixi^s,idims))
3546 bmin_c = 0.1d0/unit_magneticfield
3547 {
do ix^db=ixomin^db,ixomax^db\}
3549 bmag=bmin_c**2; bdotv=0.d0; vmag=0.d0
3551 bvec(idims)=w(ix^d,iw_mag(idims))
3552 if(b0field) bvec(idims)=bvec(idims)+block%B0(ix^d,idims,0)
3553 bmag =bmag +bvec(idims)**2
3554 bdotv=bdotv+bvec(idims)*w(ix^d,
mom(idims))
3555 vmag =vmag +w(ix^d,
mom(idims))**2
3557 bmag=dsqrt(bmag); vmag=dsqrt(vmag)
3559 gnorm=0.d0; binp2=0.d0; bgtd=0.d0
3561 gnorm=gnorm+gradt(ix^d,idims)**2
3562 binp2=binp2+bvec(idims)**2
3563 bgtd =bgtd +bvec(idims)*gradt(ix^d,idims)
3566 if(gnorm<smalldouble .or. binp2<smalldouble)
then
3567 block%wextra(ix^d,
tcoff_)=te(ix^d)
3570 l_t=te(ix^d)*bmag/(dabs(bgtd)+bmin_c*gnorm)
3574 dl_eff=dl_eff+(bvec(idims)/block%ds(ix^d,idims))**2
3576 dl_eff=bmag/dsqrt(dl_eff)
3578 v_n=(dabs(bdotv)+bmin_c*vmag)/bmag
3579 a_coeff=2.5d0*w(ix^d,
p_)*v_n/te(ix^d)
3582 if(te(ix^d)>
rc_fl%tcoolmin .and. te(ix^d)<
rc_fl%tcoolmax)
then
3583 call findl(te(ix^d),l1,
rc_fl); cooling=l1*ne(ix^d)*nh_arr(ix^d)
3584 else if(te(ix^d)>=
rc_fl%tcoolmax)
then
3585 call calc_l_extended(te(ix^d),l1,
rc_fl); cooling=l1*ne(ix^d)*nh_arr(ix^d)
3589 net_cool=dabs(cooling-q_heat(ix^d))
3590 kappa_par=
tc_fl%tc_k_para*te(ix^d)**2.5d0
3591 disc=a_coeff**2+4.d0*
tc_fl%tc_k_para*te(ix^d)**1.5d0*net_cool
3594 if(l_t<=2.d0*dx_over_delta)
then
3595 kappa_trac=(a_coeff+dsqrt(disc))/(2.d0/dx_over_delta)
3597 kappa_trac=dsqrt(4.d0*
tc_fl%tc_k_para*te(ix^d)**1.5d0*net_cool)/(2.d0/dx_over_delta)
3599 kappa_eff=max(kappa_trac,kappa_par)
3600 tcoff_eff=(kappa_eff/
tc_fl%tc_k_para)**0.4d0
3601 block%wextra(ix^d,
tcoff_)=max(te(ix^d),tcoff_eff)
3607 call mpistop(
"unknown mhd_trac_type")
3610 end subroutine mhd_get_tcutoff
3613 subroutine mhd_get_h_speed(wprim,x,ixI^L,ixO^L,idim,Hspeed)
3616 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3617 double precision,
intent(in) :: wprim(ixi^s, nw)
3618 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3619 double precision,
intent(out) :: hspeed(ixi^s,1:number_species)
3621 double precision :: csound(ixi^s,
ndim)
3622 double precision,
allocatable :: tmp(:^
d&)
3623 integer :: jxc^
l, ixc^
l, ixa^
l, id, ix^
d
3627 allocate(tmp(ixa^s))
3630 call mhd_get_csound_prim_split(wprim,x,ixi^
l,ixa^
l,id,tmp)
3632 call mhd_get_csound_prim(wprim,x,ixi^
l,ixa^
l,id,tmp)
3634 csound(ixa^s,id)=tmp(ixa^s)
3637 ixcmin^
d=ixomin^
d+
kr(idim,^
d)-1;
3638 jxcmax^
d=ixcmax^
d+
kr(idim,^
d);
3639 jxcmin^
d=ixcmin^
d+
kr(idim,^
d);
3640 hspeed(ixc^s,1)=0.5d0*abs(wprim(jxc^s,
mom(idim))+csound(jxc^s,idim)-wprim(ixc^s,
mom(idim))+csound(ixc^s,idim))
3644 ixamax^
d=ixcmax^
d+
kr(id,^
d);
3645 ixamin^
d=ixcmin^
d+
kr(id,^
d);
3646 hspeed(ixc^s,1)=max(hspeed(ixc^s,1),0.5d0*abs(wprim(ixa^s,
mom(id))+csound(ixa^s,id)-wprim(ixc^s,
mom(id))+csound(ixc^s,id)))
3647 ixamax^
d=ixcmax^
d-
kr(id,^
d);
3648 ixamin^
d=ixcmin^
d-
kr(id,^
d);
3649 hspeed(ixc^s,1)=max(hspeed(ixc^s,1),0.5d0*abs(wprim(ixc^s,
mom(id))+csound(ixc^s,id)-wprim(ixa^s,
mom(id))+csound(ixa^s,id)))
3654 ixamax^
d=jxcmax^
d+
kr(id,^
d);
3655 ixamin^
d=jxcmin^
d+
kr(id,^
d);
3656 hspeed(ixc^s,1)=max(hspeed(ixc^s,1),0.5d0*abs(wprim(ixa^s,
mom(id))+csound(ixa^s,id)-wprim(jxc^s,
mom(id))+csound(jxc^s,id)))
3657 ixamax^
d=jxcmax^
d-
kr(id,^
d);
3658 ixamin^
d=jxcmin^
d-
kr(id,^
d);
3659 hspeed(ixc^s,1)=max(hspeed(ixc^s,1),0.5d0*abs(wprim(jxc^s,
mom(id))+csound(jxc^s,id)-wprim(ixa^s,
mom(id))+csound(ixa^s,id)))
3663 end subroutine mhd_get_h_speed
3666 subroutine mhd_get_cbounds(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3670 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3671 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3672 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3673 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3674 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3675 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3676 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3678 double precision :: wmean(ixi^s,nw), csoundl(ixo^s), csoundr(ixo^s)
3680 double precision :: umean, dmean, tmp1, tmp2, tmp3
3687 call mhd_get_csound_prim(wlp,x,ixi^
l,ixo^
l,idim,csoundl)
3688 call mhd_get_csound_prim(wrp,x,ixi^
l,ixo^
l,idim,csoundr)
3693 if(
present(cmin))
then
3694 {
do ix^db=ixomin^db,ixomax^db\}
3695 tmp1=sqrt(wlp(ix^
d,
rho_))
3696 tmp2=sqrt(wrp(ix^
d,
rho_))
3697 tmp3=1.d0/(tmp1+tmp2)
3698 umean=(wlp(ix^
d,
mom(idim))*tmp1+wrp(ix^
d,
mom(idim))*tmp2)*tmp3
3699 dmean=sqrt((tmp1*csoundl(ix^
d)**2+tmp2*csoundr(ix^
d)**2)*tmp3+&
3700 half*tmp1*tmp2*tmp3**2*(wrp(ix^
d,
mom(idim))-wlp(ix^
d,
mom(idim)))**2)
3701 cmin(ix^
d,1)=umean-dmean
3702 cmax(ix^
d,1)=umean+dmean
3709 if(h_correction)
then
3710 {
do ix^db=ixomin^db,ixomax^db\}
3711 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3712 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3716 {
do ix^db=ixomin^db,ixomax^db\}
3717 tmp1=sqrt(wlp(ix^d,
rho_))
3718 tmp2=sqrt(wrp(ix^d,
rho_))
3719 tmp3=1.d0/(tmp1+tmp2)
3720 umean=(wlp(ix^d,
mom(idim))*tmp1+wrp(ix^d,
mom(idim))*tmp2)*tmp3
3721 dmean=sqrt((tmp1*csoundl(ix^d)**2+tmp2*csoundr(ix^d)**2)*tmp3+&
3722 half*tmp1*tmp2*tmp3**2*(wrp(ix^d,
mom(idim))-wlp(ix^d,
mom(idim)))**2)
3723 cmax(ix^d,1)=abs(umean)+dmean
3731 wmean(ixo^s,1:nwflux)=0.5d0*(wlp(ixo^s,1:nwflux)+wrp(ixo^s,1:nwflux))
3732 call mhd_get_csound_prim(wmean,x,ixi^l,ixo^l,idim,csoundr)
3736 if(
present(cmin))
then
3737 {
do ix^db=ixomin^db,ixomax^db\}
3738 cmax(ix^d,1)=max(wmean(ix^d,
mom(idim))+csoundr(ix^d),zero)
3739 cmin(ix^d,1)=min(wmean(ix^d,
mom(idim))-csoundr(ix^d),zero)
3746 if(h_correction)
then
3747 {
do ix^db=ixomin^db,ixomax^db\}
3748 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3749 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3753 cmax(ixo^s,1)=abs(wmean(ixo^s,
mom(idim)))+csoundr(ixo^s)
3761 call mhd_get_csound_prim(wlp,x,ixi^l,ixo^l,idim,csoundl)
3762 call mhd_get_csound_prim(wrp,x,ixi^l,ixo^l,idim,csoundr)
3767 if(
present(cmin))
then
3768 {
do ix^db=ixomin^db,ixomax^db\}
3769 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3770 cmin(ix^d,1)=min(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))-csoundl(ix^d)
3771 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3778 if(h_correction)
then
3779 {
do ix^db=ixomin^db,ixomax^db\}
3780 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3781 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3785 {
do ix^db=ixomin^db,ixomax^db\}
3786 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3787 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3796 end subroutine mhd_get_cbounds
3799 subroutine mhd_get_cbounds_semirelati(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3802 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3803 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3804 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3805 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3806 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3807 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3808 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3810 double precision,
dimension(ixO^S) :: csoundl, csoundr, gamma2l, gamma2r
3815 call mhd_get_csound_semirelati(wlp,x,ixi^
l,ixo^
l,idim,csoundl,gamma2l)
3816 call mhd_get_csound_semirelati(wrp,x,ixi^
l,ixo^
l,idim,csoundr,gamma2r)
3818 call mhd_get_csound_semirelati_noe(wlp,x,ixi^
l,ixo^
l,idim,csoundl,gamma2l)
3819 call mhd_get_csound_semirelati_noe(wrp,x,ixi^
l,ixo^
l,idim,csoundr,gamma2r)
3821 if(
present(cmin))
then
3822 {
do ix^db=ixomin^db,ixomax^db\}
3823 csoundl(ix^
d)=max(csoundl(ix^
d),csoundr(ix^
d))
3824 cmin(ix^
d,1)=min(gamma2l(ix^
d)*wlp(ix^
d,
mom(idim)),gamma2r(ix^
d)*wrp(ix^
d,
mom(idim)))-csoundl(ix^
d)
3825 cmax(ix^
d,1)=max(gamma2l(ix^
d)*wlp(ix^
d,
mom(idim)),gamma2r(ix^
d)*wrp(ix^
d,
mom(idim)))+csoundl(ix^
d)
3828 {
do ix^db=ixomin^db,ixomax^db\}
3829 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3830 cmax(ix^d,1)=max(gamma2l(ix^d)*wlp(ix^d,
mom(idim)),gamma2r(ix^d)*wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3834 end subroutine mhd_get_cbounds_semirelati
3837 subroutine mhd_get_cbounds_split_rho(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3840 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3841 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3842 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3843 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3844 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3845 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3846 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3848 double precision :: wmean(ixi^s,nw), csoundl(ixo^s), csoundr(ixo^s)
3849 double precision :: umean, dmean, tmp1, tmp2, tmp3
3856 call mhd_get_csound_prim_split(wlp,x,ixi^
l,ixo^
l,idim,csoundl)
3857 call mhd_get_csound_prim_split(wrp,x,ixi^
l,ixo^
l,idim,csoundr)
3858 if(
present(cmin))
then
3859 {
do ix^db=ixomin^db,ixomax^db\}
3862 tmp3=1.d0/(tmp1+tmp2)
3863 umean=(wlp(ix^
d,
mom(idim))*tmp1+wrp(ix^
d,
mom(idim))*tmp2)*tmp3
3864 dmean=sqrt((tmp1*csoundl(ix^
d)**2+tmp2*csoundr(ix^
d)**2)*tmp3+&
3865 half*tmp1*tmp2*tmp3**2*(wrp(ix^
d,
mom(idim))-wlp(ix^
d,
mom(idim)))**2)
3866 cmin(ix^
d,1)=umean-dmean
3867 cmax(ix^
d,1)=umean+dmean
3869 if(h_correction)
then
3870 {
do ix^db=ixomin^db,ixomax^db\}
3871 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3872 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3876 {
do ix^db=ixomin^db,ixomax^db\}
3879 tmp3=1.d0/(tmp1+tmp2)
3880 umean=(wlp(ix^d,
mom(idim))*tmp1+wrp(ix^d,
mom(idim))*tmp2)*tmp3
3881 dmean=sqrt((tmp1*csoundl(ix^d)**2+tmp2*csoundr(ix^d)**2)*tmp3+&
3882 half*tmp1*tmp2*tmp3**2*(wrp(ix^d,
mom(idim))-wlp(ix^d,
mom(idim)))**2)
3883 cmax(ix^d,1)=abs(umean)+dmean
3887 wmean(ixo^s,1:nwflux)=0.5d0*(wlp(ixo^s,1:nwflux)+wrp(ixo^s,1:nwflux))
3888 call mhd_get_csound_prim_split(wmean,x,ixi^l,ixo^l,idim,csoundr)
3889 if(
present(cmin))
then
3890 {
do ix^db=ixomin^db,ixomax^db\}
3891 cmax(ix^d,1)=max(wmean(ix^d,
mom(idim))+csoundr(ix^d),zero)
3892 cmin(ix^d,1)=min(wmean(ix^d,
mom(idim))-csoundr(ix^d),zero)
3894 if(h_correction)
then
3895 {
do ix^db=ixomin^db,ixomax^db\}
3896 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3897 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3901 cmax(ixo^s,1)=abs(wmean(ixo^s,
mom(idim)))+csoundr(ixo^s)
3905 call mhd_get_csound_prim_split(wlp,x,ixi^l,ixo^l,idim,csoundl)
3906 call mhd_get_csound_prim_split(wrp,x,ixi^l,ixo^l,idim,csoundr)
3907 if(
present(cmin))
then
3908 {
do ix^db=ixomin^db,ixomax^db\}
3909 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3910 cmin(ix^d,1)=min(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))-csoundl(ix^d)
3911 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3913 if(h_correction)
then
3914 {
do ix^db=ixomin^db,ixomax^db\}
3915 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3916 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3920 {
do ix^db=ixomin^db,ixomax^db\}
3921 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3922 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3927 end subroutine mhd_get_cbounds_split_rho
3930 subroutine mhd_get_ct_velocity_average(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3933 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3934 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3935 double precision,
intent(in) :: cmax(ixi^s)
3936 double precision,
intent(in),
optional :: cmin(ixi^s)
3937 type(ct_velocity),
intent(inout):: vcts
3939 end subroutine mhd_get_ct_velocity_average
3941 subroutine mhd_get_ct_velocity_contact(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3944 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3945 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3946 double precision,
intent(in) :: cmax(ixi^s)
3947 double precision,
intent(in),
optional :: cmin(ixi^s)
3948 type(ct_velocity),
intent(inout):: vcts
3950 if(.not.
allocated(vcts%vnorm))
allocate(vcts%vnorm(ixi^s,1:
ndim))
3952 vcts%vnorm(ixo^s,idim)=0.5d0*(wlp(ixo^s,
mom(idim))+wrp(ixo^s,
mom(idim)))
3954 end subroutine mhd_get_ct_velocity_contact
3956 subroutine mhd_get_ct_velocity_hll(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3959 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3960 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3961 double precision,
intent(in) :: cmax(ixi^s)
3962 double precision,
intent(in),
optional :: cmin(ixi^s)
3963 type(ct_velocity),
intent(inout):: vcts
3965 integer :: idime,idimn
3967 if(.not.
allocated(vcts%vbarC))
then
3968 allocate(vcts%vbarC(ixi^s,1:
ndir,2),vcts%vbarLC(ixi^s,1:
ndir,2),vcts%vbarRC(ixi^s,1:
ndir,2))
3969 allocate(vcts%cbarmin(ixi^s,1:
ndim),vcts%cbarmax(ixi^s,1:
ndim))
3972 if(
present(cmin))
then
3973 vcts%cbarmin(ixo^s,idim)=max(-cmin(ixo^s),zero)
3974 vcts%cbarmax(ixo^s,idim)=max( cmax(ixo^s),zero)
3976 vcts%cbarmax(ixo^s,idim)=max( cmax(ixo^s),zero)
3977 vcts%cbarmin(ixo^s,idim)=vcts%cbarmax(ixo^s,idim)
3980 idimn=mod(idim,
ndir)+1
3981 idime=mod(idim+1,
ndir)+1
3983 vcts%vbarLC(ixo^s,idim,1)=wlp(ixo^s,
mom(idimn))
3984 vcts%vbarRC(ixo^s,idim,1)=wrp(ixo^s,
mom(idimn))
3985 vcts%vbarC(ixo^s,idim,1)=(vcts%cbarmax(ixo^s,idim)*vcts%vbarLC(ixo^s,idim,1) &
3986 +vcts%cbarmin(ixo^s,idim)*vcts%vbarRC(ixo^s,idim,1))&
3987 /(vcts%cbarmax(ixo^s,idim)+vcts%cbarmin(ixo^s,idim))
3989 vcts%vbarLC(ixo^s,idim,2)=wlp(ixo^s,
mom(idime))
3990 vcts%vbarRC(ixo^s,idim,2)=wrp(ixo^s,
mom(idime))
3991 vcts%vbarC(ixo^s,idim,2)=(vcts%cbarmax(ixo^s,idim)*vcts%vbarLC(ixo^s,idim,2) &
3992 +vcts%cbarmin(ixo^s,idim)*vcts%vbarRC(ixo^s,idim,2))&
3993 /(vcts%cbarmax(ixo^s,idim)+vcts%cbarmin(ixo^s,idim))
3995 end subroutine mhd_get_ct_velocity_hll
4002 integer,
intent(in) :: ixi^
l, ixo^
l
4003 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4004 double precision,
intent(out):: csound(ixi^s)
4006 double precision :: wprim(ixi^s, nw)
4008 wprim(ixi^s,1:nw)=w(ixi^s,1:nw)
4009 call eos%to_primitive(ixi^
l,ixo^
l,wprim,x)
4021 integer,
intent(in) :: ixi^
l, ixo^
l
4022 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4023 double precision,
intent(out):: csound(ixi^s)
4025 double precision :: inv_rho, b2
4026 double precision :: prad_tensor(ixi^s, 1:
ndim, 1:
ndim)
4027 double precision :: prad_max(ixi^s)
4028 integer :: ix^
d,idim
4035 prad_tensor(ixo^s,idim,idim)=w(ixo^s,
r_e)/3.0d0
4040 {
do ix^db=ixomin^db,ixomax^db \}
4041 inv_rho=1.d0/w(ix^
d,
rho_)
4042 prad_max(ix^
d) = (4.0d0/3.0d0)*maxval(prad_tensor(ix^
d,:,:))
4044 csound(ix^
d)=(eos%gamma*w(ix^
d,
p_)+b2+prad_max(ix^
d))*inv_rho
4047 {
do ix^db=ixomin^db,ixomax^db \}
4048 inv_rho=1.d0/w(ix^d,
rho_)
4049 prad_max(ix^d) = (4.0d0/3.0d0)*maxval(prad_tensor(ix^d,:,:))
4050 b2=(^
c&w(ix^d,
b^
c_)**2+)
4051 csound(ix^d)=(eos%gamma*w(ix^d,
p_)+b2+prad_max(ix^d))*inv_rho
4055 if(minval(csound(ixo^s))<smalldouble)
then
4056 print *,
'issue with squared speed and rad pressure'
4057 print *,minval(csound(ixo^s))
4058 print *,minval(prad_max(ixo^s))
4059 call mpistop(
"negative squared speed in get_csrad2 for dt")
4065 subroutine mhd_get_csound_prim(w,x,ixI^L,ixO^L,idim,csound)
4070 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4071 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4072 double precision,
intent(out):: csound(ixo^s)
4074 double precision :: adiabs(ixi^s), gammas(ixi^s)
4075 double precision :: inv_rho, cfast2, avmincs2, b2, kmax
4076 double precision :: cs2(ixi^s)
4080 call mhd_uawsom_get_signal_speed(w,x,ixi^
l,ixo^
l,idim,csound)
4088 call eos%get_csound2(w, x, ixi^
l, ixo^
l, cs2)
4104 {
do ix^db=ixomin^db,ixomax^db \}
4105 inv_rho=1.d0/w(ix^
d,
rho_)
4109 cs2(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
4112 cfast2=b2*inv_rho+cs2(ix^
d)
4113 avmincs2=cfast2**2-4.0d0*cs2(ix^
d)*(w(ix^
d,mag(idim))+&
4115 if(avmincs2<zero) avmincs2=zero
4116 csound(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
4118 csound(ix^
d)=max(csound(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
4122 {
do ix^db=ixomin^db,ixomax^db \}
4123 inv_rho=1.d0/w(ix^d,
rho_)
4127 cs2(ix^d)=gammas(ix^d)*adiabs(ix^d)*w(ix^d,
rho_)**(gammas(ix^d)-1.d0)
4129 b2=(^
c&w(ix^d,
b^
c_)**2+)
4130 cfast2=b2*inv_rho+cs2(ix^d)
4131 avmincs2=cfast2**2-4.0d0*cs2(ix^d)*w(ix^d,mag(idim))**2*inv_rho
4132 if(avmincs2<zero) avmincs2=zero
4133 csound(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
4135 csound(ix^d)=max(csound(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
4140 end subroutine mhd_get_csound_prim
4144 subroutine mhd_get_csound_prim_split(w,x,ixI^L,ixO^L,idim,csound)
4147 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4148 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4149 double precision,
intent(out):: csound(ixo^s)
4151 double precision :: rho, inv_rho, cfast2, avmincs2, b2, kmax
4158 {
do ix^db=ixomin^db,ixomax^db \}
4163 cfast2=b2*inv_rho+csound(ix^
d)
4164 avmincs2=cfast2**2-4.0d0*csound(ix^
d)*(w(ix^
d,mag(idim))+&
4166 if(avmincs2<zero) avmincs2=zero
4167 csound(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
4169 csound(ix^
d)=max(csound(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
4173 {
do ix^db=ixomin^db,ixomax^db \}
4176 csound(ix^d)=eos%gamma*(w(ix^d,
p_)+block%equi_vars(ix^d,
equi_pe0_,b0i))*inv_rho
4177 b2=(^
c&w(ix^d,
b^
c_)**2+)
4178 cfast2=b2*inv_rho+csound(ix^d)
4179 avmincs2=cfast2**2-4.0d0*csound(ix^d)*w(ix^d,mag(idim))**2*inv_rho
4180 if(avmincs2<zero) avmincs2=zero
4181 csound(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
4183 csound(ix^d)=max(csound(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
4188 end subroutine mhd_get_csound_prim_split
4191 subroutine mhd_get_csound_semirelati(w,x,ixI^L,ixO^L,idim,csound,gamma2)
4194 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4196 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4197 double precision,
intent(out):: csound(ixo^s), gamma2(ixo^s)
4199 double precision :: avmincs2, inv_rho, alfven_speed2, idim_alfven_speed2
4200 double precision :: cs2(ixi^s)
4204 call eos%get_csound2(w, x, ixi^
l, ixo^
l, cs2)
4206 {
do ix^db=ixomin^db,ixomax^db\}
4207 inv_rho = 1.d0/w(ix^
d,
rho_)
4211 idim_alfven_speed2=(w(ix^
d,mag(idim))+
block%B0(ix^
d,idim,
b0i))**2*inv_rho
4213 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
4214 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
4216 gamma2(ix^
d) = 1.0d0/(1.d0+alfven_speed2*inv_squared_c)
4217 avmincs2=1.d0-gamma2(ix^
d)*w(ix^
d,
mom(idim))**2*inv_squared_c
4220 alfven_speed2=alfven_speed2*avmincs2+cs2(ix^
d)*(1.d0+idim_alfven_speed2*inv_squared_c)
4221 avmincs2=(gamma2(ix^
d)*alfven_speed2)**2-4.0d0*gamma2(ix^
d)*cs2(ix^
d)*idim_alfven_speed2*avmincs2
4222 if(avmincs2<zero) avmincs2=zero
4224 csound(ix^
d) = sqrt(half*(gamma2(ix^
d)*alfven_speed2+sqrt(avmincs2)))
4227 end subroutine mhd_get_csound_semirelati
4230 subroutine mhd_get_csound_semirelati_noe(w,x,ixI^L,ixO^L,idim,csound,gamma2)
4234 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4236 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
4237 double precision,
intent(out):: csound(ixo^s), gamma2(ixo^s)
4239 double precision :: adiabs(ixi^s), gammas(ixi^s)
4240 double precision :: avmincs2, inv_rho, alfven_speed2, idim_alfven_speed2
4253 {
do ix^db=ixomin^db,ixomax^db\}
4254 inv_rho = 1.d0/w(ix^
d,
rho_)
4256 csound(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
4257 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
4258 gamma2(ix^
d) = 1.0d0/(1.d0+alfven_speed2*inv_squared_c)
4259 avmincs2=1.d0-gamma2(ix^
d)*w(ix^
d,
mom(idim))**2*inv_squared_c
4260 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
4263 alfven_speed2=alfven_speed2*avmincs2+csound(ix^
d)*(1.d0+idim_alfven_speed2*inv_squared_c)
4264 avmincs2=(gamma2(ix^
d)*alfven_speed2)**2-4.0d0*gamma2(ix^
d)*csound(ix^
d)*idim_alfven_speed2*avmincs2
4265 if(avmincs2<zero) avmincs2=zero
4267 csound(ix^
d) = sqrt(half*(gamma2(ix^
d)*alfven_speed2+sqrt(avmincs2)))
4270 end subroutine mhd_get_csound_semirelati_noe
4283 integer,
intent(in) :: ixi^
l, ixo^
l
4284 double precision,
intent(in) :: w(ixi^s, 1:nw)
4285 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4286 double precision,
intent(out):: prad(ixi^s, 1:
ndim, 1:
ndim)
4295 integer,
intent(in) :: ixi^
l, ixo^
l
4296 double precision,
intent(in) :: w(ixi^s, 1:nw)
4297 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4298 double precision,
intent(out) :: pth_plus_prad(ixi^s)
4300 double precision :: wprim(ixi^s, 1:nw)
4301 double precision :: prad_tensor(ixi^s, 1:
ndim, 1:
ndim)
4302 double precision :: prad_max(ixi^s)
4305 wprim(ixi^s,1:nw)=w(ixi^s,1:nw)
4306 call eos%to_primitive(ixi^
l,ixo^
l,wprim,x)
4308 {
do ix^
d = ixomin^
d,ixomax^
d\}
4309 prad_max(ix^
d) = maxval(prad_tensor(ix^
d,:,:))
4311 pth_plus_prad(ixo^s) = wprim(ixo^s,
p_) + prad_max(ixo^s)
4319 integer,
intent(in) :: ixi^
l, ixo^
l
4320 double precision,
intent(in) :: w(ixi^s, 1:nw)
4321 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4322 double precision,
intent(out):: trad(ixi^s)
4329 subroutine mhd_get_flux(wC,w,x,ixI^L,ixO^L,idim,f)
4333 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4335 double precision,
intent(in) :: wc(ixi^s,nw)
4337 double precision,
intent(in) :: w(ixi^s,nw)
4338 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4339 double precision,
intent(out) :: f(ixi^s,nwflux)
4341 double precision :: vhall(ixi^s,1:
ndir)
4342 double precision :: ptotal
4343 double precision :: nperp(ixi^s,1:
ndir)
4344 double precision :: uawsom_zeta(ixi^s), uawsom_radius(ixi^s)
4345 double precision :: uawsom_lperp(ixi^s), uawsom_denom
4346 double precision :: uawsom_pwave, uawsom_bi
4347 double precision :: bunit_tc(
ndir)
4350 if(
mhd_uawsom)
call mhd_uawsom_get_coefficients(w,x,ixi^
l,ixo^
l,.true.,&
4351 uawsom_zeta,uawsom_radius,uawsom_lperp)
4354 {
do ix^db=ixomin^db,ixomax^db\}
4367 {
do ix^db=ixomin^db,ixomax^db\}
4371 ^
c&f(ix^d,
m^
c_)=wc(ix^d,
mom(idim))*w(ix^d,
m^
c_)-w(ix^d,mag(idim))*w(ix^d,
b^
c_)\
4372 ptotal=w(ix^d,
p_)+half*(^
c&w(ix^d,
b^
c_)**2+)
4375 ptotal=ptotal+uawsom_pwave
4378 f(ix^d,
mom(idim))=f(ix^d,
mom(idim))+ptotal
4381 f(ix^d,
e_)=w(ix^d,
mom(idim))*(wc(ix^d,
e_)+ptotal)&
4382 -w(ix^d,mag(idim))*(^
c&w(ix^d,
b^
c_)*w(ix^d,
m^
c_)+)
4384 uawsom_denom=dsqrt(w(ix^d,
rho_)*(uawsom_zeta(ix^d)+one)/&
4387 uawsom_bi=w(ix^d,mag(idim))
4388 f(ix^d,
e_)=f(ix^d,
e_)+uawsom_bi*(&
4393 ^
c&f(ix^d,
b^
c_)=w(ix^d,
mom(idim))*w(ix^d,
b^
c_)-w(ix^d,mag(idim))*w(ix^d,
m^
c_)\
4397 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4398 {
do ix^db=ixomin^db,ixomax^db\}
4399 if(total_energy)
then
4401 f(ix^d,
e_)=f(ix^d,
e_)+vhall(ix^d,idim)*(^
c&w(ix^d,
b^
c_)**2+)&
4402 -w(ix^d,mag(idim))*(^
c&vhall(ix^d,^
c)*w(ix^d,
b^
c_)+)
4405 ^
c&f(ix^d,
b^
c_)=f(ix^d,
b^
c_)+vhall(ix^d,idim)*w(ix^d,
b^
c_)-vhall(ix^d,^
c)*w(ix^d,mag(idim))\
4410 {
do ix^db=ixomin^db,ixomax^db\}
4411 f(ix^d,mag(idim))=w(ix^d,
psi_)
4413 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4418 {
do ix^db=ixomin^db,ixomax^db\}
4419 f(ix^d,
r_e)=w(ix^d,
mom(idim))*wc(ix^d,
r_e)
4424 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4427 {
do ix^db=ixomin^db,ixomax^db\}
4428 uawsom_denom=dsqrt(w(ix^d,
rho_)*(uawsom_zeta(ix^d)+one)/&
4431 uawsom_bi=w(ix^d,mag(idim))
4433 uawsom_bi/dsqrt(w(ix^d,
rho_)))
4435 uawsom_bi/dsqrt(w(ix^d,
rho_)))
4442 {
do ix^db=ixomin^db,ixomax^db\}
4448 {
do ix^db=ixomin^db,ixomax^db\}
4449 bunit_tc=b_unit_vector(w(ix^d,mag(1:ndir)))
4450 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qpar_)*bunit_tc(idim)
4454 call mhd_get_hyperbolic_tc_nperp(w,x,ixi^l,ixo^l,w(ixi^s,mag(1:ndir)),nperp)
4455 {
do ix^db=ixomin^db,ixomax^db\}
4456 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qperp_)*nperp(ix^d,idim)
4461 end subroutine mhd_get_flux
4465 subroutine mhd_get_flux_noe(wC,w,x,ixI^L,ixO^L,idim,f)
4470 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4472 double precision,
intent(in) :: wc(ixi^s,nw)
4474 double precision,
intent(in) :: w(ixi^s,nw)
4475 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4476 double precision,
intent(out) :: f(ixi^s,nwflux)
4478 double precision :: vhall(ixi^s,1:
ndir)
4479 double precision :: adiabs(ixi^s), gammas(ixi^s)
4492 {
do ix^db=ixomin^db,ixomax^db\}
4498 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+adiabs(ix^
d)*w(ix^
d,
rho_)**gammas(ix^
d)+half*(^
c&w(ix^
d,
b^
c_)**2+)
4503 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4504 {
do ix^db=ixomin^db,ixomax^db\}
4506 ^
c&f(ix^d,
b^
c_)=f(ix^d,
b^
c_)+vhall(ix^d,idim)*w(ix^d,
b^
c_)-vhall(ix^d,^
c)*w(ix^d,mag(idim))\
4510 {
do ix^db=ixomin^db,ixomax^db\}
4511 f(ix^d,mag(idim))=w(ix^d,
psi_)
4513 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4517 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4521 {
do ix^db=ixomin^db,ixomax^db\}
4525 end subroutine mhd_get_flux_noe
4528 subroutine mhd_get_flux_hde(wC,w,x,ixI^L,ixO^L,idim,f)
4532 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4534 double precision,
intent(in) :: wc(ixi^s,nw)
4536 double precision,
intent(in) :: w(ixi^s,nw)
4537 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4538 double precision,
intent(out) :: f(ixi^s,nwflux)
4540 double precision :: vhall(ixi^s,1:
ndir)
4541 double precision :: nperp(ixi^s,1:
ndir)
4542 double precision :: bunit_tc(
ndir)
4545 {
do ix^db=ixomin^db,ixomax^db\}
4558 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4559 {
do ix^db=ixomin^db,ixomax^db\}
4561 ^
c&f(ix^d,
b^
c_)=f(ix^d,
b^
c_)+vhall(ix^d,idim)*w(ix^d,
b^
c_)-vhall(ix^d,^
c)*w(ix^d,mag(idim))\
4565 {
do ix^db=ixomin^db,ixomax^db\}
4566 f(ix^d,mag(idim))=w(ix^d,
psi_)
4568 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4572 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4576 {
do ix^db=ixomin^db,ixomax^db\}
4582 {
do ix^db=ixomin^db,ixomax^db\}
4583 bunit_tc=b_unit_vector(w(ix^d,mag(1:ndir)))
4584 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qpar_)*bunit_tc(idim)
4588 call mhd_get_hyperbolic_tc_nperp(w,x,ixi^l,ixo^l,w(ixi^s,mag(1:ndir)),nperp)
4589 {
do ix^db=ixomin^db,ixomax^db\}
4590 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qperp_)*nperp(ix^d,idim)
4596 end subroutine mhd_get_flux_hde
4603 subroutine mhd_get_flux_split(wC,w,x,ixI^L,ixO^L,idim,f)
4607 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4609 double precision,
intent(in) :: wc(ixi^s,nw)
4611 double precision,
intent(in) :: w(ixi^s,nw)
4612 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4613 double precision,
intent(out) :: f(ixi^s,nwflux)
4615 double precision :: vhall(ixi^s,1:
ndir)
4616 double precision :: ptotal, btotal(ixo^s,1:
ndir)
4617 double precision :: nperp(ixi^s,1:
ndir)
4618 double precision :: uawsom_zeta(ixi^s), uawsom_radius(ixi^s)
4619 double precision :: uawsom_lperp(ixi^s), uawsom_denom
4620 double precision :: uawsom_pwave, uawsom_bi
4621 double precision :: bunit_tc(
ndir)
4622 logical :: use_perp_flux
4625 if(
mhd_uawsom)
call mhd_uawsom_get_coefficients(w,x,ixi^
l,ixo^
l,.true.,&
4626 uawsom_zeta,uawsom_radius,uawsom_lperp)
4628 {
do ix^db=ixomin^db,ixomax^db\}
4636 ptotal=w(ix^
d,
p_)+half*(^
c&w(ix^
d,
b^
c_)**2+)
4640 ptotal=ptotal+(^
c&w(ix^
d,
b^
c_)*
block%B0(ix^
d,^
c,idim)+)
4644 btotal(ix^
d,idim)*w(ix^
d,
b^
c_)-w(ix^
d,mag(idim))*
block%B0(ix^
d,^
c,idim)\
4645 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+ptotal
4647 ^
c&btotal(ix^
d,^
c)=w(ix^
d,
b^
c_)\
4651 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+ptotal
4655 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+uawsom_pwave
4658 ^
c&f(ix^
d,
b^
c_)=w(ix^
d,
mom(idim))*btotal(ix^
d,^
c)-btotal(ix^
d,idim)*w(ix^
d,
m^
c_)\
4665 f(ix^
d,
e_)=w(ix^
d,
mom(idim))*(wc(ix^
d,
e_)+ptotal)&
4666 -btotal(ix^
d,idim)*(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)
4668 uawsom_denom=dsqrt(w(ix^
d,
rho_)*(uawsom_zeta(ix^
d)+one)/&
4671 uawsom_bi=btotal(ix^
d,idim)
4672 f(ix^
d,
e_)=f(ix^
d,
e_)+w(ix^
d,
mom(idim))*uawsom_pwave+uawsom_bi*(&
4680 {
do ix^db=ixomin^db,ixomax^db\}
4681 f(ix^d,mag(idim))=w(ix^d,
psi_)
4683 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4688 {
do ix^db=ixomin^db,ixomax^db\}
4689 f(ix^d,
r_e)=w(ix^d,
mom(idim))*wc(ix^d,
r_e)
4694 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4695 {
do ix^db=ixomin^db,ixomax^db\}
4697 ^
c&f(ix^d,
b^
c_)=f(ix^d,
b^
c_)+vhall(ix^d,idim)*btotal(ix^d,^
c)-btotal(ix^d,idim)*vhall(ix^d,^
c)\
4698 if(total_energy)
then
4700 f(ix^d,
e_)=f(ix^d,
e_)+vhall(ix^d,idim)*(^
c&w(ix^d,
b^
c_)*btotal(ix^d,^
c)+)&
4701 -btotal(ix^d,idim)*(^
c&vhall(ix^d,^
c)*w(ix^d,
b^
c_)+)
4706 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4709 {
do ix^db=ixomin^db,ixomax^db\}
4710 uawsom_denom=dsqrt(w(ix^d,
rho_)*(uawsom_zeta(ix^d)+one)/&
4713 uawsom_bi=btotal(ix^d,idim)
4715 uawsom_bi/dsqrt(w(ix^d,
rho_)))
4717 uawsom_bi/dsqrt(w(ix^d,
rho_)))
4724 {
do ix^db=ixomin^db,ixomax^db\}
4730 {
do ix^db=ixomin^db,ixomax^db\}
4731 bunit_tc=b_unit_vector(btotal(ix^d,1:ndir))
4732 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qpar_)*bunit_tc(idim)
4736 call mhd_get_hyperbolic_tc_nperp(w,x,ixi^l,ixo^l,btotal,nperp)
4737 {
do ix^db=ixomin^db,ixomax^db\}
4738 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qperp_)*nperp(ix^d,idim)
4744 end subroutine mhd_get_flux_split
4747 subroutine mhd_get_flux_semirelati(wC,w,x,ixI^L,ixO^L,idim,f)
4751 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4753 double precision,
intent(in) :: wc(ixi^s,nw)
4755 double precision,
intent(in) :: w(ixi^s,nw)
4756 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4757 double precision,
intent(out) :: f(ixi^s,nwflux)
4758 double precision :: sa(ixo^s,1:
ndir),e(ixo^s,1:
ndir),e2
4759 double precision :: btf(ixi^s,1:
ndir),b0sq,btsq
4760 double precision :: nperp(ixi^s,1:
ndir)
4761 double precision :: bunit_tc(
ndir)
4764 {
do ix^db=ixomin^db,ixomax^db\}
4775 e(ix^
d,1)=btf(ix^
d,2)*w(ix^
d,m3_)-btf(ix^
d,3)*w(ix^
d,m2_)
4776 e(ix^
d,2)=btf(ix^
d,3)*w(ix^
d,m1_)-btf(ix^
d,1)*w(ix^
d,m3_)
4777 e(ix^
d,3)=btf(ix^
d,1)*w(ix^
d,m2_)-btf(ix^
d,2)*w(ix^
d,m1_)
4782 e(ix^
d,2)=btf(ix^
d,1)*w(ix^
d,m2_)-btf(ix^
d,2)*w(ix^
d,m1_)
4787 e2=(^
c&e(ix^
d,^
c)**2+)
4794 sa(ix^
d,1)=e(ix^
d,2)*w(ix^
d,b3_)-e(ix^
d,3)*w(ix^
d,b2_)
4795 sa(ix^
d,2)=e(ix^
d,3)*w(ix^
d,b1_)-e(ix^
d,1)*w(ix^
d,b3_)
4796 sa(ix^
d,3)=e(ix^
d,1)*w(ix^
d,b2_)-e(ix^
d,2)*w(ix^
d,b1_)
4799 sa(ix^
d,1)=-e(ix^
d,2)*w(ix^
d,b2_)
4800 sa(ix^
d,2)=e(ix^
d,2)*w(ix^
d,b1_)
4810 -half*((^
c&w(ix^
d,
b^
c_)**2+)+e2*inv_squared_c)&
4811 +w(ix^
d,
p_))+sa(ix^
d,idim)
4817 -btf(ix^
d,idim)*btf(ix^
d,^
c)+
block%B0(ix^
d,idim,idim)*
block%B0(ix^
d,^
c,idim)&
4818 -e(ix^
d,idim)*e(ix^
d,^
c)*inv_squared_c\
4819 b0sq=(^
c&
block%B0(ix^
d,^
c,idim)**2+)
4820 btsq=(^
c&btf(ix^
d,^
c)**2+)
4821 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+w(ix^
d,
p_)+half*(btsq-b0sq+e2*inv_squared_c)
4824 -w(ix^
d,mag(idim))*w(ix^
d,
b^
c_)-e(ix^
d,idim)*e(ix^
d,^
c)*inv_squared_c\
4826 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+w(ix^
d,
p_)+half*((^
c&w(ix^
d,
b^
c_)**2+)+e2*inv_squared_c)
4830 ^
c&f(ix^
d,
b^
c_)=w(ix^
d,
mom(idim))*btf(ix^
d,^
c)-btf(ix^
d,idim)*w(ix^
d,
m^
c_)\
4834 {
do ix^db=ixomin^db,ixomax^db\}
4835 f(ix^d,mag(idim))=w(ix^d,
psi_)
4837 f(ix^d,
psi_)=cmax_global**2*w(ix^d,mag(idim))
4841 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4845 {
do ix^db=ixomin^db,ixomax^db\}
4851 {
do ix^db=ixomin^db,ixomax^db\}
4852 bunit_tc=b_unit_vector(btf(ix^d,1:ndir))
4853 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qpar_)*bunit_tc(idim)
4857 call mhd_get_hyperbolic_tc_nperp(w,x,ixi^l,ixo^l,btf,nperp)
4858 {
do ix^db=ixomin^db,ixomax^db\}
4859 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
qperp_)*nperp(ix^d,idim)
4864 end subroutine mhd_get_flux_semirelati
4866 subroutine mhd_get_flux_semirelati_noe(wC,w,x,ixI^L,ixO^L,idim,f)
4871 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4873 double precision,
intent(in) :: wc(ixi^s,nw)
4875 double precision,
intent(in) :: w(ixi^s,nw)
4876 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4877 double precision,
intent(out) :: f(ixi^s,nwflux)
4879 double precision :: adiabs(ixi^s), gammas(ixi^s)
4880 double precision :: e(ixo^s,1:
ndir),e2
4893 {
do ix^db=ixomin^db,ixomax^db\}
4898 e(ix^
d,1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
4899 e(ix^
d,2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
4900 e(ix^
d,3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4901 e2=(^
c&e(ix^
d,^
c)**2+)
4906 e(ix^
d,2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4916 -w(ix^
d,mag(idim))*w(ix^
d,
b^
c_)-e(ix^
d,idim)*e(ix^
d,^
c)*inv_squared_c\
4918 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+adiabs(ix^
d)*w(ix^
d,
rho_)**gammas(ix^
d)+half*((^
c&w(ix^
d,
b^
c_)**2+)+e2*inv_squared_c)
4925 {
do ix^db=ixomin^db,ixomax^db\}
4926 f(ix^d,mag(idim))=w(ix^d,
psi_)
4928 f(ix^d,
psi_)=cmax_global**2*w(ix^d,mag(idim))
4932 f(ixo^s,
fip_) = w(ixo^s,
mom(idim)) * wc(ixo^s,
fip_)
4936 {
do ix^db=ixomin^db,ixomax^db\}
4940 end subroutine mhd_get_flux_semirelati_noe
4948 subroutine add_source_ambipolar_internal_energy(qdt,ixI^L,ixO^L,wCT,w,x)
4950 integer,
intent(in) :: ixi^
l, ixo^
l
4951 double precision,
intent(in) :: qdt
4952 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
4953 double precision,
intent(inout) :: w(ixi^s,1:nw)
4955 double precision :: tmp(ixi^s),btot2(ixi^s)
4956 double precision :: jxbxb(ixi^s,1:3)
4958 call mhd_get_jxbxb(wct,x,ixi^
l,ixo^
l,jxbxb)
4961 where (btot2(ixo^s)>smalldouble )
4962 tmp(ixo^s) = sum(jxbxb(ixo^s,1:3)**2,dim=
ndim+1) / btot2(ixo^s)
4969 w(ixo^s,
e_)=w(ixo^s,
e_)- qdt*tmp(ixo^s)
4971 end subroutine add_source_ambipolar_internal_energy
4974 subroutine mhd_get_jxbxb(w,x,ixI^L,ixO^L,res)
4977 integer,
intent(in) :: ixi^
l, ixo^
l
4978 double precision,
intent(in) :: w(ixi^s,nw)
4979 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4980 double precision,
intent(out) :: res(ixi^s,1:3)
4982 double precision :: btot(ixi^s,1:3)
4983 double precision :: current(ixi^s,7-2*
ndir:3)
4984 double precision :: tmp(ixi^s),b2(ixi^s)
4985 integer :: idir, idirmin
4995 btot(ixo^s, idir) = w(ixo^s,mag(idir)) +
block%B0(ixo^s,idir,
b0i)
4999 btot(ixo^s, idir) = w(ixo^s,mag(idir))
5003 tmp(ixo^s)= sum(current(ixo^s,idirmin:3)*btot(ixo^s,idirmin:3),dim=
ndim+1)
5004 b2(ixo^s) = sum(btot(ixo^s,1:3)**2,dim=
ndim+1)
5006 res(ixo^s,idir) = btot(ixo^s,idir) * tmp(ixo^s)
5009 res(ixo^s,idir) = btot(ixo^s,idir) * tmp(ixo^s) - current(ixo^s,idir) * b2(ixo^s)
5014 where (b2(ixo^s)<smalldouble )
5015 res(ixo^s,idir) = zero
5018 end subroutine mhd_get_jxbxb
5024 subroutine sts_set_source_ambipolar(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
5028 integer,
intent(in) :: ixi^
l,ixo^
l,igrid,nflux
5029 double precision,
intent(in) :: x(ixi^s,1:
ndim)
5030 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
5031 double precision,
intent(in) :: my_dt
5032 logical,
intent(in) :: fix_conserve_at_step
5034 double precision,
dimension(ixI^S,1:3) :: tmp,ff
5035 double precision :: fluxall(ixi^s,1:nflux,1:
ndim)
5036 double precision :: fe(ixi^s,
sdim:3)
5037 double precision :: btot(ixi^s,1:3),tmp2(ixi^s)
5038 integer :: i, ixa^
l, ie_
5045 call mhd_get_jxbxb(w,x,ixi^
l,ixa^
l,tmp)
5062 btot(ixa^s,1:3) = 0.d0
5064 btot(ixa^s,1:
ndir) = w(ixa^s,mag(1:
ndir))
5068 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5069 if(fix_conserve_at_step) fluxall(ixi^s,1,1:
ndim)=ff(ixi^s,1:
ndim)
5071 wres(ixo^s,
e_)=-tmp2(ixo^s)
5078 ff(ixa^s,1) = tmp(ixa^s,2)
5079 ff(ixa^s,2) = -tmp(ixa^s,1)
5081 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5082 if(fix_conserve_at_step) fluxall(ixi^s,1+
ndir,1:
ndim)=ff(ixi^s,1:
ndim)
5083 wres(ixo^s,mag(
ndir))=-tmp2(ixo^s)
5086 call update_faces_ambipolar(ixi^
l,ixo^
l,w,x,tmp,fe,btot)
5088 ixamin^
d=ixomin^
d-1;
5089 wres(ixa^s,mag(1:
ndim))=-btot(ixa^s,1:
ndim)
5099 ff(ixa^s,2) = tmp(ixa^s,3)
5100 ff(ixa^s,3) = -tmp(ixa^s,2)
5101 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5102 if(fix_conserve_at_step) fluxall(ixi^s,2,1:
ndim)=ff(ixi^s,1:
ndim)
5104 wres(ixo^s,mag(1))=-tmp2(ixo^s)
5107 ff(ixa^s,1) = -tmp(ixa^s,3)
5109 ff(ixa^s,3) = tmp(ixa^s,1)
5110 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5111 if(fix_conserve_at_step) fluxall(ixi^s,3,1:
ndim)=ff(ixi^s,1:
ndim)
5112 wres(ixo^s,mag(2))=-tmp2(ixo^s)
5118 ff(ixa^s,2) = tmp(ixa^s,3)
5119 ff(ixa^s,3) = -tmp(ixa^s,2)
5120 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5121 if(fix_conserve_at_step) fluxall(ixi^s,2,1:
ndim)=ff(ixi^s,1:
ndim)
5123 wres(ixo^s,mag(1))=-tmp2(ixo^s)
5125 ff(ixa^s,1) = -tmp(ixa^s,3)
5127 ff(ixa^s,3) = tmp(ixa^s,1)
5128 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5129 if(fix_conserve_at_step) fluxall(ixi^s,3,1:
ndim)=ff(ixi^s,1:
ndim)
5130 wres(ixo^s,mag(2))=-tmp2(ixo^s)
5135 ff(ixa^s,1) = tmp(ixa^s,2)
5136 ff(ixa^s,2) = -tmp(ixa^s,1)
5138 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
5139 if(fix_conserve_at_step) fluxall(ixi^s,1+
ndir,1:
ndim)=ff(ixi^s,1:
ndim)
5140 wres(ixo^s,mag(
ndir))=-tmp2(ixo^s)
5145 if(fix_conserve_at_step)
then
5146 fluxall=my_dt*fluxall
5153 end subroutine sts_set_source_ambipolar
5156 subroutine update_faces_ambipolar(ixI^L,ixO^L,w,x,ECC,fE,circ)
5159 integer,
intent(in) :: ixi^
l, ixo^
l
5160 double precision,
intent(in) :: w(ixi^s,1:nw)
5161 double precision,
intent(in) :: x(ixi^s,1:
ndim)
5163 double precision,
intent(in) :: ecc(ixi^s,1:3)
5164 double precision,
intent(out) :: fe(ixi^s,
sdim:3)
5165 double precision,
intent(out) :: circ(ixi^s,1:
ndim)
5167 integer :: hxc^
l,ixc^
l,ixa^
l
5168 integer :: idim1,idim2,idir,ix^
d
5174 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
5176 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
5177 ixamin^
d=ixcmin^
d+ix^
d;
5178 ixamax^
d=ixcmax^
d+ix^
d;
5179 fe(ixc^s,idir)=fe(ixc^s,idir)+ecc(ixa^s,idir)
5181 fe(ixc^s,idir)=fe(ixc^s,idir)*0.25d0*block%dsC(ixc^s,idir)
5187 ixcmin^d=ixomin^d-1;
5194 hxc^l=ixc^l-kr(idim2,^d);
5196 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
5197 +lvc(idim1,idim2,idir)&
5202 circ(ixc^s,idim1)=circ(ixc^s,idim1)/block%surfaceC(ixc^s,idim1)
5205 end subroutine update_faces_ambipolar
5211 subroutine get_flux_on_cell_face(ixI^L,ixO^L,ff,src)
5214 integer,
intent(in) :: ixi^
l, ixo^
l
5215 double precision,
dimension(ixI^S,1:3),
intent(inout) :: ff
5216 double precision,
intent(out) :: src(ixi^s)
5218 double precision :: ffc(ixi^s,1:
ndim)
5219 double precision :: dxinv(
ndim)
5220 integer :: idims, ix^
d, ixa^
l, ixb^
l, ixc^
l
5228 ixcmax^
d=ixomax^
d; ixcmin^
d=ixomin^
d-1;
5230 ixbmin^
d=ixcmin^
d+ix^
d;
5231 ixbmax^
d=ixcmax^
d+ix^
d;
5234 ffc(ixc^s,1:ndim)=0.5d0**ndim*ffc(ixc^s,1:ndim)
5236 call mpistop(
"to generalize using volume averaging")
5239 ff(ixi^s,1:ndim)=0.d0
5241 ixb^l=ixo^l-kr(idims,^d);
5242 ixcmax^d=ixomax^d; ixcmin^d=ixbmin^d;
5244 if({ ix^d==0 .and. ^d==idims | .or.})
then
5245 ixbmin^d=ixcmin^d-ix^d;
5246 ixbmax^d=ixcmax^d-ix^d;
5247 ff(ixc^s,idims)=ff(ixc^s,idims)+ffc(ixb^s,idims)
5250 ff(ixc^s,idims)=ff(ixc^s,idims)*0.5d0**(ndim-1)
5253 if(slab_uniform)
then
5255 ff(ixa^s,idims)=dxinv(idims)*ff(ixa^s,idims)
5256 ixb^l=ixo^l-kr(idims,^d);
5257 src(ixo^s)=src(ixo^s)+ff(ixo^s,idims)-ff(ixb^s,idims)
5261 ff(ixa^s,idims)=ff(ixa^s,idims)*block%surfaceC(ixa^s,idims)
5262 ixb^l=ixo^l-kr(idims,^d);
5263 src(ixo^s)=src(ixo^s)+ff(ixo^s,idims)-ff(ixb^s,idims)
5265 src(ixo^s)=src(ixo^s)/block%dvolume(ixo^s)
5267 end subroutine get_flux_on_cell_face
5271 function get_ambipolar_dt(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
5274 integer,
intent(in) :: ixi^
l, ixo^
l
5275 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
5276 double precision,
intent(in) :: w(ixi^s,1:nw)
5277 double precision :: dtnew
5279 double precision :: coef
5280 double precision :: dxarr(
ndim)
5281 double precision :: tmp(ixi^s)
5287 coef = maxval(dabs(tmp(ixo^s)))
5294 dtnew=minval(dxarr(1:
ndim))**2.0d0*coef
5296 dtnew=minval(
block%ds(ixo^s,1:
ndim))**2.0d0*coef
5299 end function get_ambipolar_dt
5307 integer,
intent(in) :: ixi^
l, ixo^
l
5308 double precision,
intent(in) :: w(ixi^s,1:nw), x(ixi^s,1:
ndim)
5309 double precision,
intent(inout) :: res(ixi^s)
5310 double precision :: tmp(ixi^s)
5311 double precision :: rho(ixi^s)
5318 res(ixo^s) = tmp(ixo^s) * res(ixo^s)
5323 subroutine mhd_add_source(qdt,dtfactor,ixI^L,ixO^L,wCT,wCTprim,w,x,qsourcesplit,active)
5330 integer,
intent(in) :: ixi^
l, ixo^
l
5331 double precision,
intent(in) :: qdt,dtfactor
5332 double precision,
intent(in) :: wct(ixi^s,1:nw),wctprim(ixi^s,1:nw), x(ixi^s,1:
ndim)
5333 double precision,
intent(inout) :: w(ixi^s,1:nw)
5334 logical,
intent(in) :: qsourcesplit
5335 logical,
intent(inout) :: active
5342 if (.not. qsourcesplit)
then
5345 call mhd_add_source_uawsom(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5350 call add_source_internal_e(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5354 call add_equi_terms(qdt,dtfactor,ixi^
l,ixo^
l,wct,wctprim,w,x)
5360 call add_source_hyperbolic_tc(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5369 call add_source_b0split(qdt,dtfactor,ixi^
l,ixo^
l,wct,wctprim,w,x)
5373 if (abs(
mhd_eta)>smalldouble)
then
5375 call add_source_res_exp(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5380 call add_source_ambi_exp(qdt,ixi^
l,ixo^
l,wct,w,x)
5385 call add_source_hyperres(qdt,ixi^
l,ixo^
l,wct,w,x)
5391 call add_source_hydrodynamic_e(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5395 call add_source_semirelativistic(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x)
5402 select case (type_divb)
5407 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5410 call add_source_glm(qdt,ixi^
l,ixo^
l,wct,w,x)
5413 call add_source_powel(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5414 case (divb_janhunen)
5416 call add_source_janhunen(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5417 case (divb_lindejanhunen)
5419 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5420 call add_source_janhunen(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5421 case (divb_lindepowel)
5423 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5424 call add_source_powel(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5425 case (divb_lindeglm)
5427 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5428 call add_source_glm(qdt,ixi^
l,ixo^
l,wct,w,x)
5429 case (divb_multigrid)
5434 call mpistop(
'Unknown divB fix')
5441 w,x,qsourcesplit,active,
rc_fl)
5457 w,x,gravity_energy,qsourcesplit,active)
5466 call mhd_add_radiation_source(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x,qsourcesplit,active)
5469 end subroutine mhd_add_source
5471 subroutine mhd_add_radiation_source(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x,qsourcesplit,active)
5477 integer,
intent(in) :: ixi^
l, ixo^
l
5478 double precision,
intent(in) :: qdt, x(ixi^s,1:
ndim)
5479 double precision,
intent(in) :: wct(ixi^s,1:nw),wctprim(ixi^s,1:nw)
5480 double precision,
intent(inout) :: w(ixi^s,1:nw)
5481 logical,
intent(in) :: qsourcesplit
5482 logical,
intent(inout) :: active
5488 end subroutine mhd_add_radiation_source
5491 subroutine add_equi_terms(qdt,dtfactor,ixI^L,ixO^L,wCT,wCTprim,w,x)
5496 integer,
intent(in) :: ixi^
l, ixo^
l
5497 double precision,
intent(in) :: qdt,dtfactor
5498 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5499 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
5500 double precision,
intent(inout) :: w(ixi^s,1:nw)
5502 double precision :: divv(ixi^s)
5503 double precision :: a(ixi^s,3),
b(ixi^s,3), axb(ixi^s,3)
5504 double precision :: gravity_field(ixi^s,1:
ndim)
5516 divv(ixo^s)=divv(ixo^s)*eos%gamma*eos%inv_gamma_minus_1
5527 w(ixo^s,
e_)=w(ixo^s,
e_)-qdt*wctprim(ixo^s,
mom(idir))*
block%equi_vars(ixo^s,
equi_rho0_,0)*gravity_field(ixo^s,idir)*eos%inv_gamma_minus_1
5536 a(ixo^s,idir)=
block%J0(ixo^s,idir)
5541 w(ixo^s,
e_)=w(ixo^s,
e_)-qdt*wctprim(ixo^s,
mom(idir))*axb(ixo^s,idir)*eos%inv_gamma_minus_1
5547 w(ixo^s,
e_)=w(ixo^s,
e_)-qdt*wctprim(ixo^s,
mom(idir))*
block%equi_vars(ixo^s,
equi_rho0_,0)*gravity_field(ixo^s,idir)*eos%inv_gamma_minus_1
5556 w(ixo^s,
e_)=w(ixo^s,
e_)-qdt*wctprim(ixo^s,
mom(idir))*
block%equi_vars(ixo^s,
equi_rho0_,0)*gravity_field(ixo^s,idir)*eos%inv_gamma_minus_1
5560 end subroutine add_equi_terms
5566 pure function b_unit_vector(B)
result(bunit)
5569 double precision,
intent(in) ::
b(:)
5570 double precision :: bunit(^nc), maxm, scaled_norm
5576 ^
c&bunit(^
c)=
b(^
c)/maxm\
5577 scaled_norm=dsqrt(^
c&bunit(^
c)**2+)
5579 ^
c&bunit(^
c)=bunit(^
c)/scaled_norm\
5581 end function b_unit_vector
5583 subroutine mhd_get_hyperbolic_tc_nperp(w,x,ixI^L,ixO^L,Bvec,nperp)
5586 integer,
intent(in) :: ixi^
l,ixo^
l
5587 double precision,
intent(in) :: w(ixi^s,nw)
5588 double precision,
intent(in) :: x(ixi^s,1:
ndim)
5589 double precision,
intent(in) :: bvec(ixi^s,1:
ndir)
5590 double precision,
intent(out) :: nperp(ixi^s,1:
ndir)
5592 double precision :: r(ixi^s), te(ixi^s), bgradt
5593 double precision :: bunitvec(
ndir), gradt(ixi^s,
ndir), gradt_perp(
ndir)
5594 integer :: ix^
d, idir
5597 call eos%get_Rfactor(w,x,ixi^
l,ixi^
l,r)
5598 te(ixi^s)=w(ixi^s,
p_)/(te(ixi^s)*r(ixi^s))
5601 call gradient(te,ixi^
l,ixo^
l,idir,gradt(ixi^s,idir))
5607 do ix2=ixomin2,ixomax2
5608 do ix1=ixomin1,ixomax1
5609 bunitvec=b_unit_vector(bvec(ix^
d,1:
ndir))
5611 gradt(ix^
d,1)=((8.d0*(te(ix1+1,ix2)-te(ix1-1,ix2))-te(ix1+2,ix2)+te(ix1-2,ix2))/12.d0)/
block%ds(ix^
d,1)
5612 gradt(ix^
d,2)=((8.d0*(te(ix1,ix2+1)-te(ix1,ix2-1))-te(ix1,ix2+2)+te(ix1,ix2-2))/12.d0)/
block%ds(ix^
d,2)
5616 bgradt=(^
c&bunitvec(^
c)*gradt(ix^
d,^
c)+)
5617 {^
c& gradt_perp(^
c)=gradt(ix^
d,^
c)-bgradt*bunitvec(^
c)\}
5618 nperp(ix^
d,1:
ndir)=b_unit_vector(gradt_perp(1:
ndir))
5623 do ix3=ixomin3,ixomax3
5624 do ix2=ixomin2,ixomax2
5625 do ix1=ixomin1,ixomax1
5626 bunitvec=b_unit_vector(bvec(ix^
d,1:
ndir))
5629 gradt(ix^
d,1)=((8.d0*(te(ix1+1,ix2,ix3)-te(ix1-1,ix2,ix3))-te(ix1+2,ix2,ix3)+te(ix1-2,ix2,ix3))/12.d0)/
block%ds(ix^
d,1)
5630 gradt(ix^
d,2)=((8.d0*(te(ix1,ix2+1,ix3)-te(ix1,ix2-1,ix3))-te(ix1,ix2+2,ix3)+te(ix1,ix2-2,ix3))/12.d0)/
block%ds(ix^
d,2)
5631 gradt(ix^
d,3)=((8.d0*(te(ix1,ix2,ix3+1)-te(ix1,ix2,ix3-1))-te(ix1,ix2,ix3+2)+te(ix1,ix2,ix3-2))/12.d0)/
block%ds(ix^
d,3)
5634 bgradt=(^
c&bunitvec(^
c)*gradt(ix^
d,^
c)+)
5635 {^
c& gradt_perp(^
c)=gradt(ix^
d,^
c)-bgradt*bunitvec(^
c)\}
5636 nperp(ix^
d,1:
ndir)=b_unit_vector(gradt_perp(1:
ndir))
5641 end subroutine mhd_get_hyperbolic_tc_nperp
5643 subroutine mhd_get_hyperbolic_tc_geometry(ixI^L,ixO^L,Te,Bvec,bgradT,gradTperp_mag,nperp)
5646 integer,
intent(in) :: ixi^
l,ixo^
l
5647 double precision,
intent(in) :: te(ixi^s)
5648 double precision,
intent(in) :: bvec(ixi^s,1:
ndir)
5649 double precision,
intent(out) :: bgradt(ixi^s), gradtperp_mag(ixi^s)
5650 double precision,
intent(out) :: nperp(ixi^s,1:
ndir)
5652 double precision :: bunitvec(
ndir), gradt(ixi^s,
ndir), gradt_perp(
ndir)
5653 double precision :: maxm
5654 integer :: ix^
d, idir
5658 call gradient(te,ixi^
l,ixo^
l,idir,gradt(ixi^s,idir))
5664 do ix2=ixomin2,ixomax2
5665 do ix1=ixomin1,ixomax1
5666 bunitvec=b_unit_vector(bvec(ix^
d,1:
ndir))
5668 gradt(ix^
d,1)=((8.d0*(te(ix1+1,ix2)-te(ix1-1,ix2))-te(ix1+2,ix2)+te(ix1-2,ix2))/12.d0)/
block%ds(ix^
d,1)
5669 gradt(ix^
d,2)=((8.d0*(te(ix1,ix2+1)-te(ix1,ix2-1))-te(ix1,ix2+2)+te(ix1,ix2-2))/12.d0)/
block%ds(ix^
d,2)
5670 if(
ndir>2) gradt(ix^
d,3)=zero
5673 bgradt(ix^
d)=(^
c&bunitvec(^
c)*gradt(ix^
d,^
c)+)
5674 {^
c& gradt_perp(^
c)=gradt(ix^
d,^
c)-bgradt(ix^
d)*bunitvec(^
c)\}
5675 maxm=maxval(abs(gradt_perp))
5677 gradtperp_mag(ix^
d)=zero
5678 {^
c& nperp(ix^
d,^
c)=zero\}
5680 ^
c&nperp(ix^
d,^
c)=gradt_perp(^
c)/maxm\
5681 gradtperp_mag(ix^
d)=dsqrt(^
c&nperp(ix^
d,^
c)**2+)
5682 ^
c&nperp(ix^
d,^
c)=nperp(ix^
d,^
c)/gradtperp_mag(ix^
d)\
5683 gradtperp_mag(ix^
d)=gradtperp_mag(ix^
d)*maxm
5689 do ix3=ixomin3,ixomax3
5690 do ix2=ixomin2,ixomax2
5691 do ix1=ixomin1,ixomax1
5692 bunitvec=b_unit_vector(bvec(ix^
d,1:
ndir))
5695 gradt(ix^
d,1)=((8.d0*(te(ix1+1,ix2,ix3)-te(ix1-1,ix2,ix3))-te(ix1+2,ix2,ix3)+te(ix1-2,ix2,ix3))/12.d0)/
block%ds(ix^
d,1)
5696 gradt(ix^
d,2)=((8.d0*(te(ix1,ix2+1,ix3)-te(ix1,ix2-1,ix3))-te(ix1,ix2+2,ix3)+te(ix1,ix2-2,ix3))/12.d0)/
block%ds(ix^
d,2)
5697 gradt(ix^
d,3)=((8.d0*(te(ix1,ix2,ix3+1)-te(ix1,ix2,ix3-1))-te(ix1,ix2,ix3+2)+te(ix1,ix2,ix3-2))/12.d0)/
block%ds(ix^
d,3)
5700 bgradt(ix^
d)=(^
c&bunitvec(^
c)*gradt(ix^
d,^
c)+)
5701 {^
c& gradt_perp(^
c)=gradt(ix^
d,^
c)-bgradt(ix^
d)*bunitvec(^
c)\}
5702 maxm=maxval(abs(gradt_perp))
5704 gradtperp_mag(ix^
d)=zero
5705 {^
c& nperp(ix^
d,^
c)=zero\}
5707 ^
c&nperp(ix^
d,^
c)=gradt_perp(^
c)/maxm\
5708 gradtperp_mag(ix^
d)=dsqrt(^
c&nperp(ix^
d,^
c)**2+)
5709 ^
c&nperp(ix^
d,^
c)=nperp(ix^
d,^
c)/gradtperp_mag(ix^
d)\
5710 gradtperp_mag(ix^
d)=gradtperp_mag(ix^
d)*maxm
5716 end subroutine mhd_get_hyperbolic_tc_geometry
5718 subroutine add_source_hyperbolic_tc(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
5721 integer,
intent(in) :: ixi^
l,ixo^
l
5722 double precision,
intent(in) :: qdt
5723 double precision,
dimension(ixI^S,1:ndim),
intent(in) :: x
5724 double precision,
dimension(ixI^S,1:nw),
intent(in) :: wct,wctprim
5725 double precision,
dimension(ixI^S,1:nw),
intent(inout) :: w
5727 double precision,
dimension(ixI^S) :: r,te,rho_loc,pth_loc,cs2_loc
5728 double precision,
dimension(ixI^S) :: ne_loc,nh_dummy
5729 double precision,
dimension(ixI^S,1:ndir) :: bvec
5730 double precision,
dimension(ixI^S) :: bgradt, gradtperp_mag
5731 double precision,
dimension(ixI^S,1:ndir) :: nperp
5732 double precision,
dimension(ixI^S) :: gradt_geom
5733 double precision,
parameter :: xe_prefac_cgs = 4.753567596681522d6
5734 double precision :: kappa_t5,kappa_t5_perp,kappa_t5_perp_eff
5735 double precision :: kappa_t7,f_sat,kappat5_bgradt,kappat5_gradtperp,tau,b2,fb,gradt1
5736 double precision :: bunit_tc(
ndir)
5737 double precision :: qclass_diss
5738 double precision :: bmag_loc,tloc,tcond,nloc_code,cchi,chi
5739 double precision :: cmax(
ndim),c2,cfast2,avmincs2(
ndim),inv_rho
5740 integer :: ix^
d,idir
5741 logical :: use_perp_source
5747 if(htc_perp_mode_id==htc_perp_electron)
then
5757 if (eos%eos_type ==
'LTE' .or. eos%eos_type ==
'PI')
then
5758 te(ixi^s) = wct(ixi^s,
te_)
5760 call eos%get_Rfactor(wct,x,ixi^
l,ixi^
l,r)
5761 {
do ix^db=iximin^db,iximax^db\}
5766 rho_loc(ix^
d)=wctprim(ix^
d,
rho_)
5767 pth_loc(ix^
d)=wctprim(ix^
d,
p_)
5769 te(ix^
d)=pth_loc(ix^
d)/(r(ix^
d)*rho_loc(ix^
d))
5774 cs2_loc(ixi^s)=eos%gamma*pth_loc(ixi^s)/rho_loc(ixi^s)
5776 call eos%get_csound2(wctprim,x,ixi^l,ixi^l,cs2_loc)
5782 if(htc_perp_mode_id==htc_perp_electron)
then
5783 if(eos%eos_type==
'LTE')
then
5784 call eos%get_ne_nH(ixi^l,ixi^l,wct, x,ne_loc,nh_dummy)
5785 else if(eos%eos_type==
'PI')
then
5786 ne_loc(ixi^s)=rho_loc(ixi^s)*max(r(ixi^s)*(2.d0+3.d0*eos%He_abundance) &
5787 -(1.d0+eos%He_abundance),smalldouble)
5789 ne_loc(ixi^s)=rho_loc(ixi^s)*(1.d0+2.d0*eos%He_abundance)
5794 {
do ix^db=ixomin^db,ixomax^db\}
5795 {^
c& bvec(ix^d,^
c)=wct(ix^d,mag(^
c))+block%B0(ix^d,^
c,0)\}
5798 {
do ix^db=ixomin^db,ixomax^db\}
5799 {^
c& bvec(ix^d,^
c)=wct(ix^d,mag(^
c))\}
5803 call mhd_get_hyperbolic_tc_geometry(ixi^l,ixo^l,te,bvec,bgradt,gradtperp_mag,nperp)
5807 if(.not.slab_uniform)
then
5808 call gradient(te,ixi^l,ixo^l,1,gradt_geom)
5810 do ix1=ixomin1,ixomax1
5813 kappa_t7=kappa_t5*te(ix1)
5817 tcond = max(tcond, block%wextra(ix1,
tcoff_))
5820 kappa_t7=kappa_t5*tcond
5822 if(slab_uniform)
then
5823 gradt1=((8.d0*(te(ix1+1)-te(ix1-1))-te(ix1+2)+te(ix1-2))/12.d0)/block%ds(ix1,1)
5825 gradt1=gradt_geom(ix1)
5828 {^
c& b2=b2+bvec(ix1,^
c)**2\}
5829 bunit_tc=b_unit_vector(bvec(ix1,1:ndir))
5830 bgradt(ix1)=bunit_tc(1)*gradt1
5831 kappat5_bgradt=kappa_t5*bgradt(ix1)
5832 inv_rho=1.d0/rho_loc(ix1)
5834 cfast2 = b2*inv_rho + c2
5835 avmincs2(1) = cfast2**2 - 4.0d0*c2*bvec(ix1,1)**2*inv_rho
5836 cmax(1) = sqrt(half*(cfast2 + sqrt(dabs(avmincs2(1)))))
5838 f_sat=one/(one+dabs(kappat5_bgradt)/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5839 tau=max(4.d0*dt, f_sat*kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*cmax(1)**2))
5840 w(ix^d,
qpar_)=w(ix^d,
qpar_)-qdt*(f_sat*kappat5_bgradt+wct(ix^d,
qpar_))/tau
5843 max(4.d0*dt, kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*cmax(1)**2))
5848 do ix2=ixomin2,ixomax2
5849 do ix1=ixomin1,ixomax1
5852 kappa_t7=kappa_t5*te(ix^d)
5856 tcond=max(tcond, block%wextra(ix^d,
tcoff_))
5859 kappa_t7 = kappa_t5*tcond
5861 kappat5_bgradt=kappa_t5*bgradt(ix^d)
5863 {^
c& b2 = b2 + bvec(ix^d,^
c)**2\}
5864 if(use_perp_source)
then
5865 select case(htc_perp_mode_id)
5866 case(htc_perp_fixed)
5868 case(htc_perp_weak_field)
5874 kappa_t5_perp_eff=(one-fb)*kappa_t5
5875 kappa_t5_perp=kappa_t5_perp_eff
5876 case(htc_perp_electron)
5877 bmag_loc = dsqrt(b2)
5878 tloc = max(te(ix^d), smalldouble)
5879 nloc_code = max(ne_loc(ix^d), smalldouble)
5880 chi = cchi*bmag_loc*tloc**1.5d0/nloc_code
5881 kappa_t5_perp_eff = kappa_t5/(one+chi**2)
5882 kappa_t5_perp = kappa_t5_perp_eff
5886 kappat5_gradtperp=kappa_t5_perp*gradtperp_mag(ix^d)
5888 inv_rho=1.d0/rho_loc(ix^d)
5890 cfast2 = b2*inv_rho + c2
5891 {avmincs2(^d)=cfast2**2-4.0d0*c2*bvec(ix^dd,^d)**2*inv_rho; cmax(^d)=sqrt(half*(cfast2+sqrt(dabs(avmincs2(^d)))))\}
5893 qclass_diss=dabs(kappat5_bgradt)
5894 if(use_perp_source) &
5895 qclass_diss=dsqrt(kappat5_bgradt**2+kappat5_gradtperp**2)
5896 f_sat=one/(one+qclass_diss/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5897 tau=max(4.d0*dt, f_sat*kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*maxval(cmax(:))**2))
5898 w(ix^d,
qpar_)=w(ix^d,
qpar_)-qdt*(f_sat*kappat5_bgradt+wct(ix^d,
qpar_))/tau
5899 if(use_perp_source)
then
5903 tau=max(4.d0*dt, kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*maxval(cmax(:))**2))
5905 if(use_perp_source)
then
5913 do ix3=ixomin3,ixomax3
5914 do ix2=ixomin2,ixomax2
5915 do ix1=ixomin1,ixomax1
5918 kappa_t7=kappa_t5*te(ix^d)
5922 tcond=max(tcond, block%wextra(ix^d,
tcoff_))
5925 kappa_t7 = kappa_t5*tcond
5927 kappat5_bgradt=kappa_t5*bgradt(ix^d)
5929 {^
c& b2 = b2 + bvec(ix^d,^
c)**2\}
5930 if(use_perp_source)
then
5931 select case(htc_perp_mode_id)
5932 case(htc_perp_fixed)
5934 case(htc_perp_weak_field)
5940 kappa_t5_perp_eff=(one-fb)*kappa_t5
5941 kappa_t5_perp=kappa_t5_perp_eff
5942 case(htc_perp_electron)
5943 bmag_loc = dsqrt(b2)
5944 tloc = max(te(ix^d), smalldouble)
5945 nloc_code = max(ne_loc(ix^d), smalldouble)
5946 chi = cchi*bmag_loc*tloc**1.5d0/nloc_code
5947 kappa_t5_perp_eff = kappa_t5/(one+chi**2)
5948 kappa_t5_perp = kappa_t5_perp_eff
5952 kappat5_gradtperp=kappa_t5_perp*gradtperp_mag(ix^d)
5954 inv_rho=1.d0/rho_loc(ix^d)
5956 cfast2 = b2*inv_rho + c2
5957 {avmincs2(^d)=cfast2**2-4.0d0*c2*bvec(ix^dd,^d)**2*inv_rho; cmax(^d)=sqrt(half*(cfast2+sqrt(dabs(avmincs2(^d)))))\}
5959 qclass_diss=dabs(kappat5_bgradt)
5960 if(use_perp_source) &
5961 qclass_diss=dsqrt(kappat5_bgradt**2+kappat5_gradtperp**2)
5962 f_sat=one/(one+qclass_diss/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5963 tau=max(4.d0*dt, f_sat*kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*maxval(cmax(:))**2))
5964 w(ix^d,
qpar_)=w(ix^d,
qpar_)-qdt*(f_sat*kappat5_bgradt+wct(ix^d,
qpar_))/tau
5965 if(use_perp_source)
then
5969 tau=max(4.d0*dt, kappa_t7*courantpar**2/(pth_loc(ix^d)*eos%inv_gamma_minus_1*maxval(cmax(:))**2))
5971 if(use_perp_source)
then
5979 end subroutine add_source_hyperbolic_tc
5983 subroutine get_lorentz_force(ixI^L,ixO^L,w,JxB)
5985 integer,
intent(in) :: ixi^
l, ixo^
l
5986 double precision,
intent(in) :: w(ixi^s,1:nw)
5987 double precision,
intent(inout) :: jxb(ixi^s,3)
5988 double precision :: a(ixi^s,3),
b(ixi^s,3)
5990 double precision :: current(ixi^s,7-2*
ndir:3)
5991 integer :: idir, idirmin
5996 b(ixo^s, idir) = w(ixo^s,mag(idir))+
block%B0(ixo^s,idir,0)
6000 b(ixo^s, idir) = w(ixo^s,mag(idir))
6009 a(ixo^s,idir)=current(ixo^s,idir)
6013 end subroutine get_lorentz_force
6017 integer,
intent(in) :: ixi^
l, ixo^
l
6018 double precision,
intent(in) :: w(ixi^s,1:nw),x(ixi^s,1:
ndim)
6019 double precision,
intent(out) :: rho(ixi^s)
6024 rho(ixo^s) = w(ixo^s,
rho_)
6030 subroutine mhd_handle_small_ei(w, x, ixI^L, ixO^L, ie, subname)
6033 integer,
intent(in) :: ixi^
l,ixo^
l, ie
6034 double precision,
intent(inout) :: w(ixi^s,1:nw)
6035 double precision,
intent(in) :: x(ixi^s,1:
ndim)
6036 character(len=*),
intent(in) :: subname
6038 double precision :: rho(ixi^s)
6040 logical :: flag(ixi^s,1:nw)
6045 flag(ixo^s,ie)=.true.
6047 where(w(ixo^s,ie)<
small_e) flag(ixo^s,ie)=.true.
6049 if(any(flag(ixo^s,ie)))
then
6053 where(flag(ixo^s,ie)) w(ixo^s,ie)=
small_e - &
6056 where(flag(ixo^s,ie)) w(ixo^s,ie)=
small_e
6062 w(ixo^s,
e_)=w(ixo^s,
e_)*eos%gamma_minus_1
6065 w(ixo^s,
mom(idir)) = w(ixo^s,
mom(idir))/rho(ixo^s)
6071 end subroutine mhd_handle_small_ei
6075 subroutine add_source_b0split(qdt,dtfactor,ixI^L,ixO^L,wCT,wCTprim,w,x)
6078 integer,
intent(in) :: ixi^
l, ixo^
l
6079 double precision,
intent(in) :: qdt, dtfactor,wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6080 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
6081 double precision,
intent(inout) :: w(ixi^s,1:nw)
6083 double precision :: a(ixi^s,3),
b(ixi^s,3), axb(ixi^s,3)
6095 a(ixo^s,idir)=
block%J0(ixo^s,idir)
6100 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
6103 axb(ixo^s,:)=axb(ixo^s,:)*qdt
6109 if(total_energy)
then
6112 b(ixo^s,:)=wctprim(ixo^s,mag(:))
6121 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
6124 axb(ixo^s,:)=axb(ixo^s,:)*qdt
6129 w(ixo^s,
e_)=w(ixo^s,
e_)-axb(ixo^s,idir)*
block%J0(ixo^s,idir)
6133 call mhd_getv_hall(wct,x,ixi^
l,ixo^
l,a,.true.)
6138 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
6141 axb(ixo^s,:)=axb(ixo^s,:)*qdt
6145 w(ixo^s,
e_)=w(ixo^s,
e_)-axb(ixo^s,idir)*
block%J0(ixo^s,idir)
6153 call mhd_get_jxbxb(wct,x,ixi^
l,ixo^
l,axb)
6158 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*axb(ixo^s,idir)*
block%J0(ixo^s,idir)
6164 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_B0')
6166 end subroutine add_source_b0split
6169 subroutine add_source_semirelativistic(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
6173 integer,
intent(in) :: ixi^
l, ixo^
l
6174 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6175 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
6176 double precision,
intent(inout) :: w(ixi^s,1:nw)
6178 double precision :: e(ixi^s,1:3),curle(ixi^s,1:3),dive(ixi^s),btot(1:3)
6179 integer :: idir, idirmin, ix^
d
6183 {
do ix^db=iximin^db,iximax^db\}
6185 ^
c&btot(^
c)=wct(ix^
d,
b^
c_)\
6189 e(ix^
d,1)=btot(2)*wctprim(ix^
d,m3_)-btot(3)*wctprim(ix^
d,m2_)
6190 e(ix^
d,2)=btot(3)*wctprim(ix^
d,m1_)-btot(1)*wctprim(ix^
d,m3_)
6191 e(ix^
d,3)=btot(1)*wctprim(ix^
d,m2_)-btot(2)*wctprim(ix^
d,m1_)
6193 call divvector(e,ixi^l,ixo^l,dive)
6195 call curlvector(e,ixi^l,ixo^l,curle,idirmin,1,3)
6202 {
do ix^db=ixomin^db,ixomax^db\}
6203 w(ix^d,m1_)=w(ix^d,m1_)+qdt*(inv_squared_c0-inv_squared_c)*&
6204 (e(ix^d,1)*dive(ix^d)-e(ix^d,2)*curle(ix^d,3)+e(ix^d,3)*curle(ix^d,2))
6205 w(ix^d,m2_)=w(ix^d,m2_)+qdt*(inv_squared_c0-inv_squared_c)*&
6206 (e(ix^d,2)*dive(ix^d)-e(ix^d,3)*curle(ix^d,1)+e(ix^d,1)*curle(ix^d,3))
6207 w(ix^d,m3_)=w(ix^d,m3_)+qdt*(inv_squared_c0-inv_squared_c)*&
6208 (e(ix^d,3)*dive(ix^d)-e(ix^d,1)*curle(ix^d,2)+e(ix^d,2)*curle(ix^d,1) )
6212 end subroutine add_source_semirelativistic
6215 subroutine add_source_internal_e(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
6219 integer,
intent(in) :: ixi^
l, ixo^
l
6220 double precision,
intent(in) :: qdt
6221 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6222 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
6223 double precision,
intent(inout) :: w(ixi^s,1:nw)
6225 double precision :: divv(ixi^s), tmp
6237 {
do ix^db=ixomin^db,ixomax^db\}
6239 w(ix^
d,
e_)=w(ix^
d,
e_)-qdt*wctprim(ix^
d,
p_)*divv(ix^
d)
6245 call add_source_ambipolar_internal_energy(qdt,ixi^l,ixo^l,wct,w,x)
6248 if(fix_small_values)
then
6249 call mhd_handle_small_ei(w,x,ixi^l,ixo^l,
e_,
'add_source_internal_e')
6251 end subroutine add_source_internal_e
6254 subroutine add_source_hydrodynamic_e(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
6259 integer,
intent(in) :: ixi^
l, ixo^
l
6260 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6261 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
6262 double precision,
intent(inout) :: w(ixi^s,1:nw)
6264 double precision ::
b(ixi^s,3), j(ixi^s,3), jxb(ixi^s,3)
6265 double precision :: current(ixi^s,7-2*
ndir:3)
6266 double precision :: bu(ixo^s,1:
ndir), tmp(ixo^s), b2(ixo^s)
6267 double precision :: gravity_field(ixi^s,1:
ndir), vaoc
6268 integer :: idir, idirmin, idims, ix^
d
6273 b(ixo^s, idir) = wct(ixo^s,mag(idir))
6285 j(ixo^s,idir)=current(ixo^s,idir)
6364 call add_source_ambipolar_internal_energy(qdt,ixi^
l,ixo^
l,wct,w,x)
6367 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_hydrodynamic_e')
6369 end subroutine add_source_hydrodynamic_e
6375 subroutine add_source_res1(qdt,ixI^L,ixO^L,wCT,w,x)
6380 integer,
intent(in) :: ixi^
l, ixo^
l
6381 double precision,
intent(in) :: qdt
6382 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6383 double precision,
intent(inout) :: w(ixi^s,1:nw)
6385 integer :: ixa^
l,idir,jdir,kdir,idirmin,idim
6386 double precision :: tmp(ixi^s),tmp2(ixi^s)
6389 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s)
6390 double precision :: gradeta(ixi^s,1:
ndim), bf(ixi^s,1:
ndir)
6391 double precision :: lapl_vec(ixi^s,1:
ndir)
6397 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6398 call mpistop(
"Error in add_source_res1: Non-conforming input limits")
6405 gradeta(ixo^s,1:
ndim)=zero
6410 gradeta(ixo^s,idim)=tmp(ixo^s)
6417 bf(ixi^s,1:
ndir)=wct(ixi^s,mag(1:
ndir))
6424 tmp(ixo^s)=lapl_vec(ixo^s,idir)*eta(ixo^s)
6428 do jdir=1,
ndim;
do kdir=idirmin,3
6429 if (
lvc(idir,jdir,kdir)/=0)
then
6430 if (
lvc(idir,jdir,kdir)==1)
then
6431 tmp(ixo^s)=tmp(ixo^s)-gradeta(ixo^s,jdir)*current(ixo^s,kdir)
6433 tmp(ixo^s)=tmp(ixo^s)+gradeta(ixo^s,jdir)*current(ixo^s,kdir)
6440 w(ixo^s,mag(idir))=w(ixo^s,mag(idir))+qdt*tmp(ixo^s)
6441 if(total_energy)
then
6442 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*tmp(ixo^s)*bf(ixo^s,idir)
6448 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*eta(ixo^s)*sum(current(ixo^s,:)**2,dim=ndim+1)
6451 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_res1')
6453 end subroutine add_source_res1
6457 subroutine add_source_res_exp(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x)
6462 integer,
intent(in) :: ixi^
l, ixo^
l
6463 double precision,
intent(in) :: qdt
6464 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6465 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
6466 double precision,
intent(inout) :: w(ixi^s,1:nw)
6469 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s),curlj(ixi^s,1:3)
6470 double precision :: tmpvec(ixi^s,1:3),tmp(ixo^s)
6471 integer :: ixa^
l,idir,idirmin,idirmin1,ix^
d
6475 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6476 call mpistop(
"Error in add_source_res_exp: Non-conforming input limits")
6486 tmpvec(ixa^s,idir)=current(ixa^s,idir)*
mhd_eta
6491 tmpvec(ixa^s,idir)=current(ixa^s,idir)*eta(ixa^s)
6497 {
do ix^db=ixomin^db,ixomax^db\}
6512 w(ix^
d,
e_)=w(ix^
d,
e_)+qdt*eta(ix^
d)*(^
c¤t(ix^
d,^
c)**2+)
6519 w(ix^
d,
e_)=w(ix^
d,
e_)+qdt*eta(ix^
d)*current(ix^
d,3)**2
6522 if(total_energy)
then
6525 w(ix^
d,
e_)=w(ix^
d,
e_)-qdt*(^
c&wct(ix^
d,
b^
c_)*curlj(ix^
d,^
c)+)
6530 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_res_exp')
6531 end subroutine add_source_res_exp
6536 subroutine add_source_ambi_exp(qdt,ixI^L,ixO^L,wCT,w,x)
6541 integer,
intent(in) :: ixi^
l, ixo^
l
6542 double precision,
intent(in) :: qdt
6543 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6544 double precision,
intent(inout) :: w(ixi^s,1:nw)
6546 double precision :: current(ixi^s,1:3),curlj(ixi^s,1:3)
6547 double precision :: tmpvec(ixi^s,1:3),tmp(ixi^s),btot2(ixi^s)
6548 integer :: ixa^
l,idir,idirmin1
6552 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6553 call mpistop(
"Error in add_source_ambi_exp: Non-conforming input limits")
6557 call mhd_get_jxbxb(wct,x,ixi^
l,ixa^
l,current)
6571 w(ixo^s,mag(
ndir)) = w(ixo^s,mag(
ndir))-qdt*curlj(ixo^s,
ndir)
6574 w(ixo^s,mag(1:
ndir)) = w(ixo^s,mag(1:
ndir))-qdt*curlj(ixo^s,1:
ndir)
6581 where (btot2(ixa^s)>smalldouble )
6582 tmp(ixa^s) = sum(current(ixa^s,1:3)**2,dim=
ndim+1) / btot2(ixa^s)
6589 tmp(ixo^s)=-qdt*tmp(ixo^s)
6590 if(total_energy)
then
6593 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)-&
6594 qdt*sum(wct(ixo^s,mag(1:
ndir))*curlj(ixo^s,1:
ndir),dim=
ndim+1)
6597 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)
6601 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_ambi_exp')
6602 end subroutine add_source_ambi_exp
6606 subroutine add_source_hyperres(qdt,ixI^L,ixO^L,wCT,w,x)
6610 integer,
intent(in) :: ixi^
l, ixo^
l
6611 double precision,
intent(in) :: qdt
6612 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6613 double precision,
intent(inout) :: w(ixi^s,1:nw)
6615 double precision :: current(ixi^s,7-2*
ndir:3)
6616 double precision :: tmpvec(ixi^s,1:3),tmpvec2(ixi^s,1:3),tmp(ixi^s),ehyper(ixi^s,1:3)
6617 integer :: ixa^
l,idir,jdir,kdir,idirmin,idirmin1
6620 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6621 call mpistop(
"Error in add_source_hyperres: Non-conforming input limits")
6624 tmpvec(ixa^s,1:
ndir)=zero
6626 tmpvec(ixa^s,jdir)=current(ixa^s,jdir)
6630 call curlvector(tmpvec,ixi^
l,ixa^
l,tmpvec2,idirmin1,1,3)
6633 tmpvec(ixa^s,1:
ndir)=zero
6634 call curlvector(tmpvec2,ixi^
l,ixa^
l,tmpvec,idirmin1,1,3)
6638 tmpvec2(ixa^s,1:
ndir)=zero
6639 call curlvector(ehyper,ixi^
l,ixa^
l,tmpvec2,idirmin1,1,3)
6642 w(ixo^s,mag(idir)) = w(ixo^s,mag(idir))-tmpvec2(ixo^s,idir)*qdt
6645 if(total_energy)
then
6648 tmpvec2(ixa^s,1:
ndir)=zero
6649 do idir=1,
ndir;
do jdir=1,
ndir;
do kdir=idirmin,3
6650 tmpvec2(ixa^s,idir) = tmpvec(ixa^s,idir)&
6651 +
lvc(idir,jdir,kdir)*wct(ixa^s,mag(jdir))*ehyper(ixa^s,kdir)
6652 end do;
end do;
end do
6654 call divvector(tmpvec2,ixi^l,ixo^l,tmp)
6655 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)*qdt
6658 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_hyperres')
6660 end subroutine add_source_hyperres
6662 subroutine add_source_glm(qdt,ixI^L,ixO^L,wCT,w,x)
6669 integer,
intent(in) :: ixi^
l, ixo^
l
6670 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6671 double precision,
intent(inout) :: w(ixi^s,1:nw)
6673 double precision:: divb(ixi^s), gradpsi(ixi^s), ba(ixo^s,1:
ndir)
6694 ba(ixo^s,1:
ndir)=wct(ixo^s,mag(1:
ndir))
6697 if(total_energy)
then
6706 w(ixo^s,
e_) = w(ixo^s,
e_)-qdt*wct(ixo^s,mag(idir))*gradpsi(ixo^s)
6715 w(ixo^s,
mom(idir))=w(ixo^s,
mom(idir))-qdt*ba(ixo^s,idir)*divb(ixo^s)
6719 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_glm')
6721 end subroutine add_source_glm
6724 subroutine add_source_powel(qdt,ixI^L,ixO^L,wCT,w,x)
6727 integer,
intent(in) :: ixi^
l, ixo^
l
6728 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6729 double precision,
intent(inout) :: w(ixi^s,1:nw)
6731 double precision :: divb(ixi^s), ba(1:
ndir)
6732 integer :: idir, ix^
d
6738 {
do ix^db=ixomin^db,ixomax^db\}
6743 if (total_energy)
then
6749 {
do ix^db=ixomin^db,ixomax^db\}
6751 ^
c&w(ix^d,
b^
c_)=w(ix^d,
b^
c_)-qdt*wct(ix^d,
m^
c_)*divb(ix^d)\
6753 ^
c&w(ix^d,
m^
c_)=w(ix^d,
m^
c_)-qdt*wct(ix^d,
b^
c_)*divb(ix^d)\
6754 if (total_energy)
then
6756 w(ix^d,
e_)=w(ix^d,
e_)-qdt*(^
c&wct(ix^d,
m^
c_)*wct(ix^d,
b^
c_)+)*divb(ix^d)
6761 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_powel')
6763 end subroutine add_source_powel
6765 subroutine add_source_janhunen(qdt,ixI^L,ixO^L,wCT,w,x)
6770 integer,
intent(in) :: ixi^
l, ixo^
l
6771 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6772 double precision,
intent(inout) :: w(ixi^s,1:nw)
6774 double precision :: divb(ixi^s)
6775 integer :: idir, ix^
d
6780 {
do ix^db=ixomin^db,ixomax^db\}
6785 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_janhunen')
6787 end subroutine add_source_janhunen
6789 subroutine add_source_linde(qdt,ixI^L,ixO^L,wCT,w,x)
6794 integer,
intent(in) :: ixi^
l, ixo^
l
6795 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6796 double precision,
intent(inout) :: w(ixi^s,1:nw)
6798 double precision :: divb(ixi^s),graddivb(ixi^s)
6799 integer :: idim, idir, ixp^
l, i^
d, iside
6800 logical,
dimension(-1:1^D&) :: leveljump
6808 if(i^
d==0|.and.) cycle
6809 if(neighbor_type(i^
d,
block%igrid)==2 .or. neighbor_type(i^
d,
block%igrid)==4)
then
6810 leveljump(i^
d)=.true.
6812 leveljump(i^
d)=.false.
6821 i^dd=kr(^dd,^d)*(2*iside-3);
6822 if (leveljump(i^dd))
then
6824 ixpmin^d=ixomin^d-i^d
6826 ixpmax^d=ixomax^d-i^d
6837 call gradient(divb,ixi^l,ixp^l,idim,graddivb)
6839 {
do i^db=ixpmin^db,ixpmax^db\}
6841 graddivb(i^d)=graddivb(i^d)*
divbdiff/(^d&1.0d0/block%ds({i^d},^d)**2+)
6843 w(i^d,mag(idim))=w(i^d,mag(idim))+graddivb(i^d)
6845 if (typedivbdiff==
'all' .and. total_energy)
then
6848 w(i^d,
e_)=w(i^d,
e_)+wct(i^d,mag(idim))*graddivb(i^d)
6853 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_linde')
6855 end subroutine add_source_linde
6862 integer,
intent(in) :: ixi^
l, ixo^
l
6863 double precision,
intent(in) :: w(ixi^s,1:nw)
6864 double precision :: divb(ixi^s), dsurface(ixi^s)
6866 double precision :: invb(ixo^s)
6867 integer :: ixa^
l,idims
6869 call get_divb(w,ixi^
l,ixo^
l,divb)
6871 where(invb(ixo^s)/=0.d0)
6872 invb(ixo^s)=1.d0/invb(ixo^s)
6875 divb(ixo^s)=0.5d0*abs(divb(ixo^s))*invb(ixo^s)/sum(1.d0/
dxlevel(:))
6877 ixamin^
d=ixomin^
d-1;
6878 ixamax^
d=ixomax^
d-1;
6879 dsurface(ixo^s)= sum(
block%surfaceC(ixo^s,:),dim=
ndim+1)
6881 ixa^
l=ixo^
l-
kr(idims,^
d);
6882 dsurface(ixo^s)=dsurface(ixo^s)+
block%surfaceC(ixa^s,idims)
6884 divb(ixo^s)=abs(divb(ixo^s))*invb(ixo^s)*&
6885 block%dvolume(ixo^s)/dsurface(ixo^s)
6896 integer,
intent(in) :: ixo^
l, ixi^
l
6897 double precision,
intent(in) :: w(ixi^s,1:nw)
6898 integer,
intent(out) :: idirmin
6901 double precision :: current(ixi^s,7-2*
ndir:3)
6902 integer :: idir, idirmin0
6908 if(
b0field) current(ixo^s,idirmin0:3)=current(ixo^s,idirmin0:3)+&
6909 block%J0(ixo^s,idirmin0:3)
6913 subroutine mhd_get_dt(wprim,ixI^L,ixO^L,dtnew,dx^D,x)
6921 integer,
intent(in) :: ixi^
l, ixo^
l
6922 double precision,
intent(inout) :: dtnew
6923 double precision,
intent(in) ::
dx^
d
6924 double precision,
intent(in) :: wprim(ixi^s,1:nw)
6925 double precision,
intent(in) :: x(ixi^s,1:
ndim)
6927 double precision :: dxarr(
ndim)
6928 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s)
6929 integer :: idirmin,idim
6947 dtdiffpar/(smalldouble+maxval(eta(ixo^s)/dxarr(idim)**2)))
6950 dtdiffpar/(smalldouble+maxval(eta(ixo^s)/
block%ds(ixo^s,idim)**2)))
6972 dtnew=min(
dtdiffpar*get_ambipolar_dt(wprim,ixi^
l,ixo^
l,
dx^
d,x),dtnew)
6983 end subroutine mhd_get_dt
6988 subroutine mhd_fld_implicit_update(dtfactor,qdt,qtC,psa,psb)
6993 double precision,
intent(in) :: qdt
6994 double precision,
intent(in) :: qtc
6995 double precision,
intent(in) :: dtfactor
6998 end subroutine mhd_fld_implicit_update
7000 subroutine mhd_fld_evaluate_implicit(qtC,psa)
7004 double precision,
intent(in) :: qtc
7007 end subroutine mhd_fld_evaluate_implicit
7014 subroutine mhd_add_source_geom(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
7020 integer,
intent(in) :: ixi^
l, ixo^
l
7021 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
7022 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
7024 double precision :: adiabs(ixi^s), gammas(ixi^s)
7025 double precision :: tmp,tmp1,invr,cot
7027 integer :: mr_,mphi_
7028 integer :: br_,bphi_
7031 br_=mag(1); bphi_=mag(1)-1+
phi_
7048 {
do ix^db=ixomin^db,ixomax^db\}
7051 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
7056 tmp=wprim(ix^
d,
p_)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
7058 tmp=adiabs(ix^
d)*wprim(ix^
d,
rho_)**gammas(ix^
d)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
7061 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp-&
7062 wprim(ix^
d,bphi_)**2+wprim(ix^
d,mphi_)*wct(ix^
d,mphi_))
7063 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
7064 -wct(ix^
d,mphi_)*wprim(ix^
d,mr_) &
7065 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_))
7067 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
7068 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
7069 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
7072 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*tmp
7077 {
do ix^db=ixomin^db,ixomax^db\}
7079 if(local_timestep)
then
7080 invr=block%dt(ix^d) * dtfactor/x(ix^d,1)
7085 tmp1=wprim(ix^d,
p_)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
7087 tmp1=adiabs(ix^d)*wprim(ix^d,
rho_)**gammas(ix^d)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
7091 w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp1*invr
7094 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
7095 (two*tmp1+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+))
7099 w(ix^d,mag(1))=w(ix^d,mag(1))+invr*2.0d0*wprim(ix^d,
psi_)
7105 cot=1.d0/tan(x(ix^d,2))
7109 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7110 +wprim(ix^d,b1_)*wprim(ix^d,b2_))
7112 if(.not.stagger_grid)
then
7113 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7115 tmp=tmp+wprim(ix^d,
psi_)*cot
7117 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
7122 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7123 +wprim(ix^d,b1_)*wprim(ix^d,b2_)&
7124 +(wprim(ix^d,m3_)*wct(ix^d,m3_)-wprim(ix^d,b3_)**2)*cot)
7126 if(.not.stagger_grid)
then
7127 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7129 tmp=tmp+wprim(ix^d,
psi_)*cot
7131 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
7134 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
7135 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
7136 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
7137 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
7138 -wprim(ix^d,b2_)*wprim(ix^d,b3_))*cot)
7140 if(.not.stagger_grid)
then
7141 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
7142 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
7143 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
7144 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
7145 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
7152 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
7155 end subroutine mhd_add_source_geom
7162 subroutine mhd_add_source_geom_semirelati(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
7168 integer,
intent(in) :: ixi^
l, ixo^
l
7169 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
7170 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
7172 double precision :: adiabs(ixi^s), gammas(ixi^s)
7173 double precision :: tmp,tmp1,tmp2,invr,cot,ef(ixo^s,1:
ndir)
7175 integer :: mr_,mphi_
7176 integer :: br_,bphi_
7179 br_=mag(1); bphi_=mag(1)-1+
phi_
7196 {
do ix^db=ixomin^db,ixomax^db\}
7199 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
7206 tmp=adiabs(ix^
d)*wprim(ix^
d,
rho_)**gammas(ix^
d)
7210 ef(ix^
d,1)=wprim(ix^
d,b2_)*wprim(ix^
d,m3_)-wprim(ix^
d,b3_)*wprim(ix^
d,m2_)
7211 ef(ix^
d,2)=wprim(ix^
d,b3_)*wprim(ix^
d,m1_)-wprim(ix^
d,b1_)*wprim(ix^
d,m3_)
7212 ef(ix^
d,3)=wprim(ix^
d,b1_)*wprim(ix^
d,m2_)-wprim(ix^
d,b2_)*wprim(ix^
d,m1_)
7217 ef(ix^
d,2)=wprim(ix^
d,b1_)*wprim(ix^
d,m2_)-wprim(ix^
d,b2_)*wprim(ix^
d,m1_)
7223 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp+&
7224 half*((^
c&wprim(ix^
d,
b^
c_)**2+)+(^
c&ef(ix^
d,^
c)**2+)*inv_squared_c) -&
7225 wprim(ix^
d,bphi_)**2+wprim(ix^
d,
rho_)*wprim(ix^
d,mphi_)**2)
7226 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
7227 -wprim(ix^
d,
rho_)*wprim(ix^
d,mphi_)*wprim(ix^
d,mr_) &
7228 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_)+ef(ix^
d,
phi_)*ef(ix^
d,1)*inv_squared_c)
7230 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
7231 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
7232 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
7235 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp+half*((^
c&wprim(ix^
d,
b^
c_)**2+)+&
7236 (^
c&ef(ix^
d,^
c)**2+)*inv_squared_c))
7241 {
do ix^db=ixomin^db,ixomax^db\}
7243 if(local_timestep)
then
7244 invr=block%dt(ix^d)*dtfactor/x(ix^d,1)
7250 ef(ix^d,1)=wprim(ix^d,b2_)*wprim(ix^d,m3_)-wprim(ix^d,b3_)*wprim(ix^d,m2_)
7251 ef(ix^d,2)=wprim(ix^d,b3_)*wprim(ix^d,m1_)-wprim(ix^d,b1_)*wprim(ix^d,m3_)
7252 ef(ix^d,3)=wprim(ix^d,b1_)*wprim(ix^d,m2_)-wprim(ix^d,b2_)*wprim(ix^d,m1_)
7256 ef(ix^d,1)=wprim(ix^d,b1_)*wprim(ix^d,m2_)-wprim(ix^d,b2_)*wprim(ix^d,m1_)
7263 tmp1=wprim(ix^d,
p_)+half*((^
c&wprim(ix^d,
b^
c_)**2+)+(^
c&ef(ix^d,^
c)**2+)*inv_squared_c)
7265 tmp1=adiabs(ix^d)*wprim(ix^d,
rho_)**gammas(ix^d)+half*((^
c&wprim(ix^d,
b^
c_)**2+)+(^
c&ef(ix^d,^
c)**2+)*inv_squared_c)
7269 w(ix^d,m1_)=w(ix^d,m1_)+two*tmp1*invr
7272 w(ix^d,m1_)=w(ix^d,m1_)+invr*&
7273 (two*tmp1+(^ce&wprim(ix^d,
rho_)*wprim(ix^d,
m^ce_)**2-&
7274 wprim(ix^d,
b^ce_)**2-ef(ix^d,^ce)**2*inv_squared_c+))
7278 w(ix^d,b1_)=w(ix^d,b1_)+invr*2.0d0*wprim(ix^d,
psi_)
7284 cot=1.d0/tan(x(ix^d,2))
7288 w(ix^d,m2_)=w(ix^d,m2_)+invr*(tmp1*cot-wprim(ix^d,
rho_)*wprim(ix^d,m1_)*wprim(ix^d,m2_)&
7289 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+ef(ix^d,1)*ef(ix^d,2)*inv_squared_c)
7291 if(.not.stagger_grid)
then
7292 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7294 tmp=tmp+wprim(ix^d,
psi_)*cot
7296 w(ix^d,b2_)=w(ix^d,b2_)+tmp*invr
7302 w(ix^d,m2_)=w(ix^d,m2_)+invr*(tmp1*cot-wprim(ix^d,
rho_)*wprim(ix^d,m1_)*wprim(ix^d,m2_) &
7303 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+ef(ix^d,1)*ef(ix^d,2)*inv_squared_c&
7304 +(wprim(ix^d,
rho_)*wprim(ix^d,m3_)**2&
7305 -wprim(ix^d,b3_)**2-ef(ix^d,3)**2*inv_squared_c)*cot)
7307 if(.not.stagger_grid)
then
7308 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7310 tmp=tmp+wprim(ix^d,
psi_)*cot
7312 w(ix^d,b2_)=w(ix^d,b2_)+tmp*invr
7315 w(ix^d,m3_)=w(ix^d,m3_)+invr*&
7316 (-wprim(ix^d,m3_)*wprim(ix^d,m1_)*wprim(ix^d,
rho_) &
7317 +wprim(ix^d,b3_)*wprim(ix^d,b1_) &
7318 +ef(ix^d,3)*ef(ix^d,1)*inv_squared_c&
7319 +(-wprim(ix^d,m2_)*wprim(ix^d,m3_)*wprim(ix^d,
rho_) &
7320 +wprim(ix^d,b2_)*wprim(ix^d,b3_)&
7321 +ef(ix^d,2)*ef(ix^d,3)*inv_squared_c)*cot)
7323 if(.not.stagger_grid)
then
7324 w(ix^d,b3_)=w(ix^d,b3_)+invr*&
7325 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
7326 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
7327 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
7328 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
7335 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
7338 end subroutine mhd_add_source_geom_semirelati
7347 subroutine mhd_add_source_geom_split(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
7353 integer,
intent(in) :: ixi^
l, ixo^
l
7354 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
7355 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
7357 double precision :: tmp,tmp1,tmp2,invr,cot
7358 double precision :: adiabs(ixi^s), gammas(ixi^s)
7360 integer :: mr_,mphi_
7361 integer :: br_,bphi_
7377 br_=mag(1); bphi_=mag(1)-1+
phi_
7382 {
do ix^db=ixomin^db,ixomax^db\}
7385 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
7390 tmp=wprim(ix^
d,
p_)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
7392 tmp=adiabs(ix^
d)*wprim(ix^
d,
rho_)**gammas(ix^
d)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
7396 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp-&
7397 wprim(ix^
d,bphi_)**2+wprim(ix^
d,mphi_)*wct(ix^
d,mphi_))
7401 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
7402 -wct(ix^
d,mphi_)*wprim(ix^
d,mr_) &
7403 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_))
7405 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(
block%B0(ix^
d,
phi_,0)*wprim(ix^
d,br_)+wprim(ix^
d,bphi_)*
block%B0(ix^
d,
r_,0))
7408 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
7409 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
7410 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
7412 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
7418 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*tmp
7423 {
do ix^db=ixomin^db,ixomax^db\}
7425 if(local_timestep)
then
7426 invr=block%dt(ix^d) * dtfactor/x(ix^d,1)
7430 tmp1=wprim(ix^d,
p_)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
7431 if(b0field) tmp2=(^
c&block%B0(ix^d,^
c,0)*wprim(ix^d,
b^
c_)+)
7434 w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp1*invr
7435 if(b0field) w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp2*invr
7439 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
7440 (two*(tmp1+tmp2)+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+)- &
7441 (^ce&two*block%B0(ix^d,^ce,0)*wprim(ix^d,
b^ce_)+))
7443 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
7444 (two*tmp1+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+))
7449 w(ix^d,mag(1))=w(ix^d,mag(1))+invr*2.0d0*wprim(ix^d,
psi_)
7455 cot=1.d0/tan(x(ix^d,2))
7460 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*((tmp1+tmp2)*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7461 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+block%B0(ix^d,1,0)*wprim(ix^d,b2_)&
7462 +wprim(ix^d,b1_)*block%B0(ix^d,2,0))
7464 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7465 +wprim(ix^d,b1_)*wprim(ix^d,b2_))
7468 if(.not.stagger_grid)
then
7470 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)&
7471 +wprim(ix^d,m1_)*block%B0(ix^d,2,0)-wprim(ix^d,m2_)*block%B0(ix^d,1,0)
7473 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7476 tmp=tmp+wprim(ix^d,
psi_)*cot
7478 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
7484 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*((tmp1+tmp2)*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7485 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+block%B0(ix^d,1,0)*wprim(ix^d,b2_)&
7486 +wprim(ix^d,b1_)*block%B0(ix^d,2,0)&
7487 +(wprim(ix^d,m3_)*wct(ix^d,m3_)-wprim(ix^d,b3_)**2-two*block%B0(ix^d,3,0)*wprim(ix^d,b3_))*cot)
7489 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
7490 +wprim(ix^d,b1_)*wprim(ix^d,b2_)&
7491 +(wprim(ix^d,m3_)*wct(ix^d,m3_)-wprim(ix^d,b3_)**2)*cot)
7494 if(.not.stagger_grid)
then
7496 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)&
7497 +wprim(ix^d,m1_)*block%B0(ix^d,2,0)-wprim(ix^d,m2_)*block%B0(ix^d,1,0)
7499 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
7502 tmp=tmp+wprim(ix^d,
psi_)*cot
7504 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
7508 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
7509 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
7510 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
7511 +block%B0(ix^d,1,0)*wprim(ix^d,b3_) &
7512 +wprim(ix^d,b1_)*block%B0(ix^d,3,0) &
7513 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
7514 -wprim(ix^d,b2_)*wprim(ix^d,b3_) &
7515 +block%B0(ix^d,2,0)*wprim(ix^d,b3_) &
7516 +wprim(ix^d,b2_)*block%B0(ix^d,3,0))*cot)
7518 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
7519 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
7520 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
7521 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
7522 -wprim(ix^d,b2_)*wprim(ix^d,b3_))*cot)
7525 if(.not.stagger_grid)
then
7527 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
7528 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
7529 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
7530 +wprim(ix^d,m1_)*block%B0(ix^d,3,0) &
7531 -wprim(ix^d,m3_)*block%B0(ix^d,1,0) &
7532 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
7533 -wprim(ix^d,m2_)*wprim(ix^d,b3_) &
7534 +wprim(ix^d,m3_)*block%B0(ix^d,2,0) &
7535 -wprim(ix^d,m2_)*block%B0(ix^d,3,0))*cot)
7537 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
7538 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
7539 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
7540 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
7541 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
7549 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
7552 end subroutine mhd_add_source_geom_split
7557 integer,
intent(in) :: ixi^
l, ixo^
l
7558 double precision,
intent(in) :: w(ixi^s, nw)
7559 double precision :: mge(ixo^s)
7562 mge = sum((w(ixo^s, mag(:))+
block%B0(ixo^s,:,
b0i))**2, dim=
ndim+1)
7564 mge = sum(w(ixo^s, mag(:))**2, dim=
ndim+1)
7568 subroutine mhd_getv_hall(w,x,ixI^L,ixO^L,vHall,partial)
7572 integer,
intent(in) :: ixi^
l, ixo^
l
7573 double precision,
intent(in) :: w(ixi^s,nw)
7574 double precision,
intent(in) :: x(ixi^s,1:
ndim)
7575 double precision,
intent(inout) :: vhall(ixi^s,1:
ndir)
7576 logical,
intent(in),
optional :: partial
7578 double precision :: current(ixi^s,7-2*
ndir:3)
7579 double precision :: rho(ixi^s)
7580 integer :: idir, idirmin, ix^
d
7581 logical :: use_partial
7584 if(
present(partial)) use_partial=partial
7586 if(.not.use_partial)
then
7597 do idir = idirmin,
ndir
7598 {
do ix^db=ixomin^db,ixomax^db\}
7599 vhall(ix^
d,idir)=-
mhd_etah*current(ix^
d,idir)/rho(ix^
d)
7603 end subroutine mhd_getv_hall
7605 subroutine mhd_modify_wlr(ixI^L,ixO^L,qt,wLC,wRC,wLp,wRp,s,idir)
7608 integer,
intent(in) :: ixi^
l, ixo^
l, idir
7609 double precision,
intent(in) :: qt
7610 double precision,
intent(inout) :: wlc(ixi^s,1:nw), wrc(ixi^s,1:nw)
7611 double precision,
intent(inout) :: wlp(ixi^s,1:nw), wrp(ixi^s,1:nw)
7614 double precision :: db
7615 integer :: ix^
d, saved_b0i
7618 {
do ix^db=ixomin^db,ixomax^db\}
7619 wlc(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7620 wrc(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7621 wlp(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7622 wrp(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7631 {
do ix^db=ixomin^db,ixomax^db\}
7632 db=wrp(ix^d,mag(idir))-wlp(ix^d,mag(idir))
7633 wlp(ix^d,mag(idir))=half*(wrp(ix^d,mag(idir))+wlp(ix^d,mag(idir))-(wrp(ix^d,
psi_)-wlp(ix^d,
psi_))/cmax_global)
7634 wlp(ix^d,
psi_)=half*(wrp(ix^d,
psi_)+wlp(ix^d,
psi_)-db*cmax_global)
7635 wrp(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7638 wrc(ix^d,
e_)=wrc(ix^d,
e_)-half*wrc(ix^d,mag(idir))**2
7639 wlc(ix^d,
e_)=wlc(ix^d,
e_)-half*wlc(ix^d,mag(idir))**2
7641 wrc(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7643 wlc(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7647 wrc(ix^d,
e_)=wrc(ix^d,
e_)+half*wrc(ix^d,mag(idir))**2
7648 wlc(ix^d,
e_)=wlc(ix^d,
e_)+half*wlc(ix^d,mag(idir))**2
7658 wlc(ixo^s,1:nw)=wlp(ixo^s,1:nw)
7659 wrc(ixo^s,1:nw)=wrp(ixo^s,1:nw)
7660 call phys_to_conserved(ixi^l,ixo^l,wlc,s%x)
7661 call phys_to_conserved(ixi^l,ixo^l,wrc,s%x)
7667 if(
associated(usr_set_wlr))
call usr_set_wlr(ixi^l,ixo^l,qt,wlc,wrc,wlp,wrp,s,idir)
7669 end subroutine mhd_modify_wlr
7671 subroutine mhd_boundary_adjust(igrid,psb)
7673 integer,
intent(in) :: igrid
7676 integer :: ib, idims, iside, ixo^
l, i^
d
7685 i^
d=
kr(^
d,idims)*(2*iside-3);
7686 if (neighbor_type(i^
d,igrid)/=1) cycle
7687 ib=(idims-1)*2+iside
7705 call fixdivb_boundary(ixg^
ll,ixo^
l,psb(igrid)%w,psb(igrid)%x,ib)
7710 end subroutine mhd_boundary_adjust
7712 subroutine fixdivb_boundary(ixG^L,ixO^L,w,x,iB)
7715 integer,
intent(in) :: ixg^
l,ixo^
l,ib
7716 double precision,
intent(inout) :: w(ixg^s,1:nw)
7717 double precision,
intent(in) :: x(ixg^s,1:
ndim)
7719 double precision :: dx1x2,dx1x3,dx2x1,dx2x3,dx3x1,dx3x2
7720 integer :: ix^
d,ixf^
l
7726 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
7734 do ix1=ixfmax1,ixfmin1,-1
7735 w(ix1-1,ixfmin2:ixfmax2,mag(1))=w(ix1+1,ixfmin2:ixfmax2,mag(1)) &
7736 +dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))-&
7737 w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))
7740 do ix1=ixfmax1,ixfmin1,-1
7741 w(ix1-1,ixfmin2:ixfmax2,mag(1))=( (w(ix1+1,ixfmin2:ixfmax2,mag(1))+&
7742 w(ix1,ixfmin2:ixfmax2,mag(1)))*
block%surfaceC(ix1,ixfmin2:ixfmax2,1)&
7743 +(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))+w(ix1,ixfmin2:ixfmax2,mag(2)))*&
7744 block%surfaceC(ix1,ixfmin2:ixfmax2,2)&
7745 -(w(ix1,ixfmin2:ixfmax2,mag(2))+w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))*&
7746 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,2) )&
7747 /
block%surfaceC(ix1-1,ixfmin2:ixfmax2,1)-w(ix1,ixfmin2:ixfmax2,mag(1))
7761 do ix1=ixfmax1,ixfmin1,-1
7762 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7763 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)) &
7764 +dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))-&
7765 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2))) &
7766 +dx1x3*(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))-&
7767 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))
7770 do ix1=ixfmax1,ixfmin1,-1
7771 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7772 ( (w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))+&
7773 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)))*&
7774 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)&
7775 +(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))+&
7776 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2)))*&
7777 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,2)&
7778 -(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2))+&
7779 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2)))*&
7780 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,2)&
7781 +(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))+&
7782 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3)))*&
7783 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,3)&
7784 -(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3))+&
7785 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7786 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,3) )&
7787 /
block%surfaceC(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)-&
7788 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))
7793 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
7796 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
7804 do ix1=ixfmin1,ixfmax1
7805 w(ix1+1,ixfmin2:ixfmax2,mag(1))=w(ix1-1,ixfmin2:ixfmax2,mag(1)) &
7806 -dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))-&
7807 w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))
7810 do ix1=ixfmin1,ixfmax1
7811 w(ix1+1,ixfmin2:ixfmax2,mag(1))=( (w(ix1-1,ixfmin2:ixfmax2,mag(1))+&
7812 w(ix1,ixfmin2:ixfmax2,mag(1)))*
block%surfaceC(ix1-1,ixfmin2:ixfmax2,1)&
7813 -(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))+w(ix1,ixfmin2:ixfmax2,mag(2)))*&
7814 block%surfaceC(ix1,ixfmin2:ixfmax2,2)&
7815 +(w(ix1,ixfmin2:ixfmax2,mag(2))+w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))*&
7816 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,2) )&
7817 /
block%surfaceC(ix1,ixfmin2:ixfmax2,1)-w(ix1,ixfmin2:ixfmax2,mag(1))
7831 do ix1=ixfmin1,ixfmax1
7832 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7833 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)) &
7834 -dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))-&
7835 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2))) &
7836 -dx1x3*(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))-&
7837 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))
7840 do ix1=ixfmin1,ixfmax1
7841 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7842 ( (w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))+&
7843 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)))*&
7844 block%surfaceC(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)&
7845 -(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))+&
7846 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2)))*&
7847 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,2)&
7848 +(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2))+&
7849 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2)))*&
7850 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,2)&
7851 -(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))+&
7852 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3)))*&
7853 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,3)&
7854 +(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3))+&
7855 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7856 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,3) )&
7857 /
block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)-&
7858 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))
7863 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
7866 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
7874 do ix2=ixfmax2,ixfmin2,-1
7875 w(ixfmin1:ixfmax1,ix2-1,mag(2))=w(ixfmin1:ixfmax1,ix2+1,mag(2)) &
7876 +dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))-&
7877 w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))
7880 do ix2=ixfmax2,ixfmin2,-1
7881 w(ixfmin1:ixfmax1,ix2-1,mag(2))=( (w(ixfmin1:ixfmax1,ix2+1,mag(2))+&
7882 w(ixfmin1:ixfmax1,ix2,mag(2)))*
block%surfaceC(ixfmin1:ixfmax1,ix2,2)&
7883 +(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))+w(ixfmin1:ixfmax1,ix2,mag(1)))*&
7884 block%surfaceC(ixfmin1:ixfmax1,ix2,1)&
7885 -(w(ixfmin1:ixfmax1,ix2,mag(1))+w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))*&
7886 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,1) )&
7887 /
block%surfaceC(ixfmin1:ixfmax1,ix2-1,2)-w(ixfmin1:ixfmax1,ix2,mag(2))
7901 do ix2=ixfmax2,ixfmin2,-1
7902 w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))=w(ixfmin1:ixfmax1,&
7903 ix2+1,ixfmin3:ixfmax3,mag(2)) &
7904 +dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))-&
7905 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1))) &
7906 +dx2x3*(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))-&
7907 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))
7910 do ix2=ixfmax2,ixfmin2,-1
7911 w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))=&
7912 ( (w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))+&
7913 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2)))*&
7914 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,2)&
7915 +(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))+&
7916 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7917 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,1)&
7918 -(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1))+&
7919 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7920 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,1)&
7921 +(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))+&
7922 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3)))*&
7923 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,3)&
7924 -(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3))+&
7925 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7926 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,3) )&
7927 /
block%surfaceC(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,2)-&
7928 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2))
7933 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
7936 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
7944 do ix2=ixfmin2,ixfmax2
7945 w(ixfmin1:ixfmax1,ix2+1,mag(2))=w(ixfmin1:ixfmax1,ix2-1,mag(2)) &
7946 -dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))-&
7947 w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))
7950 do ix2=ixfmin2,ixfmax2
7951 w(ixfmin1:ixfmax1,ix2+1,mag(2))=( (w(ixfmin1:ixfmax1,ix2-1,mag(2))+&
7952 w(ixfmin1:ixfmax1,ix2,mag(2)))*
block%surfaceC(ixfmin1:ixfmax1,ix2-1,2)&
7953 -(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))+w(ixfmin1:ixfmax1,ix2,mag(1)))*&
7954 block%surfaceC(ixfmin1:ixfmax1,ix2,1)&
7955 +(w(ixfmin1:ixfmax1,ix2,mag(1))+w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))*&
7956 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,1) )&
7957 /
block%surfaceC(ixfmin1:ixfmax1,ix2,2)-w(ixfmin1:ixfmax1,ix2,mag(2))
7971 do ix2=ixfmin2,ixfmax2
7972 w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))=w(ixfmin1:ixfmax1,&
7973 ix2-1,ixfmin3:ixfmax3,mag(2)) &
7974 -dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))-&
7975 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1))) &
7976 -dx2x3*(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))-&
7977 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))
7980 do ix2=ixfmin2,ixfmax2
7981 w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))=&
7982 ( (w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))+&
7983 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2)))*&
7984 block%surfaceC(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,2)&
7985 -(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))+&
7986 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7987 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,1)&
7988 +(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1))+&
7989 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7990 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,1)&
7991 -(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))+&
7992 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3)))*&
7993 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,3)&
7994 +(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3))+&
7995 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7996 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,3) )&
7997 /
block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,2)-&
7998 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2))
8003 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
8007 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
8017 do ix3=ixfmax3,ixfmin3,-1
8018 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))=w(ixfmin1:ixfmax1,&
8019 ixfmin2:ixfmax2,ix3+1,mag(3)) &
8020 +dx3x1*(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))-&
8021 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1))) &
8022 +dx3x2*(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))-&
8023 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))
8026 do ix3=ixfmax3,ixfmin3,-1
8027 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))=&
8028 ( (w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))+&
8029 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3)))*&
8030 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,3)&
8031 +(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))+&
8032 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1)))*&
8033 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,1)&
8034 -(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1))+&
8035 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1)))*&
8036 block%surfaceC(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,1)&
8037 +(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))+&
8038 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2)))*&
8039 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,2)&
8040 -(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2))+&
8041 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))*&
8042 block%surfaceC(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,2) )&
8043 /
block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,3)-&
8044 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3))
8048 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
8051 if(total_energy)
call eos%to_primitive(ixg^
l,ixo^
l,w,x)
8061 do ix3=ixfmin3,ixfmax3
8062 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))=w(ixfmin1:ixfmax1,&
8063 ixfmin2:ixfmax2,ix3-1,mag(3)) &
8064 -dx3x1*(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))-&
8065 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1))) &
8066 -dx3x2*(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))-&
8067 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))
8070 do ix3=ixfmin3,ixfmax3
8071 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))=&
8072 ( (w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))+&
8073 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3)))*&
8074 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,3)&
8075 -(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))+&
8076 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1)))*&
8077 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,1)&
8078 +(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1))+&
8079 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1)))*&
8080 block%surfaceC(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,1)&
8081 -(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))+&
8082 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2)))*&
8083 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,2)&
8084 +(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2))+&
8085 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))*&
8086 block%surfaceC(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,2) )&
8087 /
block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,3)-&
8088 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3))
8092 if(total_energy)
call eos%to_conserved(ixg^
l,ixo^
l,w,x)
8095 call mpistop(
"Special boundary is not defined for this region")
8098 end subroutine fixdivb_boundary
8107 double precision,
intent(in) :: qdt
8108 double precision,
intent(in) :: qt
8109 logical,
intent(inout) :: active
8112 integer,
parameter :: max_its = 50
8113 double precision :: residual_it(max_its), max_divb
8114 double precision :: tmp(ixg^t), grad(ixg^t,
ndim)
8115 double precision :: res
8116 double precision,
parameter :: max_residual = 1
d-3
8117 double precision,
parameter :: residual_reduction = 1
d-10
8118 integer :: iigrid, igrid
8119 integer :: n, nc, lvl, ix^
l, ixc^
l, idim
8122 mg%operator_type = mg_laplacian
8130 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
8131 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
8134 mg%bc(n, mg_iphi)%bc_type = mg_bc_neumann
8135 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
8137 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
8138 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
8141 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
8142 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
8146 write(*,*)
"mhd_clean_divb_multigrid warning: unknown boundary type"
8147 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
8148 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
8156 do iigrid = 1, igridstail
8157 igrid = igrids(iigrid);
8160 lvl =
mg%boxes(id)%lvl
8161 nc =
mg%box_size_lvl(lvl)
8167 call get_divb(ps(igrid)%w(ixg^t, 1:nw), ixg^
ll,
ixm^
ll, tmp, &
8169 mg%boxes(id)%cc({1:nc}, mg_irhs) = tmp(
ixm^t)
8170 max_divb = max(max_divb, maxval(abs(tmp(
ixm^t))))
8175 call mpi_allreduce(mpi_in_place, max_divb, 1, mpi_double_precision, &
8178 if (
mype == 0) print *,
"Performing multigrid divB cleaning"
8179 if (
mype == 0) print *,
"iteration vs residual"
8182 call mg_fas_fmg(
mg, n>1, max_res=residual_it(n))
8183 if (
mype == 0)
write(*,
"(I4,E11.3)") n, residual_it(n)
8184 if (residual_it(n) < residual_reduction * max_divb)
exit
8186 if (
mype == 0 .and. n > max_its)
then
8187 print *,
"divb_multigrid warning: not fully converged"
8188 print *,
"current amplitude of divb: ", residual_it(max_its)
8189 print *,
"multigrid smallest grid: ", &
8190 mg%domain_size_lvl(:,
mg%lowest_lvl)
8191 print *,
"note: smallest grid ideally has <= 8 cells"
8192 print *,
"multigrid dx/dy/dz ratio: ",
mg%dr(:, 1)/
mg%dr(1, 1)
8193 print *,
"note: dx/dy/dz should be similar"
8197 call mg_fas_vcycle(
mg, max_res=res)
8198 if (res < max_residual)
exit
8200 if (res > max_residual)
call mpistop(
"divb_multigrid: no convergence")
8205 do iigrid = 1, igridstail
8206 igrid = igrids(iigrid);
8215 tmp(ix^s) =
mg%boxes(id)%cc({:,}, mg_iphi)
8219 ixcmin^
d=ixmlo^
d-
kr(idim,^
d);
8221 call gradientf(tmp,ps(igrid)%x,ixg^
ll,ixc^
l,idim,grad(ixg^t,idim))
8223 ps(igrid)%ws(ixc^s,idim)=ps(igrid)%ws(ixc^s,idim)-grad(ixc^s,idim)
8236 ps(igrid)%w(
ixm^t, mag(1:
ndim)) = &
8237 ps(igrid)%w(
ixm^t, mag(1:
ndim)) - grad(
ixm^t, :)
8240 if(total_energy)
then
8242 tmp(
ixm^t) = 0.5_dp * (sum(ps(igrid)%w(
ixm^t, &
8245 ps(igrid)%w(
ixm^t,
e_) = ps(igrid)%w(
ixm^t,
e_) + tmp(
ixm^t)
8255 subroutine mhd_update_faces_average(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
8259 integer,
intent(in) :: ixi^
l, ixo^
l
8260 double precision,
intent(in) :: qt,qdt
8262 double precision,
intent(in) :: wp(ixi^s,1:nw)
8263 type(state) :: sct, s
8264 type(ct_velocity) :: vcts
8265 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
8266 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
8268 double precision :: circ(ixi^s,1:
ndim)
8270 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
8271 integer :: ix^
d,ixc^
l,ixa^
l,i1kr^
d,i2kr^
d
8272 integer :: idim1,idim2,idir,iwdim1,iwdim2
8274 associate(bfaces=>s%ws,x=>s%x)
8281 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
8288 i1kr^
d=
kr(idim1,^
d);
8291 i2kr^
d=
kr(idim2,^
d);
8294 if (
lvc(idim1,idim2,idir)==1)
then
8296 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8298 {
do ix^db=ixcmin^db,ixcmax^db\}
8299 fe(ix^
d,idir)=quarter*&
8300 (fc(ix^
d,iwdim1,idim2)+fc({ix^
d+i1kr^
d},iwdim1,idim2)&
8301 -fc(ix^
d,iwdim2,idim1)-fc({ix^
d+i2kr^
d},iwdim2,idim1))
8303 if(
mhd_eta/=zero) fe(ix^
d,idir)=fe(ix^
d,idir)+e_resi(ix^
d,idir)
8308 fe(ix^
d,idir)=fe(ix^
d,idir)*qdt*s%dsC(ix^
d,idir)
8316 if(
associated(usr_set_electric_field)) &
8317 call usr_set_electric_field(ixi^l,ixo^l,qt,qdt,fe,sct)
8319 circ(ixi^s,1:ndim)=zero
8324 ixcmin^d=ixomin^d-kr(idim1,^d);
8326 ixa^l=ixc^l-kr(idim2,^d);
8329 if(lvc(idim1,idim2,idir)==1)
then
8331 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8334 else if(lvc(idim1,idim2,idir)==-1)
then
8336 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8342 {
do ix^db=ixcmin^db,ixcmax^db\}
8344 if(s%surfaceC(ix^d,idim1) > smalldouble)
then
8346 bfaces(ix^d,idim1)=bfaces(ix^d,idim1)-circ(ix^d,idim1)/s%surfaceC(ix^d,idim1)
8353 end subroutine mhd_update_faces_average
8356 subroutine mhd_update_faces_contact(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
8361 integer,
intent(in) :: ixi^
l, ixo^
l
8362 double precision,
intent(in) :: qt, qdt
8364 double precision,
intent(in) :: wp(ixi^s,1:nw)
8365 type(state) :: sct, s
8366 type(ct_velocity) :: vcts
8367 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
8368 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
8370 double precision :: circ(ixi^s,1:
ndim)
8372 double precision :: ecc(ixi^s,
sdim:3)
8373 double precision :: ein(ixi^s,
sdim:3)
8375 double precision :: el(ixi^s),er(ixi^s)
8377 double precision :: elc,erc
8379 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
8381 double precision :: jce(ixi^s,
sdim:3)
8383 double precision :: xs(ixgs^t,1:
ndim)
8384 double precision :: gradi(ixgs^t)
8385 double precision :: resis_heat
8386 integer :: ixc^
l,ixa^
l
8387 integer :: idim1,idim2,idir,iwdim1,iwdim2,ix^
d,i1kr^
d,i2kr^
d
8389 associate(bfaces=>s%ws,x=>s%x,w=>s%w,vnorm=>vcts%vnorm,wcts=>sct%ws)
8392 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
8398 {
do ix^db=iximin^db,iximax^db\}
8401 ecc(ix^
d,1)=(wp(ix^
d,b2_)+
block%B0(ix^
d,2,0))*wp(ix^
d,m3_)-(wp(ix^
d,b3_)+
block%B0(ix^
d,3,0))*wp(ix^
d,m2_)
8402 ecc(ix^
d,2)=(wp(ix^
d,b3_)+
block%B0(ix^
d,3,0))*wp(ix^
d,m1_)-(wp(ix^
d,b1_)+
block%B0(ix^
d,1,0))*wp(ix^
d,m3_)
8403 ecc(ix^
d,3)=(wp(ix^
d,b1_)+
block%B0(ix^
d,1,0))*wp(ix^
d,m2_)-(wp(ix^
d,b2_)+
block%B0(ix^
d,2,0))*wp(ix^
d,m1_)
8406 ecc(ix^
d,3)=(wp(ix^
d,b1_)+
block%B0(ix^
d,1,0))*wp(ix^
d,m2_) &
8407 -(wp(ix^
d,b2_)+
block%B0(ix^
d,2,0))*wp(ix^
d,m1_)
8414 {
do ix^db=iximin^db,iximax^db\}
8417 ecc(ix^d,1)=wp(ix^d,b2_)*wp(ix^d,m3_)-wp(ix^d,b3_)*wp(ix^d,m2_)
8418 ecc(ix^d,2)=wp(ix^d,b3_)*wp(ix^d,m1_)-wp(ix^d,b1_)*wp(ix^d,m3_)
8419 ecc(ix^d,3)=wp(ix^d,b1_)*wp(ix^d,m2_)-wp(ix^d,b2_)*wp(ix^d,m1_)
8422 ecc(ix^d,3)=wp(ix^d,b1_)*wp(ix^d,m2_)-wp(ix^d,b2_)*wp(ix^d,m1_)
8436 i1kr^d=kr(idim1,^d);
8439 i2kr^d=kr(idim2,^d);
8442 if (lvc(idim1,idim2,idir)==1)
then
8444 ixcmin^d=ixomin^d+kr(idir,^d)-1;
8447 {
do ix^db=ixcmin^db,ixcmax^db\}
8448 fe(ix^d,idir)=quarter*&
8449 (fc(ix^d,iwdim1,idim2)+fc({ix^d+i1kr^d},iwdim1,idim2)&
8450 -fc(ix^d,iwdim2,idim1)-fc({ix^d+i2kr^d},iwdim2,idim1))
8455 ixamax^d=ixcmax^d+i1kr^d;
8456 {
do ix^db=ixamin^db,ixamax^db\}
8457 el(ix^d)=fc(ix^d,iwdim1,idim2)-ecc(ix^d,idir)
8458 er(ix^d)=fc(ix^d,iwdim1,idim2)-ecc({ix^d+i2kr^d},idir)
8461 do ix^db=ixcmin^db,ixcmax^db\}
8462 if(vnorm(ix^d,idim1)>0.d0)
then
8464 else if(vnorm(ix^d,idim1)<0.d0)
then
8465 elc=el({ix^d+i1kr^d})
8467 elc=0.5d0*(el(ix^d)+el({ix^d+i1kr^d}))
8469 if(vnorm({ix^d+i2kr^d},idim1)>0.d0)
then
8471 else if(vnorm({ix^d+i2kr^d},idim1)<0.d0)
then
8472 erc=er({ix^d+i1kr^d})
8474 erc=0.5d0*(er(ix^d)+er({ix^d+i1kr^d}))
8476 fe(ix^d,idir)=fe(ix^d,idir)+0.25d0*(elc+erc)
8481 ixamax^d=ixcmax^d+i2kr^d;
8482 {
do ix^db=ixamin^db,ixamax^db\}
8483 el(ix^d)=-fc(ix^d,iwdim2,idim1)-ecc(ix^d,idir)
8484 er(ix^d)=-fc(ix^d,iwdim2,idim1)-ecc({ix^d+i1kr^d},idir)
8487 do ix^db=ixcmin^db,ixcmax^db\}
8488 if(vnorm(ix^d,idim2)>0.d0)
then
8490 else if(vnorm(ix^d,idim2)<0.d0)
then
8491 elc=el({ix^d+i2kr^d})
8493 elc=0.5d0*(el(ix^d)+el({ix^d+i2kr^d}))
8495 if(vnorm({ix^d+i1kr^d},idim2)>0.d0)
then
8497 else if(vnorm({ix^d+i1kr^d},idim2)<0.d0)
then
8498 erc=er({ix^d+i2kr^d})
8500 erc=0.5d0*(er(ix^d)+er({ix^d+i2kr^d}))
8502 fe(ix^d,idir)=fe(ix^d,idir)+0.25d0*(elc+erc)
8506 if(
mhd_eta/=zero) fe(ix^d,idir)=fe(ix^d,idir)+e_resi(ix^d,idir)
8511 fe(ix^d,idir)=fe(ix^d,idir)*qdt*s%dsC(ix^d,idir)
8525 if (lvc(idim1,idim2,idir)==0) cycle
8527 ixcmin^d=ixomin^d+kr(idir,^d)-1;
8528 ixamax^d=ixcmax^d-kr(idir,^d)+1;
8531 xs(ixa^s,:)=x(ixa^s,:)
8532 xs(ixa^s,idim2)=x(ixa^s,idim2)+half*s%dx(ixa^s,idim2)
8533 call gradientf(wcts(ixgs^t,idim2),xs,ixgs^ll,ixc^l,idim1,gradi)
8534 if (lvc(idim1,idim2,idir)==1)
then
8535 jce(ixc^s,idir)=jce(ixc^s,idir)+gradi(ixc^s)
8537 jce(ixc^s,idir)=jce(ixc^s,idir)-gradi(ixc^s)
8543 {
do ix^db=ixomin^db,ixomax^db\}
8544 resis_heat=0.25d0*(ein(ix^d,1)*jce(ix^d,1)+ein(ix1,ix2-1,ix3,1)*jce(ix1,ix2-1,ix3,1)&
8545 +ein(ix1,ix2,ix3-1,1)*jce(ix1,ix2,ix3-1,1)+ein(ix1,ix2-1,ix3-1,1)*jce(ix1,ix2-1,ix3-1,1))&
8546 +0.25d0*(ein(ix^d,2)*jce(ix^d,2)+ein(ix1-1,ix2,ix3,2)*jce(ix1-1,ix2,ix3,2)&
8547 +ein(ix1,ix2,ix3-1,2)*jce(ix1,ix2,ix3-1,2)+ein(ix1-1,ix2,ix3-1,2)*jce(ix1-1,ix2,ix3-1,2))&
8548 +0.25d0*(ein(ix^d,3)*jce(ix^d,3)+ein(ix1-1,ix2,ix3,3)*jce(ix1-1,ix2,ix3,3)&
8549 +ein(ix1,ix2-1,ix3,3)*jce(ix1,ix2-1,ix3,3)+ein(ix1-1,ix2-1,ix3,3)*jce(ix1-1,ix2-1,ix3,3))
8550 if(resis_heat<0.d0) resis_heat=0.d0
8551 w(ix^d,
e_)=w(ix^d,
e_)+qdt*resis_heat
8556 {
do ix^db=ixomin^db,ixomax^db\}
8557 resis_heat=0.25d0*(ein(ix^d,3)*jce(ix^d,3)+ein(ix1-1,ix2,3)*jce(ix1-1,ix2,3)&
8558 +ein(ix1,ix2-1,3)*jce(ix1,ix2-1,3)+ein(ix1-1,ix2-1,3)*jce(ix1-1,ix2-1,3))
8559 if(resis_heat<0.d0) resis_heat=0.d0
8560 w(ix^d,
e_)=w(ix^d,
e_)+qdt*resis_heat
8567 if(
associated(usr_set_electric_field)) &
8568 call usr_set_electric_field(ixi^l,ixo^l,qt,qdt,fe,sct)
8570 circ(ixi^s,1:ndim)=zero
8575 ixcmin^d=ixomin^d-kr(idim1,^d);
8577 ixa^l=ixc^l-kr(idim2,^d);
8580 if(lvc(idim1,idim2,idir)==1)
then
8582 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8585 else if(lvc(idim1,idim2,idir)==-1)
then
8587 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8593 {
do ix^db=ixcmin^db,ixcmax^db\}
8595 if(s%surfaceC(ix^d,idim1) > smalldouble)
then
8597 bfaces(ix^d,idim1)=bfaces(ix^d,idim1)-circ(ix^d,idim1)/s%surfaceC(ix^d,idim1)
8604 end subroutine mhd_update_faces_contact
8607 subroutine mhd_update_faces_hll(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
8612 integer,
intent(in) :: ixi^
l, ixo^
l
8613 double precision,
intent(in) :: qt, qdt
8615 double precision,
intent(in) :: wp(ixi^s,1:nw)
8616 type(state) :: sct, s
8617 type(ct_velocity) :: vcts
8618 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
8619 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
8621 double precision :: vtill(ixi^s,2)
8622 double precision :: vtilr(ixi^s,2)
8623 double precision :: bfacetot(ixi^s,
ndim)
8624 double precision :: btill(ixi^s,
ndim)
8625 double precision :: btilr(ixi^s,
ndim)
8626 double precision :: cp(ixi^s,2)
8627 double precision :: cm(ixi^s,2)
8628 double precision :: circ(ixi^s,1:
ndim)
8630 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
8631 integer :: hxc^
l,ixc^
l,ixcp^
l,jxc^
l,ixcm^
l
8632 integer :: idim1,idim2,idir,ix^
d
8634 associate(bfaces=>s%ws,bfacesct=>sct%ws,x=>s%x,vbarc=>vcts%vbarC,cbarmin=>vcts%cbarmin,&
8635 cbarmax=>vcts%cbarmax)
8648 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
8664 ixcmin^
d=ixomin^
d-1+
kr(idir,^
d);
8668 idim2=mod(idir+1,3)+1
8670 jxc^
l=ixc^
l+
kr(idim1,^
d);
8671 ixcp^
l=ixc^
l+
kr(idim2,^
d);
8675 vtill(ixi^s,2),vtilr(ixi^s,2))
8678 vtill(ixi^s,1),vtilr(ixi^s,1))
8684 bfacetot(ixi^s,idim1)=bfacesct(ixi^s,idim1)+
block%B0(ixi^s,idim1,idim1)
8685 bfacetot(ixi^s,idim2)=bfacesct(ixi^s,idim2)+
block%B0(ixi^s,idim2,idim2)
8687 bfacetot(ixi^s,idim1)=bfacesct(ixi^s,idim1)
8688 bfacetot(ixi^s,idim2)=bfacesct(ixi^s,idim2)
8691 btill(ixi^s,idim1),btilr(ixi^s,idim1))
8694 btill(ixi^s,idim2),btilr(ixi^s,idim2))
8698 cm(ixc^s,1)=max(cbarmin(ixcp^s,idim1),cbarmin(ixc^s,idim1))
8699 cp(ixc^s,1)=max(cbarmax(ixcp^s,idim1),cbarmax(ixc^s,idim1))
8701 cm(ixc^s,2)=max(cbarmin(jxc^s,idim2),cbarmin(ixc^s,idim2))
8702 cp(ixc^s,2)=max(cbarmax(jxc^s,idim2),cbarmax(ixc^s,idim2))
8706 fe(ixc^s,idir)=-(cp(ixc^s,1)*vtill(ixc^s,1)*btill(ixc^s,idim2) &
8707 + cm(ixc^s,1)*vtilr(ixc^s,1)*btilr(ixc^s,idim2) &
8708 - cp(ixc^s,1)*cm(ixc^s,1)*(btilr(ixc^s,idim2)-btill(ixc^s,idim2)))&
8709 /(cp(ixc^s,1)+cm(ixc^s,1)) &
8710 +(cp(ixc^s,2)*vtill(ixc^s,2)*btill(ixc^s,idim1) &
8711 + cm(ixc^s,2)*vtilr(ixc^s,2)*btilr(ixc^s,idim1) &
8712 - cp(ixc^s,2)*cm(ixc^s,2)*(btilr(ixc^s,idim1)-btill(ixc^s,idim1)))&
8713 /(cp(ixc^s,2)+cm(ixc^s,2))
8716 if(
mhd_eta/=zero) fe(ixc^s,idir)=fe(ixc^s,idir)+e_resi(ixc^s,idir)
8720 fe(ixc^s,idir)=qdt*s%dsC(ixc^s,idir)*fe(ixc^s,idir)
8734 circ(ixi^s,1:
ndim)=zero
8739 ixcmin^
d=ixomin^
d-
kr(idim1,^
d);
8743 if(
lvc(idim1,idim2,idir)/=0)
then
8744 hxc^
l=ixc^
l-
kr(idim2,^
d);
8746 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8747 +
lvc(idim1,idim2,idir)&
8753 {
do ix^db=ixcmin^db,ixcmax^db\}
8755 if(s%surfaceC(ix^
d,idim1) > smalldouble)
then
8757 bfaces(ix^
d,idim1)=bfaces(ix^
d,idim1)-circ(ix^
d,idim1)/s%surfaceC(ix^
d,idim1)
8763 end subroutine mhd_update_faces_hll
8766 subroutine get_resistive_electric_field(ixI^L,ixO^L,wp,sCT,s,jce)
8771 integer,
intent(in) :: ixi^
l, ixo^
l
8773 double precision,
intent(in) :: wp(ixi^s,1:nw)
8774 type(state),
intent(in) :: sct, s
8776 double precision :: jce(ixi^s,
sdim:3)
8779 double precision :: jcc(ixi^s,7-2*
ndir:3)
8781 double precision :: xs(ixgs^t,1:
ndim)
8783 double precision :: eta(ixi^s)
8784 double precision :: gradi(ixgs^t)
8785 integer :: ix^
d,ixc^
l,ixa^
l,ixb^
l,idir,idirmin,idim1,idim2
8787 associate(x=>s%x,
dx=>s%dx,w=>s%w,wct=>sct%w,wcts=>sct%ws)
8793 if (
lvc(idim1,idim2,idir)==0) cycle
8795 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8796 ixbmax^
d=ixcmax^
d-
kr(idir,^
d)+1;
8799 xs(ixb^s,:)=x(ixb^s,:)
8800 xs(ixb^s,idim2)=x(ixb^s,idim2)+half*
dx(ixb^s,idim2)
8801 call gradientf(wcts(ixgs^t,idim2),xs,ixgs^
ll,ixc^
l,idim1,gradi,2)
8802 if (
lvc(idim1,idim2,idir)==1)
then
8803 jce(ixc^s,idir)=jce(ixc^s,idir)+gradi(ixc^s)
8805 jce(ixc^s,idir)=jce(ixc^s,idir)-gradi(ixc^s)
8812 jce(ixi^s,:)=jce(ixi^s,:)*
mhd_eta
8820 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8821 jcc(ixc^s,idir)=0.d0
8823 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
8824 ixamin^
d=ixcmin^
d+ix^
d;
8825 ixamax^
d=ixcmax^
d+ix^
d;
8826 jcc(ixc^s,idir)=jcc(ixc^s,idir)+eta(ixa^s)
8828 jcc(ixc^s,idir)=jcc(ixc^s,idir)*0.25d0
8829 jce(ixc^s,idir)=jce(ixc^s,idir)*jcc(ixc^s,idir)
8834 end subroutine get_resistive_electric_field
8837 subroutine get_ambipolar_electric_field(ixI^L,ixO^L,w,x,fE)
8840 integer,
intent(in) :: ixi^
l, ixo^
l
8841 double precision,
intent(in) :: w(ixi^s,1:nw)
8842 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8843 double precision,
intent(out) :: fe(ixi^s,
sdim:3)
8845 double precision :: jxbxb(ixi^s,1:3)
8846 integer :: idir,ixa^
l,ixc^
l,ix^
d
8849 call mhd_get_jxbxb(w,x,ixi^
l,ixa^
l,jxbxb)
8856 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8859 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
8860 ixamin^
d=ixcmin^
d+ix^
d;
8861 ixamax^
d=ixcmax^
d+ix^
d;
8862 fe(ixc^s,idir)=fe(ixc^s,idir)+jxbxb(ixa^s,idir)
8864 fe(ixc^s,idir)=fe(ixc^s,idir)*0.25d0
8867 end subroutine get_ambipolar_electric_field
8873 integer,
intent(in) :: ixo^
l
8883 do ix^db=ixomin^db,ixomax^db\}
8885 s%w(ix^
d,b1_)=half/s%surface(ix^
d,1)*(s%ws(ix^
d,1)*s%surfaceC(ix^
d,1)&
8886 +s%ws(ix1-1,ix2,ix3,1)*s%surfaceC(ix1-1,ix2,ix3,1))
8887 s%w(ix^
d,b2_)=half/s%surface(ix^
d,2)*(s%ws(ix^
d,2)*s%surfaceC(ix^
d,2)&
8888 +s%ws(ix1,ix2-1,ix3,2)*s%surfaceC(ix1,ix2-1,ix3,2))
8889 s%w(ix^
d,b3_)=half/s%surface(ix^
d,3)*(s%ws(ix^
d,3)*s%surfaceC(ix^
d,3)&
8890 +s%ws(ix1,ix2,ix3-1,3)*s%surfaceC(ix1,ix2,ix3-1,3))
8893 s%w(ix^
d,b1_)=half/s%surface(ix^
d,1)*(s%ws(ix^
d,1)*s%surfaceC(ix^
d,1)&
8894 +s%ws(ix1-1,ix2,1)*s%surfaceC(ix1-1,ix2,1))
8895 s%w(ix^
d,b2_)=half/s%surface(ix^
d,2)*(s%ws(ix^
d,2)*s%surfaceC(ix^
d,2)&
8896 +s%ws(ix1,ix2-1,2)*s%surfaceC(ix1,ix2-1,2))
8939 integer,
intent(in) :: ixis^
l, ixi^
l, ixo^
l
8940 double precision,
intent(inout) :: ws(ixis^s,1:nws)
8941 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8943 double precision :: adummy(ixis^s,1:3)
8949 subroutine get_hd_mom_flux(wC,w,x,ixI^L,ixO^L,idim,f)
8952 integer,
intent(in) :: ixi^
l, ixo^
l, idim
8954 double precision,
intent(in) :: wc(ixi^s,nw)
8956 double precision,
intent(in) :: w(ixi^s,nw)
8957 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8958 double precision,
intent(out) :: f(ixi^s,1:
ndir)
8962 {
do ix^db=ixomin^db,ixomax^db\}
8966 f(ix^
d,idim)=f(ix^
d,idim)+w(ix^
d,
p_)
8969 end subroutine get_hd_mom_flux
8971 subroutine get_hd_mom_flux_noe(wC,w,x,ixI^L,ixO^L,idim,f)
8975 integer,
intent(in) :: ixi^
l, ixo^
l, idim
8977 double precision,
intent(in) :: wc(ixi^s,nw)
8979 double precision,
intent(in) :: w(ixi^s,nw)
8980 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8981 double precision,
intent(out) :: f(ixi^s,1:
ndir)
8983 double precision :: adiabs(ixi^s), gammas(ixi^s)
8997 {
do ix^db=ixomin^db,ixomax^db\}
9001 f(ix^
d,idim)=f(ix^
d,idim)+adiabs(ix^
d)*w(ix^
d,
rho_)**gammas(ix^
d)
9004 end subroutine get_hd_mom_flux_noe
Module to include CAK radiation line force in (magneto)hydrodynamic models Computes both the force fr...
subroutine, public cak_add_source(qdt, ixil, ixol, wct, w, x, energy, qsourcesplit, active)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
subroutine, public cak_get_dt(wprim, ixil, ixol, dtnew, dxd, x)
Check time step for total radiation contribution.
subroutine, public cak_init(phys_gamma)
Initialize the module.
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Module for physical and numeric constants.
double precision, parameter bigdouble
A very large real number.
double precision, parameter zero
some frequently used numbers
subroutine reconstruct(ixil, ixcl, idir, q, ql, qr)
Reconstruct scalar q within ixO^L to 1/2 dx in direction idir Return both left and right reconstructe...
subroutine b_from_vector_potentiala(ixisl, ixil, ixol, ws, x, a)
calculate magnetic field from vector potential A at cell edges
subroutine add_convert_method(phys_convert_vars, nwc, dataset_names, file_suffix)
EoS state container – the single thermodynamic authority for AMRVAC.
integer, parameter, public eos_type_pi
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
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 lte_p_from_eint(eint_val, nh_val, log_nh_val, inv_rho)
LTE pressure from internal energy in one cell: ideal without ionE, else the table floor,...
PI (partial-ionisation) ionisation-degree backend for the eos% family.
PI (partial-ionisation, eos_type='PI') arm of the eos% family.
subroutine, public eint_from_rho_p_pi(rho, p, eint)
Primitive pressure -> GAS internal energy (prim -> conserved direction): invert (rho,...
subroutine, public state_from_eint_pi(rho, eint, t, p, rfactor, iz_h, iz_he)
Conserved gas internal energy -> temperature, thermal pressure, R. Inverse of p_eint_from_rho_T_PI....
Equation of state for AMRVAC, handled through a single eos_container object.
Module for flux conservation near refinement boundaries.
subroutine, public store_flux(igrid, fc, idimlim, nwfluxin)
subroutine, public store_edge(igrid, ixil, fe, idimlim)
Module for flux limited diffusion (FLD)-approximation in Radiation-(Magneto)hydrodynamics simulations...
double precision, public fld_bisect_tol
Tolerance for bisection method for Energy sourceterms This is a percentage of the minimum of gas- and...
subroutine, public fld_radforce_get_dt(w, ixil, ixol, dtnew, dxd, x, fl)
get dt limit for radiation force and FLD explicit source additions NOTE: w is primitive on entry
double precision, public fld_diff_tol
Tolerance for radiative Energy diffusion.
character(len=40) fld_fluxlimiter
flux limiter choice
character(len=40) fld_opal_table
double precision, public fld_cnorm
double precision, public fld_kappa0
Opacity value when using constant opacity.
subroutine, public add_fld_rad_force(qdt, ixil, ixol, wct, wctprim, w, x, qsourcesplit, active, fl)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO This subroutine handles th...
character(len=40) fld_opacity_law
switches for opacity
character(len=40) fld_interaction_method
Which method to find the root for the energy interaction polynomial.
subroutine, public fld_get_radpress(w, x, ixil, ixol, rad_pressure, fl)
Returns Radiation Pressure as tensor NOTE: w is primitive on entry.
logical fld_radforce_split
source split for energy interact and radforce:
logical fld_bound_diff
switches for using changed cmax-cmin bounds
subroutine, public fld_implicit_update(dtfactor, qdt, qtc, psa, psb, fl)
Calling all subroutines to perform the multigrid method Communicates rad_e and diff_coeff to multigri...
subroutine, public fld_evaluate_implicit(qtc, psa, fl)
inplace update of psa==>F_im(psa)
subroutine, public fld_init(gas_eos_type, gas_ion_energy, gas_pi_table)
Initialising FLD-module Read opacities Initialise Multigrid and adimensionalise kappa.
integer nth_for_diff_mg
diffusion coefficient stencil control
Module with basic grid data structures.
type(tree_node_ptr), dimension(:,:), allocatable, save igrid_to_node
Array to go from an [igrid, ipe] index to a node pointer.
subroutine, public get_divb(w, ixil, ixol, divb, nth_in)
Calculate div B within ixO.
integer, dimension(:), allocatable, public mag
Indices of the magnetic field.
Module with geometry-related routines (e.g., divergence, curl).
subroutine divvector(qvec, ixil, ixol, divq, nth_in)
integer, parameter cartesian
subroutine laplacian_of_vector(qvec, ixil, ixol, lapl_qvec)
integer, parameter cylindrical
subroutine curlvector(qvec, ixil, ixol, curlvec, idirmin, idirmin0, ndir0, fourthorder)
Calculate curl of a vector qvec within ixL Options to employ standard second order CD evaluations use...
subroutine gradient(q, ixil, ixol, idir, gradq, nth_in)
subroutine gradientf(q, x, ixil, ixol, idir, gradq, nth_in, pm_in)
subroutine gradientl(q, ixil, ixol, idir, gradq)
This module contains definitions of global parameters and variables and some generic functions/subrou...
type(state), pointer block
Block pointer for using one block and its previous state.
logical h_correction
If true, do H-correction to fix the carbuncle problem at grid-aligned shocks.
double precision const_kappae
double precision arad_norm
Normalised radiation constant.
double precision dtdiffpar
For resistive MHD, the time step is also limited by the diffusion time: .
character(len=std_len) typegrad
double precision unit_charge
Physical scaling factor for charge.
double precision small_pressure
integer ixghi
Upper index of grid block arrays.
pure subroutine cross_product(ixil, ixol, a, b, axb)
Cross product of two vectors.
integer, dimension(3, 3, 3) lvc
Levi-Civita tensor.
double precision unit_time
Physical scaling factor for time.
logical b0fieldalloccoarse
double precision unit_density
Physical scaling factor for density.
double precision unit_opacity
Physical scaling factor for Opacity.
integer, parameter unitpar
file handle for IO
integer, parameter bc_asymm
double precision unit_mass
Physical scaling factor for mass.
logical use_imex_scheme
whether IMEX in use or not
integer, dimension(3, 3) kr
Kronecker delta tensor.
double precision phys_trac_mask
integer, dimension(:, :), allocatable typeboundary
Array indicating the type of boundary condition per variable and per physical boundary.
double precision unit_numberdensity
Physical scaling factor for number density.
integer, parameter fs_hllcd
character(len=std_len) convert_type
Which format to use when converting.
double precision unit_pressure
Physical scaling factor for pressure.
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision unit_length
Physical scaling factor for length.
logical stagger_grid
True for using stagger grid.
double precision const_rad_a
Physical factors useful for radiation fld.
double precision cmax_global
global fastest wave speed needed in fd scheme and glm method
logical use_particles
Use particles module or not.
integer, parameter fs_tvdmu
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
integer icomm
The MPI communicator.
double precision bdip
amplitude of background dipolar, quadrupolar, octupolar, user's field
integer b0i
background magnetic field location indicator
integer mype
The rank of the current MPI task.
logical local_timestep
each cell has its own timestep or not
integer ndir
Number of spatial dimensions (components) for vector variables.
integer ixm
the mesh range of a physical block without ghost cells
integer ierrmpi
A global MPI error return code.
logical autoconvert
If true, already convert to output format during the run.
integer, dimension(:), allocatable flux_method
Which flux scheme of spatial discretization to use (per grid level).
double precision, dimension(:), allocatable, parameter d
logical slab
Cartesian geometry or not.
integer, parameter bc_periodic
integer, parameter bc_special
boundary condition types
double precision unit_magneticfield
Physical scaling factor for magnetic field.
double precision const_sigmasb
integer nwauxio
Number of auxiliary variables that are only included in output.
double precision unit_velocity
Physical scaling factor for velocity.
double precision small_r_e
double precision c_norm
Normalised speed of light.
logical b0field
split magnetic field as background B0 field
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
double precision unit_temperature
Physical scaling factor for temperature.
double precision unit_radflux
Physical scaling factor for radiation flux.
integer, parameter bc_cont
logical si_unit
Use SI units (.true.) or use cgs units (.false.).
double precision, dimension(:,:), allocatable dx
spatial steps for all dimensions at all levels
integer nghostcells
Number of ghost cells surrounding a grid.
integer, parameter sdim
starting dimension for electric field
integer, parameter bc_symm
logical phys_trac
Use TRAC for MHD or 1D HD.
logical need_global_cmax
need global maximal wave speed
logical convert
If true and restart_from_file is given, convert snapshots to other file formats.
logical fix_small_values
fix small values with average or replace methods
double precision, dimension(^nd) dxlevel
store unstretched cell size of current level
logical use_multigrid
Use multigrid (only available in 2D and 3D).
logical slab_uniform
uniform Cartesian geometry or not (stretched Cartesian)
double precision small_density
integer, parameter fs_hllc
integer max_blocks
The maximum number of grid blocks in a processor.
integer r_
Indices for cylindrical coordinates FOR TESTS, negative value when not used:
integer boundspeed
bound (left/min and right.max) speed of Riemann fan
integer phys_trac_finegrid
integer, parameter unitconvert
double precision unit_erad
Physical scaling factor for radiation energy density.
integer number_equi_vars
number of equilibrium set variables, besides the mag field
integer, parameter ixglo
Lower index of grid block arrays (always 1).
Module for including gravity in (magneto)hydrodynamics simulations.
subroutine gravity_get_dt(wprim, ixil, ixol, dtnew, dxd, x)
subroutine gravity_init()
Initialize the module.
subroutine gravity_add_source(qdt, ixil, ixol, wct, wctprim, w, x, energy, qsourcesplit, active)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
module mod_magnetofriction.t Purpose: use magnetofrictional method to relax 3D magnetic field to forc...
subroutine magnetofriction_init()
Initialize the module.
Magneto-hydrodynamics module.
subroutine, public mhd_get_trad(w, x, ixil, ixol, trad)
Calculates radiation temperature.
integer, public, protected c_
logical, public, protected mhd_gravity
Whether gravity is added.
integer, public, protected fip_
Index of the FIP passive scalar rho*fip in conserved form, fip in primitive form.
logical, public, protected mhd_internal_e
Whether internal energy is solved instead of total energy.
double precision, public, protected mhd_trac_delta
TRAC-7 (Johnston 2021, A&A 654 A2): target number of cells resolving the TR.
logical, public, protected mhd_glm_extended
Whether extended GLM-MHD is used with additional sources.
logical, public mhd_hyperbolic_tc_constant
character(len=std_len), public, protected type_ct
Method type of constrained transport.
integer, dimension(:), allocatable, public, protected mom
Indices of the momentum density.
subroutine, public mhd_clean_divb_multigrid(qdt, qt, active)
integer, public, protected qpar_
Index of the field-aligned heat flux q_parallel.
logical, public, protected mhd_radiative_cooling
Whether radiative cooling is added.
subroutine, public mhd_e_to_ei(ixil, ixol, w, x)
Transform total energy to internal energy.
double precision, public mhd_adiab
The adiabatic constant.
double precision, public divbdiff
Coefficient of diffusive divB cleaning.
double precision, public mhd_eta_hyper
The MHD hyper-resistivity.
character(len=std_len), public, protected mhd_uawsom_reflection_mode
Algebra used by the Alfven-wave reflection source. one_dimensional_gradient retains the original one-...
double precision, public, protected mhd_hyperbolic_tc_bmin
Field-strength transition scale for perpendicular closure.
double precision, public, protected rr
double precision, public, protected h_ion_fr
Ionization fraction of H H_ion_fr = H+/(H+ + H).
double precision, public, protected mhd_uawsom_sigma
Dimensionless multiplier in the one_dimensional_gradient source only.
integer, public, protected mhd_trac_finegrid
Distance between two adjacent traced magnetic field lines (in finest cell size).
integer, public, protected wkminus_
double precision, public, protected mhd_uawsom_thread_radius0
double precision function, public mhd_semirelati_eint(p, rho)
Internal energy from thermal pressure in one cell, the inverse of mhd_semirelati_p.
subroutine, public get_normalized_divb(w, ixil, ixol, divb)
get dimensionless div B = |divB| * volume / area / |B|
integer, public, protected mhd_uawsom_height_dim
Enable conservative kink-wave reflection from the kink-speed gradient Cartesian direction used for th...
logical, public numerical_resistive_heating
Whether numerical resistive heating is included when solving partial energy equation.
type(tc_fluid), allocatable, public tc_fl
type of fluid for thermal conduction
logical, public, protected mhd_hd_mom_conserve_fix
exclude Maxwell stress flux from momentum flux (use hydrodynamic momentum flux) for conservation fix ...
logical, public, protected mhd_rotating_frame
Whether rotating frame is activated.
logical, public, protected mhd_semirelativistic
Whether semirelativistic MHD equations (Gombosi 2002 JCP) are solved.
integer, public, protected mhd_divb_nth
Whether divB is computed with a fourth order approximation.
integer, public, protected mhd_n_tracer
Number of tracer species.
integer, public, protected te_
Indices of temperature.
integer, public, protected m
integer, public equi_rho0_
equi vars indices in the stateequi_vars array
integer, public, protected mhd_trac_type
Which TRAC method is used.
logical, public, protected mhd_cak_force
Whether plasma is partially ionized Whether CAK radiation line force is activated.
logical, public, protected source_split_divb
Whether divB cleaning sources are added splitting from fluid solver.
double precision, public, protected mhd_uawsom_zeta0
Base transverse density contrast and filling factor.
integer, public, protected ne_
Index of the electron number density for LTE module.
logical, public, protected mhd_hall
Whether Hall-MHD is used.
type(te_fluid), allocatable, public te_fl_mhd
type of fluid for thermal emission synthesis
logical, public, protected mhd_ambipolar
Whether Ambipolar term is used.
logical, public, protected mhd_hyperbolic_tc
Whether thermal conduction is used.
logical, public, protected mhd_hyperbolic_tc_sat
Whether saturation is considered for hyperbolic TC. When the perpendicular channel is active,...
double precision, public, protected mhd_hyperbolic_tc_kappa_perp_factor
Relative perpendicular hyperbolic-TC coefficient in fixed/strong-field limit: kappa_perp0 = mhd_hyper...
logical, public has_equi_rho_and_p
whether split off equilibrium density and pressure
double precision, public mhd_glm_alpha
GLM-MHD parameter: ratio of the diffusive and advective time scales for div b taking values within [0...
double precision function, dimension(ixo^s), public mhd_mag_en_all(w, ixil, ixol)
Compute 2 times total magnetic energy.
pure double precision function, public mhd_uawsom_wave_energy_cell(wcell)
logical, public, protected mhd_radiation_fld
Whether radiation-gas interaction is handled using flux limited diffusion.
subroutine, public multiplyambicoef(ixil, ixol, res, w, x)
multiply res by the ambipolar coefficient The ambipolar coefficient is calculated as -mhd_eta_ambi/rh...
subroutine, public b_from_vector_potential(ixisl, ixil, ixol, ws, x)
calculate magnetic field from vector potential
double precision, public, protected he_ion_fr
Ionization fraction of He He_ion_fr = (He2+ + He+)/(He2+ + He+ + He).
double precision, public, protected mhd_squared_c
squared reduced speed of light c
integer, public, protected waminus_
logical, public, protected mhd_viscosity
Whether viscosity is added.
subroutine, public mhd_get_pradiation_from_prim(w, x, ixil, ixol, prad)
Calculate radiation pressure within ixO^L.
double precision, public, protected mhd_reduced_c
Reduced speed of light for semirelativistic MHD: 2% of light speed.
logical, public, protected mhd_energy
Whether an energy equation is used.
logical, public, protected mhd_ambipolar_exp
Whether Ambipolar term is implemented explicitly.
logical, public, protected mhd_radiative_transfer
Whether the short-characteristics radiative transfer is used, with its settings in &rt_list.
double precision, public mhd_hyperbolic_tc_kappa
The thermal conductivity kappa in hyperbolic thermal conduction.
logical, public, protected mhd_glm
Whether GLM-MHD is used to control div B.
double precision, public, protected mhd_uawsom_zeta_scale
Physical input scales (lengths and magnetic field); converted to code units at init.
type(fld_fluid), allocatable, public fld_fl
Radiation fluid object (gas-EoS callbacks for FLD), wired in mhd_link_eos.
logical, public clean_initial_divb
clean initial divB
double precision, public mhd_eta
The MHD resistivity.
logical, public divbwave
Add divB wave in Roe solver.
logical, public, protected mhd_uawsom_reflection
Enable conservative Alfvén reflection (one-dimensional or Cartesian gradient-vorticity).
logical, public, protected mhd_magnetofriction
Whether magnetofriction is added.
double precision, public, protected mhd_trac_mask
Height of the mask used in the TRAC method.
subroutine, public mhd_semirelati_vel_emech(w, ixil, ixol, vel, emech)
Velocity from the semirelativistic momentum (Gombosi et al. 2002 eqs 15-16) and emech,...
procedure(mask_subroutine), pointer, public usr_mask_ambipolar
logical, public, protected mhd_semirelati_curl_e
Keep E x curl(E) in the semirelativistic source: eq (26) of Gombosi et al. 2002 keeps it,...
elemental pure double precision function, public mhd_uawsom_rho2_factor_cell(zeta)
character(len=std_len), public, protected typedivbfix
Method type to clean divergence of B.
logical, public, protected mhd_uawsom_kink_reflection
double precision, public, protected mhd_uawsom_filling_factor
integer, public, protected waplus_
Conserved wave-energy indices. The plus variables propagate against B.
subroutine, public mhd_uawsom_rho2_factor(ixil, ixol, w, x, factor)
double precision, public, protected mhd_uawsom_alfven_corr_length0
logical, public, protected mhd_thermal_conduction
Whether thermal conduction is used.
integer, public equi_pe0_
subroutine, public mhd_get_csrad2_prim(w, x, ixil, ixol, csound)
Calculate modified squared fast wave speed for FLD NOTE: w is primitive on entry here!...
integer, public, protected qperp_
Index of the perpendicular heat flux q_perp.
integer, public, protected p_
Index of the gas pressure (-1 if not present) should equal e_.
integer, public, protected c
Indices of the momentum density for the form of better vectorization.
character(len=std_len), public, protected mhd_hyperbolic_tc_perp_mode
Perpendicular hyperbolic-TC closure mode: Enable/disable with mhd_hyperbolic_tc_use_perp,...
double precision, public, protected he_ion_fr2
Ratio of number He2+ / number He+ + He2+ He_ion_fr2 = He2+/(He2+ + He+).
pure double precision function, public mhd_uawsom_wave_pressure_cell(wcell, zeta)
logical, public, protected mhd_dump_full_vars
whether dump full variables (when splitting is used) in a separate dat file
logical, public, protected mhd_particles
Whether particles module is added.
integer, public, protected b
subroutine, public mhd_face_to_center(ixol, s)
calculate cell-center values from face-center values
logical, dimension(2 *^nd), public, protected boundary_divbfix
To control divB=0 fix for boundary.
subroutine, public get_current(w, ixil, ixol, idirmin, current)
Calculate idirmin and the idirmin:3 components of the common current array make sure that dxlevel(^D)...
double precision, public mhd_etah
Hall resistivity.
subroutine, public mhd_get_v(w, x, ixil, ixol, v)
Calculate v vector.
double precision, public mhd_eta_ambi
The MHD ambipolar coefficient.
logical, public, protected mhd_fip
Whether FIP passive scalar is enabled.
logical, public, protected mhd_hydrodynamic_e
Whether hydrodynamic energy is solved instead of total energy.
integer, public, protected r_e
Index of the radiation energy.
subroutine, public mhd_phys_init()
logical, public, protected mhd_trac
Whether TRAC method is used.
subroutine, public mhd_get_csrad2(w, x, ixil, ixol, csound)
Calculate modified squared sound speed for FLD NOTE: only for diagnostic purposes,...
subroutine, public mhd_get_pthermal_plus_pradiation(w, x, ixil, ixol, pth_plus_prad)
Calculates the sum of the gas pressure and the max Prad tensor element.
type(rc_fluid), allocatable, public rc_fl
type of fluid for radiative cooling
integer, public, protected wkplus_
integer, dimension(:), allocatable, public, protected tracer
Indices of the tracers.
double precision, public, protected mhd_hyperbolic_tc_coulomb_log
Constant Coulomb logarithm used by the simplified electron-magnetization closure. It is a namelist pa...
integer, public, protected rho_
Index of the density (in the w array).
double precision, public, protected mhd_uawsom_bref
logical, public, protected b0field_forcefree
B0 field is force-free.
integer, dimension(2 *^nd), public, protected boundary_divbfix_skip
To skip * layer of ghost cells during divB=0 fix for boundary.
integer, public, protected tweight_
logical, public, protected mhd_ambipolar_sts
Whether Ambipolar term is implemented using supertimestepping.
logical, public, protected mhd_hyperbolic_tc_use_perp
Whether the perpendicular hyperbolic-TC channel is enabled.
subroutine, public mhd_ei_to_e(ixil, ixol, w, x)
Transform internal energy to total energy.
integer, public, protected e_
Index of the energy density (-1 if not present).
double precision function, public mhd_semirelati_p(eint, rho)
Thermal pressure from internal energy in one cell for the active EoS.
integer, public, protected tcoff_
Index of the cutoff temperature for the TRAC method.
subroutine, public mhd_get_rho(w, x, ixil, ixol, rho)
logical, public, protected mhd_uawsom
Enable the Uniturbulence and Alfven Wave Solar Model extension.
logical, public, protected mhd_fld_pradtensor
integer, public, protected psi_
Indices of the GLM psi.
logical, public mhd_equi_thermal
Module to couple the octree-mg library to AMRVAC. This file uses the VACPP preprocessor,...
type(mg_t) mg
Data structure containing the multigrid tree.
Module containing all the particle routines.
subroutine particles_init()
Initialize particle data and parameters.
This module defines the procedures of a physics module. It contains function pointers for the various...
module radiative cooling – add optically thin radiative cooling
subroutine radiative_cooling_init_params(phys_gamma, he_abund)
Radiative cooling initialization.
subroutine findl(tpoint, lpoint, fl)
subroutine radiative_cooling_init(fl, read_params)
subroutine radiative_cooling_add_source(qdt, ixil, ixol, wct, wctprim, w, x, qsourcesplit, active, fl)
subroutine calc_l_extended(tpoint, lpoint, fl)
Module for including rotating frame in (magneto)hydrodynamics simulations The rotation vector is assu...
subroutine rotating_frame_add_source(qdt, dtfactor, ixil, ixol, wct, w, x)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
subroutine rotating_frame_init()
Initialize the module.
Public face of the short-characteristics (SC) radiative transfer and its coupling to the (M)HD.
subroutine, public rt_sc_add_source(qdt, ixil, ixol, wct, w, x, thin_share, e_internal)
Unsplit heating source of one block and stage, e += qdt Q, with Q read from i_qrad,...
subroutine, public rt_sc_activate()
Switch the RT on. The physics module calls this from its initialisation when hd_radiative_transfer or...
Module for handling problematic values in simulations, such as negative pressures.
subroutine, public small_values_average(ixil, ixol, w, x, w_flag, windex)
subroutine, public small_values_error(wprim, x, ixil, ixol, w_flag, subname)
logical, dimension(:), allocatable, public small_values_fix_iw
Whether to apply small value fixes to certain variables.
character(len=20), public small_values_method
How to handle small values.
Generic supertimestepping method which can be used for multiple source terms in the governing equatio...
subroutine, public add_sts_method(sts_getdt, sts_set_sources, startvar, nflux, startwbc, nwbc, evolve_b)
subroutine which added programatically a term to be calculated using STS Params: sts_getdt function c...
subroutine, public set_conversion_methods_to_head(sts_before_first_cycle, sts_after_last_cycle)
Set the hooks called before the first cycle and after the last cycle in the STS update This method sh...
subroutine, public set_error_handling_to_head(sts_error_handling)
Set the hook of error handling in the STS update. This method is called before updating the BC....
subroutine, public sts_init()
Initialize sts module.
Thermal conduction for HD and MHD or RHD and RMHD or twofl (plasma-neutral) module Adaptation of mod_...
double precision function, public get_tc_dt_mhd(w, ixil, ixol, dxd, x, fl)
Get the explicit timestep for the TC (mhd implementation) Note: for multi-D MHD (1D MHD will use HD f...
double precision function, public get_tc_dt_hd(w, ixil, ixol, dxd, x, fl)
Get the explicit timestep for the TC (hd implementation) Note: also used in 1D MHD (or for neutrals i...
subroutine tc_init_params(phys_gamma)
subroutine, public sts_set_source_tc_hd(ixil, ixol, w, x, wres, fix_conserve_at_step, my_dt, igrid, nflux, fl)
subroutine, public sts_set_source_tc_mhd(ixil, ixol, w, x, wres, fix_conserve_at_step, my_dt, igrid, nflux, fl)
anisotropic thermal conduction with slope limited symmetric scheme Sharma 2007 Journal of Computation...
subroutine, public tc_get_mhd_params(fl, read_mhd_params)
Init TC coefficients: MHD case.
subroutine get_euv_image(qunit, fl)
subroutine get_sxr_image(qunit, fl)
subroutine get_euv_spectrum(qunit, fl)
subroutine get_whitelight_image(qunit, fl)
Module with all the methods that users can customize in AMRVAC.
procedure(rfactor), pointer usr_rfactor
procedure(special_resistivity), pointer usr_special_resistivity
procedure(set_adiab), pointer usr_set_adiab
procedure(set_adiab), pointer usr_set_gamma
procedure(sub_get_heating), pointer usr_get_heating
procedure(phys_gravity), pointer usr_gravity
procedure(uawsom_coefficients), pointer usr_uawsom_coefficients
Optionally provide local UAWSoM closure coefficients. The returned thread radius and Alfven correlati...
procedure(set_equi_vars), pointer usr_set_equi_vars
procedure(set_electric_field), pointer usr_set_electric_field
The module add viscous source terms and check time step.
subroutine, public viscosity_get_dt(wprim, ixil, ixol, dtnew, dxd, x)
procedure(sub_add_source), pointer, public viscosity_add_source
subroutine, public viscosity_init(phys_wider_stencil)
Initialize the module.
Radiation fluid object: gas-EoS callbacks the FLD module needs, wired by the physics module at link t...
The data structure that contains information about a tree node/grid block.