Neko  0.9.0
A portable framework for high-order spectral element flow simulations
cylinder_point_zone.f90
Go to the documentation of this file.
1 ! Copyright (c) 2024, 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 !
35  use point_zone, only: point_zone_t
36  use num_types, only: rp
38  use json_module, only: json_file
39  use utils, only: neko_error
40  implicit none
41  private
42 
48  type, public, extends(point_zone_t) :: cylinder_point_zone_t
49  real(kind=rp), dimension(3) :: p0
50  real(kind=rp), dimension(3) :: p1
51  real(kind=rp) :: radius
52  contains
54  procedure, pass(this) :: init => cylinder_point_zone_init_from_json
56  procedure, pass(this) :: free => cylinder_point_zone_free
59  procedure, pass(this) :: criterion => cylinder_point_zone_criterion
60  end type cylinder_point_zone_t
61 
62 contains
63 
67  subroutine cylinder_point_zone_init_from_json(this, json, size)
68  class(cylinder_point_zone_t), intent(inout) :: this
69  type(json_file), intent(inout) :: json
70  integer, intent(in) :: size
71 
72  character(len=:), allocatable :: name
73  real(kind=rp), dimension(:), allocatable :: p0, p1
74  real(kind=rp) :: radius
75  logical :: invert
76 
77  call json_get(json, "name", name)
78  call json_get(json, "start", p0)
79  call json_get(json, "end", p1)
80  call json_get(json, "radius", radius)
81 
82  ! Needed to use `shape` because of input name.
83  if (all(shape(p0) .ne. (/3/))) then
84  call neko_error("Cylinder point zone: invalid start point")
85  end if
86 
87  if (all(shape(p1) .ne. (/3/))) then
88  call neko_error("Cylinder point zone: invalid end point")
89  end if
90 
91  if (radius .lt. 0.0_rp) then
92  call neko_error("Cylinder point zone: invalid radius")
93  end if
94 
95  call json_get_or_default(json, "invert", invert, .false.)
96 
97  call cylinder_point_zone_init_common(this, size, trim(name), invert, &
98  p0, p1, radius)
99 
101 
108  subroutine cylinder_point_zone_init_common(this, size, name, invert, &
109  p0, p1, radius)
110  class(cylinder_point_zone_t), intent(inout) :: this
111  integer, intent(in), optional :: size
112  character(len=*), intent(in) :: name
113  logical, intent(in) :: invert
114  real(kind=rp), intent(in), dimension(3) :: p0
115  real(kind=rp), intent(in), dimension(3) :: p1
116  real(kind=rp), intent(in) :: radius
117 
118  call this%init_base(size, name, invert)
119 
120  this%p0 = p0
121  this%p1 = p1
122  this%radius = radius
123 
124  end subroutine cylinder_point_zone_init_common
125 
127  subroutine cylinder_point_zone_free(this)
128  class(cylinder_point_zone_t), intent(inout) :: this
129 
130  call this%free_base()
131 
132  this%p0 = 0.0_rp
133  this%p1 = 0.0_rp
134  this%radius = 0.0_rp
135 
136  end subroutine cylinder_point_zone_free
137 
161  pure function cylinder_point_zone_criterion(this, x, y, z, j, k, l, e) &
162  result(is_inside)
163  class(cylinder_point_zone_t), intent(in) :: this
164  real(kind=rp), intent(in) :: x
165  real(kind=rp), intent(in) :: y
166  real(kind=rp), intent(in) :: z
167  integer, intent(in) :: j
168  integer, intent(in) :: k
169  integer, intent(in) :: l
170  integer, intent(in) :: e
171  logical :: is_inside
172 
173  real(kind=rp), dimension(3) :: p
174  real(kind=rp), dimension(3) :: centerline
175  real(kind=rp), dimension(3) :: vec_p
176  real(kind=rp) :: t
177  real(kind=rp), dimension(3) :: projection
178  real(kind=rp) :: distance
179 
180  p = [x, y, z]
181 
182  centerline = this%p1 - this%p0
183  vec_p = p - this%p0
184  t = dot_product(vec_p, centerline) / dot_product(centerline, centerline)
185 
186  projection = this%p0 + t * centerline
187  distance = norm2(projection - p)
188 
189  is_inside = t >= 0.0_rp .and. t <= 1.0_rp .and. distance <= this%radius
190 
191  end function cylinder_point_zone_criterion
192 
193 end module cylinder_point_zone
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Definition: json_utils.f90:54
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:45
Implements a cylinder geometry subset.
subroutine cylinder_point_zone_free(this)
Destructor.
subroutine cylinder_point_zone_init_common(this, size, name, invert, p0, p1, radius)
Initializes a cylinder point zone from its endpoint coordinates and radius.
pure logical function cylinder_point_zone_criterion(this, x, y, z, j, k, l, e)
Defines the criterion of selection of a GLL point in the cylinder point zone.
subroutine cylinder_point_zone_init_from_json(this, json, size)
Constructor from json object file.
Utilities for retrieving parameters from the case files.
Definition: json_utils.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Project x onto X, the space of old solutions and back again.
Definition: projection.f90:63
Utilities.
Definition: utils.f90:35
Base abstract type for point zones.
Definition: point_zone.f90:47