Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
point_zone_fctry.f90
Go to the documentation of this file.
1! Copyright (c) 2023-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!
33!
35submodule(point_zone) point_zone_fctry
39 use json_utils, only: json_get
41 implicit none
42
43 ! List of all possible types created by the factory routine
44 character(len=20) :: POINTZ_KNOWN_TYPES(3) = [character(len=20) :: &
45 "box", &
46 "sphere", &
47 "cylinder"]
48
49contains
50
56 module subroutine point_zone_factory(object, json, dof)
57 class(point_zone_t), allocatable, intent(inout) :: object
58 type(json_file), intent(inout) :: json
59 type(dofmap_t), intent(inout), optional :: dof
60 character(len=:), allocatable :: type_name
61 character(len=:), allocatable :: type_string
62
63 call json_get(json, "geometry", type_name)
64
65 call point_zone_allocator(object, type_name)
66
67 if (present(dof)) then
68 call object%init(json, dof%size())
69 call object%map(dof)
70 call object%finalize()
71 else
72 ! This is for initializing zones inside a combine point zone,
73 ! as they don't need to be mapped
74 call object%init(json, 1)
75 call object%finalize()
76 end if
77 end subroutine point_zone_factory
78
79 module subroutine point_zone_allocator(object, type_name)
80 class(point_zone_t), allocatable, intent(inout) :: object
81 character(len=:), allocatable, intent(in) :: type_name
82 integer :: i
83
84 if (allocated(object)) then
85 call object%free()
86 deallocate(object)
87 end if
88
89 select case (trim(type_name))
90 case ('box')
91 allocate(box_point_zone_t::object)
92 case ('sphere')
93 allocate(sphere_point_zone_t::object)
94 case ('cylinder')
95 allocate(cylinder_point_zone_t::object)
96 case default
97 do i = 1, point_zone_registry_size
98 if (trim(type_name) .eq. trim(point_zone_registry(i)%type_name)) then
99 call point_zone_registry(i)%allocator(object)
100 return
101 end if
102 end do
103 call neko_error("Unknown point zone type: " // trim(type_name))
104 end select
105 end subroutine point_zone_allocator
106
112 module subroutine register_point_zone(type_name, allocator)
113 character(len=*), intent(in) :: type_name
114 procedure(point_zone_allocate), pointer, intent(in) :: allocator
115 type(allocator_entry), allocatable :: temp(:)
116 integer :: i
117
118 do i = 1, size(pointz_known_types)
119 if (trim(type_name) .eq. trim(pointz_known_types(i))) then
120 call neko_type_registration_error("point zone", type_name, .true.)
121 end if
122 end do
123
124 do i = 1, point_zone_registry_size
125 if (trim(type_name) .eq. trim(point_zone_registry(i)%type_name)) then
126 call neko_type_registration_error("point zone", type_name, .false.)
127 end if
128 end do
129
130 ! Expand registry
131 if (point_zone_registry_size .eq. 0) then
132 allocate(point_zone_registry(1))
133 else
134 allocate(temp(point_zone_registry_size + 1))
135 temp(1:point_zone_registry_size) = point_zone_registry
136 call move_alloc(temp, point_zone_registry)
137 end if
138
139 point_zone_registry_size = point_zone_registry_size + 1
140 point_zone_registry(point_zone_registry_size)%type_name = type_name
141 point_zone_registry(point_zone_registry_size)%allocator => allocator
142
143 end subroutine register_point_zone
144
145end submodule point_zone_fctry
Retrieves a parameter by name or throws an error.
Implements a cylinder geometry subset.
Utilities for retrieving parameters from the case files.
Utilities.
Definition utils.f90:35
subroutine, public neko_type_registration_error(base_type, wrong_type, known)
Definition utils.f90:328