9 integer,
parameter :: dp = kind(0.0d0)
24 integer,
intent(in) :: n_dim
25 real(dp),
intent(in) :: r(n_dim), r0(n_dim), r1(n_dim)
26 real(dp),
intent(out) :: dist_vec(n_dim)
27 real(dp),
intent(out) :: frac
30 line_len2 = sum((r1 - r0)**2)
31 frac = sum((r - r0) * (r1 - r0))
33 if (frac <= 0.0_dp)
then
36 else if (frac >= line_len2)
then
40 dist_vec = r - (r0 + frac/line_len2 * (r1 - r0))
41 frac = frac / line_len2
46 integer,
intent(in) :: n_dim
47 real(dp),
intent(in) :: r(n_dim), r0(n_dim), r1(n_dim)
48 real(dp) :: dist, dist_vec(n_dim), frac
50 dist = norm2(dist_vec)
53 function gm_density_line(r, r0, r1, n_0, n_1, n_dim, width, falloff_t)
result(val)
54 integer,
intent(in) :: n_dim
55 real(dp),
intent(in) :: r(n_dim), r0(n_dim), r1(n_dim), width
56 real(dp),
intent(in) :: n_0, n_1
57 character(len=*),
intent(in) :: falloff_t
58 real(dp) :: dist, val, dist_vec(n_dim), frac
61 dist = norm2(dist_vec)
63 select case (falloff_t)
71 val = gm_step(dist, width)
73 val = gm_laser(dist_vec, width, n_dim)
75 print *,
"GM_density_line: unknown fall-off type: ", trim(falloff_t)
76 print *,
"Valid options: sigmoid, gaussian, smoothstep, step, laser"
81 val = val * (frac * n_0 + (1-frac) * n_1)
85 real(dp),
intent(in) :: dist, width
89 if (tmp > log(0.5_dp * huge(1.0_dp)))
then
92 val = 2 / (1 + exp(tmp))
97 real(dp),
intent(in) :: dist, width
99 val = exp(-(dist/width)**2)
103 real(dp),
intent(in) :: dist, width
104 real(dp) :: val, temp
105 if (dist < width)
then
107 else if (dist < 2 * width)
then
108 temp = dist/width - 1
109 val = (1- (3 * temp**2 - 2 * temp**3))
115 function gm_step(dist, width)
result(val)
116 real(dp),
intent(in) :: dist, width
118 if (dist < width)
then
125 function gm_laser(dist_vec, width, n_dim)
result(val)
126 integer,
intent(in) :: n_dim
127 real(dp),
intent(in) :: dist_vec(n_dim), width
128 real(dp) :: val, xz(2), dy, dxz
132 dy = abs(dist_vec(2))
135 if (dy < width .and. dxz < width)
then
138 val = exp(1-(dy**2 + dxz**2)/width**2)
140 end function gm_laser
Module that provides routines for geometric operations and calculations. Methods and types have a pre...
real(dp) function, public gm_sigmoid(dist, width)
real(dp) function, public gm_density_line(r, r0, r1, n_0, n_1, n_dim, width, falloff_t)
real(dp) function, public gm_gaussian(dist, width)
real(dp) function, public gm_dist_line(r, r0, r1, n_dim)
pure subroutine, public gm_dist_vec_line(r, r0, r1, n_dim, dist_vec, frac)
Compute distance vector between point and its projection onto a line between r0 and r1.
real(dp) function, public gm_smoothstep(dist, width)