3#include "../afivo/src/cpp_macros.h"
22 real(dp),
protected :: refine_adx = 1.0_dp
25 real(dp),
protected :: refine_adx_fac = 1.0_dp
28 real(dp),
protected :: refine_cphi = 1e99_dp
31 real(dp),
protected :: derefine_cphi = 1e99_dp
34 real(dp),
protected :: derefine_dx = 1e-4_dp
37 real(dp),
protected :: refine_init_time = 10e-9_dp
40 real(dp),
protected :: refine_init_fac = 0.25_dp
57 real(dp),
protected :: refine_min_dens = -1.0e99_dp
60 real(dp),
protected,
allocatable :: refine_regions_dr(:)
63 real(dp),
protected,
allocatable :: refine_regions_tstop(:)
66 real(dp),
protected,
allocatable :: refine_regions_rmin(:,:)
69 real(dp),
protected,
allocatable :: refine_regions_rmax(:,:)
72 real(dp),
protected,
allocatable :: refine_limits_dr(:)
75 real(dp),
protected,
allocatable :: refine_limits_rmin(:,:)
78 real(dp),
protected,
allocatable :: refine_limits_rmax(:,:)
81 logical,
protected :: refine_use_alpha_effective
96 type(cfg_t),
intent(inout) :: cfg
99 real(dp),
allocatable :: dbuffer(:)
103 "The refinement buffer width in cells (around flagged cells)")
105 "The number of steps after which the mesh is updated")
107 "The grid spacing will always be larger than this value (m)")
109 "The grid spacing will always be smaller than this value (m)")
110 call cfg_add_get(cfg,
"refine_adx", refine_adx, &
111 "Refine if alpha*dx is larger than this value")
112 call cfg_add_get(cfg,
"derefine_dx", derefine_dx, &
113 "Only derefine if grid spacing if smaller than this value")
114 call cfg_add_get(cfg,
"refine_init_time", refine_init_time, &
115 "Refine around initial conditions up to this time")
116 call cfg_add_get(cfg,
"refine_init_fac", refine_init_fac, &
117 "Refine until dx is smaller than this factor times the seed width")
119 "Ensure grid spacing around electrode is less than this value (m)")
123 error stop
"Cannot have refine_min_dx < refine_max_dx"
127 call cfg_add_get(cfg,
"refine_adx_fac", refine_adx_fac, &
128 "For refinement, use alpha(f * E)/f, where f is this factor")
129 call cfg_add_get(cfg,
"refine_cphi", refine_cphi, &
130 "Refine if the curvature in phi is larger than this value")
131 call cfg_add_get(cfg,
"derefine_cphi", derefine_cphi, &
132 "Allow derefinement if the curvature in phi is smaller than this value")
134 call cfg_add_get(cfg,
"electrode_derefine_factor", &
136 "Multiplication factor to derefine electrode during interpulse")
138 "Start refining electrode some time before the start of a new pulse")
139 call cfg_add_get(cfg,
"refine_min_dens", refine_min_dens, &
140 "Minimum electron density for adding grid refinement")
141 call cfg_add_get(cfg,
"refine_use_alpha_effective", refine_use_alpha_effective, &
142 "Use effective alpha (minus attachment) for refinement")
144 call cfg_add(cfg,
"refine_regions_dr", [1.0e99_dp], &
145 "Refine regions up to this grid spacing (m)", .true.)
146 call cfg_add(cfg,
"refine_regions_tstop", [1.0e99_dp], &
147 "Refine regions up to this simulation time", .true.)
149 call cfg_add(cfg,
"refine_regions_rmin", vec, &
150 "Minimum coordinate of the refinement regions", .true.)
151 call cfg_add(cfg,
"refine_regions_rmax", vec, &
152 "Maximum coordinate of the refinement regions", .true.)
154 call cfg_get_size(cfg,
"refine_regions_dr", n)
155 allocate(refine_regions_dr(n))
156 allocate(refine_regions_tstop(n))
157 allocate(refine_regions_rmin(ndim, n))
158 allocate(refine_regions_rmax(ndim, n))
159 allocate(dbuffer(ndim * n))
161 call cfg_get(cfg,
"refine_regions_dr", refine_regions_dr)
162 call cfg_get(cfg,
"refine_regions_tstop", refine_regions_tstop)
163 call cfg_get(cfg,
"refine_regions_rmin", dbuffer)
164 refine_regions_rmin = reshape(dbuffer, [ndim, n])
165 call cfg_get(cfg,
"refine_regions_rmax", dbuffer)
166 refine_regions_rmax = reshape(dbuffer, [ndim, n])
168 call cfg_add(cfg,
"refine_limits_dr", [1.0e99_dp], &
169 "Refine regions at most up to this grid spacing", .true.)
171 call cfg_add(cfg,
"refine_limits_rmin", vec, &
172 "Minimum coordinate of the refinement limits", .true.)
173 call cfg_add(cfg,
"refine_limits_rmax", vec, &
174 "Maximum coordinate of the refinement limits", .true.)
176 call cfg_get_size(cfg,
"refine_limits_dr", n)
177 allocate(refine_limits_dr(n))
178 allocate(refine_limits_rmin(ndim, n))
179 allocate(refine_limits_rmax(ndim, n))
181 allocate(dbuffer(ndim * n))
183 call cfg_get(cfg,
"refine_limits_dr", refine_limits_dr)
184 call cfg_get(cfg,
"refine_limits_rmin", dbuffer)
185 refine_limits_rmin = reshape(dbuffer, [ndim, n])
186 call cfg_get(cfg,
"refine_limits_rmax", dbuffer)
187 refine_limits_rmax = reshape(dbuffer, [ndim, n])
198 subroutine default_refinement(box, cell_flags)
205 type(box_t),
intent(in) :: box
207 integer,
intent(out) :: &
208 cell_flags(dtimes(box%n_cell))
209 integer :: ijk, n, nc
210 real(dp) :: min_dx, max_dx, gas_dens
211 real(dp) :: alpha, adx, fld, elec_dens
212 real(dp) :: dist, rmin(ndim), rmax(ndim)
215 min_dx = minval(box%dr)
216 max_dx = maxval(box%dr)
226 if (refine_use_alpha_effective)
then
229 gas_dens / refine_adx_fac
230 alpha = max(0.0_dp, alpha)
233 gas_dens / refine_adx_fac
239 if (adx > refine_adx .and. elec_dens > refine_min_dens)
then
240 cell_flags(ijk) = af_do_ref
241 else if (adx < 0.125_dp * refine_adx .and. max_dx < derefine_dx)
then
242 cell_flags(ijk) = af_rm_ref
244 cell_flags(ijk) = af_keep_ref
253 if (dist -
init_conds%seed_width(n) < 2 * max_dx &
254 .and. max_dx > refine_init_fac * &
256 cell_flags(ijk) = af_do_ref
262 if (iand(box%tag, mg_lsf_box) > 0 .and. &
264 cell_flags(ijk) = af_do_ref
270 rmax = box%r_min + box%dr * box%n_cell
272 do n = 1,
size(refine_regions_dr)
273 if (global_time <= refine_regions_tstop(n) .and. &
274 max_dx > refine_regions_dr(n) .and. all(&
275 rmax >= refine_regions_rmin(:, n) .and. &
276 rmin <= refine_regions_rmax(:, n)))
then
278 cell_flags(dtimes(nc/2)) = af_do_ref
282 do n = 1,
size(refine_limits_dr)
283 if (max_dx < 2 * refine_limits_dr(n) .and. all(&
284 rmin >= refine_limits_rmin(:, n) .and. &
285 rmax <= refine_limits_rmax(:, n)))
then
287 where (cell_flags == af_do_ref) cell_flags = af_keep_ref
293 cell_flags = af_do_ref
295 where(cell_flags == af_do_ref) cell_flags = af_keep_ref
298 end subroutine default_refinement
Module that stores parameters related to the gas.
integer, public, protected i_gas_dens
real(dp), parameter, public si_to_townsend
logical, public, protected gas_constant_density
Whether the gas has a constant density.
real(dp), public, protected gas_number_density
Module that provides routines for geometric operations and calculations. Methods and types have a pre...
real(dp) function, public gm_dist_line(r, r0, r1, n_dim)
Module to help setting up initial conditions.
type(initcnd_t), public, protected init_conds
Module with grid refinement settings and routines.
integer, public, protected refine_buffer_width
subroutine, public refine_initialize(cfg)
Initialize the grid refinement options.
real(dp), public current_electrode_dx
real(dp), public refine_electrode_dx
real(dp), public, protected refine_prepulse_time
integer, public, protected refine_per_steps
real(dp), public, protected refine_min_dx
procedure(af_subr_ref), pointer, public refine_routine
real(dp), public, protected electrode_derefine_factor
real(dp), public, protected refine_max_dx
This module contains several pre-defined variables like:
real(dp), public global_time
Global time.
integer, public, protected i_electron
Index of electron density.
integer, public, protected i_electric_fld
Index of electric field norm.
Module that provides routines for reading in arbritrary transport data.
type(lt_t), public, protected td_tbl
integer, parameter, public td_eta
Attachment coefficient.
integer, parameter, public td_alpha
Ionization coefficient.
This module contains all the methods that users can customize.
procedure(af_subr_ref), pointer user_refine
User-defined refinement routine.