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

Open-Sn / opensn / 20185909776

12 Dec 2025 06:55PM UTC coverage: 74.333% (+0.3%) from 74.037%
20185909776

push

github

web-flow
Merge pull request #859 from wdhawkins/td_source_driver

Adding time-dependent solver and time-dependent sources

367 of 398 new or added lines in 23 files covered. (92.21%)

113 existing lines in 28 files now uncovered.

18610 of 25036 relevant lines covered (74.33%)

68947552.69 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
5,245✔
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)
3,249✔
58
  {
3,249✔
59
    for (const auto& val : raw_list)
12,233✔
60
      list_.emplace_back(val);
8,984✔
61
  }
3,249✔
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)
3,249✔
72
  {
73
    return std::make_shared<AllowableRangeList>(raw_list);
3,249✔
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
1,745✔
84
  {
85
    return std::find(list_.begin(), list_.end(), value) != list_.end();
1,745✔
86
  }
87

UNCOV
88
  std::string AllowableRangeStr() const override
×
89
  {
90
    std::stringstream outstr;
×
UNCOV
91
    for (const auto& value : list_)
×
92
    {
93
      outstr << value;
×
UNCOV
94
      if (value != list_.back())
×
95
        outstr << ", ";
×
96
    }
97
    return outstr.str();
×
UNCOV
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)
1,968✔
111
    : low_limit_(Varying(low_value)), low_closed_(low_closed)
1,968✔
112
  {
113
  }
114

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

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

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

3,361✔
UNCOV
141
  const Varying low_limit_;
×
142
  bool low_closed_ = true;
×
UNCOV
143
};
×
UNCOV
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)
28✔
151
    : hi_limit_(Varying(hi_value)), hi_closed_(hi_closed)
28✔
152
  {
153
  }
154

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

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

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

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

182
  const Varying hi_limit_;
183
  bool hi_closed_ = true;
184
};
185

186
/// Upper and lower limit range
187
class AllowableRangeLowHighLimit : public AllowableRange
188
{
189
public:
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