Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
hex.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!
34module hex
35 use num_types, only : dp
36 use element, only : element_t
38 use point, only : point_t
39 implicit none
40 private
41
42 integer, public, parameter :: neko_hex_npts = 8
43 integer, public, parameter :: neko_hex_nfcs = 6
44 integer, public, parameter :: neko_hex_neds = 12
45 integer, public, parameter :: neko_hex_gdim = 3
46
47
63 type, public, extends(element_t) :: hex_t
64 contains
65 procedure, pass(this) :: init => hex_init
66 procedure, pass(this) :: facet_id => hex_facet_id
67 procedure, pass(this) :: facet_order => hex_facet_order
68 procedure, pass(this) :: diameter => hex_diameter
69 procedure, pass(this) :: centroid => hex_centroid
70 procedure, pass(this) :: edge_id => hex_edge_id
71 procedure, pass(this) :: equal => hex_equal
72 generic :: operator(.eq.) => equal
73 end type hex_t
74
93 integer, public, parameter, dimension(4, 6) :: face_nodes = &
94 reshape([1, 5, 7, 3, &
95 2, 6, 8, 4, &
96 1, 2, 6, 5, &
97 3, 4, 8, 7, &
98 1, 2, 4, 3, &
99 5, 6, 8, 7], &
100 [4, 6])
101
120 integer, public, parameter, dimension(2, 12) :: edge_nodes = &
121 reshape([1, 2, &
122 3, 4, &
123 5, 6, &
124 7, 8, &
125 1, 3, &
126 2, 4, &
127 5, 7, &
128 6, 8, &
129 1, 5, &
130 2, 6, &
131 3, 7, &
132 4, 8], &
133 [2, 12])
134
136 integer, public, parameter, dimension(3, 8) :: node_faces = &
137 reshape([1, 3, 5, &
138 2, 3, 5, &
139 1, 4, 5, &
140 2, 4, 5, &
141 1, 3, 6, &
142 2, 3, 6, &
143 1, 4, 6, &
144 2, 4, 6], [3, 8])
145
147 integer, public, parameter, dimension(3, 8) :: node_edges = &
148 reshape([1, 5, 9, &
149 1, 6, 10, &
150 2, 5, 11, &
151 2, 6, 12, &
152 3, 7, 9, &
153 3, 8, 10, &
154 4, 7, 11, &
155 4, 8, 12], [3, 8])
156
158 integer, public, parameter, dimension(2, 12) :: edge_faces = &
159 reshape([3, 5, &
160 4, 5, &
161 3, 6, &
162 4, 6, &
163 1, 5, &
164 2, 5, &
165 1, 6, &
166 2, 6, &
167 1, 3, &
168 2, 3, &
169 1, 4, &
170 2, 4], [2, 12])
171
172contains
173
175 subroutine hex_init(this, id, p1, p2, p3, p4, p5, p6, p7, p8)
176 class(hex_t), intent(inout) :: this
177 integer, intent(inout) :: id
178 type(point_t), target, intent(in) :: p1, p2, p3, p4, p5, p6, p7, p8
179
180 call this%element(id, neko_hex_gdim, neko_hex_npts)
181
182 this%pts(1)%p => p1
183 this%pts(2)%p => p2
184 this%pts(3)%p => p3
185 this%pts(4)%p => p4
186 this%pts(5)%p => p5
187 this%pts(6)%p => p6
188 this%pts(7)%p => p7
189 this%pts(8)%p => p8
190
191 end subroutine hex_init
192
194 subroutine hex_facet_id(this, t, side)
195 class(hex_t), intent(in) :: this
196 class(tuple_t), intent(inout) :: t
197 integer, intent(in) :: side
198 integer :: i, j, temp
199 type(point_t), pointer :: p1, p2, p3, p4
200
201 p1 => this%p(face_nodes(1, side))
202 p2 => this%p(face_nodes(2, side))
203 p3 => this%p(face_nodes(3, side))
204 p4 => this%p(face_nodes(4, side))
205
206 select type (t)
207 type is (tuple4_i4_t)
208 t%x = [p1%id(), p2%id(), p3%id(), p4%id()]
209 do i = 1, 3
210 do j = i + 1, 4
211 if (t%x(j) .lt. t%x(i)) then
212 temp = t%x(i)
213 t%x(i) = t%x(j)
214 t%x(j) = temp
215 end if
216 end do
217 end do
218 end select
219
220 end subroutine hex_facet_id
221
223 subroutine hex_facet_order(this, t, side)
224 class(hex_t), intent(in) :: this
225 class(tuple_t), intent(inout) :: t
226 integer, intent(in) :: side
227 type(point_t), pointer :: p1, p2, p3, p4
228
229 p1 => this%p(face_nodes(1, side))
230 p2 => this%p(face_nodes(2, side))
231 p3 => this%p(face_nodes(3, side))
232 p4 => this%p(face_nodes(4, side))
233
234 select type (t)
235 type is (tuple4_i4_t)
236 t%x = [p1%id(), p2%id(), p3%id(), p4%id()]
237 end select
238
239 end subroutine hex_facet_order
240
241
243 subroutine hex_edge_id(this, t, side)
244 class(hex_t), intent(in) :: this
245 class(tuple_t), intent(inout) :: t
246 integer, intent(in) :: side
247 type(point_t), pointer :: p1, p2
248
249 p1 => this%p(edge_nodes(1, side))
250 p2 => this%p(edge_nodes(2, side))
251
252 select type (t)
253 type is (tuple_i4_t)
254 if (p1%id() .lt. p2%id()) then
255 t%x = [p1%id(), p2%id()]
256 else
257 t%x = [p2%id(), p1%id()]
258 end if
259
260 end select
261
262 end subroutine hex_edge_id
263
265 function hex_diameter(this) result(res)
266 class(hex_t), intent(in) :: this
267 real(kind=dp) :: d1, d2, d3, d4, res
268 type(point_t), pointer :: p1, p2, p3, p4, p5, p6, p7, p8
269 integer :: i
270
271 d1 = 0d0
272 d2 = 0d0
273 d3 = 0d0
274 d4 = 0d0
275
276 p1 => this%p(1)
277 p2 => this%p(2)
278 p3 => this%p(3)
279 p4 => this%p(4)
280 p5 => this%p(5)
281 p6 => this%p(6)
282 p7 => this%p(7)
283 p8 => this%p(8)
284
285 do i = 1, neko_hex_gdim
286 d1 = d1 + (p8%x(i) - p1%x(i))**2
287 d2 = d2 + (p7%x(i) - p2%x(i))**2
288 d3 = d3 + (p5%x(i) - p4%x(i))**2
289 d4 = d4 + (p6%x(i) - p3%x(i))**2
290 end do
291
292 res = sqrt(max(max(d1, d2), max(d3, d4)))
293
294 end function hex_diameter
295
297 function hex_centroid(this) result(res)
298 class(hex_t), intent(in) :: this
299 type(point_t) :: res
300 type(point_t), pointer :: p1, p2, p3, p4, p5, p6, p7, p8
301 integer :: i
302
303 p1 => this%p(1)
304 p2 => this%p(2)
305 p3 => this%p(3)
306 p4 => this%p(4)
307 p5 => this%p(5)
308 p6 => this%p(6)
309 p7 => this%p(7)
310 p8 => this%p(8)
311 res%x = 0d0
312
313 do i = 1, this%gdim()
314 res%x(i) = 0.125 * (p1%x(i) + p2%x(i) + p3%x(i) + p4%x(i) + &
315 p5%x(i) + p6%x(i) + p7%x(i) + p8%x(i))
316 end do
317
318 end function hex_centroid
319
322 pure function hex_equal(this, other) result(res)
323 class(hex_t), intent(in) :: this
324 class(element_t), intent(in) :: other
325 integer :: i
326 logical :: res
327
328 res = .false.
329 select type (other)
330 type is (hex_t)
331 if ((this%gdim() .eq. other%gdim()) .and. &
332 (this%npts() .eq. other%npts())) then
333 do i = 1, this%npts()
334 if (this%pts(i)%p .ne. other%pts(i)%p) then
335 return
336 end if
337 end do
338 res = .true.
339 end if
340 end select
341
342 end function hex_equal
343
344end module hex
Defines a hexahedron element.
Definition hex.f90:34
type(point_t) function hex_centroid(this)
Compute the centroid of a hexahedron element.
Definition hex.f90:298
subroutine hex_facet_order(this, t, side)
Return the ordered points for face i as a 4-tuple t.
Definition hex.f90:224
integer, dimension(3, 8), parameter, public node_edges
Edge ids incident to each node.
Definition hex.f90:147
subroutine hex_edge_id(this, t, side)
Return the edge id for an edge i as a 2-tuple t.
Definition hex.f90:244
integer, dimension(2, 12), parameter, public edge_faces
Face ids incident to each edge.
Definition hex.f90:158
integer, parameter, public neko_hex_gdim
Geometric dimension.
Definition hex.f90:45
integer, parameter, public neko_hex_npts
Number of points.
Definition hex.f90:42
integer, parameter, public neko_hex_nfcs
Number of faces.
Definition hex.f90:43
integer, parameter, public neko_hex_neds
Number of edges.
Definition hex.f90:44
real(kind=dp) function hex_diameter(this)
Compute the diameter of a hexahedron element.
Definition hex.f90:266
integer, dimension(4, 6), parameter, public face_nodes
Face node ids.
Definition hex.f90:93
pure logical function hex_equal(this, other)
Check if two hex elements are equal.
Definition hex.f90:323
integer, dimension(3, 8), parameter, public node_faces
Face ids incident to each node.
Definition hex.f90:136
subroutine hex_init(this, id, p1, p2, p3, p4, p5, p6, p7, p8)
Create a hexahedron element based upon eight points.
Definition hex.f90:176
integer, dimension(2, 12), parameter, public edge_nodes
Edge node ids.
Definition hex.f90:120
subroutine hex_facet_id(this, t, side)
Return the facet id for face i as a 4-tuple t.
Definition hex.f90:195
integer, parameter, public dp
Definition num_types.f90:10
Implements a point.
Definition point.f90:35
Implements a n-tuple.
Definition tuple.f90:41
Base type for an element.
Definition element.f90:44
Hexahedron element.
Definition hex.f90:63
A point in with coordinates .
Definition point.f90:43
Integer based 4-tuple.
Definition tuple.f90:76
Integer based 2-tuple.
Definition tuple.f90:58
Base type for an n-tuple.
Definition tuple.f90:48
#define max(a, b)
Definition tensor.cu:40