556 subroutine af_write_vtk(tree, filename, n_cycle, time, ixs_cc, &
560 type(af_t),
intent(in) :: tree
561 character(len=*),
intent(in) :: filename
562 integer,
intent(in),
optional :: n_cycle
563 real(dp),
intent(in),
optional :: time
564 integer,
intent(in),
optional :: ixs_cc(:)
566 character(len=*),
intent(in),
optional :: add_names(:)
568 integer :: lvl, bc, bn, n, n_cells, n_nodes
569 integer :: ig, ijk, id, n_ix, c_ix, n_grids
570 integer :: cell_ix, node_ix, n_cycle_val
571 integer :: n_cc, n_add
572 integer,
parameter :: n_ch = af_num_children
573 integer :: nodes_per_box, cells_per_box
575 real(dp),
allocatable :: coords(:), cc_vars(:,:)
576 integer,
allocatable :: offsets(:), connects(:)
577 integer,
allocatable :: cell_types(:), icc_val(:)
579 character(len=400) :: fname
580 character(len=100),
allocatable :: var_names(:)
581 real(dp),
allocatable :: cc(dtimes(:), :)
586 if (.not. tree%ready) error stop
"Tree not ready"
587 time_val = 0.0_dp;
if (
present(time)) time_val = time
588 n_cycle_val = 0;
if (
present(n_cycle)) n_cycle_val = n_cycle
589 n_add = 0;
if (
present(add_names)) n_add =
size(add_names)
591 if (
present(add_names) .neqv.
present(add_vars)) &
592 stop
"af_write_vtk: both arguments (add_names, add_vars) needed"
594 if (
present(ixs_cc))
then
595 if (maxval(ixs_cc) > tree%n_var_cell .or. &
596 minval(ixs_cc) < 1) stop
"af_write_vtk: wrong indices given (ixs_cc)"
597 allocate(icc_val(
size(ixs_cc)))
600 call get_output_vars(tree, icc_val)
605 allocate(var_names(n_cc+n_add))
606 var_names(1:n_cc) = tree%cc_names(icc_val)
608 if (
present(add_names))
then
609 var_names(n_cc+1:n_cc+n_add) = add_names(:)
614 nodes_per_box = bn**ndim
615 cells_per_box = bc**ndim
617 allocate(cc(dtimes(0:bc+1), n_cc + n_add))
620 do lvl = 1, tree%highest_lvl
621 n_grids = n_grids +
size(tree%lvls(lvl)%leaves)
623 n_nodes = nodes_per_box * n_grids
624 n_cells = cells_per_box * n_grids
626 allocate(coords(ndim * n_nodes))
627 allocate(cc_vars(n_cells, n_cc+n_add))
628 allocate(offsets(cells_per_box * n_grids))
629 allocate(cell_types(cells_per_box * n_grids))
630 allocate(connects(n_ch * cells_per_box * n_grids))
642 do lvl = 1, tree%highest_lvl
643 do n = 1,
size(tree%lvls(lvl)%leaves)
644 id = tree%lvls(lvl)%leaves(n)
646 cell_ix = (ig-1) * cells_per_box
647 node_ix = (ig-1) * nodes_per_box
650 cc(:, 1:n_cc) = tree%boxes(id)%cc(:, icc_val)
652 if (
present(add_vars))
then
653 call add_vars(tree%boxes(id), &
654 cc(:, n_cc+1:n_cc+n_add), n_add)
659 coords(n_ix) = tree%boxes(id)%r_min(1) + &
660 (i-1) * tree%boxes(id)%dr(1)
665 n_ix = node_ix + i - 1
667 cc_vars(c_ix, :) = cc(i, :)
668 offsets(c_ix) = af_num_children * c_ix
669 connects(n_ch*(c_ix-1)+1:n_ch*c_ix) = [n_ix, n_ix+1]
672 cc(:, :, 1:n_cc) = tree%boxes(id)%cc(:, :, icc_val)
674 if (
present(add_vars))
then
675 call add_vars(tree%boxes(id), &
676 cc(:, :, n_cc+1:n_cc+n_add), n_add)
681 n_ix = 2 * (node_ix + (j-1) * bn + i)
682 coords(n_ix-1:n_ix) = tree%boxes(id)%r_min + &
683 [i-1,j-1] * tree%boxes(id)%dr
690 n_ix = node_ix + (j-1) * bn + i - 1
691 c_ix = cell_ix + (j-1) * bc + i
692 cc_vars(c_ix, :) = cc(i, j, :)
693 offsets(c_ix) = af_num_children * c_ix
694 connects(n_ch*(c_ix-1)+1:n_ch*c_ix) = [n_ix, n_ix+1, n_ix+bn, n_ix+bn+1]
698 cc(:, :, :, 1:n_cc) = tree%boxes(id)%cc(:, :, :, icc_val)
700 if (
present(add_vars))
then
701 call add_vars(tree%boxes(id), &
702 cc(:, :, :, n_cc+1:n_cc+n_add), n_add)
708 n_ix = 3 * (node_ix + (k-1) * bn2 + (j-1) * bn + i)
709 coords(n_ix-2:n_ix) = tree%boxes(id)%r_min + &
710 [i-1,j-1,k-1] * tree%boxes(id)%dr
719 n_ix = node_ix + (k-1) * bn2 + &
721 c_ix = cell_ix + (k-1) * bc**2 + &
723 cc_vars(c_ix, :) = cc(i, j, k, :)
724 offsets(c_ix) = 8 * c_ix
725 connects(n_ch*(c_ix-1)+1:n_ch*c_ix) = &
726 [n_ix, n_ix+1, n_ix+bn, n_ix+bn+1, &
727 n_ix+bn2, n_ix+bn2+1, n_ix+bn2+bn, n_ix+bn2+bn+1]
735 fname = trim(filename) //
".vtu"
737 call vtk_ini_xml(vtkf, trim(fname),
'UnstructuredGrid')
738 call vtk_dat_xml(vtkf,
"UnstructuredGrid", .true.)
739 call vtk_unstr_geo_xml(vtkf, coords, n_nodes, n_cells, ndim, n_cycle_val, time_val)
740 call vtk_unstr_con_xml(vtkf, connects, offsets, cell_types, n_cells)
741 call vtk_dat_xml(vtkf,
"CellData", .true.)
743 do n = 1, n_cc + n_add
744 call vtk_var_r8_xml(vtkf, trim(var_names(n)), cc_vars(:, n), n_cells)
747 call vtk_dat_xml(vtkf,
"CellData", .false.)
748 call vtk_unstr_geo_xml_close(vtkf)
749 call vtk_dat_xml(vtkf,
"UnstructuredGrid", .false.)
750 call vtk_end_xml(vtkf)
751 print *,
"af_write_vtk: written " // trim(fname)
1005 subroutine af_write_silo(tree, filename, n_cycle, time, ixs_cc, &
1006 add_vars, add_names, add_curve_names, add_curve_dat, max_lvl)
1009 type(af_t),
intent(in) :: tree
1010 character(len=*) :: filename
1011 integer,
intent(in),
optional :: n_cycle
1012 real(dp),
intent(in),
optional :: time
1013 integer,
intent(in),
optional :: ixs_cc(:)
1015 character(len=*),
intent(in),
optional :: add_names(:), add_curve_names(:)
1016 real(dp),
intent(in),
optional :: add_curve_dat(:, :, :)
1019 integer,
intent(in),
optional :: max_lvl
1021 character(len=*),
parameter :: grid_name =
"gg", block_prefix =
"blk_"
1022 character(len=*),
parameter :: amr_name =
"mesh", meshdir =
"data"
1023 character(len=100),
allocatable :: grid_list(:), grid_list_block(:)
1024 character(len=100),
allocatable :: var_list(:, :), var_names(:)
1025 character(len=400) :: fname
1026 integer :: lvl, i, id, i_grid, iv, nc, n_grids_max
1027 integer :: n_cc, n_add, dbix, highest_lvl
1028 integer :: nx, nx_prev, ix
1029 integer :: n_cycle_val, ncurve, ncurve_add
1030 integer :: lo(ndim), hi(ndim), vlo(ndim), vhi(ndim)
1031 integer :: blo(ndim), bhi(ndim)
1032 logical :: lo_bnd(ndim), hi_bnd(ndim)
1033 integer,
allocatable :: ids(:), nb_ids(:), icc_val(:)
1034 logical,
allocatable :: box_done(:)
1035 real(dp) :: dr(ndim), r_min(ndim), time_val
1036 integer,
allocatable :: box_list(dtimes(:)), new_box_list(dtimes(:))
1037 real(dp),
allocatable :: var_data(dtimes(:),:), cc(dtimes(:), :)
1039 integer :: ny, ny_prev, iy
1042 integer :: nz, nz_prev, iz
1045 if (.not. tree%ready) stop
"Tree not ready"
1046 time_val = 0.0_dp;
if (
present(time)) time_val = time
1047 n_cycle_val = 0;
if (
present(n_cycle)) n_cycle_val = n_cycle
1048 n_add = 0;
if (
present(add_names)) n_add =
size(add_names)
1050 if (
present(add_names) .neqv.
present(add_vars)) &
1051 stop
"af_write_silo: both arguments (add_names, add_vars) needed"
1053 if (
present(add_curve_names) .neqv.
present(add_curve_dat)) &
1054 stop
"af_write_silo: both arguments (add_curve_names, add_curve_dat) needed"
1056 if (
present(add_curve_names))
then
1057 if (
size(add_curve_names, 1) .ne.
size(add_curve_dat, 1)) &
1058 stop
"af_write_silo: number of curve names and data do not agree"
1061 if (
present(ixs_cc))
then
1062 if (maxval(ixs_cc) > tree%n_var_cell .or. &
1063 minval(ixs_cc) < 1) stop
"af_write_silo: wrong indices given (ixs_cc)"
1064 allocate(icc_val(
size(ixs_cc)))
1067 call get_output_vars(tree, icc_val)
1070 highest_lvl = tree%highest_lvl
1071 if (
present(max_lvl)) highest_lvl = min(max_lvl, tree%highest_lvl)
1073 n_cc =
size(icc_val)
1075 allocate(var_names(n_cc+n_add))
1076 var_names(1:n_cc) = tree%cc_names(icc_val)
1078 if (
present(add_names))
then
1079 var_names(n_cc+1:n_cc+n_add) = add_names(:)
1084 do lvl = 1, highest_lvl
1085 n_grids_max = n_grids_max +
size(tree%lvls(lvl)%leaves)
1088 allocate(grid_list(n_grids_max))
1089 allocate(grid_list_block(n_grids_max))
1090 allocate(var_list(n_cc+n_add, n_grids_max))
1091 allocate(box_done(tree%highest_id))
1094 allocate(cc(dtimes(0:nc+1), n_cc + n_add))
1096 fname = trim(filename) //
".silo"
1097 call silo_create_file(trim(fname), dbix)
1098 call silo_set_time_varying(dbix)
1099 call silo_mkdir(dbix, meshdir)
1102 if (
present(add_curve_names))
then
1103 ncurve_add =
size(add_curve_dat, 1)
1104 do ncurve = 1, ncurve_add
1105 call silo_add_curve(dbix, add_curve_names(ncurve), &
1106 add_curve_dat(ncurve, 1, :), add_curve_dat(ncurve, 2, :))
1112 do lvl = 1, highest_lvl
1113 do i = 1,
size(tree%lvls(lvl)%leaves)
1114 id = tree%lvls(lvl)%leaves(i)
1116 if (box_done(id)) cycle
1123 allocate(box_list(1))
1125 box_done(id) = .true.
1133 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowx)
1134 if (all(nb_ids > af_no_box))
then
1135 if (.not. any(box_done(nb_ids)) .and. &
1136 tree%boxes(nb_ids(1))%ix(1) < tree%boxes(ids(1))%ix(1) .and. &
1137 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1139 allocate(new_box_list(nx))
1140 new_box_list(1:1) = nb_ids
1141 new_box_list(2:) = box_list
1142 box_list = new_box_list
1143 box_done(nb_ids) = .true.
1144 deallocate(new_box_list)
1149 ids = box_list(nx:nx)
1150 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highx)
1151 if (all(nb_ids > af_no_box))
then
1152 if (.not. any(box_done(nb_ids)) .and. &
1153 tree%boxes(nb_ids(1))%ix(1) > tree%boxes(ids(1))%ix(1) .and. &
1154 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1156 allocate(new_box_list(nx))
1157 new_box_list(nx:nx) = nb_ids
1158 new_box_list(1:nx-1) = box_list
1159 box_list = new_box_list
1160 box_done(nb_ids) = .true.
1161 deallocate(new_box_list)
1165 if (nx == nx_prev)
exit
1171 lo_bnd = af_is_phys_boundary(tree%boxes, id, af_low_neighbs)
1174 hi_bnd = af_is_phys_boundary(tree%boxes, id, af_high_neighbs)
1177 where (.not. lo_bnd) lo = lo - 1
1180 where (.not. hi_bnd) hi = hi + 1
1183 allocate(var_data(lo(1):hi(1), n_cc+n_add))
1188 cc(:, 1:n_cc) = tree%boxes(id)%cc(:, icc_val)
1189 if (
present(add_vars))
then
1190 call add_vars(tree%boxes(id), &
1191 cc(:, n_cc+1:n_cc+n_add), n_add)
1196 where ([ix] == 1 .and. .not. lo_bnd) blo = 0
1199 where ([ix] == [nx] .and. .not. hi_bnd) bhi = nc+1
1201 vlo = blo + ([ix]-1) * nc
1202 vhi = bhi + ([ix]-1) * nc
1204 var_data(vlo(1):vhi(1), :) = cc(blo(1):bhi(1), :)
1208 dr = tree%boxes(id)%dr
1209 r_min = tree%boxes(id)%r_min - (1 - lo) * dr
1211 write(grid_list(i_grid),
"(A,I0)") meshdir //
'/' // grid_name, i_grid
1212 call silo_add_grid(dbix, grid_list(i_grid), 1, &
1213 hi - lo + 2, r_min, dr, 1-lo, hi - [nx] * nc)
1214 write(grid_list_block(i_grid),
"(A,I0)") meshdir //
'/' // block_prefix &
1215 // grid_name, i_grid
1216 call silo_add_grid(dbix, grid_list_block(i_grid), 1, [nx+1], &
1217 tree%boxes(id)%r_min, nc*dr, [0], [0])
1219 do iv = 1, n_cc+n_add
1220 write(var_list(iv, i_grid),
"(A,I0)") meshdir //
'/' // &
1221 trim(var_names(iv)) //
"_", i_grid
1222 call silo_add_var(dbix, var_list(iv, i_grid), grid_list(i_grid), &
1223 var_data(:, iv), hi-lo+1)
1226 deallocate(var_data)
1227 deallocate(box_list)
1229 allocate(box_list(1,1))
1231 box_done(id) = .true.
1240 ids = box_list(1, :)
1241 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowx)
1242 if (all(nb_ids > af_no_box))
then
1243 if (.not. any(box_done(nb_ids)) .and. &
1244 tree%boxes(nb_ids(1))%ix(1) < tree%boxes(ids(1))%ix(1) .and. &
1245 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1247 allocate(new_box_list(nx, ny))
1248 new_box_list(1, :) = nb_ids
1249 new_box_list(2:, :) = box_list
1250 box_list = new_box_list
1251 box_done(nb_ids) = .true.
1252 deallocate(new_box_list)
1257 ids = box_list(nx, :)
1258 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highx)
1259 if (all(nb_ids > af_no_box))
then
1260 if (.not. any(box_done(nb_ids)) .and. &
1261 tree%boxes(nb_ids(1))%ix(1) > tree%boxes(ids(1))%ix(1) .and. &
1262 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1264 allocate(new_box_list(nx, ny))
1265 new_box_list(nx, :) = nb_ids
1266 new_box_list(1:nx-1, :) = box_list
1267 box_list = new_box_list
1268 box_done(nb_ids) = .true.
1269 deallocate(new_box_list)
1274 ids = box_list(:, 1)
1275 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowy)
1276 if (all(nb_ids > af_no_box))
then
1277 if (.not. any(box_done(nb_ids)) .and. &
1278 tree%boxes(nb_ids(1))%ix(2) < tree%boxes(ids(1))%ix(2) .and. &
1279 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1281 allocate(new_box_list(nx, ny))
1282 new_box_list(:, 1) = nb_ids
1283 new_box_list(:, 2:) = box_list
1284 box_list = new_box_list
1285 box_done(nb_ids) = .true.
1286 deallocate(new_box_list)
1291 ids = box_list(:, ny)
1292 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highy)
1293 if (all(nb_ids > af_no_box))
then
1294 if (.not. any(box_done(nb_ids)) .and. &
1295 tree%boxes(nb_ids(1))%ix(2) > tree%boxes(ids(1))%ix(2) .and. &
1296 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1298 allocate(new_box_list(nx, ny))
1299 new_box_list(:, ny) = nb_ids
1300 new_box_list(:, 1:ny-1) = box_list
1301 box_list = new_box_list
1302 box_done(nb_ids) = .true.
1303 deallocate(new_box_list)
1307 if (nx == nx_prev .and. ny == ny_prev)
exit
1313 lo_bnd = af_is_phys_boundary(tree%boxes, id, af_low_neighbs)
1315 id = box_list(nx, ny)
1316 hi_bnd = af_is_phys_boundary(tree%boxes, id, af_high_neighbs)
1319 where (.not. lo_bnd) lo = lo - 1
1322 where (.not. hi_bnd) hi = hi + 1
1325 allocate(var_data(lo(1):hi(1), lo(2):hi(2), n_cc+n_add))
1329 id = box_list(ix, iy)
1331 cc(:, :, 1:n_cc) = tree%boxes(id)%cc(:, :, icc_val)
1332 if (
present(add_vars))
then
1333 call add_vars(tree%boxes(id), &
1334 cc(:, :, n_cc+1:n_cc+n_add), n_add)
1339 where ([ix, iy] == 1 .and. .not. lo_bnd) blo = 0
1342 where ([ix, iy] == [nx, ny] .and. .not. hi_bnd) bhi = nc+1
1344 vlo = blo + ([ix, iy]-1) * nc
1345 vhi = bhi + ([ix, iy]-1) * nc
1347 var_data(vlo(1):vhi(1), vlo(2):vhi(2), :) = &
1348 cc(blo(1):bhi(1), blo(2):bhi(2), :)
1353 dr = tree%boxes(id)%dr
1354 r_min = tree%boxes(id)%r_min - (1 - lo) * dr
1356 write(grid_list(i_grid),
"(A,I0)") meshdir //
'/' // grid_name, i_grid
1357 call silo_add_grid(dbix, grid_list(i_grid), 2, &
1358 hi - lo + 2, r_min, dr, 1-lo, hi - [nx, ny] * nc, n_cycle_val)
1359 write(grid_list_block(i_grid),
"(A,I0)") meshdir //
'/' // block_prefix &
1360 // grid_name, i_grid
1361 call silo_add_grid(dbix, grid_list_block(i_grid), 2, [nx+1, ny+1], &
1362 tree%boxes(id)%r_min, nc*dr, [0, 0], [0, 0], n_cycle_val)
1364 do iv = 1, n_cc+n_add
1365 write(var_list(iv, i_grid),
"(A,I0)") meshdir //
'/' // &
1366 trim(var_names(iv)) //
"_", i_grid
1367 call silo_add_var(dbix, var_list(iv, i_grid), grid_list(i_grid), &
1368 pack(var_data(:, :, iv), .true.), hi-lo+1, n_cycle_val)
1371 deallocate(var_data)
1372 deallocate(box_list)
1374 allocate(box_list(1,1,1))
1375 box_list(1,1,1) = id
1376 box_done(id) = .true.
1387 ids = pack(box_list(1, :, :), .true.)
1388 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowx)
1389 if (all(nb_ids > af_no_box))
then
1390 if (.not. any(box_done(nb_ids)) .and. &
1391 tree%boxes(nb_ids(1))%ix(1) < tree%boxes(ids(1))%ix(1) .and. &
1392 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1394 allocate(new_box_list(nx, ny, nz))
1395 new_box_list(1, :, :) = reshape(nb_ids, [ny, nz])
1396 new_box_list(2:, :, :) = box_list
1397 box_list = new_box_list
1398 box_done(nb_ids) = .true.
1399 deallocate(new_box_list)
1404 ids = pack(box_list(nx, :, :), .true.)
1405 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highx)
1406 if (all(nb_ids > af_no_box))
then
1407 if (.not. any(box_done(nb_ids)) .and. &
1408 tree%boxes(nb_ids(1))%ix(1) > tree%boxes(ids(1))%ix(1) .and. &
1409 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1411 allocate(new_box_list(nx, ny, nz))
1412 new_box_list(nx, :, :) = reshape(nb_ids, [ny, nz])
1413 new_box_list(1:nx-1, :, :) = box_list
1414 box_list = new_box_list
1415 box_done(nb_ids) = .true.
1416 deallocate(new_box_list)
1421 ids = pack(box_list(:, 1, :), .true.)
1422 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowy)
1423 if (all(nb_ids > af_no_box))
then
1424 if (.not. any(box_done(nb_ids)) .and. &
1425 tree%boxes(nb_ids(1))%ix(2) < tree%boxes(ids(1))%ix(2) .and. &
1426 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1428 allocate(new_box_list(nx, ny, nz))
1429 new_box_list(:, 1, :) = reshape(nb_ids, [nx, nz])
1430 new_box_list(:, 2:, :) = box_list
1431 box_list = new_box_list
1432 box_done(nb_ids) = .true.
1433 deallocate(new_box_list)
1438 ids = pack(box_list(:, ny, :), .true.)
1439 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highy)
1440 if (all(nb_ids > af_no_box))
then
1441 if (.not. any(box_done(nb_ids)) .and. &
1442 tree%boxes(nb_ids(1))%ix(2) > tree%boxes(ids(1))%ix(2) .and. &
1443 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1445 allocate(new_box_list(nx, ny, nz))
1446 new_box_list(:, ny, :) = reshape(nb_ids, [nx, nz])
1447 new_box_list(:, 1:ny-1, :) = box_list
1448 box_list = new_box_list
1449 box_done(nb_ids) = .true.
1450 deallocate(new_box_list)
1455 ids = pack(box_list(:, :, 1), .true.)
1456 nb_ids = tree%boxes(ids)%neighbors(af_neighb_lowz)
1457 if (all(nb_ids > af_no_box))
then
1458 if (.not. any(box_done(nb_ids)) .and. &
1459 tree%boxes(nb_ids(1))%ix(3) < tree%boxes(ids(1))%ix(3) .and. &
1460 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1462 allocate(new_box_list(nx, ny, nz))
1463 new_box_list(:, :, 1) = reshape(nb_ids, [nx, ny])
1464 new_box_list(:, :, 2:) = box_list
1465 box_list = new_box_list
1466 box_done(nb_ids) = .true.
1467 deallocate(new_box_list)
1472 ids = pack(box_list(:, :, nz), .true.)
1473 nb_ids = tree%boxes(ids)%neighbors(af_neighb_highz)
1474 if (all(nb_ids > af_no_box))
then
1475 if (.not. any(box_done(nb_ids)) .and. &
1476 tree%boxes(nb_ids(1))%ix(3) > tree%boxes(ids(1))%ix(3) .and. &
1477 .not. any(af_has_children(tree%boxes(nb_ids))))
then
1479 allocate(new_box_list(nx, ny, nz))
1480 new_box_list(:, :, nz) = reshape(nb_ids, [nx, ny])
1481 new_box_list(:, :, 1:nz-1) = box_list
1482 box_list = new_box_list
1483 box_done(nb_ids) = .true.
1484 deallocate(new_box_list)
1488 if (nx == nx_prev .and. ny == ny_prev .and. nz == nz_prev)
exit
1493 id = box_list(1, 1, 1)
1494 lo_bnd = af_is_phys_boundary(tree%boxes, id, af_low_neighbs)
1496 id = box_list(nx, ny, nz)
1497 hi_bnd = af_is_phys_boundary(tree%boxes, id, af_high_neighbs)
1500 where (.not. lo_bnd) lo = lo - 1
1502 hi = [nx, ny, nz] * nc
1503 where (.not. hi_bnd) hi = hi + 1
1506 allocate(var_data(lo(1):hi(1), lo(2):hi(2), lo(3):hi(3), n_cc+n_add))
1511 id = box_list(ix, iy, iz)
1512 cc(:, :, :, 1:n_cc) = tree%boxes(id)%cc(:, :, :, icc_val)
1513 if (
present(add_vars))
then
1514 call add_vars(tree%boxes(id), &
1515 cc(:, :, :, n_cc+1:n_cc+n_add), n_add)
1520 where ([ix, iy, iz] == 1 .and. .not. lo_bnd) blo = 0
1523 where ([ix, iy, iz] == [nx, ny, nz] &
1524 .and. .not. hi_bnd) bhi = nc+1
1526 vlo = blo + ([ix, iy, iz]-1) * nc
1527 vhi = bhi + ([ix, iy, iz]-1) * nc
1529 var_data(vlo(1):vhi(1), vlo(2):vhi(2), vlo(3):vhi(3), :) = &
1530 cc(blo(1):bhi(1), blo(2):bhi(2), blo(3):bhi(3), :)
1535 id = box_list(1, 1, 1)
1536 dr = tree%boxes(id)%dr
1537 r_min = tree%boxes(id)%r_min - (1 - lo) * dr
1539 write(grid_list(i_grid),
"(A,I0)") meshdir //
'/' // grid_name, i_grid
1540 call silo_add_grid(dbix, grid_list(i_grid), 3, &
1541 hi - lo + 2, r_min, dr, 1-lo, hi-[nx, ny, nz]*nc, n_cycle_val)
1542 write(grid_list_block(i_grid),
"(A,I0)") meshdir //
'/' // block_prefix // &
1544 call silo_add_grid(dbix, grid_list_block(i_grid), 3, [nx+1, ny+1, nz+1], &
1545 tree%boxes(id)%r_min, nc*dr, [0, 0, 0], [0, 0, 0], n_cycle_val)
1547 do iv = 1, n_cc+n_add
1548 write(var_list(iv, i_grid),
"(A,I0)") meshdir //
'/' // &
1549 trim(var_names(iv)) //
"_", i_grid
1550 call silo_add_var(dbix, var_list(iv, i_grid), grid_list(i_grid), &
1551 pack(var_data(:, :, :, iv), .true.), hi-lo+1, n_cycle_val)
1554 deallocate(var_data)
1555 deallocate(box_list)
1561 call silo_set_mmesh_grid(dbix, amr_name, grid_list(1:i_grid), &
1562 n_cycle_val, time_val)
1563 do iv = 1, n_cc+n_add
1564 call silo_set_mmesh_var(dbix, trim(var_names(iv)), amr_name, &
1565 var_list(iv, 1:i_grid), n_cycle_val, time_val)
1568 call silo_set_mmesh_grid(dbix, block_prefix // amr_name, &
1569 grid_list_block(1:i_grid), n_cycle_val, time_val)
1570 call silo_close_file(dbix)
1571 print *,
"af_write_silo: written " // trim(fname)