137 real(kind=
rp),
allocatable :: g11(:,:,:,:)
139 real(kind=
rp),
allocatable :: g22(:,:,:,:)
141 real(kind=
rp),
allocatable :: g33(:,:,:,:)
143 real(kind=
rp),
allocatable :: g12(:,:,:,:)
145 real(kind=
rp),
allocatable :: g13(:,:,:,:)
147 real(kind=
rp),
allocatable :: g23(:,:,:,:)
152 real(kind=
rp) :: metric_cond = 0.0_rp
159 real(kind=
rp) :: metric_scaled_cond = 0.0_rp
162 integer :: metric_degenerate = 0
168 real(kind=
rp) :: metric_perturb = 0.0_rp
179 logical :: metric_sp_safe = .false.
181 real(kind=
rp),
allocatable :: g11_compressed(:,:,:,:)
183 real(kind=
rp),
allocatable :: g22_compressed(:,:,:,:)
185 real(kind=
rp),
allocatable :: g33_compressed(:,:,:,:)
187 real(kind=
rp),
allocatable :: g12_compressed(:,:,:,:)
189 real(kind=
rp),
allocatable :: g13_compressed(:,:,:,:)
191 real(kind=
rp),
allocatable :: g23_compressed(:,:,:,:)
193 integer,
allocatable :: compression_inds(:)
195 real(kind=
rp),
allocatable :: mult(:,:,:,:)
200 real(kind=
rp),
allocatable :: dxdr(:,:,:,:), dydr(:,:,:,:), dzdr(:,:,:,:)
201 real(kind=
rp),
allocatable :: dxds(:,:,:,:), dyds(:,:,:,:), dzds(:,:,:,:)
202 real(kind=
rp),
allocatable :: dxdt(:,:,:,:), dydt(:,:,:,:), dzdt(:,:,:,:)
206 real(kind=
rp),
allocatable :: drdx(:,:,:,:), drdy(:,:,:,:), drdz(:,:,:,:)
207 real(kind=
rp),
allocatable :: dsdx(:,:,:,:), dsdy(:,:,:,:), dsdz(:,:,:,:)
208 real(kind=
rp),
allocatable :: dtdx(:,:,:,:), dtdy(:,:,:,:), dtdz(:,:,:,:)
210 real(kind=
rp),
allocatable :: h1(:,:,:,:)
211 real(kind=
rp),
allocatable :: h2(:,:,:,:)
214 real(kind=
rp),
allocatable :: jac(:,:,:,:)
215 real(kind=
rp),
allocatable :: jacinv(:,:,:,:)
216 real(kind=
rp),
allocatable :: b(:,:,:,:)
217 real(kind=
rp),
allocatable :: binv(:,:,:,:)
218 real(kind=
rp),
pointer :: blag(:,:,:,:) => null()
219 real(kind=
rp),
pointer :: blaglag(:,:,:,:) => null()
220 real(kind=
rp),
allocatable :: area(:,:,:,:)
221 real(kind=
rp),
allocatable :: nx(:,:,:,:)
222 real(kind=
rp),
allocatable :: ny(:,:,:,:)
223 real(kind=
rp),
allocatable :: nz(:,:,:,:)
224 logical :: cyclic = .false.
225 integer,
allocatable :: cyc_msk(:)
226 real(kind=
rp),
allocatable :: r11(:)
227 real(kind=
rp),
allocatable :: r12(:)
230 logical,
private :: coef_metrics_initialized = .false.
238 real(kind=
rp) :: volume = 0.0_rp
243 type(
gs_t),
pointer :: gs_h=> null()
249 type(c_ptr) :: g11_d = c_null_ptr
250 type(c_ptr) :: g22_d = c_null_ptr
251 type(c_ptr) :: g33_d = c_null_ptr
252 type(c_ptr) :: g12_d = c_null_ptr
253 type(c_ptr) :: g13_d = c_null_ptr
254 type(c_ptr) :: g23_d = c_null_ptr
255 type(c_ptr) :: dxdr_d = c_null_ptr
256 type(c_ptr) :: dydr_d = c_null_ptr
257 type(c_ptr) :: dzdr_d = c_null_ptr
258 type(c_ptr) :: dxds_d = c_null_ptr
259 type(c_ptr) :: dyds_d = c_null_ptr
260 type(c_ptr) :: dzds_d = c_null_ptr
261 type(c_ptr) :: dxdt_d = c_null_ptr
262 type(c_ptr) :: dydt_d = c_null_ptr
263 type(c_ptr) :: dzdt_d = c_null_ptr
264 type(c_ptr) :: drdx_d = c_null_ptr
265 type(c_ptr) :: drdy_d = c_null_ptr
266 type(c_ptr) :: drdz_d = c_null_ptr
267 type(c_ptr) :: dsdx_d = c_null_ptr
268 type(c_ptr) :: dsdy_d = c_null_ptr
269 type(c_ptr) :: dsdz_d = c_null_ptr
270 type(c_ptr) :: dtdx_d = c_null_ptr
271 type(c_ptr) :: dtdy_d = c_null_ptr
272 type(c_ptr) :: dtdz_d = c_null_ptr
273 type(c_ptr) :: mult_d = c_null_ptr
274 type(c_ptr) :: h1_d = c_null_ptr
275 type(c_ptr) :: h2_d = c_null_ptr
276 type(c_ptr) :: jac_d = c_null_ptr
277 type(c_ptr) :: jacinv_d = c_null_ptr
278 type(c_ptr) :: b_d = c_null_ptr
279 type(c_ptr) :: blag_d = c_null_ptr
280 type(c_ptr) :: blaglag_d = c_null_ptr
281 type(c_ptr) :: binv_d = c_null_ptr
282 type(c_ptr) :: area_d = c_null_ptr
283 type(c_ptr) :: nx_d = c_null_ptr
284 type(c_ptr) :: ny_d = c_null_ptr
285 type(c_ptr) :: nz_d = c_null_ptr
286 type(c_ptr) :: cyc_msk_d = c_null_ptr
287 type(c_ptr) :: r11_d = c_null_ptr
288 type(c_ptr) :: r12_d = c_null_ptr
291 integer :: metrics_version = 0
305 generic :: init => init_empty, init_all
361 class(
coef_t),
intent(inout),
target :: this
362 type(
gs_t),
intent(inout),
target :: gs_h
363 integer,
intent(in),
optional :: scope
364 integer :: n, m, ncyc
369 if (
present(scope))
then
376 call neko_log%section(
'Coefficients')
378 this%msh => gs_h%dofmap%msh
379 this%Xh => gs_h%dofmap%Xh
380 this%dof => gs_h%dofmap
387 allocate(this%G11(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
388 allocate(this%G22(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
389 allocate(this%G33(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
390 allocate(this%G12(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
391 allocate(this%G13(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
392 allocate(this%G23(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
394 allocate(this%dxdr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
395 allocate(this%dxds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
396 allocate(this%dxdt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
398 allocate(this%dydr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
399 allocate(this%dyds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
400 allocate(this%dydt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
402 allocate(this%dzdr(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
403 allocate(this%dzds(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
404 allocate(this%dzdt(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
406 allocate(this%drdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
407 allocate(this%dsdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
408 allocate(this%dtdx(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
410 allocate(this%drdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
411 allocate(this%dsdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
412 allocate(this%dtdy(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
414 allocate(this%drdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
415 allocate(this%dsdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
416 allocate(this%dtdz(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
418 allocate(this%jac(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
419 allocate(this%jacinv(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
422 allocate(this%area(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
423 allocate(this%nx(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
424 allocate(this%ny(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
425 allocate(this%nz(this%Xh%lx, this%Xh%ly, 6, this%msh%nelv))
428 allocate(this%B(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
429 allocate(this%Binv(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
433 this%Blaglag => this%B
435 allocate(this%h1(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
436 allocate(this%h2(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
438 allocate(this%mult(this%Xh%lx, this%Xh%ly, this%Xh%lz, this%msh%nelv))
445 n = this%Xh%lx * this%Xh%ly * this%Xh%lz * this%msh%nelv
483 call device_map(this%jacinv, this%jacinv_d, n)
487 this%Blag_d = this%B_d
488 this%Blaglag_d = this%B_d
491 m = this%Xh%lx * this%Xh%ly * 6 * this%msh%nelv
518 this%coef_metrics_initialized = .true.
543 call rone(this%mult, n)
556 ncyc = this%msh%periodic%size * this%Xh%lx * this%Xh%lx
557 allocate(this%cyc_msk(0:ncyc))
558 this%cyc_msk(0) = ncyc + 1
559 if (ncyc .gt. 0)
then
560 allocate(this%R11(ncyc))
561 allocate(this%R12(ncyc))
564 call rone(this%R11, ncyc)
565 call rzero(this%R12, ncyc)
568 call device_map(this%cyc_msk, this%cyc_msk_d, ncyc+1)
1002 type(
coef_t),
intent(inout) :: c
1003 integer :: e, i, lxy, lyz, ntot
1005 lxy = c%Xh%lx*c%Xh%ly
1006 lyz = c%Xh%ly*c%Xh%lz
1009 associate(drdx => c%drdx, drdy => c%drdy, drdz => c%drdz, &
1010 dsdx => c%dsdx, dsdy => c%dsdy, dsdz => c%dsdz, &
1011 dtdx => c%dtdx, dtdy => c%dtdy, dtdz => c%dtdz, &
1012 dxdr => c%dxdr, dydr => c%dydr, dzdr => c%dzdr, &
1013 dxds => c%dxds, dyds => c%dyds, dzds => c%dzds, &
1014 dxdt => c%dxdt, dydt => c%dydt, dzdt => c%dzdt, &
1015 dx => c%Xh%dx, dy => c%Xh%dy, dz => c%Xh%dz, &
1016 x => c%dof%x%x, y => c%dof%y%x, z => c%dof%z%x, &
1017 lx => c%Xh%lx, ly => c%Xh%ly, lz => c%Xh%lz, &
1018 dyt => c%Xh%dyt, dzt => c%Xh%dzt, &
1019 jacinv => c%jacinv, jac => c%jac)
1024 c%dsdx_d, c%dsdy_d, c%dsdz_d, c%dtdx_d, c%dtdy_d, c%dtdz_d, &
1025 c%dxdr_d, c%dydr_d, c%dzdr_d, c%dxds_d, c%dyds_d, c%dzds_d, &
1026 c%dxdt_d, c%dydt_d, c%dzdt_d, c%Xh%dx_d, c%Xh%dy_d, c%Xh%dz_d, &
1027 c%dof%x%x_d, c%dof%y%x_d, c%dof%z%x_d, c%jacinv_d, c%jac_d, &
1028 c%Xh%lx, c%msh%nelv)
1031 if (.not. c%coef_metrics_initialized)
then
1076 do e = 1, c%msh%nelv
1077 call mxm(dx, lx, x(1,1,1,e), lx, dxdr(1,1,1,e), lyz)
1078 call mxm(dx, lx, y(1,1,1,e), lx, dydr(1,1,1,e), lyz)
1079 call mxm(dx, lx, z(1,1,1,e), lx, dzdr(1,1,1,e), lyz)
1082 call mxm(x(1,1,i,e), lx, dyt, ly, dxds(1,1,i,e), ly)
1083 call mxm(y(1,1,i,e), lx, dyt, ly, dyds(1,1,i,e), ly)
1084 call mxm(z(1,1,i,e), lx, dyt, ly, dzds(1,1,i,e), ly)
1088 if (c%msh%gdim .eq. 3)
then
1089 call mxm(x(1,1,1,e), lxy, dzt, lz, dxdt(1,1,1,e), lz)
1090 call mxm(y(1,1,1,e), lxy, dzt, lz, dydt(1,1,1,e), lz)
1091 call mxm(z(1,1,1,e), lxy, dzt, lz, dzdt(1,1,1,e), lz)
1093 call rzero(dxdt(1,1,1,e), lxy)
1094 call rzero(dydt(1,1,1,e), lxy)
1095 call rone(dzdt(1,1,1,e), lxy)
1100 if (c%msh%gdim .eq. 2)
then
1101 call rzero (jac, ntot)
1102 call addcol3 (jac, dxdr, dyds, ntot)
1103 call subcol3 (jac, dxds, dydr, ntot)
1104 call copy (drdx, dyds, ntot)
1105 call copy (drdy, dxds, ntot)
1107 call copy (dsdx, dydr, ntot)
1109 call copy (dsdy, dxdr, ntot)
1110 call rzero (drdz, ntot)
1111 call rzero (dsdz, ntot)
1112 call rone (dtdz, ntot)
1117 c%jac(i, 1, 1, 1) = 0.0_rp
1122 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxdr(i, 1, 1, 1) &
1123 * c%dyds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) )
1125 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxdt(i, 1, 1, 1) &
1126 * c%dydr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) )
1128 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) + ( c%dxds(i, 1, 1, 1) &
1129 * c%dydt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) )
1134 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxdr(i, 1, 1, 1) &
1135 * c%dydt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) )
1137 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxds(i, 1, 1, 1) &
1138 * c%dydr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) )
1140 c%jac(i, 1, 1, 1) = c%jac(i, 1, 1, 1) - ( c%dxdt(i, 1, 1, 1) &
1141 * c%dyds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) )
1146 c%drdx(i, 1, 1, 1) = c%dyds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) &
1147 - c%dydt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1)
1149 c%drdy(i, 1, 1, 1) = c%dxdt(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) &
1150 - c%dxds(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1)
1152 c%drdz(i, 1, 1, 1) = c%dxds(i, 1, 1, 1) * c%dydt(i, 1, 1, 1) &
1153 - c%dxdt(i, 1, 1, 1) * c%dyds(i, 1, 1, 1)
1158 c%dsdx(i, 1, 1, 1) = c%dydt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) &
1159 - c%dydr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1)
1161 c%dsdy(i, 1, 1, 1) = c%dxdr(i, 1, 1, 1) * c%dzdt(i, 1, 1, 1) &
1162 - c%dxdt(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1)
1164 c%dsdz(i, 1, 1, 1) = c%dxdt(i, 1, 1, 1) * c%dydr(i, 1, 1, 1) &
1165 - c%dxdr(i, 1, 1, 1) * c%dydt(i, 1, 1, 1)
1170 c%dtdx(i, 1, 1, 1) = c%dydr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1) &
1171 - c%dyds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1)
1173 c%dtdy(i, 1, 1, 1) = c%dxds(i, 1, 1, 1) * c%dzdr(i, 1, 1, 1) &
1174 - c%dxdr(i, 1, 1, 1) * c%dzds(i, 1, 1, 1)
1176 c%dtdz(i, 1, 1, 1) = c%dxdr(i, 1, 1, 1) * c%dyds(i, 1, 1, 1) &
1177 - c%dxds(i, 1, 1, 1) * c%dydr(i, 1, 1, 1)
1182 call invers2(jacinv, jac, ntot)
1191 type(
coef_t),
intent(inout) :: c
1192 integer :: e, i, lxyz, ntot
1194 lxyz = c%Xh%lx * c%Xh%ly * c%Xh%lz
1197 if (neko_bcknd_device .eq. 1)
then
1199 call device_coef_generate_geo(c%G11_d, c%G12_d, c%G13_d, &
1200 c%G22_d, c%G23_d, c%G33_d, &
1201 c%drdx_d, c%drdy_d, c%drdz_d, &
1202 c%dsdx_d, c%dsdy_d, c%dsdz_d, &
1203 c%dtdx_d, c%dtdy_d, c%dtdz_d, &
1204 c%jacinv_d, c%Xh%w3_d, c%msh%nelv, &
1205 c%Xh%lx, c%msh%gdim)
1208 if (.not. c%coef_metrics_initialized)
then
1209 call device_memcpy(c%G11, c%G11_d, ntot, device_to_host, &
1211 call device_memcpy(c%G22, c%G22_d, ntot, device_to_host, &
1213 call device_memcpy(c%G33, c%G33_d, ntot, device_to_host, &
1215 call device_memcpy(c%G12, c%G12_d, ntot, device_to_host, &
1217 call device_memcpy(c%G13, c%G13_d, ntot, device_to_host, &
1219 call device_memcpy(c%G23, c%G23_d, ntot, device_to_host, &
1224 if (c%msh%gdim .eq. 2)
then
1227 c%G11(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%drdx(i, 1, 1, 1) &
1228 + c%drdy(i, 1, 1, 1) * c%drdy(i, 1, 1, 1)
1230 c%G22(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1231 + c%dsdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1)
1233 c%G12(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1234 + c%drdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1)
1238 c%G11(i, 1, 1, 1) = c%G11(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1239 c%G22(i, 1, 1, 1) = c%G22(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1240 c%G12(i, 1, 1, 1) = c%G12(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1241 c%G33(i, 1, 1, 1) = 0.0_rp
1242 c%G13(i, 1, 1, 1) = 0.0_rp
1243 c%G23(i, 1, 1, 1) = 0.0_rp
1246 do concurrent(e = 1:c%msh%nelv)
1247 do concurrent(i = 1:lxyz)
1248 c%G11(i,1,1,e) = c%G11(i,1,1,e) * c%Xh%w3(i,1,1)
1249 c%G22(i,1,1,e) = c%G22(i,1,1,e) * c%Xh%w3(i,1,1)
1250 c%G12(i,1,1,e) = c%G12(i,1,1,e) * c%Xh%w3(i,1,1)
1258 c%G11(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%drdx(i, 1, 1, 1) &
1259 + c%drdy(i, 1, 1, 1) * c%drdy(i, 1, 1, 1) &
1260 + c%drdz(i, 1, 1, 1) * c%drdz(i, 1, 1, 1)
1262 c%G22(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1263 + c%dsdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1) &
1264 + c%dsdz(i, 1, 1, 1) * c%dsdz(i, 1, 1, 1)
1266 c%G33(i, 1, 1, 1) = c%dtdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1267 + c%dtdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1268 + c%dtdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1273 c%G11(i, 1, 1, 1) = c%G11(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1274 c%G22(i, 1, 1, 1) = c%G22(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1275 c%G33(i, 1, 1, 1) = c%G33(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1280 c%G12(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dsdx(i, 1, 1, 1) &
1281 + c%drdy(i, 1, 1, 1) * c%dsdy(i, 1, 1, 1) &
1282 + c%drdz(i, 1, 1, 1) * c%dsdz(i, 1, 1, 1)
1284 c%G13(i, 1, 1, 1) = c%drdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1285 + c%drdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1286 + c%drdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1288 c%G23(i, 1, 1, 1) = c%dsdx(i, 1, 1, 1) * c%dtdx(i, 1, 1, 1) &
1289 + c%dsdy(i, 1, 1, 1) * c%dtdy(i, 1, 1, 1) &
1290 + c%dsdz(i, 1, 1, 1) * c%dtdz(i, 1, 1, 1)
1295 c%G12(i, 1, 1, 1) = c%G12(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1296 c%G13(i, 1, 1, 1) = c%G13(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1297 c%G23(i, 1, 1, 1) = c%G23(i, 1, 1, 1) * c%jacinv(i, 1, 1, 1)
1301 do e = 1, c%msh%nelv
1302 do concurrent(i = 1:lxyz)
1303 c%G11(i,1,1,e) = c%G11(i,1,1,e) * c%Xh%w3(i,1,1)
1304 c%G22(i,1,1,e) = c%G22(i,1,1,e) * c%Xh%w3(i,1,1)
1305 c%G12(i,1,1,e) = c%G12(i,1,1,e) * c%Xh%w3(i,1,1)
1307 c%G33(i,1,1,e) = c%G33(i,1,1,e) * c%Xh%w3(i,1,1)
1308 c%G13(i,1,1,e) = c%G13(i,1,1,e) * c%Xh%w3(i,1,1)
1309 c%G23(i,1,1,e) = c%G23(i,1,1,e) * c%Xh%w3(i,1,1)
1378 class(
coef_t),
intent(inout) :: this
1379 real(kind=dp) :: e1, e2, e3, scal
1380 real(kind=dp) :: c1, c2, c3, c12, c13, c23
1381 real(kind=rp) :: kmax, kcmax, tmp(1)
1382 integer :: i, j, k, e, n, ndeg, ndeg_glb, ierr
1383 character(len=LOG_SIZE) :: log_buf
1388 if (neko_bcknd_device .eq. 1 .and. this%coef_metrics_initialized)
then
1389 call device_memcpy(this%G11, this%G11_d, n, device_to_host, &
1391 call device_memcpy(this%G22, this%G22_d, n, device_to_host, &
1393 call device_memcpy(this%G33, this%G33_d, n, device_to_host, &
1395 call device_memcpy(this%G12, this%G12_d, n, device_to_host, &
1397 call device_memcpy(this%G13, this%G13_d, n, device_to_host, &
1399 call device_memcpy(this%G23, this%G23_d, n, device_to_host, &
1407 do e = 1, this%msh%nelv
1408 do k = 1, this%Xh%lz
1409 do j = 1, this%Xh%ly
1410 do i = 1, this%Xh%lx
1415 scal =
max(abs(
real(this%G11(i,j,k,e), dp)), &
1416 abs(
real(this%G22(i,j,k,e), dp)))
1417 scal =
max(scal, abs(
real(this%G33(i,j,k,e), dp)))
1418 scal =
max(scal, abs(
real(this%G12(i,j,k,e), dp)))
1419 scal =
max(scal, abs(
real(this%G13(i,j,k,e), dp)))
1420 scal =
max(scal, abs(
real(this%G23(i,j,k,e), dp)))
1422 if (scal .le. 0.0_dp)
then
1427 if (this%msh%gdim .eq. 2)
then
1428 call eig_sym2(
real(this%G11(i,j,k,e), dp) / scal, &
1429 real(this%G22(i,j,k,e), dp) / scal, &
1430 real(this%G12(i,j,k,e), dp) / scal, e1, e3)
1432 call eig_sym3(
real(this%G11(i,j,k,e), dp) / scal, &
1433 real(this%G22(i,j,k,e), dp) / scal, &
1434 real(this%G33(i,j,k,e), dp) / scal, &
1435 real(this%G12(i,j,k,e), dp) / scal, &
1436 real(this%G13(i,j,k,e), dp) / scal, &
1437 real(this%G23(i,j,k,e), dp) / scal, e1, e2, e3)
1440 if (e3 .le. 0.0_dp)
then
1443 kmax =
max(kmax,
real(e1 / e3, rp))
1453 c12 =
real(this%G12(i,j,k,e), dp) &
1454 / sqrt(
real(this%G11(i,j,k,e), dp) &
1455 *
real(this%G22(i,j,k,e), dp))
1457 if (this%msh%gdim .eq. 2)
then
1458 call eig_sym2(1.0_dp, 1.0_dp, c12, c1, c3)
1460 c13 =
real(this%G13(i,j,k,e), dp) &
1461 / sqrt(
real(this%G11(i,j,k,e), dp) &
1462 *
real(this%G33(i,j,k,e), dp))
1463 c23 =
real(this%G23(i,j,k,e), dp) &
1464 / sqrt(
real(this%G22(i,j,k,e), dp) &
1465 *
real(this%G33(i,j,k,e), dp))
1466 call eig_sym3(1.0_dp, 1.0_dp, 1.0_dp, &
1467 c12, c13, c23, c1, c2, c3)
1470 if (c3 .gt. 0.0_dp)
then
1471 kcmax =
max(kcmax,
real(c1 / c3, rp))
1476 kcmax = huge(0.0_rp)
1486 this%metric_cond = glmax(tmp, 1)
1489 this%metric_scaled_cond = glmax(tmp, 1)
1491 call mpi_allreduce(ndeg, ndeg_glb, 1, mpi_integer, mpi_sum, &
1493 this%metric_degenerate = ndeg_glb
1501 this%metric_perturb =
real(neko_eps_sp, rp) * this%metric_scaled_cond &
1502 + neko_eps * this%metric_cond
1504 this%metric_sp_safe = (this%metric_degenerate .eq. 0) .and. &
1507 write(log_buf,
'(A,ES12.5)')
'Metric condition : ', this%metric_cond
1508 call neko_log%message(log_buf)
1509 write(log_buf,
'(A,ES12.5)')
'Metric skew cond : ', &
1510 this%metric_scaled_cond
1511 call neko_log%message(log_buf)
1512 write(log_buf,
'(A,ES12.5)')
'Metric perturb : ', this%metric_perturb
1513 call neko_log%message(log_buf)
1514 write(log_buf,
'(A,L1)')
'Metric fp32 safe : ', this%metric_sp_safe
1515 call neko_log%message(log_buf)
1530 write(log_buf,
'(A,ES12.5)') &
1531 'Metric too ill conditioned for single precision, limit ', &
1533 call neko_log%warning(log_buf)
1534 call neko_log%message(
'Geometric factors may lose positive ' // &
1535 'definiteness, consider a double precision build')
1547 if (rp .eq. sp)
then
1548 write(log_buf,
'(A,ES12.5,A,ES12.5)') &
1549 'Single precision metric error ', this%metric_perturb, &
1551 call neko_log%warning(log_buf)
1553 call neko_log%message(
'Single precision storage of the ' // &
1554 'geometric factors would exceed the error tolerance')
1557 if (
real(neko_eps_sp, rp) * this%metric_scaled_cond .ge. &
1558 neko_eps * this%metric_cond)
then
1559 call neko_log%message(
'Dominated by element skew')
1561 call neko_log%message(
'Dominated by element aspect ratio')
1569 if (this%metric_degenerate .gt. 0)
then
1570 write(log_buf,
'(A,I0)') &
1571 'Non positive definite metric at points: ', this%metric_degenerate
1572 call neko_log%error(log_buf)
1580 type(
coef_t),
intent(inout) :: c
1581 integer :: e, m, i, lxyz, m_max
1582 integer,
allocatable :: c_inds_rev(:)
1583 real(kind=rp) :: ctol = 1.0e-7_rp
1584 real(kind=rp) :: diff = 0.0_rp
1587 allocate(c%compression_inds(c%msh%nelv))
1588 allocate(c_inds_rev(c%msh%nelv))
1593 c%compression_inds(1) = 1
1598 lxyz = c%Xh%lx * c%Xh%ly * c%Xh%lz
1599 do e = 2, c%msh%nelv
1606 diff = diff + abs(c%G11(i,1,1,e) - c%G11(i,1,1,c_inds_rev(m))) &
1607 + 2.0*abs(c%G12(i,1,1,e) - c%G12(i,1,1,c_inds_rev(m))) &
1608 + 2.0*abs(c%G13(i,1,1,e) - c%G13(i,1,1,c_inds_rev(m))) &
1609 + abs(c%G22(i,1,1,e) - c%G22(i,1,1,c_inds_rev(m))) &
1610 + 2.0*abs(c%G23(i,1,1,e) - c%G23(i,1,1,c_inds_rev(m))) &
1611 + abs(c%G33(i,1,1,e) - c%G33(i,1,1,c_inds_rev(m)))
1615 if ( diff .le. ctol )
then
1616 c%compression_inds(e) = m
1622 if ( diff .gt. ctol )
then
1624 c%compression_inds(e) = m_max
1625 c_inds_rev(m_max) = e
1630 write(*,*)
'------Mapping Compression-----'
1631 write(*,*)
'Compressed from ', c%msh%nelv,
' to ', m_max
1634 allocate(c%G11_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1635 allocate(c%G22_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1636 allocate(c%G33_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1637 allocate(c%G12_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1638 allocate(c%G13_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1639 allocate(c%G23_compressed(c%Xh%lx, c%Xh%ly, c%Xh%lz, m_max))
1642 c%G11_compressed(i,1,1,m) = c%G11(i,1,1,c_inds_rev(m))
1643 c%G22_compressed(i,1,1,m) = c%G22(i,1,1,c_inds_rev(m))
1644 c%G33_compressed(i,1,1,m) = c%G33(i,1,1,c_inds_rev(m))
1645 c%G12_compressed(i,1,1,m) = c%G12(i,1,1,c_inds_rev(m))
1646 c%G13_compressed(i,1,1,m) = c%G13(i,1,1,c_inds_rev(m))
1647 c%G23_compressed(i,1,1,m) = c%G23(i,1,1,c_inds_rev(m))
1651 deallocate(c_inds_rev)
1778 type(
coef_t),
intent(inout) :: coef
1779 real(kind=rp),
allocatable :: a(:,:,:,:)
1780 real(kind=rp),
allocatable :: b(:,:,:,:)
1781 real(kind=rp),
allocatable :: c(:,:,:,:)
1782 real(kind=rp),
allocatable :: dot(:,:,:,:)
1783 integer :: n, m, e, i, j, k, lx
1784 real(kind=rp) :: weight, len
1788 if (neko_bcknd_device .eq. 1)
then
1790 call device_coef_generate_area_and_normal( &
1791 coef%area_d, coef%nx_d, coef%ny_d, coef%nz_d, &
1792 coef%dxdr_d, coef%dydr_d, coef%dzdr_d, &
1793 coef%dxds_d, coef%dyds_d, coef%dzds_d, &
1794 coef%dxdt_d, coef%dydt_d, coef%dzdt_d, &
1795 coef%Xh%wx_d, coef%Xh%wy_d, coef%Xh%wz_d, &
1796 lx, coef%msh%nelv, neko_eps)
1800 call device_memcpy(coef%area, coef%area_d, m, &
1801 device_to_host, sync = .false.)
1802 call device_memcpy(coef%nx, coef%nx_d, m, &
1803 device_to_host, sync = .false.)
1804 call device_memcpy(coef%ny, coef%ny_d, m, &
1805 device_to_host, sync = .false.)
1806 call device_memcpy(coef%nz, coef%nz_d, &
1807 m, device_to_host, sync = .true.)
1811 allocate(a(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1812 allocate(b(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1813 allocate(c(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1814 allocate(dot(coef%Xh%lx, coef%Xh%lx, coef%Xh%lx, coef%msh%nelv))
1821 a(i, 1, 1, 1) = coef%dyds(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1) &
1822 - coef%dzds(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1)
1824 b(i, 1, 1, 1) = coef%dzds(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1) &
1825 - coef%dxds(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1)
1827 c(i, 1, 1, 1) = coef%dxds(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1) &
1828 - coef%dyds(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1)
1833 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
1834 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
1835 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
1839 do e = 1, coef%msh%nelv
1840 do concurrent(k = 1:coef%Xh%lx)
1841 do concurrent(j = 1:coef%Xh%lx)
1842 weight = coef%Xh%wy(j) * coef%Xh%wz(k)
1843 coef%area(j, k, 2, e) = sqrt(dot(lx, j, k, e)) * weight
1844 coef%area(j, k, 1, e) = sqrt(dot(1, j, k, e)) * weight
1845 coef%nx(j,k, 1, e) = -a(1, j, k, e)
1846 coef%nx(j,k, 2, e) = a(lx, j, k, e)
1847 coef%ny(j,k, 1, e) = -b(1, j, k, e)
1848 coef%ny(j,k, 2, e) = b(lx, j, k, e)
1849 coef%nz(j,k, 1, e) = -c(1, j, k, e)
1850 coef%nz(j,k, 2, e) = c(lx, j, k, e)
1859 a(i, 1, 1, 1) = coef%dydr(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1) &
1860 - coef%dzdr(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1)
1862 b(i, 1, 1, 1) = coef%dzdr(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1) &
1863 - coef%dxdr(i, 1, 1, 1) * coef%dzdt(i, 1, 1, 1)
1865 c(i, 1, 1, 1) = coef%dxdr(i, 1, 1, 1) * coef%dydt(i, 1, 1, 1) &
1866 - coef%dydr(i, 1, 1, 1) * coef%dxdt(i, 1, 1, 1)
1871 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
1872 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
1873 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
1877 do e = 1, coef%msh%nelv
1878 do concurrent(k = 1:coef%Xh%lx)
1879 do concurrent(j = 1:coef%Xh%lx)
1880 weight = coef%Xh%wx(j) * coef%Xh%wz(k)
1881 coef%area(j, k, 3, e) = sqrt(dot(j, 1, k, e)) * weight
1882 coef%area(j, k, 4, e) = sqrt(dot(j, lx, k, e)) * weight
1883 coef%nx(j,k, 3, e) = a(j, 1, k, e)
1884 coef%nx(j,k, 4, e) = -a(j, lx, k, e)
1885 coef%ny(j,k, 3, e) = b(j, 1, k, e)
1886 coef%ny(j,k, 4, e) = -b(j, lx, k, e)
1887 coef%nz(j,k, 3, e) = c(j, 1, k, e)
1888 coef%nz(j,k, 4, e) = -c(j, lx, k, e)
1896 a(i, 1, 1, 1) = coef%dydr(i, 1, 1, 1) * coef%dzds(i, 1, 1, 1) &
1897 - coef%dzdr(i, 1, 1, 1) * coef%dyds(i, 1, 1, 1)
1899 b(i, 1, 1, 1) = coef%dzdr(i, 1, 1, 1) * coef%dxds(i, 1, 1, 1) &
1900 - coef%dxdr(i, 1, 1, 1) * coef%dzds(i, 1, 1, 1)
1902 c(i, 1, 1, 1) = coef%dxdr(i, 1, 1, 1) * coef%dyds(i, 1, 1, 1) &
1903 - coef%dydr(i, 1, 1, 1) * coef%dxds(i, 1, 1, 1)
1908 dot(i, 1, 1, 1) = a(i, 1, 1, 1) * a(i, 1, 1, 1) &
1909 + b(i, 1, 1, 1) * b(i, 1, 1, 1) &
1910 + c(i, 1, 1, 1) * c(i, 1, 1, 1)
1914 do e = 1, coef%msh%nelv
1915 do concurrent(k = 1:coef%Xh%lx)
1916 do concurrent(j = 1:coef%Xh%lx)
1917 weight = coef%Xh%wx(j) * coef%Xh%wy(k)
1918 coef%area(j, k, 5, e) = sqrt(dot(j, k, 1, e)) * weight
1919 coef%area(j, k, 6, e) = sqrt(dot(j, k, lx, e)) * weight
1920 coef%nx(j,k, 5, e) = -a(j, k, 1, e)
1921 coef%nx(j,k, 6, e) = a(j, k, lx, e)
1922 coef%ny(j,k, 5, e) = -b(j, k, 1, e)
1923 coef%ny(j,k, 6, e) = b(j, k, lx, e)
1924 coef%nz(j,k, 5, e) = -c(j, k, 1, e)
1925 coef%nz(j,k, 6, e) = c(j, k, lx, e)
1932 do j = 1,
size(coef%nz)
1933 len = sqrt(coef%nx(j,1,1,1)**2 + &
1934 coef%ny(j,1,1,1)**2 + coef%nz(j,1,1,1)**2)
1935 if (len .gt. neko_eps)
then
1936 coef%nx(j,1,1,1) = coef%nx(j,1,1,1) / len
1937 coef%ny(j,1,1,1) = coef%ny(j,1,1,1) / len
1938 coef%nz(j,1,1,1) = coef%nz(j,1,1,1) / len