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

openmc-dev / openmc / 27780945043

18 Jun 2026 06:30PM UTC coverage: 81.097% (-0.2%) from 81.34%
27780945043

Pull #3911

github

web-flow
Merge c5ade9293 into 09ee8308d
Pull Request #3911: Creating a new HDF5 nuclear data library for UQ

18119 of 26286 branches covered (68.93%)

Branch coverage included in aggregate %.

310 of 599 new or added lines in 3 files covered. (51.75%)

2247 existing lines in 53 files now uncovered.

59544 of 69480 relevant lines covered (85.7%)

40971728.6 hits per line

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

81.73
/src/output.cpp
1
#include "openmc/output.h"
2

3
#include <algorithm> // for transform, max
4
#include <cstdio>    // for stdout
5
#include <cstring>   // for strlen
6
#include <ctime>     // for time, localtime
7
#include <fstream>
8
#include <iomanip> // for setw, setprecision, put_time
9
#include <ios>     // for fixed, scientific, left
10
#include <iostream>
11
#include <sstream>
12
#include <unordered_map>
13
#include <utility> // for pair
14

15
#include <fmt/core.h>
16
#include <fmt/ostream.h>
17
#ifdef _OPENMP
18
#include <omp.h>
19
#endif
20
#include "openmc/tensor.h"
21

22
#include "openmc/capi.h"
23
#include "openmc/cell.h"
24
#include "openmc/constants.h"
25
#include "openmc/eigenvalue.h"
26
#include "openmc/error.h"
27
#include "openmc/geometry.h"
28
#include "openmc/lattice.h"
29
#include "openmc/math_functions.h"
30
#include "openmc/message_passing.h"
31
#include "openmc/mgxs_interface.h"
32
#include "openmc/nuclide.h"
33
#include "openmc/plot.h"
34
#include "openmc/random_ray/flat_source_domain.h"
35
#include "openmc/reaction.h"
36
#include "openmc/settings.h"
37
#include "openmc/simulation.h"
38
#include "openmc/surface.h"
39
#include "openmc/tallies/derivative.h"
40
#include "openmc/tallies/filter.h"
41
#include "openmc/tallies/tally.h"
42
#include "openmc/tallies/tally_scoring.h"
43
#include "openmc/timer.h"
44

45
namespace openmc {
46

47
#ifdef OPENMC_ENABLE_STRICT_FP
48
const bool STRICT_FP_ENABLED = true;
49
#else
50
const bool STRICT_FP_ENABLED = false;
51
#endif
52

53
//==============================================================================
54

55
void title()
5,494✔
56
{
57
  fmt::print("                                %%%%%%%%%%%%%%%\n"
5,494✔
58
             "                           %%%%%%%%%%%%%%%%%%%%%%%%\n"
59
             "                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
60
             "                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
61
             "                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
62
             "                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
63
             "                                    %%%%%%%%%%%%%%%%%%%%%%%%\n"
64
             "                                     %%%%%%%%%%%%%%%%%%%%%%%%\n"
65
             "                 ###############      %%%%%%%%%%%%%%%%%%%%%%%%\n"
66
             "                ##################     %%%%%%%%%%%%%%%%%%%%%%%\n"
67
             "                ###################     %%%%%%%%%%%%%%%%%%%%%%%\n"
68
             "                ####################     %%%%%%%%%%%%%%%%%%%%%%\n"
69
             "                #####################     %%%%%%%%%%%%%%%%%%%%%\n"
70
             "                ######################     %%%%%%%%%%%%%%%%%%%%\n"
71
             "                #######################     %%%%%%%%%%%%%%%%%%\n"
72
             "                 #######################     %%%%%%%%%%%%%%%%%\n"
73
             "                 ######################     %%%%%%%%%%%%%%%%%\n"
74
             "                  ####################     %%%%%%%%%%%%%%%%%\n"
75
             "                    #################     %%%%%%%%%%%%%%%%%\n"
76
             "                     ###############     %%%%%%%%%%%%%%%%\n"
77
             "                       ############     %%%%%%%%%%%%%%%\n"
78
             "                          ########     %%%%%%%%%%%%%%\n"
79
             "                                      %%%%%%%%%%%\n\n");
80

81
  // Write version information
82
  fmt::print(
10,988✔
83
    "                 | The OpenMC Monte Carlo Code\n"
84
    "       Copyright | 2011-2026 MIT, UChicago Argonne LLC, and contributors\n"
85
    "         License | https://docs.openmc.org/en/latest/license.html\n"
86
    "         Version | {}.{}.{}{}{}\n",
87
    VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_DEV ? "-dev" : "",
5,494✔
88
    VERSION_COMMIT_COUNT);
89
  fmt::print("     Commit Hash | {}\n", VERSION_COMMIT_HASH);
5,494✔
90

91
  // Write the date and time
92
  fmt::print("       Date/Time | {}\n", time_stamp());
6,173✔
93

94
#ifdef OPENMC_MPI
95
  // Write number of processors
96
  fmt::print("   MPI Processes | {}\n", mpi::n_procs);
1,416✔
97
#endif
98

99
#ifdef _OPENMP
100
  // Write number of OpenMP threads
101
  fmt::print("  OpenMP Threads | {}\n", omp_get_max_threads());
3,442✔
102
#endif
103
  fmt::print("\n");
5,494✔
104
  std::fflush(stdout);
5,494✔
105
}
5,494✔
106

107
//==============================================================================
108

109
std::string header(const char* msg)
29,380✔
110
{
111
  // Determine how many times to repeat the '=' character.
112
  int n_prefix = (63 - strlen(msg)) / 2;
29,380✔
113
  int n_suffix = n_prefix;
29,380✔
114
  if ((strlen(msg) % 2) == 0)
29,380✔
115
    ++n_suffix;
5,938✔
116

117
  // Convert to uppercase.
118
  std::string upper(msg);
29,380✔
119
  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
29,380✔
120

121
  // Add ===>  <=== markers.
122
  std::stringstream out;
29,380✔
123
  out << ' ';
29,380✔
124
  for (int i = 0; i < n_prefix; i++)
745,121✔
125
    out << '=';
715,741✔
126
  out << ">     " << upper << "     <";
29,380✔
127
  for (int i = 0; i < n_suffix; i++)
751,059✔
128
    out << '=';
721,679✔
129

130
  return out.str();
29,380✔
131
}
29,380✔
132

133
std::string header(const std::string& msg)
14,564✔
134
{
135
  return header(msg.c_str());
14,564✔
136
}
137

138
void header(const char* msg, int level)
14,816✔
139
{
140
  auto out = header(msg);
14,816✔
141

142
  // Print header based on verbosity level.
143
  if (settings::verbosity >= level) {
14,816✔
144
    fmt::print("\n{}\n\n", out);
14,495✔
145
    std::fflush(stdout);
14,495✔
146
  }
147
}
14,816✔
148

149
//==============================================================================
150

151
std::string time_stamp()
16,566✔
152
{
153
  std::stringstream ts;
16,566✔
154
  std::time_t t = std::time(nullptr); // get time now
16,566✔
155
  ts << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");
16,566✔
156
  return ts.str();
33,132✔
157
}
16,566✔
158

159
//==============================================================================
160

161
void print_particle(Particle& p)
32✔
162
{
163
  // Display particle type and ID.
164
  switch (p.type().pdg_number()) {
32!
165
  case PDG_NEUTRON:
32✔
166
    fmt::print("Neutron ");
32✔
167
    break;
32✔
168
  case PDG_PHOTON:
×
169
    fmt::print("Photon ");
×
170
    break;
×
171
  case PDG_ELECTRON:
×
172
    fmt::print("Electron ");
×
173
    break;
×
174
  case PDG_POSITRON:
×
175
    fmt::print("Positron ");
×
176
    break;
×
177
  default:
×
178
    fmt::print("Particle {} ", p.type().str());
×
179
  }
180
  fmt::print("{}\n", p.id());
32✔
181

182
  // Display particle geometry hierarchy.
183
  for (auto i = 0; i < p.n_coord(); i++) {
64✔
184
    fmt::print("  Level {}\n", i);
32✔
185

186
    if (p.coord(i).cell() != C_NONE) {
32!
187
      const Cell& c {*model::cells[p.coord(i).cell()]};
32✔
188
      fmt::print("    Cell             = {}\n", c.id_);
32✔
189
    }
190

191
    if (p.coord(i).universe() != C_NONE) {
32!
192
      const Universe& u {*model::universes[p.coord(i).universe()]};
32✔
193
      fmt::print("    Universe         = {}\n", u.id_);
32✔
194
    }
195

196
    if (p.coord(i).lattice() != C_NONE) {
32!
197
      const Lattice& lat {*model::lattices[p.coord(i).lattice()]};
×
198
      fmt::print("    Lattice          = {}\n", lat.id_);
×
199
      fmt::print("    Lattice position = ({},{},{})\n",
×
200
        p.coord(i).lattice_index()[0], p.coord(i).lattice_index()[1],
×
201
        p.coord(i).lattice_index()[2]);
×
202
    }
203

204
    fmt::print("    r = {}\n", p.coord(i).r());
32✔
205
    fmt::print("    u = {}\n", p.coord(i).u());
32✔
206
  }
207

208
  // Display miscellaneous info.
209
  if (p.surface() != SURFACE_NONE) {
32!
210
    // Surfaces identifiers are >= 1, but indices are >= 0 so we need -1
211
    const Surface& surf {*model::surfaces[p.surface_index()]};
×
212
    fmt::print("  Surface = {}\n", (p.surface() > 0) ? surf.id_ : -surf.id_);
×
213
  }
214
  fmt::print("  Weight = {}\n", p.wgt());
32✔
215
  if (settings::run_CE) {
32!
216
    fmt::print("  Energy = {}\n", p.E());
32✔
217
  } else {
218
    fmt::print("  Energy Group = {}\n", p.g());
×
219
  }
220
  fmt::print("  Delayed Group = {}\n\n", p.delayed_group());
32✔
221
}
32✔
222

223
//==============================================================================
224

225
void print_plot()
64✔
226
{
227
  header("PLOTTING SUMMARY", 5);
64✔
228
  if (settings::verbosity < 5)
64!
229
    return;
230

231
  for (const auto& pl : model::plots) {
240✔
232
    fmt::print("Plot ID: {}\n", pl->id());
176✔
233
    fmt::print("Plot file: {}\n", pl->path_plot());
176✔
234
    fmt::print("Universe depth: {}\n", pl->level());
176✔
235
    pl->print_info(); // prints type-specific plot info
176✔
236
    fmt::print("\n");
176✔
237
  }
238
}
239

240
//==============================================================================
241

242
void print_overlap_check()
×
243
{
244
#ifdef OPENMC_MPI
245
  vector<int64_t> temp(model::overlap_check_count);
246
  MPI_Reduce(temp.data(), model::overlap_check_count.data(),
×
247
    model::overlap_check_count.size(), MPI_INT64_T, MPI_SUM, 0, mpi::intracomm);
×
248
#endif
249

250
  if (mpi::master) {
×
251
    header("cell overlap check summary", 1);
×
252
    fmt::print(" Cell ID      No. Overlap Checks\n");
×
253

254
    vector<int32_t> sparse_cell_ids;
×
255
    for (int i = 0; i < model::cells.size(); i++) {
×
256
      fmt::print(
×
257
        " {:8} {:17}\n", model::cells[i]->id_, model::overlap_check_count[i]);
×
258
      if (model::overlap_check_count[i] < 10) {
×
259
        sparse_cell_ids.push_back(model::cells[i]->id_);
×
260
      }
261
    }
262

263
    fmt::print("\n There were {} cells with less than 10 overlap checks\n",
×
264
      sparse_cell_ids.size());
×
265
    for (auto id : sparse_cell_ids) {
×
266
      fmt::print(" {}", id);
×
267
    }
268
    fmt::print("\n");
×
269
  }
×
270
}
×
271

272
//==============================================================================
273

274
void print_usage()
×
275
{
276
  if (mpi::master) {
×
277
    fmt::print(
×
278
      "Usage: openmc [options] [path]\n\n"
279
      "Options:\n"
280
      "  -c, --volume           Run in stochastic volume calculation mode\n"
281
      "  -g, --geometry-debug   Run with geometry debugging on\n"
282
      "  -n, --particles        Number of particles per generation\n"
283
      "  -p, --plot             Run in plotting mode\n"
284
      "  -r, --restart          Restart a previous run from a state point\n"
285
      "                         or a particle restart file\n"
286
      "  -s, --threads          Number of OpenMP threads\n"
287
      "  -t, --track            Write tracks for all particles (up to "
288
      "max_tracks)\n"
289
      "  -e, --event            Run using event-based parallelism\n"
290
      "  -q, --verbosity        Output verbosity\n"
291
      "  -v, --version          Show version information\n"
292
      "  -h, --help             Show this message\n");
293
  }
294
}
×
295

296
//==============================================================================
297

298
void print_version()
8✔
299
{
300
  if (mpi::master) {
8!
301
    fmt::print("OpenMC version {}.{}.{}{}{}\n", VERSION_MAJOR, VERSION_MINOR,
16✔
302
      VERSION_RELEASE, VERSION_DEV ? "-dev" : "", VERSION_COMMIT_COUNT);
8✔
303
    fmt::print("Commit hash: {}\n", VERSION_COMMIT_HASH);
8✔
304
    fmt::print("Copyright (c) 2011-2026 MIT, UChicago Argonne LLC, and "
8✔
305
               "contributors\nMIT/X license at "
306
               "<https://docs.openmc.org/en/latest/license.html>\n");
307
  }
308
}
8✔
309

310
//==============================================================================
311

312
void print_build_info()
8✔
313
{
314
  const std::string n("no");
8✔
315
  const std::string y("yes");
8✔
316

317
  std::string mpi(n);
8✔
318
  std::string phdf5(n);
8✔
319
  std::string dagmc(n);
8✔
320
  std::string libmesh(n);
8✔
321
  std::string png(n);
8✔
322
  std::string profiling(n);
8✔
323
  std::string coverage(n);
8✔
324
  std::string uwuw(n);
8✔
325
  std::string strict_fp(n);
8✔
326

327
#ifdef PHDF5
328
  phdf5 = y;
2✔
329
#endif
330
#ifdef OPENMC_MPI
331
  mpi = y;
2✔
332
#endif
333
#ifdef OPENMC_DAGMC_ENABLED
334
  dagmc = y;
1✔
335
#endif
336
#ifdef OPENMC_LIBMESH_ENABLED
337
  libmesh = y;
1✔
338
#endif
339
#ifdef USE_LIBPNG
340
  png = y;
8✔
341
#endif
342
#ifdef PROFILINGBUILD
343
  profiling = y;
344
#endif
345
#ifdef COVERAGEBUILD
346
  coverage = y;
8✔
347
#endif
348
#ifdef OPENMC_UWUW_ENABLED
349
  uwuw = y;
1✔
350
#endif
351
#ifdef OPENMC_ENABLE_STRICT_FP
352
  strict_fp = y;
8✔
353
#endif
354

355
  // Wraps macro variables in quotes
356
#define STRINGIFY(x) STRINGIFY2(x)
357
#define STRINGIFY2(x) #x
358

359
  if (mpi::master) {
8!
360
    fmt::print("Build type:            {}\n", STRINGIFY(BUILD_TYPE));
8✔
361
    fmt::print("Compiler ID:           {} {}\n", STRINGIFY(COMPILER_ID),
8✔
362
      STRINGIFY(COMPILER_VERSION));
363
    fmt::print("MPI enabled:           {}\n", mpi);
8✔
364
    fmt::print("Parallel HDF5 enabled: {}\n", phdf5);
8✔
365
    fmt::print("PNG support:           {}\n", png);
8✔
366
    fmt::print("DAGMC support:         {}\n", dagmc);
8✔
367
    fmt::print("libMesh support:       {}\n", libmesh);
8✔
368
    fmt::print("Coverage testing:      {}\n", coverage);
8✔
369
    fmt::print("Profiling flags:       {}\n", profiling);
8✔
370
    fmt::print("UWUW support:          {}\n", uwuw);
8✔
371
    fmt::print("Strict FP:             {}\n", strict_fp);
9✔
372
  }
373
}
8✔
374

375
//==============================================================================
376

377
void print_columns()
2,477✔
378
{
379
  if (settings::entropy_on) {
2,477✔
380
    fmt::print("  Bat./Gen.      k       Entropy         Average k \n"
360✔
381
               "  =========   ========   ========   ====================\n");
382
  } else {
383
    fmt::print("  Bat./Gen.      k            Average k\n"
2,117✔
384
               "  =========   ========   ====================\n");
385
  }
386
}
2,477✔
387

388
//==============================================================================
389

390
void print_generation()
55,334✔
391
{
392
  // Determine overall generation index and number of active generations
393
  int idx = overall_generation() - 1;
55,334✔
394
  int n = simulation::current_batch > settings::n_inactive
110,668✔
395
            ? settings::gen_per_batch * simulation::n_realizations +
55,334✔
396
                simulation::current_gen
397
            : 0;
398

399
  // write out batch/generation and generation k-effective
400
  auto batch_and_gen = std::to_string(simulation::current_batch) + "/" +
110,668✔
401
                       std::to_string(simulation::current_gen);
110,668✔
402
  fmt::print("  {:>9}   {:8.5f}", batch_and_gen, simulation::k_generation[idx]);
55,334✔
403

404
  // write out entropy info
405
  if (settings::entropy_on) {
55,334✔
406
    fmt::print("   {:8.5f}", simulation::entropy[idx]);
9,640✔
407
  }
408

409
  if (n > 1) {
55,334✔
410
    fmt::print("   {:8.5f} +/-{:8.5f}", simulation::keff, simulation::keff_std);
39,005✔
411
  }
412
  fmt::print("\n");
55,334✔
413
  std::fflush(stdout);
55,334✔
414
}
55,334✔
415

416
//==============================================================================
417

418
void show_time(const char* label, double secs, int indent_level)
53,105✔
419
{
420
  int width = 33 - indent_level * 2;
53,105✔
421
  fmt::print("{0:{1}} {2:<{3}} = {4:>10.4e} seconds\n", "", 2 * indent_level,
53,105✔
422
    label, width, secs);
423
}
53,105✔
424

425
void show_rate(const char* label, double particles_per_sec)
5,759✔
426
{
427
  fmt::print(" {:<33} = {:.6} particles/second\n", label, particles_per_sec);
5,759✔
428
}
5,759✔
429

430
void print_runtime()
4,127✔
431
{
432
  using namespace simulation;
4,127✔
433

434
  // display header block
435
  header("Timing Statistics", 6);
4,127✔
436
  if (settings::verbosity < 6)
4,127!
437
    return;
438

439
  // display time elapsed for various sections
440
  show_time("Total time for initialization", time_initialize.elapsed());
4,127✔
441
  show_time("Reading cross sections", time_read_xs.elapsed(), 1);
4,127✔
442
  show_time("Total time in simulation",
4,127✔
443
    time_inactive.elapsed() + time_active.elapsed());
4,127✔
444
  show_time("Time in transport only", time_transport.elapsed(), 1);
4,127✔
445
  if (settings::event_based) {
4,127✔
446
    show_time("Particle initialization", time_event_init.elapsed(), 2);
161✔
447
    show_time("XS lookups", time_event_calculate_xs.elapsed(), 2);
161✔
448
    show_time("Advancing", time_event_advance_particle.elapsed(), 2);
161✔
449
    show_time("Surface crossings", time_event_surface_crossing.elapsed(), 2);
161✔
450
    show_time("Collisions", time_event_collision.elapsed(), 2);
161✔
451
    show_time("Particle death", time_event_death.elapsed(), 2);
161✔
452
  }
453
  if (settings::run_mode == RunMode::EIGENVALUE) {
4,127✔
454
    show_time("Time in inactive batches", time_inactive.elapsed(), 1);
2,277✔
455
  }
456
  show_time("Time in active batches", time_active.elapsed(), 1);
4,127✔
457
  if (settings::run_mode == RunMode::EIGENVALUE) {
4,127✔
458
    show_time("Time synchronizing fission bank", time_bank.elapsed(), 1);
2,277✔
459
    show_time("Sampling source sites", time_bank_sample.elapsed(), 2);
2,277✔
460
    show_time("SEND/RECV source sites", time_bank_sendrecv.elapsed(), 2);
2,277✔
461
  }
462
  show_time("Time accumulating tallies", time_tallies.elapsed(), 1);
4,127✔
463
  show_time("Time writing statepoints", time_statepoint.elapsed(), 1);
4,127✔
464
  show_time("Total time for finalization", time_finalize.elapsed());
4,127✔
465
  show_time("Total time elapsed", time_total.elapsed());
4,127✔
466

467
  // Calculate particle rate in active/inactive batches
468
  int n_active = simulation::current_batch - settings::n_inactive;
4,127✔
469
  double speed_inactive = 0.0;
4,127✔
470
  double speed_active;
4,127✔
471
  if (settings::restart_run) {
4,127✔
472
    if (simulation::restart_batch < settings::n_inactive) {
24!
UNCOV
473
      speed_inactive = (settings::n_particles *
×
UNCOV
474
                         (settings::n_inactive - simulation::restart_batch) *
×
UNCOV
475
                         settings::gen_per_batch) /
×
UNCOV
476
                       time_inactive.elapsed();
×
UNCOV
477
      speed_active =
×
478
        (settings::n_particles * n_active * settings::gen_per_batch) /
×
479
        time_active.elapsed();
×
480
    } else {
481
      speed_active = (settings::n_particles *
24✔
482
                       (settings::n_batches - simulation::restart_batch) *
24✔
483
                       settings::gen_per_batch) /
24✔
484
                     time_active.elapsed();
24✔
485
    }
486
  } else {
487
    if (settings::n_inactive > 0) {
4,103✔
488
      speed_inactive = (settings::n_particles * settings::n_inactive *
1,632✔
489
                         settings::gen_per_batch) /
1,632✔
490
                       time_inactive.elapsed();
1,632✔
491
    }
492
    speed_active =
4,103✔
493
      (settings::n_particles * n_active * settings::gen_per_batch) /
4,103✔
494
      time_active.elapsed();
4,103✔
495
  }
496

497
  // display calculation rate
498
  if (!(settings::restart_run &&
4,127✔
499
        (simulation::restart_batch >= settings::n_inactive)) &&
24!
500
      settings::n_inactive > 0) {
4,103✔
501
    show_rate("Calculation Rate (inactive)", speed_inactive);
1,632✔
502
  }
503
  show_rate("Calculation Rate (active)", speed_active);
4,127✔
504

505
  // Display track rate when weight windows are enabled
506
  if (settings::weight_windows_on) {
4,127✔
507
    double speed_tracks =
196✔
508
      simulation::simulation_tracks_completed / time_active.elapsed();
196✔
509
    fmt::print(
196✔
510
      " {:<33} = {:.6} tracks/second\n", "Track Rate (active)", speed_tracks);
511
  }
512
}
513

514
//==============================================================================
515

516
std::pair<double, double> mean_stdev(const double* x, int n)
10,073,832✔
517
{
518
  double mean = x[static_cast<int>(TallyResult::SUM)] / n;
10,073,832✔
519
  double stdev =
10,073,832✔
520
    n > 1 ? std::sqrt(std::max(0.0,
20,141,680✔
521
              (x[static_cast<int>(TallyResult::SUM_SQ)] / n - mean * mean) /
20,141,680✔
522
                (n - 1)))
10,067,848✔
523
          : 0.0;
10,073,832✔
524
  return {mean, stdev};
10,073,832✔
525
}
526

527
//==============================================================================
528

529
void print_results()
4,127✔
530
{
531
  // display header block for results
532
  header("Results", 4);
4,127✔
533
  if (settings::verbosity < 4)
4,127!
UNCOV
534
    return;
×
535

536
  // Calculate t-value for confidence intervals
537
  int n = simulation::n_realizations;
4,127✔
538
  double alpha, t_n1, t_n3;
4,127✔
539
  if (settings::confidence_intervals) {
4,127✔
540
    alpha = 1.0 - CONFIDENCE_LEVEL;
8✔
541
    t_n1 = t_percentile(1.0 - alpha / 2.0, n - 1);
8✔
542
    t_n3 = t_percentile(1.0 - alpha / 2.0, n - 3);
8✔
543
  } else {
544
    t_n1 = 1.0;
545
    t_n3 = 1.0;
546
  }
547

548
  // write global tallies
549
  const auto& gt = simulation::global_tallies;
4,127✔
550
  double mean, stdev;
4,127✔
551
  if (n > 1) {
4,127✔
552
    if (settings::run_mode == RunMode::EIGENVALUE) {
3,831✔
553
      std::tie(mean, stdev) = mean_stdev(&gt(GlobalTally::K_COLLISION, 0), n);
2,197✔
554
      fmt::print(" k-effective (Collision)     = {:.5f} +/- {:.5f}\n", mean,
4,394✔
555
        t_n1 * stdev);
2,197✔
556
      std::tie(mean, stdev) = mean_stdev(&gt(GlobalTally::K_TRACKLENGTH, 0), n);
2,197✔
557
      fmt::print(" k-effective (Track-length)  = {:.5f} +/- {:.5f}\n", mean,
4,394✔
558
        t_n1 * stdev);
2,197✔
559
      std::tie(mean, stdev) = mean_stdev(&gt(GlobalTally::K_ABSORPTION, 0), n);
2,197✔
560
      fmt::print(" k-effective (Absorption)    = {:.5f} +/- {:.5f}\n", mean,
4,394✔
561
        t_n1 * stdev);
2,197✔
562
      if (n > 3) {
2,197✔
563
        double k_combined[2];
2,149✔
564
        openmc_get_keff(k_combined);
2,149✔
565
        fmt::print(" Combined k-effective        = {:.5f} +/- {:.5f}\n",
2,149✔
566
          k_combined[0], k_combined[1]);
567
      }
568
    }
569
    std::tie(mean, stdev) = mean_stdev(&gt(GlobalTally::LEAKAGE, 0), n);
3,831✔
570
    fmt::print(
7,177✔
571
      " Leakage Fraction            = {:.5f} +/- {:.5f}\n", mean, t_n1 * stdev);
3,831✔
572
  } else {
573
    if (mpi::master)
296!
574
      warning("Could not compute uncertainties -- only one "
592✔
575
              "active batch simulated!");
576

577
    if (settings::run_mode == RunMode::EIGENVALUE) {
296✔
578
      fmt::print(" k-effective (Collision)    = {:.5f}\n",
160✔
579
        gt(GlobalTally::K_COLLISION, TallyResult::SUM) / n);
80✔
580
      fmt::print(" k-effective (Track-length) = {:.5f}\n",
160✔
581
        gt(GlobalTally::K_TRACKLENGTH, TallyResult::SUM) / n);
80✔
582
      fmt::print(" k-effective (Absorption)   = {:.5f}\n",
150✔
583
        gt(GlobalTally::K_ABSORPTION, TallyResult::SUM) / n);
80✔
584
    }
585
    fmt::print(" Leakage Fraction           = {:.5f}\n",
554✔
586
      gt(GlobalTally::LEAKAGE, TallyResult::SUM) / n);
296✔
587
  }
588
  fmt::print("\n");
4,127✔
589
  std::fflush(stdout);
4,127✔
590
}
591

592
//==============================================================================
593

594
const std::unordered_map<int, const char*> score_names = {
595
  {SCORE_FLUX, "Flux"},
596
  {SCORE_TOTAL, "Total Reaction Rate"},
597
  {SCORE_SCATTER, "Scattering Rate"},
598
  {SCORE_NU_SCATTER, "Scattering Production Rate"},
599
  {SCORE_ABSORPTION, "Absorption Rate"},
600
  {SCORE_FISSION, "Fission Rate"},
601
  {SCORE_NU_FISSION, "Nu-Fission Rate"},
602
  {SCORE_KAPPA_FISSION, "Kappa-Fission Rate"},
603
  {SCORE_EVENTS, "Events"},
604
  {SCORE_DECAY_RATE, "Decay Rate"},
605
  {SCORE_DELAYED_NU_FISSION, "Delayed-Nu-Fission Rate"},
606
  {SCORE_PROMPT_NU_FISSION, "Prompt-Nu-Fission Rate"},
607
  {SCORE_INVERSE_VELOCITY, "Flux-Weighted Inverse Velocity"},
608
  {SCORE_FISS_Q_PROMPT, "Prompt fission power"},
609
  {SCORE_FISS_Q_RECOV, "Recoverable fission power"},
610
  {SCORE_CURRENT, "Current"},
611
  {SCORE_PULSE_HEIGHT, "pulse-height"},
612
  {SCORE_IFP_TIME_NUM, "IFP lifetime numerator"},
613
  {SCORE_IFP_BETA_NUM, "IFP delayed fraction numerator"},
614
  {SCORE_IFP_DENOM, "IFP common denominator"},
615
};
616

617
//! Create an ASCII output file showing all tally results.
618

619
void write_tallies()
4,629✔
620
{
621
  if (model::tallies.empty())
4,629✔
622
    return;
1,510✔
623

624
  // Set filename for tallies_out
625
  std::string filename = fmt::format("{}tallies.out", settings::path_output);
3,119✔
626

627
  // Open the tallies.out file.
628
  std::ofstream tallies_out;
3,119✔
629
  tallies_out.open(filename, std::ios::out | std::ios::trunc);
3,119✔
630

631
  // Loop over each tally.
632
  for (auto i_tally = 0; i_tally < model::tallies.size(); ++i_tally) {
17,683✔
633
    const auto& tally {*model::tallies[i_tally]};
14,564✔
634

635
    // Write header block.
636
    std::string tally_header("TALLY " + std::to_string(tally.id_));
14,564✔
637
    if (!tally.name_.empty())
14,564✔
638
      tally_header += ": " + tally.name_;
3,436✔
639
    fmt::print(tallies_out, "{}\n\n", header(tally_header));
14,564✔
640

641
    if (!tally.writable_) {
14,564✔
642
      fmt::print(tallies_out, " Internal\n\n");
425✔
643
      continue;
425✔
644
    }
645

646
    // Calculate t-value for confidence intervals
647
    double t_value = 1;
14,139✔
648
    if (settings::confidence_intervals) {
14,139✔
649
      auto alpha = 1 - CONFIDENCE_LEVEL;
8✔
650
      t_value = t_percentile(1 - alpha * 0.5, tally.n_realizations_ - 1);
8✔
651
    }
652

653
    // Write derivative information.
654
    if (tally.deriv_ != C_NONE) {
14,139✔
655
      const auto& deriv {model::tally_derivs[tally.deriv_]};
160!
656
      switch (deriv.variable) {
160!
657
      case DerivativeVariable::DENSITY:
64✔
658
        fmt::print(tallies_out, " Density derivative Material {}\n",
128✔
659
          deriv.diff_material);
64✔
660
        break;
64✔
661
      case DerivativeVariable::NUCLIDE_DENSITY:
64✔
662
        fmt::print(tallies_out,
128✔
663
          " Nuclide density derivative Material {} Nuclide {}\n",
664
          deriv.diff_material, data::nuclides[deriv.diff_nuclide]->name_);
64✔
665
        break;
64✔
666
      case DerivativeVariable::TEMPERATURE:
32✔
667
        fmt::print(tallies_out, " Temperature derivative Material {}\n",
64✔
668
          deriv.diff_material);
32✔
669
        break;
32✔
670
      default:
×
UNCOV
671
        fatal_error(fmt::format("Differential tally dependent variable for "
×
672
                                "tally {} not defined in output.cpp",
UNCOV
673
          tally.id_));
×
674
      }
675
    }
676

677
    // Initialize Filter Matches Object
678
    vector<FilterMatch> filter_matches;
28,278✔
679
    // Allocate space for tally filter matches
680
    filter_matches.resize(model::tally_filters.size());
14,139✔
681

682
    // Loop over all filter bin combinations.
683
    auto filter_iter = FilterBinIter(tally, false, &filter_matches);
14,139✔
684
    auto end = FilterBinIter(tally, true, &filter_matches);
14,139✔
685
    for (; filter_iter != end; ++filter_iter) {
6,947,421✔
686
      auto filter_index = filter_iter.index_;
687

688
      // Print info about this combination of filter bins.  The stride check
689
      // prevents redundant output.
690
      int indent = 0;
691
      for (auto i = 0; i < tally.filters().size(); ++i) {
21,887,564✔
692
        if (filter_index % tally.strides(i) == 0) {
14,954,282✔
693
          auto i_filt = tally.filters(i);
10,444,138✔
694
          const auto& filt {*model::tally_filters[i_filt]};
10,444,138✔
695
          auto& match {filter_matches[i_filt]};
10,444,138✔
696
          fmt::print(tallies_out, "{0:{1}}{2}\n", "", indent + 1,
10,444,138✔
697
            filt.text_label(match.i_bin_));
20,888,276✔
698
        }
699
        indent += 2;
14,954,282✔
700
      }
701

702
      // Loop over all nuclide and score combinations.
703
      int score_index = 0;
6,933,282✔
704
      for (auto i_nuclide : tally.nuclides_) {
14,905,084✔
705
        // Write label for this nuclide bin.
706
        if (i_nuclide == -1) {
7,971,802✔
707
          fmt::print(tallies_out, "{0:{1}}Total Material\n", "", indent + 1);
5,908,818✔
708
        } else {
709
          if (settings::run_CE) {
2,062,984✔
710
            fmt::print(tallies_out, "{0:{1}}{2}\n", "", indent + 1,
2,062,712✔
711
              data::nuclides[i_nuclide]->name_);
2,062,712✔
712
          } else {
713
            fmt::print(tallies_out, "{0:{1}}{2}\n", "", indent + 1,
272✔
714
              data::mg.nuclides_[i_nuclide].name);
272✔
715
          }
716
        }
717

718
        // Write the score, mean, and uncertainty.
719
        indent += 2;
7,971,802✔
720
        for (auto score : tally.scores_) {
18,035,212✔
721
          std::string score_name =
10,063,410✔
722
            score > 0 ? reaction_name(score) : score_names.at(score);
10,063,410✔
723
          double mean, stdev;
10,063,410✔
724
          std::tie(mean, stdev) =
10,063,410✔
725
            mean_stdev(&tally.results_(filter_index, score_index, 0),
20,126,820✔
726
              tally.n_realizations_);
10,063,410✔
727
          fmt::print(tallies_out, "{0:{1}}{2:<36} {3:.6} +/- {4:.6}\n", "",
20,126,820✔
728
            indent + 1, score_name, mean, t_value * stdev);
10,063,410✔
729
          score_index += 1;
10,063,410✔
730
        }
10,063,410✔
731
        indent -= 2;
7,971,802✔
732
      }
733
    }
734
  }
14,564✔
735
}
3,119✔
736

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