Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
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
61
62contains
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 logical :: full_elements
77
78 call json_get(json, "name", name)
79 call json_get_or_lookup(json, "start", p0)
80 call json_get_or_lookup(json, "end", p1)
81 call json_get_or_lookup(json, "radius", radius)
82
83 ! Needed to use `shape` because of input name.
84 if (all(shape(p0) .ne. (/3/))) then
85 call neko_error("Cylinder point zone: invalid start point")
86 end if
87
88 if (all(shape(p1) .ne. (/3/))) then
89 call neko_error("Cylinder point zone: invalid end point")
90 end if
91
92 if (radius .lt. 0.0_rp) then
93 call neko_error("Cylinder point zone: invalid radius")
94 end if
95
96 call json_get_or_default(json, "invert", invert, .false.)
97 call json_get_or_default(json, "full_elements", full_elements, .false.)
98
99 call cylinder_point_zone_init_common(this, size, trim(name), invert, full_elements, &
100 p0, p1, radius)
101
103
112 subroutine cylinder_point_zone_init_common(this, size, name, invert, full_elements, &
113 p0, p1, radius)
114 class(cylinder_point_zone_t), intent(inout) :: this
115 integer, intent(in), optional :: size
116 character(len=*), intent(in) :: name
117 logical, intent(in) :: invert
118 logical, intent(in) :: full_elements
119 real(kind=rp), intent(in), dimension(3) :: p0
120 real(kind=rp), intent(in), dimension(3) :: p1
121 real(kind=rp), intent(in) :: radius
122
123
124 call this%init_base(size, name, invert, full_elements)
125
126 this%p0 = p0
127 this%p1 = p1
128 this%radius = radius
129
131
134 class(cylinder_point_zone_t), intent(inout) :: this
135
136 call this%free_base()
137
138 this%p0 = 0.0_rp
139 this%p1 = 0.0_rp
140 this%radius = 0.0_rp
141
142 end subroutine cylinder_point_zone_free
143
167 pure function cylinder_point_zone_criterion(this, x, y, z, j, k, l, e) &
168 result(is_inside)
169 class(cylinder_point_zone_t), intent(in) :: this
170 real(kind=rp), intent(in) :: x
171 real(kind=rp), intent(in) :: y
172 real(kind=rp), intent(in) :: z
173 integer, intent(in) :: j
174 integer, intent(in) :: k
175 integer, intent(in) :: l
176 integer, intent(in) :: e
177 logical :: is_inside
178
179 real(kind=rp), dimension(3) :: p
180 real(kind=rp), dimension(3) :: centerline
181 real(kind=rp), dimension(3) :: vec_p
182 real(kind=rp) :: t
183 real(kind=rp), dimension(3) :: projection
184 real(kind=rp) :: distance
185
186 p = [x, y, z]
187
188 centerline = this%p1 - this%p0
189 vec_p = p - this%p0
190 t = dot_product(vec_p, centerline) / dot_product(centerline, centerline)
191
192 projection = this%p0 + t * centerline
193 distance = norm2(projection - p)
194
195 is_inside = t >= 0.0_rp .and. t <= 1.0_rp .and. distance <= this%radius
196
198
199end module cylinder_point_zone
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Implements a cylinder geometry subset.
subroutine cylinder_point_zone_init_common(this, size, name, invert, full_elements, 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.
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.
Utilities.
Definition utils.f90:35
Base abstract type for point zones.