Cardinal
OpenMCProblemBase.h
Go to the documentation of this file.
1 /********************************************************************/
2 /* SOFTWARE COPYRIGHT NOTIFICATION */
3 /* Cardinal */
4 /* */
5 /* (c) 2021 UChicago Argonne, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by UChicago Argonne, LLC */
9 /* Under Contract No. DE-AC02-06CH11357 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* Prepared by Battelle Energy Alliance, LLC */
13 /* Under Contract No. DE-AC07-05ID14517 */
14 /* With the U. S. Department of Energy */
15 /* */
16 /* See LICENSE for full restrictions */
17 /********************************************************************/
18 
19 #pragma once
20 
21 #define LIBMESH
22 
23 #include "CardinalProblem.h"
24 #include "PostprocessorInterface.h"
25 #include "CardinalEnums.h"
26 #include "OpenMCNuclideDensities.h"
27 #include "OpenMCTallyNuclides.h"
28 
29 #include "mpi.h"
30 #include "openmc/bank.h"
31 #include "openmc/capi.h"
32 #include "openmc/cell.h"
33 #include "openmc/geometry.h"
34 #include "openmc/geometry_aux.h"
35 #include "openmc/hdf5_interface.h"
36 #include "openmc/material.h"
37 #include "openmc/mesh.h"
38 #include "openmc/settings.h"
39 #include "openmc/simulation.h"
40 #include "openmc/source.h"
41 #include "openmc/state_point.h"
42 #include "openmc/tallies/tally.h"
43 #include "openmc/tallies/filter_cell_instance.h"
44 #include "xtensor/xview.hpp"
45 
49 class OpenMCProblemBase : public CardinalProblem, public PostprocessorInterface
50 {
51 public:
52  OpenMCProblemBase(const InputParameters & params);
53 
54  static InputParameters validParams();
55 
56  virtual ~OpenMCProblemBase() override;
57 
63  std::string subdomainName(const SubdomainID & id) const;
64 
70  void catchOpenMCError(const int & err, const std::string descriptor) const;
71 
76  bool isReactionRateScore(const std::string & score) const;
77 
82  bool isHeatingScore(const std::string & score) const;
83 
90  unsigned int addExternalVariable(const std::string & name, const std::vector<SubdomainName> * block = nullptr);
91 
96  const Real & scaling() const { return _scaling; }
97 
102  bool hasScaling() const { return _specified_scaling; }
103 
109  std::string enumToTallyScore(const std::string & score) const;
110 
116  std::string tallyScoreToEnum(const std::string & score) const;
117 
123  virtual void geometryType(bool & has_csg_universe, bool & has_dag_universe) const;
124 
126  bool firstSolve() const;
127 
133  openmc::TriggerMetric triggerMetric(trigger::TallyTriggerTypeEnum trigger) const;
134  openmc::TriggerMetric triggerMetric(std::string trigger) const;
135 
141  openmc::TallyEstimator tallyEstimator(tally::TallyEstimatorEnum estimator) const;
142 
148  std::string estimatorToString(openmc::TallyEstimator estimator) const;
149 
151  void externalSolve() override;
152 
154  void importProperties() const;
155 
168  xt::xtensor<double, 1> tallySum(openmc::Tally * tally, const unsigned int & score) const;
169 
176  double tallySumAcrossBins(std::vector<openmc::Tally *> tally, const unsigned int & score) const;
177 
184  double tallyMeanAcrossBins(std::vector<openmc::Tally *> tally, const unsigned int & score) const;
185 
190  typedef std::pair<int32_t, int32_t> cellInfo;
191 
197  bool cellIsVoid(const cellInfo & cell_info) const;
198 
204  bool cellHasZeroInstances(const cellInfo & cell_info) const;
205 
212  std::string materialName(const int32_t index) const;
213 
220  xt::xtensor<double, 1> relativeError(const xt::xtensor<double, 1> & sum,
221  const xt::xtensor<double, 1> & sum_sq, const int & n_realizations) const;
222 
227  const Real & densityConversionFactor() const { return _density_conversion_factor; }
228 
233  int nParticles() const;
234 
239  int nTotalParticles() const { return _total_n_particles; }
240 
246  int32_t cellID(const int32_t index) const;
247 
253  int32_t materialID(const int32_t index) const;
254 
259  std::string printPoint(const Point & p) const;
260 
266  std::string printMaterial(const int32_t & index) const;
267 
272  void writeSourceBank(const std::string & filename);
273 
280  unsigned int numElemsInSubdomain(const SubdomainID & id) const;
281 
286  bool isLocalElem(const Elem * elem) const;
287 
293  unsigned int globalElemID(const unsigned int & id) const { return _local_to_global_elem[id]; }
294 
304  virtual void setCellTemperature(const int32_t & id, const int32_t & instance, const Real & T,
305  const cellInfo & cell_info) const;
306 
312  virtual void setCellDensity(const Real & density, const cellInfo & cell_info) const;
313 
320  virtual std::string printCell(const cellInfo & cell_info, const bool brief = false) const;
321 
328  virtual std::vector<int32_t> cellFill(const cellInfo & cell_info, int & fill_type) const;
329 
337  bool materialFill(const cellInfo & cell_info, int32_t & material_index) const;
338 
343  long unsigned int numCells() const;
344 
345 protected:
347  void getOpenMCUserObjects();
348 
351 
354 
361  void fillElementalAuxVariable(const unsigned int & var_num,
362  const std::vector<unsigned int> & elem_ids,
363  const Real & value);
364 
369  std::string sourceBankFileName() const
370  {
371  return openmc::settings::path_output + "initial_source_" +
372  std::to_string(_fixed_point_iteration) + ".h5";
373  }
374 
376  const bool & _verbose;
377 
379  const Real * _power;
380 
382  const Real * _source_strength;
383 
392 
394  const bool _specified_scaling;
395 
415  const Real & _scaling;
416 
418  const bool & _skip_statepoint;
419 
427 
429  unsigned int _total_n_particles;
430 
432  long unsigned int _n_openmc_cells;
433 
441 
443  openmc::RunMode _run_mode;
444 
446  std::vector<OpenMCNuclideDensities *> _nuclide_densities_uos;
447 
449  std::vector<OpenMCTallyNuclides *> _tally_nuclides_uos;
450 
452  std::vector<unsigned int> _local_to_global_elem;
453 
455  static constexpr Real _density_conversion_factor{0.001};
456 
458  static constexpr int MATERIAL_VOID{-1};
459 };
TallyTriggerTypeEnum
Type of trigger to apply.
Definition: CardinalEnums.h:163
unsigned int _total_n_particles
Total number of particles simulated.
Definition: OpenMCProblemBase.h:429
int _fixed_point_iteration
Definition: OpenMCProblemBase.h:426
std::string materialName(const int32_t index) const
bool isReactionRateScore(const std::string &score) const
void writeSourceBank(const std::string &filename)
double tallyMeanAcrossBins(std::vector< openmc::Tally * > tally, const unsigned int &score) const
const bool _specified_scaling
Whether a mesh scaling was specified by the user.
Definition: OpenMCProblemBase.h:394
std::vector< OpenMCTallyNuclides * > _tally_nuclides_uos
Userobjects for changing OpenMC tally nuclides.
Definition: OpenMCProblemBase.h:449
const bool & _skip_statepoint
Whether to skip writing statepoints from OpenMC.
Definition: OpenMCProblemBase.h:418
const Real & densityConversionFactor() const
Definition: OpenMCProblemBase.h:227
bool materialFill(const cellInfo &cell_info, int32_t &material_index) const
long unsigned int numCells() const
virtual ~OpenMCProblemBase() override
static InputParameters validParams()
int32_t materialID(const int32_t index) const
bool isHeatingScore(const std::string &score) const
unsigned int addExternalVariable(const std::string &name, const std::vector< SubdomainName > *block=nullptr)
virtual std::vector< int32_t > cellFill(const cellInfo &cell_info, int &fill_type) const
std::vector< unsigned int > _local_to_global_elem
Mapping from local element indices to global element indices for this rank.
Definition: OpenMCProblemBase.h:452
std::string sourceBankFileName() const
Definition: OpenMCProblemBase.h:369
OpenMCProblemBase(const InputParameters &params)
void sendNuclideDensitiesToOpenMC()
Set the nuclide densities for any materials being modified via MOOSE.
static constexpr int MATERIAL_VOID
ID used by OpenMC to indicate that a material fill is VOID.
Definition: OpenMCProblemBase.h:458
virtual void geometryType(bool &has_csg_universe, bool &has_dag_universe) const
virtual void setCellTemperature(const int32_t &id, const int32_t &instance, const Real &T, const cellInfo &cell_info) const
int _n_cell_digits
Definition: OpenMCProblemBase.h:440
void getOpenMCUserObjects()
Find all userobjects which are changing OpenMC data structures.
Definition: CardinalEnums.h:206
xt::xtensor< double, 1 > relativeError(const xt::xtensor< double, 1 > &sum, const xt::xtensor< double, 1 > &sum_sq, const int &n_realizations) const
int32_t cellID(const int32_t index) const
virtual std::string printCell(const cellInfo &cell_info, const bool brief=false) const
Definition: CardinalProblem.h:26
openmc::TriggerMetric triggerMetric(trigger::TallyTriggerTypeEnum trigger) const
std::vector< OpenMCNuclideDensities * > _nuclide_densities_uos
Userobjects for changing OpenMC material compositions.
Definition: OpenMCProblemBase.h:446
const Real & scaling() const
Definition: OpenMCProblemBase.h:96
std::string printPoint(const Point &p) const
bool cellIsVoid(const cellInfo &cell_info) const
Definition: OpenMCProblemBase.h:49
void importProperties() const
Import temperature and density from a properties.h5 file.
TallyEstimatorEnum
Type of estimator to use for OpenMC tallies.
Definition: CardinalEnums.h:140
int nTotalParticles() const
Definition: OpenMCProblemBase.h:239
bool cellHasZeroInstances(const cellInfo &cell_info) const
const Real & _scaling
Definition: OpenMCProblemBase.h:415
static constexpr Real _density_conversion_factor
Conversion unit to transfer between kg/m3 and g/cm3.
Definition: OpenMCProblemBase.h:455
void sendTallyNuclidesToOpenMC()
Set the tally nuclides for any tallies being modified via MOOSE.
long unsigned int _n_openmc_cells
Total number of unique OpenMC cell IDs + instances combinations.
Definition: OpenMCProblemBase.h:432
unsigned int numElemsInSubdomain(const SubdomainID &id) const
bool hasScaling() const
Definition: OpenMCProblemBase.h:102
const bool & _verbose
Whether to print diagnostic information about model setup and the transfers.
Definition: OpenMCProblemBase.h:376
bool _reuse_source
Definition: OpenMCProblemBase.h:391
void fillElementalAuxVariable(const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
int nParticles() const
xt::xtensor< double, 1 > tallySum(openmc::Tally *tally, const unsigned int &score) const
Compute the sum of a tally within each bin.
std::string printMaterial(const int32_t &index) const
openmc::TallyEstimator tallyEstimator(tally::TallyEstimatorEnum estimator) const
unsigned int globalElemID(const unsigned int &id) const
Definition: OpenMCProblemBase.h:293
Definition: CardinalEnums.h:160
std::string subdomainName(const SubdomainID &id) const
void catchOpenMCError(const int &err, const std::string descriptor) const
virtual void setCellDensity(const Real &density, const cellInfo &cell_info) const
Definition: CardinalEnums.h:129
bool firstSolve() const
Whether this is the first time OpenMC is running.
openmc::RunMode _run_mode
OpenMC run mode.
Definition: OpenMCProblemBase.h:443
const Real * _source_strength
Source strength by which to normalize the OpenMC results, for fixed source mode.
Definition: OpenMCProblemBase.h:382
std::pair< int32_t, int32_t > cellInfo
Definition: OpenMCProblemBase.h:190
std::string estimatorToString(openmc::TallyEstimator estimator) const
void externalSolve() override
Run a k-eigenvalue OpenMC simulation.
const Real * _power
Power by which to normalize the OpenMC results, for k-eigenvalue mode.
Definition: OpenMCProblemBase.h:379
bool isLocalElem(const Elem *elem) const
std::string enumToTallyScore(const std::string &score) const
double tallySumAcrossBins(std::vector< openmc::Tally * > tally, const unsigned int &score) const
std::string tallyScoreToEnum(const std::string &score) const