SimiLie
Loading...
Searching...
No Matches
clamp_to_domain.hpp
1// SPDX-FileCopyrightText: 2026 Baptiste Legouix
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <ddc/ddc.hpp>
7
8#include "select_from_type_seq.hpp"
9#include "type_seq_ext.hpp"
10
11namespace sil {
12
13namespace misc {
14
15namespace detail {
16
17template <class CommonSeq>
18struct ClampToDomain;
19
20template <class... CommonDDim>
21struct ClampToDomain<ddc::detail::TypeSeq<CommonDDim...>>
22{
23 template <class BatchDomain, class Elem>
24 KOKKOS_FUNCTION static Elem run(BatchDomain const& batch_domain, Elem elem)
25 {
26 ddc::DiscreteDomain<CommonDDim...> const common_domain
27 = select_from_type_seq<ddc::detail::TypeSeq<CommonDDim...>>(batch_domain);
28 ddc::DiscreteElement<CommonDDim...> const front = common_domain.front();
29 ddc::DiscreteElement<CommonDDim...> const back = common_domain.back();
30
31 ((elem.template uid<CommonDDim>() = std::
32 min(std::max(elem.template uid<CommonDDim>(), front.template uid<CommonDDim>()),
33 back.template uid<CommonDDim>())),
34 ...);
35 return elem;
36 }
37};
38
39} // namespace detail
40
41template <class BatchDomain, class Elem>
42KOKKOS_FUNCTION Elem clamp_to_domain(BatchDomain const& batch_domain, Elem const& elem)
43{
44 using CommonSeq
45 = misc::type_seq_intersect_t<ddc::to_type_seq_t<Elem>, ddc::to_type_seq_t<BatchDomain>>;
46 return detail::ClampToDomain<CommonSeq>::run(batch_domain, elem);
47}
48
49} // namespace misc
50
51} // namespace sil
KOKKOS_FUNCTION Elem clamp_to_domain(BatchDomain const &batch_domain, Elem const &elem)
ddc::type_seq_remove_t< TagSeqA, ddc::type_seq_remove_t< TagSeqA, TagSeqB > > type_seq_intersect_t
KOKKOS_FUNCTION auto select_from_type_seq(T t)
The top-level namespace of SimiLie.
Definition csr.hpp:15