8 double precision :: dL,Tmax,trac_delta,T_bott
9 double precision,
allocatable :: xFi(:,:)
12 double precision :: dxT^D
13 double precision :: xTmin(ndim),xTmax(ndim)
14 double precision,
allocatable :: xT(:^D&,:)
16 integer,
allocatable :: trac_grid(:),ground_grid(:)
17 integer :: ngrid_trac,ngrid_ground
18 logical,
allocatable :: trac_pe(:)
22 subroutine init_trac_line(mask)
23 logical,
intent(in) :: mask
24 integer :: refine_factor,ix^D,ix(ndim),j,iFL,numL(ndim),finegrid
25 double precision :: lengthFL
26 double precision :: xprobmin(ndim),xprobmax(ndim),domain_nx(ndim)
32 ^d&xprobmin(^d)=xprobmin^d\
33 ^d&xprobmax(^d)=xprobmax^d\
34 ^d&domain_nx(^d)=domain_nx^d\
35 dl=(xprobmax(ndim)-xprobmin(ndim))/(domain_nx(ndim)*refine_factor)
45 numlp=floor(lengthfl/dl)
51 numl(j)=floor((xprobmax(j)-xprobmin(j))/dl/finegrid)
54 allocate(xfi(numfl,ndim))
55 xfi(:,ndim)=xprobmin(ndim)+dl/50.d0
56 {
do ix^db=1,numl(^db)\}
60 ifl=ifl+(ix(j)-(ndim-1-j))*(numl(j))**(ndim-1-j)
62 xfi(ifl,1:ndim-1)=xprobmin(1:ndim-1)+finegrid*dl*ix(1:ndim-1)-finegrid*dl/2.d0
65 if(
mype .eq. 0)
write(*,*)
'NOTE: 2D TRAC method take the y-dir == grav-dir'
68 if(
mype .eq. 0)
write(*,*)
'NOTE: 3D TRAC method take the z-dir == grav-dir'
71 memxfi=floor(8*numfl*numlp*ndim/1e6)
72 if (
mype==0)
write(*,*)
'Memory requirement for each processor in TRAC:'
73 if (
mype==0)
write(*,*) memxfi,
' MB'
77 end subroutine init_trac_line
79 subroutine init_trac_block(mask)
80 logical,
intent(in) :: mask
81 integer :: refine_factor,finegrid,iFL,j
83 integer :: numL(ndim),ix(ndim)
84 double precision :: lengthFL
85 double precision :: ration,a0
86 double precision :: xprobmin(ndim),xprobmax(ndim),dxT(ndim)
88 refine_factor=2**(refine_max_level-1)
89 ^d&xprobmin(^d)=xprobmin^d\
90 ^d&xprobmax(^d)=xprobmax^d\
91 ^d&dxt^d=(xprobmax^d-xprobmin^d)/(domain_nx^d*refine_factor/block_nx^d)\
93 finegrid=phys_trac_finegrid
98 dl=min(dxt^d)/finegrid
101 ^d&xtmin(^d)=xprobmin^d\
102 ^d&xtmax(^d)=xprobmax^d\
103 if(mask) xtmax(ndim)=phys_trac_mask
106 lengthfl=maxval(xtmax-xprobmin)*3.d0
108 lengthfl=maxval(xprobmax-xprobmin)*3.d0
110 numlp=floor(lengthfl/dl)
111 ^d&numxt^d=ceiling((xtmax(^d)-xtmin(^d)-smalldouble)/dxt^d)\
112 allocate(xt(numxt^d,ndim))
116 xt(j^d%ixT^s,^d)=(j-0.5d0)*dxt^d+xtmin(^d)
118 if(mask) xtmax(ndim)=maxval(xt(:^d&,ndim))+half*dxt(ndim)
123 numl(j)=floor((xprobmax(j)-xprobmin(j))/dl)
126 allocate(xfi(numfl,ndim))
127 xfi(:,ndim)=xprobmin(ndim)+dl/50.d0
128 {
do ix^db=1,numl(^db)\}
132 ifl=ifl+(ix(j)-(ndim-1-j))*(numl(j))**(ndim-1-j)
134 xfi(ifl,1:ndim-1)=xprobmin(1:ndim-1)+dl*ix(1:ndim-1)-dl/2.d0
137 if(mype .eq. 0)
write(*,*)
'NOTE: 2D TRAC method take the y-dir == grav-dir'
140 if(mype .eq. 0)
write(*,*)
'NOTE: 3D TRAC method take the z-dir == grav-dir'
142 end subroutine init_trac_block
144 subroutine trac_simple(tco_global,trac_alfa,T_peak)
145 double precision,
intent(in) :: tco_global, trac_alfa,T_peak
146 integer :: iigrid, igrid
148 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
150 ps(igrid)%special_values(1)=tco_global
152 if(ps(igrid)%special_values(1)<trac_alfa*ps(igrid)%special_values(2))
then
153 ps(igrid)%special_values(1)=trac_alfa*ps(igrid)%special_values(2)
155 if(ps(igrid)%special_values(1) .lt. t_bott)
then
156 ps(igrid)%special_values(1)=t_bott
157 else if(ps(igrid)%special_values(1) .gt. 0.2d0*t_peak)
then
158 ps(igrid)%special_values(1)=0.2d0*t_peak
160 ps(igrid)%wextra(ixg^t,iw_tcoff)=ps(igrid)%special_values(1)
162 ps(igrid)%special_values(2)=ps(igrid)%special_values(1)
164 end subroutine trac_simple
166 subroutine ltrac(T_peak)
167 double precision,
intent(in) :: T_peak
168 integer :: iigrid, igrid
169 integer :: ixO^L,trac_tcoff
173 do iigrid=1,igridstail_active; igrid=igrids_active(iigrid);
174 where(ps(igrid)%wextra(ixo^s,trac_tcoff) .lt. t_bott)
175 ps(igrid)%wextra(ixo^s,trac_tcoff)=t_bott
176 else where(ps(igrid)%wextra(ixo^s,trac_tcoff) .gt. 0.2d0*t_peak)
177 ps(igrid)%wextra(ixo^s,trac_tcoff)=0.2d0*t_peak
182 subroutine tracl(mask,T_peak)
183 logical,
intent(in) :: mask
184 double precision,
intent(in) :: T_peak
186 integer :: iigrid, igrid
187 double precision :: xF(numFL,numLP,ndim)
188 integer :: numR(numFL),ix^L
189 double precision :: Tlcoff(numFL)
190 integer :: ipel(numFL,numLP),igridl(numFL,numLP)
191 logical :: forwardl(numFL)
200 call mpi_barrier(icomm,ierrmpi)
207 call get_btracing_dir(ipel,igridl,forwardl)
209 call get_tcoff_line(xf,numr,tlcoff,ipel,igridl,forwardl,mask)
211 call init_trac_tcoff()
215 call mpi_barrier(icomm,ierrmpi)
220 subroutine tracb(mask,T_peak)
221 logical,
intent(in) :: mask
222 double precision,
intent(in) :: T_peak
223 integer :: peArr(numxT^D),gdArr(numxT^D),numR(numFL)
224 double precision :: Tcoff(numxT^D),Tcmax(numxT^D),Bdir(numxT^D,ndim)
225 double precision :: xF(numFL,numLP,ndim),Tcoff_line(numFL)
226 integer :: xpe(numFL,numLP,2**ndim)
227 integer :: xgd(numFL,numLP,2**ndim)
235 call block_estable(mask,tcoff,tcmax,bdir,pearr,gdarr)
239 call block_trace_mfl(mask,tcoff,tcoff_line,tcmax,bdir,pearr,gdarr,xf,numr,xpe,xgd)
240 call block_interp_grid(mask,xf,numr,xpe,xgd,tcoff_line)
243 subroutine block_estable(mask,Tcoff,Tcmax,Bdir,peArr,gdArr)
245 double precision :: Tcoff(numxT^D),Tcoff_recv(numxT^D)
246 double precision :: Tcmax(numxT^D),Tcmax_recv(numxT^D)
247 double precision :: Bdir(numxT^D,ndim),Bdir_recv(numxT^D,ndim)
248 integer :: peArr(numxT^D),peArr_recv(numxT^D)
249 integer :: gdArr(numxT^D),gdArr_recv(numxT^D)
250 integer :: xc^L,xd^L,ix^D
251 integer :: iigrid,igrid,numxT,intab
252 double precision :: xb^L
260 xcmin^d=nghostcells+1\
261 xcmax^d=block_nx^d+nghostcells\
262 do iigrid=1,igridstail; igrid=igrids(iigrid);
263 ps(igrid)%wextra(:^d&,iw_tweight)=zero
264 ps(igrid)%wextra(:^d&,iw_tcoff)=zero
265 ^d&xbmin^d=rnode(rpxmin^d_,igrid)-xtmin(^d)\
266 ^d&xbmax^d=rnode(rpxmax^d_,igrid)-xtmin(^d)\
267 xdmin^d=nint(xbmin^d/dxt^d)+1\
268 xdmax^d=ceiling((xbmax^d-smalldouble)/dxt^d)\
269 {
do ix^d=xdmin^d,xdmax^d \}
271 {
if (ix^d .le. numxt^d) intab=intab+1 \}
272 if(intab .eq. ndim)
then
274 tcoff(ix^d)=max(tcoff(ix^d),ps(igrid)%special_values(1))
275 tcmax(ix^d)=ps(igrid)%special_values(2)
277 bdir(ix^d,1:ndim)=ps(igrid)%special_values(3:3+ndim-1)+2.d0
283 call mpi_barrier(icomm,ierrmpi)
285 call mpi_allreduce(pearr,pearr_recv,numxt,mpi_integer,&
286 mpi_max,icomm,ierrmpi)
287 call mpi_allreduce(gdarr,gdarr_recv,numxt,mpi_integer,&
288 mpi_max,icomm,ierrmpi)
289 call mpi_allreduce(tcoff,tcoff_recv,numxt,mpi_double_precision,&
290 mpi_max,icomm,ierrmpi)
291 call mpi_allreduce(bdir,bdir_recv,numxt*ndim,mpi_double_precision,&
292 mpi_max,icomm,ierrmpi)
294 call mpi_allreduce(tcmax,tcmax_recv,numxt,mpi_double_precision,&
295 mpi_max,icomm,ierrmpi)
301 if(.not. mask) tcmax=tcmax_recv
302 end subroutine block_estable
304 subroutine block_trace_mfl(mask,Tcoff,Tcoff_line,Tcmax,Bdir,peArr,gdArr,xF,numR,xpe,xgd)
305 integer :: i,j,k,k^D,ix_next^D
306 logical :: mask,flag,first
307 double precision :: Tcoff(numxT^D),Tcoff_line(numFL)
308 double precision :: Tcmax(numxT^D),Tcmax_line(numFL)
309 double precision :: xF(numFL,numLP,ndim)
310 integer :: ix_mod(ndim,2),numR(numFL)
311 double precision :: alfa_mod(ndim,2)
312 double precision :: nowpoint(ndim),nowgridc(ndim)
313 double precision :: Bdir(numxT^D,ndim)
314 double precision :: init_dir,now_dir1(ndim),now_dir2(ndim)
315 integer :: peArr(numxT^D),xpe(numFL,numLP,2**ndim)
316 integer :: gdArr(numxT^D),xgd(numFL,numLP,2**ndim)
320 ^d&k^d=ceiling((xfi(i,^d)-xtmin(^d)-smalldouble)/dxt^d)\
321 tcoff_line(i)=tcoff(k^d)
322 if(.not. mask) tcmax_line(i)=tcmax(k^d)
327 nowpoint(:)=xf(i,j,:)
328 nowgridc(:)=xt(ix_next^d,:)
331 call rk_bdir(nowgridc,nowpoint,ix_next^d,now_dir1,bdir,&
332 ix_mod,first,init_dir)
334 call rk_bdir(nowgridc,nowpoint,ix_next^d,now_dir1,bdir,&
338 xgd(i,j,1)=gdarr(ix_mod(1,1),ix_mod(2,1))
339 xgd(i,j,2)=gdarr(ix_mod(1,2),ix_mod(2,1))
340 xgd(i,j,3)=gdarr(ix_mod(1,1),ix_mod(2,2))
341 xgd(i,j,4)=gdarr(ix_mod(1,2),ix_mod(2,2))
342 xpe(i,j,1)=pearr(ix_mod(1,1),ix_mod(2,1))
343 xpe(i,j,2)=pearr(ix_mod(1,2),ix_mod(2,1))
344 xpe(i,j,3)=pearr(ix_mod(1,1),ix_mod(2,2))
345 xpe(i,j,4)=pearr(ix_mod(1,2),ix_mod(2,2))
348 xgd(i,j,1)=gdarr(ix_mod(1,1),ix_mod(2,1),ix_mod(3,1))
349 xgd(i,j,2)=gdarr(ix_mod(1,2),ix_mod(2,1),ix_mod(3,1))
350 xgd(i,j,3)=gdarr(ix_mod(1,1),ix_mod(2,2),ix_mod(3,1))
351 xgd(i,j,4)=gdarr(ix_mod(1,2),ix_mod(2,2),ix_mod(3,1))
352 xgd(i,j,5)=gdarr(ix_mod(1,1),ix_mod(2,1),ix_mod(3,2))
353 xgd(i,j,6)=gdarr(ix_mod(1,2),ix_mod(2,1),ix_mod(3,2))
354 xgd(i,j,7)=gdarr(ix_mod(1,1),ix_mod(2,2),ix_mod(3,2))
355 xgd(i,j,8)=gdarr(ix_mod(1,2),ix_mod(2,2),ix_mod(3,2))
356 xpe(i,j,1)=pearr(ix_mod(1,1),ix_mod(2,1),ix_mod(3,1))
357 xpe(i,j,2)=pearr(ix_mod(1,2),ix_mod(2,1),ix_mod(3,1))
358 xpe(i,j,3)=pearr(ix_mod(1,1),ix_mod(2,2),ix_mod(3,1))
359 xpe(i,j,4)=pearr(ix_mod(1,2),ix_mod(2,2),ix_mod(3,1))
360 xpe(i,j,5)=pearr(ix_mod(1,1),ix_mod(2,1),ix_mod(3,2))
361 xpe(i,j,6)=pearr(ix_mod(1,2),ix_mod(2,1),ix_mod(3,2))
362 xpe(i,j,7)=pearr(ix_mod(1,1),ix_mod(2,2),ix_mod(3,2))
363 xpe(i,j,8)=pearr(ix_mod(1,2),ix_mod(2,2),ix_mod(3,2))
365 nowpoint(:)=nowpoint(:)+init_dir*now_dir1*dl
366 {
if(nowpoint(^d) .gt. xtmax(^d) .or. nowpoint(^d) .lt. xtmin(^d))
then
369 if(mask .and. nowpoint(ndim) .gt. phys_trac_mask)
then
374 ^d&ix_next^d=ceiling((nowpoint(^d)-xtmin(^d)-smalldouble)/dxt^d)\
375 nowgridc(:)=xt(ix_next^d,:)
376 call rk_bdir(nowgridc,nowpoint,ix_next^d,now_dir2,bdir,&
378 xf(i,j+1,:)=xf(i,j,:)+init_dir*dl*half*(now_dir1+now_dir2)
379 {
if(xf(i,j+1,^d) .gt. xtmax(^d) .or. xf(i,j+1,^d) .lt. xtmin(^d))
then
382 if(mask .and. xf(i,j+1,ndim) .gt. phys_trac_mask)
then
386 ^d&ix_next^d=ceiling((xf(i,j+1,^d)-xtmin(^d)-smalldouble)/dxt^d)\
388 tcoff_line(i)=max(tcoff_line(i),tcoff(ix_next^d))
389 if(.not.mask) tcmax_line(i)=max(tcmax_line(i),tcmax(ix_next^d))
395 if(tcoff_line(i) .gt. tmax*0.2d0)
then
396 tcoff_line(i)=tmax*0.2d0
399 if(tcoff_line(i) .gt. tcmax_line(i)*0.2d0)
then
400 tcoff_line(i)=tcmax_line(i)*0.2d0
404 end subroutine block_trace_mfl
406 subroutine rk_bdir(nowgridc,nowpoint,ix_next^D,now_dir,Bdir,ix_mod,first,init_dir)
407 double precision :: nowpoint(ndim),nowgridc(ndim)
408 integer :: ix_mod(ndim,2)
409 double precision :: alfa_mod(ndim,2)
410 integer :: ix_next^D,k^D
411 double precision :: now_dir(ndim)
412 double precision :: Bdir(numxT^D,ndim)
414 double precision,
optional :: init_dir
416 {
if(nowpoint(^d) .gt. xtmin(^d)+half*dxt^d .and. nowpoint(^d) .lt. xtmax(^d)-half*dxt^d)
then
417 if(nowpoint(^d) .le. nowgridc(^d))
then
418 ix_mod(^d,1)=ix_next^d-1
419 ix_mod(^d,2)=ix_next^d
420 alfa_mod(^d,1)=abs(nowgridc(^d)-nowpoint(^d))/dxt^d
421 alfa_mod(^d,2)=one-alfa_mod(^d,1)
423 ix_mod(^d,1)=ix_next^d
424 ix_mod(^d,2)=ix_next^d+1
425 alfa_mod(^d,2)=abs(nowgridc(^d)-nowpoint(^d))/dxt^d
426 alfa_mod(^d,1)=one-alfa_mod(^d,2)
429 ix_mod(^d,:)=ix_next^d
436 now_dir=now_dir + bdir(ix_mod(1,k1),ix_mod(2,k2),:)*alfa_mod(1,k1)*alfa_mod(2,k2)
444 now_dir=now_dir + bdir(ix_mod(1,k1),ix_mod(2,k2),ix_mod(3,k3),:)&
445 *alfa_mod(1,k1)*alfa_mod(2,k2)*alfa_mod(3,k3)
450 if(
present(init_dir))
then
451 init_dir=sign(one,now_dir(ndim))
453 end subroutine rk_bdir
455 subroutine block_interp_grid(mask,xF,numR,xpe,xgd,Tcoff_line)
457 double precision :: xF(numFL,numLP,ndim)
458 integer :: numR(numFL)
459 integer :: xpe(numFL,numLP,2**ndim)
460 integer :: xgd(numFL,numLP,2**ndim)
461 double precision :: Tcoff_line(numFL)
462 double precision :: weightIndex,weight,ds
463 integer :: i,j,k,igrid,iigrid,ixO^L,ixc^L,ixc^D
464 double precision :: dxMax^D,dxb^D
473 if(mype .eq. xpe(i,j,k))
then
475 if(igrid .le. igrids(igridstail))
then
476 ^d&dxb^d=rnode(rpdx^d_,igrid)\
477 ^d&ixcmin^d=floor((xf(i,j,^d)-dxmax^d-ps(igrid)%x(ixomin^dd,^d))/dxb^d)+ixomin^d\
478 ^d&ixcmax^d=floor((xf(i,j,^d)+dxmax^d-ps(igrid)%x(ixomin^dd,^d))/dxb^d)+ixomin^d\
479 {
if (ixcmin^d<ixomin^d) ixcmin^d=ixomin^d\}
480 {
if (ixcmax^d>ixomax^d) ixcmax^d=ixomax^d\}
481 {
do ixc^d=ixcmin^d,ixcmax^d\}
483 {ds=ds+(xf(i,j,^d)-ps(igrid)%x(ixc^dd,^d))**2\}
485 if(ds .le. 0.099d0*dl)
then
486 weight=(1/(0.099d0*dl))**weightindex
488 weight=(1/ds)**weightindex
490 ps(igrid)%wextra(ixc^d,iw_tweight)=ps(igrid)%wextra(ixc^d,iw_tweight)+weight
491 ps(igrid)%wextra(ixc^d,iw_tcoff)=ps(igrid)%wextra(ixc^d,iw_tcoff)+weight*tcoff_line(i)
494 call mpistop(
"we need to check here 366Line in mod_trac.t")
501 do iigrid=1,igridstail; igrid=igrids(iigrid);
502 where (ps(igrid)%wextra(ixo^s,iw_tweight)>0.d0)
503 ps(igrid)%wextra(ixo^s,iw_tcoff)=ps(igrid)%wextra(ixo^s,iw_tcoff)/ps(igrid)%wextra(ixo^s,iw_tweight)
505 ps(igrid)%wextra(ixo^s,iw_tcoff)=0.2d0*tmax
508 end subroutine block_interp_grid
523 subroutine init_trac_tcoff()
524 integer :: ixI^L,ixO^L,igrid,iigrid
529 do iigrid=1,igridstail; igrid=igrids(iigrid);
530 ps(igrid)%wextra(ixi^s,iw_tcoff)=0.d0
531 ps(igrid)%wextra(ixi^s,iw_tweight)=0.d0
533 end subroutine init_trac_tcoff
535 subroutine update_pegrid()
544 call traverse_gridtable()
546 end subroutine update_pegrid
548 subroutine traverse_gridtable()
551 double precision :: dxb^D,xb^L
552 integer :: iigrid,igrid,j
553 logical,
allocatable :: trac_pe_recv(:)
554 double precision :: hcmax_bt
556 allocate(trac_pe_recv(
npe))
560 do iigrid=1,igridstail; igrid=igrids(iigrid);
564 ngrid_trac=ngrid_trac+1
565 trac_grid(ngrid_trac)=igrid
566 if (xbmin^nd<hcmax_bt)
then
567 ngrid_ground=ngrid_ground+1
568 ground_grid(ngrid_ground)=igrid
573 call mpi_allreduce(trac_pe,trac_pe_recv,
npe,mpi_logical,mpi_lor,
icomm,
ierrmpi)
576 deallocate(trac_pe_recv)
577 end subroutine traverse_gridtable
580 integer :: ixI^L,ixO^L,igrid,iigrid,j
581 double precision :: rho(ixM^T)
587 call phys_get_pthermal(ps(igrid)%w,ps(igrid)%x,ixi^l,ixi^l,ps(igrid)%wextra(ixi^s,iw_tcoff))
588 call phys_get_rho(ps(igrid)%w,ps(igrid)%x,ixi^l,ixi^l,rho)
589 ps(igrid)%wextra(ixi^s,iw_tcoff)=ps(igrid)%wextra(ixi^s,iw_tcoff)/rho(ixi^s)
593 subroutine get_btracing_dir(ipel,igridl,forwardl)
594 integer :: ipel(numFL,numLP),igridl(numFL,numLP)
595 logical :: forwardl(numFL)
596 integer :: igrid,ixO^L,iFL,j,ix^D,idir,ixb^D,ixbb^D
597 double precision :: xb^L,dxb^D,xd^D,factor,Bh
598 integer :: numL(ndim),ixmin(ndim),ixmax(ndim),ix(ndim)
599 logical :: forwardRC(numFL)
609 ^d&dxb^d=rnode(rpdx^d_,igrid);
610 ^d&xbmin^d=rnode(rpxmin^d_,igrid);
611 ^d&xbmax^d=rnode(rpxmax^d_,igrid);
612 ^d&ixmin(^d)=floor((xbmin^d-xprobmin^d)/(phys_trac_finegrid*dl))+1;
613 ^d&ixmax(^d)=floor((xbmax^d-xprobmin^d)/(phys_trac_finegrid*dl));
614 ^d&numl(^d)=floor((xprobmax^d-xprobmin^d)/(phys_trac_finegrid*dl));
618 {
do ix^db=ixmin(^db),ixmax(^db)\}
622 ifl=ifl+(ix(idir)-(ndim-1-idir))*(numl(idir))**(ndim-1-idir)
626 ^d&ixb^d=floor((xfi(ifl,^d)-ps(igrid)%x(ixomin^dd,^d))/dxb^d)+ixomin^d;
627 ^d&xd^d=(xfi(ifl,^d)-ps(igrid)%x(ixb^dd,^d))/dxb^d;
630 factor={abs(1-ix^d-xd^d)*}
632 if(
allocated(iw_mag))
then
633 bh=bh+factor*(ps(igrid)%w(ixb^d+ixbb^d,iw_mag(^nd))+ps(igrid)%B0(ixb^d+ixbb^d,^nd,0))
635 bh=bh+factor*(ps(igrid)%B0(ixb^d+ixbb^d,^nd,0))
638 bh=bh+factor*ps(igrid)%w(ixb^d+ixbb^d,iw_mag(^nd))
644 forwardl(ifl)=.false.
648 call mpi_allreduce(forwardl,forwardrc,numfl,mpi_logical,&
649 mpi_land,icomm,ierrmpi)
651 end subroutine get_btracing_dir
653 subroutine get_tcoff_line(xFL,numR,TcoffFL,ipeFL,igridFL,forwardFL,mask)
655 double precision :: xFL(numFL,numLP,ndim)
656 integer :: numR(numFL)
657 double precision :: TcoffFL(numFL),TmaxFL(numFL)
658 integer :: ipeFL(numFL,numLP),igridFL(numFL,numLP)
659 logical :: forwardFL(numFL)
660 logical,
intent(in) :: mask
661 integer :: nwP,nwL,iFL,iLP
662 double precision :: wPm(numFL,numLP,2),wLm(numFL,1+2)
663 character(len=std_len) :: ftype,tcondi
669 call trace_field_multi(xfl,wpm,wlm,dl,numfl,numlp,nwp,nwl,forwardfl,ftype,tcondi)
671 numr(ifl)=int(wlm(ifl,1))
672 tcofffl(ifl)=wlm(ifl,2)
673 tmaxfl(ifl)=wlm(ifl,3)
675 if(tcofffl(ifl)>0.2d0*tmax) tcofffl(ifl)=0.2d0*tmax
677 tmaxfl(ifl)=wlm(ifl,3)
678 if(tcofffl(ifl)>0.2d0*tmaxfl(ifl)) tcofffl(ifl)=0.2d0*tmaxfl(ifl)
681 if(tcofffl(ifl)<t_bott) tcofffl(ifl)=t_bott
685 if (numr(ifl)>0)
then
687 ipefl(ifl,ilp)=int(wpm(ifl,ilp,1))
688 igridfl(ifl,ilp)=int(wpm(ifl,ilp,2))
692 end subroutine get_tcoff_line
695 double precision :: xF(numFL,numLP,ndim)
696 integer :: numR(numFL),ipel(numFL,numLP),igridl(numFL,numLP)
697 double precision :: Tlcoff(numFL)
698 integer :: iFL,iLP,ixO^L,ixI^L,ixc^L,ixb^L,ixc^D
699 integer :: igrid,j,ipmin,ipmax,igrid_nb
700 double precision :: dxb^D,dxMax^D,xb^L,Tcnow
701 double precision :: xFnow(ndim),xc(ndim)
702 integer :: weightIndex,idn^D,ixmax^ND
703 double precision :: ds,weight
715 do while (ilp<=numr(ifl))
718 do while (ipel(ifl,ipmin)/=mype .and. ipmin<=numr(ifl))
721 igrid=igridl(ifl,ipmin)
723 do while (ipel(ifl,ipmax)==mype .and. igridl(ifl,ipmax+1)==igrid .and. ipmax<numr(ifl))
728 ^d&dxb^d=rnode(rpdx^d_,igrid);
732 xfnow(:)=xf(ifl,ilp,:)
733 ^d&ixbmin^d=floor((xfnow(^d)-dxmax^d-ps(igrid)%x(ixomin^dd,^d))/dxb^d)+ixomin^d;
734 ^d&ixbmax^d=floor((xfnow(^d)+dxmax^d-ps(igrid)%x(ixomin^dd,^d))/dxb^d)+ixomin^d;
737 {ixcmin^d=max(ixbmin^d,ixomin^d)\}
738 {ixcmax^d=min(ixbmax^d,ixomax^d)\}
739 xbmin^nd=rnode(rpxmin^nd_,igrid)
740 xbmax^nd=rnode(rpxmax^nd_,igrid)
741 ixmax^nd=floor((phys_trac_mask-xbmin^nd)/dxb^nd)+ixomin^nd
742 if (xbmax^nd>phys_trac_mask) ixcmax^nd=min(ixmax^nd,ixcmax^nd)
743 {
do ixc^d=ixcmin^d,ixcmax^d\}
745 {ds=ds+(xfnow(^d)-ps(igrid)%x(ixc^dd,^d))**2\}
747 if(ds<1.0d-2*dxb1)
then
748 weight=(1/(1.0d-2*dxb1))**weightindex
750 weight=(1/ds)**weightindex
752 ps(igrid)%wextra(ixc^d,iw_tweight)=ps(igrid)%wextra(ixc^d,iw_tweight)+weight
753 ps(igrid)%wextra(ixc^d,iw_tcoff)=ps(igrid)%wextra(ixc^d,iw_tcoff)+weight*tcnow
758 if (ixbmin^d<ixomin^d)
then
761 if (neighbor(2,idn^dd,igrid)==mype .and. neighbor_type(idn^dd,igrid)==neighbor_sibling)
then
762 igrid_nb=neighbor(1,idn^dd,igrid)
763 ixcmin^dd=max(ixbmin^dd,ixomin^dd);
764 ixcmax^dd=min(ixbmax^dd,ixomax^dd);
765 ixcmin^d=ixomax^d+(ixbmin^d-ixomin^d)
767 xbmin^nd=rnode(rpxmin^nd_,igrid_nb)
768 xbmax^nd=rnode(rpxmax^nd_,igrid_nb)
769 ixmax^nd=floor((phys_trac_mask-xbmin^nd)/dxb^nd)+ixomin^nd
770 if (xbmax^nd>phys_trac_mask) ixcmax^nd=min(ixmax^nd,ixcmax^nd)
772 {
do ixc^dd=ixcmin^dd,ixcmax^dd;}
774 xc(:)=ps(igrid_nb)%x(ixc^dd,:)
775 {ds=ds+(xfnow(^dd)-xc(^dd))**2;}
777 if(ds<1.0d-2*dxb1)
then
778 weight=(1/(1.0d-2*dxb1))**weightindex
780 weight=(1/ds)**weightindex
782 ps(igrid_nb)%wextra(ixc^dd,iw_tweight)=ps(igrid_nb)%wextra(ixc^dd,iw_tweight)+weight
783 ps(igrid_nb)%wextra(ixc^dd,iw_tcoff)=ps(igrid_nb)%wextra(ixc^dd,iw_tcoff)+weight*tcnow
788 if (ixbmax^d>ixomin^d)
then
791 if (neighbor(2,idn^dd,igrid)==mype .and. neighbor_type(idn^dd,igrid)==neighbor_sibling)
then
792 igrid_nb=neighbor(1,idn^dd,igrid)
793 xbmin^nd=rnode(rpxmin^nd_,igrid_nb)
794 if (xbmin^nd<phys_trac_mask)
then
795 ixcmin^dd=max(ixbmin^dd,ixomin^dd);
796 ixcmax^dd=min(ixbmax^dd,ixomax^dd);
798 ixcmax^d=ixomin^d+(ixbmax^d-ixomax^d)
799 xbmax^nd=rnode(rpxmax^nd_,igrid_nb)
800 ixmax^nd=floor((phys_trac_mask-xbmin^nd)/dxb^nd)+ixomin^nd
801 if (xbmax^nd>phys_trac_mask) ixcmax^nd=min(ixmax^nd,ixcmax^nd)
803 {
do ixc^dd=ixcmin^dd,ixcmax^dd;}
805 xc(:)=ps(igrid_nb)%x(ixc^dd,:)
806 {ds=ds+(xfnow(^dd)-xc(^dd))**2;}
808 if(ds<1.0d-2*dxb1)
then
809 weight=(1/(1.0d-2*dxb1))**weightindex
811 weight=(1/ds)**weightindex
813 ps(igrid_nb)%wextra(ixc^dd,iw_tweight)=ps(igrid_nb)%wextra(ixc^dd,iw_tweight)+weight
814 ps(igrid_nb)%wextra(ixc^dd,iw_tcoff)=ps(igrid_nb)%wextra(ixc^dd,iw_tcoff)+weight*tcnow
828 where(ps(igrid)%wextra(ixo^s,iw_tweight)>0.d0)
829 ps(igrid)%wextra(ixo^s,iw_tcoff)=ps(igrid)%wextra(ixo^s,iw_tcoff)/ps(igrid)%wextra(ixo^s,iw_tweight)
831 ps(igrid)%wextra(ixo^s,iw_tcoff)=t_bott
836 subroutine trac_after_setdt(tco,trac_alfa,T_peak, T_bott_in)
837 double precision,
intent(in) :: trac_alfa,tco,T_peak, T_bott_in
840 select case(phys_trac_type)
846 call trac_simple(tco,trac_alfa,t_peak)
853 call tracl(.false.,t_peak)
856 call tracb(.false.,t_peak)
859 call tracl(.true.,t_peak)
862 call tracb(.true.,t_peak)
864 call mpistop(
"undefined TRAC method type")
866 end subroutine trac_after_setdt
875 if(
mype .eq. 0)
write(*,*)
'Using TRACL(ine) global method'
876 if(
mype .eq. 0)
write(*,*)
'By default, magnetic field lines are traced every 4 grid cells'
877 call init_trac_line(.false.)
880 if(
mype .eq. 0)
write(*,*)
'Using TRACB(lock) global method'
881 if(
mype .eq. 0)
write(*,*)
'Currently, only valid in Cartesian uniform settings'
882 if(
mype .eq. 0)
write(*,*)
'By default, magnetic field lines are traced every 4 grid cells'
883 call init_trac_block(.false.)
886 if(
mype .eq. 0)
write(*,*)
'Using TRACL(ine) method with a mask'
887 if(
mype .eq. 0)
write(*,*)
'By default, magnetic field lines are traced every 4 grid cells'
888 call init_trac_line(.true.)
891 if(
mype .eq. 0)
write(*,*)
'Using TRACB(lock) method with a mask'
892 if(
mype .eq. 0)
write(*,*)
'Currently, only valid in Cartesian uniform settings'
893 if(
mype .eq. 0)
write(*,*)
'By default, magnetic field lines are traced every 4 grid cells'
894 call init_trac_block(.true.)
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer domain_nx
number of cells for each dimension in level-one mesh
double precision phys_trac_mask
integer, parameter rpxmin
integer icomm
The MPI communicator.
integer mype
The rank of the current MPI task.
integer ierrmpi
A global MPI error return code.
integer npe
The number of MPI tasks.
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
logical phys_trac
Use TRAC (Johnston 2019 ApJL, 873, L22) for MHD or 1D HD.
integer refine_max_level
Maximal number of AMR levels.
integer max_blocks
The maximum number of grid blocks in a processor.
integer phys_trac_finegrid
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_trac_after_setdt), pointer phys_trac_after_setdt
subroutine interp_tcoff(xF, ipel, igridl, numR, Tlcoff)
subroutine, public initialize_trac_after_settree
subroutine trace_field_multi(xfm, wPm, wLm, dL, numL, numP, nwP, nwL, forwardm, ftype, tcondi)