5 #include "cpp_macros.h"
13 public :: af_interp0_to_grid
14 public :: af_interp1_fc
19 function af_interp0(tree, r, ivs, success, id_guess)
result(vals)
21 type(
af_t),
intent(in) :: tree
22 real(dp),
intent(in) :: r(ndim)
23 integer,
intent(in) :: ivs(:)
24 logical,
intent(out) :: success
25 integer,
intent(inout),
optional :: id_guess
26 real(dp) :: vals(size(ivs))
29 loc = af_get_loc(tree, r, guess=id_guess)
31 if (
present(id_guess)) id_guess = loc%id
33 if (loc%id == -1)
then
38 vals = tree%boxes(loc%id)%cc(dindex(loc%ix), ivs)
40 end function af_interp0
43 function af_interp1(tree, r, ivs, success, id_guess)
result(vals)
45 type(
af_t),
intent(in) :: tree
46 real(dp),
intent(in) :: r(ndim)
47 integer,
intent(in) :: ivs(:)
48 logical,
intent(out) :: success
49 integer,
intent(inout),
optional :: id_guess
50 real(dp) :: vals(size(ivs))
51 integer :: i, iv, id, ix(ndim)
52 real(dp) :: r_loc(ndim), dvec(ndim), ovec(ndim), w(dtimes(2))
54 id = af_get_id_at(tree, r, guess=id_guess)
56 if (
present(id_guess)) id_guess = id
58 if (id <= af_no_box)
then
64 ix = nint((r - tree%boxes(id)%r_min) / tree%boxes(id)%dr)
65 r_loc = af_r_cc(tree%boxes(id), ix)
69 dvec = dvec / tree%boxes(id)%dr
77 w(1, 1) = ovec(1) * ovec(2)
78 w(2, 1) = dvec(1) * ovec(2)
79 w(1, 2) = ovec(1) * dvec(2)
80 w(2, 2) = dvec(1) * dvec(2)
82 w(1, 1, 1) = ovec(1) * ovec(2) * ovec(3)
83 w(2, 1, 1) = dvec(1) * ovec(2) * ovec(3)
84 w(1, 2, 1) = ovec(1) * dvec(2) * ovec(3)
85 w(2, 2, 1) = dvec(1) * dvec(2) * ovec(3)
86 w(1, 1, 2) = ovec(1) * ovec(2) * dvec(3)
87 w(2, 1, 2) = dvec(1) * ovec(2) * dvec(3)
88 w(1, 2, 2) = ovec(1) * dvec(2) * dvec(3)
89 w(2, 2, 2) = dvec(1) * dvec(2) * dvec(3)
95 vals(i) = sum(w * tree%boxes(id)%cc(ix(1):ix(1)+1, iv))
97 vals(i) = sum(w * tree%boxes(id)%cc(ix(1):ix(1)+1, &
100 vals(i) = sum(w * tree%boxes(id)%cc(ix(1):ix(1)+1, &
101 ix(2):ix(2)+1, ix(3):ix(3)+1, iv))
105 end function af_interp1
108 subroutine af_interp0_to_grid(tree, r, iv, amount, to_density)
110 type(
af_t),
intent(inout) :: tree
111 integer,
intent(in) :: iv
112 real(dp),
intent(in) :: r(ndim)
113 real(dp),
intent(in) :: amount
114 logical,
intent(in) :: to_density
115 real(dp) :: actual_amount
117 integer :: id, ix(ndim)
119 loc = af_get_loc(tree, r)
121 if (loc%id == -1)
then
122 print *,
"af_interp0_to_grid error, no box at ", r
131 actual_amount = amount / product(tree%boxes(id)%dr)
133 actual_amount = amount
136 tree%boxes(id)%cc(dindex(ix), iv) = &
137 tree%boxes(id)%cc(dindex(ix), iv) + &
139 end subroutine af_interp0_to_grid
142 function af_interp1_fc(tree, r, ifc, success, id_guess)
result(vals)
144 type(
af_t),
intent(in) :: tree
145 real(dp),
intent(in) :: r(ndim)
146 integer,
intent(in) :: ifc
147 logical,
intent(out) :: success
148 integer,
intent(inout),
optional :: id_guess
149 real(dp) :: vals(ndim), inv_dr(ndim)
150 integer :: id, ix(ndim)
151 real(dp) :: ix_frac(ndim), r_rel(ndim)
153 id = af_get_id_at(tree, r, guess=id_guess)
156 if (
present(id_guess)) id_guess = id
158 if (id <= af_no_box)
then
163 inv_dr = 1/tree%boxes(id)%dr
165 r_rel = r - tree%boxes(id)%r_min
166 ix_frac = r_rel * inv_dr + 1
168 where (ix < 1) ix = 1
169 where (ix > tree%n_cell) ix = tree%n_cell
170 ix_frac = ix_frac - ix
173 vals(1) = (1 - ix_frac(1)) * tree%boxes(id)%fc(ix(1), ix(2), 1, ifc) + &
174 ix_frac(1) * tree%boxes(id)%fc(ix(1)+1, ix(2), 1, ifc)
175 vals(2) = (1 - ix_frac(2)) * tree%boxes(id)%fc(ix(1), ix(2), 2, ifc) + &
176 ix_frac(2) * tree%boxes(id)%fc(ix(1), ix(2)+1, 2, ifc)
178 vals(1) = (1 - ix_frac(1)) * tree%boxes(id)%fc(ix(1), ix(2), ix(3), 1, ifc) + &
179 ix_frac(1) * tree%boxes(id)%fc(ix(1)+1, ix(2), ix(3), 1, ifc)
180 vals(2) = (1 - ix_frac(2)) * tree%boxes(id)%fc(ix(1), ix(2), ix(3), 2, ifc) + &
181 ix_frac(2) * tree%boxes(id)%fc(ix(1), ix(2)+1, ix(3), 2, ifc)
182 vals(3) = (1 - ix_frac(3)) * tree%boxes(id)%fc(ix(1), ix(2), ix(3), 3, ifc) + &
183 ix_frac(3) * tree%boxes(id)%fc(ix(1), ix(2), ix(3)+1, 3, ifc)
186 end function af_interp1_fc
This module contains routines related to interpolation, which can interpolate 'to' the grid and 'from...
This module contains the basic types and constants that are used in the NDIM-dimensional version of A...
This module contains all kinds of different 'helper' routines for Afivo. If the number of routines fo...
Type specifying the location of a cell.
Type which stores all the boxes and levels, as well as some information about the number of boxes,...