Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
point_zone.f90
Go to the documentation of this file.
1! Copyright (c) 2019-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! Implements a zone as a subset of GLL points in the mesh
35 use utils, only : neko_typename_len
36 use stack, only: stack_i4_t
37 use num_types, only: rp
39 use dofmap, only: dofmap_t
40 use json_module, only: json_file
42 use mask, only: mask_t
44 use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr, c_associated
45 implicit none
46 private
47
49 type, public, abstract :: point_zone_t
51 type(mask_t) :: mask
53 type(stack_i4_t), private :: scratch
55 integer :: size = 0
58 logical, private :: finalized = .false.
60 character(len=80) :: name
62 logical :: invert = .false.
65 logical :: full_elements = .false.
66 contains
68 procedure, pass(this) :: init_base => point_zone_init_base
70 procedure, pass(this) :: free_base => point_zone_free_base
72 procedure, pass(this) :: finalize => point_zone_finalize
74 procedure, pass(this) :: add => point_zone_add
77 procedure, pass(this) :: map => point_zone_map
79 procedure(point_zone_init), pass(this), deferred :: init
81 procedure(point_zone_free), pass(this), deferred :: free
83 procedure(point_zone_criterion), pass(this), deferred :: criterion
84 end type point_zone_t
85
87 type, public :: point_zone_wrapper_t
88 class(point_zone_t), allocatable :: pz
90
92 type, public :: point_zone_pointer_t
93 class(point_zone_t), pointer :: pz => null()
95
96 abstract interface
97
105 pure function point_zone_criterion(this, x, y, z, j, k, l, e) &
106 result(is_inside)
107 import :: point_zone_t
108 import :: rp
109 class(point_zone_t), intent(in) :: this
110 real(kind=rp), intent(in) :: x
111 real(kind=rp), intent(in) :: y
112 real(kind=rp), intent(in) :: z
113 integer, intent(in) :: j
114 integer, intent(in) :: k
115 integer, intent(in) :: l
116 integer, intent(in) :: e
117 logical :: is_inside
118 end function point_zone_criterion
119 end interface
120
121 abstract interface
122
125 subroutine point_zone_init(this, json, size)
126 import :: point_zone_t
127 import :: json_file
128 import :: dofmap_t
129 class(point_zone_t), intent(inout) :: this
130 type(json_file), intent(inout) :: json
131 integer, intent(in) :: size
132 end subroutine point_zone_init
133 end interface
134
135 abstract interface
136
137 subroutine point_zone_free(this)
138 import :: point_zone_t
139 class(point_zone_t), intent(inout) :: this
140 end subroutine point_zone_free
141 end interface
142
143 interface
144
149 module subroutine point_zone_factory(object, json, dof)
150 class(point_zone_t), allocatable, intent(inout) :: object
151 type(json_file), intent(inout) :: json
152 type(dofmap_t), intent(inout), optional :: dof
153 end subroutine point_zone_factory
154 end interface
155
156 interface
157
160 module subroutine point_zone_allocator(object, type_name)
161 class(point_zone_t), allocatable, intent(inout) :: object
162 character(len=:), allocatable, intent(in) :: type_name
163 end subroutine point_zone_allocator
164 end interface
165
166 !
167 ! Machinery for injecting user-defined types
168 !
169
173 abstract interface
174 subroutine point_zone_allocate(obj)
175 import point_zone_t
176 class(point_zone_t), allocatable, intent(inout) :: obj
177 end subroutine point_zone_allocate
178 end interface
179
180 interface
181
182 module subroutine register_point_zone(type_name, allocator)
183 character(len=*), intent(in) :: type_name
184 procedure(point_zone_allocate), pointer, intent(in) :: allocator
185 end subroutine register_point_zone
186 end interface
187
188 ! A name-allocator pair for user-defined types. A helper type to define a
189 ! registry of custom allocators.
190 type allocator_entry
191 character(len=NEKO_TYPENAME_LEN) :: type_name
192 procedure(point_zone_allocate), pointer, nopass :: allocator
193 end type allocator_entry
194
196 type(allocator_entry), allocatable :: point_zone_registry(:)
197
199 integer :: point_zone_registry_size = 0
200
201 public :: point_zone_factory, point_zone_allocator, register_point_zone, &
202 point_zone_allocate
203
204contains
205
213 subroutine point_zone_init_base(this, size, name, invert, full_elements)
214 class(point_zone_t), intent(inout) :: this
215 integer, intent(in), optional :: size
216 character(len=*), intent(in) :: name
217 logical, intent(in) :: invert
218 logical, intent(in) :: full_elements
219
220 call point_zone_free_base(this)
221
222 if (present(size)) then
223 call this%scratch%init(size)
224 else
225 call this%scratch%init()
226 end if
227
228 this%name = trim(name)
229 this%invert = invert
230 this%full_elements = full_elements
231
232 end subroutine point_zone_init_base
233
235 subroutine point_zone_free_base(this)
236 class(point_zone_t), intent(inout) :: this
237
238 this%finalized = .false.
239 this%size = 0
240
241 call this%scratch%free()
242 call this%mask%free()
243
244 end subroutine point_zone_free_base
245
247 subroutine point_zone_finalize(this)
248 class(point_zone_t), intent(inout) :: this
249 integer, pointer :: tp(:)
250
251 if (.not. this%finalized) then
252
253 if (this%scratch%size() .ne. 0) then
254
255 tp => this%scratch%array()
256 this%size = this%scratch%size()
257 call this%mask%init(tp, this%size)
258
259 call this%scratch%clear()
260 else
261
262 this%size = 0
263 tp => this%scratch%array()
264 call this%mask%init(tp, this%size)
265
266 call this%scratch%clear()
267
268 end if
269
270 this%finalized = .true.
271
272 end if
273
274 end subroutine point_zone_finalize
275
280 subroutine point_zone_add(this, idx)
281 class(point_zone_t), intent(inout) :: this
282 integer, intent(inout) :: idx
283
284 if (this%finalized) then
285 call neko_error('Point zone already finalized')
286 end if
287
288 call this%scratch%push(idx)
289
290 end subroutine point_zone_add
291
295 subroutine point_zone_map(this, dof)
296 class(point_zone_t), intent(inout) :: this
297 type(dofmap_t), intent(in) :: dof
298
299 integer :: i, ix, iy, iz, ie, nlindex(4), lx, idx
300 real(kind=rp) :: x, y, z
301
302 lx = dof%Xh%lx
303
304 i = 1
305 do while (i <= dof%size())
306 nlindex = nonlinear_index(i, lx, lx, lx)
307 x = dof%x%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
308 y = dof%y%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
309 z = dof%z%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
310 ix = nlindex(1)
311 iy = nlindex(2)
312 iz = nlindex(3)
313 ie = nlindex(4)
314
315 if (this%invert .neqv. this%criterion(x, y, z, ix, iy, iz, ie)) then
316
317 if (.not. this%full_elements) then
318 idx = i
319 call this%add(idx)
320 i = i + 1
321 else
322 do iz = 1, lx
323 do iy = 1, lx
324 do ix = 1, lx
325 idx = linear_index(ix, iy, iz, ie, lx, lx, lx)
326 call this%add(idx)
327 end do
328 end do
329 end do
330 i = idx + 1
331 end if
332 else
333 i = i + 1
334
335 end if
336 end do
337
338 end subroutine point_zone_map
339
340end module point_zone
__inline__ __device__ void nonlinear_index(const int idx, const int lx, int *index)
Definition bc_utils.h:44
Map a Fortran array to a device (allocate and associate)
Definition device.F90:83
Copy data between host and device (or device and device)
Definition device.F90:72
Defines the criterion of selection of a GLL point to the point_zone.
The common constructor using a JSON object.
Device abstraction, common interface for various accelerators.
Definition device.F90:34
subroutine, public device_free(x_d)
Deallocate memory on the device.
Definition device.F90:243
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
NEKTON map.
Definition map.f90:3
Object for handling masks in Neko.
Definition mask.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
subroutine point_zone_init_base(this, size, name, invert, full_elements)
Constructor for the point_zone_t base type.
subroutine point_zone_free_base(this)
Destructor for the point_zone_t base type.
subroutine point_zone_add(this, idx)
Adds a point's linear index to the scratch stack.
subroutine point_zone_finalize(this)
Builds the mask from the scratch stack.
subroutine point_zone_map(this, dof)
Maps the GLL points that verify a point_zone's criterion by adding them to the stack.
Implements a dynamic stack ADT.
Definition stack.f90:49
Utilities.
Definition utils.f90:35
pure integer function, public linear_index(i, j, k, l, lx, ly, lz)
Compute the address of a (i,j,k,l) array with sizes (1:lx, 1:ly, 1:lz, :)
Definition utils.f90:328
integer, parameter, public neko_typename_len
Definition utils.f90:44
Type for consistently handling masks in Neko. This type encapsulates the mask array and its associate...
Definition mask.f90:51
A helper type to build a list of pointers to point_zones.
Base abstract type for point zones.
A helper type to build a list of polymorphic point_zones.
Integer based stack.
Definition stack.f90:77