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

Open-Sn / opensn / 16766938693

05 Aug 2025 03:26PM UTC coverage: 73.386% (+0.1%) from 73.282%
16766938693

push

github

web-flow
Merge pull request #693 from andrsd/move-bnds

Moving sweep boundaries into `DiscreteOrdinatesProblem`

247 of 311 new or added lines in 19 files covered. (79.42%)

625 existing lines in 49 files now uncovered.

18320 of 24964 relevant lines covered (73.39%)

43106214.05 hits per line

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

91.55
/python/lib/xs.cc
1
// SPDX-FileCopyrightText: 2025 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "python/lib/py_wrappers.h"
5
#include "framework/runtime.h"
6
#include "framework/materials/multi_group_xs/multi_group_xs.h"
7
#include <pybind11/stl.h>
8
#include <memory>
9
#include <string>
10
#include <vector>
11

12
#define XS_GETTER(method_name) [](MultiGroupXS& self) { return convert_vector(self.method_name()); }
13

14
namespace opensn
15
{
16

17
// Wrap multi-group cross section
18
void
19
WrapMultiGroupXS(py::module& xs)
380✔
20
{
21
  // clang-format off
22
  // multi-group cross section
23
  auto multigroup_xs = py::class_<MultiGroupXS, std::shared_ptr<MultiGroupXS>>(
380✔
24
    xs,
25
    "MultiGroupXS",
26
    R"(
27
    Multi-group cross section.
28

29
    Wrapper of :cpp:class:`opensn::MultiGroupXS`.
30
    )"
31
  );
380✔
32
  multigroup_xs.def(
760✔
33
    py::init(
380✔
34
      []()
393✔
35
      {
36
        std::shared_ptr<MultiGroupXS> xs = std::make_shared<MultiGroupXS>();
393✔
37
        multigroup_xs_stack.push_back(xs);
393✔
38
        return xs;
393✔
UNCOV
39
      }),
×
40
    "Create an empty multi-group cross section."
41
  );
42
  multigroup_xs.def(
380✔
43
    "CreateSimpleOneGroup",
44
    [](MultiGroupXS& self, double sigma_t, double c) {
456✔
45
      self.Initialize(sigma_t, c);
76✔
46
    },
47
    R"(
48
    Create a one-group cross section.
49

50
    Parameters
51
    ----------
52
    sigma_t: float
53
        Total cross section.
54
    c: float
55
        Scattering ratio.
56
    )",
57
    py::arg("sigma_t"),
760✔
58
    py::arg("c")
380✔
59
  );
60
  multigroup_xs.def(
380✔
61
    "LoadFromOpenSn",
62
    [](MultiGroupXS& self, const std::string& file_name)
632✔
63
    {
64
      self.Initialize(file_name);
252✔
65
    },
66
    py::arg("file_name"),
380✔
67
    R"(
68
    Load multi-group cross sections from an OpenSn cross section input file.
69

70
    Format is as follows (for transfers, gprime denotes the departing group and g is the arrival
71
    group).
72

73
    .. code-block:: none
74

75
       # Add comment lines, as needed
76
       NUM_GROUPS ng
77
       NUM_MOMENTS nmom
78

79
       SIGMA_T_BEGIN
80
       0 value
81
       .
82
       .
83
       ng-1 value
84
       SIGMA_T_END
85

86
       SIGMA_A_BEGIN
87
       0 value
88
       .
89
       .
90
       ng-1 value
91
       SIGMA_A_END
92

93
       TRANSFER_MOMENTS_BEGIN
94
       M_GPRIME_G_VAL 0 0 0 value
95
       .
96
       M_GPRIME_G_VAL moment gprime g value
97
       .
98
       M_GPRIME_G_VAL nmom-1 ng-1 ng-1 value
99
       TRANSFER_MOMENTS_END
100
    )"
101
  );
102
  multigroup_xs.def(
380✔
103
    "Combine",
104
    [](MultiGroupXS& self, const std::vector<std::pair<std::shared_ptr<MultiGroupXS>, double>>& combinations)
381✔
105
    {
106
      self.Initialize(combinations);
1✔
107
    },
108
    R"(
109
    Combine cross-section
110

111
    Parameters
112
    ----------
113

114
    combinations: List[Tuple[pyopensn.xs.MultiGroupXS, float]]
115
        List of combinations (cross section, factor)
116

117
    Examples
118
    --------
119

120
    >>> xs_1 = MultiGroupXS()
121
    >>> xs_1.CreateSimpleOneGroup(sigma_t=1, c=0.5)
122
    >>> xs_2 = MultiGroupXS()
123
    >>> xs_2.CreateSimpleOneGroup(sigma_t=2, c=1./3.)
124
    >>> xs_combined = MultiGroupXS()
125
    >>> combo = [
126
    ...     ( xs_1, 0.5 ),
127
    ...     ( xs_2, 3.0 )
128
    ... ]
129
    >>> xs_combined.Combine(combo)
130
    )",
131
    py::arg("combinations")
380✔
132
  );
133
  multigroup_xs.def(
380✔
134
    "LoadFromOpenMC",
135
    [](MultiGroupXS& self, const std::string& file_name, const std::string& dataset_name,
444✔
136
       double temperature)
137
    {
138
      self.Initialize(file_name, dataset_name, temperature);
64✔
139
    },
140
    "Load multi-group cross sections from an OpenMC cross-section file.",
141
    py::arg("file_name"),
760✔
142
    py::arg("dataset_name"),
760✔
143
    py::arg("temperature")
380✔
144
  );
145
  multigroup_xs.def(
380✔
146
    "SetScalingFactor",
147
    &MultiGroupXS::SetScalingFactor,
760✔
148
    "Scale the cross sections by the specified factor.",
149
    py::arg("factor")
380✔
150
  );
151
  multigroup_xs.def_property_readonly(
380✔
152
    "num_groups",
153
    &MultiGroupXS::GetNumGroups,
380✔
154
    "Get number of energy groups."
155
  );
156
  multigroup_xs.def_property_readonly(
380✔
157
    "scattering_order",
158
    &MultiGroupXS::GetScatteringOrder,
380✔
159
    "Get Legendre scattering order."
160
  );
161
  multigroup_xs.def_property_readonly(
380✔
162
    "num_precursors",
163
    &MultiGroupXS::GetNumPrecursors,
380✔
164
    "Get number of precursors."
165
  );
166
  multigroup_xs.def_property_readonly(
380✔
167
    "is_fissionable",
168
    &MultiGroupXS::IsFissionable,
380✔
169
    "Check if the material is fissile."
170
  );
171
  multigroup_xs.def_property_readonly(
380✔
172
    "scaling_factor",
173
    &MultiGroupXS::GetScalingFactor,
380✔
174
    "Get the arbitrary scaling factor."
175
  );
176
  multigroup_xs.def_property_readonly(
380✔
177
    "sigma_t",
178
    XS_GETTER(GetSigmaTotal),
7✔
179
    "Get total cross section.",
180
    py::keep_alive<0, 1>()
380✔
181
  );
182
  multigroup_xs.def_property_readonly(
380✔
183
    "sigma_a",
184
    XS_GETTER(GetSigmaAbsorption),
8✔
185
    "Get absorption cross section.",
186
    py::keep_alive<0, 1>()
380✔
187
  );
188
  multigroup_xs.def_property_readonly(
380✔
189
    "sigma_f",
UNCOV
190
    XS_GETTER(GetSigmaFission),
×
191
    "Get fission cross section.",
192
    py::keep_alive<0, 1>()
380✔
193
  );
194
  multigroup_xs.def_property_readonly(
380✔
195
    "chi",
196
    XS_GETTER(GetChi),
2✔
197
    "Get neutron fission spectrum.",
198
    py::keep_alive<0, 1>()
380✔
199
  );
200
  multigroup_xs.def_property_readonly(
380✔
201
    "nu_sigma_f",
UNCOV
202
    XS_GETTER(GetNuSigmaF),
×
203
    "Get neutron production due to fission.",
204
    py::keep_alive<0, 1>()
380✔
205
  );
206
  multigroup_xs.def_property_readonly(
380✔
207
    "nu_prompt_sigma_f",
UNCOV
208
    XS_GETTER(GetNuPromptSigmaF),
×
209
    "Get prompt neutron production due to fission.",
210
    py::keep_alive<0, 1>()
380✔
211
  );
212
  multigroup_xs.def_property_readonly(
380✔
213
    "nu_delayed_sigma_f",
UNCOV
214
    XS_GETTER(GetNuDelayedSigmaF),
×
215
    "Get delayed neutron production due to fission.",
216
    py::keep_alive<0, 1>()
380✔
217
  );
218
  multigroup_xs.def_property_readonly(
380✔
219
    "inv_velocity",
UNCOV
220
    XS_GETTER(GetInverseVelocity),
×
221
    "Get inverse velocity.",
222
    py::keep_alive<0, 1>()
380✔
223
  );
224
  // clang-format on
225
}
380✔
226

227
// Wrap the cross section components of OpenSn
228
void
229
py_xs(py::module& pyopensn)
34✔
230
{
231
  py::module xs = pyopensn.def_submodule("xs", "Cross section module.");
34✔
232
  WrapMultiGroupXS(xs);
34✔
233
}
34✔
234

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