Octopus
lookup.F90
Go to the documentation of this file.
1!! Copyright (C) 2009 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module lookup_oct_m
22 use debug_oct_m
23 use global_oct_m
26
27 implicit none
28
29 private
30 public :: &
31 lookup_t, &
33 lookup_end, &
35
36 type lookup_t
37 private
38 integer :: nobjs = 0
39 integer :: dim = 0
40 real(real64), allocatable :: pos(:, :)
41 end type lookup_t
42
43contains
44
45 subroutine lookup_init(this, dim, nobjs, pos)
46 type(lookup_t), intent(inout) :: this
47 integer, intent(in) :: dim
48 integer, intent(in) :: nobjs
49 real(real64), intent(in) :: pos(:, :)
50
51 push_sub(lookup_init)
52
53 this%nobjs = nobjs
54 this%dim = dim
55 safe_allocate(this%pos(1:this%dim, 1:this%nobjs))
56
57 this%pos(1:this%dim, 1:this%nobjs) = pos(1:this%dim, 1:this%nobjs)
58
59 pop_sub(lookup_init)
60 end subroutine lookup_init
61
62 ! -----------------------------------------
63 subroutine lookup_end(this)
64 type(lookup_t), intent(inout) :: this
65
66 push_sub(lookup_end)
67 safe_deallocate_a(this%pos)
68
69 pop_sub(lookup_end)
70 end subroutine lookup_end
71
72 ! ------------------------------------------
73 subroutine lookup_get_list(this, npoint, points, radius, nlist, list)
74 type(lookup_t), intent(in) :: this
75 integer, intent(in) :: npoint
76 real(real64), intent(in) :: points(:, :)
77 real(real64), intent(in) :: radius
78 integer, intent(out) :: nlist(:)
79 integer, optional, allocatable, intent(out) :: list(:, :)
80
81 real(real64) :: r2
82 integer :: ii, ipoint
83
84 ! No PUSH SUB, called too often.
85
86 if (present(list)) then
87 safe_allocate(list(1:this%nobjs, 1:npoint))
88 end if
89
90 nlist(1:npoint) = 0
91
92 do ii = 1, this%nobjs
93 do ipoint = 1, npoint
94 r2 = sum((this%pos(1:this%dim, ii) - points(ipoint, 1:this%dim))**2)
95 if (r2 < radius**2) then
96 nlist(ipoint) = nlist(ipoint) + 1
97!This is a PGI pragma to force the optimization level of this file to -O0.
98!-O2 or below is needed for 10.5. -O1 or below is needed for 10.8.
99!The line after the pragma causes a segmentation fault otherwise.
100!pgi$r opt=0
101 if (present(list)) list(nlist(ipoint), ipoint) = ii
102 end if
103 end do
104 end do
105
106 end subroutine lookup_get_list
107
108end module lookup_oct_m
109
110!! Local Variables:
111!! mode: f90
112!! coding: utf-8
113!! End:
subroutine, public lookup_end(this)
Definition: lookup.F90:159
subroutine, public lookup_init(this, dim, nobjs, pos)
Definition: lookup.F90:141
subroutine, public lookup_get_list(this, npoint, points, radius, nlist, list)
Definition: lookup.F90:169