MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_refine.t
Go to the documentation of this file.
2
3 implicit none
4 private
5
6 public :: refine_grids
7
8contains
9
10
11 !> refine one block to its children blocks
12 subroutine refine_grids(child_igrid,child_ipe,igrid,ipe,active)
16
17 integer, dimension(2^D&), intent(in) :: child_igrid, child_ipe
18 integer, intent(in) :: igrid, ipe
19 logical, intent(in) :: active
20
21 integer :: ic^d
22
23 ! allocate solution space for new children
24 {do ic^db=1,2\}
25 call alloc_node(child_igrid(ic^d))
26 {end do\}
27
28 if ((time_advance .and. active).or.convert.or.reset_grid) then
29 ! prolong igrid to new children
30 call prolong_grid(child_igrid,child_ipe,igrid,ipe)
31 else
32 ! Fill new created children with initial condition
33 {do ic^db=1,2\}
34 call initial_condition(child_igrid(ic^d))
35 {end do\}
36 end if
37
38 ! remove solution space of igrid to save memory when converting data
39 if(convert) call dealloc_node(igrid)
40 end subroutine refine_grids
41
42 !> prolong one block
43 subroutine prolong_grid(child_igrid,child_ipe,igrid,ipe)
47 use mod_amr_fct, only: old_neighbors
48
49 integer, dimension(2^D&), intent(in) :: child_igrid, child_ipe
50 integer, intent(in) :: igrid, ipe
51
52 double precision :: dxco^d, xcomin^d, dxfi^d, xfimin^d
53 integer :: ix^l, ichild, ixco^l, ic^d
54
55 ix^l=ixm^ll^ladd1;
56
57 ! Convert parent to prolongation space:
58 ! phys_to_prolong: EoS-aware (rho, v, T) — avoids Jensen's inequality
59 ! phys_to_primitive: standard (rho, v, p) — used with prolongprimitive
60 if(associated(phys_to_prolong)) then
61 call phys_to_prolong(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
62 else if(prolongprimitive) then
63 call phys_to_primitive(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
64 end if
65
66 xcomin^d=rnode(rpxmin^d_,igrid)\
67 dxco^d=rnode(rpdx^d_,igrid)\
68
69 if(stagger_grid) call old_neighbors(child_igrid,child_ipe,igrid,ipe)
70
71 {do ic^db=1,2\}
72 ichild=child_igrid(ic^d)
73
74 ixcomin^d=ixmlo^d+(ic^d-1)*block_nx^d/2\
75 ixcomax^d=ixmhi^d+(ic^d-2)*block_nx^d/2\
76
77 xfimin^d=rnode(rpxmin^d_,ichild)\
78 dxfi^d=rnode(rpdx^d_,ichild)\
79 ^d&dxlevel(^d)=dxfi^d;
80 call prolong_2nd(ps(igrid),ixco^l,ps(ichild), &
81 dxco^d,xcomin^d,dxfi^d,xfimin^d,igrid,ichild)
82 !call prolong_1st(ps(igrid)%w,ixCo^L,ps(ichild)%w,ps(ichild)%x)
83 {end do\}
84
85 ! Convert parent back from prolongation space
86 if(associated(phys_to_prolong)) then
87 call phys_from_prolong(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
88 else if (prolongprimitive) then
89 call phys_to_conserved(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
90 end if
91
92 end subroutine prolong_grid
93
94 !> do 2nd order prolongation
95 subroutine prolong_2nd(sCo,ixCo^L,sFi,dxCo^D,xComin^D,dxFi^D,xFimin^D,igridCo,igridFi)
101
102 integer, intent(in) :: ixco^l, igridfi, igridco
103 double precision, intent(in) :: dxco^d, xcomin^d, dxfi^d, xfimin^d
104 type(state), intent(in) :: sco
105 type(state), intent(inout) :: sfi
106
107 double precision :: slopel, sloper, slopec, signc, signr
108 double precision :: slope(nw,ndim)
109 double precision :: eta^d
110 integer :: ixco^d, jxco^d, hxco^d, ixfi^d, ix^d, idim, iw, ixcg^l, el
111 logical :: fine_^l
112
113 associate(wco=>sco%w, wfi=>sfi%w)
114 ixcg^l=ixco^l;
115 {do ixco^db = ixcg^lim^db
116 ! lower left grid index in finer child block
117 ixfi^db=2*(ixco^db-ixcomin^db)+ixmlo^db\}
118
119 do idim=1,ndim
120 hxco^d=ixco^d-kr(^d,idim)\
121 jxco^d=ixco^d+kr(^d,idim)\
122
123 do iw=1,nw
124 slopel=wco(ixco^d,iw)-wco(hxco^d,iw)
125 sloper=wco(jxco^d,iw)-wco(ixco^d,iw)
126 slopec=half*(sloper+slopel)
127
128 ! get limited slope
129 signr=sign(one,sloper)
130 signc=sign(one,slopec)
131 !select case(prolong_limiter)
132 !case(1)
133 ! ! unlimited
134 ! slope(iw,idim)=slopeC
135 !case(2)
136 ! ! minmod
137 ! slope(iw,idim)=signR*max(zero,min(dabs(slopeR), &
138 ! signR*slopeL))
139 !case(3)
140 ! ! woodward
141 ! slope(iw,idim)=two*signR*max(zero,min(dabs(slopeR), &
142 ! signR*slopeL,signR*half*slopeC))
143 !case(4)
144 ! ! koren
145 ! slope(iw,idim)=signR*max(zero,min(two*signR*slopeL, &
146 ! (dabs(slopeR)+two*slopeL*signR)*third,two*dabs(slopeR)))
147 !case default
148 slope(iw,idim)=signc*max(zero,min(dabs(slopec), &
149 signc*slopel,signc*sloper))
150 !end select
151 end do
152 end do
153 ! cell-centered coordinates of coarse grid point
154 !^D&xCo^D=xCo({ixCo^DD},^D)
155 {do ix^db=ixfi^db,ixfi^db+1 \}
156 ! cell-centered coordinates of fine grid point
157 !^D&xFi^D=xFi({ix^DD},^D)
158 if(slab_uniform) then
159 ! normalized distance between fine/coarse cell center
160 ! in coarse cell: ranges from -0.5 to 0.5 in each direction
161 ! (origin is coarse cell center)
162 ! hence this is +1/4 or -1/4 on cartesian mesh
163 !eta^D=(xFi^D-xCo^D)*invdxCo^D;
164 eta^d=0.5d0*(dble(ix^d-ixfi^d)-0.5d0);
165 else
166 {! forefactor is -0.5d0 when ix=ixFi and +0.5d0 for ixFi+1
167 eta^d=(dble(ix^d-ixfi^d)-0.5d0)*(one-sfi%dvolume(ix^dd) &
168 /sum(sfi%dvolume(ixfi^d:ixfi^d+1^d%ix^dd))) \}
169 end if
170 wfi(ix^d,1:nw) = wco(ixco^d,1:nw) &
171 + {(slope(1:nw,^d)*eta^d)+}
172 {end do\}
173 {end do\}
174 if(stagger_grid) then
175 call already_fine(sfi,igridfi,fine_^l)
176 call prolong_2nd_stg(sco,sfi,ixco^l,ixm^ll,dxco^d,xcomin^d,dxfi^d,xfimin^d,.false.,fine_^l)
177 end if
178
179 if(fix_small_values) call phys_handle_small_values(prolongprimitive,wfi,sfi%x,ixg^ll,ixm^ll,'prolong_2nd')
180
181 ! Convert child cells from prolongation space to conserved.
182 if(associated(phys_from_prolong) .and. associated(phys_wb_prolong)) then
183 ! EoS-aware interpolation produced (rho, v, T) in the child cells.
184 ! WB is also active: re-balance pressure via the HSE recurrence so
185 ! the prolonged state preserves the discrete WB reference exactly.
186 ! (rho,v,T) -[from_prolong]-> (rho,m,E) -[to_primitive]-> (rho,v,p)
187 ! -[wb_prolong]-> (rho_eq, v, p_eq) -[to_conserved]-> (rho_eq, m, E_eq)
188 call phys_from_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
189 call phys_to_primitive(ixg^ll,ixm^ll,wfi,sfi%x)
190 call phys_wb_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
191 call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
192 else if(associated(phys_from_prolong)) then
193 ! EoS-aware only: (rho, v, T) -> (rho, rho*v, E) using EoS tables
194 call phys_from_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
195 else if(associated(phys_wb_prolong)) then
196 ! WB only: rebuild p from HSE recurrence using interpolated T = p/rho
197 if(.not. prolongprimitive .and. .not. associated(phys_to_prolong)) then
198 call phys_to_primitive(ixg^ll,ixm^ll,wfi,sfi%x)
199 end if
200 call phys_wb_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
201 call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
202 else
203 if(prolongprimitive) call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
204 end if
205 end associate
206
207 end subroutine prolong_2nd
208
209 !> do 1st order prolongation
210 subroutine prolong_1st(wCo,ixCo^L,wFi,xFi)
212
213 integer, intent(in) :: ixco^l
214 double precision, intent(in) :: wco(ixg^t,nw), xfi(ixg^t,1:ndim)
215 double precision, intent(out) :: wfi(ixg^t,nw)
216
217 integer :: ixco^d, ixfi^d, iw
218 integer :: ixfi^l
219
220 {do ixco^db = ixco^lim^db
221 ixfi^db=2*(ixco^db-ixcomin^db)+ixmlo^db\}
222 forall(iw=1:nw) wfi(ixfi^d:ixfi^d+1,iw)=wco(ixco^d,iw)
223 {end do\}
224
225 end subroutine prolong_1st
226
227end module mod_refine
subroutine, public already_fine(sfi, ichild, fine_l)
This routine fills the fine faces before prolonging. It is the face equivalent of fix_conserve.
subroutine, public old_neighbors(child_igrid, child_ipe, igrid, ipe)
subroutine, public prolong_2nd_stg(sco, sfi, ixcolin, ixfilin, dxcod, xcomind, dxfid, xfimind, ghost, fine_lin)
This subroutine performs a 2nd order prolongation for a staggered field F, preserving the divergence ...
Definition mod_amr_fct.t:41
subroutine, public dealloc_node(igrid)
subroutine, public alloc_node(igrid)
allocate arrays on igrid node
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer, dimension(3, 3) kr
Kronecker delta tensor.
integer, parameter ndim
Number of spatial dimensions for grid variables.
logical stagger_grid
True for using stagger grid.
integer block_nx
number of cells for each dimension in grid block excluding ghostcells
integer ixm
the mesh range of a physical block without ghost cells
double precision, dimension(:), allocatable, parameter d
logical prolongprimitive
prolongate primitive variables in level-jump ghost cells
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
double precision, dimension(^nd) dxlevel
store unstretched cell size of current level
logical slab_uniform
uniform Cartesian geometry or not (stretched Cartesian)
subroutine, public initial_condition(igrid)
fill in initial condition
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:52
procedure(sub_small_values), pointer phys_handle_small_values
Definition mod_physics.t:84
procedure(sub_wb_prolong), pointer phys_wb_prolong
Definition mod_physics.t:59
procedure(sub_convert), pointer phys_to_prolong
Definition mod_physics.t:55
procedure(sub_convert), pointer phys_to_conserved
Definition mod_physics.t:51
procedure(sub_convert), pointer phys_from_prolong
Definition mod_physics.t:56
subroutine, public refine_grids(child_igrid, child_ipe, igrid, ipe, active)
refine one block to its children blocks
Definition mod_refine.t:13