Skip to content

Commit c1aa9b2

Browse files
jtrammclaude
andcommitted
Inline solve type comparisons instead of accessor functions
adjoint() and outputs_are_intermediate() each had only a few call sites, and the direct comparisons against RandomRaySolve enumerators are clearer than the function names they were hidden behind. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 267368b commit c1aa9b2

6 files changed

Lines changed: 15 additions & 21 deletions

File tree

include/openmc/random_ray/flat_source_domain.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ class FlatSourceDomain {
7373
int64_t lookup_mesh_bin(int64_t sr, Position r) const;
7474
int lookup_mesh_idx(int64_t sr) const;
7575

76-
// True while the adjoint solve is executing
77-
static bool adjoint() { return solve_ == RandomRaySolve::ADJOINT; }
78-
79-
// True while the initial forward solve of an adjoint (FW-CADIS) run is
80-
// executing. Output files written by this solve are tagged "forward" so that
81-
// the subsequent adjoint solve does not overwrite them, and no weight window
82-
// file is written.
83-
static bool outputs_are_intermediate()
84-
{
85-
return solve_ == RandomRaySolve::FORWARD_FOR_ADJOINT;
86-
}
87-
8876
//----------------------------------------------------------------------------
8977
// Static Data members
9078
static bool volume_normalized_flux_tallies_;

src/output.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,9 @@ void write_tallies()
623623

624624
// Tag tallies.out written during the forward solve of an adjoint run
625625
const char* forward =
626-
FlatSourceDomain::outputs_are_intermediate() ? "forward." : "";
626+
(FlatSourceDomain::solve_ == RandomRaySolve::FORWARD_FOR_ADJOINT)
627+
? "forward."
628+
: "";
627629

628630
// Set filename for tallies_out
629631
std::string filename =

src/random_ray/flat_source_domain.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ double FlatSourceDomain::compute_fixed_source_normalization_factor() const
557557
// If we are in adjoint mode of a fixed source problem, the external
558558
// source is already normalized, such that all resulting fluxes are
559559
// also normalized.
560-
if (adjoint()) {
560+
if (solve_ == RandomRaySolve::ADJOINT) {
561561
return 1.0;
562562
}
563563

@@ -797,7 +797,7 @@ void FlatSourceDomain::output_to_vtk() const
797797
std::string filename = openmc_plot->path_plot();
798798

799799
// Tag plots written during the forward solve of an adjoint run
800-
if (outputs_are_intermediate()) {
800+
if (solve_ == RandomRaySolve::FORWARD_FOR_ADJOINT) {
801801
auto dot = filename.find_last_of('.');
802802
filename = filename.substr(0, dot) + ".forward" + filename.substr(dot);
803803
}
@@ -1009,9 +1009,10 @@ void FlatSourceDomain::output_to_vtk() const
10091009
void FlatSourceDomain::apply_external_source_to_source_region(
10101010
int src_idx, SourceRegionHandle& srh)
10111011
{
1012-
auto s = (adjoint() && !model::adjoint_sources.empty())
1013-
? model::adjoint_sources[src_idx].get()
1014-
: model::external_sources[src_idx].get();
1012+
auto s =
1013+
(solve_ == RandomRaySolve::ADJOINT && !model::adjoint_sources.empty())
1014+
? model::adjoint_sources[src_idx].get()
1015+
: model::external_sources[src_idx].get();
10151016
auto is = dynamic_cast<IndependentSource*>(s);
10161017
auto discrete = dynamic_cast<Discrete*>(is->energy());
10171018
double strength_factor = is->strength();

src/random_ray/random_ray_simulation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ void RandomRaySimulation::print_results_random_ray(
602602
}
603603
fmt::print(" Volume Estimator Type = {}\n", estimator);
604604

605-
std::string adjoint_true = (FlatSourceDomain::adjoint()) ? "ON" : "OFF";
605+
std::string adjoint_true =
606+
(FlatSourceDomain::solve_ == RandomRaySolve::ADJOINT) ? "ON" : "OFF";
606607
fmt::print(" Adjoint Flux Mode = {}\n", adjoint_true);
607608

608609
std::string shape;

src/simulation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ int openmc_simulation_finalize()
206206
// adjoint (FW-CADIS) run, where only the adjoint-derived weight windows
207207
// are meaningful.
208208
if (variance_reduction::weight_windows_generators.size() > 0 &&
209-
!FlatSourceDomain::outputs_are_intermediate()) {
209+
FlatSourceDomain::solve_ != RandomRaySolve::FORWARD_FOR_ADJOINT) {
210210
openmc_weight_windows_export();
211211
}
212212

src/state_point.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ extern "C" int openmc_statepoint_write(const char* filename, bool* write_source)
4949

5050
// Tag statepoints written during the forward solve of an adjoint run
5151
const char* forward =
52-
FlatSourceDomain::outputs_are_intermediate() ? "forward." : "";
52+
(FlatSourceDomain::solve_ == RandomRaySolve::FORWARD_FOR_ADJOINT)
53+
? "forward."
54+
: "";
5355

5456
// Set filename for state point
5557
filename_ = fmt::format("{0}statepoint.{3}{1:0{2}}.h5",

0 commit comments

Comments
 (0)