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

Open-Sn / opensn / 17170369288

22 Aug 2025 06:44PM UTC coverage: 74.605% (+0.2%) from 74.434%
17170369288

push

github

web-flow
Merge pull request #721 from andrsd/issue/557

Renaming `SteadyStateSolver` `SteadyStateSourceSolver`

13 of 14 new or added lines in 3 files covered. (92.86%)

239 existing lines in 24 files now uncovered.

17550 of 23524 relevant lines covered (74.6%)

45237948.15 hits per line

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

48.84
/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
4,785✔
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
    const Varying vvalue(value);
36
    std::stringstream outstr;
37

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

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

44
    return outstr.str();
45
  }
46

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

50
  virtual ~AllowableRange() = default;
51
};
52

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

59
public:
60
  template <typename T>
61
  AllowableRangeList(const std::initializer_list<T>& raw_list)
3,293✔
62
  {
3,293✔
63
    for (const auto& val : raw_list)
13,464✔
64
      list_.emplace_back(val);
10,171✔
65
  }
3,293✔
66

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

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

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

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

104
class AllowableRangeLowHighLimit;
105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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