163KOKKOS_INLINE_FUNCTION
void ibmFillEntry(
const OV& o,
int list_idx,
int c_idx,
164 typename OV::value_type sdf_c,
165 const typename OV::value_type sdf_n[6],
int bc_type,
166 const typename OV::value_type* thEx,
167 const typename OV::value_type* lamAxis =
nullptr,
168 int* sandwichSkipped =
nullptr) {
169 using Real =
typename OV::value_type;
170 o.cell_index(list_idx) = c_idx;
171 o.num_boundaries(list_idx) = 6;
173 Real xi_vals[6], D_vals[6];
174 for (
int k = 0; k < 6; ++k) {
175 if (sdf_n[k] < Real(0)) {
178 Real theta = sdf_c / (sdf_c - sdf_n[k]);
179 if (thEx !=
nullptr && Kokkos::isfinite(thEx[k]))
181 if (theta < Real(1e-4))
186 const Real lam = (lamAxis !=
nullptr && SCHEME == 0) ? lamAxis[k >> 1] : Real(0);
187 D_vals[k] = lam > Real(0) ?
poly_D_slip(theta, lam)
190 xi_vals[k] = Real(0.5);
195 xi_vals[k] = Real(1);
196 D_vals[k] = Real(1e9);
201 bool is_sandwich[3] = {is_ghost[0] && is_ghost[1], is_ghost[2] && is_ghost[3],
202 is_ghost[4] && is_ghost[5]};
203 Real D_sandwich[3] = {Real(0), Real(0), Real(0)};
204 for (
int a = 0; a < 3; ++a)
206 D_sandwich[a] = (SCHEME == 0) ?
poly_D_sandwich(xi_vals[2 * a + 1], xi_vals[2 * a])
208 Real min_D_abs = Real(1e30), D_rescale = Real(1);
209 auto update_min = [&](Real
val) {
210 if (Kokkos::fabs(
val) < min_D_abs) {
211 min_D_abs = Kokkos::fabs(
val);
215 for (
int axis = 0; axis < 3; ++axis) {
216 if (is_sandwich[axis])
217 update_min(D_sandwich[axis]);
219 if (is_ghost[2 * axis])
220 update_min(D_vals[2 * axis]);
221 if (is_ghost[2 * axis + 1])
222 update_min(D_vals[2 * axis + 1]);
225 o.D_rescale(list_idx) = D_rescale;
227 for (
int axis = 0; axis < 3; ++axis) {
228 int km = 2 * axis + 1, kp = 2 * axis;
229 bool sandwich = is_sandwich[axis], g_p = is_ghost[kp], g_m = is_ghost[km];
234 if (sandwich && lamAxis !=
nullptr && lamAxis[axis] > Real(0) && sandwichSkipped !=
nullptr)
235 Kokkos::atomic_fetch_add(sandwichSkipped, 1);
237 sandwich ? D_sandwich[axis] : (g_p ? D_vals[kp] : (g_m ? D_vals[km] : D_rescale));
238 Real
R = D_rescale / D_axis;
239 if (Kokkos::fabs(D_axis) < Real(1e-9))
241 o.R_val(list_idx * 6 + kp) =
R;
242 o.R_val(list_idx * 6 + km) =
R;
247 o.Nbc_val(list_idx * 6 + kp) = (
poly_Nbc_pp_sw(xi_vals[km], xi_vals[kp]) +
250 o.Nbc_val(list_idx * 6 + km) = (
poly_Nbc_pp_sw(xi_vals[kp], xi_vals[km]) +
263 o.M_val(list_idx * 6 + kp) = Real(0);
264 o.X_val(list_idx * 6 + kp) = Real(0);
265 o.M_val(list_idx * 6 + km) = Real(0);
266 o.X_val(list_idx * 6 + km) = Real(0);
268 for (
int side = 0; side < 2; ++side) {
269 int kk = side == 0 ? kp : km;
271 const Real lam = (lamAxis !=
nullptr && SCHEME == 0) ? lamAxis[axis] : Real(0);
273 o.K_val(list_idx * 6 + kk) =
poly_Nc_slip(xi_vals[kk], lam) *
R;
275 o.Nbc_val(list_idx * 6 + kk) =
poly_Nbc(xi_vals[kk]) *
R;
276 }
else if (SCHEME == 0) {
277 o.K_val(list_idx * 6 + kk) =
poly_Nc(xi_vals[kk]) *
R;
278 o.X_val(list_idx * 6 + kk) =
poly_N_nb(xi_vals[kk]) *
R;
279 o.Nbc_val(list_idx * 6 + kk) =
poly_Nbc(xi_vals[kk]) *
R;
281 o.K_val(list_idx * 6 + kk) =
poly_Nc_avg(xi_vals[kk]) *
R;
283 o.Nbc_val(list_idx * 6 + kk) =
poly_Nbc_avg(xi_vals[kk]) *
R;
285 o.M_val(list_idx * 6 + kk) = Real(0);
287 o.K_val(list_idx * 6 + kk) = Real(0);
288 o.M_val(list_idx * 6 + kk) = Real(1);
289 o.X_val(list_idx * 6 + kk) = Real(0);
290 o.Nbc_val(list_idx * 6 + kk) = Real(0);
294 o.dir_code(list_idx * 6 + kp) = kp;
295 o.dir_code(list_idx * 6 + km) = km;
298 o.D_rescale(list_idx) = Real(1);
299 for (
int k = 0; k < 6; ++k) {
300 o.dir_code(list_idx * 6 + k) = k;
301 o.R_val(list_idx * 6 + k) = Real(1);
302 o.K_val(list_idx * 6 + k) = is_ghost[k] ? Real(1) : Real(0);
303 o.M_val(list_idx * 6 + k) = is_ghost[k] ? Real(0) : Real(1);
304 o.X_val(list_idx * 6 + k) = Real(0);
305 o.Nbc_val(list_idx * 6 + k) = Real(0);
328 int ez,
double bx,
double by,
double bz,
double idiag) {
329 Kokkos::DefaultExecutionSpace space;
330 const std::size_t n = (std::size_t)ex * ey * ez;
331 using MVreal =
typename MV::non_const_value_type;
332 const MVreal nbx = (MVreal)(-bx), nby = (MVreal)(-by), nbz = (MVreal)(-bz),
333 c = (MVreal)(idiag + 2.0 * ((bx + by) + bz));
334 Kokkos::parallel_for(
335 "peclet::flow::ibm_build_diff", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, n),
336 KOKKOS_LAMBDA(std::size_t i) {
362 int ez,
int g, FaceProps fp,
double wx = 1.0,
double wy = 1.0,
367 "peclet::flow::ibm_build_diff_var",
C3{g, g, g},
C3{ex - g, ey - g, ez - g},
368 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
369 const long sx = 1, sy = ex, sz = (long)ex * ey;
370 const long i = (long)lx + (
long)ly * sy + (long)lz * sz;
373 const double bw = fp.beta(i, i - sx) * wx, be = fp.beta(i, i + sx) * wx;
374 const double bs = fp.beta(i, i - sy) * wy, bn = fp.beta(i, i + sy) * wy;
375 const double bb = fp.beta(i, i - sz) * wz, bt = fp.beta(i, i + sz) * wz;
376 AW(i) = (
typename MV::non_const_value_type)(-bw);
377 AE(i) = (
typename MV::non_const_value_type)(-be);
378 AS(i) = (
typename MV::non_const_value_type)(-bs);
379 AN(i) = (
typename MV::non_const_value_type)(-bn);
380 AB(i) = (
typename MV::non_const_value_type)(-bb);
381 AT(i) = (
typename MV::non_const_value_type)(-bt);
382 AC(i) = (
typename MV::non_const_value_type)(fp.idiag(i) + bw + be + bs + bn + bb + bt);
396 MV
AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, Kokkos::View<double*, IMem> a_inhom,
397 Kokkos::View<double*, IMem> rhs_scale,
const OV& ibm,
int numActive,
398 typename OV::value_type u_bc_val,
399 Kokkos::View<const double*, IMem> u_bc = Kokkos::View<const double*, IMem>()) {
400 Kokkos::DefaultExecutionSpace space;
401 const bool hasInhom = (a_inhom.extent(0) != 0), hasScale = (rhs_scale.extent(0) != 0);
402 const bool hasWallVel = (u_bc.extent(0) != 0);
403 Kokkos::parallel_for(
404 "peclet::flow::ibm_modify", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, numActive),
405 KOKKOS_LAMBDA(
int list_idx) {
406 const int OPP[6] = {1, 0, 3, 2, 5, 4};
407 const int c = ibm.cell_index(list_idx);
408 const auto descale = ibm.D_rescale(list_idx);
410 rhs_scale(c) = descale;
411 const double ubc = hasWallVel ? u_bc(c) : (double)u_bc_val;
412 const double orig[6] = {AE(c), AW(c), AN(c), AS(c), AT(c), AB(c)};
413 double aC = (double)
AC(c) * (double)descale;
414 double mod[6] = {0, 0, 0, 0, 0, 0};
416 for (
int k = 0; k < 6; ++k) {
417 const auto K = ibm.K_val(list_idx * 6 + k), M = ibm.M_val(list_idx * 6 + k);
418 const auto X = ibm.X_val(list_idx * 6 + k), Nbc = ibm.Nbc_val(list_idx * 6 + k);
419 const double vnb = orig[k];
420 aC += vnb * (double)K;
421 inhom += (double)Nbc * ubc * vnb;
422 mod[k] += vnb * ((double)descale * (double)M - 1.0);
423 mod[OPP[k]] += vnb * (double)X;
425 AC(c) = (
typename MV::non_const_value_type)aC;
426 AE(c) = (
typename MV::non_const_value_type)(orig[0] + mod[0]);
427 AW(c) = (
typename MV::non_const_value_type)(orig[1] + mod[1]);
428 AN(c) = (
typename MV::non_const_value_type)(orig[2] + mod[2]);
429 AS(c) = (
typename MV::non_const_value_type)(orig[3] + mod[3]);
430 AT(c) = (
typename MV::non_const_value_type)(orig[4] + mod[4]);
431 AB(c) = (
typename MV::non_const_value_type)(orig[5] + mod[5]);
void ibmModifyStencil(MV AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, Kokkos::View< double *, IMem > a_inhom, Kokkos::View< double *, IMem > rhs_scale, const OV &ibm, int numActive, typename OV::value_type u_bc_val, Kokkos::View< const double *, IMem > u_bc=Kokkos::View< const double *, IMem >())