• 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

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

4
#include "python/lib/console.h"
5
#include "framework/utils/utils.h"
6
#include "framework/logging/log.h"
7
#include "framework/runtime.h"
8
#include <iostream>
9
#include <functional>
10
#include <regex>
11

12
using namespace opensn;
13
namespace py = pybind11;
14

15
namespace opensnpy
16
{
17

18
Console& console = Console::GetInstance();
19

20
void
21
Console::BindModule(std::function<void(py::module&)> bind_function)
18,619✔
22
{
23
  py::module main = py::module::import("__main__");
18,619✔
24
  bind_function(main);
18,619✔
25
}
18,619✔
26

27
void
28
Console::BindBarrier(const mpi::Communicator& comm)
433✔
29
{
30
  // clang-format off
31
  py::module main = py::module::import("__main__");
433✔
32
  main.def(
433✔
33
    "MPIBarrier",
34
    [comm]()
866✔
35
    {
36
      comm.barrier();
30✔
37
    },
38
    "MPI barrier for console."
39
  );
40
  // clang-format on
41
}
433✔
42

43
void
44
Console::BindAllReduce(const mpi::Communicator& comm)
433✔
45
{
46
  // clang-format off
47
  py::module main = py::module::import("__main__");
433✔
48
  main.def(
433✔
49
    "MPIAllReduce",
50
    [comm](double value)
866✔
51
    {
52
      double out = 0.0;
4✔
53
      comm.all_reduce(value, out, mpi::op::sum<double>());
4✔
54
      return out;
4✔
55
    },
56
    "MPI all-reduce sum for a scalar."
57
  );
58
  main.def(
433✔
59
    "MPIAllReduce",
60
    [comm](const std::vector<double>& values)
866✔
61
    {
62
      std::vector<double> out(values.size(), 0.0);
×
63
      if (not values.empty())
×
64
      {
65
        const auto count = static_cast<int>(values.size());
×
66
        comm.all_reduce(values.data(), count, out.data(), mpi::op::sum<double>());
×
67
      }
68
      return out;
×
69
    },
×
70
    "MPI all-reduce sum for a list of doubles."
71
  );
72
  // clang-format on
73
}
433✔
74

75
void
76
Console::InitConsole()
433✔
77
{
78
  assert(Py_IsInitialized());
433✔
79

80
  for (const auto& command : command_buffer_)
866✔
81
  {
82
    try
433✔
83
    {
84
      py::exec(command);
866✔
85
      py::exec("import sys; sys.stdout.flush(); sys.stderr.flush();");
866✔
86
      std::cout << std::flush;
433✔
87
      std::cerr << std::flush;
433✔
88
    }
89
    catch (const py::error_already_set& e)
×
90
    {
91
      opensn::log.LogAllError() << e.what();
×
92
      opensn::mpi_comm.abort(EXIT_FAILURE);
×
93
    }
×
94
  }
95
}
433✔
96

97
void
98
Console::ExecuteFile(const std::string& input_filename) const
433✔
99
{
100
  try
433✔
101
  {
102
    py::eval_file(input_filename);
868✔
103
    py::exec("import sys; sys.stdout.flush(); sys.stderr.flush();");
862✔
104
    std::cout << std::flush;
431✔
105
    std::cerr << std::flush;
431✔
106
  }
107
  catch (const py::error_already_set& e)
2✔
108
  {
109
    opensn::log.LogAllError() << e.what();
4✔
110
    opensn::mpi_comm.abort(EXIT_FAILURE);
2✔
111
  }
×
112
}
431✔
113

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