8#include <similie/exterior/hodge_star.hpp>
9#include <similie/misc/macros.hpp>
10#include <similie/misc/specialization.hpp>
11#include <similie/tensor/character.hpp>
12#include <similie/tensor/tensor_impl.hpp>
14#include <Kokkos_StdAlgorithms.hpp>
17#include "cosimplex.hpp"
27struct CodifferentialType;
33 class LayoutStridedPolicy1,
34 class LayoutStridedPolicy2,
36struct CodifferentialType<
39 LayoutStridedPolicy2>>
41 using type = Cosimplex<
Simplex<K - 1, Tag...>, ElementType>;
46template <misc::Specialization<Cochain> CochainType>
51template <
class TagToRemoveFromCochain,
class CochainTag>
52struct CodifferentialIndex;
54template <tensor::TensorNatIndex TagToRemoveFromCochain, tensor::TensorNatIndex CochainTag>
55 requires(CochainTag::rank() == 1 && std::is_same_v<TagToRemoveFromCochain, CochainTag>)
56struct CodifferentialIndex<TagToRemoveFromCochain, CochainTag>
61template <tensor::TensorNatIndex TagToRemoveFromCochain, tensor::TensorNatIndex Tag>
62struct CodifferentialIndex<
63 TagToRemoveFromCochain,
64 tensor::TensorAntisymmetricIndex<TagToRemoveFromCochain, Tag>>
70 requires(
sizeof...(Tag) > 1)
71struct CodifferentialIndex<
72 TagToRemoveFromCochain,
80template <
class TagToRemoveFromCochain,
class CochainTag>
82 typename detail::CodifferentialIndex<TagToRemoveFromCochain, CochainTag>::type;
90struct CodifferentialTensorType;
99struct CodifferentialTensorType<
100 TagToRemoveFromCochain,
102 tensor::Tensor<ElementType, ddc::DiscreteDomain<DDim...>, SupportType, MemorySpace>>
104 static_assert(ddc::type_seq_contains_v<
105 ddc::detail::TypeSeq<CochainIndex>,
106 ddc::detail::TypeSeq<DDim...>>);
109 ddc::replace_dim_of_t<
110 ddc::DiscreteDomain<DDim...>,
124 CodifferentialTensorType<TagToRemoveFromCochain, CochainTag, TensorType>::type;
128template <std::
size_t I,
class T>
133template <
class Ids,
class T>
134struct CodifferentialDummyIndexSeq_;
136template <std::size_t... Id,
class T>
137struct CodifferentialDummyIndexSeq_<std::index_sequence<Id...>, T>
139 using type = ddc::detail::TypeSeq<tensor::Covariant<CodifferentialDummyIndex<Id, T>>...>;
142template <std::
size_t EndId,
class T>
143struct CodifferentialDummyIndexSeq;
145template <std::
size_t EndId,
class T>
147struct CodifferentialDummyIndexSeq<EndId, T>
149 using type = ddc::detail::TypeSeq<>;
152template <std::
size_t EndId,
class T>
154struct CodifferentialDummyIndexSeq<EndId, T>
156 using type =
typename CodifferentialDummyIndexSeq_<std::make_index_sequence<EndId>, T>::type;
169 ExecSpace
const& exec_space,
171 codifferential_tensor,
173 MetricType inv_metric)
177 using NuLowSeq =
typename detail::CodifferentialDummyIndexSeq<
178 TagToRemoveFromCochain::size() - CochainTag::rank(),
179 TagToRemoveFromCochain>::type;
180 using RhoLowSeq = ddc::type_seq_merge_t<ddc::detail::TypeSeq<TagToRemoveFromCochain>, NuLowSeq>;
182 using SigmaLowSeq = ddc::type_seq_remove_t<
184 ddc::detail::TypeSeq<TagToRemoveFromCochain>>;
191 ddc::cartesian_prod_t<typename MetricType::non_indices_domain_t, HodgeStarDomain>
192 hodge_star_dom(inv_metric.non_indices_domain(), hodge_star_accessor.domain());
193 ddc::Chunk hodge_star_alloc(
195 ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
201 NuLowSeq>(exec_space, hodge_star, inv_metric);
206 dual_tensor_accessor;
207 ddc::cartesian_prod_t<
208 typename TensorType::non_indices_domain_t,
211 dual_tensor_dom(tensor.non_indices_domain(), dual_tensor_accessor.domain());
212 ddc::Chunk dual_tensor_alloc(
214 ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
217 SIMILIE_DEBUG_LOG(
"similie_compute_dual_tensor");
218 ddc::parallel_for_each(
219 "similie_compute_dual_tensor",
221 dual_tensor.non_indices_domain(),
222 KOKKOS_LAMBDA(
typename TensorType::non_indices_domain_t::discrete_element_type elem) {
229 dual_codifferential_accessor;
230 ddc::cartesian_prod_t<
231 typename TensorType::non_indices_domain_t,
234 dual_codifferential_dom(
235 tensor.non_indices_domain(),
236 dual_codifferential_accessor.domain());
237 ddc::Chunk dual_codifferential_alloc(
238 dual_codifferential_dom,
239 ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
242 TagToRemoveFromCochain,
245 NuLowSeq>>(exec_space, dual_codifferential, dual_tensor);
249 hodge_star_accessor2;
250 ddc::cartesian_prod_t<typename MetricType::non_indices_domain_t, HodgeStarDomain2>
251 hodge_star_dom2(inv_metric.non_indices_domain(), hodge_star_accessor2.domain());
252 ddc::Chunk hodge_star_alloc2(
254 ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
260 SigmaLowSeq>(exec_space, hodge_star2, inv_metric);
263 SIMILIE_DEBUG_LOG(
"similie_compute_codifferential");
264 ddc::parallel_for_each(
265 "similie_compute_codifferential",
267 codifferential_tensor.non_indices_domain(),
268 KOKKOS_LAMBDA(
typename TensorType::non_indices_domain_t::discrete_element_type elem) {
270 codifferential_tensor[elem],
271 dual_codifferential[elem],
274 (TagToRemoveFromCochain::size() * (CochainTag::rank() + 1) + 1) % 2 == 1) {
275 codifferential_tensor[elem] *= -1;
279 return codifferential_tensor;
HodgeStarType fill_hodge_star(ExecSpace const &exec_space, HodgeStarType hodge_star, MetricDeterminantType metric_determinant, MetricProdType metric_prod)
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... >
typename detail:: CodifferentialTensorType< TagToRemoveFromCochain, CochainTag, TensorType >::type codifferential_tensor_t
Chain(Head, Tail...) -> Chain< typename Head::value_type, typename Head::array_layout, typename Head::memory_space >
ddc::detail::convert_type_seq_to_discrete_domain_t< ddc::type_seq_merge_t< ddc::detail::TypeSeq< misc::convert_type_seq_to_t< tensor::TensorFullIndex, Indices1 > >, std::conditional_t<(ddc::type_seq_size_v< Indices2 >==0), ddc::detail::TypeSeq<>, ddc::detail::TypeSeq< misc::convert_type_seq_to_t< tensor::TensorAntisymmetricIndex, Indices2 > > > > > hodge_star_domain_t
coboundary_tensor_t< TagToAddToCochain, CochainTag, TensorType > deriv(ExecSpace const &exec_space, coboundary_tensor_t< TagToAddToCochain, CochainTag, TensorType > coboundary_tensor, TensorType tensor)
typename detail::CodifferentialIndex< TagToRemoveFromCochain, CochainTag >::type codifferential_index_t
codifferential_tensor_t< TagToRemoveFromCochain, CochainTag, TensorType > codifferential(ExecSpace const &exec_space, codifferential_tensor_t< TagToRemoveFromCochain, CochainTag, TensorType > codifferential_tensor, TensorType tensor, MetricType inv_metric)
typename detail::CodifferentialType< CochainType >::type codifferential_t
typename detail::ConvertTypeSeqTo< T, Seq >::type convert_type_seq_to_t
Tensor(ddc::Chunk< ElementType, SupportType, Allocator >) -> Tensor< ElementType, SupportType, Kokkos::layout_right, typename Allocator::memory_space >
detail::Upper< T >::type upper_t
Tensor< ElementType, ddc::DiscreteDomain< ProdDDim... >, LayoutStridedPolicy, MemorySpace > tensor_prod(Tensor< ElementType, ddc::DiscreteDomain< ProdDDim... >, LayoutStridedPolicy, MemorySpace > prod_tensor, Tensor< ElementType, ddc::DiscreteDomain< DDim1... >, LayoutStridedPolicy, MemorySpace > tensor1, Tensor< ElementType, ddc::DiscreteDomain< DDim2... >, LayoutStridedPolicy, MemorySpace > tensor2)
detail::Uncharacterize< Index >::type uncharacterize_t
detail::Lower< T >::type lower_t
bool constexpr is_covariant_v
detail::TensorAccessorForDomain< Dom >::type tensor_accessor_for_domain_t
The top-level namespace of SimiLie.