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

openmc-dev / openmc / 21092019830

17 Jan 2026 09:18AM UTC coverage: 80.822% (-1.2%) from 82.044%
21092019830

Pull #3732

github

web-flow
Merge 81036cf07 into 5847b0de2
Pull Request #3732: Volume Calculation enhancement including refactoring and real-valued scoring implementation

15996 of 22249 branches covered (71.9%)

Branch coverage included in aggregate %.

229 of 255 new or added lines in 3 files covered. (89.8%)

1115 existing lines in 52 files now uncovered.

53688 of 63970 relevant lines covered (83.93%)

13910352.73 hits per line

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

82.54
/src/error.cpp
1
#include "openmc/error.h"
2

3
#include "openmc/message_passing.h"
4
#include "openmc/settings.h"
5

6
#if defined(__unix__) || defined(__unix) ||                                    \
7
  (defined(__APPLE__) && defined(__MACH__))
8
#include <unistd.h> // for isatty
9
#endif
10

11
#include <cstdlib> // for exit
12
#include <iomanip> // for setw
13
#include <iostream>
14

15
//==============================================================================
16
// Global variables / constants
17
//==============================================================================
18

19
// Error codes
20
int OPENMC_E_UNASSIGNED {-1};
21
int OPENMC_E_ALLOCATE {-2};
22
int OPENMC_E_OUT_OF_BOUNDS {-3};
23
int OPENMC_E_INVALID_SIZE {-4};
24
int OPENMC_E_INVALID_ARGUMENT {-5};
25
int OPENMC_E_INVALID_TYPE {-6};
26
int OPENMC_E_INVALID_ID {-7};
27
int OPENMC_E_GEOMETRY {-8};
28
int OPENMC_E_DATA {-9};
29
int OPENMC_E_PHYSICS {-10};
30
int OPENMC_E_WARNING {1};
31

32
// Error message
33
char openmc_err_msg[256];
34

35
//==============================================================================
36
// Functions
37
//==============================================================================
38

39
namespace openmc {
40

41
#ifdef OPENMC_MPI
42
void abort_mpi(int code)
43
{
44
  MPI_Abort(mpi::intracomm, code);
45
}
46
#endif
47

48
void output(const std::string& message, std::ostream& out, int indent)
25,784✔
49
{
50
  // Set line wrapping and indentation
51
  int line_wrap = 80;
25,784✔
52

53
  // Determine length of message
54
  int length = message.size();
25,784✔
55

56
  int i_start = 0;
25,784✔
57
  int line_len = line_wrap - indent + 1;
25,784✔
58
  while (i_start < length) {
27,220!
59
    if (length - i_start < line_len) {
27,220✔
60
      // Remainder of message will fit on line
61
      out << message.substr(i_start) << std::endl;
25,784✔
62
      break;
25,784✔
63

64
    } else {
65
      // Determine last space in current line
66
      std::string s = message.substr(i_start, line_len);
1,436✔
67
      auto pos = s.find_last_of(' ');
1,436✔
68

69
      // Write up to last space, or whole line if no space is present
70
      out << s.substr(0, pos) << '\n' << std::setw(indent) << " ";
1,436✔
71

72
      // Advance starting position
73
      i_start += (pos == std::string::npos) ? line_len : pos + 1;
1,436✔
74
    }
1,436✔
75
  }
76
}
25,784✔
77

78
void warning(const std::string& message)
1,412✔
79
{
80
#ifdef _POSIX_VERSION
81
  // Make output yellow if user is in a terminal
82
  if (isatty(STDERR_FILENO)) {
1,412!
83
    std::cerr << "\033[0;33m";
×
84
  }
85
#endif
86

87
  // Write warning
88
  std::cerr << " WARNING: ";
1,412✔
89
  output(message, std::cerr, 10);
1,412✔
90

91
#ifdef _POSIX_VERSION
92
  // Reset color for terminal
93
  if (isatty(STDERR_FILENO)) {
1,412!
94
    std::cerr << "\033[0m";
×
95
  }
96
#endif
97
}
1,412✔
98

99
void write_message(const std::string& message, int level)
24,754✔
100
{
101
  // Only allow master to print to screen
102
  if (!mpi::master)
24,754!
UNCOV
103
    return;
×
104

105
  if (level <= settings::verbosity) {
24,754✔
106
    std::cout << " ";
24,336✔
107
    output(message, std::cout, 1);
24,336✔
108
  }
109
}
110

111
void fatal_error(const std::string& message, int err)
36✔
112
{
113
#pragma omp critical(FatalError)
114
  {
115
#ifdef _POSIX_VERSION
116
    // Make output red if user is in a terminal
117
    if (isatty(STDERR_FILENO)) {
36!
118
      std::cerr << "\033[0;31m";
×
119
    }
120
#endif
121

122
    // Write error message
123
    std::cerr << " ERROR: ";
36✔
124
    output(message, std::cerr, 8);
36✔
125

126
#ifdef _POSIX_VERSION
127
    // Reset color for terminal
128
    if (isatty(STDERR_FILENO)) {
36!
129
      std::cerr << "\033[0m";
×
130
    }
131
#endif
132
  }
133

134
#ifdef OPENMC_MPI
135
  MPI_Abort(mpi::intracomm, err);
136
#endif
137

138
  // Abort the program
139
  std::exit(err);
36✔
140
}
141

142
} // namespace openmc
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