Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
aabb_el_finder.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2023, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33
35 use num_types, only : rp, dp, xp
37 use el_finder, only : el_finder_t
38 use space, only : space_t
39 use stack, only : stack_i4_t
40 use tuple, only : tuple_i4_t
41 use point, only : point_t
42 use aabb, only : aabb_t
44 implicit none
45 private
46
48 type, public, extends(el_finder_t) :: aabb_el_finder_t
49 real(kind=dp) :: padding
51 type(aabb_t), allocatable :: local_aabb(:)
52 type(aabb_tree_t) :: local_aabb_tree
53
54 contains
55 procedure, pass(this) :: init => aabb_el_finder_init
56 procedure, pass(this) :: free => aabb_el_finder_free
57 procedure, pass(this) :: find => aabb_el_finder_find_candidates
58 procedure, pass(this) :: find_batch => aabb_el_finder_find_candidates_batch
59
60 end type aabb_el_finder_t
61
62contains
63
65 subroutine aabb_el_finder_init(this, x, y, z, nel, Xh, padding)
66 class(aabb_el_finder_t), intent(inout) :: this
67 type(space_t), intent(in) :: Xh
68 real(kind=rp), intent(in), target :: x(:), y(:), z(:)
69 integer, intent(in) :: nel
70 real(kind=dp), intent(in) :: padding
71 integer :: id1, id2, i, lx, ly, lz
72 this%padding = padding
73 lx = xh%lx
74 ly = xh%ly
75 lz = xh%lz
76 if (allocated(this%local_aabb)) deallocate(this%local_aabb)
77 allocate(this%local_aabb(nel))
79 call this%local_aabb_tree%init(nel)
80 do i = 1, nel
81 id1 = lx*ly*lz*(i-1)+1
82 id2 = lx*ly*lz*(i)
83 call this%local_aabb(i)%init( real((/minval(x(id1:id2)), &
84 minval(y(id1:id2)), &
85 minval(z(id1:id2))/), dp), &
86 real((/maxval(x(id1:id2)), &
87 maxval(y(id1:id2)), &
88 maxval(z(id1:id2))/), dp))
89 end do
90 call this%local_aabb_tree%build_from_aabb(this%local_aabb, padding)
91 end subroutine aabb_el_finder_init
92
94 subroutine aabb_el_finder_free(this)
95 class(aabb_el_finder_t), intent(inout) :: this
96
97 ! Free the AABB element finder
98 if (allocated(this%local_aabb)) deallocate(this%local_aabb)
99
100
101 end subroutine aabb_el_finder_free
102
103
105 subroutine aabb_el_finder_find_candidates(this, my_point, el_candidates)
106 class(aabb_el_finder_t), intent(inout) :: this
107 type(point_t), intent(in) :: my_point
108 type(stack_i4_t), intent(inout) :: el_candidates
109
110 ! Find the element candidates for a given point
111 call this%local_aabb_tree%query_overlaps(my_point, -1, el_candidates)
112
113 end subroutine aabb_el_finder_find_candidates
114
115 ! Might be better to organize this slightly differently
116 ! In order to get more cache hits
117 subroutine aabb_el_finder_find_candidates_batch(this, points, n_points, &
118 all_el_candidates, n_el_cands)
119 class(aabb_el_finder_t), intent(inout) :: this
120 integer, intent(in) :: n_points
121 real(kind=rp), intent(in) :: points(3, n_points)
122 type(stack_i4_t), intent(inout) :: all_el_candidates
123 integer, intent(inout) :: n_el_cands(n_points)
124 type(stack_i4_t) :: el_candidates
125 type(point_t) :: my_point
126 integer :: i, j
127 integer, pointer :: el_cands(:)
128 integer :: stupid_intent
129 real(kind=dp) :: pt_xyz(3)
130
131 call all_el_candidates%clear()
132 call el_candidates%init()
133 n_el_cands = 0
134
135 do i = 1, n_points
136 pt_xyz = (/ points(1,i), points(2,i), points(3,i) /)
137 call my_point%init(pt_xyz)
138 call el_candidates%clear()
139 call this%find(my_point, el_candidates)
140 el_cands => el_candidates%array()
141 do j = 1, el_candidates%size()
142 stupid_intent = el_cands(j) - 1
143 call all_el_candidates%push(stupid_intent)
144 end do
145 n_el_cands(i) = el_candidates%size()
146 end do
147
149
150
151end module aabb_el_finder
double real
subroutine aabb_el_finder_find_candidates_batch(this, points, n_points, all_el_candidates, n_el_cands)
subroutine aabb_el_finder_find_candidates(this, my_point, el_candidates)
It uses the AABB tree to find the elements that overlap with the point.
subroutine aabb_el_finder_free(this)
Free the AABB element finder.
subroutine aabb_el_finder_init(this, x, y, z, nel, xh, padding)
Initialize the AABB element finder.
Axis Aligned Bounding Box (aabb) Tree data structure.
Definition aabb_tree.f90:70
integer, parameter, public aabb_null_node
Definition aabb_tree.f90:79
Axis Aligned Bounding Box (aabb) implementation in Fortran.
Definition aabb.f90:71
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public xp
Definition num_types.f90:14
integer, parameter, public dp
Definition num_types.f90:9
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Implements a point.
Definition point.f90:35
Defines a function space.
Definition space.f90:34
Implements a dynamic stack ADT.
Definition stack.f90:35
Implements a n-tuple.
Definition tuple.f90:34
Axis Aligned Bounding Box (aabb) data structure.
Definition aabb.f90:107
Implements global interpolation for arbitrary points in the domain.
Node type for the Axis Aligned Bounding Box (aabb) Tree.
Definition aabb_tree.f90:86
Axis Aligned Bounding Box (aabb) Tree.
Base type for element finder providing element candidates for a given point in the domain.
Definition el_finder.f90:43
A point in with coordinates .
Definition point.f90:43
The function space for the SEM solution fields.
Definition space.f90:63
Integer based stack.
Definition stack.f90:63
Integer based 2-tuple.
Definition tuple.f90:51