Neko 1.99.10
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
43 !> A sphere-shaped point zone.
44 !! @details As defined here, a sphere is described by its center of
45 !! coordinates `x0,y0,z0` and its radius, specified in the json file
46 !! as e.g. `"center": [<x0>, <y0>, <z0>]", "radius": <r>`.
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
53 !> Constructor from json object file.
54 procedure, pass(this) :: init => sphere_point_zone_init_from_json
55 !> Destructor.
56 procedure, pass(this) :: free => sphere_point_zone_free
57 !> Defines the criterion of selection of a GLL point in the sphere point
58 !! zone.
59 procedure, pass(this) :: criterion => sphere_point_zone_criterion
60 end type sphere_point_zone_t
61
62contains
63
64 !> Constructor from json object file.
65 !! @param json Json object file.
66 !! @param size Size with which to initialize the stack
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, &
91 full_elements, x0, y0, z0, radius)
92
94
95 !> Initializes a sphere point zone from its center coordinates and radius.
96 !! @param size Size of the scratch stack.
97 !! @param name Name of the sphere point zone.
98 !! @param full_elements Whether to mark all points in the element containing
99 !! points that satisfy the criterion.
100 !! @param x0 Sphere center's x-coordinate.
101 !! @param y0 Sphere center's y-coordinate.
102 !! @param z0 Sphere center's z-coordinate.
103 !! @param radius Sphere radius.
104 subroutine sphere_point_zone_init_common(this, size, name, invert, &
105 full_elements, 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
125 !> Destructor.
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
138 !> Defines the criterion of selection of a GLL point in the sphere point zone.
139 !! A GLL point of coordinates \f$ \vec{X} = (x, y, z) \f$ is considered as
140 !! being inside the zone if:
141 !! \f{eqnarray*}{
142 !! |\vec{X} - \vec{X_0}|^2 \le r
143 !! \f}
144 !! Where \f$ r \f$ is the radius of the sphere and
145 !! \f$ \vec{X_0} = (x_0, y_0, z_0) \f$
146 !! the coordinates of its center.
147 !! @param x x-coordinate of the GLL point.
148 !! @param y y-coordinate of the GLL point.
149 !! @param z z-coordinate of the GLL point.
150 !! @param j 1st nonlinear index of the GLL point.
151 !! @param k 2nd nonlinear index of the GLL point.
152 !! @param l 3rd nonlinear index of the GLL point.
153 !! @param e element index of the GLL point.
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:14
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.