diff --git a/include/openmc/plot.h b/include/openmc/plot.h index aa15277aa..3d526cad6 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -30,9 +30,7 @@ namespace model { extern std::unordered_map plot_map; //!< map of plot ids to index extern vector plots; //!< Plot instance container -extern uint64_t - plotter_prn_seeds[N_STREAMS]; // Random number seeds used for plotter -extern int plotter_stream; // Stream index used by the plotter +extern uint64_t plotter_seed; // Stream index used by the plotter } // namespace model @@ -274,6 +272,9 @@ void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); //! Read plot specifications from a plots.xml file void read_plots_xml(); +//! Clear memory +void free_memory_plot(); + //! Create a ppm image for a plot object //! \param[in] plot object void create_ppm(Plot const& pl); diff --git a/openmc/model/model.py b/openmc/model/model.py index b35f50c87..44479d7e7 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -664,18 +664,12 @@ class Model: "before executing this method!") with _change_directory(Path(cwd)): - # TODO: openmc.is_initialized doesnt read plots.xml unless it is - # in plot mode so the following will not work. Commented out for - # now and replacing with non-C API code - self.export_to_xml() - openmc.plot_geometry(output=output, openmc_exec=openmc_exec) - - # if self.is_initialized: - # # Compute the volumes - # openmc.lib.plot_geometry(output) - # else: - # self.export_to_xml() - # openmc.plot_geometry(output=output, openmc_exec=openmc_exec) + if self.is_initialized: + # Compute the volumes + openmc.lib.plot_geometry(output) + else: + self.export_to_xml() + openmc.plot_geometry(output=output, openmc_exec=openmc_exec) if convert: for p in self.plots: diff --git a/src/finalize.cpp b/src/finalize.cpp index b1e09a37e..2f6c65aaf 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -15,6 +15,7 @@ #include "openmc/message_passing.h" #include "openmc/nuclide.h" #include "openmc/photon.h" +#include "openmc/plot.h" #include "openmc/random_lcg.h" #include "openmc/settings.h" #include "openmc/simulation.h" @@ -45,6 +46,7 @@ void free_memory() free_memory_mesh(); free_memory_tally(); free_memory_bank(); + free_memory_plot(); if (mpi::master) { free_memory_cmfd(); } @@ -128,6 +130,7 @@ int openmc_finalize() data::temperature_min = 0.0; data::temperature_max = INFTY; model::root_universe = -1; + model::plotter_seed = 1; openmc::openmc_set_seed(DEFAULT_SEED); // Deallocate arrays diff --git a/src/initialize.cpp b/src/initialize.cpp index e53767691..75ec20518 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -305,9 +305,11 @@ void read_input_xml() // Initialize distribcell_filters prepare_distribcell(); + // Read the plots.xml regardless of plot mode in case plots are requested + // via the API + read_plots_xml(); if (settings::run_mode == RunMode::PLOTTING) { // Read plots.xml if it exists - read_plots_xml(); if (mpi::master && settings::verbosity >= 5) print_plot(); diff --git a/src/plot.cpp b/src/plot.cpp index 789437691..217b09839 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -119,9 +119,11 @@ extern "C" int openmc_plot_geometry() void read_plots_xml() { - // Check if plots.xml exists + // Check if plots.xml exists; this is only necessary when the plot runmode is + // initiated. Otherwise, we want to read plots.xml because it may be called + // later via the API. In that case, its ok for a plots.xml to not exist std::string filename = settings::path_input + "plots.xml"; - if (!file_exists(filename)) { + if (!file_exists(filename) && settings::run_mode == RunMode::PLOTTING) { fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename)); } @@ -138,6 +140,12 @@ void read_plots_xml() } } +void free_memory_plot() +{ + model::plots.clear(); + model::plot_map.clear(); +} + //============================================================================== // CREATE_PPM creates an image based on user input from a plots.xml // specification in the portable pixmap format (PPM)