Afivo 0.3
All Classes Namespaces Functions Variables Pages
solid_body_rotation.f90
1#include "../src/cpp_macros.h"
2
3program solid_body_rotation
4 use m_af_all
5 implicit none
6
7 integer, parameter :: ncells = 8
8 integer :: iq, i_flux
9 integer, parameter :: coord_type = af_xyz
10 real(dp) :: l_max(NDIM), l_min(NDIM)
11 integer :: grid(NDIM)
12 logical :: periodicBC(NDIM)
13
14 type(af_t) :: tree
15 !Add the stuff for AMR later
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()
21
22 !Setting up the domain and ncells
23 grid(:) = 8*ncells
24 l_max(:) = 1.0_dp
25 l_min(:) = -1.0_dp
26 periodicbc(:) = .false.
27
28
29 !Initialize the variables, boundary conditions and the tree
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)
33
34 call af_init(tree, ncells, l_max, grid, &
35 periodic = periodicbc, r_min = l_min, &
36 coord = coord_type)
37
38 !Setting the boundary conditions
39 call af_loop_box(tree, setinitconds)
40
41 !Fill the ghost cells according to the initial conditions
42 call af_gc_tree(tree, [iq])
43
44 !Setting the time step data
45 dt = 0.005_dp
46 time = 0.0
47 end_time = acos(-1.0_dp)
48 time_steps = ceiling(end_time/dt)
49
50 !Starting the time integration
51 do t_iter = 1, time_steps
52
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)
57 end if
58
59
60 call af_loop_tree(tree, korenflux)
61 !print *, 'Finished Looping over tree'
62
63 call af_loop_box_arg(tree, updatesoln, [dt])
64 !print *, 'finished time stepping'
65
66 call af_gc_tree(tree, [iq])
67 !print *, 'Updating ghost cells'
68
69 time = time + dt
70
71
72 end do
73 call af_destroy(tree)
74
75contains
76
77 subroutine setinitconds( box )
78 type(box_t), intent(inout) :: box
79 integer :: IJK, nc
80 real(dp) :: rr(NDIM)
81
82 nc = box%n_cell
83 do kji_do(0, nc+1)
84 rr = af_r_cc(box, [ijk])
85 box%cc(ijk, iq) = solution(rr)
86 end do; close_do
87 end subroutine setinitconds
88
89 function solution( rr ) result(sol)
90 real(dp), intent(in) :: rr(NDIM)
91 real(dp) :: sol
92 real(dp) :: peak(NDIM), xLim(NDIM), yLim(NDIM)
93
94 peak(1) = 0.45_dp
95 peak(2) = 0.0_dp
96
97 xlim(1) = 0.1_dp
98 xlim(2) = 0.6_dp
99
100 ylim(1) = -0.25_dp
101 ylim(2) = 0.25_dp
102
103 if( xlim(1) < rr(1) .and. rr(1) < xlim(2) .and. ylim(1) < rr(2) &
104 .and. rr(2) < ylim(2) ) then
105 sol = 1.0_dp
106 else if (norm2(rr + peak) < 0.35_dp) then
107 sol = 1.0_dp - (norm2(rr + peak)/0.35_dp)
108 else
109 sol = 0.0_dp
110 end if
111
112 end function solution
113
114 subroutine korenflux( tree, id )
116 type(af_t), intent(inout) :: tree
117 integer, intent(in) :: id
118 integer :: nc, IJK
119 real(dp), allocatable :: cc(DTIMES(:), :)
120 real(dp), allocatable :: v(DTIMES(:),:)
121 real(dp) :: rr(NDIM)
122
123 nc = tree%boxes(id)%n_cell
124 allocate(cc(dtimes(-1:nc+2), 1))
125 allocate(v(dtimes(1:nc+1), ndim))
126
127 !print *, "Inside Koren flux", id
128 call af_gc2_box(tree, id, [iq], cc)
129 !Computing the spatially varying velocities
130 do kji_do(1,nc+1)
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)
134 end do; close_do
135
136 call flux_koren_2d(cc(dtimes(:), iq), v, nc, 2)
137 tree%boxes(id)%fc(:,:,:,i_flux) = v
138
139 end subroutine korenflux
140
141 subroutine updatesoln( box, dt )
142 type(box_t), intent(inout) :: box
143 real(dp), intent(in) :: dt(:)
144 real(dp) :: inv_dr(NDIM)
145 integer :: IJK, nc
146
147 nc = box%n_cell
148 inv_dr = 1/box%dr
149
150 do j=1,nc
151 do i=1,nc
152 box%cc(i,j,iq) = box%cc(i,j,iq) - dt(1) * ( &
153 inv_dr(1)* &
154 (box%fc(i+1,j,1,iq) - box%fc(i,j,1,iq)) &
155 + inv_dr(2)* &
156 (box%fc(i,j+1,2,iq) - box%fc(i,j,2,iq)))
157 end do
158 end do
159
160 end subroutine updatesoln
161
162end program solid_body_rotation
Module which contains all Afivo modules, so that a user does not have to include them separately.
Definition: m_af_all.f90:3
Module containing a couple flux schemes for solving hyperbolic problems explicitly,...