14#include <similie/exterior/codifferential/codifferential.hpp>
15#include <similie/exterior/stencil.hpp>
30KOKKOS_FORCEINLINE_FUNCTION
double laplacian_contribution_sum(
double first,
double second)
32 double const sum = first + second;
33 double const scale = Kokkos::max(Kokkos::abs(first), Kokkos::abs(second));
34 return Kokkos::isfinite(sum)
36 <= 128.0 * std::numeric_limits<double>::epsilon() * scale
41template <std::
size_t Rank,
class Domain,
class Memory>
42using LaplacianChains = StencilChains<Rank, Domain, Memory>;
44template <
class Source,
class Target,
class Domain,
class Memory>
47 using source_index = Source;
49 Kokkos::View<double***, Kokkos::LayoutRight, Memory> coefficients;
50 template <
class Element>
51 KOKKOS_FORCEINLINE_FUNCTION
double operator()(
54 std::size_t source)
const
57 for (std::size_t axis = 0; axis < Domain::rank(); ++axis)
58 node = node * ddc::detail::array(domain.extents())[axis]
59 + ddc::detail::array(element)[axis] - ddc::detail::array(domain.front())[axis];
60 return coefficients(node, target, source);
65template <
class Source,
class Target,
class Exec,
class Hodge,
class Metric,
class Position>
66LaplacianHodge<Source, Target, typename Metric::non_indices_domain_t, typename Metric::memory_space>
71 Position
const& position)
73 using Domain =
typename Metric::non_indices_domain_t;
74 using Memory =
typename Metric::memory_space;
75 Domain
const domain = metric.non_indices_domain();
76 Kokkos::View<double***, Kokkos::LayoutRight, Memory> coefficients(
77 "laplacian_hodge_components",
81 ddc::parallel_for_each(
82 "similie_cache_laplacian_hodge",
85 KOKKOS_LAMBDA(
typename Domain::discrete_element_type element) {
86 auto unit = make_stencil<Memory, Source>(ddc::DiscreteElement<>());
87 auto output = make_stencil<Memory, Target>(ddc::DiscreteElement<>());
88 std::size_t
const node = [&] {
89 std::size_t result = 0;
90 for (std::size_t axis = 0; axis < Domain::rank(); ++axis)
91 result = result * ddc::detail::array(domain.extents())[axis]
92 + ddc::detail::array(element)[axis]
93 - ddc::detail::array(domain.front())[axis];
96 for (std::size_t source = 0; source < Source::mem_size(); ++source) {
97 unit.mem(ddc::DiscreteElement<Source>(source)) = 1.0;
103 for (std::size_t target = 0; target < Target::mem_size(); ++target)
104 coefficients(node, target, source)
105 = output.mem(ddc::DiscreteElement<Target>(target));
106 unit.mem(ddc::DiscreteElement<Source>(source)) = 0.0;
111 return {domain, coefficients};
114template <
class Hodge,
class Exec,
class Metric,
class Position>
115Hodge make_laplacian_hodge(Exec
const& exec, Metric
const& metric, Position
const& position)
117 if constexpr (std::is_constructible_v<Hodge, Exec const&, Metric, Position>)
118 return Hodge(exec, metric, position);
128 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
129struct LaplacianHodgePair
134 using InverseSourceIndices = ddc::type_seq_merge_t<ddc::TypeSeq<Index>, TargetIndices>;
135 using InverseTargetIndices
136 = ddc::type_seq_remove_t<tensor::lower_t<SourceIndices>, ddc::TypeSeq<Index>>;
140 using Element =
typename Metric::non_indices_domain_t::discrete_element_type;
142 = Hodge<CellComplex::Primal, SourceIndices, TargetIndices, Metric, Position, Element>;
146 InverseTargetIndices,
150 static_assert(DiscreteHodgeStarConcept<
154 ddc::DiscreteDomain<Dual>,
155 Kokkos::layout_right,
156 typename Metric::memory_space>>,
159 ddc::DiscreteDomain<Cochain>,
160 Kokkos::layout_right,
161 typename Metric::memory_space>>,
167 discrete_element_type>);
168 static_assert(DiscreteHodgeStarConcept<
172 ddc::DiscreteDomain<codifferential_index_t<Index, Cochain>>,
173 Kokkos::layout_right,
174 typename Metric::memory_space>>,
177 ddc::DiscreteDomain<Intermediate>,
178 Kokkos::layout_right,
179 typename Metric::memory_space>>,
185 InverseTargetIndices>>::natural_domain_t::discrete_element_type>);
188 template <
class Exec>
189 LaplacianHodgePair(Exec
const& exec, Metric
const& metric, Position
const& position)
190 : forward(make_laplacian_hodge<Forward>(exec, metric, position))
191 , inverse(make_laplacian_hodge<Inverse>(exec, metric, position))
194 template <
class Exec>
195 auto canonical(Exec
const& exec, Metric
const& metric, Position
const& position)
const
198 pair {cache_laplacian_hodge<Cochain, Dual>(exec, forward, metric, position),
199 cache_laplacian_hodge<
203 Cochain>>(exec, inverse, metric, position)};
207template <
class A,
class B,
class C,
class D,
class Chains>
208struct LaplacianGeometry
211 B inverse_derivative_hodge;
217template <
class Index,
class Domain,
class Memory,
class Evaluate>
218using LaplacianField = StencilField<Index, Domain, Memory, Evaluate>;
220template <
class Index,
class Field,
class Rules,
class Element,
class Chains>
221KOKKOS_FORCEINLINE_FUNCTION
auto laplacian_derivative(
225 Chains
const& chains)
227 using Source = ddc::type_seq_element_t<0, ddc::to_type_seq_t<typename Field::indices_domain_t>>;
229 auto output = make_stencil<typename Field::memory_space, Target>(ddc::DiscreteElement<>());
230 auto const chain = chains.template get<Source::rank() + 1>();
231 auto const lower = chains.template get<Source::rank()>();
233 if constexpr (misc::Specialization<Rules, tensor::ExtrapolationRules>)
238 apply_incidence<false, Index, Source>(
240 [&](
auto sample,
auto component) { return boundary(field, sample).mem(component); },
255KOKKOS_FORCEINLINE_FUNCTION
auto laplacian_codifferential(
258 Inverse
const& inverse,
261 Chains
const& chains)
263 using Source = ddc::type_seq_element_t<0, ddc::to_type_seq_t<typename Field::indices_domain_t>>;
265 tensor::TensorAntisymmetricIndex,
268 auto evaluate = [&](
auto sample,
auto component) {
270 for (std::size_t source = 0; source < Source::mem_size(); ++source)
271 value += hodge(sample, component.template uid<Dual>(), source)
272 * field.mem(sample, ddc::DiscreteElement<Source>(source));
277 typename Field::non_indices_domain_t,
278 typename Field::memory_space,
279 decltype(evaluate)>
const dual(field.non_indices_domain(), evaluate);
281 if constexpr (misc::Specialization<Rules, tensor::ExtrapolationRules>)
286 auto output = make_stencil<typename Field::memory_space, Target>(ddc::DiscreteElement<>());
287 auto const chain = chains.template get<Dual::rank() + 1>();
288 auto const lower = chains.template get<Dual::rank()>();
289 using Intermediate =
typename Inverse::source_index;
291 = make_stencil<typename Field::memory_space, Intermediate>(ddc::DiscreteElement<>());
292 apply_incidence<true, Index, Dual>(
294 [&](
auto sample,
auto component) { return boundary(dual, sample).mem(component); },
298 ddc::device_for_each(output.domain(), [&](
auto target) {
300 for (std::size_t source = 0; source < Intermediate::mem_size(); ++source)
301 value += inverse(element, target.template uid<Target>(), source)
302 * derivative.mem(ddc::DiscreteElement<Intermediate>(source));
303 if constexpr ((Index::size() * (Source::rank() + 1) + 1) % 2 == 1)
305 output.mem(target) = value;
310template <
class Domain,
class Element>
311KOKKOS_FORCEINLINE_FUNCTION std::size_t laplacian_node_id(Domain
const& domain, Element element)
314 for (std::size_t axis = 0; axis < Domain::rank(); ++axis)
315 id =
id * ddc::detail::array(domain.extents())[axis] + ddc::detail::array(element)[axis]
316 - ddc::detail::array(domain.front())[axis];
320template <
class Domain>
321KOKKOS_FORCEINLINE_FUNCTION
typename Domain::discrete_element_type laplacian_element(
322 Domain
const& domain,
325 typename Domain::discrete_element_type element = domain.front();
326 for (std::size_t axis = Domain::rank(); axis-- > 0;) {
327 ddc::detail::array(element)[axis] +=
id % ddc::detail::array(domain.extents())[axis];
328 id /= ddc::detail::array(domain.extents())[axis];
333template <
class Tensor>
334struct LaplacianInputEvaluator
337 template <
class Output,
class Element>
338 KOKKOS_FUNCTION
void operator()(Output
const& output, Element element)
const
340 ddc::device_for_each(output.domain(), [&](
auto component) {
341 output.mem(component) = input.mem(element, component);
346template <
class Index,
class Cochain,
class Tensor,
class Boundary,
class Chain,
class Lower>
347struct LaplacianDerivativeEvaluator
353 template <
class Output,
class Element>
354 KOKKOS_FUNCTION
void operator()(Output
const& output, Element element)
const
356 Coboundary<Index, Cochain>::operator()(
358 [&](
auto sample,
auto component) {
return boundary(input, sample).mem(component); },
372 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
373struct LaplacianCodifferential
375 using Pair = LaplacianHodgePair<Index, Cochain, Metric, Position, Hodge>;
376 using DualIndex =
typename Pair::Dual;
377 using Memory =
typename Tensor::memory_space;
378 using Domain = misc::
379 cartesian_prod_t<typename Tensor::non_indices_domain_t, ddc::DiscreteDomain<DualIndex>>;
381 ddc::Chunk<double, Domain, ddc::KokkosAllocator<double, Memory>> buffer;
383 LaplacianCodifferential(
386 Metric
const& metric,
387 Position
const& position)
388 : stars(exec, metric, position)
389 , buffer(Domain(input.non_indices_domain(), tensor::TensorAccessor<DualIndex>::domain()),
390 ddc::KokkosAllocator<double, Memory>())
394 template <
class Output,
class Evaluate,
class Rules>
398 Evaluate
const& evaluate,
399 Metric
const& metric,
400 Position
const& position,
404 auto const& forward = stars.forward;
405 auto const& inverse = stars.inverse;
407 if constexpr (misc::Specialization<Rules, tensor::ExtrapolationRules>)
413 typename NonSpectatorDimension<Index, typename Tensor::non_indices_domain_t>::type;
416 ddc::parallel_for_each(
417 "similie_laplacian_first_hodge",
419 dual.non_indices_domain(),
421 typename Tensor::non_indices_domain_t::discrete_element_type element) {
422 auto point = make_stencil<Memory, Cochain>(ddc::DiscreteElement<>());
424 forward(dual[element],
430 ddc::parallel_for_each(
431 "similie_laplacian_second_hodge",
433 output.non_indices_domain(),
435 typename Tensor::non_indices_domain_t::discrete_element_type element) {
436 auto derivative = make_stencil<Memory, typename Pair::Intermediate>(
437 ddc::DiscreteElement<>());
438 TransposedCoboundary<Index, DualIndex>::operator()(
440 [&](
auto sample,
auto component) {
441 return boundary(dual, sample).mem(component);
446 inverse(output[element],
451 if constexpr ((Index::size() * (Cochain::rank() + 1) + 1) % 2 == 1)
452 output[element] *= -1;
458struct EmptyLaplacianTerm
460 template <
class... Args>
461 EmptyLaplacianTerm(Args
const&...)
474 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
475struct LaplacianUpper : EmptyLaplacianTerm
477 using EmptyLaplacianTerm::EmptyLaplacianTerm;
487 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
488struct LaplacianUpper<true, Index,
Cochain,
Tensor, Metric, Position, Exec, Hodge>
490 using Added = tensor::Covariant<
491 IndexForCodifferentialOfCoboundaryInLaplacian<tensor::uncharacterize_t<Index>>>;
492 LaplacianCodifferential<
504 Metric
const& metric,
505 Position
const& position)
506 : operation(exec, input, metric, position)
519 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
520struct LaplacianLower : EmptyLaplacianTerm
522 using EmptyLaplacianTerm::EmptyLaplacianTerm;
532 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge>
533struct LaplacianLower<true, Index,
Cochain,
Tensor, Metric, Position, Exec, Hodge>
535 using Memory =
typename Tensor::memory_space;
537 typename Tensor::non_indices_domain_t,
538 ddc::DiscreteDomain<codifferential_index_t<Index, Cochain>>>;
539 LaplacianCodifferential<Index, Cochain, Tensor, Metric, Position, Exec, Hodge> operation;
540 ddc::Chunk<double, LowerDomain, ddc::KokkosAllocator<double, Memory>> lower;
541 std::optional<ddc::Chunk<
543 typename Tensor::discrete_domain_type,
544 ddc::KokkosAllocator<double, Memory>>>
548 Tensor
const& output,
550 Metric
const& metric,
551 Position
const& position)
552 : operation(exec, input, metric, position)
554 input.non_indices_domain(),
556 ddc::KokkosAllocator<double, Memory>())
558 if constexpr (Cochain::rank() < Index::size())
559 contribution.emplace(output.domain(), ddc::KokkosAllocator<double, Memory>());
579 tensor::TensorIndex MetricIndex,
580 tensor::TensorNatIndex Index,
583 misc::Specialization<tensor::Tensor> Metric,
584 misc::Specialization<tensor::Tensor> Position,
586 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge = DiscreteHodgeStar>
592 detail::LaplacianUpper<
593 (Cochain::rank() < Index::size()),
602 detail::LaplacianLower<
603 (Cochain::rank() > 0),
615 LinearSpatialOperatorStorage<Laplacian, Index, Cochain, Cochain, 2, Tensor, Exec, true>;
619 Tensor
const& output,
621 Metric
const& metric,
622 Position
const& position)
625 , m_position(position)
626 , m_upper(exec, input, metric, position)
627 , m_lower(exec, output, input, metric, position)
635 Tensor
const& output,
637 Primal const& primal = {},
638 Dual
const& dual = {})
640 if constexpr (Cochain::rank() < Index::size()) {
642 IndexForCodifferentialOfCoboundaryInLaplacian<tensor::uncharacterize_t<Index>>>;
643 using ChainDomain =
typename detail::
644 NonSpectatorDimension<Index, typename Tensor::non_indices_domain_t>::type;
656 detail::LaplacianDerivativeEvaluator<
662 decltype(lower)> {input,
boundary, chain, lower},
667 if constexpr (Cochain::rank() > 0) {
672 detail::LaplacianInputEvaluator<Tensor> {input},
676 if constexpr (Cochain::rank() < Index::size()) {
680 ddc::parallel_for_each(
681 "similie_add_laplacian_contributions",
684 KOKKOS_LAMBDA(
typename Tensor::discrete_element_type element) {
685 output.mem(element) += contribution.mem(element);
697 static auto geometry(Exec
const& exec, Metric
const& metric, Position
const& position)
699 using Domain =
typename detail::
700 NonSpectatorDimension<Index, typename Tensor::non_indices_domain_t>::type;
701 detail::LaplacianChains<0, Domain, typename Tensor::memory_space>
const chains {};
702 auto derivative = [&] {
703 if constexpr (Cochain::rank() < Index::size()) {
704 using Added = tensor::Covariant<IndexForCodifferentialOfCoboundaryInLaplacian<
705 tensor::uncharacterize_t<Index>>>;
706 return detail::LaplacianHodgePair<
711 Hodge>(exec, metric, position)
712 .canonical(exec, metric, position);
714 return std::pair {0, 0};
717 if constexpr (Cochain::rank() > 0)
718 return detail::LaplacianHodgePair<
723 Hodge>(exec, metric, position)
724 .canonical(exec, metric, position);
726 return std::pair {0, 0};
728 return detail::LaplacianGeometry {
737 template <
class Geometry,
class Evaluate,
class Element,
class Primal,
class Dual>
739 Geometry
const& staged,
741 Evaluate
const& evaluate,
746 using Memory =
typename Tensor::memory_space;
747 using Domain =
typename Tensor::non_indices_domain_t;
748 detail::LaplacianField<Cochain, Domain, Memory, Evaluate>
const
749 field(input.non_indices_domain(), evaluate);
750 auto output = detail::make_stencil<Memory, Cochain>(ddc::DiscreteElement<>());
751 if constexpr (Cochain::rank() < Index::size()) {
755 auto derivative = [&](
auto sample,
auto component) {
756 return detail::laplacian_derivative<Added>(field, primal, sample, staged.chains)
759 detail::LaplacianField<Derived, Domain, Memory,
decltype(derivative)>
const
760 derivatives(input.non_indices_domain(), derivative);
761 auto result = detail::laplacian_codifferential<Added>(
763 staged.derivative_hodge,
764 staged.inverse_derivative_hodge,
768 ddc::device_for_each(output.domain(), [&](
auto component) {
769 output.mem(component) += result.mem(component);
772 if constexpr (Cochain::rank() > 0) {
775 return detail::laplacian_codifferential<Index>(
778 staged.inverse_hodge,
784 detail::LaplacianField<Lower, Domain, Memory,
decltype(
codifferential)>
const
786 auto result = detail::laplacian_derivative<
787 Index>(codifferentials, primal, element, staged.chains);
788 ddc::device_for_each(output.domain(), [&](
auto component) {
789 output.mem(component) = detail::
790 laplacian_contribution_sum(output.mem(component), result.mem(component));
801 template <
class Geometry,
class Element,
class Primal,
class Dual>
802 KOKKOS_FORCEINLINE_FUNCTION
static auto value(
803 Geometry
const& geometry,
809 return detail::operator_stencil<
813 2>(input.non_indices_domain(), element, [&](
auto evaluate) {
814 return operator()(geometry, input, evaluate, element, primal, dual);
818 template <
class Geometry,
class Element,
class Component,
class Primal,
class Dual>
819 KOKKOS_FORCEINLINE_FUNCTION
static double value(
820 Geometry
const& staged,
831 [&](
auto sample,
auto component) {
832 return detail::laplacian_node_id(input.non_indices_domain(), sample)
833 * Cochain::mem_size()
834 + component.template uid<Cochain>()
842 return result.mem(target);
850 template <CellComplex,
class,
class,
class,
class,
class>
class Hodge = DiscreteHodgeStar,
857 Tensor
const& output,
859 Metric
const& metric,
860 Position
const& position)
862 return {exec, output, input, metric, position};
871 CochainType DualTensorBufferType,
872 CochainType TensorType,
878TensorType codifferential_of_coboundary(
879 ExecSpace
const& exec_space,
880 TensorType out_tensor,
881 TensorType
const& tensor,
882 HodgeStarType
const& hodge_star,
883 DualHodgeStarType
const& dual_hodge_star,
884 DualTensorBufferType
const& dual_tensor_buffer,
885 PrimalExtrapolationRule
const& primal_extrapolation = {},
886 DualExtrapolationRule
const& dual_extrapolation = {})
888 auto const primal_extrapolation_rules = [&]() {
889 if constexpr (misc::Specialization<PrimalExtrapolationRule, tensor::ExtrapolationRules>)
890 return primal_extrapolation;
894 auto const dual_extrapolation_rules = [&]() {
895 if constexpr (misc::Specialization<DualExtrapolationRule, tensor::ExtrapolationRules>)
896 return dual_extrapolation;
902 LaplacianDummyIndex::size() - coboundary_output_index::rank(),
903 LaplacianDummyIndex>;
905 tensor::TensorAntisymmetricIndex,
906 codifferential_hodge_output_indices>;
907 using dual_codifferential_hodge_input_indices = ddc::type_seq_merge_t<
908 ddc::TypeSeq<LaplacianDummyIndex>,
909 codifferential_hodge_output_indices>;
911 tensor::TensorAntisymmetricIndex,
912 dual_codifferential_hodge_input_indices>;
914 CochainTag::rank() + 1,
915 typename detail::NonSpectatorDimension<
917 typename TensorType::non_indices_domain_t>::type>(exec_space);
920 typename detail::NonSpectatorDimension<
922 typename TensorType::non_indices_domain_t>::type>(exec_space);
924 coboundary_dual_tensor_index::rank() + 1,
925 typename detail::NonSpectatorDimension<
927 typename TensorType::non_indices_domain_t>::type>(exec_space);
929 coboundary_dual_tensor_index::rank(),
930 typename detail::NonSpectatorDimension<
932 typename TensorType::non_indices_domain_t>::type>(exec_space);
934 SIMILIE_DEBUG_LOG(
"similie_deriv_and_apply_first_hodge_star_for_codifferential_of_coboundary");
935 ddc::parallel_for_each(
936 "similie_deriv_and_apply_first_hodge_star_for_codifferential_of_coboundary",
938 dual_tensor_buffer.non_indices_domain(),
939 KOKKOS_LAMBDA(
typename TensorType::non_indices_domain_t::discrete_element_type elem) {
940 [[maybe_unused]] tensor::TensorAccessor<coboundary_output_index>
942 std::array<double, coboundary_output_index::mem_size()> derivative_alloc {};
945 ddc::DiscreteDomain<coboundary_output_index>,
946 Kokkos::layout_right,
947 typename TensorType::memory_space>
948 derivative_span(derivative_alloc.data(), derivative_accessor.domain());
951 Coboundary<LaplacianDummyIndex, CochainTag>::operator()(
953 [&](
auto sampled_elem,
auto cochain_elem) {
954 return primal_extrapolation_rules(tensor, sampled_elem)
962 tensor_prod(dual_tensor_buffer[elem], derivative_tensor, hodge_star[elem]);
965 SIMILIE_DEBUG_LOG(
"similie_deriv_and_apply_second_hodge_star_for_codifferential_of_coboundary");
966 ddc::parallel_for_each(
967 "similie_deriv_and_apply_second_hodge_star_for_codifferential_of_coboundary",
969 out_tensor.non_indices_domain(),
970 KOKKOS_LAMBDA(
typename TensorType::non_indices_domain_t::discrete_element_type elem) {
971 [[maybe_unused]] tensor::TensorAccessor<dual_codifferential_index>
972 dual_codifferential_accessor;
973 std::array<double, dual_codifferential_index::mem_size()>
974 dual_codifferential_alloc {};
977 ddc::DiscreteDomain<dual_codifferential_index>,
978 Kokkos::layout_right,
979 typename TensorType::memory_space>
980 dual_codifferential_span(
981 dual_codifferential_alloc.data(),
982 dual_codifferential_accessor.domain());
986 TransposedCoboundary<LaplacianDummyIndex, coboundary_dual_tensor_index>::operator()(
988 [&](
auto sampled_elem,
auto dual_elem) {
989 return dual_extrapolation_rules(dual_tensor_buffer, sampled_elem)
997 tensor_prod(out_tensor[elem], dual_codifferential, dual_hodge_star[elem]);
999 (LaplacianDummyIndex::size() * (coboundary_output_index::rank() + 1) + 1)
1002 out_tensor[elem] *= -1;
1009template <
class LaplacianDummyIndex,
class CochainTag>
1010concept ZeroRankLaplacianCochain = CochainTag::rank() == 0;
1012template <
class LaplacianDummyIndex,
class CochainTag>
1013concept IntermediateRankLaplacianCochain
1014 = CochainTag::rank() > 0 && CochainTag::rank() < LaplacianDummyIndex::size();
1016template <
class LaplacianDummyIndex,
class CochainTag>
1017concept TopRankLaplacianCochain = CochainTag::rank() == LaplacianDummyIndex::size();
1022 tensor::TensorIndex MetricIndex,
1023 tensor::TensorNatIndex LaplacianDummyIndex,
1024 tensor::TensorIndex CochainTag,
1025 CochainType TensorType,
1026 misc::Specialization<tensor::Tensor> DerivativeHodgeStarType,
1027 misc::Specialization<tensor::Tensor> DualDerivativeHodgeStarType,
1028 CochainType DerivativeDualTensorBufferType,
1030 class PrimalExtrapolationRule = tensor::ClampExtrapolationRule,
1031 class DualExtrapolationRule = tensor::ZeroExtrapolationRule>
1032 requires(detail::ZeroRankLaplacianCochain<LaplacianDummyIndex, CochainTag>)
1034 ExecSpace
const& exec_space,
1035 TensorType
const& laplacian_tensor,
1036 TensorType
const& tensor,
1037 DerivativeHodgeStarType
const& hodge_star,
1038 DualDerivativeHodgeStarType
const& dual_hodge_star,
1039 DerivativeDualTensorBufferType
const& dual_tensor_buffer,
1040 PrimalExtrapolationRule
const& primal_extrapolation = {},
1041 DualExtrapolationRule
const& dual_extrapolation = {})
1043 using codifferential_of_coboundary_index
1044 = tensor::Covariant<IndexForCodifferentialOfCoboundaryInLaplacian<
1045 tensor::uncharacterize_t<LaplacianDummyIndex>>>;
1046 return detail::codifferential_of_coboundary<
1048 codifferential_of_coboundary_index,
1056 primal_extrapolation,
1057 dual_extrapolation);
1061 tensor::TensorIndex MetricIndex,
1062 tensor::TensorNatIndex LaplacianDummyIndex,
1063 tensor::TensorIndex CochainTag,
1064 CochainType TensorType,
1065 misc::Specialization<tensor::Tensor> DerivativeHodgeStarType,
1066 misc::Specialization<tensor::Tensor> DualDerivativeHodgeStarType,
1067 CochainType DerivativeDualTensorBufferType,
1068 misc::Specialization<tensor::Tensor> HodgeStarType,
1069 misc::Specialization<tensor::Tensor> DualHodgeStarType,
1070 CochainType DualTensorBufferType,
1071 CochainType CodifferentialTensorBufferType,
1072 CochainType CoboundaryOfCodifferentialBufferType,
1074 class PrimalExtrapolationRule = tensor::ClampExtrapolationRule,
1075 class DualExtrapolationRule = tensor::ZeroExtrapolationRule>
1076 requires(detail::IntermediateRankLaplacianCochain<LaplacianDummyIndex, CochainTag>)
1078 ExecSpace
const& exec_space,
1079 TensorType
const& laplacian_tensor,
1080 TensorType
const& tensor,
1081 DerivativeHodgeStarType
const& derivative_hodge_star,
1082 DualDerivativeHodgeStarType
const& dual_derivative_hodge_star,
1083 DerivativeDualTensorBufferType
const& derivative_dual_tensor_buffer,
1084 HodgeStarType
const& hodge_star,
1085 DualHodgeStarType
const& dual_hodge_star,
1086 DualTensorBufferType
const& dual_tensor_buffer,
1087 CodifferentialTensorBufferType
const& codifferential_tensor_buffer,
1088 CoboundaryOfCodifferentialBufferType
const& coboundary_of_codifferential_buffer,
1089 PrimalExtrapolationRule
const& primal_extrapolation = {},
1090 DualExtrapolationRule
const& dual_extrapolation = {})
1092 using codifferential_of_coboundary_index
1093 = tensor::Covariant<IndexForCodifferentialOfCoboundaryInLaplacian<
1094 tensor::uncharacterize_t<LaplacianDummyIndex>>>;
1095 auto exec_spaces = Kokkos::Experimental::partition_space(exec_space, 1, 1);
1097 detail::codifferential_of_coboundary<
1099 codifferential_of_coboundary_index,
1104 derivative_hodge_star,
1105 dual_derivative_hodge_star,
1106 derivative_dual_tensor_buffer,
1107 primal_extrapolation,
1108 dual_extrapolation);
1112 codifferential_tensor_buffer,
1117 dual_extrapolation);
1119 deriv<LaplacianDummyIndex, codifferential_index_t<LaplacianDummyIndex, CochainTag>>(
1121 coboundary_of_codifferential_buffer,
1122 codifferential_tensor_buffer,
1123 primal_extrapolation);
1125 exec_spaces[0].fence();
1126 exec_spaces[1].fence();
1128 SIMILIE_DEBUG_LOG(
"similie_add_coboundary_of_codifferential_contribution_to_laplacian");
1129 ddc::parallel_for_each(
1130 "similie_add_coboundary_of_codifferential_contribution_to_laplacian",
1132 laplacian_tensor.domain(),
1133 KOKKOS_LAMBDA(
typename TensorType::discrete_element_type elem) {
1134 laplacian_tensor.mem(elem) += coboundary_of_codifferential_buffer.mem(elem);
1137 return laplacian_tensor;
1141 tensor::TensorIndex MetricIndex,
1142 tensor::TensorNatIndex LaplacianDummyIndex,
1143 tensor::TensorIndex CochainTag,
1144 CochainType TensorType,
1145 misc::Specialization<tensor::Tensor> HodgeStarType,
1146 misc::Specialization<tensor::Tensor> DualHodgeStarType,
1147 CochainType DualTensorBufferType,
1148 CochainType CodifferentialTensorBufferType,
1150 class PrimalExtrapolationRule = tensor::ClampExtrapolationRule,
1151 class DualExtrapolationRule = tensor::ZeroExtrapolationRule>
1152 requires(detail::TopRankLaplacianCochain<LaplacianDummyIndex, CochainTag>)
1154 ExecSpace
const& exec_space,
1155 TensorType
const& laplacian_tensor,
1156 TensorType
const& tensor,
1157 HodgeStarType
const& hodge_star,
1158 DualHodgeStarType
const& dual_hodge_star,
1159 DualTensorBufferType
const& dual_tensor_buffer,
1160 CodifferentialTensorBufferType
const& codifferential_tensor_buffer,
1161 PrimalExtrapolationRule
const& primal_extrapolation = {},
1162 DualExtrapolationRule
const& dual_extrapolation = {})
1166 codifferential_tensor_buffer,
1171 dual_extrapolation);
1172 return sil::exterior::
1173 deriv<LaplacianDummyIndex, codifferential_index_t<LaplacianDummyIndex, CochainTag>>(
1176 codifferential_tensor_buffer,
1177 primal_extrapolation);
Hodge Laplacian assembled from independently selected Hodge-star policies.
detail:: LinearSpatialOperatorStorage< Laplacian, Index, Cochain, Cochain, 2, Tensor, Exec, true > staged_storage_type
static KOKKOS_FORCEINLINE_FUNCTION auto operator()(Geometry const &staged, Tensor const &input, Evaluate const &evaluate, Element element, Primal const &primal, Dual const &dual)
Laplacian(Exec const &exec, Tensor const &output, Tensor const &input, Metric const &metric, Position const &position)
Tensor operator()(Tensor const &output, Tensor const &input, Primal const &primal={}, Dual const &dual={})
static KOKKOS_FORCEINLINE_FUNCTION double value(Geometry const &staged, Tensor const &input, Element element, Component target, std::size_t column, Primal const &primal, Dual const &dual)
static KOKKOS_FORCEINLINE_FUNCTION auto value(Geometry const &geometry, Tensor const &input, Element element, Primal const &primal, Dual const &dual)
Complete fixed stencil at one node, including component couplings.
TensorType laplacian(ExecSpace const &exec_space, TensorType const &laplacian_tensor, TensorType const &tensor, DerivativeHodgeStarType const &hodge_star, DualDerivativeHodgeStarType const &dual_hodge_star, DerivativeDualTensorBufferType const &dual_tensor_buffer, PrimalExtrapolationRule const &primal_extrapolation={}, DualExtrapolationRule const &dual_extrapolation={})
Chain(Head, Tail...) -> Chain< typename Head::value_type, typename Head::array_layout, typename Head::memory_space >
Laplacian< MetricIndex, Index, Cochain, Tensor, Metric, Position, Exec, Hodge > make_laplacian(Exec const &exec, Tensor const &output, Tensor const &input, Metric const &metric, Position const &position)
Cochain(Tensor const &) -> Cochain< Tensor >
KOKKOS_FUNCTION Chain< boundary_t< SimplexType >, typename AllocationType::array_layout, typename AllocationType::memory_space > boundary(AllocationType allocation, SimplexType const &simplex)
codifferential_tensor_t< TagToRemoveFromCochain, CochainTag, TensorType > codifferential(ExecSpace const &exec_space, codifferential_tensor_t< TagToRemoveFromCochain, CochainTag, TensorType > const &codifferential_tensor, TensorType const &tensor, HodgeStarType const &hodge_star, DualHodgeStarType const &dual_hodge_star, DualTensorType const &dual_tensor_buffer, DualExtrapolationRule const &dual_extrapolation={})
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
typename detail::CodifferentialIndex< TagToRemoveFromCochain, CochainTag >::type codifferential_index_t
coboundary_tensor_t< TagToAddToCochain, CochainTag, TensorType > deriv(ExecSpace const &exec_space, coboundary_tensor_t< TagToAddToCochain, CochainTag, TensorType > const &coboundary_tensor, TensorType const &tensor, ExtrapolationRules const &extrapolation={})
KOKKOS_FUNCTION constexpr auto tangent_basis(Elem elem)
typename detail::CodifferentialHodgeOutputIndexSeq< EndId, T >::type codifferential_hodge_output_indices_t
typename detail::CoboundaryIndex< TagToAddToCochain, CochainTag >::type coboundary_index_t
convert_type_seq_to_t< ddc::DiscreteDomain, typename detail::CartesianProd< Domains... >::type > cartesian_prod_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
KOKKOS_FUNCTION auto make_extrapolation_rules(ExtrapolationRule rule)
Broadcast a rule to both sides of all N non-index dimensions.
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::TensorAccessorForDomain< Dom >::type tensor_accessor_for_domain_t