Skip to content

Commit

Permalink
Expose ExtrapolationRules from SplineEvaluator (#348)
Browse files Browse the repository at this point in the history
* Expose extrapolation rules in 2D

* Expose extrapolation rules in 1D. Homogenise names

* Rename missed extrapolation rule

* Format

* Avoid name conflict

---------

Co-authored-by: Emily Bourne <[email protected]>
Co-authored-by: Thomas Padioleau <[email protected]>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent cc033e5 commit 5e400d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
19 changes: 16 additions & 3 deletions include/ddc/kernels/splines/spline_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SplineEvaluator

using bsplines_type = BSplinesType;

using left_extrapolation_rule_type = LeftExtrapolationRule;
using right_extrapolation_rule_type = RightExtrapolationRule;

using interpolation_mesh_type = InterpolationMesh;

using interpolation_domain_type = ddc::DiscreteDomain<interpolation_mesh_type>;
Expand Down Expand Up @@ -71,7 +74,7 @@ class SplineEvaluator

LeftExtrapolationRule m_left_extrap_rule;

RightExtrapolationRule m_right_bc;
RightExtrapolationRule m_right_extrap_rule;

public:
static_assert(
Expand Down Expand Up @@ -112,7 +115,7 @@ class SplineEvaluator
RightExtrapolationRule const& right_extrap_rule)
: m_spline_domain(spline_domain)
, m_left_extrap_rule(left_extrap_rule)
, m_right_bc(right_extrap_rule)
, m_right_extrap_rule(right_extrap_rule)
{
}

Expand Down Expand Up @@ -143,6 +146,16 @@ class SplineEvaluator
return ddc::remove_dims_of(spline_domain(), bsplines_domain());
}

left_extrapolation_rule_type left_extrapolation_rule() const
{
return m_left_extrap_rule;
}

right_extrapolation_rule_type right_extrapolation_rule() const
{
return m_right_extrap_rule;
}

template <class Layout, class... CoordsDims>
KOKKOS_FUNCTION double operator()(
ddc::Coordinate<CoordsDims...> const& coord_eval,
Expand Down Expand Up @@ -263,7 +276,7 @@ class SplineEvaluator
return m_left_extrap_rule(coord_eval_interpolation, spline_coef);
}
if (coord_eval_interpolation > ddc::discrete_space<bsplines_type>().rmax()) {
return m_right_bc(coord_eval_interpolation, spline_coef);
return m_right_extrap_rule(coord_eval_interpolation, spline_coef);
}
}
return eval_no_bc<eval_type>(coord_eval_interpolation, spline_coef);
Expand Down
49 changes: 37 additions & 12 deletions include/ddc/kernels/splines/spline_evaluator_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class SplineEvaluator2D
using bsplines_type1 = BSplinesType1;
using bsplines_type2 = BSplinesType2;

using left_extrapolation_rule_1_type = LeftExtrapolationRule1;
using right_extrapolation_rule_1_type = RightExtrapolationRule1;
using left_extrapolation_rule_2_type = LeftExtrapolationRule2;
using right_extrapolation_rule_2_type = RightExtrapolationRule2;

using interpolation_domain_type1 = ddc::DiscreteDomain<interpolation_mesh_type1>;
using interpolation_domain_type2 = ddc::DiscreteDomain<interpolation_mesh_type2>;
using interpolation_domain_type
Expand Down Expand Up @@ -80,13 +85,13 @@ class SplineEvaluator2D
private:
spline_domain_type m_spline_domain;

LeftExtrapolationRule1 m_left1_bc;
LeftExtrapolationRule1 m_left_extrap_rule_1;

RightExtrapolationRule1 m_right1_bc;
RightExtrapolationRule1 m_right_extrap_rule_1;

LeftExtrapolationRule2 m_left2_bc;
LeftExtrapolationRule2 m_left_extrap_rule_2;

RightExtrapolationRule2 m_right2_bc;
RightExtrapolationRule2 m_right_extrap_rule_2;

public:
static_assert(
Expand Down Expand Up @@ -162,10 +167,10 @@ class SplineEvaluator2D
LeftExtrapolationRule2 const& left_extrap_rule2,
RightExtrapolationRule2 const& right_extrap_rule2)
: m_spline_domain(spline_domain)
, m_left1_bc(left_extrap_rule1)
, m_right1_bc(right_extrap_rule1)
, m_left2_bc(left_extrap_rule2)
, m_right2_bc(right_extrap_rule2)
, m_left_extrap_rule_1(left_extrap_rule1)
, m_right_extrap_rule_1(right_extrap_rule1)
, m_left_extrap_rule_2(left_extrap_rule2)
, m_right_extrap_rule_2(right_extrap_rule2)
{
}

Expand Down Expand Up @@ -198,6 +203,26 @@ class SplineEvaluator2D
return ddc::remove_dims_of(spline_domain(), bsplines_domain());
}

left_extrapolation_rule_1_type left_extrapolation_rule_dim_1() const
{
return m_left_extrap_rule_1;
}

right_extrapolation_rule_1_type right_extrapolation_rule_dim_1() const
{
return m_right_extrap_rule_1;
}

left_extrapolation_rule_2_type left_extrapolation_rule_dim_2() const
{
return m_left_extrap_rule_2;
}

right_extrapolation_rule_2_type right_extrapolation_rule_dim_2() const
{
return m_right_extrap_rule_2;
}

template <class Layout, class... CoordsDims>
KOKKOS_FUNCTION double operator()(
ddc::Coordinate<CoordsDims...> const& coord_eval,
Expand Down Expand Up @@ -509,10 +534,10 @@ class SplineEvaluator2D
}
} else {
if (coord_eval_interpolation1 < ddc::discrete_space<bsplines_type1>().rmin()) {
return m_left1_bc(coord_eval, spline_coef);
return m_left_extrap_rule_1(coord_eval, spline_coef);
}
if (coord_eval_interpolation1 > ddc::discrete_space<bsplines_type1>().rmax()) {
return m_right1_bc(coord_eval, spline_coef);
return m_right_extrap_rule_1(coord_eval, spline_coef);
}
}
if constexpr (bsplines_type2::is_periodic()) {
Expand All @@ -527,10 +552,10 @@ class SplineEvaluator2D
}
} else {
if (coord_eval_interpolation2 < ddc::discrete_space<bsplines_type2>().rmin()) {
return m_left2_bc(coord_eval, spline_coef);
return m_left_extrap_rule_2(coord_eval, spline_coef);
}
if (coord_eval_interpolation2 > ddc::discrete_space<bsplines_type2>().rmax()) {
return m_right2_bc(coord_eval, spline_coef);
return m_right_extrap_rule_2(coord_eval, spline_coef);
}
}
return eval_no_bc<eval_type, eval_type>(
Expand Down

0 comments on commit 5e400d4

Please sign in to comment.