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

Open-Sn / opensn / 21933416870

12 Feb 2026 03:12AM UTC coverage: 74.409% (-0.4%) from 74.806%
21933416870

push

github

web-flow
Merge pull request #922 from wdhawkins/named_xs

Adding ability to load user-specifed OpenMC cross sections

28 of 52 new or added lines in 4 files covered. (53.85%)

418 existing lines in 9 files now uncovered.

19839 of 26662 relevant lines covered (74.41%)

67886044.11 hits per line

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

52.73
/framework/data_types/allowable_range.h
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#pragma once
5

6
#include "framework/data_types/varying.h"
7
#include <string>
8
#include <utility>
9
#include <vector>
10
#include <algorithm>
11
#include <sstream>
12

13
namespace opensn
14
{
15

16
/// Base class for an allowable range.
17
class AllowableRange
9,125✔
18
{
19
public:
20
  /// Returns `true` is the value is within the allowable range.
21
  template <typename T>
22
  bool IsAllowable(const T& value)
23
  {
24
    return ChildIsAllowable(Varying(value));
25
  }
26

27
  /// Provides a formatted string of the message to display if a value is out of range.
28
  template <typename T>
29
  std::string OutOfRangeString(const std::string& scope, const T& value) const
30
  {
31
    std::stringstream outstr;
32

33
    if (not scope.empty())
34
      outstr << "Parameter \"" << scope << "\": ";
35

36
    outstr << "Value " << value << " out of range. ";
37
    outstr << "Constraints: " << AllowableRangeStr() << ".";
38

39
    return outstr.str();
40
  }
41

42
  /// Prints the allowable constraints to a string.
43
  std::string PrintRange() { return AllowableRangeStr(); }
44

45
  virtual ~AllowableRange() = default;
46

47
protected:
48
  virtual bool ChildIsAllowable(Varying value) const = 0;
49
  virtual std::string AllowableRangeStr() const = 0;
50
};
51

52
/// Range comprising a list of values
53
class AllowableRangeList : public AllowableRange
54
{
55
public:
56
  template <typename T>
57
  AllowableRangeList(const std::initializer_list<T>& raw_list)
5,735✔
58
  {
5,735✔
59
    for (const auto& val : raw_list)
23,007✔
60
      list_.emplace_back(val);
17,272✔
61
  }
5,735✔
62

63
  template <typename T>
64
  AllowableRangeList(const std::vector<T>& raw_list)
65
  {
66
    for (const auto& val : raw_list)
67
      list_.emplace_back(val);
68
  }
69

70
  template <typename T>
71
  static std::shared_ptr<AllowableRangeList> New(const std::initializer_list<T>& raw_list)
5,735✔
72
  {
73
    return std::make_shared<AllowableRangeList>(raw_list);
5,735✔
74
  }
75

76
  template <typename T>
77
  static std::shared_ptr<AllowableRangeList> New(const std::vector<T>& raw_list)
78
  {
79
    return std::make_shared<AllowableRangeList>(raw_list);
80
  }
81

82
protected:
83
  bool ChildIsAllowable(Varying value) const override
3,441✔
84
  {
85
    return std::find(list_.begin(), list_.end(), value) != list_.end();
3,441✔
86
  }
87

88
  std::string AllowableRangeStr() const override
×
89
  {
90
    std::stringstream outstr;
×
91
    for (const auto& value : list_)
×
92
    {
93
      outstr << value;
×
94
      if (value != list_.back())
×
95
        outstr << ", ";
×
96
    }
97
    return outstr.str();
×
98
  }
×
99

100
  std::vector<Varying> list_;
101
};
102

103
class AllowableRangeLowHighLimit;
104

105
/// Lower limit range.
106
class AllowableRangeLowLimit : public AllowableRange
107
{
108
public:
109
  template <typename T>
110
  explicit AllowableRangeLowLimit(const T& low_value, bool low_closed = true)
3,234✔
111
    : low_limit_(Varying(low_value)), low_closed_(low_closed)
3,234✔
112
  {
113
  }
114

115
  template <typename T>
116
  static std::shared_ptr<AllowableRangeLowLimit> New(const T& low_value, bool low_closed = true)
3,234✔
117
  {
118
    return std::make_shared<AllowableRangeLowLimit>(low_value, low_closed);
3,234✔
119
  }
120

121
protected:
122
  friend class AllowableRangeLowHighLimit;
123
  bool ChildIsAllowable(Varying value) const override
2,178✔
124
  {
125
    if (value.GetType() != low_limit_.GetType())
2,178✔
126
      return false;
127

128
    if (low_closed_)
2,178✔
129
      return value >= low_limit_;
1,984✔
130
    else
131
      return value > low_limit_;
194✔
132
  }
133
  std::string AllowableRangeStr() const override
×
134
  {
135
    if (low_closed_)
×
136
      return std::string(">= ") + low_limit_.PrintStr();
×
137
    else
138
      return std::string("> ") + low_limit_.PrintStr();
×
139
  }
140

141
  const Varying low_limit_;
142
  bool low_closed_ = true;
143
};
144

145
/// Upper limit range
146
class AllowableRangeHighLimit : public AllowableRange
147
{
148
public:
149
  template <typename T>
150
  explicit AllowableRangeHighLimit(const T& hi_value, bool hi_closed = true)
156✔
151
    : hi_limit_(Varying(hi_value)), hi_closed_(hi_closed)
156✔
152
  {
153
  }
154

155
  template <typename T>
156
  static std::shared_ptr<AllowableRangeHighLimit> New(const T& hi_value, bool hi_closed = true)
156✔
157
  {
158
    return std::make_shared<AllowableRangeHighLimit>(hi_value, hi_closed);
156✔
159
  }
160

161
protected:
162
  friend class AllowableRangeLowHighLimit;
163
  bool ChildIsAllowable(Varying value) const override
48✔
164
  {
165
    if (value.GetType() != hi_limit_.GetType())
48✔
166
      return false;
167

168
    if (hi_closed_)
48✔
169
      return value <= hi_limit_;
48✔
170
    else
171
      return value < hi_limit_;
×
172
  }
173

174
  std::string AllowableRangeStr() const override
×
175
  {
176
    if (hi_closed_)
×
177
      return std::string("<= ") + hi_limit_.PrintStr();
×
178
    else
179
      return std::string("< ") + hi_limit_.PrintStr();
×
180
  }
5,667✔
181

5,667✔
UNCOV
182
  const Varying hi_limit_;
×
UNCOV
183
  bool hi_closed_ = true;
×
UNCOV
184
};
×
UNCOV
185

×
UNCOV
186
/// Upper and lower limit range
×
UNCOV
187
class AllowableRangeLowHighLimit : public AllowableRange
×
UNCOV
188
{
×
UNCOV
189
public:
×
UNCOV
190
  template <typename T>
×
191
  explicit AllowableRangeLowHighLimit(const T& low_value,
192
                                      const T& hi_value,
193
                                      bool low_closed = true,
194
                                      bool hi_closed = true)
195
    : low_range_(Varying(low_value), low_closed), hi_range(Varying(hi_value), hi_closed)
196
  {
197
  }
198

199
  template <typename T>
200
  static std::shared_ptr<AllowableRangeLowHighLimit>
201
  New(const T& low_value, const T& hi_value, bool low_closed = true, bool hi_closed = true)
202
  {
203
    return std::make_shared<AllowableRangeLowHighLimit>(low_value, hi_value, low_closed, hi_closed);
204
  }
205

206
protected:
207
  bool ChildIsAllowable(Varying value) const override
208
  {
209
    return low_range_.ChildIsAllowable(value) and hi_range.ChildIsAllowable(value);
210
  }
211
  std::string AllowableRangeStr() const override
212
  {
213

214
    return low_range_.AllowableRangeStr() + ", " + hi_range.AllowableRangeStr();
215
  }
216

217
  AllowableRangeLowLimit low_range_;
218
  AllowableRangeHighLimit hi_range;
219
};
220

221
} // 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