15 double precision :: factor
16 integer :: igrid, iigrid, ixcog^
l
17 logical,
dimension(:,:),
allocatable :: refine2
19 if (igridstail==0)
return
27 do iigrid=1,igridstail; igrid=igrids(iigrid);
29 call lohner_orig_grid(igrid)
35 do iigrid=1,igridstail; igrid=igrids(iigrid);
37 call lohner_grid(igrid)
41 call mpistop(
"Unknown error estimator")
52 do iigrid=1,igridstail; igrid=igrids(iigrid);
54 call forcedrefine_grid(igrid,ps(igrid)%w)
63 subroutine lohner_grid(igrid)
69 integer,
intent(in) :: igrid
71 double precision :: epsilon, threshold, wtol(1:nw), xtol(1:
ndim)
72 double precision,
dimension(ixM^T) :: numerator, denominator, error
73 double precision,
dimension(ixG^T) :: tmp, tmp1, tmp2
74 double precision :: w(ixg^t,1:nw)
75 integer :: iflag, idims, idims2, level
76 integer :: ix^
l, hx^
l, jx^
l, h2x^
l, j2x^
l, ix^
d
77 logical,
dimension(ixG^T) :: refineflag, coarsenflag
85 w(ixg^t,1:nw)=ps(igrid)%w(ixg^t,1:nw)
87 if(
b0field .and.
allocated(iw_mag))
then
89 w(ixg^t,iw_e)=w(ixg^t,iw_e)+0.5d0*sum(ps(igrid)%B0(ixg^t,:,0)**2,dim=
ndim+1) &
90 + sum(w(ixg^t,iw_mag(:))*ps(igrid)%B0(ixg^t,:,0),dim=
ndim+1)
91 w(ixg^t,iw_mag(:))=w(ixg^t,iw_mag(:))+ps(igrid)%B0(ixg^t,:,0)
101 call mpistop(
"usr_var_for_errest not defined")
108 hx^
l=ix^
l-
kr(^
d,idims);
109 jx^
l=ix^
l+
kr(^
d,idims);
112 tmp(ix^s)=dlog10(w(jx^s,iflag))-dlog10(w(hx^s,iflag))
114 tmp(ix^s)=w(jx^s,iflag)-w(hx^s,iflag)
118 tmp(ix^s)=dlog10(tmp1(jx^s))-dlog10(tmp1(hx^s))
120 tmp(ix^s)=tmp1(jx^s)-tmp1(hx^s)
126 numerator=numerator+(tmp(j2x^s)-tmp(h2x^s))**2
141 tmp=dabs(w(ixg^t,iflag))
147 tmp=dabs(tmp1(ixg^t))
150 hx^
l=ix^
l-
kr(^
d,idims);
151 jx^
l=ix^
l+
kr(^
d,idims);
152 tmp2(ix^s)=tmp(jx^s)+tmp(hx^s)
157 tmp(
ixm^t)=dabs(dlog10(w(jx^s,iflag))&
158 -dlog10(w(
ixm^t,iflag))) &
159 +dabs(dlog10(w(
ixm^t,iflag))&
160 -dlog10(w(hx^s,iflag)))
162 tmp(
ixm^t)=dabs(w(jx^s,iflag)-w(
ixm^t,iflag)) &
163 +dabs(w(
ixm^t,iflag)-w(hx^s,iflag))
167 tmp(
ixm^t)=dabs(dlog10(tmp1(jx^s))-dlog10(tmp1(
ixm^t))) &
168 +dabs(dlog10(tmp1(
ixm^t))-dlog10(tmp1(hx^s)))
170 tmp(
ixm^t)=dabs(tmp1(jx^s)-tmp1(
ixm^t)) &
171 +dabs(tmp1(
ixm^t)-tmp1(hx^s))
177 denominator=denominator &
181 error=error+
w_refine_weight(iflag)*dsqrt(numerator/max(denominator,epsilon))
187 {
do ix^db=ixmlo^db,ixmhi^db\}
190 wtol(1:nw) = w(ix^
d,1:nw)
195 if (error(ix^
d) >= threshold)
then
196 refineflag(ix^
d) = .true.
198 coarsenflag(ix^
d) = .true.
202 if (any(refineflag(ixm^t)).and.level<refine_max_level) refine(igrid,mype)=.true.
203 if (all(coarsenflag(ixm^t)).and.level>1) coarsen(igrid,mype)=.true.
205 end subroutine lohner_grid
207 subroutine lohner_orig_grid(igrid)
212 integer,
intent(in) :: igrid
214 double precision :: epsilon, threshold, wtol(1:nw), xtol(1:
ndim)
215 double precision,
dimension(ixM^T) :: numerator, denominator, error
216 double precision,
dimension(ixG^T) :: dp, dm, dref, tmp1
217 integer :: iflag, idims, level
218 integer :: ix^
l, hx^
l, jx^
l, ix^
d
219 logical,
dimension(ixG^T) :: refineflag, coarsenflag
233 call mpistop(
"usr_var_for_errest not defined")
240 hx^
l=ix^
l-
kr(^
d,idims);
241 jx^
l=ix^
l+
kr(^
d,idims);
244 dp(ix^s)=dlog10(ps(igrid)%w(jx^s,iflag))-dlog10(ps(igrid)%w(ix^s,iflag))
245 dm(ix^s)=dlog10(ps(igrid)%w(ix^s,iflag))-dlog10(ps(igrid)%w(hx^s,iflag))
246 dref(
ixm^t)=dabs(dlog10(ps(igrid)%w(jx^s,iflag)))&
247 + 2.0d0 * dabs(dlog10(ps(igrid)%w(
ixm^t,iflag))) &
248 + dabs(dlog10(ps(igrid)%w(hx^s,iflag)))
250 dp(ix^s)=ps(igrid)%w(jx^s,iflag)-ps(igrid)%w(ix^s,iflag)
251 dm(ix^s)=ps(igrid)%w(ix^s,iflag)-ps(igrid)%w(hx^s,iflag)
252 dref(
ixm^t)=dabs(ps(igrid)%w(jx^s,iflag))+2.0d0*dabs(ps(igrid)%w(
ixm^t,iflag)) &
253 +dabs(ps(igrid)%w(hx^s,iflag))
257 dp(ix^s)=dlog10(tmp1(jx^s))-dlog10(tmp1(ix^s))
258 dm(ix^s)=dlog10(tmp1(ix^s))-dlog10(tmp1(hx^s))
259 dref(ix^s)=dabs(dlog10(tmp1(jx^s)))&
260 + 2.0d0 * dabs(dlog10(tmp1(ix^s))) &
261 + dabs(dlog10(tmp1(hx^s)))
263 dp(ix^s)=tmp1(jx^s)-tmp1(ix^s)
264 dm(ix^s)=tmp1(ix^s)-tmp1(hx^s)
265 dref(ix^s)=dabs(tmp1(jx^s))+2.0d0*dabs(tmp1(ix^s)) &
270 numerator(
ixm^t)=numerator+(dp(
ixm^t)-dm(
ixm^t))**2
271 denominator(
ixm^t)=denominator &
275 error=error+
w_refine_weight(iflag)*dsqrt(numerator/max(denominator,epsilon))
282 {
do ix^db=ixmlo^db,ixmhi^db\}
285 wtol(1:nw) = ps(igrid)%w(ix^
d,1:nw)
290 if (error(ix^
d) >= threshold)
then
291 refineflag(ix^
d) = .true.
293 coarsenflag(ix^
d) = .true.
297 if (any(refineflag(ixm^t)).and.level<refine_max_level) refine(igrid,mype)=.true.
298 if (all(coarsenflag(ixm^t)).and.level>1) coarsen(igrid,mype)=.true.
300 end subroutine lohner_orig_grid
302 subroutine forcedrefine_grid(igrid,w)
307 integer,
intent(in) :: igrid
308 double precision,
intent(in) :: w(ixg^t,nw)
310 double precision :: qt
312 integer :: my_refine, my_coarsen
313 logical,
dimension(ixG^T) :: refineflag
329 my_refine,my_coarsen)
332 if (my_coarsen==1)
then
342 if (my_coarsen==-1)
then
346 if (my_refine==1)
then
356 if (my_refine==-1)
then
362 refineflag(
ixm^t)=.true.
363 call refinebuffer(igrid,refineflag)
367 end subroutine forcedrefine_grid
373 integer,
intent(in) :: igrid
374 double precision,
intent(in) :: w(ixg^t,nw)
376 logical,
dimension(ixG^T) :: refineflag
377 integer :: level, my_levmin, my_levmax
389 if (level>my_levmax)
then
392 elseif (level<my_levmin)
then
397 if (level==my_levmin .or. level==my_levmax)
then
407 subroutine refinebuffer(igrid,refineflag)
411 integer,
intent(in) :: igrid
412 logical,
dimension(ixG^T),
intent(in) :: refineflag
414 integer :: ishiftbuf^
d, i^
d, ix^
l, ineighbor, ipe_neighbor, level
418 ixmin^
d=max(ixmlo^
d,ixmlo^
d+i^
d*ishiftbuf^
d);
419 ixmax^
d=min(ixmhi^
d,ixmhi^
d+i^
d*ishiftbuf^
d);
420 if (ixmax^
d<ixmin^
d|.or.) cycle
421 if (any(refineflag(ix^s)))
then
422 select case (neighbor_type(i^
d,igrid))
423 case (neighbor_coarse)
424 ineighbor=neighbor(1,i^
d,igrid)
425 ipe_neighbor=neighbor(2,i^
d,igrid)
426 if (.not.
refine(ineighbor,ipe_neighbor))
then
427 buffer(ineighbor,ipe_neighbor)=.true.
428 refine(ineighbor,ipe_neighbor)=.true.
430 case (neighbor_sibling)
433 ineighbor=neighbor(1,i^
d,igrid)
434 ipe_neighbor=neighbor(2,i^
d,igrid)
435 if (.not.
refine(ineighbor,ipe_neighbor))
then
436 buffer(ineighbor,ipe_neighbor)=.true.
437 refine(ineighbor,ipe_neighbor)=.true.
444 end subroutine refinebuffer
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
subroutine, public errest
Do all local error estimation which determines (de)refinement.
subroutine, public forcedrefine_grid_io(igrid, w)
Module with basic grid data structures.
logical, dimension(:,:), allocatable, save refine
logical, dimension(:,:), allocatable, save buffer
logical, dimension(:,:), allocatable, save coarsen
AMR flags and grids-in-use identifier per processor (igrid,ipe)
This module contains definitions of global parameters and variables and some generic functions/subrou...
type(state), pointer block
Block pointer for using one block and its previous state.
double precision global_time
The global simulation time.
integer, dimension(3, 3) kr
Kronecker delta tensor.
logical, dimension(:), allocatable logflag
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision, dimension(:), allocatable amr_wavefilter
refinement: lohner estimate wavefilter setting
integer icomm
The MPI communicator.
integer mype
The rank of the current MPI task.
integer, parameter plevel_
double precision dt
global time step
integer refine_criterion
select types of refine criterion
integer ixm
the mesh range of a physical block without ghost cells
integer ierrmpi
A global MPI error return code.
double precision, dimension(:), allocatable, parameter d
integer npe
The number of MPI tasks.
logical time_advance
do time evolving
logical b0field
split magnetic field as background B0 field
integer nbufferx
Number of cells as buffer zone.
double precision, dimension(:), allocatable w_refine_weight
Weights of variables used to calculate error for mesh refinement.
double precision, dimension(:), allocatable refine_threshold
Error tolerance for refinement decision.
integer refine_max_level
Maximal number of AMR levels.
double precision, dimension(:), allocatable derefine_ratio
Error tolerance ratio for derefinement decision.
integer max_blocks
The maximum number of grid blocks in a processor.
integer, dimension(:,:), allocatable node
This module defines the procedures of a physics module. It contains function pointers for the various...
logical phys_energy
Solve energy equation or not.
Module with all the methods that users can customize in AMRVAC.
procedure(a_refine_threshold), pointer usr_refine_threshold
procedure(refine_grid), pointer usr_refine_grid
procedure(var_for_errest), pointer usr_var_for_errest