Neko 1.99.11
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
48 !> Base abstract type for point zones.
49 type, public, abstract :: point_zone_t
50 !> List of linear indices of the GLL points in the zone.
51 type(mask_t) :: mask
52 !> Scratch stack of integers to build the list mask.
53 type(stack_i4_t), private :: scratch
54 !> Size of the point zone mask.
55 integer :: size = 0
56 !> Flag to indicate if point_zone_finalize has been called and the mask
57 !! has been built.
58 logical, private :: finalized = .false.
59 !> Name of the point zone (used for retrieval in the point_zone_registry).
60 character(len=80) :: name
61 !> If we select the inverse of the criterion or not
62 logical :: invert = .false.
63 !> If we select to mark all points in the element containing points that
64 !! satisfy the criterion
65 logical :: full_elements = .false.
66 contains
67 !> Constructor for the point_zone_t base type.
68 procedure, pass(this) :: init_base => point_zone_init_base
69 !> Destructor for the point_zone_t base type.
70 procedure, pass(this) :: free_base => point_zone_free_base
71 !> Builds the mask from the scratch stack.
72 procedure, pass(this) :: finalize => point_zone_finalize
73 !> Adds a point's linear index to the scratch stack.
74 procedure, pass(this) :: add => point_zone_add
75 !> Maps the GLL points that verify a point_zone's `criterion` by adding
76 !! them to the stack.
77 procedure, pass(this) :: map => point_zone_map
78 !> The common constructor using a JSON object.
79 procedure(point_zone_init), pass(this), deferred :: init
80 !> Destructor.
81 procedure(point_zone_free), pass(this), deferred :: free
82 !> Defines the criterion of selection of a GLL point to the point_zone.
83 procedure(point_zone_criterion), pass(this), deferred :: criterion
84 end type point_zone_t
85
86 !> A helper type to build a list of polymorphic point_zones.
87 type, public :: point_zone_wrapper_t
88 class(point_zone_t), allocatable :: pz
90
91 !> A helper type to build a list of pointers to point_zones
92 type, public :: point_zone_pointer_t
93 class(point_zone_t), pointer :: pz => null()
95
96 abstract interface
97 !> Defines the criterion of selection of a GLL point to the point_zone.
98 !! @param x x-coordinate of the GLL point.
99 !! @param y y-coordinate of the GLL point.
100 !! @param z z-coordinate of the GLL point.
101 !! @param j 1st nonlinear index of the GLL point.
102 !! @param k 2nd nonlinear index of the GLL point.
103 !! @param l 3rd nonlinear index of the GLL point.
104 !! @param e element index of the GLL point.
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 !> The common constructor using a JSON object.
123 !! @param json Json object for the point zone.
124 !! @param size Size with which to initialize the stack
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 !> Destructor.
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 !> Point zone factory. Constructs, initializes, and maps the
145 !! point zone object.
146 !! @param object The object allocated by the factory.
147 !! @param json JSON object initializing the point zone.
148 !! @param dof Dofmap from which to map the point zone.
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 !> Point zone allocator.
158 !! @param object The object to be allocated.
159 !! @param type_name The name of the type to allocate.
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
170 !> Interface for an object allocator.
171 !! Implemented in the user modules, should allocate the `obj` to the custom
172 !! user type.
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 !> Called in user modules to add an allocator for custom types.
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
195 !> Registry of point zone allocators for user-defined types
196 type(allocator_entry), allocatable :: point_zone_registry(:)
197
198 !> The size of the `point_zone_registry`
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
206 !> Constructor for the point_zone_t base type.
207 !! @param size Size of the scratch stack.
208 !! @param name Name of the point zone.
209 !! @param invert Flag to indicate wether or not to invert the selection
210 !! of points.
211 !! @param full_elements Whether to mark all points in the element containing
212 !! points that satisfy the criterion.
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
234 !> Destructor for the point_zone_t base type.
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
246 !> Builds the mask from the scratch stack.
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
276 !> Adds a point's linear index to the scratch stack.
277 !! @param idx Linear index of the point to add.
278 !! @note The linear index of a point `(j,k,l,e)` can be retrieved using the
279 !! subroutine `linear_index(j,k,l,e,lx)` in the `utils` module.
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
292 !> Maps the GLL points that verify a point_zone's `criterion` by adding
293 !! them to the stack.
294 !! @param dof Dofmap of points to go through.
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
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:281
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
pure integer function, dimension(4), public nonlinear_index(linear_index, lx, ly, lz)
Compute (i,j,k,l) array given linear index with sizes (1:lx, 1:ly, 1:lz, :).
Definition utils.f90:337
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