8#include <similie/misc/are_all_same.hpp>
9#include <similie/misc/specialization.hpp>
10#include <similie/tensor/antisymmetric_tensor.hpp>
13#include "cosimplex.hpp"
14#include "local_chain.hpp"
20template <
typename CochainType>
26 class ElementType = double,
27 class LayoutStridedPolicy = Kokkos::LayoutRight>
28 requires(misc::Specialization<ChainType, Chain> || misc::Specialization<ChainType, LocalChain>)
39 using values_type = Kokkos::View<ElementType*, LayoutStridedPolicy, memory_space>;
48 KOKKOS_DEFAULTED_FUNCTION
constexpr Cochain() =
default;
55 requires(
sizeof...(T) >= 1 && (std::is_convertible_v<T, double> && ...))
56 KOKKOS_FUNCTION constexpr explicit
Cochain(
60 : m_chain(std::move(chain))
61 , m_values(std::move(allocation))
64 ((m_values(i++) = value), ...);
65 assert(
sizeof...(T) == chain.size()
66 &&
"cochain constructor must get as much values as the chain contains simplices");
69 KOKKOS_FUNCTION
constexpr explicit Cochain(
72 : m_chain(std::move(chain))
73 , m_values(std::move(values))
75 assert(values.size() == chain.size()
76 &&
"cochain constructor must get as much values as the chain contains simplices");
79 template <tensor::TensorIndex Index>
82 KOKKOS_FUNCTION
constexpr explicit Cochain(
86 ddc::DiscreteDomain<Index>,
87 ddc::detail::kokkos_to_mdspan_layout_t<LayoutStridedPolicy>,
89 : m_chain(std::move(chain))
90 , m_values(tensor.allocation_kokkos_view())
92 assert(m_values.size() == chain.size()
93 &&
"cochain constructor must get as much values as the chain contains simplices");
96 KOKKOS_DEFAULTED_FUNCTION
~Cochain() =
default;
102 static KOKKOS_FUNCTION
constexpr bool is_local() noexcept
104 return chain_type::is_local();
107 static KOKKOS_FUNCTION
constexpr std::size_t
dimension() noexcept
109 return chain_type::dimension();
112 KOKKOS_FUNCTION std::size_t
size() noexcept
114 return m_chain.size();
117 KOKKOS_FUNCTION std::size_t
size() const noexcept
119 return m_chain.size();
124 return m_chain.allocation_size();
129 return m_chain.allocation_size();
146 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
151 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
154 KOKKOS_FUNCTION
auto end()
156 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
159 KOKKOS_FUNCTION
auto end()
const
161 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
166 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
169 KOKKOS_FUNCTION
auto cend()
const
171 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
181 std::size_t i)
const noexcept
190 for (
auto i = begin(); i < end(); ++i) {
192 out += ((*i).negative() ? -1 : 1) * (*i).value();
194 out += (m_chain.negative() ? -1 : 1) * (*i).value();
203 for (
auto i = begin(); i < end(); ++i) {
205 out += ((*i).negative() ? -1 : 1) * (*i).value();
207 out += (m_chain.negative() ? -1 : 1) * (*i).value();
214template <
class ChainType, misc::Specialization<tensor::Tensor> TensorType>
218 typename TensorType::value_type,
219 ddc::detail::mdspan_to_kokkos_layout_t<typename TensorType::layout_type>>;
221template <
typename CochainType>
235 = Kokkos::Experimental::Impl::RandomAccessIterator<typename CochainType::values_type>;
248 , m_values(values_it)
254 if constexpr (!CochainType::chain_type::is_local()) {
258 Simplex(std::integral_constant<std::size_t, CochainType::dimension()> {},
314 friend KOKKOS_FUNCTION
constexpr bool operator==(
318 return xx.m_chain == yy.m_chain && xx.m_values == yy.m_values;
321 friend KOKKOS_FUNCTION
constexpr bool operator<(
325 return xx.m_chain < yy.m_chain && xx.m_values < yy.m_values;
328 friend KOKKOS_FUNCTION
constexpr bool operator>(
332 return xx.m_chain > yy.m_chain && xx.m_values > yy.m_values;
335 friend KOKKOS_FUNCTION
constexpr bool operator<=(
342 friend KOKKOS_FUNCTION
constexpr bool operator>=(
368 return xx.m_chain - yy.m_chain;
372template <misc::Specialization<Cochain> CochainType>
373std::ostream&
operator<<(std::ostream& out, CochainType
const& cochain)
376 for (
auto i = cochain.begin(); i < cochain.end(); ++i) {
377 if constexpr (!cochain.is_local()) {
378 out <<
" " << (*i).simplex() <<
" : " << (*i).value() <<
"\n";
380 out <<
" -> " << (*i).discrete_vector() <<
" : " << (*i).value() <<
"\n";
friend KOKKOS_FUNCTION constexpr bool operator<(CochainIterator const &xx, CochainIterator const &yy)
typename CochainType::cosimplex_type cosimplex_type
typename CochainType::cosimplex_type value_type
KOKKOS_FUNCTION constexpr CochainIterator & operator-=(difference_type n)
friend KOKKOS_FUNCTION constexpr bool operator<=(CochainIterator const &xx, CochainIterator const &yy)
KOKKOS_FUNCTION constexpr CochainIterator & operator++()
KOKKOS_FUNCTION constexpr CochainIterator & operator--()
friend KOKKOS_FUNCTION constexpr bool operator>=(CochainIterator const &xx, CochainIterator const &yy)
KOKKOS_FUNCTION constexpr CochainIterator & operator+=(difference_type n)
std::random_access_iterator_tag iterator_category
KOKKOS_DEFAULTED_FUNCTION CochainIterator()=default
typename CochainType::chain_type::iterator_type chain_iterator
friend KOKKOS_FUNCTION constexpr CochainIterator operator-(CochainIterator i, difference_type n)
Kokkos::Experimental::Impl::RandomAccessIterator< typename CochainType::values_type > values_iterator
friend KOKKOS_FUNCTION constexpr bool operator>(CochainIterator const &xx, CochainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator==(CochainIterator const &xx, CochainIterator const &yy)
std::ptrdiff_t difference_type
friend KOKKOS_FUNCTION constexpr CochainIterator operator+(CochainIterator i, difference_type n)
KOKKOS_FUNCTION constexpr value_type operator*() const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr Cochain()=default
Kokkos::View< ElementType *, LayoutStridedPolicy, memory_space > values_type
static KOKKOS_FUNCTION constexpr bool is_local() noexcept
KOKKOS_FUNCTION std::size_t allocation_size() const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr Cochain(Cochain const &)=default
KOKKOS_FUNCTION auto end()
KOKKOS_FUNCTION auto begin()
static KOKKOS_FUNCTION constexpr std::size_t dimension() noexcept
KOKKOS_DEFAULTED_FUNCTION Cochain & operator=(Cochain &&other)=default
KOKKOS_FUNCTION chain_type const & chain() const noexcept
KOKKOS_DEFAULTED_FUNCTION Cochain & operator=(Cochain const &other)=default
KOKKOS_FUNCTION auto end() const
ChainType::discrete_element_type discrete_element_type
KOKKOS_FUNCTION Cosimplex< simplex_type, element_type > & operator[](std::size_t i) noexcept
KOKKOS_FUNCTION chain_type const & values() const noexcept
KOKKOS_FUNCTION constexpr Cochain(chain_type const &chain, tensor::Tensor< element_type, ddc::DiscreteDomain< Index >, ddc::detail::kokkos_to_mdspan_layout_t< LayoutStridedPolicy >, memory_space > tensor) noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr Cochain(Cochain &&)=default
typename ChainType::simplex_type simplex_type
KOKKOS_FUNCTION std::size_t size() noexcept
KOKKOS_FUNCTION element_type integrate() noexcept
KOKKOS_FUNCTION std::size_t size() const noexcept
ChainType::discrete_vector_type discrete_vector_type
KOKKOS_FUNCTION element_type const integrate() const noexcept
KOKKOS_FUNCTION Cosimplex< simplex_type, element_type > const & operator[](std::size_t i) const noexcept
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION auto begin() const
KOKKOS_DEFAULTED_FUNCTION ~Cochain()=default
KOKKOS_FUNCTION std::size_t allocation_size() noexcept
KOKKOS_FUNCTION constexpr Cochain(chain_type const &chain, values_type const &values) noexcept
KOKKOS_FUNCTION auto cbegin() const
typename ChainType::memory_space memory_space
std::ostream & operator<<(std::ostream &out, ChainType const &chain)
Cochain(ChainType, TensorType) -> Cochain< ChainType, typename TensorType::value_type, ddc::detail::mdspan_to_kokkos_layout_t< typename TensorType::layout_type > >
Simplex(ddc::DiscreteElement< Tag... >, ddc::DiscreteVector< T... >) -> Simplex< sizeof...(T), Tag... >
constexpr T filled_struct(ElementType const n=0)
Tensor(ddc::Chunk< ElementType, SupportType, Allocator >) -> Tensor< ElementType, SupportType, Kokkos::layout_right, typename Allocator::memory_space >
The top-level namespace of SimiLie.