138 real(kind=
rp),
allocatable :: g11(:,:,:,:)
140 real(kind=
rp),
allocatable :: g22(:,:,:,:)
142 real(kind=
rp),
allocatable :: g33(:,:,:,:)
144 real(kind=
rp),
allocatable :: g12(:,:,:,:)
146 real(kind=
rp),
allocatable :: g13(:,:,:,:)
148 real(kind=
rp),
allocatable :: g23(:,:,:,:)
153 real(kind=
rp) :: metric_cond = 0.0_rp
160 real(kind=
rp) :: metric_scaled_cond = 0.0_rp
163 integer :: metric_degenerate = 0
169 real(kind=
rp) :: metric_perturb = 0.0_rp
180 logical :: metric_sp_safe = .false.
182 real(kind=
rp),
allocatable :: g11_compr(:,:,:,:)
184 real(kind=
rp),
allocatable :: g22_compr(:,:,:,:)
186 real(kind=
rp),
allocatable :: g33_compr(:,:,:,:)
188 real(kind=
rp),
allocatable :: g12_compr(:,:,:,:)
190 real(kind=
rp),
allocatable :: g13_compr(:,:,:,:)
192 real(kind=
rp),
allocatable :: g23_compr(:,:,:,:)
194 integer,
allocatable :: compression_inds(:)
197 logical :: geo_compression = .false.
200 real(kind=
rp) :: geo_compression_tol = 0.0_rp
202 real(kind=
rp),
allocatable :: mult(:,:,:,:)
207 real(kind=
rp),
allocatable :: dxdr(:,:,:,:), dydr(:,:,:,:), dzdr(:,:,:,:)
208 real(kind=
rp),
allocatable :: dxds(:,:,:,:), dyds(:,:,:,:), dzds(:,:,:,:)
209 real(kind=
rp),
allocatable :: dxdt(:,:,:,:), dydt(:,:,:,:), dzdt(:,:,:,:)
213 real(kind=
rp),
allocatable :: drdx(:,:,:,:), drdy(:,:,:,:), drdz(:,:,:,:)
214 real(kind=
rp),
allocatable :: dsdx(:,:,:,:), dsdy(:,:,:,:), dsdz(:,:,:,:)
215 real(kind=
rp),
allocatable :: dtdx(:,:,:,:), dtdy(:,:,:,:), dtdz(:,:,:,:)
217 real(kind=
rp),
allocatable :: h1(:,:,:,:)
218 real(kind=
rp),
allocatable :: h2(:,:,:,:)
221 real(kind=
rp),
allocatable :: jac(:,:,:,:)
222 real(kind=
rp),
allocatable :: jacinv(:,:,:,:)
223 real(kind=
rp),
allocatable :: b(:,:,:,:)
224 real(kind=
rp),
allocatable :: binv(:,:,:,:)
225 real(kind=
rp),
pointer :: blag(:,:,:,:) => null()
226 real(kind=
rp),
pointer :: blaglag(:,:,:,:) => null()
227 real(kind=
rp),
allocatable :: area(:,:,:,:)
228 real(kind=
rp),
allocatable :: nx(:,:,:,:)
229 real(kind=
rp),
allocatable :: ny(:,:,:,:)
230 real(kind=
rp),
allocatable :: nz(:,:,:,:)
231 logical :: cyclic = .false.
232 integer,
allocatable :: cyc_msk(:)
233 real(kind=
rp),
allocatable :: r11(:)
234 real(kind=
rp),
allocatable :: r12(:)
237 logical,
private :: coef_metrics_initialized = .false.
245 real(kind=
rp) :: volume = 0.0_rp
250 type(
gs_t),
pointer :: gs_h=> null()
256 type(c_ptr) :: g11_d = c_null_ptr
257 type(c_ptr) :: g22_d = c_null_ptr
258 type(c_ptr) :: g33_d = c_null_ptr
259 type(c_ptr) :: g12_d = c_null_ptr
260 type(c_ptr) :: g13_d = c_null_ptr
261 type(c_ptr) :: g23_d = c_null_ptr
262 type(c_ptr) :: g11_compr_d = c_null_ptr
263 type(c_ptr) :: g22_compr_d = c_null_ptr
264 type(c_ptr) :: g33_compr_d = c_null_ptr
265 type(c_ptr) :: g12_compr_d = c_null_ptr
266 type(c_ptr) :: g13_compr_d = c_null_ptr
267 type(c_ptr) :: g23_compr_d = c_null_ptr
268 type(c_ptr) :: compression_inds_d = c_null_ptr
269 type(c_ptr) :: dxdr_d = c_null_ptr
270 type(c_ptr) :: dydr_d = c_null_ptr
271 type(c_ptr) :: dzdr_d = c_null_ptr
272 type(c_ptr) :: dxds_d = c_null_ptr
273 type(c_ptr) :: dyds_d = c_null_ptr
274 type(c_ptr) :: dzds_d = c_null_ptr
275 type(c_ptr) :: dxdt_d = c_null_ptr
276 type(c_ptr) :: dydt_d = c_null_ptr
277 type(c_ptr) :: dzdt_d = c_null_ptr
278 type(c_ptr) :: drdx_d = c_null_ptr
279 type(c_ptr) :: drdy_d = c_null_ptr
280 type(c_ptr) :: drdz_d = c_null_ptr
281 type(c_ptr) :: dsdx_d = c_null_ptr
282 type(c_ptr) :: dsdy_d = c_null_ptr
283 type(c_ptr) :: dsdz_d = c_null_ptr
284 type(c_ptr) :: dtdx_d = c_null_ptr
285 type(c_ptr) :: dtdy_d = c_null_ptr
286 type(c_ptr) :: dtdz_d = c_null_ptr
287 type(c_ptr) :: mult_d = c_null_ptr
288 type(c_ptr) :: h1_d = c_null_ptr
289 type(c_ptr) :: h2_d = c_null_ptr
290 type(c_ptr) :: jac_d = c_null_ptr
291 type(c_ptr) :: jacinv_d = c_null_ptr
292 type(c_ptr) :: b_d = c_null_ptr
293 type(c_ptr) :: blag_d = c_null_ptr
294 type(c_ptr) :: blaglag_d = c_null_ptr
295 type(c_ptr) :: binv_d = c_null_ptr
296 type(c_ptr) :: area_d = c_null_ptr
297 type(c_ptr) :: nx_d = c_null_ptr
298 type(c_ptr) :: ny_d = c_null_ptr
299 type(c_ptr) :: nz_d = c_null_ptr
300 type(c_ptr) :: cyc_msk_d = c_null_ptr
301 type(c_ptr) :: r11_d = c_null_ptr
302 type(c_ptr) :: r12_d = c_null_ptr
305 integer :: metrics_version = 0
317 procedure, pass(this) :: enable_geo_compression => &
321 generic :: init => init_empty, init_all
377 class(
coef_t),
intent(inout),
target :: this
378 type(
gs_t),
intent(inout),
target :: gs_h
379 integer,
intent(in),
optional :: scope
380 integer :: n, m, ncyc
385 if (
present(scope))
then
392 call neko_log%section(
'Coefficients')
394 this%msh => gs_h%dofmap%msh
395 this%Xh => gs_h%dofmap%Xh
396 this%dof => gs_h%dofmap
403 allocate(this%G11(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
404 allocate(this%G22(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
405 allocate(this%G33(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
406 allocate(this%G12(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
407 allocate(this%G13(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
408 allocate(this%G23(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
410 allocate(this%dxdr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
411 allocate(this%dxds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
412 allocate(this%dxdt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
414 allocate(this%dydr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
415 allocate(this%dyds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
416 allocate(this%dydt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
418 allocate(this%dzdr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
419 allocate(this%dzds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
420 allocate(this%dzdt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
422 allocate(this%drdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
423 allocate(this%dsdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
424 allocate(this%dtdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
426 allocate(this%drdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
427 allocate(this%dsdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
428 allocate(this%dtdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
430 allocate(this%drdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
431 allocate(this%dsdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
432 allocate(this%dtdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
434 allocate(this%jac(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
435 allocate(this%jacinv(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
438 allocate(this%area(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
439 allocate(this%nx(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
440 allocate(this%ny(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
441 allocate(this%nz(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
444 allocate(this%B(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
445 allocate(this%Binv(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
449 this%Blaglag => this%B
451 allocate(this%h1(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
452 allocate(this%h2(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
454 allocate(this%mult(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
461 n = this%Xh%lx * this%Xh%ly * this%Xh%lz * this%msh%nelv
499 call device_map(this%jacinv, this%jacinv_d, n)
503 this%Blag_d = this%B_d
504 this%Blaglag_d = this%B_d
507 m = this%Xh%lx * this%Xh%ly * 6 * this%msh%nelv
532 this%coef_metrics_initialized = .true.
557 call rone(this%mult, n)
570 ncyc = this%msh%periodic%size * this%Xh%lx * this%Xh%lx
571 allocate(this%cyc_msk(0:ncyc))
572 this%cyc_msk(0) = ncyc + 1
573 if (ncyc .gt. 0)
then
574 allocate(this%R11(ncyc))
575 allocate(this%R12(ncyc))
578 call rone(this%R11, ncyc)
579 call rzero(this%R12, ncyc)
582 call device_map(this%cyc_msk, this%cyc_msk_d, ncyc+1)
992 type(
coef_t),
intent(inout) :: c
993 integer :: e, i, lxy, lyz, ntot
995 lxy = c%Xh%lx*c%Xh%ly
996 lyz = c%Xh%ly*c%Xh%lz
999 associate(drdx => c%drdx, drdy => c%drdy, drdz => c%drdz, &
1000 dsdx => c%dsdx, dsdy => c%dsdy, dsdz => c%dsdz, &
1001 dtdx => c%dtdx, dtdy => c%dtdy, dtdz => c%dtdz, &
1002 dxdr => c%dxdr, dydr => c%dydr, dzdr => c%dzdr, &
1003 dxds => c%dxds, dyds => c%dyds, dzds => c%dzds, &
1004 dxdt => c%dxdt, dydt => c%dydt, dzdt => c%dzdt, &
1005 dx => c%Xh%dx, dy => c%Xh%dy, dz => c%Xh%dz, &
1006 x => c%dof%x%x, y => c%dof%y%x, z => c%dof%z%x, &
1007 lx => c%Xh%lx, ly => c%Xh%ly, lz => c%Xh%lz, &
1008 dyt => c%Xh%dyt, dzt => c%Xh%dzt, &
1009 jacinv => c%jacinv, jac => c%jac)
1014 c%dsdx_d, c%dsdy_d, c%dsdz_d, c%dtdx_d, c%dtdy_d, c%dtdz_d, &
1015 c%dxdr_d, c%dydr_d, c%dzdr_d, c%dxds_d, c%dyds_d, c%dzds_d, &
1016 c%dxdt_d, c%dydt_d, c%dzdt_d, c%Xh%dx_d, c%Xh%dy_d, c%Xh%dz_d, &
1017 c%dof%x%x_d, c%dof%y%x_d, c%dof%z%x_d, c%jacinv_d, c%jac_d, &
1018 c%Xh%lx, c%msh%nelv)
1021 if (.not. c%coef_metrics_initialized)
then
1066 do e = 1, c%msh%nelv
1067 call mxm(dx, lx, x(1,1,1,e), lx, dxdr(1,1,1,e), lyz)
1068 call mxm(dx, lx, y(1,1,1,e), lx, dydr(1,1,1,e), lyz)
1069 call mxm(dx, lx, z(1,1,1,e), lx, dzdr(1,1,1,e), lyz)
1072 call mxm(x(1,1,i,e), lx, dyt, ly, dxds(1,1,i,e), ly)
1073 call mxm(y(1,1,i,e), lx, dyt, ly, dyds(1,1,i,e), ly)
1074 call mxm(z(1,1,i,e), lx, dyt, ly, dzds(1,1,i,e), ly)
1078 if (c%msh%gdim .eq. 3)
then
1079 call mxm(x(1,1,1,e), lxy, dzt, lz, dxdt(1,1,1,e), lz)
1080 call mxm(y(1,1,1,e), lxy, dzt, lz, dydt(1,1,1,e), lz)
1081 call mxm(z(1,1,1,e), lxy, dzt, lz, dzdt(1,1,1,e), lz)
1083 call rzero(dxdt(1,1,1,e), lxy)
1084 call rzero(dydt(1,1,1,e), lxy)
1085 call rone(dzdt(1,1,1,e), lxy)
1090 if (c%msh%gdim .eq. 2)
then
1091 call rzero (jac, ntot)
1092 call addcol3 (jac, dxdr, dyds, ntot)
1093 call subcol3 (jac, dxds, dydr, ntot)
1094 call copy (drdx, dyds, ntot)
1095 call copy (drdy, dxds, ntot)
1097 call copy (dsdx, dydr, ntot)
1099 call copy (dsdy, dxdr, ntot)
1100 call rzero (drdz, ntot)
1101 call rzero (dsdz, ntot)
1102 call rone (dtdz, ntot)
1107 c%jac(i, 1, 1, 1) = 0.0_rp
1112 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxdr(i, 1, 1, 1) &
1113 * c%dyds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) )
1115 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxdt(i, 1, 1, 1) &
1116 * c%dydr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) )
1118 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxds(i, 1, 1, 1) &
1119 * c%dydt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) )
1124 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxdr(i, 1, 1, 1) &
1125 * c%dydt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) )
1127 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxds(i, 1, 1, 1) &
1128 * c%dydr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) )
1130 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxdt(i, 1, 1, 1) &
1131 * c%dyds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) )
1136 c%drdx(i, 1, 1, 1) = c%dyds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) &
1137 - c%dydt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1)
1139 c%drdy(i, 1, 1, 1) = c%dxdt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) &
1140 - c%dxds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1)
1142 c%drdz(i, 1, 1, 1) = c%dxds(i, 1, 1, 1) * c%dydt(i, 1, 1, 1) &
1143 - c%dxdt(i, 1, 1, 1) * c%dyds(i, 1, 1, 1)
1148 c%dsdx(i, 1, 1, 1) = c%dydt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) &
1149 - c%dydr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1)
1151 c%dsdy(i, 1, 1, 1) = c%dxdr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) &
1152 - c%dxdt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1)
1154 c%dsdz(i, 1, 1, 1) = c%dxdt(i, 1, 1, 1) * c%dydr(i, 1, 1, 1) &
1155 - c%dxdr(i, 1, 1, 1) * c%dydt(i, 1, 1, 1)
1160 c%dtdx(i, 1, 1, 1) = c%dydr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) &
1161 - c%dyds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1)
1163 c%dtdy(i, 1, 1, 1) = c%dxds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) &
1164 - c%dxdr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1)
1166 c%dtdz(i, 1, 1, 1) = c%dxdr(i, 1, 1, 1) * c%dyds(i, 1, 1, 1) &
1167 - c%dxds(i, 1, 1, 1) * c%dydr(i, 1, 1, 1)
1172 call invers2(jacinv, jac, ntot)
1181 type(
coef_t),
intent(inout) :: c
1182 integer :: e, i, lxyz, ntot
1184 lxyz = c%Xh%lx * c%Xh%ly * c%Xh%lz
1187 if (neko_bcknd_device .eq. 1)
then
1189 call device_coef_generate_geo(c%G11_d, c%G12_d, c%G13_d, &
1190 c%G22_d, c%G23_d, c%G33_d, &
1191 c%drdx_d, c%drdy_d, c%drdz_d, &
1192 c%dsdx_d, c%dsdy_d, c%dsdz_d, &
1193 c%dtdx_d, c%dtdy_d, c%dtdz_d, &
1194 c%jacinv_d, c%Xh%w3_d, c%msh%nelv, &
1195 c%Xh%lx, c%msh%gdim)
1198 if (.not. c%coef_metrics_initialized)
then
1199 call device_memcpy(c%G11, c%G11_d, ntot, device_to_host, &
1201 call device_memcpy(c%G22, c%G22_d, ntot, device_to_host, &
1203 call device_memcpy(c%G33, c%G33_d, ntot, device_to_host, &
1205 call device_memcpy(c%G12, c%G12_d, ntot, device_to_host, &
1207 call device_memcpy(c%G13, c%G13_d, ntot, device_to_host, &
1209 call device_memcpy(c%G23, c%G23_d, ntot, device_to_host, &
1214 if (c%msh%gdim .eq. 2)
then
1217 c%G11(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%drdx(i, 1, 1, 1) &
1218 + c%drdy(i, 1, 1, 1) * c%drdy(i, 1, 1, 1)
1220 c%G22(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1221 + c%dsdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1)
1223 c%G12(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1224 + c%drdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1)
1228 c%G11(i, 1, 1, 1) = c%G11(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1229 c%G22(i, 1, 1, 1) = c%G22(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1230 c%G12(i, 1, 1, 1) = c%G12(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1231 c%G33(i, 1, 1, 1) = 0.0_rp
1232 c%G13(i, 1, 1, 1) = 0.0_rp
1233 c%G23(i, 1, 1, 1) = 0.0_rp
1236 do concurrent(e = 1:c%msh%nelv)
1237 do concurrent(i = 1:lxyz)
1238 c%G11(i,1,1,e) = c%G11(i,1,1,e) * c%Xh%w3(i,1,1)
1239 c%G22(i,1,1,e) = c%G22(i,1,1,e) * c%Xh%w3(i,1,1)
1240 c%G12(i,1,1,e) = c%G12(i,1,1,e) * c%Xh%w3(i,1,1)
1248 c%G11(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%drdx(i, 1, 1, 1) &
1249 + c%drdy(i, 1, 1, 1) * c%drdy(i, 1, 1, 1) &
1250 + c%drdz(i, 1, 1, 1) * c%drdz(i, 1, 1, 1)
1252 c%G22(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1253 + c%dsdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1) &
1254 + c%dsdz(i, 1, 1, 1) * c%dsdz(i, 1, 1, 1)
1256 c%G33(i, 1, 1, 1) = c%dtdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1257 + c%dtdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1258 + c%dtdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1263 c%G11(i, 1, 1, 1) = c%G11(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1264 c%G22(i, 1, 1, 1) = c%G22(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1265 c%G33(i, 1, 1, 1) = c%G33(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1270 c%G12(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1271 + c%drdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1) &
1272 + c%drdz(i, 1, 1, 1) * c%dsdz(i, 1, 1, 1)
1274 c%G13(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1275 + c%drdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1276 + c%drdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1278 c%G23(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1279 + c%dsdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1280 + c%dsdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1285 c%G12(i, 1, 1, 1) = c%G12(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1286 c%G13(i, 1, 1, 1) = c%G13(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1287 c%G23(i, 1, 1, 1) = c%G23(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1291 do e = 1, c%msh%nelv
1292 do concurrent(i = 1:lxyz)
1293 c%G11(i,1,1,e) = c%G11(i,1,1,e) * c%Xh%w3(i,1,1)
1294 c%G22(i,1,1,e) = c%G22(i,1,1,e) * c%Xh%w3(i,1,1)
1295 c%G12(i,1,1,e) = c%G12(i,1,1,e) * c%Xh%w3(i,1,1)
1297 c%G33(i,1,1,e) = c%G33(i,1,1,e) * c%Xh%w3(i,1,1)
1298 c%G13(i,1,1,e) = c%G13(i,1,1,e) * c%Xh%w3(i,1,1)
1299 c%G23(i,1,1,e) = c%G23(i,1,1,e) * c%Xh%w3(i,1,1)
1368 class(
coef_t),
intent(inout) :: this
1369 real(kind=dp) :: e1, e2, e3, scal
1370 real(kind=dp) :: c1, c2, c3, c12, c13, c23
1371 real(kind=rp) :: kmax, kcmax, tmp(1)
1372 integer :: i, j, k, e, n, ndeg, ndeg_glb, ierr
1373 character(len=LOG_SIZE) :: log_buf
1378 if (neko_bcknd_device .eq. 1 .and. this%coef_metrics_initialized)
then
1379 call device_memcpy(this%G11, this%G11_d, n, device_to_host, &
1381 call device_memcpy(this%G22, this%G22_d, n, device_to_host, &
1383 call device_memcpy(this%G33, this%G33_d, n, device_to_host, &
1385 call device_memcpy(this%G12, this%G12_d, n, device_to_host, &
1387 call device_memcpy(this%G13, this%G13_d, n, device_to_host, &
1389 call device_memcpy(this%G23, this%G23_d, n, device_to_host, &
1397 do e = 1, this%msh%nelv
1398 do k = 1, this%Xh%lz
1399 do j = 1, this%Xh%ly
1400 do i = 1, this%Xh%lx
1405 scal =
max(abs(
real(this%G11(i,j,k,e), dp)), &
1406 abs(
real(this%G22(i,j,k,e), dp)))
1407 scal =
max(scal, abs(
real(this%G33(i,j,k,e), dp)))
1408 scal =
max(scal, abs(
real(this%G12(i,j,k,e), dp)))
1409 scal =
max(scal, abs(
real(this%G13(i,j,k,e), dp)))
1410 scal =
max(scal, abs(
real(this%G23(i,j,k,e), dp)))
1412 if (scal .le. 0.0_dp)
then
1417 if (this%msh%gdim .eq. 2)
then
1418 call eig_sym2(
real(this%G11(i,j,k,e), dp) / scal, &
1419 real(this%G22(i,j,k,e), dp) / scal, &
1420 real(this%G12(i,j,k,e), dp) / scal, e1, e3)
1422 call eig_sym3(
real(this%G11(i,j,k,e), dp) / scal, &
1423 real(this%G22(i,j,k,e), dp) / scal, &
1424 real(this%G33(i,j,k,e), dp) / scal, &
1425 real(this%G12(i,j,k,e), dp) / scal, &
1426 real(this%G13(i,j,k,e), dp) / scal, &
1427 real(this%G23(i,j,k,e), dp) / scal, e1, e2, e3)
1430 if (e3 .le. 0.0_dp)
then
1433 kmax =
max(kmax,
real(e1 / e3, rp))
1443 c12 =
real(this%G12(i,j,k,e), dp) &
1444 / sqrt(
real(this%G11(i,j,k,e), dp) &
1445 *
real(this%G22(i,j,k,e), dp))
1447 if (this%msh%gdim .eq. 2)
then
1448 call eig_sym2(1.0_dp, 1.0_dp, c12, c1, c3)
1450 c13 =
real(this%G13(i,j,k,e), dp) &
1451 / sqrt(
real(this%G11(i,j,k,e), dp) &
1452 *
real(this%G33(i,j,k,e), dp))
1453 c23 =
real(this%G23(i,j,k,e), dp) &
1454 / sqrt(
real(this%G22(i,j,k,e), dp) &
1455 *
real(this%G33(i,j,k,e), dp))
1456 call eig_sym3(1.0_dp, 1.0_dp, 1.0_dp, &
1457 c12, c13, c23, c1, c2, c3)
1460 if (c3 .gt. 0.0_dp)
then
1461 kcmax =
max(kcmax,
real(c1 / c3, rp))
1466 kcmax = huge(0.0_rp)
1476 this%metric_cond = glmax(tmp, 1)
1479 this%metric_scaled_cond = glmax(tmp, 1)
1481 call mpi_allreduce(ndeg, ndeg_glb, 1, mpi_integer, mpi_sum, &
1483 this%metric_degenerate = ndeg_glb
1491 this%metric_perturb =
real(neko_eps_sp, rp) * this%metric_scaled_cond &
1492 + neko_eps * this%metric_cond
1494 this%metric_sp_safe = (this%metric_degenerate .eq. 0) .and. &
1497 write(log_buf,
'(A,ES12.5)')
'Metric condition : ', this%metric_cond
1498 call neko_log%message(log_buf)
1499 write(log_buf,
'(A,ES12.5)')
'Metric skew cond : ', &
1500 this%metric_scaled_cond
1501 call neko_log%message(log_buf)
1502 write(log_buf,
'(A,ES12.5)')
'Metric perturb : ', this%metric_perturb
1503 call neko_log%message(log_buf)
1504 write(log_buf,
'(A,L1)')
'Metric fp32 safe : ', this%metric_sp_safe
1505 call neko_log%message(log_buf)
1520 write(log_buf,
'(A,ES12.5)') &
1521 'Metric too ill conditioned for single precision, limit ', &
1523 call neko_log%warning(log_buf)
1524 call neko_log%message(
'Geometric factors may lose positive ' // &
1525 'definiteness, consider a double precision build')
1537 if (rp .eq. sp)
then
1538 write(log_buf,
'(A,ES12.5,A,ES12.5)') &
1539 'Single precision metric error ', this%metric_perturb, &
1541 call neko_log%warning(log_buf)
1543 call neko_log%message(
'Single precision storage of the ' // &
1544 'geometric factors would exceed the error tolerance')
1547 if (
real(neko_eps_sp, rp) * this%metric_scaled_cond .ge. &
1548 neko_eps * this%metric_cond)
then
1549 call neko_log%message(
'Dominated by element skew')
1551 call neko_log%message(
'Dominated by element aspect ratio')
1559 if (this%metric_degenerate .gt. 0)
then
1560 write(log_buf,
'(A,I0)') &
1561 'Non positive definite metric at points: ', this%metric_degenerate
1562 call neko_log%error(log_buf)
1622 type(
coef_t),
intent(inout) :: c
1623 logical,
intent(in) :: verbose
1624 integer :: e, m, i, lxyz, m_max, ierr, n
1625 integer,
allocatable :: c_inds_rev(:)
1626 integer :: stats(2), glb_stats(2)
1627 real(kind=rp) :: ctol, diff
1628 character(len=LOG_SIZE) :: log_buf
1634 if (neko_bcknd_device .eq. 1)
then
1636 call device_memcpy(c%G11, c%G11_d, n, device_to_host, sync = .false.)
1637 call device_memcpy(c%G22, c%G22_d, n, device_to_host, sync = .false.)
1638 call device_memcpy(c%G33, c%G33_d, n, device_to_host, sync = .false.)
1639 call device_memcpy(c%G12, c%G12_d, n, device_to_host, sync = .false.)
1640 call device_memcpy(c%G13, c%G13_d, n, device_to_host, sync = .false.)
1641 call device_memcpy(c%G23, c%G23_d, n, device_to_host, sync = .true.)
1644 ctol = c%geo_compression_tol
1648 allocate(c%compression_inds(c%msh%nelv))
1649 allocate(c_inds_rev(c%msh%nelv))
1654 if (c%msh%nelv .gt. 0)
then
1656 c%compression_inds(1) = 1
1662 lxyz = c%Xh%lx * c%Xh%ly * c%Xh%lz
1663 do e = 2, c%msh%nelv
1670 diff = diff + abs(c%G11(i,1,1,e) - c%G11(i,1,1,c_inds_rev(m))) &
1671 + 2.0_rp*abs(c%G12(i,1,1,e) - c%G12(i,1,1,c_inds_rev(m))) &
1672 + 2.0_rp*abs(c%G13(i,1,1,e) - c%G13(i,1,1,c_inds_rev(m))) &
1673 + abs(c%G22(i,1,1,e) - c%G22(i,1,1,c_inds_rev(m))) &
1674 + 2.0_rp*abs(c%G23(i,1,1,e) - c%G23(i,1,1,c_inds_rev(m))) &
1675 + abs(c%G33(i,1,1,e) - c%G33(i,1,1,c_inds_rev(m)))
1679 if ( diff .le. ctol )
then
1680 c%compression_inds(e) = m
1686 if (.not. (diff .le. ctol))
then
1688 c%compression_inds(e) = m_max
1689 c_inds_rev(m_max) = e
1694 allocate(c%G11_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1695 allocate(c%G22_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1696 allocate(c%G33_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1697 allocate(c%G12_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1698 allocate(c%G13_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1699 allocate(c%G23_compr(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1702 c%G11_compr(i,1,1,m) = c%G11(i,1,1,c_inds_rev(m))
1703 c%G22_compr(i,1,1,m) = c%G22(i,1,1,c_inds_rev(m))
1704 c%G33_compr(i,1,1,m) = c%G33(i,1,1,c_inds_rev(m))
1705 c%G12_compr(i,1,1,m) = c%G12(i,1,1,c_inds_rev(m))
1706 c%G13_compr(i,1,1,m) = c%G13(i,1,1,c_inds_rev(m))
1707 c%G23_compr(i,1,1,m) = c%G23(i,1,1,c_inds_rev(m))
1711 deallocate(c_inds_rev)
1713 if (neko_bcknd_device .eq. 1)
then
1715 call device_map(c%G11_compr, c%G11_compr_d, n)
1716 call device_map(c%G22_compr, c%G22_compr_d, n)
1717 call device_map(c%G33_compr, c%G33_compr_d, n)
1718 call device_map(c%G12_compr, c%G12_compr_d, n)
1719 call device_map(c%G13_compr, c%G13_compr_d, n)
1720 call device_map(c%G23_compr, c%G23_compr_d, n)
1721 call device_map(c%compression_inds, c%compression_inds_d, c%msh%nelv)
1722 call device_memcpy(c%G11_compr, c%G11_compr_d, n, host_to_device, &
1724 call device_memcpy(c%G22_compr, c%G22_compr_d, n, host_to_device, &
1726 call device_memcpy(c%G33_compr, c%G33_compr_d, n, host_to_device, &
1728 call device_memcpy(c%G12_compr, c%G12_compr_d, n, host_to_device, &
1730 call device_memcpy(c%G13_compr, c%G13_compr_d, n, host_to_device, &
1732 call device_memcpy(c%G23_compr, c%G23_compr_d, n, host_to_device, &
1734 call device_memcpy(c%compression_inds, c%compression_inds_d, &
1735 c%msh%nelv, host_to_device, sync = .true.)
1739 stats(1) = c%msh%nelv
1741 call mpi_allreduce(
stats, glb_stats, 2, mpi_integer, mpi_sum, &
1744 call neko_log%section(
'Compressed G')
1745 write(log_buf,
'(A,I0)')
'Copies : ', glb_stats(2)
1746 call neko_log%message(log_buf)
1747 write(log_buf,
'(A,I0)')
'Elements : ', glb_stats(1)
1748 call neko_log%message(log_buf)
1749 write(log_buf,
'(A,ES12.5)')
'Tolerance : ', ctol
1750 call neko_log%message(log_buf)
1751 call neko_log%end_section()
1935 type(
coef_t),
intent(inout) :: coef
1936 real(kind=rp),
allocatable :: a(:,:,:,:)
1937 real(kind=rp),
allocatable :: b(:,:,:,:)
1938 real(kind=rp),
allocatable :: c(:,:,:,:)
1939 real(kind=rp),
allocatable :: dot(:,:,:,:)
1940 integer :: n, m, e, i, j, k, lx
1941 real(kind=rp) :: weight, len
1945 if (neko_bcknd_device .eq. 1)
then
1947 call device_coef_generate_area_and_normal( &
1948 coef%area_d, coef%nx_d, coef%ny_d, coef%nz_d, &
1949 coef%dxdr_d, coef%dydr_d, coef%dzdr_d, &
1950 coef%dxds_d, coef%dyds_d, coef%dzds_d, &
1951 coef%dxdt_d, coef%dydt_d, coef%dzdt_d, &
1952 coef%Xh%wx_d, coef%Xh%wy_d, coef%Xh%wz_d, &
1953 lx, coef%msh%nelv, neko_eps)
1957 call device_memcpy(coef%area, coef%area_d, m, &
1958 device_to_host, sync = .false.)
1959 call device_memcpy(coef%nx, coef%nx_d, m, &
1960 device_to_host, sync = .false.)
1961 call device_memcpy(coef%ny, coef%ny_d, m, &
1962 device_to_host, sync = .false.)
1963 call device_memcpy(coef%nz, coef%nz_d, &
1964 m, device_to_host, sync = .true.)
1968 allocate(a(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1969 allocate(b(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1970 allocate(c(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1971 allocate(dot(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1978 a(i, 1, 1, 1) = coef%dyds(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1) &
1979 - coef%dzds(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1)
1981 b(i, 1, 1, 1) = coef%dzds(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1) &
1982 - coef%dxds(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1)
1984 c(i, 1, 1, 1) = coef%dxds(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1) &
1985 - coef%dyds(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1)
1990 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
1991 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
1992 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
1996 do e = 1, coef%msh%nelv
1997 do concurrent(k = 1:coef%Xh%lx)
1998 do concurrent(j = 1:coef%Xh%lx)
1999 weight = coef%Xh%wy(j) * coef%Xh%wz(k)
2000 coef%area(j, k, 2, e) = sqrt(dot(lx, j, k, e)) * weight
2001 coef%area(j, k, 1, e) = sqrt(dot(1, j, k, e)) * weight
2002 coef%nx(j,k, 1, e) = -a(1, j, k, e)
2003 coef%nx(j,k, 2, e) = a(lx, j, k, e)
2004 coef%ny(j,k, 1, e) = -b(1, j, k, e)
2005 coef%ny(j,k, 2, e) = b(lx, j, k, e)
2006 coef%nz(j,k, 1, e) = -c(1, j, k, e)
2007 coef%nz(j,k, 2, e) = c(lx, j, k, e)
2016 a(i, 1, 1, 1) = coef%dydr(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1) &
2017 - coef%dzdr(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1)
2019 b(i, 1, 1, 1) = coef%dzdr(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1) &
2020 - coef%dxdr(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1)
2022 c(i, 1, 1, 1) = coef%dxdr(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1) &
2023 - coef%dydr(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1)
2028 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
2029 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
2030 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
2034 do e = 1, coef%msh%nelv
2035 do concurrent(k = 1:coef%Xh%lx)
2036 do concurrent(j = 1:coef%Xh%lx)
2037 weight = coef%Xh%wx(j) * coef%Xh%wz(k)
2038 coef%area(j, k, 3, e) = sqrt(dot(j, 1, k, e)) * weight
2039 coef%area(j, k, 4, e) = sqrt(dot(j, lx, k, e)) * weight
2040 coef%nx(j,k, 3, e) = a(j, 1, k, e)
2041 coef%nx(j,k, 4, e) = -a(j, lx, k, e)
2042 coef%ny(j,k, 3, e) = b(j, 1, k, e)
2043 coef%ny(j,k, 4, e) = -b(j, lx, k, e)
2044 coef%nz(j,k, 3, e) = c(j, 1, k, e)
2045 coef%nz(j,k, 4, e) = -c(j, lx, k, e)
2053 a(i, 1, 1, 1) = coef%dydr(i, 1, 1, 1) * coef%dzds(i, 1, 1, 1) &
2054 - coef%dzdr(i, 1, 1, 1) * coef%dyds(i, 1, 1, 1)
2056 b(i, 1, 1, 1) = coef%dzdr(i, 1, 1, 1) * coef%dxds(i, 1, 1, 1) &
2057 - coef%dxdr(i, 1, 1, 1) * coef%dzds(i, 1, 1, 1)
2059 c(i, 1, 1, 1) = coef%dxdr(i, 1, 1, 1) * coef%dyds(i, 1, 1, 1) &
2060 - coef%dydr(i, 1, 1, 1) * coef%dxds(i, 1, 1, 1)
2065 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
2066 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
2067 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
2071 do e = 1, coef%msh%nelv
2072 do concurrent(k = 1:coef%Xh%lx)
2073 do concurrent(j = 1:coef%Xh%lx)
2074 weight = coef%Xh%wx(j) * coef%Xh%wy(k)
2075 coef%area(j, k, 5, e) = sqrt(dot(j, k, 1, e)) * weight
2076 coef%area(j, k, 6, e) = sqrt(dot(j, k, lx, e)) * weight
2077 coef%nx(j,k, 5, e) = -a(j, k, 1, e)
2078 coef%nx(j,k, 6, e) = a(j, k, lx, e)
2079 coef%ny(j,k, 5, e) = -b(j, k, 1, e)
2080 coef%ny(j,k, 6, e) = b(j, k, lx, e)
2081 coef%nz(j,k, 5, e) = -c(j, k, 1, e)
2082 coef%nz(j,k, 6, e) = c(j, k, lx, e)
2089 do j = 1,
size(coef%nz)
2090 len = sqrt(coef%nx(j,1,1,1)**2 + &
2091 coef%ny(j,1,1,1)**2 + coef%nz(j,1,1,1)**2)
2092 if (len .gt. neko_eps)
then
2093 coef%nx(j,1,1,1) = coef%nx(j,1,1,1) / len
2094 coef%ny(j,1,1,1) = coef%ny(j,1,1,1) / len
2095 coef%nz(j,1,1,1) = coef%nz(j,1,1,1) / len