20struct NonUniformBSplinesBase
32
33
34
35
36
37
38
39
40template <
class CDim, std::size_t D>
43 static_assert(D > 0,
"Parameter `D` must be positive");
47 using continuous_dimension_type = CDim;
53
54
55
56 static constexpr std::size_t
degree()
noexcept
62
63
64
67 return CDim::PERIODIC;
71
72
73
80
81
82
83
84 template <
class DDim,
class MemorySpace>
87 template <
class ODDim,
class OMemorySpace>
101 using discrete_element_type = DiscreteElement<DDim>;
114
115
116
117
118
119
120 Impl(std::initializer_list<
ddc::Coordinate<CDim>> breaks)
121 :
Impl(breaks.begin(), breaks.end())
126
127
128
129
130
131
132 explicit Impl(std::vector<
ddc::Coordinate<CDim>>
const& breaks)
133 :
Impl(breaks.begin(), breaks.end())
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 template <
class RandomIt>
156 Impl(RandomIt breaks_begin, RandomIt breaks_end);
159
160
161
162 template <
class OriginMemorySpace>
163 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
164 : m_knot_domain(impl.m_knot_domain)
165 , m_break_point_domain(impl.m_break_point_domain)
170
171
172
176
177
178
185
186
187
188
192
193
194
195
199
200
201
202
203
204
205
206
207
208
209
211 eval_basis(DSpan1D values,
ddc::Coordinate<CDim>
const& x)
const;
214
215
216
217
218
219
220
221
222
223
224
226 eval_deriv(DSpan1D derivs,
ddc::Coordinate<CDim>
const& x)
const;
229
230
231
232
233
234
235
236
237
238
239
240
243 ddc::Coordinate<CDim>
const& x,
244 std::size_t n)
const;
247
248
249
250
251
252
253
254
258 return ddc::DiscreteElement<knot_discrete_dimension_type>(
259 (ix - discrete_element_type(0)).value());
263
264
265
266
267
268
269
270
279
280
281
284 return ddc::coordinate(m_break_point_domain.front());
288
289
290
293 return ddc::coordinate(m_break_point_domain.back());
297
298
299
306
307
308
309
310
311
312
319
320
321
324 return discrete_domain_type(discrete_element_type(0), discrete_vector_type(
size()));
328
329
330
334 return m_break_point_domain;
338
339
340
341
342
345 return m_knot_domain.size() - 2 *
degree();
349
350
351
352
353
360
361
362
363
364
365
373 ddc::DiscreteElement<knot_discrete_dimension_type>
const& ic)
const
375 return discrete_element_type((ic - m_break_point_domain.front()).value());
379
380
381
382
384 ddc::Coordinate<CDim>
const& x)
const;
394
395
396
397
403template <
class RandomIt>
405 RandomIt
const breaks_begin,
406 RandomIt
const breaks_end)
408 ddc::DiscreteElement<knot_discrete_dimension_type>(0),
410 (breaks_end - breaks_begin)
412 , m_break_point_domain(
413 ddc::DiscreteElement<knot_discrete_dimension_type>(
degree()),
415 (breaks_end - breaks_begin)))
417 std::vector<
ddc::Coordinate<CDim>> knots((breaks_end - breaks_begin) + 2 *
degree());
420 for (RandomIt it = breaks_begin; it < breaks_end; ++it) {
424 ddc::Coordinate<CDim>
const rmin = knots[
degree()];
425 ddc::Coordinate<CDim>
const rmax = knots[(breaks_end - breaks_begin) +
degree() - 1];
430 double const period = rmax - rmin;
431 for (std::size_t i = 1; i <
degree() + 1; ++i) {
437 for (std::size_t i = 1; i <
degree() + 1; ++i) {
442 ddc::init_discrete_space<knot_discrete_dimension_type>(knots);
445template <
class CDim, std::size_t D>
446template <
class DDim,
class MemorySpace>
448 Impl<DDim, MemorySpace>::
eval_basis(DSpan1D values,
ddc::Coordinate<CDim>
const& x)
const
450 assert(values.size() == D + 1);
455 assert(x - rmin() >= -length() * 1e-14);
456 assert(rmax() - x >= -length() * 1e-14);
457 assert(values.size() == degree() + 1);
460 ddc::DiscreteElement<knot_discrete_dimension_type>
const icell = find_cell_start(x);
462 assert(icell >= m_break_point_domain.front());
463 assert(icell <= m_break_point_domain.back());
464 assert(ddc::coordinate(icell) - x <= length() * 1e-14);
465 assert(x - ddc::coordinate(icell + 1) <= length() * 1e-14);
470 for (std::size_t j = 0; j <
degree(); ++j) {
471 left[j] = x -
ddc::coordinate(icell - j);
472 right[j] =
ddc::coordinate(icell + j + 1) - x;
474 for (std::size_t r = 0; r < j + 1; ++r) {
475 temp = values[r] / (right[r] + left[j - r]);
476 values[r] = saved + right[r] * temp;
477 saved = left[j - r] * temp;
479 values[j + 1] = saved;
482 return get_first_bspline_in_cell(icell);
485template <
class CDim, std::size_t D>
486template <
class DDim,
class MemorySpace>
488 Impl<DDim, MemorySpace>::
eval_deriv(DSpan1D derivs,
ddc::Coordinate<CDim>
const& x)
const
493 assert(x - rmin() >= -length() * 1e-14);
494 assert(rmax() - x >= -length() * 1e-14);
495 assert(derivs.size() == degree() + 1);
498 ddc::DiscreteElement<knot_discrete_dimension_type>
const icell = find_cell_start(x);
500 assert(icell >= m_break_point_domain.front());
501 assert(icell <= m_break_point_domain.back());
502 assert(ddc::coordinate(icell) <= x);
503 assert(ddc::coordinate(icell + 1) >= x);
508
509
510
511
515 for (std::size_t j = 0; j <
degree() - 1; ++j) {
516 left[j] = x -
ddc::coordinate(icell - j);
517 right[j] =
ddc::coordinate(icell + j + 1) - x;
519 for (std::size_t r = 0; r < j + 1; ++r) {
520 temp = derivs[r] / (right[r] + left[j - r]);
521 derivs[r] = saved + right[r] * temp;
522 saved = left[j - r] * temp;
524 derivs[j + 1] = saved;
528
529
530
532 / (
ddc::coordinate(icell + 1) -
ddc::coordinate(icell + 1 -
degree()));
534 for (std::size_t j = 1; j <
degree(); ++j) {
537 / (
ddc::coordinate(icell + j + 1) -
ddc::coordinate(icell + j + 1 -
degree()));
538 derivs[j] = temp - saved;
542 return get_first_bspline_in_cell(icell);
545template <
class CDim, std::size_t D>
546template <
class DDim,
class MemorySpace>
548 Impl<DDim, MemorySpace>::eval_basis_and_n_derivs(
549 ddc::DSpan2D
const derivs,
550 ddc::Coordinate<CDim>
const& x,
551 std::size_t
const n)
const
556 std::array<
double, 2 * (
degree() + 1)> a_ptr;
557 Kokkos::mdspan<
double, Kokkos::extents<std::size_t,
degree() + 1, 2>>
const a(a_ptr.data());
560 Kokkos::mdspan<
double, Kokkos::extents<std::size_t,
degree() + 1,
degree() + 1>>
const ndu(
563 assert(x - rmin() >= -length() * 1e-14);
564 assert(rmax() - x >= -length() * 1e-14);
566 assert(n <= degree());
567 assert(derivs.extent(0) == 1 + degree());
568 assert(derivs.extent(1) == 1 + n);
571 ddc::DiscreteElement<knot_discrete_dimension_type>
const icell = find_cell_start(x);
573 assert(icell >= m_break_point_domain.front());
574 assert(icell <= m_break_point_domain.back());
575 assert(ddc::coordinate(icell) <= x);
576 assert(ddc::coordinate(icell + 1) >= x);
588 DDC_MDSPAN_ACCESS_OP(ndu, 0, 0) = 1.0;
589 for (std::size_t j = 0; j <
degree(); ++j) {
590 left[j] = x -
ddc::coordinate(icell - j);
591 right[j] =
ddc::coordinate(icell + j + 1) - x;
593 for (std::size_t r = 0; r < j + 1; ++r) {
596 DDC_MDSPAN_ACCESS_OP(ndu, r, j + 1) = 1.0 / (right[r] + left[j - r]);
599 temp = DDC_MDSPAN_ACCESS_OP(ndu, j, r) * DDC_MDSPAN_ACCESS_OP(ndu, r, j + 1);
600 DDC_MDSPAN_ACCESS_OP(ndu, j + 1, r) = saved + right[r] * temp;
601 saved = left[j - r] * temp;
603 DDC_MDSPAN_ACCESS_OP(ndu, j + 1, j + 1) = saved;
606 for (std::size_t j = 0; j <
degree() + 1; ++j) {
607 DDC_MDSPAN_ACCESS_OP(derivs, j, 0) = DDC_MDSPAN_ACCESS_OP(ndu, degree(), j);
610 for (
int r = 0; r <
int(
degree() + 1); ++r) {
613 DDC_MDSPAN_ACCESS_OP(a, 0, 0) = 1.0;
614 for (
int k = 1; k <
int(n + 1); ++k) {
616 int const rk = r - k;
619 DDC_MDSPAN_ACCESS_OP(a, 0, s2)
620 = DDC_MDSPAN_ACCESS_OP(a, 0, s1) * DDC_MDSPAN_ACCESS_OP(ndu, rk, pk + 1);
621 d = DDC_MDSPAN_ACCESS_OP(a, 0, s2) * DDC_MDSPAN_ACCESS_OP(ndu, pk, rk);
623 int const j1 = rk > -1 ? 1 : (-rk);
624 int const j2 = (r - 1) <= pk ? k : (
degree() - r + 1);
625 for (
int j = j1; j < j2; ++j) {
626 DDC_MDSPAN_ACCESS_OP(a, j, s2)
627 = (DDC_MDSPAN_ACCESS_OP(a, j, s1) - DDC_MDSPAN_ACCESS_OP(a, j - 1, s1))
628 * DDC_MDSPAN_ACCESS_OP(ndu, rk + j, pk + 1);
629 d += DDC_MDSPAN_ACCESS_OP(a, j, s2) * DDC_MDSPAN_ACCESS_OP(ndu, pk, rk + j);
632 DDC_MDSPAN_ACCESS_OP(a, k, s2) = -DDC_MDSPAN_ACCESS_OP(a, k - 1, s1)
633 * DDC_MDSPAN_ACCESS_OP(ndu, r, pk + 1);
634 d += DDC_MDSPAN_ACCESS_OP(a, k, s2) * DDC_MDSPAN_ACCESS_OP(ndu, pk, r);
636 DDC_MDSPAN_ACCESS_OP(derivs, r, k) = d;
637 Kokkos::kokkos_swap(s1, s2);
642 for (
int k = 1; k <
int(n + 1); ++k) {
643 for (std::size_t i = 0; i < derivs.extent(0); ++i) {
644 DDC_MDSPAN_ACCESS_OP(derivs, i, k) *= r;
649 return get_first_bspline_in_cell(icell);
652template <
class CDim, std::size_t D>
653template <
class DDim,
class MemorySpace>
656 D>::
Impl<DDim, MemorySpace>::find_cell_start(
ddc::Coordinate<CDim>
const& x)
const
658 assert(x - rmin() >= -length() * 1e-14);
659 assert(rmax() - x >= -length() * 1e-14);
662 return m_break_point_domain.front();
665 return m_break_point_domain.back() - 1;
669 ddc::DiscreteElement<knot_discrete_dimension_type> low = m_break_point_domain.front();
670 ddc::DiscreteElement<knot_discrete_dimension_type> high = m_break_point_domain.back();
671 ddc::DiscreteElement<knot_discrete_dimension_type> icell = low + (high - low) / 2;
672 while (x <
ddc::coordinate(icell) || x >=
ddc::coordinate(icell + 1)) {
673 if (x <
ddc::coordinate(icell)) {
678 icell = low + (high - low) / 2;
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
The top-level namespace of DDC.
constexpr bool is_non_uniform_bsplines_v
Indicates if a tag corresponds to non-uniform B-splines or not.