197 start_time, end_time, a, b, variable_name)
199 type(
coef_t),
target,
intent(in) :: coef
201 real(kind=
rp),
intent(in) :: start_time
202 real(kind=
rp),
intent(in) :: end_time
203 real(kind=
rp),
intent(in) :: a, b
204 character(len=*),
intent(in) :: variable_name
206 integer :: i, j, k, l
207 real(kind=
rp),
allocatable :: zg(:)
208 real(kind=
rp) :: normal(3)
211 call coef%require_facets(
'gradient_jump_penalty')
215 call this%init_base(fields, coef, start_time, end_time)
221 if (fields%size() .eq. 1)
then
222 call this%s_fields%init(1)
223 call this%s_fields%assign(1, &
225 else if (fields%size() .eq. 3)
then
226 call this%s_fields%init(3)
227 call this%s_fields%assign(1, this%u)
228 call this%s_fields%assign(2, this%v)
229 call this%s_fields%assign(3, this%w)
231 call neko_error(
"The GJP source assumes either 3 or 1 RHS fields.")
237 this%p = coef%dof%Xh%lx - 1
238 this%lx = coef%dof%Xh%lx
240 if (this%p .gt. 1)
then
241 this%tau = -a * (this%p + 1) ** (-b)
246 this%n = this%lx ** 3 * this%coef%msh%nelv
247 this%n_large = (this%lx + 2) ** 3 * this%coef%msh%nelv
249 allocate(this%n_facet(this%coef%msh%nelv))
250 do i = 1, this%coef%msh%nelv
251 select type (ep => this%coef%msh%elements(i)%e)
256 &supported now for gradient jump penalty")
259 this%n_facet_max = maxval(this%n_facet)
261 allocate(this%h2(this%lx + 2, this%lx + 2, &
262 this%lx + 2, this%coef%msh%nelv))
264 do i = 1, this%coef%msh%nelv
265 select type (ep => this%coef%msh%elements(i)%e)
267 call eval_h2_hex(this%h2(:, :, :, i), this%lx, i, this%coef)
269 call neko_error(
"Gradient jump penalty error: mesh size &
270 &evaluation is not supported for quad_t")
274 allocate(zg(this%lx))
275 allocate(this%dphidxi(this%lx, this%lx))
280 this%dphidxi(j,i) = this%coef%Xh%dx(j,i)
284 allocate(this%penalty(this%lx, this%lx, this%lx, this%coef%msh%nelv))
285 allocate(this%grad1(this%lx, this%lx, this%lx, this%coef%msh%nelv))
286 allocate(this%grad2(this%lx, this%lx, this%lx, this%coef%msh%nelv))
287 allocate(this%grad3(this%lx, this%lx, this%lx, this%coef%msh%nelv))
289 allocate(this%penalty_facet(this%lx + 2, this%lx + 2, &
290 this%lx + 2, this%coef%msh%nelv))
291 allocate(this%G(this%lx + 2, this%lx + 2, &
292 this%lx + 2, this%coef%msh%nelv))
293 allocate(this%flux1(this%lx + 2, this%lx + 2, &
294 this%lx + 2, this%coef%msh%nelv))
295 allocate(this%flux2(this%lx + 2, this%lx + 2, &
296 this%lx + 2, this%coef%msh%nelv))
297 allocate(this%flux3(this%lx + 2, this%lx + 2, &
298 this%lx + 2, this%coef%msh%nelv))
299 allocate(this%volflux1(this%lx + 2, this%lx + 2, &
300 this%lx + 2, this%coef%msh%nelv))
301 allocate(this%volflux2(this%lx + 2, this%lx + 2, &
302 this%lx + 2, this%coef%msh%nelv))
303 allocate(this%volflux3(this%lx + 2, this%lx + 2, &
304 this%lx + 2, this%coef%msh%nelv))
305 allocate(this%absvolflux(this%lx + 2, this%lx + 2, &
306 this%lx + 2, this%coef%msh%nelv))
307 allocate(this%n1(this%lx + 2, this%lx + 2, &
308 this%lx + 2, this%coef%msh%nelv))
309 allocate(this%n2(this%lx + 2, this%lx + 2, &
310 this%lx + 2, this%coef%msh%nelv))
311 allocate(this%n3(this%lx + 2, this%lx + 2, &
312 this%lx + 2, this%coef%msh%nelv))
315 do i = 1, this%coef%msh%nelv
321 normal = this%coef%get_normal(1, l, k, i, j)
322 this%n1(1, l + 1, k + 1, i) = normal(1)
323 this%n2(1, l + 1, k + 1, i) = normal(2)
324 this%n3(1, l + 1, k + 1, i) = normal(3)
326 normal = this%coef%get_normal(1, l, k, i, j)
327 this%n1(this%lx + 2, l + 1, k + 1, i) = normal(1)
328 this%n2(this%lx + 2, l + 1, k + 1, i) = normal(2)
329 this%n3(this%lx + 2, l + 1, k + 1, i) = normal(3)
331 normal = this%coef%get_normal(l, 1, k, i, j)
332 this%n1(l + 1, 1, k + 1, i) = normal(1)
333 this%n2(l + 1, 1, k + 1, i) = normal(2)
334 this%n3(l + 1, 1, k + 1, i) = normal(3)
336 normal = this%coef%get_normal(l, 1, k, i, j)
337 this%n1(l + 1, this%lx + 2, k + 1, i) = normal(1)
338 this%n2(l + 1, this%lx + 2, k + 1, i) = normal(2)
339 this%n3(l + 1, this%lx + 2, k + 1, i) = normal(3)
341 normal = this%coef%get_normal(l, k, 1, i, j)
342 this%n1(l + 1, k + 1, 1, i) = normal(1)
343 this%n2(l + 1, k + 1, 1, i) = normal(2)
344 this%n3(l + 1, k + 1, 1, i) = normal(3)
346 normal = this%coef%get_normal(l, k, 1, i, j)
347 this%n1(l + 1, k + 1, this%lx + 2, i) = normal(1)
348 this%n2(l + 1, k + 1, this%lx + 2, i) = normal(2)
349 this%n3(l + 1, k + 1, this%lx + 2, i) = normal(3)
351 call neko_error(
"The face index is not correct")
362 call this%Xh_GJP%init(
gll, this%lx+2, this%lx+2, this%lx+2)
363 call this%dm_GJP%init(this%coef%msh, this%Xh_GJP)
364 call this%gs_GJP%init(this%dm_GJP)
368 call device_map(this%dphidxi, this%dphidxi_d, &
370 call device_map(this%penalty, this%penalty_d, this%n)
371 call device_map(this%grad1, this%grad1_d, this%n)
372 call device_map(this%grad2, this%grad2_d, this%n)
373 call device_map(this%grad3, this%grad3_d, this%n)
375 call device_map(this%penalty_facet, this%penalty_facet_d, this%n_large)
376 call device_map(this%G, this%G_d, this%n_large)
377 call device_map(this%flux1, this%flux1_d, this%n_large)
378 call device_map(this%flux2, this%flux2_d, this%n_large)
379 call device_map(this%flux3, this%flux3_d, this%n_large)
381 call device_map(this%volflux1, this%volflux1_d, this%n_large)
382 call device_map(this%volflux2, this%volflux2_d, this%n_large)
383 call device_map(this%volflux3, this%volflux3_d, this%n_large)
384 call device_map(this%absvolflux, this%absvolflux_d, this%n_large)
386 call device_map(this%n1, this%n1_d, this%n_large)
387 call device_map(this%n2, this%n2_d, this%n_large)
388 call device_map(this%n3, this%n3_d, this%n_large)
389 call device_map(this%facet_factor, this%facet_factor_d, this%n_large)
400 call device_memcpy(this%facet_factor, this%facet_factor_d, this%n_large,&
454 integer,
intent(in) :: l, k, j, i, n
455 type(
dofmap_t),
pointer,
intent(in) :: dm
456 type(
coef_t),
pointer,
intent(in) :: coef
457 real(kind=
rp) :: dist2, dist_1, dist_2
459 real(kind=
rp) :: x1, y1, z1, x2, y2, z2
460 real(kind=
rp) :: normal1(3), normal2(3)
461 real(kind=
rp) :: n11, n12, n13, n21, n22, n23
462 real(kind=
rp) :: v1, v2, v3
467 normal1 = coef%get_normal(1, l, k, i, 1)
471 x1 = dm%x(1, l, k, i)
472 y1 = dm%y(1, l, k, i)
473 z1 = dm%z(1, l, k, i)
474 normal2 = coef%get_normal(1, l, k, i, 2)
478 x2 = dm%x(n, l, k, i)
479 y2 = dm%y(n, l, k, i)
480 z2 = dm%z(n, l, k, i)
484 normal1 = coef%get_normal(1, l, k, i, 2)
488 x1 = dm%x(n, l, k, i)
489 y1 = dm%y(n, l, k, i)
490 z1 = dm%z(n, l, k, i)
491 normal2 = coef%get_normal(1, l, k, i, 1)
495 x2 = dm%x(1, l, k, i)
496 y2 = dm%y(1, l, k, i)
497 z2 = dm%z(1, l, k, i)
499 normal1 = coef%get_normal(1, l, k, i, 3)
503 x1 = dm%x(l, 1, k, i)
504 y1 = dm%y(l, 1, k, i)
505 z1 = dm%z(l, 1, k, i)
506 normal2 = coef%get_normal(1, l, k, i, 4)
510 x2 = dm%x(l, n, k, i)
511 y2 = dm%y(l, n, k, i)
512 z2 = dm%z(l, n, k, i)
514 normal1 = coef%get_normal(1, l, k, i, 4)
518 x1 = dm%x(l, n, k, i)
519 y1 = dm%y(l, n, k, i)
520 z1 = dm%z(l, n, k, i)
521 normal2 = coef%get_normal(1, l, k, i, 3)
525 x2 = dm%x(l, 1, k, i)
526 y2 = dm%y(l, 1, k, i)
527 z2 = dm%z(l, 1, k, i)
529 normal1 = coef%get_normal(1, l, k, i, 5)
533 x1 = dm%x(l, k, 1, i)
534 y1 = dm%y(l, k, 1, i)
535 z1 = dm%z(l, k, 1, i)
536 normal2 = coef%get_normal(1, l, k, i, 6)
540 x2 = dm%x(l, k, n, i)
541 y2 = dm%y(l, k, n, i)
542 z2 = dm%z(l, k, n, i)
544 normal1 = coef%get_normal(1, l, k, i, 6)
548 x1 = dm%x(l, k, n, i)
549 y1 = dm%y(l, k, n, i)
550 z1 = dm%z(l, k, n, i)
551 normal2 = coef%get_normal(1, l, k, i, 5)
555 x2 = dm%x(l, k, 1, i)
556 y2 = dm%y(l, k, 1, i)
557 z2 = dm%z(l, k, 1, i)
559 call neko_error(
"The face index is not correct")
567 dist_1 = v1*n11 + v2*n12 + v3*n13
568 dist_2 = - (v1*n21 + v2*n22 + v3*n23)
570 dist2 = ((dist_1 + dist_2)/2.0_rp)*((dist_1 + dist_2)/2.0_rp)
577 integer :: i, j, k, l
578 real(kind=
rp) :: area_tmp
580 allocate(this%facet_factor(this%lx + 2, this%lx + 2, &
581 this%lx + 2, this%coef%msh%nelv))
583 associate(facet_factor => this%facet_factor, &
586 nelv => this%coef%msh%nelv, &
587 jacinv => this%coef%jacinv, h2 => this%h2, &
588 tau => this%tau, n1 => this%n1, &
589 n2 => this%n2, n3 => this%n3)
597 area_tmp = coef%get_area(1, l, k, i, j)
598 facet_factor(1, l + 1, k + 1, i) = area_tmp * tau * &
599 h2(1, l + 1, k + 1, i) * &
600 (n1(1, l + 1, k + 1, i) * coef%drdx(1, l, k, i) + &
601 n2(1, l + 1, k + 1, i) * coef%drdy(1, l, k, i) + &
602 n3(1, l + 1, k + 1, i) * coef%drdz(1, l, k, i) ) &
605 area_tmp = coef%get_area(1, l, k, i, j)
606 facet_factor(lx + 2, l + 1, k + 1, i) = area_tmp * tau * &
607 h2(lx + 2, l + 1, k + 1, i) * &
608 (n1(lx + 2, l + 1, k + 1, i) * &
609 coef%drdx(lx, l, k, i) + &
610 n2(lx + 2, l + 1, k + 1, i) * &
611 coef%drdy(lx, l, k, i) + &
612 n3(lx + 2, l + 1, k + 1, i) * &
613 coef%drdz(lx, l, k, i) ) &
614 * jacinv(lx, l, k, i)
616 area_tmp = coef%get_area(l, 1, k, i, j)
617 facet_factor(l + 1, 1, k + 1, i) = area_tmp * tau * &
618 h2(l + 1, 1, k + 1, i) * &
619 (n1(l + 1, 1, k + 1, i) * coef%dsdx(l, 1, k, i) + &
620 n2(l + 1, 1, k + 1, i) * coef%dsdy(l, 1, k, i) + &
621 n3(l + 1, 1, k + 1, i) * coef%dsdz(l, 1, k, i) ) &
624 area_tmp = coef%get_area(l, 1, k, i, j)
625 facet_factor(l + 1, lx + 2, k + 1, i) = area_tmp * tau * &
626 h2(l + 1, lx + 2, k + 1, i) * &
627 (n1(l + 1, lx + 2, k + 1, i) * &
628 coef%dsdx(l, lx, k, i) + &
629 n2(l + 1, lx + 2, k + 1, i) * &
630 coef%dsdy(l, lx, k, i) + &
631 n3(l + 1, lx + 2, k + 1, i) * &
632 coef%dsdz(l, lx, k, i) ) &
633 * jacinv(l, lx, k, i)
635 area_tmp = coef%get_area(l, k, 1, i, j)
636 facet_factor(l + 1, k + 1, 1, i) = area_tmp * tau * &
637 h2(l + 1, k + 1, 1, i) * &
638 (n1(l + 1, k + 1, 1, i) * coef%dtdx(l, k, 1, i) + &
639 n2(l + 1, k + 1, 1, i) * coef%dtdy(l, k, 1, i) + &
640 n3(l + 1, k + 1, 1, i) * coef%dtdz(l, k, 1, i) ) &
643 area_tmp = coef%get_area(l, k, 1, i, j)
644 facet_factor(l + 1, k + 1, lx + 2, i) = area_tmp * tau * &
645 h2(l + 1, k + 1, lx + 2, i) * &
647 n1(l + 1, k + 1, lx + 2, i) * &
648 coef%dtdx(l, k, lx, i) + &
649 n2(l + 1, k + 1, lx + 2, i) * &
650 coef%dtdy(l, k, lx, i) + &
651 n3(l + 1, k + 1, lx + 2, i) * &
652 coef%dtdz(l, k, lx, i) &
654 * jacinv(l, k, lx, i)
656 call neko_error(
"The face index is not correct")
673 if (
allocated(this%penalty))
then
674 if (neko_bcknd_device .eq. 1)
then
675 call device_unmap(this%penalty, this%penalty_d)
677 deallocate(this%penalty)
679 if (
allocated(this%grad1))
then
680 if (neko_bcknd_device .eq. 1)
then
681 call device_unmap(this%grad1, this%grad1_d)
683 deallocate(this%grad1)
685 if (
allocated(this%grad2))
then
686 if (neko_bcknd_device .eq. 1)
then
687 call device_unmap(this%grad2, this%grad2_d)
689 deallocate(this%grad2)
691 if (
allocated(this%grad3))
then
692 if (neko_bcknd_device .eq. 1)
then
693 call device_unmap(this%grad3, this%grad3_d)
695 deallocate(this%grad3)
697 if (
allocated(this%h2))
then
700 if (
allocated(this%n_facet))
then
701 deallocate(this%n_facet)
703 if (
allocated(this%dphidxi))
then
704 if (neko_bcknd_device .eq. 1)
then
705 call device_unmap(this%dphidxi, this%dphidxi_d)
707 deallocate(this%dphidxi)
709 if (
allocated(this%penalty_facet))
then
710 if (neko_bcknd_device .eq. 1)
then
711 call device_unmap(this%penalty_facet, this%penalty_facet_d)
713 deallocate(this%penalty_facet)
715 if (
allocated(this%G))
then
716 if (neko_bcknd_device .eq. 1)
then
717 call device_unmap(this%G, this%G_d)
721 if (
allocated(this%flux1))
then
722 if (neko_bcknd_device .eq. 1)
then
723 call device_unmap(this%flux1, this%flux1_d)
725 deallocate(this%flux1)
727 if (
allocated(this%flux2))
then
728 if (neko_bcknd_device .eq. 1)
then
729 call device_unmap(this%flux2, this%flux2_d)
731 deallocate(this%flux2)
733 if (
allocated(this%flux3))
then
734 if (neko_bcknd_device .eq. 1)
then
735 call device_unmap(this%flux3, this%flux3_d)
737 deallocate(this%flux3)
739 if (
allocated(this%volflux1))
then
740 if (neko_bcknd_device .eq. 1)
then
741 call device_unmap(this%volflux1, this%volflux1_d)
743 deallocate(this%volflux1)
745 if (
allocated(this%volflux2))
then
746 if (neko_bcknd_device .eq. 1)
then
747 call device_unmap(this%volflux2, this%volflux2_d)
749 deallocate(this%volflux2)
751 if (
allocated(this%volflux3))
then
752 if (neko_bcknd_device .eq. 1)
then
753 call device_unmap(this%volflux3, this%volflux3_d)
755 deallocate(this%volflux3)
757 if (
allocated(this%absvolflux))
then
758 if (neko_bcknd_device .eq. 1)
then
759 call device_unmap(this%absvolflux, this%absvolflux_d)
761 deallocate(this%absvolflux)
763 if (
allocated(this%n1))
then
764 if (neko_bcknd_device .eq. 1)
then
765 call device_unmap(this%n1, this%n1_d)
769 if (
allocated(this%n2))
then
770 if (neko_bcknd_device .eq. 1)
then
771 call device_unmap(this%n2, this%n2_d)
775 if (
allocated(this%n3))
then
776 if (neko_bcknd_device .eq. 1)
then
777 call device_unmap(this%n3, this%n3_d)
781 if (
allocated(this%facet_factor))
then
782 if (neko_bcknd_device .eq. 1)
then
783 call device_unmap(this%facet_factor, this%facet_factor_d)
785 deallocate(this%facet_factor)
792 call this%s_fields%free()
794 call this%Xh_GJP%free()
795 call this%gs_GJP%free()
796 call this%dm_GJP%free()
923 type(field_t),
intent(in) :: s
925 call dudxyz(this%grad1, s%x, this%coef%drdx, &
926 this%coef%dsdx, this%coef%dtdx, this%coef)
927 call dudxyz(this%grad2, s%x, this%coef%drdy, &
928 this%coef%dsdy, this%coef%dtdy, this%coef)
929 call dudxyz(this%grad3, s%x, this%coef%drdz, &
930 this%coef%dsdz, this%coef%dtdz, this%coef)
932 if (neko_bcknd_device .eq. 1)
then
933 call device_pick_facet_value_hex(this%flux1_d, this%grad1_d, &
934 this%lx, this%coef%msh%nelv)
935 call device_pick_facet_value_hex(this%flux2_d, this%grad2_d, &
936 this%lx, this%coef%msh%nelv)
937 call device_pick_facet_value_hex(this%flux3_d, this%grad3_d, &
938 this%lx, this%coef%msh%nelv)
939 call device_col2(this%flux1_d, this%n1_d, this%n_large)
940 call device_col2(this%flux2_d, this%n2_d, this%n_large)
941 call device_col2(this%flux3_d, this%n3_d, this%n_large)
942 call device_add3s2(this%G_d, this%flux1_d, this%flux2_d, &
943 1.0_rp, 1.0_rp, this%n_large)
944 call device_add2(this%G_d, this%flux3_d, this%n_large)
947 this%lx, this%coef%msh%nelv)
949 this%lx, this%coef%msh%nelv)
951 this%lx, this%coef%msh%nelv)
952 call col2(this%flux1, this%n1, this%n_large)
953 call col2(this%flux2, this%n2, this%n_large)
954 call col2(this%flux3, this%n3, this%n_large)
955 call add3(this%G, this%flux1, this%flux2, this%n_large)
956 call add2(this%G, this%flux3, this%n_large)
959 call this%gs_GJP%op(this%G, this%n_large, gs_op_add)
969 type(field_t),
intent(in) :: u, v, w
973 if (neko_bcknd_device .eq. 1)
then
974 call device_pick_facet_value_hex(this%volflux1_d, u%x_d, this%lx, &
976 call device_pick_facet_value_hex(this%volflux2_d, v%x_d, this%lx, &
978 call device_pick_facet_value_hex(this%volflux3_d, w%x_d, this%lx, &
980 call device_col2(this%volflux1_d, this%n1_d, this%n_large)
981 call device_col2(this%volflux2_d, this%n2_d, this%n_large)
982 call device_col2(this%volflux3_d, this%n3_d, this%n_large)
983 call device_add3s2(this%absvolflux_d, this%volflux1_d, &
984 this%volflux2_d, 1.0_rp, 1.0_rp, this%n_large)
985 call device_add2(this%absvolflux_d, this%volflux3_d, this%n_large)
986 call device_absval(this%absvolflux_d, this%n_large)
989 this%lx, this%coef%msh%nelv)
991 this%lx, this%coef%msh%nelv)
993 this%lx, this%coef%msh%nelv)
994 call col2(this%volflux1, this%n1, this%n_large)
995 call col2(this%volflux2, this%n2, this%n_large)
996 call col2(this%volflux3, this%n3, this%n_large)
997 call add3(this%absvolflux, this%volflux1, this%volflux2, this%n_large)
998 call add2(this%absvolflux, this%volflux3, this%n_large)
999 call absval(this%absvolflux, this%n_large)
1010 integer,
intent(in) :: lx, nelv
1011 real(kind=rp),
intent(in) :: f_field(lx, lx, lx, nelv)
1012 real(kind=rp),
intent(inout) :: f_facet(lx + 2, lx + 2, lx + 2, nelv)
1014 call copy(f_facet(1, 2: lx + 1, 2: lx + 1, :), &
1015 f_field(1, :, :, :), lx * lx * nelv)
1016 call copy(f_facet(lx + 2, 2: lx + 1, 2: lx + 1, :), &
1017 f_field(lx, :, :, :), lx * lx * nelv)
1018 call copy(f_facet(2: lx + 1, 1, 2: lx + 1, :), &
1019 f_field(:, 1, :, :), lx * lx * nelv)
1020 call copy(f_facet(2: lx + 1, lx + 2, 2: lx + 1, :), &
1021 f_field(:, lx, :, :), lx * lx * nelv)
1022 call copy(f_facet(2: lx + 1, 2: lx + 1, 1, :), &
1023 f_field(:, :, 1, :), lx * lx * nelv)
1024 call copy(f_facet(2: lx + 1, 2: lx + 1, lx + 2, :), &
1025 f_field(:, :, lx, :), lx * lx * nelv)