| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2026 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #include "oiseau/dg/nodal/ref_line.hpp" | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | #include <xtensor-blas/xlinalg.hpp> | ||
| 11 | #include <xtensor/core/xshape.hpp> | ||
| 12 | #include <xtensor/core/xtensor_forward.hpp> | ||
| 13 | #include <xtensor/misc/xmanipulation.hpp> | ||
| 14 | #include <xtensor/views/xslice.hpp> | ||
| 15 | #include <xtensor/views/xview.hpp> | ||
| 16 | |||
| 17 | #include "oiseau/dg/nodal/ref_element.hpp" | ||
| 18 | #include "oiseau/utils/integration.hpp" | ||
| 19 | #include "oiseau/utils/math.hpp" | ||
| 20 | |||
| 21 | namespace oiseau::dg::nodal { | ||
| 22 | |||
| 23 | 47 | RefLine::RefLine(unsigned order) : RefElement(order) { | |
| 24 | 46 | this->m_np = order + 1; | |
| 25 | 46 | this->m_nfp = 1; | |
| 26 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | this->m_r = detail::generate_line_nodes(this->m_order); |
| 27 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | this->m_v = RefLine::vandermonde(this->m_r); |
| 28 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | this->m_gv = this->grad_vandermonde(this->m_r); |
| 29 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | this->m_d = this->grad_operator(this->m_v, this->m_gv); |
| 30 | 46 | } | |
| 31 | |||
| 32 | 763 | xt::xarray<double> RefLine::basis_function(const xt::xarray<double>& r, int i) { | |
| 33 | 763 | return oiseau::utils::jacobi_p(i, 0.0, 0.0, r); | |
| 34 | } | ||
| 35 | |||
| 36 | 227 | xt::xarray<double> RefLine::grad_basis_function(const xt::xarray<double>& r, int i) { | |
| 37 | 227 | return oiseau::utils::grad_jacobi_p(i, 0.0, 0.0, r); | |
| 38 | } | ||
| 39 | |||
| 40 | 307 | xt::xarray<double> RefLine::vandermonde(const xt::xarray<double>& r) const { | |
| 41 | 307 | const auto n_points = r.shape()[0]; | |
| 42 | 307 | const auto n_basis = this->m_np; // order + 1 | |
| 43 |
2/4✓ Branch 1 taken 307 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 307 times.
✗ Branch 5 not taken.
|
307 | xt::xarray<double> output(xt::dynamic_shape<std::size_t>({n_points, n_basis})); |
| 44 |
2/2✓ Branch 0 taken 763 times.
✓ Branch 1 taken 307 times.
|
1070 | for (std::size_t i = 0; i <= this->m_order; ++i) { |
| 45 |
3/6✓ Branch 1 taken 763 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 763 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 763 times.
✗ Branch 9 not taken.
|
763 | xt::view(output, xt::all(), i) = this->basis_function(r, i); |
| 46 | } | ||
| 47 | 307 | return output; | |
| 48 | ✗ | } | |
| 49 | |||
| 50 | 46 | xt::xarray<double> RefLine::grad_vandermonde(const xt::xarray<double>& r) const { | |
| 51 | 46 | const auto n_points = r.shape()[0]; | |
| 52 | 46 | const auto n_basis = this->m_np; // order + 1 | |
| 53 |
2/4✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
|
46 | xt::xarray<double> output(xt::dynamic_shape<std::size_t>({n_points, n_basis})); |
| 54 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 46 times.
|
268 | for (size_t i = 0; i <= this->m_order; ++i) { |
| 55 |
3/6✓ Branch 1 taken 222 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 222 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 222 times.
✗ Branch 9 not taken.
|
222 | xt::view(output, xt::all(), i) = grad_basis_function(r, i); |
| 56 | } | ||
| 57 | 46 | return output; | |
| 58 | ✗ | } | |
| 59 | |||
| 60 | 46 | xt::xarray<double> RefLine::grad_operator(const xt::xarray<double>& v, | |
| 61 | const xt::xarray<double>& gv) { | ||
| 62 |
2/4✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 46 times.
✗ Branch 8 not taken.
|
46 | return xt::transpose(xt::linalg::solve(xt::transpose(v), xt::transpose(gv))); |
| 63 | } | ||
| 64 | |||
| 65 | } // namespace oiseau::dg::nodal | ||
| 66 | |||
| 67 | namespace oiseau::dg::nodal::detail { | ||
| 68 | |||
| 69 | 46 | xt::xarray<double> generate_line_nodes(unsigned order) { | |
| 70 | 46 | return oiseau::utils::integration::jacobi_gl(order, 0.0, 0.0); | |
| 71 | } | ||
| 72 | } // namespace oiseau::dg::nodal::detail | ||
| 73 |