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

Open-Sn / opensn / 18300593117

06 Oct 2025 10:47PM UTC coverage: 74.862% (-0.2%) from 75.031%
18300593117

push

github

web-flow
Merge pull request #759 from wdhawkins/performance

Sweep performance optimizations

294 of 302 new or added lines in 15 files covered. (97.35%)

334 existing lines in 80 files now uncovered.

17788 of 23761 relevant lines covered (74.86%)

61852783.95 hits per line

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

50.0
/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
18
{
19
protected:
20
  virtual bool ChildIsAllowable(Varying value) const = 0;
21
  virtual std::string AllowableRangeStr() const = 0;
22

23
public:
24
  /// Returns `true` is the value is within the allowable range.
25
  template <typename T>
26
  bool IsAllowable(const T& value)
27
  {
28
    return ChildIsAllowable(Varying(value));
29
  }
30

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

37
    if (not scope.empty())
38
      outstr << "Parameter \"" << scope << "\": ";
39

40
    outstr << "Value " << value << " out of range. ";
41
    outstr << "Constraints: " << AllowableRangeStr() << ".";
42

43
    return outstr.str();
44
  }
45

46
  /// Prints the allowable constraints to a string.
47
  std::string PrintRange() { return AllowableRangeStr(); }
48

49
  virtual ~AllowableRange() = default;
5,081✔
50
};
51

52
/// Range comprising a list of values
53
class AllowableRangeList : public AllowableRange
54
{
55
protected:
56
  std::vector<Varying> list_;
57

58
public:
59
  template <typename T>
60
  AllowableRangeList(const std::initializer_list<T>& raw_list)
3,461✔
61
  {
3,461✔
62
    for (const auto& val : raw_list)
14,936✔
63
      list_.emplace_back(val);
11,475✔
64
  }
3,461✔
65

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

73
  template <typename T>
74
  static std::shared_ptr<AllowableRangeList> New(const std::initializer_list<T>& raw_list)
3,461✔
75
  {
76
    return std::make_shared<AllowableRangeList>(raw_list);
3,461✔
77
  }
78

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

85
protected:
86
  bool ChildIsAllowable(Varying value) const override
2,103✔
87
  {
88
    return std::find(list_.begin(), list_.end(), value) != list_.end();
2,103✔
89
  }
UNCOV
90
  std::string AllowableRangeStr() const override
×
91
  {
UNCOV
92
    std::stringstream outstr;
×
93
    for (const auto& value : list_)
×
94
    {
UNCOV
95
      outstr << value;
×
96
      if (value != list_.back())
×
97
        outstr << ", ";
×
98
    }
UNCOV
99
    return outstr.str();
×
100
  }
×
101
};
102

103
class AllowableRangeLowHighLimit;
104

105
/// Lower limit range.
106
class AllowableRangeLowLimit : public AllowableRange
107
{
108
protected:
109
  const Varying low_limit_;
110
  bool low_closed_ = true;
111

112
public:
113
  template <typename T>
114
  explicit AllowableRangeLowLimit(const T& low_value, bool low_closed = true)
1,620✔
115
    : low_limit_(Varying(low_value)), low_closed_(low_closed)
1,620✔
116
  {
117
  }
1,620✔
118

119
  template <typename T>
120
  static std::shared_ptr<AllowableRangeLowLimit> New(const T& low_value, bool low_closed = true)
1,620✔
121
  {
122
    return std::make_shared<AllowableRangeLowLimit>(low_value, low_closed);
1,620✔
123
  }
124

125
protected:
126
  friend class AllowableRangeLowHighLimit;
127
  bool ChildIsAllowable(Varying value) const override
1,349✔
128
  {
129
    if (value.GetType() != low_limit_.GetType())
1,349✔
UNCOV
130
      return false;
×
131

132
    if (low_closed_)
1,349✔
133
      return value >= low_limit_;
1,177✔
134
    else
135
      return value > low_limit_;
172✔
136
  }
UNCOV
137
  std::string AllowableRangeStr() const override
×
138
  {
UNCOV
139
    if (low_closed_)
×
140
      return std::string(">= ") + low_limit_.PrintStr();
×
141
    else
UNCOV
142
      return std::string("> ") + low_limit_.PrintStr();
×
143
  }
3,452✔
144
};
3,452✔
UNCOV
145

×
146
/// Upper limit range
×
147
class AllowableRangeHighLimit : public AllowableRange
×
148
{
×
149
protected:
×
150
  const Varying hi_limit_;
×
151
  bool hi_closed_ = true;
×
152

×
153
public:
×
154
  template <typename T>
155
  explicit AllowableRangeHighLimit(const T& hi_value, bool hi_closed = true)
156
    : hi_limit_(Varying(hi_value)), hi_closed_(hi_closed)
157
  {
158
  }
159

160
  template <typename T>
161
  static std::shared_ptr<AllowableRangeHighLimit> New(const T& hi_value, bool hi_closed = true)
162
  {
163
    return std::make_shared<AllowableRangeHighLimit>(hi_value, hi_closed);
164
  }
165

166
protected:
167
  friend class AllowableRangeLowHighLimit;
168
  bool ChildIsAllowable(Varying value) const override
169
  {
170
    if (value.GetType() != hi_limit_.GetType())
171
      return false;
172

173
    if (hi_closed_)
174
      return value <= hi_limit_;
175
    else
176
      return value < hi_limit_;
177
  }
178
  std::string AllowableRangeStr() const override
179
  {
180
    if (hi_closed_)
181
      return std::string("<= ") + hi_limit_.PrintStr();
182
    else
183
      return std::string("< ") + hi_limit_.PrintStr();
184
  }
185
};
186

187
/// Upper and lower limit range
188
class AllowableRangeLowHighLimit : public AllowableRange
189
{
190
protected:
191
  AllowableRangeLowLimit low_range_;
192
  AllowableRangeHighLimit hi_range;
193

194
public:
195
  template <typename T>
196
  explicit AllowableRangeLowHighLimit(const T& low_value,
197
                                      const T& hi_value,
198
                                      bool low_closed = true,
199
                                      bool hi_closed = true)
200
    : low_range_(Varying(low_value), low_closed), hi_range(Varying(hi_value), hi_closed)
201
  {
202
  }
203

204
  template <typename T>
205
  static std::shared_ptr<AllowableRangeLowHighLimit>
206
  New(const T& low_value, const T& hi_value, bool low_closed = true, bool hi_closed = true)
207
  {
208
    return std::make_shared<AllowableRangeLowHighLimit>(low_value, hi_value, low_closed, hi_closed);
209
  }
210

211
protected:
212
  bool ChildIsAllowable(Varying value) const override
213
  {
214
    return low_range_.ChildIsAllowable(value) and hi_range.ChildIsAllowable(value);
215
  }
216
  std::string AllowableRangeStr() const override
217
  {
218

219
    return low_range_.AllowableRangeStr() + ", " + hi_range.AllowableRangeStr();
220
  }
221
};
222

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