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, &
36
37 type lookup_t
38 private
39 integer :: nobjs = 0
40 integer :: dim = 0
41 real(real64), allocatable :: pos(:, :)
42 end type lookup_t
43
44contains
45
46 subroutine lookup_init(this, dim, nobjs, pos)
47 type(lookup_t), intent(inout) :: this
48 integer, intent(in) :: dim
49 integer, intent(in) :: nobjs
50 real(real64), intent(in) :: pos(:, :)
51
52 push_sub(lookup_init)
53
54 this%nobjs = nobjs
55 this%dim = dim
56 safe_allocate(this%pos(1:this%dim, 1:this%nobjs))
57
58 this%pos(1:this%dim, 1:this%nobjs) = pos(1:this%dim, 1:this%nobjs)
59
60 pop_sub(lookup_init)
61 end subroutine lookup_init
62
63 ! -----------------------------------------
64 subroutine lookup_end(this)
65 type(lookup_t), intent(inout) :: this
66
67 push_sub(lookup_end)
68 safe_deallocate_a(this%pos)
69
70 pop_sub(lookup_end)
71 end subroutine lookup_end
72
73 ! -----------------------------------------
74 subroutine lookup_copy(cin, cout)
75 type(lookup_t), intent(in) :: cin
76 type(lookup_t), intent(inout) :: cout
77
78 push_sub(lookup_copy)
79
80 call lookup_end(cout)
81 cout%nobjs = cin%nobjs
82 cout%dim = cin%dim
83 safe_allocate_source_a(cout%pos, cin%pos)
84
85 pop_sub(lookup_copy)
86 end subroutine lookup_copy
87
88 ! ------------------------------------------
89
90 subroutine lookup_get_list(this, npoint, points, radius, nlist, list)
91 type(lookup_t), intent(in) :: this
92 integer, intent(in) :: npoint
93 real(real64), intent(in) :: points(:, :)
94 real(real64), intent(in) :: radius
95 integer, intent(out) :: nlist(:)
96 integer, optional, allocatable, intent(out) :: list(:, :)
97
98 real(real64) :: r2
99 integer :: ii, ipoint
100
101 ! No PUSH SUB, called too often.
102
103 if (present(list)) then
104 safe_allocate(list(1:this%nobjs, 1:npoint))
105 end if
106
107 nlist(1:npoint) = 0
108
109 do ii = 1, this%nobjs
110 do ipoint = 1, npoint
111 r2 = sum((this%pos(1:this%dim, ii) - points(ipoint, 1:this%dim))**2)
112 if (r2 < radius**2) then
113 nlist(ipoint) = nlist(ipoint) + 1
114!This is a PGI pragma to force the optimization level of this file to -O0.
115!-O2 or below is needed for 10.5. -O1 or below is needed for 10.8.
116!The line after the pragma causes a segmentation fault otherwise.
117!pgi$r opt=0
118 if (present(list)) list(nlist(ipoint), ipoint) = ii
119 end if
120 end do
121 end do
122
123 end subroutine lookup_get_list
124
125end module lookup_oct_m
126
127!! Local Variables:
128!! mode: f90
129!! coding: utf-8
130!! End:
subroutine, public lookup_end(this)
Definition: lookup.F90:158
subroutine, public lookup_init(this, dim, nobjs, pos)
Definition: lookup.F90:140
subroutine, public lookup_copy(cin, cout)
Definition: lookup.F90:168
subroutine, public lookup_get_list(this, npoint, points, radius, nlist, list)
Definition: lookup.F90:184