Example showing how to include a dielectric object. Warning: the functionality is not fully ready
1 #include "../src/cpp_macros.h"
6 program dielectric_test
12 integer,
parameter :: box_size = 8
13 integer,
parameter :: n_iterations = 10
20 double precision,
parameter :: epsilon_high = 10.0_dp
23 type(ref_info_t) :: ref_info
26 character(len=100) :: fname
28 integer :: count_rate, t_start, t_end
30 print *,
"****************************************"
31 print *,
"Warning: functionality demonstrated here is not fully ready"
32 print *,
"For large epsilon, convergence will probably be slow"
33 print *,
"****************************************"
34 print *,
"Number of threads", af_get_max_threads()
36 call af_add_cc_variable(tree,
"phi", ix=i_phi)
37 call af_add_cc_variable(tree,
"rhs", ix=i_rhs)
38 call af_add_cc_variable(tree,
"tmp", ix=i_tmp)
39 call af_add_cc_variable(tree,
"eps", ix=i_eps)
47 call af_print_info(tree)
49 call system_clock(t_start, count_rate)
52 call af_loop_box(tree, set_init_cond)
55 call af_adjust_refinement(tree, ref_routine, ref_info)
58 if (ref_info%n_add == 0)
exit
60 call system_clock(t_end, count_rate)
65 call af_restrict_tree(tree, [i_eps])
67 write(*,
"(A,Es10.3,A)")
" Wall-clock time generating AMR grid: ", &
68 (t_end-t_start) / real(count_rate,dp),
" seconds"
70 call af_print_info(tree)
77 mg%sides_bc => sides_bc
83 call mg_init(tree, mg)
85 print *,
"Multigrid iteration | max residual | max error"
86 call system_clock(t_start, count_rate)
88 do mg_iter = 1, n_iterations
92 call mg_fas_fmg(tree, mg, .true., mg_iter>1)
95 call af_tree_min_cc(tree, i_tmp, residu(1))
96 call af_tree_max_cc(tree, i_tmp, residu(2))
97 write(*,
"(I8,Es14.5)") mg_iter, maxval(abs(residu))
99 write(fname,
"(A,I0)")
"output/dielectric_" // dimname //
"_", mg_iter
100 call af_write_silo(tree, trim(fname))
102 call system_clock(t_end, count_rate)
104 write(*,
"(A,I0,A,E10.3,A)") &
105 " Wall-clock time after ", n_iterations, &
106 " iterations: ", (t_end-t_start) / real(count_rate, dp), &
111 call af_destroy(tree)
116 subroutine ref_routine(box, cell_flags)
117 type(box_t),
intent(in) :: box
118 integer,
intent(out) :: cell_flags(DTIMES(box%n_cell))
119 real(dp) :: eps_min, eps_max
121 eps_min = minval(box%cc(dtimes(:), i_eps))
122 eps_max = maxval(box%cc(dtimes(:), i_eps))
124 if ((box%lvl < 5 .and. eps_max > eps_min) .or. box%lvl < 2)
then
125 cell_flags(dtimes(:)) = af_do_ref
127 cell_flags(dtimes(:)) = af_keep_ref
129 end subroutine ref_routine
132 subroutine set_init_cond(box)
133 type(box_t),
intent(inout) :: box
136 real(dp) :: ellips_fac(NDIM)
141 ellips_fac(2:) = 3.0_dp
142 ellips_fac(1) = 1.0_dp
145 rr = af_r_cc(box, [ijk])
148 if (norm2((rr - 0.5_dp) * ellips_fac) < 0.25_dp)
then
149 box%cc(ijk, i_eps) = epsilon_high
151 box%cc(ijk, i_eps) = 1.0_dp
154 box%cc(ijk, i_rhs) = 0.0d0
155 box%cc(ijk, i_phi) = 0.0d0
158 end subroutine set_init_cond
161 subroutine sides_bc(box, nb, iv, coords, bc_val, bc_type)
162 type(box_t),
intent(in) :: box
163 integer,
intent(in) :: nb
164 integer,
intent(in) :: iv
165 real(dp),
intent(in) :: coords(NDIM, box%n_cell**(NDIM-1))
166 real(dp),
intent(out) :: bc_val(box%n_cell**(NDIM-1))
167 integer,
intent(out) :: bc_type
174 case (af_neighb_lowx)
175 bc_type = af_bc_dirichlet
177 case (af_neighb_highx)
178 bc_type = af_bc_dirichlet
181 bc_type = af_bc_neumann
184 end subroutine sides_bc
186 end program dielectric_test
Module which contains all Afivo modules, so that a user does not have to include them separately.
This module can be used to construct solutions consisting of one or more Gaussians.