3#include "../afivo/src/cpp_macros.h"
14 real(dp) :: background_density
15 real(dp) :: stochastic_density
17 real(dp),
allocatable :: seed_r0(:, :)
18 real(dp),
allocatable :: seed_r1(:, :)
19 real(dp),
allocatable :: seed_density(:)
20 real(dp),
allocatable :: seed_density2(:)
21 integer,
allocatable :: seed_charge_type(:)
22 real(dp),
allocatable :: seed_width(:)
23 character(string_len),
allocatable :: seed_falloff(:)
24 integer,
allocatable :: seed1_species(:)
25 integer,
allocatable :: background_species(:)
40 type(af_t),
intent(in) :: tree
41 type(cfg_t),
intent(inout) :: cfg
43 integer :: n, n_cond, varsize, empty_int(0)
44 real(dp) :: empty_real(0)
45 real(dp),
allocatable :: tmp_vec(:)
46 character(len=name_len) :: empty_string(0)
47 character(len=name_len),
allocatable :: seed_species(:)
48 character(len=name_len),
allocatable :: background_species(:)
51 call cfg_add(cfg,
"background_density", 0.0_dp, &
52 "The background ion and electron density (1/m3)")
53 call cfg_add(cfg,
"stochastic_density", 0.0_dp, &
54 "Stochastic background density (1/m3)")
55 call cfg_add(cfg,
"seed_density", empty_real, &
56 "Initial density of the seed (1/m3)", .true.)
57 call cfg_add(cfg,
"seed_rel_r0", empty_real, &
58 "The relative start position of the initial seed", .true.)
59 call cfg_add(cfg,
"seed_rel_r1", empty_real, &
60 "The relative end position of the initial seed", .true.)
61 call cfg_add(cfg,
"seed_charge_type", empty_int, &
62 "Type of seed: neutral (0), ions (1) or electrons (-1)", .true.)
63 call cfg_add(cfg,
"seed_width", empty_real, &
64 "Seed width (m)", .true.)
65 call cfg_add(cfg,
"seed_falloff", empty_string, &
66 "Fall-off type for seed (sigmoid, gaussian, smoothstep, step, laser)", .true.)
67 call cfg_add(cfg,
"seed1_species", empty_string, &
68 "Names of custom species for the first seed", .true.)
69 call cfg_add(cfg,
"background_species", empty_string, &
70 "Names of custom species for the background density", .true.)
72 call cfg_get_size(cfg,
"seed_density", n_cond)
75 call cfg_get_size(cfg,
"seed_rel_r0", varsize)
76 if (varsize /= ndim * n_cond) &
77 stop
"seed_rel_r0 variable has incompatible size"
79 call cfg_get_size(cfg,
"seed_rel_r1", varsize)
80 if (varsize /= ndim * n_cond) &
81 stop
"seed_rel_r1 variable has incompatible size"
83 call cfg_get_size(cfg,
"seed_charge_type", varsize)
84 if (varsize /= n_cond) &
85 stop
"seed_charge_type variable has incompatible size"
87 call cfg_get_size(cfg,
"seed_width", varsize)
88 if (varsize /= n_cond) &
89 stop
"seed_width variable has incompatible size"
91 allocate(ic%seed_density(n_cond))
92 allocate(ic%seed_density2(n_cond))
93 allocate(ic%seed_charge_type(n_cond))
94 allocate(ic%seed_r0(ndim, n_cond))
95 allocate(ic%seed_r1(ndim, n_cond))
96 allocate(ic%seed_width(n_cond))
97 allocate(ic%seed_falloff(n_cond))
99 allocate(tmp_vec(ndim * n_cond))
100 call cfg_get(cfg,
"seed_rel_r0", tmp_vec)
101 ic%seed_r0 = reshape(tmp_vec, [ndim, n_cond])
102 call cfg_get(cfg,
"seed_rel_r1", tmp_vec)
103 ic%seed_r1 = reshape(tmp_vec, [ndim, n_cond])
110 call cfg_get(cfg,
"background_density", ic%background_density)
111 call cfg_get(cfg,
"stochastic_density", ic%stochastic_density)
112 call cfg_get(cfg,
"seed_density", ic%seed_density)
113 call cfg_get(cfg,
"seed_charge_type", ic%seed_charge_type)
114 call cfg_get(cfg,
"seed_width", ic%seed_width)
115 call cfg_get(cfg,
"seed_falloff", ic%seed_falloff)
118 call cfg_add(cfg,
"seed_density2", ic%seed_density, &
119 "Initial density of the seed at other endpoint (1/m3)")
120 call cfg_get(cfg,
"seed_density2", ic%seed_density2)
122 call cfg_get_size(cfg,
"seed1_species", varsize)
123 if (varsize > 0)
then
124 allocate(seed_species(varsize))
125 allocate(ic%seed1_species(varsize))
126 call cfg_get(cfg,
"seed1_species", seed_species)
128 ic%seed1_species(n) = af_find_cc_variable(tree, seed_species(n))
132 call cfg_get_size(cfg,
"background_species", varsize)
133 if (varsize > 0)
then
134 allocate(background_species(varsize))
135 allocate(ic%background_species(varsize))
136 call cfg_get(cfg,
"background_species", background_species)
138 ic%background_species(n) = af_find_cc_variable(tree, background_species(n))
149 use m_af_ghostcell,
only: af_bc_neumann_zero
151 type(af_t),
intent(inout) :: tree
152 integer :: my_lvl, lvl, i, id
154 if (
init_conds%stochastic_density <= 0.0_dp)
return
158 do my_lvl = 1, tree%highest_lvl
159 if (
size(tree%lvls(my_lvl)%leaves) > 0)
exit
163 call af_tree_clear_cc(tree,
i_rhs)
165 do i = 1,
size(tree%lvls(my_lvl)%ids)
166 id = tree%lvls(my_lvl)%ids(i)
167 call set_stochastic_density(tree%boxes(id))
172 do lvl = my_lvl, tree%highest_lvl-1
173 do i = 1,
size(tree%lvls(lvl)%parents)
174 id = tree%lvls(lvl)%parents(i)
175 call af_gc_box(tree, id, [
i_rhs])
178 do i = 1,
size(tree%lvls(lvl)%parents)
179 id = tree%lvls(lvl)%parents(i)
180 call af_prolong_linear_from(tree%boxes, id,
i_rhs, add=.true.)
186 do lvl = my_lvl, tree%highest_lvl
187 do i = 1,
size(tree%lvls(lvl)%ids)
188 id = tree%lvls(lvl)%ids(i)
200 subroutine set_stochastic_density(box)
203 type(box_t),
intent(inout) :: box
204 integer :: proc_id, ijk
207 proc_id = 1+omp_get_thread_num()
209 do kji_do(1,box%n_cell)
210 density =
st_prng%rngs(proc_id)%unif_01() * &
212 box%cc(ijk,
i_rhs) = density
214 end subroutine set_stochastic_density
222 type(box_t),
intent(inout) :: box
223 integer :: ijk, n, nc
229 if (
allocated(
init_conds%background_species))
then
230 box%cc(dtimes(:),
init_conds%background_species) = &
238 rr = af_r_cc(box, [ijk])
265 if (n == 1 .and.
allocated(
init_conds%seed1_species))
then
267 box%cc(ijk,
init_conds%seed1_species) + density
279 error stop
"Invalid seed_charge_type"
285 if (box%cc(ijk,
i_lsf) <= 0)
then
Module for handling chemical reactions.
Module that stores parameters related to the gas.
real(dp), public, protected gas_molecular_weight
real(dp), public, protected gas_euler_gamma
logical, public, protected gas_dynamics
Whether the gas dynamics are simulated.
integer, public, protected i_gas_dens
integer, dimension(ndim), parameter, public i_mom
real(dp), public, protected gas_pressure
integer, dimension(n_vars_euler), public, protected gas_vars
integer, parameter, public i_e
integer, parameter, public i_rho
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_density_line(r, r0, r1, n_0, n_1, n_dim, width, falloff_t)
Module to help setting up initial conditions.
subroutine, public init_cond_stochastic_density(tree)
Add a stochastic background density to the electrons and ions. Note: this routine temporarily uses va...
type(initcnd_t), public, protected init_conds
subroutine, public init_cond_set_box(box)
Sets the initial condition.
subroutine, public init_cond_initialize(tree, cfg)
Set the initial conditions from the configuration.
This module contains several pre-defined variables like:
logical, public, protected st_use_electrode
Whether to include an electrode.
integer, public, protected i_lsf
Index can be set to include an electrode.
integer, public, protected i_electron
Index of electron density.
integer, public, protected i_rhs
Index of source term Poisson.
integer, public, protected i_1pos_ion
Index of first positive ion species.
real(dp), dimension(ndim), public, protected st_domain_len
Domain length per dimension.
real(dp), dimension(ndim), public, protected st_domain_origin
Origin of domain.
integer, dimension(:), allocatable, public, protected all_densities
Index of all densities that evolve in time.
type(prng_t), public st_prng
Parallel random number generator.
This module contains all the methods that users can customize.
procedure(gas_dens_func), pointer user_gas_density
To set a user-defined gas number density.