Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
dofmap.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2026, 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!> Defines a mapping of the degrees of freedom
34!! @details A mapping defined based on a function space and a mesh
35module dofmap
37 use mesh, only : mesh_t
38 use mask, only : mask_t
39 use space, only : space_t, gll
40 use tuple, only : tuple4_i4_t
41 use num_types, only : i4, i8, rp, xp
42 use utils, only : neko_error, neko_warning
43 use fast3d, only : fd_weights_full
44 use tensor4, only: tensor4_t
45 use tensor, only : tensr3, tnsr2d_el, trsp, addtnsr
50 use element, only : element_t
51 use quad, only : quad_t
52 use hex, only : hex_t
54 use, intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr, c_associated
55 implicit none
56 private
57
58 type, public :: dofmap_t
59 integer(kind=i8), allocatable :: dof(:,:,:,:) !< Mapping to unique dof
60 logical, allocatable :: shared_dof(:,:,:,:) !< True if the dof is shared
61 type(tensor4_t) :: x !< Mapping to x-coordinates
62 type(tensor4_t) :: y !< Mapping to y-coordinates
63 type(tensor4_t) :: z !< Mapping to z-coordinates
64 integer, private :: ntot !< Local number of dofs
65
66 type(mesh_t), pointer :: msh
67 type(mesh_t), allocatable :: msh_subset
68 type(space_t), pointer :: xh
69
70 contains
71 !> Constructor.
72 procedure, pass(this) :: init_from_mesh => dofmap_init
73 procedure, pass(this) :: init_from_dof => dofmap_init_and_map
74 generic :: init => init_from_mesh, init_from_dof
75 !> Destructor.
76 procedure, pass(this) :: free => dofmap_free
77 !> Return the local number of degrees of freedom, lx*ly*lz*nelv
78 procedure, pass(this) :: size => dofmap_size
79 !> Initialize a new dofmap based on a mask
80 procedure, pass(this) :: subset_by_mask => dofmap_subset_by_mask
81 !> Return the global number of degrees of freedom, lx*ly*lz*glb_nelv
82 procedure, pass(this) :: global_size => dofmap_global_size
83 end type dofmap_t
84
85contains
86
87 !> Constructor.
88 !! @param msh The mesh.
89 !! @param Xh The SEM function space.
90 subroutine dofmap_init(this, msh, Xh)
91 class(dofmap_t) :: this
92 type(mesh_t), target, intent(inout) :: msh
93 type(space_t), target, intent(inout) :: Xh
94
95 if ((msh%gdim .eq. 3 .and. xh%lz .eq. 1) .or. &
96 (msh%gdim .eq. 2 .and. xh%lz .gt. 1)) then
97 call neko_error("Invalid dimension of function space for the given mesh")
98 end if
99
100 call this%free()
101
102 this%msh => msh
103 this%Xh => xh
104
105 this%ntot = xh%lx* xh%ly * xh%lz * msh%nelv
106
107 !
108 ! Assign a unique id for all dofs
109 !
110
111 allocate(this%dof(xh%lx, xh%ly, xh%lz, msh%nelv))
112 allocate(this%shared_dof(xh%lx, xh%ly, xh%lz, msh%nelv))
113
114 this%dof = 0
115 this%shared_dof = .false.
116
117 !> @todo implement for 2d elements
118 if (msh%gdim .eq. 3) then
119 call dofmap_number_points(this)
120 call dofmap_number_edges(this)
121 call dofmap_number_faces(this)
122 else
123 call dofmap_number_points(this)
124 call dofmap_number_edges(this)
125 end if
126
127 !
128 ! Generate x,y,z-coordinates for all dofs
129 !
130
131 call this%x%init(xh%lx, xh%ly, xh%lz, msh%nelv)
132 call this%y%init(xh%lx, xh%ly, xh%lz, msh%nelv)
133 call this%z%init(xh%lx, xh%ly, xh%lz, msh%nelv)
134
135 this%x = 0.0_rp
136 this%y = 0.0_rp
137 this%z = 0.0_rp
138
139 !> @note should be intialised differently in axissymmetric case
140 call dofmap_generate_xyz(this)
141
142 end subroutine dofmap_init
143
144 !> Constructor.
145 !! @param dof The existing dofmap to initialize from.
146 !! @param Xh The SEM function space.
147 subroutine dofmap_init_and_map(this, dof, Xh)
148 class(dofmap_t) :: this
149 type(dofmap_t), target, intent(inout) :: dof
150 type(space_t), target, intent(inout) :: Xh
151 type(interpolator_t) :: interpolator
152
153 ! Initialize as usual
154 call this%init_from_mesh(dof%msh, xh)
155
156 ! Interpolate if needed
157 if (dof%Xh%lxyz .ne. this%Xh%lxyz) then
158 call interpolator%init(this%Xh, dof%Xh)
159
160 call interpolator%map(this%x%x, dof%x%x, this%msh%nelv, this%Xh)
161 call interpolator%map(this%y%x, dof%y%x, this%msh%nelv, this%Xh)
162 call interpolator%map(this%z%x, dof%z%x, this%msh%nelv, this%Xh)
163
164 call interpolator%free()
165
166 else
167 this%x = dof%x
168 this%y = dof%y
169 this%z = dof%z
170 end if
171
172 end subroutine dofmap_init_and_map
173
174 !> Destructor.
175 subroutine dofmap_free(this)
176 class(dofmap_t), intent(inout) :: this
177
178 if (allocated(this%dof)) then
179 deallocate(this%dof)
180 end if
181
182 if (allocated(this%shared_dof)) then
183 deallocate(this%shared_dof)
184 end if
185
186 call this%x%free()
187 call this%y%free()
188 call this%z%free()
189
190 nullify(this%msh)
191 nullify(this%Xh)
192
193 if (allocated(this%msh_subset)) then
194 call this%msh_subset%free()
195 deallocate(this%msh_subset)
196 end if
197
198 end subroutine dofmap_free
199
200 !> Return the local number of dofs in the dofmap, lx*ly*lz*nelv
201 pure function dofmap_size(this) result(res)
202 class(dofmap_t), intent(in) :: this
203 integer :: res
204 res = this%ntot
205 end function dofmap_size
206
207 !> Return the global number of dofs in the dofmap, lx*ly*lz*glb_nelv
208 pure function dofmap_global_size(this) result(res)
209 class(dofmap_t), intent(in) :: this
210 integer(kind=i8) :: res
211 res = int(this%Xh%lx * this%Xh%ly * this%Xh%lz, i8) * &
212 int(this%msh%glb_nelv, i8)
213 end function dofmap_global_size
214
215 !> Assign numbers to each dofs on points
216 subroutine dofmap_number_points(this)
217 type(dofmap_t), target :: this
218 integer :: il, jl, ix, iy, iz
219 type(mesh_t), pointer :: msh
220 type(space_t), pointer :: Xh
221
222 msh => this%msh
223 xh => this%Xh
224 !$omp parallel do private(il,jl,ix,iy,iz)
225 do il = 1, msh%nelv
226 do jl = 1, msh%npts
227 ix = mod(jl - 1, 2) * (xh%lx - 1) + 1
228 iy = (mod(jl - 1, 4)/2) * (xh%ly - 1) + 1
229 iz = ((jl - 1)/4) * (xh%lz - 1) + 1
230 this%dof(ix, iy, iz, il) = int(msh%elements(il)%e%pts(jl)%p%id(), i8)
231 this%shared_dof(ix, iy, iz, il) = msh%is_shared_point(il, jl)
232 end do
233 end do
234 !$omp end parallel do
235 end subroutine dofmap_number_points
236
237 !> Assing numbers to dofs on edges
238 subroutine dofmap_number_edges(this)
239 type(dofmap_t), target :: this
240 type(mesh_t), pointer :: msh
241 type(space_t), pointer :: Xh
242 integer :: i,j,k
243 integer :: global_id
244 integer(kind=i8) :: num_dofs_edges(3) ! #dofs for each dir (r, s, t)
245 integer(kind=i8) :: edge_id, edge_offset
246 logical :: shared_dof
247
248 msh => this%msh
249 xh => this%Xh
250
251 ! Number of dofs on an edge excluding end-points
252 num_dofs_edges(1) = int(xh%lx - 2, i8)
253 num_dofs_edges(2) = int(xh%ly - 2, i8)
254 num_dofs_edges(3) = int(xh%lz - 2, i8)
255 edge_offset = int(msh%glb_mpts, i8) + int(1, i8)
256
257 !$omp parallel do private(i,j,k,global_id,edge_id,shared_dof)
258 do i = 1, msh%nelv
259
260 select type (ep => msh%elements(i)%e)
261 type is (hex_t)
262 !
263 ! Number edges in r-direction
264 !
265 shared_dof = msh%is_shared_edge(i, 1)
266 global_id = msh%get_global_edge(i, 1)
267 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
268 !Reverse order of tranversal if edge is reversed
269 if (this%dof(1,1,1,i) .gt. this%dof(xh%lx, 1, 1, i)) then
270 do concurrent(j = 2:xh%lx - 1)
271 k = xh%lx+1-j
272 this%dof(k, 1, 1, i) = edge_id + (j-2)
273 this%shared_dof(k, 1, 1, i) = shared_dof
274 end do
275 else
276 do concurrent(j = 2:xh%lx - 1)
277 k = j
278 this%dof(k, 1, 1, i) = edge_id + (j-2)
279 this%shared_dof(k, 1, 1, i) = shared_dof
280 end do
281 end if
282
283 shared_dof = msh%is_shared_edge(i, 3)
284 global_id = msh%get_global_edge(i, 3)
285 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
286 if (this%dof(1, 1, xh%lz, i) .gt. this%dof(xh%lx, 1, xh%lz, i)) then
287 do concurrent(j = 2:xh%lx - 1)
288 k = xh%lx+1-j
289 this%dof(k, 1, xh%lz, i) = edge_id + (j-2)
290 this%shared_dof(k, 1, xh%lz, i) = shared_dof
291 end do
292 else
293 do concurrent(j = 2:xh%lx - 1)
294 k = j
295 this%dof(k, 1, xh%lz, i) = edge_id + (j-2)
296 this%shared_dof(k, 1, xh%lz, i) = shared_dof
297 end do
298 end if
299
300 shared_dof = msh%is_shared_edge(i, 2)
301 global_id = msh%get_global_edge(i, 2)
302 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
303 if (this%dof(1, xh%ly, 1, i) .gt. this%dof(xh%lx, xh%ly, 1, i)) then
304 do concurrent(j = 2:xh%lx - 1)
305 k = xh%lx+1-j
306 this%dof(k, xh%ly, 1, i) = edge_id + (j-2)
307 this%shared_dof(k, xh%ly, 1, i) = shared_dof
308 end do
309 else
310 do concurrent(j = 2:xh%lx - 1)
311 k = j
312 this%dof(k, xh%ly, 1, i) = edge_id + (j-2)
313 this%shared_dof(k, xh%ly, 1, i) = shared_dof
314 end do
315 end if
316
317 shared_dof = msh%is_shared_edge(i, 4)
318 global_id = msh%get_global_edge(i, 4)
319 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
320 if (this%dof(1, xh%ly, xh%lz, i) .gt. &
321 this%dof(xh%lx, xh%ly, xh%lz, i)) then
322 do concurrent(j = 2:xh%lx - 1)
323 k = xh%lx+1-j
324 this%dof(k, xh%ly, xh%lz, i) = edge_id + (j-2)
325 this%shared_dof(k, xh%ly, xh%lz, i) = shared_dof
326 end do
327 else
328 do concurrent(j = 2:xh%lx - 1)
329 k = j
330 this%dof(k, xh%ly, xh%lz, i) = edge_id + (j-2)
331 this%shared_dof(k, xh%ly, xh%lz, i) = shared_dof
332 end do
333 end if
334
335
336 !
337 ! Number edges in s-direction
338 !
339 shared_dof = msh%is_shared_edge(i, 5)
340 global_id = msh%get_global_edge(i, 5)
341 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
342 if (this%dof(1,1,1,i) .gt. this%dof(1, xh%ly, 1, i)) then
343 do concurrent(j = 2:xh%ly - 1)
344 k = xh%ly+1-j
345 this%dof(1, k, 1, i) = edge_id + (j-2)
346 this%shared_dof(1, k, 1, i) = shared_dof
347 end do
348 else
349 do concurrent(j = 2:xh%ly - 1)
350 k = j
351 this%dof(1, k, 1, i) = edge_id + (j-2)
352 this%shared_dof(1, k, 1, i) = shared_dof
353 end do
354 end if
355
356 shared_dof = msh%is_shared_edge(i, 7)
357 global_id = msh%get_global_edge(i, 7)
358 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
359 if (this%dof(1, 1, xh%lz, i) .gt. this%dof(1, xh%ly, xh%lz, i)) then
360 do concurrent(j = 2:xh%ly - 1)
361 k = xh%ly+1-j
362 this%dof(1, k, xh%lz, i) = edge_id + (j-2)
363 this%shared_dof(1, k, xh%lz, i) = shared_dof
364 end do
365 else
366 do concurrent(j = 2:xh%ly - 1)
367 k = j
368 this%dof(1, k, xh%lz, i) = edge_id + (j-2)
369 this%shared_dof(1, k, xh%lz, i) = shared_dof
370 end do
371 end if
372
373 shared_dof = msh%is_shared_edge(i, 6)
374 global_id = msh%get_global_edge(i, 6)
375 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
376 if (this%dof(xh%lx, 1, 1, i) .gt. this%dof(xh%lx, xh%ly, 1, i)) then
377 do concurrent(j = 2:xh%ly - 1)
378 k = xh%ly+1-j
379 this%dof(xh%lx, k, 1, i) = edge_id + (j-2)
380 this%shared_dof(xh%lx, k, 1, i) = shared_dof
381 end do
382 else
383 do concurrent(j = 2:xh%ly - 1)
384 k = j
385 this%dof(xh%lx, k, 1, i) = edge_id + (j-2)
386 this%shared_dof(xh%lx, k, 1, i) = shared_dof
387 end do
388 end if
389
390 shared_dof = msh%is_shared_edge(i, 8)
391 global_id = msh%get_global_edge(i, 8)
392 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
393 if (this%dof(xh%lx, 1, xh%lz, i) .gt. &
394 this%dof(xh%lx, xh%ly, xh%lz, i)) then
395 do concurrent(j = 2:xh%ly - 1)
396 k = xh%lz+1-j
397 this%dof(xh%lx, k, xh%lz, i) = edge_id + (j-2)
398 this%shared_dof(xh%lx, k, xh%lz, i) = shared_dof
399 end do
400 else
401 do concurrent(j = 2:xh%ly - 1)
402 k = j
403 this%dof(xh%lx, k, xh%lz, i) = edge_id + (j-2)
404 this%shared_dof(xh%lx, k, xh%lz, i) = shared_dof
405 end do
406 end if
407
408 !
409 ! Number edges in t-direction
410 !
411 shared_dof = msh%is_shared_edge(i, 9)
412 global_id = msh%get_global_edge(i, 9)
413 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(3)
414 if (this%dof(1,1,1,i) .gt. this%dof(1, 1, xh%lz, i)) then
415 do concurrent(j = 2:xh%lz - 1)
416 k = xh%lz+1-j
417 this%dof(1, 1, k, i) = edge_id + (j-2)
418 this%shared_dof(1, 1, k, i) = shared_dof
419 end do
420 else
421 do concurrent(j = 2:xh%lz - 1)
422 k = j
423 this%dof(1, 1, k, i) = edge_id + (j-2)
424 this%shared_dof(1, 1, k, i) = shared_dof
425 end do
426 end if
427
428 shared_dof = msh%is_shared_edge(i, 10)
429 global_id = msh%get_global_edge(i, 10)
430 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(3)
431 if (this%dof(xh%lx,1,1,i) .gt. this%dof(xh%lx, 1, xh%lz, i)) then
432 do concurrent(j = 2:xh%lz - 1)
433 k = xh%lz+1-j
434 this%dof(xh%lx, 1, k, i) = edge_id + (j-2)
435 this%shared_dof(xh%lx, 1, k, i) = shared_dof
436 end do
437 else
438 do concurrent(j = 2:xh%lz - 1)
439 k = j
440 this%dof(xh%lx, 1, k, i) = edge_id + (j-2)
441 this%shared_dof(xh%lx, 1, k, i) = shared_dof
442 end do
443 end if
444
445 shared_dof = msh%is_shared_edge(i, 11)
446 global_id = msh%get_global_edge(i, 11)
447 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(3)
448 if (this%dof(1, xh%ly, 1, i) .gt. this%dof(1, xh%ly, xh%lz, i)) then
449 do concurrent(j = 2:xh%lz - 1)
450 k = xh%lz+1-j
451 this%dof(1, xh%ly, k, i) = edge_id + (j-2)
452 this%shared_dof(1, xh%ly, k, i) = shared_dof
453 end do
454 else
455 do concurrent(j = 2:xh%lz - 1)
456 k = j
457 this%dof(1, xh%ly, k, i) = edge_id + (j-2)
458 this%shared_dof(1, xh%ly, k, i) = shared_dof
459 end do
460 end if
461
462 shared_dof = msh%is_shared_edge(i, 12)
463 global_id = msh%get_global_edge(i, 12)
464 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(3)
465 if (this%dof(xh%lx, xh%ly, 1, i) .gt. &
466 this%dof(xh%lx, xh%ly, xh%lz, i)) then
467 do concurrent(j = 2:xh%lz - 1)
468 k = xh%lz+1-j
469 this%dof(xh%lx, xh%ly, k, i) = edge_id + (j-2)
470 this%shared_dof(xh%lx, xh%ly, k, i) = shared_dof
471 end do
472 else
473 do concurrent(j = 2:xh%lz - 1)
474 k = j
475 this%dof(xh%lx, xh%ly, k, i) = edge_id + (j-2)
476 this%shared_dof(xh%lx, xh%ly, k, i) = shared_dof
477 end do
478 end if
479 type is (quad_t)
480 !
481 ! Number edges in r-direction
482 !
483 shared_dof = msh%is_shared_edge(i, 3)
484 global_id = msh%get_global_edge(i, 3)
485 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
486 !Reverse order of tranversal if edge is reversed
487 if (this%dof(1,1,1,i) .gt. this%dof(xh%lx, 1, 1, i)) then
488 do concurrent(j = 2:xh%lx - 1)
489 k = xh%lx+1-j
490 this%dof(k, 1, 1, i) = edge_id + (j-2)
491 this%shared_dof(k, 1, 1, i) = shared_dof
492 end do
493 else
494 do concurrent(j = 2:xh%lx - 1)
495 k = j
496 this%dof(k, 1, 1, i) = edge_id + (j-2)
497 this%shared_dof(k, 1, 1, i) = shared_dof
498 end do
499 end if
500
501 shared_dof = msh%is_shared_edge(i, 4)
502 global_id = msh%get_global_edge(i, 4)
503 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(1)
504 if (this%dof(1, xh%ly, 1, i) .gt. this%dof(xh%lx, xh%ly, 1, i)) then
505 do concurrent(j = 2:xh%lx - 1)
506 k = xh%lx+1-j
507 this%dof(k, xh%ly, 1, i) = edge_id + (j-2)
508 this%shared_dof(k, xh%ly, 1, i) = shared_dof
509 end do
510 else
511 do concurrent(j = 2:xh%lx - 1)
512 k = j
513 this%dof(k, xh%ly, 1, i) = edge_id + (j-2)
514 this%shared_dof(k, xh%ly, 1, i) = shared_dof
515 end do
516 end if
517
518 !
519 ! Number edges in s-direction
520 !
521 shared_dof = msh%is_shared_edge(i, 1)
522 global_id = msh%get_global_edge(i, 1)
523 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
524 if (this%dof(1,1,1,i) .gt. this%dof(1, xh%ly, 1, i)) then
525 do concurrent(j = 2:xh%ly - 1)
526 k = xh%ly+1-j
527 this%dof(1, k, 1, i) = edge_id + (j-2)
528 this%shared_dof(1, k, 1, i) = shared_dof
529 end do
530 else
531 do concurrent(j = 2:xh%ly - 1)
532 k = j
533 this%dof(1, k, 1, i) = edge_id + (j-2)
534 this%shared_dof(1, k, 1, i) = shared_dof
535 end do
536 end if
537
538 shared_dof = msh%is_shared_edge(i, 2)
539 global_id = msh%get_global_edge(i, 2)
540 edge_id = edge_offset + int((global_id - 1), i8) * num_dofs_edges(2)
541 if (this%dof(xh%lx,1,1,i) .gt. this%dof(xh%lx, xh%ly, 1, i)) then
542 do concurrent(j = 2:xh%ly - 1)
543 k = xh%ly+1-j
544 this%dof(xh%lx, k, 1, i) = edge_id + (j-2)
545 this%shared_dof(xh%lx, k, 1, i) = shared_dof
546 end do
547 else
548 do concurrent(j = 2:xh%ly - 1)
549 k = j
550 this%dof(xh%lx, k, 1, i) = edge_id + (j-2)
551 this%shared_dof(xh%lx, k, 1, i) = shared_dof
552 end do
553 end if
554 end select
555
556 end do
557 !$omp end parallel do
558 end subroutine dofmap_number_edges
559
560 !> Assign numbers to dofs on faces
561 subroutine dofmap_number_faces(this)
562 type(dofmap_t), target :: this
563 type(mesh_t), pointer :: msh
564 type(space_t), pointer :: Xh
565 integer :: i,j,k
566 integer :: global_id
567 type(tuple4_i4_t) :: face, face_order
568 integer(kind=i8) :: num_dofs_faces(3) ! #dofs for each dir (r, s, t)
569 integer(kind=i8) :: facet_offset, facet_id
570 logical :: shared_dof
571
572 msh => this%msh
573 xh => this%Xh
574
575 !> @todo don't assume lx = ly = lz
576 facet_offset = int(msh%glb_mpts, i8) + &
577 int(msh%glb_meds, i8) * int(xh%lx-2, i8) + int(1, i8)
578
579 ! Number of dofs on an face excluding end-points
580 num_dofs_faces(1) = int((xh%ly - 2) * (xh%lz - 2), i8)
581 num_dofs_faces(2) = int((xh%lx - 2) * (xh%lz - 2), i8)
582 num_dofs_faces(3) = int((xh%lx - 2) * (xh%ly - 2), i8)
583
584 !$omp parallel do private(i,j,k,global_id,face,face_order,facet_id, shared_dof)
585 do i = 1, msh%nelv
586
587 !
588 ! Number facets in r-direction (s, t)-plane
589 !
590 call msh%elements(i)%e%facet_id(face, 1)
591 call msh%elements(i)%e%facet_order(face_order, 1)
592 shared_dof = msh%is_shared_facet(i, 1)
593 global_id = msh%get_global_facet(i, 1)
594 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(1)
595 do k = 2, xh%lz - 1
596 do j = 2, xh%ly - 1
597 this%dof(1, j, k, i) = dofmap_facetidx(face_order, face, &
598 facet_id, j, k, xh%lz, xh%ly)
599 this%shared_dof(1, j, k, i) = shared_dof
600 end do
601 end do
602
603 call msh%elements(i)%e%facet_id(face, 2)
604 call msh%elements(i)%e%facet_order(face_order, 2)
605 shared_dof = msh%is_shared_facet(i, 2)
606 global_id = msh%get_global_facet(i, 2)
607 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(1)
608 do k = 2, xh%lz - 1
609 do j = 2, xh%ly - 1
610 this%dof(xh%lx, j, k, i) = dofmap_facetidx(face_order, face, &
611 facet_id, j, k, xh%lz, xh%ly)
612 this%shared_dof(xh%lx, j, k, i) = shared_dof
613 end do
614 end do
615
616
617 !
618 ! Number facets in s-direction (r, t)-plane
619 !
620 call msh%elements(i)%e%facet_id(face, 3)
621 call msh%elements(i)%e%facet_order(face_order, 3)
622 shared_dof = msh%is_shared_facet(i, 3)
623 global_id = msh%get_global_facet(i, 3)
624 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(2)
625 do k = 2, xh%lz - 1
626 do j = 2, xh%lx - 1
627 this%dof(j, 1, k, i) = dofmap_facetidx(face_order, face, &
628 facet_id, k, j, xh%lz, xh%lx)
629 this%shared_dof(j, 1, k, i) = shared_dof
630 end do
631 end do
632
633 call msh%elements(i)%e%facet_id(face, 4)
634 call msh%elements(i)%e%facet_order(face_order, 4)
635 shared_dof = msh%is_shared_facet(i, 4)
636 global_id = msh%get_global_facet(i, 4)
637 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(2)
638 do k = 2, xh%lz - 1
639 do j = 2, xh%lx - 1
640 this%dof(j, xh%ly, k, i) = dofmap_facetidx(face_order, face, &
641 facet_id, k, j, xh%lz, xh%lx)
642 this%shared_dof(j, xh%ly, k, i) = shared_dof
643 end do
644 end do
645
646
647 !
648 ! Number facets in t-direction (r, s)-plane
649 !
650 call msh%elements(i)%e%facet_id(face, 5)
651 call msh%elements(i)%e%facet_order(face_order, 5)
652 shared_dof = msh%is_shared_facet(i, 5)
653 global_id = msh%get_global_facet(i, 5)
654 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(3)
655 do k = 2, xh%ly - 1
656 do j = 2, xh%lx - 1
657 this%dof(j, k, 1, i) = dofmap_facetidx(face_order, face, &
658 facet_id, k, j, xh%ly, xh%lx)
659 this%shared_dof(j, k, 1, i) = shared_dof
660 end do
661 end do
662
663 call msh%elements(i)%e%facet_id(face, 6)
664 call msh%elements(i)%e%facet_order(face_order, 6)
665 shared_dof = msh%is_shared_facet(i, 6)
666 global_id = msh%get_global_facet(i, 6)
667 facet_id = facet_offset + int((global_id - 1), i8) * num_dofs_faces(3)
668 do k = 2, xh%ly - 1
669 do j = 2, xh%lx - 1
670 this%dof(j, k, xh%lz, i) = dofmap_facetidx(face_order, face, &
671 facet_id, k, j, xh%lz, xh%lx)
672 this%shared_dof(j, k, xh%lz, i) = shared_dof
673 end do
674 end do
675 end do
676 !$omp end parallel do
677
678 end subroutine dofmap_number_faces
679
680 !> Get idx for GLL point on face depending on face ordering k and j
681 pure function dofmap_facetidx(face_order, face, facet_id, k1, j1, lk1, &
682 lj1) result(facet_idx)
683 type(tuple4_i4_t), intent(in) :: face_order, face
684 integer(kind=i8), intent(in) :: facet_id
685 integer(kind=i8) :: facet_idx
686 integer, intent(in) :: k1, j1, lk1, lj1
687 integer :: k, j, lk, lj
688
689 k = k1 - 2
690 j = j1 - 2
691 lk = lk1 - 2
692 lj = lj1 - 2
693
694 ! Given the indexes k,j for a GLL point on the inner part of the
695 ! face, we assign a unique number to it that depends on the
696 ! corner with the lowest id and its neighbour with the lowest
697 ! id. The id is assigned in this way to be consistent regardless
698 ! of how the faces are rotated or mirrored.
699 !
700 ! 4 -------- 3
701 ! | | k
702 ! |----->| ^
703 ! |----->| |
704 ! |----->| |
705 ! 1 -------- 2 0--->j
706
707
708 if (face_order%x(1) .eq. face%x(1)) then
709 if (face_order%x(2) .lt. face_order%x(4)) then
710 facet_idx = facet_id + j + k*lj
711 else
712 facet_idx = facet_id + j*lk + k
713 end if
714 else if (face_order%x(2) .eq. face%x(1)) then
715 if (face_order%x(3) .lt. face_order%x(1)) then
716 facet_idx = facet_id + lk*(lj-1-j) + k
717 else
718 facet_idx = facet_id + (lj-1-j) + k*lj
719 end if
720 else if (face_order%x(3) .eq. face%x(1)) then
721 if (face_order%x(4) .lt. face_order%x(2)) then
722 facet_idx = facet_id + (lj-1-j) + lj*(lk-1-k)
723 else
724 facet_idx = facet_id + lk*(lj-1-j) + (lk-1-k)
725 end if
726 else if (face_order%x(4) .eq. face%x(1)) then
727 if (face_order%x(1) .lt. face_order%x(3)) then
728 facet_idx = facet_id + lk*j + (lk-1-k)
729 else
730 facet_idx = facet_id + j + lj*(lk-1-k)
731 end if
732 end if
733
734 end function dofmap_facetidx
735
736 !> Generate x,y,z-coordinates for all dofs
737 !! @note Assumes \f$ X_{h_x} = X_{h_y} = X_{h_z} \f$
738 subroutine dofmap_generate_xyz(this)
739 type(dofmap_t), target :: this
740 integer :: i, j, el_idx
741 type(mesh_t), pointer :: msh
742 type(space_t), pointer :: Xh
743 real(kind=rp) :: rp_curve_data(5), curve_data_tot(5,12)
744 logical :: midpoint
745 integer :: n_edge, curve_type(12)
746
747 msh => this%msh
748 xh => this%Xh
749
750 if (msh%gdim .eq. 3) then
751 n_edge = 12
752 else
753 n_edge = 4
754 end if
755
756 !$omp parallel do
757 do i = 1, msh%nelv
758 call dofmap_xyzlin(xh, msh, msh%elements(i)%e, this%x%x(1,1,1,i), &
759 this%y%x(1,1,1,i), this%z%x(1,1,1,i))
760 end do
761 !$omp end parallel do
762
763 do i = 1, msh%curve%size
764 midpoint = .false.
765 el_idx = msh%curve%curve_el(i)%el_idx
766 curve_type = msh%curve%curve_el(i)%curve_type
767 curve_data_tot = msh%curve%curve_el(i)%curve_data
768 do j = 1, n_edge
769 if (curve_type(j) .eq. 4) then
770 midpoint = .true.
771 end if
772 end do
773 if (midpoint .and. xh%lx .gt. 2) then
774 call dofmap_xyzquad(xh, msh, msh%elements(el_idx)%e, &
775 this%x%x(1, 1, 1, el_idx), this%y%x(1, 1, 1, el_idx), &
776 this%z%x(1 ,1, 1, el_idx), curve_type, curve_data_tot)
777 end if
778 end do
779 do i = 1, msh%curve%size
780 el_idx = msh%curve%curve_el(i)%el_idx
781 do j = 1, 8
782 if (msh%curve%curve_el(i)%curve_type(j) .eq. 3) then
783 rp_curve_data = msh%curve%curve_el(i)%curve_data(1:5,j)
784 call arc_surface(j, rp_curve_data, &
785 this%x%x(1, 1, 1, el_idx), &
786 this%y%x(1, 1, 1, el_idx), &
787 this%z%x(1, 1, 1, el_idx), &
788 xh, msh%elements(el_idx)%e, msh%gdim)
789 end if
790 end do
791 end do
792 if (associated(msh%apply_deform)) then
793 call msh%apply_deform(this%x%x, this%y%x, this%z%x, xh%lx, xh%ly, xh%lz)
794 end if
795
796 call this%x%copy_from(host_to_device, .false.)
797 call this%y%copy_from(host_to_device, .false.)
798 call this%z%copy_from(host_to_device, .true.)
799 end subroutine dofmap_generate_xyz
800
801 !> Generate the x, y, z coordinates of the dofs in a signle element, assuming
802 !! linear element edges.
803 !! @param Xh The function space.
804 !! @param msh The mesh.
805 !! @param element The element.
806 !! @param x The x coordinates of the dofs.
807 !! @param y The y coordinates of the dofs.
808 !! @param z The z coordinates of the dofs.
809 subroutine dofmap_xyzlin(Xh, msh, element, x, y, z)
810 type(mesh_t), pointer, intent(in) :: msh
811 type(space_t), intent(in) :: Xh
812 class(element_t), intent(in) :: element
813 real(kind=rp), intent(inout) :: x(xh%lx, xh%ly, xh%lz), &
814 y(xh%lx, xh%ly, xh%lz), &
815 z(xh%lx, xh%ly, xh%lz)
816 real(kind=rp) :: xyzb(2,2,2,3), zgml(xh%lx, 3)
817 real(kind=rp) :: jx(xh%lx*2)
818 real(kind=rp) :: jxt(xh%lx*2), jyt(xh%lx*2), jzt(xh%lx*2)
819 real(kind=rp) :: w(4*xh%lx**3), tmp(xh%lx, xh%lx, xh%lx)
820 real(kind=rp), dimension(2), parameter :: zlin = [-1d0, 1d0]
821
822 integer :: j, k
823
824 zgml = 0d0
825 xyzb = 0d0
826
827 w = 0d0
828 call copy(zgml(1,1), xh%zg(1,1), xh%lx)
829 call copy(zgml(1,2), xh%zg(1,2), xh%ly)
830 if (msh%gdim .gt. 2) then
831 call copy(zgml(1,3), xh%zg(1,3), xh%lz)
832 end if
833
834 k = 1
835 do j = 1, xh%lx
836 call fd_weights_full(zgml(j,1), zlin, 1, 0, jxt(k))
837 call fd_weights_full(zgml(j,2), zlin, 1, 0, jyt(k))
838 if (msh%gdim .gt. 2) then
839 call fd_weights_full(zgml(j,3), zlin, 1, 0, jzt(k))
840 end if
841 k = k + 2
842 end do
843 call trsp(jx, xh%lx, jxt, 2)
844
845 if (msh%gdim .eq. 2) then
846 jzt = 1d0
847 end if
848
849 if (msh%gdim .gt. 2) then
850 do concurrent(j = 1:msh%gdim)
851 xyzb(1,1,1,j) = element%pts(1)%p%x(j)
852 xyzb(2,1,1,j) = element%pts(2)%p%x(j)
853 xyzb(1,2,1,j) = element%pts(3)%p%x(j)
854 xyzb(2,2,1,j) = element%pts(4)%p%x(j)
855
856 xyzb(1,1,2,j) = element%pts(5)%p%x(j)
857 xyzb(2,1,2,j) = element%pts(6)%p%x(j)
858 xyzb(1,2,2,j) = element%pts(7)%p%x(j)
859 xyzb(2,2,2,j) = element%pts(8)%p%x(j)
860 end do
861 else
862 do concurrent(j = 1:msh%gdim)
863 xyzb(1,1,1,j) = element%pts(1)%p%x(j)
864 xyzb(2,1,1,j) = element%pts(2)%p%x(j)
865 xyzb(1,2,1,j) = element%pts(3)%p%x(j)
866 xyzb(2,2,1,j) = element%pts(4)%p%x(j)
867 end do
868 end if
869 if (msh%gdim .eq. 3) then
870 call tensr3(tmp, xh%lx, xyzb(1,1,1,1), 2, jx, jyt, jzt, w)
871 call copy(x, tmp, xh%lx*xh%ly*xh%lz)
872 call tensr3(tmp, xh%ly, xyzb(1,1,1,2), 2, jx, jyt, jzt, w)
873 call copy(y, tmp, xh%lx*xh%ly*xh%lz)
874 call tensr3(tmp, xh%lz, xyzb(1,1,1,3), 2, jx, jyt, jzt, w)
875 call copy(z, tmp, xh%lx*xh%ly*xh%lz)
876 else
877 call tnsr2d_el(tmp, xh%lx, xyzb(1,1,1,1), 2, jx, jyt)
878 call copy(x, tmp, xh%lx*xh%ly*xh%lz)
879 call tnsr2d_el(tmp, xh%ly, xyzb(1,1,1,2), 2, jx, jyt)
880 call copy(y, tmp, xh%lx*xh%ly*xh%lz)
881 end if
882 end subroutine dofmap_xyzlin
883
884 !OCL SERIAL
885 subroutine dofmap_xyzquad(Xh, msh, element, x, y, z, curve_type, curve_data)
886 type(mesh_t), pointer, intent(in) :: msh
887 type(space_t), intent(in) :: Xh
888 class(element_t), intent(in) :: element
889 real(kind=rp), dimension(Xh%lx, Xh%ly, Xh%lz), intent(inout) :: x, y, z
890 integer :: curve_type(12), eindx(12)
891 real(kind=rp) :: curve_data(5,12), x3(3,3,3), y3(3,3,3), z3(3,3,3)
892 type(space_t), target :: xh3
893 real(kind=rp), dimension(3), parameter :: zquad = [-1d0, 0d0,1d0]
894 real(kind=rp) :: zg(3)
895 real(kind=rp), dimension(Xh%lx, Xh%lx, Xh%lx) :: tmp
896 real(kind=rp) :: jx(xh%lx*3)
897 real(kind=rp) :: jxt(xh%lx*3), jyt(xh%lx*3), jzt(xh%lx*3)
898 real(kind=rp) :: w(4*xh%lxyz,2)
899 integer :: j, k, n_edges
900 eindx = [2 , 6 , 8 , 4, &
901 20 , 24 , 26 , 22, &
902 10 , 12 , 18 , 16]
903
904 w = 0d0
905 if (msh%gdim .eq. 3) then
906 n_edges = 12
907 call xh3%init(gll, 3, 3, 3)
908 else
909 n_edges = 4
910 call xh3%init(gll, 3, 3)
911 end if
912 call dofmap_xyzlin(xh3, msh, element, x3, y3, z3)
913
914 do k = 1, n_edges
915 if (curve_type(k) .eq. 4) then
916 x3(eindx(k),1,1) = curve_data(1,k)
917 y3(eindx(k),1,1) = curve_data(2,k)
918 z3(eindx(k),1,1) = curve_data(3,k)
919 end if
920 end do
921 zg(1) = -1
922 zg(2) = 0
923 zg(3) = 1
924 if (msh%gdim .eq. 3) then
925 call gh_face_extend_3d(x3, zg, 3, 2, w(1,1), w(1,2)) ! 2 --> edge extend
926 call gh_face_extend_3d(y3, zg, 3, 2, w(1,1), w(1,2))
927 call gh_face_extend_3d(z3, zg, 3, 2, w(1,1), w(1,2))
928 else
929 call neko_warning(' m deformation not supported for 2d yet')
930 call gh_face_extend_2d(x3, zg, 3, 2, w(1,1), w(1,2)) ! 2 --> edge extend
931 call gh_face_extend_2d(y3, zg, 3, 2, w(1,1), w(1,2))
932 end if
933 k = 1
934 do j = 1, xh%lx
935 call fd_weights_full(xh%zg(j,1), zquad, 2, 0, jxt(k))
936 call fd_weights_full(xh%zg(j,2), zquad, 2, 0, jyt(k))
937 if (msh%gdim .gt. 2) then
938 call fd_weights_full(xh%zg(j,3), zquad, 2, 0, jzt(k))
939 end if
940 k = k + 3
941 end do
942 call trsp(jx, xh%lx, jxt, 3)
943 if (msh%gdim .eq. 3) then
944 call tensr3(tmp, xh%lx, x3, 3, jx, jyt, jzt, w)
945 call copy(x, tmp, xh%lx*xh%ly*xh%lz)
946 call tensr3(tmp, xh%ly, y3, 3, jx, jyt, jzt, w)
947 call copy(y, tmp, xh%lx*xh%ly*xh%lz)
948 call tensr3(tmp, xh%lz, z3, 3, jx, jyt, jzt, w)
949 call copy(z, tmp, xh%lx*xh%ly*xh%lz)
950 else
951 call tnsr2d_el(tmp, xh%lx, x3, 3, jx, jyt)
952 call copy(x, tmp, xh%lx*xh%ly*xh%lz)
953 call tnsr2d_el(tmp, xh%ly, y3, 3, jx, jyt)
954 call copy(y, tmp, xh%lx*xh%ly*xh%lz)
955 end if
956
957 call xh3%free()
958 end subroutine dofmap_xyzquad
959
960
961 !OCL SERIAL
962 !> Extend faces into interior via gordon hall
963 !! gh_type: 1 - vertex only
964 !! 2 - vertex and edges
965 !! 3 - vertex, edges, and faces
966 !! Original in Nek5000/core/navier5.f
967 subroutine gh_face_extend_3d(x, zg, n, gh_type, e, v)
968 integer, intent(in) :: n
969 real(kind=rp), intent(inout) :: x(n, n, n)
970 real(kind=rp), intent(in) :: zg(n)
971 real(kind=rp), intent(inout) :: e(n, n, n)
972 real(kind=rp), intent(inout) :: v(n, n, n)
973 integer :: gh_type, ntot, kk, jj, ii, k, j, i
974 real(kind=xp) :: si, sj, sk, hi, hj, hk
975
976 !
977 ! Build vertex interpolant
978 !
979 ntot = n**3
980 do concurrent(i = 1:ntot)
981 v(i,1,1) = 0.0_rp
982 end do
983
984 do concurrent(i = 1:n, j = 1:n, k = 1:n, &
985 ii = 1:n:n-1, jj = 1:n:n-1, kk = 1:n:n-1)
986 si = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
987 sj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
988 sk = 0.5_xp*((n-kk)*(1-zg(k))+(kk-1)*(1+zg(k)))/(n-1)
989 v(i,j,k) = v(i,j,k) + si * sj* sk * x(ii, jj, kk)
990 end do
991
992 if (gh_type .eq. 1) then
993 do concurrent(i = 1:ntot)
994 x(i,1,1) = v(i,1,1)
995 end do
996 return
997 end if
998 !
999 !
1000 ! Extend 12 edges
1001 do concurrent(i = 1:ntot)
1002 e(i,1,1) = 0.0_rp
1003 end do
1004 !
1005 ! x-edges
1006 !
1007 do concurrent(i = 1:n, j = 1:n, k = 1:n, jj = 1:n:n-1, kk = 1:n:n-1)
1008 hj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
1009 hk = 0.5_xp*((n-kk)*(1-zg(k))+(kk-1)*(1+zg(k)))/(n-1)
1010 e(i,j,k) = e(i,j,k) + hj*hk*(x(i, jj, kk) - v(i, jj, kk))
1011 end do
1012 !
1013 ! y-edges
1014 !
1015 do concurrent(i = 1:n, j = 1:n, k = 1:n, ii = 1:n:n-1, kk = 1:n:n-1)
1016 hi = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
1017 hk = 0.5_xp*((n-kk)*(1-zg(k))+(kk-1)*(1+zg(k)))/(n-1)
1018 e(i,j,k) = e(i,j,k) + hi*hk*(x(ii, j, kk) - v(ii, j, kk))
1019 end do
1020 !
1021 ! z-edges
1022 !
1023 do concurrent(i = 1:n, j = 1:n, k = 1:n, ii = 1:n:n-1, jj = 1:n:n-1)
1024 hi = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
1025 hj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
1026 e(i,j,k) = e(i,j,k) + hi*hj*(x(ii, jj, k) - v(ii, jj, k))
1027 end do
1028
1029 do concurrent(i = 1:ntot)
1030 e(i,1,1) = e(i,1,1) + v(i,1,1)
1031 end do
1032
1033 if (gh_type .eq. 2) then
1034 do concurrent(i = 1:ntot)
1035 x(i,1,1) = e(i,1,1)
1036 end do
1037 return
1038 end if
1039 !
1040 ! Extend faces
1041 !
1042 do concurrent(i = 1:ntot)
1043 v(i,1,1) = 0.0_rp
1044 end do
1045 !
1046 ! x-edges
1047 !
1048 do concurrent(i = 1:n, j = 1:n, k = 1:n, ii = 1:n:n-1)
1049 hi = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
1050 v(i,j,k) = v(i,j,k) + hi*(x(ii,j,k)-e(ii,j,k))
1051 end do
1052
1053 !
1054 ! y-edges
1055 !
1056 do concurrent(i = 1:n, j = 1:n, k = 1:n, jj = 1:n:n-1)
1057 hj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
1058 v(i,j,k) = v(i,j,k) + hj*(x(i, jj, k) - e(i, jj, k))
1059 end do
1060
1061 !
1062 ! z-edges
1063 !
1064 do concurrent(i = 1:n, j = 1:n, k = 1:n, kk = 1:n:n-1)
1065 hk = 0.5_xp*((n-kk)*(1-zg(k))+(kk-1)*(1+zg(k)))/(n-1)
1066 v(i,j,k) = v(i,j,k) + hk*(x(i, j, kk) - e(i, j, kk))
1067 end do
1068
1069 do concurrent(i = 1:ntot)
1070 v(i,1,1) = v(i,1,1) + e(i,1,1)
1071 x(i,1,1) = v(i,1,1)
1072 end do
1073
1074 end subroutine gh_face_extend_3d
1075
1076 !OCL SERIAL
1077 !> Extend 2D faces into interior via gordon hall
1078 !! gh_type: 1 - vertex only
1079 !! 2 - vertex and faces
1080 subroutine gh_face_extend_2d(x, zg, n, gh_type, e, v)
1081 integer, intent(in) :: n
1082 real(kind=rp), intent(inout) :: x(n, n)
1083 real(kind=rp), intent(in) :: zg(n)
1084 real(kind=rp), intent(inout) :: e(n, n)
1085 real(kind=rp), intent(inout) :: v(n, n)
1086 integer, intent(in) :: gh_type
1087 integer :: i,j , jj, ii, ntot
1088 real(kind=rp) :: si, sj, hi, hj
1089
1090 !Build vertex interpolant
1091
1092 ntot = n*n
1093 call rzero(v, ntot)
1094 do jj = 1, n, n-1
1095 do ii = 1, n, n-1
1096 do j = 1, n
1097 do i = 1, n
1098 si = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
1099 sj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
1100 v(i,j) = v(i,j) + si*sj*x(ii, jj)
1101 end do
1102 end do
1103 end do
1104 end do
1105 if (gh_type .eq. 1) then
1106 call copy(x, v, ntot)
1107 return
1108 end if
1109
1110 !Extend 4 edges
1111 call rzero(e, ntot)
1112
1113 !x-edges
1114
1115 do jj = 1, n, n-1
1116 do j = 1, n
1117 do i = 1, n
1118 hj = 0.5_xp*((n-jj)*(1-zg(j))+(jj-1)*(1+zg(j)))/(n-1)
1119 e(i,j) = e(i,j) + hj*(x(i, jj) - v(i, jj))
1120 end do
1121 end do
1122 end do
1123
1124 !y-edges
1125
1126 do ii = 1, n, n-1
1127 do j = 1, n
1128 do i = 1, n
1129 hi = 0.5_xp*((n-ii)*(1-zg(i))+(ii-1)*(1+zg(i)))/(n-1)
1130 e(i,j) = e(i,j) + hi*(x(ii,j)-v(ii,j))
1131 end do
1132 end do
1133 end do
1134
1135 call add3(x, e, v, ntot)
1136
1137 end subroutine gh_face_extend_2d
1138
1139
1140
1141 subroutine arc_surface(isid, curve_data, x, y, z, Xh, element, gdim)
1142 integer, intent(in) :: isid, gdim
1143 type(space_t), intent(in) :: Xh
1144 class(element_t) :: element
1145 real(kind=rp), dimension(5), intent(in) :: curve_data
1146 real(kind=rp), dimension(Xh%lx, Xh%ly, Xh%lz), intent(inout) :: x, y, z
1147 real(kind=rp) :: pt1x, pt1y, pt2x, pt2y, pt12x, pt12y
1148 real(kind=rp) :: radius, dtheta, r, xys
1149 real(kind=rp) :: theta0, xcenn, ycenn, h(xh%lx, 3, 2)
1150 real(kind=rp) :: xcrved(xh%lx), ycrved(xh%lx), xs, ys
1151 integer :: isid1, ixt, iyt, izt, ix, itmp
1152 ! Cyclic to symmetric face mapping
1153 integer(i4), dimension(6), parameter :: fcyc_to_sym = [3, 2, 4, 1, 5, 6]
1154 ! Cyclic to symmetric edge mapping
1155 integer(i4), dimension(12), parameter :: ecyc_to_sym = [1, 6, 2, 5, 3, 8, &
1156 4, 7, 9, 10, 12, 11]
1157 ! Symmetric edge to vertex mapping
1158 integer, parameter, dimension(2, 12) :: edge_nodes = reshape([1, 2, 3, 4, &
1159 5, 6, 7, 8, 1, 3, 2, 4, 5, 7, 6, 8, 1, 5, 2, 6, 3, 7, 4, 8], &
1160 [2,12])
1161 ! copy from hex as this has private attribute there
1162
1163 ! this subroutine is a mess of symmetric and cyclic edge/face numberring and
1164 ! cannot be cleaned without changing an input format (isid seems to be
1165 ! a cyclic edge number)
1166 ! following according to cyclic edge numbering and orientation
1167 itmp = ecyc_to_sym(isid)
1168 select case (isid)
1169 case (1:2,5:6)
1170 pt1x = element%pts(edge_nodes(1, itmp))%p%x(1)
1171 pt1y = element%pts(edge_nodes(1, itmp))%p%x(2)
1172 pt2x = element%pts(edge_nodes(2, itmp))%p%x(1)
1173 pt2y = element%pts(edge_nodes(2, itmp))%p%x(2)
1174 case (3:4,7:8)
1175 pt1x = element%pts(edge_nodes(2, itmp))%p%x(1)
1176 pt1y = element%pts(edge_nodes(2, itmp))%p%x(2)
1177 pt2x = element%pts(edge_nodes(1, itmp))%p%x(1)
1178 pt2y = element%pts(edge_nodes(1, itmp))%p%x(2)
1179 end select
1180 ! find slope of perpendicular
1181 radius = curve_data(1)
1182 xs = pt2y-pt1y
1183 ys = pt1x-pt2x
1184 ! make length radius
1185 xys = sqrt(xs**2 + ys**2)
1186 ! sanity check
1187 if (abs(2.0 * radius) <= xys * 1.00001) &
1188 & call neko_error('Radius to small for arced element surface')
1189 ! find center
1190 dtheta = abs(asin(0.5_xp*xys/radius))
1191 pt12x = (pt1x + pt2x)/2.0
1192 pt12y = (pt1y + pt2y)/2.0
1193 xcenn = pt12x - xs/xys * radius*cos(dtheta)
1194 ycenn = pt12y - ys/xys * radius*cos(dtheta)
1195 theta0 = atan2((pt12y-ycenn), (pt12x-xcenn))
1196 ! compute perturbation of geometry
1197 isid1 = mod(isid+4-1, 4)+1
1198 call compute_h(h, xh%zg, gdim, xh%lx)
1199 if (radius < 0.0) dtheta = -dtheta
1200 do ix = 1, xh%lx
1201 ixt = ix
1202 if (isid1 .gt. 2) ixt = xh%lx+1-ix
1203 r = xh%zg(ix,1)
1204 xcrved(ixt) = xcenn + abs(radius) * cos(theta0 + r*dtheta) &
1205 - ( h(ix,1,1)*pt1x + h(ix,1,2)*pt2x )
1206 ycrved(ixt) = ycenn + abs(radius) * sin(theta0 + r*dtheta) &
1207 - ( h(ix,1,1)*pt1y + h(ix,1,2)*pt2y )
1208 end do
1209 ! points all set, add perturbation to current mesh.
1210 ! LEGACY WARNING
1211 ! I dont want to dive in this again, Martin Karp 2/3 - 2021
1212 isid1 = fcyc_to_sym(isid1)
1213 izt = (isid-1)/4+1
1214 iyt = isid1-2
1215 ixt = isid1
1216 if (isid1 .le. 2) then
1217 call addtnsr(x, h(1, 1, ixt), xcrved, h(1, 3, izt), &
1218 xh%lx, xh%ly, xh%lz)
1219 call addtnsr(y, h(1, 1, ixt), ycrved, h(1, 3, izt), &
1220 xh%lx, xh%ly, xh%lz)
1221 else
1222 call addtnsr(x, xcrved, h(1, 2, iyt), h(1, 3, izt), &
1223 xh%lx, xh%ly, xh%lz)
1224 call addtnsr(y, ycrved, h(1, 2, iyt), h(1, 3, izt), &
1225 xh%lx, xh%ly, xh%lz)
1226 end if
1227 end subroutine arc_surface
1228
1229 !OCL SERIAL
1230 subroutine compute_h(h, zgml, gdim, lx)
1231 integer, intent(in) :: lx, gdim
1232 real(kind=rp), intent(inout) :: h(lx, 3, 2)
1233 real(kind=rp), intent(in) :: zgml(lx, 3)
1234 integer :: ix, iy, iz
1235
1236 do ix = 1, lx
1237 h(ix,1,1) = (1.0_rp - zgml(ix, 1)) * 0.5_rp
1238 h(ix,1,2) = (1.0_rp + zgml(ix, 1)) * 0.5_rp
1239 end do
1240
1241 do iy = 1, lx
1242 h(iy,2,1) = (1.0_rp - zgml(iy, 2)) * 0.5_rp
1243 h(iy,2,2) = (1.0_rp + zgml(iy, 2)) * 0.5_rp
1244 end do
1245
1246 if (gdim .eq. 3) then
1247 do iz = 1, lx
1248 h(iz,3,1) = (1.0_rp - zgml(iz, 3)) * 0.5_rp
1249 h(iz,3,2) = (1.0_rp + zgml(iz, 3)) * 0.5_rp
1250 end do
1251 else
1252 call rone(h(1,3,1), lx)
1253 call rone(h(1,3,2), lx)
1254 end if
1255
1256 end subroutine compute_h
1257
1258 !> Generate/Initialize a new dofmap object based on a mask
1259 !! @note Assumes that all points in an element are marked in by the mask.
1260 !! @param other The new dofmap to be initialized.
1261 !! @param mask the mask type defining the elements to be included.
1262 subroutine dofmap_subset_by_mask(this, other, mask)
1263 class(dofmap_t), intent(inout) :: this
1264 class(dofmap_t), intent(inout) :: other
1265 type(mask_t), intent(in) :: mask
1266 integer :: i
1267
1268 ! Initialize the mesh subset_mesh in this
1269 ! Deallocate any previously allocated mesh subset
1270 if (allocated(this%msh_subset)) then
1271 call this%msh_subset%free()
1272 deallocate(this%msh_subset)
1273 end if
1274
1275 allocate(this%msh_subset)
1276 call this%msh%subset_by_mask(this%msh_subset, mask, &
1277 this%Xh%lx, this%Xh%ly, this%Xh%lz)
1278
1279 ! Initialize the other dofmap
1280 call other%init(this%msh_subset, this%Xh)
1281
1282 ! Overwrite dofmap in case it has been updated and
1283 ! the mesh has not.
1284 if (neko_bcknd_device .eq. 1) then
1285 call device_masked_gather_copy_aligned(other%x%x_d, &
1286 this%x%x_d, mask%get_d(), &
1287 this%size(), mask%size())
1288 call device_masked_gather_copy_aligned(other%y%x_d, &
1289 this%y%x_d, mask%get_d(), &
1290 this%size(), mask%size())
1291 call device_masked_gather_copy_aligned(other%z%x_d, &
1292 this%z%x_d, mask%get_d(), &
1293 this%size(), mask%size())
1294
1295 ! Sync with host
1296 call other%x%copy_from(device_to_host, sync = .false.)
1297 call other%y%copy_from(device_to_host, sync = .false.)
1298 call other%z%copy_from(device_to_host, sync = .true.)
1299
1300 else
1301 call masked_gather_copy(other%x%x, this%x%x, mask%get(), &
1302 this%size(), mask%size())
1303 call masked_gather_copy(other%y%x, this%y%x, mask%get(), &
1304 this%size(), mask%size())
1305 call masked_gather_copy(other%z%x, this%z%x, mask%get(), &
1306 this%size(), mask%size())
1307 end if
1308
1309 end subroutine dofmap_subset_by_mask
1310
1311end module dofmap
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
Unmap a Fortran array from a device (deassociate and free).
Definition device.F90:89
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_masked_gather_copy_aligned(a_d, b_d, mask_d, n, n_mask, strm)
Gather a masked vector .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
integer, parameter, public device_to_host
Definition device.F90:48
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
subroutine gh_face_extend_2d(x, zg, n, gh_type, e, v)
Extend 2D faces into interior via gordon hall gh_type: 1 - vertex only 2 - vertex and faces.
Definition dofmap.f90:1081
pure integer(kind=i8) function dofmap_global_size(this)
Return the global number of dofs in the dofmap, lx*ly*lz*glb_nelv.
Definition dofmap.f90:209
subroutine dofmap_init_and_map(this, dof, xh)
Constructor.
Definition dofmap.f90:148
subroutine dofmap_generate_xyz(this)
Generate x,y,z-coordinates for all dofs.
Definition dofmap.f90:739
subroutine arc_surface(isid, curve_data, x, y, z, xh, element, gdim)
Definition dofmap.f90:1142
subroutine compute_h(h, zgml, gdim, lx)
Definition dofmap.f90:1231
subroutine dofmap_subset_by_mask(this, other, mask)
Generate/Initialize a new dofmap object based on a mask.
Definition dofmap.f90:1263
subroutine dofmap_xyzlin(xh, msh, element, x, y, z)
Generate the x, y, z coordinates of the dofs in a signle element, assuming linear element edges.
Definition dofmap.f90:810
subroutine dofmap_free(this)
Destructor.
Definition dofmap.f90:176
subroutine dofmap_number_edges(this)
Assing numbers to dofs on edges.
Definition dofmap.f90:239
subroutine dofmap_init(this, msh, xh)
Constructor.
Definition dofmap.f90:91
subroutine dofmap_number_points(this)
Assign numbers to each dofs on points.
Definition dofmap.f90:217
pure integer function dofmap_size(this)
Return the local number of dofs in the dofmap, lx*ly*lz*nelv.
Definition dofmap.f90:202
subroutine dofmap_xyzquad(xh, msh, element, x, y, z, curve_type, curve_data)
Definition dofmap.f90:886
subroutine dofmap_number_faces(this)
Assign numbers to dofs on faces.
Definition dofmap.f90:562
subroutine gh_face_extend_3d(x, zg, n, gh_type, e, v)
Extend faces into interior via gordon hall gh_type: 1 - vertex only 2 - vertex and edges 3 - vertex,...
Definition dofmap.f90:968
pure integer(kind=i8) function dofmap_facetidx(face_order, face, facet_id, k1, j1, lk1, lj1)
Get idx for GLL point on face depending on face ordering k and j.
Definition dofmap.f90:683
Fast diagonalization methods from NEKTON.
Definition fast3d.f90:61
subroutine, public fd_weights_full(xi, x, n, m, c)
Compute finite-difference stencil weights for evaluating derivatives up to order at a point.
Definition fast3d.f90:106
Defines a hexahedron element.
Definition hex.f90:34
Routines to interpolate between different spaces.
Object for handling masks in Neko.
Definition mask.f90:34
Definition math.F90:60
subroutine, public rone(a, n)
Set all elements to one.
Definition math.F90:291
subroutine, public masked_gather_copy(a, b, mask, n, n_mask)
Gather a masked vector to reduced contigous vector .
Definition math.F90:434
subroutine, public add3(a, b, c, n)
Vector addition .
Definition math.F90:964
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.F90:249
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public i8
Definition num_types.f90:7
integer, parameter, public i4
Definition num_types.f90:6
integer, parameter, public xp
Definition num_types.f90:16
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a quadrilateral element.
Definition quad.f90:34
Defines a function space.
Definition space.f90:34
integer, parameter, public gll
Definition space.f90:50
Defines a rank-4 tensor.
Definition tensor4.f90:34
Tensor operations.
Definition tensor.f90:61
subroutine, public addtnsr(s, h1, h2, h3, nx, ny, nz)
Maps and adds to S a tensor product form of the three functions H1,H2,H3. This is a single element ro...
Definition tensor.f90:280
subroutine, public trsp(a, lda, b, ldb)
Transpose of a rectangular tensor .
Definition tensor.f90:124
subroutine, public tensr3(v, nv, u, nu, a, bt, ct, w)
Tensor product .
Definition tensor.f90:94
subroutine, public tnsr2d_el(v, nv, u, nu, a, bt)
Computes .
Definition tensor.f90:157
Implements a n-tuple.
Definition tuple.f90:41
Utilities.
Definition utils.f90:35
subroutine, public neko_warning(warning_msg)
Reports a warning to standard output.
Definition utils.f90:454
Base type for an element.
Definition element.f90:44
Hexahedron element.
Definition hex.f90:63
Interpolation between two space::space_t.
Type for consistently handling masks in Neko. This type encapsulates the mask array and its associate...
Definition mask.f90:51
Quadrilateral element.
Definition quad.f90:58
The function space for the SEM solution fields.
Definition space.f90:64
Integer based 4-tuple.
Definition tuple.f90:76