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

Open-Sn / opensn / 21933416870

12 Feb 2026 03:12AM UTC coverage: 74.409% (-0.4%) from 74.806%
21933416870

push

github

web-flow
Merge pull request #922 from wdhawkins/named_xs

Adding ability to load user-specifed OpenMC cross sections

28 of 52 new or added lines in 4 files covered. (53.85%)

418 existing lines in 9 files now uncovered.

19839 of 26662 relevant lines covered (74.41%)

67886044.11 hits per line

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

86.32
/python/lib/py_app.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_app.h"
5
#include "python/lib/console.h"
6
#include "python/lib/py_wrappers.h"
7
#include "framework/logging/log.h"
8
#include "framework/utils/utils.h"
9
#include "framework/utils/timer.h"
10
#include "framework/runtime.h"
11
#include "caliper/cali.h"
12
#include "cxxopts/cxxopts.h"
13
#include <string>
14

15
using namespace opensn;
16
namespace py = pybind11;
17

18
namespace opensnpy
19
{
20

21
PyApp::PyApp(const mpi::Communicator& comm)
605✔
22
{
23
  opensn::mpi_comm = comm;
605✔
24

25
  py::module sys = py::module::import("sys");
605✔
26
  py::exec("rank = " + std::to_string(comm.rank()));
1,815✔
27
  py::exec("size = " + std::to_string(comm.size()));
1,815✔
28
  py::exec("opensn_console = True");
1,210✔
29

30
  console.BindBarrier(comm);
605✔
31
  console.BindAllReduce(comm);
605✔
32

33
  Console::BindModule(WrapYlm);
605✔
34
  Console::BindModule(WrapVector3);
605✔
35
  Console::BindModule(WrapFunctors);
605✔
36

37
  Console::BindModule(WrapQuadraturePointPhiTheta);
605✔
38
  Console::BindModule(WrapQuadrature);
605✔
39
  Console::BindModule(WrapProductQuadrature);
605✔
40
  Console::BindModule(WrapTriangularQuadrature);
605✔
41
  Console::BindModule(WrapCurvilinearProductQuadrature);
605✔
42
  Console::BindModule(WrapSLDFEsqQuadrature);
605✔
43
  Console::BindModule(WrapLebedevQuadrature);
605✔
44

45
  Console::BindModule(WrapMesh);
605✔
46
  Console::BindModule(WrapMeshGenerator);
605✔
47
  Console::BindModule(WrapGraphPartitioner);
605✔
48

49
  Console::BindModule(WrapLogicalVolume);
605✔
50

51
  Console::BindModule(WrapPointSource);
605✔
52
  Console::BindModule(WrapVolumetricSource);
605✔
53

54
  Console::BindModule(WrapMultiGroupXS);
605✔
55

56
  Console::BindModule(WrapFieldFunction);
605✔
57
  Console::BindModule(WrapFieldFunctionGridBased);
605✔
58
  Console::BindModule(WrapFieldFunctionInterpolation);
605✔
59

60
  Console::BindModule(WrapResEval);
605✔
61

62
  Console::BindModule(WrapProblem);
605✔
63
  Console::BindModule(WrapSolver);
605✔
64
  Console::BindModule(WrapLBS);
605✔
65
  Console::BindModule(WrapSteadyState);
605✔
66
  Console::BindModule(WrapTransient);
605✔
67
  Console::BindModule(WrapNLKEigen);
605✔
68
  Console::BindModule(WrapPIteration);
605✔
69
  Console::BindModule(WrapDiscreteOrdinatesKEigenAcceleration);
1,210✔
70
}
605✔
71

72
int
73
PyApp::Run(int argc, char** argv)
605✔
74
{
75
  if (opensn::mpi_comm.rank() == 0)
605✔
76
  {
77
    std::cout << opensn::program << " version " << GetVersionStr() << "\n"
555✔
78
              << Timer::GetLocalDateTimeString() << " Running " << opensn::program << " with "
740✔
79
              << opensn::mpi_comm.size() << " processes.\n"
80
              << opensn::program << " number of arguments supplied: " << argc - 1 << "\n"
185✔
81
              << std::endl;
185✔
82
  }
83

84
  if (ProcessArguments(argc, argv))
605✔
85
  {
86
    opensn::Initialize();
605✔
87
    console.InitConsole();
605✔
88
    console.ExecuteFile(opensn::input_path.string());
605✔
89
    opensn::Finalize();
603✔
90

91
    if (opensn::mpi_comm.rank() == 0)
603✔
92
    {
93
      std::cout << "\nElapsed execution time: " << program_timer.GetTimeString() << "\n"
366✔
94
                << Timer::GetLocalDateTimeString() << " " << opensn::program
366✔
95
                << " finished execution." << std::endl;
549✔
96
    }
97
  }
98
  else
99
    return EXIT_FAILURE;
100

101
  cali_mgr.flush();
603✔
102
  return EXIT_SUCCESS;
603✔
103
}
104

105
bool
106
PyApp::ProcessArguments(int argc, char** argv)
605✔
107
{
108
  cxxopts::Options options(LowerCase(opensn::program), "");
1,210✔
109

110
  try
605✔
111
  {
112
    /* clang-format off */
113
    options.add_options("User")
1,210✔
114
    ("h,help",                      "Help message")
1,815✔
115
    ("c,suppress-color",            "Suppress color output")
1,815✔
116
    ("v,verbose",                   "Verbosity level (0 to 3). Default is 0.", cxxopts::value<unsigned int>())
1,815✔
117
    ("caliper",                     "Enable Caliper reporting",
1,815✔
118
      cxxopts::value<std::string>()->implicit_value("runtime-report(calc.inclusive=true),max_column_width=80"))
1,815✔
119
    ("i,input",                     "Input file", cxxopts::value<std::string>())
1,815✔
120
    ("p,py",                        "Python expression", cxxopts::value<std::vector<std::string>>());
1,815✔
121
    /* clang-format on */
122

123
    auto result = options.parse(argc, argv);
605✔
124

125
    if (result.count("help"))
605✔
126
    {
UNCOV
127
      if (opensn::mpi_comm.rank() == 0)
×
128
        std::cout << options.help({"User"}) << std::endl;
×
129
      return false;
×
130
    }
131

132
    if (result.count("verbose"))
605✔
133
    {
134
      auto verbosity = result["verbose"].as<unsigned int>();
4✔
135
      opensn::log.SetVerbosity(verbosity);
4✔
136
    }
137

138
    if (result.count("suppress-color"))
605✔
139
      opensn::suppress_color = true;
605✔
140

141
    if (result.count("caliper"))
605✔
142
    {
UNCOV
143
      opensn::use_caliper = true;
×
144
      opensn::cali_config = result["caliper"].as<std::string>();
×
145
    }
146

147
    if (result.count("py"))
605✔
148
    {
149
      for (const auto& pyarg : result["py"].as<std::vector<std::string>>())
1,210✔
150
        console.GetCommandBuffer().push_back(pyarg);
605✔
151
    }
152

153
    opensn::input_path = result["input"].as<std::string>();
605✔
154
    if (not std::filesystem::exists(input_path) or not std::filesystem::is_regular_file(input_path))
1,210✔
155
    {
UNCOV
156
      if (opensn::mpi_comm.rank() == 0)
×
157
        std::cerr << "Invalid input file: " << input_path.string() << "\n" << std::endl;
×
158
      return false;
×
159
    }
160
  }
605✔
UNCOV
161
  catch (const std::exception& e)
×
162
  {
UNCOV
163
    if (opensn::mpi_comm.rank() == 0)
×
164
      std::cerr << e.what() << "\n" << options.help({"User"}) << std::endl;
×
165
    return false;
×
166
  }
×
167

168
  return true;
605✔
169
}
605✔
170

171
} // namespace opensnpy
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