Neko  0.9.0
A portable framework for high-order spectral element flow simulations
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 
62 contains
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 
78  call json_get(json, "center", values)
79  x0 = values(1)
80  y0 = values(2)
81  z0 = values(3)
82  call json_get(json, "radius", value)
83  radius = value
84  call json_get(json, "name", str_read)
85 
86  call json_get_or_default(json, "invert", invert, .false.)
87 
88  call sphere_point_zone_init_common(this, size, trim(str_read), invert, &
89  x0, y0, z0, radius)
90 
92 
100  subroutine sphere_point_zone_init_common(this, size, name, invert, &
101  x0, y0, z0, radius)
102  class(sphere_point_zone_t), intent(inout) :: this
103  integer, intent(in), optional :: size
104  character(len=*), intent(in) :: name
105  logical, intent(in) :: invert
106  real(kind=rp), intent(in) :: x0
107  real(kind=rp), intent(in) :: y0
108  real(kind=rp), intent(in) :: z0
109  real(kind=rp), intent(in) :: radius
110 
111  call this%init_base(size, name, invert)
112 
113  this%x0 = x0
114  this%y0 = y0
115  this%z0 = z0
116  this%radius = radius
117 
118  end subroutine sphere_point_zone_init_common
119 
121  subroutine sphere_point_zone_free(this)
122  class(sphere_point_zone_t), intent(inout) :: this
123 
124  call this%free_base()
125 
126  this%x0 = 0.0_rp
127  this%y0 = 0.0_rp
128  this%z0 = 0.0_rp
129  this%radius = 0.0_rp
130 
131  end subroutine sphere_point_zone_free
132 
149  pure function sphere_point_zone_criterion(this, x, y, z, j, k, l, e) &
150  result(is_inside)
151  class(sphere_point_zone_t), intent(in) :: this
152  real(kind=rp), intent(in) :: x
153  real(kind=rp), intent(in) :: y
154  real(kind=rp), intent(in) :: z
155  integer, intent(in) :: j
156  integer, intent(in) :: k
157  integer, intent(in) :: l
158  integer, intent(in) :: e
159  logical :: is_inside
160 
161  real(kind=rp) :: dist_from_center
162 
163  dist_from_center = sqrt( &
164  (x - this%x0)**2 + (y - this%y0)**2 + (z - this%z0)**2)
165 
166  ! Inside if distance from center <= radius
167  is_inside = (dist_from_center .lt. this%radius .or. &
168  abscmp(dist_from_center, this%radius))
169 
170  end function sphere_point_zone_criterion
171 
172 end module sphere_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
Utilities for retrieving parameters from the case files.
Definition: json_utils.f90:34
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, 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.
Definition: point_zone.f90:47