MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_initialize.t
Go to the documentation of this file.
1!> This module handles the initialization of various components of amrvac
3 use mod_comm_lib, only: mpistop
4
5 implicit none
6 private
7
8 logical :: initialized_already = .false.
9
10 ! Public methods
11 public :: initialize_amrvac
12
13contains
14
15 !> Initialize amrvac: read par files and initialize variables
16 subroutine initialize_amrvac()
21 use mod_bc_data, only: bc_data_init
24 use mod_eos, only: eos
25
26 if (initialized_already) return
27
28 ! Check whether the user has loaded a physics module
29 call phys_check()
30
31 ! Read input files
32 call read_par_files()
33 call initialize_vars()
34 call init_comm_types()
35
36 ! Possibly load boundary condition data or initial data
37 call bc_data_init()
38 call read_data_init()
39
40 if(associated(usr_set_parameters)) call usr_set_parameters()
41
43
44 !> Lock (runs just after usr_set_parameters): gamma must be set via the parfile
45 !> (&eos_list gamma=) so eos_init refreshes the cached derived constants. A direct
46 !> eos%gamma assignment in user code leaves inv_gamma_minus_1 stale. Kept here, out
47 !> of the hot physics modules, so this guard never perturbs flux-routine codegen.
48 if (eos%gamma > 0.0d0 .and. eos%gamma /= 1.0d0) then
49 if (abs(eos%inv_gamma_minus_1*(eos%gamma-1.0d0) - 1.0d0) > 1.0d-10) &
50 call mpistop("eos%gamma derived constants are stale: set gamma via "// &
51 "&eos_list gamma= in the parfile, not by assigning eos%gamma directly")
52 end if
53
54 initialized_already = .true.
55 end subroutine initialize_amrvac
56
57 !> Initialize (and allocate) simulation and grid variables
58 subroutine initialize_vars
59 use mod_forest
62 use mod_fix_conserve, only: pflux
64 use mod_geometry
65
66 integer :: igrid, level, ipe, ig^d
67 logical :: ok
68
69 allocate(ps(max_blocks))
70 allocate(ps1(max_blocks))
71 allocate(ps2(max_blocks))
72 allocate(ps3(max_blocks))
73 allocate(ps4(max_blocks))
74 allocate(psc(max_blocks))
75 allocate(ps_sub(max_blocks))
76 allocate(neighbor(2,-1:1^d&,max_blocks),neighbor_child(2,0:3^d&,max_blocks))
77 allocate(neighbor_type(-1:1^d&,max_blocks),neighbor_active(-1:1^d&,max_blocks))
78 allocate(neighbor_pole(-1:1^d&,max_blocks))
79 allocate(igrids(max_blocks),igrids_active(max_blocks),igrids_passive(max_blocks))
82 allocate(pflux(2,^nd,max_blocks))
83 ! allocate mesh for particles
84 if(use_particles) allocate(gridvars(max_blocks))
85 if(stagger_grid) then
86 allocate(pface(2,^nd,max_blocks),fine_neighbors(2^d&,^nd,max_blocks))
87 allocate(old_neighbor(2,-1:1^d,max_blocks))
88 end if
89
92
93 dt=zero
94
95 ! no poles initially
96 neighbor_pole=0
97
98 ! check resolution
99 if ({mod(ixghi^d,2)/=0|.or.}) then
100 call mpistop("mesh widths must give even number grid points")
101 end if
102 ixm^ll=ixg^ll^lsubnghostcells;
103
104 if (nbufferx^d>(ixmhi^d-ixmlo^d+1)|.or.) then
105 write(unitterm,*) "nbufferx^D bigger than mesh size makes no sense."
106 write(unitterm,*) "Decrease nbufferx or increase mesh size"
107 call mpistop("")
108 end if
109
110 ! initialize dx arrays on finer (>1) levels
111 do level=2,refine_max_level
112 {dx(^d,level) = dx(^d,level-1) * half\} ! refine ratio 2
113 end do
114
115 ! domain decomposition
116 ! physical extent of a grid block at level 1, per dimension
117 ^d&dg^d(1)=dx(^d,1)*dble(block_nx^d)\
118 ! number of grid blocks at level 1 in simulation domain, per dimension
119 ^d&ng^d(1)=nint((xprobmax^d-xprobmin^d)/dg^d(1))\
120 ! total number of grid blocks at level 1
121 nglev1={ng^d(1)*}
122
123 do level=2,refine_max_level
124 dg^d(level)=half*dg^d(level-1);
125 ng^d(level)=ng^d(level-1)*2;
126 end do
127
128 ! check that specified stepsize correctly divides domain
129 ok=({(abs(dble(ng^d(1))*dg^d(1)-(xprobmax^d-xprobmin^d))<=smalldouble)|.and.})
130 if (.not.ok) then
131 write(unitterm,*)"domain cannot be divided by meshes of given gridsize"
132 call mpistop("domain cannot be divided by meshes of given gridsize")
133 end if
134
135 poleb=.false.
136 if (.not.slab) call set_pole
137
138 ! number of grid blocks at level 1 along a dimension, which does not have a pole or periodic boundary,
139 ! must be larger than 1 for a rectangular AMR mesh
140 if(({ng^d(1)/=1|.or.}).and.refine_max_level>1) then
141 {
142 if(ng^d(1)==1.and..not.poleb(1,^d).and.&
143 .not.poleb(2,^d).and..not.periodb(^d).and..not.aperiodb(^d)) then
144 write(unitterm,"(a,i2,a)") "number of grid blocks at level 1 in dimension",^d,&
145 " be larger than 1 for a rectangular AMR mesh!"
146 write(unitterm,"(a,i1)") "increase domain_nx",^d
147 call mpistop("")
148 end if
149 \}
150 end if
151
152 ! initialize connectivity data
153 igridstail=0
154
155 ! allocate memory for forest data structures
157 do level=1,refine_max_level
158 nullify(level_head(level)%node,level_tail(level)%node)
159 end do
160
161 allocate(igrid_to_node(max_blocks,0:npe-1))
162 do ipe=0,npe-1
163 do igrid=1,max_blocks
164 nullify(igrid_to_node(igrid,ipe)%node)
165 end do
166 end do
167
168 allocate(sfc(1:3,max_blocks*npe))
169
170 allocate(igrid_to_sfc(max_blocks))
171
172 sfc=0
173 ! Cost-weighted load balancer arrays. costlist is global Morton-indexed
174 ! (sized to max_blocks*npe, the upper bound on nleafs); cold-start to 1.0
175 ! so the first partition equals the equal-block-count cut. block_cost is
176 ! the per-step scratch accumulator (per-rank, per-igrid), reset every
177 ! advance.
178 allocate(costlist(max_blocks*npe))
179 allocate(block_cost(max_blocks))
180 costlist = 1.0d0
181 block_cost = 0.0d0
182 allocate(morton_start(0:npe-1),morton_stop(0:npe-1))
183 allocate(morton_sub_start(0:npe-1),morton_sub_stop(0:npe-1))
184
185 allocate(nleafs_level(1:nlevelshi))
186
187 allocate(coarsen(max_blocks,0:npe-1),refine(max_blocks,0:npe-1))
188 coarsen=.false.
189 refine=.false.
190 if (nbufferx^d/=0|.or.) then
191 allocate(buffer(max_blocks,0:npe-1))
192 buffer=.false.
193 end if
194 allocate(igrid_inuse(max_blocks,0:npe-1))
195 igrid_inuse=.false.
196
197 allocate(tree_root(1:ng^d(1)))
198 {do ig^db=1,ng^db(1)\}
199 nullify(tree_root(ig^d)%node)
200 {end do\}
201
202 ! define index ranges and MPI send/receive derived datatype for ghost-cell swap
203 call init_bc()
204 type_send_srl=>type_send_srl_f
205 type_recv_srl=>type_recv_srl_f
206 type_send_r=>type_send_r_f
207 type_recv_r=>type_recv_r_f
208 type_send_p=>type_send_p_f
209 type_recv_p=>type_recv_p_f
210 call create_bc_mpi_datatype(iwstart,nwgc)
211
212 end subroutine initialize_vars
213
214
215end module mod_initialize
type(fake_neighbors), dimension(:^d &,:,:), allocatable, public fine_neighbors
Definition mod_amr_fct.t:16
integer, dimension(:,:^d &,:), allocatable, public old_neighbor
Definition mod_amr_fct.t:18
type(facealloc), dimension(:,:,:), allocatable, public pface
Definition mod_amr_fct.t:14
Module to set boundary conditions from user data.
Definition mod_bc_data.t:2
subroutine, public bc_data_init()
Definition mod_bc_data.t:46
subroutine, public init_comm_types
Create and store the MPI types that will be used for parallel communication.
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Equation of state for AMRVAC, handled through a single eos_container object.
Definition mod_eos.t:30
Module for flux conservation near refinement boundaries.
type(fluxalloc), dimension(:,:,:), allocatable, public pflux
store flux to fix conservation
Module with basic grid data structures.
Definition mod_forest.t:2
integer, dimension(:), allocatable, save nleafs_level
How many leaves are present per refinement level.
Definition mod_forest.t:81
logical, dimension(:,:), allocatable, save refine
Definition mod_forest.t:70
integer, dimension(:), allocatable, save morton_start
First Morton number per processor.
Definition mod_forest.t:62
integer, dimension(:), allocatable, save morton_sub_start
Definition mod_forest.t:67
logical, dimension(:,:), allocatable, save buffer
Definition mod_forest.t:70
logical, dimension(:,:), allocatable, save igrid_inuse
Definition mod_forest.t:70
integer, dimension(:), allocatable, save igrid_to_sfc
Go from a grid index to Morton number (for a single processor)
Definition mod_forest.t:56
integer nglev1
Definition mod_forest.t:78
integer, dimension(:), allocatable, save morton_sub_stop
Definition mod_forest.t:67
logical, dimension(:,:), allocatable, save coarsen
AMR flags and grids-in-use identifier per processor (igrid,ipe)
Definition mod_forest.t:70
type(tree_node_ptr), dimension(:), allocatable, save level_tail
The tail pointer of the linked list per refinement level.
Definition mod_forest.t:38
integer, dimension(:), allocatable, save morton_stop
Last Morton number per processor.
Definition mod_forest.t:65
type(tree_node_ptr), dimension(:^d &), allocatable, save tree_root
Pointers to the coarse grid.
Definition mod_forest.t:29
integer, dimension(:,:), allocatable, save sfc
Array to go from a Morton number to an igrid and processor index. Sfc(1:3, MN) contains [igrid,...
Definition mod_forest.t:43
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
type(tree_node_ptr), dimension(:), allocatable, save level_head
The head pointer of the linked list per refinement level.
Definition mod_forest.t:35
Module with geometry-related routines (e.g., divergence, curl)
Definition mod_geometry.t:2
subroutine set_pole
update ghost cells of all blocks including physical boundaries
This module contains definitions of global parameters and variables and some generic functions/subrou...
logical, dimension(ndim) aperiodb
True for dimensions with aperiodic boundaries.
integer ixghi
Upper index of grid block arrays.
double precision, dimension(:), allocatable costlist
Persistent global per-Morton-leaf EWMA cost. Sized to max_blocks*npe (the upper bound on nleafs); onl...
double precision, dimension(:), allocatable block_cost
Per-step per-block (per-rank, indexed by igrid) cost accumulator. Reset at start of each advance call...
double precision global_time
The global simulation time.
double precision time_init
Start time for the simulation.
integer it
Number of time steps taken.
double precision, dimension(:), allocatable dg
extent of grid blocks in domain per dimension, in array over levels
integer it_init
initial iteration count
integer, parameter nlevelshi
The maximum number of levels in the grid refinement.
logical stagger_grid
True for using stagger grid.
logical, dimension(:), allocatable phyboundblock
True if a block has any physical boundary.
logical use_particles
Use particles module or not.
integer, dimension(:), allocatable ng
number of grid blocks in domain per dimension, in array over levels
integer block_nx
number of cells for each dimension in grid block excluding ghostcells
double precision dt
global time step
integer, parameter nodehi
grid hierarchy info (level and grid indices)
double precision, dimension(:), allocatable, parameter d
logical slab
Cartesian geometry or not.
integer npe
The number of MPI tasks.
integer, parameter unitterm
Unit for standard output.
logical, dimension(ndim) periodb
True for dimensions with periodic boundaries.
double precision, dimension(:,:), allocatable rnode
Corner coordinates.
integer nbufferx
Number of cells as buffer zone.
double precision, dimension(:,:), allocatable dx
spatial steps for all dimensions at all levels
double precision, dimension(:,:), allocatable rnode_sub
integer, parameter rnodehi
grid location info (corner coordinates and grid spacing)
integer refine_max_level
Maximal number of AMR levels.
integer max_blocks
The maximum number of grid blocks in a processor.
logical, dimension(2, ndim) poleb
Indicates whether there is a pole at a boundary.
integer, dimension(:,:), allocatable node
integer, dimension(:,:), allocatable node_sub
Module to set (or derive) initial conditions from user data We read in a vtk file that provides value...
subroutine, public read_data_init()
This module handles the initialization of various components of amrvac.
subroutine, public initialize_amrvac()
Initialize amrvac: read par files and initialize variables.
Module for reading input and writing output.
subroutine read_par_files()
Read in the user-supplied parameter-file.
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition mod_physics.t:4
procedure(sub_check_params), pointer phys_check_params
Definition mod_physics.t:49
subroutine phys_check()
Module with all the methods that users can customize in AMRVAC.
procedure(p_no_args), pointer usr_set_parameters
Initialize the user's settings (after initializing amrvac)