MPI-AMRVAC  3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
mod_convert_files.t
Go to the documentation of this file.
2  use mod_comm_lib, only: mpistop
3 
4  implicit none
5  public
6 
7 contains
8 
9  subroutine generate_plotfile
14  use mod_convert, only: convert_all
16 
17  character(len=std_len) :: convert_type_elem
18  integer :: i
19 
20  if(.not. phys_req_diagonal) then
21  call getbc(global_time,0.d0,ps,iwstart,nwgc)
22  end if
23 
24  select case(convert_type)
25  case('tecplot','tecplotCC','tecline')
26  call tecplot(unitconvert)
27  case('tecplotmpi','tecplotCCmpi','teclinempi')
29  case('vtu','vtuCC')
31  case('vtumpi','vtuCCmpi')
33  case('vtuB','vtuBCC','vtuBmpi','vtuBCCmpi')
35  case('vtuB64','vtuBCC64','vtuBmpi64','vtuBCCmpi64')
37  {^iftwod
38  case('vtuB23','vtuBCC23')
40  case('vtuBsym23','vtuBCCsym23')
42  }
43  case('pvtumpi','pvtuCCmpi')
45  case('pvtuBmpi','pvtuBCCmpi')
47  case('vtimpi','vtiCCmpi')
49  case('onegrid','onegridmpi')
50  call onegrid(unitconvert)
51  case('oneblock','oneblockB')
52  call oneblock(unitconvert)
53  case('EIvtiCCmpi','ESvtiCCmpi','SIvtiCCmpi','WIvtiCCmpi','EIvtuCCmpi','ESvtuCCmpi','SIvtuCCmpi','WIvtuCCmpi')
54  ! output synthetic euv emission
55  if (ndim==3 .and. associated(phys_te_images)) then
56  call phys_te_images
57  endif
58  case('dat_generic_mpi')
59  call convert_all()
60  case('user','usermpi')
61  if (.not. associated(usr_special_convert)) then
62  call mpistop("usr_special_convert not defined")
63  else
65  end if
66  case default
67  call mpistop("Error in generate_plotfile: Unknown convert_type")
68  end select
69 
70  end subroutine generate_plotfile
71 
72  subroutine oneblock(qunit)
73  ! this is for turning an AMR run into a single block
74  ! the data will be all on selected level level_io
75  ! this version should work for any dimension
76  ! only writes w_write selected 1:nw variables, also nwauxio
77  ! may use saveprim to switch to primitives
78  ! this version can not work on multiple CPUs
79  ! does not renormalize variables
80  ! header info differs from onegrid below
81  ! ASCII or binary output
82 
86  use mod_physics
88  integer, intent(in) :: qunit
89 
90  double precision :: wval1,xval1
91  double precision, dimension({^D&1:1},1:nw+nwauxio) :: wval
92  double precision, dimension({^D&1:1},1:ndim) :: xval
93  double precision:: normconv(0:nw+nwauxio)
94  integer :: Morton_no,igrid,ix^D,ig^D,level
95  integer, pointer :: ig_to_igrid(:^D&,:)
96  integer :: filenr,ncells^D,ncellx^D,jg^D,jig^D
97  integer :: iw,iiw,writenw,iwrite(1:nw+nwauxio),iigrid,idim
98  logical :: fileopen,writeblk(max_blocks)
99  logical :: patchw(ixG^T)
100  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
101  character(len=1024) :: outfilehead
102  character(len=80) :: filename
103 
104  if(level_io<1)then
105  call mpistop('please specify level_io>0 for usage with oneblock')
106  end if
107 
108  if(autoconvert)then
109  call mpistop('Set autoconvert=F and convert oneblock data manually')
110  end if
111 
112  if(npe>1)then
113  if(mype==0) print *,'ONEBLOCK as yet to be parallelized'
114  call mpistop('npe>1, oneblock')
115  end if
116 
117  ! only variables selected by w_write will be written out
118  normconv(0:nw+nwauxio)=one
119  normconv(0) = length_convert_factor
120  normconv(1:nw) = w_convert_factor
121  writenw=count(w_write(1:nw))+nwauxio
122  iiw=0
123  do iw =1,nw
124  if (.not.w_write(iw))cycle
125  iiw=iiw+1
126  iwrite(iiw)=iw
127  end do
128  if(nwauxio>0)then
129  do iw =nw+1,nw+nwauxio
130  iiw=iiw+1
131  iwrite(iiw)=iw
132  end do
133  end if
134 
135  allocate(ig_to_igrid(ng^d(level_io),0:npe-1))
136  ig_to_igrid=-1
137  writeblk=.false.
138  do morton_no=morton_start(mype),morton_stop(mype)
139  igrid=sfc_to_igrid(morton_no)
140  level=node(plevel_,igrid)
141  ig^d=igrid_to_node(igrid,mype)%node%ig^d;
142  ig_to_igrid(ig^d,mype)=igrid
143  if(({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
144  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
145  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
146  writeblk(igrid)=.true.
147  end if
148  end do
149 
150  call getheadernames(wnamei,xandwnamei,outfilehead)
151  ncells^d=0;
152  ncellx^d=ixmhi^d-ixmlo^d+1\
153  {do ig^d=1,ng^d(level_io)\}
154  igrid=ig_to_igrid(ig^d,mype)
155  if(writeblk(igrid)) go to 20
156  {end do\}
157  20 continue
158  jg^d=ig^d;
159  {
160  jig^dd=jg^dd;
161  do ig^d=1,ng^d(level_io)
162  jig^d=ig^d
163  igrid=ig_to_igrid(jig^dd,mype)
164  if(writeblk(igrid)) ncells^d=ncells^d+ncellx^d
165  end do
166  \}
167 
168  do iigrid=1,igridstail; igrid=igrids(iigrid)
169  if(.not.writeblk(igrid)) cycle
170  block=>ps(igrid)
171  if (nwauxio > 0) then
172  if (.not. associated(usr_aux_output)) then
173  call mpistop("usr_aux_output not defined")
174  else
175  call usr_aux_output(ixg^ll,ixm^ll^ladd1, &
176  ps(igrid)%w,ps(igrid)%x,normconv)
177  end if
178  end if
179  end do
180 
181  if (saveprim) then
182  do iigrid=1,igridstail; igrid=igrids(iigrid)
183  if (.not.writeblk(igrid)) cycle
184  block=>ps(igrid)
185  call phys_to_primitive(ixg^ll,ixg^ll^lsub1,ps(igrid)%w,ps(igrid)%x)
186  if(b0field) then
187  ! add background magnetic field B0 to B
188  ps(igrid)%w(ixg^t,iw_mag(:))=ps(igrid)%w(ixg^t,iw_mag(:))+ps(igrid)%B0(ixg^t,:,0)
189  end if
190  end do
191  else
192  do iigrid=1,igridstail; igrid=igrids(iigrid)
193  if (.not.writeblk(igrid)) cycle
194  block=>ps(igrid)
195  if (b0field) then
196  ! add background magnetic field B0 to B
197  if(phys_energy) &
198  ps(igrid)%w(ixg^t,iw_e)=ps(igrid)%w(ixg^t,iw_e)+0.5d0*sum(ps(igrid)%B0(ixg^t,:,0)**2,dim=ndim+1) &
199  + sum(ps(igrid)%w(ixg^t,iw_mag(:))*ps(igrid)%B0(ixg^t,:,0),dim=ndim+1)
200  ps(igrid)%w(ixg^t,iw_mag(:))=ps(igrid)%w(ixg^t,iw_mag(:))+ps(igrid)%B0(ixg^t,:,0)
201  end if
202  end do
203  end if
204 
205  master_cpu_open : if (mype == 0) then
206  inquire(qunit,opened=fileopen)
207  if (.not.fileopen) then
208  ! generate filename
209  filenr=snapshotini
210  if (autoconvert) filenr=snapshotnext
211  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".blk"
212  select case(convert_type)
213  case("oneblock")
214  open(qunit,file=filename,status='unknown')
215  write(qunit,*) trim(outfilehead)
216  write(qunit,*) ncells^d
217  write(qunit,*) real(global_time*time_convert_factor)
218  case("oneblockB")
219  open(qunit,file=filename,form='unformatted',status='unknown')
220  write(qunit) outfilehead
221  write(qunit) ncells^d
222  write(qunit) real(global_time*time_convert_factor)
223  end select
224  end if
225  end if master_cpu_open
226 
227  {^ifthreed
228  do ig3=1,ng3(level_io)
229  do ix3=ixmlo3,ixmhi3}
230 
231  {^nooned
232  do ig2=1,ng2(level_io)
233  do ix2=ixmlo2,ixmhi2}
234 
235  do ig1=1,ng1(level_io)
236  igrid=ig_to_igrid(ig^d,mype)
237  if(.not.writeblk(igrid)) cycle
238  do ix1=ixmlo1,ixmhi1
239  master_write : if(mype==0) then
240  select case(convert_type)
241  case("oneblock")
242  write(qunit,fmt="(100(e14.6))") &
243  ps(igrid)%x(ix^d,1:ndim)*normconv(0),&
244  (ps(igrid)%w(ix^d,iwrite(iw))*normconv(iwrite(iw)),iw=1,writenw)
245  case("oneblockB")
246  write(qunit) real(ps(igrid)%x(ix^d,1:ndim)*normconv(0)),&
247  (real(ps(igrid)%w(ix^d,iwrite(iw))*normconv(iwrite(iw))),iw=1,writenw)
248  end select
249  end if master_write
250  end do
251  end do
252  {^nooned
253  end do
254  end do}
255  {^ifthreed
256  end do
257  end do}
258 
259  close(qunit)
260 
261  end subroutine oneblock
262 
263  subroutine onegrid(qunit)
264  ! this is for turning an AMR run into a single grid
265  ! this version should work for any dimension, can be in parallel
266  ! in 1D, should behave much like oneblock, except for header info
267 
268  ! only writes all 1:nw variables, no nwauxio
269  ! may use saveprim to switch to primitives
270  ! this version can work on multiple CPUs
271  ! does not renormalize variables
272  ! ASCII output
273 
276  use mod_physics
277  use mod_calculate_xw
278  integer, intent(in) :: qunit
279 
280  double precision :: w_recv(ixG^T,1:nw),x_recv(ixG^T,1:ndim)
281  integer :: itag,Morton_no,igrid,ix^D,iw
282  integer :: filenr
283  !.. MPI variables ..
284  integer :: igrid_recv,ipe
285  integer, allocatable :: intstatus(:,:)
286  logical :: fileopen
287  character(len=80) :: filename
288  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
289  character(len=1024) :: outfilehead
290 
291 
292  if(nwauxio>0)then
293  if(mype==0) print *,'ONEGRID to be used without nwauxio'
294  call mpistop('nwauxio>0, onegrid')
295  end if
296 
297  if(saveprim)then
298  if(mype==0.and.nwaux>0) print *,'warning: ONEGRID used with saveprim, check auxiliaries'
299  end if
300 
301  master_cpu_open : if (mype == 0) then
302  call getheadernames(wnamei,xandwnamei,outfilehead)
303  write(outfilehead,'(a)') "#"//" "//trim(outfilehead)
304  inquire(qunit,opened=fileopen)
305  if (.not.fileopen) then
306  ! generate filename
307  filenr=snapshotini
308  if (autoconvert) filenr=snapshotnext
309  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".blk"
310  open(qunit,file=filename,status='unknown')
311  end if
312  write(qunit,"(a)")outfilehead
313  write(qunit,"(i7)") ( {^d&(ixmhi^d-ixmlo^d+1)*} )*(morton_stop(npe-1)-morton_start(0)+1)
314  end if master_cpu_open
315 
316  do morton_no=morton_start(mype),morton_stop(mype)
317  igrid=sfc_to_igrid(morton_no)
318  if(saveprim) call phys_to_primitive(ixg^ll,ixm^ll,ps(igrid)%w,ps(igrid)%x)
319  if(mype/=0)then
320  itag=morton_no
321  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
322  call mpi_send(ps(igrid)%x,1,type_block_xcc_io, 0,itag,icomm,ierrmpi)
323  itag=igrid
324  call mpi_send(ps(igrid)%w,1,type_block_io, 0,itag,icomm,ierrmpi)
325  else
326  {do ix^db=ixmlo^db,ixmhi^db\}
327  do iw=1,nw
328  if( dabs(ps(igrid)%w(ix^d,iw)) < 1.0d-32 ) ps(igrid)%w(ix^d,iw) = zero
329  end do
330  write(qunit,fmt="(100(e14.6))") ps(igrid)%x(ix^d,1:ndim),ps(igrid)%w(ix^d,1:nw)
331  {end do\}
332  end if
333  end do
334 
335  if(mype==0.and.npe>1) allocate(intstatus(mpi_status_size,1))
336 
337  manycpu : if (npe>1) then
338  if (mype==0) then
339  loop_cpu : do ipe =1, npe-1
340  loop_morton : do morton_no=morton_start(ipe),morton_stop(ipe)
341  itag=morton_no
342  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
343  call mpi_recv(x_recv,1,type_block_xcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
344  itag=igrid_recv
345  call mpi_recv(w_recv,1,type_block_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
346  {do ix^db=ixmlo^db,ixmhi^db\}
347  do iw=1,nw
348  if( dabs(ps(igrid)%w(ix^d,iw)) < smalldouble ) ps(igrid)%w(ix^d,iw) = zero
349  end do
350  write(qunit,fmt="(100(e14.6))") x_recv(ix^d,1:ndim),w_recv(ix^d,1:nw)
351  {end do\}
352  end do loop_morton
353  end do loop_cpu
354  end if
355  end if manycpu
356 
357  if (npe>1) then
358  call mpi_barrier(icomm,ierrmpi)
359  if(mype==0)deallocate(intstatus)
360  end if
361 
362  if(mype==0) close(qunit)
363  end subroutine onegrid
364 
365  subroutine tecplot(qunit)
366 
367  ! output for tecplot (ASCII format)
368  ! not parallel, uses calc_grid to compute nwauxio variables
369  ! allows renormalizing using convert factors
370 
372  use mod_calculate_xw
373 
374  integer, intent(in) :: qunit
375 
376  double precision :: x_TEC(ndim), w_TEC(nw+nwauxio)
377  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
378  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
379  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
380  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
381  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP
382  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
383  double precision, dimension(0:nw+nwauxio) :: normconv
384  integer:: igrid,iigrid,level,igonlevel,iw,idim,ix^D
385  integer:: NumGridsOnLevel(1:nlevelshi)
386  integer :: nx^D,nxC^D,nodesonlevel,elemsonlevel,ixC^L,ixCC^L
387  integer :: nodes, elems
388  integer :: filenr
389  logical :: fileopen,first
390  character(len=80) :: filename
391  !!! possible length conflict
392  character(len=1024) :: tecplothead
393  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
394  character(len=1024) :: outfilehead
395 
396  if(npe>1)then
397  if(mype==0) print *,'tecplot not parallel, use tecplotmpi'
398  call mpistop('npe>1, tecplot')
399  end if
400 
401  if(nw/=count(w_write(1:nw)))then
402  if(mype==0) print *,'tecplot does not use w_write=F'
403  call mpistop('w_write, tecplot')
404  end if
405 
406  if(nocartesian)then
407  if(mype==0) print *,'tecplot with nocartesian'
408  end if
409 
410  inquire(qunit,opened=fileopen)
411  if(.not.fileopen) then
412  ! generate filename
413  filenr=snapshotini
414  if (autoconvert) filenr=snapshotnext
415  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".plt"
416  open(qunit,file=filename,status='unknown')
417  end if
418 
419  call getheadernames(wnamei,xandwnamei,outfilehead)
420 
421  write(tecplothead,'(a)') "VARIABLES = "//trim(outfilehead)
422  write(qunit,'(a)') tecplothead(1:len_trim(tecplothead))
423 
424  numgridsonlevel(1:nlevelshi)=0
425  do level=levmin,levmax
426  numgridsonlevel(level)=0
427  do iigrid=1,igridstail; igrid=igrids(iigrid);
428  if (node(plevel_,igrid)/=level) cycle
429  numgridsonlevel(level)=numgridsonlevel(level)+1
430  end do
431  end do
432 
433  nx^d=ixmhi^d-ixmlo^d+1;
434  nxc^d=nx^d+1;
435 
436  {^ifoned
437  if(convert_type=='tecline') then
438  nodes=0
439  elems=0
440  do level=levmin,levmax
441  nodes=nodes + numgridsonlevel(level)*{nxc^d*}
442  elems=elems + numgridsonlevel(level)*{nx^d*}
443  end do
444 
445  write(qunit,"(a,i7,a,1pe12.5,a)") &
446  'ZONE T="all levels", I=',elems, &
447  ', SOLUTIONTIME=',global_time*time_convert_factor,', F=POINT'
448 
449  igonlevel=0
450  do iigrid=1,igridstail; igrid=igrids(iigrid);
451  block=>ps(igrid)
452  call calc_x(igrid,xc,xcc)
453  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,ixc^l,ixcc^l,.true.)
454  {do ix^db=ixccmin^db,ixccmax^db\}
455  x_tec(1:ndim)=xcc_tmp(ix^d,1:ndim)*normconv(0)
456  w_tec(1:nw+nwauxio)=wcc_tmp(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
457  write(qunit,fmt="(100(e24.16))") x_tec, w_tec
458  {end do\}
459  end do
460  close(qunit)
461  else
462  }
463  do level=levmin,levmax
464  nodesonlevel=numgridsonlevel(level)*{nxc^d*}
465  elemsonlevel=numgridsonlevel(level)*{nx^d*}
466  ! for all tecplot variants coded up here, we let the TECPLOT ZONES coincide
467  ! with the AMR grid LEVEL. Other options would be
468  ! let each grid define a zone: inefficient for TECPLOT internal workings
469  ! hence not implemented
470  ! let entire octree define 1 zone: no difference in interpolation
471  ! properties across TECPLOT zones detected as yet, hence not done
472  select case(convert_type)
473  case('tecplot')
474  ! in this option, we store the corner coordinates, as well as the corner
475  ! values of all variables (obtained by averaging). This allows POINT packaging,
476  ! and thus we can save full grid info by using one call to calc_grid
477  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,a)") &
478  'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel, &
479  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=POINT, ZONETYPE=', &
480  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
481  do iigrid=1,igridstail; igrid=igrids(iigrid);
482  if (node(plevel_,igrid)/=level) cycle
483  block=>ps(igrid)
484  call calc_x(igrid,xc,xcc)
485  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
486  ixc^l,ixcc^l,.true.)
487  {do ix^db=ixcmin^db,ixcmax^db\}
488  x_tec(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0)
489  w_tec(1:nw+nwauxio)=wc_tmp(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
490  write(qunit,fmt="(100(e14.6))") x_tec, w_tec
491  {end do\}
492  end do
493  case('tecplotCC')
494  ! in this option, we store the corner coordinates, and the cell center
495  ! values of all variables. Due to this mix of corner/cell center, we must
496  ! use BLOCK packaging, and thus we have enormous overhead by using
497  ! calc_grid repeatedly to merely fill values of cell corner coordinates
498  ! and cell center values per dimension, per variable
499  if(ndim+nw+nwauxio>99) call mpistop("adjust format specification in writeout")
500  if(nw+nwauxio==1)then
501  ! to make tecplot happy: avoid [ndim+1-ndim+1] in varlocation varset
502  ! and just set [ndim+1]
503  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,a)") &
504  'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel, &
505  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
506  ndim+1,']=CELLCENTERED), ZONETYPE=', &
507  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
508  else
509  if(ndim+nw+nwauxio<10) then
510  ! difference only in length of integer format specification for ndim+nw+nwauxio
511  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i1,a,a)") &
512  'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel, &
513  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
514  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
515  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
516  else
517  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i2,a,a)") &
518  'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel, &
519  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
520  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
521  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
522  end if
523  end if
524  do idim=1,ndim
525  first=(idim==1)
526  do iigrid=1,igridstail; igrid=igrids(iigrid);
527  if (node(plevel_,igrid)/=level) cycle
528  block=>ps(igrid)
529  call calc_x(igrid,xc,xcc)
530  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
531  ixc^l,ixcc^l,first)
532  write(qunit,fmt="(100(e14.6))") xc_tmp(ixc^s,idim)*normconv(0)
533  end do
534  end do
535  do iw=1,nw+nwauxio
536  do iigrid=1,igridstail; igrid=igrids(iigrid);
537  if (node(plevel_,igrid)/=level) cycle
538  block=>ps(igrid)
539  call calc_x(igrid,xc,xcc)
540  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
541  ixc^l,ixcc^l,.true.)
542  write(qunit,fmt="(100(e14.6))") wcc_tmp(ixcc^s,iw)*normconv(iw)
543  enddo
544  enddo
545  case default
546  call mpistop('no such tecplot type')
547  end select
548  igonlevel=0
549  do iigrid=1,igridstail; igrid=igrids(iigrid);
550  if (node(plevel_,igrid)/=level) cycle
551  block=>ps(igrid)
552  igonlevel=igonlevel+1
553  call save_conntec(qunit,igrid,igonlevel)
554  end do
555  end do
556  {^ifoned endif}
557 
558  close(qunit)
559 
560  end subroutine tecplot
561 
562  subroutine save_conntec(qunit,igrid,igonlevel)
563 
564  ! this saves the basic line, quad and brick connectivity,
565  ! as used by TECPLOT file outputs for unstructured grid
567 
568  integer, intent(in) :: qunit, igrid, igonlevel
569 
570  integer :: nx^D, nxC^D, ix^D
571 
572  nx^d=ixmhi^d-ixmlo^d+1;
573  nxc^d=nx^d+1;
574 
575  ! connectivity list
576  {do ix^db=1,nx^db\}
577  {^ifthreed
578  ! basic brick connectivity
579  write(qunit,'(8(i7,1x))') &
580  nodenumbertec3d(ix1, ix2-1,ix3-1,nxc1,nxc2,nxc3,igonlevel,igrid),&
581  nodenumbertec3d(ix1+1,ix2-1,ix3-1,nxc1,nxc2,nxc3,igonlevel,igrid),&
582  nodenumbertec3d(ix1+1,ix2 ,ix3-1,nxc1,nxc2,nxc3,igonlevel,igrid),&
583  nodenumbertec3d(ix1 ,ix2 ,ix3-1,nxc1,nxc2,nxc3,igonlevel,igrid),&
584  nodenumbertec3d(ix1 ,ix2-1,ix3 ,nxc1,nxc2,nxc3,igonlevel,igrid),&
585  nodenumbertec3d(ix1+1,ix2-1,ix3 ,nxc1,nxc2,nxc3,igonlevel,igrid),&
586  nodenumbertec3d(ix1+1,ix2 ,ix3 ,nxc1,nxc2,nxc3,igonlevel,igrid),&
587  nodenumbertec3d(ix1 ,ix2 ,ix3 ,nxc1,nxc2,nxc3,igonlevel,igrid)
588  }
589  {^iftwod
590  ! basic quadrilateral connectivity
591  write(qunit,'(4(i7,1x))') &
592  nodenumbertec2d(ix1, ix2-1,nxc1,nxc2,igonlevel,igrid),&
593  nodenumbertec2d(ix1+1,ix2-1,nxc1,nxc2,igonlevel,igrid),&
594  nodenumbertec2d(ix1+1,ix2 ,nxc1,nxc2,igonlevel,igrid),&
595  nodenumbertec2d(ix1 ,ix2 ,nxc1,nxc2,igonlevel,igrid)
596  }
597  {^ifoned
598  ! basic line connectivity
599  write(qunit,'(2(i7,1x))') nodenumbertec1d(ix1,nxc1,igonlevel,igrid),&
600  nodenumbertec1d(ix1+1,nxc1,igonlevel,igrid)
601  }
602  {end do\}
603 
604  end subroutine save_conntec
605 
606  integer function nodenumbertec1d(i1,nx1,ig,igrid)
607  use mod_comm_lib, only: mpistop
608  integer, intent(in):: i1,nx1,ig,igrid
609 
610  nodenumbertec1d=i1+(ig-1)*nx1
611  if(nodenumbertec1d>9999999)call mpistop("too large nodenumber")
612 
613  end function nodenumbertec1d
614 
615  integer function nodenumbertec2d(i1,i2,nx1,nx2,ig,igrid)
616 
617  integer, intent(in):: i1,i2,nx1,nx2,ig,igrid
618 
619  nodenumbertec2d=i1+i2*nx1+(ig-1)*nx1*nx2
620  if(nodenumbertec2d>9999999)call mpistop("too large nodenumber")
621 
622  end function nodenumbertec2d
623 
624  integer function nodenumbertec3d(i1,i2,i3,nx1,nx2,nx3,ig,igrid)
625 
626  integer, intent(in):: i1,i2,i3,nx1,nx2,nx3,ig,igrid
627 
628  nodenumbertec3d=i1+i2*nx1+i3*nx1*nx2+(ig-1)*nx1*nx2*nx3
629  if(nodenumbertec3d>9999999)call mpistop("too large nodenumber")
630 
631  end function nodenumbertec3d
632 
633  subroutine unstructuredvtk(qunit)
634 
635  ! output for vtu format to paraview
636  ! not parallel, uses calc_grid to compute nwauxio variables
637  ! allows renormalizing using convert factors
639  use mod_calculate_xw
640 
641  integer, intent(in) :: qunit
642 
643  double precision :: x_VTK(1:3)
644  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
645  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
646  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
647  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
648  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP
649  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
650  double precision, dimension(0:nw+nwauxio) :: normconv
651  integer:: igrid,iigrid,level,igonlevel,icel,ixC^L,ixCC^L,iw
652  integer:: NumGridsOnLevel(1:nlevelshi)
653  integer :: nx^D,nxC^D,nodesonlevel,elemsonlevel,nc,np,VTK_type,ix^D
654  integer :: filenr
655  character(len=80):: filename
656  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
657  character(len=1024) :: outfilehead
658  logical :: fileopen
659 
660  if(npe>1)then
661  if(mype==0) print *,'unstructuredvtk not parallel, use vtumpi'
662  call mpistop('npe>1, unstructuredvtk')
663  end if
664 
665  inquire(qunit,opened=fileopen)
666  if(.not.fileopen)then
667  ! generate filename
668  filenr=snapshotini
669  if (autoconvert) filenr=snapshotnext
670  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".vtu"
671  ! Open the file for the header part
672  open(qunit,file=filename,status='unknown')
673  end if
674 
675  call getheadernames(wnamei,xandwnamei,outfilehead)
676 
677  ! generate xml header
678  write(qunit,'(a)')'<?xml version="1.0"?>'
679  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
680  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
681  write(qunit,'(a)')'<UnstructuredGrid>'
682  write(qunit,'(a)')'<FieldData>'
683  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
684  'NumberOfTuples="1" format="ascii">'
685  write(qunit,*) dble(dble(global_time)*time_convert_factor)
686  write(qunit,'(a)')'</DataArray>'
687  write(qunit,'(a)')'</FieldData>'
688 
689  ! number of cells, number of corner points, per grid.
690  nx^d=ixmhi^d-ixmlo^d+1;
691  nxc^d=nx^d+1;
692  nc={nx^d*}
693  np={nxc^d*}
694 
695  ! Note: using the w_write, writelevel, writespshift
696  ! we can clip parts of the grid away, select variables, levels etc.
697  do level=levmin,levmax
698  if (writelevel(level)) then
699  do iigrid=1,igridstail; igrid=igrids(iigrid);
700  if (node(plevel_,igrid)/=level) cycle
701  block=>ps(igrid)
702  ! only output a grid when fully within clipped region selected
703  ! by writespshift array
704  if(({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
705  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
706  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
707  call calc_x(igrid,xc,xcc)
708  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
709  ixc^l,ixcc^l,.true.)
710  select case(convert_type)
711  case('vtu')
712  ! we write out every grid as one VTK PIECE
713  write(qunit,'(a,i7,a,i7,a)') &
714  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
715  write(qunit,'(a)')'<PointData>'
716  do iw=1,nw+nwauxio
717  if(iw<=nw) then
718  if(.not.w_write(iw)) cycle
719  end if
720  write(qunit,'(a,a,a)')&
721  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
722  write(qunit,'(200(1pe14.6))') {(|}wc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixcmin^d,ixcmax^d)}
723  write(qunit,'(a)')'</DataArray>'
724  end do
725  write(qunit,'(a)')'</PointData>'
726  write(qunit,'(a)')'<Points>'
727  write(qunit,'(a)')'<DataArray type="Float32" NumberOfComponents="3" format="ascii">'
728  ! write cell corner coordinates in a backward dimensional loop, always 3D output
729  {do ix^db=ixcmin^db,ixcmax^db \}
730  x_vtk(1:3)=zero;
731  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
732  write(qunit,'(3(1pe14.6))') x_vtk
733  {end do \}
734  write(qunit,'(a)')'</DataArray>'
735  write(qunit,'(a)')'</Points>'
736  case('vtuCC')
737  ! we write out every grid as one VTK PIECE
738  write(qunit,'(a,i7,a,i7,a)') &
739  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
740  write(qunit,'(a)')'<CellData>'
741  do iw=1,nw+nwauxio
742  if(iw<=nw) then
743  if(.not.w_write(iw)) cycle
744  end if
745  write(qunit,'(a,a,a)')&
746  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
747  write(qunit,'(200(1pe14.6))') {(|}wcc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixccmin^d,ixccmax^d)}
748  write(qunit,'(a)')'</DataArray>'
749  end do
750  write(qunit,'(a)')'</CellData>'
751  write(qunit,'(a)')'<Points>'
752  write(qunit,'(a)')'<DataArray type="Float32" NumberOfComponents="3" format="ascii">'
753  ! write cell corner coordinates in a backward dimensional loop, always 3D output
754  {do ix^db=ixcmin^db,ixcmax^db \}
755  x_vtk(1:3)=zero;
756  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
757  write(qunit,'(3(1pe14.6))') x_vtk
758  {end do \}
759  write(qunit,'(a)')'</DataArray>'
760  write(qunit,'(a)')'</Points>'
761  end select
762 
763  write(qunit,'(a)')'<Cells>'
764  ! connectivity part
765  write(qunit,'(a)')'<DataArray type="Int32" Name="connectivity" format="ascii">'
766  call save_connvtk(qunit,igrid)
767  write(qunit,'(a)')'</DataArray>'
768 
769  ! offsets data array
770  write(qunit,'(a)')'<DataArray type="Int32" Name="offsets" format="ascii">'
771  do icel=1,nc
772  write(qunit,'(i7)') icel*(2**^nd)
773  end do
774  write(qunit,'(a)')'</DataArray>'
775 
776  ! VTK cell type data array
777  write(qunit,'(a)')'<DataArray type="Int32" Name="types" format="ascii">'
778  ! VTK_LINE=3; VTK_PIXEL=8; VTK_VOXEL=11 -> vtk-syntax
779  {^ifoned vtk_type=3 \}
780  {^iftwod vtk_type=8 \}
781  {^ifthreed vtk_type=11 \}
782  do icel=1,nc
783  write(qunit,'(i2)') vtk_type
784  end do
785  write(qunit,'(a)')'</DataArray>'
786 
787  write(qunit,'(a)')'</Cells>'
788 
789  write(qunit,'(a)')'</Piece>'
790  end if
791  end do
792  end if
793  end do
794 
795  write(qunit,'(a)')'</UnstructuredGrid>'
796  write(qunit,'(a)')'</VTKFile>'
797  close(qunit)
798 
799  end subroutine unstructuredvtk
800 
801  subroutine unstructuredvtkb(qunit)
802 
803  ! output for vtu format to paraview, binary version output
804  ! not parallel, uses calc_grid to compute nwauxio variables
805  ! allows renormalizing using convert factors
808  use mod_calculate_xw
809 
810  integer, intent(in) :: qunit
811 
812  double precision :: x_VTK(1:3)
813  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
814  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
815  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
816  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
817  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio):: wC_TMP
818  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
819  double precision :: normconv(0:nw+nwauxio)
820  integer, allocatable :: intstatus(:,:)
821  integer*8 :: offset
822  integer :: itag,ipe,igrid,level,icel,ixC^L,ixCC^L,Morton_no,Morton_length
823  integer :: nx^D,nxC^D,nc,np,VTK_type,ix^D,filenr
824  integer:: k,iw
825  integer:: length,lengthcc,length_coords,length_conn,length_offsets
826  character:: buf
827  character(len=80):: filename
828  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
829  character(len=1024) :: outfilehead
830  logical :: fileopen,cell_corner=.false.
831  logical, allocatable :: Morton_aim(:),Morton_aim_p(:)
832 
833  normconv=one
834  morton_length=morton_stop(npe-1)-morton_start(0)+1
835  allocate(morton_aim(morton_start(0):morton_stop(npe-1)))
836  allocate(morton_aim_p(morton_start(0):morton_stop(npe-1)))
837  morton_aim=.false.
838  morton_aim_p=.false.
839  do morton_no=morton_start(mype),morton_stop(mype)
840  igrid=sfc_to_igrid(morton_no)
841  level=node(plevel_,igrid)
842  ! we can clip parts of the grid away, select variables, levels etc.
843  if(writelevel(level)) then
844  ! only output a grid when fully within clipped region selected
845  ! by writespshift array
846  if(({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
847  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
848  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
849  morton_aim_p(morton_no)=.true.
850  end if
851  end if
852  end do
853  call mpi_allreduce(morton_aim_p,morton_aim,morton_length,mpi_logical,mpi_lor,&
854  icomm,ierrmpi)
855  select case(convert_type)
856  case('vtuB','vtuBmpi')
857  cell_corner=.true.
858  case('vtuBCC','vtuBCCmpi')
859  cell_corner=.false.
860  end select
861  if (mype /= 0) then
862  do morton_no=morton_start(mype),morton_stop(mype)
863  if(.not. morton_aim(morton_no)) cycle
864  igrid=sfc_to_igrid(morton_no)
865  call calc_x(igrid,xc,xcc)
866  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
867  ixc^l,ixcc^l,.true.)
868  itag=morton_no
869  call mpi_send(xc_tmp,1,type_block_xc_io, 0,itag,icomm,ierrmpi)
870  if(cell_corner) then
871  call mpi_send(wc_tmp,1,type_block_wc_io, 0,itag,icomm,ierrmpi)
872  else
873  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
874  end if
875  end do
876 
877  else
878  ! mype==0
879  offset=0
880  inquire(qunit,opened=fileopen)
881  if(.not.fileopen)then
882  ! generate filename
883  filenr=snapshotini
884  if (autoconvert) filenr=snapshotnext
885  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".vtu"
886  ! Open the file for the header part
887  open(qunit,file=filename,status='replace')
888  end if
889  call getheadernames(wnamei,xandwnamei,outfilehead)
890  ! generate xml header
891  write(qunit,'(a)')'<?xml version="1.0"?>'
892  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
893  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
894  write(qunit,'(a)')'<UnstructuredGrid>'
895  write(qunit,'(a)')'<FieldData>'
896  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
897  'NumberOfTuples="1" format="ascii">'
898  write(qunit,*) real(global_time*time_convert_factor)
899  write(qunit,'(a)')'</DataArray>'
900  write(qunit,'(a)')'</FieldData>'
901 
902  ! number of cells, number of corner points, per grid.
903  nx^d=ixmhi^d-ixmlo^d+1;
904  nxc^d=nx^d+1;
905  nc={nx^d*}
906  np={nxc^d*}
907  length=np*size_real
908  lengthcc=nc*size_real
909  length_coords=3*length
910  length_conn=2**^nd*size_int*nc
911  length_offsets=nc*size_int
912 
913  ! Note: using the w_write, writelevel, writespshift
914  do morton_no=morton_start(0),morton_stop(0)
915  if(.not. morton_aim(morton_no)) cycle
916  if(cell_corner) then
917  ! we write out every grid as one VTK PIECE
918  write(qunit,'(a,i7,a,i7,a)') &
919  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
920  write(qunit,'(a)')'<PointData>'
921  do iw=1,nw+nwauxio
922  if(iw<=nw) then
923  if(.not.w_write(iw)) cycle
924  endif
925  write(qunit,'(a,a,a,i16,a)')&
926  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
927  '" format="appended" offset="',offset,'">'
928  write(qunit,'(a)')'</DataArray>'
929  offset=offset+length+size_int
930  end do
931  write(qunit,'(a)')'</PointData>'
932  write(qunit,'(a)')'<Points>'
933  write(qunit,'(a,i16,a)') &
934  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
935  ! write cell corner coordinates in a backward dimensional loop, always 3D output
936  offset=offset+length_coords+size_int
937  write(qunit,'(a)')'</Points>'
938  else
939  ! we write out every grid as one VTK PIECE
940  write(qunit,'(a,i7,a,i7,a)') &
941  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
942  write(qunit,'(a)')'<CellData>'
943  do iw=1,nw+nwauxio
944  if(iw<=nw) then
945  if(.not.w_write(iw)) cycle
946  end if
947  write(qunit,'(a,a,a,i16,a)')&
948  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
949  '" format="appended" offset="',offset,'">'
950  write(qunit,'(a)')'</DataArray>'
951  offset=offset+lengthcc+size_int
952  end do
953  write(qunit,'(a)')'</CellData>'
954  write(qunit,'(a)')'<Points>'
955  write(qunit,'(a,i16,a)') &
956  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
957  ! write cell corner coordinates in a backward dimensional loop, always 3D output
958  offset=offset+length_coords+size_int
959  write(qunit,'(a)')'</Points>'
960  end if
961  write(qunit,'(a)')'<Cells>'
962  ! connectivity part
963  write(qunit,'(a,i16,a)')&
964  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',offset,'"/>'
965  offset=offset+length_conn+size_int
966  ! offsets data array
967  write(qunit,'(a,i16,a)') &
968  '<DataArray type="Int32" Name="offsets" format="appended" offset="',offset,'"/>'
969  offset=offset+length_offsets+size_int
970  ! VTK cell type data array
971  write(qunit,'(a,i16,a)') &
972  '<DataArray type="Int32" Name="types" format="appended" offset="',offset,'"/>'
973  offset=offset+size_int+nc*size_int
974  write(qunit,'(a)')'</Cells>'
975  write(qunit,'(a)')'</Piece>'
976  end do
977  ! write metadata communicated from other processors
978  if(npe>1)then
979  do ipe=1, npe-1
980  do morton_no=morton_start(ipe),morton_stop(ipe)
981  if(.not. morton_aim(morton_no)) cycle
982  if(cell_corner) then
983  ! we write out every grid as one VTK PIECE
984  write(qunit,'(a,i7,a,i7,a)') &
985  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
986  write(qunit,'(a)')'<PointData>'
987  do iw=1,nw+nwauxio
988  if(iw<=nw) then
989  if(.not.w_write(iw)) cycle
990  end if
991  write(qunit,'(a,a,a,i16,a)')&
992  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
993  '" format="appended" offset="',offset,'">'
994  write(qunit,'(a)')'</DataArray>'
995  offset=offset+length+size_int
996  end do
997  write(qunit,'(a)')'</PointData>'
998  write(qunit,'(a)')'<Points>'
999  write(qunit,'(a,i16,a)') &
1000  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1001  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1002  offset=offset+length_coords+size_int
1003  write(qunit,'(a)')'</Points>'
1004  else
1005  ! we write out every grid as one VTK PIECE
1006  write(qunit,'(a,i7,a,i7,a)') &
1007  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
1008  write(qunit,'(a)')'<CellData>'
1009  do iw=1,nw+nwauxio
1010  if(iw<=nw) then
1011  if(.not.w_write(iw)) cycle
1012  end if
1013  write(qunit,'(a,a,a,i16,a)')&
1014  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
1015  '" format="appended" offset="',offset,'">'
1016  write(qunit,'(a)')'</DataArray>'
1017  offset=offset+lengthcc+size_int
1018  end do
1019  write(qunit,'(a)')'</CellData>'
1020  write(qunit,'(a)')'<Points>'
1021  write(qunit,'(a,i16,a)') &
1022  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1023  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1024  offset=offset+length_coords+size_int
1025  write(qunit,'(a)')'</Points>'
1026  end if
1027  write(qunit,'(a)')'<Cells>'
1028  ! connectivity part
1029  write(qunit,'(a,i16,a)')&
1030  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',offset,'"/>'
1031  offset=offset+length_conn+size_int
1032  ! offsets data array
1033  write(qunit,'(a,i16,a)') &
1034  '<DataArray type="Int32" Name="offsets" format="appended" offset="',offset,'"/>'
1035  offset=offset+length_offsets+size_int
1036  ! VTK cell type data array
1037  write(qunit,'(a,i16,a)') &
1038  '<DataArray type="Int32" Name="types" format="appended" offset="',offset,'"/>'
1039  offset=offset+size_int+nc*size_int
1040  write(qunit,'(a)')'</Cells>'
1041  write(qunit,'(a)')'</Piece>'
1042  end do
1043  end do
1044  end if
1045 
1046  write(qunit,'(a)')'</UnstructuredGrid>'
1047  write(qunit,'(a)')'<AppendedData encoding="raw">'
1048  close(qunit)
1049  open(qunit,file=filename,access='stream',form='unformatted',position='append')
1050  buf='_'
1051  write(qunit) trim(buf)
1052 
1053  do morton_no=morton_start(0),morton_stop(0)
1054  if(.not. morton_aim(morton_no)) cycle
1055  igrid=sfc_to_igrid(morton_no)
1056  call calc_x(igrid,xc,xcc)
1057  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1058  ixc^l,ixcc^l,.true.)
1059  do iw=1,nw+nwauxio
1060  if(iw<=nw) then
1061  if(.not.w_write(iw)) cycle
1062  end if
1063  if(cell_corner) then
1064  write(qunit) length
1065  write(qunit) {(|}real(wc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixcmin^d,ixcmax^d)}
1066  else
1067  write(qunit) lengthcc
1068  write(qunit) {(|}real(wcc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixccmin^d,ixccmax^d)}
1069  end if
1070  end do
1071 
1072  write(qunit) length_coords
1073  {do ix^db=ixcmin^db,ixcmax^db \}
1074  x_vtk(1:3)=zero;
1075  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
1076  do k=1,3
1077  write(qunit) real(x_vtk(k))
1078  end do
1079  {end do \}
1080 
1081  write(qunit) length_conn
1082  {do ix^db=1,nx^db\}
1083  {^ifoned write(qunit)ix1-1,ix1 \}
1084  {^iftwod
1085  write(qunit)(ix2-1)*nxc1+ix1-1, &
1086  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
1087  \}
1088  {^ifthreed
1089  write(qunit)&
1090  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
1091  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1092  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1093  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
1094  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
1095  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1096  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1097  ix3*nxc2*nxc1+ ix2*nxc1+ix1
1098  \}
1099  {end do\}
1100 
1101  write(qunit) length_offsets
1102  do icel=1,nc
1103  write(qunit) icel*(2**^nd)
1104  end do
1105 
1106  {^ifoned vtk_type=3 \}
1107  {^iftwod vtk_type=8 \}
1108  {^ifthreed vtk_type=11 \}
1109  write(qunit) size_int*nc
1110  do icel=1,nc
1111  write(qunit) vtk_type
1112  end do
1113  end do
1114  allocate(intstatus(mpi_status_size,1))
1115  if(npe>1)then
1116  ixccmin^d=ixmlo^d; ixccmax^d=ixmhi^d;
1117  ixcmin^d=ixmlo^d-1; ixcmax^d=ixmhi^d;
1118  do ipe=1, npe-1
1119  do morton_no=morton_start(ipe),morton_stop(ipe)
1120  if(.not. morton_aim(morton_no)) cycle
1121  itag=morton_no
1122  call mpi_recv(xc_tmp,1,type_block_xc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1123  if(cell_corner) then
1124  call mpi_recv(wc_tmp,1,type_block_wc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1125  else
1126  call mpi_recv(wcc_tmp,1,type_block_wcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1127  end if
1128  do iw=1,nw+nwauxio
1129  if(iw<=nw) then
1130  if(.not.w_write(iw)) cycle
1131  end if
1132  if(cell_corner) then
1133  write(qunit) length
1134  write(qunit) {(|}real(wc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixcmin^d,ixcmax^d)}
1135  else
1136  write(qunit) lengthcc
1137  write(qunit) {(|}real(wcc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixccmin^d,ixccmax^d)}
1138  end if
1139  end do
1140  write(qunit) length_coords
1141  {do ix^db=ixcmin^db,ixcmax^db \}
1142  x_vtk(1:3)=zero;
1143  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
1144  do k=1,3
1145  write(qunit) real(x_vtk(k))
1146  end do
1147  {end do \}
1148  write(qunit) length_conn
1149  {do ix^db=1,nx^db\}
1150  {^ifoned write(qunit)ix1-1,ix1 \}
1151  {^iftwod
1152  write(qunit)(ix2-1)*nxc1+ix1-1, &
1153  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
1154  \}
1155  {^ifthreed
1156  write(qunit)&
1157  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
1158  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1159  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1160  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
1161  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
1162  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1163  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1164  ix3*nxc2*nxc1+ ix2*nxc1+ix1
1165  \}
1166  {end do\}
1167  write(qunit) length_offsets
1168  do icel=1,nc
1169  write(qunit) icel*(2**^nd)
1170  end do
1171  {^ifoned vtk_type=3 \}
1172  {^iftwod vtk_type=8 \}
1173  {^ifthreed vtk_type=11 \}
1174  write(qunit) size_int*nc
1175  do icel=1,nc
1176  write(qunit) vtk_type
1177  end do
1178  end do
1179  end do
1180  end if
1181  close(qunit)
1182  open(qunit,file=filename,status='unknown',form='formatted',position='append')
1183  write(qunit,'(a)')'</AppendedData>'
1184  write(qunit,'(a)')'</VTKFile>'
1185  close(qunit)
1186  deallocate(intstatus)
1187  end if
1188 
1189  deallocate(morton_aim,morton_aim_p)
1190  if (npe>1) then
1191  call mpi_barrier(icomm,ierrmpi)
1192  end if
1193 
1194  end subroutine unstructuredvtkb
1195 
1196  subroutine unstructuredvtkb64(qunit)
1197  ! output for vtu format to paraview, binary version output
1198  ! not parallel, uses calc_grid to compute nwauxio variables
1199  ! allows renormalizing using convert factors
1202  use mod_calculate_xw
1203 
1204  integer, intent(in) :: qunit
1205 
1206  double precision :: x_VTK(1:3)
1207  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
1208  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
1209  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
1210  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
1211  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio):: wC_TMP
1212  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
1213  double precision :: normconv(0:nw+nwauxio)
1214  integer, allocatable :: intstatus(:,:)
1215  integer*8 :: offset
1216  integer :: itag,ipe,igrid,level,icel,ixC^L,ixCC^L,Morton_no,Morton_length
1217  integer :: nx^D,nxC^D,nc,np,VTK_type,ix^D,filenr
1218  integer:: k,iw
1219  integer:: length,lengthcc,length_coords,length_conn,length_offsets
1220  character:: buf
1221  character(len=80):: filename
1222  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
1223  character(len=1024) :: outfilehead
1224  logical :: fileopen,cell_corner=.false.
1225  logical, allocatable :: Morton_aim(:),Morton_aim_p(:)
1226 
1227  normconv=one
1228  morton_length=morton_stop(npe-1)-morton_start(0)+1
1229  allocate(morton_aim(morton_start(0):morton_stop(npe-1)))
1230  allocate(morton_aim_p(morton_start(0):morton_stop(npe-1)))
1231  morton_aim=.false.
1232  morton_aim_p=.false.
1233  do morton_no=morton_start(mype),morton_stop(mype)
1234  igrid=sfc_to_igrid(morton_no)
1235  level=node(plevel_,igrid)
1236  ! we can clip parts of the grid away, select variables, levels etc.
1237  if(writelevel(level)) then
1238  ! only output a grid when fully within clipped region selected
1239  ! by writespshift array
1240  if(({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
1241  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
1242  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
1243  morton_aim_p(morton_no)=.true.
1244  end if
1245  end if
1246  end do
1247  call mpi_allreduce(morton_aim_p,morton_aim,morton_length,mpi_logical,mpi_lor,&
1248  icomm,ierrmpi)
1249  select case(convert_type)
1250  case('vtuB64','vtuBmpi64')
1251  cell_corner=.true.
1252  case('vtuBCC64','vtuBCCmpi64')
1253  cell_corner=.false.
1254  end select
1255  if (mype /= 0) then
1256  do morton_no=morton_start(mype),morton_stop(mype)
1257  if(.not. morton_aim(morton_no)) cycle
1258  igrid=sfc_to_igrid(morton_no)
1259  call calc_x(igrid,xc,xcc)
1260  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1261  ixc^l,ixcc^l,.true.)
1262  itag=morton_no
1263  call mpi_send(xc_tmp,1,type_block_xc_io, 0,itag,icomm,ierrmpi)
1264  if(cell_corner) then
1265  call mpi_send(wc_tmp,1,type_block_wc_io, 0,itag,icomm,ierrmpi)
1266  else
1267  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
1268  end if
1269  end do
1270  else
1271  ! mype==0
1272  offset=0
1273  inquire(qunit,opened=fileopen)
1274  if(.not.fileopen)then
1275  ! generate filename
1276  filenr=snapshotini
1277  if (autoconvert) filenr=snapshotnext
1278  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".vtu"
1279  ! Open the file for the header part
1280  open(qunit,file=filename,status='replace')
1281  end if
1282  call getheadernames(wnamei,xandwnamei,outfilehead)
1283  ! generate xml header
1284  write(qunit,'(a)')'<?xml version="1.0"?>'
1285  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
1286  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
1287  write(qunit,'(a)')'<UnstructuredGrid>'
1288  write(qunit,'(a)')'<FieldData>'
1289  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
1290  'NumberOfTuples="1" format="ascii">'
1291  write(qunit,*) real(global_time*time_convert_factor)
1292  write(qunit,'(a)')'</DataArray>'
1293  write(qunit,'(a)')'</FieldData>'
1294  ! number of cells, number of corner points, per grid.
1295  nx^d=ixmhi^d-ixmlo^d+1;
1296  nxc^d=nx^d+1;
1297  nc={nx^d*}
1298  np={nxc^d*}
1299  length=np*size_double
1300  lengthcc=nc*size_double
1301  length_coords=3*length
1302  length_conn=2**^nd*size_int*nc
1303  length_offsets=nc*size_int
1304  ! Note: using the w_write, writelevel, writespshift
1305  do morton_no=morton_start(0),morton_stop(0)
1306  if(.not. morton_aim(morton_no)) cycle
1307  if(cell_corner) then
1308  ! we write out every grid as one VTK PIECE
1309  write(qunit,'(a,i7,a,i7,a)') &
1310  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
1311  write(qunit,'(a)')'<PointData>'
1312  do iw=1,nw+nwauxio
1313  if(iw<=nw) then
1314  if(.not.w_write(iw)) cycle
1315  end if
1316  write(qunit,'(a,a,a,i16,a)')&
1317  '<DataArray type="Float64" Name="',trim(wnamei(iw)), &
1318  '" format="appended" offset="',offset,'">'
1319  write(qunit,'(a)')'</DataArray>'
1320  offset=offset+length+size_int
1321  end do
1322  write(qunit,'(a)')'</PointData>'
1323  write(qunit,'(a)')'<Points>'
1324  write(qunit,'(a,i16,a)') &
1325  '<DataArray type="Float64" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1326  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1327  offset=offset+length_coords+size_int
1328  write(qunit,'(a)')'</Points>'
1329  else
1330  ! we write out every grid as one VTK PIECE
1331  write(qunit,'(a,i7,a,i7,a)') &
1332  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
1333  write(qunit,'(a)')'<CellData>'
1334  do iw=1,nw+nwauxio
1335  if(iw<=nw) then
1336  if(.not.w_write(iw)) cycle
1337  end if
1338  write(qunit,'(a,a,a,i16,a)')&
1339  '<DataArray type="Float64" Name="',trim(wnamei(iw)), &
1340  '" format="appended" offset="',offset,'">'
1341  write(qunit,'(a)')'</DataArray>'
1342  offset=offset+lengthcc+size_int
1343  end do
1344  write(qunit,'(a)')'</CellData>'
1345  write(qunit,'(a)')'<Points>'
1346  write(qunit,'(a,i16,a)') &
1347  '<DataArray type="Float64" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1348  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1349  offset=offset+length_coords+size_int
1350  write(qunit,'(a)')'</Points>'
1351  end if
1352  write(qunit,'(a)')'<Cells>'
1353  ! connectivity part
1354  write(qunit,'(a,i16,a)')&
1355  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',offset,'"/>'
1356  offset=offset+length_conn+size_int
1357  ! offsets data array
1358  write(qunit,'(a,i16,a)') &
1359  '<DataArray type="Int32" Name="offsets" format="appended" offset="',offset,'"/>'
1360  offset=offset+length_offsets+size_int
1361  ! VTK cell type data array
1362  write(qunit,'(a,i16,a)') &
1363  '<DataArray type="Int32" Name="types" format="appended" offset="',offset,'"/>'
1364  offset=offset+size_int+nc*size_int
1365  write(qunit,'(a)')'</Cells>'
1366  write(qunit,'(a)')'</Piece>'
1367  end do
1368  ! write metadata communicated from other processors
1369  if(npe>1)then
1370  do ipe=1, npe-1
1371  do morton_no=morton_start(ipe),morton_stop(ipe)
1372  if(.not. morton_aim(morton_no)) cycle
1373  if(cell_corner) then
1374  ! we write out every grid as one VTK PIECE
1375  write(qunit,'(a,i7,a,i7,a)') &
1376  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
1377  write(qunit,'(a)')'<PointData>'
1378  do iw=1,nw+nwauxio
1379  if(iw<=nw) then
1380  if(.not.w_write(iw)) cycle
1381  end if
1382  write(qunit,'(a,a,a,i16,a)')&
1383  '<DataArray type="Float64" Name="',trim(wnamei(iw)), &
1384  '" format="appended" offset="',offset,'">'
1385  write(qunit,'(a)')'</DataArray>'
1386  offset=offset+length+size_int
1387  end do
1388  write(qunit,'(a)')'</PointData>'
1389  write(qunit,'(a)')'<Points>'
1390  write(qunit,'(a,i16,a)') &
1391  '<DataArray type="Float64" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1392  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1393  offset=offset+length_coords+size_int
1394  write(qunit,'(a)')'</Points>'
1395  else
1396  ! we write out every grid as one VTK PIECE
1397  write(qunit,'(a,i7,a,i7,a)') &
1398  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
1399  write(qunit,'(a)')'<CellData>'
1400  do iw=1,nw+nwauxio
1401  if(iw<=nw) then
1402  if(.not.w_write(iw)) cycle
1403  end if
1404  write(qunit,'(a,a,a,i16,a)')&
1405  '<DataArray type="Float64" Name="',trim(wnamei(iw)), &
1406  '" format="appended" offset="',offset,'">'
1407  write(qunit,'(a)')'</DataArray>'
1408  offset=offset+lengthcc+size_int
1409  end do
1410  write(qunit,'(a)')'</CellData>'
1411  write(qunit,'(a)')'<Points>'
1412  write(qunit,'(a,i16,a)') &
1413  '<DataArray type="Float64" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
1414  ! write cell corner coordinates in a backward dimensional loop, always 3D output
1415  offset=offset+length_coords+size_int
1416  write(qunit,'(a)')'</Points>'
1417  end if
1418  write(qunit,'(a)')'<Cells>'
1419  ! connectivity part
1420  write(qunit,'(a,i16,a)')&
1421  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',offset,'"/>'
1422  offset=offset+length_conn+size_int
1423  ! offsets data array
1424  write(qunit,'(a,i16,a)') &
1425  '<DataArray type="Int32" Name="offsets" format="appended" offset="',offset,'"/>'
1426  offset=offset+length_offsets+size_int
1427  ! VTK cell type data array
1428  write(qunit,'(a,i16,a)') &
1429  '<DataArray type="Int32" Name="types" format="appended" offset="',offset,'"/>'
1430  offset=offset+size_int+nc*size_int
1431  write(qunit,'(a)')'</Cells>'
1432  write(qunit,'(a)')'</Piece>'
1433  end do
1434  end do
1435  end if
1436  write(qunit,'(a)')'</UnstructuredGrid>'
1437  write(qunit,'(a)')'<AppendedData encoding="raw">'
1438  close(qunit)
1439  open(qunit,file=filename,access='stream',form='unformatted',position='append')
1440  buf='_'
1441  write(qunit) trim(buf)
1442  do morton_no=morton_start(0),morton_stop(0)
1443  if(.not. morton_aim(morton_no)) cycle
1444  igrid=sfc_to_igrid(morton_no)
1445  call calc_x(igrid,xc,xcc)
1446  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1447  ixc^l,ixcc^l,.true.)
1448  do iw=1,nw+nwauxio
1449  if(iw<=nw) then
1450  if(.not.w_write(iw)) cycle
1451  end if
1452  if(cell_corner) then
1453  write(qunit) length
1454  write(qunit) {(|}wc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixcmin^d,ixcmax^d)}
1455  else
1456  write(qunit) lengthcc
1457  write(qunit) {(|}wcc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixccmin^d,ixccmax^d)}
1458  end if
1459  end do
1460  write(qunit) length_coords
1461  {do ix^db=ixcmin^db,ixcmax^db \}
1462  x_vtk(1:3)=zero;
1463  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
1464  do k=1,3
1465  write(qunit) x_vtk(k)
1466  end do
1467  {end do \}
1468  write(qunit) length_conn
1469  {do ix^db=1,nx^db\}
1470  {^ifoned write(qunit)ix1-1,ix1 \}
1471  {^iftwod
1472  write(qunit)(ix2-1)*nxc1+ix1-1, &
1473  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
1474  \}
1475  {^ifthreed
1476  write(qunit)&
1477  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
1478  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1479  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1480  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
1481  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
1482  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1483  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1484  ix3*nxc2*nxc1+ ix2*nxc1+ix1
1485  \}
1486  {end do\}
1487  write(qunit) length_offsets
1488  do icel=1,nc
1489  write(qunit) icel*(2**^nd)
1490  end do
1491  {^ifoned vtk_type=3 \}
1492  {^iftwod vtk_type=8 \}
1493  {^ifthreed vtk_type=11 \}
1494  write(qunit) size_int*nc
1495  do icel=1,nc
1496  write(qunit) vtk_type
1497  end do
1498  end do
1499  allocate(intstatus(mpi_status_size,1))
1500  if(npe>1)then
1501  ixccmin^d=ixmlo^d; ixccmax^d=ixmhi^d;
1502  ixcmin^d=ixmlo^d-1; ixcmax^d=ixmhi^d;
1503  do ipe=1, npe-1
1504  do morton_no=morton_start(ipe),morton_stop(ipe)
1505  if(.not. morton_aim(morton_no)) cycle
1506  itag=morton_no
1507  call mpi_recv(xc_tmp,1,type_block_xc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1508  if(cell_corner) then
1509  call mpi_recv(wc_tmp,1,type_block_wc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1510  else
1511  call mpi_recv(wcc_tmp,1,type_block_wcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1512  end if
1513  do iw=1,nw+nwauxio
1514  if(iw<=nw) then
1515  if(.not.w_write(iw)) cycle
1516  end if
1517  if(cell_corner) then
1518  write(qunit) length
1519  write(qunit) {(|}wc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixcmin^d,ixcmax^d)}
1520  else
1521  write(qunit) lengthcc
1522  write(qunit) {(|}wcc_tmp(ix^d,iw)*normconv(iw),{ix^d=ixccmin^d,ixccmax^d)}
1523  end if
1524  end do
1525  write(qunit) length_coords
1526  {do ix^db=ixcmin^db,ixcmax^db \}
1527  x_vtk(1:3)=zero;
1528  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
1529  do k=1,3
1530  write(qunit) x_vtk(k)
1531  end do
1532  {end do \}
1533  write(qunit) length_conn
1534  {do ix^db=1,nx^db\}
1535  {^ifoned write(qunit)ix1-1,ix1 \}
1536  {^iftwod
1537  write(qunit)(ix2-1)*nxc1+ix1-1, &
1538  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
1539  \}
1540  {^ifthreed
1541  write(qunit)&
1542  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
1543  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1544  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1545  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
1546  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
1547  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1548  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1549  ix3*nxc2*nxc1+ ix2*nxc1+ix1
1550  \}
1551  {end do\}
1552  write(qunit) length_offsets
1553  do icel=1,nc
1554  write(qunit) icel*(2**^nd)
1555  end do
1556  {^ifoned vtk_type=3 \}
1557  {^iftwod vtk_type=8 \}
1558  {^ifthreed vtk_type=11 \}
1559  write(qunit) size_int*nc
1560  do icel=1,nc
1561  write(qunit) vtk_type
1562  end do
1563  end do
1564  end do
1565  end if
1566  close(qunit)
1567  open(qunit,file=filename,status='unknown',form='formatted',position='append')
1568  write(qunit,'(a)')'</AppendedData>'
1569  write(qunit,'(a)')'</VTKFile>'
1570  close(qunit)
1571  deallocate(intstatus)
1572  end if
1573  deallocate(morton_aim,morton_aim_p)
1574  if (npe>1) then
1575  call mpi_barrier(icomm,ierrmpi)
1576  end if
1577 
1578  end subroutine unstructuredvtkb64
1579 
1580  subroutine save_connvtk(qunit,igrid)
1581  ! this saves the basic line, pixel and voxel connectivity,
1582  ! as used by VTK file outputs for unstructured grid
1584 
1585  integer, intent(in) :: qunit, igrid
1586 
1587  integer :: nx^D, nxC^D, ix^D
1588 
1589  nx^d=ixmhi^d-ixmlo^d+1;
1590  nxc^d=nx^d+1;
1591  {do ix^db=1,nx^db\}
1592  {^ifoned write(qunit,'(2(i7,1x))')ix1-1,ix1 \}
1593  {^iftwod
1594  write(qunit,'(4(i7,1x))')(ix2-1)*nxc1+ix1-1, &
1595  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
1596  \}
1597  {^ifthreed
1598  write(qunit,'(8(i7,1x))')&
1599  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
1600  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1601  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1602  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
1603  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
1604  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
1605  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
1606  ix3*nxc2*nxc1+ ix2*nxc1+ix1
1607  \}
1608  {end do\}
1609 
1610  end subroutine save_connvtk
1611 
1612  subroutine imagedatavtk_mpi(qunit)
1613  ! output for vti format to paraview, non-binary version output
1614  ! parallel, uses calc_grid to compute nwauxio variables
1615  ! allows renormalizing using convert factors
1616  ! allows skipping of w_write selected variables
1617  ! implementation such that length of ASCII output is identical when
1618  ! run on 1 versus multiple CPUs (however, the order of the vtu pieces can differ)
1621  use mod_calculate_xw
1622 
1623  integer, intent(in) :: qunit
1624 
1625  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP,xC_TMP_recv
1626  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP,xCC_TMP_recv
1627  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
1628  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
1629  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP,wC_TMP_recv
1630  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP,wCC_TMP_recv
1631  double precision, dimension(0:nw+nwauxio) :: normconv
1632  double precision :: origin(1:3), spacing(1:3)
1633  integer :: igrid,iigrid,level,ixC^L,ixCC^L
1634  integer :: NumGridsOnLevel(1:nlevelshi)
1635  integer :: nx^D
1636  integer :: filenr
1637  integer :: itag,ipe,Morton_no,Morton_length
1638  integer :: ixrvC^L, ixrvCC^L, siz_ind, ind_send(5*^ND), ind_recv(5*^ND)
1639  integer :: wholeExtent(1:6), ig^D
1640  integer, allocatable :: intstatus(:,:)
1641  logical, allocatable :: Morton_aim(:),Morton_aim_p(:)
1642  logical :: fileopen
1643  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
1644  character(len=1024) :: outfilehead
1645  character(len=80):: filename
1646  type(tree_node_ptr) :: tree
1647 
1648  if(levmin/=levmax) call mpistop('ImageData can only be used when levmin=levmax')
1649  normconv(0) = length_convert_factor
1650  normconv(1:nw) = w_convert_factor
1651  siz_ind=5*^nd
1652  morton_length=morton_stop(npe-1)-morton_start(0)+1
1653  allocate(morton_aim(morton_start(0):morton_stop(npe-1)))
1654  allocate(morton_aim_p(morton_start(0):morton_stop(npe-1)))
1655  morton_aim=.false.
1656  morton_aim_p=.false.
1657  do morton_no=morton_start(mype),morton_stop(mype)
1658  igrid=sfc_to_igrid(morton_no)
1659  level=node(plevel_,igrid)
1660  ! we can clip parts of the grid away, select variables, levels etc.
1661  if(writelevel(level)) then
1662  ! only output a grid when fully within clipped region selected
1663  ! by writespshift array
1664  if(({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
1665  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
1666  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
1667  morton_aim_p(morton_no)=.true.
1668  end if
1669  end if
1670  end do
1671  call mpi_allreduce(morton_aim_p,morton_aim,morton_length,mpi_logical,mpi_lor,&
1672  icomm,ierrmpi)
1673  if(mype /= 0) then
1674  do morton_no=morton_start(mype),morton_stop(mype)
1675  if(.not. morton_aim(morton_no)) cycle
1676  igrid=sfc_to_igrid(morton_no)
1677  call calc_x(igrid,xc,xcc)
1678  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1679  ixc^l,ixcc^l,.true.)
1680  tree%node => igrid_to_node(igrid, mype)%node
1681  {^d& ig^d = tree%node%ig^d; }
1682  itag=morton_no
1683  ind_send=(/ ixc^l,ixcc^l, ig^d /)
1684  call mpi_send(ind_send,siz_ind,mpi_integer, 0,itag,icomm,ierrmpi)
1685  call mpi_send(wc_tmp,1,type_block_wc_io, 0,itag,icomm,ierrmpi)
1686  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
1687  end do
1688  else
1689  inquire(qunit,opened=fileopen)
1690  if(.not.fileopen)then
1691  ! generate filename
1692  filenr=snapshotini
1693  if (autoconvert) filenr=snapshotnext
1694  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".vti"
1695  ! Open the file for the header part
1696  open(qunit,file=filename,status='unknown',form='formatted')
1697  end if
1698  call getheadernames(wnamei,xandwnamei,outfilehead)
1699  ! number of cells per grid.
1700  nx^d=ixmhi^d-ixmlo^d+1;
1701  origin = 0
1702  {^d& origin(^d) = xprobmin^d*normconv(0); }
1703  spacing = zero
1704  {^d&spacing(^d) = dxlevel(^d)*normconv(0); }
1705  wholeextent = 0
1706  ! if we use writespshift, the whole extent has to be calculated:
1707  {^d&wholeextent(^d*2-1) = nx^d * ceiling(((xprobmax^d-xprobmin^d)*writespshift(^d,1)) &
1708  /(nx^d*dxlevel(^d))) \}
1709  {^d&wholeextent(^d*2) = nx^d * floor(((xprobmax^d-xprobmin^d)*(1.0d0-writespshift(^d,2))) &
1710  /(nx^d*dxlevel(^d))) \}
1711 
1712  ! generate xml header
1713  write(qunit,'(a)')'<?xml version="1.0"?>'
1714  write(qunit,'(a)',advance='no') '<VTKFile type="ImageData"'
1715  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
1716  write(qunit,'(a,3(1pe14.6),a,6(i10),a,3(1pe14.6),a)')' <ImageData Origin="',&
1717  origin,'" WholeExtent="',wholeextent,'" Spacing="',spacing,'">'
1718  write(qunit,'(a)')'<FieldData>'
1719  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
1720  'NumberOfTuples="1" format="ascii">'
1721  write(qunit,*) real(global_time*time_convert_factor)
1722  write(qunit,'(a)')'</DataArray>'
1723  write(qunit,'(a)')'</FieldData>'
1724 
1725  ! write the data from proc 0
1726  do morton_no=morton_start(0),morton_stop(0)
1727  if(.not. morton_aim(morton_no)) cycle
1728  igrid=sfc_to_igrid(morton_no)
1729  tree%node => igrid_to_node(igrid, 0)%node
1730  {^d& ig^d = tree%node%ig^d; }
1731  call calc_x(igrid,xc,xcc)
1732  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1733  ixc^l,ixcc^l,.true.)
1734  call write_vti(qunit,ixg^ll,ixc^l,ixcc^l,ig^d,&
1735  nx^d,normconv,wnamei,wc_tmp,wcc_tmp)
1736  end do
1737 
1738  if(npe>1)then
1739  allocate(intstatus(mpi_status_size,1))
1740  do ipe=1, npe-1
1741  do morton_no=morton_start(ipe),morton_stop(ipe)
1742  if(.not. morton_aim(morton_no)) cycle
1743  itag=morton_no
1744  call mpi_recv(ind_recv,siz_ind, mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1745  ixrvcmin^d=ind_recv(^d);ixrvcmax^d=ind_recv(^nd+^d);
1746  ixrvccmin^d=ind_recv(2*^nd+^d);ixrvccmax^d=ind_recv(3*^nd+^d);
1747  ig^d=ind_recv(4*^nd+^d);
1748  call mpi_recv(wc_tmp,1,type_block_wc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1749  call mpi_recv(wcc_tmp,1,type_block_wcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1750  call write_vti(qunit,ixg^ll,ixrvc^l,ixrvcc^l,ig^d,&
1751  nx^d,normconv,wnamei,wc_tmp,wcc_tmp)
1752  end do
1753  end do
1754  end if
1755  write(qunit,'(a)')'</ImageData>'
1756  write(qunit,'(a)')'</VTKFile>'
1757  close(qunit)
1758  if(npe>1) deallocate(intstatus)
1759  end if
1760 
1761  deallocate(morton_aim,morton_aim_p)
1762  if (npe>1) then
1763  call mpi_barrier(icomm,ierrmpi)
1764  endif
1765 
1766  end subroutine imagedatavtk_mpi
1767 
1768  subroutine punstructuredvtk_mpi(qunit)
1769  ! Write one pvtu and vtu files for each processor
1770  ! Otherwise like unstructuredvtk_mpi
1773  use mod_calculate_xw
1774 
1775  integer, intent(in) :: qunit
1776 
1777  double precision, dimension(0:nw+nwauxio) :: normconv
1778  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
1779  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
1780  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
1781  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
1782  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP
1783  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
1784  integer :: nx^D,nxC^D,nc,np, igrid,ixC^L,ixCC^L,level,Morton_no
1785  integer :: filenr
1786  logical :: fileopen,conv_grid
1787  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
1788  character(len=1024) :: outfilehead
1789  character(len=80) :: pfilename
1790 
1791  ! Write pvtu-file:
1792  if (mype==0) then
1793  call write_pvtu(qunit)
1794  endif
1795  ! Now write the Source files:
1796  inquire(qunit,opened=fileopen)
1797  if(.not.fileopen)then
1798  ! generate filename
1799  filenr=snapshotini
1800  if (autoconvert) filenr=snapshotnext
1801  ! Open the file for the header part
1802  write(pfilename,'(a,i4.4,a,i4.4,a)') trim(base_filename),filenr,"p",mype,".vtu"
1803  open(qunit,file=pfilename,status='unknown',form='formatted')
1804  end if
1805  ! generate xml header
1806  write(qunit,'(a)')'<?xml version="1.0"?>'
1807  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
1808  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
1809  write(qunit,'(a)')' <UnstructuredGrid>'
1810  write(qunit,'(a)')'<FieldData>'
1811  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
1812  'NumberOfTuples="1" format="ascii">'
1813  write(qunit,*) real(global_time*time_convert_factor)
1814  write(qunit,'(a)')'</DataArray>'
1815  write(qunit,'(a)')'</FieldData>'
1816 
1817  call getheadernames(wnamei,xandwnamei,outfilehead)
1818 
1819  ! number of cells, number of corner points, per grid.
1820  nx^d=ixmhi^d-ixmlo^d+1;
1821  nxc^d=nx^d+1;
1822  nc={nx^d*}
1823  np={nxc^d*}
1824 
1825  ! Note: using the w_write, writelevel, writespshift
1826  ! we can clip parts of the grid away, select variables, levels etc.
1827  do level=levmin,levmax
1828  if (.not.writelevel(level)) cycle
1829  do morton_no=morton_start(mype),morton_stop(mype)
1830  igrid=sfc_to_igrid(morton_no)
1831  if (node(plevel_,igrid)/=level) cycle
1832  ! only output a grid when fully within clipped region selected
1833  ! by writespshift array
1834  conv_grid=({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
1835  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
1836  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})
1837  if (.not.conv_grid) cycle
1838  call calc_x(igrid,xc,xcc)
1839  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1840  ixc^l,ixcc^l,.true.)
1841  call write_vtk(qunit,ixg^ll,ixc^l,ixcc^l,igrid,nc,np,nx^d,nxc^d,&
1842  normconv,wnamei,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp)
1843  end do ! Morton_no loop
1844  end do ! level loop
1845 
1846  write(qunit,'(a)')' </UnstructuredGrid>'
1847  write(qunit,'(a)')'</VTKFile>'
1848  close(qunit)
1849 
1850  if (npe>1) then
1851  call mpi_barrier(icomm,ierrmpi)
1852  end if
1853 
1854  end subroutine punstructuredvtk_mpi
1855 
1856  subroutine unstructuredvtk_mpi(qunit)
1857  ! output for vtu format to paraview, non-binary version output
1858  ! parallel, uses calc_grid to compute nwauxio variables
1859  ! allows renormalizing using convert factors
1860  ! allows skipping of w_write selected variables
1861  ! implementation such that length of ASCII output is identical when
1862  ! run on 1 versus multiple CPUs (however, the order of the vtu pieces can differ)
1865  use mod_calculate_xw
1866 
1867  integer, intent(in) :: qunit
1868 
1869  double precision :: x_VTK(1:3)
1870  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP,xC_TMP_recv
1871  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP,xCC_TMP_recv
1872  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
1873  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
1874  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP,wC_TMP_recv
1875  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP,wCC_TMP_recv
1876  double precision, dimension(0:nw+nwauxio) :: normconv
1877  integer:: igrid,iigrid,level,ixC^L,ixCC^L
1878  integer:: NumGridsOnLevel(1:nlevelshi)
1879  integer :: nx^D,nxC^D,nodesonlevel,elemsonlevel,nc,np,ix^D
1880  integer :: filenr
1881  integer :: itag,ipe,Morton_no,siz_ind
1882  integer :: ind_send(4*^ND),ind_recv(4*^ND)
1883  integer :: levmin_recv,levmax_recv,level_recv,igrid_recv,ixrvC^L,ixrvCC^L
1884  integer, allocatable :: intstatus(:,:)
1885  logical :: fileopen,conv_grid,cond_grid_recv
1886  character(len=80):: filename
1887  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
1888  character(len=1024) :: outfilehead
1889 
1890  if(mype==0) then
1891  inquire(qunit,opened=fileopen)
1892  if(.not.fileopen)then
1893  ! generate filename
1894  filenr=snapshotini
1895  if (autoconvert) filenr=snapshotnext
1896  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".vtu"
1897  ! Open the file for the header part
1898  open(qunit,file=filename,status='unknown',form='formatted')
1899  end if
1900  ! generate xml header
1901  write(qunit,'(a)')'<?xml version="1.0"?>'
1902  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
1903  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
1904  write(qunit,'(a)')'<UnstructuredGrid>'
1905  write(qunit,'(a)')'<FieldData>'
1906  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
1907  'NumberOfTuples="1" format="ascii">'
1908  write(qunit,*) real(global_time*time_convert_factor)
1909  write(qunit,'(a)')'</DataArray>'
1910  write(qunit,'(a)')'</FieldData>'
1911  end if
1912 
1913  call getheadernames(wnamei,xandwnamei,outfilehead)
1914  ! number of cells, number of corner points, per grid.
1915  nx^d=ixmhi^d-ixmlo^d+1;
1916  nxc^d=nx^d+1;
1917  nc={nx^d*}
1918  np={nxc^d*}
1919  ! all slave processors send their minmal/maximal levels
1920  if (mype/=0) then
1921  if (morton_stop(mype)==0) call mpistop("nultag")
1922  itag=1000*morton_stop(mype)
1923  !print *,'ype,itag for levmin=',mype,itag,levmin
1924  call mpi_send(levmin,1,mpi_integer, 0,itag,icomm,ierrmpi)
1925  itag=2000*morton_stop(mype)
1926  !print *,'mype,itag for levmax=',mype,itag,levmax
1927  call mpi_send(levmax,1,mpi_integer, 0,itag,icomm,ierrmpi)
1928  end if
1929  ! Note: using the w_write, writelevel, writespshift
1930  ! we can clip parts of the grid away, select variables, levels etc.
1931  do level=levmin,levmax
1932  if (.not.writelevel(level)) cycle
1933  do morton_no=morton_start(mype),morton_stop(mype)
1934  igrid=sfc_to_igrid(morton_no)
1935  if (mype/=0)then
1936  itag=morton_no
1937  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
1938  itag=igrid
1939  call mpi_send(node(plevel_,igrid),1,mpi_integer, 0,itag,icomm,ierrmpi)
1940  end if
1941  if (node(plevel_,igrid)/=level) cycle
1942  ! only output a grid when fully within clipped region selected
1943  ! by writespshift array
1944  conv_grid=({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
1945  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
1946  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})
1947  if (mype/=0)then
1948  call mpi_send(conv_grid,1,mpi_logical,0,itag,icomm,ierrmpi)
1949  end if
1950  if (.not.conv_grid) cycle
1951  call calc_x(igrid,xc,xcc)
1952  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
1953  ixc^l,ixcc^l,.true.)
1954  if(mype/=0) then
1955  itag=morton_no
1956  ind_send=(/ ixc^l,ixcc^l /)
1957  siz_ind=4*^nd
1958  call mpi_send(ind_send,siz_ind,mpi_integer, 0,itag,icomm,ierrmpi)
1959  call mpi_send(normconv,nw+nwauxio+1,mpi_double_precision, 0,itag,icomm,ierrmpi)
1960  call mpi_send(wc_tmp,1,type_block_wc_io, 0,itag,icomm,ierrmpi)
1961  call mpi_send(xc_tmp,1,type_block_xc_io, 0,itag,icomm,ierrmpi)
1962  itag=igrid
1963  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
1964  call mpi_send(xcc_tmp,1,type_block_xcc_io, 0,itag,icomm,ierrmpi)
1965  else
1966  call write_vtk(qunit,ixg^ll,ixc^l,ixcc^l,igrid,nc,np,nx^d,nxc^d,&
1967  normconv,wnamei,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp)
1968  end if
1969  end do ! Morton_no loop
1970  end do ! level loop
1971 
1972  if(mype==0) then
1973  allocate(intstatus(mpi_status_size,1))
1974  if(npe>1)then
1975  do ipe=1,npe-1
1976  itag=1000*morton_stop(ipe)
1977  call mpi_recv(levmin_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1978  !!print *,'mype RECEIVES,itag for levmin=',mype,itag,levmin_recv
1979  itag=2000*morton_stop(ipe)
1980  call mpi_recv(levmax_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1981  !!print *,'mype RECEIVES itag for levmax=',mype,itag,levmax_recv
1982  do level=levmin_recv,levmax_recv
1983  if (.not.writelevel(level)) cycle
1984  do morton_no=morton_start(ipe),morton_stop(ipe)
1985  itag=morton_no
1986  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1987  itag=igrid_recv
1988  call mpi_recv(level_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1989  if (level_recv/=level) cycle
1990  call mpi_recv(cond_grid_recv,1,mpi_logical, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1991  if(.not.cond_grid_recv)cycle
1992  itag=morton_no
1993  siz_ind=4*^nd
1994  call mpi_recv(ind_recv,siz_ind, mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
1995  ixrvcmin^d=ind_recv(^d);ixrvcmax^d=ind_recv(^nd+^d);
1996  ixrvccmin^d=ind_recv(2*^nd+^d);ixrvccmax^d=ind_recv(3*^nd+^d);
1997  call mpi_recv(normconv,nw+nwauxio+1, mpi_double_precision,ipe,itag&
1998  ,icomm,intstatus(:,1),ierrmpi)
1999  call mpi_recv(wc_tmp_recv,1,type_block_wc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2000  call mpi_recv(xc_tmp_recv,1,type_block_xc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2001  itag=igrid_recv
2002  call mpi_recv(wcc_tmp_recv,1,type_block_wcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2003  call mpi_recv(xcc_tmp_recv,1,type_block_xcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2004  call write_vtk(qunit,ixg^ll,ixrvc^l,ixrvcc^l,igrid_recv,&
2005  nc,np,nx^d,nxc^d,normconv,wnamei,&
2006  xc_tmp_recv,xcc_tmp_recv,wc_tmp_recv,wcc_tmp_recv)
2007  end do ! Morton_no loop
2008  end do ! level loop
2009  end do ! processor loop
2010  end if ! multiple processors
2011  write(qunit,'(a)')'</UnstructuredGrid>'
2012  write(qunit,'(a)')'</VTKFile>'
2013  close(qunit)
2014  end if
2015  if (npe>1) then
2016  call mpi_barrier(icomm,ierrmpi)
2017  if(mype==0)deallocate(intstatus)
2018  end if
2019 
2020  end subroutine unstructuredvtk_mpi
2021 
2022  subroutine write_vtk(qunit,ixI^L,ixC^L,ixCC^L,igrid,nc,np,nx^D,nxC^D,&
2023  normconv,wnamei,xC,xCC,wC,wCC)
2025 
2026  integer, intent(in) :: qunit
2027  integer, intent(in) :: ixI^L,ixC^L,ixCC^L
2028  integer, intent(in) :: igrid,nc,np,nx^D,nxC^D
2029  double precision, intent(in) :: normconv(0:nw+nwauxio)
2030  character(len=name_len), intent(in):: wnamei(1:nw+nwauxio)
2031  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
2032  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
2033  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC
2034  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC
2035 
2036  double precision :: x_VTK(1:3)
2037  integer :: iw,ix^D,icel,VTK_type
2038 
2039  select case(convert_type)
2040  case('vtumpi','pvtumpi')
2041  ! we write out every grid as one VTK PIECE
2042  write(qunit,'(a,i7,a,i7,a)') &
2043  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
2044  write(qunit,'(a)')'<PointData>'
2045  do iw=1,nw+nwauxio
2046  if(iw<=nw) then
2047  if(.not.w_write(iw)) cycle
2048  end if
2049  write(qunit,'(a,a,a)')&
2050  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
2051  write(qunit,'(200(1pe14.6))') {(|}wc(ix^d,iw)*normconv(iw),{ix^d=ixcmin^d,ixcmax^d)}
2052  write(qunit,'(a)')'</DataArray>'
2053  end do
2054  write(qunit,'(a)')'</PointData>'
2055  write(qunit,'(a)')'<Points>'
2056  write(qunit,'(a)')'<DataArray type="Float32" NumberOfComponents="3" format="ascii">'
2057  ! write cell corner coordinates in a backward dimensional loop, always 3D output
2058  {do ix^db=ixcmin^db,ixcmax^db \}
2059  x_vtk(1:3)=zero;
2060  x_vtk(1:ndim)=xc(ix^d,1:ndim)*normconv(0);
2061  write(qunit,'(3(1pe14.6))') x_vtk
2062  {end do \}
2063  write(qunit,'(a)')'</DataArray>'
2064  write(qunit,'(a)')'</Points>'
2065 
2066  case('vtuCCmpi','pvtuCCmpi')
2067  ! we write out every grid as one VTK PIECE
2068  write(qunit,'(a,i7,a,i7,a)') &
2069  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
2070  write(qunit,'(a)')'<CellData>'
2071  do iw=1,nw+nwauxio
2072  if(iw<=nw) then
2073  if(.not.w_write(iw)) cycle
2074  end if
2075  write(qunit,'(a,a,a)')&
2076  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
2077  write(qunit,'(200(1pe14.6))') {(|}wcc(ix^d,iw)*normconv(iw),{ix^d=ixccmin^d,ixccmax^d)}
2078  write(qunit,'(a)')'</DataArray>'
2079  end do
2080  write(qunit,'(a)')'</CellData>'
2081  write(qunit,'(a)')'<Points>'
2082  write(qunit,'(a)')'<DataArray type="Float32" NumberOfComponents="3" format="ascii">'
2083  ! write cell corner coordinates in a backward dimensional loop, always 3D output
2084  {do ix^db=ixcmin^db,ixcmax^db \}
2085  x_vtk(1:3)=zero;
2086  x_vtk(1:ndim)=xc(ix^d,1:ndim)*normconv(0);
2087  write(qunit,'(3(1pe14.6))') x_vtk
2088  {end do \}
2089  write(qunit,'(a)')'</DataArray>'
2090  write(qunit,'(a)')'</Points>'
2091  end select
2092 
2093  write(qunit,'(a)')'<Cells>'
2094  ! connectivity part
2095  write(qunit,'(a)')'<DataArray type="Int32" Name="connectivity" format="ascii">'
2096  call save_connvtk(qunit,igrid)
2097  write(qunit,'(a)')'</DataArray>'
2098  ! offsets data array
2099  write(qunit,'(a)')'<DataArray type="Int32" Name="offsets" format="ascii">'
2100  do icel=1,nc
2101  write(qunit,'(i7)') icel*(2**^nd)
2102  end do
2103  write(qunit,'(a)')'</DataArray>'
2104  ! VTK cell type data array
2105  write(qunit,'(a)')'<DataArray type="Int32" Name="types" format="ascii">'
2106  ! VTK_LINE=3; VTK_PIXEL=8; VTK_VOXEL=11 -> vtk-syntax
2107  {^ifoned vtk_type=3 \}
2108  {^iftwod vtk_type=8 \}
2109  {^ifthreed vtk_type=11 \}
2110  do icel=1,nc
2111  write(qunit,'(i2)') vtk_type
2112  end do
2113  write(qunit,'(a)')'</DataArray>'
2114  write(qunit,'(a)')'</Cells>'
2115  write(qunit,'(a)')'</Piece>'
2116 
2117  end subroutine write_vtk
2118 
2119  subroutine write_vti(qunit,ixI^L,ixC^L,ixCC^L,ig^D,nx^D,&
2120  normconv,wnamei,wC,wCC)
2122 
2123  integer, intent(in) :: qunit
2124  integer, intent(in) :: ixI^L,ixC^L,ixCC^L
2125  integer, intent(in) :: ig^D,nx^D
2126  double precision, intent(in) :: normconv(0:nw+nwauxio)
2127  character(len=name_len), intent(in):: wnamei(1:nw+nwauxio)
2128  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC
2129  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC
2130 
2131  integer :: iw,ix^D
2132  integer :: extent(1:6)
2133 
2134  extent = 0
2135  {^d& extent(^d*2-1) = (ig^d-1) * nx^d; }
2136  {^d& extent(^d*2) = (ig^d) * nx^d; }
2137 
2138  select case(convert_type)
2139  case('vtimpi','pvtimpi')
2140  ! we write out every grid as one VTK PIECE
2141  write(qunit,'(a,6(i10),a)') &
2142  '<Piece Extent="',extent,'">'
2143  write(qunit,'(a)')'<PointData>'
2144  do iw=1,nw+nwauxio
2145  if(iw<=nw) then
2146  if(.not.w_write(iw)) cycle
2147  end if
2148  write(qunit,'(a,a,a)')&
2149  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
2150  write(qunit,'(200(1pe20.12))') {(|}wc(ix^d,iw)*normconv(iw),{ix^d=ixcmin^d,ixcmax^d)}
2151  write(qunit,'(a)')'</DataArray>'
2152  end do
2153  write(qunit,'(a)')'</PointData>'
2154  case('vtiCCmpi','pvtiCCmpi')
2155  ! we write out every grid as one VTK PIECE
2156  write(qunit,'(a,6(i10),a)') &
2157  '<Piece Extent="',extent,'">'
2158  write(qunit,'(a)')'<CellData>'
2159  do iw=1,nw+nwauxio
2160  if(iw<=nw) then
2161  if(.not.w_write(iw)) cycle
2162  end if
2163  write(qunit,'(a,a,a)')&
2164  '<DataArray type="Float64" Name="',trim(wnamei(iw)),'" format="ascii">'
2165  write(qunit,'(200(1pe20.12))') {(|}wcc(ix^d,iw)*normconv(iw),{ix^d=ixccmin^d,ixccmax^d)}
2166  write(qunit,'(a)')'</DataArray>'
2167  end do
2168  write(qunit,'(a)')'</CellData>'
2169  end select
2170 
2171  write(qunit,'(a)')'</Piece>'
2172 
2173  end subroutine write_vti
2174 
2175  subroutine write_pvtu(qunit)
2177  use mod_calculate_xw
2178 
2179  integer, intent(in) :: qunit
2180 
2181  integer :: filenr,iw,ipe,iscalars
2182  logical :: fileopen
2183  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio),outtype
2184  character(len=1024) :: outfilehead
2185  character(len=80) :: filename,pfilename
2186 
2187  select case(convert_type)
2188  case('pvtumpi','pvtuBmpi')
2189  outtype="PPointData"
2190  case('pvtuCCmpi','pvtuBCCmpi')
2191  outtype="PCellData"
2192  end select
2193  inquire(qunit,opened=fileopen)
2194  if(.not.fileopen)then
2195  ! generate filename
2196  filenr=snapshotini
2197  if (autoconvert) filenr=snapshotnext
2198  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".pvtu"
2199  ! Open the file
2200  open(qunit,file=filename,status='unknown',form='formatted')
2201  end if
2202 
2203  call getheadernames(wnamei,xandwnamei,outfilehead)
2204  ! Get the default selection:
2205  iscalars=1
2206  do iw=nw,1, -1
2207  if (w_write(iw)) iscalars=iw
2208  end do
2209  ! generate xml header
2210  write(qunit,'(a)')'<?xml version="1.0"?>'
2211  write(qunit,'(a)',advance='no') '<VTKFile type="PUnstructuredGrid"'
2212  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
2213  write(qunit,'(a)')' <PUnstructuredGrid GhostLevel="0">'
2214  ! Either celldata or pointdata:
2215  write(qunit,'(a,a,a,a,a)')&
2216  ' <',trim(outtype),' Scalars="',trim(wnamei(iscalars))//'">'
2217  do iw=1,nw
2218  if(.not.w_write(iw))cycle
2219  write(qunit,'(a,a,a)')&
2220  ' <PDataArray type="Float32" Name="',trim(wnamei(iw)),'"/>'
2221  end do
2222  do iw=nw+1,nw+nwauxio
2223  write(qunit,'(a,a,a)')&
2224  ' <PDataArray type="Float32" Name="',trim(wnamei(iw)),'"/>'
2225  end do
2226  write(qunit,'(a,a,a)')' </',trim(outtype),'>'
2227  write(qunit,'(a)')' <PPoints>'
2228  write(qunit,'(a)')' <PDataArray type="Float32" NumberOfComponents="3"/>'
2229  write(qunit,'(a)')' </PPoints>'
2230 
2231  do ipe=0,npe-1
2232  write(pfilename,'(a,i4.4,a,i4.4,a)') trim(base_filename(&
2233  index(base_filename, '/', back = .true.)+1:&
2234  len(base_filename))),filenr,"p",&
2235  ipe,".vtu"
2236  write(qunit,'(a,a,a)')' <Piece Source="',trim(pfilename),'"/>'
2237  end do
2238  write(qunit,'(a)')' </PUnstructuredGrid>'
2239  write(qunit,'(a)')'</VTKFile>'
2240  close(qunit)
2241 
2242  end subroutine write_pvtu
2243 
2244  subroutine tecplot_mpi(qunit)
2245  ! output for tecplot (ASCII format)
2246  ! parallel, uses calc_grid to compute nwauxio variables
2247  ! allows renormalizing using convert factors
2248  ! the current implementation is such that tecplotmpi and tecplotCCmpi will
2249  ! create different length output ASCII files when used on 1 versus multiple CPUs
2250  ! in fact, on 1 CPU, there will be as many zones as there are levels
2251  ! on multiple CPUs, there will be a number of zones up to the number of
2252  ! levels times the number of CPUs (can be less, when some level not on a CPU)
2255  use mod_calculate_xw
2256 
2257  integer, intent(in) :: qunit
2258 
2259  double precision :: x_TEC(ndim), w_TEC(nw+nwauxio)
2260  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP,xC_TMP_recv
2261  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP,xCC_TMP_recv
2262  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
2263  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
2264  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP,wC_TMP_recv
2265  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP,wCC_TMP_recv
2266  double precision, dimension(0:nw+nwauxio) :: normconv
2267  integer:: igrid,iigrid,level,igonlevel,iw,idim,ix^D
2268  integer:: NumGridsOnLevel(1:nlevelshi)
2269  integer :: nx^D,nxC^D,nodesonlevel,elemsonlevel,ixC^L,ixCC^L
2270  integer :: nodesonlevelmype,elemsonlevelmype
2271  integer :: nodes, elems
2272  integer, allocatable :: intstatus(:,:)
2273  integer :: itag,Morton_no,ipe,levmin_recv,levmax_recv,igrid_recv,level_recv
2274  integer :: ixrvC^L,ixrvCC^L
2275  integer :: ind_send(2*^ND),ind_recv(2*^ND),siz_ind,igonlevel_recv
2276  integer :: NumGridsOnLevel_mype(1:nlevelshi,0:npe-1)
2277  integer :: filenr
2278  logical :: fileopen,first
2279  character(len=80) :: filename
2280  character(len=1024) :: tecplothead
2281  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
2282  character(len=1024) :: outfilehead
2283 
2284  if(nw/=count(w_write(1:nw)))then
2285  if(mype==0) print *,'tecplot_mpi does not use w_write=F'
2286  call mpistop('w_write, tecplot')
2287  end if
2288 
2289  if(nocartesian)then
2290  if(mype==0) print *,'tecplot_mpi with nocartesian'
2291  end if
2292 
2293  master_cpu_open : if (mype == 0) then
2294  inquire(qunit,opened=fileopen)
2295  if (.not.fileopen) then
2296  ! generate filename
2297  filenr=snapshotini
2298  if (autoconvert) filenr=snapshotnext
2299  write(filename,'(a,i4.4,a)') trim(base_filename),filenr,".plt"
2300  open(qunit,file=filename,status='unknown')
2301  end if
2302  call getheadernames(wnamei,xandwnamei,outfilehead)
2303  write(tecplothead,'(a)') "VARIABLES = "//trim(outfilehead)
2304  write(qunit,'(a)') tecplothead(1:len_trim(tecplothead))
2305  end if master_cpu_open
2306 
2307  ! determine overall number of grids per level, and the same info per CPU
2308  numgridsonlevel(1:nlevelshi)=0
2309  do level=levmin,levmax
2310  numgridsonlevel(level)=0
2311  do morton_no=morton_start(mype),morton_stop(mype)
2312  igrid = sfc_to_igrid(morton_no)
2313  if (node(plevel_,igrid)/=level) cycle
2314  numgridsonlevel(level)=numgridsonlevel(level)+1
2315  end do
2316  numgridsonlevel_mype(level,0:npe-1)=0
2317  numgridsonlevel_mype(level,mype) = numgridsonlevel(level)
2318  call mpi_allreduce(mpi_in_place,numgridsonlevel_mype(level,0:npe-1),npe,mpi_integer,&
2319  mpi_max,icomm,ierrmpi)
2320  call mpi_allreduce(mpi_in_place,numgridsonlevel(level),1,mpi_integer,mpi_sum, &
2321  icomm,ierrmpi)
2322  end do
2323 
2324  nx^d=ixmhi^d-ixmlo^d+1;
2325  nxc^d=nx^d+1;
2326 
2327  if(mype==0.and.npe>1) allocate(intstatus(mpi_status_size,1))
2328 
2329  {^ifoned
2330  if(convert_type=='teclinempi') then
2331  nodes=0
2332  elems=0
2333  do level=levmin,levmax
2334  nodes=nodes + numgridsonlevel(level)*{nxc^d*}
2335  elems=elems + numgridsonlevel(level)*{nx^d*}
2336  end do
2337 
2338  if (mype==0) write(qunit,"(a,i7,a,1pe12.5,a)") &
2339  'ZONE T="all levels", I=',elems, &
2340  ', SOLUTIONTIME=',global_time*time_convert_factor,', F=POINT'
2341 
2342  igonlevel=0
2343  do morton_no=morton_start(mype),morton_stop(mype)
2344  igrid = sfc_to_igrid(morton_no)
2345  call calc_x(igrid,xc,xcc)
2346  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,ixc^l,ixcc^l,.true.)
2347  if (mype==0) then
2348  {do ix^db=ixccmin^db,ixccmax^db\}
2349  x_tec(1:ndim)=xcc_tmp(ix^d,1:ndim)*normconv(0)
2350  w_tec(1:nw+nwauxio)=wcc_tmp(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
2351  write(qunit,fmt="(100(e14.6))") x_tec, w_tec
2352  {end do\}
2353  else if (mype/=0) then
2354  itag=morton_no
2355  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
2356  call mpi_send(normconv,nw+nwauxio+1,mpi_double_precision,0,itag,icomm,ierrmpi)
2357  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
2358  call mpi_send(xcc_tmp,1,type_block_xcc_io, 0,itag,icomm,ierrmpi)
2359  end if
2360  end do
2361  if(mype==0) then
2362  do ipe=1,npe-1
2363  do morton_no=morton_start(ipe),morton_stop(ipe)
2364  itag=morton_no
2365  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2366  call mpi_recv(normconv,nw+nwauxio+1, mpi_double_precision,ipe,&
2367  itag,icomm,intstatus(:,1),ierrmpi)
2368  call mpi_recv(wcc_tmp_recv,1,type_block_wcc_io, ipe,itag,&
2369  icomm,intstatus(:,1),ierrmpi)
2370  call mpi_recv(xcc_tmp_recv,1,type_block_xcc_io, ipe,itag,&
2371  icomm,intstatus(:,1),ierrmpi)
2372  {do ix^db=ixccmin^db,ixccmax^db\}
2373  x_tec(1:ndim)=xcc_tmp_recv(ix^d,1:ndim)*normconv(0)
2374  w_tec(1:nw+nwauxio)=wcc_tmp_recv(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
2375  write(qunit,fmt="(100(e14.6))") x_tec, w_tec
2376  {end do\}
2377  end do
2378  end do
2379  close(qunit)
2380  end if
2381  else
2382  }
2383  if(mype/=0) then
2384  itag=1000*morton_stop(mype)
2385  call mpi_send(levmin,1,mpi_integer, 0,itag,icomm,ierrmpi)
2386  itag=2000*morton_stop(mype)
2387  call mpi_send(levmax,1,mpi_integer, 0,itag,icomm,ierrmpi)
2388  end if
2389 
2390  do level=levmin,levmax
2391  nodesonlevelmype=numgridsonlevel_mype(level,mype)*{nxc^d*}
2392  elemsonlevelmype=numgridsonlevel_mype(level,mype)*{nx^d*}
2393  nodesonlevel=numgridsonlevel(level)*{nxc^d*}
2394  elemsonlevel=numgridsonlevel(level)*{nx^d*}
2395  ! for all tecplot variants coded up here, we let the TECPLOT ZONES coincide
2396  ! with the AMR grid LEVEL. Other options would be
2397  ! let each grid define a zone: inefficient for TECPLOT internal workings
2398  ! hence not implemented
2399  ! let entire octree define 1 zone: no difference in interpolation
2400  ! properties across TECPLOT zones detected as yet, hence not done
2401  select case(convert_type)
2402  case('tecplotmpi')
2403  ! in this option, we store the corner coordinates, as well as the corner
2404  ! values of all variables (obtained by averaging). This allows POINT packaging,
2405  ! and thus we can save full grid info by using one call to calc_grid
2406  if (mype==0.and.(nodesonlevelmype>0.and.elemsonlevelmype>0))&
2407  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,a)") &
2408  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2409  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=POINT, ZONETYPE=', &
2410  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2411  do morton_no=morton_start(mype),morton_stop(mype)
2412  igrid = sfc_to_igrid(morton_no)
2413  if (mype/=0)then
2414  itag=morton_no
2415  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
2416  itag=igrid
2417  call mpi_send(node(plevel_,igrid),1,mpi_integer, 0,itag,icomm,ierrmpi)
2418  end if
2419  if (node(plevel_,igrid)/=level) cycle
2420  call calc_x(igrid,xc,xcc)
2421  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
2422  ixc^l,ixcc^l,.true.)
2423  if (mype/=0) then
2424  itag=morton_no
2425  ind_send=(/ ixc^l /)
2426  siz_ind=2*^nd
2427  call mpi_send(ind_send,siz_ind, mpi_integer, 0,itag,icomm,ierrmpi)
2428  call mpi_send(normconv,nw+nwauxio+1,mpi_double_precision, 0,itag,icomm,ierrmpi)
2429 
2430  call mpi_send(wc_tmp,1,type_block_wc_io, 0,itag,icomm,ierrmpi)
2431  call mpi_send(xc_tmp,1,type_block_xc_io, 0,itag,icomm,ierrmpi)
2432  else
2433  {do ix^db=ixcmin^db,ixcmax^db\}
2434  x_tec(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0)
2435  w_tec(1:nw+nwauxio)=wc_tmp(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
2436  write(qunit,fmt="(100(e14.6))") x_tec, w_tec
2437  {end do\}
2438  end if
2439  end do
2440  case('tecplotCCmpi')
2441  ! in this option, we store the corner coordinates, and the cell center
2442  ! values of all variables. Due to this mix of corner/cell center, we must
2443  ! use BLOCK packaging, and thus we have enormous overhead by using
2444  ! calc_grid repeatedly to merely fill values of cell corner coordinates
2445  ! and cell center values per dimension, per variable
2446  if(ndim+nw+nwauxio>99) call mpistop("adjust format specification in writeout")
2447  if(nw+nwauxio==1)then
2448  ! to make tecplot happy: avoid [ndim+1-ndim+1] in varlocation varset
2449  ! and just set [ndim+1]
2450  if (mype==0.and.(nodesonlevelmype>0.and.elemsonlevelmype>0))&
2451  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,a)") &
2452  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2453  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2454  ndim+1,']=CELLCENTERED), ZONETYPE=', &
2455  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2456  else
2457  if(ndim+nw+nwauxio<10) then
2458  ! difference only in length of integer format specification for ndim+nw+nwauxio
2459  if (mype==0.and.(nodesonlevelmype>0.and.elemsonlevelmype>0))&
2460  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i1,a,a)") &
2461  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2462  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2463  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
2464  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2465  else
2466  if (mype==0.and.(nodesonlevelmype>0.and.elemsonlevelmype>0))&
2467  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i2,a,a)") &
2468  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2469  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2470  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
2471  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2472  end if
2473  end if
2474 
2475  do idim=1,ndim
2476  first=(idim==1)
2477  do morton_no=morton_start(mype),morton_stop(mype)
2478  igrid = sfc_to_igrid(morton_no)
2479  if (mype/=0)then
2480  itag=morton_no*idim
2481  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
2482  itag=igrid*idim
2483  call mpi_send(node(plevel_,igrid),1,mpi_integer, 0,itag,icomm,ierrmpi)
2484  end if
2485  if (node(plevel_,igrid)/=level) cycle
2486  call calc_x(igrid,xc,xcc)
2487  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
2488  ixc^l,ixcc^l,first)
2489  if (mype/=0)then
2490  ind_send=(/ ixc^l /)
2491  siz_ind=2*^nd
2492  itag=igrid*idim
2493  call mpi_send(ind_send,siz_ind, mpi_integer, 0,itag,icomm,ierrmpi)
2494  call mpi_send(normconv,nw+nwauxio+1,mpi_double_precision, 0,itag,icomm,ierrmpi)
2495  call mpi_send(xc_tmp,1,type_block_xc_io, 0,itag,icomm,ierrmpi)
2496  else
2497  write(qunit,fmt="(100(e14.6))") xc_tmp(ixc^s,idim)*normconv(0)
2498  end if
2499  end do
2500  end do
2501  do iw=1,nw+nwauxio
2502  do morton_no=morton_start(mype),morton_stop(mype)
2503  igrid = sfc_to_igrid(morton_no)
2504  if(mype/=0)then
2505  itag=morton_no*(ndim+iw)
2506  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
2507  itag=igrid*(ndim+iw)
2508  call mpi_send(node(plevel_,igrid),1,mpi_integer, 0,itag,icomm,ierrmpi)
2509  end if
2510  if (node(plevel_,igrid)/=level) cycle
2511  call calc_x(igrid,xc,xcc)
2512  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
2513  ixc^l,ixcc^l,.true.)
2514  if(mype/=0)then
2515  ind_send=(/ ixcc^l /)
2516  siz_ind=2*^nd
2517  itag=igrid*(ndim+iw)
2518  call mpi_send(ind_send,siz_ind, mpi_integer, 0,itag,icomm,ierrmpi)
2519  call mpi_send(normconv,nw+nwauxio+1,mpi_double_precision, 0,itag,icomm,ierrmpi)
2520  call mpi_send(wcc_tmp,1,type_block_wcc_io, 0,itag,icomm,ierrmpi)
2521  else
2522  write(qunit,fmt="(100(e14.6))") wcc_tmp(ixcc^s,iw)*normconv(iw)
2523  end if
2524  end do
2525  end do
2526  case default
2527  call mpistop('no such tecplot type')
2528  end select
2529 
2530  igonlevel=0
2531  do morton_no=morton_start(mype),morton_stop(mype)
2532  igrid = sfc_to_igrid(morton_no)
2533  if(mype/=0)then
2534  itag=morton_no
2535  call mpi_send(igrid,1,mpi_integer, 0,itag,icomm,ierrmpi)
2536  itag=igrid
2537  call mpi_send(node(plevel_,igrid),1,mpi_integer, 0,itag,icomm,ierrmpi)
2538  end if
2539  if(node(plevel_,igrid)/=level) cycle
2540  igonlevel=igonlevel+1
2541  if(mype/=0)then
2542  itag=igrid
2543  call mpi_send(igonlevel,1,mpi_integer, 0,itag,icomm,ierrmpi)
2544  end if
2545  if(mype==0)then
2546  call save_conntec(qunit,igrid,igonlevel)
2547  end if
2548  end do
2549  end do
2550 
2551  if(mype==0 .and.npe>1) then
2552  do ipe=1,npe-1
2553  itag=1000*morton_stop(ipe)
2554  call mpi_recv(levmin_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2555  itag=2000*morton_stop(ipe)
2556  call mpi_recv(levmax_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2557  do level=levmin_recv,levmax_recv
2558  nodesonlevelmype=numgridsonlevel_mype(level,ipe)*{nxc^d*}
2559  elemsonlevelmype=numgridsonlevel_mype(level,ipe)*{nx^d*}
2560  nodesonlevel=numgridsonlevel(level)*{nxc^d*}
2561  elemsonlevel=numgridsonlevel(level)*{nx^d*}
2562  select case(convert_type)
2563  case('tecplotmpi')
2564  ! in this option, we store the corner coordinates, as well as the corner
2565  ! values of all variables (obtained by averaging). This allows POINT packaging,
2566  ! and thus we can save full grid info by using one call to calc_grid
2567  if(nodesonlevelmype>0.and.elemsonlevelmype>0) &
2568  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,a)") &
2569  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2570  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=POINT, ZONETYPE=', &
2571  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2572  do morton_no=morton_start(ipe),morton_stop(ipe)
2573  itag=morton_no
2574  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2575  itag=igrid_recv
2576  call mpi_recv(level_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2577  if (level_recv/=level) cycle
2578  itag=morton_no
2579  siz_ind=2*^nd
2580  call mpi_recv(ind_recv,siz_ind, mpi_integer, ipe,itag,&
2581  icomm,intstatus(:,1),ierrmpi)
2582  ixrvcmin^d=ind_recv(^d);ixrvcmax^d=ind_recv(^nd+^d);
2583  call mpi_recv(normconv,nw+nwauxio+1, mpi_double_precision,ipe,itag&
2584  ,icomm,intstatus(:,1),ierrmpi)
2585  call mpi_recv(wc_tmp_recv,1,type_block_wc_io, ipe,itag,&
2586  icomm,intstatus(:,1),ierrmpi)
2587  call mpi_recv(xc_tmp_recv,1,type_block_xc_io, ipe,itag,&
2588  icomm,intstatus(:,1),ierrmpi)
2589  {do ix^db=ixrvcmin^db,ixrvcmax^db\}
2590  x_tec(1:ndim)=xc_tmp_recv(ix^d,1:ndim)*normconv(0)
2591  w_tec(1:nw+nwauxio)=wc_tmp_recv(ix^d,1:nw+nwauxio)*normconv(1:nw+nwauxio)
2592  write(qunit,fmt="(100(e14.6))") x_tec, w_tec
2593  {end do\}
2594  end do
2595  case('tecplotCCmpi')
2596  ! in this option, we store the corner coordinates, and the cell center
2597  ! values of all variables. Due to this mix of corner/cell center, we must
2598  ! use BLOCK packaging, and thus we have enormous overhead by using
2599  ! calc_grid repeatedly to merely fill values of cell corner coordinates
2600  ! and cell center values per dimension, per variable
2601  if(ndim+nw+nwauxio>99) call mpistop("adjust format specification in writeout")
2602  if(nw+nwauxio==1)then
2603  ! to make tecplot happy: avoid [ndim+1-ndim+1] in varlocation varset
2604  ! and just set [ndim+1]
2605  if(nodesonlevelmype>0.and.elemsonlevelmype>0) &
2606  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,a)") &
2607  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2608  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2609  ndim+1,']=CELLCENTERED), ZONETYPE=', &
2610  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2611  else
2612  if(ndim+nw+nwauxio<10) then
2613  ! difference only in length of integer format specification for ndim+nw+nwauxio
2614  if(nodesonlevelmype>0.and.elemsonlevelmype>0) &
2615  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i1,a,a)") &
2616  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2617  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2618  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
2619  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2620  else
2621  if(nodesonlevelmype>0.and.elemsonlevelmype>0) &
2622  write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i2,a,a)") &
2623  'ZONE T="',level,'"',', N=',nodesonlevelmype,', E=',elemsonlevelmype, &
2624  ', SOLUTIONTIME=',global_time*time_convert_factor,', DATAPACKING=BLOCK, VARLOCATION=([', &
2625  ndim+1,'-',ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', &
2626  {^ifoned 'FELINESEG'}{^iftwod 'FEQUADRILATERAL'}{^ifthreed 'FEBRICK'}
2627  end if
2628  end if
2629 
2630  do idim=1,ndim
2631  do morton_no=morton_start(ipe),morton_stop(ipe)
2632  itag=morton_no*idim
2633  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2634  itag=igrid_recv*idim
2635  call mpi_recv(level_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2636  if (level_recv/=level) cycle
2637  siz_ind=2*^nd
2638  itag=igrid_recv*idim
2639  call mpi_recv(ind_recv,siz_ind, mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2640  ixrvcmin^d=ind_recv(^d);ixrvcmax^d=ind_recv(^nd+^d);
2641  call mpi_recv(normconv,nw+nwauxio+1, mpi_double_precision,ipe,itag&
2642  ,icomm,intstatus(:,1),ierrmpi)
2643  call mpi_recv(xc_tmp_recv,1,type_block_xc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2644  write(qunit,fmt="(100(e14.6))") xc_tmp_recv(ixrvc^s,idim)*normconv(0)
2645  end do
2646  end do
2647  do iw=1,nw+nwauxio
2648  do morton_no=morton_start(ipe),morton_stop(ipe)
2649  itag=morton_no*(ndim+iw)
2650  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2651  itag=igrid_recv*(ndim+iw)
2652  call mpi_recv(level_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2653  if (level_recv/=level) cycle
2654  siz_ind=2*^nd
2655  itag=igrid_recv*(ndim+iw)
2656  call mpi_recv(ind_recv,siz_ind, mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2657  ixrvccmin^d=ind_recv(^d);ixrvccmax^d=ind_recv(^nd+^d);
2658  call mpi_recv(normconv,nw+nwauxio+1, mpi_double_precision,ipe,itag&
2659  ,icomm,intstatus(:,1),ierrmpi)
2660  call mpi_recv(wcc_tmp_recv,1,type_block_wcc_io, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2661  write(qunit,fmt="(100(e14.6))") wcc_tmp_recv(ixrvcc^s,iw)*normconv(iw)
2662  end do
2663  end do
2664  case default
2665  call mpistop('no such tecplot type')
2666  end select
2667 
2668  do morton_no=morton_start(ipe),morton_stop(ipe)
2669  itag=morton_no
2670  call mpi_recv(igrid_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2671  itag=igrid_recv
2672  call mpi_recv(level_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2673  if (level_recv/=level) cycle
2674  itag=igrid_recv
2675  call mpi_recv(igonlevel_recv,1,mpi_integer, ipe,itag,icomm,intstatus(:,1),ierrmpi)
2676  call save_conntec(qunit,igrid_recv,igonlevel_recv)
2677  end do ! morton loop
2678  end do ! level loop
2679  end do ! ipe loop
2680  end if ! mype=0 if
2681  {^ifoned endif}
2682 
2683  if (npe>1) then
2684  call mpi_barrier(icomm,ierrmpi)
2685  if(mype==0)deallocate(intstatus)
2686  end if
2687 
2688  end subroutine tecplot_mpi
2689 
2690  subroutine punstructuredvtkb_mpi(qunit)
2691  ! Write one pvtu and vtu files for each processor
2692  ! Otherwise like unstructuredvtk_mpi
2693  ! output for vtu format to paraview, binary version output
2694  ! uses calc_grid to compute nwauxio variables
2695  ! allows renormalizing using convert factors
2698  use mod_calculate_xw
2699 
2700  integer, intent(in) :: qunit
2701 
2702  double precision :: x_VTK(1:3)
2703  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC_TMP
2704  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC_TMP
2705  double precision, dimension(ixMlo^D-1:ixMhi^D,ndim) :: xC
2706  double precision, dimension(ixMlo^D:ixMhi^D,ndim) :: xCC
2707  double precision, dimension(ixMlo^D-1:ixMhi^D,nw+nwauxio) :: wC_TMP
2708  double precision, dimension(ixMlo^D:ixMhi^D,nw+nwauxio) :: wCC_TMP
2709  double precision :: normconv(0:nw+nwauxio)
2710  integer*8 :: offset
2711  integer :: igrid,iigrid,level,igonlevel,icel,ixC^L,ixCC^L,Morton_no
2712  integer :: NumGridsOnLevel(1:nlevelshi)
2713  integer :: nx^D,nxC^D,nodesonlevel,elemsonlevel,nc,np,VTK_type,ix^D
2714  integer:: recsep,k,iw,filenr
2715  integer:: length,lengthcc,offset_points,offset_cells, &
2716  length_coords,length_conn,length_offsets
2717  logical :: fileopen
2718  character:: buf
2719  character(len=6):: bufform
2720  character(len=80) :: pfilename
2721  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:ndim+nw+nwauxio)
2722  character(len=1024) :: outfilehead
2723 
2724  ! Write pvtu-file:
2725  if (mype==0) then
2726  call write_pvtu(qunit)
2727  end if
2728  ! Now write the Source files:
2729  inquire(qunit,opened=fileopen)
2730  if(.not.fileopen)then
2731  ! generate filename
2732  filenr=snapshotnext-1
2733  if (autoconvert) filenr=snapshotnext
2734  ! Open the file for the header part
2735  write(pfilename,'(a,i4.4,a,i4.4,a)') trim(base_filename),filenr,"p",mype,".vtu"
2736  open(qunit,file=pfilename,status='unknown',form='formatted')
2737  end if
2738  ! generate xml header
2739  write(qunit,'(a)')'<?xml version="1.0"?>'
2740  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
2741  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
2742  write(qunit,'(a)')' <UnstructuredGrid>'
2743  write(qunit,'(a)')'<FieldData>'
2744  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
2745  'NumberOfTuples="1" format="ascii">'
2746  write(qunit,*) real(global_time*time_convert_factor)
2747  write(qunit,'(a)')'</DataArray>'
2748  write(qunit,'(a)')'</FieldData>'
2749  offset=0
2750  recsep=4
2751 
2752  call getheadernames(wnamei,xandwnamei,outfilehead)
2753 
2754  ! number of cells, number of corner points, per grid.
2755  nx^d=ixmhi^d-ixmlo^d+1;
2756  nxc^d=nx^d+1;
2757  nc={nx^d*}
2758  np={nxc^d*}
2759 
2760  length=np*size_real
2761  lengthcc=nc*size_real
2762 
2763  length_coords=3*length
2764  length_conn=2**^nd*size_int*nc
2765  length_offsets=nc*size_int
2766 
2767  ! Note: using the w_write, writelevel, writespshift
2768  ! we can clip parts of the grid away, select variables, levels etc.
2769  do level=levmin,levmax
2770  if (writelevel(level)) then
2771  do morton_no=morton_start(mype),morton_stop(mype)
2772  igrid=sfc_to_igrid(morton_no)
2773  if (node(plevel_,igrid)/=level) cycle
2774  ! only output a grid when fully within clipped region selected
2775  ! by writespshift array
2776  if (({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
2777  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
2778  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
2779  select case(convert_type)
2780  case('pvtuBmpi')
2781  ! we write out every grid as one VTK PIECE
2782  write(qunit,'(a,i7,a,i7,a)') &
2783  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
2784  write(qunit,'(a)')'<PointData>'
2785  do iw=1,nw
2786  if(.not.w_write(iw))cycle
2787 
2788  write(qunit,'(a,a,a,i16,a)')&
2789  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
2790  '" format="appended" offset="',offset,'">'
2791  write(qunit,'(a)')'</DataArray>'
2792  offset=offset+length+size_int
2793  enddo
2794  do iw=nw+1,nw+nwauxio
2795 
2796  write(qunit,'(a,a,a,i16,a)')&
2797  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
2798  '" format="appended" offset="',offset,'">'
2799  write(qunit,'(a)')'</DataArray>'
2800  offset=offset+length+size_int
2801  enddo
2802  write(qunit,'(a)')'</PointData>'
2803 
2804  write(qunit,'(a)')'<Points>'
2805  write(qunit,'(a,i16,a)') &
2806  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
2807  ! write cell corner coordinates in a backward dimensional loop, always 3D output
2808  offset=offset+length_coords+size_int
2809  write(qunit,'(a)')'</Points>'
2810  case('pvtuBCCmpi')
2811  ! we write out every grid as one VTK PIECE
2812  write(qunit,'(a,i7,a,i7,a)') &
2813  '<Piece NumberOfPoints="',np,'" NumberOfCells="',nc,'">'
2814  write(qunit,'(a)')'<CellData>'
2815  do iw=1,nw
2816  if(.not.w_write(iw))cycle
2817 
2818  write(qunit,'(a,a,a,i16,a)')&
2819  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
2820  '" format="appended" offset="',offset,'">'
2821  write(qunit,'(a)')'</DataArray>'
2822  offset=offset+lengthcc+size_int
2823  enddo
2824  do iw=nw+1,nw+nwauxio
2825 
2826  write(qunit,'(a,a,a,i16,a)')&
2827  '<DataArray type="Float32" Name="',trim(wnamei(iw)), &
2828  '" format="appended" offset="',offset,'">'
2829  write(qunit,'(a)')'</DataArray>'
2830  offset=offset+lengthcc+size_int
2831  enddo
2832  write(qunit,'(a)')'</CellData>'
2833  write(qunit,'(a)')'<Points>'
2834  write(qunit,'(a,i16,a)') &
2835  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',offset,'"/>'
2836  ! write cell corner coordinates in a backward dimensional loop, always 3D output
2837  offset=offset+length_coords+size_int
2838  write(qunit,'(a)')'</Points>'
2839  end select
2840  write(qunit,'(a)')'<Cells>'
2841  ! connectivity part
2842  write(qunit,'(a,i16,a)')&
2843  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',offset,'"/>'
2844  offset=offset+length_conn+size_int
2845  ! offsets data array
2846  write(qunit,'(a,i16,a)') &
2847  '<DataArray type="Int32" Name="offsets" format="appended" offset="',offset,'"/>'
2848  offset=offset+length_offsets+size_int
2849  ! VTK cell type data array
2850  write(qunit,'(a,i16,a)') &
2851  '<DataArray type="Int32" Name="types" format="appended" offset="',offset,'"/>'
2852  offset=offset+size_int+nc*size_int
2853  write(qunit,'(a)')'</Cells>'
2854  write(qunit,'(a)')'</Piece>'
2855  end if
2856  end do
2857  end if
2858  end do
2859 
2860  write(qunit,'(a)')'</UnstructuredGrid>'
2861  write(qunit,'(a)')'<AppendedData encoding="raw">'
2862  close(qunit)
2863  ! next to make gfortran compiler happy, as it does not know
2864  ! form='binary' and produces error on compilation
2865  !bufform='binary'
2866  !open(qunit,file=pfilename,form=bufform,position='append')
2867  !This should in principle do also for gfortran (tested with gfortran 4.6.0 and Intel 11.1):
2868  open(qunit,file=pfilename,access='stream',form='unformatted',position='append')
2869  buf='_'
2870  write(qunit) trim(buf)
2871 
2872  do level=levmin,levmax
2873  if (writelevel(level)) then
2874  do morton_no=morton_start(mype),morton_stop(mype)
2875  igrid=sfc_to_igrid(morton_no)
2876  if (node(plevel_,igrid)/=level) cycle
2877  ! only output a grid when fully within clipped region selected
2878  ! by writespshift array
2879  if (({rnode(rpxmin^d_,igrid)>=xprobmin^d+(xprobmax^d-xprobmin^d)&
2880  *writespshift(^d,1)|.and.}).and.({rnode(rpxmax^d_,igrid)&
2881  <=xprobmax^d-(xprobmax^d-xprobmin^d)*writespshift(^d,2)|.and.})) then
2882  call calc_x(igrid,xc,xcc)
2883  call calc_grid(qunit,igrid,xc,xcc,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
2884  ixc^l,ixcc^l,.true.)
2885  do iw=1,nw
2886  if(.not.w_write(iw))cycle
2887  select case(convert_type)
2888  case('pvtuBmpi')
2889  write(qunit) length
2890  write(qunit) {(|}real(wc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixcmin^d,ixcmax^d)}
2891  case('pvtuBCCmpi')
2892  write(qunit) lengthcc
2893  write(qunit) {(|}real(wcc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixccmin^d,ixccmax^d)}
2894  end select
2895  enddo
2896  do iw=nw+1,nw+nwauxio
2897  select case(convert_type)
2898  case('pvtuBmpi')
2899  write(qunit) length
2900  write(qunit) {(|}real(wc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixcmin^d,ixcmax^d)}
2901  case('pvtuBCCmpi')
2902  write(qunit) lengthcc
2903  write(qunit) {(|}real(wcc_tmp(ix^d,iw)*normconv(iw)),{ix^d=ixccmin^d,ixccmax^d)}
2904  end select
2905  enddo
2906  write(qunit) length_coords
2907  {do ix^db=ixcmin^db,ixcmax^db \}
2908  x_vtk(1:3)=zero;
2909  x_vtk(1:ndim)=xc_tmp(ix^d,1:ndim)*normconv(0);
2910  do k=1,3
2911  write(qunit) real(x_vtk(k))
2912  end do
2913  {end do \}
2914  write(qunit) length_conn
2915  {do ix^db=1,nx^db\}
2916  {^ifoned write(qunit)ix1-1,ix1 \}
2917  {^iftwod
2918  write(qunit)(ix2-1)*nxc1+ix1-1, &
2919  (ix2-1)*nxc1+ix1,ix2*nxc1+ix1-1,ix2*nxc1+ix1
2920  \}
2921  {^ifthreed
2922  write(qunit)&
2923  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
2924  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
2925  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
2926  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
2927  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
2928  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
2929  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
2930  ix3*nxc2*nxc1+ ix2*nxc1+ix1
2931  \}
2932  {end do\}
2933  write(qunit) length_offsets
2934  do icel=1,nc
2935  write(qunit) icel*(2**^nd)
2936  end do
2937  {^ifoned vtk_type=3 \}
2938  {^iftwod vtk_type=8 \}
2939  {^ifthreed vtk_type=11 \}
2940  write(qunit) size_int*nc
2941  do icel=1,nc
2942  write(qunit) vtk_type
2943  end do
2944  end if
2945  end do
2946  end if
2947  end do
2948 
2949  close(qunit)
2950  open(qunit,file=pfilename,status='unknown',form='formatted',position='append')
2951  write(qunit,'(a)')'</AppendedData>'
2952  write(qunit,'(a)')'</VTKFile>'
2953  close(qunit)
2954 
2955  end subroutine punstructuredvtkb_mpi
2956  {^iftwod
2957  ! subroutines to convert 2.5D data to 3D data
2958  subroutine unstructuredvtkb23(qunit)
2959  ! output for vtu format to paraview, binary version output
2960  ! not parallel, uses calc_grid to compute nwauxio variables
2962  use mod_physics
2963  use mod_calculate_xw
2964 
2965  integer, intent(in) :: qunit
2966 
2967  double precision :: x_VTK(1:3)
2968  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,3) :: xC_TMP
2969  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,& 3) :: xCC_TMP
2970  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,nw+nwauxio) :: wC_TMP
2971  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,nw& +nwauxio) :: wCC_TMP
2972  double precision, dimension(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1,1:nw& +nwauxio) :: w
2973  double precision :: normconv(0:nw+nwauxio)
2974  double precision :: zlength
2975  double precision ::d3grid,zlengsc,zgridsc
2976  integer*8 :: offset
2977  integer:: igrid,iigrid,level,igonlevel,icel,ixCmin1,ixCmin2,&
2978  ixCmin3,ixCmax1,ixCmax2,ixCmax3,ixCCmin1,ixCCmin2,ixCCmin3,ixCCmax1,&
2979  ixCCmax2,ixCCmax3
2980  integer:: NumGridsOnLevel(1:nlevelshi)
2981  integer :: nx1,nx2,nx3,nxC1,nxC2,nxC3,nodesonlevel,elemsonlevel,nc,np,&
2982  VTK_type,ix1,ix2,ix3
2983  integer :: size_length,recsep,k,iw
2984  integer :: length,lengthcc,offset_points,offset_cells, length_coords,&
2985  length_conn,length_offsets
2986  integer :: i3grid,n3grid
2987  logical :: fileopen
2988  character:: buffer
2989  character(len=6):: bufform
2990  character(len=80):: filename
2991  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:3+nw+nwauxio)
2992  character(len=1024) :: outfilehead
2993 
2994  if(npe>1)then
2995  if(mype==0) print *,'unstructuredvtkB23 not parallel, use vtumpi'
2996  call mpistop('npe>1, unstructuredvtkB23')
2997  end if
2998 
2999  offset=0
3000  recsep=4
3001  size_length=4
3002  inquire(qunit,opened=fileopen)
3003  if(.not.fileopen)then
3004  ! generate filename
3005  write(filename,'(a,a,i4.4,a)') trim(base_filename),"3D",snapshotini,".vtu"
3006  ! Open the file for the header part
3007  open(qunit,file=filename,status='replace')
3008  endif
3009  call getheadernames(wnamei,xandwnamei,outfilehead)
3010  ! generate xml header
3011  write(qunit,'(a)')'<?xml version="1.0"?>'
3012  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
3013  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
3014  write(qunit,'(a)')'<UnstructuredGrid>'
3015  write(qunit,'(a)')'<FieldData>'
3016  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
3017  'NumberOfTuples="1" format="ascii">'
3018  write(qunit,'(f10.2)') real(global_time*time_convert_factor)
3019  write(qunit,'(a)')'</DataArray>'
3020  write(qunit,'(a)')'</FieldData>'
3021 
3022  ! number of cells, number of corner points, per grid.
3023  nx1=ixmhi1-ixmlo1+1;nx2=ixmhi2-ixmlo2+1;nx3=ixmhi1-ixmlo1+1;
3024  nxc1=nx1+1;nxc2=nx2+1;nxc3=nx3+1;
3025  nc=nx1*nx2*nx3
3026  np=nxc1*nxc2*nxc3
3027 
3028  length=np*size_real
3029  lengthcc=nc*size_real
3030 
3031  length_coords=3*length
3032  length_conn=2**3*size_int*nc
3033  length_offsets=nc*size_int
3034 
3035  ! Note: using the w_write, writelevel, writespshift
3036  ! we can clip parts of the grid away, select variables, levels etc.
3037  zgridsc=2.d0
3038  zlengsc=2.d0*zgridsc
3039  zlength=zlengsc*(xprobmax1-xprobmin1)
3040  do level=levmin,levmax
3041  if (writelevel(level)) then
3042  do iigrid=1,igridstail; igrid=igrids(iigrid);
3043  if (node(plevel_,igrid)/=level) cycle
3044  block=>ps(igrid)
3045  ! only output a grid when fully within clipped region selected
3046  ! by writespshift array
3047  if ((rnode(rpxmin1_,igrid)>=xprobmin1+(xprobmax1-xprobmin1)&
3048  *writespshift(1,1).and.rnode(rpxmin2_,igrid)>=xprobmin2&
3049  +(xprobmax2-xprobmin2)*writespshift(2,1))&
3050  .and.(rnode(rpxmax1_,igrid)<=xprobmax1-(xprobmax1-xprobmin1)&
3051  *writespshift(1,2).and.rnode(rpxmax2_,igrid)<=xprobmax2-(xprobmax2&
3052  -xprobmin2)*writespshift(2,2))) then
3053  d3grid=zgridsc*(rnode(rpxmax1_,igrid)-rnode(rpxmin1_,igrid))
3054  n3grid=nint(zlength/d3grid)
3055  do i3grid=1,n3grid !subcycles
3056  select case(convert_type)
3057  case('vtuB23')
3058  ! we write out every grid as one VTK PIECE
3059  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3060  '" NumberOfCells="',nc,'">'
3061  write(qunit,'(a)')'<PointData>'
3062  do iw=1,nw
3063  if(.not.w_write(iw))cycle
3064  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3065  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3066  write(qunit,'(a)')'</DataArray>'
3067  offset=offset+length+size_int
3068  enddo
3069  if(nwauxio>0)then
3070  do iw=nw+1,nw+nwauxio
3071  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3072  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3073  write(qunit,'(a)')'</DataArray>'
3074  offset=offset+length+size_int
3075  enddo
3076  endif
3077  write(qunit,'(a)')'</PointData>'
3078 
3079  write(qunit,'(a)')'<Points>'
3080  write(qunit,'(a,i16,a)') &
3081  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3082  offset,'"/>'
3083  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3084  offset=offset+length_coords+size_int
3085  write(qunit,'(a)')'</Points>'
3086  case('vtuBCC23')
3087  ! we write out every grid as one VTK PIECE
3088  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3089  '" NumberOfCells="',nc,'">'
3090  write(qunit,'(a)')'<CellData>'
3091  do iw=1,nw
3092  if(.not.w_write(iw))cycle
3093  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3094  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3095  write(qunit,'(a)')'</DataArray>'
3096  offset=offset+lengthcc+size_int
3097  enddo
3098  if(nwauxio>0)then
3099  do iw=nw+1,nw+nwauxio
3100  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3101  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3102  write(qunit,'(a)')'</DataArray>'
3103  offset=offset+lengthcc+size_int
3104  enddo
3105  endif
3106  write(qunit,'(a)')'</CellData>'
3107  write(qunit,'(a)')'<Points>'
3108  write(qunit,'(a,i16,a)') &
3109  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3110  offset,'"/>'
3111  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3112  offset=offset+length_coords+size_int
3113  write(qunit,'(a)')'</Points>'
3114  end select
3115  write(qunit,'(a)')'<Cells>'
3116  ! connectivity part
3117  write(qunit,'(a,i16,a)')&
3118  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',&
3119  offset,'"/>'
3120  offset=offset+length_conn+size_int
3121  ! offsets data array
3122  write(qunit,'(a,i16,a)') &
3123  '<DataArray type="Int32" Name="offsets" format="appended" offset="',&
3124  offset,'"/>'
3125  offset=offset+length_offsets+size_int
3126  ! VTK cell type data array
3127  write(qunit,'(a,i16,a)') &
3128  '<DataArray type="Int32" Name="types" format="appended" offset="',&
3129  offset,'"/>'
3130  offset=offset+size_length+nc*size_int
3131  write(qunit,'(a)')'</Cells>'
3132  write(qunit,'(a)')'</Piece>'
3133  end do !subcycles
3134  end if
3135  end do
3136  end if
3137  end do
3138 
3139  write(qunit,'(a)')'</UnstructuredGrid>'
3140  write(qunit,'(a)')'<AppendedData encoding="raw">'
3141  close(qunit)
3142  open(qunit,file=filename,form='unformatted',access='stream',status='old',position='append')
3143  buffer='_'
3144  write(qunit) trim(buffer)
3145 
3146  do level=levmin,levmax
3147  if (writelevel(level)) then
3148  do iigrid=1,igridstail; igrid=igrids(iigrid);
3149  if (node(plevel_,igrid)/=level) cycle
3150  block=>ps(igrid)
3151  ! only output a grid when fully within clipped region selected
3152  ! by writespshift array
3153  if ((rnode(rpxmin1_,igrid)>=xprobmin1+(xprobmax1-xprobmin1)&
3154  *writespshift(1,1).and.rnode(rpxmin2_,igrid)>=xprobmin2&
3155  +(xprobmax2-xprobmin2)*writespshift(2,1))&
3156  .and.(rnode(rpxmax1_,igrid)<=xprobmax1-(xprobmax1-xprobmin1)&
3157  *writespshift(1,2).and.rnode(rpxmax2_,igrid)<=xprobmax2-(xprobmax2&
3158  -xprobmin2)*writespshift(2,2))) then
3159  d3grid=zgridsc*(rnode(rpxmax1_,igrid)-rnode(rpxmin1_,igrid))
3160  n3grid=nint(zlength/d3grid)
3161  ! In case primitives to be saved: use primitive subroutine
3162  ! extra layer around mesh only needed when storing corner values and averaging
3163  if(saveprim) then
3164  call phys_to_primitive(ixglo1,ixglo2,ixghi1,ixghi2,&
3165  ixglo1,ixglo2,ixghi1,ixghi2,ps(igrid)%w,ps(igrid)%x)
3166  endif
3167  ! using array w so that new output auxiliaries can be calculated by the user
3168  ! extend 2D data to 3D insuring variables are independent on the third coordinate
3169  do ix3=ixglo1,ixghi1
3170  w(ixglo1:ixghi1,ixglo2:ixghi2,ix3,1:nw)=ps(igrid)%w(ixglo1:ixghi1,&
3171  ixglo2:ixghi2,1:nw)
3172  end do
3173  do i3grid=1,n3grid !subcycles
3174  call calc_grid23(qunit,igrid,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
3175  ixcmin1,ixcmin2,ixcmin3,ixcmax1,ixcmax2,ixcmax3,ixccmin1,ixccmin2,&
3176  ixccmin3,ixccmax1,ixccmax2,ixccmax3,.true.,i3grid,d3grid,w,zlength,zgridsc)
3177  do iw=1,nw
3178  if(.not.w_write(iw))cycle
3179  select case(convert_type)
3180  case('vtuB23')
3181  write(qunit) length
3182  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3183  =ixcmin1,ixcmax1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3184  case('vtuBCC23')
3185  write(qunit) lengthcc
3186  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3187  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3188  =ixccmin3,ixccmax3)
3189  end select
3190  enddo
3191  if(nwauxio>0)then
3192  do iw=nw+1,nw+nwauxio
3193  select case(convert_type)
3194  case('vtuB23')
3195  write(qunit) length
3196  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3197  =ixcmin1,ixcmax1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3198  case('vtuBCC23')
3199  write(qunit) lengthcc
3200  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3201  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3202  =ixccmin3,ixccmax3)
3203  end select
3204  end do
3205  end if
3206  write(qunit) length_coords
3207  do ix3=ixcmin3,ixcmax3
3208  do ix2=ixcmin2,ixcmax2
3209  do ix1=ixcmin1,ixcmax1
3210  x_vtk(1:3)=zero;
3211  x_vtk(1:3)=xc_tmp(ix1,ix2,ix3,1:3)*normconv(0);
3212  do k=1,3
3213  write(qunit) real(x_vtk(k))
3214  end do
3215  end do
3216  end do
3217  end do
3218  write(qunit) length_conn
3219  do ix3=1,nx3
3220  do ix2=1,nx2
3221  do ix1=1,nx1
3222  write(qunit)&
3223  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
3224  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3225  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3226  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
3227  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
3228  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3229  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3230  ix3*nxc2*nxc1+ ix2*nxc1+ix1
3231  end do
3232  end do
3233  end do
3234  write(qunit) length_offsets
3235  do icel=1,nc
3236  write(qunit) icel*(2**3)
3237  end do
3238  vtk_type=11
3239  write(qunit) size_int*nc
3240  do icel=1,nc
3241  write(qunit) vtk_type
3242  end do
3243  end do !subcycles
3244  end if
3245  end do
3246  end if
3247  end do
3248 
3249  close(qunit)
3250  open(qunit,file=filename,status='unknown',form='formatted',position='append')
3251 
3252  write(qunit,'(a)')'</AppendedData>'
3253  write(qunit,'(a)')'</VTKFile>'
3254  close(qunit)
3255 
3256  end subroutine unstructuredvtkb23
3257 
3258  subroutine unstructuredvtkbsym23(qunit)
3259  ! output for vtu format to paraview, binary version output
3260  ! not parallel, uses calc_grid to compute nwauxio variables
3261  ! use this subroutine when the physical domain is symmetric/asymmetric about (0,y,z)
3262  ! plane, xprobmin1=0 and the computational domain is a half of the physical domain
3264  use mod_physics
3265  use mod_calculate_xw
3266 
3267  integer, intent(in) :: qunit
3268 
3269  double precision :: x_VTK(1:3)
3270  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,3) :: xC_TMP
3271  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,& 3) :: xCC_TMP
3272  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,nw+nwauxio) :: wC_TMP
3273  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,nw& +nwauxio) :: wCC_TMP
3274  double precision, dimension(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1,1:nw& +nwauxio) :: w
3275  double precision :: normconv(0:nw+nwauxio)
3276  double precision ::d3grid,zlengsc,zgridsc
3277  double precision :: zlength
3278  integer*8 :: offset
3279  integer:: igrid,iigrid,level,igonlevel,icel,ixCmin1,ixCmin2,&
3280  ixCmin3,ixCmax1,ixCmax2,ixCmax3,ixCCmin1,ixCCmin2,ixCCmin3,ixCCmax1,&
3281  ixCCmax2,ixCCmax3
3282  integer:: NumGridsOnLevel(1:nlevelshi)
3283  integer :: nx1,nx2,nx3,nxC1,nxC2,nxC3,nodesonlevel,elemsonlevel,nc,np,&
3284  VTK_type,ix1,ix2,ix3
3285  integer :: size_length,recsep,k,iw
3286  integer :: length,lengthcc,offset_points,offset_cells, length_coords,&
3287  length_conn,length_offsets
3288  integer :: i3grid,n3grid
3289  logical :: fileopen
3290  character(len=80):: filename
3291  character(len=name_len) :: wnamei(1:nw+nwauxio),xandwnamei(1:3+nw+nwauxio)
3292  character(len=1024) :: outfilehead
3293  character:: buffer
3294  character(len=6):: bufform
3295 
3296  if(npe>1)then
3297  if(mype==0) print *,'unstructuredvtkBsym23 not parallel, use vtumpi'
3298  call mpistop('npe>1, unstructuredvtkBsym23')
3299  end if
3300 
3301  offset=0
3302  recsep=4
3303  size_length=4
3304 
3305  inquire(qunit,opened=fileopen)
3306  if(.not.fileopen)then
3307  ! generate filename
3308  write(filename,'(a,a,i4.4,a)') trim(base_filename),"3D",snapshotini,".vtu"
3309  ! Open the file for the header part
3310  open(qunit,file=filename,status='unknown')
3311  end if
3312 
3313  call getheadernames(wnamei,xandwnamei,outfilehead)
3314  ! generate xml header
3315  write(qunit,'(a)')'<?xml version="1.0"?>'
3316  write(qunit,'(a)',advance='no') '<VTKFile type="UnstructuredGrid"'
3317  write(qunit,'(a)')' version="0.1" byte_order="LittleEndian">'
3318  write(qunit,'(a)')'<UnstructuredGrid>'
3319  write(qunit,'(a)')'<FieldData>'
3320  write(qunit,'(2a)')'<DataArray type="Float32" Name="TIME" ',&
3321  'NumberOfTuples="1" format="ascii">'
3322  write(qunit,'(f10.2)') real(global_time*time_convert_factor)
3323  write(qunit,'(a)')'</DataArray>'
3324  write(qunit,'(a)')'</FieldData>'
3325 
3326  ! number of cells, number of corner points, per grid.
3327  nx1=ixmhi1-ixmlo1+1;nx2=ixmhi2-ixmlo2+1;nx3=ixmhi1-ixmlo1+1;
3328  nxc1=nx1+1;nxc2=nx2+1;nxc3=nx3+1;
3329  nc=nx1*nx2*nx3
3330  np=nxc1*nxc2*nxc3
3331 
3332  length=np*size_real
3333  lengthcc=nc*size_real
3334 
3335  length_coords=3*length
3336  length_conn=2**3*size_int*nc
3337  length_offsets=nc*size_int
3338 
3339  ! Note: using the w_write, writelevel, writespshift
3340  ! we can clip parts of the grid away, select variables, levels etc.
3341  zlengsc=4.d0
3342  zgridsc=2.d0
3343  zlength=zlengsc*(xprobmax1-xprobmin1)
3344  do level=levmin,levmax
3345  if (writelevel(level)) then
3346  do iigrid=1,igridstail; igrid=igrids(iigrid);
3347  if (node(plevel_,igrid)/=level) cycle
3348  block=>ps(igrid)
3349  ! only output a grid when fully within clipped region selected
3350  ! by writespshift array
3351  if ((rnode(rpxmin1_,igrid)>=xprobmin1+(xprobmax1-xprobmin1)&
3352  *writespshift(1,1).and.rnode(rpxmin2_,igrid)>=xprobmin2&
3353  +(xprobmax2-xprobmin2)*writespshift(2,1))&
3354  .and.(rnode(rpxmax1_,igrid)<=xprobmax1-(xprobmax1-xprobmin1)&
3355  *writespshift(1,2).and.rnode(rpxmax2_,igrid)<=xprobmax2-(xprobmax2&
3356  -xprobmin2)*writespshift(2,2))) then
3357  d3grid=zgridsc*(rnode(rpxmax1_,igrid)-rnode(rpxmin1_,igrid))
3358  n3grid=nint(zlength/d3grid)
3359  do i3grid=1,n3grid !subcycles
3360  !! original domain ----------------------------------start
3361  select case(convert_type)
3362  case('vtuBsym23')
3363  ! we write out every grid as one VTK PIECE
3364  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3365  '" NumberOfCells="',nc,'">'
3366  write(qunit,'(a)')'<PointData>'
3367  do iw=1,nw
3368  if(.not.w_write(iw))cycle
3369  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3370  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3371  write(qunit,'(a)')'</DataArray>'
3372  offset=offset+length+size_length
3373  enddo
3374  if(nwauxio>0)then
3375  do iw=nw+1,nw+nwauxio
3376  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3377  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3378  write(qunit,'(a)')'</DataArray>'
3379  offset=offset+length+size_length
3380  enddo
3381  endif
3382  write(qunit,'(a)')'</PointData>'
3383  write(qunit,'(a)')'<Points>'
3384  write(qunit,'(a,i16,a)') &
3385  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3386  offset,'"/>'
3387  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3388  offset=offset+length_coords+size_length
3389  write(qunit,'(a)')'</Points>'
3390  case('vtuBCCsym23')
3391  ! we write out every grid as one VTK PIECE
3392  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3393  '" NumberOfCells="',nc,'">'
3394  write(qunit,'(a)')'<CellData>'
3395  do iw=1,nw
3396  if(.not.w_write(iw))cycle
3397  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3398  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3399  write(qunit,'(a)')'</DataArray>'
3400  offset=offset+lengthcc+size_length
3401  enddo
3402  if(nwauxio>0)then
3403  do iw=nw+1,nw+nwauxio
3404  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3405  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3406  write(qunit,'(a)')'</DataArray>'
3407  offset=offset+lengthcc+size_length
3408  enddo
3409  endif
3410  write(qunit,'(a)')'</CellData>'
3411 
3412  write(qunit,'(a)')'<Points>'
3413  write(qunit,'(a,i16,a)') &
3414  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3415  offset,'"/>'
3416  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3417  offset=offset+length_coords+size_length
3418  write(qunit,'(a)')'</Points>'
3419  end select
3420  write(qunit,'(a)')'<Cells>'
3421  ! connectivity part
3422  write(qunit,'(a,i16,a)')&
3423  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',&
3424  offset,'"/>'
3425  offset=offset+length_conn+size_length
3426  ! offsets data array
3427  write(qunit,'(a,i16,a)') &
3428  '<DataArray type="Int32" Name="offsets" format="appended" offset="',&
3429  offset,'"/>'
3430  offset=offset+length_offsets+size_length
3431  ! VTK cell type data array
3432  write(qunit,'(a,i16,a)') &
3433  '<DataArray type="Int32" Name="types" format="appended" offset="',&
3434  offset,'"/>'
3435  offset=offset+size_length+nc*size_int
3436  write(qunit,'(a)')'</Cells>'
3437  write(qunit,'(a)')'</Piece>'
3438  !! original domain ----------------------------------end
3439  !! symetric/asymetric mirror domain -----------------start
3440  select case(convert_type)
3441  case('vtuBsym23')
3442  ! we write out every grid as one VTK PIECE
3443  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3444  '" NumberOfCells="',nc,'">'
3445  write(qunit,'(a)')'<PointData>'
3446  do iw=1,nw
3447  if(.not.w_write(iw))cycle
3448  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3449  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3450  write(qunit,'(a)')'</DataArray>'
3451  offset=offset+length+size_length
3452  enddo
3453  if(nwauxio>0)then
3454  do iw=nw+1,nw+nwauxio
3455  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3456  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3457  write(qunit,'(a)')'</DataArray>'
3458  offset=offset+length+size_length
3459  enddo
3460  endif
3461  write(qunit,'(a)')'</PointData>'
3462  write(qunit,'(a)')'<Points>'
3463  write(qunit,'(a,i16,a)') &
3464  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3465  offset,'"/>'
3466  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3467  offset=offset+length_coords+size_length
3468  write(qunit,'(a)')'</Points>'
3469  case('vtuBCCsym23')
3470  ! we write out every grid as one VTK PIECE
3471  write(qunit,'(a,i7,a,i7,a)') '<Piece NumberOfPoints="',np,&
3472  '" NumberOfCells="',nc,'">'
3473  write(qunit,'(a)')'<CellData>'
3474  do iw=1,nw
3475  if(.not.w_write(iw))cycle
3476  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3477  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3478  write(qunit,'(a)')'</DataArray>'
3479  offset=offset+lengthcc+size_length
3480  enddo
3481  if(nwauxio>0)then
3482  do iw=nw+1,nw+nwauxio
3483  write(qunit,'(a,a,a,i16,a)')'<DataArray type="Float32" Name="',&
3484  trim(wnamei(iw)), '" format="appended" offset="',offset,'">'
3485  write(qunit,'(a)')'</DataArray>'
3486  offset=offset+lengthcc+size_length
3487  enddo
3488  endif
3489  write(qunit,'(a)')'</CellData>'
3490  write(qunit,'(a)')'<Points>'
3491  write(qunit,'(a,i16,a)') &
3492  '<DataArray type="Float32" NumberOfComponents="3" format="appended" offset="',&
3493  offset,'"/>'
3494  ! write cell corner coordinates in a backward dimensional loop, always 3D output
3495  offset=offset+length_coords+size_length
3496  write(qunit,'(a)')'</Points>'
3497  end select
3498  write(qunit,'(a)')'<Cells>'
3499  ! connectivity part
3500  write(qunit,'(a,i16,a)')&
3501  '<DataArray type="Int32" Name="connectivity" format="appended" offset="',&
3502  offset,'"/>'
3503  offset=offset+length_conn+size_length
3504  ! offsets data array
3505  write(qunit,'(a,i16,a)') &
3506  '<DataArray type="Int32" Name="offsets" format="appended" offset="',&
3507  offset,'"/>'
3508  offset=offset+length_offsets+size_length
3509  ! VTK cell type data array
3510  write(qunit,'(a,i16,a)') &
3511  '<DataArray type="Int32" Name="types" format="appended" offset="',&
3512  offset,'"/>'
3513  offset=offset+size_length+nc*size_int
3514  write(qunit,'(a)')'</Cells>'
3515  write(qunit,'(a)')'</Piece>'
3516  !! symetric/asymetric mirror domain -----------------end
3517  end do !subcycles
3518  end if
3519  end do
3520  end if
3521  end do
3522 
3523  write(qunit,'(a)')'</UnstructuredGrid>'
3524  write(qunit,'(a)')'<AppendedData encoding="raw">'
3525  close(qunit)
3526  open(qunit,file=filename,form='unformatted',access='stream',status='old',position='append')
3527  buffer='_'
3528  write(qunit) trim(buffer)
3529  do level=levmin,levmax
3530  if (writelevel(level)) then
3531  do iigrid=1,igridstail; igrid=igrids(iigrid);
3532  if (node(plevel_,igrid)/=level) cycle
3533  block=>ps(igrid)
3534  ! only output a grid when fully within clipped region selected
3535  ! by writespshift array
3536  if ((rnode(rpxmin1_,igrid)>=xprobmin1+(xprobmax1-xprobmin1)&
3537  *writespshift(1,1).and.rnode(rpxmin2_,igrid)>=xprobmin2&
3538  +(xprobmax2-xprobmin2)*writespshift(2,1))&
3539  .and.(rnode(rpxmax1_,igrid)<=xprobmax1-(xprobmax1-xprobmin1)&
3540  *writespshift(1,2).and.rnode(rpxmax2_,igrid)<=xprobmax2-(xprobmax2&
3541  -xprobmin2)*writespshift(2,2))) then
3542  d3grid=zgridsc*(rnode(rpxmax1_,igrid)-rnode(rpxmin1_,igrid))
3543  n3grid=nint(zlength/d3grid)
3544  ! In case primitives to be saved: use primitive subroutine
3545  ! extra layer around mesh only needed when storing corner values and averaging
3546  if(saveprim) then
3547  call phys_to_primitive(ixglo1,ixglo2,ixghi1,ixghi2,&
3548  ixglo1,ixglo2,ixghi1,ixghi2,ps(igrid)%w,ps(igrid)%x)
3549  endif
3550  ! using array w so that new output auxiliaries can be calculated by the user
3551  ! extend 2D data to 3D insuring variables are independent on the third coordinate
3552  do ix3=ixglo1,ixghi1
3553  w(ixglo1:ixghi1,ixglo2:ixghi2,ix3,1:nw)=ps(igrid)%w(ixglo1:ixghi1,&
3554  ixglo2:ixghi2,1:nw)
3555  end do
3556  do i3grid=1,n3grid !subcycles
3557  call calc_grid23(qunit,igrid,xc_tmp,xcc_tmp,wc_tmp,wcc_tmp,normconv,&
3558  ixcmin1,ixcmin2,ixcmin3,ixcmax1,ixcmax2,ixcmax3,ixccmin1,ixccmin2,&
3559  ixccmin3,ixccmax1,ixccmax2,ixccmax3,.true.,i3grid,d3grid,w,zlength,zgridsc)
3560  !! original domain ----------------------------------start
3561  do iw=1,nw
3562  if(.not.w_write(iw))cycle
3563  select case(convert_type)
3564  case('vtuBsym23')
3565  write(qunit) length
3566  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3567  =ixcmin1,ixcmax1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3568  case('vtuBCCsym23')
3569  write(qunit) lengthcc
3570  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3571  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3572  =ixccmin3,ixccmax3)
3573  end select
3574  enddo
3575  if(nwauxio>0)then
3576  do iw=nw+1,nw+nwauxio
3577  select case(convert_type)
3578  case('vtuBsym23')
3579  write(qunit) length
3580  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3581  =ixcmin1,ixcmax1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3582  case('vtuBCCsym23')
3583  write(qunit) lengthcc
3584  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3585  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3586  =ixccmin3,ixccmax3)
3587  end select
3588  enddo
3589  endif
3590  write(qunit) length_coords
3591  do ix3=ixcmin3,ixcmax3
3592  do ix2=ixcmin2,ixcmax2
3593  do ix1=ixcmin1,ixcmax1
3594  x_vtk(1:3)=zero;
3595  x_vtk(1:3)=xc_tmp(ix1,ix2,ix3,1:3)*normconv(0);
3596  do k=1,3
3597  write(qunit) real(x_vtk(k))
3598  end do
3599  end do
3600  end do
3601  end do
3602  write(qunit) length_conn
3603  do ix3=1,nx3
3604  do ix2=1,nx2
3605  do ix1=1,nx1
3606  write(qunit)&
3607  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
3608  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3609  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3610  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
3611  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
3612  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3613  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3614  ix3*nxc2*nxc1+ ix2*nxc1+ix1
3615  end do
3616  end do
3617  end do
3618  write(qunit) length_offsets
3619  do icel=1,nc
3620  write(qunit) icel*(2**3)
3621  end do
3622  vtk_type=11
3623  write(qunit) size_int*nc
3624  do icel=1,nc
3625  write(qunit) vtk_type
3626  end do
3627  !! original domain ----------------------------------end
3628  !! symetric/asymetric mirror domain -----------------start
3629  do iw=1,nw
3630  if(.not.w_write(iw))cycle
3631  if(iw==2 .or. iw==4 .or. iw==7) then
3632  wc_tmp(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,iw)=&
3633  -wc_tmp(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,iw)
3634  wcc_tmp(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,iw)=&
3635  -wcc_tmp(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,iw)
3636  end if
3637  select case(convert_type)
3638  case('vtuBsym23')
3639  write(qunit) length
3640  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3641  =ixcmax1,ixcmin1,-1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3642  case('vtuBCCsym23')
3643  write(qunit) lengthcc
3644  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3645  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3646  =ixccmin3,ixccmax3)
3647  end select
3648  enddo
3649  if(nwauxio>0)then
3650  do iw=nw+1,nw+nwauxio
3651  select case(convert_type)
3652  case('vtuBsym23')
3653  write(qunit) length
3654  write(qunit) (((real(wc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3655  =ixcmax1,ixcmin1,-1),ix2=ixcmin2,ixcmax2),ix3=ixcmin3,ixcmax3)
3656  case('vtuBCCsym23')
3657  write(qunit) lengthcc
3658  write(qunit) (((real(wcc_tmp(ix1,ix2,ix3,iw)*normconv(iw)),ix1&
3659  =ixccmin1,ixccmax1),ix2=ixccmin2,ixccmax2),ix3&
3660  =ixccmin3,ixccmax3)
3661  end select
3662  end do
3663  end if
3664  write(qunit) length_coords
3665  do ix3=ixcmin3,ixcmax3
3666  do ix2=ixcmin2,ixcmax2
3667  do ix1=ixcmax1,ixcmin1,-1
3668  x_vtk(1:3)=zero;
3669  x_vtk(1:3)=xc_tmp(ix1,ix2,ix3,1:3)*normconv(0);
3670  x_vtk(1)=-x_vtk(1)
3671  do k=1,3
3672  write(qunit) real(x_vtk(k))
3673  end do
3674  end do
3675  end do
3676  end do
3677  write(qunit) length_conn
3678  do ix3=1,nx3
3679  do ix2=1,nx2
3680  do ix1=nx1,1,-1
3681  write(qunit)&
3682  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
3683  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3684  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3685  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
3686  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
3687  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3688  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3689  ix3*nxc2*nxc1+ ix2*nxc1+ix1
3690  end do
3691  end do
3692  end do
3693  write(qunit) length_offsets
3694  do icel=1,nc
3695  write(qunit) icel*(2**3)
3696  end do
3697  vtk_type=11
3698  write(qunit) size_int*nc
3699  do icel=1,nc
3700  write(qunit) vtk_type
3701  end do
3702  !! symetric/asymetric mirror domain -----------------end
3703  end do !subcycles
3704  end if
3705  end do
3706  end if
3707  end do
3708  close(qunit)
3709  open(qunit,file=filename,status='unknown',form='formatted',position='append')
3710  write(qunit,'(a)')'</AppendedData>'
3711  write(qunit,'(a)')'</VTKFile>'
3712  close(qunit)
3713 
3714  end subroutine unstructuredvtkbsym23
3715 
3716  subroutine calc_grid23(qunit,igrid,xC_TMP,xCC_TMP,wC_TMP,wCC_TMP,normconv,&
3717  ixCmin1,ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,ixCCmin1,ixCCmin2,ixCCmin3,&
3718  ixCCmax1,ixCCmax2,ixCCmax3,first,i3grid,d3grid,w,zlength,zgridsc)
3719  ! this subroutine computes both corner as well as cell-centered values
3720  ! it handles how we do the center to corner averaging, as well as
3721  ! whether we switch to cartesian or want primitive or conservative output,
3722  ! handling the addition of B0 in B0+B1 cases, ...
3723  ! the normconv is passed on to specialvar_output for extending with
3724  ! possible normalization values for the nw+1:nw+nwauxio entries
3726  integer, intent(in) :: qunit, igrid,i3grid
3727  logical, intent(in) :: first
3728 
3729  double precision :: dx1,dx2,dx3,d3grid,zlength,zgridsc
3730  double precision :: ldw(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1),&
3731  dwC(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1)
3732  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,3) :: xC
3733  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,& 3) :: xCC
3734  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,nw+nwauxio) :: wC
3735  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,nw& +nwauxio) :: wCC
3736  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,3) :: xC_TMP
3737  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,& 3) :: xCC_TMP
3738  double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,ixMlo1& -1:ixMhi1,nw+nwauxio) :: wC_TMP
3739  double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo1:ixMhi1,nw& +nwauxio) :: wCC_TMP
3740  double precision, dimension(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1,1:nw& +nwauxio) :: w
3741  double precision,dimension(0:nw+nwauxio) :: normconv
3742  integer :: nx1,nx2,nx3, nxC1,nxC2,nxC3, ix1,ix2,ix3, ix, iw, level, idir
3743  integer :: ixCmin1,ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,ixCCmin1,&
3744  ixCCmin2,ixCCmin3,ixCCmax1,ixCCmax2,ixCCmax3,nxCC1,nxCC2,nxCC3
3745  integer :: idims,jxCmin1,jxCmin2,jxCmin3,jxCmax1,jxCmax2,jxCmax3
3746  logical, save :: subfirst=.true.
3747 
3748  ! following only for allowing compiler to go through with debug on
3749  nx1=ixmhi1-ixmlo1+1;nx2=ixmhi2-ixmlo2+1;nx3=ixmhi1-ixmlo1+1;
3750  level=node(plevel_,igrid)
3751  dx1=dx(1,level);dx2=dx(2,level);dx3=zgridsc*dx(1,level);
3752  ! for normalization within the code
3753  if(saveprim) then
3754  normconv(0) = length_convert_factor
3755  normconv(1:nw) = w_convert_factor
3756  else
3757  normconv(0)=length_convert_factor
3758  ! assuming density
3759  normconv(1)=w_convert_factor(1)
3760  ! assuming momentum=density*velocity
3761  if (nw>=2) normconv(2:2+3)=w_convert_factor(1)*w_convert_factor(2:2+3)
3762  ! assuming energy/pressure and magnetic field
3763  if (nw>=2+3) normconv(2+3:nw)=w_convert_factor(2+3:nw)
3764  end if
3765  ! coordinates of cell centers
3766  nxcc1=nx1;nxcc2=nx2;nxcc3=nx3;
3767  ixccmin1=ixmlo1;ixccmin2=ixmlo2;ixccmin3=ixmlo1; ixccmax1=ixmhi1
3768  ixccmax2=ixmhi2;ixccmax3=ixmhi1;
3769  do ix=ixccmin1,ixccmax1
3770  xcc(ix,ixccmin2:ixccmax2,ixccmin3:ixccmax3,1)=rnode(rpxmin1_,igrid)&
3771  +(dble(ix-ixccmin1)+half)*dx1
3772  end do
3773  do ix=ixccmin2,ixccmax2
3774  xcc(ixccmin1:ixccmax1,ix,ixccmin3:ixccmax3,2)=rnode(rpxmin2_,igrid)&
3775  +(dble(ix-ixccmin2)+half)*dx2
3776  end do
3777  do ix=ixccmin3,ixccmax3
3778  xcc(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ix,3)=-zlength/two+&
3779  dble(i3grid-1)*d3grid+(dble(ix-ixccmin3)+half)*dx3
3780  end do
3781 
3782  ! coordinates of cell corners
3783  nxc1=nx1+1;nxc2=nx2+1;nxc3=nx3+1;
3784  ixcmin1=ixmlo1-1;ixcmin2=ixmlo2-1;ixcmin3=ixmlo1-1; ixcmax1=ixmhi1
3785  ixcmax2=ixmhi2;ixcmax3=ixmhi1;
3786  do ix=ixcmin1,ixcmax1
3787  xc(ix,ixcmin2:ixcmax2,ixcmin3:ixcmax3,1)=rnode(rpxmin1_,igrid)&
3788  +dble(ix-ixcmin1)*dx1
3789  end do
3790  do ix=ixcmin2,ixcmax2
3791  xc(ixcmin1:ixcmax1,ix,ixcmin3:ixcmax3,2)=rnode(rpxmin2_,igrid)&
3792  +dble(ix-ixcmin2)*dx2
3793  end do
3794  do ix=ixcmin3,ixcmax3
3795  xc(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ix,3)=-zlength/two+&
3796  dble(i3grid-1)*d3grid+dble(ix-ixcmin3)*dx3
3797  end do
3798 
3799  if (nwextra>0) then
3800  ! here we actually fill the ghost layers for the nwextra variables using
3801  ! continuous extrapolation (as these values do not exist normally in ghost
3802  ! cells)
3803  do idims=1,3
3804  select case(idims)
3805  case(1)
3806  jxcmin1=ixghi1+1-nghostcells;jxcmin2=ixglo2;jxcmin3=ixglo1;
3807  jxcmax1=ixghi1;jxcmax2=ixghi2;jxcmax3=ixghi1;
3808  do ix1=jxcmin1,jxcmax1
3809  w(ix1,jxcmin2:jxcmax2,jxcmin3:jxcmax3,nw-nwextra+1:nw) = w(jxcmin1&
3810  -1,jxcmin2:jxcmax2,jxcmin3:jxcmax3,nw-nwextra+1:nw)
3811  end do
3812  jxcmin1=ixglo1;jxcmin2=ixglo2;jxcmin3=ixglo1;
3813  jxcmax1=ixglo1-1+nghostcells;jxcmax2=ixghi2;jxcmax3=ixghi1;
3814  do ix1=jxcmin1,jxcmax1
3815  w(ix1,jxcmin2:jxcmax2,jxcmin3:jxcmax3,nw-nwextra+1:nw) = w(jxcmax1&
3816  +1,jxcmin2:jxcmax2,jxcmin3:jxcmax3,nw-nwextra+1:nw)
3817  end do
3818  case(2)
3819  jxcmin1=ixglo1;jxcmin2=ixghi2+1-nghostcells;jxcmin3=ixglo1;
3820  jxcmax1=ixghi1;jxcmax2=ixghi2;jxcmax3=ixghi1;
3821  do ix2=jxcmin2,jxcmax2
3822  w(jxcmin1:jxcmax1,ix2,jxcmin3:jxcmax3,nw-nwextra+1:nw) &
3823  = w(jxcmin1:jxcmax1,jxcmin2-1,jxcmin3:jxcmax3,nw-nwextra+1:nw)
3824  end do
3825  jxcmin1=ixglo1;jxcmin2=ixglo2;jxcmin3=ixglo1;
3826  jxcmax1=ixghi1;jxcmax2=ixglo2-1+nghostcells;jxcmax3=ixghi1;
3827  do ix2=jxcmin2,jxcmax2
3828  w(jxcmin1:jxcmax1,ix2,jxcmin3:jxcmax3,nw-nwextra+1:nw) &
3829  = w(jxcmin1:jxcmax1,jxcmax2+1,jxcmin3:jxcmax3,nw-nwextra+1:nw)
3830  end do
3831  case(3)
3832  jxcmin1=ixglo1;jxcmin2=ixglo2;jxcmin3=ixghi1+1-nghostcells;
3833  jxcmax1=ixghi1;jxcmax2=ixghi2;jxcmax3=ixghi1;
3834  do ix3=jxcmin3,jxcmax3
3835  w(jxcmin1:jxcmax1,jxcmin2:jxcmax2,ix3,nw-nwextra+1:nw) &
3836  = w(jxcmin1:jxcmax1,jxcmin2:jxcmax2,jxcmin3-1,nw-nwextra+1:nw)
3837  end do
3838  jxcmin1=ixglo1;jxcmin2=ixglo2;jxcmin3=ixglo1;
3839  jxcmax1=ixghi1;jxcmax2=ixghi2;jxcmax3=ixglo1-1+nghostcells;
3840  do ix3=jxcmin3,jxcmax3
3841  w(jxcmin1:jxcmax1,jxcmin2:jxcmax2,ix3,nw-nwextra+1:nw) &
3842  = w(jxcmin1:jxcmax1,jxcmin2:jxcmax2,jxcmax3+1,nw-nwextra+1:nw)
3843  end do
3844  end select
3845  end do
3846  end if
3847  ! next lines needed when specialvar_output uses gradients
3848  ! and later on when dwlimiter2 is used
3849  if(nwauxio>0)then
3850  ! auxiliary io variables can be computed and added by user
3851  ! next few lines ensure correct usage of routines like divvector etc
3852  dxlevel(1)=rnode(rpdx1_,igrid);dxlevel(2)=rnode(rpdx2_,igrid)
3853  ! default (no) normalization for auxiliary variables
3854  normconv(nw+1:nw+nwauxio)=one
3855  ! maybe need for restriction to ixG^LL^LSUB1
3856  call specialvar_output23(ixglo1,ixglo2,ixglo1,ixghi1,ixghi2,ixghi1,ixglo1&
3857  +1,ixglo2+1,ixglo1+1,ixghi1-1,ixghi2-1,ixghi1-1,w,xcc,normconv)
3858  endif
3859  ! compute the cell-center values for w first
3860  !===========================================
3861  ! cell center values obtained from mere copy, while B0+B1 split handled here
3862  wcc(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,:)=w(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,:)
3863  if(b0field) then
3864  do ix3=ixccmin3,ixccmax3
3865  do ix2=ixccmin2,ixccmax2
3866  do ix1=ixccmin1,ixccmax1
3867  wcc(ix1,ix2,ix3,iw_mag(:))=wcc(ix1,ix2,ix3,iw_mag(:))+ps(igrid)%B0(ix1,ix2,&
3868  :,0)
3869  end do
3870  end do
3871  end do
3872  end if
3873  if(.not.saveprim .and. b0field .and. iw_e>0) then
3874  do ix3=ixccmin3,ixccmax3
3875  do ix2=ixccmin2,ixccmax2
3876  do ix1=ixccmin1,ixccmax1
3877  wcc(ix1,ix2,ix3,iw_e)=w(ix1,ix2,ix3,iw_e) +half*sum(ps(igrid)%B0(ix1,&
3878  ix2,:,0)**2 ) + sum(w(ix1,ix2,ix3,&
3879  iw_mag(:))*ps(igrid)%B0(ix1,ix2,:,0))
3880  end do
3881  end do
3882  end do
3883  end if
3884  ! compute the corner values for w now by averaging
3885  !=================================================
3886  if(slab_uniform)then
3887  ! for slab symmetry: no geometrical info required
3888  do iw=1,nw+nwauxio
3889  if (b0field.and.iw>iw_mag(1)-1.and.iw<=iw_mag(ndir)) then
3890  idir=iw-iw_mag(1)+1
3891  do ix3=ixcmin3,ixcmax3
3892  do ix2=ixcmin2,ixcmax2
3893  do ix1=ixcmin1,ixcmax1
3894  wc(ix1,ix2,ix3,iw)=sum(w(ix1:ix1+1,ix2:ix2+1,ix3,iw) &
3895  +ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3896  ,idir,0))/dble(2**3)+&
3897  sum(w(ix1:ix1+1,ix2:ix2+1,ix3+1,iw) &
3898  +ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3899  ,idir,0))/dble(2**3)
3900  end do
3901  end do
3902  end do
3903  else
3904  do ix3=ixcmin3,ixcmax3
3905  do ix2=ixcmin2,ixcmax2
3906  do ix1=ixcmin1,ixcmax1
3907  wc(ix1,ix2,ix3,iw)=sum(w(ix1:ix1+1,ix2:ix2+1,ix3:ix3&
3908  +1,iw))/dble(2**3)
3909  end do
3910  end do
3911  end do
3912  end if
3913  end do
3914  if(.not.saveprim .and. b0field .and. iw_e>0) then
3915  do ix3=ixcmin3,ixcmax3
3916  do ix2=ixcmin2,ixcmax2
3917  do ix1=ixcmin1,ixcmax1
3918  wc(ix1,ix2,ix3,iw_e)=sum( w(ix1:ix1+1,ix2:ix2+1,ix3,iw_e) &
3919  +half*sum(ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3920  ,:,0)**2,dim=ndim+1) + sum( w(ix1:ix1+1,ix2:ix2+1,ix3&
3921  ,iw_mag(:))*ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3922  ,:,0),dim=ndim+1) ) /dble(2**3)+&
3923  sum( w(ix1:ix1+1,ix2:ix2+1,ix3+1,iw_e) &
3924  +half*sum(ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3925  ,:,0)**2,dim=ndim+1) + sum( w(ix1:ix1+1,ix2:ix2+1,ix3&
3926  +1,iw_mag(:))*ps(igrid)%B0(ix1:ix1+1,ix2:ix2+1&
3927  ,:,0),dim=ndim+1) ) /dble(2**3)
3928  end do
3929  end do
3930  end do
3931  end if
3932  end if
3933  ! keep the coordinate and vector components
3934  xc_tmp(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,1:3) &
3935  = xc(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,1:3)
3936  wc_tmp(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,1:nw&
3937  +nwauxio) = wc(ixcmin1:ixcmax1,ixcmin2:ixcmax2,ixcmin3:ixcmax3,1:nw&
3938  +nwauxio)
3939  xcc_tmp(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,&
3940  1:3) = xcc(ixccmin1:ixccmax1,ixccmin2:ixccmax2,&
3941  ixccmin3:ixccmax3,1:3)
3942  wcc_tmp(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,1:nw&
3943  +nwauxio) = wcc(ixccmin1:ixccmax1,ixccmin2:ixccmax2,ixccmin3:ixccmax3,&
3944  1:nw+nwauxio)
3945  end subroutine calc_grid23
3946 
3947  subroutine save_connvtk23(qunit,igrid)
3948  ! this saves the basic line, pixel and voxel connectivity,
3949  ! as used by VTK file outputs for unstructured grid
3951 
3952  integer, intent(in) :: qunit, igrid
3953 
3954  integer :: nx1,nx2,nx3, nxC1,nxC2,nxC3, ix1,ix2,ix3
3955 
3956  nx1=ixmhi1-ixmlo1+1;nx2=ixmhi2-ixmlo2+1;nx3=ixmhi1-ixmlo1+1;
3957  nxc1=nx1+1;nxc2=nx2+1;nxc3=nx3+1;
3958  do ix3=1,nx3
3959  do ix2=1,nx2
3960  do ix1=1,nx1
3961  write(qunit,'(8(i7,1x))')&
3962  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1-1, &
3963  (ix3-1)*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3964  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3965  (ix3-1)*nxc2*nxc1+ ix2*nxc1+ix1,&
3966  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1-1,&
3967  ix3*nxc2*nxc1+(ix2-1)*nxc1+ix1,&
3968  ix3*nxc2*nxc1+ ix2*nxc1+ix1-1,&
3969  ix3*nxc2*nxc1+ ix2*nxc1+ix1
3970 
3971  end do
3972  end do
3973  end do
3974  end subroutine save_connvtk23
3975 
3976  subroutine specialvar_output23(ixImin1,ixImin2,ixImin3,ixImax1,ixImax2,&
3977  ixImax3,ixOmin1,ixOmin2,ixOmin3,ixOmax1,ixOmax2,ixOmax3,w,x,normconv)
3978  ! this subroutine can be used in convert, to add auxiliary variables to the
3979  ! converted output file, for further analysis using tecplot, paraview, ....
3980  ! these auxiliary values need to be stored in the nw+1:nw+nwauxio slots
3981  ! the array normconv can be filled in the (nw+1:nw+nwauxio) range with
3982  ! corresponding normalization values (default value 1)
3984 
3985  integer, intent(in) :: ixImin1,ixImin2,ixImin3,ixImax1,ixImax2,&
3986  ixImax3,ixOmin1,ixOmin2,ixOmin3,ixOmax1,ixOmax2,ixOmax3
3987  double precision, intent(in) :: x(ixImin1:ixImax1,ixImin2:ixImax2,&
3988  ixImin3:ixImax3,1:3)
3989  double precision :: w(ixImin1:ixImax1,ixImin2:ixImax2,&
3990  ixImin3:ixImax3,nw+nwauxio)
3991  double precision :: normconv(0:nw+nwauxio)
3992 
3993  double precision :: qvec(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1,1:ndir),&
3994  curlvec(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo1:ixGhi1,1:ndir)
3995  integer :: idirmin
3996 
3997  ! output Te
3998  !if(saveprim)then
3999  ! w(ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,nw+1)=w(ixOmin1:ixOmax1,&
4000  ! ixOmin2:ixOmax2,ixOmin3:ixOmax3,iw_e)/w(ixOmin1:ixOmax1,ixOmin2:ixOmax2,&
4001  ! ixOmin3:ixOmax3,iw_rho)
4002  !endif
4003  !!! store current
4004  ! qvec(ixImin1:ixImax1,ixImin2:ixImax2,ixImin3:ixImax3,1)=w(ixImin1:ixImax1,&
4005  ! ixImin2:ixImax2,ixImin3:ixImax3,mag(1))
4006  ! qvec(ixImin1:ixImax1,ixImin2:ixImax2,ixImin3:ixImax3,2)=w(ixImin1:ixImax1,&
4007  ! ixImin2:ixImax2,ixImin3:ixImax3,mag(2))
4008  ! qvec(ixImin1:ixImax1,ixImin2:ixImax2,ixImin3:ixImax3,3)=w(ixImin1:ixImax1,&
4009  ! ixImin2:ixImax2,ixImin3:ixImax3,mag(3));
4010  !call curlvector3D(qvec,ixImin1,ixImin2,ixImin3,ixImax1,ixImax2,ixImax3,ixOmin1,&
4011  ! ixOmin2,ixOmin3,ixOmax1,ixOmax2,ixOmax3,curlvec,idirmin,1,ndir)
4012  !w(ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,nw+2)=curlvec&
4013  ! (ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,1)
4014  !w(ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,nw+3)=curlvec&
4015  ! (ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,2)
4016  !w(ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,nw+4)=curlvec&
4017  ! (ixOmin1:ixOmax1,ixOmin2:ixOmax2,ixOmin3:ixOmax3,3);
4018  end subroutine specialvar_output23
4019  \}
4020 
4021 end module mod_convert_files
4022 
Handles computations for coordinates and variables in output.
subroutine calc_grid(qunit, igrid, xC, xCC, xC_TMP, xCC_TMP, wC_TMP, wCC_TMP, normconv, ixCL, ixCCL, first)
Compute both corner as well as cell-centered values for output.
subroutine getheadernames(wnamei, xandwnamei, outfilehead)
get all variables names
subroutine calc_x(igrid, xC, xCC)
computes cell corner (xC) and cell center (xCC) coordinates
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: mod_comm_lib.t:208
subroutine unstructuredvtkb64(qunit)
subroutine punstructuredvtk_mpi(qunit)
subroutine tecplot_mpi(qunit)
subroutine oneblock(qunit)
subroutine calc_grid23(qunit, igrid, xC_TMP, xCC_TMP, wC_TMP, wCC_TMP, normconv, ixCmin1, ixCmin2, ixCmin3, ixCmax1, ixCmax2, ixCmax3, ixCCmin1, ixCCmin2, ixCCmin3, ixCCmax1, ixCCmax2, ixCCmax3, first, i3grid, d3grid, w, zlength, zgridsc)
subroutine write_pvtu(qunit)
subroutine imagedatavtk_mpi(qunit)
subroutine save_connvtk(qunit, igrid)
integer function nodenumbertec2d(i1, i2, nx1, nx2, ig, igrid)
subroutine tecplot(qunit)
subroutine generate_plotfile
integer function nodenumbertec1d(i1, nx1, ig, igrid)
subroutine unstructuredvtk(qunit)
subroutine unstructuredvtkb23(qunit)
subroutine unstructuredvtkb(qunit)
integer function nodenumbertec3d(i1, i2, i3, nx1, nx2, nx3, ig, igrid)
subroutine write_vtk(qunit, ixIL, ixCL, ixCCL, igrid, nc, np, nxD, nxCD, normconv, wnamei, xC, xCC, wC, wCC)
subroutine save_conntec(qunit, igrid, igonlevel)
subroutine save_connvtk23(qunit, igrid)
subroutine onegrid(qunit)
subroutine unstructuredvtk_mpi(qunit)
subroutine specialvar_output23(ixImin1, ixImin2, ixImin3, ixImax1, ixImax2, ixImax3, ixOmin1, ixOmin2, ixOmin3, ixOmax1, ixOmax2, ixOmax3, w, x, normconv)
subroutine write_vti(qunit, ixIL, ixCL, ixCCL, igD, nxD, normconv, wnamei, wC, wCC)
subroutine punstructuredvtkb_mpi(qunit)
subroutine unstructuredvtkbsym23(qunit)
subroutine convert_all()
Definition: mod_convert.t:91
Module with basic grid data structures.
Definition: mod_forest.t:2
integer, dimension(:), allocatable, save sfc_to_igrid
Go from a Morton number to an igrid index (for a single processor)
Definition: mod_forest.t:53
integer, dimension(:), allocatable, save morton_start
First Morton number per processor.
Definition: mod_forest.t:62
integer, dimension(:), allocatable, save morton_stop
Last Morton number per processor.
Definition: mod_forest.t:65
type(tree_node_ptr), dimension(:,:), allocatable, save igrid_to_node
Array to go from an [igrid, ipe] index to a node pointer.
Definition: mod_forest.t:32
update ghost cells of all blocks including physical boundaries
subroutine getbc(time, qdt, psb, nwstart, nwbc, req_diag)
do update ghost cells of all blocks including physical boundaries
This module contains definitions of global parameters and variables and some generic functions/subrou...
double precision, dimension(:), allocatable w_convert_factor
Conversion factors the primitive variables.
type(state), pointer block
Block pointer for using one block and its previous state.
logical nocartesian
IO switches for conversion.
double precision global_time
The global simulation time.
integer type_block_xc_io
MPI type for IO: cell corner (xc) or cell center (xcc) coordinates.
integer snapshotini
Resume from the snapshot with this index.
logical saveprim
If true, convert from conservative to primitive variables in output.
character(len=std_len) convert_type
Which format to use when converting.
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision time_convert_factor
Conversion factor for time unit.
integer icomm
The MPI communicator.
integer, dimension(:), allocatable ng
number of grid blocks in domain per dimension, in array over levels
integer mype
The rank of the current MPI task.
integer type_block_io
MPI type for IO: block excluding ghost cells.
integer, parameter plevel_
double precision length_convert_factor
Conversion factor for length unit.
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.
integer type_block_wc_io
MPI type for IO: cell corner (wc) or cell center (wcc) variables.
integer snapshotnext
IO: snapshot and collapsed views output numbers/labels.
integer npe
The number of MPI tasks.
integer nwauxio
Number of auxiliary variables that are only included in output.
logical, dimension(:), allocatable w_write
if true write the w variable in output
logical b0field
split magnetic field as background B0 field
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
logical, dimension(:), allocatable writelevel
double precision, dimension(:,:), allocatable dx
integer nghostcells
Number of ghost cells surrounding a grid.
double precision, dimension(^nd) dxlevel
store unstretched cell size of current level
logical slab_uniform
uniform Cartesian geometry or not (stretched Cartesian)
character(len=std_len) base_filename
Base file name for simulation output, which will be followed by a number.
double precision, dimension(^nd, 2) writespshift
domain percentage cut off shifted from each boundary when converting data
integer, parameter unitconvert
integer, dimension(:,:), allocatable node
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition: mod_physics.t:4
procedure(sub_convert), pointer phys_to_primitive
Definition: mod_physics.t:59
logical phys_req_diagonal
Whether the physics routines require diagonal ghost cells, for example for computing a curl.
Definition: mod_physics.t:36
procedure(sub_check_params), pointer phys_te_images
Definition: mod_physics.t:92
Module with all the methods that users can customize in AMRVAC.
procedure(aux_output), pointer usr_aux_output
procedure(special_convert), pointer usr_special_convert
Pointer to a tree_node.
Definition: mod_forest.t:6