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 "OpenMCCellMaterialFill.h" 22 : #include "UserErrorChecking.h" 23 : #include "openmc/cell.h" 24 : 25 : registerMooseObject("CardinalApp", OpenMCCellMaterialFill); 26 : 27 : InputParameters 28 58 : OpenMCCellMaterialFill::validParams() 29 : { 30 58 : auto params = ModelModifiersBase::validParams(); 31 116 : params.addRequiredParam<int32_t>("cell_id", "Cell ID to modify"); 32 116 : params.addRequiredParam<std::vector<int32_t>>( 33 : "material_ids", 34 : "IDs of the materials to fill into the cell; the length of this array can be one material ID " 35 : "that will be applied to all instances. Otherwise, it must match the number " 36 : "of instances of the cell"); 37 58 : params.addClassDescription("Modifies the cell fill within an OpenMC cell"); 38 58 : return params; 39 0 : } 40 : 41 32 : OpenMCCellMaterialFill::OpenMCCellMaterialFill(const InputParameters & parameters) 42 64 : : ModelModifiersBase(parameters), _cell_id(getParam<int32_t>("cell_id")) 43 : { 44 : // get the cell requested 45 32 : _cell_index = -1; 46 32 : int err = openmc_get_cell_index(_cell_id, &_cell_index); 47 32 : if (err) 48 2 : paramError("cell_id", 49 2 : "Cell ID " + std::to_string(_cell_id) + " was not found in the OpenMC model!"); 50 : 51 30 : auto n_cell_instances = openmc::model::cells[_cell_index]->n_instances(); 52 30 : if (n_cell_instances == 0) 53 2 : paramError("cell_id", 54 2 : "Cell ID " + std::to_string(_cell_id) + 55 : " has zero instances so its material fill cannot be modified. This cell is " 56 : "probably corresponding to a cell in a lattice.outer universe. If you want to " 57 : "change the material here, you will need to either (i) widen your lattice to " 58 : "have universes covering all of the space you want to change the material or " 59 : "(ii) represent this region of space as a conventional cell.\n\nFor more " 60 : "information, see: https://github.com/openmc-dev/openmc/issues/551."); 61 : 62 : // check that the length of the materials matches the number of instances 63 56 : const auto & material_ids = getParam<std::vector<int32_t>>("material_ids"); 64 : auto n_mats = std::size(material_ids); 65 28 : if (n_mats != 1 && (n_cell_instances != n_mats)) 66 2 : paramError("material_ids", 67 2 : "'material_ids' (length " + std::to_string(n_mats) + 68 : ") must either be of length 1 or have a length equal to the number of instances " 69 2 : "of cell " + 70 4 : std::to_string(_cell_id) + " (" + std::to_string(n_cell_instances) + ")"); 71 : 72 : // check that each provided material exists in the model 73 26 : int32_t material_index = -1; 74 86 : for (const auto & m : material_ids) 75 : { 76 62 : err = openmc_get_material_index(m, &material_index); 77 62 : if (err) 78 2 : paramError("material_ids", 79 2 : "Material with ID " + std::to_string(m) + " was not found in the OpenMC model!"); 80 60 : _material_indices.push_back(material_index); 81 : } 82 : 83 24 : if (n_mats == 1) 84 : { 85 : // make _material_indices equal in length to the number of cell instances 86 8 : _material_indices.assign(n_cell_instances, material_index); 87 : } 88 24 : } 89 : 90 : void 91 24 : OpenMCCellMaterialFill::modifyOpenMCModel() const 92 : { 93 : const auto n_mats = std::size(_material_indices); 94 24 : std::string m = n_mats > 1 ? "materials" : "material"; 95 24 : _console << "Modifying " << m << " in cell " << _cell_id << "..." << std::endl; 96 : 97 24 : int err = openmc_cell_set_fill(_cell_index, 0, n_mats, _material_indices.data()); 98 48 : catchOpenMCError(err, "attempting to set a material fill in cell " + std::to_string(_cell_id)); 99 24 : } 100 : 101 : #endif