Gyselalib++
 
Loading...
Searching...
No Matches
multipatch_spline_builder_2d.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
44template <
45 class ExecSpace,
46 class MemorySpace,
47 template <typename P>
48 typename BSpline1OnPatch,
49 template <typename P>
50 typename BSpline2OnPatch,
51 template <typename P>
52 typename Grid1OnPatch,
53 template <typename P>
54 typename Grid2OnPatch,
55 ddc::BoundCond BcLower1,
56 ddc::BoundCond BcUpper1,
57 ddc::BoundCond BcLower2,
58 ddc::BoundCond BcUpper2,
59 ddc::BoundCond BcTransition,
60 class Connectivity,
61 ddc::SplineSolver Solver,
62 template <typename P>
63 typename ValuesOnPatch,
64 class... Patches>
66{
67 static_assert(
68 (((ddc::is_uniform_bsplines_v<BSpline1OnPatch<Patches>>)
69 || (ddc::is_non_uniform_bsplines_v<BSpline1OnPatch<Patches>>))
70 && ...),
71 "The BSpline1OnPatch argument does not create 1D BSpline objects.");
72 static_assert(
73 (((ddc::is_uniform_bsplines_v<BSpline2OnPatch<Patches>>)
74 || (ddc::is_non_uniform_bsplines_v<BSpline2OnPatch<Patches>>))
75 && ...),
76 "The BSpline2OnPatch argument does not create 1D BSpline objects.");
77 static_assert(
78 (((ddc::is_uniform_point_sampling_v<Grid1OnPatch<Patches>>)
79 || (ddc::is_non_uniform_point_sampling_v<Grid1OnPatch<Patches>>))
80 && ...),
81 "The Grid1OnPatch argument does not create 1D Grid objects.");
82 static_assert(
83 (((ddc::is_uniform_point_sampling_v<Grid2OnPatch<Patches>>)
84 || (ddc::is_non_uniform_point_sampling_v<Grid2OnPatch<Patches>>))
85 && ...),
86 "The Grid2OnPatch argument does not create 1D Grid objects.");
87 static_assert(
88 ((std::is_same_v<
89 typename BSpline1OnPatch<Patches>::continuous_dimension_type,
90 typename Grid1OnPatch<Patches>::continuous_dimension_type>)&&...),
91 "The BSpline1OnPatch argument does not define bsplines on the dimension where the "
92 "grids defined by Grid1OnPatch are defined.");
93 static_assert(
94 ((std::is_same_v<
95 typename BSpline2OnPatch<Patches>::continuous_dimension_type,
96 typename Grid2OnPatch<Patches>::continuous_dimension_type>)&&...),
97 "The BSpline2OnPatch argument does not define bsplines on the dimension where the "
98 "grids defined by Grid2OnPatch are defined.");
103 template <class Patch, class FieldType>
104 struct Build_BuilderType
105 {
106 static_assert(
107 !std::is_same_v<Patch, Patch>,
108 "The values should be saved in a constant field of doubles on the specified memory "
109 "space.");
110 };
111
112 template <class Patch, class... Grid1D>
113 struct Build_BuilderType<Patch, DConstField<IdxRange<Grid1D...>, MemorySpace>>
114 {
115 using lower_matching_edge1 = equivalent_edge_t<
117 typename Connectivity::interface_collection>;
118 using upper_matching_edge1 = equivalent_edge_t<
120 typename Connectivity::interface_collection>;
121 using lower_matching_edge2 = equivalent_edge_t<
123 typename Connectivity::interface_collection>;
124 using upper_matching_edge2 = equivalent_edge_t<
126 typename Connectivity::interface_collection>;
127 using type = ddc::SplineBuilder2D<
128 ExecSpace,
129 MemorySpace,
130 BSpline1OnPatch<Patch>,
131 BSpline2OnPatch<Patch>,
132 Grid1OnPatch<Patch>,
133 Grid2OnPatch<Patch>,
134 std::is_same_v<lower_matching_edge1, OutsideEdge> ? BcLower1 : BcTransition,
135 std::is_same_v<upper_matching_edge1, OutsideEdge> ? BcUpper1 : BcTransition,
136 std::is_same_v<lower_matching_edge2, OutsideEdge> ? BcLower2 : BcTransition,
137 std::is_same_v<upper_matching_edge2, OutsideEdge> ? BcUpper2 : BcTransition,
138 Solver,
139 Grid1D...>;
140 };
141
143 template <class Patch>
144 using BuilderOnPatch = typename Build_BuilderType<Patch, ValuesOnPatch<Patch>>::type;
145
147 template <class Patch>
148 using SplineOnPatch
149 = DField<typename BuilderOnPatch<Patch>::batched_spline_domain_type, MemorySpace>;
150
152 template <class Patch>
153 using Derivs1OnPatch
154 = DConstField<typename BuilderOnPatch<Patch>::batched_derivs_domain_type1, MemorySpace>;
155
157 template <class Patch>
158 using Derivs2OnPatch
159 = DConstField<typename BuilderOnPatch<Patch>::batched_derivs_domain_type2, MemorySpace>;
160
162 template <class Patch>
163 using Derivs12OnPatch
164 = DConstField<typename BuilderOnPatch<Patch>::batched_derivs_domain_type, MemorySpace>;
165
167 using MultipatchSplineCoeffs = MultipatchField<SplineOnPatch, Patches...>;
168
169 // For PERIODIC or GREVILLE boundary conditions
171 using MultipatchValues = MultipatchField<ValuesOnPatch, Patches...>;
172
173 using MultipatchDerivs1 = MultipatchField<Derivs1OnPatch, Patches...>;
174
175 using MultipatchDerivs2 = MultipatchField<Derivs2OnPatch, Patches...>;
176
177 using MultipatchDerivs12 = MultipatchField<Derivs12OnPatch, Patches...>;
178
180 using BuilderTuple = std::tuple<BuilderOnPatch<Patches> const&...>;
181
182
183 BuilderTuple const m_builders;
184
185private:
186 template <class Patch, template <typename P> typename DerivTypeOnPatch>
187 std::optional<DerivTypeOnPatch<Patch>> get_deriv_value(
188 std::optional<MultipatchField<DerivTypeOnPatch, Patches...>> derivs) const
189 {
190 if (derivs.has_value()) {
191 return derivs->template get<Patch>();
192 } else {
193 return std::nullopt;
194 }
195 }
196
197public:
207 explicit MultipatchSplineBuilder2D(BuilderOnPatch<Patches> const&... builders)
208 : m_builders(std::tie(builders...)) {};
209
210
211 ~MultipatchSplineBuilder2D() = default;
212
242 MultipatchValues const& values,
243 std::optional<MultipatchDerivs1> derivs_min1 = std::nullopt,
244 std::optional<MultipatchDerivs1> derivs_max1 = std::nullopt,
245 std::optional<MultipatchDerivs2> derivs_min2 = std::nullopt,
246 std::optional<MultipatchDerivs2> derivs_max2 = std::nullopt,
247 std::optional<MultipatchDerivs12> mixed_derivs_min1_min2 = std::nullopt,
248 std::optional<MultipatchDerivs12> mixed_derivs_max1_min2 = std::nullopt,
249 std::optional<MultipatchDerivs12> mixed_derivs_min1_max2 = std::nullopt,
250 std::optional<MultipatchDerivs12> mixed_derivs_max1_max2 = std::nullopt) const
251 {
252 ((std::get<BuilderOnPatch<Patches> const&>(m_builders)(
253 splines.template get<Patches>(),
254 get_const_field(values.template get<Patches>()),
255 get_deriv_value<Patches, Derivs1OnPatch>(derivs_min1),
256 get_deriv_value<Patches, Derivs1OnPatch>(derivs_max1),
257 get_deriv_value<Patches, Derivs2OnPatch>(derivs_min2),
258 get_deriv_value<Patches, Derivs2OnPatch>(derivs_max2),
259 get_deriv_value<Patches, Derivs12OnPatch>(mixed_derivs_min1_min2),
260 get_deriv_value<Patches, Derivs12OnPatch>(mixed_derivs_max1_min2),
261 get_deriv_value<Patches, Derivs12OnPatch>(mixed_derivs_min1_max2),
262 get_deriv_value<Patches, Derivs12OnPatch>(mixed_derivs_max1_max2))),
263 ...);
264 };
265};
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_2d.hpp:66
void operator()(MultipatchSplineCoeffs splines, MultipatchValues const &values, std::optional< MultipatchDerivs1 > derivs_min1=std::nullopt, std::optional< MultipatchDerivs1 > derivs_max1=std::nullopt, std::optional< MultipatchDerivs2 > derivs_min2=std::nullopt, std::optional< MultipatchDerivs2 > derivs_max2=std::nullopt, std::optional< MultipatchDerivs12 > mixed_derivs_min1_min2=std::nullopt, std::optional< MultipatchDerivs12 > mixed_derivs_max1_min2=std::nullopt, std::optional< MultipatchDerivs12 > mixed_derivs_min1_max2=std::nullopt, std::optional< MultipatchDerivs12 > mixed_derivs_max1_max2=std::nullopt) const
Build the spline representation of each given function.
Definition multipatch_spline_builder_2d.hpp:240
MultipatchSplineBuilder2D(BuilderOnPatch< Patches > const &... builders)
Instantiate the MultipatchSplineBuilder from a std::tuple of all the builder on each patch.
Definition multipatch_spline_builder_2d.hpp:207
Define an edge of a given patch.
Definition edge.hpp:25
Base tag for a patch.
Definition patch.hpp:14