Line data Source code
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 : #ifdef ENABLE_OPENMC_COUPLING 20 : 21 : #include "OpenMCNuclideDensities.h" 22 : #include "openmc/material.h" 23 : 24 : registerMooseObject("CardinalApp", OpenMCNuclideDensities); 25 : 26 : InputParameters 27 94 : OpenMCNuclideDensities::validParams() 28 : { 29 94 : InputParameters params = GeneralUserObject::validParams(); 30 94 : params += OpenMCBase::validParams(); 31 188 : params.addRequiredParam<int32_t>("material_id", "ID of material to change nuclide densities"); 32 188 : params.addRequiredParam<std::vector<std::string>>("names", 33 : "Names of the nuclides to modify densities"); 34 188 : params.addRequiredParam<std::vector<double>>("densities", "Nuclide densities (atom/b/cm) to set"); 35 188 : params.declareControllable("names"); 36 188 : params.declareControllable("densities"); 37 94 : params.addClassDescription("Updates nuclide densities in an OpenMC material"); 38 94 : return params; 39 0 : } 40 : 41 48 : OpenMCNuclideDensities::OpenMCNuclideDensities(const InputParameters & parameters) 42 : : GeneralUserObject(parameters), 43 : OpenMCBase(this, parameters), 44 48 : _material_id(getParam<int32_t>("material_id")), 45 96 : _names(getParam<std::vector<std::string>>("names")), 46 144 : _densities(getParam<std::vector<double>>("densities")) 47 : { 48 48 : _openmc_problem->catchOpenMCError(openmc_get_material_index(_material_id, &_material_index), 49 48 : "get the material index for material with ID " + 50 48 : std::to_string(_material_id)); 51 46 : } 52 : 53 : void 54 44 : OpenMCNuclideDensities::setValue() 55 : { 56 44 : if (_names.size() == 0) 57 0 : paramError("names", "'names' cannot be of length zero!"); 58 : 59 44 : if (_names.size() != _densities.size()) 60 2 : mooseError("'names' and 'densities' must be the same length!"); 61 : 62 : try 63 : { 64 42 : openmc::model::materials[_material_index]->set_densities(_names, _densities); 65 : } 66 2 : catch (const std::exception & e) 67 : { 68 4 : mooseError("In attempting to set nuclide densities in the '" + name() + 69 2 : "' UserObject, OpenMC reported:\n\n" + e.what()); 70 0 : } 71 40 : } 72 : 73 : #endif