• 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

92.31
/framework/parameters/input_parameters.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/parameters/parameter_block.h"
7
#include "framework/data_types/allowable_range.h"
8
#include <map>
9

10
namespace opensn
11
{
12

13
enum class InputParameterTag
14
{
15
  NONE = 0,
16
  OPTIONAL = 1,
17
  REQUIRED = 2
18
};
19

20
/// Class for handling input parameters.
21
class InputParameters : public ParameterBlock
22
{
23
public:
24
  InputParameters() = default;
17,235✔
25
  InputParameters& operator+=(InputParameters other);
26

27
  /// Sets the object type string for more descriptive error messages.
28
  void SetObjectType(const std::string& obj_type);
29

30
  /// Returns the object type string.
31
  std::string GetObjectType() const;
32

33
  /// Sets the class name to be applied to this object. If not used a default will be generated.
34
  void SetClassName(const std::string& class_name) { class_name_ = class_name; }
35

36
  /**
37
   * Sets a general description of the object that should be included with the object's
38
   * documentation.
39
   */
40
  void SetGeneralDescription(const std::string& description) { general_description_ = description; }
41
  std::string GetGeneralDescription() const { return general_description_; }
42

43
  /// Space separated list of doxygen group names to which this documentation should belong.
44

45
  /// Sets a link to the documentation of a different object.
46
  void LinkParameterToBlock(const std::string& param_name, const std::string& block_name);
47

48
  /// Gets any linkage information of a parameter.
49
  std::string GetParameterDocumentationLink(const std::string& param_name) const;
50

51
  /// Returns the parameter's doc string.
52
  std::string GetParameterDocString(const std::string& param_name);
53

54
  template <typename T>
55
  void AddOptionalParameter(const std::string& name, T value, const std::string& doc_string)
29,774✔
56
  {
57
    AddParameter(name, value);
29,774✔
58
    parameter_class_tags_[name] = InputParameterTag::OPTIONAL;
29,774✔
59
    parameter_doc_string_[name] = doc_string;
29,774✔
60
  }
29,774✔
61

62
  /// Specialization for block type parameters.
63
  void AddOptionalParameterBlock(const std::string& name,
64
                                 const ParameterBlock& block,
65
                                 const std::string& doc_string);
66

67
  template <typename T>
68
  void AddOptionalParameterArray(const std::string& name,
69
                                 const std::vector<T>& array,
70
                                 const std::string& doc_string)
71
  {
72
    AddParameter(name, array);
73
    parameter_class_tags_[name] = InputParameterTag::OPTIONAL;
74
    parameter_doc_string_[name] = doc_string;
75
  }
76

77
  /// Specialization for block type parameters.
78
  void AddOptionalParameterArray(const std::string& name,
79
                                 const std::vector<ParameterBlock>& array,
80
                                 const std::string& doc_string);
81

82
  template <typename T>
83
  void AddRequiredParameter(const std::string& name, const std::string& doc_string)
4,194✔
84
  {
85
    AddParameter(name, Varying::DefaultValue<T>());
4,194✔
86
    parameter_class_tags_[name] = InputParameterTag::REQUIRED;
4,194✔
87
    parameter_doc_string_[name] = doc_string;
4,194✔
88
  }
4,194✔
89

5,429✔
90
  /// Specialization for block type parameters.
91
  void AddRequiredParameterBlock(const std::string& name, const std::string& doc_string);
92

93
  /// Specialization for array type parameters.
94
  void AddRequiredParameterArray(const std::string& name, const std::string& doc_string);
95

96
  template <typename T>
97
  void ChangeExistingParamToOptional(const std::string& name,
1,080✔
98
                                     T value,
99
                                     const std::string& doc_string = "")
100
  {
101
    auto& param = GetParam(name);
1,080✔
102
    param = ParameterBlock(name, value);
1,080✔
103
    parameter_class_tags_[name] = InputParameterTag::OPTIONAL;
1,080✔
104
    if (not doc_string.empty())
1,080✔
UNCOV
105
      parameter_doc_string_[name] = doc_string;
×
106
  }
1,080✔
107

3,234✔
108
  template <typename T>
3,234✔
109
  void ChangeExistingParamToRequired(const std::string& name, const std::string& doc_string = "")
3,234✔
110
  {
3,234✔
111
    auto& param = GetParam(name);
3,234✔
UNCOV
112
    param = ParameterBlock(name, Varying::DefaultValue<T>());
×
113
    parameter_class_tags_[name] = InputParameterTag::REQUIRED;
758✔
114
    if (not doc_string.empty())
115
      parameter_doc_string_[name] = doc_string;
116
  }
117

118
  /// Assigns parameters with thorough type checks, deprecation checks, unused parameter checks.
119
  void AssignParameters(const ParameterBlock& params);
120

121
  /**
122
   * Returns the raw parameter block used at assignment. This can be used to see if a user supplied
123
   * an optional parameter or not.
124
   */
125
  const ParameterBlock& GetParametersAtAssignment() const { return param_block_at_assignment_; }
126

127
  bool IsParameterValid(const std::string& param_name) const;
128

129
  /// Marks a parameters as deprecated but will only produce a warning.
130
  void MarkParameterDeprecatedWarning(const std::string& param_name,
131
                                      const std::string& deprecation_message = "");
132

133
  /// Marks a parameters as deprecated and will produce an error if the parameter is specified.
134
  void MarkParameterDeprecatedError(const std::string& param_name,
135
                                    const std::string& deprecation_message = "");
136

137
  /// Marks a parameters as renamed and will produce an error if the parameter is specified.
138
  void MarkParameterRenamed(const std::string& param_name, const std::string& renaming_description);
139

140
  /// Creates a range based constraint for a given parameter.
141
  void ConstrainParameterRange(const std::string& param_name,
142
                               std::shared_ptr<AllowableRange> allowable_range);
143

144
  /// Sets a tag for the given parameter that will allow its type to be mismatched upon assignment.
145
  void SetParameterTypeMismatchAllowed(const std::string& param_name);
146

147
  /// Dumps the input parameters to stdout.
148
  void DumpParameters() const;
149

150
private:
151
  /// String to represent class name. If not provided a default will be generated.
152
  std::string class_name_;
153
  /// Space separated list of group names.
154
  std::string doc_group_;
155
  std::map<std::string, InputParameterTag> parameter_class_tags_;
156
  std::map<std::string, std::string> parameter_doc_string_;
157
  std::map<std::string, bool> parameter_valid_;
158
  std::map<std::string, std::string> deprecation_warning_tags_;
159
  std::map<std::string, std::string> deprecation_error_tags_;
160
  std::map<std::string, std::string> renamed_error_tags_;
161
  std::map<std::string, bool> type_mismatch_allowed_tags_;
162
  std::map<std::string, std::string> parameter_link_;
163

164
  std::map<std::string, std::shared_ptr<AllowableRange>> constraint_tags_;
165

166
  std::string general_description_;
167

168
  ParameterBlock param_block_at_assignment_;
169

170
public:
171
  template <typename T>
172
  static InputParameters MakeForObject(const ParameterBlock& params)
173
  {
174
    auto input_param = T::GetInputParameters();
175

176
    input_param.AssignParameters(params);
177
    return input_param;
178
  }
179

180
private:
181
  using ParameterBlock::AddParameter;
182

183
  /// Determines if a parameter is ignored.
184
  static bool IsParameterIgnored(const std::string& param_name);
185
  /// Parameter names to ignore when trying to assign. For now this "obj_type"
186
  static const std::vector<std::string> system_ignored_param_names_;
187
};
188

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