Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
sphere_point_zone.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!
33! Implements a sphere geometry subset.
35 use point_zone, only: point_zone_t
36 use num_types, only: rp
38 use json_module, only: json_file
39 use math, only: abscmp
40 implicit none
41 private
42
47 type, public, extends(point_zone_t) :: sphere_point_zone_t
48 real(kind=rp) :: x0
49 real(kind=rp) :: y0
50 real(kind=rp) :: z0
51 real(kind=rp) :: radius
52 contains
54 procedure, pass(this) :: init => sphere_point_zone_init_from_json
56 procedure, pass(this) :: free => sphere_point_zone_free
59 procedure, pass(this) :: criterion => sphere_point_zone_criterion
60 end type sphere_point_zone_t
61
62contains
63
67 subroutine sphere_point_zone_init_from_json(this, json, size)
68 class(sphere_point_zone_t), intent(inout) :: this
69 type(json_file), intent(inout) :: json
70 integer, intent(in) :: size
71
72 character(len=:), allocatable :: str_read
73 real(kind=rp), allocatable :: values(:)
74 real(kind=rp) :: value
75 real(kind=rp) :: x0, y0, z0, radius
76 logical :: invert
77 logical :: full_elements
78
79 call json_get_or_lookup(json, "center", values)
80 x0 = values(1)
81 y0 = values(2)
82 z0 = values(3)
83 call json_get_or_lookup(json, "radius", value)
84 radius = value
85 call json_get(json, "name", str_read)
86
87 call json_get_or_default(json, "invert", invert, .false.)
88 call json_get_or_default(json, "full_elements", full_elements, .false.)
89
90 call sphere_point_zone_init_common(this, size, trim(str_read), invert, full_elements, &
91 x0, y0, z0, radius)
92
94
104 subroutine sphere_point_zone_init_common(this, size, name, invert, full_elements, &
105 x0, y0, z0, radius)
106 class(sphere_point_zone_t), intent(inout) :: this
107 integer, intent(in), optional :: size
108 character(len=*), intent(in) :: name
109 logical, intent(in) :: invert
110 logical, intent(in) :: full_elements
111 real(kind=rp), intent(in) :: x0
112 real(kind=rp), intent(in) :: y0
113 real(kind=rp), intent(in) :: z0
114 real(kind=rp), intent(in) :: radius
115
116 call this%init_base(size, name, invert, full_elements)
117
118 this%x0 = x0
119 this%y0 = y0
120 this%z0 = z0
121 this%radius = radius
122
123 end subroutine sphere_point_zone_init_common
124
126 subroutine sphere_point_zone_free(this)
127 class(sphere_point_zone_t), intent(inout) :: this
128
129 call this%free_base()
130
131 this%x0 = 0.0_rp
132 this%y0 = 0.0_rp
133 this%z0 = 0.0_rp
134 this%radius = 0.0_rp
135
136 end subroutine sphere_point_zone_free
137
154 pure function sphere_point_zone_criterion(this, x, y, z, j, k, l, e) &
155 result(is_inside)
156 class(sphere_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) :: dist_from_center
167
168 dist_from_center = sqrt( &
169 (x - this%x0)**2 + (y - this%y0)**2 + (z - this%z0)**2)
170
171 ! Inside if distance from center <= radius
172 is_inside = (dist_from_center .lt. this%radius .or. &
173 abscmp(dist_from_center, this%radius))
174
175 end function sphere_point_zone_criterion
176
177end module sphere_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.
Utilities for retrieving parameters from the case files.
Definition math.f90:60
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
subroutine sphere_point_zone_free(this)
Destructor.
subroutine sphere_point_zone_init_from_json(this, json, size)
Constructor from json object file.
subroutine sphere_point_zone_init_common(this, size, name, invert, full_elements, x0, y0, z0, radius)
Initializes a sphere point zone from its center coordinates and radius.
pure logical function sphere_point_zone_criterion(this, x, y, z, j, k, l, e)
Defines the criterion of selection of a GLL point in the sphere point zone. A GLL point of coordinate...
Base abstract type for point zones.