Skip to content

Commit

Permalink
Resolve "Add tests in the mask initialiation"
Browse files Browse the repository at this point in the history
Closes #415

See merge request gysela-developpers/gyselalibxx!807

--------------------------------------------
  • Loading branch information
Matthieu PROTAIS committed Dec 12, 2024
1 parent 97c3ff3 commit 6efbf97
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions src/geometryXVx/rhs/mask_tanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,50 @@ host_t<DFieldMemX> mask_tanh(
MaskType const type,
bool const normalized)
{
if (stiffness <= 0) {
throw std::runtime_error("Invalid stiffness, cannot be negative");
}
if (extent < 0 || extent > 0.5) {
throw std::runtime_error("Invalid extent, cannot be more than 0.5");
}
host_t<DFieldMemX> mask(gridx);
if (extent == 0) {
ddc::parallel_fill(mask, 0.);
} else {
CoordX const x_min(ddc::coordinate(gridx.front()));
double const Lx = ddcHelper::total_interval_length(gridx);
CoordX const x_left(x_min + Lx * extent);
CoordX const x_right(x_min + Lx - Lx * extent);

IdxStepX const Nx(gridx.size());
CoordX const x_min(ddc::coordinate(gridx.front()));
double const Lx = ddcHelper::total_interval_length(gridx);
CoordX const x_left(x_min + Lx * extent);
CoordX const x_right(x_min + Lx - Lx * extent);
switch (type) {
case MaskType::Normal:
ddc::for_each(gridx, [&](IdxX const ix) {
CoordX const coordx = ddc::coordinate(ix);
mask(ix) = 0.5
* (std::tanh((coordx - x_left) / stiffness)
- std::tanh((coordx - x_right) / stiffness));
});
break;

switch (type) {
case MaskType::Normal:
ddc::for_each(gridx, [&](IdxX const ix) {
CoordX const coordx = ddc::coordinate(ix);
mask(ix) = 0.5
* (std::tanh((coordx - x_left) / stiffness)
- std::tanh((coordx - x_right) / stiffness));
});
break;

case MaskType::Inverted:
ddc::for_each(gridx, [&](IdxX const ix) {
CoordX const coordx = ddc::coordinate(ix);
mask(ix) = 1
- 0.5
* (std::tanh((coordx - x_left) / stiffness)
- std::tanh((coordx - x_right) / stiffness));
});
break;
}
case MaskType::Inverted:
ddc::for_each(gridx, [&](IdxX const ix) {
CoordX const coordx = ddc::coordinate(ix);
mask(ix) = 1
- 0.5
* (std::tanh((coordx - x_left) / stiffness)
- std::tanh((coordx - x_right) / stiffness));
});
break;
}

if (normalized) {
host_t<DFieldMemX> const quadrature_coeffs
= trapezoid_quadrature_coefficients<Kokkos::DefaultHostExecutionSpace>(gridx);
host_t<Quadrature<IdxRangeX>> const integrate_x(get_const_field(quadrature_coeffs));
double const coeff_norm
= integrate_x(Kokkos::DefaultHostExecutionSpace(), get_const_field(mask));
ddc::for_each(gridx, [&](IdxX const ix) { mask(ix) = mask(ix) / coeff_norm; });
if (normalized) {
host_t<DFieldMemX> const quadrature_coeffs
= trapezoid_quadrature_coefficients<Kokkos::DefaultHostExecutionSpace>(gridx);
host_t<Quadrature<IdxRangeX>> const integrate_x(get_const_field(quadrature_coeffs));
double const coeff_norm
= integrate_x(Kokkos::DefaultHostExecutionSpace(), get_const_field(mask));
ddc::for_each(gridx, [&](IdxX const ix) { mask(ix) = mask(ix) / coeff_norm; });
}
}

return mask;
Expand Down

0 comments on commit 6efbf97

Please sign in to comment.