| 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_element.hpp" | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | #include <functional> | ||
| 11 | #include <memory> | ||
| 12 | #include <stdexcept> | ||
| 13 | #include <unordered_map> | ||
| 14 | #include <utility> | ||
| 15 | #include <xtensor-blas/xlinalg.hpp> | ||
| 16 | #include <xtensor/core/xtensor_forward.hpp> | ||
| 17 | #include <xtensor/misc/xmanipulation.hpp> | ||
| 18 | |||
| 19 | #include "oiseau/dg/nodal/ref_hexahedron.hpp" | ||
| 20 | #include "oiseau/dg/nodal/ref_line.hpp" | ||
| 21 | #include "oiseau/dg/nodal/ref_quadrilateral.hpp" | ||
| 22 | #include "oiseau/dg/nodal/ref_tetrahedron.hpp" | ||
| 23 | #include "oiseau/dg/nodal/ref_triangle.hpp" | ||
| 24 | |||
| 25 | namespace oiseau::dg::nodal { | ||
| 26 | |||
| 27 | 41 | xt::xarray<double> RefElement::mass() const { | |
| 28 |
1/2✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
|
41 | const auto inverse = inv_v(); |
| 29 |
1/2✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
|
123 | return xt::linalg::dot(xt::transpose(inverse), inverse); |
| 30 | 41 | } | |
| 31 | |||
| 32 |
1/2✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
|
41 | xt::xarray<double> RefElement::inv_mass() const { return xt::linalg::dot(m_v, xt::transpose(m_v)); } |
| 33 | |||
| 34 |
2/4✓ Branch 1 taken 83 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 83 times.
✗ Branch 5 not taken.
|
83 | xt::xarray<double> RefElement::inv_v() const { return xt::linalg::inv(m_v); } |
| 35 | |||
| 36 | 736 | std::shared_ptr<RefElement> get_ref_element(RefElementType type, unsigned order) { | |
| 37 | using Key = std::pair<RefElementType, unsigned>; | ||
| 38 | |||
| 39 | struct KeyHash { | ||
| 40 | 811 | std::size_t operator()(const Key& k) const { | |
| 41 | 811 | return std::hash<int>()(static_cast<int>(k.first)) ^ std::hash<unsigned>()(k.second); | |
| 42 | } | ||
| 43 | }; | ||
| 44 | |||
| 45 |
3/4✓ Branch 0 taken 28 times.
✓ Branch 1 taken 708 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
736 | static std::unordered_map<Key, std::shared_ptr<RefElement>, KeyHash> cache; |
| 46 | |||
| 47 | 736 | Key key{type, order}; | |
| 48 |
1/2✓ Branch 1 taken 736 times.
✗ Branch 2 not taken.
|
736 | auto it = cache.find(key); |
| 49 |
2/2✓ Branch 2 taken 661 times.
✓ Branch 3 taken 75 times.
|
736 | if (it != cache.end()) { |
| 50 | 661 | return it->second; | |
| 51 | } | ||
| 52 | |||
| 53 | 75 | std::shared_ptr<RefElement> elem; | |
| 54 |
5/6✓ Branch 0 taken 11 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
75 | switch (type) { |
| 55 | 11 | case RefElementType::Line: | |
| 56 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | elem = std::make_shared<RefLine>(order); |
| 57 | 11 | break; | |
| 58 | 32 | case RefElementType::Triangle: | |
| 59 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | elem = std::make_shared<RefTriangle>(order); |
| 60 | 32 | break; | |
| 61 | 25 | case RefElementType::Quadrilateral: | |
| 62 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
25 | elem = std::make_shared<RefQuadrilateral>(order); |
| 63 | 25 | break; | |
| 64 | 6 | case RefElementType::Tetrahedron: | |
| 65 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | elem = std::make_shared<RefTetrahedron>(order); |
| 66 | 6 | break; | |
| 67 | 1 | case RefElementType::Hexahedron: | |
| 68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | elem = std::make_shared<RefHexahedron>(order); |
| 69 | 1 | break; | |
| 70 | ✗ | default: | |
| 71 | ✗ | throw std::invalid_argument("Unknown element type"); | |
| 72 | } | ||
| 73 | |||
| 74 |
1/2✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
|
75 | cache[key] = elem; |
| 75 | 75 | return elem; | |
| 76 | 75 | } | |
| 77 | |||
| 78 | } // namespace oiseau::dg::nodal | ||
| 79 |