Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tally and Domain Filter Editor UOs #923

Open
wants to merge 60 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
56d86f6
A start to creating tallies with UOs
pshriwise May 22, 2024
ba4f527
Initial cut at at UserObject for tally generation
pshriwise Jun 25, 2024
1ca6ee9
Adding tally generator uo in a new spot
pshriwise Jun 27, 2024
4a1cf4f
Moving to reliance on a tally generator user object
pshriwise Jun 30, 2024
e260d8c
Moving to rely on tally generator user object
pshriwise Jun 30, 2024
003e4a9
push for logan
pshriwise Jul 1, 2024
31fe02f
Updating tally generator UOs to handle updates as well.
pshriwise Jul 2, 2024
e81626b
Name change. QOL funcs
pshriwise Jul 2, 2024
54d5181
One more name change
pshriwise Jul 2, 2024
8ef4c2e
Adding a domain filter editor
pshriwise Jul 3, 2024
e2f571c
Updating openmc_xml test files for now
pshriwise Jul 3, 2024
6512da4
Including a parameter for multiplication by atom density
pshriwise Jul 3, 2024
19c8ced
Removing tally generator action
pshriwise Jul 3, 2024
a283225
Reverting changes to the openmc_xml test
pshriwise Jul 3, 2024
9305b5e
Updating copywrite year.
pshriwise Jul 3, 2024
2c2d322
Added error checking. Changing timing of tally ID check.
pshriwise Jul 5, 2024
371440c
Updates to tests to use the tally editor instead of tally nuclides
pshriwise Jul 5, 2024
996544c
Some quick self-review
pshriwise Jul 8, 2024
f041ba8
Renaming test dir for tally editor
pshriwise Jul 8, 2024
5c73d9a
Removing OpenMCTallyNuclidesUO
pshriwise Jul 8, 2024
207c6b9
Missed some changes
pshriwise Jul 8, 2024
62f10d9
Applying style guide patch
pshriwise Jul 8, 2024
fe8630b
Start of docs
pshriwise Jul 8, 2024
6460bd1
Adding new test and reorganizing inputs
pshriwise Jul 9, 2024
b0307b5
Use the filter_index method
pshriwise Jul 9, 2024
85cc7b2
More tests for filters
pshriwise Jul 9, 2024
ddb6224
Adding filter tests
pshriwise Jul 9, 2024
22f52e0
Adding new tests and correcting filter editor constructor code
pshriwise Jul 9, 2024
a366788
Creating a base class for OpenMC user objects
pshriwise Jul 9, 2024
2ecf25d
Formatting test input files
pshriwise Jul 10, 2024
47db4a7
OpenMC user object source file formatting
pshriwise Jul 10, 2024
7618cbb
Applying style guide
pshriwise Jul 10, 2024
2f6a120
Updating documentation for object editor UOs
pshriwise Jul 10, 2024
cb8b75c
Updates to control, checks, and execution of OpenMC editor UOs
pshriwise Jul 10, 2024
d41464c
Adding tests for clashing editor IDs
pshriwise Jul 10, 2024
04cca8f
Adding test for invalid tally score
pshriwise Jul 10, 2024
58e83db
Adding an XML tally to test clashes with existing filter types.
pshriwise Jul 10, 2024
3747b05
New test for clashing type with existing filter.
pshriwise Jul 10, 2024
37513d7
CI trigger
pshriwise Jul 11, 2024
adf7948
Test input file formatting
pshriwise Jul 11, 2024
ced4b2a
Source formatting
pshriwise Jul 11, 2024
cd6a8f7
Correcting filter editor UO class name in docs
pshriwise Jul 11, 2024
cd6904c
Updating comment on allowed filter types
pshriwise Jul 12, 2024
06c9caa
Moving _first_execution into base class
pshriwise Jul 12, 2024
3a1fe15
Factoring out first_execution method into base object
pshriwise Jul 12, 2024
89daf68
Use UO console
pshriwise Jul 12, 2024
bcdf830
Changing filter type attribute to an enumerator
pshriwise Jul 12, 2024
9ede8c3
EOL for cardinal enums src file
pshriwise Jul 12, 2024
b5533af
CI trigger
pshriwise Jul 13, 2024
2a37b87
CI trigger
pshriwise Jul 15, 2024
7f3a512
Updating expected behavior and test files
pshriwise Aug 21, 2024
9e7b3b6
Breaking up the current tallies section a bit. Adding a section on ta…
pshriwise Aug 21, 2024
9646b61
Remove commented section
pshriwise Aug 21, 2024
6f16ad3
Style guide fix
pshriwise Aug 21, 2024
8ea3dbc
Style fix
pshriwise Aug 21, 2024
50715ec
Clarifying use case for Tally/Filter editors.
pshriwise Sep 19, 2024
c578788
Removing unused OpenMCDomainFilter::_allowed_types attribute
pshriwise Sep 19, 2024
b25c149
Ensuring that TallyEditor IDs don't overlap with Cardinal-mapped tallies
pshriwise Sep 19, 2024
c0d8a83
Formatting
pshriwise Sep 19, 2024
107d06f
Adding new test input file
pshriwise Sep 19, 2024
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
17 changes: 16 additions & 1 deletion doc/content/source/problems/OpenMCCellAverageProblem.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ regions where there are no cells at that level.

## Adding Tallies

### Mapped Tallies

This class takes the tally objects initialized by the `[Tallies]` block and use them to construct
tally auxvariables. At the moment there are two options for discretizing tallies spatially in Cardinal:

Expand All @@ -308,6 +310,8 @@ $k$-eigenvalue or fixed-source problem). By default, the normalization is done a
tally added over the entire OpenMC domain. By setting `normalize_by_global_tally` to false, however,
the tally is instead normalized by the sum of the tally itself.

### Mapped Tally Scores

You can customize the type of score that Cardinal uses to normalize tallies to `power` with the `source_rate_normalization`
parameter. Options include:

Expand Down Expand Up @@ -341,7 +345,9 @@ by Cardinal. Note that for all area or volume units in [tally_units], that those
| `flux` | particle - cm / source particle | particle / area / second |
| `H3_production` | tritium / source particle | tritium / volume / second |

This units-transformation
### Tally Normalization

The tally units-transformation
process involves *division by a volume*. In Cardinal, there are two different notions of volume:

- The volume of the `[Mesh]` elements which *map* to a tally bin region
Expand Down Expand Up @@ -378,6 +384,15 @@ already are exactly the same volume, then no special thought is needed for the t
normalization, and the value will be exactly consistent with the interpretation
used in OpenMC.

## Tally and Filter Editors

Cardinal provides UserObjects for editing tallies and filters.

- [OpenMCTallyEditor](https://cardinal.cels.anl.gov/source/userobjects/OpenMCTallyEditor.html)
- [OpenMCDomainFilterEditor](https://cardinal.cels.anl.gov/source/userobjects/OpenMCTallyEditor.html)

These objects provide online control of tally and filter parameters, respectively. These objects can be used to interact with tallies and/or filters that are mapped in Cardinal as part of the `OpenMCCellAverageProblem` or are present in a `tallies.xml` file for the problem being run (unmapped tallies). These objects can be used to create tallies as well -- in this case the new objects will **not be mapped** to the mesh mirror.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend revising this section of the documentation to make it clear to the user that mapped tallies cannot be modified by either OpenMCTallyEditor or OpenMCDomainFilterEditor.


## Other Features

While this class mainly facilitates data transfers to and from OpenMC, a number of
Expand Down
20 changes: 20 additions & 0 deletions doc/content/source/userobjects/OpenMCDomainFilterEditor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OpenMCDomainFilterEditor

!syntax description /UserObjects/OpenMCDomainFilterEditor

## Description

This user object can be used to create or control new domain filter in OpenMC.
Currently suppored filter types are specified under the "filter_type" parameter.
The filter bins are set using domain ID(s) in the OpenMC model.

## Example Input Syntax

!listing test/tests/userobjects/openmc_tally_editor/add_filter.i
block=UserObjects

!syntax parameters /UserObjects/OpenMCDomainFilterEditor

!syntax inputs /UserObjects/OpenMCDomainFilterEditor

!syntax children /UserObjects/OpenMCDomainFilterEditor
25 changes: 25 additions & 0 deletions doc/content/source/userobjects/OpenMCTallyEditor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# OpenMCTallyEditor

!syntax description /UserObjects/OpenMCTallyEditor

## Description

This user object can be used to change the nuclides, filters, and scores on a
given OpenMC tally. This object is primarily used for facilitating depletion
coupling of OpenMC to MOOSE, where we need to register new tallies with
controllable parameters to account for changing compositions during depletion.

## Example Input Syntax

Below is an example which will create an OpenMC tally with controllable parameters
tally to only obtain the fission heating from U-238 (ignoring the
portion from U-235 in this particular tally).

!listing test/tests/userobjects/openmc_tally_editor/nuclide_absorption.i
block=UserObjects

!syntax parameters /UserObjects/OpenMCTallyEditor

!syntax inputs /UserObjects/OpenMCTallyEditor

!syntax children /UserObjects/OpenMCTallyEditor
25 changes: 0 additions & 25 deletions doc/content/source/userobjects/OpenMCTallyNuclides.md

This file was deleted.

10 changes: 10 additions & 0 deletions include/base/CardinalEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MooseEnum getTallyTriggerEnum();
MooseEnum getInitialPropertiesEnum();
MultiMooseEnum getTallyScoreEnum();
MooseEnum getNekMeshEnum();
MooseEnum getFilterTypeEnum();

namespace nek_mesh
{
Expand Down Expand Up @@ -211,3 +212,12 @@ enum RelaxationEnum
none
};
} // namespace relaxation

enum OpenMCFilterType
{
cell,
material,
universe,
mesh,
none
};
22 changes: 19 additions & 3 deletions include/base/OpenMCProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "PostprocessorInterface.h"
#include "CardinalEnums.h"
#include "OpenMCNuclideDensities.h"
#include "OpenMCTallyNuclides.h"
#include "OpenMCDomainFilterEditor.h"
#include "OpenMCTallyEditor.h"

#include "mpi.h"
#include "openmc/bank.h"
Expand Down Expand Up @@ -340,6 +341,18 @@ class OpenMCProblemBase : public CardinalProblem, public PostprocessorInterface
/// Find all userobjects which are changing OpenMC data structures
void getOpenMCUserObjects();

/// Ensure that the IDs of OpenMC objects in UserObjects don't clash
void checkOpenMCUserObjectIDs() const;

/// Execute all filter editor userobjects
void executeFilterEditors();

/// Execute all tally editor userobjects
void executeTallyEditors();

// execute all userobjects that change OpenMC filters
void executeTallyUpdates();

/// Set the nuclide densities for any materials being modified via MOOSE
void sendNuclideDensitiesToOpenMC();

Expand Down Expand Up @@ -439,8 +452,11 @@ class OpenMCProblemBase : public CardinalProblem, public PostprocessorInterface
/// Userobjects for changing OpenMC material compositions
std::vector<OpenMCNuclideDensities *> _nuclide_densities_uos;

/// Userobjects for changing OpenMC tally nuclides
std::vector<OpenMCTallyNuclides *> _tally_nuclides_uos;
/// Userobjects for creating/changing OpenMC filters
std::vector<OpenMCDomainFilterEditor *> _filter_editor_uos;

/// Userobjects for creating/changing OpenMC tallies
std::vector<OpenMCTallyEditor *> _tally_editor_uos;

/// Mapping from local element indices to global element indices for this rank
std::vector<unsigned int> _local_to_global_elem;
Expand Down
70 changes: 70 additions & 0 deletions include/userobjects/OpenMCDomainFilterEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/********************************************************************/
/* SOFTWARE COPYRIGHT NOTIFICATION */
/* Cardinal */
/* */
/* (c) 2024 UChicago Argonne, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by UChicago Argonne, LLC */
/* Under Contract No. DE-AC02-06CH11357 */
/* With the U. S. Department of Energy */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See LICENSE for full restrictions */
/********************************************************************/

#pragma once

#include "OpenMCUserObject.h"

#include "CardinalEnums.h"

// forward declarations
class OpenMCProblemBase;

/**
* User object to create and/or modify an OpenMC tally filter for a limited set of domain types.
*/
class OpenMCDomainFilterEditor : public OpenMCUserObject
{
public:
static InputParameters validParams();

OpenMCDomainFilterEditor(const InputParameters & parameters);

/// Virtual method overrides
virtual void execute() override;
virtual void initialize() override;
virtual void finalize() override {}

/**
* Get the index of the filter in OpenMC's data space
*/
bool filter_exists() const;

/**
* Return the index of the filter in the OpenMC data space
*/
int32_t filter_index() const;

/**
* Check that this object's filter type is valid and matches the type in the OpenMC data space
*/
void check_filter_type_match() const;

std::string filterTypeEnumToString(OpenMCFilterType t) const;
OpenMCFilterType stringToFilterTypeEnum(const std::string & s) const;

std::string long_name() const { return "OpenMCDomainFilterEditor \"" + this->name() + "\""; }

// Accessors
int32_t filter_id() const { return _filter_id; }

protected:
int32_t _filter_id;
OpenMCFilterType _filter_type;
const std::set<std::string> _allowed_types{"cell", "universe", "material", "mesh"};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Convention is to use a MooseEnum if possible

};
54 changes: 54 additions & 0 deletions include/userobjects/OpenMCTallyEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/********************************************************************/
/* SOFTWARE COPYRIGHT NOTIFICATION */
/* Cardinal */
/* */
/* (c) 2024 UChicago Argonne, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by UChicago Argonne, LLC */
/* Under Contract No. DE-AC02-06CH11357 */
/* With the U. S. Department of Energy */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See LICENSE for full restrictions */
/********************************************************************/

#pragma once

#include "OpenMCUserObject.h"

// forward declarations
class OpenMCProblemBase;

/**
* User object to modify an OpenMC tally
*/
class OpenMCTallyEditor : public OpenMCUserObject
{
public:
static InputParameters validParams();

OpenMCTallyEditor(const InputParameters & parameters);

bool tally_exists() const;

// get the index of the tally in OpenMC's data space, creating it if necessary according to the
// input parameters
int32_t tally_index() const;

/// We don't want this user object to execute in MOOSE's control
virtual void execute() override;
virtual void initialize() override;
virtual void finalize() override {}

std::string long_name() const { return "OpenMCTallyEditor \"" + this->name() + "\""; }

// Accessors
int32_t tally_id() const { return _tally_id; }

protected:
int32_t _tally_id;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* SOFTWARE COPYRIGHT NOTIFICATION */
/* Cardinal */
/* */
/* (c) 2021 UChicago Argonne, LLC */
/* (c) 2024 UChicago Argonne, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by UChicago Argonne, LLC */
Expand All @@ -20,29 +20,25 @@

#include "GeneralUserObject.h"

// forward declarations
class OpenMCProblemBase;

/**
* User object to modify the nuclides in an OpenMC tally.
* User object to modify an OpenMC object
*/
class OpenMCTallyNuclides : public GeneralUserObject
class OpenMCUserObject : public GeneralUserObject
{
public:
static InputParameters validParams();

OpenMCTallyNuclides(const InputParameters & parameters);
OpenMCUserObject(const InputParameters & parameters);

/// We don't want this user object to execute in MOOSE's control
virtual void execute() override {}
void execute() override;

virtual void initialize() override {}
virtual void finalize() override {}
std::string long_name() const { return "OpenMCUserObject \"" + this->name() + "\""; }

/// Instead, we want to have a separate method that we can call from the OpenMC problem
virtual void setValue();
const OpenMCProblemBase * openmc_problem() const;

protected:
/// The tally index
int32_t _tally_index;

/// Nuclide names
const std::vector<std::string> & _names;
bool _first_execution;
};
2 changes: 2 additions & 0 deletions src/base/CardinalAppTypes.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "ExecFlagRegistry.h"

#ifdef ENABLE_OPENMC_COUPLING
const ExecFlagType EXEC_FILTER_GENERATORS = registerExecFlag("EXEC_FILTER_GENERATORS");
const ExecFlagType EXEC_TALLY_GENERATORS = registerExecFlag("EXEC_TALLY_GENERATORS");
const ExecFlagType EXEC_SEND_OPENMC_DENSITIES = registerExecFlag("SEND_OPENMC_DENSITIES");
const ExecFlagType EXEC_SEND_OPENMC_TALLY_NUCLIDES = registerExecFlag("SEND_OPENMC_TALLY_NUCLIDES");
#endif
6 changes: 6 additions & 0 deletions src/base/CardinalEnums.C
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ getTallyScoreEnum()
{
return MultiMooseEnum("heating heating_local kappa_fission fission_q_prompt fission_q_recoverable damage_energy flux H3_production");
}

MooseEnum
getFilterTypeEnum()
{
return MooseEnum("cell material universe mesh none", "none");
}
2 changes: 0 additions & 2 deletions src/base/OpenMCCellAverageProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -2322,8 +2322,6 @@ OpenMCCellAverageProblem::syncSolutions(ExternalProblem::Direction direction)
// amounts of the different nuclides)
sendNuclideDensitiesToOpenMC();

sendTallyNuclidesToOpenMC();

if (_first_transfer && (_specified_temperature_feedback || _specified_density_feedback))
{
std::string incoming_transfer =
Expand Down
Loading