• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-Sn / opensn / 18671457779

20 Oct 2025 05:12PM UTC coverage: 74.776% (-0.02%) from 74.796%
18671457779

push

github

web-flow
Merge pull request #799 from andrsd/narr-conversion

Enable `bugprone-narrowing-conversions` check for clang-tidy linting

218 of 301 new or added lines in 42 files covered. (72.43%)

11 existing lines in 5 files now uncovered.

18208 of 24350 relevant lines covered (74.78%)

53805997.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.8
/framework/math/unknown_manager/unknown_manager.cc
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "framework/math/unknown_manager/unknown_manager.h"
5
#include "framework/logging/log.h"
6
#include "framework/runtime.h"
7

8
namespace opensn
9
{
10

11
std::size_t
12
UnknownManager::AddUnknown(UnknownType unk_type, unsigned int dimension)
124,841✔
13
{
14
  std::size_t last_unknown_end = 0;
124,841✔
15
  if (not unknowns.empty())
124,841✔
16
    last_unknown_end = unknowns.back().GetMapEnd() + 1;
50,986✔
17

18
  if (unk_type == UnknownType::SCALAR)
124,841✔
19
  {
20
    unknowns.emplace_back(UnknownType::SCALAR, 1, last_unknown_end);
73,138✔
21
    unknowns.back().name = "Unknown_" + std::to_string(unknowns.size() - 1);
73,138✔
22
  }
23
  else if (unk_type == UnknownType::VECTOR_2)
51,703✔
24
  {
NEW
25
    unknowns.emplace_back(UnknownType::VECTOR_2, 2, last_unknown_end);
×
26
    unknowns.back().name = "Unknown_" + std::to_string(unknowns.size() - 1);
×
27
  }
28
  else if (unk_type == UnknownType::VECTOR_3)
51,703✔
29
  {
NEW
30
    unknowns.emplace_back(UnknownType::VECTOR_3, 3, last_unknown_end);
×
31
    unknowns.back().name = "Unknown_" + std::to_string(unknowns.size() - 1);
×
32
  }
33
  else if (unk_type == UnknownType::VECTOR_N)
51,703✔
34
  {
35
    if (dimension == 0)
51,703✔
36
    {
37
      std::ostringstream oss;
×
38
      oss << "UnknownManager: When adding unknown of type VECTOR_N, dimension cannot be 0";
×
39
      throw std::runtime_error(oss.str());
×
40
    }
×
41

42
    unknowns.emplace_back(UnknownType::VECTOR_N, dimension, last_unknown_end);
51,703✔
43
    unknowns.back().name = "Unknown_" + std::to_string(unknowns.size() - 1);
51,703✔
44
  }
45
  else
46
    throw std::runtime_error(
×
47
      "UnknownManager: Invalid call to AddUnknown. Unknown type not supported.");
×
48

49
  return unknowns.size();
124,841✔
50
}
51

52
std::size_t
53
UnknownManager::MapUnknown(std::size_t unknown_id, unsigned int component) const
1,834,202,454✔
54
{
55
  if (unknown_id >= unknowns.size())
1,834,202,454✔
56
  {
57
    std::ostringstream oss;
×
58
    oss << "UnknownManager: Call to MapUnknown failed (id = " << unknown_id << ")";
×
59
    throw std::runtime_error(oss.str());
×
60
  }
×
61
  return unknowns[unknown_id].GetMap(component);
1,834,202,454✔
62
}
63

64
std::size_t
65
UnknownManager::GetTotalUnknownStructureSize() const
1,834,383,845✔
66
{
67
  if (unknowns.empty())
1,834,383,845✔
68
    return 0;
69

70
  return unknowns.back().GetMapEnd() + 1;
1,834,383,845✔
71
}
72

73
void
NEW
74
UnknownManager::SetUnknownNumOffBlockConnections(std::size_t unknown_id, int num_conn)
×
75
{
NEW
76
  if (unknown_id >= unknowns.size())
×
77
  {
78
    std::ostringstream oss;
×
79
    oss << "UnknownManager: Call to SetUnknownNumOffBlockConnections failed (id = " << unknown_id
×
80
        << ")";
×
81
    throw std::runtime_error(oss.str());
×
82
  }
×
83

84
  for (auto& val : unknowns[unknown_id].num_off_block_connections)
×
85
    val = num_conn;
×
86
}
×
87

88
void
NEW
89
UnknownManager::SetUnknownComponentNumOffBlockConnections(std::size_t unknown_id,
×
90
                                                          unsigned int component,
91
                                                          int num_conn)
92
{
NEW
93
  if (unknown_id >= unknowns.size())
×
94
  {
95
    std::ostringstream oss;
×
96
    oss << "UnknownManager: Call to SetUnknownComponentNumOffBlockConnections failed "
×
97
        << "(id = " << unknown_id << ")";
×
98
    throw std::runtime_error(oss.str());
×
99
  }
×
100

101
  if (component < 0 or component >= unknowns[unknown_id].num_components)
×
102
  {
103
    std::ostringstream oss;
×
104
    oss << "UnknownManager: Call to SetUnknownComponentNumOffBlockConnections failed "
×
105
        << "(component id = " << component << ")";
×
106
    throw std::runtime_error(oss.str());
×
107
  }
×
108

109
  unknowns[unknown_id].num_off_block_connections[component] = num_conn;
×
110
}
×
111

112
void
113
UnknownManager::SetUnknownName(std::size_t unknown_id, const std::string& unk_name)
72,775✔
114
{
115
  if (unknown_id >= unknowns.size())
72,775✔
116
  {
117
    std::ostringstream oss;
×
118
    oss << "UnknownManager: Call to SetUnknownName failed (id = " << unknown_id << ")";
×
119
    throw std::runtime_error(oss.str());
×
120
  }
×
121

122
  unknowns[unknown_id].name = unk_name;
72,775✔
123
}
72,775✔
124

125
void
126
UnknownManager::SetUnknownComponentName(std::size_t unknown_id,
72,908✔
127
                                        unsigned int component,
128
                                        const std::string& component_name)
129
{
130
  if (unknown_id >= unknowns.size())
72,908✔
131
  {
132
    std::ostringstream oss;
×
133
    oss << "UnknownManager: Call to SetUnknownComponentName failed (id = " << unknown_id << ")";
×
134
    throw std::runtime_error(oss.str());
×
135
  }
×
136

137
  if (component < 0 or component >= unknowns[unknown_id].num_components)
72,908✔
138
  {
139
    std::ostringstream oss;
×
140
    oss << "UnknownManager: Call to SetUnknownComponentName failed "
×
141
        << "(component id = " << component << ")";
×
142
    throw std::runtime_error(oss.str());
×
143
  }
×
144

145
  unknowns[unknown_id].component_names[component] = component_name;
72,908✔
146
}
72,908✔
147

148
} // namespace opensn
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc