Neko  0.8.99
A portable framework for high-order spectral element flow simulations
quad.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 module quad
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_quad_npts = 4
43  integer, public, parameter :: neko_quad_neds = 4
44  integer, public, parameter :: neko_quad_gdim = 2
45 
58  type, public, extends(element_t) :: quad_t
59  contains
60  procedure, pass(this) :: init => quad_init
61  procedure, pass(this) :: facet_id => quad_facet_id
62  procedure, pass(this) :: facet_order => quad_facet_order
63  procedure, pass(this) :: diameter => quad_diameter
64  procedure, pass(this) :: centroid => quad_centroid
65  procedure, pass(this) :: equal => quad_equal
66  generic :: operator(.eq.) => equal
67  end type quad_t
68 
81  integer, parameter, dimension(2, 4) :: edge_nodes = reshape((/1,3,&
82  2,4,&
83  1,2,&
84  3,4 /),&
85  (/2,4/))
86 
87 contains
88 
90  subroutine quad_init(this, id, p1, p2, p3, p4)
91  class(quad_t), intent(inout) :: this
92  integer, intent(inout) :: id
93  type(point_t), target, intent(in) :: p1, p2, p3, p4
94 
95  call this%element(id, neko_quad_gdim, neko_quad_npts)
96 
97  this%pts(1)%p => p1
98  this%pts(2)%p => p2
99  this%pts(3)%p => p3
100  this%pts(4)%p => p4
101 
102  end subroutine quad_init
103 
106  subroutine quad_facet_id(this, t, side)
107  class(quad_t), intent(in) :: this
108  class(tuple_t), intent(inout) :: t
109  integer, intent(in) :: side
110  type(point_t), pointer :: p1, p2
111 
112  p1 => this%p(edge_nodes(1, side))
113  p2 => this%p(edge_nodes(2, side))
114 
115  select type(t)
116  type is(tuple_i4_t)
117  if (p1%id() .lt. p2%id()) then
118  t%x = (/ p1%id(), p2%id() /)
119  else
120  t%x = (/ p2%id(), p1%id() /)
121  endif
122  end select
123  end subroutine quad_facet_id
124 
126  subroutine quad_facet_order(this, t, side)
127  class(quad_t), intent(in) :: this
128  class(tuple_t), intent(inout) :: t
129  integer, intent(in) :: side
130  type(point_t), pointer :: p1, p2
131 
132  p1 => this%p(edge_nodes(1, side))
133  p2 => this%p(edge_nodes(2, side))
134 
135  select type(t)
136  type is(tuple_i4_t)
137  t%x = (/ p1%id(), p2%id() /)
138  end select
139 
140  end subroutine quad_facet_order
141 
143  function quad_diameter(this) result(res)
144  class(quad_t), intent(in) :: this
145  real(kind=dp) :: d1, d2, res
146  type(point_t), pointer :: p1, p2, p3, p4
147  integer :: i
148 
149  d1 = 0d0
150  d2 = 0d0
151 
152  p1 => this%p(1)
153  p2 => this%p(2)
154  p3 => this%p(3)
155  p4 => this%p(4)
156 
157  do i = 1, neko_quad_gdim
158  d1 = d1 + (p4%x(i) - p1%x(i))**2
159  d2 = d2 + (p3%x(i) - p2%x(i))**2
160  end do
161 
162  res = sqrt(max(d1, d2))
163 
164  end function quad_diameter
165 
167  function quad_centroid(this) result(res)
168  class(quad_t), intent(in) :: this
169  type(point_t) :: res
170  type(point_t), pointer :: p1, p2, p3, p4
171  integer :: i
172 
173  p1 => this%p(1)
174  p2 => this%p(2)
175  p3 => this%p(3)
176  p4 => this%p(4)
177  res%x = 0d0
178 
179  do i = 1, this%gdim()
180  res%x(i) = 0.25d0 * (p1%x(i) + p2%x(i) + p3%x(i) + p4%x(i))
181  end do
182  end function quad_centroid
183 
186  pure function quad_equal(this, other) result(res)
187  class(quad_t), intent(in) :: this
188  class(element_t), intent(in) :: other
189  integer :: i
190  logical :: res
191 
192  res = .false.
193  select type(other)
194  type is (quad_t)
195  if ((this%gdim() .eq. other%gdim()) .and. &
196  (this%npts() .eq. other%npts())) then
197  do i = 1, this%npts()
198  if (this%pts(i)%p .ne. other%pts(i)%p) then
199  return
200  end if
201  end do
202  res = .true.
203  end if
204  end select
205 
206  end function quad_equal
207 
208 end module quad
integer, parameter, public dp
Definition: num_types.f90:9
Implements a point.
Definition: point.f90:35
Defines a quadrilateral element.
Definition: quad.f90:34
integer, dimension(2, 4), parameter edge_nodes
Edge node ids.
Definition: quad.f90:81
integer, parameter, public neko_quad_gdim
Geometric dimension.
Definition: quad.f90:44
subroutine quad_facet_order(this, t, side)
Return the ordered edge for face i as a 2-tuple t.
Definition: quad.f90:127
integer, parameter, public neko_quad_neds
Number of edges.
Definition: quad.f90:43
integer, parameter, public neko_quad_npts
Number of points.
Definition: quad.f90:42
subroutine quad_facet_id(this, t, side)
Return the edge id for face i as a 2-tuple t.
Definition: quad.f90:107
subroutine quad_init(this, id, p1, p2, p3, p4)
Create a quadrilateral element based upon four points.
Definition: quad.f90:91
real(kind=dp) function quad_diameter(this)
Compute the diameter of a quadrilateral element.
Definition: quad.f90:144
pure logical function quad_equal(this, other)
Check if two quad elements are equal.
Definition: quad.f90:187
type(point_t) function quad_centroid(this)
Compute the centroid of a quadrilateral element.
Definition: quad.f90:168
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
Quadrilateral element.
Definition: quad.f90:58
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