Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/base/OpenMCProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,20 @@ class OpenMCProblemBase : public CardinalProblem, public PostprocessorInterface
std::to_string(_fixed_point_iteration) + ".h5";
}

/**
* Return path to write current timestep's statepoint to in transient solves.
* @return statepoint path
*/
const std::string transientStatepointPath();
Comment thread
TheBEllis marked this conversation as resolved.

/**
* Formats `path_output` so that it is ready to be passed to
* openmc::settings::path_output
* @param[in] path_output unformatted path
* @return formatted absolute path
*/
const std::string formattedOutputPath(const std::string & path_output);
Comment thread
TheBEllis marked this conversation as resolved.

/// Whether to print diagnostic information about model setup and the transfers
const bool & _verbose;

Expand Down Expand Up @@ -567,6 +581,12 @@ class OpenMCProblemBase : public CardinalProblem, public PostprocessorInterface
/// Directory in which OpenMC settings xml files are located
const std::string & _xml_directory;

/// Directory to write statepoint file to
const std::string & _statepoint_directory;

/// Parameter determines whether statepoints from all timesteps should be saved in separtate directories to avoid them being overwritten
Comment thread
aprilnovak marked this conversation as resolved.
const bool _keep_transient_statepoint;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bool _keep_transient_statepoint;
const bool & _keep_transient_statepoint;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capturing by reference is recommended by MOOSE convention when possible because it'll be compatible with controls and other systems


/// Conversion unit to transfer between kg/m3 and g/cm3
static constexpr Real _density_conversion_factor{0.001};

Expand Down
106 changes: 105 additions & 1 deletion src/base/OpenMCProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ OpenMCProblemBase::validParams()
"The number of generations to use with the method of iterated fission probabilities.");
params.addParam<FileName>(
"xml_directory", "./", "The directory in which to look for OpenMC XML files.");

params.addParam<FileName>(
"statepoint_directory",
"./",
"The directory to write statepoint files to. Sets openmc::settings::path_output.");

params.addParam<bool>("keep_transient_statepoint",
false,
"Whether or not statepoints from all timesteps should be kept, and written "
"to seperate directories.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"to seperate directories.");
"to separate directories.");


return params;
}

Expand All @@ -116,7 +127,9 @@ OpenMCProblemBase::OpenMCProblemBase(const InputParameters & params)
_calc_kinetics_params(getParam<bool>("calc_kinetics_params")),
_reset_seed(getParam<bool>("reset_seed")),
_initial_seed(openmc::openmc_get_seed()),
_xml_directory(getParam<FileName>("xml_directory"))
_xml_directory(getParam<FileName>("xml_directory")),
_statepoint_directory(getParam<FileName>("statepoint_directory")),
_keep_transient_statepoint(getParam<bool>("keep_transient_statepoint"))
{
if (isParamValid("tally_type"))
mooseError("The tally system used by OpenMCProblemBase derived classes has been deprecated. "
Expand Down Expand Up @@ -233,6 +246,22 @@ OpenMCProblemBase::OpenMCProblemBase(const InputParameters & params)
catchOpenMCError(err, "set the number of batches");
}

if (isParamSetByUser("statepoint_directory") && !_keep_transient_statepoint)
{
/// path_output must end with a "/", otherwise statepoint will not output correctly
openmc::settings::path_output = formattedOutputPath(_statepoint_directory);

/// Need to remove trailing "/" to do "is_regular_file"
std::filesystem::path p = openmc::settings::path_output;
p = p.filename().empty() ? p.parent_path() : p;

if (std::filesystem::is_regular_file(p))
mooseError("Cannot create directory " + openmc::settings::path_output +
", as a file with the same name already exists");

std::filesystem::create_directory(openmc::settings::path_output);
}

// The OpenMC wrapping doesn't require material properties itself, but we might
// define them on some blocks of the domain for other auxiliary kernel purposes
setMaterialCoverageCheck(false);
Expand Down Expand Up @@ -375,6 +404,19 @@ OpenMCProblemBase::externalSolve()
// update tallies as needed before starting the OpenMC run
executeEditors();

if (_keep_transient_statepoint)
{
openmc::settings::path_output = transientStatepointPath();

/// Need to remove trailing "/" to do "is_regular_file"
std::filesystem::path p = openmc::settings::path_output;
p = p.filename().empty() ? p.parent_path() : p;
if (std::filesystem::is_regular_file(p))
mooseError("Cannot create directory " + openmc::settings::path_output +
", as a file with the same name already exists");
std::filesystem::create_directory(openmc::settings::path_output);
}

if (_reset_seed)
{
openmc_hard_reset();
Expand Down Expand Up @@ -1030,4 +1072,66 @@ OpenMCProblemBase::sendNuclideDensitiesToOpenMC()
uo->setValue();
}

const std::string
OpenMCProblemBase::transientStatepointPath()
{
if (!isTransient())
{
mooseWarning("keep_transient_statepoint is set to True, but selected Executioner is Steady. "
"Keeping original statepoint path.");
return openmc::settings::path_output;
}

// Get path of current input file
std::filesystem::path running_path =
std::filesystem::absolute(getMooseApp().getLastInputFileName()).parent_path();

std::filesystem::path transient_statepoint_path;

// If user has not set statepoint_directory parameter, or has defined it as './',
// use a default
if (std::filesystem::weakly_canonical(_statepoint_directory) ==
std::filesystem::weakly_canonical(running_path))
transient_statepoint_path = "./statepoint_folder";
else
{
transient_statepoint_path = _statepoint_directory;

// Removes trailing "/" from transient_statepoint_path, if user has left any, ready to append
// suffix
transient_statepoint_path = transient_statepoint_path.filename().empty()
? transient_statepoint_path.parent_path()
: transient_statepoint_path;
}

std::string timestep_suffix = "_ts_" + std::to_string(timeStep()) + "/";

transient_statepoint_path += timestep_suffix;

const std::string transient_statepoint_path_str =
formattedOutputPath(transient_statepoint_path.string());

return transient_statepoint_path_str;
}

const std::string
OpenMCProblemBase::formattedOutputPath(const std::string & output_path)
{
std::filesystem::path p = output_path;
p = p.lexically_normal();

if (p.is_relative())
{
std::filesystem::path input_file_path =
std::filesystem::absolute(getMooseApp().getLastInputFileName()).parent_path();

p = std::filesystem::weakly_canonical(input_file_path / p);
}

if (p.string().back() != '/')
p += "/";

return p.string();
}

#endif
Empty file.
27 changes: 27 additions & 0 deletions test/tests/neutronics/openmc_statepoint/openmc_custom_dir.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Mesh]
[sphere]
type = FileMeshGenerator
file = ../meshes/sphere.e
[]
[]

[Problem]
type = OpenMCCellAverageProblem
statepoint_directory = "./custom_dir"
batches = 50
[]

[Executioner]
type = Transient
num_steps = 1
[]

[Postprocessors]
[k]
type = KEigenvalue
[]
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Mesh]
[sphere]
type = FileMeshGenerator
file = ../meshes/sphere.e
[]
[]

[Problem]
type = OpenMCCellAverageProblem
statepoint_directory = "./existing_file"
batches = 50
[]

[Executioner]
type = Transient
num_steps = 1
[]

[Postprocessors]
[k]
type = KEigenvalue
[]
[]

[Outputs]
csv = true
[]
24 changes: 24 additions & 0 deletions test/tests/neutronics/openmc_statepoint/tests
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,28 @@
"in settings.xml and they are both specified."
capabilities = 'openmc'
[]

[check_statepoint_exists_in_directory]
type = CheckFiles
input = openmc_custom_dir.i
check_files = 'custom_dir/statepoint.50.h5'
# This test has very few particles, and OpenMC will error if there aren't enough source particles
# in the fission bank on a process
max_parallel = 8
requirement = "A statepoint file must be written to the parameter defined directory when the batches parameter matches the batches "
"in settings.xml and they are both specified."
capabilities = 'openmc'
[]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure each test has a issues and design parameter



[check_statepoint_exists_in_directory_w_existing_filename]
type = RunException
input = openmc_custom_dir_filename.i
expect_err = 'a file with the same name already exists'
# This test has very few particles, and OpenMC will error if there aren't enough source particles
# in the fission bank on a process
max_parallel = 8
requirement = "The user defined directory has the same name as an existing file. Expect test to throw due to attempting to create directory with the same name as the file."
capabilities = 'openmc'
[]
[]
16 changes: 16 additions & 0 deletions test/tests/neutronics/openmc_statepoint_transient/geometry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" region="-1" universe="1" />
<cell id="2" material="2" region="-2" universe="1" />
<cell id="3" material="3" region="-3" universe="1" />
<cell id="4" material="4" region="1 2 3 4 -5 6 -7 8 -9" universe="1" />
<surface coeffs="0.0 0.0 0.0 1.5" id="1" type="sphere" />
<surface coeffs="0.0 0.0 4.0 1.5" id="2" type="sphere" />
<surface coeffs="0.0 0.0 8.0 1.5" id="3" type="sphere" />
<surface boundary="reflective" coeffs="-2.5" id="4" name="minimum x" type="x-plane" />
<surface boundary="reflective" coeffs="2.5" id="5" name="maximum x" type="x-plane" />
<surface boundary="reflective" coeffs="-2.5" id="6" name="minimum y" type="y-plane" />
<surface boundary="reflective" coeffs="2.5" id="7" name="maximum y" type="y-plane" />
<surface boundary="reflective" coeffs="-2.0" id="8" type="z-plane" />
<surface boundary="reflective" coeffs="10.0" id="9" type="z-plane" />
</geometry>
40 changes: 40 additions & 0 deletions test/tests/neutronics/openmc_statepoint_transient/materials.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version='1.0' encoding='utf-8'?>
<materials>
<material depletable="true" id="1">
<density units="g/cc" value="10.0" />
<nuclide ao="9.051308944870946e-05" name="U234" />
<nuclide ao="0.010126612654073502" name="U235" />
<nuclide ao="0.9897364895065476" name="U238" />
<nuclide ao="4.63847499302226e-05" name="U236" />
<nuclide ao="1.999242" name="O16" />
<nuclide ao="0.000758" name="O17" />
</material>
<material depletable="true" id="2">
<density units="g/cc" value="10.0" />
<nuclide ao="0.0004523305496680539" name="U234" />
<nuclide ao="0.05060678290832386" name="U235" />
<nuclide ao="0.948709083169038" name="U238" />
<nuclide ao="0.00023180337297007338" name="U236" />
<nuclide ao="1.999242" name="O16" />
<nuclide ao="0.000758" name="O17" />
</material>
<material depletable="true" id="3">
<density units="g/cc" value="10.0" />
<nuclide ao="0.0009040745407538578" name="U234" />
<nuclide ao="0.10114794158928406" name="U235" />
<nuclide ao="0.8974846777145036" name="U238" />
<nuclide ao="0.00046330615545845175" name="U236" />
<nuclide ao="1.999242" name="O16" />
<nuclide ao="0.000758" name="O17" />
</material>
<material depletable="true" id="4">
<density units="g/cc" value="1.0" />
<nuclide ao="1.99968852" name="H1" />
<nuclide ao="0.00031148" name="H2" />
<nuclide ao="0.999621" name="O16" />
<nuclide ao="0.000379" name="O17" />
<nuclide ao="5.4e-05" name="U234" />
<nuclide ao="0.007204" name="U235" />
<nuclide ao="0.992742" name="U238" />
</material>
</materials>
27 changes: 27 additions & 0 deletions test/tests/neutronics/openmc_statepoint_transient/openmc.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Mesh]
[sphere]
type = FileMeshGenerator
file = ../meshes/sphere.e
[]
[]

[Problem]
type = OpenMCCellAverageProblem
keep_transient_statepoint = true
batches = 50
[]

[Executioner]
type = Transient
num_steps = 2
[]

[Postprocessors]
[k]
type = KEigenvalue
[]
[]

[Outputs]
csv = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[Mesh]
[sphere]
type = FileMeshGenerator
file = ../meshes/sphere.e
[]
[]

[Problem]
type = OpenMCCellAverageProblem
keep_transient_statepoint = true
statepoint_directory = "./mystatepoints/"
batches = 50
[]

[Executioner]
type = Transient
num_steps = 2
[]

[Postprocessors]
[k]
type = KEigenvalue
[]
[]

[Outputs]
csv = true
[]
16 changes: 16 additions & 0 deletions test/tests/neutronics/openmc_statepoint_transient/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>100</particles>
<batches>50</batches>
<inactive>10</inactive>
<source strength="1.0">
<space type="fission">
<parameters>-5.0 -5.0 0 5.0 5.0 12.0</parameters>
</space>
</source>
<temperature_default>600.0</temperature_default>
<temperature_method>nearest</temperature_method>
<temperature_multipole>false</temperature_multipole>
<temperature_range>294.0 1600.0</temperature_range>
</settings>
Loading