22 double precision,
public ::
mhd_eta = 0.0d0
44 double precision,
public,
protected ::
h_ion_fr=1d0
47 double precision,
public,
protected ::
he_ion_fr=1d0
54 double precision,
public,
protected ::
rr=1d0
56 double precision :: gamma_1, inv_gamma_1
58 double precision :: inv_squared_c0, inv_squared_c
65 integer,
public,
protected ::
rho_
67 integer,
allocatable,
public,
protected ::
mom(:)
69 integer,
public,
protected :: ^
c&m^C_
71 integer,
public,
protected ::
e_
73 integer,
public,
protected :: ^
c&b^C_
75 integer,
public,
protected ::
p_
77 integer,
public,
protected ::
q_
79 integer,
public,
protected ::
psi_
81 integer,
public,
protected ::
r_e
83 integer,
public,
protected ::
te_
88 integer,
allocatable,
public,
protected ::
tracer(:)
96 integer,
parameter :: divb_none = 0
97 integer,
parameter :: divb_multigrid = -1
98 integer,
parameter :: divb_glm = 1
99 integer,
parameter :: divb_powel = 2
100 integer,
parameter :: divb_janhunen = 3
101 integer,
parameter :: divb_linde = 4
102 integer,
parameter :: divb_lindejanhunen = 5
103 integer,
parameter :: divb_lindepowel = 6
104 integer,
parameter :: divb_lindeglm = 7
105 integer,
parameter :: divb_ct = 8
135 logical,
public,
protected ::
mhd_glm = .false.
178 logical :: total_energy = .true.
182 logical :: gravity_energy
184 character(len=std_len),
public,
protected ::
typedivbfix =
'linde'
186 character(len=std_len),
public,
protected ::
type_ct =
'uct_contact'
188 character(len=std_len) :: typedivbdiff =
'all'
199 subroutine mask_subroutine(ixI^L,ixO^L,w,x,res)
201 integer,
intent(in) :: ixi^
l, ixo^
l
202 double precision,
intent(in) :: x(ixi^s,1:
ndim)
203 double precision,
intent(in) :: w(ixi^s,1:nw)
204 double precision,
intent(inout) :: res(ixi^s)
205 end subroutine mask_subroutine
260 subroutine mhd_read_params(files)
263 character(len=*),
intent(in) :: files(:)
280 do n = 1,
size(files)
281 open(
unitpar, file=trim(files(n)), status=
"old")
282 read(
unitpar, mhd_list,
end=111)
286 end subroutine mhd_read_params
289 subroutine mhd_write_info(fh)
291 integer,
intent(in) :: fh
294 integer,
parameter :: n_par = 1
295 double precision :: values(n_par)
296 integer,
dimension(MPI_STATUS_SIZE) :: st
297 character(len=name_len) :: names(n_par)
299 call mpi_file_write(fh, n_par, 1, mpi_integer, st, er)
303 call mpi_file_write(fh, values, n_par, mpi_double_precision, st, er)
304 call mpi_file_write(fh, names, n_par * name_len, mpi_character, st, er)
305 end subroutine mhd_write_info
333 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_internal_e=T'
337 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_internal_e=T'
344 if(
mype==0)
write(*,*)
'WARNING: set mhd_internal_e=F when mhd_hydrodynamic_e=T'
348 if(
mype==0)
write(*,*)
'WARNING: set B0field=F when mhd_hydrodynamic_e=T'
352 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_hydrodynamic_e=T'
359 if(
mype==0)
write(*,*)
'WARNING: set B0field=F when mhd_semirelativistic=T'
363 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_semirelativistic=T'
367 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_semirelativistic=T'
374 if(
mype==0)
write(*,*)
'WARNING: set mhd_internal_e=F when mhd_energy=F'
378 if(
mype==0)
write(*,*)
'WARNING: set mhd_hydrodynamic_e=F when mhd_energy=F'
382 if(
mype==0)
write(*,*)
'WARNING: set mhd_thermal_conduction=F when mhd_energy=F'
386 if(
mype==0)
write(*,*)
'WARNING: set mhd_hyperbolic_thermal_conduction=F when mhd_energy=F'
390 if(
mype==0)
write(*,*)
'WARNING: set mhd_radiative_cooling=F when mhd_energy=F'
394 if(
mype==0)
write(*,*)
'WARNING: set mhd_trac=F when mhd_energy=F'
398 if(
mype==0)
write(*,*)
'WARNING: set mhd_partial_ionization=F when mhd_energy=F'
402 if(
mype==0)
write(*,*)
'WARNING: set B0field=F when mhd_energy=F'
406 if(
mype==0)
write(*,*)
'WARNING: set has_equi_rho_and_p=F when mhd_energy=F'
412 if(
mype==0)
write(*,*)
'WARNING: set mhd_partial_ionization=F when eq_state_units=F'
418 if(
mype==0)
write(*,*)
'WARNING: set either parabolic TC or hyperbolic TC to F'
419 if(
mype==0)
write(*,*)
'WARNING: defaulting to only mhd_hyperbolic_thermal_conduction=T'
443 phys_total_energy=total_energy
446 gravity_energy=.false.
448 gravity_energy=.true.
451 gravity_energy=.false.
457 if(
mype==0)
write(*,*)
'WARNING: reset mhd_trac_type=1 for 1D simulation'
462 if(
mype==0)
write(*,*)
'WARNING: set mhd_trac_mask==bigdouble for global TRAC method'
470 type_divb = divb_none
473 if(
mhd_radiation_fld)
call mpistop(
'To verify whether mg usage for FLD versus divB can be combined')
474 type_divb = divb_multigrid
476 mg%operator_type = mg_laplacian
483 case (
'powel',
'powell')
484 type_divb = divb_powel
486 type_divb = divb_janhunen
488 type_divb = divb_linde
489 case (
'lindejanhunen')
490 type_divb = divb_lindejanhunen
492 type_divb = divb_lindepowel
496 type_divb = divb_lindeglm
501 call mpistop(
'Unknown divB fix')
506 allocate(start_indices(number_species),stop_indices(number_species))
513 mom(:) = var_set_momentum(
ndir)
519 e_ = var_set_energy()
528 mag(:) = var_set_bfield(
ndir)
532 psi_ = var_set_fluxvar(
'psi',
'psi', need_bc=.false.)
548 tracer(itr) = var_set_fluxvar(
"trc",
"trp", itr, need_bc=.false.)
554 write(*,*)
'Warning: CAK force addition together with FLD radiation'
559 write(*,*)
'Warning: Optically thin cooling together with FLD radiation'
563 call mpistop(
'using FLD implies the use of an energy equation, set mhd_energy=T')
566 call mpistop(
'using FLD not yet with semirelativistic energy formalism')
569 call mpistop(
'using FLD not yet with hydrodynamic or internal energy formalism')
572 call mpistop(
'using FLD not yet with split off rho and p')
576 r_e = var_set_radiation_energy()
588 te_ = var_set_auxvar(
'Te',
'Te')
597 stop_indices(1)=nwflux
625 allocate(iw_vector(nvector))
626 iw_vector(1) =
mom(1) - 1
627 iw_vector(2) = mag(1) - 1
630 if (.not.
allocated(flux_type))
then
631 allocate(flux_type(
ndir, nwflux))
632 flux_type = flux_default
633 else if (any(shape(flux_type) /= [
ndir, nwflux]))
then
634 call mpistop(
"phys_check error: flux_type has wrong shape")
637 if(nwflux>mag(
ndir))
then
639 flux_type(:,mag(
ndir)+1:nwflux)=flux_hll
644 flux_type(:,
psi_)=flux_special
646 flux_type(idir,mag(idir))=flux_special
650 flux_type(idir,mag(idir))=flux_tvdlf
656 phys_get_dt => mhd_get_dt
659 phys_get_cmax => mhd_get_cmax_semirelati
661 phys_get_cmax => mhd_get_cmax_semirelati_noe
665 phys_get_cmax => mhd_get_cmax_origin
667 phys_get_cmax => mhd_get_cmax_origin_noe
670 phys_get_tcutoff => mhd_get_tcutoff
671 phys_get_h_speed => mhd_get_h_speed
673 phys_get_cbounds => mhd_get_cbounds_split_rho
675 phys_get_cbounds => mhd_get_cbounds_semirelati
677 phys_get_cbounds => mhd_get_cbounds
680 phys_to_primitive => mhd_to_primitive_hde
682 phys_to_conserved => mhd_to_conserved_hde
686 phys_to_primitive => mhd_to_primitive_semirelati
688 phys_to_conserved => mhd_to_conserved_semirelati
691 phys_to_primitive => mhd_to_primitive_semirelati_noe
693 phys_to_conserved => mhd_to_conserved_semirelati_noe
698 phys_to_primitive => mhd_to_primitive_split_rho
700 phys_to_conserved => mhd_to_conserved_split_rho
703 phys_to_primitive => mhd_to_primitive_inte
705 phys_to_conserved => mhd_to_conserved_inte
708 phys_to_primitive => mhd_to_primitive_origin
710 phys_to_conserved => mhd_to_conserved_origin
713 phys_to_primitive => mhd_to_primitive_origin_noe
715 phys_to_conserved => mhd_to_conserved_origin_noe
720 phys_get_flux => mhd_get_flux_hde
723 phys_get_flux => mhd_get_flux_semirelati
725 phys_get_flux => mhd_get_flux_semirelati_noe
729 phys_get_flux => mhd_get_flux_split
731 phys_get_flux => mhd_get_flux
733 phys_get_flux => mhd_get_flux_noe
738 phys_add_source_geom => mhd_add_source_geom_semirelati
740 phys_add_source_geom => mhd_add_source_geom_split
742 phys_add_source_geom => mhd_add_source_geom
744 phys_add_source => mhd_add_source
745 phys_check_params => mhd_check_params
746 phys_write_info => mhd_write_info
749 phys_handle_small_values => mhd_handle_small_values_inte
750 mhd_handle_small_values => mhd_handle_small_values_inte
751 phys_check_w => mhd_check_w_inte
753 phys_handle_small_values => mhd_handle_small_values_hde
754 mhd_handle_small_values => mhd_handle_small_values_hde
755 phys_check_w => mhd_check_w_hde
757 phys_handle_small_values => mhd_handle_small_values_semirelati
758 mhd_handle_small_values => mhd_handle_small_values_semirelati
759 phys_check_w => mhd_check_w_semirelati
761 phys_handle_small_values => mhd_handle_small_values_split
762 mhd_handle_small_values => mhd_handle_small_values_split
763 phys_check_w => mhd_check_w_split
765 phys_handle_small_values => mhd_handle_small_values_origin
766 mhd_handle_small_values => mhd_handle_small_values_origin
767 phys_check_w => mhd_check_w_origin
769 phys_handle_small_values => mhd_handle_small_values_noe
770 mhd_handle_small_values => mhd_handle_small_values_noe
771 phys_check_w => mhd_check_w_noe
775 phys_get_pthermal => mhd_get_pthermal_inte
778 phys_get_pthermal => mhd_get_pthermal_hde
781 phys_get_pthermal => mhd_get_pthermal_semirelati
784 phys_get_pthermal => mhd_get_pthermal_origin
787 phys_get_pthermal => mhd_get_pthermal_noe
792 phys_set_equi_vars => set_equi_vars_grid
795 if(type_divb==divb_glm)
then
796 phys_modify_wlr => mhd_modify_wlr
802 phys_update_temperature => mhd_update_temperature
829 transverse_ghost_cells = 1
830 phys_get_ct_velocity => mhd_get_ct_velocity_average
831 phys_update_faces => mhd_update_faces_average
833 transverse_ghost_cells = 1
834 phys_get_ct_velocity => mhd_get_ct_velocity_contact
835 phys_update_faces => mhd_update_faces_contact
837 transverse_ghost_cells = 2
838 phys_get_ct_velocity => mhd_get_ct_velocity_hll
839 phys_update_faces => mhd_update_faces_hll
841 call mpistop(
'choose average, uct_contact,or uct_hll for type_ct!')
844 phys_modify_wlr => mhd_modify_wlr
846 phys_boundary_adjust => mhd_boundary_adjust
852 call mpistop(
'To verify whether mg usage for FLD versus divB can be combined')
857 call mhd_physical_units()
872 if(
mype==0)
write(*,*)
'WARNING: turning mhd_equi_thermal=F as no splitting or total e in use'
875 if(
mype==0)
write(*,*)
'Will subtract thermal balance in TC or RC with mhd_equi_thermal=T'
878 if(
mype==0)
write(*,*)
'WARNING: turning mhd_equi_thermal=F as no TC or RC in use'
897 tc_fl%get_temperature_from_conserved => mhd_get_temperature_from_eint_with_equi
899 tc_fl%get_temperature_from_conserved => mhd_get_temperature_from_eint
905 tc_fl%get_temperature_from_eint => mhd_get_temperature_from_eint_with_equi
907 tc_fl%subtract_equi = .true.
908 tc_fl%get_temperature_equi => mhd_get_temperature_equi
909 tc_fl%get_rho_equi => mhd_get_rho_equi
911 tc_fl%subtract_equi = .false.
914 tc_fl%get_temperature_from_eint => mhd_get_temperature_from_eint
943 rc_fl%subtract_equi = .true.
944 rc_fl%get_rho_equi => mhd_get_rho_equi
945 rc_fl%get_pthermal_equi => mhd_get_pe_equi
946 rc_fl%get_temperature_equi => mhd_get_temperature_equi
948 rc_fl%subtract_equi = .false.
958 phys_te_images => mhd_te_images
964 write(*,*)
'*****Using hyperresistivity: with mhd_eta_hyper :',
mhd_eta_hyper
968 call mpistop(
"Must have B0field=F when using hyperresistivity")
972 call mpistop(
"Must have mhd_eta_hyper positive when using hyperresistivity")
989 call mpistop(
"Must have has_equi_rho_and_p=F when mhd_rotating_frame=T")
1003 call mpistop(
"Must have mhd_hall=F when mhd_semirelativistic=T")
1007 call mpistop(
"Must have Cartesian coordinates for Hall")
1011 phys_wider_stencil = 1
1018 call add_sts_method(get_ambipolar_dt,sts_set_source_ambipolar,mag(1),&
1029 phys_wider_stencil = 1
1039 call mpistop(
"CAK implementation not available in internal or semirelativistic variants")
1042 call mpistop(
"CAK force implementation not available for split off pressure and density")
1050 subroutine mhd_te_images
1055 case(
'EIvtiCCmpi',
'EIvtuCCmpi')
1057 case(
'ESvtiCCmpi',
'ESvtuCCmpi')
1059 case(
'SIvtiCCmpi',
'SIvtuCCmpi')
1061 case(
'WIvtiCCmpi',
'WIvtuCCmpi')
1064 call mpistop(
"Error in synthesize emission: Unknown convert_type")
1066 end subroutine mhd_te_images
1072 subroutine mhd_sts_set_source_tc_mhd(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
1076 integer,
intent(in) :: ixi^
l, ixo^
l, igrid, nflux
1077 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1078 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
1079 double precision,
intent(in) :: my_dt
1080 logical,
intent(in) :: fix_conserve_at_step
1082 end subroutine mhd_sts_set_source_tc_mhd
1084 subroutine mhd_sts_set_source_tc_hd(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
1088 integer,
intent(in) :: ixi^
l, ixo^
l, igrid, nflux
1089 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1090 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
1091 double precision,
intent(in) :: my_dt
1092 logical,
intent(in) :: fix_conserve_at_step
1094 end subroutine mhd_sts_set_source_tc_hd
1096 function mhd_get_tc_dt_mhd(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
1103 integer,
intent(in) :: ixi^
l, ixo^
l
1104 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
1105 double precision,
intent(in) :: w(ixi^s,1:nw)
1106 double precision :: dtnew
1109 end function mhd_get_tc_dt_mhd
1111 function mhd_get_tc_dt_hd(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
1118 integer,
intent(in) :: ixi^
l, ixo^
l
1119 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
1120 double precision,
intent(in) :: w(ixi^s,1:nw)
1121 double precision :: dtnew
1124 end function mhd_get_tc_dt_hd
1126 subroutine mhd_tc_handle_small_e(w, x, ixI^L, ixO^L, step)
1129 integer,
intent(in) :: ixi^
l,ixo^
l
1130 double precision,
intent(inout) :: w(ixi^s,1:nw)
1131 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1132 integer,
intent(in) :: step
1133 character(len=140) :: error_msg
1135 write(error_msg,
"(a,i3)")
"Thermal conduction step ", step
1136 call mhd_handle_small_ei(w,x,ixi^
l,ixo^
l,
e_,error_msg)
1137 end subroutine mhd_tc_handle_small_e
1140 subroutine tc_params_read_mhd(fl)
1142 type(tc_fluid),
intent(inout) :: fl
1144 double precision :: tc_k_para=0d0
1145 double precision :: tc_k_perp=0d0
1148 logical :: tc_perpendicular=.false.
1149 logical :: tc_saturate=.false.
1150 character(len=std_len) :: tc_slope_limiter=
"MC"
1152 namelist /tc_list/ tc_perpendicular, tc_saturate, tc_slope_limiter, tc_k_para, tc_k_perp
1156 read(
unitpar, tc_list,
end=111)
1160 fl%tc_perpendicular = tc_perpendicular
1161 fl%tc_saturate = tc_saturate
1162 fl%tc_k_para = tc_k_para
1163 fl%tc_k_perp = tc_k_perp
1164 select case(tc_slope_limiter)
1166 fl%tc_slope_limiter = 0
1169 fl%tc_slope_limiter = 1
1172 fl%tc_slope_limiter = 2
1175 fl%tc_slope_limiter = 3
1178 fl%tc_slope_limiter = 4
1181 fl%tc_slope_limiter = 5
1183 call mpistop(
"Unknown tc_slope_limiter, choose MC, minmod, superbee, koren, vanleer")
1185 end subroutine tc_params_read_mhd
1189 subroutine rc_params_read(fl)
1192 type(rc_fluid),
intent(inout) :: fl
1196 double precision :: rad_cut_hgt=0.5d0
1197 double precision :: rad_cut_dey=0.15d0
1200 integer :: ncool = 4000
1202 logical :: tfix=.false.
1204 logical :: rc_split=.false.
1205 logical :: rad_cut=.false.
1207 character(len=std_len) :: coolcurve=
'JCcorona'
1209 namelist /rc_list/ coolcurve, ncool, tlow, tfix, rc_split,rad_cut,rad_cut_hgt,rad_cut_dey
1213 read(
unitpar, rc_list,
end=111)
1218 fl%coolcurve=coolcurve
1221 fl%rc_split=rc_split
1223 fl%rad_cut_hgt=rad_cut_hgt
1224 fl%rad_cut_dey=rad_cut_dey
1225 end subroutine rc_params_read
1229 subroutine set_equi_vars_grid_faces(igrid,x,ixI^L,ixO^L)
1232 integer,
intent(in) :: igrid, ixi^
l, ixo^
l
1233 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1235 double precision :: delx(ixi^s,1:
ndim)
1236 double precision :: xc(ixi^s,1:
ndim),xshift^
d
1237 integer :: idims, ixc^
l, hxo^
l, ix, idims2
1243 delx(ixi^s,1:
ndim)=ps(igrid)%dx(ixi^s,1:
ndim)
1247 hxo^
l=ixo^
l-
kr(idims,^
d);
1253 ixcmax^
d=ixomax^
d; ixcmin^
d=hxomin^
d;
1256 xshift^
d=half*(one-
kr(^
d,idims));
1263 xc(ix^
d%ixC^s,^
d)=x(ix^
d%ixC^s,^
d)+(half-xshift^
d)*delx(ix^
d%ixC^s,^
d)
1267 call usr_set_equi_vars(ixi^l,ixc^l,xc,ps(igrid)%equi_vars(ixi^s,1:number_equi_vars,idims))
1270 end subroutine set_equi_vars_grid_faces
1273 subroutine set_equi_vars_grid(igrid)
1277 integer,
intent(in) :: igrid
1283 call set_equi_vars_grid_faces(igrid,ps(igrid)%x,ixg^
ll,
ixm^
ll)
1285 end subroutine set_equi_vars_grid
1288 function convert_vars_splitting(ixI^L,ixO^L, w, x, nwc)
result(wnew)
1290 integer,
intent(in) :: ixi^
l,ixo^
l, nwc
1291 double precision,
intent(in) :: w(ixi^s, 1:nw)
1292 double precision,
intent(in) :: x(ixi^s,1:
ndim)
1293 double precision :: wnew(ixo^s, 1:nwc)
1300 wnew(ixo^s,
mom(:))=w(ixo^s,
mom(:))
1306 wnew(ixo^s,mag(1:
ndir))=w(ixo^s,mag(1:
ndir))
1310 wnew(ixo^s,
e_)=w(ixo^s,
e_)
1314 if(
b0field .and. total_energy)
then
1315 wnew(ixo^s,
e_)=wnew(ixo^s,
e_)+0.5d0*sum(
block%B0(ixo^s,:,0)**2,dim=
ndim+1) &
1316 + sum(w(ixo^s,mag(:))*
block%B0(ixo^s,:,0),dim=
ndim+1)
1320 end function convert_vars_splitting
1322 subroutine mhd_check_params
1329 ngridvars,num_particles,physics_type_particles
1332 double precision :: a,
b,xfrac,yfrac
1337 if (particles_eta < zero) particles_eta =
mhd_eta
1338 if (particles_etah < zero) particles_eta =
mhd_etah
1344 if (
mhd_gamma <= 0.0d0)
call mpistop (
"Error: mhd_gamma <= 0")
1345 if (
mhd_adiab < 0.0d0)
call mpistop (
"Error: mhd_adiab < 0")
1349 call mpistop (
"Error: mhd_gamma <= 0 or mhd_gamma == 1")
1350 inv_gamma_1=1.d0/gamma_1
1356 call mpistop(
"usr_set_equi_vars has to be implemented in the user file")
1361 if(
mype .eq. 0) print*,
" add conversion method: split -> full "
1369 call mpistop(
'select IMEX scheme for FLD radiation use')
1372 call phys_set_mg_bounds()
1374 if(.not.
fld_no_mg)
call mpistop(
'multigrid must have BCs for IMEX and FLD radiation use')
1377 write(*,*)
'==FLD SETUP======================'
1378 write(*,*)
'Using FLD with settings:'
1383 write(*,*)
'Using FLD with settings: fld_kappa0=',
fld_kappa0
1384 write(*,*)
'Using FLD with settings: fld_opal_table=',
fld_opal_table
1386 write(*,*)
'Using FLD with settings: fld_bisect_tol=',
fld_bisect_tol
1387 write(*,*)
'Using FLD with settings: fld_diff_tol=',
fld_diff_tol
1391 print *,
'NORMALIZED arad_norm=',
arad_norm
1392 print *,
'NORMALIZED c_norm=',
c_norm
1399 print *,
'physical fld_kappa (in cgs or SI) =',
fld_kappa0
1403 write(*,*)
'===FLD SETUP====================='
1408 write(*,*)
'====MHD run with settings===================='
1409 write(*,*)
'Using mod_mhd_phys with settings:'
1411 write(*,*)
'Dimensionality :',
ndim
1412 write(*,*)
'vector components:',
ndir
1414 write(*,*)
'number of variables nw=',nw
1415 write(*,*)
' start index iwstart=',iwstart
1416 write(*,*)
'number of vector variables=',nvector
1417 write(*,*)
'number of stagger variables nws=',nws
1418 write(*,*)
'number of variables with BCs=',nwgc
1419 write(*,*)
'number of vars with fluxes=',nwflux
1420 write(*,*)
'number of vars with flux + BC=',nwfluxbc
1421 write(*,*)
'number of auxiliary variables=',nwaux
1422 write(*,*)
'number of extra vars without flux=',nwextra
1423 write(*,*)
'number of extra vars for wextra=',nw_extra
1424 write(*,*)
'number of auxiliary I/O variables=',
nwauxio
1426 write(*,*)
' mhd_energy=',
mhd_energy,
' with total_energy=',total_energy
1431 write(*,*)
' mhd_eta=',
mhd_eta,
' nonzero implies resistivity'
1445 write(*,*)
'*****Using particles: with mhd_eta, mhd_etah :',
mhd_eta,
mhd_etah
1446 write(*,*)
'*****Using particles: particles_eta, particles_etah :', particles_eta, particles_etah
1447 write(*,*)
'*****Using particles: npayload,ngridvars :', npayload,ngridvars
1448 write(*,*)
'*****Using particles: nusrpayload :', nusrpayload
1449 write(*,*)
'*****Using particles: num_particles :', num_particles
1450 write(*,*)
'*****Using particles: physics_type_particles=',physics_type_particles
1453 write(*,*)
'number due to phys_wider_stencil=',phys_wider_stencil
1454 write(*,*)
'==========================================='
1455 print *,
'========EOS and UNITS==========='
1461 print *,
'========EOS and UNITS==========='
1483 print *,
' compare this to ',mp_si*(1.d0+4.d0*
he_abundance)
1485 print *,
' compare this to ',mp_cgs*(1.d0+4.d0*
he_abundance)
1489 print *,
' compare this to ',kb_si*(2.d0+3.d0*
he_abundance)
1493 print *,
' compare this to ',kb_cgs*(2.d0+3.d0*
he_abundance)
1501 print *,
'mass fraction hydrogen X is =',1/a,
' and this equals ', 1.d0/(1.d0+4.d0*
he_abundance)
1502 print *,
'mass fraction helium Y is =',yfrac
1503 print *,
' check that 1/mu',
b/a,
' is equal to 2X+3Y/4=',2.d0*xfrac+3.d0*yfrac/4.d0
1506 print *,
'========UNITS==========='
1509 end subroutine mhd_check_params
1511 subroutine mhd_physical_units()
1513 double precision :: mp,kb,miu0,c_lightspeed,xfrac,sigma_telectron
1514 double precision :: a,
b
1522 sigma_telectron=sigma_te_si
1528 c_lightspeed=const_c
1529 sigma_telectron=sigma_te_cgs
1688 end subroutine mhd_physical_units
1690 subroutine mhd_check_w_semirelati(primitive,ixI^L,ixO^L,w,flag)
1693 logical,
intent(in) :: primitive
1694 logical,
intent(inout) :: flag(ixi^s,1:nw)
1695 integer,
intent(in) :: ixi^
l, ixo^
l
1696 double precision,
intent(in) :: w(ixi^s,nw)
1698 double precision :: tmp,
b(1:
ndir),v(1:
ndir),factor
1709 {
do ix^db=ixomin^db,ixomax^db \}
1713 {
do ix^db=ixomin^db,ixomax^db \}
1715 tmp=(^
c&w(ix^d,
b^
c_)*w(ix^d,
m^
c_)+)*inv_squared_c
1716 factor=1.0d0/(w(ix^d,
rho_)*(w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+)*inv_squared_c))
1717 ^
c&v(^
c)=factor*(w(ix^d,
m^
c_)*w(ix^d,
rho_)+w(ix^d,
b^
c_)*tmp)\
1720 b(1)=w(ix^d,b2_)*v(3)-w(ix^d,b3_)*v(2)
1721 b(2)=w(ix^d,b3_)*v(1)-w(ix^d,b1_)*v(3)
1722 b(3)=w(ix^d,b1_)*v(2)-w(ix^d,b2_)*v(1)
1727 b(2)=w(ix^d,b1_)*v(2)-w(ix^d,b2_)*v(1)
1733 tmp=w(ix^d,
e_)-half*((^
c&v(^
c)**2+)*w(ix^d,
rho_)&
1734 +(^
c&w(ix^d,
b^
c_)**2+)+(^
c&
b(^
c)**2+)*inv_squared_c)
1735 if(tmp<small_e) flag(ix^d,
e_)=.true.
1741 end subroutine mhd_check_w_semirelati
1743 subroutine mhd_check_w_origin(primitive,ixI^L,ixO^L,w,flag)
1746 logical,
intent(in) :: primitive
1747 integer,
intent(in) :: ixi^
l, ixo^
l
1748 double precision,
intent(in) :: w(ixi^s,nw)
1749 logical,
intent(inout) :: flag(ixi^s,1:nw)
1754 {
do ix^db=ixomin^db,ixomax^db\}
1767 end subroutine mhd_check_w_origin
1769 subroutine mhd_check_w_split(primitive,ixI^L,ixO^L,w,flag)
1772 logical,
intent(in) :: primitive
1773 integer,
intent(in) :: ixi^
l, ixo^
l
1774 double precision,
intent(in) :: w(ixi^s,nw)
1775 logical,
intent(inout) :: flag(ixi^s,1:nw)
1777 double precision :: tmp
1781 {
do ix^db=ixomin^db,ixomax^db\}
1787 tmp=w(ix^
d,
e_)-half*((^
c&w(ix^
d,
m^
c_)**2+)/tmp+(^
c&w(ix^
d,
b^
c_)**2+))
1792 end subroutine mhd_check_w_split
1794 subroutine mhd_check_w_noe(primitive,ixI^L,ixO^L,w,flag)
1797 logical,
intent(in) :: primitive
1798 integer,
intent(in) :: ixi^
l, ixo^
l
1799 double precision,
intent(in) :: w(ixi^s,nw)
1800 logical,
intent(inout) :: flag(ixi^s,1:nw)
1805 {
do ix^db=ixomin^db,ixomax^db\}
1809 end subroutine mhd_check_w_noe
1811 subroutine mhd_check_w_inte(primitive,ixI^L,ixO^L,w,flag)
1814 logical,
intent(in) :: primitive
1815 integer,
intent(in) :: ixi^
l, ixo^
l
1816 double precision,
intent(in) :: w(ixi^s,nw)
1817 logical,
intent(inout) :: flag(ixi^s,1:nw)
1822 {
do ix^db=ixomin^db,ixomax^db\}
1831 end subroutine mhd_check_w_inte
1833 subroutine mhd_check_w_hde(primitive,ixI^L,ixO^L,w,flag)
1836 logical,
intent(in) :: primitive
1837 integer,
intent(in) :: ixi^
l, ixo^
l
1838 double precision,
intent(in) :: w(ixi^s,nw)
1839 logical,
intent(inout) :: flag(ixi^s,1:nw)
1844 {
do ix^db=ixomin^db,ixomax^db\}
1853 end subroutine mhd_check_w_hde
1856 subroutine mhd_to_conserved_origin(ixI^L,ixO^L,w,x)
1858 integer,
intent(in) :: ixi^
l, ixo^
l
1859 double precision,
intent(inout) :: w(ixi^s, nw)
1860 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1864 {
do ix^db=ixomin^db,ixomax^db\}
1866 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1&
1868 +(^
c&w(ix^
d,
b^
c_)**2+))
1873 end subroutine mhd_to_conserved_origin
1876 subroutine mhd_to_conserved_origin_noe(ixI^L,ixO^L,w,x)
1878 integer,
intent(in) :: ixi^
l, ixo^
l
1879 double precision,
intent(inout) :: w(ixi^s, nw)
1880 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1884 {
do ix^db=ixomin^db,ixomax^db\}
1889 end subroutine mhd_to_conserved_origin_noe
1892 subroutine mhd_to_conserved_hde(ixI^L,ixO^L,w,x)
1894 integer,
intent(in) :: ixi^
l, ixo^
l
1895 double precision,
intent(inout) :: w(ixi^s, nw)
1896 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1900 {
do ix^db=ixomin^db,ixomax^db\}
1902 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1&
1908 end subroutine mhd_to_conserved_hde
1911 subroutine mhd_to_conserved_inte(ixI^L,ixO^L,w,x)
1913 integer,
intent(in) :: ixi^
l, ixo^
l
1914 double precision,
intent(inout) :: w(ixi^s, nw)
1915 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1919 {
do ix^db=ixomin^db,ixomax^db\}
1921 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1
1926 end subroutine mhd_to_conserved_inte
1929 subroutine mhd_to_conserved_split_rho(ixI^L,ixO^L,w,x)
1931 integer,
intent(in) :: ixi^
l, ixo^
l
1932 double precision,
intent(inout) :: w(ixi^s, nw)
1933 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1935 double precision :: rho
1938 {
do ix^db=ixomin^db,ixomax^db\}
1941 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1&
1942 +half*((^
c&w(ix^
d,
m^
c_)**2+)*rho&
1943 +(^
c&w(ix^
d,
b^
c_)**2+))
1948 end subroutine mhd_to_conserved_split_rho
1951 subroutine mhd_to_conserved_semirelati(ixI^L,ixO^L,w,x)
1953 integer,
intent(in) :: ixi^
l, ixo^
l
1954 double precision,
intent(inout) :: w(ixi^s, nw)
1955 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
1958 double precision :: ef(ixo^s,1:
ndir), s(ixo^s,1:
ndir)
1961 {
do ix^db=ixomin^db,ixomax^db\}
1963 ef(ix^
d,1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
1964 ef(ix^
d,2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
1965 ef(ix^
d,3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
1966 s(ix^
d,1)=ef(ix^
d,2)*w(ix^
d,b3_)-ef(ix^
d,3)*w(ix^
d,b2_)
1967 s(ix^
d,2)=ef(ix^
d,3)*w(ix^
d,b1_)-ef(ix^
d,1)*w(ix^
d,b3_)
1968 s(ix^
d,3)=ef(ix^
d,1)*w(ix^
d,b2_)-ef(ix^
d,2)*w(ix^
d,b1_)
1973 ef(ix^
d,2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
1974 s(ix^
d,1)=-ef(ix^
d,2)*w(ix^
d,b2_)
1975 s(ix^
d,2)=ef(ix^
d,2)*w(ix^
d,b1_)
1983 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1
1987 w(ix^
d,
e_)=w(ix^
d,
p_)*inv_gamma_1&
1989 +(^
c&w(ix^
d,
b^
c_)**2+)&
1990 +(^
c&ef(ix^
d,^
c)**2+)*inv_squared_c)
1998 end subroutine mhd_to_conserved_semirelati
2000 subroutine mhd_to_conserved_semirelati_noe(ixI^L,ixO^L,w,x)
2002 integer,
intent(in) :: ixi^
l, ixo^
l
2003 double precision,
intent(inout) :: w(ixi^s, nw)
2004 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2006 double precision :: e(ixo^s,1:
ndir), s(ixo^s,1:
ndir)
2009 {
do ix^db=ixomin^db,ixomax^db\}
2011 e(ix^
d,1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
2012 e(ix^
d,2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
2013 e(ix^
d,3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
2014 s(ix^
d,1)=e(ix^
d,2)*w(ix^
d,b3_)-e(ix^
d,3)*w(ix^
d,b2_)
2015 s(ix^
d,2)=e(ix^
d,3)*w(ix^
d,b1_)-e(ix^
d,1)*w(ix^
d,b3_)
2016 s(ix^
d,3)=e(ix^
d,1)*w(ix^
d,b2_)-e(ix^
d,2)*w(ix^
d,b1_)
2021 e(ix^
d,2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
2022 s(ix^
d,1)=-e(ix^
d,2)*w(ix^
d,b2_)
2023 s(ix^
d,2)=e(ix^
d,2)*w(ix^
d,b1_)
2033 end subroutine mhd_to_conserved_semirelati_noe
2036 subroutine mhd_to_primitive_origin(ixI^L,ixO^L,w,x)
2038 integer,
intent(in) :: ixi^
l, ixo^
l
2039 double precision,
intent(inout) :: w(ixi^s, nw)
2040 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2042 double precision :: inv_rho
2047 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_origin')
2050 {
do ix^db=ixomin^db,ixomax^db\}
2051 inv_rho = 1.d0/w(ix^
d,
rho_)
2055 w(ix^
d,
p_)=gamma_1*(w(ix^
d,
e_)&
2057 +(^
c&w(ix^
d,
b^
c_)**2+)))
2060 end subroutine mhd_to_primitive_origin
2063 subroutine mhd_to_primitive_origin_noe(ixI^L,ixO^L,w,x)
2065 integer,
intent(in) :: ixi^
l, ixo^
l
2066 double precision,
intent(inout) :: w(ixi^s, nw)
2067 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2069 double precision :: inv_rho
2074 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_origin_noe')
2077 {
do ix^db=ixomin^db,ixomax^db\}
2078 inv_rho = 1.d0/w(ix^
d,
rho_)
2083 end subroutine mhd_to_primitive_origin_noe
2086 subroutine mhd_to_primitive_hde(ixI^L,ixO^L,w,x)
2088 integer,
intent(in) :: ixi^
l, ixo^
l
2089 double precision,
intent(inout) :: w(ixi^s, nw)
2090 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2092 double precision :: inv_rho
2097 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_hde')
2100 {
do ix^db=ixomin^db,ixomax^db\}
2101 inv_rho = 1d0/w(ix^
d,
rho_)
2108 end subroutine mhd_to_primitive_hde
2111 subroutine mhd_to_primitive_inte(ixI^L,ixO^L,w,x)
2113 integer,
intent(in) :: ixi^
l, ixo^
l
2114 double precision,
intent(inout) :: w(ixi^s, nw)
2115 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2117 double precision :: inv_rho
2122 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_inte')
2125 {
do ix^db=ixomin^db,ixomax^db\}
2127 w(ix^
d,
p_)=w(ix^
d,
e_)*gamma_1
2129 inv_rho = 1.d0/w(ix^
d,
rho_)
2133 end subroutine mhd_to_primitive_inte
2136 subroutine mhd_to_primitive_split_rho(ixI^L,ixO^L,w,x)
2138 integer,
intent(in) :: ixi^
l, ixo^
l
2139 double precision,
intent(inout) :: w(ixi^s, nw)
2140 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2142 double precision :: inv_rho
2147 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_split_rho')
2150 {
do ix^db=ixomin^db,ixomax^db\}
2155 w(ix^
d,
p_)=gamma_1*(w(ix^
d,
e_)&
2157 (^
c&w(ix^
d,
m^
c_)**2+)+(^
c&w(ix^
d,
b^
c_)**2+)))
2160 end subroutine mhd_to_primitive_split_rho
2163 subroutine mhd_to_primitive_semirelati(ixI^L,ixO^L,w,x)
2165 integer,
intent(in) :: ixi^
l, ixo^
l
2166 double precision,
intent(inout) :: w(ixi^s, nw)
2167 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2169 double precision :: e(1:
ndir), tmp, factor
2174 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_semirelati')
2177 {
do ix^db=ixomin^db,ixomax^db\}
2179 tmp=(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)*inv_squared_c
2180 factor=1.0d0/(w(ix^
d,
rho_)*(w(ix^
d,
rho_)+(^
c&w(ix^
d,
b^
c_)**2+)*inv_squared_c))
2185 w(ix^
d,
p_)=gamma_1*w(ix^
d,
e_)
2189 e(1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
2190 e(2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
2191 e(3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
2195 e(2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
2201 w(ix^
d,
p_)=gamma_1*(w(ix^
d,
e_)&
2203 +(^
c&w(ix^
d,
b^
c_)**2+)&
2204 +(^
c&e(^
c)**2+)*inv_squared_c))
2208 end subroutine mhd_to_primitive_semirelati
2211 subroutine mhd_to_primitive_semirelati_noe(ixI^L,ixO^L,w,x)
2213 integer,
intent(in) :: ixi^
l, ixo^
l
2214 double precision,
intent(inout) :: w(ixi^s, nw)
2215 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2217 double precision :: tmp, factor
2222 call mhd_handle_small_values(.false., w, x, ixi^
l, ixo^
l,
'mhd_to_primitive_semirelati_noe')
2225 {
do ix^db=ixomin^db,ixomax^db\}
2227 tmp=(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)*inv_squared_c
2228 factor=1.0d0/(w(ix^
d,
rho_)*(w(ix^
d,
rho_)+(^
c&w(ix^
d,
b^
c_)**2+)*inv_squared_c))
2232 end subroutine mhd_to_primitive_semirelati_noe
2237 integer,
intent(in) :: ixi^
l, ixo^
l
2238 double precision,
intent(inout) :: w(ixi^s, nw)
2239 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2244 {
do ix^db=ixomin^db,ixomax^db\}
2247 +half*((^
c&w(ix^
d,
m^
c_)**2+)/&
2249 +(^
c&w(ix^
d,
b^
c_)**2+))
2252 {
do ix^db=ixomin^db,ixomax^db\}
2254 w(ix^d,
e_)=w(ix^d,
e_)&
2255 +half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)&
2256 +(^
c&w(ix^d,
b^
c_)**2+))
2263 subroutine mhd_ei_to_e_hde(ixI^L,ixO^L,w,x)
2265 integer,
intent(in) :: ixi^
l, ixo^
l
2266 double precision,
intent(inout) :: w(ixi^s, nw)
2267 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2271 {
do ix^db=ixomin^db,ixomax^db\}
2277 end subroutine mhd_ei_to_e_hde
2280 subroutine mhd_ei_to_e_semirelati(ixI^L,ixO^L,w,x)
2282 integer,
intent(in) :: ixi^
l, ixo^
l
2283 double precision,
intent(inout) :: w(ixi^s, nw)
2284 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2286 w(ixo^s,
p_)=w(ixo^s,
e_)*gamma_1
2287 call mhd_to_conserved_semirelati(ixi^
l,ixo^
l,w,x)
2289 end subroutine mhd_ei_to_e_semirelati
2294 integer,
intent(in) :: ixi^
l, ixo^
l
2295 double precision,
intent(inout) :: w(ixi^s, nw)
2296 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2301 {
do ix^db=ixomin^db,ixomax^db\}
2304 -half*((^
c&w(ix^
d,
m^
c_)**2+)/&
2306 +(^
c&w(ix^
d,
b^
c_)**2+))
2309 {
do ix^db=ixomin^db,ixomax^db\}
2311 w(ix^d,
e_)=w(ix^d,
e_)&
2312 -half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)&
2313 +(^
c&w(ix^d,
b^
c_)**2+))
2317 if(fix_small_values)
then
2318 call mhd_handle_small_ei(w,x,ixi^l,ixi^l,
e_,
'mhd_e_to_ei')
2324 subroutine mhd_e_to_ei_hde(ixI^L,ixO^L,w,x)
2326 integer,
intent(in) :: ixi^
l, ixo^
l
2327 double precision,
intent(inout) :: w(ixi^s, nw)
2328 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2332 {
do ix^db=ixomin^db,ixomax^db\}
2338 if(fix_small_values)
then
2339 call mhd_handle_small_ei(w,x,ixi^l,ixi^l,
e_,
'mhd_e_to_ei_hde')
2342 end subroutine mhd_e_to_ei_hde
2345 subroutine mhd_e_to_ei_semirelati(ixI^L,ixO^L,w,x)
2347 integer,
intent(in) :: ixi^
l, ixo^
l
2348 double precision,
intent(inout) :: w(ixi^s, nw)
2349 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
2351 call mhd_to_primitive_semirelati(ixi^
l,ixo^
l,w,x)
2352 w(ixo^s,
e_)=w(ixo^s,
p_)*inv_gamma_1
2354 end subroutine mhd_e_to_ei_semirelati
2356 subroutine mhd_handle_small_values_semirelati(primitive, w, x, ixI^L, ixO^L, subname)
2359 logical,
intent(in) :: primitive
2360 integer,
intent(in) :: ixi^
l,ixo^
l
2361 double precision,
intent(inout) :: w(ixi^s,1:nw)
2362 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2363 character(len=*),
intent(in) :: subname
2365 double precision :: e(ixi^s,1:
ndir), pressure(ixi^s), v(ixi^s,1:
ndir)
2366 double precision :: tmp, factor
2368 logical :: flag(ixi^s,1:nw)
2377 {
do ix^db=ixomin^db,ixomax^db\}
2379 tmp=(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)*inv_squared_c
2380 factor=1.0d0/(w(ix^
d,
rho_)*(w(ix^
d,
rho_)+(^
c&w(ix^
d,
b^
c_)**2+)*inv_squared_c))
2384 e(ix^
d,1)=w(ix^
d,b2_)*v(ix^
d,3)-w(ix^
d,b3_)*v(ix^
d,2)
2385 e(ix^
d,2)=w(ix^
d,b3_)*v(ix^
d,1)-w(ix^
d,b1_)*v(ix^
d,3)
2386 e(ix^
d,3)=w(ix^
d,b1_)*v(ix^
d,2)-w(ix^
d,b2_)*v(ix^
d,1)
2390 e(ix^
d,2)=w(ix^
d,b1_)*v(ix^
d,2)-w(ix^
d,b2_)*v(ix^
d,1)
2396 pressure(ix^
d)=gamma_1*(w(ix^
d,
e_)&
2397 -half*((^
c&v(ix^
d,^
c)**2+)*w(ix^
d,
rho_)&
2398 +(^
c&w(ix^
d,
b^
c_)**2+)+(^
c&e(ix^
d,^
c)**2+)*inv_squared_c))
2405 select case (small_values_method)
2407 {
do ix^db=ixomin^db,ixomax^db\}
2408 if(flag(ix^d,
rho_))
then
2409 w(ix^d,
rho_) = small_density
2410 ^
c&w(ix^d,
m^
c_)=0.d0\
2414 if(flag(ix^d,
e_)) w(ix^d,
p_) = small_pressure
2416 if(flag(ix^d,
e_))
then
2417 w(ix^d,
e_)=small_pressure*inv_gamma_1+half*((^
c&v(ix^d,^
c)**2+)*w(ix^d,
rho_)&
2418 +(^
c&w(ix^d,
b^
c_)**2+)+(^
c&e(ix^d,^
c)**2+)*inv_squared_c)
2425 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2428 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2430 w(ixo^s,
e_)=pressure(ixo^s)
2431 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2432 {
do ix^db=ixomin^db,ixomax^db\}
2433 w(ix^d,
e_)=w(ix^d,
p_)*inv_gamma_1+half*((^
c&v(ix^d,^
c)**2+)*w(ix^d,
rho_)&
2434 +(^
c&w(ix^d,
b^
c_)**2+)+(^
c&e(ix^d,^
c)**2+)*inv_squared_c)
2439 if(.not.primitive)
then
2441 w(ixo^s,
mom(1:ndir))=v(ixo^s,1:ndir)
2442 w(ixo^s,
e_)=pressure(ixo^s)
2444 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2448 end subroutine mhd_handle_small_values_semirelati
2450 subroutine mhd_handle_small_values_origin(primitive, w, x, ixI^L, ixO^L, subname)
2453 logical,
intent(in) :: primitive
2454 integer,
intent(in) :: ixi^
l,ixo^
l
2455 double precision,
intent(inout) :: w(ixi^s,1:nw)
2456 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2457 character(len=*),
intent(in) :: subname
2460 logical :: flag(ixi^s,1:nw)
2462 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2467 {
do ix^db=ixomin^db,ixomax^db\}
2471 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2488 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2490 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2493 {
do ix^db=iximin^db,iximax^db\}
2494 w(ix^d,
e_)=w(ix^d,
e_)&
2495 -half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+))
2497 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2499 {
do ix^db=iximin^db,iximax^db\}
2500 w(ix^d,
e_)=w(ix^d,
e_)&
2501 +half*((^
c&w(ix^d,
m^
c_)**2+)/w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+))
2505 call small_values_average(ixi^l, ixo^l, w, x, flag,
r_e)
2508 if(.not.primitive)
then
2510 {
do ix^db=ixomin^db,ixomax^db\}
2512 w(ix^d,
p_)=gamma_1*(w(ix^d,
e_)&
2513 -half*((^
c&w(ix^d,
m^
c_)**2+)*w(ix^d,
rho_)+(^
c&w(ix^d,
b^
c_)**2+)))
2516 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2520 end subroutine mhd_handle_small_values_origin
2522 subroutine mhd_handle_small_values_split(primitive, w, x, ixI^L, ixO^L, subname)
2525 logical,
intent(in) :: primitive
2526 integer,
intent(in) :: ixi^
l,ixo^
l
2527 double precision,
intent(inout) :: w(ixi^s,1:nw)
2528 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2529 character(len=*),
intent(in) :: subname
2531 double precision :: rho
2533 logical :: flag(ixi^s,1:nw)
2535 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2540 {
do ix^db=ixomin^db,ixomax^db\}
2545 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2558 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2560 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2563 {
do ix^db=iximin^db,iximax^db\}
2565 w(ix^d,
e_)=w(ix^d,
e_)&
2566 -half*((^
c&w(ix^d,
m^
c_)**2+)/rho+(^
c&w(ix^d,
b^
c_)**2+))
2568 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2570 {
do ix^db=iximin^db,iximax^db\}
2572 w(ix^d,
e_)=w(ix^d,
e_)&
2573 +half*((^
c&w(ix^d,
m^
c_)**2+)/rho+(^
c&w(ix^d,
b^
c_)**2+))
2577 if(.not.primitive)
then
2579 {
do ix^db=ixomin^db,ixomax^db\}
2581 ^
c&w(ix^d,
m^
c_)=w(ix^d,
m^
c_)/rho\
2582 w(ix^d,
p_)=gamma_1*(w(ix^d,
e_)&
2583 -half*((^
c&w(ix^d,
m^
c_)**2+)*rho+(^
c&w(ix^d,
b^
c_)**2+)))
2586 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2590 end subroutine mhd_handle_small_values_split
2592 subroutine mhd_handle_small_values_inte(primitive, w, x, ixI^L, ixO^L, subname)
2595 logical,
intent(in) :: primitive
2596 integer,
intent(in) :: ixi^
l,ixo^
l
2597 double precision,
intent(inout) :: w(ixi^s,1:nw)
2598 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2599 character(len=*),
intent(in) :: subname
2602 logical :: flag(ixi^s,1:nw)
2604 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2609 {
do ix^db=ixomin^db,ixomax^db\}
2610 if(flag(ix^
d,
rho_))
then
2612 ^
c&w(ix^
d,
m^
c_)=0.d0\
2622 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2624 call small_values_average(ixi^l, ixo^l, w, x, flag,
p_)
2626 if(.not.primitive)
then
2628 {
do ix^db=ixomin^db,ixomax^db\}
2630 w(ix^d,
p_)=gamma_1*w(ix^d,
e_)
2633 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2637 end subroutine mhd_handle_small_values_inte
2639 subroutine mhd_handle_small_values_noe(primitive, w, x, ixI^L, ixO^L, subname)
2642 logical,
intent(in) :: primitive
2643 integer,
intent(in) :: ixi^
l,ixo^
l
2644 double precision,
intent(inout) :: w(ixi^s,1:nw)
2645 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2646 character(len=*),
intent(in) :: subname
2649 logical :: flag(ixi^s,1:nw)
2651 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2656 {
do ix^db=ixomin^db,ixomax^db\}
2660 if(flag({ix^
d},
rho_)) w({ix^
d},
m^
c_)=0.0d0
2666 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2668 if(.not.primitive)
then
2670 {
do ix^db=ixomin^db,ixomax^db\}
2674 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2678 end subroutine mhd_handle_small_values_noe
2680 subroutine mhd_handle_small_values_hde(primitive, w, x, ixI^L, ixO^L, subname)
2683 logical,
intent(in) :: primitive
2684 integer,
intent(in) :: ixi^
l,ixo^
l
2685 double precision,
intent(inout) :: w(ixi^s,1:nw)
2686 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2687 character(len=*),
intent(in) :: subname
2690 logical :: flag(ixi^s,1:nw)
2692 call phys_check_w(primitive, ixi^
l, ixo^
l, w, flag)
2697 {
do ix^db=ixomin^db,ixomax^db\}
2698 if(flag(ix^
d,
rho_))
then
2700 ^
c&w(ix^
d,
m^
c_)=0.d0\
2710 call small_values_average(ixi^l, ixo^l, w, x, flag,
rho_)
2712 call small_values_average(ixi^l, ixo^l, w, x, flag,
e_)
2714 if(.not.primitive)
then
2716 {
do ix^db=ixomin^db,ixomax^db\}
2718 w(ix^d,
p_)=gamma_1*(w(ix^d,
e_)-half*(^
c&w(ix^d,
m^
c_)**2+)*w(ix^d,
rho_))
2721 call small_values_error(w, x, ixi^l, ixo^l, flag, subname)
2725 end subroutine mhd_handle_small_values_hde
2731 integer,
intent(in) :: ixi^
l, ixo^
l
2732 double precision,
intent(in) :: w(ixi^s,nw), x(ixi^s,1:
ndim)
2733 double precision,
intent(out) :: v(ixi^s,
ndir)
2735 double precision :: rho(ixi^s)
2740 rho(ixo^s)=1.d0/rho(ixo^s)
2743 v(ixo^s, idir) = w(ixo^s,
mom(idir))*rho(ixo^s)
2749 subroutine mhd_get_csound2(w,x,ixI^L,ixO^L,cs2)
2752 integer,
intent(in) :: ixi^
l, ixo^
l
2753 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
2754 double precision,
intent(inout) :: cs2(ixi^s)
2756 double precision :: rho, inv_rho, ploc
2759 {
do ix^db=ixomin^db,ixomax^db \}
2771 end subroutine mhd_get_csound2
2774 subroutine mhd_get_cmax_origin(w,x,ixI^L,ixO^L,idim,cmax)
2777 integer,
intent(in) :: ixi^
l, ixo^
l, idim
2778 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
2779 double precision,
intent(inout) :: cmax(ixi^s)
2781 double precision :: rho, inv_rho, ploc, cfast2, avmincs2, b2, kmax
2787 {
do ix^db=ixomin^db,ixomax^db \}
2800 cfast2=b2*inv_rho+cmax(ix^
d)
2801 avmincs2=cfast2**2-4.0d0*cmax(ix^
d)*(w(ix^
d,mag(idim))+
block%B0(ix^
d,idim,
b0i))**2*inv_rho
2802 if(avmincs2<zero) avmincs2=zero
2803 cmax(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
2807 cmax(ix^
d)=max(cmax(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
2809 cmax(ix^
d)=abs(w(ix^
d,
mom(idim)))+cmax(ix^
d)
2812 {
do ix^db=ixomin^db,ixomax^db \}
2815 ploc=(w(ix^d,
p_)+block%equi_vars(ix^d,
equi_pe0_,b0i))
2824 b2=(^
c&w(ix^d,
b^
c_)**2+)
2825 cfast2=b2*inv_rho+cmax(ix^d)
2826 avmincs2=cfast2**2-4.0d0*cmax(ix^d)*w(ix^d,mag(idim))**2*inv_rho
2827 if(avmincs2<zero) avmincs2=zero
2828 cmax(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
2832 cmax(ix^d)=max(cmax(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
2834 cmax(ix^d)=abs(w(ix^d,
mom(idim)))+cmax(ix^d)
2838 end subroutine mhd_get_cmax_origin
2841 subroutine mhd_get_cmax_origin_noe(w,x,ixI^L,ixO^L,idim,cmax)
2845 integer,
intent(in) :: ixi^
l, ixo^
l, idim
2846 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
2847 double precision,
intent(inout) :: cmax(ixi^s)
2849 double precision :: rho, inv_rho, cfast2, avmincs2, b2, kmax
2850 double precision :: adiabs(ixi^s), gammas(ixi^s)
2865 {
do ix^db=ixomin^db,ixomax^db \}
2869 cmax(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*rho**(gammas(ix^
d)-1.d0)
2871 b2=(^
c&w(ix^
d,
b^
c_)**2+)
2872 cfast2=b2*inv_rho+cmax(ix^
d)
2873 avmincs2=cfast2**2-4.0d0*cmax(ix^
d)*w(ix^
d,mag(idim))**2*inv_rho
2874 if(avmincs2<zero) avmincs2=zero
2875 cmax(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
2879 cmax(ix^
d)=max(cmax(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
2881 cmax(ix^
d)=abs(w(ix^
d,
mom(idim)))+cmax(ix^
d)
2884 end subroutine mhd_get_cmax_origin_noe
2887 subroutine mhd_get_cmax_semirelati(w,x,ixI^L,ixO^L,idim,cmax)
2890 integer,
intent(in) :: ixi^
l, ixo^
l, idim
2891 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
2892 double precision,
intent(inout):: cmax(ixi^s)
2894 double precision :: csound, avmincs2, idim_alfven_speed2
2895 double precision :: inv_rho, alfven_speed2, gamma2
2898 {
do ix^db=ixomin^db,ixomax^db \}
2899 inv_rho=1.d0/w(ix^
d,
rho_)
2900 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
2901 gamma2=1.0d0/(1.d0+alfven_speed2*inv_squared_c)
2902 cmax(ix^
d)=1.d0-gamma2*w(ix^
d,
mom(idim))**2*inv_squared_c
2905 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
2908 alfven_speed2=alfven_speed2*cmax(ix^
d)+csound*(1.d0+idim_alfven_speed2*inv_squared_c)
2909 avmincs2=(gamma2*alfven_speed2)**2-4.0d0*gamma2*csound*idim_alfven_speed2*cmax(ix^
d)
2910 if(avmincs2<zero) avmincs2=zero
2912 csound = sqrt(half*(gamma2*alfven_speed2+sqrt(avmincs2)))
2913 cmax(ix^
d)=gamma2*abs(w(ix^
d,
mom(idim)))+csound
2916 end subroutine mhd_get_cmax_semirelati
2919 subroutine mhd_get_cmax_semirelati_noe(w,x,ixI^L,ixO^L,idim,cmax)
2923 integer,
intent(in) :: ixi^
l, ixo^
l, idim
2924 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
2925 double precision,
intent(inout):: cmax(ixi^s)
2927 double precision :: adiabs(ixi^s), gammas(ixi^s)
2928 double precision :: csound, avmincs2, idim_alfven_speed2
2929 double precision :: inv_rho, alfven_speed2, gamma2
2943 {
do ix^db=ixomin^db,ixomax^db \}
2944 inv_rho=1.d0/w(ix^
d,
rho_)
2945 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
2946 gamma2=1.0d0/(1.d0+alfven_speed2*inv_squared_c)
2947 cmax(ix^
d)=1.d0-gamma2*w(ix^
d,
mom(idim))**2*inv_squared_c
2948 csound=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
2949 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
2952 alfven_speed2=alfven_speed2*cmax(ix^
d)+csound*(1.d0+idim_alfven_speed2*inv_squared_c)
2953 avmincs2=(gamma2*alfven_speed2)**2-4.0d0*gamma2*csound*idim_alfven_speed2*cmax(ix^
d)
2954 if(avmincs2<zero) avmincs2=zero
2956 csound = sqrt(half*(gamma2*alfven_speed2+sqrt(avmincs2)))
2957 cmax(ix^
d)=gamma2*abs(w(ix^
d,
mom(idim)))+csound
2960 end subroutine mhd_get_cmax_semirelati_noe
2963 subroutine mhd_get_tcutoff(ixI^L,ixO^L,w,x,Tco_local,Tmax_local)
2966 integer,
intent(in) :: ixi^
l,ixo^
l
2967 double precision,
intent(in) :: x(ixi^s,1:
ndim)
2969 double precision,
intent(inout) :: w(ixi^s,1:nw)
2970 double precision,
intent(out) :: tco_local,tmax_local
2972 double precision,
parameter :: trac_delta=0.25d0
2973 double precision :: te(ixi^s),lts(ixi^s)
2974 double precision,
dimension(1:ndim) :: bdir, bunitvec
2975 double precision,
dimension(ixI^S,1:ndim) :: gradt
2976 double precision :: ltrc,ltrp,altr
2977 integer :: idims,ix^
d,jxo^
l,hxo^
l,ixa^
d,ixb^
d
2978 integer :: jxp^
l,hxp^
l,ixp^
l,ixq^
l
2981 call mhd_get_temperature_from_te(w,x,ixi^
l,ixi^
l,te)
2984 te(ixi^s)=w(ixi^s,
p_)/(te(ixi^s)*w(ixi^s,
rho_))
2987 tmax_local=maxval(te(ixo^s))
2995 do ix1=ixomin1,ixomax1
2996 lts(ix1)=0.5d0*abs(te(ix1+1)-te(ix1-1))/te(ix1)
2997 if(lts(ix1)>trac_delta)
then
2998 tco_local=max(tco_local,te(ix1))
3010 lts(ixp^s)=0.5d0*abs(te(jxp^s)-te(hxp^s))/te(ixp^s)
3011 lts(ixp^s)=max(one, (exp(lts(ixp^s))/ltrc)**ltrp)
3012 lts(ixo^s)=0.25d0*(lts(jxo^s)+two*lts(ixo^s)+lts(hxo^s))
3013 block%wextra(ixo^s,
tcoff_)=te(ixo^s)*lts(ixo^s)**0.4d0
3015 call mpistop(
"mhd_trac_type not allowed for 1D simulation")
3026 call gradient(te,ixi^
l,ixo^
l,idims,gradt(ixi^s,idims))
3033 ixb^
d=(ixomin^
d+ixomax^
d-1)/2+ixa^
d;
3038 ixb^d=(ixomin^d+ixomax^d-1)/2+ixa^d;
3039 bdir(1:ndim)=bdir(1:ndim)+w(ixb^d,iw_mag(1:ndim))
3043 if(bdir(1)/=0.d0)
then
3044 block%special_values(3)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3046 block%special_values(3)=0.d0
3048 if(bdir(2)/=0.d0)
then
3049 block%special_values(4)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3051 block%special_values(4)=0.d0
3055 if(bdir(1)/=0.d0)
then
3056 block%special_values(3)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+&
3057 (bdir(3)/bdir(1))**2)
3059 block%special_values(3)=0.d0
3061 if(bdir(2)/=0.d0)
then
3062 block%special_values(4)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+&
3063 (bdir(3)/bdir(2))**2)
3065 block%special_values(4)=0.d0
3067 if(bdir(3)/=0.d0)
then
3068 block%special_values(5)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+&
3069 (bdir(2)/bdir(3))**2)
3071 block%special_values(5)=0.d0
3076 block%special_values(1)=zero
3077 {
do ix^db=ixomin^db,ixomax^db\}
3079 ^d&bdir(^d)=w({ix^d},iw_mag(^d))+block%B0({ix^d},^d,0)\
3081 ^d&bdir(^d)=w({ix^d},iw_mag(^d))\
3084 if(bdir(1)/=0.d0)
then
3085 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3089 if(bdir(2)/=0.d0)
then
3090 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3095 lts(ix^d)=min(block%ds(ix^d,1),block%ds(ix^d,2))*&
3096 abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3099 if(bdir(1)/=0.d0)
then
3100 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+(bdir(3)/bdir(1))**2)
3104 if(bdir(2)/=0.d0)
then
3105 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+(bdir(3)/bdir(2))**2)
3109 if(bdir(3)/=0.d0)
then
3110 bunitvec(3)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+(bdir(2)/bdir(3))**2)
3115 lts(ix^d)=min(block%ds(ix^d,1),block%ds(ix^d,2),block%ds(ix^d,3))*&
3116 abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3118 if(lts(ix^d)>trac_delta)
then
3119 block%special_values(1)=max(block%special_values(1),te(ix^d))
3122 block%special_values(2)=tmax_local
3141 call gradient(te,ixi^l,ixq^l,idims,gradt(ixi^s,idims))
3142 call gradientf(te,x,ixi^l,hxp^l,idims,gradt(ixi^s,idims),nghostcells,.true.)
3143 call gradientf(te,x,ixi^l,jxp^l,idims,gradt(ixi^s,idims),nghostcells,.false.)
3147 {
do ix^db=ixpmin^db,ixpmax^db\}
3148 ^d&bdir(^d)=w({ix^d},iw_mag(^d))+block%B0({ix^d},^d,0)\
3150 if(bdir(1)/=0.d0)
then
3151 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2)
3155 if(bdir(2)/=0.d0)
then
3156 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2)
3162 if(bdir(1)/=0.d0)
then
3163 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+(bdir(3)/bdir(1))**2)
3167 if(bdir(2)/=0.d0)
then
3168 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+(bdir(3)/bdir(2))**2)
3172 if(bdir(3)/=0.d0)
then
3173 bunitvec(3)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+(bdir(2)/bdir(3))**2)
3179 lts(ix^d)=abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3181 lts(ix^d)=min(^d&block%ds({ix^d},^d))*lts(ix^d)
3182 lts(ix^d)=max(one,(exp(lts(ix^d))/ltrc)**ltrp)
3185 {
do ix^db=ixpmin^db,ixpmax^db\}
3187 if(w(ix^d,iw_mag(1))/=0.d0)
then
3188 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)
3192 if(w(ix^d,iw_mag(2))/=0.d0)
then
3193 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)
3199 if(w(ix^d,iw_mag(1))/=0.d0)
then
3200 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+&
3201 (w(ix^d,iw_mag(3))/w(ix^d,iw_mag(1)))**2)
3205 if(w(ix^d,iw_mag(2))/=0.d0)
then
3206 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+&
3207 (w(ix^d,iw_mag(3))/w(ix^d,iw_mag(2)))**2)
3211 if(w(ix^d,iw_mag(3))/=0.d0)
then
3212 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+&
3213 (w(ix^d,iw_mag(2))/w(ix^d,iw_mag(3)))**2)
3219 lts(ix^d)=abs(^d&gradt({ix^d},^d)*bunitvec(^d)+)/te(ix^d)
3221 lts(ix^d)=min(^d&block%ds({ix^d},^d))*lts(ix^d)
3222 lts(ix^d)=max(one,(exp(lts(ix^d))/ltrc)**ltrp)
3228 {
do ix^db=ixpmin^db,ixpmax^db\}
3230 altr=0.25d0*((lts(ix1-1,ix2)+two*lts(ix^d)+lts(ix1+1,ix2))*bunitvec(1)**2+&
3231 (lts(ix1,ix2-1)+two*lts(ix^d)+lts(ix1,ix2+1))*bunitvec(2)**2)
3232 block%wextra(ix^d,
tcoff_)=te(ix^d)*altr**0.4d0
3235 altr=0.25d0*((lts(ix1-1,ix2,ix3)+two*lts(ix^d)+lts(ix1+1,ix2,ix3))*bunitvec(1)**2+&
3236 (lts(ix1,ix2-1,ix3)+two*lts(ix^d)+lts(ix1,ix2+1,ix3))*bunitvec(2)**2+&
3237 (lts(ix1,ix2,ix3-1)+two*lts(ix^d)+lts(ix1,ix2,ix3+1))*bunitvec(3)**2)
3238 block%wextra(ix^d,
tcoff_)=te(ix^d)*altr**0.4d0
3244 call mpistop(
"unknown mhd_trac_type")
3247 end subroutine mhd_get_tcutoff
3250 subroutine mhd_get_h_speed(wprim,x,ixI^L,ixO^L,idim,Hspeed)
3253 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3254 double precision,
intent(in) :: wprim(ixi^s, nw)
3255 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3256 double precision,
intent(out) :: hspeed(ixi^s,1:number_species)
3258 double precision :: csound(ixi^s,
ndim)
3259 double precision,
allocatable :: tmp(:^
d&)
3260 integer :: jxc^
l, ixc^
l, ixa^
l, id, ix^
d
3264 allocate(tmp(ixa^s))
3267 call mhd_get_csound_prim_split(wprim,x,ixi^
l,ixa^
l,id,tmp)
3269 call mhd_get_csound_prim(wprim,x,ixi^
l,ixa^
l,id,tmp)
3271 csound(ixa^s,id)=tmp(ixa^s)
3274 ixcmin^
d=ixomin^
d+
kr(idim,^
d)-1;
3275 jxcmax^
d=ixcmax^
d+
kr(idim,^
d);
3276 jxcmin^
d=ixcmin^
d+
kr(idim,^
d);
3277 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))
3281 ixamax^
d=ixcmax^
d+
kr(id,^
d);
3282 ixamin^
d=ixcmin^
d+
kr(id,^
d);
3283 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)))
3284 ixamax^
d=ixcmax^
d-
kr(id,^
d);
3285 ixamin^
d=ixcmin^
d-
kr(id,^
d);
3286 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)))
3291 ixamax^
d=jxcmax^
d+
kr(id,^
d);
3292 ixamin^
d=jxcmin^
d+
kr(id,^
d);
3293 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)))
3294 ixamax^
d=jxcmax^
d-
kr(id,^
d);
3295 ixamin^
d=jxcmin^
d-
kr(id,^
d);
3296 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)))
3300 end subroutine mhd_get_h_speed
3303 subroutine mhd_get_cbounds(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3306 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3307 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3308 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3309 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3310 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3311 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3312 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3314 double precision :: wmean(ixi^s,nw), csoundl(ixo^s), csoundr(ixo^s)
3315 double precision :: umean, dmean, tmp1, tmp2, tmp3
3322 call mhd_get_csound_prim(wlp,x,ixi^
l,ixo^
l,idim,csoundl)
3323 call mhd_get_csound_prim(wrp,x,ixi^
l,ixo^
l,idim,csoundr)
3324 if(
present(cmin))
then
3325 {
do ix^db=ixomin^db,ixomax^db\}
3326 tmp1=sqrt(wlp(ix^
d,
rho_))
3327 tmp2=sqrt(wrp(ix^
d,
rho_))
3328 tmp3=1.d0/(tmp1+tmp2)
3329 umean=(wlp(ix^
d,
mom(idim))*tmp1+wrp(ix^
d,
mom(idim))*tmp2)*tmp3
3330 dmean=sqrt((tmp1*csoundl(ix^
d)**2+tmp2*csoundr(ix^
d)**2)*tmp3+&
3331 half*tmp1*tmp2*tmp3**2*(wrp(ix^
d,
mom(idim))-wlp(ix^
d,
mom(idim)))**2)
3332 cmin(ix^
d,1)=umean-dmean
3333 cmax(ix^
d,1)=umean+dmean
3335 if(h_correction)
then
3336 {
do ix^db=ixomin^db,ixomax^db\}
3337 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3338 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3342 {
do ix^db=ixomin^db,ixomax^db\}
3343 tmp1=sqrt(wlp(ix^d,
rho_))
3344 tmp2=sqrt(wrp(ix^d,
rho_))
3345 tmp3=1.d0/(tmp1+tmp2)
3346 umean=(wlp(ix^d,
mom(idim))*tmp1+wrp(ix^d,
mom(idim))*tmp2)*tmp3
3347 dmean=sqrt((tmp1*csoundl(ix^d)**2+tmp2*csoundr(ix^d)**2)*tmp3+&
3348 half*tmp1*tmp2*tmp3**2*(wrp(ix^d,
mom(idim))-wlp(ix^d,
mom(idim)))**2)
3349 cmax(ix^d,1)=abs(umean)+dmean
3353 wmean(ixo^s,1:nwflux)=0.5d0*(wlp(ixo^s,1:nwflux)+wrp(ixo^s,1:nwflux))
3354 call mhd_get_csound_prim(wmean,x,ixi^l,ixo^l,idim,csoundr)
3355 if(
present(cmin))
then
3356 {
do ix^db=ixomin^db,ixomax^db\}
3357 cmax(ix^d,1)=max(wmean(ix^d,
mom(idim))+csoundr(ix^d),zero)
3358 cmin(ix^d,1)=min(wmean(ix^d,
mom(idim))-csoundr(ix^d),zero)
3360 if(h_correction)
then
3361 {
do ix^db=ixomin^db,ixomax^db\}
3362 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3363 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3367 cmax(ixo^s,1)=abs(wmean(ixo^s,
mom(idim)))+csoundr(ixo^s)
3371 call mhd_get_csound_prim(wlp,x,ixi^l,ixo^l,idim,csoundl)
3372 call mhd_get_csound_prim(wrp,x,ixi^l,ixo^l,idim,csoundr)
3373 if(
present(cmin))
then
3374 {
do ix^db=ixomin^db,ixomax^db\}
3375 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3376 cmin(ix^d,1)=min(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))-csoundl(ix^d)
3377 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3379 if(h_correction)
then
3380 {
do ix^db=ixomin^db,ixomax^db\}
3381 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3382 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3386 {
do ix^db=ixomin^db,ixomax^db\}
3387 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3388 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3393 end subroutine mhd_get_cbounds
3396 subroutine mhd_get_cbounds_semirelati(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3399 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3400 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3401 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3402 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3403 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3404 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3405 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3407 double precision,
dimension(ixO^S) :: csoundl, csoundr, gamma2l, gamma2r
3412 call mhd_get_csound_semirelati(wlp,x,ixi^
l,ixo^
l,idim,csoundl,gamma2l)
3413 call mhd_get_csound_semirelati(wrp,x,ixi^
l,ixo^
l,idim,csoundr,gamma2r)
3415 call mhd_get_csound_semirelati_noe(wlp,x,ixi^
l,ixo^
l,idim,csoundl,gamma2l)
3416 call mhd_get_csound_semirelati_noe(wrp,x,ixi^
l,ixo^
l,idim,csoundr,gamma2r)
3418 if(
present(cmin))
then
3419 {
do ix^db=ixomin^db,ixomax^db\}
3420 csoundl(ix^
d)=max(csoundl(ix^
d),csoundr(ix^
d))
3421 cmin(ix^
d,1)=min(gamma2l(ix^
d)*wlp(ix^
d,
mom(idim)),gamma2r(ix^
d)*wrp(ix^
d,
mom(idim)))-csoundl(ix^
d)
3422 cmax(ix^
d,1)=max(gamma2l(ix^
d)*wlp(ix^
d,
mom(idim)),gamma2r(ix^
d)*wrp(ix^
d,
mom(idim)))+csoundl(ix^
d)
3425 {
do ix^db=ixomin^db,ixomax^db\}
3426 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3427 cmax(ix^d,1)=max(gamma2l(ix^d)*wlp(ix^d,
mom(idim)),gamma2r(ix^d)*wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3431 end subroutine mhd_get_cbounds_semirelati
3434 subroutine mhd_get_cbounds_split_rho(wLC,wRC,wLp,wRp,x,ixI^L,ixO^L,idim,Hspeed,cmax,cmin)
3437 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3438 double precision,
intent(in) :: wlc(ixi^s, nw), wrc(ixi^s, nw)
3439 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3440 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3441 double precision,
intent(inout) :: cmax(ixi^s,1:number_species)
3442 double precision,
intent(inout),
optional :: cmin(ixi^s,1:number_species)
3443 double precision,
intent(in) :: hspeed(ixi^s,1:number_species)
3445 double precision :: wmean(ixi^s,nw), csoundl(ixo^s), csoundr(ixo^s)
3446 double precision :: umean, dmean, tmp1, tmp2, tmp3
3453 call mhd_get_csound_prim_split(wlp,x,ixi^
l,ixo^
l,idim,csoundl)
3454 call mhd_get_csound_prim_split(wrp,x,ixi^
l,ixo^
l,idim,csoundr)
3455 if(
present(cmin))
then
3456 {
do ix^db=ixomin^db,ixomax^db\}
3459 tmp3=1.d0/(tmp1+tmp2)
3460 umean=(wlp(ix^
d,
mom(idim))*tmp1+wrp(ix^
d,
mom(idim))*tmp2)*tmp3
3461 dmean=sqrt((tmp1*csoundl(ix^
d)**2+tmp2*csoundr(ix^
d)**2)*tmp3+&
3462 half*tmp1*tmp2*tmp3**2*(wrp(ix^
d,
mom(idim))-wlp(ix^
d,
mom(idim)))**2)
3463 cmin(ix^
d,1)=umean-dmean
3464 cmax(ix^
d,1)=umean+dmean
3466 if(h_correction)
then
3467 {
do ix^db=ixomin^db,ixomax^db\}
3468 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3469 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3473 {
do ix^db=ixomin^db,ixomax^db\}
3476 tmp3=1.d0/(tmp1+tmp2)
3477 umean=(wlp(ix^d,
mom(idim))*tmp1+wrp(ix^d,
mom(idim))*tmp2)*tmp3
3478 dmean=sqrt((tmp1*csoundl(ix^d)**2+tmp2*csoundr(ix^d)**2)*tmp3+&
3479 half*tmp1*tmp2*tmp3**2*(wrp(ix^d,
mom(idim))-wlp(ix^d,
mom(idim)))**2)
3480 cmax(ix^d,1)=abs(umean)+dmean
3484 wmean(ixo^s,1:nwflux)=0.5d0*(wlp(ixo^s,1:nwflux)+wrp(ixo^s,1:nwflux))
3485 call mhd_get_csound_prim_split(wmean,x,ixi^l,ixo^l,idim,csoundr)
3486 if(
present(cmin))
then
3487 {
do ix^db=ixomin^db,ixomax^db\}
3488 cmax(ix^d,1)=max(wmean(ix^d,
mom(idim))+csoundr(ix^d),zero)
3489 cmin(ix^d,1)=min(wmean(ix^d,
mom(idim))-csoundr(ix^d),zero)
3491 if(h_correction)
then
3492 {
do ix^db=ixomin^db,ixomax^db\}
3493 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3494 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3498 cmax(ixo^s,1)=abs(wmean(ixo^s,
mom(idim)))+csoundr(ixo^s)
3502 call mhd_get_csound_prim_split(wlp,x,ixi^l,ixo^l,idim,csoundl)
3503 call mhd_get_csound_prim_split(wrp,x,ixi^l,ixo^l,idim,csoundr)
3504 if(
present(cmin))
then
3505 {
do ix^db=ixomin^db,ixomax^db\}
3506 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3507 cmin(ix^d,1)=min(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))-csoundl(ix^d)
3508 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3510 if(h_correction)
then
3511 {
do ix^db=ixomin^db,ixomax^db\}
3512 cmin(ix^d,1)=sign(one,cmin(ix^d,1))*max(abs(cmin(ix^d,1)),hspeed(ix^d,1))
3513 cmax(ix^d,1)=sign(one,cmax(ix^d,1))*max(abs(cmax(ix^d,1)),hspeed(ix^d,1))
3517 {
do ix^db=ixomin^db,ixomax^db\}
3518 csoundl(ix^d)=max(csoundl(ix^d),csoundr(ix^d))
3519 cmax(ix^d,1)=max(wlp(ix^d,
mom(idim)),wrp(ix^d,
mom(idim)))+csoundl(ix^d)
3524 end subroutine mhd_get_cbounds_split_rho
3527 subroutine mhd_get_ct_velocity_average(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3530 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3531 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3532 double precision,
intent(in) :: cmax(ixi^s)
3533 double precision,
intent(in),
optional :: cmin(ixi^s)
3534 type(ct_velocity),
intent(inout):: vcts
3536 end subroutine mhd_get_ct_velocity_average
3538 subroutine mhd_get_ct_velocity_contact(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3541 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3542 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3543 double precision,
intent(in) :: cmax(ixi^s)
3544 double precision,
intent(in),
optional :: cmin(ixi^s)
3545 type(ct_velocity),
intent(inout):: vcts
3547 if(.not.
allocated(vcts%vnorm))
allocate(vcts%vnorm(ixi^s,1:
ndim))
3549 vcts%vnorm(ixo^s,idim)=0.5d0*(wlp(ixo^s,
mom(idim))+wrp(ixo^s,
mom(idim)))
3551 end subroutine mhd_get_ct_velocity_contact
3553 subroutine mhd_get_ct_velocity_hll(vcts,wLp,wRp,ixI^L,ixO^L,idim,cmax,cmin)
3556 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3557 double precision,
intent(in) :: wlp(ixi^s, nw), wrp(ixi^s, nw)
3558 double precision,
intent(in) :: cmax(ixi^s)
3559 double precision,
intent(in),
optional :: cmin(ixi^s)
3560 type(ct_velocity),
intent(inout):: vcts
3562 integer :: idime,idimn
3564 if(.not.
allocated(vcts%vbarC))
then
3565 allocate(vcts%vbarC(ixi^s,1:
ndir,2),vcts%vbarLC(ixi^s,1:
ndir,2),vcts%vbarRC(ixi^s,1:
ndir,2))
3566 allocate(vcts%cbarmin(ixi^s,1:
ndim),vcts%cbarmax(ixi^s,1:
ndim))
3569 if(
present(cmin))
then
3570 vcts%cbarmin(ixo^s,idim)=max(-cmin(ixo^s),zero)
3571 vcts%cbarmax(ixo^s,idim)=max( cmax(ixo^s),zero)
3573 vcts%cbarmax(ixo^s,idim)=max( cmax(ixo^s),zero)
3574 vcts%cbarmin(ixo^s,idim)=vcts%cbarmax(ixo^s,idim)
3577 idimn=mod(idim,
ndir)+1
3578 idime=mod(idim+1,
ndir)+1
3580 vcts%vbarLC(ixo^s,idim,1)=wlp(ixo^s,
mom(idimn))
3581 vcts%vbarRC(ixo^s,idim,1)=wrp(ixo^s,
mom(idimn))
3582 vcts%vbarC(ixo^s,idim,1)=(vcts%cbarmax(ixo^s,idim)*vcts%vbarLC(ixo^s,idim,1) &
3583 +vcts%cbarmin(ixo^s,idim)*vcts%vbarRC(ixo^s,idim,1))&
3584 /(vcts%cbarmax(ixo^s,idim)+vcts%cbarmin(ixo^s,idim))
3586 vcts%vbarLC(ixo^s,idim,2)=wlp(ixo^s,
mom(idime))
3587 vcts%vbarRC(ixo^s,idim,2)=wrp(ixo^s,
mom(idime))
3588 vcts%vbarC(ixo^s,idim,2)=(vcts%cbarmax(ixo^s,idim)*vcts%vbarLC(ixo^s,idim,2) &
3589 +vcts%cbarmin(ixo^s,idim)*vcts%vbarRC(ixo^s,idim,1))&
3590 /(vcts%cbarmax(ixo^s,idim)+vcts%cbarmin(ixo^s,idim))
3592 end subroutine mhd_get_ct_velocity_hll
3599 integer,
intent(in) :: ixi^
l, ixo^
l
3600 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3601 double precision,
intent(out):: csound(ixi^s)
3603 double precision :: wprim(ixi^s, nw)
3605 wprim(ixi^s,1:nw)=w(ixi^s,1:nw)
3618 integer,
intent(in) :: ixi^
l, ixo^
l
3619 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3620 double precision,
intent(out):: csound(ixi^s)
3622 double precision :: inv_rho, b2
3623 double precision :: prad_tensor(ixi^s, 1:
ndim, 1:
ndim)
3624 double precision :: prad_max(ixi^s)
3630 {
do ix^db=ixomin^db,ixomax^db \}
3631 inv_rho=1.d0/w(ix^
d,
rho_)
3632 prad_max(ix^
d) = maxval(prad_tensor(ix^
d,:,:))
3637 {
do ix^db=ixomin^db,ixomax^db \}
3638 inv_rho=1.d0/w(ix^d,
rho_)
3639 prad_max(ix^d) = maxval(prad_tensor(ix^d,:,:))
3640 b2=(^
c&w(ix^d,
b^
c_)**2+)
3641 csound(ix^d)=(
mhd_gamma*w(ix^d,
p_)+b2+prad_max(ix^d))*inv_rho
3645 if(minval(csound(ixo^s))<smalldouble)
then
3646 print *,
'issue with squared speed and rad pressure'
3647 print *,minval(csound(ixo^s))
3648 print *,minval(prad_max(ixo^s))
3649 call mpistop(
"negative squared speed in get_csrad2 for dt")
3655 subroutine mhd_get_csound_prim(w,x,ixI^L,ixO^L,idim,csound)
3659 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3660 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3661 double precision,
intent(out):: csound(ixo^s)
3663 double precision :: adiabs(ixi^s), gammas(ixi^s)
3664 double precision :: inv_rho, cfast2, avmincs2, b2, kmax
3684 {
do ix^db=ixomin^db,ixomax^db \}
3685 inv_rho=1.d0/w(ix^
d,
rho_)
3689 csound(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
3692 cfast2=b2*inv_rho+csound(ix^
d)
3693 avmincs2=cfast2**2-4.0d0*csound(ix^
d)*(w(ix^
d,mag(idim))+&
3695 if(avmincs2<zero) avmincs2=zero
3696 csound(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3698 csound(ix^
d)=max(csound(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3702 {
do ix^db=ixomin^db,ixomax^db \}
3703 inv_rho=1.d0/w(ix^d,
rho_)
3707 csound(ix^d)=gammas(ix^d)*adiabs(ix^d)*w(ix^d,
rho_)**(gammas(ix^d)-1.d0)
3709 b2=(^
c&w(ix^d,
b^
c_)**2+)
3710 cfast2=b2*inv_rho+csound(ix^d)
3711 avmincs2=cfast2**2-4.0d0*csound(ix^d)*w(ix^d,mag(idim))**2*inv_rho
3712 if(avmincs2<zero) avmincs2=zero
3713 csound(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3715 csound(ix^d)=max(csound(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3720 end subroutine mhd_get_csound_prim
3724 subroutine mhd_get_csound_prim_split(w,x,ixI^L,ixO^L,idim,csound)
3727 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3728 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3729 double precision,
intent(out):: csound(ixo^s)
3731 double precision :: rho, inv_rho, cfast2, avmincs2, b2, kmax
3738 {
do ix^db=ixomin^db,ixomax^db \}
3743 cfast2=b2*inv_rho+csound(ix^
d)
3744 avmincs2=cfast2**2-4.0d0*csound(ix^
d)*(w(ix^
d,mag(idim))+&
3746 if(avmincs2<zero) avmincs2=zero
3747 csound(ix^
d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3749 csound(ix^
d)=max(csound(ix^
d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3753 {
do ix^db=ixomin^db,ixomax^db \}
3757 b2=(^
c&w(ix^d,
b^
c_)**2+)
3758 cfast2=b2*inv_rho+csound(ix^d)
3759 avmincs2=cfast2**2-4.0d0*csound(ix^d)*w(ix^d,mag(idim))**2*inv_rho
3760 if(avmincs2<zero) avmincs2=zero
3761 csound(ix^d)=sqrt(half*(cfast2+sqrt(avmincs2)))
3763 csound(ix^d)=max(csound(ix^d),
mhd_etah*sqrt(b2)*inv_rho*kmax)
3768 end subroutine mhd_get_csound_prim_split
3771 subroutine mhd_get_csound_semirelati(w,x,ixI^L,ixO^L,idim,csound,gamma2)
3774 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3776 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3777 double precision,
intent(out):: csound(ixo^s), gamma2(ixo^s)
3779 double precision :: avmincs2, inv_rho, alfven_speed2, idim_alfven_speed2
3782 {
do ix^db=ixomin^db,ixomax^db\}
3783 inv_rho = 1.d0/w(ix^
d,
rho_)
3786 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
3787 gamma2(ix^
d) = 1.0d0/(1.d0+alfven_speed2*inv_squared_c)
3788 avmincs2=1.d0-gamma2(ix^
d)*w(ix^
d,
mom(idim))**2*inv_squared_c
3789 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
3792 alfven_speed2=alfven_speed2*avmincs2+csound(ix^
d)*(1.d0+idim_alfven_speed2*inv_squared_c)
3793 avmincs2=(gamma2(ix^
d)*alfven_speed2)**2-4.0d0*gamma2(ix^
d)*csound(ix^
d)*idim_alfven_speed2*avmincs2
3794 if(avmincs2<zero) avmincs2=zero
3796 csound(ix^
d) = sqrt(half*(gamma2(ix^
d)*alfven_speed2+sqrt(avmincs2)))
3799 end subroutine mhd_get_csound_semirelati
3802 subroutine mhd_get_csound_semirelati_noe(w,x,ixI^L,ixO^L,idim,csound,gamma2)
3806 integer,
intent(in) :: ixi^
l, ixo^
l, idim
3808 double precision,
intent(in) :: w(ixi^s, nw), x(ixi^s,1:
ndim)
3809 double precision,
intent(out):: csound(ixo^s), gamma2(ixo^s)
3811 double precision :: adiabs(ixi^s), gammas(ixi^s)
3812 double precision :: avmincs2, inv_rho, alfven_speed2, idim_alfven_speed2
3825 {
do ix^db=ixomin^db,ixomax^db\}
3826 inv_rho = 1.d0/w(ix^
d,
rho_)
3828 csound(ix^
d)=gammas(ix^
d)*adiabs(ix^
d)*w(ix^
d,
rho_)**(gammas(ix^
d)-1.d0)
3829 alfven_speed2=(^
c&w(ix^
d,
b^
c_)**2+)*inv_rho
3830 gamma2(ix^
d) = 1.0d0/(1.d0+alfven_speed2*inv_squared_c)
3831 avmincs2=1.d0-gamma2(ix^
d)*w(ix^
d,
mom(idim))**2*inv_squared_c
3832 idim_alfven_speed2=w(ix^
d,mag(idim))**2*inv_rho
3835 alfven_speed2=alfven_speed2*avmincs2+csound(ix^
d)*(1.d0+idim_alfven_speed2*inv_squared_c)
3836 avmincs2=(gamma2(ix^
d)*alfven_speed2)**2-4.0d0*gamma2(ix^
d)*csound(ix^
d)*idim_alfven_speed2*avmincs2
3837 if(avmincs2<zero) avmincs2=zero
3839 csound(ix^
d) = sqrt(half*(gamma2(ix^
d)*alfven_speed2+sqrt(avmincs2)))
3842 end subroutine mhd_get_csound_semirelati_noe
3845 subroutine mhd_get_pthermal_noe(w,x,ixI^L,ixO^L,pth)
3849 integer,
intent(in) :: ixi^
l, ixo^
l
3850 double precision,
intent(in) :: w(ixi^s,nw)
3851 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3852 double precision,
intent(out):: pth(ixi^s)
3854 double precision :: adiabs(ixi^s), gammas(ixi^s)
3867 {
do ix^db=ixomin^db,ixomax^db\}
3868 pth(ix^
d)=adiabs(ix^
d)*w(ix^
d,
rho_)**gammas(ix^
d)
3871 end subroutine mhd_get_pthermal_noe
3874 subroutine mhd_get_pthermal_inte(w,x,ixI^L,ixO^L,pth)
3878 integer,
intent(in) :: ixi^
l, ixo^
l
3879 double precision,
intent(in) :: w(ixi^s,nw)
3880 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3881 double precision,
intent(out):: pth(ixi^s)
3885 {
do ix^db= ixomin^db,ixomax^db\}
3886 pth(ix^
d)=gamma_1*w(ix^
d,
e_)
3890 if(check_small_values.and..not.fix_small_values)
then
3891 {
do ix^db= ixomin^db,ixomax^db\}
3892 if(pth(ix^d)<small_pressure)
then
3893 write(*,*)
"Error: small value of gas pressure",pth(ix^d),&
3894 " encountered when call mhd_get_pthermal_inte"
3895 write(*,*)
"Iteration: ", it,
" Time: ", global_time
3896 write(*,*)
"Location: ", x(ix^d,:)
3897 write(*,*)
"Cell number: ", ix^d
3899 write(*,*) trim(cons_wnames(iw)),
": ",w(ix^d,iw)
3902 if(trace_small_values)
write(*,*) sqrt(pth(ix^d)-bigdouble)
3903 write(*,*)
"Saving status at the previous time step"
3909 end subroutine mhd_get_pthermal_inte
3912 subroutine mhd_get_pthermal_origin(w,x,ixI^L,ixO^L,pth)
3916 integer,
intent(in) :: ixi^
l, ixo^
l
3917 double precision,
intent(in) :: w(ixi^s,nw)
3918 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3919 double precision,
intent(out):: pth(ixi^s)
3923 {
do ix^db=ixomin^db,ixomax^db\}
3928 pth(ix^
d)=gamma_1*(w(ix^
d,
e_)-half*((^
c&w(ix^
d,
m^
c_)**2+)/w(ix^
d,
rho_)&
3929 +(^
c&w(ix^
d,
b^
c_)**2+)))
3934 if(check_small_values.and..not.fix_small_values)
then
3935 {
do ix^db=ixomin^db,ixomax^db\}
3936 if(pth(ix^d)<small_pressure)
then
3937 write(*,*)
"Error: small value of gas pressure",pth(ix^d),&
3938 " encountered when call mhd_get_pthermal"
3939 write(*,*)
"Iteration: ", it,
" Time: ", global_time
3940 write(*,*)
"Location: ", x(ix^d,:)
3941 write(*,*)
"Cell number: ", ix^d
3943 write(*,*) trim(cons_wnames(iw)),
": ",w(ix^d,iw)
3946 if(trace_small_values)
write(*,*) sqrt(pth(ix^d)-bigdouble)
3947 write(*,*)
"Saving status at the previous time step"
3953 end subroutine mhd_get_pthermal_origin
3956 subroutine mhd_get_pthermal_semirelati(w,x,ixI^L,ixO^L,pth)
3960 integer,
intent(in) :: ixi^
l, ixo^
l
3961 double precision,
intent(in) :: w(ixi^s,nw)
3962 double precision,
intent(in) :: x(ixi^s,1:
ndim)
3963 double precision,
intent(out):: pth(ixi^s)
3965 double precision :: e(1:
ndir), v(1:
ndir), tmp, factor
3968 {
do ix^db=ixomin^db,ixomax^db\}
3970 tmp=(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)*inv_squared_c
3971 factor=1.0d0/(w(ix^
d,
rho_)*(w(ix^
d,
rho_)+(^
c&w(ix^
d,
b^
c_)**2+)*inv_squared_c))
3976 e(1)=w(ix^
d,b2_)*v(3)-w(ix^
d,b3_)*v(2)
3977 e(2)=w(ix^
d,b3_)*v(1)-w(ix^
d,b1_)*v(3)
3978 e(3)=w(ix^
d,b1_)*v(2)-w(ix^
d,b2_)*v(1)
3982 e(2)=w(ix^
d,b1_)*v(2)-w(ix^
d,b2_)*v(1)
3988 pth(ix^
d)=gamma_1*(w(ix^
d,
e_)&
3989 -half*((^
c&v(^
c)**2+)*w(ix^
d,
rho_)&
3990 +(^
c&w(ix^
d,
b^
c_)**2+)+(^
c&e(^
c)**2+)*inv_squared_c))
3994 if(check_small_values.and..not.fix_small_values)
then
3995 {
do ix^db=ixomin^db,ixomax^db\}
3996 if(pth(ix^d)<small_pressure)
then
3997 write(*,*)
"Error: small value of gas pressure",pth(ix^d),&
3998 " encountered when call mhd_get_pthermal_semirelati"
3999 write(*,*)
"Iteration: ", it,
" Time: ", global_time
4000 write(*,*)
"Location: ", x(ix^d,:)
4001 write(*,*)
"Cell number: ", ix^d
4003 write(*,*) trim(cons_wnames(iw)),
": ",w(ix^d,iw)
4006 if(trace_small_values)
write(*,*) sqrt(pth(ix^d)-bigdouble)
4007 write(*,*)
"Saving status at the previous time step"
4013 end subroutine mhd_get_pthermal_semirelati
4016 subroutine mhd_get_pthermal_hde(w,x,ixI^L,ixO^L,pth)
4020 integer,
intent(in) :: ixi^
l, ixo^
l
4021 double precision,
intent(in) :: w(ixi^s,nw)
4022 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4023 double precision,
intent(out):: pth(ixi^s)
4027 {
do ix^db= ixomin^db,ixomax^db\}
4028 pth(ix^
d)=gamma_1*(w(ix^
d,
e_)-half*((^
c&w(ix^
d,
m^
c_)**2+)/w(ix^
d,
rho_)))
4031 if(check_small_values.and..not.fix_small_values)
then
4032 {
do ix^db= ixomin^db,ixomax^db\}
4033 if(pth(ix^d)<small_pressure)
then
4034 write(*,*)
"Error: small value of gas pressure",pth(ix^d),&
4035 " encountered when call mhd_get_pthermal_hde"
4036 write(*,*)
"Iteration: ", it,
" Time: ", global_time
4037 write(*,*)
"Location: ", x(ix^d,:)
4038 write(*,*)
"Cell number: ", ix^d
4040 write(*,*) trim(cons_wnames(iw)),
": ",w(ix^d,iw)
4043 if(trace_small_values)
write(*,*) sqrt(pth(ix^d)-bigdouble)
4044 write(*,*)
"Saving status at the previous time step"
4050 end subroutine mhd_get_pthermal_hde
4053 subroutine mhd_get_temperature_from_te(w, x, ixI^L, ixO^L, res)
4055 integer,
intent(in) :: ixi^
l, ixo^
l
4056 double precision,
intent(in) :: w(ixi^s, 1:nw)
4057 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4058 double precision,
intent(out):: res(ixi^s)
4059 res(ixo^s) = w(ixo^s,
te_)
4060 end subroutine mhd_get_temperature_from_te
4063 subroutine mhd_get_temperature_from_eint(w, x, ixI^L, ixO^L, res)
4065 integer,
intent(in) :: ixi^
l, ixo^
l
4066 double precision,
intent(in) :: w(ixi^s, 1:nw)
4067 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4068 double precision,
intent(out):: res(ixi^s)
4070 double precision :: r(ixi^s)
4073 res(ixo^s) = gamma_1 * w(ixo^s,
e_)/(w(ixo^s,
rho_)*r(ixo^s))
4074 end subroutine mhd_get_temperature_from_eint
4079 integer,
intent(in) :: ixi^
l, ixo^
l
4080 double precision,
intent(in) :: w(ixi^s, 1:nw)
4081 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4082 double precision,
intent(out):: res(ixi^s)
4084 double precision :: r(ixi^s)
4087 res(ixo^s) = w(ixo^s,
p_)/(w(ixo^s,
rho_)*r(ixo^s))
4093 integer,
intent(in) :: ixi^
l, ixo^
l
4094 double precision,
intent(in) :: w(ixi^s, 1:nw)
4095 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4096 double precision,
intent(out):: res(ixi^s)
4098 double precision :: r(ixi^s),rho(ixi^s)
4103 res(ixo^s)=res(ixo^s)/(r(ixo^s)*rho(ixo^s))
4107 subroutine mhd_get_temperature_from_eint_with_equi(w, x, ixI^L, ixO^L, res)
4109 integer,
intent(in) :: ixi^
l, ixo^
l
4110 double precision,
intent(in) :: w(ixi^s, 1:nw)
4111 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4112 double precision,
intent(out):: res(ixi^s)
4114 double precision :: r(ixi^s)
4120 end subroutine mhd_get_temperature_from_eint_with_equi
4122 subroutine mhd_get_temperature_equi(w,x, ixI^L, ixO^L, res)
4124 integer,
intent(in) :: ixi^
l, ixo^
l
4125 double precision,
intent(in) :: w(ixi^s, 1:nw)
4126 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4127 double precision,
intent(out):: res(ixi^s)
4129 double precision :: r(ixi^s)
4135 end subroutine mhd_get_temperature_equi
4137 subroutine mhd_get_rho_equi(w, x, ixI^L, ixO^L, res)
4139 integer,
intent(in) :: ixi^
l, ixo^
l
4140 double precision,
intent(in) :: w(ixi^s, 1:nw)
4141 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4142 double precision,
intent(out):: res(ixi^s)
4144 end subroutine mhd_get_rho_equi
4146 subroutine mhd_get_pe_equi(w,x, ixI^L, ixO^L, res)
4148 integer,
intent(in) :: ixi^
l, ixo^
l
4149 double precision,
intent(in) :: w(ixi^s, 1:nw)
4150 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4151 double precision,
intent(out):: res(ixi^s)
4153 end subroutine mhd_get_pe_equi
4159 integer,
intent(in) :: ixi^
l, ixo^
l
4160 double precision,
intent(in) :: w(ixi^s, 1:nw)
4161 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4162 double precision,
intent(out):: prad(ixi^s, 1:
ndim, 1:
ndim)
4171 integer,
intent(in) :: ixi^
l, ixo^
l
4172 double precision,
intent(in) :: w(ixi^s, 1:nw)
4173 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4174 double precision,
intent(out) :: pth_plus_prad(ixi^s)
4176 double precision :: wprim(ixi^s, 1:nw)
4177 double precision :: prad_tensor(ixi^s, 1:
ndim, 1:
ndim)
4178 double precision :: prad_max(ixi^s)
4181 wprim(ixi^s,1:nw)=w(ixi^s,1:nw)
4184 {
do ix^
d = ixomin^
d,ixomax^
d\}
4185 prad_max(ix^
d) = maxval(prad_tensor(ix^
d,:,:))
4187 pth_plus_prad(ixo^s) = wprim(ixo^s,
p_) + prad_max(ixo^s)
4195 integer,
intent(in) :: ixi^
l, ixo^
l
4196 double precision,
intent(in) :: w(ixi^s, 1:nw)
4197 double precision,
intent(in) :: x(ixi^s, 1:
ndim)
4198 double precision,
intent(out):: trad(ixi^s)
4205 subroutine mhd_get_flux(wC,w,x,ixI^L,ixO^L,idim,f)
4209 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4211 double precision,
intent(in) :: wc(ixi^s,nw)
4213 double precision,
intent(in) :: w(ixi^s,nw)
4214 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4215 double precision,
intent(out) :: f(ixi^s,nwflux)
4217 double precision :: vhall(ixi^s,1:
ndir)
4218 double precision :: ptotal
4222 {
do ix^db=ixomin^db,ixomax^db\}
4235 {
do ix^db=ixomin^db,ixomax^db\}
4239 ^
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_)\
4240 ptotal=w(ix^d,
p_)+half*(^
c&w(ix^d,
b^
c_)**2+)
4242 f(ix^d,
mom(idim))=f(ix^d,
mom(idim))+ptotal
4245 f(ix^d,
e_)=w(ix^d,
mom(idim))*(wc(ix^d,
e_)+ptotal)&
4246 -w(ix^d,mag(idim))*(^
c&w(ix^d,
b^
c_)*w(ix^d,
m^
c_)+)
4248 ^
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_)\
4252 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4253 {
do ix^db=ixomin^db,ixomax^db\}
4254 if(total_energy)
then
4256 f(ix^d,
e_)=f(ix^d,
e_)+vhall(ix^d,idim)*(^
c&w(ix^d,
b^
c_)**2+)&
4257 -w(ix^d,mag(idim))*(^
c&vhall(ix^d,^
c)*w(ix^d,
b^
c_)+)
4260 ^
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))\
4265 {
do ix^db=ixomin^db,ixomax^db\}
4266 f(ix^d,mag(idim))=w(ix^d,
psi_)
4268 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4273 {
do ix^db=ixomin^db,ixomax^db\}
4274 f(ix^d,
r_e)=w(ix^d,
mom(idim))*wc(ix^d,
r_e)
4280 {
do ix^db=ixomin^db,ixomax^db\}
4286 {
do ix^db=ixomin^db,ixomax^db\}
4287 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
q_)*w(ix^d,mag(idim))/(dsqrt(^
c&w({ix^d},
b^
c_)**2+)+smalldouble)
4292 end subroutine mhd_get_flux
4296 subroutine mhd_get_flux_noe(wC,w,x,ixI^L,ixO^L,idim,f)
4301 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4303 double precision,
intent(in) :: wc(ixi^s,nw)
4305 double precision,
intent(in) :: w(ixi^s,nw)
4306 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4307 double precision,
intent(out) :: f(ixi^s,nwflux)
4309 double precision :: vhall(ixi^s,1:
ndir)
4310 double precision :: adiabs(ixi^s), gammas(ixi^s)
4323 {
do ix^db=ixomin^db,ixomax^db\}
4329 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+)
4334 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4335 {
do ix^db=ixomin^db,ixomax^db\}
4337 ^
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))\
4341 {
do ix^db=ixomin^db,ixomax^db\}
4342 f(ix^d,mag(idim))=w(ix^d,
psi_)
4344 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4349 {
do ix^db=ixomin^db,ixomax^db\}
4354 end subroutine mhd_get_flux_noe
4357 subroutine mhd_get_flux_hde(wC,w,x,ixI^L,ixO^L,idim,f)
4361 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4363 double precision,
intent(in) :: wc(ixi^s,nw)
4365 double precision,
intent(in) :: w(ixi^s,nw)
4366 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4367 double precision,
intent(out) :: f(ixi^s,nwflux)
4369 double precision :: vhall(ixi^s,1:
ndir)
4372 {
do ix^db=ixomin^db,ixomax^db\}
4385 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4386 {
do ix^db=ixomin^db,ixomax^db\}
4388 ^
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))\
4392 {
do ix^db=ixomin^db,ixomax^db\}
4393 f(ix^d,mag(idim))=w(ix^d,
psi_)
4395 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4400 {
do ix^db=ixomin^db,ixomax^db\}
4406 {
do ix^db=ixomin^db,ixomax^db\}
4407 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
q_)*w(ix^d,mag(idim))/(dsqrt(^
c&w({ix^d},
b^
c_)**2+)+smalldouble)
4412 end subroutine mhd_get_flux_hde
4419 subroutine mhd_get_flux_split(wC,w,x,ixI^L,ixO^L,idim,f)
4423 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4425 double precision,
intent(in) :: wc(ixi^s,nw)
4427 double precision,
intent(in) :: w(ixi^s,nw)
4428 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4429 double precision,
intent(out) :: f(ixi^s,nwflux)
4431 double precision :: vhall(ixi^s,1:
ndir)
4432 double precision :: ptotal, btotal(ixo^s,1:
ndir)
4435 {
do ix^db=ixomin^db,ixomax^db\}
4443 ptotal=w(ix^
d,
p_)+half*(^
c&w(ix^
d,
b^
c_)**2+)
4447 ptotal=ptotal+(^
c&w(ix^
d,
b^
c_)*
block%B0(ix^
d,^
c,idim)+)
4451 btotal(ix^
d,idim)*w(ix^
d,
b^
c_)-w(ix^
d,mag(idim))*
block%B0(ix^
d,^
c,idim)\
4452 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+ptotal
4454 ^
c&btotal(ix^
d,^
c)=w(ix^
d,
b^
c_)\
4458 f(ix^
d,
mom(idim))=f(ix^
d,
mom(idim))+ptotal
4461 ^
c&f(ix^
d,
b^
c_)=w(ix^
d,
mom(idim))*btotal(ix^
d,^
c)-btotal(ix^
d,idim)*w(ix^
d,
m^
c_)\
4468 f(ix^
d,
e_)=w(ix^
d,
mom(idim))*(wc(ix^
d,
e_)+ptotal)&
4469 -btotal(ix^
d,idim)*(^
c&w(ix^
d,
b^
c_)*w(ix^
d,
m^
c_)+)
4474 {
do ix^db=ixomin^db,ixomax^db\}
4475 f(ix^d,mag(idim))=w(ix^d,
psi_)
4477 f(ix^d,
psi_) = cmax_global**2*w(ix^d,mag(idim))
4482 {
do ix^db=ixomin^db,ixomax^db\}
4483 f(ix^d,
r_e)=w(ix^d,
mom(idim))*wc(ix^d,
r_e)
4488 call mhd_getv_hall(w,x,ixi^l,ixo^l,vhall)
4489 {
do ix^db=ixomin^db,ixomax^db\}
4491 ^
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)\
4492 if(total_energy)
then
4494 f(ix^d,
e_)=f(ix^d,
e_)+vhall(ix^d,idim)*(^
c&w(ix^d,
b^
c_)*btotal(ix^d,^
c)+)&
4495 -btotal(ix^d,idim)*(^
c&vhall(ix^d,^
c)*w(ix^d,
b^
c_)+)
4501 {
do ix^db=ixomin^db,ixomax^db\}
4506 {
do ix^db=ixomin^db,ixomax^db\}
4507 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
q_)*btotal(ix^d,idim)/(dsqrt(^
c&btotal({ix^d},^
c)**2+)+smalldouble)
4512 end subroutine mhd_get_flux_split
4515 subroutine mhd_get_flux_semirelati(wC,w,x,ixI^L,ixO^L,idim,f)
4519 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4521 double precision,
intent(in) :: wc(ixi^s,nw)
4523 double precision,
intent(in) :: w(ixi^s,nw)
4524 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4525 double precision,
intent(out) :: f(ixi^s,nwflux)
4527 double precision :: sa(ixo^s,1:
ndir),e(ixo^s,1:
ndir),e2
4530 {
do ix^db=ixomin^db,ixomax^db\}
4535 e(ix^
d,1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
4536 e(ix^
d,2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
4537 e(ix^
d,3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4542 e(ix^
d,2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4547 e2=(^
c&e(ix^
d,^
c)**2+)
4554 sa(ix^
d,1)=e(ix^
d,2)*w(ix^
d,b3_)-e(ix^
d,3)*w(ix^
d,b2_)
4555 sa(ix^
d,2)=e(ix^
d,3)*w(ix^
d,b1_)-e(ix^
d,1)*w(ix^
d,b3_)
4556 sa(ix^
d,3)=e(ix^
d,1)*w(ix^
d,b2_)-e(ix^
d,2)*w(ix^
d,b1_)
4559 sa(ix^
d,1)=-e(ix^
d,2)*w(ix^
d,b2_)
4560 sa(ix^
d,2)=e(ix^
d,2)*w(ix^
d,b1_)
4573 -w(ix^
d,mag(idim))*w(ix^
d,
b^
c_)-e(ix^
d,idim)*e(ix^
d,^
c)*inv_squared_c\
4575 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)
4582 {
do ix^db=ixomin^db,ixomax^db\}
4583 f(ix^d,mag(idim))=w(ix^d,
psi_)
4585 f(ix^d,
psi_)=cmax_global**2*w(ix^d,mag(idim))
4590 {
do ix^db=ixomin^db,ixomax^db\}
4595 {
do ix^db=ixomin^db,ixomax^db\}
4596 f(ix^d,
e_)=f(ix^d,
e_)+w(ix^d,
q_)*w(ix^d,mag(idim))/(dsqrt(^
c&w({ix^d},
b^
c_)**2+)+smalldouble)
4601 end subroutine mhd_get_flux_semirelati
4603 subroutine mhd_get_flux_semirelati_noe(wC,w,x,ixI^L,ixO^L,idim,f)
4608 integer,
intent(in) :: ixi^
l, ixo^
l, idim
4610 double precision,
intent(in) :: wc(ixi^s,nw)
4612 double precision,
intent(in) :: w(ixi^s,nw)
4613 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4614 double precision,
intent(out) :: f(ixi^s,nwflux)
4616 double precision :: adiabs(ixi^s), gammas(ixi^s)
4617 double precision :: e(ixo^s,1:
ndir),e2
4630 {
do ix^db=ixomin^db,ixomax^db\}
4635 e(ix^
d,1)=w(ix^
d,b2_)*w(ix^
d,m3_)-w(ix^
d,b3_)*w(ix^
d,m2_)
4636 e(ix^
d,2)=w(ix^
d,b3_)*w(ix^
d,m1_)-w(ix^
d,b1_)*w(ix^
d,m3_)
4637 e(ix^
d,3)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4638 e2=(^
c&e(ix^
d,^
c)**2+)
4643 e(ix^
d,2)=w(ix^
d,b1_)*w(ix^
d,m2_)-w(ix^
d,b2_)*w(ix^
d,m1_)
4653 -w(ix^
d,mag(idim))*w(ix^
d,
b^
c_)-e(ix^
d,idim)*e(ix^
d,^
c)*inv_squared_c\
4655 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)
4662 {
do ix^db=ixomin^db,ixomax^db\}
4663 f(ix^d,mag(idim))=w(ix^d,
psi_)
4665 f(ix^d,
psi_)=cmax_global**2*w(ix^d,mag(idim))
4670 {
do ix^db=ixomin^db,ixomax^db\}
4675 end subroutine mhd_get_flux_semirelati_noe
4683 subroutine add_source_ambipolar_internal_energy(qdt,ixI^L,ixO^L,wCT,w,x)
4685 integer,
intent(in) :: ixi^
l, ixo^
l
4686 double precision,
intent(in) :: qdt
4687 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
4688 double precision,
intent(inout) :: w(ixi^s,1:nw)
4690 double precision :: tmp(ixi^s),btot2(ixi^s)
4691 double precision :: jxbxb(ixi^s,1:3)
4693 call mhd_get_jxbxb(wct,x,ixi^
l,ixo^
l,jxbxb)
4696 where (btot2(ixo^s)>smalldouble )
4697 tmp(ixo^s) = sum(jxbxb(ixo^s,1:3)**2,dim=
ndim+1) / btot2(ixo^s)
4704 w(ixo^s,
e_)=w(ixo^s,
e_)- qdt*tmp(ixo^s)
4706 end subroutine add_source_ambipolar_internal_energy
4709 subroutine mhd_get_jxbxb(w,x,ixI^L,ixO^L,res)
4712 integer,
intent(in) :: ixi^
l, ixo^
l
4713 double precision,
intent(in) :: w(ixi^s,nw)
4714 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4715 double precision,
intent(out) :: res(ixi^s,1:3)
4717 double precision :: btot(ixi^s,1:3)
4718 double precision :: current(ixi^s,7-2*
ndir:3)
4719 double precision :: tmp(ixi^s),b2(ixi^s)
4720 integer :: idir, idirmin
4730 btot(ixo^s, idir) = w(ixo^s,mag(idir)) +
block%B0(ixo^s,idir,
b0i)
4734 btot(ixo^s, idir) = w(ixo^s,mag(idir))
4738 tmp(ixo^s)= sum(current(ixo^s,idirmin:3)*btot(ixo^s,idirmin:3),dim=
ndim+1)
4739 b2(ixo^s) = sum(btot(ixo^s,1:3)**2,dim=
ndim+1)
4741 res(ixo^s,idir) = btot(ixo^s,idir) * tmp(ixo^s)
4744 res(ixo^s,idir) = btot(ixo^s,idir) * tmp(ixo^s) - current(ixo^s,idir) * b2(ixo^s)
4749 where (b2(ixo^s)<smalldouble )
4750 res(ixo^s,idir) = zero
4753 end subroutine mhd_get_jxbxb
4759 subroutine sts_set_source_ambipolar(ixI^L,ixO^L,w,x,wres,fix_conserve_at_step,my_dt,igrid,nflux)
4763 integer,
intent(in) :: ixi^
l,ixo^
l,igrid,nflux
4764 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4765 double precision,
intent(inout) :: wres(ixi^s,1:nw), w(ixi^s,1:nw)
4766 double precision,
intent(in) :: my_dt
4767 logical,
intent(in) :: fix_conserve_at_step
4769 double precision,
dimension(ixI^S,1:3) :: tmp,ff
4770 double precision :: fluxall(ixi^s,1:nflux,1:
ndim)
4771 double precision :: fe(ixi^s,
sdim:3)
4772 double precision :: btot(ixi^s,1:3),tmp2(ixi^s)
4773 integer :: i, ixa^
l, ie_
4780 call mhd_get_jxbxb(w,x,ixi^
l,ixa^
l,tmp)
4797 btot(ixa^s,1:3) = 0.d0
4799 btot(ixa^s,1:
ndir) = w(ixa^s,mag(1:
ndir))
4803 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4804 if(fix_conserve_at_step) fluxall(ixi^s,1,1:
ndim)=ff(ixi^s,1:
ndim)
4806 wres(ixo^s,
e_)=-tmp2(ixo^s)
4813 ff(ixa^s,1) = tmp(ixa^s,2)
4814 ff(ixa^s,2) = -tmp(ixa^s,1)
4816 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4817 if(fix_conserve_at_step) fluxall(ixi^s,1+
ndir,1:
ndim)=ff(ixi^s,1:
ndim)
4818 wres(ixo^s,mag(
ndir))=-tmp2(ixo^s)
4821 call update_faces_ambipolar(ixi^
l,ixo^
l,w,x,tmp,fe,btot)
4823 ixamin^
d=ixomin^
d-1;
4824 wres(ixa^s,mag(1:
ndim))=-btot(ixa^s,1:
ndim)
4834 ff(ixa^s,2) = tmp(ixa^s,3)
4835 ff(ixa^s,3) = -tmp(ixa^s,2)
4836 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4837 if(fix_conserve_at_step) fluxall(ixi^s,2,1:
ndim)=ff(ixi^s,1:
ndim)
4839 wres(ixo^s,mag(1))=-tmp2(ixo^s)
4842 ff(ixa^s,1) = -tmp(ixa^s,3)
4844 ff(ixa^s,3) = tmp(ixa^s,1)
4845 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4846 if(fix_conserve_at_step) fluxall(ixi^s,3,1:
ndim)=ff(ixi^s,1:
ndim)
4847 wres(ixo^s,mag(2))=-tmp2(ixo^s)
4853 ff(ixa^s,2) = tmp(ixa^s,3)
4854 ff(ixa^s,3) = -tmp(ixa^s,2)
4855 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4856 if(fix_conserve_at_step) fluxall(ixi^s,2,1:
ndim)=ff(ixi^s,1:
ndim)
4858 wres(ixo^s,mag(1))=-tmp2(ixo^s)
4860 ff(ixa^s,1) = -tmp(ixa^s,3)
4862 ff(ixa^s,3) = tmp(ixa^s,1)
4863 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4864 if(fix_conserve_at_step) fluxall(ixi^s,3,1:
ndim)=ff(ixi^s,1:
ndim)
4865 wres(ixo^s,mag(2))=-tmp2(ixo^s)
4870 ff(ixa^s,1) = tmp(ixa^s,2)
4871 ff(ixa^s,2) = -tmp(ixa^s,1)
4873 call get_flux_on_cell_face(ixi^
l,ixo^
l,ff,tmp2)
4874 if(fix_conserve_at_step) fluxall(ixi^s,1+
ndir,1:
ndim)=ff(ixi^s,1:
ndim)
4875 wres(ixo^s,mag(
ndir))=-tmp2(ixo^s)
4880 if(fix_conserve_at_step)
then
4881 fluxall=my_dt*fluxall
4888 end subroutine sts_set_source_ambipolar
4891 subroutine update_faces_ambipolar(ixI^L,ixO^L,w,x,ECC,fE,circ)
4894 integer,
intent(in) :: ixi^
l, ixo^
l
4895 double precision,
intent(in) :: w(ixi^s,1:nw)
4896 double precision,
intent(in) :: x(ixi^s,1:
ndim)
4898 double precision,
intent(in) :: ecc(ixi^s,1:3)
4899 double precision,
intent(out) :: fe(ixi^s,
sdim:3)
4900 double precision,
intent(out) :: circ(ixi^s,1:
ndim)
4902 integer :: hxc^
l,ixc^
l,ixa^
l
4903 integer :: idim1,idim2,idir,ix^
d
4909 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
4911 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
4912 ixamin^
d=ixcmin^
d+ix^
d;
4913 ixamax^
d=ixcmax^
d+ix^
d;
4914 fe(ixc^s,idir)=fe(ixc^s,idir)+ecc(ixa^s,idir)
4916 fe(ixc^s,idir)=fe(ixc^s,idir)*0.25d0*block%dsC(ixc^s,idir)
4922 ixcmin^d=ixomin^d-1;
4929 hxc^l=ixc^l-kr(idim2,^d);
4931 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
4932 +lvc(idim1,idim2,idir)&
4937 circ(ixc^s,idim1)=circ(ixc^s,idim1)/block%surfaceC(ixc^s,idim1)
4940 end subroutine update_faces_ambipolar
4946 subroutine get_flux_on_cell_face(ixI^L,ixO^L,ff,src)
4949 integer,
intent(in) :: ixi^
l, ixo^
l
4950 double precision,
dimension(ixI^S,1:3),
intent(inout) :: ff
4951 double precision,
intent(out) :: src(ixi^s)
4953 double precision :: ffc(ixi^s,1:
ndim)
4954 double precision :: dxinv(
ndim)
4955 integer :: idims, ix^
d, ixa^
l, ixb^
l, ixc^
l
4963 ixcmax^
d=ixomax^
d; ixcmin^
d=ixomin^
d-1;
4965 ixbmin^
d=ixcmin^
d+ix^
d;
4966 ixbmax^
d=ixcmax^
d+ix^
d;
4969 ffc(ixc^s,1:ndim)=0.5d0**ndim*ffc(ixc^s,1:ndim)
4971 call mpistop(
"to generalize using volume averaging")
4974 ff(ixi^s,1:ndim)=0.d0
4976 ixb^l=ixo^l-kr(idims,^d);
4977 ixcmax^d=ixomax^d; ixcmin^d=ixbmin^d;
4979 if({ ix^d==0 .and. ^d==idims | .or.})
then
4980 ixbmin^d=ixcmin^d-ix^d;
4981 ixbmax^d=ixcmax^d-ix^d;
4982 ff(ixc^s,idims)=ff(ixc^s,idims)+ffc(ixb^s,idims)
4985 ff(ixc^s,idims)=ff(ixc^s,idims)*0.5d0**(ndim-1)
4988 if(slab_uniform)
then
4990 ff(ixa^s,idims)=dxinv(idims)*ff(ixa^s,idims)
4991 ixb^l=ixo^l-kr(idims,^d);
4992 src(ixo^s)=src(ixo^s)+ff(ixo^s,idims)-ff(ixb^s,idims)
4996 ff(ixa^s,idims)=ff(ixa^s,idims)*block%surfaceC(ixa^s,idims)
4997 ixb^l=ixo^l-kr(idims,^d);
4998 src(ixo^s)=src(ixo^s)+ff(ixo^s,idims)-ff(ixb^s,idims)
5000 src(ixo^s)=src(ixo^s)/block%dvolume(ixo^s)
5002 end subroutine get_flux_on_cell_face
5006 function get_ambipolar_dt(w,ixI^L,ixO^L,dx^D,x)
result(dtnew)
5009 integer,
intent(in) :: ixi^
l, ixo^
l
5010 double precision,
intent(in) ::
dx^
d, x(ixi^s,1:
ndim)
5011 double precision,
intent(in) :: w(ixi^s,1:nw)
5012 double precision :: dtnew
5014 double precision :: coef
5015 double precision :: dxarr(
ndim)
5016 double precision :: tmp(ixi^s)
5022 coef = maxval(dabs(tmp(ixo^s)))
5029 dtnew=minval(dxarr(1:
ndim))**2.0d0*coef
5031 dtnew=minval(
block%ds(ixo^s,1:
ndim))**2.0d0*coef
5034 end function get_ambipolar_dt
5042 integer,
intent(in) :: ixi^
l, ixo^
l
5043 double precision,
intent(in) :: w(ixi^s,1:nw), x(ixi^s,1:
ndim)
5044 double precision,
intent(inout) :: res(ixi^s)
5045 double precision :: tmp(ixi^s)
5046 double precision :: rho(ixi^s)
5053 res(ixo^s) = tmp(ixo^s) * res(ixo^s)
5058 subroutine mhd_add_source(qdt,dtfactor,ixI^L,ixO^L,wCT,wCTprim,w,x,qsourcesplit,active)
5065 integer,
intent(in) :: ixi^
l, ixo^
l
5066 double precision,
intent(in) :: qdt,dtfactor
5067 double precision,
intent(in) :: wct(ixi^s,1:nw),wctprim(ixi^s,1:nw), x(ixi^s,1:
ndim)
5068 double precision,
intent(inout) :: w(ixi^s,1:nw)
5069 logical,
intent(in) :: qsourcesplit
5070 logical,
intent(inout) :: active
5077 if (.not. qsourcesplit)
then
5081 call add_source_internal_e(qdt,ixi^
l,ixo^
l,wct,w,x,wctprim)
5085 call add_equi_terms(qdt,dtfactor,ixi^
l,ixo^
l,wct,w,x,wctprim)
5091 call add_hypertc_source(qdt,ixi^
l,ixo^
l,wct,w,x,wctprim)
5100 call add_source_b0split(qdt,dtfactor,ixi^
l,ixo^
l,wct,w,x,wctprim)
5104 if (abs(
mhd_eta)>smalldouble)
then
5106 call add_source_res_exp(qdt,ixi^
l,ixo^
l,wct,w,x)
5111 call add_source_ambi_exp(qdt,ixi^
l,ixo^
l,wct,w,x)
5116 call add_source_hyperres(qdt,ixi^
l,ixo^
l,wct,w,x)
5122 call add_source_hydrodynamic_e(qdt,ixi^
l,ixo^
l,wct,w,x,wctprim)
5126 call add_source_semirelativistic(qdt,ixi^
l,ixo^
l,wct,w,x,wctprim)
5133 select case (type_divb)
5138 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5141 call add_source_glm(qdt,ixi^
l,ixo^
l,wct,w,x)
5144 call add_source_powel(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5145 case (divb_janhunen)
5147 call add_source_janhunen(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5148 case (divb_lindejanhunen)
5150 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5151 call add_source_janhunen(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5152 case (divb_lindepowel)
5154 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5155 call add_source_powel(qdt,ixi^
l,ixo^
l,wctprim,w,x)
5156 case (divb_lindeglm)
5158 call add_source_linde(qdt,ixi^
l,ixo^
l,wct,w,x)
5159 call add_source_glm(qdt,ixi^
l,ixo^
l,wct,w,x)
5160 case (divb_multigrid)
5165 call mpistop(
'Unknown divB fix')
5172 w,x,qsourcesplit,active,
rc_fl)
5182 w,x,gravity_energy,qsourcesplit,active)
5191 call mhd_add_radiation_source(qdt,ixi^
l,ixo^
l,wct,wctprim,w,x,qsourcesplit,active)
5196 if(.not.qsourcesplit)
then
5198 call mhd_update_temperature(ixi^
l,ixo^
l,wct,w,x)
5202 end subroutine mhd_add_source
5204 subroutine mhd_add_radiation_source(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x,qsourcesplit,active)
5210 integer,
intent(in) :: ixi^
l, ixo^
l
5211 double precision,
intent(in) :: qdt, x(ixi^s,1:
ndim)
5212 double precision,
intent(in) :: wct(ixi^s,1:nw),wctprim(ixi^s,1:nw)
5213 double precision,
intent(inout) :: w(ixi^s,1:nw)
5214 logical,
intent(in) :: qsourcesplit
5215 logical,
intent(inout) :: active
5221 end subroutine mhd_add_radiation_source
5224 subroutine add_equi_terms(qdt,dtfactor,ixI^L,ixO^L,wCT,w,x,wCTprim)
5229 integer,
intent(in) :: ixi^
l, ixo^
l
5230 double precision,
intent(in) :: qdt,dtfactor
5231 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5232 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
5233 double precision,
intent(inout) :: w(ixi^s,1:nw)
5235 double precision :: divv(ixi^s)
5236 double precision :: a(ixi^s,3),
b(ixi^s,3), axb(ixi^s,3)
5237 double precision :: gravity_field(ixi^s,1:
ndim)
5249 divv(ixo^s)=divv(ixo^s)*
mhd_gamma*inv_gamma_1
5260 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)*inv_gamma_1
5269 a(ixo^s,idir)=
block%J0(ixo^s,idir)
5274 w(ixo^s,
e_)=w(ixo^s,
e_)-qdt*wctprim(ixo^s,
mom(idir))*axb(ixo^s,idir)*inv_gamma_1
5280 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)*inv_gamma_1
5289 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)*inv_gamma_1
5293 end subroutine add_equi_terms
5295 subroutine add_hypertc_source(qdt,ixI^L,ixO^L,wCT,w,x,wCTprim)
5297 integer,
intent(in) :: ixi^
l,ixo^
l
5298 double precision,
intent(in) :: qdt
5299 double precision,
dimension(ixI^S,1:ndim),
intent(in) :: x
5300 double precision,
dimension(ixI^S,1:nw),
intent(in) :: wct,wctprim
5301 double precision,
dimension(ixI^S,1:nw),
intent(inout) :: w
5303 double precision :: r(ixi^s),te(ixi^s),rho_loc(ixi^s),pth_loc(ixi^s)
5304 double precision :: sigma_t5,sigma_t7,f_sat,sigmat5_bgradt,tau,bdir(
ndir),bunitvec(
ndim)
5305 double precision :: cmax(
ndim),c2,cfast2,avmincs2(
ndim),inv_rho
5309 {
do ix^db=iximin^db,iximax^db\}
5314 rho_loc(ix^
d)=wctprim(ix^
d,
rho_)
5315 pth_loc(ix^
d)=wctprim(ix^
d,
p_)
5317 te(ix^
d)=pth_loc(ix^
d)/(r(ix^
d)*rho_loc(ix^
d))
5323 do ix1=ixomin1,ixomax1
5325 if(te(ix^d)<block%wextra(ix^d,
tcoff_))
then
5327 sigma_t7=sigma_t5*block%wextra(ix^d,
tcoff_)
5330 sigma_t7=sigma_t5*te(ix^d)
5334 sigma_t7=sigma_t5*te(ix^d)
5336 sigmat5_bgradt=sigma_t5*(8.d0*(te(ix1+1)-te(ix1-1))-te(ix1+2)+te(ix1-2))/12.d0/block%ds(ix^d,1)
5337 inv_rho=1.d0/rho_loc(ix1)
5339 cfast2=(^
c&bdir(^
c)**2+)*inv_rho+c2
5340 avmincs2(1)=cfast2**2-4.0d0*c2*bdir(1)**2*inv_rho
5342 cmax(1)=sqrt(half*(cfast2+sqrt(dabs(avmincs2(1)))))\
5345 f_sat=one/(one+dabs(sigmat5_bgradt)/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5346 tau=max(4.d0*dt, f_sat*sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*cmax(1)**2))
5347 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(f_sat*sigmat5_bgradt+wct(ix^d,
q_))/tau
5349 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(sigmat5_bgradt+wct(ix^d,
q_))/&
5350 max(4.d0*dt, sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*cmax(1)**2))
5355 do ix2=ixomin2,ixomax2
5356 do ix1=ixomin1,ixomax1
5358 if(te(ix^d)<block%wextra(ix^d,
tcoff_))
then
5360 sigma_t7=sigma_t5*block%wextra(ix^d,
tcoff_)
5363 sigma_t7=sigma_t5*te(ix^d)
5367 sigma_t7=sigma_t5*te(ix^d)
5370 ^
c&bdir(^
c)=wct({ix^d},mag(^
c))+block%B0({ix^d},^
c,0)\
5372 ^
c&bdir(^
c)=wct({ix^d},mag(^
c))\
5374 if(bdir(1)/=0.d0)
then
5375 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(^ce&(bdir(^ce)/bdir(1))**2+))
5379 if(bdir(2)/=0.d0)
then
5380 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(^cf&(bdir(^cf)/bdir(2))**2+))
5384 sigmat5_bgradt=sigma_t5*(&
5385 bunitvec(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)&
5386 +bunitvec(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))
5387 inv_rho=1.d0/rho_loc(ix^d)
5389 cfast2=(^
c&bdir(^
c)**2+)*inv_rho+c2
5390 ^d&avmincs2(^d)=cfast2**2-4.0d0*c2*bdir(^d)**2*inv_rho\
5392 ^d&cmax(^d)=sqrt(half*(cfast2+sqrt(dabs(avmincs2(^d)))))\
5395 f_sat=one/(one+dabs(sigmat5_bgradt)/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5396 tau=max(4.d0*dt, f_sat*sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*maxval(cmax(:))**2))
5397 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(f_sat*sigmat5_bgradt+wct(ix^d,
q_))/tau
5399 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(sigmat5_bgradt+wct(ix^d,
q_))/&
5400 max(4.d0*dt, sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*maxval(cmax(:))**2))
5406 do ix3=ixomin3,ixomax3
5407 do ix2=ixomin2,ixomax2
5408 do ix1=ixomin1,ixomax1
5410 if(te(ix^d)<block%wextra(ix^d,
tcoff_))
then
5412 sigma_t7=sigma_t5*block%wextra(ix^d,
tcoff_)
5415 sigma_t7=sigma_t5*te(ix^d)
5419 sigma_t7=sigma_t5*te(ix^d)
5422 ^d&bdir(^d)=wct({ix^d},mag(^d))+block%B0({ix^d},^d,0)\
5424 ^d&bdir(^d)=wct({ix^d},mag(^d))\
5426 if(bdir(1)/=0.d0)
then
5427 bunitvec(1)=sign(1.d0,bdir(1))/dsqrt(1.d0+(bdir(2)/bdir(1))**2+(bdir(3)/bdir(1))**2)
5431 if(bdir(2)/=0.d0)
then
5432 bunitvec(2)=sign(1.d0,bdir(2))/dsqrt(1.d0+(bdir(1)/bdir(2))**2+(bdir(3)/bdir(2))**2)
5436 if(bdir(3)/=0.d0)
then
5437 bunitvec(3)=sign(1.d0,bdir(3))/dsqrt(1.d0+(bdir(1)/bdir(3))**2+(bdir(2)/bdir(3))**2)
5441 sigmat5_bgradt=sigma_t5*(&
5442 bunitvec(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)&
5443 +bunitvec(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)&
5444 +bunitvec(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))
5445 inv_rho=1.d0/rho_loc(ix^d)
5447 cfast2=(^
c&bdir(^
c)**2+)*inv_rho+c2
5448 ^d&avmincs2(^d)=cfast2**2-4.0d0*c2*bdir(^d)**2*inv_rho\
5450 ^d&cmax(^d)=sqrt(half*(cfast2+sqrt(dabs(avmincs2(^d)))))\
5453 f_sat=one/(one+dabs(sigmat5_bgradt)/(1.5d0*rho_loc(ix^d)*(pth_loc(ix^d)/rho_loc(ix^d))**1.5d0))
5454 tau=max(4.d0*dt, f_sat*sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*maxval(cmax(:))**2))
5455 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(f_sat*sigmat5_bgradt+wct(ix^d,
q_))/tau
5457 w(ix^d,
q_)=w(ix^d,
q_)-qdt*(sigmat5_bgradt+wct(ix^d,
q_))/&
5458 max(4.d0*dt, sigma_t7*courantpar**2/(pth_loc(ix^d)*inv_gamma_1*maxval(cmax(:))**2))
5464 end subroutine add_hypertc_source
5468 subroutine get_lorentz_force(ixI^L,ixO^L,w,JxB)
5470 integer,
intent(in) :: ixi^
l, ixo^
l
5471 double precision,
intent(in) :: w(ixi^s,1:nw)
5472 double precision,
intent(inout) :: jxb(ixi^s,3)
5473 double precision :: a(ixi^s,3),
b(ixi^s,3)
5475 double precision :: current(ixi^s,7-2*
ndir:3)
5476 integer :: idir, idirmin
5481 b(ixo^s, idir) = w(ixo^s,mag(idir))+
block%B0(ixo^s,idir,0)
5485 b(ixo^s, idir) = w(ixo^s,mag(idir))
5494 a(ixo^s,idir)=current(ixo^s,idir)
5498 end subroutine get_lorentz_force
5502 integer,
intent(in) :: ixi^
l, ixo^
l
5503 double precision,
intent(in) :: w(ixi^s,1:nw),x(ixi^s,1:
ndim)
5504 double precision,
intent(out) :: rho(ixi^s)
5509 rho(ixo^s) = w(ixo^s,
rho_)
5515 subroutine mhd_handle_small_ei(w, x, ixI^L, ixO^L, ie, subname)
5518 integer,
intent(in) :: ixi^
l,ixo^
l, ie
5519 double precision,
intent(inout) :: w(ixi^s,1:nw)
5520 double precision,
intent(in) :: x(ixi^s,1:
ndim)
5521 character(len=*),
intent(in) :: subname
5523 double precision :: rho(ixi^s)
5525 logical :: flag(ixi^s,1:nw)
5530 flag(ixo^s,ie)=.true.
5532 where(w(ixo^s,ie)<
small_e) flag(ixo^s,ie)=.true.
5534 if(any(flag(ixo^s,ie)))
then
5538 where(flag(ixo^s,ie)) w(ixo^s,ie)=
small_e - &
5541 where(flag(ixo^s,ie)) w(ixo^s,ie)=
small_e
5547 w(ixo^s,
e_)=w(ixo^s,
e_)*gamma_1
5550 w(ixo^s,
mom(idir)) = w(ixo^s,
mom(idir))/rho(ixo^s)
5556 end subroutine mhd_handle_small_ei
5558 subroutine mhd_update_temperature(ixI^L,ixO^L,wCT,w,x)
5562 integer,
intent(in) :: ixi^
l, ixo^
l
5563 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5564 double precision,
intent(inout) :: w(ixi^s,1:nw)
5566 double precision :: iz_h(ixo^s),iz_he(ixo^s), pth(ixi^s)
5575 end subroutine mhd_update_temperature
5578 subroutine add_source_b0split(qdt,dtfactor,ixI^L,ixO^L,wCT,w,x,wCTprim)
5581 integer,
intent(in) :: ixi^
l, ixo^
l
5582 double precision,
intent(in) :: qdt, dtfactor,wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5583 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
5584 double precision,
intent(inout) :: w(ixi^s,1:nw)
5586 double precision :: a(ixi^s,3),
b(ixi^s,3), axb(ixi^s,3)
5598 a(ixo^s,idir)=
block%J0(ixo^s,idir)
5603 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
5606 axb(ixo^s,:)=axb(ixo^s,:)*qdt
5612 if(total_energy)
then
5615 b(ixo^s,:)=wctprim(ixo^s,mag(:))
5624 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
5627 axb(ixo^s,:)=axb(ixo^s,:)*qdt
5632 w(ixo^s,
e_)=w(ixo^s,
e_)-axb(ixo^s,idir)*
block%J0(ixo^s,idir)
5636 call mhd_getv_hall(wct,x,ixi^
l,ixo^
l,a,.true.)
5641 axb(ixo^s,idir)=axb(ixo^s,idir)*
block%dt(ixo^s)*dtfactor
5644 axb(ixo^s,:)=axb(ixo^s,:)*qdt
5648 w(ixo^s,
e_)=w(ixo^s,
e_)-axb(ixo^s,idir)*
block%J0(ixo^s,idir)
5656 call mhd_get_jxbxb(wct,x,ixi^
l,ixo^
l,axb)
5661 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*axb(ixo^s,idir)*
block%J0(ixo^s,idir)
5667 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_B0')
5669 end subroutine add_source_b0split
5672 subroutine add_source_semirelativistic(qdt,ixI^L,ixO^L,wCT,w,x,wCTprim)
5676 integer,
intent(in) :: ixi^
l, ixo^
l
5677 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5678 double precision,
intent(inout) :: w(ixi^s,1:nw)
5679 double precision,
intent(in),
optional :: wctprim(ixi^s,1:nw)
5681 double precision :: e(ixi^s,1:3),curle(ixi^s,1:3),dive(ixi^s)
5682 integer :: idir, idirmin, ix^
d
5686 {
do ix^db=iximin^db,iximax^db\}
5688 e(ix^
d,1)=w(ix^
d,b2_)*wctprim(ix^
d,m3_)-w(ix^
d,b3_)*wctprim(ix^
d,m2_)
5689 e(ix^
d,2)=w(ix^
d,b3_)*wctprim(ix^
d,m1_)-w(ix^
d,b1_)*wctprim(ix^
d,m3_)
5690 e(ix^
d,3)=w(ix^
d,b1_)*wctprim(ix^
d,m2_)-w(ix^
d,b2_)*wctprim(ix^
d,m1_)
5692 call divvector(e,ixi^l,ixo^l,dive)
5694 call curlvector(e,ixi^l,ixo^l,curle,idirmin,1,3)
5697 {
do ix^db=ixomin^db,ixomax^db\}
5698 w(ix^d,m1_)=w(ix^d,m1_)+qdt*(inv_squared_c0-inv_squared_c)*&
5699 (e(ix^d,1)*dive(ix^d)-e(ix^d,2)*curle(ix^d,3)+e(ix^d,3)*curle(ix^d,2))
5700 w(ix^d,m2_)=w(ix^d,m2_)+qdt*(inv_squared_c0-inv_squared_c)*&
5701 (e(ix^d,2)*dive(ix^d)-e(ix^d,3)*curle(ix^d,1)+e(ix^d,1)*curle(ix^d,3))
5702 w(ix^d,m3_)=w(ix^d,m3_)+qdt*(inv_squared_c0-inv_squared_c)*&
5703 (e(ix^d,3)*dive(ix^d)-e(ix^d,1)*curle(ix^d,2)+e(ix^d,2)*curle(ix^d,1) )
5707 end subroutine add_source_semirelativistic
5710 subroutine add_source_internal_e(qdt,ixI^L,ixO^L,wCT,w,x,wCTprim)
5714 integer,
intent(in) :: ixi^
l, ixo^
l
5715 double precision,
intent(in) :: qdt
5716 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5717 double precision,
intent(inout) :: w(ixi^s,1:nw)
5718 double precision,
intent(in) :: wctprim(ixi^s,1:nw)
5720 double precision :: divv(ixi^s), tmp
5732 {
do ix^db=ixomin^db,ixomax^db\}
5734 w(ix^
d,
e_)=w(ix^
d,
e_)-qdt*wctprim(ix^
d,
p_)*divv(ix^
d)
5740 call add_source_ambipolar_internal_energy(qdt,ixi^l,ixo^l,wct,w,x)
5743 if(fix_small_values)
then
5744 call mhd_handle_small_ei(w,x,ixi^l,ixo^l,
e_,
'add_source_internal_e')
5746 end subroutine add_source_internal_e
5749 subroutine add_source_hydrodynamic_e(qdt,ixI^L,ixO^L,wCT,w,x,wCTprim)
5754 integer,
intent(in) :: ixi^
l, ixo^
l
5755 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5756 double precision,
intent(inout) :: w(ixi^s,1:nw)
5757 double precision,
intent(in),
optional :: wctprim(ixi^s,1:nw)
5759 double precision ::
b(ixi^s,3), j(ixi^s,3), jxb(ixi^s,3)
5760 double precision :: current(ixi^s,7-2*
ndir:3)
5761 double precision :: bu(ixo^s,1:
ndir), tmp(ixo^s), b2(ixo^s)
5762 double precision :: gravity_field(ixi^s,1:
ndir), vaoc
5763 integer :: idir, idirmin, idims, ix^
d
5768 b(ixo^s, idir) = wct(ixo^s,mag(idir))
5780 j(ixo^s,idir)=current(ixo^s,idir)
5859 call add_source_ambipolar_internal_energy(qdt,ixi^
l,ixo^
l,wct,w,x)
5862 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_hydrodynamic_e')
5864 end subroutine add_source_hydrodynamic_e
5870 subroutine add_source_res1(qdt,ixI^L,ixO^L,wCT,w,x)
5875 integer,
intent(in) :: ixi^
l, ixo^
l
5876 double precision,
intent(in) :: qdt
5877 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5878 double precision,
intent(inout) :: w(ixi^s,1:nw)
5880 integer :: ixa^
l,idir,jdir,kdir,idirmin,idim
5881 double precision :: tmp(ixi^s),tmp2(ixi^s)
5884 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s)
5885 double precision :: gradeta(ixi^s,1:
ndim), bf(ixi^s,1:
ndir)
5886 double precision :: lapl_vec(ixi^s,1:
ndir)
5892 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
5893 call mpistop(
"Error in add_source_res1: Non-conforming input limits")
5900 gradeta(ixo^s,1:
ndim)=zero
5905 gradeta(ixo^s,idim)=tmp(ixo^s)
5912 bf(ixi^s,1:
ndir)=wct(ixi^s,mag(1:
ndir))
5919 tmp(ixo^s)=lapl_vec(ixo^s,idir)*eta(ixo^s)
5923 do jdir=1,
ndim;
do kdir=idirmin,3
5924 if (
lvc(idir,jdir,kdir)/=0)
then
5925 if (
lvc(idir,jdir,kdir)==1)
then
5926 tmp(ixo^s)=tmp(ixo^s)-gradeta(ixo^s,jdir)*current(ixo^s,kdir)
5928 tmp(ixo^s)=tmp(ixo^s)+gradeta(ixo^s,jdir)*current(ixo^s,kdir)
5935 w(ixo^s,mag(idir))=w(ixo^s,mag(idir))+qdt*tmp(ixo^s)
5936 if(total_energy)
then
5937 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*tmp(ixo^s)*bf(ixo^s,idir)
5943 w(ixo^s,
e_)=w(ixo^s,
e_)+qdt*eta(ixo^s)*sum(current(ixo^s,:)**2,dim=ndim+1)
5946 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_res1')
5948 end subroutine add_source_res1
5952 subroutine add_source_res_exp(qdt,ixI^L,ixO^L,wCT,w,x)
5957 integer,
intent(in) :: ixi^
l, ixo^
l
5958 double precision,
intent(in) :: qdt
5959 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
5960 double precision,
intent(inout) :: w(ixi^s,1:nw)
5963 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s),curlj(ixi^s,1:3)
5964 double precision :: tmpvec(ixi^s,1:3),tmp(ixo^s)
5965 integer :: ixa^
l,idir,idirmin,idirmin1
5969 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
5970 call mpistop(
"Error in add_source_res_exp: Non-conforming input limits")
5980 tmpvec(ixa^s,idir)=current(ixa^s,idir)*
mhd_eta
5985 tmpvec(ixa^s,idir)=current(ixa^s,idir)*eta(ixa^s)
5994 w(ixo^s,mag(
ndir)) = w(ixo^s,mag(
ndir))-qdt*curlj(ixo^s,
ndir)
5997 w(ixo^s,mag(1:
ndir)) = w(ixo^s,mag(1:
ndir))-qdt*curlj(ixo^s,1:
ndir)
6002 tmp(ixo^s)=qdt*
mhd_eta*sum(current(ixo^s,:)**2,dim=
ndim+1)
6004 tmp(ixo^s)=qdt*eta(ixo^s)*sum(current(ixo^s,:)**2,dim=
ndim+1)
6006 if(total_energy)
then
6009 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)-&
6010 qdt*sum(wct(ixo^s,mag(1:
ndir))*curlj(ixo^s,1:
ndir),dim=
ndim+1)
6013 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)
6017 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_res_exp')
6018 end subroutine add_source_res_exp
6023 subroutine add_source_ambi_exp(qdt,ixI^L,ixO^L,wCT,w,x)
6028 integer,
intent(in) :: ixi^
l, ixo^
l
6029 double precision,
intent(in) :: qdt
6030 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6031 double precision,
intent(inout) :: w(ixi^s,1:nw)
6033 double precision :: current(ixi^s,1:3),curlj(ixi^s,1:3)
6034 double precision :: tmpvec(ixi^s,1:3),tmp(ixi^s),btot2(ixi^s)
6035 integer :: ixa^
l,idir,idirmin1
6039 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6040 call mpistop(
"Error in add_source_ambi_exp: Non-conforming input limits")
6044 call mhd_get_jxbxb(wct,x,ixi^
l,ixa^
l,current)
6058 w(ixo^s,mag(
ndir)) = w(ixo^s,mag(
ndir))-qdt*curlj(ixo^s,
ndir)
6061 w(ixo^s,mag(1:
ndir)) = w(ixo^s,mag(1:
ndir))-qdt*curlj(ixo^s,1:
ndir)
6068 where (btot2(ixa^s)>smalldouble )
6069 tmp(ixa^s) = sum(current(ixa^s,1:3)**2,dim=
ndim+1) / btot2(ixa^s)
6076 tmp(ixo^s)=-qdt*tmp(ixo^s)
6077 if(total_energy)
then
6080 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)-&
6081 qdt*sum(wct(ixo^s,mag(1:
ndir))*curlj(ixo^s,1:
ndir),dim=
ndim+1)
6084 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)
6088 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_ambi_exp')
6089 end subroutine add_source_ambi_exp
6093 subroutine add_source_hyperres(qdt,ixI^L,ixO^L,wCT,w,x)
6097 integer,
intent(in) :: ixi^
l, ixo^
l
6098 double precision,
intent(in) :: qdt
6099 double precision,
intent(in) :: wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6100 double precision,
intent(inout) :: w(ixi^s,1:nw)
6102 double precision :: current(ixi^s,7-2*
ndir:3)
6103 double precision :: tmpvec(ixi^s,1:3),tmpvec2(ixi^s,1:3),tmp(ixi^s),ehyper(ixi^s,1:3)
6104 integer :: ixa^
l,idir,jdir,kdir,idirmin,idirmin1
6107 if (iximin^
d>ixamin^
d.or.iximax^
d<ixamax^
d|.or.) &
6108 call mpistop(
"Error in add_source_hyperres: Non-conforming input limits")
6111 tmpvec(ixa^s,1:
ndir)=zero
6113 tmpvec(ixa^s,jdir)=current(ixa^s,jdir)
6117 call curlvector(tmpvec,ixi^
l,ixa^
l,tmpvec2,idirmin1,1,3)
6120 tmpvec(ixa^s,1:
ndir)=zero
6121 call curlvector(tmpvec2,ixi^
l,ixa^
l,tmpvec,idirmin1,1,3)
6125 tmpvec2(ixa^s,1:
ndir)=zero
6126 call curlvector(ehyper,ixi^
l,ixa^
l,tmpvec2,idirmin1,1,3)
6129 w(ixo^s,mag(idir)) = w(ixo^s,mag(idir))-tmpvec2(ixo^s,idir)*qdt
6132 if(total_energy)
then
6135 tmpvec2(ixa^s,1:
ndir)=zero
6136 do idir=1,
ndir;
do jdir=1,
ndir;
do kdir=idirmin,3
6137 tmpvec2(ixa^s,idir) = tmpvec(ixa^s,idir)&
6138 +
lvc(idir,jdir,kdir)*wct(ixa^s,mag(jdir))*ehyper(ixa^s,kdir)
6139 end do;
end do;
end do
6141 call divvector(tmpvec2,ixi^l,ixo^l,tmp)
6142 w(ixo^s,
e_)=w(ixo^s,
e_)+tmp(ixo^s)*qdt
6145 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_hyperres')
6147 end subroutine add_source_hyperres
6149 subroutine add_source_glm(qdt,ixI^L,ixO^L,wCT,w,x)
6156 integer,
intent(in) :: ixi^
l, ixo^
l
6157 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6158 double precision,
intent(inout) :: w(ixi^s,1:nw)
6160 double precision:: divb(ixi^s), gradpsi(ixi^s), ba(ixo^s,1:
ndir)
6181 ba(ixo^s,1:
ndir)=wct(ixo^s,mag(1:
ndir))
6184 if(total_energy)
then
6193 w(ixo^s,
e_) = w(ixo^s,
e_)-qdt*ba(ixo^s,idir)*gradpsi(ixo^s)
6202 w(ixo^s,
mom(idir))=w(ixo^s,
mom(idir))-qdt*ba(ixo^s,idir)*divb(ixo^s)
6206 if (
fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^
l,ixo^
l,
'add_source_glm')
6208 end subroutine add_source_glm
6211 subroutine add_source_powel(qdt,ixI^L,ixO^L,wCT,w,x)
6214 integer,
intent(in) :: ixi^
l, ixo^
l
6215 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6216 double precision,
intent(inout) :: w(ixi^s,1:nw)
6218 double precision :: divb(ixi^s), ba(1:
ndir)
6219 integer :: idir, ix^
d
6225 {
do ix^db=ixomin^db,ixomax^db\}
6230 if (total_energy)
then
6236 {
do ix^db=ixomin^db,ixomax^db\}
6238 ^
c&w(ix^d,
b^
c_)=w(ix^d,
b^
c_)-qdt*wct(ix^d,
m^
c_)*divb(ix^d)\
6240 ^
c&w(ix^d,
m^
c_)=w(ix^d,
m^
c_)-qdt*wct(ix^d,
b^
c_)*divb(ix^d)\
6241 if (total_energy)
then
6243 w(ix^d,
e_)=w(ix^d,
e_)-qdt*(^
c&wct(ix^d,
m^
c_)*wct(ix^d,
b^
c_)+)*divb(ix^d)
6248 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_powel')
6250 end subroutine add_source_powel
6252 subroutine add_source_janhunen(qdt,ixI^L,ixO^L,wCT,w,x)
6257 integer,
intent(in) :: ixi^
l, ixo^
l
6258 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6259 double precision,
intent(inout) :: w(ixi^s,1:nw)
6261 double precision :: divb(ixi^s)
6262 integer :: idir, ix^
d
6267 {
do ix^db=ixomin^db,ixomax^db\}
6272 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_janhunen')
6274 end subroutine add_source_janhunen
6276 subroutine add_source_linde(qdt,ixI^L,ixO^L,wCT,w,x)
6281 integer,
intent(in) :: ixi^
l, ixo^
l
6282 double precision,
intent(in) :: qdt, wct(ixi^s,1:nw), x(ixi^s,1:
ndim)
6283 double precision,
intent(inout) :: w(ixi^s,1:nw)
6285 double precision :: divb(ixi^s),graddivb(ixi^s)
6286 integer :: idim, idir, ixp^
l, i^
d, iside
6287 logical,
dimension(-1:1^D&) :: leveljump
6295 if(i^
d==0|.and.) cycle
6296 if(neighbor_type(i^
d,
block%igrid)==2 .or. neighbor_type(i^
d,
block%igrid)==4)
then
6297 leveljump(i^
d)=.true.
6299 leveljump(i^
d)=.false.
6308 i^dd=kr(^dd,^d)*(2*iside-3);
6309 if (leveljump(i^dd))
then
6311 ixpmin^d=ixomin^d-i^d
6313 ixpmax^d=ixomax^d-i^d
6324 call gradient(divb,ixi^l,ixp^l,idim,graddivb)
6326 {
do i^db=ixpmin^db,ixpmax^db\}
6328 graddivb(i^d)=graddivb(i^d)*
divbdiff/(^d&1.0d0/block%ds({i^d},^d)**2+)
6330 w(i^d,mag(idim))=w(i^d,mag(idim))+graddivb(i^d)
6332 if (typedivbdiff==
'all' .and. total_energy)
then
6334 w(i^d,
e_)=w(i^d,
e_)+wct(i^d,mag(idim))*graddivb(i^d)
6339 if (fix_small_values)
call mhd_handle_small_values(.false.,w,x,ixi^l,ixo^l,
'add_source_linde')
6341 end subroutine add_source_linde
6348 integer,
intent(in) :: ixi^
l, ixo^
l
6349 double precision,
intent(in) :: w(ixi^s,1:nw)
6350 double precision :: divb(ixi^s), dsurface(ixi^s)
6352 double precision :: invb(ixo^s)
6353 integer :: ixa^
l,idims
6355 call get_divb(w,ixi^
l,ixo^
l,divb)
6357 where(invb(ixo^s)/=0.d0)
6358 invb(ixo^s)=1.d0/invb(ixo^s)
6361 divb(ixo^s)=0.5d0*abs(divb(ixo^s))*invb(ixo^s)/sum(1.d0/
dxlevel(:))
6363 ixamin^
d=ixomin^
d-1;
6364 ixamax^
d=ixomax^
d-1;
6365 dsurface(ixo^s)= sum(
block%surfaceC(ixo^s,:),dim=
ndim+1)
6367 ixa^
l=ixo^
l-
kr(idims,^
d);
6368 dsurface(ixo^s)=dsurface(ixo^s)+
block%surfaceC(ixa^s,idims)
6370 divb(ixo^s)=abs(divb(ixo^s))*invb(ixo^s)*&
6371 block%dvolume(ixo^s)/dsurface(ixo^s)
6382 integer,
intent(in) :: ixo^
l, ixi^
l
6383 double precision,
intent(in) :: w(ixi^s,1:nw)
6384 integer,
intent(out) :: idirmin
6387 double precision :: current(ixi^s,7-2*
ndir:3)
6388 integer :: idir, idirmin0
6394 if(
b0field) current(ixo^s,idirmin0:3)=current(ixo^s,idirmin0:3)+&
6395 block%J0(ixo^s,idirmin0:3)
6399 subroutine mhd_get_dt(wprim,ixI^L,ixO^L,dtnew,dx^D,x)
6407 integer,
intent(in) :: ixi^
l, ixo^
l
6408 double precision,
intent(inout) :: dtnew
6409 double precision,
intent(in) ::
dx^
d
6410 double precision,
intent(in) :: wprim(ixi^s,1:nw)
6411 double precision,
intent(in) :: x(ixi^s,1:
ndim)
6413 double precision :: dxarr(
ndim)
6414 double precision :: current(ixi^s,7-2*
ndir:3),eta(ixi^s)
6415 integer :: idirmin,idim
6433 dtdiffpar/(smalldouble+maxval(eta(ixo^s)/dxarr(idim)**2)))
6436 dtdiffpar/(smalldouble+maxval(eta(ixo^s)/
block%ds(ixo^s,idim)**2)))
6458 dtnew=min(
dtdiffpar*get_ambipolar_dt(wprim,ixi^
l,ixo^
l,
dx^
d,x),dtnew)
6469 end subroutine mhd_get_dt
6476 subroutine mhd_add_source_geom(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
6482 integer,
intent(in) :: ixi^
l, ixo^
l
6483 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
6484 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
6486 double precision :: adiabs(ixi^s), gammas(ixi^s)
6487 double precision :: tmp,tmp1,invr,cot
6489 integer :: mr_,mphi_
6490 integer :: br_,bphi_
6493 br_=mag(1); bphi_=mag(1)-1+
phi_
6510 {
do ix^db=ixomin^db,ixomax^db\}
6513 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
6518 tmp=wprim(ix^
d,
p_)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
6520 tmp=adiabs(ix^
d)*wprim(ix^
d,
rho_)**gammas(ix^
d)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
6523 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp-&
6524 wprim(ix^
d,bphi_)**2+wprim(ix^
d,mphi_)*wct(ix^
d,mphi_))
6525 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
6526 -wct(ix^
d,mphi_)*wprim(ix^
d,mr_) &
6527 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_))
6529 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
6530 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
6531 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
6534 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*tmp
6539 {
do ix^db=ixomin^db,ixomax^db\}
6541 if(local_timestep)
then
6542 invr=block%dt(ix^d) * dtfactor/x(ix^d,1)
6547 tmp1=wprim(ix^d,
p_)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
6549 tmp1=adiabs(ix^d)*wprim(ix^d,
rho_)**gammas(ix^d)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
6553 w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp1*invr
6556 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
6557 (two*tmp1+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+))
6561 w(ix^d,mag(1))=w(ix^d,mag(1))+invr*2.0d0*wprim(ix^d,
psi_)
6567 cot=1.d0/tan(x(ix^d,2))
6571 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6572 +wprim(ix^d,b1_)*wprim(ix^d,b2_))
6574 if(.not.stagger_grid)
then
6575 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6577 tmp=tmp+wprim(ix^d,
psi_)*cot
6579 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
6584 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6585 +wprim(ix^d,b1_)*wprim(ix^d,b2_)&
6586 +(wprim(ix^d,m3_)*wct(ix^d,m3_)-wprim(ix^d,b3_)**2)*cot)
6588 if(.not.stagger_grid)
then
6589 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6591 tmp=tmp+wprim(ix^d,
psi_)*cot
6593 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
6596 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
6597 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
6598 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
6599 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
6600 -wprim(ix^d,b2_)*wprim(ix^d,b3_))*cot)
6602 if(.not.stagger_grid)
then
6603 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
6604 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
6605 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
6606 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
6607 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
6614 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
6617 end subroutine mhd_add_source_geom
6624 subroutine mhd_add_source_geom_semirelati(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
6630 integer,
intent(in) :: ixi^
l, ixo^
l
6631 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
6632 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
6634 double precision :: adiabs(ixi^s), gammas(ixi^s)
6635 double precision :: tmp,tmp1,tmp2,invr,cot,ef(ixo^s,1:
ndir)
6637 integer :: mr_,mphi_
6638 integer :: br_,bphi_
6641 br_=mag(1); bphi_=mag(1)-1+
phi_
6658 {
do ix^db=ixomin^db,ixomax^db\}
6661 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
6668 tmp=adiabs(ix^
d)*wprim(ix^
d,
rho_)**gammas(ix^
d)
6672 ef(ix^
d,1)=wprim(ix^
d,b2_)*wprim(ix^
d,m3_)-wprim(ix^
d,b3_)*wprim(ix^
d,m2_)
6673 ef(ix^
d,2)=wprim(ix^
d,b3_)*wprim(ix^
d,m1_)-wprim(ix^
d,b1_)*wprim(ix^
d,m3_)
6674 ef(ix^
d,3)=wprim(ix^
d,b1_)*wprim(ix^
d,m2_)-wprim(ix^
d,b2_)*wprim(ix^
d,m1_)
6679 ef(ix^
d,2)=wprim(ix^
d,b1_)*wprim(ix^
d,m2_)-wprim(ix^
d,b2_)*wprim(ix^
d,m1_)
6685 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp+&
6686 half*((^
c&wprim(ix^
d,
b^
c_)**2+)+(^
c&ef(ix^
d,^
c)**2+)*inv_squared_c) -&
6687 wprim(ix^
d,bphi_)**2+wprim(ix^
d,
rho_)*wprim(ix^
d,mphi_)**2)
6688 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
6689 -wprim(ix^
d,
rho_)*wprim(ix^
d,mphi_)*wprim(ix^
d,mr_) &
6690 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_)+ef(ix^
d,
phi_)*ef(ix^
d,1)*inv_squared_c)
6692 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
6693 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
6694 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
6697 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp+half*((^
c&wprim(ix^
d,
b^
c_)**2+)+&
6698 (^
c&ef(ix^
d,^
c)**2+)*inv_squared_c))
6703 {
do ix^db=ixomin^db,ixomax^db\}
6705 if(local_timestep)
then
6706 invr=block%dt(ix^d)*dtfactor/x(ix^d,1)
6712 ef(ix^d,1)=wprim(ix^d,b2_)*wprim(ix^d,m3_)-wprim(ix^d,b3_)*wprim(ix^d,m2_)
6713 ef(ix^d,2)=wprim(ix^d,b3_)*wprim(ix^d,m1_)-wprim(ix^d,b1_)*wprim(ix^d,m3_)
6714 ef(ix^d,3)=wprim(ix^d,b1_)*wprim(ix^d,m2_)-wprim(ix^d,b2_)*wprim(ix^d,m1_)
6718 ef(ix^d,1)=wprim(ix^d,b1_)*wprim(ix^d,m2_)-wprim(ix^d,b2_)*wprim(ix^d,m1_)
6725 tmp1=wprim(ix^d,
p_)+half*((^
c&wprim(ix^d,
b^
c_)**2+)+(^
c&ef(ix^d,^
c)**2+)*inv_squared_c)
6727 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)
6731 w(ix^d,m1_)=w(ix^d,m1_)+two*tmp1*invr
6734 w(ix^d,m1_)=w(ix^d,m1_)+invr*&
6735 (two*tmp1+(^ce&wprim(ix^d,
rho_)*wprim(ix^d,
m^ce_)**2-&
6736 wprim(ix^d,
b^ce_)**2-ef(ix^d,^ce)**2*inv_squared_c+))
6740 w(ix^d,b1_)=w(ix^d,b1_)+invr*2.0d0*wprim(ix^d,
psi_)
6746 cot=1.d0/tan(x(ix^d,2))
6750 w(ix^d,m2_)=w(ix^d,m2_)+invr*(tmp1*cot-wprim(ix^d,
rho_)*wprim(ix^d,m1_)*wprim(ix^d,m2_)&
6751 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+ef(ix^d,1)*ef(ix^d,2)*inv_squared_c)
6753 if(.not.stagger_grid)
then
6754 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6756 tmp=tmp+wprim(ix^d,
psi_)*cot
6758 w(ix^d,b2_)=w(ix^d,b2_)+tmp*invr
6764 w(ix^d,m2_)=w(ix^d,m2_)+invr*(tmp1*cot-wprim(ix^d,
rho_)*wprim(ix^d,m1_)*wprim(ix^d,m2_) &
6765 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+ef(ix^d,1)*ef(ix^d,2)*inv_squared_c&
6766 +(wprim(ix^d,
rho_)*wprim(ix^d,m3_)**2&
6767 -wprim(ix^d,b3_)**2-ef(ix^d,3)**2*inv_squared_c)*cot)
6769 if(.not.stagger_grid)
then
6770 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6772 tmp=tmp+wprim(ix^d,
psi_)*cot
6774 w(ix^d,b2_)=w(ix^d,b2_)+tmp*invr
6777 w(ix^d,m3_)=w(ix^d,m3_)+invr*&
6778 (-wprim(ix^d,m3_)*wprim(ix^d,m1_)*wprim(ix^d,
rho_) &
6779 +wprim(ix^d,b3_)*wprim(ix^d,b1_) &
6780 +ef(ix^d,3)*ef(ix^d,1)*inv_squared_c&
6781 +(-wprim(ix^d,m2_)*wprim(ix^d,m3_)*wprim(ix^d,
rho_) &
6782 +wprim(ix^d,b2_)*wprim(ix^d,b3_)&
6783 +ef(ix^d,2)*ef(ix^d,3)*inv_squared_c)*cot)
6785 if(.not.stagger_grid)
then
6786 w(ix^d,b3_)=w(ix^d,b3_)+invr*&
6787 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
6788 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
6789 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
6790 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
6797 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
6800 end subroutine mhd_add_source_geom_semirelati
6809 subroutine mhd_add_source_geom_split(qdt,dtfactor,ixI^L,ixO^L,wCT,wprim,w,x)
6814 integer,
intent(in) :: ixi^
l, ixo^
l
6815 double precision,
intent(in) :: qdt, dtfactor,x(ixi^s,1:
ndim)
6816 double precision,
intent(inout) :: wct(ixi^s,1:nw),wprim(ixi^s,1:nw),w(ixi^s,1:nw)
6818 double precision :: tmp,tmp1,tmp2,invr,cot
6820 integer :: mr_,mphi_
6821 integer :: br_,bphi_
6824 br_=mag(1); bphi_=mag(1)-1+
phi_
6829 {
do ix^db=ixomin^db,ixomax^db\}
6832 invr=
block%dt(ix^
d) * dtfactor/x(ix^
d,1)
6836 tmp=wprim(ix^
d,
p_)+half*(^
c&wprim(ix^
d,
b^
c_)**2+)
6839 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*(tmp-&
6840 wprim(ix^
d,bphi_)**2+wprim(ix^
d,mphi_)*wct(ix^
d,mphi_))
6844 w(ix^
d,mphi_)=w(ix^
d,mphi_)+invr*(&
6845 -wct(ix^
d,mphi_)*wprim(ix^
d,mr_) &
6846 +wprim(ix^
d,bphi_)*wprim(ix^
d,br_))
6848 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))
6851 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
6852 (wprim(ix^
d,bphi_)*wprim(ix^
d,mr_) &
6853 -wprim(ix^
d,br_)*wprim(ix^
d,mphi_))
6855 w(ix^
d,bphi_)=w(ix^
d,bphi_)+invr*&
6861 w(ix^
d,mr_)=w(ix^
d,mr_)+invr*tmp
6866 {
do ix^db=ixomin^db,ixomax^db\}
6868 if(local_timestep)
then
6869 invr=block%dt(ix^d) * dtfactor/x(ix^d,1)
6873 tmp1=wprim(ix^d,
p_)+half*(^
c&wprim(ix^d,
b^
c_)**2+)
6874 if(b0field) tmp2=(^
c&block%B0(ix^d,^
c,0)*wprim(ix^d,
b^
c_)+)
6877 w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp1*invr
6878 if(b0field) w(ix^d,
mom(1))=w(ix^d,
mom(1))+two*tmp2*invr
6882 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
6883 (two*(tmp1+tmp2)+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+)- &
6884 (^ce&two*block%B0(ix^d,^ce,0)*wprim(ix^d,
b^ce_)+))
6886 w(ix^d,
mom(1))=w(ix^d,
mom(1))+invr*&
6887 (two*tmp1+(^ce&wprim(ix^d,
m^ce_)*wct(ix^d,
m^ce_)-wprim(ix^d,
b^ce_)**2+))
6892 w(ix^d,mag(1))=w(ix^d,mag(1))+invr*2.0d0*wprim(ix^d,
psi_)
6898 cot=1.d0/tan(x(ix^d,2))
6903 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*((tmp1+tmp2)*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6904 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+block%B0(ix^d,1,0)*wprim(ix^d,b2_)&
6905 +wprim(ix^d,b1_)*block%B0(ix^d,2,0))
6907 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6908 +wprim(ix^d,b1_)*wprim(ix^d,b2_))
6911 if(.not.stagger_grid)
then
6913 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)&
6914 +wprim(ix^d,m1_)*block%B0(ix^d,2,0)-wprim(ix^d,m2_)*block%B0(ix^d,1,0)
6916 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6919 tmp=tmp+wprim(ix^d,
psi_)*cot
6921 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
6927 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*((tmp1+tmp2)*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6928 +wprim(ix^d,b1_)*wprim(ix^d,b2_)+block%B0(ix^d,1,0)*wprim(ix^d,b2_)&
6929 +wprim(ix^d,b1_)*block%B0(ix^d,2,0)&
6930 +(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)
6932 w(ix^d,
mom(2))=w(ix^d,
mom(2))+invr*(tmp1*cot-wprim(ix^d,m1_)*wct(ix^d,m2_)&
6933 +wprim(ix^d,b1_)*wprim(ix^d,b2_)&
6934 +(wprim(ix^d,m3_)*wct(ix^d,m3_)-wprim(ix^d,b3_)**2)*cot)
6937 if(.not.stagger_grid)
then
6939 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)&
6940 +wprim(ix^d,m1_)*block%B0(ix^d,2,0)-wprim(ix^d,m2_)*block%B0(ix^d,1,0)
6942 tmp=wprim(ix^d,m1_)*wprim(ix^d,b2_)-wprim(ix^d,m2_)*wprim(ix^d,b1_)
6945 tmp=tmp+wprim(ix^d,
psi_)*cot
6947 w(ix^d,mag(2))=w(ix^d,mag(2))+tmp*invr
6951 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
6952 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
6953 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
6954 +block%B0(ix^d,1,0)*wprim(ix^d,b3_) &
6955 +wprim(ix^d,b1_)*block%B0(ix^d,3,0) &
6956 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
6957 -wprim(ix^d,b2_)*wprim(ix^d,b3_) &
6958 +block%B0(ix^d,2,0)*wprim(ix^d,b3_) &
6959 +wprim(ix^d,b2_)*block%B0(ix^d,3,0))*cot)
6961 w(ix^d,
mom(3))=w(ix^d,
mom(3))-invr*&
6962 (wprim(ix^d,m3_)*wct(ix^d,m1_) &
6963 -wprim(ix^d,b3_)*wprim(ix^d,b1_) &
6964 +(wprim(ix^d,m2_)*wct(ix^d,m3_) &
6965 -wprim(ix^d,b2_)*wprim(ix^d,b3_))*cot)
6968 if(.not.stagger_grid)
then
6970 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
6971 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
6972 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
6973 +wprim(ix^d,m1_)*block%B0(ix^d,3,0) &
6974 -wprim(ix^d,m3_)*block%B0(ix^d,1,0) &
6975 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
6976 -wprim(ix^d,m2_)*wprim(ix^d,b3_) &
6977 +wprim(ix^d,m3_)*block%B0(ix^d,2,0) &
6978 -wprim(ix^d,m2_)*block%B0(ix^d,3,0))*cot)
6980 w(ix^d,mag(3))=w(ix^d,mag(3))+invr*&
6981 (wprim(ix^d,m1_)*wprim(ix^d,b3_) &
6982 -wprim(ix^d,m3_)*wprim(ix^d,b1_) &
6983 -(wprim(ix^d,m3_)*wprim(ix^d,b2_) &
6984 -wprim(ix^d,m2_)*wprim(ix^d,b3_))*cot)
6992 call rotating_frame_add_source(qdt,dtfactor,ixi^l,ixo^l,wprim,w,x)
6995 end subroutine mhd_add_source_geom_split
7000 integer,
intent(in) :: ixi^
l, ixo^
l
7001 double precision,
intent(in) :: w(ixi^s, nw)
7002 double precision :: mge(ixo^s)
7005 mge = sum((w(ixo^s, mag(:))+
block%B0(ixo^s,:,
b0i))**2, dim=
ndim+1)
7007 mge = sum(w(ixo^s, mag(:))**2, dim=
ndim+1)
7011 subroutine mhd_getv_hall(w,x,ixI^L,ixO^L,vHall,partial)
7015 integer,
intent(in) :: ixi^
l, ixo^
l
7016 double precision,
intent(in) :: w(ixi^s,nw)
7017 double precision,
intent(in) :: x(ixi^s,1:
ndim)
7018 double precision,
intent(inout) :: vhall(ixi^s,1:
ndir)
7019 logical,
intent(in),
optional :: partial
7021 double precision :: current(ixi^s,7-2*
ndir:3)
7022 double precision :: rho(ixi^s)
7023 integer :: idir, idirmin, ix^
d
7024 logical :: use_partial
7027 if(
present(partial)) use_partial=partial
7029 if(.not.use_partial)
then
7040 do idir = idirmin,
ndir
7041 {
do ix^db=ixomin^db,ixomax^db\}
7042 vhall(ix^
d,idir)=-
mhd_etah*current(ix^
d,idir)/rho(ix^
d)
7046 end subroutine mhd_getv_hall
7048 subroutine mhd_modify_wlr(ixI^L,ixO^L,qt,wLC,wRC,wLp,wRp,s,idir)
7051 integer,
intent(in) :: ixi^
l, ixo^
l, idir
7052 double precision,
intent(in) :: qt
7053 double precision,
intent(inout) :: wlc(ixi^s,1:nw), wrc(ixi^s,1:nw)
7054 double precision,
intent(inout) :: wlp(ixi^s,1:nw), wrp(ixi^s,1:nw)
7057 double precision :: db(ixo^s), dpsi(ixo^s)
7061 {
do ix^db=ixomin^db,ixomax^db\}
7062 wlc(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7063 wrc(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7064 wlp(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7065 wrp(ix^
d,mag(idir))=s%ws(ix^
d,idir)
7074 {
do ix^db=ixomin^db,ixomax^db\}
7075 db(ix^d)=wrp(ix^d,mag(idir))-wlp(ix^d,mag(idir))
7076 dpsi(ix^d)=wrp(ix^d,
psi_)-wlp(ix^d,
psi_)
7077 wlp(ix^d,mag(idir))=half*(wrp(ix^d,mag(idir))+wlp(ix^d,mag(idir))-dpsi(ix^d)/cmax_global)
7078 wlp(ix^d,
psi_)=half*(wrp(ix^d,
psi_)+wlp(ix^d,
psi_)-db(ix^d)*cmax_global)
7079 wrp(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7081 if(total_energy)
then
7082 wrc(ix^d,
e_)=wrc(ix^d,
e_)-half*wrc(ix^d,mag(idir))**2
7083 wlc(ix^d,
e_)=wlc(ix^d,
e_)-half*wlc(ix^d,mag(idir))**2
7085 wrc(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7087 wlc(ix^d,mag(idir))=wlp(ix^d,mag(idir))
7090 if(total_energy)
then
7091 wrc(ix^d,
e_)=wrc(ix^d,
e_)+half*wrc(ix^d,mag(idir))**2
7092 wlc(ix^d,
e_)=wlc(ix^d,
e_)+half*wlc(ix^d,mag(idir))**2
7097 if(
associated(usr_set_wlr))
call usr_set_wlr(ixi^l,ixo^l,qt,wlc,wrc,wlp,wrp,s,idir)
7099 end subroutine mhd_modify_wlr
7101 subroutine mhd_boundary_adjust(igrid,psb)
7103 integer,
intent(in) :: igrid
7106 integer :: ib, idims, iside, ixo^
l, i^
d
7115 i^
d=
kr(^
d,idims)*(2*iside-3);
7116 if (neighbor_type(i^
d,igrid)/=1) cycle
7117 ib=(idims-1)*2+iside
7135 call fixdivb_boundary(ixg^
ll,ixo^
l,psb(igrid)%w,psb(igrid)%x,ib)
7140 end subroutine mhd_boundary_adjust
7142 subroutine fixdivb_boundary(ixG^L,ixO^L,w,x,iB)
7145 integer,
intent(in) :: ixg^
l,ixo^
l,ib
7146 double precision,
intent(inout) :: w(ixg^s,1:nw)
7147 double precision,
intent(in) :: x(ixg^s,1:
ndim)
7149 double precision :: dx1x2,dx1x3,dx2x1,dx2x3,dx3x1,dx3x2
7150 integer :: ix^
d,ixf^
l
7163 do ix1=ixfmax1,ixfmin1,-1
7164 w(ix1-1,ixfmin2:ixfmax2,mag(1))=w(ix1+1,ixfmin2:ixfmax2,mag(1)) &
7165 +dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))-&
7166 w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))
7169 do ix1=ixfmax1,ixfmin1,-1
7170 w(ix1-1,ixfmin2:ixfmax2,mag(1))=( (w(ix1+1,ixfmin2:ixfmax2,mag(1))+&
7171 w(ix1,ixfmin2:ixfmax2,mag(1)))*
block%surfaceC(ix1,ixfmin2:ixfmax2,1)&
7172 +(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))+w(ix1,ixfmin2:ixfmax2,mag(2)))*&
7173 block%surfaceC(ix1,ixfmin2:ixfmax2,2)&
7174 -(w(ix1,ixfmin2:ixfmax2,mag(2))+w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))*&
7175 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,2) )&
7176 /
block%surfaceC(ix1-1,ixfmin2:ixfmax2,1)-w(ix1,ixfmin2:ixfmax2,mag(1))
7190 do ix1=ixfmax1,ixfmin1,-1
7191 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7192 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)) &
7193 +dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))-&
7194 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2))) &
7195 +dx1x3*(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))-&
7196 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))
7199 do ix1=ixfmax1,ixfmin1,-1
7200 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7201 ( (w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))+&
7202 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)))*&
7203 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)&
7204 +(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))+&
7205 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2)))*&
7206 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,2)&
7207 -(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2))+&
7208 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2)))*&
7209 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,2)&
7210 +(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))+&
7211 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3)))*&
7212 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,3)&
7213 -(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3))+&
7214 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7215 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,3) )&
7216 /
block%surfaceC(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)-&
7217 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))
7231 do ix1=ixfmin1,ixfmax1
7232 w(ix1+1,ixfmin2:ixfmax2,mag(1))=w(ix1-1,ixfmin2:ixfmax2,mag(1)) &
7233 -dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))-&
7234 w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))
7237 do ix1=ixfmin1,ixfmax1
7238 w(ix1+1,ixfmin2:ixfmax2,mag(1))=( (w(ix1-1,ixfmin2:ixfmax2,mag(1))+&
7239 w(ix1,ixfmin2:ixfmax2,mag(1)))*
block%surfaceC(ix1-1,ixfmin2:ixfmax2,1)&
7240 -(w(ix1,ixfmin2+1:ixfmax2+1,mag(2))+w(ix1,ixfmin2:ixfmax2,mag(2)))*&
7241 block%surfaceC(ix1,ixfmin2:ixfmax2,2)&
7242 +(w(ix1,ixfmin2:ixfmax2,mag(2))+w(ix1,ixfmin2-1:ixfmax2-1,mag(2)))*&
7243 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,2) )&
7244 /
block%surfaceC(ix1,ixfmin2:ixfmax2,1)-w(ix1,ixfmin2:ixfmax2,mag(1))
7258 do ix1=ixfmin1,ixfmax1
7259 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7260 w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)) &
7261 -dx1x2*(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))-&
7262 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2))) &
7263 -dx1x3*(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))-&
7264 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))
7267 do ix1=ixfmin1,ixfmax1
7268 w(ix1+1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))=&
7269 ( (w(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))+&
7270 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1)))*&
7271 block%surfaceC(ix1-1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)&
7272 -(w(ix1,ixfmin2+1:ixfmax2+1,ixfmin3:ixfmax3,mag(2))+&
7273 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2)))*&
7274 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,2)&
7275 +(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(2))+&
7276 w(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,mag(2)))*&
7277 block%surfaceC(ix1,ixfmin2-1:ixfmax2-1,ixfmin3:ixfmax3,2)&
7278 -(w(ix1,ixfmin2:ixfmax2,ixfmin3+1:ixfmax3+1,mag(3))+&
7279 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3)))*&
7280 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,3)&
7281 +(w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(3))+&
7282 w(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7283 block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3-1:ixfmax3-1,3) )&
7284 /
block%surfaceC(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,1)-&
7285 w(ix1,ixfmin2:ixfmax2,ixfmin3:ixfmax3,mag(1))
7299 do ix2=ixfmax2,ixfmin2,-1
7300 w(ixfmin1:ixfmax1,ix2-1,mag(2))=w(ixfmin1:ixfmax1,ix2+1,mag(2)) &
7301 +dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))-&
7302 w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))
7305 do ix2=ixfmax2,ixfmin2,-1
7306 w(ixfmin1:ixfmax1,ix2-1,mag(2))=( (w(ixfmin1:ixfmax1,ix2+1,mag(2))+&
7307 w(ixfmin1:ixfmax1,ix2,mag(2)))*
block%surfaceC(ixfmin1:ixfmax1,ix2,2)&
7308 +(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))+w(ixfmin1:ixfmax1,ix2,mag(1)))*&
7309 block%surfaceC(ixfmin1:ixfmax1,ix2,1)&
7310 -(w(ixfmin1:ixfmax1,ix2,mag(1))+w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))*&
7311 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,1) )&
7312 /
block%surfaceC(ixfmin1:ixfmax1,ix2-1,2)-w(ixfmin1:ixfmax1,ix2,mag(2))
7326 do ix2=ixfmax2,ixfmin2,-1
7327 w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))=w(ixfmin1:ixfmax1,&
7328 ix2+1,ixfmin3:ixfmax3,mag(2)) &
7329 +dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))-&
7330 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1))) &
7331 +dx2x3*(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))-&
7332 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))
7335 do ix2=ixfmax2,ixfmin2,-1
7336 w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))=&
7337 ( (w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))+&
7338 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2)))*&
7339 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,2)&
7340 +(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))+&
7341 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7342 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,1)&
7343 -(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1))+&
7344 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7345 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,1)&
7346 +(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))+&
7347 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3)))*&
7348 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,3)&
7349 -(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3))+&
7350 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7351 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,3) )&
7352 /
block%surfaceC(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,2)-&
7353 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2))
7367 do ix2=ixfmin2,ixfmax2
7368 w(ixfmin1:ixfmax1,ix2+1,mag(2))=w(ixfmin1:ixfmax1,ix2-1,mag(2)) &
7369 -dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))-&
7370 w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))
7373 do ix2=ixfmin2,ixfmax2
7374 w(ixfmin1:ixfmax1,ix2+1,mag(2))=( (w(ixfmin1:ixfmax1,ix2-1,mag(2))+&
7375 w(ixfmin1:ixfmax1,ix2,mag(2)))*
block%surfaceC(ixfmin1:ixfmax1,ix2-1,2)&
7376 -(w(ixfmin1+1:ixfmax1+1,ix2,mag(1))+w(ixfmin1:ixfmax1,ix2,mag(1)))*&
7377 block%surfaceC(ixfmin1:ixfmax1,ix2,1)&
7378 +(w(ixfmin1:ixfmax1,ix2,mag(1))+w(ixfmin1-1:ixfmax1-1,ix2,mag(1)))*&
7379 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,1) )&
7380 /
block%surfaceC(ixfmin1:ixfmax1,ix2,2)-w(ixfmin1:ixfmax1,ix2,mag(2))
7394 do ix2=ixfmin2,ixfmax2
7395 w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))=w(ixfmin1:ixfmax1,&
7396 ix2-1,ixfmin3:ixfmax3,mag(2)) &
7397 -dx2x1*(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))-&
7398 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1))) &
7399 -dx2x3*(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))-&
7400 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))
7403 do ix2=ixfmin2,ixfmax2
7404 w(ixfmin1:ixfmax1,ix2+1,ixfmin3:ixfmax3,mag(2))=&
7405 ( (w(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,mag(2))+&
7406 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2)))*&
7407 block%surfaceC(ixfmin1:ixfmax1,ix2-1,ixfmin3:ixfmax3,2)&
7408 -(w(ixfmin1+1:ixfmax1+1,ix2,ixfmin3:ixfmax3,mag(1))+&
7409 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7410 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,1)&
7411 +(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(1))+&
7412 w(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,mag(1)))*&
7413 block%surfaceC(ixfmin1-1:ixfmax1-1,ix2,ixfmin3:ixfmax3,1)&
7414 -(w(ixfmin1:ixfmax1,ix2,ixfmin3+1:ixfmax3+1,mag(3))+&
7415 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3)))*&
7416 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,3)&
7417 +(w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(3))+&
7418 w(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,mag(3)))*&
7419 block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3-1:ixfmax3-1,3) )&
7420 /
block%surfaceC(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,2)-&
7421 w(ixfmin1:ixfmax1,ix2,ixfmin3:ixfmax3,mag(2))
7438 do ix3=ixfmax3,ixfmin3,-1
7439 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))=w(ixfmin1:ixfmax1,&
7440 ixfmin2:ixfmax2,ix3+1,mag(3)) &
7441 +dx3x1*(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))-&
7442 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1))) &
7443 +dx3x2*(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))-&
7444 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))
7447 do ix3=ixfmax3,ixfmin3,-1
7448 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))=&
7449 ( (w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))+&
7450 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3)))*&
7451 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,3)&
7452 +(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))+&
7453 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1)))*&
7454 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,1)&
7455 -(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1))+&
7456 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1)))*&
7457 block%surfaceC(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,1)&
7458 +(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))+&
7459 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2)))*&
7460 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,2)&
7461 -(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2))+&
7462 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))*&
7463 block%surfaceC(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,2) )&
7464 /
block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,3)-&
7465 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3))
7480 do ix3=ixfmin3,ixfmax3
7481 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))=w(ixfmin1:ixfmax1,&
7482 ixfmin2:ixfmax2,ix3-1,mag(3)) &
7483 -dx3x1*(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))-&
7484 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1))) &
7485 -dx3x2*(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))-&
7486 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))
7489 do ix3=ixfmin3,ixfmax3
7490 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3+1,mag(3))=&
7491 ( (w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,mag(3))+&
7492 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3)))*&
7493 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3-1,3)&
7494 -(w(ixfmin1+1:ixfmax1+1,ixfmin2:ixfmax2,ix3,mag(1))+&
7495 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1)))*&
7496 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,1)&
7497 +(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(1))+&
7498 w(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,mag(1)))*&
7499 block%surfaceC(ixfmin1-1:ixfmax1-1,ixfmin2:ixfmax2,ix3,1)&
7500 -(w(ixfmin1:ixfmax1,ixfmin2+1:ixfmax2+1,ix3,mag(2))+&
7501 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2)))*&
7502 block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,2)&
7503 +(w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(2))+&
7504 w(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,mag(2)))*&
7505 block%surfaceC(ixfmin1:ixfmax1,ixfmin2-1:ixfmax2-1,ix3,2) )&
7506 /
block%surfaceC(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,3)-&
7507 w(ixfmin1:ixfmax1,ixfmin2:ixfmax2,ix3,mag(3))
7513 call mpistop(
"Special boundary is not defined for this region")
7516 end subroutine fixdivb_boundary
7525 double precision,
intent(in) :: qdt
7526 double precision,
intent(in) :: qt
7527 logical,
intent(inout) :: active
7530 integer,
parameter :: max_its = 50
7531 double precision :: residual_it(max_its), max_divb
7532 double precision :: tmp(ixg^t), grad(ixg^t,
ndim)
7533 double precision :: res
7534 double precision,
parameter :: max_residual = 1
d-3
7535 double precision,
parameter :: residual_reduction = 1
d-10
7536 integer :: iigrid, igrid
7537 integer :: n, nc, lvl, ix^
l, ixc^
l, idim
7540 mg%operator_type = mg_laplacian
7548 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
7549 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
7552 mg%bc(n, mg_iphi)%bc_type = mg_bc_neumann
7553 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
7555 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
7556 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
7559 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
7560 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
7564 write(*,*)
"mhd_clean_divb_multigrid warning: unknown boundary type"
7565 mg%bc(n, mg_iphi)%bc_type = mg_bc_dirichlet
7566 mg%bc(n, mg_iphi)%bc_value = 0.0_dp
7574 do iigrid = 1, igridstail
7575 igrid = igrids(iigrid);
7578 lvl =
mg%boxes(id)%lvl
7579 nc =
mg%box_size_lvl(lvl)
7585 call get_divb(ps(igrid)%w(ixg^t, 1:nw), ixg^
ll,
ixm^
ll, tmp, &
7587 mg%boxes(id)%cc({1:nc}, mg_irhs) = tmp(
ixm^t)
7588 max_divb = max(max_divb, maxval(abs(tmp(
ixm^t))))
7593 call mpi_allreduce(mpi_in_place, max_divb, 1, mpi_double_precision, &
7596 if (
mype == 0) print *,
"Performing multigrid divB cleaning"
7597 if (
mype == 0) print *,
"iteration vs residual"
7600 call mg_fas_fmg(
mg, n>1, max_res=residual_it(n))
7601 if (
mype == 0)
write(*,
"(I4,E11.3)") n, residual_it(n)
7602 if (residual_it(n) < residual_reduction * max_divb)
exit
7604 if (
mype == 0 .and. n > max_its)
then
7605 print *,
"divb_multigrid warning: not fully converged"
7606 print *,
"current amplitude of divb: ", residual_it(max_its)
7607 print *,
"multigrid smallest grid: ", &
7608 mg%domain_size_lvl(:,
mg%lowest_lvl)
7609 print *,
"note: smallest grid ideally has <= 8 cells"
7610 print *,
"multigrid dx/dy/dz ratio: ",
mg%dr(:, 1)/
mg%dr(1, 1)
7611 print *,
"note: dx/dy/dz should be similar"
7615 call mg_fas_vcycle(
mg, max_res=res)
7616 if (res < max_residual)
exit
7618 if (res > max_residual)
call mpistop(
"divb_multigrid: no convergence")
7623 do iigrid = 1, igridstail
7624 igrid = igrids(iigrid);
7633 tmp(ix^s) =
mg%boxes(id)%cc({:,}, mg_iphi)
7637 ixcmin^
d=ixmlo^
d-
kr(idim,^
d);
7639 call gradientf(tmp,ps(igrid)%x,ixg^
ll,ixc^
l,idim,grad(ixg^t,idim))
7641 ps(igrid)%ws(ixc^s,idim)=ps(igrid)%ws(ixc^s,idim)-grad(ixc^s,idim)
7654 ps(igrid)%w(
ixm^t, mag(1:
ndim)) = &
7655 ps(igrid)%w(
ixm^t, mag(1:
ndim)) - grad(
ixm^t, :)
7658 if(total_energy)
then
7660 tmp(
ixm^t) = 0.5_dp * (sum(ps(igrid)%w(
ixm^t, &
7663 ps(igrid)%w(
ixm^t,
e_) = ps(igrid)%w(
ixm^t,
e_) + tmp(
ixm^t)
7673 subroutine mhd_update_faces_average(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
7677 integer,
intent(in) :: ixi^
l, ixo^
l
7678 double precision,
intent(in) :: qt,qdt
7680 double precision,
intent(in) :: wp(ixi^s,1:nw)
7681 type(state) :: sct, s
7682 type(ct_velocity) :: vcts
7683 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
7684 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
7686 double precision :: circ(ixi^s,1:
ndim)
7688 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
7689 integer :: ix^
d,ixc^
l,ixa^
l,i1kr^
d,i2kr^
d
7690 integer :: idim1,idim2,idir,iwdim1,iwdim2
7692 associate(bfaces=>s%ws,x=>s%x)
7699 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
7706 i1kr^
d=
kr(idim1,^
d);
7709 i2kr^
d=
kr(idim2,^
d);
7712 if (
lvc(idim1,idim2,idir)==1)
then
7714 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
7716 {
do ix^db=ixcmin^db,ixcmax^db\}
7717 fe(ix^
d,idir)=quarter*&
7718 (fc(ix^
d,iwdim1,idim2)+fc({ix^
d+i1kr^
d},iwdim1,idim2)&
7719 -fc(ix^
d,iwdim2,idim1)-fc({ix^
d+i2kr^
d},iwdim2,idim1))
7721 if(
mhd_eta/=zero) fe(ix^
d,idir)=fe(ix^
d,idir)+e_resi(ix^
d,idir)
7726 fe(ix^
d,idir)=fe(ix^
d,idir)*qdt*s%dsC(ix^
d,idir)
7734 if(
associated(usr_set_electric_field)) &
7735 call usr_set_electric_field(ixi^l,ixo^l,qt,qdt,fe,sct)
7737 circ(ixi^s,1:ndim)=zero
7742 ixcmin^d=ixomin^d-kr(idim1,^d);
7744 ixa^l=ixc^l-kr(idim2,^d);
7747 if(lvc(idim1,idim2,idir)==1)
then
7749 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
7752 else if(lvc(idim1,idim2,idir)==-1)
then
7754 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
7760 {
do ix^db=ixcmin^db,ixcmax^db\}
7762 if(s%surfaceC(ix^d,idim1) > smalldouble)
then
7764 bfaces(ix^d,idim1)=bfaces(ix^d,idim1)-circ(ix^d,idim1)/s%surfaceC(ix^d,idim1)
7771 end subroutine mhd_update_faces_average
7774 subroutine mhd_update_faces_contact(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
7779 integer,
intent(in) :: ixi^
l, ixo^
l
7780 double precision,
intent(in) :: qt, qdt
7782 double precision,
intent(in) :: wp(ixi^s,1:nw)
7783 type(state) :: sct, s
7784 type(ct_velocity) :: vcts
7785 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
7786 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
7788 double precision :: circ(ixi^s,1:
ndim)
7790 double precision :: ecc(ixi^s,
sdim:3)
7791 double precision :: ein(ixi^s,
sdim:3)
7793 double precision :: el(ixi^s),er(ixi^s)
7795 double precision :: elc,erc
7797 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
7799 double precision :: jce(ixi^s,
sdim:3)
7801 double precision :: xs(ixgs^t,1:
ndim)
7802 double precision :: gradi(ixgs^t)
7803 integer :: ixc^
l,ixa^
l
7804 integer :: idim1,idim2,idir,iwdim1,iwdim2,ix^
d,i1kr^
d,i2kr^
d
7806 associate(bfaces=>s%ws,x=>s%x,w=>s%w,vnorm=>vcts%vnorm,wcts=>sct%ws)
7809 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
7815 {
do ix^db=iximin^db,iximax^db\}
7818 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_)
7819 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_)
7820 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_)
7823 ecc(ix^
d,3)=wp(ix^
d,b1_)*wp(ix^
d,m2_)-wp(ix^
d,b2_)*wp(ix^
d,m1_)
7830 {
do ix^db=iximin^db,iximax^db\}
7833 ecc(ix^d,1)=wp(ix^d,b2_)*wp(ix^d,m3_)-wp(ix^d,b3_)*wp(ix^d,m2_)
7834 ecc(ix^d,2)=wp(ix^d,b3_)*wp(ix^d,m1_)-wp(ix^d,b1_)*wp(ix^d,m3_)
7835 ecc(ix^d,3)=wp(ix^d,b1_)*wp(ix^d,m2_)-wp(ix^d,b2_)*wp(ix^d,m1_)
7838 ecc(ix^d,3)=wp(ix^d,b1_)*wp(ix^d,m2_)-wp(ix^d,b2_)*wp(ix^d,m1_)
7852 i1kr^d=kr(idim1,^d);
7855 i2kr^d=kr(idim2,^d);
7858 if (lvc(idim1,idim2,idir)==1)
then
7860 ixcmin^d=ixomin^d+kr(idir,^d)-1;
7863 {
do ix^db=ixcmin^db,ixcmax^db\}
7864 fe(ix^d,idir)=quarter*&
7865 (fc(ix^d,iwdim1,idim2)+fc({ix^d+i1kr^d},iwdim1,idim2)&
7866 -fc(ix^d,iwdim2,idim1)-fc({ix^d+i2kr^d},iwdim2,idim1))
7871 ixamax^d=ixcmax^d+i1kr^d;
7872 {
do ix^db=ixamin^db,ixamax^db\}
7873 el(ix^d)=fc(ix^d,iwdim1,idim2)-ecc(ix^d,idir)
7874 er(ix^d)=fc(ix^d,iwdim1,idim2)-ecc({ix^d+i2kr^d},idir)
7877 do ix^db=ixcmin^db,ixcmax^db\}
7878 if(vnorm(ix^d,idim1)>0.d0)
then
7880 else if(vnorm(ix^d,idim1)<0.d0)
then
7881 elc=el({ix^d+i1kr^d})
7883 elc=0.5d0*(el(ix^d)+el({ix^d+i1kr^d}))
7885 if(vnorm({ix^d+i2kr^d},idim1)>0.d0)
then
7887 else if(vnorm({ix^d+i2kr^d},idim1)<0.d0)
then
7888 erc=er({ix^d+i1kr^d})
7890 erc=0.5d0*(er(ix^d)+er({ix^d+i1kr^d}))
7892 fe(ix^d,idir)=fe(ix^d,idir)+0.25d0*(elc+erc)
7897 ixamax^d=ixcmax^d+i2kr^d;
7898 {
do ix^db=ixamin^db,ixamax^db\}
7899 el(ix^d)=-fc(ix^d,iwdim2,idim1)-ecc(ix^d,idir)
7900 er(ix^d)=-fc(ix^d,iwdim2,idim1)-ecc({ix^d+i1kr^d},idir)
7903 do ix^db=ixcmin^db,ixcmax^db\}
7904 if(vnorm(ix^d,idim2)>0.d0)
then
7906 else if(vnorm(ix^d,idim2)<0.d0)
then
7907 elc=el({ix^d+i2kr^d})
7909 elc=0.5d0*(el(ix^d)+el({ix^d+i2kr^d}))
7911 if(vnorm({ix^d+i1kr^d},idim2)>0.d0)
then
7913 else if(vnorm({ix^d+i1kr^d},idim2)<0.d0)
then
7914 erc=er({ix^d+i2kr^d})
7916 erc=0.5d0*(er(ix^d)+er({ix^d+i2kr^d}))
7918 fe(ix^d,idir)=fe(ix^d,idir)+0.25d0*(elc+erc)
7922 if(
mhd_eta/=zero) fe(ix^d,idir)=fe(ix^d,idir)+e_resi(ix^d,idir)
7927 fe(ix^d,idir)=fe(ix^d,idir)*qdt*s%dsC(ix^d,idir)
7941 if (lvc(idim1,idim2,idir)==0) cycle
7943 ixcmin^d=ixomin^d+kr(idir,^d)-1;
7944 ixamax^d=ixcmax^d-kr(idir,^d)+1;
7947 xs(ixa^s,:)=x(ixa^s,:)
7948 xs(ixa^s,idim2)=x(ixa^s,idim2)+half*s%dx(ixa^s,idim2)
7949 call gradientf(wcts(ixgs^t,idim2),xs,ixgs^ll,ixc^l,idim1,gradi)
7950 if (lvc(idim1,idim2,idir)==1)
then
7951 jce(ixc^s,idir)=jce(ixc^s,idir)+gradi(ixc^s)
7953 jce(ixc^s,idir)=jce(ixc^s,idir)-gradi(ixc^s)
7960 ixcmin^d=ixomin^d+kr(idir,^d)-1;
7962 ein(ixc^s,idir)=ein(ixc^s,idir)*jce(ixc^s,idir)
7966 {
do ix^db=ixomin^db,ixomax^db\}
7967 jce(ix^d,idir)=0.25d0*(ein(ix^d,idir)+ein(ix1,ix2-1,ix3,idir)+ein(ix1,ix2,ix3-1,idir)&
7968 +ein(ix1,ix2-1,ix3-1,idir))
7969 if(jce(ix^d,idir)<0.d0) jce(ix^d,idir)=0.d0
7970 w(ix^d,
e_)=w(ix^d,
e_)+qdt*jce(ix^d,idir)
7972 else if(idir==2)
then
7973 {
do ix^db=ixomin^db,ixomax^db\}
7974 jce(ix^d,idir)=0.25d0*(ein(ix^d,idir)+ein(ix1-1,ix2,ix3,idir)+ein(ix1,ix2,ix3-1,idir)&
7975 +ein(ix1-1,ix2,ix3-1,idir))
7976 if(jce(ix^d,idir)<0.d0) jce(ix^d,idir)=0.d0
7977 w(ix^d,
e_)=w(ix^d,
e_)+qdt*jce(ix^d,idir)
7980 {
do ix^db=ixomin^db,ixomax^db\}
7981 jce(ix^d,idir)=0.25d0*(ein(ix^d,idir)+ein(ix1-1,ix2,ix3,idir)+ein(ix1,ix2-1,ix3,idir)&
7982 +ein(ix1-1,ix2-1,ix3,idir))
7983 if(jce(ix^d,idir)<0.d0) jce(ix^d,idir)=0.d0
7984 w(ix^d,
e_)=w(ix^d,
e_)+qdt*jce(ix^d,idir)
7990 {
do ix^db=ixomin^db,ixomax^db\}
7991 jce(ix^d,idir)=0.25d0*(ein(ix^d,idir)+ein(ix1-1,ix2,idir)+ein(ix1,ix2-1,idir)&
7992 +ein(ix1-1,ix2-1,idir))
7993 if(jce(ix^d,idir)<0.d0) jce(ix^d,idir)=0.d0
7994 w(ix^d,
e_)=w(ix^d,
e_)+qdt*jce(ix^d,idir)
8005 if(
associated(usr_set_electric_field)) &
8006 call usr_set_electric_field(ixi^l,ixo^l,qt,qdt,fe,sct)
8008 circ(ixi^s,1:ndim)=zero
8013 ixcmin^d=ixomin^d-kr(idim1,^d);
8015 ixa^l=ixc^l-kr(idim2,^d);
8018 if(lvc(idim1,idim2,idir)==1)
then
8020 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8023 else if(lvc(idim1,idim2,idir)==-1)
then
8025 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8031 {
do ix^db=ixcmin^db,ixcmax^db\}
8033 if(s%surfaceC(ix^d,idim1) > smalldouble)
then
8035 bfaces(ix^d,idim1)=bfaces(ix^d,idim1)-circ(ix^d,idim1)/s%surfaceC(ix^d,idim1)
8042 end subroutine mhd_update_faces_contact
8045 subroutine mhd_update_faces_hll(ixI^L,ixO^L,qt,qdt,wp,fC,fE,sCT,s,vcts)
8050 integer,
intent(in) :: ixi^
l, ixo^
l
8051 double precision,
intent(in) :: qt, qdt
8053 double precision,
intent(in) :: wp(ixi^s,1:nw)
8054 type(state) :: sct, s
8055 type(ct_velocity) :: vcts
8056 double precision,
intent(in) :: fc(ixi^s,1:nwflux,1:
ndim)
8057 double precision,
intent(inout) :: fe(ixi^s,
sdim:3)
8059 double precision :: vtill(ixi^s,2)
8060 double precision :: vtilr(ixi^s,2)
8061 double precision :: bfacetot(ixi^s,
ndim)
8062 double precision :: btill(ixi^s,
ndim)
8063 double precision :: btilr(ixi^s,
ndim)
8064 double precision :: cp(ixi^s,2)
8065 double precision :: cm(ixi^s,2)
8066 double precision :: circ(ixi^s,1:
ndim)
8068 double precision,
dimension(ixI^S,sdim:3) :: e_resi, e_ambi
8069 integer :: hxc^
l,ixc^
l,ixcp^
l,jxc^
l,ixcm^
l
8070 integer :: idim1,idim2,idir,ix^
d
8072 associate(bfaces=>s%ws,bfacesct=>sct%ws,x=>s%x,vbarc=>vcts%vbarC,cbarmin=>vcts%cbarmin,&
8073 cbarmax=>vcts%cbarmax)
8086 if(
mhd_eta/=zero)
call get_resistive_electric_field(ixi^
l,ixo^
l,wp,sct,s,e_resi)
8102 ixcmin^
d=ixomin^
d-1+
kr(idir,^
d);
8106 idim2=mod(idir+1,3)+1
8108 jxc^
l=ixc^
l+
kr(idim1,^
d);
8109 ixcp^
l=ixc^
l+
kr(idim2,^
d);
8113 vtill(ixi^s,2),vtilr(ixi^s,2))
8116 vtill(ixi^s,1),vtilr(ixi^s,1))
8122 bfacetot(ixi^s,idim1)=bfacesct(ixi^s,idim1)+
block%B0(ixi^s,idim1,idim1)
8123 bfacetot(ixi^s,idim2)=bfacesct(ixi^s,idim2)+
block%B0(ixi^s,idim2,idim2)
8125 bfacetot(ixi^s,idim1)=bfacesct(ixi^s,idim1)
8126 bfacetot(ixi^s,idim2)=bfacesct(ixi^s,idim2)
8129 btill(ixi^s,idim1),btilr(ixi^s,idim1))
8132 btill(ixi^s,idim2),btilr(ixi^s,idim2))
8136 cm(ixc^s,1)=max(cbarmin(ixcp^s,idim1),cbarmin(ixc^s,idim1))
8137 cp(ixc^s,1)=max(cbarmax(ixcp^s,idim1),cbarmax(ixc^s,idim1))
8139 cm(ixc^s,2)=max(cbarmin(jxc^s,idim2),cbarmin(ixc^s,idim2))
8140 cp(ixc^s,2)=max(cbarmax(jxc^s,idim2),cbarmax(ixc^s,idim2))
8144 fe(ixc^s,idir)=-(cp(ixc^s,1)*vtill(ixc^s,1)*btill(ixc^s,idim2) &
8145 + cm(ixc^s,1)*vtilr(ixc^s,1)*btilr(ixc^s,idim2) &
8146 - cp(ixc^s,1)*cm(ixc^s,1)*(btilr(ixc^s,idim2)-btill(ixc^s,idim2)))&
8147 /(cp(ixc^s,1)+cm(ixc^s,1)) &
8148 +(cp(ixc^s,2)*vtill(ixc^s,2)*btill(ixc^s,idim1) &
8149 + cm(ixc^s,2)*vtilr(ixc^s,2)*btilr(ixc^s,idim1) &
8150 - cp(ixc^s,2)*cm(ixc^s,2)*(btilr(ixc^s,idim1)-btill(ixc^s,idim1)))&
8151 /(cp(ixc^s,2)+cm(ixc^s,2))
8154 if(
mhd_eta/=zero) fe(ixc^s,idir)=fe(ixc^s,idir)+e_resi(ixc^s,idir)
8158 fe(ixc^s,idir)=qdt*s%dsC(ixc^s,idir)*fe(ixc^s,idir)
8172 circ(ixi^s,1:
ndim)=zero
8177 ixcmin^
d=ixomin^
d-
kr(idim1,^
d);
8181 if(
lvc(idim1,idim2,idir)/=0)
then
8182 hxc^
l=ixc^
l-
kr(idim2,^
d);
8184 circ(ixc^s,idim1)=circ(ixc^s,idim1)&
8185 +
lvc(idim1,idim2,idir)&
8191 {
do ix^db=ixcmin^db,ixcmax^db\}
8193 if(s%surfaceC(ix^
d,idim1) > smalldouble)
then
8195 bfaces(ix^
d,idim1)=bfaces(ix^
d,idim1)-circ(ix^
d,idim1)/s%surfaceC(ix^
d,idim1)
8201 end subroutine mhd_update_faces_hll
8204 subroutine get_resistive_electric_field(ixI^L,ixO^L,wp,sCT,s,jce)
8209 integer,
intent(in) :: ixi^
l, ixo^
l
8211 double precision,
intent(in) :: wp(ixi^s,1:nw)
8212 type(state),
intent(in) :: sct, s
8214 double precision :: jce(ixi^s,
sdim:3)
8217 double precision :: jcc(ixi^s,7-2*
ndir:3)
8219 double precision :: xs(ixgs^t,1:
ndim)
8221 double precision :: eta(ixi^s)
8222 double precision :: gradi(ixgs^t)
8223 integer :: ix^
d,ixc^
l,ixa^
l,ixb^
l,idir,idirmin,idim1,idim2
8225 associate(x=>s%x,
dx=>s%dx,w=>s%w,wct=>sct%w,wcts=>sct%ws)
8231 if (
lvc(idim1,idim2,idir)==0) cycle
8233 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8234 ixbmax^
d=ixcmax^
d-
kr(idir,^
d)+1;
8237 xs(ixb^s,:)=x(ixb^s,:)
8238 xs(ixb^s,idim2)=x(ixb^s,idim2)+half*
dx(ixb^s,idim2)
8239 call gradientf(wcts(ixgs^t,idim2),xs,ixgs^
ll,ixc^
l,idim1,gradi,2)
8240 if (
lvc(idim1,idim2,idir)==1)
then
8241 jce(ixc^s,idir)=jce(ixc^s,idir)+gradi(ixc^s)
8243 jce(ixc^s,idir)=jce(ixc^s,idir)-gradi(ixc^s)
8250 jce(ixi^s,:)=jce(ixi^s,:)*
mhd_eta
8258 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8259 jcc(ixc^s,idir)=0.d0
8261 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
8262 ixamin^
d=ixcmin^
d+ix^
d;
8263 ixamax^
d=ixcmax^
d+ix^
d;
8264 jcc(ixc^s,idir)=jcc(ixc^s,idir)+eta(ixa^s)
8266 jcc(ixc^s,idir)=jcc(ixc^s,idir)*0.25d0
8267 jce(ixc^s,idir)=jce(ixc^s,idir)*jcc(ixc^s,idir)
8272 end subroutine get_resistive_electric_field
8275 subroutine get_ambipolar_electric_field(ixI^L,ixO^L,w,x,fE)
8278 integer,
intent(in) :: ixi^
l, ixo^
l
8279 double precision,
intent(in) :: w(ixi^s,1:nw)
8280 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8281 double precision,
intent(out) :: fe(ixi^s,
sdim:3)
8283 double precision :: jxbxb(ixi^s,1:3)
8284 integer :: idir,ixa^
l,ixc^
l,ix^
d
8287 call mhd_get_jxbxb(w,x,ixi^
l,ixa^
l,jxbxb)
8294 ixcmin^
d=ixomin^
d+
kr(idir,^
d)-1;
8297 if({ ix^
d==1 .and. ^
d==idir | .or.}) cycle
8298 ixamin^
d=ixcmin^
d+ix^
d;
8299 ixamax^
d=ixcmax^
d+ix^
d;
8300 fe(ixc^s,idir)=fe(ixc^s,idir)+jxbxb(ixa^s,idir)
8302 fe(ixc^s,idir)=fe(ixc^s,idir)*0.25d0
8305 end subroutine get_ambipolar_electric_field
8311 integer,
intent(in) :: ixo^
l
8321 do ix^db=ixomin^db,ixomax^db\}
8323 s%w(ix^
d,b1_)=half/s%surface(ix^
d,1)*(s%ws(ix^
d,1)*s%surfaceC(ix^
d,1)&
8324 +s%ws(ix1-1,ix2,ix3,1)*s%surfaceC(ix1-1,ix2,ix3,1))
8325 s%w(ix^
d,b2_)=half/s%surface(ix^
d,2)*(s%ws(ix^
d,2)*s%surfaceC(ix^
d,2)&
8326 +s%ws(ix1,ix2-1,ix3,2)*s%surfaceC(ix1,ix2-1,ix3,2))
8327 s%w(ix^
d,b3_)=half/s%surface(ix^
d,3)*(s%ws(ix^
d,3)*s%surfaceC(ix^
d,3)&
8328 +s%ws(ix1,ix2,ix3-1,3)*s%surfaceC(ix1,ix2,ix3-1,3))
8331 s%w(ix^
d,b1_)=half/s%surface(ix^
d,1)*(s%ws(ix^
d,1)*s%surfaceC(ix^
d,1)&
8332 +s%ws(ix1-1,ix2,1)*s%surfaceC(ix1-1,ix2,1))
8333 s%w(ix^
d,b2_)=half/s%surface(ix^
d,2)*(s%ws(ix^
d,2)*s%surfaceC(ix^
d,2)&
8334 +s%ws(ix1,ix2-1,2)*s%surfaceC(ix1,ix2-1,2))
8377 integer,
intent(in) :: ixis^
l, ixi^
l, ixo^
l
8378 double precision,
intent(inout) :: ws(ixis^s,1:nws)
8379 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8381 double precision :: adummy(ixis^s,1:3)
8387 subroutine rfactor_from_temperature_ionization(w,x,ixI^L,ixO^L,Rfactor)
8390 integer,
intent(in) :: ixi^
l, ixo^
l
8391 double precision,
intent(in) :: w(ixi^s,1:nw)
8392 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8393 double precision,
intent(out):: rfactor(ixi^s)
8395 double precision :: iz_h(ixo^s),iz_he(ixo^s)
8399 rfactor(ixo^s)=(1.d0+iz_h(ixo^s)+0.1d0*(1.d0+iz_he(ixo^s)*(1.d0+iz_he(ixo^s))))/(2.d0+3.d0*
he_abundance)
8401 end subroutine rfactor_from_temperature_ionization
8403 subroutine rfactor_from_constant_ionization(w,x,ixI^L,ixO^L,Rfactor)
8405 integer,
intent(in) :: ixi^
l, ixo^
l
8406 double precision,
intent(in) :: w(ixi^s,1:nw)
8407 double precision,
intent(in) :: x(ixi^s,1:
ndim)
8408 double precision,
intent(out):: rfactor(ixi^s)
8412 end subroutine rfactor_from_constant_ionization
Module to include CAK radiation line force in (magneto)hydrodynamic models Computes both the force fr...
subroutine cak_init(phys_gamma)
Initialize the module.
subroutine cak_get_dt(wprim, ixil, ixol, dtnew, dxd, x)
Check time step for total radiation contribution.
subroutine 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 mpistop(message)
Exit MPI-AMRVAC with an error message.
Module for physical and numeric constants.
double precision, parameter bigdouble
A very large real number.
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)
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...
subroutine, public fld_get_radpress(w, x, ixil, ixol, rad_pressure)
Returns Radiation Pressure as tensor NOTE: w is primitive on entry.
double precision, public fld_bisect_tol
Tolerance for bisection method for Energy sourceterms This is a percentage of the minimum of gas- and...
double precision, public fld_diff_tol
Tolerance for radiative Energy diffusion.
double precision, public fld_gamma
A copy of (m)hd_gamma.
character(len=40) fld_fluxlimiter
flux limiter choice
character(len=40) fld_opal_table
double precision, public fld_kappa0
Opacity value when using constant opacity.
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 add_fld_rad_force(qdt, ixil, ixol, wct, wctprim, w, x, qsourcesplit, active)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO This subroutine handles th...
logical fld_radforce_split
source split for energy interact and radforce:
subroutine, public fld_init(r_gamma)
Initialising FLD-module Read opacities Initialise Multigrid and adimensionalise kappa.
subroutine, public fld_radforce_get_dt(w, ixil, ixol, dtnew, dxd, x)
get dt limit for radiation force and FLD explicit source additions NOTE: w is primitive on entry
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)
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.
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.
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.
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.
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.
double precision, dimension(:), allocatable, parameter d
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.
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 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 ionization degree - get ionization degree for given temperature
subroutine ionization_degree_from_temperature(ixil, ixol, te, iz_h, iz_he)
subroutine ionization_degree_init()
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.
logical, public, protected mhd_internal_e
Whether internal energy is solved instead of total energy.
logical, public, protected mhd_glm_extended
Whether extended GLM-MHD is used with additional sources.
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)
logical, public, protected mhd_hyperbolic_thermal_conduction
Whether thermal conduction is used.
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.
logical, public, protected mhd_partial_ionization
Whether plasma is partially ionized.
double precision, public divbdiff
Coefficient of diffusive divB cleaning.
double precision, public mhd_eta_hyper
The MHD hyper-resistivity.
subroutine, public mhd_get_temperature_from_prim(w, x, ixil, ixol, res)
Calculate temperature=p/rho when in e_ the pressure p_ (primitive) is stored.
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 mhd_gamma
The adiabatic index.
integer, public, protected mhd_trac_finegrid
Distance between two adjacent traced magnetic field lines (in finest cell size)
subroutine, public get_normalized_divb(w, ixil, ixol, divb)
get dimensionless div B = |divB| * volume / area / |B|
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_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 q_
Index of the heat flux q.
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 CAK radiation line force is activated.
logical, public, protected source_split_divb
Whether divB cleaning sources are added splitting from fluid solver.
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.
double precision, public hypertc_kappa
The thermal conductivity kappa in hyperbolic thermal conduction.
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.
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)
logical, public, protected mhd_viscosity
Whether viscosity is added.
procedure(sub_get_pthermal), pointer, public mhd_get_rfactor
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_htc_sat
Whether saturation is considered for hyperbolic TC.
logical, public, protected mhd_glm
Whether GLM-MHD is used to control div B.
logical, public clean_initial_divb
clean initial divB
procedure(sub_convert), pointer, public mhd_to_conserved
double precision, public mhd_eta
The MHD resistivity.
logical, public divbwave
Add divB wave in Roe solver.
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.
procedure(mask_subroutine), pointer, public usr_mask_ambipolar
character(len=std_len), public, protected typedivbfix
Method type to clean divergence of B.
subroutine, public mhd_get_temperature_from_etot(w, x, ixil, ixol, res)
Calculate temperature=p/rho from total energy.
logical, public, protected mhd_thermal_conduction
Whether thermal conduction is used.
procedure(sub_get_pthermal), pointer, public mhd_get_temperature
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 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.
double precision, public, protected he_ion_fr2
Ratio of number He2+ / number He+ + He2+ He_ion_fr2 = He2+/(He2+ + He+)
procedure(sub_convert), pointer, public mhd_to_primitive
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_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.
logical, public, protected eq_state_units
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, dimension(:), allocatable, public, protected tracer
Indices of the tracers.
integer, public, protected rho_
Index of the density (in the w array)
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.
procedure(sub_get_pthermal), pointer, public mhd_get_pthermal
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, public, protected he_abundance
Helium abundance over Hydrogen.
integer, public, protected tcoff_
Index of the cutoff temperature for the TRAC method.
subroutine, public mhd_get_rho(w, x, ixil, ixol, rho)
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 radiative_cooling_init(fl, read_params)
subroutine radiative_cooling_add_source(qdt, ixil, ixol, wct, wctprim, w, x, qsourcesplit, active, 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.
Module for handling problematic values in simulations, such as negative pressures.
subroutine, public small_values_average(ixil, ixol, w, x, w_flag, windex)
logical, public trace_small_values
trace small values in the source file using traceback flag of compiler
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(phys_gravity), pointer usr_gravity
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.
The data structure that contains information about a tree node/grid block.