Neko  0.8.1
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
37  use json_utils, only: json_get
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
58  procedure, pass(this) :: criterion => cylinder_point_zone_criterion
59  end type cylinder_point_zone_t
60 
61 contains
62 
66  subroutine cylinder_point_zone_init_from_json(this, json, size)
67  class(cylinder_point_zone_t), intent(inout) :: this
68  type(json_file), intent(inout) :: json
69  integer, intent(in) :: size
70 
71  character(len=:), allocatable :: name
72  real(kind=rp), dimension(:), allocatable :: p0, p1
73  real(kind=rp) :: radius
74 
75  call json_get(json, "name", name)
76  call json_get(json, "start", p0)
77  call json_get(json, "end", p1)
78  call json_get(json, "radius", radius)
79 
80  ! Needed to use `shape` because of input name.
81  if (all(shape(p0) .ne. (/3/))) then
82  call neko_error("Cylinder point zone: invalid start point")
83  end if
84 
85  if (all(shape(p1) .ne. (/3/))) then
86  call neko_error("Cylinder point zone: invalid end point")
87  end if
88 
89  if (radius .lt. 0.0_rp) then
90  call neko_error("Cylinder point zone: invalid radius")
91  end if
92 
93  call cylinder_point_zone_init_common(this, size, trim(name), p0, p1, &
94  radius)
95 
97 
104  subroutine cylinder_point_zone_init_common(this, size, name, p0, p1, radius)
105  class(cylinder_point_zone_t), intent(inout) :: this
106  integer, intent(in), optional :: size
107  character(len=*), intent(in) :: name
108  real(kind=rp), intent(in), dimension(3) :: p0
109  real(kind=rp), intent(in), dimension(3) :: p1
110  real(kind=rp), intent(in) :: radius
111 
112  call this%init_base(size, name)
113 
114  this%p0 = p0
115  this%p1 = p1
116  this%radius = radius
117 
118  end subroutine cylinder_point_zone_init_common
119 
121  subroutine cylinder_point_zone_free(this)
122  class(cylinder_point_zone_t), intent(inout) :: this
123 
124  call this%free_base()
125 
126  this%p0 = 0.0_rp
127  this%p1 = 0.0_rp
128  this%radius = 0.0_rp
129 
130  end subroutine cylinder_point_zone_free
131 
155  pure function cylinder_point_zone_criterion(this, x, y, z, j, k, l, e) result(is_inside)
156  class(cylinder_point_zone_t), intent(in) :: this
157  real(kind=rp), intent(in) :: x
158  real(kind=rp), intent(in) :: y
159  real(kind=rp), intent(in) :: z
160  integer, intent(in) :: j
161  integer, intent(in) :: k
162  integer, intent(in) :: l
163  integer, intent(in) :: e
164  logical :: is_inside
165 
166  real(kind=rp), dimension(3) :: p
167  real(kind=rp), dimension(3) :: centerline
168  real(kind=rp), dimension(3) :: vec_p
169  real(kind=rp) :: t
170  real(kind=rp), dimension(3) :: projection
171  real(kind=rp) :: distance
172 
173  p = [x, y, z]
174 
175  centerline = this%p1 - this%p0
176  vec_p = p - this%p0
177  t = dot_product(vec_p, centerline) / dot_product(centerline, centerline)
178 
179  projection = this%p0 + t * centerline
180  distance = norm2(projection - p)
181 
182  is_inside = t >= 0.0_rp .and. t <= 1.0_rp .and. distance <= this%radius
183 
184  end function cylinder_point_zone_criterion
185 
186 end module cylinder_point_zone
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:44
Implements a cylinder geometry subset.
subroutine cylinder_point_zone_init_common(this, size, name, p0, p1, radius)
Initializes a cylinder point zone from its endpoint coordinates and radius.
subroutine cylinder_point_zone_free(this)
Destructor.
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