8#include <similie/misc/are_all_same.hpp>
9#include <similie/misc/specialization.hpp>
10#include <similie/tensor/tensor_indices/antisymmetric_tensor.hpp>
13#include "cosimplex.hpp"
14#include "local_chain.hpp"
20template <
typename CochainType>
26 class ElementType = double,
27 class LayoutStridedPolicy = Kokkos::LayoutRight>
29 misc::Specialization<ChainType, Chain> || misc::Specialization<ChainType, LocalChain>
30 || misc::Specialization<ChainType, tensor::Tensor>)
41 using values_type = Kokkos::View<ElementType*, LayoutStridedPolicy, memory_space>;
50 KOKKOS_DEFAULTED_FUNCTION
constexpr Cochain() =
default;
57 requires(
sizeof...(T) >= 1 && (std::is_convertible_v<T, double> && ...))
58 KOKKOS_FUNCTION constexpr explicit
Cochain(
62 : m_chain(std::move(chain))
63 , m_values(std::move(allocation))
66 ((m_values(i++) = value), ...);
67 assert(
sizeof...(T) == chain.size()
68 &&
"cochain constructor must get as much values as the chain contains simplices");
71 KOKKOS_FUNCTION
constexpr explicit Cochain(
74 : m_chain(std::move(chain))
75 , m_values(std::move(values))
77 assert(values.size() == chain.size()
78 &&
"cochain constructor must get as much values as the chain contains simplices");
81 template <tensor::TensorIndex Index>
84 KOKKOS_FUNCTION
constexpr explicit Cochain(
88 ddc::DiscreteDomain<Index>,
89 ddc::detail::kokkos_to_mdspan_layout_t<LayoutStridedPolicy>,
91 : m_chain(std::move(chain))
92 , m_values(tensor.allocation_kokkos_view())
94 assert(m_values.size() == chain.size()
95 &&
"cochain constructor must get as much values as the chain contains simplices");
98 KOKKOS_DEFAULTED_FUNCTION
~Cochain() =
default;
106 return chain_type::is_local();
111 return chain_type::dimension();
114 KOKKOS_FUNCTION std::size_t
size() noexcept
116 return m_chain.size();
119 KOKKOS_FUNCTION std::size_t
size() const noexcept
121 return m_chain.size();
126 return m_chain.allocation_size();
131 return m_chain.allocation_size();
148 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
153 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
156 KOKKOS_FUNCTION
auto end()
158 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
161 KOKKOS_FUNCTION
auto end()
const
163 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
168 return iterator(m_chain.begin(), Kokkos::Experimental::begin(m_values));
171 KOKKOS_FUNCTION
auto cend()
const
173 return iterator(m_chain.end(), Kokkos::Experimental::end(m_values));
183 std::size_t i)
const noexcept
192 for (
auto i = begin(); i < end(); ++i) {
194 out += (i->negative() ? -1 : 1) * i->value();
196 out += (i->negative() ? -1 : 1) * i->value();
205 for (
auto i = begin(); i < end(); ++i) {
207 out += (i->negative() ? -1 : 1) * i->value();
209 out += (i->negative() ? -1 : 1) * i->value();
217template <
class T,
class Domain,
class Layout,
class Memory,
class ElementType,
class ChainLayout>
218class Cochain<tensor::
Tensor<T, Domain, Layout, Memory>, ElementType, ChainLayout>
225 KOKKOS_DEFAULTED_FUNCTION
Cochain() =
default;
238 coefficients() += other.coefficients();
243 coefficients() *= scalar;
247 template <
class Element>
248 KOKKOS_FUNCTION
auto operator[](Element
const& element)
const
250 return ::sil::exterior::Cochain(Tensor::operator[](element));
254template <misc::Specialization<tensor::Tensor> Tensor>
260template <
class ChainType, misc::Specialization<tensor::Tensor> TensorType>
263 typename TensorType::value_type,
264 ddc::detail::mdspan_to_kokkos_layout_t<typename TensorType::layout_type>>;
266template <
typename CochainType>
280 = Kokkos::Experimental::Impl::RandomAccessIterator<typename CochainType::values_type>;
293 , m_values(values_it)
349 friend KOKKOS_FUNCTION
constexpr bool operator==(
353 return xx.m_chain == yy.m_chain && xx.m_values == yy.m_values;
356 friend KOKKOS_FUNCTION
constexpr bool operator<(
360 return xx.m_chain < yy.m_chain && xx.m_values < yy.m_values;
363 friend KOKKOS_FUNCTION
constexpr bool operator>(
367 return xx.m_chain > yy.m_chain && xx.m_values > yy.m_values;
370 friend KOKKOS_FUNCTION
constexpr bool operator<=(
377 friend KOKKOS_FUNCTION
constexpr bool operator>=(
403 return xx.m_chain - yy.m_chain;
407template <misc::Specialization<Cochain> CochainType>
411 for (
auto i = cochain.begin(); i < cochain.end(); ++i) {
412 if constexpr (!cochain.is_local()) {
413 out <<
" " << i->simplex() <<
" : " << i->value() <<
"\n";
415 out <<
" -> " << i->discrete_vector() <<
" : " << i->value() <<
"\n";
KOKKOS_FUNCTION constexpr reference operator*() const noexcept
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)
KOKKOS_FUNCTION constexpr pointer operator->() const noexcept
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 auto operator[](Element const &element) const
KOKKOS_FUNCTION Cochain & operator*=(T scalar)
KOKKOS_FUNCTION Cochain(Tensor const &tensor)
KOKKOS_DEFAULTED_FUNCTION Cochain()=default
KOKKOS_FUNCTION Cochain & operator+=(Cochain const &other)
KOKKOS_FUNCTION Tensor const & coefficients() const
KOKKOS_FUNCTION Tensor & coefficients()
KOKKOS_DEFAULTED_FUNCTION constexpr Cochain()=default
Kokkos::View< ElementType *, LayoutStridedPolicy, memory_space > values_type
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()
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_DEFAULTED_FUNCTION constexpr Cochain(Cochain &&)=default
typename ChainType::simplex_type simplex_type
KOKKOS_FUNCTION std::size_t size() noexcept
static constexpr bool is_local() noexcept
KOKKOS_FUNCTION element_type integrate() noexcept
static constexpr std::size_t dimension() 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
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 > const &tensor) noexcept
typename ChainType::memory_space memory_space
std::ostream & operator<<(std::ostream &out, ChainType const &chain)
Cochain(Tensor const &) -> Cochain< Tensor >
The top-level namespace of SimiLie.