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

Open-Sn / opensn / 21273491277

22 Jan 2026 04:54PM UTC coverage: 74.361% (-0.006%) from 74.367%
21273491277

push

github

web-flow
Merge pull request #902 from quocdang1998/doxygen-specs

Add Doxygen guidelines

18756 of 25223 relevant lines covered (74.36%)

67566753.71 hits per line

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

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

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

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

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

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

44
  Console::BindModule(WrapMesh);
433✔
45
  Console::BindModule(WrapMeshGenerator);
433✔
46
  Console::BindModule(WrapGraphPartitioner);
433✔
47

48
  Console::BindModule(WrapLogicalVolume);
433✔
49

50
  Console::BindModule(WrapPointSource);
433✔
51
  Console::BindModule(WrapVolumetricSource);
433✔
52

53
  Console::BindModule(WrapMultiGroupXS);
433✔
54

55
  Console::BindModule(WrapFieldFunction);
433✔
56
  Console::BindModule(WrapFieldFunctionGridBased);
433✔
57
  Console::BindModule(WrapFieldFunctionInterpolation);
433✔
58

59
  Console::BindModule(WrapResEval);
433✔
60

61
  Console::BindModule(WrapProblem);
433✔
62
  Console::BindModule(WrapSolver);
433✔
63
  Console::BindModule(WrapLBS);
433✔
64
  Console::BindModule(WrapSteadyState);
433✔
65
  Console::BindModule(WrapTimeDependent);
433✔
66
  Console::BindModule(WrapNLKEigen);
433✔
67
  Console::BindModule(WrapPIteration);
433✔
68
  Console::BindModule(WrapDiscreteOrdinatesKEigenAcceleration);
866✔
69
}
433✔
70

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

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

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

100
  cali_mgr.flush();
431✔
101
  return EXIT_SUCCESS;
431✔
102
}
103

104
bool
105
PyApp::ProcessArguments(int argc, char** argv)
433✔
106
{
107
  cxxopts::Options options(LowerCase(opensn::program), "");
866✔
108

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

122
    auto result = options.parse(argc, argv);
433✔
123

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

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

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

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

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

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

167
  return true;
433✔
168
}
433✔
169

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