Gyselalib++
 
Loading...
Searching...
No Matches
multipatch_spline_builder.hpp
1// SPDX-License-Identifier: MIT
2
3#pragma once
4#include <cassert>
5#include <tuple>
6#include <utility>
7
8#include <ddc/ddc.hpp>
9#include <ddc/kernels/splines.hpp>
10
11#include "ddc_aliases.hpp"
12#include "multipatch_type.hpp"
13
40template <
41 class ExecSpace,
42 class MemorySpace,
43 template <typename P>
44 typename BSplineOnPatch,
45 template <typename P>
46 typename GridOnPatch,
47 ddc::BoundCond BcLower,
48 ddc::BoundCond BcUpper,
49 ddc::BoundCond BcTransition,
50 class Connectivity,
51 ddc::SplineSolver Solver,
52 template <typename P>
53 typename ValuesOnPatch,
54 class... Patches>
56{
57 static_assert(
58 (((ddc::is_uniform_bsplines_v<BSplineOnPatch<Patches>>)
59 || (ddc::is_non_uniform_bsplines_v<BSplineOnPatch<Patches>>))
60 && ...),
61 "The BSplineOnPatch argument does not create 1D BSpline objects.");
62 static_assert(
63 (((ddc::is_uniform_point_sampling_v<GridOnPatch<Patches>>)
64 || (ddc::is_non_uniform_point_sampling_v<GridOnPatch<Patches>>))
65 && ...),
66 "The GridOnPatch argument does not create 1D Grid objects.");
67
68 using PatchOrdering = ddc::detail::TypeSeq<Patches...>;
69 static constexpr std::size_t n_patches = ddc::type_seq_size_v<PatchOrdering>;
70
75 template <class Patch, class FieldType>
76 struct Build_BuilderType
77 {
78 static_assert(
79 !std::is_same_v<Patch, Patch>,
80 "The values should be saved in a constant field of doubles on the specified memory "
81 "space.");
82 };
83
84 template <class Patch, class... Grid1D>
85 struct Build_BuilderType<Patch, DConstField<IdxRange<Grid1D...>, MemorySpace>>
86 {
87 using lower_matching_edge = equivalent_edge_t<
89 typename Connectivity::interface_collection>;
90 using upper_matching_edge = equivalent_edge_t<
92 typename Connectivity::interface_collection>;
93 static constexpr std::size_t patch_id = ddc::type_seq_rank_v<Patch, PatchOrdering>;
94 using type = ddc::SplineBuilder<
95 ExecSpace,
96 MemorySpace,
97 BSplineOnPatch<Patch>,
98 GridOnPatch<Patch>,
99 std::is_same_v<lower_matching_edge, OutsideEdge> ? BcLower : BcTransition,
100 std::is_same_v<upper_matching_edge, OutsideEdge> ? BcUpper : BcTransition,
101 Solver,
102 Grid1D...>;
103 };
104
106 template <class Patch>
107 using BuilderOnPatch = typename Build_BuilderType<Patch, ValuesOnPatch<Patch>>::type;
108
110 template <class Patch>
111 using SplineOnPatch
112 = DField<typename BuilderOnPatch<Patch>::batched_spline_domain_type, MemorySpace>;
113
115 template <class Patch>
116 using DerivsOnPatch
117 = DConstField<typename BuilderOnPatch<Patch>::batched_derivs_domain_type, MemorySpace>;
118
120 using MultipatchSplineCoeffs = MultipatchField<SplineOnPatch, Patches...>;
121
122 // For PERIODIC or GREVILLE boundary conditions
124 using MultipatchValues = MultipatchField<ValuesOnPatch, Patches...>;
125
126 using MultipatchDerivs = MultipatchField<DerivsOnPatch, Patches...>;
127
129 using BuilderTuple = std::tuple<BuilderOnPatch<Patches> const&...>;
130
131
132 BuilderTuple const m_builders;
133
134private:
135 template <class Patch>
136 std::optional<DerivsOnPatch<Patch>> get_deriv_value(
137 std::optional<MultipatchDerivs> derivs) const
138 {
139 if (derivs.has_value()) {
140 return derivs->template get<Patch>();
141 } else {
142 return std::nullopt;
143 }
144 }
145
146public:
156 explicit MultipatchSplineBuilder(BuilderOnPatch<Patches> const&... builders)
157 : m_builders(std::tie(builders...)) {};
158
159
160 ~MultipatchSplineBuilder() = default;
161
172 MultipatchValues const& values,
173 std::optional<MultipatchDerivs> derivs_xmin = std::nullopt,
174 std::optional<MultipatchDerivs> derivs_xmax = std::nullopt) const
175 {
176 ((std::get<BuilderOnPatch<Patches> const&>(m_builders)(
177 splines.template get<Patches>(),
178 get_const_field(values.template get<Patches>()),
179 get_deriv_value<Patches>(derivs_xmin),
180 get_deriv_value<Patches>(derivs_xmax))),
181 ...);
182 };
183};
A class to store field objects on patches.
Definition multipatch_field.hpp:30
A class to call all the builders of all the patches once.
Definition multipatch_spline_builder.hpp:56
void operator()(MultipatchSplineCoeffs splines, MultipatchValues const &values, std::optional< MultipatchDerivs > derivs_xmin=std::nullopt, std::optional< MultipatchDerivs > derivs_xmax=std::nullopt) const
Build the spline representation of each given function.
Definition multipatch_spline_builder.hpp:170
MultipatchSplineBuilder(BuilderOnPatch< Patches > const &... builders)
Instantiate the MultipatchSplineBuilder from a std::tuple of all the builder on each patch.
Definition multipatch_spline_builder.hpp:156
Define an edge of a given patch.
Definition edge.hpp:25
Base tag for a patch.
Definition patch.hpp:14