1 #include "../src/cpp_macros.h"
3 program solid_body_rotation
7 integer,
parameter :: ncells = 8
9 integer,
parameter :: coord_type = af_xyz
10 real(dp) :: l_max(NDIM), l_min(NDIM)
12 logical :: periodicBC(NDIM)
16 real(dp) :: dt, time, end_time
17 integer :: time_steps, t_iter
18 character(len=100) :: fname
19 print *,
"Running solid body rotation 2D"
20 print *,
"Number of threads", af_get_max_threads()
26 periodicbc(:) = .false.
30 call af_add_cc_variable(tree,
"q", ix=iq)
31 call af_add_fc_variable(tree,
"flux", ix=i_flux)
32 call af_set_cc_methods(tree, iq, af_bc_dirichlet_zero)
34 call af_init(tree, ncells, l_max, grid, &
35 periodic = periodicbc, r_min = l_min, &
39 call af_loop_box(tree, setinitconds)
42 call af_gc_tree(tree, [iq])
47 end_time = acos(-1.0_dp)
48 time_steps = ceiling(end_time/dt)
51 do t_iter = 1, time_steps
53 if (mod(t_iter, 10) == 0)
then
54 write(fname,
"(A,I0)")
"output/solid_body_rotation_" // &
55 dimname //
"_", t_iter
56 call af_write_silo(tree, trim(fname), t_iter, time)
60 call af_loop_tree(tree, korenflux)
63 call af_loop_box_arg(tree, updatesoln, [dt])
66 call af_gc_tree(tree, [iq])
77 subroutine setinitconds( box )
78 type(box_t),
intent(inout) :: box
84 rr = af_r_cc(box, [ijk])
85 box%cc(ijk, iq) = solution(rr)
87 end subroutine setinitconds
89 function solution( rr )
result(sol)
90 real(dp),
intent(in) :: rr(NDIM)
92 real(dp) :: peak(NDIM), xLim(NDIM), yLim(NDIM)
103 if( xlim(1) < rr(1) .and. rr(1) < xlim(2) .and. ylim(1) < rr(2) &
104 .and. rr(2) < ylim(2) )
then
106 else if (norm2(rr + peak) < 0.35_dp)
then
107 sol = 1.0_dp - (norm2(rr + peak)/0.35_dp)
112 end function solution
114 subroutine korenflux( tree, id )
116 type(af_t),
intent(inout) :: tree
117 integer,
intent(in) :: id
119 real(dp),
allocatable :: cc(DTIMES(:), :)
120 real(dp),
allocatable :: v(DTIMES(:),:)
123 nc = tree%boxes(id)%n_cell
124 allocate(cc(dtimes(-1:nc+2), 1))
125 allocate(v(dtimes(1:nc+1), ndim))
128 call af_gc2_box(tree, id, [iq], cc)
131 rr = af_r_cc(tree%boxes(id), [ijk]) - 0.5_dp*tree%boxes(id)%dr
132 v(ijk, 1) = 2.0_dp*rr(2)
133 v(ijk, 2) = -2.0_dp*rr(1)
136 call flux_koren_2d(cc(dtimes(:), iq), v, nc, 2)
137 tree%boxes(id)%fc(:,:,:,i_flux) = v
139 end subroutine korenflux
141 subroutine updatesoln( box, dt )
142 type(box_t),
intent(inout) :: box
143 real(dp),
intent(in) :: dt(:)
144 real(dp) :: inv_dr(NDIM)
152 box%cc(i,j,iq) = box%cc(i,j,iq) - dt(1) * ( &
154 (box%fc(i+1,j,1,iq) - box%fc(i,j,1,iq)) &
156 (box%fc(i,j+1,2,iq) - box%fc(i,j,2,iq)))
160 end subroutine updatesoln
162 end program solid_body_rotation
Module which contains all Afivo modules, so that a user does not have to include them separately.
Module containing a couple flux schemes for solving hyperbolic problems explicitly,...