Cardinal
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
OpenMCProblemBase Class Reference

#include <OpenMCProblemBase.h>

Inheritance diagram for OpenMCProblemBase:
[legend]

Public Types

typedef std::pair< int32_t, int32_t > cellInfo
 

Public Member Functions

 OpenMCProblemBase (const InputParameters &params)
 
virtual ~OpenMCProblemBase () override
 
std::string subdomainName (const SubdomainID &id) const
 
void catchOpenMCError (const int &err, const std::string descriptor) const
 
bool isReactionRateScore (const std::string &score) const
 
bool isHeatingScore (const std::string &score) const
 
unsigned int addExternalVariable (const std::string &name, const std::vector< SubdomainName > *block=nullptr)
 
const Real & scaling () const
 
bool hasScaling () const
 
std::string enumToTallyScore (const std::string &score) const
 
std::string tallyScoreToEnum (const std::string &score) const
 
virtual void geometryType (bool &has_csg_universe, bool &has_dag_universe) const
 
bool firstSolve () const
 Whether this is the first time OpenMC is running. More...
 
openmc::TriggerMetric triggerMetric (trigger::TallyTriggerTypeEnum trigger) const
 
openmc::TriggerMetric triggerMetric (std::string trigger) const
 
openmc::TallyEstimator tallyEstimator (tally::TallyEstimatorEnum estimator) const
 
std::string estimatorToString (openmc::TallyEstimator estimator) const
 
void externalSolve () override
 Run a k-eigenvalue OpenMC simulation. More...
 
void importProperties () const
 Import temperature and density from a properties.h5 file. More...
 
xt::xtensor< double, 1 > tallySum (openmc::Tally *tally, const unsigned int &score) const
 Compute the sum of a tally within each bin. More...
 
double tallySumAcrossBins (std::vector< openmc::Tally * > tally, const unsigned int &score) const
 
double tallyMeanAcrossBins (std::vector< openmc::Tally * > tally, const unsigned int &score) const
 
bool cellIsVoid (const cellInfo &cell_info) const
 
bool cellHasZeroInstances (const cellInfo &cell_info) const
 
std::string materialName (const int32_t index) const
 
xt::xtensor< double, 1 > relativeError (const xt::xtensor< double, 1 > &sum, const xt::xtensor< double, 1 > &sum_sq, const int &n_realizations) const
 
const Real & densityConversionFactor () const
 
int nParticles () const
 
int nTotalParticles () const
 
int32_t cellID (const int32_t index) const
 
int32_t materialID (const int32_t index) const
 
std::string printPoint (const Point &p) const
 
std::string printMaterial (const int32_t &index) const
 
void writeSourceBank (const std::string &filename)
 
unsigned int numElemsInSubdomain (const SubdomainID &id) const
 
bool isLocalElem (const Elem *elem) const
 
unsigned int globalElemID (const unsigned int &id) const
 
virtual void setCellTemperature (const int32_t &id, const int32_t &instance, const Real &T, const cellInfo &cell_info) const
 
virtual void setCellDensity (const Real &density, const cellInfo &cell_info) const
 
virtual std::string printCell (const cellInfo &cell_info, const bool brief=false) const
 
virtual std::vector< int32_t > cellFill (const cellInfo &cell_info, int &fill_type) const
 
bool materialFill (const cellInfo &cell_info, int32_t &material_index) const
 
long unsigned int numCells () const
 
template<typename T >
void checkDuplicateEntries (const std::vector< T > &var, const std::string &name) const
 
void checkDuplicateVariableName (const std::string &name) const
 
bool stringHasEnding (std::string const &full, std::string const &ending) const
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

void getOpenMCUserObjects ()
 Find all userobjects which are changing OpenMC data structures. More...
 
void sendNuclideDensitiesToOpenMC ()
 Set the nuclide densities for any materials being modified via MOOSE. More...
 
void sendTallyNuclidesToOpenMC ()
 Set the tally nuclides for any tallies being modified via MOOSE. More...
 
void fillElementalAuxVariable (const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
 
std::string sourceBankFileName () const
 

Protected Attributes

const bool & _verbose
 Whether to print diagnostic information about model setup and the transfers. More...
 
const Real * _power
 Power by which to normalize the OpenMC results, for k-eigenvalue mode. More...
 
const Real * _source_strength
 Source strength by which to normalize the OpenMC results, for fixed source mode. More...
 
bool _reuse_source
 
const bool _specified_scaling
 Whether a mesh scaling was specified by the user. More...
 
const Real & _scaling
 
const bool & _skip_statepoint
 Whether to skip writing statepoints from OpenMC. More...
 
int _fixed_point_iteration
 
unsigned int _total_n_particles
 Total number of particles simulated. More...
 
long unsigned int _n_openmc_cells
 Total number of unique OpenMC cell IDs + instances combinations. More...
 
int _n_cell_digits
 
openmc::RunMode _run_mode
 OpenMC run mode. More...
 
std::vector< OpenMCNuclideDensities * > _nuclide_densities_uos
 Userobjects for changing OpenMC material compositions. More...
 
std::vector< OpenMCTallyNuclides * > _tally_nuclides_uos
 Userobjects for changing OpenMC tally nuclides. More...
 
std::vector< unsigned int > _local_to_global_elem
 Mapping from local element indices to global element indices for this rank. More...
 

Static Protected Attributes

static constexpr Real _density_conversion_factor {0.001}
 Conversion unit to transfer between kg/m3 and g/cm3. More...
 
static constexpr int MATERIAL_VOID {-1}
 ID used by OpenMC to indicate that a material fill is VOID. More...
 

Detailed Description

Base class for all MOOSE wrappings of OpenMC

Member Typedef Documentation

◆ cellInfo

typedef std::pair<int32_t, int32_t> OpenMCProblemBase::cellInfo

Type definition for storing the relevant aspects of the OpenMC geometry; the first value is the cell index, while the second is the cell instance.

Constructor & Destructor Documentation

◆ OpenMCProblemBase()

OpenMCProblemBase::OpenMCProblemBase ( const InputParameters &  params)

◆ ~OpenMCProblemBase()

virtual OpenMCProblemBase::~OpenMCProblemBase ( )
overridevirtual

Member Function Documentation

◆ addExternalVariable()

unsigned int OpenMCProblemBase::addExternalVariable ( const std::string &  name,
const std::vector< SubdomainName > *  block = nullptr 
)

Add a constant monomial auxiliary variable

Parameters
[in]namename of the variable
[in]blockoptional subdomain names on which to restrict the variable
Returns
numeric index for the variable in the auxiliary system

◆ catchOpenMCError()

void OpenMCProblemBase::catchOpenMCError ( const int &  err,
const std::string  descriptor 
) const

Print a full error message when catching errors from OpenMC

Parameters
[in]errOpenMC error code
[in]descriptordescriptive message for error

◆ cellFill()

virtual std::vector<int32_t> OpenMCProblemBase::cellFill ( const cellInfo cell_info,
int &  fill_type 
) const
virtual

Get the fill of an OpenMC cell

Parameters
[in]cell_infocell ID, instance
[out]fill_typefill type of the cell, one of MATERIAL, UNIVERSE, or LATTICE
Returns
indices of what is filling the cell

◆ cellHasZeroInstances()

bool OpenMCProblemBase::cellHasZeroInstances ( const cellInfo cell_info) const

Whether this cell has zero instances

Parameters
[in]cell_infocell info
Returns
whether this cell has zero instances

◆ cellID()

int32_t OpenMCProblemBase::cellID ( const int32_t  index) const

Get the cell ID from the cell index

Parameters
[in]indexcell index
Returns
cell ID

◆ cellIsVoid()

bool OpenMCProblemBase::cellIsVoid ( const cellInfo cell_info) const

Whether a cell is filled with VOID (vacuum)

Parameters
[in]cell_infocell ID, instance
Returns
whether cell is void

◆ checkDuplicateEntries()

template<typename T >
void CardinalProblem::checkDuplicateEntries ( const std::vector< T > &  var,
const std::string &  name 
) const
inlineinherited

Check for duplicate entries in a 1-d vector

Parameters
[in]varinput vector
[in]namestring to use for printing error message

◆ checkDuplicateVariableName()

void CardinalProblem::checkDuplicateVariableName ( const std::string &  name) const
inherited

Check whether the user has already created a variable using one of the protected names that the wrapping is using.

Parameters
[in]namevariable name

◆ densityConversionFactor()

const Real& OpenMCProblemBase::densityConversionFactor ( ) const
inline

Get the density conversion factor (multiplicative factor)

Returns
density conversion factor from kg/m3 to g/cm3

◆ enumToTallyScore()

std::string OpenMCProblemBase::enumToTallyScore ( const std::string &  score) const

Convert from a MOOSE-type enum into a valid OpenMC tally score string

Parameters
[in]scoreMOOSE-type enum string
Returns
OpenMC tally score string

◆ estimatorToString()

std::string OpenMCProblemBase::estimatorToString ( openmc::TallyEstimator  estimator) const

Convert a tally estimator to a string (for output purposes).

Parameters
[in]estimatorOpenMC tally estimator enum
Returns
a string form of the OpenMC tally estimator enum

◆ externalSolve()

void OpenMCProblemBase::externalSolve ( )
override

Run a k-eigenvalue OpenMC simulation.

◆ fillElementalAuxVariable()

void OpenMCProblemBase::fillElementalAuxVariable ( const unsigned int &  var_num,
const std::vector< unsigned int > &  elem_ids,
const Real &  value 
)
protected

Set an auxiliary elemental variable to a specified value

Parameters
[in]var_numvariable number
[in]elem_idselement IDs to set
[in]valuevalue to set

◆ firstSolve()

bool OpenMCProblemBase::firstSolve ( ) const

Whether this is the first time OpenMC is running.

◆ geometryType()

virtual void OpenMCProblemBase::geometryType ( bool &  has_csg_universe,
bool &  has_dag_universe 
) const
virtual

Find the geometry type in the OpenMC model

Parameters
[out]has_csg_universewhether there is at least 1 CSG universe
[out]has_dag_universewhether there is at least 1 DagMC universe

◆ getOpenMCUserObjects()

void OpenMCProblemBase::getOpenMCUserObjects ( )
protected

Find all userobjects which are changing OpenMC data structures.

◆ globalElemID()

unsigned int OpenMCProblemBase::globalElemID ( const unsigned int &  id) const
inline

Get the global element ID from the local element ID

Parameters
[in]idlocal element ID
Returns
global element ID

◆ hasScaling()

bool OpenMCProblemBase::hasScaling ( ) const
inline

Whether the problem has user defined scaling or not.

Returns
whether the user has set the problem scaling or not

◆ importProperties()

void OpenMCProblemBase::importProperties ( ) const

Import temperature and density from a properties.h5 file.

◆ isHeatingScore()

bool OpenMCProblemBase::isHeatingScore ( const std::string &  score) const

Whether the score is a heating-type score

Returns
whether the tally from OpenMC has units of eV/src

◆ isLocalElem()

bool OpenMCProblemBase::isLocalElem ( const Elem *  elem) const

Whether the element is owned by this rank

Returns
whether element is owned by this rank

◆ isReactionRateScore()

bool OpenMCProblemBase::isReactionRateScore ( const std::string &  score) const

Whether the score is a reaction rate score

Returns
whether the tally from OpenMC has units of 1/src

◆ materialFill()

bool OpenMCProblemBase::materialFill ( const cellInfo cell_info,
int32_t &  material_index 
) const

Whether the cell has a material fill (if so, then get the material index). Void counts as a material, with a material index of -1.

Parameters
[in]cell_infocell ID, instance
[out]material_indexmaterial index in the cell
Returns
whether the cell is filled by a material

◆ materialID()

int32_t OpenMCProblemBase::materialID ( const int32_t  index) const

Get the material ID from the material index; for VOID cells, this returns -1

Parameters
[in]indexmaterial index
Returns
cell material ID

◆ materialName()

std::string OpenMCProblemBase::materialName ( const int32_t  index) const

Get the material name given its index. If the material does not have a name, return the ID.

Parameters
[in]index
Returns
material name

◆ nParticles()

int OpenMCProblemBase::nParticles ( ) const

Get the number of particles used in the current Monte Carlo calculation

Returns
number of particles

◆ nTotalParticles()

int OpenMCProblemBase::nTotalParticles ( ) const
inline

Total number of particles run (not multiplied by batches)

Returns
total number of particles

◆ numCells()

long unsigned int OpenMCProblemBase::numCells ( ) const

Calculate the number of unique OpenMC cells (each with a unique ID & instance)

Returns
number of unique OpenMC Cells in entire model

◆ numElemsInSubdomain()

unsigned int OpenMCProblemBase::numElemsInSubdomain ( const SubdomainID &  id) const

Get the total (i.e. summed across all ranks, if distributed) number of elements in a given block

Parameters
[in]idsubdomainID return number of elements in block

◆ printCell()

virtual std::string OpenMCProblemBase::printCell ( const cellInfo cell_info,
const bool  brief = false 
) const
virtual

Get a descriptive, formatted, string describing a cell

Parameters
[in]cell_infocell index, instance pair
[in]briefwhether to print a shorter string
Returns
descriptive string describing cell

◆ printMaterial()

std::string OpenMCProblemBase::printMaterial ( const int32_t &  index) const

Get a descriptive, formatted, string describing a material

Parameters
[in]indexmaterial index
Returns
descriptive string

◆ printPoint()

std::string OpenMCProblemBase::printPoint ( const Point &  p) const

Print point coordinates with a neater formatting than the default MOOSE printing

Returns
formatted point string

◆ relativeError()

xt::xtensor<double, 1> OpenMCProblemBase::relativeError ( const xt::xtensor< double, 1 > &  sum,
const xt::xtensor< double, 1 > &  sum_sq,
const int &  n_realizations 
) const

Compute relative error

Parameters
[in]sumsum of scores
[in]sum_sqsum of scores squared
[in]n_realizationsnumber of realizations

◆ scaling()

const Real& OpenMCProblemBase::scaling ( ) const
inline

Get the scaling value applied to the [Mesh] to convert to OpenMC's centimeters units

Returns
scaling value

◆ sendNuclideDensitiesToOpenMC()

void OpenMCProblemBase::sendNuclideDensitiesToOpenMC ( )
protected

Set the nuclide densities for any materials being modified via MOOSE.

◆ sendTallyNuclidesToOpenMC()

void OpenMCProblemBase::sendTallyNuclidesToOpenMC ( )
protected

Set the tally nuclides for any tallies being modified via MOOSE.

◆ setCellDensity()

virtual void OpenMCProblemBase::setCellDensity ( const Real &  density,
const cellInfo cell_info 
) const
virtual

Set the cell density, and print helpful error message if a failure occurs

Parameters
[in]densitydensity
[in]cell_infocell info for which we are setting the density

◆ setCellTemperature()

virtual void OpenMCProblemBase::setCellTemperature ( const int32_t &  id,
const int32_t &  instance,
const Real &  T,
const cellInfo cell_info 
) const
virtual

Set the cell temperature, and print helpful error message if a failure occurs; this sets the temperature for the id + instance, which could be one of N cells filling the 'cell_info' parent cell (which is what we actually use for error printing)

Parameters
[in]idcell ID
[in]instancecell instance
[in]Ttemperature
[in]cell_infocell info for which we are setting interior temperature, for error printing

◆ sourceBankFileName()

std::string OpenMCProblemBase::sourceBankFileName ( ) const
inlineprotected

Get name of source bank file to write

Parameters
[out]filename

◆ stringHasEnding()

bool CardinalProblem::stringHasEnding ( std::string const &  full,
std::string const &  ending 
) const
inherited

Whether a string ends in a particular sub-string

Parameters
[in]fullfull string
[in]endingsub-string ending
Returns
whether full string has ending

◆ subdomainName()

std::string OpenMCProblemBase::subdomainName ( const SubdomainID &  id) const

Get the subdomain name for a given ID. If not named, we return the ID

Parameters
[in]idsubdomain ID
Returns
name

◆ tallyEstimator()

openmc::TallyEstimator OpenMCProblemBase::tallyEstimator ( tally::TallyEstimatorEnum  estimator) const

Convert from a MooseEnum for tally estimator to an OpenMC enum

Parameters
[in]estimatorMOOSE estimator enum
Returns
OpenMC enum

◆ tallyMeanAcrossBins()

double OpenMCProblemBase::tallyMeanAcrossBins ( std::vector< openmc::Tally * >  tally,
const unsigned int &  score 
) const

Compute the mean of a tally across all of its bins

Parameters
[in]tallyOpenMC tallies (multiple if repeated mesh tallies)
[in]scoretally score
Returns
tally mean

◆ tallyScoreToEnum()

std::string OpenMCProblemBase::tallyScoreToEnum ( const std::string &  score) const

Convert into a MOOSE-type enum from a valid OpenMC tally score string

Parameters
[in]scoreOpenMC tally score string
Returns
MOOSE-type enum string

◆ tallySum()

xt::xtensor<double, 1> OpenMCProblemBase::tallySum ( openmc::Tally *  tally,
const unsigned int &  score 
) const

Compute the sum of a tally within each bin.

For example, suppose we have a cell tally with 4 bins, one for each of 4 different cells. This function will return the sum of the tally in each of those bins, so the return xtensor will have a length of 4, with each value representing the sum for that bin.

Parameters
[in]tallyOpenMC tally
[in]scoretally score
Returns
tally sum within each bin

◆ tallySumAcrossBins()

double OpenMCProblemBase::tallySumAcrossBins ( std::vector< openmc::Tally * >  tally,
const unsigned int &  score 
) const

Compute the sum of a tally across all of its bins

Parameters
[in]tallyOpenMC tallies (multiple if repeated mesh tallies)
[in]scoretally score
Returns
tally sum

◆ triggerMetric() [1/2]

openmc::TriggerMetric OpenMCProblemBase::triggerMetric ( trigger::TallyTriggerTypeEnum  trigger) const

Convert from a MooseEnum for a trigger metric to an OpenMC enum

Parameters
[in]triggertrigger metric
Returns
OpenMC enum

◆ triggerMetric() [2/2]

openmc::TriggerMetric OpenMCProblemBase::triggerMetric ( std::string  trigger) const

◆ validParams()

static InputParameters OpenMCProblemBase::validParams ( )
static

◆ writeSourceBank()

void OpenMCProblemBase::writeSourceBank ( const std::string &  filename)

Write the source bank to HDF5 for postprocessing or for use in subsequent solves

Parameters
[in]filenamefile name

Member Data Documentation

◆ _density_conversion_factor

constexpr Real OpenMCProblemBase::_density_conversion_factor {0.001}
staticprotected

Conversion unit to transfer between kg/m3 and g/cm3.

◆ _fixed_point_iteration

int OpenMCProblemBase::_fixed_point_iteration
protected

Fixed point iteration index used in relaxation; because we sometimes run OpenMC in a pseudo-transient coupling with NekRS, we simply increment this by 1 each time we call openmc::run(). This uses a zero indexing, so after the first iteration, we have finished iteration 0, and so on.

◆ _local_to_global_elem

std::vector<unsigned int> OpenMCProblemBase::_local_to_global_elem
protected

Mapping from local element indices to global element indices for this rank.

◆ _n_cell_digits

int OpenMCProblemBase::_n_cell_digits
protected

Number of digits to use to display the cell ID for diagnostic messages; this is estimated conservatively based on the total number of cells, even though there may be distributed cells such that the maximum cell ID is far smaller than the total number of cells.

◆ _n_openmc_cells

long unsigned int OpenMCProblemBase::_n_openmc_cells
protected

Total number of unique OpenMC cell IDs + instances combinations.

◆ _nuclide_densities_uos

std::vector<OpenMCNuclideDensities *> OpenMCProblemBase::_nuclide_densities_uos
protected

Userobjects for changing OpenMC material compositions.

◆ _power

const Real* OpenMCProblemBase::_power
protected

Power by which to normalize the OpenMC results, for k-eigenvalue mode.

◆ _reuse_source

bool OpenMCProblemBase::_reuse_source
protected

Whether to take the starting fission source from iteration \(n\) as the fission source converged from iteration \(n-1\). Setting this to true will in most cases lead to improved convergence of the initial source as iterations progress because you don't "start from scratch" each iteration and do the same identical (within a random number seed) converging of the fission source.

◆ _run_mode

openmc::RunMode OpenMCProblemBase::_run_mode
protected

OpenMC run mode.

◆ _scaling

const Real& OpenMCProblemBase::_scaling
protected

Multiplicative factor to apply to the mesh in the [Mesh] block in order to convert whatever units that mesh is in into OpenMC's length scale of centimeters. For instance, it is commonplace to develop fuel performance models with a length scale of meters. Rather than onerously convert all MOOSE inputs to which OpenMC will be coupled to units of centimeters, this parameter allows us to scale the mesh we couple to OpenMC. Note that this does not actually scale the mesh itself, but simply multiplies the mesh coordinates by this parameter when identifying the mapping between elements and cells.

By default, this parameter is set to 1.0, meaning that OpenMC is coupled to another MOOSE application with an input written in terms of centimeters. Set this parameter to 100 if the coupled MOOSE application is in units of meters, for instance.

To summarize by example - if the MOOSE application uses units of meters, with a mesh named mesh.exo, then the OpenMC-wrapped input file should also use that mesh (with units of meters) in its [Mesh] block (or perhaps a coarser version of that mesh if the resolution of coupling does not need to match - the units just have to be the same). Then, you should set 'scaling = 100.0' so that the mapping is performed correctly.

◆ _skip_statepoint

const bool& OpenMCProblemBase::_skip_statepoint
protected

Whether to skip writing statepoints from OpenMC.

◆ _source_strength

const Real* OpenMCProblemBase::_source_strength
protected

Source strength by which to normalize the OpenMC results, for fixed source mode.

◆ _specified_scaling

const bool OpenMCProblemBase::_specified_scaling
protected

Whether a mesh scaling was specified by the user.

◆ _tally_nuclides_uos

std::vector<OpenMCTallyNuclides *> OpenMCProblemBase::_tally_nuclides_uos
protected

Userobjects for changing OpenMC tally nuclides.

◆ _total_n_particles

unsigned int OpenMCProblemBase::_total_n_particles
protected

Total number of particles simulated.

◆ _verbose

const bool& OpenMCProblemBase::_verbose
protected

Whether to print diagnostic information about model setup and the transfers.

◆ MATERIAL_VOID

constexpr int OpenMCProblemBase::MATERIAL_VOID {-1}
staticprotected

ID used by OpenMC to indicate that a material fill is VOID.


The documentation for this class was generated from the following file: