11#include <similie/exterior/coboundary/coboundary.hpp>
12#include <similie/exterior/cochain_indices.hpp>
13#include <similie/exterior/concepts.hpp>
14#include <similie/exterior/reduction_and_reconstruction/reduction_and_reconstruction.hpp>
15#include <similie/exterior/stencil.hpp>
16#include <similie/exterior/volume.hpp>
17#include <similie/misc/factorial.hpp>
18#include <similie/misc/macros.hpp>
19#include <similie/misc/small_matrix.hpp>
20#include <similie/misc/specialization.hpp>
21#include <similie/misc/type_seq_conversion.hpp>
22#include <similie/tensor/metric.hpp>
23#include <similie/tensor/tensor_indices/antisymmetric_tensor.hpp>
24#include <similie/tensor/tensor_indices/character.hpp>
25#include <similie/tensor/tensor_indices/full_tensor.hpp>
31template <misc::Specialization<ddc::TypeSeq> Indices1, misc::Specialization<ddc::TypeSeq> Indices2>
33 = ddc::detail::convert_type_seq_to_discrete_domain_t<ddc::type_seq_merge_t<
34 ddc::TypeSeq<misc::convert_type_seq_to_t<tensor::TensorFullIndex, Indices1>>,
36 (ddc::type_seq_size_v<Indices2> == 0),
57 template <
class,
class,
class, CellComplex>
class ReconstructionPolicy =
Reconstruction,
58 template <
class,
class,
class, CellComplex>
class ReductionPolicy =
Reduction,
66template <
class MetricType,
class PositionType,
class BatchElem>
67KOKKOS_FUNCTION
auto one_form_pairing(
68 MetricType
const& metric,
69 PositionType
const& position,
72 using PositionIndex = ddc::
73 type_seq_element_t<0, ddc::to_type_seq_t<typename PositionType::indices_domain_t>>;
75 = ddc::type_seq_element_t<0, ddc::to_type_seq_t<typename MetricType::indices_domain_t>>;
76 constexpr std::size_t N = PositionIndex::size();
77 std::array<double, N * N> jacobian {}, gram {}, inverse {}, workspace {};
78 for (std::size_t axis = 0; axis < N; ++axis) {
79 std::array<double, N>
const edge = detail::edge_vector<PositionIndex>(position, elem, axis);
80 for (std::size_t physical = 0; physical < N; ++physical)
81 jacobian[physical * N + axis] = edge[physical];
83 for (std::size_t i = 0; i < N; ++i)
84 for (std::size_t j = 0; j < N; ++j)
85 for (std::size_t a = 0; a < N; ++a)
86 for (std::size_t b = 0; b < N; ++b)
87 gram[i * N + j] += jacobian[a * N + i] * jacobian[b * N + j]
88 * metric.get(metric.access_element(
102 typename MetricType::memory_space>(workspace.data(), N * N)))
104 double const orientation = detail::reduction_determinant<N>(jacobian);
105 double const volume = (orientation < 0.0 ? -1.0 : 1.0)
106 * Kokkos::sqrt(Kokkos::abs(detail::reduction_determinant<N>(gram)));
107 for (
double& coefficient : inverse)
108 coefficient *= volume;
114template <std::
size_t N, std::
size_t M>
115KOKKOS_FUNCTION
bool has_unique_ids(std::array<std::size_t, M>
const& ids)
117 if constexpr (M > 0) {
118 for (std::size_t i = 0; i < M; ++i) {
122 for (std::size_t j = i + 1; j < M; ++j) {
123 if (ids[i] == ids[j]) {
132template <std::
size_t N, std::
size_t M1, std::
size_t M2>
133KOKKOS_FUNCTION
int permutation_sign(
134 std::array<std::size_t, M1>
const& source_ids,
135 std::array<std::size_t, M2>
const& target_ids)
137 std::array<std::size_t, N> permutation {};
138 for (std::size_t i = 0; i < M1; ++i) {
139 permutation[i] = source_ids[i];
141 if constexpr (M2 > 0) {
142 for (std::size_t i = 0; i < M2; ++i) {
143 permutation[M1 + i] = target_ids[i];
148 for (std::size_t i = 0; i < N; ++i) {
149 for (std::size_t j = i + 1; j < N; ++j) {
150 odd = (permutation[i] > permutation[j]) != odd;
156template <std::
size_t N, std::
size_t M>
157KOKKOS_FUNCTION std::array<std::size_t, N - M> complement_ids(std::array<std::size_t, M>
const& ids)
159 std::array<std::size_t, N - M> complement {};
160 std::size_t complement_id = 0;
161 for (std::size_t i = 0; i < N; ++i) {
163 for (std::size_t
id : ids) {
164 found = found || (
id == i);
167 complement[complement_id++] = i;
173template <misc::Specialization<ddc::TypeSeq> Indices>
174struct HodgeStarTargetSize
176 static constexpr std::size_t value
177 = misc::convert_type_seq_to_t<tensor::TensorAntisymmetricIndex, Indices>::mem_size();
181struct HodgeStarTargetSize<
ddc::TypeSeq<>>
183 static constexpr std::size_t value = 1;
188 misc::Specialization<ddc::TypeSeq> Indices1,
189 misc::Specialization<ddc::TypeSeq> Indices2,
190 misc::Specialization<tensor::Tensor> HodgeStarType,
191 misc::Specialization<tensor::Tensor> MetricType,
193struct FillContinuousHodgeStarMem
195 HodgeStarType m_hodge_star;
199 template <
class MemElem>
200 KOKKOS_FUNCTION
void operator()(MemElem mem_elem)
const
202 m_hodge_star.mem(
typename HodgeStarType::discrete_element_type(m_elem, mem_elem))
206 m_hodge_star.accessor().canonical_natural_element(mem_elem));
221 misc::Specialization<ddc::TypeSeq> Indices1,
222 misc::Specialization<ddc::TypeSeq> Indices2,
233 typename MetricType::non_indices_domain_t,
234 typename MetricType::memory_space,
235 typename MetricType::memory_space::execution_space,
240 template <FormType HodgeTensorType, FormType FormTensorType>
242 HodgeTensorType
const& hodge_tensor,
243 FormTensorType
const& form_tensor,
244 MetricType
const& metric,
249 static constexpr std::size_t HODGE_STAR_SIZE
251 * detail::HodgeStarTargetSize<Indices2>::value;
252 std::array<double, HODGE_STAR_SIZE> hodge_star_alloc {};
256 Kokkos::layout_right,
257 typename HodgeTensorType::memory_space>
258 hodge_star_span(hodge_star_alloc.data(), hodge_star_accessor.domain());
260 ddc::device_for_each(hodge_star.domain(), [&](
auto it) {
261 hodge_star.mem(it) = value(metric, elem, hodge_star.canonical_natural_element(it));
264 tensor_prod(hodge_tensor.coefficients(), hodge_star, form_tensor.coefficients());
267 KOKKOS_FUNCTION
static detail::LocalOperatorStencil<
270 value(MetricType
const& metric, BatchElem element)
274 detail::LocalOperatorStencil<Source, Target> result;
275 auto unit = detail::make_stencil<typename MetricType::memory_space, Source>(
276 ddc::DiscreteElement<>());
277 auto output = detail::make_stencil<typename MetricType::memory_space, Target>(
278 ddc::DiscreteElement<>());
279 for (std::size_t source = 0; source < Source::mem_size(); ++source) {
280 unit.mem(ddc::DiscreteElement<Source>(source)) = 1.0;
286 for (std::size_t target = 0; target < Target::mem_size(); ++target)
287 result.weights[target * Source::mem_size() + source]
288 = output.mem(ddc::DiscreteElement<Target>(target));
289 unit.mem(ddc::DiscreteElement<Source>(source)) = 0.0;
294 KOKKOS_FUNCTION
static double value(MetricType
const& metric, BatchElem elem,
auto natural_elem)
296 constexpr std::size_t N = ddc::type_seq_size_v<Indices1> + ddc::type_seq_size_v<Indices2>;
297 constexpr std::size_t K = ddc::type_seq_size_v<Indices1>;
300 std::array
const source_ids = ddc::detail::array(SourceElem(natural_elem));
301 std::array
const target_ids = ddc::detail::array(TargetElem(natural_elem));
303 if (!detail::has_unique_ids<N>(source_ids) || !detail::has_unique_ids<N>(target_ids)) {
307 std::array<std::size_t, K>
const complement = detail::complement_ids<N>(target_ids);
308 using MetricIndex = ddc::
309 type_seq_element_t<0, ddc::to_type_seq_t<typename MetricType::indices_domain_t>>;
312 std::array<double, N * N> metric_alloc {};
313 std::array<double, N * N> determinant_metric_alloc {};
314 std::array<double, N * N> inverse_metric_alloc {};
315 std::array<double, N * N> workspace_alloc {};
316 std::array<double, K * K> submatrix_alloc {};
317 for (std::size_t i = 0; i < N; ++i) {
318 for (std::size_t j = 0; j < N; ++j) {
319 metric_alloc[i * N + j] = metric.get(metric.access_element(
321 ddc::DiscreteElement<MetricIndex1, MetricIndex2>(i, j)));
324 determinant_metric_alloc = metric_alloc;
328 typename MetricType::memory_space>(determinant_metric_alloc.data(), N, N);
334 typename MetricType::memory_space>(inverse_metric_alloc.data(), N, N);
337 typename MetricType::memory_space>(workspace_alloc.data(), N * N);
342 return Kokkos::sqrt(Kokkos::abs(determinant))
343 *
static_cast<double>(detail::permutation_sign<N>(complement, target_ids))
345 K>(inverse_metric_view, source_ids, complement, submatrix_alloc)
350static_assert(ContinuousHodgeStarConcept<
352 ddc::TypeSeq<detail::DirectionConcept>,
354 detail::FieldConcept<detail::MetricIndexConcept>,
355 ddc::DiscreteElement<detail::GridConcept>>,
356 detail::FormFieldConcept<detail::ScalarConcept>,
357 detail::FormFieldConcept<detail::DirectionConcept>,
358 detail::FieldConcept<detail::MetricIndexConcept>,
359 ddc::DiscreteElement<detail::GridConcept>,
360 ddc::DiscreteElement<detail::DirectionConcept>>);
371 ExecSpace
const& exec_space,
372 HodgeStarType
const& hodge_star,
373 MetricType
const& metric,
374 PositionType
const& position)
377 ddc::type_seq_size_v<ddc::to_type_seq_t<typename PositionType::indices_domain_t>> == 1);
379 SIMILIE_DEBUG_LOG(
"similie_compute_hodge_star");
380 ddc::parallel_for_each(
381 "similie_compute_hodge_star",
383 hodge_star.non_indices_domain(),
385 typename HodgeStarType::non_indices_domain_t::discrete_element_type elem) {
392 typename HodgeStarType::non_indices_domain_t::
393 discrete_element_type> {}
394 .
value(metric, position, elem);
395 ddc::device_for_each(hodge_star.accessor().domain(), [&](
auto component) {
396 using Source = tensor::lower_t<reduction_index_t<Indices1>>;
397 using Target = reduction_index_t<Indices2>;
399 = misc::convert_type_seq_to_t<ddc::DiscreteElement, Indices1>;
401 = misc::convert_type_seq_to_t<ddc::DiscreteElement, Indices2>;
402 auto const natural = hodge_star.accessor().canonical_natural_element(component);
403 hodge_star.mem(elem, component)
404 = detail::local_stencil_coefficient<Source, Target>(
406 ddc::detail::array(SourceElement(natural)),
407 ddc::detail::array(TargetElement(natural)));
420 ExecSpace
const& exec_space,
421 HodgeStarType
const& hodge_star,
422 MetricType
const& metric)
424 SIMILIE_DEBUG_LOG(
"similie_compute_continuous_hodge_star");
425 ddc::parallel_for_each(
426 "similie_compute_continuous_hodge_star",
428 hodge_star.non_indices_domain(),
430 typename HodgeStarType::non_indices_domain_t::discrete_element_type elem) {
431 ddc::device_for_each(
432 hodge_star.accessor().domain(),
433 detail::FillContinuousHodgeStarMem<
438 typename HodgeStarType::non_indices_domain_t::
439 discrete_element_type> {hodge_star, metric, elem});
452template <std::
size_t I,
class T>
453struct CodifferentialHodgeOutputIndex : tensor::uncharacterize_t<T>
457template <
class Ids,
class T>
458struct CodifferentialHodgeOutputIndexSeq_;
460template <std::size_t... Id,
class T>
461struct CodifferentialHodgeOutputIndexSeq_<std::index_sequence<Id...>, T>
463 using type = ddc::TypeSeq<tensor::Covariant<CodifferentialHodgeOutputIndex<Id, T>>...>;
466template <std::
size_t EndId,
class T>
467struct CodifferentialHodgeOutputIndexSeq;
469template <std::
size_t EndId,
class T>
471struct CodifferentialHodgeOutputIndexSeq<EndId, T>
473 using type = ddc::TypeSeq<>;
476template <std::
size_t EndId,
class T>
478struct CodifferentialHodgeOutputIndexSeq<EndId, T>
481 typename CodifferentialHodgeOutputIndexSeq_<std::make_index_sequence<EndId>, T>::type;
486template <std::
size_t EndId,
class T>
488 typename detail::CodifferentialHodgeOutputIndexSeq<EndId, T>::type;
491template <std::
size_t Axis,
class Position,
class Rules,
class Element>
492KOKKOS_FUNCTION
void geometry_front(
493 Position
const& position,
498 if (!tensor::detail::is_interface(rules.template boundary_rule<Axis, true>())) {
499 if (ddc::detail::array(elem)[Axis]
500 == ddc::detail::array(position.non_indices_domain().back())[Axis]
501 && ddc::detail::array(elem)[Axis]
502 > ddc::detail::array(position.non_indices_domain().front())[Axis])
503 --ddc::detail::array(front)[Axis];
507template <
class Position,
class Rules,
class Element, std::size_t... Axis>
508KOKKOS_FUNCTION
auto local_geometry(
509 Position
const& position,
512 std::index_sequence<Axis...>)
515 = ddc::type_seq_element_t<0, ddc::to_type_seq_t<typename Position::indices_domain_t>>;
516 Element front = elem;
517 (geometry_front<Axis>(position, rules, elem, front), ...);
518 auto geometry = make_stencil<typename Position::memory_space, Index>(front);
519 ddc::device_for_each(geometry.domain(), [&](
auto sample) {
521 = rules(position, Element(sample)).mem(ddc::DiscreteElement<Index>(sample));
526template <
class MemorySpace,
class... Coordinates>
527KOKKOS_FUNCTION
auto euclidean_metric(ddc::TypeSeq<Coordinates...>)
537 ddc::DiscreteDomain<Index>,
538 Kokkos::layout_right,
539 MemorySpace>(
nullptr, accessor.
domain()));
562 class BoundaryFluxRules>
582 return cochain.non_indices_domain();
585 template <std::
size_t Axis,
class Element,
class Component>
590 double& result)
const
592 if (!tensor::detail::is_interface(
geometry.template boundary_rule<Axis, true>())) {
594 && ddc::detail::array(elem)[Axis]
596 ++ddc::detail::array(elem)[Axis];
597 auto const& rule =
boundary_flux.template boundary_rule<Axis, true>();
599 result = tensor::detail::contract_extrapolation_basis(
601 [](
auto) {
return 0.0; },
603 return tensor::detail::
604 extrapolation_source_value(rule, *
this, elem, component);
612 template <std::
size_t Axis,
class Element>
615 if (!tensor::detail::is_interface(
geometry.template boundary_rule<Axis, false>()))
616 if (ddc::detail::array(cell)[Axis]
619 if (!tensor::detail::is_interface(
geometry.template boundary_rule<Axis, true>()))
620 if (ddc::detail::array(cell)[Axis]
626 template <
class Element>
629 constexpr std::size_t N = Direction::size();
630 constexpr std::size_t edge_count = std::size_t(1) << (N - 1);
632 type_seq_element_t<0, ddc::to_type_seq_t<typename Position::indices_domain_t>>;
633 auto positions = detail::make_stencil<typename Position::memory_space, Index>(cell);
634 std::array<double, N * N> jacobian {};
635 for (std::size_t axis = 0; axis < N; ++axis) {
636 for (std::size_t edge_id = 0; edge_id < edge_count; ++edge_id) {
637 Element first = cell;
638 std::size_t tangent = 0;
639 for (std::size_t other = 0; other < N; ++other)
641 ddc::detail::array(first)[other] += (edge_id >> tangent++) & 1;
642 Element second = first;
643 ++ddc::detail::array(second)[axis];
644 for (std::size_t physical = 0; physical < N; ++physical)
645 jacobian[physical * N + axis]
647 .
mem(ddc::DiscreteElement<Index>(physical))
649 .
mem(ddc::DiscreteElement<Index>(physical)))
653 ddc::device_for_each(positions.domain(), [&](
auto sample) {
654 std::size_t const physical = ddc::DiscreteElement<Index>(sample).uid();
656 for (std::size_t axis = 0; axis < N; ++axis)
657 value += jacobian[physical * N + axis]
658 * (ddc::detail::array(Element(sample))[axis]
659 - ddc::detail::array(cell)[axis]);
660 positions.mem(sample) = value;
665 template <
class Element, std::size_t... Axis>
666 KOKKOS_FUNCTION
double dual_volume(Element elem, std::index_sequence<Axis...>)
const
668 constexpr std::size_t N = Direction::size();
669 auto metric = detail::euclidean_metric<typename Position::memory_space>(
671 std::array<std::size_t, N>
const ids {Axis...};
673 for (std::size_t vertex = 0; vertex < (std::size_t(1) << N); ++vertex) {
675 for (std::size_t axis = 0; axis < N; ++axis)
676 ddc::detail::array(cell)[axis] -= (vertex >> axis) & 1;
682 typename Position::discrete_domain_type,
683 Kokkos::layout_right,
684 typename Position::memory_space>
685 local_position(positions);
690 decltype(local_position),
691 Element>::template operator()<N>(metric, local_position, cell, ids)
692 / (std::size_t(1) << N);
697 template <
class Component>
703 for (std::size_t normal = 0; normal < Direction::size(); ++normal) {
705 for (std::size_t
id : ids)
706 found = found ||
id == normal;
710 return Direction::size();
713 template <
class Element,
class Component, std::size_t... Axis>
718 std::index_sequence<Axis...>)
const
723 template <
class Element,
class Component>
724 KOKKOS_FUNCTION
bool prescribed_flux(Element elem, Component component,
double& prescribed)
731 std::make_index_sequence<Direction::size()> {});
738 template <
class Element,
class Component, std::size_t... Axis>
739 KOKKOS_FUNCTION
auto stencil(Element elem, Component component, std::index_sequence<Axis...>)
743 type_seq_element_t<0, ddc::to_type_seq_t<typename Cochain::indices_domain_t>>;
744 constexpr std::size_t N = Direction::size();
745 constexpr std::size_t edge_count = std::size_t(1) << (N - 1);
746 auto result = detail::make_stencil<typename Position::memory_space, Index, 3>(Element {});
747 double prescribed = 0.0;
754 auto metric = detail::euclidean_metric<typename Position::memory_space>(
756 for (std::size_t incident = 0; incident < edge_count; ++incident) {
759 for (std::size_t axis = 0; axis < N; ++axis)
761 ddc::detail::array(cell)[axis] -= (incident >> bit++) & 1;
767 typename Position::discrete_domain_type,
768 Kokkos::layout_right,
769 typename Position::memory_space>
770 local_position(positions);
771 std::array<double, N * N>
const pairing
772 = detail::one_form_pairing(metric, local_position, cell);
773 using PositionIndex = ddc::
774 type_seq_element_t<0, ddc::to_type_seq_t<typename Position::indices_domain_t>>;
775 std::array<double, N * edge_count * N> edges {};
776 std::array<double, N * edge_count> projector_row {};
777 std::array<double, N> weighted_projection {};
778 std::array<double, N * N> gram {}, inverse {}, workspace {};
779 std::size_t selected = 0;
780 for (std::size_t axis = 0; axis < N; ++axis) {
781 for (std::size_t edge_id = 0; edge_id < edge_count; ++edge_id) {
782 Element first = cell;
783 std::size_t tangent = 0;
784 for (std::size_t other = 0; other < N; ++other)
786 ddc::detail::array(first)[other] += (edge_id >> tangent++) & 1;
788 ++ddc::detail::array(second)[axis];
789 std::size_t
const edge = axis * edge_count + edge_id;
790 if (axis == normal && first == elem)
792 for (std::size_t physical = 0; physical < N; ++physical)
793 edges[edge * N + physical]
795 .mem(ddc::DiscreteElement<PositionIndex>(physical))
797 .mem(ddc::DiscreteElement<PositionIndex>(physical));
798 for (std::size_t i = 0; i < N; ++i) {
799 for (std::size_t j = 0; j < N; ++j)
800 gram[i * N + j] += edges[edge * N + i] * edges[edge * N + j];
810 typename Position::memory_space>(gram.data(), N, N),
813 typename Position::memory_space>(workspace.data(), N * N)))
818 for (std::size_t edge = 0; edge < N * edge_count; ++edge) {
819 projector_row[edge] = edge == selected ? 1.0 : 0.0;
820 for (std::size_t i = 0; i < N; ++i)
821 for (std::size_t j = 0; j < N; ++j)
822 projector_row[edge] -= edges[selected * N + i] * inverse[i * N + j]
823 * edges[edge * N + j];
824 projector_row[edge] *= pairing[(edge / edge_count) * (N + 1)] / edge_count;
825 for (std::size_t i = 0; i < N; ++i)
826 weighted_projection[i] += edges[edge * N + i] * projector_row[edge];
828 for (std::size_t axis = 0; axis < N; ++axis)
829 for (std::size_t edge_id = 0; edge_id < edge_count; ++edge_id) {
830 std::size_t
const edge = axis * edge_count + edge_id;
831 double weight = pairing[normal * N + axis] / (edge_count * edge_count)
832 + projector_row[edge];
833 for (std::size_t i = 0; i < N; ++i)
834 for (std::size_t j = 0; j < N; ++j)
835 weight -= weighted_projection[i] * inverse[i * N + j]
836 * edges[edge * N + j];
838 * detail::permutation_sign<
839 N>(std::array<std::size_t, 1> {normal}, ids);
840 Element first = cell;
841 std::size_t tangent = 0;
842 for (std::size_t other = 0; other < N; ++other)
844 ddc::detail::array(first)[other] += (edge_id >> tangent++) & 1;
845 Element local = first;
846 for (std::size_t coordinate = 0; coordinate < N; ++coordinate)
847 ddc::detail::array(local)[coordinate]
848 = ddc::detail::array(first)[coordinate]
849 - ddc::detail::array(elem)[coordinate] + 1;
850 if constexpr (Index::rank() == 0) {
853 result.mem(local, ddc::DiscreteElement<Index>(0)) -= weight;
854 ++ddc::detail::array(local)[axis];
855 result.mem(local, ddc::DiscreteElement<Index>(0)) += weight;
857 result.mem(local, ddc::DiscreteElement<Index>(axis)) += weight;
863 template <
class Element,
class Component>
864 KOKKOS_FUNCTION
auto value(Element elem, Component component)
const
866 return stencil(elem, component, std::make_index_sequence<Direction::size()> {});
870 template <CochainType TopTensor,
class Element>
871 KOKKOS_FUNCTION
double inverse_zero_form(TopTensor
const& top, Element elem)
const
873 using TopIndices = ddc::type_seq_merge_t<ddc::TypeSeq<Direction>,
dual_indices>;
875 using Memory =
typename Position::memory_space;
878 auto scalar = detail::make_stencil<Memory, Scalar>(ddc::DiscreteElement<>());
879 auto positions = detail::local_geometry(
883 std::make_index_sequence<Direction::size()> {});
886 typename Position::discrete_domain_type,
887 Kokkos::layout_right,
889 local_position(positions);
890 auto metric = detail::euclidean_metric<Memory>(
897 decltype(local_position),
905 double const local_volume = SimplexVolume<
909 decltype(local_position),
911 operator()<Direction::size()>(
915 []<std::size_t... Axis>(std::index_sequence<Axis...>) {
916 return std::array<std::size_t, Direction::size()> {Axis...};
917 }(std::make_index_sequence<Direction::size()> {}));
920 return scalar.mem(ddc::DiscreteElement<Scalar>(0)) * local_volume
921 /
dual_volume(elem, std::make_index_sequence<Direction::size()> {});
927 template <CochainType Output, CochainType TopTensor,
class Element>
928 KOKKOS_FUNCTION
void operator()(Output
const& output, TopTensor
const& top, Element elem)
const
930 output.mem(ddc::DiscreteElement<tensor::Covariant<tensor::ScalarIndex>>(0))
934 template <
class Element,
class Component>
935 KOKKOS_FUNCTION
double mem(Element elem, Component component)
const
937 double prescribed = 0.0;
940 auto const coefficients =
value(elem, component);
942 ddc::device_for_each(coefficients.domain(), [&](
auto entry) {
943 double const weight = coefficients.mem(entry);
947 .mem(tensor::detail::stencil_sample(elem, entry),
948 typename Cochain::indices_domain_t::discrete_element_type(
958template <
class Direction,
class Cochain,
class Position,
class Geometry,
class Flux>
961 Position
const& position,
962 Geometry
const& geometry_rule,
963 Flux
const& flux_rule,
964 double diffusivity = 1.0)
966#if defined(KOKKOS_ENABLE_CUDA)
967 if constexpr (Kokkos::SpaceAccessibility<Kokkos::Cuda, typename Position::memory_space>::
970 std::size_t stack_size = 0;
971 if (cudaDeviceGetLimit(&stack_size, cudaLimitStackSize) != cudaSuccess
972 || (stack_size < 32768 && cudaDeviceSetLimit(cudaLimitStackSize, 32768) != cudaSuccess))
973 throw std::runtime_error(
"cannot reserve the CUDA stack for scalar DEC sampling");
976 auto const geometry = [&] {
978 return geometry_rule;
982 auto const flux = [&] {
992 std::remove_cvref_t<
decltype(geometry)>,
993 std::remove_cvref_t<
decltype(flux)>> {cochain, position, geometry, flux, diffusivity};
1000#include <similie/exterior/discrete_hodge_star/discrete_hodge_star.hpp>
static KOKKOS_FUNCTION constexpr natural_domain_t::discrete_element_type canonical_natural_element(ddc::DiscreteElement< MemIndex... > mem_elem)
static KOKKOS_FUNCTION constexpr discrete_domain_type domain()
HodgeStarType fill_discrete_hodge_star(ExecSpace const &exec_space, HodgeStarType const &hodge_star, MetricType const &metric, PositionType const &position)
auto make_dual_hodge_cochain(Cochain cochain, Position const &position, Geometry const &geometry_rule, Flux const &flux_rule, double diffusivity=1.0)
Normalize single policies locally, as for the staged differential operators.
Cochain(Tensor const &) -> Cochain< Tensor >
typename detail::ReductionTargetIndex< Indices >::type reduction_index_t
Form(Coefficients const &) -> Form< Coefficients >
ddc::detail::convert_type_seq_to_discrete_domain_t< ddc::type_seq_merge_t< ddc::TypeSeq< misc::convert_type_seq_to_t< tensor::TensorFullIndex, Indices1 > >, std::conditional_t<(ddc::type_seq_size_v< Indices2 >==0), ddc::TypeSeq<>, ddc::TypeSeq< misc::convert_type_seq_to_t< tensor::TensorAntisymmetricIndex, Indices2 > > > > > hodge_star_domain_t
HodgeStarType fill_continuous_hodge_star(ExecSpace const &exec_space, HodgeStarType const &hodge_star, MetricType const &metric)
typename detail::CodifferentialHodgeOutputIndexSeq< EndId, T >::type codifferential_hodge_output_indices_t
KOKKOS_FUNCTION bool invert(InverseView const &inverse, MatrixView const &matrix, WorkspaceView const &workspace)
KOKKOS_FUNCTION unmanaged_vector_view_t< Scalar, MemorySpace > vector_view(Scalar *data, std::size_t n)
KOKKOS_FUNCTION MatrixView::non_const_value_type determinant(MatrixView const &matrix)
KOKKOS_FUNCTION unmanaged_matrix_view_t< Scalar, MemorySpace > matrix_view(Scalar *data, std::size_t rows, std::size_t cols)
KOKKOS_FUNCTION double submatrix_determinant(MatrixView const &matrix, RowIds const &row_ids, ColIds const &col_ids, std::array< double, N *N > &submatrix_alloc)
convert_type_seq_to_t< ddc::DiscreteDomain, typename detail::CartesianProd< Domains... >::type > cartesian_prod_t
KOKKOS_FUNCTION constexpr std::size_t factorial(std::size_t k) noexcept
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
ddc::type_seq_element_t< 0, ddc::to_type_seq_t< typename MetricIndex::subindices_domain_t > > metric_index_1
KOKKOS_FUNCTION auto make_extrapolation_rules(ExtrapolationRule rule)
Broadcast a rule to both sides of all N non-index dimensions.
ddc::type_seq_element_t< 1, ddc::to_type_seq_t< typename MetricIndex::subindices_domain_t > > metric_index_2
Tensor< ElementType, ddc::DiscreteDomain< ProdDDim... >, LayoutStridedPolicy, MemorySpace > tensor_prod(Tensor< ElementType, ddc::DiscreteDomain< ProdDDim... >, LayoutStridedPolicy, MemorySpace > const &prod_tensor, Tensor< ElementType, ddc::DiscreteDomain< DDim1... >, LayoutStridedPolicy, MemorySpace > const &tensor1, Tensor< ElementType, ddc::DiscreteDomain< DDim2... >, LayoutStridedPolicy, MemorySpace > const &tensor2)
detail::Uncharacterize< Index >::type uncharacterize_t
detail::Lower< T >::type lower_t
detail::TensorAccessorForDomain< Dom >::type tensor_accessor_for_domain_t
The top-level namespace of SimiLie.
static KOKKOS_FUNCTION void operator()(HodgeTensorType const &hodge_tensor, FormTensorType const &form_tensor, MetricType const &metric, BatchElem elem)
static constexpr bool output_is_form
detail::LinearLocalOperatorStorage< ContinuousHodgeStar, tensor::lower_t< reduction_index_t< Indices1 > >, reduction_index_t< Indices2 >, typename MetricType::non_indices_domain_t, typename MetricType::memory_space, typename MetricType::memory_space::execution_space, tensor::TensorFullIndex, misc::convert_type_seq_to_t< ddc::DiscreteElement, Indices1 >, misc::convert_type_seq_to_t< ddc::DiscreteElement, Indices2 > > staged_storage_type
static constexpr bool input_is_form
static KOKKOS_FUNCTION detail::LocalOperatorStencil< tensor::lower_t< reduction_index_t< Indices1 > >, reduction_index_t< Indices2 > > value(MetricType const &metric, BatchElem element)
static KOKKOS_FUNCTION double value(MetricType const &metric, BatchElem elem, auto natural_elem)
Compose reconstruction, continuous Hodge star and reduction policies.
KOKKOS_FUNCTION detail::LocalOperatorStencil< Source, Target > value(MetricType const &metric, PositionType const &position, BatchElem element) const
Lazy dual cochain obtained by applying the Hodge star to a primal one-cochain.
KOKKOS_FUNCTION auto cell_geometry(Element cell) const
misc::convert_type_seq_to_t< tensor::TensorAntisymmetricIndex, dual_indices > component_type
codifferential_hodge_output_indices_t< Direction::size() - 1, Direction > dual_indices
KOKKOS_FUNCTION double mem(Element elem, Component component) const
KOKKOS_FUNCTION auto value(Element elem, Component component) const
KOKKOS_FUNCTION double inverse_zero_form(TopTensor const &top, Element elem) const
Inverse zero-form Hodge with the physical, truncated dual volume.
KOKKOS_FUNCTION non_indices_domain_t non_indices_domain() const
KOKKOS_FUNCTION double dual_volume(Element elem, std::index_sequence< Axis... >) const
KOKKOS_FUNCTION std::size_t normal_direction(Component component) const
BoundaryFluxRules boundary_flux
typename Position::memory_space memory_space
KOKKOS_FUNCTION void operator()(Output const &output, TopTensor const &top, Element elem) const
Apply the inverse zero-form Hodge to a pointwise top cochain.
ddc::DiscreteDomain< component_type > indices_domain_t
KOKKOS_FUNCTION auto stencil(Element elem, Component component, std::index_sequence< Axis... >) const
Constitutive coefficients on the neighbouring primal tensor nodes.
KOKKOS_FUNCTION bool upper_flux(Element elem, Component component, std::size_t normal, double &result) const
KOKKOS_FUNCTION bool physical_cell(Element cell) const
KOKKOS_FUNCTION bool prescribed_flux(Element elem, Component component, double &prescribed, std::index_sequence< Axis... >) const
misc::cartesian_prod_t< non_indices_domain_t, ddc::DiscreteDomain< component_type > > discrete_domain_type
tensor::upper_t< ddc::to_type_seq_t< tensor::natural_domain_t< Direction > > > source_indices
typename Cochain::non_indices_domain_t non_indices_domain_t