Neko 1.99.2
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 stack, only: stack_i4_t
36 use num_types, only: rp
38 use dofmap, only: dofmap_t
39 use json_module, only: json_file
41 use mask, only: mask_t
43 use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr, c_associated
44 implicit none
45 private
46
48 type, public, abstract :: point_zone_t
50 type(mask_t) :: mask
52 type(stack_i4_t), private :: scratch
54 integer :: size = 0
57 logical, private :: finalized = .false.
59 character(len=80) :: name
61 logical :: invert = .false.
64 logical :: full_elements = .false.
65 contains
67 procedure, pass(this) :: init_base => point_zone_init_base
69 procedure, pass(this) :: free_base => point_zone_free_base
71 procedure, pass(this) :: finalize => point_zone_finalize
73 procedure, pass(this) :: add => point_zone_add
76 procedure, pass(this) :: map => point_zone_map
78 procedure(point_zone_init), pass(this), deferred :: init
80 procedure(point_zone_free), pass(this), deferred :: free
82 procedure(point_zone_criterion), pass(this), deferred :: criterion
83 end type point_zone_t
84
86 type, public :: point_zone_wrapper_t
87 class(point_zone_t), allocatable :: pz
89
91 type, public :: point_zone_pointer_t
92 class(point_zone_t), pointer :: pz => null()
94
95 abstract interface
96
104 pure function point_zone_criterion(this, x, y, z, j, k, l, e) &
105 result(is_inside)
106 import :: point_zone_t
107 import :: rp
108 class(point_zone_t), intent(in) :: this
109 real(kind=rp), intent(in) :: x
110 real(kind=rp), intent(in) :: y
111 real(kind=rp), intent(in) :: z
112 integer, intent(in) :: j
113 integer, intent(in) :: k
114 integer, intent(in) :: l
115 integer, intent(in) :: e
116 logical :: is_inside
117 end function point_zone_criterion
118 end interface
119
120 abstract interface
121
124 subroutine point_zone_init(this, json, size)
125 import :: point_zone_t
126 import :: json_file
127 import :: dofmap_t
128 class(point_zone_t), intent(inout) :: this
129 type(json_file), intent(inout) :: json
130 integer, intent(in) :: size
131 end subroutine point_zone_init
132 end interface
133
134 abstract interface
135
136 subroutine point_zone_free(this)
137 import :: point_zone_t
138 class(point_zone_t), intent(inout) :: this
139 end subroutine point_zone_free
140 end interface
141
142 interface
143
148 module subroutine point_zone_factory(object, json, dof)
149 class(point_zone_t), allocatable, intent(inout) :: object
150 type(json_file), intent(inout) :: json
151 type(dofmap_t), intent(inout), optional :: dof
152 end subroutine point_zone_factory
153 end interface
154
155 interface
156
159 module subroutine point_zone_allocator(object, type_name)
160 class(point_zone_t), allocatable, intent(inout) :: object
161 character(len=:), allocatable, intent(in) :: type_name
162 end subroutine point_zone_allocator
163 end interface
164
165 !
166 ! Machinery for injecting user-defined types
167 !
168
172 abstract interface
173 subroutine point_zone_allocate(obj)
174 import point_zone_t
175 class(point_zone_t), allocatable, intent(inout) :: obj
176 end subroutine point_zone_allocate
177 end interface
178
179 interface
180
181 module subroutine register_point_zone(type_name, allocator)
182 character(len=*), intent(in) :: type_name
183 procedure(point_zone_allocate), pointer, intent(in) :: allocator
184 end subroutine register_point_zone
185 end interface
186
187 ! A name-allocator pair for user-defined types. A helper type to define a
188 ! registry of custom allocators.
189 type allocator_entry
190 character(len=20) :: type_name
191 procedure(point_zone_allocate), pointer, nopass :: allocator
192 end type allocator_entry
193
195 type(allocator_entry), allocatable :: point_zone_registry(:)
196
198 integer :: point_zone_registry_size = 0
199
200 public :: point_zone_factory, point_zone_allocator, register_point_zone, &
201 point_zone_allocate
202
203contains
204
212 subroutine point_zone_init_base(this, size, name, invert, full_elements)
213 class(point_zone_t), intent(inout) :: this
214 integer, intent(in), optional :: size
215 character(len=*), intent(in) :: name
216 logical, intent(in) :: invert
217 logical, intent(in) :: full_elements
218
219 call point_zone_free_base(this)
220
221 if (present(size)) then
222 call this%scratch%init(size)
223 else
224 call this%scratch%init()
225 end if
226
227 this%name = trim(name)
228 this%invert = invert
229 this%full_elements = full_elements
230
231 end subroutine point_zone_init_base
232
234 subroutine point_zone_free_base(this)
235 class(point_zone_t), intent(inout) :: this
236
237 this%finalized = .false.
238 this%size = 0
239
240 call this%scratch%free()
241 call this%mask%free()
242
243 end subroutine point_zone_free_base
244
246 subroutine point_zone_finalize(this)
247 class(point_zone_t), intent(inout) :: this
248 integer, pointer :: tp(:)
249
250 if (.not. this%finalized) then
251
252 if (this%scratch%size() .ne. 0) then
253
254 tp => this%scratch%array()
255 this%size = this%scratch%size()
256 call this%mask%init(tp, this%size)
257
258 call this%scratch%clear()
259 else
260
261 this%size = 0
262 tp => this%scratch%array()
263 call this%mask%init(tp, this%size)
264
265 call this%scratch%clear()
266
267 end if
268
269 this%finalized = .true.
270
271 end if
272
273 end subroutine point_zone_finalize
274
279 subroutine point_zone_add(this, idx)
280 class(point_zone_t), intent(inout) :: this
281 integer, intent(inout) :: idx
282
283 if (this%finalized) then
284 call neko_error('Point zone already finalized')
285 end if
286
287 call this%scratch%push(idx)
288
289 end subroutine point_zone_add
290
294 subroutine point_zone_map(this, dof)
295 class(point_zone_t), intent(inout) :: this
296 type(dofmap_t), intent(in) :: dof
297
298 integer :: i, ix, iy, iz, ie, nlindex(4), lx, idx
299 real(kind=rp) :: x, y, z
300
301 lx = dof%Xh%lx
302
303 i = 1
304 do while (i <= dof%size())
305 nlindex = nonlinear_index(i, lx, lx, lx)
306 x = dof%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
307 y = dof%y(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
308 z = dof%z(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
309 ix = nlindex(1)
310 iy = nlindex(2)
311 iz = nlindex(3)
312 ie = nlindex(4)
313
314 if (this%invert .neqv. this%criterion(x, y, z, ix, iy, iz, ie)) then
315
316 if (.not. this%full_elements) then
317 idx = i
318 call this%add(idx)
319 i = i + 1
320 else
321 do iz = 1, lx
322 do iy = 1, lx
323 do ix = 1, lx
324 idx = linear_index(ix, iy, iz, ie, lx, lx, lx)
325 call this%add(idx)
326 end do
327 end do
328 end do
329 i = idx + 1
330 end if
331 else
332 i = i + 1
333
334 end if
335 end do
336
337 end subroutine point_zone_map
338
339end 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:77
Copy data between host and device (or device and device)
Definition device.F90:71
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:219
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:12
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:35
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:237
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:63