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

Open-Sn / opensn / 18300593117

06 Oct 2025 10:47PM UTC coverage: 74.862% (-0.2%) from 75.031%
18300593117

push

github

web-flow
Merge pull request #759 from wdhawkins/performance

Sweep performance optimizations

294 of 302 new or added lines in 15 files covered. (97.35%)

334 existing lines in 80 files now uncovered.

17788 of 23761 relevant lines covered (74.86%)

61852783.95 hits per line

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

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

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

30
  console.BindBarrier(comm);
354✔
31

32
  Console::BindModule(WrapYlm);
354✔
33
  Console::BindModule(WrapVector3);
354✔
34
  Console::BindModule(WrapFunctors);
354✔
35

36
  Console::BindModule(WrapQuadraturePointPhiTheta);
354✔
37
  Console::BindModule(WrapQuadrature);
354✔
38
  Console::BindModule(WrapProductQuadrature);
354✔
39
  Console::BindModule(WrapCurvilinearProductQuadrature);
354✔
40
  Console::BindModule(WrapSLDFESQuadrature);
354✔
41
  Console::BindModule(WrapLebedevQuadrature);
354✔
42

43
  Console::BindModule(WrapMesh);
354✔
44
  Console::BindModule(WrapMeshGenerator);
354✔
45
  Console::BindModule(WrapGraphPartitioner);
354✔
46

47
  Console::BindModule(WrapLogicalVolume);
354✔
48

49
  Console::BindModule(WrapPointSource);
354✔
50
  Console::BindModule(WrapVolumetricSource);
354✔
51

52
  Console::BindModule(WrapMultiGroupXS);
354✔
53

54
  Console::BindModule(WrapFieldFunction);
354✔
55
  Console::BindModule(WrapFieldFunctionGridBased);
354✔
56
  Console::BindModule(WrapFieldFunctionInterpolation);
354✔
57

58
  Console::BindModule(WrapResEval);
354✔
59

60
  Console::BindModule(WrapProblem);
354✔
61
  Console::BindModule(WrapSolver);
354✔
62
  Console::BindModule(WrapLBS);
354✔
63
  Console::BindModule(WrapSteadyState);
354✔
64
  Console::BindModule(WrapNLKEigen);
354✔
65
  Console::BindModule(WrapPIteration);
354✔
66
  Console::BindModule(WrapDiscreteOrdinatesKEigenAcceleration);
354✔
67
}
354✔
68

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

81
  if (ProcessArguments(argc, argv))
354✔
82
  {
83
    opensn::Initialize();
354✔
84
    console.InitConsole();
354✔
85
    console.ExecuteFile(opensn::input_path.string());
354✔
86
    opensn::Finalize();
352✔
87

88
    if (opensn::mpi_comm.rank() == 0)
352✔
89
    {
90
      std::cout << "\nElapsed execution time: " << program_timer.GetTimeString() << "\n"
113✔
91
                << Timer::GetLocalDateTimeString() << " " << opensn::program
113✔
92
                << " finished execution." << std::endl;
113✔
93
    }
94
  }
95
  else
UNCOV
96
    return EXIT_FAILURE;
×
97

98
  cali_mgr.flush();
352✔
99
  return EXIT_SUCCESS;
352✔
100
}
101

102
bool
103
PyApp::ProcessArguments(int argc, char** argv)
354✔
104
{
105
  cxxopts::Options options(LowerCase(opensn::program), "");
708✔
106

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

120
    auto result = options.parse(argc, argv);
354✔
121

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

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

135
    if (result.count("suppress-color"))
708✔
136
      opensn::suppress_color = true;
354✔
137

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

144
    if (result.count("py"))
708✔
145
    {
146
      for (const auto& pyarg : result["py"].as<std::vector<std::string>>())
1,062✔
147
        console.GetCommandBuffer().push_back(pyarg);
354✔
148
    }
149

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

165
  return true;
354✔
166
}
354✔
167

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