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 "UserErrorChecking.h" 23 : #include "openmc/material.h" 24 : 25 : registerMooseObject("CardinalApp", OpenMCNuclideDensities); 26 : 27 : InputParameters 28 94 : OpenMCNuclideDensities::validParams() 29 : { 30 94 : InputParameters params = GeneralUserObject::validParams(); 31 94 : params += OpenMCBase::validParams(); 32 188 : params.addRequiredParam<int32_t>("material_id", "ID of material to change nuclide densities"); 33 188 : params.addRequiredParam<std::vector<std::string>>("names", 34 : "Names of the nuclides to modify densities"); 35 188 : params.addRequiredParam<std::vector<double>>("densities", "Nuclide densities (atom/b/cm) to set"); 36 188 : params.declareControllable("names"); 37 188 : params.declareControllable("densities"); 38 94 : params.addClassDescription("Updates nuclide densities in an OpenMC material"); 39 94 : return params; 40 0 : } 41 : 42 48 : OpenMCNuclideDensities::OpenMCNuclideDensities(const InputParameters & parameters) 43 : : GeneralUserObject(parameters), 44 : OpenMCBase(this, parameters), 45 48 : _material_id(getParam<int32_t>("material_id")), 46 96 : _names(getParam<std::vector<std::string>>("names")), 47 144 : _densities(getParam<std::vector<double>>("densities")) 48 : { 49 48 : catchOpenMCError(openmc_get_material_index(_material_id, &_material_index), 50 48 : "get the material index for material with ID " + 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