Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
tri.f90
Go to the documentation of this file.
1! Copyright (c) 2021-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!
34module tri
35 use num_types, only : dp
36 use element, only : element_t
37 use tuple, only : tuple_t, tuple_i4_t
38 use point, only : point_t
39 implicit none
40 private
41
42 integer, public, parameter :: neko_tri_npts = 3
43 integer, public, parameter :: neko_tri_neds = 3
44 integer, public, parameter :: neko_tri_gdim = 2
45
60 type, public, extends(element_t) :: tri_t
61 contains
62 procedure, pass(this) :: init => tri_init
63 procedure, pass(this) :: facet_id => tri_facet_id
64 procedure, pass(this) :: facet_order => tri_facet_order
65 procedure, pass(this) :: diameter => tri_diameter
66 procedure, pass(this) :: centroid => tri_centroid
67 procedure, pass(this) :: equal => tri_equal
68 generic :: operator(.eq.) => equal
69 end type tri_t
70
85 integer, parameter, dimension(2, 3) :: edge_nodes = reshape((/1,3,&
86 2,3,&
87 1,2 /),&
88 (/2,3/))
89
90contains
91
93 subroutine tri_init(this, id, p1, p2, p3)
94 class(tri_t), intent(inout) :: this
95 integer, intent(inout) :: id
96 type(point_t), target, intent(in) :: p1, p2, p3
97
98 call this%element(id, neko_tri_gdim, neko_tri_npts)
99
100 this%pts(1)%p => p1
101 this%pts(2)%p => p2
102 this%pts(3)%p => p3
103
104 end subroutine tri_init
105
108 subroutine tri_facet_id(this, t, side)
109 class(tri_t), intent(in) :: this
110 class(tuple_t), intent(inout) :: t
111 integer, intent(in) :: side
112 type(point_t), pointer :: p1, p2
113
114 p1 => this%p(edge_nodes(1, side))
115 p2 => this%p(edge_nodes(2, side))
116
117 select type(t)
118 type is(tuple_i4_t)
119 if (p1 .lt. p2) then
120 t%x = (/ p1%id(), p2%id() /)
121 else
122 t%x = (/ p2%id(), p1%id() /)
123 end if
124 end select
125
126 end subroutine tri_facet_id
127
129 subroutine tri_facet_order(this, t, side)
130 class(tri_t), intent(in) :: this
131 class(tuple_t), intent(inout) :: t
132 integer, intent(in) :: side
133 type(point_t), pointer :: p1, p2
134
135 p1 => this%p(edge_nodes(1, side))
136 p2 => this%p(edge_nodes(2, side))
137
138 select type(t)
139 type is(tuple_i4_t)
140 t%x = (/ p1%id(), p2%id() /)
141 end select
142
143 end subroutine tri_facet_order
144
146 function tri_diameter(this) result(res)
147 class(tri_t), intent(in) :: this
148 real(kind=dp) :: d1, d2, d3, res
149 type(point_t), pointer :: p1, p2, p3
150 integer :: i
151
152 d1 = 0d0
153 d2 = 0d0
154 d3 = 0d0
155
156 p1 => this%p(1)
157 p2 => this%p(2)
158 p3 => this%p(3)
159
160 do i = 1, neko_tri_gdim
161 d1 = d1 + (p2%x(i) - p1%x(i))**2
162 d2 = d2 + (p3%x(i) - p2%x(i))**2
163 d3 = d3 + (p1%x(i) - p3%x(i))**2
164 end do
165
166 res = sqrt(max(max(d1, d2), d3))
167
168 end function tri_diameter
169
171 function tri_centroid(this) result(res)
172 class(tri_t), intent(in) :: this
173 type(point_t) :: res
174 type(point_t), pointer :: p1, p2, p3
175 integer :: i
176
177 p1 => this%p(1)
178 p2 => this%p(2)
179 p3 => this%p(3)
180 res%x = 0d0
181
182 do i = 1, this%gdim()
183 res%x(i) = 1d0/3d0 * (p1%x(i) + p2%x(i) + p3%x(i))
184 end do
185 end function tri_centroid
186
189 pure function tri_equal(this, other) result(res)
190 class(tri_t), intent(in) :: this
191 class(element_t), intent(in) :: other
192 integer :: i
193 logical :: res
194
195 res = .false.
196 select type(other)
197 class is (tri_t)
198 if ((this%gdim() .eq. other%gdim()) .and. &
199 (this%npts() .eq. other%npts())) then
200 do i = 1, this%npts()
201 if (this%pts(i)%p .ne. other%pts(i)%p) then
202 return
203 end if
204 end do
205 res = .true.
206 end if
207 end select
208
209 end function tri_equal
210
211end module tri
integer, parameter, public dp
Definition num_types.f90:9
Implements a point.
Definition point.f90:35
Defines a triangular element.
Definition tri.f90:34
integer, parameter, public neko_tri_npts
Number of points.
Definition tri.f90:42
integer, parameter, public neko_tri_gdim
Geometric dimension.
Definition tri.f90:44
real(kind=dp) function tri_diameter(this)
Compute the diameter of a triangular element.
Definition tri.f90:147
subroutine tri_facet_order(this, t, side)
Return the ordered edge for face i as a 2-tuple t.
Definition tri.f90:130
integer, parameter, public neko_tri_neds
Number of edges.
Definition tri.f90:43
subroutine tri_facet_id(this, t, side)
Return the edge id for face i as a 2-tuple t.
Definition tri.f90:109
type(point_t) function tri_centroid(this)
Compute the centroid of a triangular element.
Definition tri.f90:172
subroutine tri_init(this, id, p1, p2, p3)
Create a trinagular element based upon three points.
Definition tri.f90:94
integer, dimension(2, 3), parameter edge_nodes
Edge node ids.
Definition tri.f90:85
pure logical function tri_equal(this, other)
Check if two triangle elements are equal.
Definition tri.f90:190
Implements a n-tuple.
Definition tuple.f90:34
Base type for an element.
Definition element.f90:44
A point in with coordinates .
Definition point.f90:43
Triangular element.
Definition tri.f90:60
Integer based 2-tuple.
Definition tuple.f90:51
Base type for an n-tuple.
Definition tuple.f90:41
#define max(a, b)
Definition tensor.cu:40