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

Open-Sn / opensn / 21738357923

06 Feb 2026 02:45AM UTC coverage: 74.553% (+0.6%) from 73.983%
21738357923

push

github

web-flow
Merge pull request #921 from wdhawkins/update_quick_install_doc

Updating quick install instructions.

19363 of 25972 relevant lines covered (74.55%)

59700221.09 hits per line

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

86.46
/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)
540✔
22
{
23
  opensn::mpi_comm = comm;
540✔
24

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

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

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

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

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

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

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

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

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

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

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

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

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

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

102
  cali_mgr.flush();
538✔
103
  return EXIT_SUCCESS;
538✔
104
}
105

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

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

124
    auto result = options.parse(argc, argv);
540✔
125

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

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

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

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

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

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

169
  return true;
540✔
170
}
540✔
171

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