3 use,
intrinsic :: iso_fortran_env
12 integer,
parameter ::
dp = real64
15 complex(dp),
parameter ::
ic = (0.0d0, 1.0d0)
21 complex(dp),
allocatable ::
rho(:)
22 complex(dp),
allocatable ::
v1(:)
23 complex(dp),
allocatable ::
v2(:)
24 complex(dp),
allocatable ::
v3(:)
25 complex(dp),
allocatable ::
p(:)
26 complex(dp),
allocatable ::
b1(:)
27 complex(dp),
allocatable ::
b2(:)
28 complex(dp),
allocatable ::
b3(:)
36 character(len=100),
intent(in) :: legolas_file
37 integer,
intent(in) :: file_id
75 integer,
intent(in) :: gridpts
78 allocate(
rho(gridpts))
88 integer,
intent(in) :: ixI^L, ixO^L
89 real(dp),
intent(inout) :: w(ixI^S, nw)
90 integer,
intent(in) :: w_index
91 real(dp),
intent(in) :: x(ixI^S, ndim)
92 complex(dp) :: amplitude, exp_factor(ixI^S), quantity, values(ef_gridpts)
94 real(dp) :: k1 = 0.0d0
97 exp_factor = {exp(
ic * k^d * x(ixi^s, ^d))|*}
99 {
do idx^d = iximin^d, iximax^d|\}
101 quantity = amplitude * exp_factor(idx^d)
102 w(idx^d, w_index) = w(idx^d, w_index) + quantity%re
127 integer,
intent(in) :: w_index
128 complex(dp),
intent(inout) :: array(ef_gridpts)
134 else if (w_index ==
mom_idx(1))
then
136 else if (w_index ==
mom_idx(2))
then
141 if (w_index ==
mom_idx(3))
then
145 if (w_index ==
p_idx)
then
149 if (w_index ==
mag_idx(1))
then
151 else if (w_index ==
mag_idx(2))
then
155 if (w_index ==
mag_idx(3))
then
164 real(dp),
intent(in) :: x, grid(ef_gridpts)
165 complex(dp),
intent(in) :: array(ef_gridpts)
166 complex(dp),
intent(out) :: amplitude
169 if (x <= grid(1) .and. xprobmin1 <= x)
then
173 if (x >= grid(1)/2)
then
174 amplitude = (x - grid(1)/2) * array(1) / grid(1)
179 else if (x >= grid(
size(grid)) .and. x <= xprobmax1)
then
180 amplitude = array(
size(grid))
181 else if (x < xprobmin1 .or. x > xprobmax1)
then
184 idl = maxloc(grid, mask=(grid < x), dim=1)
185 idu = minloc(grid, mask=(grid > x), dim=1)
186 amplitude = array(idl) + (x - grid(idl)) * &
187 (array(idu) - array(idl)) / (grid(idu) - grid(idl))
197 integer,
parameter :: n_modes = 2
198 integer,
parameter :: my_unit = 123
199 character(len=80) :: fmt_string =
'(9(es12.4))', filename
200 logical,
save :: alive, visited=.false.
201 double precision :: volume, magn_avg
202 double precision :: Tmax, Tmin, vmax, B1max, B2max, B3max
217 if (.not. visited)
then
220 open(unit=my_unit,file=trim(filename),form=
'formatted',status=
'replace')
221 write(my_unit,
'(a)')
''
223 write(my_unit,
'(a)')
'#Global_time Tmax Tmin vmax B1max B2max B3max mag_avg'
225 write(my_unit,
'(a)')
'#Global_time Tmax Tmin vmax'
232 write(filename,
"(a)") filename
233 inquire(file=filename,exist=alive)
235 open(unit=my_unit,file=filename,form=
'formatted',status=
'old',access=
'append')
237 open(unit=my_unit,file=filename,form=
'formatted',status=
'new')
242 write(my_unit, fmt_string)
global_time, tmax, tmin, vmax, b1max, b2max, b3max, magn_avg
244 write(my_unit, fmt_string)
global_time, tmax, tmin, vmax
250 pure function magnetic(w_vec, w_size)
result(magn_energy)
252 integer,
intent(in) :: w_size
253 double precision,
intent(in) :: w_vec(w_size)
254 double precision :: magn_energy
256 magn_energy = 0.5d0 * sum(w_vec(mag_mhd(:))**2,dim=
ndir+1)
264 double precision,
intent(out) :: Tmax, Tmin
266 integer :: iigrid, igrid, iw
267 double precision :: Tmax_mype, Tmax_recv, Tmin_mype, Tmin_recv
268 double precision :: w(ixG^T,1:nw), wlocal(ixG^T,1:nw), xlocal(ixG^T,1:nw)
269 double precision :: Te(ixG^T), pth(ixG^T), rho(ixG^T)
271 tmax_mype = -bigdouble
272 tmin_mype = bigdouble
275 do iigrid = 1, igridstail
276 igrid = igrids(iigrid)
278 wlocal(ixg^t,1:nw) = ps(igrid)%w(ixg^t,1:nw)
279 xlocal(ixg^t,1:
ndim) = ps(igrid)%x(ixg^t,1:
ndim)
282 te(ixg^t) = pth(ixg^t)/rho(ixg^t)
285 tmax_mype = max(tmax_mype,maxval(te(
ixm^t)))
286 tmin_mype = min(tmin_mype,minval(te(
ixm^t)))
290 call mpi_allreduce(tmax_mype, tmax_recv, 1, mpi_double_precision, &
292 call mpi_allreduce(tmin_mype, tmin_recv, 1, mpi_double_precision, &
304 double precision,
intent(out) :: vmax
306 integer :: iigrid, igrid, iw
307 double precision :: vmax_mype,vmax_recv
308 double precision :: v_vec(ixG^T,1:ndir), v(ixG^T)
310 vmax_mype = -bigdouble
313 do iigrid = 1, igridstail
314 igrid = igrids(iigrid)
318 v(
ixm^t) = sqrt(sum(v_vec(
ixm^t,:)**2,dim=ndir+1))
320 vmax_mype =max(vmax_mype ,maxval(v(
ixm^t)))
325 call mpi_allreduce(vmax_mype, vmax_recv, 1, mpi_double_precision, &
335 double precision,
intent(out) :: B1max, B2max, B3max
337 integer :: iigrid, igrid, iw
338 double precision :: B1max_mype, B1max_recv
339 double precision :: B2max_mype, B2max_recv
340 double precision :: B3max_mype, B3max_recv
342 b1max_mype = -bigdouble
343 b2max_mype = -bigdouble
344 b3max_mype = -bigdouble
347 do iigrid = 1, igridstail
348 igrid = igrids(iigrid)
350 b1max_mype = max(b1max_mype, maxval(ps(igrid)%w(ixg^t, mag_mhd(1))))
351 b2max_mype = max(b2max_mype, maxval(ps(igrid)%w(ixg^t, mag_mhd(2))))
353 b3max_mype = max(b3max_mype, maxval(ps(igrid)%w(ixg^t, mag_mhd(3))))
358 call mpi_allreduce(b1max_mype, b1max_recv, 1, mpi_double_precision, &
360 call mpi_allreduce(b2max_mype, b2max_recv, 1, mpi_double_precision, &
362 call mpi_allreduce(b3max_mype, b3max_recv, 1, mpi_double_precision, &
integer, dimension(:), allocatable, public mag
Indices of the magnetic field.
Module with geometry-related routines (e.g., divergence, curl)
integer, parameter cylindrical
Module for reading in Legolas .ldat data as initial condition.
integer, dimension(:), allocatable mom_idx
complex(dp), dimension(:), allocatable b2
real(dp), dimension(:), allocatable ef_grid
integer, dimension(:), allocatable mag_idx
subroutine get_minmax_temperature(tmax, tmin)
complex(dp), dimension(:), allocatable p
subroutine read_legolas_data(legolas_file, file_id)
complex(dp), dimension(:), allocatable v1
subroutine add_perturbation_to_w_array(ixil, ixol, w, w_index, x)
subroutine ef_amplitude(x, grid, array, amplitude)
subroutine get_max_b(b1max, b2max, b3max)
complex(dp), parameter ic
complex(dp), dimension(:), allocatable v3
subroutine get_max_velocity(vmax)
subroutine init_gimli_indices()
complex(dp), dimension(:), allocatable b1
subroutine allocate_arrays(gridpts)
subroutine w_index_to_array(w_index, array)
complex(dp), dimension(:), allocatable b3
complex(dp), dimension(:), allocatable rho
complex(dp), dimension(:), allocatable v2
pure double precision function magnetic(w_vec, w_size)
This module contains definitions of global parameters and variables and some generic functions/subrou...
double precision unit_time
Physical scaling factor for time.
double precision unit_density
Physical scaling factor for density.
double precision global_time
The global simulation time.
double precision unit_numberdensity
Physical scaling factor for number density.
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.
integer icomm
The MPI communicator.
logical reset_time
If true, reset iteration count and global_time to original values, and start writing snapshots at ind...
integer mype
The rank of the current MPI task.
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.
double precision unit_magneticfield
Physical scaling factor for magnetic field.
double precision unit_velocity
Physical scaling factor for velocity.
character(len=std_len) restart_from_file
If not 'unavailable', resume from snapshot with this base file name.
double precision unit_temperature
Physical scaling factor for temperature.
character(len= *), parameter undefined
character(len=std_len) base_filename
Base file name for simulation output, which will be followed by a number.
Hydrodynamics physics module.
integer, dimension(:), allocatable, public, protected mom
Indices of the momentum density.
integer, public, protected rho_
Index of the density (in the w array)
integer, public, protected p_
Index of the gas pressure (-1 if not present) should equal e_.
Magneto-hydrodynamics module.
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_get_pthermal), pointer phys_get_pthermal
procedure(sub_get_rho), pointer phys_get_rho
procedure(sub_get_v), pointer phys_get_v