Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
uset.f90
Go to the documentation of this file.
1! Copyright (c) 2019-2023, 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!
39module uset
40 use utils, only : neko_error
41 use num_types, only : i8, dp
42 use htable, only : htable_i4_t, htable_iter_i4_t, &
45 implicit none
46 private
47
49 type, private, abstract :: uset_t
50 contains
51 procedure(uset_init), pass(this), deferred :: init
52 procedure(uset_free), pass(this), deferred :: free
53 procedure(uset_size), pass(this), deferred :: size
54 procedure(uset_clear), pass(this), deferred :: clear
55 procedure(uset_element), pass(this), deferred :: element
56 procedure(uset_add), pass(this), deferred :: add
57 procedure(uset_remove), pass(this), deferred :: remove
58 end type uset_t
59
61 type, public, extends(uset_t) :: uset_i4_t
62 type(htable_i4_t) :: t
63 type(htable_iter_i4_t) :: it
64 contains
65 procedure, pass(this) :: init => uset_i4_init
66 procedure, pass(this) :: free => uset_i4_free
67 procedure, pass(this) :: size => uset_i4_size
68 procedure, pass(this) :: clear => uset_i4_clear
69 procedure, pass(this) :: element => uset_i4_element
70 procedure, pass(this) :: add => uset_i4_add
71 procedure, pass(this) :: remove => uset_i4_remove
72 procedure, pass(this) :: iter_init => uset_i4_iter_init
73 procedure, pass(this) :: iter_next => uset_i4_iter_next
74 procedure, pass(this) :: iter_value => uset_i4_iter_value
75 end type uset_i4_t
76
78 type, public, extends(uset_t) :: uset_i8_t
79 type(htable_i8_t) :: t
80 type(htable_iter_i8_t) :: it
81 contains
82 procedure, pass(this) :: init => uset_i8_init
83 procedure, pass(this) :: free => uset_i8_free
84 procedure, pass(this) :: size => uset_i8_size
85 procedure, pass(this) :: clear => uset_i8_clear
86 procedure, pass(this) :: element => uset_i8_element
87 procedure, pass(this) :: add => uset_i8_add
88 procedure, pass(this) :: remove => uset_i8_remove
89 procedure, pass(this) :: iter_init => uset_i8_iter_init
90 procedure, pass(this) :: iter_next => uset_i8_iter_next
91 procedure, pass(this) :: iter_value => uset_i8_iter_value
92 end type uset_i8_t
93
95 type, public, extends(uset_t) :: uset_r8_t
96 type(htable_r8_t) :: t
97 type(htable_iter_r8_t) :: it
98 contains
99 procedure, pass(this) :: init => uset_r8_init
100 procedure, pass(this) :: free => uset_r8_free
101 procedure, pass(this) :: size => uset_r8_size
102 procedure, pass(this) :: clear => uset_r8_clear
103 procedure, pass(this) :: element => uset_r8_element
104 procedure, pass(this) :: add => uset_r8_add
105 procedure, pass(this) :: remove => uset_r8_remove
106 procedure, pass(this) :: iter_init => uset_r8_iter_init
107 procedure, pass(this) :: iter_next => uset_r8_iter_next
108 procedure, pass(this) :: iter_value => uset_r8_iter_value
109 end type uset_r8_t
110
112 abstract interface
113 subroutine uset_init(this, n)
114 import uset_t
115 class(uset_t), intent(inout) :: this
116 integer, optional :: n
117 end subroutine uset_init
118 end interface
119
121 abstract interface
122 subroutine uset_free(this)
123 import uset_t
124 class(uset_t), intent(inout) :: this
125 end subroutine uset_free
126 end interface
127
129 abstract interface
130 pure function uset_size(this) result(entries)
131 import uset_t
132 class(uset_t), intent(in) :: this
133 integer :: entries
134 end function uset_size
135 end interface
136
138 abstract interface
139 subroutine uset_clear(this)
140 import uset_t
141 class(uset_t), intent(inout) :: this
142 end subroutine uset_clear
143 end interface
144
146 abstract interface
147 function uset_element(this, key) result(res)
148 import uset_t
149 class(uset_t), intent(inout) :: this
150 class(*), intent(inout) :: key
151 logical :: res
152 end function uset_element
153 end interface
154
156 abstract interface
157 subroutine uset_add(this, key)
158 import uset_t
159 class(uset_t), intent(inout) :: this
160 class(*), intent(inout) :: key
161 end subroutine uset_add
162 end interface
163
165 abstract interface
166 subroutine uset_remove(this, key)
167 import uset_t
168 class(uset_t), intent(inout) :: this
169 class(*), intent(inout) :: key
170 end subroutine uset_remove
171 end interface
172
173contains
174
176 subroutine uset_i4_init(this, n)
177 class(uset_i4_t), intent(inout) :: this
178 integer, optional :: n
179
180 if (present(n)) then
181 call this%t%init(n)
182 else
183 call this%t%init(64)
184 end if
185 end subroutine uset_i4_init
186
188 subroutine uset_i4_free(this)
189 class(uset_i4_t), intent(inout) :: this
190
191 nullify(this%it%t)
192 call this%t%free()
193
194 end subroutine uset_i4_free
195
197 pure function uset_i4_size(this) result(entries)
198 class(uset_i4_t), intent(in) :: this
199 integer :: entries
200
201 entries = this%t%num_entries()
202
203 end function uset_i4_size
204
206 subroutine uset_i4_clear(this)
207 class(uset_i4_t), intent(inout) :: this
208
209 call this%t%clear()
210 end subroutine uset_i4_clear
211
213 function uset_i4_element(this, key) result(res)
214 class(uset_i4_t), intent(inout) :: this
215 class(*), intent(inout) :: key
216 integer :: data
217 logical :: res
218
219 select type (key)
220 type is (integer)
221 res = (this%t%get(key, data) .eq. 0)
222 class default
223 res = .false.
224 end select
225 end function uset_i4_element
226
228 subroutine uset_i4_add(this, key)
229 class(uset_i4_t), intent(inout) :: this
230 class(*), intent(inout) :: key
231 integer :: data
232
233 select type (key)
234 type is (integer)
235 data = key
236 call this%t%set(key, data)
237 class default
238 call neko_error("Invalid key")
239 end select
240 end subroutine uset_i4_add
241
243 subroutine uset_i4_remove(this, key)
244 class(uset_i4_t), intent(inout) :: this
245 class(*), intent(inout) :: key
246
247 select type (key)
248 type is (integer)
249 call this%t%remove(key)
250 class default
251 call neko_error("Invalid key")
252 end select
253 end subroutine uset_i4_remove
254
256 subroutine uset_i4_iter_init(this)
257 class(uset_i4_t), target, intent(inout) :: this
258 call this%it%init(this%t)
259 end subroutine uset_i4_iter_init
260
262 function uset_i4_iter_next(this) result(valid)
263 class(uset_i4_t), intent(inout) :: this
264 logical :: valid
265 valid = this%it%next()
266 end function uset_i4_iter_next
267
269 function uset_i4_iter_value(this) result(value)
270 class(uset_i4_t), target, intent(inout) :: this
271 integer, pointer :: value
272 value => this%it%value()
273 end function uset_i4_iter_value
274
276 subroutine uset_i8_init(this, n)
277 class(uset_i8_t), intent(inout) :: this
278 integer, optional :: n
279
280 if (present(n)) then
281 call this%t%init(n)
282 else
283 call this%t%init(64)
284 end if
285 end subroutine uset_i8_init
286
288 subroutine uset_i8_free(this)
289 class(uset_i8_t), intent(inout) :: this
290
291 nullify(this%it%t)
292 call this%t%free()
293
294 end subroutine uset_i8_free
295
297 pure function uset_i8_size(this) result(entries)
298 class(uset_i8_t), intent(in) :: this
299 integer :: entries
300
301 entries = this%t%num_entries()
302
303 end function uset_i8_size
304
306 subroutine uset_i8_clear(this)
307 class(uset_i8_t), intent(inout) :: this
308
309 call this%t%clear()
310 end subroutine uset_i8_clear
311
313 function uset_i8_element(this, key) result(res)
314 class(uset_i8_t), intent(inout) :: this
315 class(*), intent(inout) :: key
316 integer(kind=i8) :: data
317 logical :: res
318
319 select type (key)
320 type is (integer(i8))
321 res = (this%t%get(key, data) .eq. 0)
322 class default
323 res = .false.
324 end select
325 end function uset_i8_element
326
328 subroutine uset_i8_add(this, key)
329 class(uset_i8_t), intent(inout) :: this
330 class(*), intent(inout) :: key
331 integer(kind=i8) :: data
332
333 select type (key)
334 type is (integer(i8))
335 data = key
336 call this%t%set(key, data)
337 class default
338 call neko_error("Invalid key")
339 end select
340 end subroutine uset_i8_add
341
343 subroutine uset_i8_remove(this, key)
344 class(uset_i8_t), intent(inout) :: this
345 class(*), intent(inout) :: key
346
347 select type (key)
348 type is (integer(i8))
349 call this%t%remove(key)
350 class default
351 call neko_error("Invalid key")
352 end select
353 end subroutine uset_i8_remove
354
356 subroutine uset_i8_iter_init(this)
357 class(uset_i8_t), target, intent(inout) :: this
358 call this%it%init(this%t)
359 end subroutine uset_i8_iter_init
360
362 function uset_i8_iter_next(this) result(valid)
363 class(uset_i8_t), intent(inout) :: this
364 logical :: valid
365 valid = this%it%next()
366 end function uset_i8_iter_next
367
369 function uset_i8_iter_value(this) result(value)
370 class(uset_i8_t), target, intent(inout) :: this
371 integer(kind=i8), pointer :: value
372
373 ! We should not need this extra select block, and it works great
374 ! without it for GNU, Intel and NEC, but breaks horribly on Cray
375 ! (>11.0.x) when using high opt. levels.
376 select type (hp => this)
377 type is (uset_i8_t)
378 value => hp%it%value()
379 class default
380 call neko_error('Invalid uset htable iter (i8)')
381 end select
382 end function uset_i8_iter_value
383
385 subroutine uset_r8_init(this, n)
386 class(uset_r8_t), intent(inout) :: this
387 integer, optional :: n
388
389 if (present(n)) then
390 call this%t%init(n)
391 else
392 call this%t%init(64)
393 end if
394 end subroutine uset_r8_init
395
397 subroutine uset_r8_free(this)
398 class(uset_r8_t), intent(inout) :: this
399
400 call this%t%free()
401
402 end subroutine uset_r8_free
403
405 pure function uset_r8_size(this) result(entries)
406 class(uset_r8_t), intent(in) :: this
407 integer :: entries
408
409 entries = this%t%num_entries()
410
411 end function uset_r8_size
412
414 subroutine uset_r8_clear(this)
415 class(uset_r8_t), intent(inout) :: this
416
417 call this%t%clear()
418 end subroutine uset_r8_clear
419
421 function uset_r8_element(this, key) result(res)
422 class(uset_r8_t), intent(inout) :: this
423 class(*), intent(inout) :: key
424 logical :: res
425 real(kind=dp) :: data
426
427 select type (key)
428 type is (double precision)
429 res = (this%t%get(key, data) .eq. 0)
430 class default
431 res = .false.
432 end select
433
434 end function uset_r8_element
435
437 subroutine uset_r8_add(this, key)
438 class(uset_r8_t), intent(inout) :: this
439 class(*), intent(inout) :: key
440 real(kind=dp) :: data
441
442 select type (key)
443 type is (double precision)
444 data = key
445 call this%t%set(key, data)
446 class default
447 call neko_error("Invalid key")
448 end select
449 end subroutine uset_r8_add
450
452 subroutine uset_r8_remove(this, key)
453 class(uset_r8_t), intent(inout) :: this
454 class(*), intent(inout) :: key
455
456 select type (key)
457 type is (double precision)
458 call this%t%remove(key)
459 class default
460 call neko_error("Invalid key")
461 end select
462 end subroutine uset_r8_remove
463
465 subroutine uset_r8_iter_init(this)
466 class(uset_r8_t), target, intent(inout) :: this
467 call this%it%init(this%t)
468 end subroutine uset_r8_iter_init
469
471 function uset_r8_iter_next(this) result(valid)
472 class(uset_r8_t), intent(inout) :: this
473 logical :: valid
474 valid = this%it%next()
475 end function uset_r8_iter_next
476
478 function uset_r8_iter_value(this) result(value)
479 class(uset_r8_t), target, intent(inout) :: this
480 real(kind=dp), pointer :: value
481 value => this%it%value()
482 end function uset_r8_iter_value
483
484
485end module uset
Inteface for adding key to an unorderd set.
Definition uset.f90:157
Interface for clearing an unordered set.
Definition uset.f90:139
Interface for checking if key is an element of an unordered set.
Definition uset.f90:147
Interface for destroying an unordered set.
Definition uset.f90:122
Interface for initializing an unordered set.
Definition uset.f90:113
Inteface for removing key in an unorderd set.
Definition uset.f90:166
Interface for getting the cardinality of an unordered set.
Definition uset.f90:130
Implements a hash table ADT.
Definition htable.f90:52
integer, parameter, public i8
Definition num_types.f90:7
integer, parameter, public dp
Definition num_types.f90:9
Implements an unordered set ADT.
Definition uset.f90:39
subroutine uset_r8_clear(this)
Clear a double precision based unordered set.
Definition uset.f90:415
subroutine uset_i4_iter_init(this)
Initialise an integer based set iterator.
Definition uset.f90:257
subroutine uset_i4_add(this, key)
Add an integer key to the set.
Definition uset.f90:229
subroutine uset_i8_clear(this)
Clear an integer*8 based unordered set.
Definition uset.f90:307
subroutine uset_r8_remove(this, key)
Remove a double precision key from the set.
Definition uset.f90:453
subroutine uset_r8_add(this, key)
Add a double precision key to the set.
Definition uset.f90:438
logical function uset_i8_element(this, key)
Check if an integer*8 key is an element of the set.
Definition uset.f90:314
subroutine uset_i8_add(this, key)
Add an integer*8 key to the set.
Definition uset.f90:329
subroutine uset_i8_iter_init(this)
Initialise an integer based set iterator*8.
Definition uset.f90:357
logical function uset_i8_iter_next(this)
Advance an integer*8 based set iterator.
Definition uset.f90:363
integer function, pointer uset_i4_iter_value(this)
Return the current value of an integer based set iterator.
Definition uset.f90:270
subroutine uset_i4_clear(this)
Clear an integer based unordered set.
Definition uset.f90:207
integer(kind=i8) function, pointer uset_i8_iter_value(this)
Return the current value of an integer*8 based set iterator.
Definition uset.f90:370
subroutine uset_r8_init(this, n)
Initialize an empty double precision based unordered set.
Definition uset.f90:386
real(kind=dp) function, pointer uset_r8_iter_value(this)
Return the current value of a double precision based set iterator.
Definition uset.f90:479
subroutine uset_i8_init(this, n)
Initialize an empty integer*8 based unordered set.
Definition uset.f90:277
subroutine uset_i8_remove(this, key)
Remove an integer*8 key from the set.
Definition uset.f90:344
subroutine uset_r8_iter_init(this)
Initialise a double precision based set iterator.
Definition uset.f90:466
logical function uset_i4_element(this, key)
Check if an integer key is an element of the set.
Definition uset.f90:214
subroutine uset_i4_init(this, n)
Initialize an empty integer based unordered set.
Definition uset.f90:177
logical function uset_r8_iter_next(this)
Advance a double precision based set iterator.
Definition uset.f90:472
pure integer function uset_i4_size(this)
Return the cardinality of an integer based unordered set.
Definition uset.f90:198
logical function uset_i4_iter_next(this)
Advance an integer based set iterator.
Definition uset.f90:263
pure integer function uset_i8_size(this)
Return the cardinality of an integer*8 based unordered set.
Definition uset.f90:298
subroutine uset_i4_remove(this, key)
Remove an integer key from the set.
Definition uset.f90:244
subroutine uset_i8_free(this)
Destroy an integer*8 based unordered set.
Definition uset.f90:289
subroutine uset_r8_free(this)
Destroy a double precision based unordered set.
Definition uset.f90:398
subroutine uset_i4_free(this)
Destroy an integer based unordered set.
Definition uset.f90:189
pure integer function uset_r8_size(this)
Return the cardinality of a double precision based unordered set.
Definition uset.f90:406
logical function uset_r8_element(this, key)
Check if a double precision key is an element of the set.
Definition uset.f90:422
Utilities.
Definition utils.f90:35
Integer based hash table.
Definition htable.f90:102
Integer*8 based hash table.
Definition htable.f90:112
Iterator for an integer based hash table.
Definition htable.f90:186
Iterator for an integer*8 based hash table.
Definition htable.f90:195
Iterator for a double precision based hash table.
Definition htable.f90:204
Double precision based hash table.
Definition htable.f90:122
Integer based unordered set.
Definition uset.f90:61
Integer*8 based unordered set.
Definition uset.f90:78
Double precision unordered set.
Definition uset.f90:95
Base type for an unordered set.
Definition uset.f90:49