188 double precision,
dimension(nsavehi) :: tsave_log, tsave_dat, tsave_slice, &
189 tsave_collapsed, tsave_custom
190 double precision :: dtsave_log, dtsave_dat, dtsave_slice, &
191 dtsave_collapsed, dtsave_custom
192 double precision :: tsavestart_log, tsavestart_dat, tsavestart_slice, &
193 tsavestart_collapsed, tsavestart_custom
194 double precision :: sizeuniformpart^D
195 double precision :: im_delta,im_nu,rka54,rka51,rkb54,rka55
196 double precision :: dx_vec(^ND)
197 integer :: ditsave_log, ditsave_dat, ditsave_slice, &
198 ditsave_collapsed, ditsave_custom
199 integer :: windex, ipower
200 integer :: i, j, k, ifile, io_state
201 integer :: iB, isave, iw, level, idim, islice
202 integer :: nx_vec(^ND), block_nx_vec(^ND)
203 integer :: my_unit, iostate
205 logical :: fileopen, file_exists
208 character(len=80) :: fmt_string
209 character(len=std_len) :: err_msg, restart_from_file_arg
210 character(len=std_len) :: basename_full, basename_prev, dummy_file
211 character(len=std_len),
dimension(:),
allocatable :: &
212 typeboundary_min^D, typeboundary_max^D
213 character(len=std_len),
allocatable :: limiter(:)
214 character(len=std_len),
allocatable :: gradient_limiter(:)
215 character(len=name_len) :: stretch_dim(ndim)
218 character(len=std_len) :: typesourcesplit
220 character(len=std_len),
allocatable :: flux_scheme(:)
222 character(len=std_len) :: typeboundspeed
224 character(len=std_len) :: time_stepper
226 character(len=std_len) :: time_integrator
228 character(len=std_len) :: typecurl
230 character(len=std_len) :: typeprolonglimit
236 character(len=std_len) :: typecourant
251 tsave_log, tsave_dat, tsave_slice, tsave_collapsed, tsave_custom, &
252 dtsave_log, dtsave_dat, dtsave_slice, dtsave_collapsed, dtsave_custom, &
253 ditsave_log, ditsave_dat, ditsave_slice, ditsave_collapsed, ditsave_custom,&
254 tsavestart_log, tsavestart_dat, tsavestart_slice, tsavestart_collapsed,&
261 namelist /methodlist/ time_stepper, time_integrator, &
328 allocate(typeboundary_min^d(nwfluxbc))
329 allocate(typeboundary_max^d(nwfluxbc))
392 typeprolonglimit =
'default'
430 tsave(isave,ifile) = bigdouble
431 itsave(isave,ifile) = biginteger
440 tsave_log = bigdouble
441 tsave_dat = bigdouble
442 tsave_slice = bigdouble
443 tsave_collapsed = bigdouble
444 tsave_custom = bigdouble
446 dtsave_log = bigdouble
447 dtsave_dat = bigdouble
448 dtsave_slice = bigdouble
449 dtsave_collapsed = bigdouble
450 dtsave_custom = bigdouble
452 ditsave_log = biginteger
453 ditsave_dat = biginteger
454 ditsave_slice = biginteger
455 ditsave_collapsed = biginteger
456 ditsave_custom = biginteger
458 tsavestart_log = bigdouble
459 tsavestart_dat = bigdouble
460 tsavestart_slice = bigdouble
461 tsavestart_collapsed = bigdouble
462 tsavestart_custom = bigdouble
486 typecourant =
'maxsum'
495 typeboundspeed =
'Einfeldt'
497 time_stepper =
'twostep'
498 time_integrator =
'default'
546 flux_scheme(level) =
'tvdlf'
548 limiter(level) =
'minmod'
549 gradient_limiter(level) =
'minmod'
556 typesourcesplit =
'sfs'
583 if(i==j.or.j==k.or.k==i)
then
585 else if(i+1==j.or.i-2==j)
then
602 inquire(file=trim(
par_files(i)), exist=file_exists)
604 if (.not. file_exists)
then
605 write(err_msg, *)
"The parameter file " // trim(
par_files(i)) // &
615 read(
unitpar, filelist,
end=101)
618 read(unitpar, savelist,
end=102)
621 read(unitpar, stoplist,
end=103)
624 read(unitpar, methodlist,
end=104)
627 read(unitpar, boundlist,
end=105)
630 read(unitpar, meshlist,
end=106)
633 read(unitpar, paramlist,
end=107)
636 read(unitpar, emissionlist,
end=108)
641 if (base_filename /= basename_prev) &
642 basename_full = trim(basename_full) // trim(base_filename)
643 basename_prev = base_filename
646 base_filename = basename_full
650 dummy_file = trim(base_filename)//
"DUMMY"
651 open(newunit=my_unit, file=trim(dummy_file), iostat=iostate)
652 if (iostate /= 0)
then
653 call mpistop(
"Can't write to output directory (" // &
654 trim(base_filename) //
")")
656 close(my_unit, status=
'delete')
660 if(source_split_usr) any_source_split=.true.
663 if(restart_from_file_arg /= undefined) &
664 restart_from_file=restart_from_file_arg
668 if(restart_from_file == undefined)
then
671 do index_latest_data = 9999, 0, -1
677 if(.not.file_exists) index_latest_data=-1
683 call mpi_bcast(index_latest_data, 1, mpi_integer, 0, icomm, ierrmpi)
685 if (resume_previous_run)
then
686 if (index_latest_data == -1)
then
687 if(mype==0)
write(*,*)
"No snapshots found to resume from, start a new run..."
690 write(restart_from_file,
"(a,i4.4,a)") trim(base_filename),index_latest_data,
".dat"
694 if (restart_from_file == undefined)
then
699 call mpistop(
"Please restart from a snapshot when firstprocess=T")
701 call mpistop(
'Change convert to .false. for a new run!')
704 if (small_pressure < 0.d0)
call mpistop(
"small_pressure should be positive.")
705 if (small_density < 0.d0)
call mpistop(
"small_density should be positive.")
706 if (ghostcell_comm_batched .and. ghostcell_comm_batch_size < 1) &
707 call mpistop(
"ghostcell_comm_batch_size should be positive.")
709 if (small_temperature>0.d0) small_pressure=small_density*small_temperature
711 if(convert) autoconvert=.false.
713 where (tsave_log < bigdouble) tsave(:, 1) = tsave_log
714 where (tsave_dat < bigdouble) tsave(:, 2) = tsave_dat
715 where (tsave_slice < bigdouble) tsave(:, 3) = tsave_slice
716 where (tsave_collapsed < bigdouble) tsave(:, 4) = tsave_collapsed
717 where (tsave_custom < bigdouble) tsave(:, 5) = tsave_custom
719 if (dtsave_log < bigdouble) dtsave(1) = dtsave_log
720 if (dtsave_dat < bigdouble) dtsave(2) = dtsave_dat
721 if (dtsave_slice < bigdouble) dtsave(3) = dtsave_slice
722 if (dtsave_collapsed < bigdouble) dtsave(4) = dtsave_collapsed
723 if (dtsave_custom < bigdouble) dtsave(5) = dtsave_custom
725 if (tsavestart_log < bigdouble) tsavestart(1) = tsavestart_log
726 if (tsavestart_dat < bigdouble) tsavestart(2) = tsavestart_dat
727 if (tsavestart_slice < bigdouble) tsavestart(3) = tsavestart_slice
728 if (tsavestart_collapsed < bigdouble) tsavestart(4) = tsavestart_collapsed
729 if (tsavestart_custom < bigdouble) tsavestart(5) = tsavestart_custom
731 if (ditsave_log < bigdouble) ditsave(1) = ditsave_log
732 if (ditsave_dat < bigdouble) ditsave(2) = ditsave_dat
733 if (ditsave_slice < bigdouble) ditsave(3) = ditsave_slice
734 if (ditsave_collapsed < bigdouble) ditsave(4) = ditsave_collapsed
735 if (ditsave_custom < bigdouble) ditsave(5) = ditsave_custom
737 if (wall_time_max < bigdouble) wall_time_max=wall_time_max*3600.d0
740 write(unitterm, *)
''
741 write(unitterm, *)
'Output type | tsavestart | dtsave | ditsave | itsave(1) | tsave(1)'
742 write(fmt_string, *)
'(A12," | ",E9.3E2," | ",E9.3E2," | ",I6," | "'//&
747 if (mype == 0)
write(unitterm, fmt_string) trim(output_names(ifile)), &
748 tsavestart(ifile), dtsave(ifile), ditsave(ifile), itsave(1, ifile), tsave(1, ifile)
751 if (mype == 0)
write(unitterm, *)
''
754 if(slicedir(islice) > ndim) &
755 write(uniterr,*)
'Warning in read_par_files: ', &
756 'Slice ', islice,
' direction',slicedir(islice),
'larger than ndim=',ndim
757 if(slicedir(islice) < 1) &
758 write(uniterr,*)
'Warning in read_par_files: ', &
759 'Slice ', islice,
' direction',slicedir(islice),
'too small, should be [',1,ndim,
']'
762 if(it_max==biginteger .and. time_max==bigdouble.and.mype==0)
write(uniterr,*) &
763 'Warning in read_par_files: it_max or time_max not given!'
765 select case (typecourant)
767 type_courant=type_maxsum
769 type_courant=type_summax
770 if (local_timestep)
then
771 call mpistop(
"Type courant summax incompatible with local_timestep")
774 type_courant=type_minimum
775 if (local_timestep)
then
776 call mpistop(
"Type courant minimum incompatible with local_timestep")
779 write(unitterm,*)
'Unknown typecourant=',typecourant
780 call mpistop(
"Error from read_par_files: no such typecourant!")
785 select case (flux_scheme(level))
787 flux_method(level)=fs_hll
789 flux_method(level)=fs_hllc
791 flux_method(level)=fs_hlld
793 flux_method(level)=fs_hllcd
795 flux_method(level)=fs_tvdlf
797 flux_method(level)=fs_tvdmu
799 flux_method(level)=fs_tvd
801 flux_method(level)=fs_cd
803 flux_method(level)=fs_cd4
805 flux_method(level)=fs_fd
807 flux_method(level)=fs_source
809 flux_method(level)=fs_nul
811 call mpistop(
"unkown or bad flux scheme")
813 if(flux_scheme(level)==
'tvd'.and.time_stepper/=
'onestep') &
814 call mpistop(
" tvd is onestep method, reset time_stepper='onestep'")
815 if(flux_scheme(level)==
'tvd')
then
816 if(mype==0.and.(.not.dimsplit))
write(unitterm,*) &
817 'Warning: setting dimsplit=T for tvd, as used for level=',level
820 if(flux_scheme(level)==
'hlld'.and.physics_type/=
'mhd' .and. physics_type/=
'twofl') &
821 call mpistop(
"Cannot use hlld flux if not using MHD or 2FL only charges physics!")
823 if(flux_scheme(level)==
'hlld'.and. .not.phys_total_energy) &
824 call mpistop(
"Cannot use hlld flux if not solving total energy equation!")
826 if(flux_scheme(level)==
'hllc'.and.physics_type==
'mf') &
827 call mpistop(
"Cannot use hllc flux if using magnetofriction physics!")
829 if(flux_scheme(level)==
'tvd'.and.physics_type==
'mf') &
830 call mpistop(
"Cannot use tvd flux if using magnetofriction physics!")
832 if(flux_scheme(level)==
'tvdmu'.and.physics_type==
'mf') &
833 call mpistop(
"Cannot use tvdmu flux if using magnetofriction physics!")
835 if (typepred1(level)==0)
then
836 select case (flux_scheme(level))
838 typepred1(level)=fs_cd
840 typepred1(level)=fs_cd4
842 typepred1(level)=fs_fd
843 case (
'tvdlf',
'tvdmu')
844 typepred1(level)=fs_hancock
846 typepred1(level)=fs_hll
848 typepred1(level)=fs_hllc
850 typepred1(level)=fs_hllcd
852 typepred1(level)=fs_hlld
853 case (
'nul',
'source',
'tvd')
854 typepred1(level)=fs_nul
856 call mpistop(
"No default predictor for this full step")
862 if(any(flux_scheme==
'fd')) need_global_cmax=.true.
865 select case (typecurl)
871 type_curl=stokesbased
873 write(unitterm,*)
"typecurl=",typecurl
874 call mpistop(
"unkown type of curl operator in read_par_files")
878 select case (time_stepper)
882 if (time_integrator==
'default')
then
883 time_integrator=
"Forward_Euler"
885 select case (time_integrator)
886 case (
"Forward_Euler")
887 t_integrator=forward_euler
889 t_integrator=imex_euler
893 write(unitterm,*)
"time_integrator=",time_integrator,
"time_stepper=",time_stepper
894 call mpistop(
"unkown onestep time_integrator in read_par_files")
896 use_imex_scheme=(t_integrator==imex_euler.or.t_integrator==imex_sp)
900 if (time_integrator==
'default')
then
901 time_integrator=
"Predictor_Corrector"
903 select case (time_integrator)
904 case (
"Predictor_Corrector")
905 t_integrator=predictor_corrector
910 case (
"IMEX_Midpoint")
911 t_integrator=imex_midpoint
912 case (
"IMEX_Trapezoidal")
913 t_integrator=imex_trapezoidal
915 t_integrator=imex_222
917 write(unitterm,*)
"time_integrator=",time_integrator,
"time_stepper=",time_stepper
918 call mpistop(
"unkown twostep time_integrator in read_par_files")
920 use_imex_scheme=(t_integrator==imex_midpoint.or.t_integrator==imex_trapezoidal&
921 .or.t_integrator==imex_222)
922 if (t_integrator==rk2_alf)
then
923 if(rk2_alfa<smalldouble.or.rk2_alfa>one)
call mpistop(
"set rk2_alfa within [0,1]")
925 rk_b2=1.0d0/(2.0d0*rk2_alfa)
931 if (time_integrator==
'default')
then
932 time_integrator=
'ssprk3'
934 select case (time_integrator)
940 t_integrator=imex_ars3
942 t_integrator=imex_232
944 t_integrator=imex_cb3a
946 write(unitterm,*)
"time_integrator=",time_integrator,
"time_stepper=",time_stepper
947 call mpistop(
"unkown threestep time_integrator in read_par_files")
949 if(t_integrator==rk3_bt)
then
950 select case(rk3_switch)
980 call mpistop(
"Unknown rk3_switch")
983 rk3_b3=1.0d0-rk3_b1-rk3_b2
985 rk3_c3=rk3_a31+rk3_a32
987 if(t_integrator==ssprk3)
then
988 select case(ssprk_order)
991 rk_beta22=1.0d0/4.0d0
992 rk_beta33=2.0d0/3.0d0
993 rk_alfa21=3.0d0/4.0d0
994 rk_alfa31=1.0d0/3.0d0
998 rk_beta11=1.0d0/2.0d0
999 rk_beta22=1.0d0/2.0d0
1000 rk_beta33=1.0d0/3.0d0
1002 rk_alfa31=1.0d0/3.0d0
1006 call mpistop(
"Unknown ssprk3_order")
1008 rk_alfa22=1.0d0-rk_alfa21
1009 rk_alfa33=1.0d0-rk_alfa31
1011 if(t_integrator==imex_ars3)
then
1012 ars_gamma=(3.0d0+dsqrt(3.0d0))/6.0d0
1014 if(t_integrator==imex_232)
then
1015 select case(imex_switch)
1017 im_delta=1.0d0-1.0d0/dsqrt(2.0d0)
1018 im_nu=(3.0d0+2.0d0*dsqrt(2.0d0))/6.0d0
1019 imex_a21=2.0d0*im_delta
1020 imex_a31=1.0d0-im_nu
1022 imex_b1=1.0d0/(2.0d0*dsqrt(2.0d0))
1023 imex_b2=1.0d0/(2.0d0*dsqrt(2.0d0))
1028 imex_a21=0.711664700366941d0
1029 imex_a31=0.077338168947683d0
1030 imex_a32=0.917273367886007d0
1031 imex_b1=0.398930808264688d0
1032 imex_b2=0.345755244189623d0
1033 imex_ha21=0.353842865099275d0
1034 imex_ha22=0.353842865099275d0
1036 call mpistop(
"Unknown imex_siwtch")
1039 imex_c3=imex_a31+imex_a32
1040 imex_b3=1.0d0-imex_b1-imex_b2
1042 if(t_integrator==imex_cb3a)
then
1043 imex_c2 = 0.8925502329346865
1046 imex_c3 = imex_c2 / (6.0d0*imex_c2**2 - 3.0d0*imex_c2 + 1.0d0)
1048 imex_b2 = (3.0d0*imex_c2 - 1.0d0) / (6.0d0*imex_c2**2)
1049 imex_b3 = (6.0d0*imex_c2**2 - 3.0d0*imex_c2 + 1.0d0) / (6.0d0*imex_c2**2)
1050 imex_a33 = (1.0d0/6.0d0 - imex_b2*imex_c2**2 - imex_b3*imex_c2*imex_c3) / (imex_b3*(imex_c3-imex_c2))
1051 imex_a32 = imex_c3 - imex_a33
1065 use_imex_scheme=(t_integrator==imex_ars3.or.t_integrator==imex_232.or.t_integrator==imex_cb3a)
1069 if (time_integrator==
'default')
then
1070 time_integrator=
"ssprk4"
1072 select case (time_integrator)
1078 write(unitterm,*)
"time_integrator=",time_integrator,
"time_stepper=",time_stepper
1079 call mpistop(
"unkown fourstep time_integrator in read_par_files")
1081 if(t_integrator==ssprk4)
then
1082 select case(ssprk_order)
1084 rk_beta11=1.0d0/2.0d0
1085 rk_beta22=1.0d0/2.0d0
1086 rk_beta33=1.0d0/6.0d0
1087 rk_beta44=1.0d0/2.0d0
1089 rk_alfa31=2.0d0/3.0d0
1095 rk_beta11=1.0d0/3.0d0
1096 rk_beta22=1.0d0/3.0d0
1097 rk_beta33=1.0d0/3.0d0
1098 rk_beta44=1.0d0/4.0d0
1101 rk_alfa41=1.0d0/4.0d0
1106 call mpistop(
"Unknown ssprk_order")
1108 rk_alfa22=1.0d0-rk_alfa21
1109 rk_alfa33=1.0d0-rk_alfa31
1110 rk_alfa44=1.0d0-rk_alfa41
1115 if (time_integrator==
'default')
then
1116 time_integrator=
"ssprk5"
1118 select case (time_integrator)
1122 write(unitterm,*)
"time_integrator=",time_integrator,
"time_stepper=",time_stepper
1123 call mpistop(
"unkown fivestep time_integrator in read_par_files")
1125 if(t_integrator==ssprk5)
then
1126 select case(ssprk_order)
1129 rk_beta11=0.391752226571890d0
1130 rk_beta22=0.368410593050371d0
1131 rk_beta33=0.251891774271694d0
1132 rk_beta44=0.544974750228521d0
1133 rk_beta54=0.063692468666290d0
1134 rk_beta55=0.226007483236906d0
1135 rk_alfa21=0.444370493651235d0
1136 rk_alfa31=0.620101851488403d0
1137 rk_alfa41=0.178079954393132d0
1138 rk_alfa53=0.517231671970585d0
1139 rk_alfa54=0.096059710526147d0
1141 rk_alfa22=0.555629506348765d0
1142 rk_alfa33=0.379898148511597d0
1143 rk_alfa44=0.821920045606868d0
1144 rk_alfa55=0.386708617503269d0
1145 rk_alfa22=1.0d0-rk_alfa21
1146 rk_alfa33=1.0d0-rk_alfa31
1147 rk_alfa44=1.0d0-rk_alfa41
1148 rk_alfa55=1.0d0-rk_alfa53-rk_alfa54
1150 rk_c3=rk_alfa22*rk_c2+rk_beta22
1151 rk_c4=rk_alfa33*rk_c3+rk_beta33
1152 rk_c5=rk_alfa44*rk_c4+rk_beta44
1154 rk_beta11=0.39175222700392d0
1155 rk_beta22=0.36841059262959d0
1156 rk_beta33=0.25189177424738d0
1157 rk_beta44=0.54497475021237d0
1160 rk_alfa21=0.44437049406734d0
1161 rk_alfa31=0.62010185138540d0
1162 rk_alfa41=0.17807995410773d0
1163 rk_alfa53=0.51723167208978d0
1166 rk_alfa22=1.0d0-rk_alfa21
1167 rk_alfa33=1.0d0-rk_alfa31
1168 rk_alfa44=1.0d0-rk_alfa41
1170 rka51=0.00683325884039d0
1171 rka54=0.12759831133288d0
1172 rkb54=0.08460416338212d0
1173 rk_beta54=rkb54-rk_beta44*rka51/rk_alfa41
1174 rk_alfa54=rka54-rk_alfa44*rka51/rk_alfa41
1176 rk_alfa55=1.0d0-rk_alfa53-rk_alfa54
1178 rk_c3=rk_alfa22*rk_c2+rk_beta22
1179 rk_c4=rk_alfa33*rk_c3+rk_beta33
1180 rk_c5=rk_alfa44*rk_c4+rk_beta44
1181 rk_beta55=1.0d0-rk_beta54-rk_alfa53*rk_c3-rk_alfa54*rk_c4-rk_alfa55*rk_c5
1183 call mpistop(
"Unknown ssprk_order")
1192 use_imex_scheme=.false.
1194 call mpistop(
"Unknown time_stepper in read_par_files")
1198 select case (stretch_dim(i))
1199 case (undefined,
'none')
1200 stretch_type(i) = stretch_none
1201 stretched_dim(i) = .false.
1202 case (
'uni',
'uniform')
1203 stretch_type(i) = stretch_uni
1204 stretched_dim(i) = .true.
1205 case (
'symm',
'symmetric')
1206 stretch_type(i) = stretch_symm
1207 stretched_dim(i) = .true.
1209 stretch_type(i) = stretch_none
1210 stretched_dim(i) = .false.
1211 if (mype == 0) print *,
'Got stretch_type = ', stretch_type(i)
1212 call mpistop(
'Unknown stretch type')
1217 if(typedimsplit ==
'default'.and. dimsplit) typedimsplit=
'xyyx'
1218 if(typedimsplit ==
'default'.and..not.dimsplit) typedimsplit=
'unsplit'
1219 dimsplit = typedimsplit /=
'unsplit'
1222 select case (typesourcesplit)
1224 sourcesplit=sourcesplit_sfs
1226 sourcesplit=sourcesplit_sf
1228 sourcesplit=sourcesplit_ssf
1230 sourcesplit=sourcesplit_ssfss
1232 write(unitterm,*)
'No such typesourcesplit=',typesourcesplit
1233 call mpistop(
"Error: Unknown typesourcesplit!")
1236 if(coordinate==-1)
then
1237 coordinate=cartesian
1239 write(*,*)
'Warning: coordinate system is not specified!'
1240 write(*,*)
'call set_coordinate_system in usr_init in mod_usr.t'
1241 write(*,*)
'Now use Cartesian coordinate'
1245 if(coordinate==cartesian)
then
1248 if(any(stretched_dim))
then
1249 coordinate=cartesian_stretched
1250 slab_uniform=.false.
1254 slab_uniform=.false.
1257 if(coordinate==spherical)
then
1259 if(mype==0)print *,
'Warning: spherical symmetry needs dimsplit=F, resetting'
1264 if (ndim==1) dimsplit=.false.
1267 select case(typeprolonglimit)
1282 allocate(type_limiter(nlevelshi))
1283 allocate(type_gradient_limiter(nlevelshi))
1285 do level=1,nlevelshi
1286 type_limiter(level) = limiter_type(limiter(level))
1287 type_gradient_limiter(level) = limiter_type(gradient_limiter(level))
1290 if (any(limiter(1:nlevelshi)==
'ppm')&
1291 .and.(flatsh.and.physics_type==
'rho'))
then
1292 call mpistop(
" PPM with flatsh=.true. can not be used with physics_type='rho'!")
1298 select case(typeboundary_min^d(iw))
1300 typeboundary(iw,2*^d-1)=bc_special
1302 typeboundary(iw,2*^d-1)=bc_cont
1304 typeboundary(iw,2*^d-1)=bc_symm
1306 typeboundary(iw,2*^d-1)=bc_asymm
1308 typeboundary(iw,2*^d-1)=bc_periodic
1310 typeboundary(iw,2*^d-1)=bc_aperiodic
1312 typeboundary(iw,2*^d-1)=bc_noinflow
1314 typeboundary(iw,2*^d-1)=12
1316 typeboundary(iw,2*^d-1)=bc_data
1318 typeboundary(iw,2*^d-1)=bc_icarus
1320 typeboundary(iw,2*^d-1)=bc_character
1322 write (unitterm,*)
"Undefined boundarytype found in read_par_files", &
1323 typeboundary_min^d(iw),
"for variable iw=",iw,
" and side iB=",2*^d-1
1327 select case(typeboundary_max^d(iw))
1329 typeboundary(iw,2*^d)=bc_special
1331 typeboundary(iw,2*^d)=bc_cont
1333 typeboundary(iw,2*^d)=bc_symm
1335 typeboundary(iw,2*^d)=bc_asymm
1337 typeboundary(iw,2*^d)=bc_periodic
1339 typeboundary(iw,2*^d)=bc_aperiodic
1341 typeboundary(iw,2*^d)=bc_noinflow
1343 typeboundary(iw,2*^d)=12
1345 typeboundary(iw,2*^d)=bc_data
1347 typeboundary(iw,2*^d-1)=bc_icarus
1348 case(
"bc_character")
1349 typeboundary(iw,2*^d)=bc_character
1351 write (unitterm,*)
"Undefined boundarytype found in read_par_files", &
1352 typeboundary_max^d(iw),
"for variable iw=",iw,
" and side iB=",2*^d
1358 if (nwfluxbc<nwflux)
then
1359 do iw=nwfluxbc+1,nwflux
1360 typeboundary(iw,:) = typeboundary(1, :)
1365 do iw=nwflux+1, nwflux+nwaux
1366 typeboundary(iw,:) = typeboundary(1, :)
1370 if (any(typeboundary == 0))
then
1371 call mpistop(
"Not all boundary conditions have been defined")
1375 periodb(idim)=(any(typeboundary(:,2*idim-1:2*idim)==bc_periodic))
1376 aperiodb(idim)=(any(typeboundary(:,2*idim-1:2*idim)==bc_aperiodic))
1377 if (periodb(idim).or.aperiodb(idim))
then
1379 if (typeboundary(iw,2*idim-1) .ne. typeboundary(iw,2*idim)) &
1380 call mpistop(
"Wrong counterpart in periodic boundary")
1382 if (typeboundary(iw,2*idim-1) /= bc_periodic .and. &
1383 typeboundary(iw,2*idim-1) /= bc_aperiodic)
then
1384 call mpistop(
"Each dimension should either have all "//&
1385 "or no variables periodic, some can be aperiodic")
1392 if(any(typeboundary(:,2*idim-1)==12))
then
1393 if(any(typeboundary(:,2*idim-1)/=12)) typeboundary(:,2*idim-1)=12
1394 select case(physics_type)
1395 case (
'rho',
'ard',
'nonlinear',
'ffhd')
1397 typeboundary(:,2*idim-1)=bc_symm
1398 if(mype==0) print *,
'symmetric minimal pole'
1399 case (
'hd',
'rhd',
'srhd',
'mhd',
'rmhd')
1400 typeboundary(:,2*idim-1)=bc_symm
1402 if(phys_energy)
then
1407 select case(coordinate)
1410 typeboundary(r_+1,2*idim-1)=bc_asymm
1411 typeboundary(phi_+1,2*idim-1)=bc_asymm
1412 if(physics_type==
'mhd'.or.physics_type==
'rmhd')
then
1413 typeboundary(ndir+windex+r_,2*idim-1)=bc_asymm
1414 typeboundary(ndir+windex+phi_,2*idim-1)=bc_asymm
1417 typeboundary(3:ndir+1,2*idim-1)=bc_asymm
1418 if(physics_type==
'mhd'.or.physics_type==
'rmhd') typeboundary(ndir+windex+2:ndir+windex+ndir,2*idim-1)=bc_asymm
1420 call mpistop(
'Pole is in cylindrical, polar, spherical coordinates!')
1423 call mpistop(
'Pole treatment for twofl not implemented yet')
1425 if (ndim /= 3 .or. coordinate /= spherical .or. idim /= 2) &
1426 call mpistop(
"MF pole requires a 3D spherical theta boundary")
1429 if (.not. periodb(3) .or. abs(xprobmax3-xprobmin3-one) >= smalldouble) &
1430 call mpistop(
"MF pole requires full periodic longitude")
1431 if (abs(xprobmin2) >= smalldouble) &
1432 call mpistop(
"MF pole requires a true theta pole")
1434 typeboundary(:,2*idim-1)=bc_symm
1435 typeboundary(iw_mom(2:3),2*idim-1)=bc_asymm
1436 typeboundary(iw_mag(2:3),2*idim-1)=bc_asymm
1439 call mpistop(
'unknown physics type for setting minimal pole boundary treatment')
1442 if(any(typeboundary(:,2*idim)==12))
then
1443 if(any(typeboundary(:,2*idim)/=12)) typeboundary(:,2*idim)=12
1444 select case(physics_type)
1445 case (
'rho',
'ard',
'nonlinear',
'ffhd')
1447 typeboundary(:,2*idim)=bc_symm
1448 if(mype==0) print *,
'symmetric maximal pole'
1449 case (
'hd',
'rhd',
'srhd',
'mhd',
'rmhd')
1450 typeboundary(:,2*idim)=bc_symm
1452 if(phys_energy)
then
1457 select case(coordinate)
1460 typeboundary(r_+1,2*idim)=bc_asymm
1461 typeboundary(phi_+1,2*idim)=bc_asymm
1462 if(physics_type==
'mhd'.or.physics_type==
'rmhd')
then
1463 typeboundary(ndir+windex+r_,2*idim)=bc_asymm
1464 typeboundary(ndir+windex+phi_,2*idim)=bc_asymm
1467 typeboundary(3:ndir+1,2*idim)=bc_asymm
1468 if(physics_type==
'mhd'.or.physics_type==
'rmhd') typeboundary(ndir+windex+2:ndir+windex+ndir,2*idim)=bc_asymm
1470 call mpistop(
'Pole is in cylindrical, polar, spherical coordinates!')
1473 call mpistop(
'Pole treatment for twofl not implemented yet')
1475 if (ndim /= 3 .or. coordinate /= spherical .or. idim /= 2) &
1476 call mpistop(
"MF pole requires a 3D spherical theta boundary")
1479 if (.not. periodb(3) .or. abs(xprobmax3-xprobmin3-one) >= smalldouble) &
1480 call mpistop(
"MF pole requires full periodic longitude")
1481 if (abs(xprobmax2-half) >= smalldouble) &
1482 call mpistop(
"MF pole requires a true theta pole")
1484 typeboundary(:,2*idim)=bc_symm
1485 typeboundary(iw_mom(2:3),2*idim)=bc_asymm
1486 typeboundary(iw_mag(2:3),2*idim)=bc_asymm
1489 call mpistop(
'unknown physics type for setting maximal pole boundary treatment')
1495 if(.not.phys_energy)
then
1500 if(any(limiter(1:nlevelshi)==
'mp5'))
then
1501 nghostcells=max(nghostcells,3)
1504 if(any(limiter(1:nlevelshi)==
'weno5'))
then
1505 nghostcells=max(nghostcells,3)
1508 if(any(limiter(1:nlevelshi)==
'weno5nm'))
then
1509 nghostcells=max(nghostcells,3)
1512 if(any(limiter(1:nlevelshi)==
'wenoz5'))
then
1513 nghostcells=max(nghostcells,3)
1516 if(any(limiter(1:nlevelshi)==
'wenoz5nm'))
then
1517 nghostcells=max(nghostcells,3)
1520 if(any(limiter(1:nlevelshi)==
'wenozp5'))
then
1521 nghostcells=max(nghostcells,3)
1524 if(any(limiter(1:nlevelshi)==
'wenozp5nm'))
then
1525 nghostcells=max(nghostcells,3)
1528 if(any(limiter(1:nlevelshi)==
'teno5ad'))
then
1529 nghostcells=max(nghostcells,3)
1532 if(any(limiter(1:nlevelshi)==
'weno5cu6'))
then
1533 nghostcells=max(nghostcells,3)
1536 if(any(limiter(1:nlevelshi)==
'ppm'))
then
1537 if(flatsh .or. flatcd)
then
1538 nghostcells=max(nghostcells,4)
1540 nghostcells=max(nghostcells,3)
1544 if(any(limiter(1:nlevelshi)==
'weno7'))
then
1545 nghostcells=max(nghostcells,4)
1548 if(any(limiter(1:nlevelshi)==
'mpweno7'))
then
1549 nghostcells=max(nghostcells,4)
1553 nghostcells = nghostcells + phys_wider_stencil
1556 if(stagger_grid .and. refine_max_level>1 .and. mod(nghostcells,2)/=0)
then
1557 nghostcells=nghostcells+1
1560 select case (coordinate)
1563 xprob^lim^de=xprob^lim^de*two*dpi;
1568 xprob^lim^d=xprob^lim^d*two*dpi;
1574 {ixghi^d = block_nx^d + 2*nghostcells\}
1575 {ixgshi^d = ixghi^d\}
1577 nx_vec = [{domain_nx^d|, }]
1578 block_nx_vec = [{block_nx^d|, }]
1580 if (any(nx_vec < 4) .or. any(mod(nx_vec, 2) == 1)) &
1581 call mpistop(
'Grid size (domain_nx^D) has to be even and >= 4')
1583 if (any(block_nx_vec < 4) .or. any(mod(block_nx_vec, 2) == 1)) &
1584 call mpistop(
'Block size (block_nx^D) has to be even and >= 4')
1586 {
if(mod(domain_nx^d,block_nx^d)/=0) &
1587 call mpistop(
'Grid (domain_nx^D) and block (block_nx^D) must be consistent') \}
1589 if(refine_max_level>nlevelshi.or.refine_max_level<1)
then
1590 write(unitterm,*)
'Error: refine_max_level',refine_max_level,
'>nlevelshi ',nlevelshi
1591 call mpistop(
"Reset nlevelshi and recompile!")
1594 if (any(stretched_dim))
then
1595 allocate(qstretch(0:nlevelshi,1:ndim),dxfirst(0:nlevelshi,1:ndim),&
1596 dxfirst_1mq(0:nlevelshi,1:ndim),dxmid(0:nlevelshi,1:ndim))
1597 allocate(nstretchedblocks(1:nlevelshi,1:ndim))
1598 qstretch(0:nlevelshi,1:ndim)=0.0d0
1599 dxfirst(0:nlevelshi,1:ndim)=0.0d0
1600 nstretchedblocks(1:nlevelshi,1:ndim)=0
1601 {
if (stretch_type(^d) == stretch_uni)
then
1603 if(qstretch_baselevel(^d)<1.0d0.or.qstretch_baselevel(^d)==bigdouble)
then
1605 write(*,*)
'stretched grid needs finite qstretch_baselevel>1'
1606 write(*,*)
'will try default value for qstretch_baselevel in dimension', ^d
1608 if(xprobmin^d>smalldouble)
then
1609 qstretch_baselevel(^d)=(xprobmax^d/xprobmin^d)**(1.d0/dble(domain_nx^d))
1611 call mpistop(
"can not set qstretch_baselevel automatically")
1614 if(mod(block_nx^d,2)==1) &
1615 call mpistop(
"stretched grid needs even block size block_nxD")
1616 if(mod(domain_nx^d/block_nx^d,2)/=0) &
1617 call mpistop(
"number level 1 blocks in D must be even")
1618 qstretch(1,^d)=qstretch_baselevel(^d)
1619 dxfirst(1,^d)=(xprobmax^d-xprobmin^d) &
1620 *(1.0d0-qstretch(1,^d))/(1.0d0-qstretch(1,^d)**domain_nx^d)
1621 qstretch(0,^d)=qstretch(1,^d)**2
1622 dxfirst(0,^d)=dxfirst(1,^d)*(1.0d0+qstretch(1,^d))
1623 if(refine_max_level>1)
then
1624 do ilev=2,refine_max_level
1625 qstretch(ilev,^d)=dsqrt(qstretch(ilev-1,^d))
1626 dxfirst(ilev,^d)=dxfirst(ilev-1,^d) &
1627 /(1.0d0+dsqrt(qstretch(ilev-1,^d)))
1632 {
if(stretch_type(^d) == stretch_uni)
then
1633 write(*,*)
'Stretched dimension ', ^d
1634 write(*,*)
'Using stretched grid with qs=',qstretch(0:refine_max_level,^d)
1635 write(*,*)
' and first cell sizes=',dxfirst(0:refine_max_level,^d)
1638 {
if(stretch_type(^d) == stretch_symm)
then
1640 write(*,*)
'will apply symmetric stretch in dimension', ^d
1642 if(mod(block_nx^d,2)==1) &
1643 call mpistop(
"stretched grid needs even block size block_nxD")
1645 if(nstretchedblocks_baselevel(^d)==0) &
1646 call mpistop(
"need finite even number of stretched blocks at baselevel")
1647 if(mod(nstretchedblocks_baselevel(^d),2)==1) &
1648 call mpistop(
"need even number of stretched blocks at baselevel")
1649 if(qstretch_baselevel(^d)<1.0d0.or.qstretch_baselevel(^d)==bigdouble) &
1650 call mpistop(
'stretched grid needs finite qstretch_baselevel>1')
1652 ipower=(nstretchedblocks_baselevel(^d)/2)*block_nx^d
1653 if(nstretchedblocks_baselevel(^d)==domain_nx^d/block_nx^d)
then
1654 xstretch^d=0.5d0*(xprobmax^d-xprobmin^d)
1656 xstretch^d=(xprobmax^d-xprobmin^d) &
1657 /(2.0d0+dble(domain_nx^d-nstretchedblocks_baselevel(^d)*block_nx^d) &
1658 *(1.0d0-qstretch_baselevel(^d))/(1.0d0-qstretch_baselevel(^d)**ipower))
1660 if(xstretch^d>(xprobmax^d-xprobmin^d)*0.5d0) &
1661 call mpistop(
" stretched grid part should not exceed full domain")
1662 dxfirst(1,^d)=xstretch^d*(1.0d0-qstretch_baselevel(^d)) &
1663 /(1.0d0-qstretch_baselevel(^d)**ipower)
1664 nstretchedblocks(1,^d)=nstretchedblocks_baselevel(^d)
1665 qstretch(1,^d)=qstretch_baselevel(^d)
1666 qstretch(0,^d)=qstretch(1,^d)**2
1667 dxfirst(0,^d)=dxfirst(1,^d)*(1.0d0+qstretch(1,^d))
1668 dxmid(1,^d)=dxfirst(1,^d)
1669 dxmid(0,^d)=dxfirst(1,^d)*2.0d0
1670 if(refine_max_level>1)
then
1671 do ilev=2,refine_max_level
1672 nstretchedblocks(ilev,^d)=2*nstretchedblocks(ilev-1,^d)
1673 qstretch(ilev,^d)=dsqrt(qstretch(ilev-1,^d))
1674 dxfirst(ilev,^d)=dxfirst(ilev-1,^d) &
1675 /(1.0d0+dsqrt(qstretch(ilev-1,^d)))
1676 dxmid(ilev,^d)=dxmid(ilev-1,^d)/2.0d0
1680 sizeuniformpart^d=dxfirst(1,^d) &
1681 *(domain_nx^d-nstretchedblocks_baselevel(^d)*block_nx^d)
1683 print *,
'uniform part of size=',sizeuniformpart^d
1684 print *,
'setting of domain is then=',2*xstretch^d+sizeuniformpart^d
1685 print *,
'versus=',xprobmax^d-xprobmin^d
1687 if(dabs(xprobmax^d-xprobmin^d-2*xstretch^d-sizeuniformpart^d)>smalldouble)
then
1688 call mpistop(
'mismatch in domain size!')
1691 dxfirst_1mq(0:refine_max_level,1:ndim)=dxfirst(0:refine_max_level,1:ndim) &
1692 /(1.0d0-qstretch(0:refine_max_level,1:ndim))
1695 dx_vec = [{xprobmax^d-xprobmin^d|, }] / nx_vec
1698 write(c_ndim,
'(I1)') ^nd
1699 write(unitterm,
'(A30,' // c_ndim //
'(I0," "))') &
1700 ' Domain size (cells): ', nx_vec
1701 write(unitterm,
'(A30,' // c_ndim //
'(E9.3," "))') &
1702 ' Level one dx: ', dx_vec
1705 if (any(dx_vec < smalldouble)) &
1706 call mpistop(
"Incorrect domain size (too small grid spacing)")
1710 if(sum(w_refine_weight(:))==0) w_refine_weight(1) = 1.d0
1711 if(dabs(sum(w_refine_weight(:))-1.d0)>smalldouble)
then
1712 write(unitterm,*)
"Sum of all elements in w_refine_weight be 1.d0"
1713 call mpistop(
"Reset w_refine_weight so the sum is 1.d0")
1716 select case (typeboundspeed)
1721 case(
'cmaxleftright')
1726 call mpistop(
"set typeboundspeed='Einfeldt' or 'cmaxmean' or 'cmaxleftright' or 'pvrs'")
1729 if (mype==0)
write(unitterm,
'(A30)', advance=
'no')
'Refine estimation: '
1731 select case (refine_criterion)
1733 if (mype==0)
write(unitterm,
'(A)')
"user defined"
1735 if (mype==0)
write(unitterm,
'(A)')
"relative error"
1737 if (mype==0)
write(unitterm,
'(A)')
"Lohner's original scheme"
1739 if (mype==0)
write(unitterm,
'(A)')
"Lohner's scheme"
1741 call mpistop(
"Unknown error estimator, change refine_criterion")
1744 if (tfixgrid<bigdouble/2.0d0)
then
1745 if(mype==0)print*,
'Warning, at time=',tfixgrid,
'the grid will be fixed'
1747 if (itfixgrid<biginteger/2)
then
1748 if(mype==0)print*,
'Warning, at iteration=',itfixgrid,
'the grid will be fixed'
1750 if (ditregrid>1)
then
1751 if(mype==0)print*,
'Note, Grid is reconstructed once every',ditregrid,
'iterations'
1756 select case(slicedir(islice))
1758 if(slicecoord(islice)<xprobmin^d.or.slicecoord(islice)>xprobmax^d) &
1759 write(uniterr,*)
'Warning in read_par_files: ', &
1760 'Slice ', islice,
' coordinate',slicecoord(islice),
'out of bounds for dimension ',slicedir(islice)
1766 write(unitterm,
'(A30,A,A)')
'restart_from_file: ',
' ', trim(restart_from_file)
1767 write(unitterm,
'(A30,L1)')
'converting: ', convert
1768 write(unitterm,
'(A)')
''
1771 deallocate(flux_scheme)
1923 integer,
intent(in) :: fh
1924 integer(MPI_OFFSET_KIND),
intent(out) :: offset_tree
1925 integer(MPI_OFFSET_KIND),
intent(out) :: offset_block
1927 double precision :: rbuf(ndim)
1928 double precision,
allocatable :: params(:)
1929 integer :: i, version
1930 integer :: ibuf(ndim), iw
1931 integer :: er, n_par, tmp_int
1932 integer,
dimension(MPI_STATUS_SIZE) :: st
1933 logical :: periodic(ndim)
1934 character(len=name_len),
allocatable :: var_names(:), param_names(:)
1935 character(len=name_len) :: phys_name, geom_name
1938 call mpi_file_read(fh, version, 1, mpi_integer, st, er)
1940 call mpistop(
"Incompatible file version (maybe old format?)")
1944 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1945 offset_tree = ibuf(1)
1948 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1949 offset_block = ibuf(1)
1952 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1954 if (nw /= ibuf(1))
then
1955 write(*,*)
"nw=",nw,
" and nw found in restart file=",ibuf(1)
1956 write(*,*)
"Please be aware of changes in w at restart."
1961 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1962 if (ibuf(1) /=
ndir)
then
1965 write(*,*)
"WARNING: ndir in restart file = ",ibuf(1),
" but current ndir = ",
ndir
1966 write(*,*)
"allow_ndir_change=T: loading anyway (block I/O is ndim-based)."
1967 write(*,*)
"Ensure usr_transform_w maps the source vars into the right slots."
1970 write(*,*)
"ndir in restart file = ",ibuf(1)
1971 write(*,*)
"ndir = ",
ndir
1972 call mpistop(
"reset ndir to ndir in restart file (or set allow_ndir_change=T)")
1977 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1978 if (ibuf(1) /= ndim)
then
1979 write(*,*)
"ndim in restart file = ",ibuf(1)
1980 write(*,*)
"ndim = ",ndim
1981 call mpistop(
"reset ndim to ndim in restart file")
1985 call mpi_file_read(fh, ibuf(1), 1, mpi_integer, st, er)
1987 write(*,*)
"number of levels in restart file = ",ibuf(1)
1989 call mpistop(
"refine_max_level < num. levels in restart file")
1993 call mpi_file_read(fh,
nleafs, 1, mpi_integer, st, er)
1996 call mpi_file_read(fh,
nparents, 1, mpi_integer, st, er)
1999 call mpi_file_read(fh,
it, 1, mpi_integer, st, er)
2002 call mpi_file_read(fh,
global_time, 1, mpi_double_precision, st, er)
2005 call mpi_file_read(fh,rbuf(1:ndim),ndim,mpi_double_precision,st,er)
2006 if (maxval(abs(rbuf(1:ndim) - [ xprobmin^
d ])) > 0)
then
2007 write(*,*)
"Error: xprobmin differs from restart data: ", rbuf(1:ndim)
2008 call mpistop(
"change xprobmin^D in par file")
2012 call mpi_file_read(fh,rbuf(1:ndim),ndim,mpi_double_precision,st,er)
2013 if (maxval(abs(rbuf(1:ndim) - [ xprobmax^
d ])) > 0)
then
2014 write(*,*)
"Error: xprobmax differs from restart data: ", rbuf(1:ndim)
2015 call mpistop(
"change xprobmax^D in par file")
2019 call mpi_file_read(fh,ibuf(1:ndim), ndim, mpi_integer,st,er)
2020 if (any(ibuf(1:ndim) /= [
domain_nx^
d ]))
then
2021 write(*,*)
"Error: mesh size differs from restart data: ", ibuf(1:ndim)
2022 call mpistop(
"change domain_nx^D in par file")
2026 call mpi_file_read(fh,ibuf(1:ndim), ndim, mpi_integer,st,er)
2027 if (any(ibuf(1:ndim) /= [
block_nx^
d ]))
then
2028 write(*,*)
"Error: block size differs from restart data:", ibuf(1:ndim)
2029 call mpistop(
"change block_nx^D in par file")
2033 if (version > 4)
then
2034 call mpi_file_read(fh, periodic, ndim, mpi_logical, st, er)
2035 if ({periodic(^
d) .and. .not.
periodb(^
d) .or. .not.periodic(^
d) .and.
periodb(^
d)| .or. }) &
2036 call mpistop(
"change in periodicity in par file")
2038 call mpi_file_read(fh, geom_name, name_len, mpi_character, st, er)
2042 if (
mype==0)
write(*,*)
"WARNING: coordinates in data = ",trim(geom_name), &
2043 " vs current ",trim(
geometry_name),
"; allow_ndir_change=T (e.g. Cartesian_2D->2.5D), loading anyway."
2045 write(*,*)
"type of coordinates in data is: ", geom_name
2046 call mpistop(
"select the correct coordinates in mod_usr.t file")
2050 call mpi_file_read(fh, stagger_mark_dat, 1, mpi_logical, st, er)
2052 write(*,*)
"Warning: stagger grid flag differs from restart data:", stagger_mark_dat
2058 if (version > 3)
then
2062 call mpi_file_read(fh, var_names(iw), name_len, mpi_character, st, er)
2066 call mpi_file_read(fh, phys_name, name_len, mpi_character, st, er)
2072 call mpi_file_read(fh, n_par, 1, mpi_integer, st, er)
2073 allocate(params(n_par))
2074 allocate(param_names(n_par))
2075 call mpi_file_read(fh, params, n_par, mpi_double_precision, st, er)
2076 call mpi_file_read(fh, param_names, name_len * n_par, mpi_character, st, er)
2079 call mpi_file_read(fh, tmp_int, 1, mpi_integer, st, er)
2084 call mpi_file_read(fh, tmp_int, 1, mpi_integer, st, er)
2087 call mpi_file_read(fh, tmp_int, 1, mpi_integer, st, er)