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 ! the conversions may read block%B0
61 block=>ps(igrid)
62 if(associated(phys_to_prolong)) then
63 call phys_to_prolong(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
64 else if(prolongprimitive) then
65 call phys_to_primitive(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
66 end if
67
68 xcomin^d=rnode(rpxmin^d_,igrid)\
69 dxco^d=rnode(rpdx^d_,igrid)\
70
71 if(stagger_grid) call old_neighbors(child_igrid,child_ipe,igrid,ipe)
72
73 {do ic^db=1,2\}
74 ichild=child_igrid(ic^d)
75
76 ixcomin^d=ixmlo^d+(ic^d-1)*block_nx^d/2\
77 ixcomax^d=ixmhi^d+(ic^d-2)*block_nx^d/2\
78
79 xfimin^d=rnode(rpxmin^d_,ichild)\
80 dxfi^d=rnode(rpdx^d_,ichild)\
81 ^d&dxlevel(^d)=dxfi^d;
82 call prolong_2nd(ps(igrid),ixco^l,ps(ichild), &
83 dxco^d,xcomin^d,dxfi^d,xfimin^d,igrid,ichild)
84 !call prolong_1st(ps(igrid)%w,ixCo^L,ps(ichild)%w,ps(ichild)%x)
85 {end do\}
86
87 ! Convert parent back from prolongation space
88 block=>ps(igrid)
89 if(associated(phys_to_prolong)) then
90 call phys_from_prolong(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
91 else if (prolongprimitive) then
92 call phys_to_conserved(ixg^ll,ix^l,ps(igrid)%w,ps(igrid)%x)
93 end if
94
95 end subroutine prolong_grid
96
97 !> do 2nd order prolongation
98 subroutine prolong_2nd(sCo,ixCo^L,sFi,dxCo^D,xComin^D,dxFi^D,xFimin^D,igridCo,igridFi)
104
105 integer, intent(in) :: ixco^l, igridfi, igridco
106 double precision, intent(in) :: dxco^d, xcomin^d, dxfi^d, xfimin^d
107 type(state), intent(in) :: sco
108 type(state), intent(inout) :: sfi
109
110 double precision :: slopel, sloper, slopec, signc, signr
111 double precision :: slope(nw,ndim)
112 double precision :: eta^d
113 integer :: ixco^d, jxco^d, hxco^d, ixfi^d, ix^d, idim, iw, ixcg^l, el
114 logical :: fine_^l
115
116 associate(wco=>sco%w, wfi=>sfi%w)
117 ixcg^l=ixco^l;
118 {do ixco^db = ixcg^lim^db
119 ! lower left grid index in finer child block
120 ixfi^db=2*(ixco^db-ixcomin^db)+ixmlo^db\}
121
122 do idim=1,ndim
123 hxco^d=ixco^d-kr(^d,idim)\
124 jxco^d=ixco^d+kr(^d,idim)\
125
126 do iw=1,nw
127 slopel=wco(ixco^d,iw)-wco(hxco^d,iw)
128 sloper=wco(jxco^d,iw)-wco(ixco^d,iw)
129 slopec=half*(sloper+slopel)
130
131 ! get limited slope
132 signr=sign(one,sloper)
133 signc=sign(one,slopec)
134 !select case(prolong_limiter)
135 !case(1)
136 ! ! unlimited
137 ! slope(iw,idim)=slopeC
138 !case(2)
139 ! ! minmod
140 ! slope(iw,idim)=signR*max(zero,min(dabs(slopeR), &
141 ! signR*slopeL))
142 !case(3)
143 ! ! woodward
144 ! slope(iw,idim)=two*signR*max(zero,min(dabs(slopeR), &
145 ! signR*slopeL,signR*half*slopeC))
146 !case(4)
147 ! ! koren
148 ! slope(iw,idim)=signR*max(zero,min(two*signR*slopeL, &
149 ! (dabs(slopeR)+two*slopeL*signR)*third,two*dabs(slopeR)))
150 !case default
151 slope(iw,idim)=signc*max(zero,min(dabs(slopec), &
152 signc*slopel,signc*sloper))
153 !end select
154 end do
155 end do
156 ! cell-centered coordinates of coarse grid point
157 !^D&xCo^D=xCo({ixCo^DD},^D)
158 {do ix^db=ixfi^db,ixfi^db+1 \}
159 ! cell-centered coordinates of fine grid point
160 !^D&xFi^D=xFi({ix^DD},^D)
161 if(slab_uniform) then
162 ! normalized distance between fine/coarse cell center
163 ! in coarse cell: ranges from -0.5 to 0.5 in each direction
164 ! (origin is coarse cell center)
165 ! hence this is +1/4 or -1/4 on cartesian mesh
166 !eta^D=(xFi^D-xCo^D)*invdxCo^D;
167 eta^d=0.5d0*(dble(ix^d-ixfi^d)-0.5d0);
168 else
169 {! forefactor is -0.5d0 when ix=ixFi and +0.5d0 for ixFi+1
170 eta^d=(dble(ix^d-ixfi^d)-0.5d0)*(one-sfi%dvolume(ix^dd) &
171 /sum(sfi%dvolume(ixfi^d:ixfi^d+1^d%ix^dd))) \}
172 end if
173 wfi(ix^d,1:nw) = wco(ixco^d,1:nw) &
174 + {(slope(1:nw,^d)*eta^d)+}
175 {end do\}
176 {end do\}
177 if(stagger_grid) then
178 call already_fine(sfi,igridfi,fine_^l)
179 call prolong_2nd_stg(sco,sfi,ixco^l,ixm^ll,dxco^d,xcomin^d,dxfi^d,xfimin^d,.false.,fine_^l)
180 end if
181
182 ! Convert child cells from prolongation space to conserved.
183 block=>ps(igridfi)
184 if(associated(phys_from_prolong) .and. associated(phys_wb_prolong)) then
185 ! EoS-aware interpolation produced (rho, v, T) in the child cells.
186 ! WB is also active: re-balance pressure via the HSE recurrence so
187 ! the prolonged state preserves the discrete WB reference exactly.
188 ! (rho,v,T) -[from_prolong]-> (rho,m,E) -[to_primitive]-> (rho,v,p)
189 ! -[wb_prolong]-> (rho_eq, v, p_eq) -[to_conserved]-> (rho_eq, m, E_eq)
190 call phys_from_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
191 call phys_to_primitive(ixg^ll,ixm^ll,wfi,sfi%x)
192 call phys_wb_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
193 call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
194 else if(associated(phys_from_prolong)) then
195 ! EoS-aware only: (rho, v, T) -> (rho, rho*v, E) using EoS tables
196 call phys_from_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
197 else if(associated(phys_wb_prolong)) then
198 ! WB only: rebuild p from HSE recurrence using interpolated T = p/rho
199 if(.not. prolongprimitive .and. .not. associated(phys_to_prolong)) then
200 call phys_to_primitive(ixg^ll,ixm^ll,wfi,sfi%x)
201 end if
202 call phys_wb_prolong(ixg^ll,ixm^ll,wfi,sfi%x)
203 call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
204 else
205 if(prolongprimitive) call phys_to_conserved(ixg^ll,ixm^ll,wfi,sfi%x)
206 end if
207
208 ! Small-value repair runs here, after the conversion above, not before it. wFi is in
209 ! EoS prolongation space until then -- (rho, v, T), with T in the e_ slot and velocity in
210 ! the momentum slots -- whereas phys_handle_small_values is told the layout by
211 ! prolongprimitive, which is .false. here. Called earlier it therefore read T as total
212 ! energy and formed 0.5*v^2/rho instead of 0.5*m^2/rho, and with
213 ! small_values_method='replace' overwrote cells on the strength of that misreading.
214 ! Symptom: only the energy slot of newly refined blocks was destroyed (rho/m/Ne within 4%
215 ! of untouched blocks, e 5.7e6x too large), dt collapsing 1.9E-04 -> 2.7E-20 at the first
216 ! regrid. Invisible whenever fix_small_values=.false., because that skips this call.
217 if(fix_small_values) call phys_handle_small_values(prolongprimitive,wfi,sfi%x,ixg^ll,ixm^ll,'prolong_2nd')
218 end associate
219
220 end subroutine prolong_2nd
221
222 !> do 1st order prolongation
223 subroutine prolong_1st(wCo,ixCo^L,wFi,xFi)
225
226 integer, intent(in) :: ixco^l
227 double precision, intent(in) :: wco(ixg^t,nw), xfi(ixg^t,1:ndim)
228 double precision, intent(out) :: wfi(ixg^t,nw)
229
230 integer :: ixco^d, ixfi^d, iw
231 integer :: ixfi^l
232
233 {do ixco^db = ixco^lim^db
234 ixfi^db=2*(ixco^db-ixcomin^db)+ixmlo^db\}
235 forall(iw=1:nw) wfi(ixfi^d:ixfi^d+1,iw)=wco(ixco^d,iw)
236 {end do\}
237
238 end subroutine prolong_1st
239
240end 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...
type(state), pointer block
Block pointer for using one block and its previous state.
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:54
procedure(sub_small_values), pointer phys_handle_small_values
Definition mod_physics.t:86
procedure(sub_wb_prolong), pointer phys_wb_prolong
Definition mod_physics.t:61
procedure(sub_convert), pointer phys_to_prolong
Definition mod_physics.t:57
procedure(sub_convert), pointer phys_to_conserved
Definition mod_physics.t:53
procedure(sub_convert), pointer phys_from_prolong
Definition mod_physics.t:58
subroutine, public refine_grids(child_igrid, child_ipe, igrid, ipe, active)
refine one block to its children blocks
Definition mod_refine.t:13