13 integer,
intent(in) :: ixi^
l,ixo^
l, nwc
14 double precision,
intent(in) :: w(ixi^s, 1:nw)
15 double precision,
intent(in) :: x(ixi^s,1:
ndim)
16 double precision :: wnew(ixo^s, 1:nwc)
24 character(len=40) :: file_suffix
25 character(len=40) :: dataset_names(
max_nw)
40 integer,
intent(in) :: nwc
41 character(len=*),
intent(in):: aux_variable_names
42 character(len=*),
intent(in) :: file_suffix
45 function phys_convert_vars(ixI^L, ixO^L, w, x, nwc)
result(wnew)
47 integer,
intent(in) :: ixI^L, ixO^L, nwc
48 double precision,
intent(in) :: w(ixI^S, 1:nw)
49 double precision,
intent(in) :: x(ixI^S,1:ndim)
50 double precision :: wnew(ixO^S, 1:nwc)
51 end function phys_convert_vars
60 integer,
intent(in) :: nwc
61 character(len=*),
intent(in) :: dataset_names(:)
62 character(len=*),
intent(in) :: file_suffix
65 function phys_convert_vars(ixI^L, ixO^L, w, x, nwc)
result(wnew)
67 integer,
intent(in) :: ixI^L, ixO^L, nwc
68 double precision,
intent(in) :: w(ixI^S, 1:nw)
69 double precision,
intent(in) :: x(ixI^S,1:ndim)
70 double precision :: wnew(ixO^S, 1:nwc)
71 end function phys_convert_vars
77 call mpistop(
"INCREASE max_nw ")
81 temp%phys_convert_vars => phys_convert_vars
83 temp%file_suffix = file_suffix
84 temp%dataset_names(1:nwc) = dataset_names(1:nwc)
93 do while(
associated(temp))
94 call convert_dat_generic(temp%nwc, temp%dataset_names, temp%file_suffix, temp%phys_convert_vars)
108 integer :: file_handle, igrid, Morton_no, iwrite
109 integer :: ipe, ix_buffer(2*ndim+1), n_values
110 integer :: ixI^L, ixO^L, n_ghost(2*ndim)
111 integer :: ixOs^L,n_values_stagger
112 integer :: iorecvstatus(MPI_STATUS_SIZE)
113 integer :: ioastatus(MPI_STATUS_SIZE)
114 integer :: igrecvstatus(MPI_STATUS_SIZE)
115 integer :: istatus(MPI_STATUS_SIZE)
117 integer(kind=MPI_OFFSET_KIND) :: offset_tree_info
118 integer(kind=MPI_OFFSET_KIND) :: offset_block_data
119 integer(kind=MPI_OFFSET_KIND) :: offset_offsets
120 double precision,
allocatable :: w_buffer(:)
121 double precision,
allocatable:: converted_vars(:^D&,:)
123 integer :: idim, itag
124 integer,
allocatable :: block_ig(:, :)
125 integer,
allocatable :: block_lvl(:)
126 integer(kind=MPI_OFFSET_KIND),
allocatable :: block_offset(:)
128 integer,
intent(in) :: nwc
129 character(len=*),
intent(in) :: dataset_names(:)
130 character(len=*),
intent(in) :: file_suffix
133 function convert_vars(ixI^L, ixO^L,w,x,nwc)
result(wres)
135 integer,
intent(in) :: ixI^L, ixO^L, nwc
136 double precision,
intent(in) :: x(ixI^S,1:ndim)
137 double precision,
intent(in) :: w(ixI^S,1:nw)
138 double precision :: wres(ixO^S,1:nwc)
139 end function convert_vars
148 allocate(w_buffer(n_values))
151 allocate(block_ig(ndim,
nleafs))
152 allocate(block_lvl(
nleafs))
153 allocate(block_offset(
nleafs+1))
160 offset_tree_info = -1
161 offset_block_data = -1
163 offset_block_data, dataset_names, nwc)
165 call mpi_file_get_position(file_handle, offset_tree_info,
ierrmpi)
172 igrid =
sfc(1, morton_no)
173 ipe =
sfc(2, morton_no)
176 block_ig(:, morton_no) = [ pnode%ig^d ]
177 block_lvl(morton_no) = pnode%level
178 block_offset(morton_no) = 0
181 call mpi_file_write(file_handle, block_lvl,
size(block_lvl), &
184 call mpi_file_write(file_handle, block_ig,
size(block_ig), &
188 call mpi_file_get_position(file_handle, offset_offsets,
ierrmpi)
189 call mpi_file_write(file_handle, block_offset(1:
nleafs),
nleafs, &
192 call mpi_file_get_position(file_handle, offset_block_data,
ierrmpi)
195 if (offset_block_data - offset_tree_info /= &
197 nleafs * ((1+ndim) * size_int + 2 * size_int))
then
199 print *,
"Warning: MPI_OFFSET type /= 8 bytes"
200 print *,
"This *could* cause problems when reading .dat files"
204 block_offset(1) = offset_block_data
224 if(ps(igrid)%is_physical_boundary(2*idim-1)) n_ghost(idim)=
nghostcells
226 if(ps(igrid)%is_physical_boundary(2*idim)) n_ghost(ndim+idim)=
nghostcells
230 {ixomin^d = ixmlo^d - n_ghost(^d)\}
231 {ixomax^d = ixmhi^d + n_ghost(ndim+^d)\}
236 {iximin^d =
ixglo^d\}
237 {iximax^d =
ixghi^d\}
239 w_buffer(1:n_values) = pack(convert_vars(ixi^l, ixo^l,ps(igrid)%w(ixi^s, 1:nw), ps(igrid)%x(ixi^s, 1:ndim),nwc), .true.)
241 ix_buffer(1) = n_values
242 ix_buffer(2:) = n_ghost
245 call mpi_send(ix_buffer, 2*ndim+1, &
247 call mpi_send(w_buffer, n_values, &
251 call mpi_file_write(file_handle, ix_buffer(2:), &
252 2*ndim, mpi_integer, istatus,
ierrmpi)
253 call mpi_file_write(file_handle, w_buffer, &
254 n_values, mpi_double_precision, istatus,
ierrmpi)
257 block_offset(iwrite+1) = block_offset(iwrite) + &
258 int(n_values, mpi_offset_kind) * size_double + &
270 call mpi_recv(ix_buffer, 2*ndim+1, mpi_integer, ipe, itag,
icomm,&
272 n_values = ix_buffer(1)
274 call mpi_recv(w_buffer, n_values, mpi_double_precision,&
277 call mpi_file_write(file_handle, ix_buffer(2:), &
278 2*ndim, mpi_integer, istatus,
ierrmpi)
279 call mpi_file_write(file_handle, w_buffer, &
280 n_values, mpi_double_precision, istatus,
ierrmpi)
283 block_offset(iwrite+1) = block_offset(iwrite) + &
284 int(n_values, mpi_offset_kind) * size_double + &
290 call mpi_file_seek(file_handle, offset_offsets, mpi_seek_set,
ierrmpi)
291 call mpi_file_write(file_handle, block_offset(1:
nleafs),
nleafs, &
295 call mpi_file_seek(file_handle, 0_mpi_offset_kind, mpi_seek_set,
ierrmpi)
297 offset_block_data, dataset_names, nwc)
299 call mpi_file_close(file_handle,
ierrmpi)
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
subroutine convert_dat_generic(nwc, dataset_names, file_suffix, convert_vars)
subroutine add_convert_method2(phys_convert_vars, nwc, aux_variable_names, file_suffix)
type(convert_vars_method), pointer head_convert_vars_methods
subroutine init_convert()
subroutine add_convert_method(phys_convert_vars, nwc, dataset_names, file_suffix)
Module with basic grid data structures.
integer, dimension(:), allocatable, save sfc_to_igrid
Go from a Morton number to an igrid index (for a single processor)
integer, dimension(:), allocatable, save morton_start
First Morton number per processor.
integer, save nleafs
Number of leaf block.
integer, dimension(:), allocatable, save morton_stop
Last Morton number per processor.
integer, dimension(:,:), allocatable, save sfc
Array to go from a Morton number to an igrid and processor index. Sfc(1:3, MN) contains [igrid,...
integer, save nparents
Number of parent blocks.
type(tree_node_ptr), dimension(:,:), allocatable, save igrid_to_node
Array to go from an [igrid, ipe] index to a node pointer.
subroutine, public write_forest(file_handle)
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.
integer ixghi
Upper index of grid block arrays.
integer, parameter ndim
Number of spatial dimensions for grid variables.
logical save_physical_boundary
True for save physical boundary cells in dat files.
integer icomm
The MPI communicator.
integer mype
The rank of the current MPI task.
integer ierrmpi
A global MPI error return code.
integer snapshotnext
IO: snapshot and collapsed views output numbers/labels.
integer npe
The number of MPI tasks.
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
integer nghostcells
Number of ghost cells surrounding a grid.
double precision, dimension(^nd) dxlevel
store unstretched cell size of current level
integer, parameter ixglo
Lower index of grid block arrays (always 1)
integer, parameter max_nw
Maximum number of variables.
The data structure that contains information about a tree node/grid block.