GCC Code Coverage Report


Directory: src/oiseau/
File: src/oiseau/dg/nodal/ref_element.cpp
Date: 2025-05-24 01:28:39
Exec Total Coverage
Lines: 0 30 0.0%
Functions: 0 2 0.0%
Branches: 0 28 0.0%

Line Branch Exec Source
1 // Copyright (C) 2025 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
16 #include "oiseau/dg/nodal/ref_hexahedron.hpp"
17 #include "oiseau/dg/nodal/ref_line.hpp"
18 #include "oiseau/dg/nodal/ref_quadrilateral.hpp"
19 #include "oiseau/dg/nodal/ref_tetrahedron.hpp"
20 #include "oiseau/dg/nodal/ref_triangle.hpp"
21
22 namespace oiseau::dg::nodal {
23
24 std::shared_ptr<RefElement> get_ref_element(RefElementType type, unsigned order) {
25 using Key = std::pair<RefElementType, unsigned>;
26
27 struct KeyHash {
28 std::size_t operator()(const Key& k) const {
29 return std::hash<int>()(static_cast<int>(k.first)) ^ std::hash<unsigned>()(k.second);
30 }
31 };
32
33 static std::unordered_map<Key, std::shared_ptr<RefElement>, KeyHash> cache;
34
35 Key key{type, order};
36 auto it = cache.find(key);
37 if (it != cache.end()) {
38 return it->second;
39 }
40
41 std::shared_ptr<RefElement> elem;
42 switch (type) {
43 case RefElementType::Line:
44 elem = std::make_shared<RefLine>(order);
45 break;
46 case RefElementType::Triangle:
47 elem = std::make_shared<RefTriangle>(order);
48 break;
49 case RefElementType::Quadrilateral:
50 elem = std::make_shared<RefQuadrilateral>(order);
51 break;
52 case RefElementType::Tetrahedron:
53 elem = std::make_shared<RefTetrahedron>(order);
54 break;
55 case RefElementType::Hexahedron:
56 elem = std::make_shared<RefHexahedron>(order);
57 break;
58 default:
59 throw std::invalid_argument("Unknown element type");
60 }
61
62 cache[key] = elem;
63 return elem;
64 }
65
66 } // namespace oiseau::dg::nodal
67