Neko  0.8.1
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
37  use json_utils, only: json_get
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
58  procedure, pass(this) :: criterion => sphere_point_zone_criterion
59  end type sphere_point_zone_t
60 
61 contains
62 
66  subroutine sphere_point_zone_init_from_json(this, json, size)
67  class(sphere_point_zone_t), intent(inout) :: this
68  type(json_file), intent(inout) :: json
69  integer, intent(in) :: size
70 
71  character(len=:), allocatable :: str_read
72  real(kind=rp), allocatable :: values(:)
73  real(kind=rp) :: value
74  real(kind=rp) :: x0, y0, z0, radius
75 
76  call json_get(json, "center", values)
77  x0 = values(1)
78  y0 = values(2)
79  z0 = values(3)
80  call json_get(json, "radius", value)
81  radius = value
82  call json_get(json, "name", str_read)
83 
84  call sphere_point_zone_init_common(this, size, trim(str_read), x0, &
85  y0, z0, radius)
86 
88 
96  subroutine sphere_point_zone_init_common(this, size, name, x0, y0, z0, radius)
97  class(sphere_point_zone_t), intent(inout) :: this
98  integer, intent(in), optional :: size
99  character(len=*), intent(in) :: name
100  real(kind=rp), intent(in) :: x0
101  real(kind=rp), intent(in) :: y0
102  real(kind=rp), intent(in) :: z0
103  real(kind=rp), intent(in) :: radius
104 
105  call this%init_base(size, name)
106 
107  this%x0 = x0
108  this%y0 = y0
109  this%z0 = z0
110  this%radius = radius
111 
112  end subroutine sphere_point_zone_init_common
113 
115  subroutine sphere_point_zone_free(this)
116  class(sphere_point_zone_t), intent(inout) :: this
117 
118  call this%free_base()
119 
120  this%x0 = 0.0_rp
121  this%y0 = 0.0_rp
122  this%z0 = 0.0_rp
123  this%radius = 0.0_rp
124 
125  end subroutine sphere_point_zone_free
126 
142  pure function sphere_point_zone_criterion(this, x, y, z, j, k, l, e) result(is_inside)
143  class(sphere_point_zone_t), intent(in) :: this
144  real(kind=rp), intent(in) :: x
145  real(kind=rp), intent(in) :: y
146  real(kind=rp), intent(in) :: z
147  integer, intent(in) :: j
148  integer, intent(in) :: k
149  integer, intent(in) :: l
150  integer, intent(in) :: e
151  logical :: is_inside
152 
153  real(kind=rp) :: dist_from_center
154 
155  dist_from_center = sqrt( (x - this%x0)**2 + (y - this%y0)**2 + (z - this%z0)**2 )
156 
157  ! Inside if distance from center <= radius
158  is_inside = (dist_from_center .lt. this%radius .or. &
159  abscmp(dist_from_center, this%radius))
160 
161  end function sphere_point_zone_criterion
162 
163 end module sphere_point_zone
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:44
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, 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