Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
point.f90
Go to the documentation of this file.
1! Copyright (c) 2019-2021, 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!
34!
35module point
36 use num_types, only : dp, rp
37 use math, only : abscmp
38 use entity, only : entity_t
39 implicit none
40 private
41
43 type, extends(entity_t), public :: point_t
44 real(kind=dp), dimension(3) :: x
45 contains
46 procedure :: point_eq
47 procedure :: point_ne
48 procedure :: point_lt
49 procedure :: point_gt
50 procedure :: point_assign
51 procedure :: point_add
52 procedure :: point_subtract
53 procedure :: point_scalar_mult
54 procedure, pass(p1) :: dist => point_euclid_dist
55 procedure, pass(x) :: point_mat_mult
56 generic :: operator(.eq.) => point_eq
57 generic :: operator(.ne.) => point_ne
58 generic :: operator(.lt.) => point_lt
59 generic :: operator(.gt.) => point_gt
60 generic :: assignment(=) => point_assign
61 generic :: operator(+) => point_add
62 generic :: operator(-) => point_subtract
63 generic :: operator(*) => point_scalar_mult, point_mat_mult
64 end type point_t
65
67 type, public :: point_ptr
68 type(point_t), pointer :: p
69 end type point_ptr
70
71 interface point_t
72 module procedure point_init, point_init_xyz
73 end interface point_t
74
75contains
76
78 function point_init(x, id) result(this)
79 real(kind=dp), dimension(3), intent(in) :: x
80 integer, optional, intent(inout) :: id
81 type(point_t) :: this
82
83 if (present(id)) then
84 call this%set_id(id)
85 else
86 call this%set_id(-1)
87 end if
88
89 this%x = x
90
91 end function point_init
92
94 function point_init_xyz(x, y, z, id) result(this)
95 real(kind=dp), intent(in) :: x
96 real(kind=dp), intent(in) :: y
97 real(kind=dp), intent(in) :: z
98 integer, optional, intent(inout) :: id
99 type(point_t) :: this
100
101 if (present(id)) then
102 call this%set_id(id)
103 else
104 call this%set_id(-1)
105 end if
106
107 this%x(1) = x
108 this%x(2) = y
109 this%x(3) = z
110
111 end function point_init_xyz
112
114 subroutine point_assign(this, x)
115 class(point_t), intent(inout) :: this
116 real(kind=dp), dimension(3), intent(in) :: x
117
118 this%x = x
119
120 end subroutine point_assign
121
124 pure function point_eq(p1, p2) result(res)
125 class(point_t), intent(in) :: p1
126 class(point_t), intent(in) :: p2
127 logical :: res
128
129 if (abscmp(p1%x(1), p2%x(1)) .and. &
130 abscmp(p1%x(2), p2%x(2)) .and. &
131 abscmp(p1%x(3), p2%x(3))) then
132 res = .true.
133 else
134 res = .false.
135 end if
136
137 end function point_eq
138
141 pure function point_ne(p1, p2) result(res)
142 class(point_t), intent(in) :: p1
143 class(point_t), intent(in) :: p2
144 logical :: res
145
146 if (.not. abscmp(p1%x(1), p2%x(1)) .or. &
147 .not. abscmp(p1%x(2), p2%x(2)) .or. &
148 .not. abscmp(p1%x(3), p2%x(3))) then
149 res = .true.
150 else
151 res = .false.
152 end if
153
154 end function point_ne
155
158 pure function point_lt(p1, p2) result(res)
159 class(point_t), intent(in) :: p1
160 class(point_t), intent(in) :: p2
161 logical :: res
162
163 if (p1%x(1) .lt. p2%x(1) .or. &
164 (abscmp(p1%x(1), p2%x(1)) .and. &
165 (p1%x(2) .lt. p2%x(2) .or. &
166 (abscmp(p1%x(2), p2%x(2)) .and. p1%x(3) .lt. p2%x(3))))) then
167 res = .true.
168 else
169 res = .false.
170 end if
171
172 end function point_lt
173
176 pure function point_gt(p1, p2) result(res)
177 class(point_t), intent(in) :: p1
178 class(point_t), intent(in) :: p2
179 logical :: res
180
181 if (point_lt(p1, p2)) then
182 res = .false.
183 else
184 res = .true.
185 end if
186
187 end function point_gt
188
190 function point_add(p1, p2) result(res)
191 class(point_t), intent(in) :: p1
192 class(point_t), intent(in) :: p2
193 type(point_t) :: res
194
195 res%x(1) = p1%x(1) + p2%x(1)
196 res%x(2) = p1%x(2) + p2%x(2)
197 res%x(3) = p1%x(3) + p2%x(3)
198
199 end function point_add
200
202 function point_subtract(p1, p2) result(res)
203 class(point_t), intent(in) :: p1
204 class(point_t), intent(in) :: p2
205 type(point_t) :: res
206
207 res%x(1) = p1%x(1) - p2%x(1)
208 res%x(2) = p1%x(2) - p2%x(2)
209 res%x(3) = p1%x(3) - p2%x(3)
210
211 end function point_subtract
212
214 function point_scalar_mult(p, a) result(res)
215 class(point_t), intent(in) :: p
216 real(kind=rp), intent(in) :: a
217 type(point_t) :: res
218
219 res%x(1) = a * p%x(1)
220 res%x(2) = a * p%x(2)
221 res%x(3) = a * p%x(3)
222
223 end function point_scalar_mult
224
226 pure function point_euclid_dist(p1, p2) result(res)
227 class(point_t), intent(in) :: p1
228 type(point_t), intent(in) :: p2
229 real(kind=rp) :: res
230
231 res = sqrt( (p1%x(1) - p2%x(1))**2 &
232 + (p1%x(2) - p2%x(2))**2 &
233 + (p1%x(3) - p2%x(3))**2 )
234 end function point_euclid_dist
235
237 function point_mat_mult(A,x) result(b)
238 class(point_t), intent(in) :: x
239 real(kind=rp), intent(in) :: a(3,3)
240 type(point_t) :: b
241 integer :: i,j
242
243 b%x = 0.0_rp
244
245 do i = 1, 3
246 do j = 1, 3
247 b%x(i) = b%x(i) + a(i,j) * x%x(j)
248 end do
249 end do
250
251 end function point_mat_mult
252
253end module point
Definition math.f90:60
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
type(point_t) function point_init(x, id)
Initialize a point from an array x of coordinates.
Definition point.f90:79
pure logical function point_gt(p1, p2)
Check if .
Definition point.f90:177
pure logical function point_eq(p1, p2)
Check if .
Definition point.f90:125
type(point_t) function point_subtract(p1, p2)
Returns the subtraction of 2 points .
Definition point.f90:203
type(point_t) function point_mat_mult(a, x)
Computes matrix-vector product in : .
Definition point.f90:238
type(point_t) function point_init_xyz(x, y, z, id)
Initialize a point from coordinates.
Definition point.f90:95
subroutine point_assign(this, x)
Assigns coordinates x to a point.
Definition point.f90:115
type(point_t) function point_scalar_mult(p, a)
Returns the multiplication of a point by a scalar .
Definition point.f90:215
pure logical function point_lt(p1, p2)
Check if .
Definition point.f90:159
pure real(kind=rp) function point_euclid_dist(p1, p2)
Returns the Euclidean distance between two points .
Definition point.f90:227
type(point_t) function point_add(p1, p2)
Returns the addition of 2 points .
Definition point.f90:191
pure logical function point_ne(p1, p2)
Check if .
Definition point.f90:142
Base type for an entity.
Definition entity.f90:38
Defines a pointer to a point type.
Definition point.f90:67
A point in with coordinates .
Definition point.f90:43