Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
tuple.f90
Go to the documentation of this file.
1! Copyright (c) 2020-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!
41module tuple
42 use math, only : abscmp
43 use num_types, only : dp
44 implicit none
45 private
46
48 type, public, abstract :: tuple_t
49 contains
50 procedure(tuple_assign_tuple), pass(this), deferred :: assign_tuple
51 procedure(tuple_assign_vector), pass(this), deferred :: assign_vector
52 procedure(tuple_equal), pass(this) , deferred :: equal
53 generic :: operator(.eq.) => equal
54 generic :: assignment(=) => assign_tuple, assign_vector
55 end type tuple_t
56
58 type, public, extends(tuple_t) :: tuple_i4_t
59 integer :: x(2) = (/0, 0/)
60 contains
61 procedure, pass(this) :: assign_tuple => tuple_i4_assign_tuple
62 procedure, pass(this) :: assign_vector => tuple_i4_assign_vector
63 procedure, pass(this) :: equal => tuple_i4_equal
64 end type tuple_i4_t
65
67 type, public, extends(tuple_t) :: tuple3_i4_t
68 integer :: x(3) = (/0, 0, 0/)
69 contains
70 procedure, pass(this) :: assign_tuple => tuple3_i4_assign_tuple
71 procedure, pass(this) :: assign_vector => tuple3_i4_assign_vector
72 procedure, pass(this) :: equal => tuple3_i4_equal
73 end type tuple3_i4_t
74
76 type, public, extends(tuple_t) :: tuple4_i4_t
77 integer :: x(4) = (/0, 0, 0, 0/)
78 contains
79 procedure, pass(this) :: assign_tuple => tuple4_i4_assign_tuple
80 procedure, pass(this) :: assign_vector => tuple4_i4_assign_vector
81 procedure, pass(this) :: equal => tuple4_i4_equal
82 end type tuple4_i4_t
83
85 type, public, extends(tuple_t) :: tuple_r8_t
86 real(kind=dp) :: x(2) = (/0d0, 0d0/)
87 contains
88 procedure, pass(this) :: assign_tuple => tuple_r8_assign_tuple
89 procedure, pass(this) :: assign_vector => tuple_r8_assign_vector
90 procedure, pass(this) :: equal => tuple_r8_equal
91 end type tuple_r8_t
92
94 type, public, extends(tuple_t) :: tuple_i4r8_t
95 integer :: x
96 real(kind=dp) :: y
97 contains
98 procedure, pass(this) :: assign_tuple => tuple_i4r8_assign_tuple
99 procedure, pass(this) :: assign_vector => tuple_i4r8_assign_vector
100 procedure, pass(this) :: equal => tuple_i4r8_equal
101 end type tuple_i4r8_t
102
104 type, public, extends(tuple_t) :: tuple_2i4r8_t
105 integer :: x, y
106 real(kind=dp) :: z
107 contains
108 procedure, pass(this) :: assign_tuple => tuple_2i4r8_assign_tuple
109 procedure, pass(this) :: assign_vector => tuple_2i4r8_assign_vector
110 procedure, pass(this) :: equal => tuple_2i4r8_equal
111 end type tuple_2i4r8_t
112
114 abstract interface
115 subroutine tuple_assign_tuple(this, other)
116 import :: tuple_t
117 class(tuple_t), intent(inout) :: this
118 class(tuple_t), intent(in) :: other
119 end subroutine tuple_assign_tuple
120 end interface
121
123 abstract interface
124 subroutine tuple_assign_vector(this, x)
125 import :: tuple_t
126 class(tuple_t), intent(inout) :: this
127 class(*), dimension(:), intent(in) :: x
128 end subroutine tuple_assign_vector
129 end interface
130
132 abstract interface
133 pure function tuple_equal(this, other) result(res)
134 import :: tuple_t
135 class(tuple_t), intent(in) :: this
136 class(tuple_t), intent(in) :: other
137 logical :: res
138 end function tuple_equal
139 end interface
140
141contains
142
144 subroutine tuple_i4_assign_tuple(this, other)
145 class(tuple_i4_t), intent(inout) :: this
146 class(tuple_t), intent(in) :: other
147
148 select type(other)
149 type is (tuple_i4_t)
150 this%x = other%x
151 end select
152 end subroutine tuple_i4_assign_tuple
153
155 subroutine tuple_i4_assign_vector(this, x)
156 class(tuple_i4_t), intent(inout) :: this
157 class(*), dimension(:), intent(in) :: x
158
159 select type(x)
160 type is (integer)
161 this%x = x
162 end select
163 end subroutine tuple_i4_assign_vector
164
166 pure function tuple_i4_equal(this, other) result(res)
167 class(tuple_i4_t), intent(in) :: this
168 class(tuple_t), intent(in) :: other
169 logical :: res
170
171 res = .false.
172 select type(other)
173 type is(tuple_i4_t)
174 res = all(this%x .eq. other%x)
175 end select
176 end function tuple_i4_equal
177
179 subroutine tuple3_i4_assign_tuple(this, other)
180 class(tuple3_i4_t), intent(inout) :: this
181 class(tuple_t), intent(in) :: other
182
183 select type(other)
184 type is(tuple3_i4_t)
185 this%x = other%x
186 end select
187 end subroutine tuple3_i4_assign_tuple
188
190 subroutine tuple3_i4_assign_vector(this, x)
191 class(tuple3_i4_t), intent(inout) :: this
192 class(*), dimension(:), intent(in) :: x
193
194 select type(x)
195 type is (integer)
196 this%x = x
197 end select
198 end subroutine tuple3_i4_assign_vector
199
201 pure function tuple3_i4_equal(this, other) result(res)
202 class(tuple3_i4_t), intent(in) :: this
203 class(tuple_t), intent(in) :: other
204 logical :: res
205
206 res = .false.
207 select type(other)
208 type is(tuple3_i4_t)
209 res = all(this%x .eq. other%x)
210 end select
211 end function tuple3_i4_equal
212
214 subroutine tuple4_i4_assign_tuple(this, other)
215 class(tuple4_i4_t), intent(inout) :: this
216 class(tuple_t), intent(in) :: other
217
218 select type(other)
219 type is(tuple4_i4_t)
220 this%x = other%x
221 end select
222 end subroutine tuple4_i4_assign_tuple
223
225 subroutine tuple4_i4_assign_vector(this, x)
226 class(tuple4_i4_t), intent(inout) :: this
227 class(*), dimension(:), intent(in) :: x
228
229 select type(x)
230 type is (integer)
231 this%x = x
232 end select
233 end subroutine tuple4_i4_assign_vector
234
236 pure function tuple4_i4_equal(this, other) result(res)
237 class(tuple4_i4_t), intent(in) :: this
238 class(tuple_t), intent(in) :: other
239 logical :: res
240
241 res = .false.
242 select type(other)
243 type is(tuple4_i4_t)
244 res = all(this%x .eq. other%x)
245 end select
246 end function tuple4_i4_equal
247
249 subroutine tuple_r8_assign_tuple(this, other)
250 class(tuple_r8_t), intent(inout) :: this
251 class(tuple_t), intent(in) :: other
252
253 select type(other)
254 type is(tuple_r8_t)
255 this%x = other%x
256 end select
257 end subroutine tuple_r8_assign_tuple
258
260 subroutine tuple_r8_assign_vector(this, x)
261 class(tuple_r8_t), intent(inout) :: this
262 class(*), dimension(:), intent(in) :: x
263
264 select type(x)
265 type is (double precision)
266 this%x = x
267 end select
268 end subroutine tuple_r8_assign_vector
269
271 pure function tuple_r8_equal(this, other) result(res)
272 class(tuple_r8_t), intent(in) :: this
273 class(tuple_t), intent(in) :: other
274 logical :: res
275
276 res = .false.
277 select type(other)
278 type is(tuple_r8_t)
279 if (abscmp(this%x(1), other%x(1)) .and. &
280 abscmp(this%x(2), other%x(2))) then
281 res = .true.
282 end if
283 end select
284 end function tuple_r8_equal
285
287 subroutine tuple_i4r8_assign_tuple(this, other)
288 class(tuple_i4r8_t), intent(inout) :: this
289 class(tuple_t), intent(in) :: other
290
291 select type(other)
292 type is(tuple_i4r8_t)
293 this%x = other%x
294 this%y = other%y
295 end select
296 end subroutine tuple_i4r8_assign_tuple
297
299 subroutine tuple_i4r8_assign_vector(this, x)
300 class(tuple_i4r8_t), intent(inout) :: this
301 class(*), dimension(:), intent(in) :: x
302
303 select type(x)
304 type is (integer)
305 this%x = x(1)
306 this%y = dble(x(2))
307 type is (double precision)
308 this%x = int(x(1))
309 this%y = x(2)
310 end select
311
312 end subroutine tuple_i4r8_assign_vector
313
315 pure function tuple_i4r8_equal(this, other) result(res)
316 class(tuple_i4r8_t), intent(in) :: this
317 class(tuple_t), intent(in) :: other
318 logical :: res
319
320 res = .false.
321 select type(other)
322 type is(tuple_i4r8_t)
323 if ((this%x .eq. other%x) .and. &
324 abscmp(this%y, other%y)) then
325 res = .true.
326 end if
327 end select
328 end function tuple_i4r8_equal
329
331 subroutine tuple_2i4r8_assign_tuple(this, other)
332 class(tuple_2i4r8_t), intent(inout) :: this
333 class(tuple_t), intent(in) :: other
334
335 select type(other)
336 type is(tuple_2i4r8_t)
337 this%x = other%x
338 this%y = other%y
339 this%z = other%z
340 end select
341 end subroutine tuple_2i4r8_assign_tuple
342
344 subroutine tuple_2i4r8_assign_vector(this, x)
345 class(tuple_2i4r8_t), intent(inout) :: this
346 class(*), dimension(:), intent(in) :: x
347
348 select type(x)
349 type is (integer)
350 this%x = x(1)
351 this%y = x(2)
352 this%z = dble(x(3))
353 type is (double precision)
354 this%x = int(x(1))
355 this%y = int(x(2))
356 this%z = x(3)
357 end select
358
359 end subroutine tuple_2i4r8_assign_vector
360
362 pure function tuple_2i4r8_equal(this, other) result(res)
363 class(tuple_2i4r8_t), intent(in) :: this
364 class(tuple_t), intent(in) :: other
365 logical :: res
366
367 res = .false.
368 select type(other)
369 type is(tuple_2i4r8_t)
370 if ((this%x .eq. other%x) .and. &
371 (this%y .eq. other%y) .and. &
372 abscmp(this%z, other%z)) then
373 res = .true.
374 end if
375 end select
376 end function tuple_2i4r8_equal
377
378end module tuple
Abstract intf. for assigning a tuple to a tuple.
Definition tuple.f90:115
Abstract intf. for assigning a vector to a n-tuple.
Definition tuple.f90:124
Abstract intf. for tuple comparison.
Definition tuple.f90:133
Definition math.f90:60
integer, parameter, public dp
Definition num_types.f90:9
Implements a n-tuple.
Definition tuple.f90:41
subroutine tuple3_i4_assign_tuple(this, other)
Assign an integer 3-tuple to a tuple.
Definition tuple.f90:180
pure logical function tuple_r8_equal(this, other)
Check if two double precision tuples are equal.
Definition tuple.f90:272
subroutine tuple4_i4_assign_tuple(this, other)
Assign an integer 4-tuple to a tuple.
Definition tuple.f90:215
subroutine tuple_i4r8_assign_vector(this, x)
Assign a mixed intreger-double precision vector to a tuple.
Definition tuple.f90:300
pure logical function tuple4_i4_equal(this, other)
Check if two integer based tuples are equal.
Definition tuple.f90:237
subroutine tuple_i4_assign_tuple(this, other)
Assign an integer 2-tuple to a tuple.
Definition tuple.f90:145
subroutine tuple_r8_assign_tuple(this, other)
Assign a double precision 2-tuple to a tuple.
Definition tuple.f90:250
pure logical function tuple_i4r8_equal(this, other)
Check if two mixed integer-double precision tuples are equal.
Definition tuple.f90:316
subroutine tuple_r8_assign_vector(this, x)
Assign a double precision vector to a tuple.
Definition tuple.f90:261
subroutine tuple_i4_assign_vector(this, x)
Assign an integer vector to a tuple.
Definition tuple.f90:156
subroutine tuple_i4r8_assign_tuple(this, other)
Assign a mixed integer-double precision 2-tuple to a tuple.
Definition tuple.f90:288
subroutine tuple4_i4_assign_vector(this, x)
Assign an integer vector to a tuple.
Definition tuple.f90:226
pure logical function tuple_i4_equal(this, other)
Check if two integer based tuples are equal.
Definition tuple.f90:167
pure logical function tuple_2i4r8_equal(this, other)
Check if two mixed integer-double precision tuples are equal.
Definition tuple.f90:363
pure logical function tuple3_i4_equal(this, other)
Check if two integer based tuples are equal.
Definition tuple.f90:202
subroutine tuple_2i4r8_assign_vector(this, x)
Assign a mixed intreger-double precision vector to a tuple.
Definition tuple.f90:345
subroutine tuple3_i4_assign_vector(this, x)
Assign an integer vector to a tuple.
Definition tuple.f90:191
subroutine tuple_2i4r8_assign_tuple(this, other)
Assign a mixed integer-double precision 3-tuple to a tuple.
Definition tuple.f90:332
Integer based 3-tuple.
Definition tuple.f90:67
Integer based 4-tuple.
Definition tuple.f90:76
Mixed integer ( ) double precision ( ) 3-tuple.
Definition tuple.f90:104
Integer based 2-tuple.
Definition tuple.f90:58
Mixed integer ( ) double precision ( ) 2-tuple .
Definition tuple.f90:94
Double precision based 2-tuple.
Definition tuple.f90:85
Base type for an n-tuple.
Definition tuple.f90:48