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 "MooseEnum.h" 22 : #include "MooseUtils.h" 23 : 24 : #include "OpenMCCellTransformBase.h" 25 : #include "OpenMCBase.h" 26 : #include "UserErrorChecking.h" 27 : 28 : InputParameters 29 218 : OpenMCCellTransformBase::validParams() 30 : { 31 218 : auto params = emptyInputParameters(); 32 : 33 436 : params.addRequiredParam<std::vector<int32_t>>( 34 : "cell_ids", "List of OpenMC cell IDs whose filled universes will be transformed."); 35 : 36 218 : return params; 37 0 : } 38 : 39 : const MooseEnum OpenMCCellTransformBase::transform_type("translation rotation", "translation"); 40 : const std::array<std::string, 3> OpenMCCellTransformBase::rotation_vector_symbols{"φ", "θ", "ψ"}; 41 : const std::string OpenMCCellTransformBase::rotation_vector_symbols_list = 42 : OpenMCCellTransformBase::rotation_vector_symbols[0] + ", " + 43 : OpenMCCellTransformBase::rotation_vector_symbols[1] + ", " + 44 : OpenMCCellTransformBase::rotation_vector_symbols[2]; 45 : 46 112 : OpenMCCellTransformBase::OpenMCCellTransformBase(const MooseObject & moose_object) 47 336 : : _cell_ids(moose_object.getParam<std::vector<int32_t>>("cell_ids").begin(), 48 112 : moose_object.getParam<std::vector<int32_t>>("cell_ids").end()), 49 112 : _moose_object(moose_object), 50 112 : _openmc_problem(getOpenMCProblem(moose_object)) 51 : { 52 112 : if (_cell_ids.empty()) 53 2 : moose_object.paramError("cell_ids", "At least one OpenMC cell ID must be provided."); 54 220 : if (_cell_ids.size() != _moose_object.getParam<std::vector<int32_t>>("cell_ids").size()) 55 2 : moose_object.paramError("cell_ids", 56 : "Duplicate OpenMC cell IDs were detected. Provide each ID only once."); 57 108 : } 58 : 59 : void 60 742 : OpenMCCellTransformBase::transform(const MooseEnum & transform_type, const Point & transform_vector) 61 : { 62 742 : std::array<double, 3> vec{transform_vector(0), transform_vector(1), transform_vector(2)}; 63 : 64 742 : if (transform_type == "translation") 65 384 : for (const auto i : index_range(vec)) 66 288 : vec[i] *= _openmc_problem.scaling(); 67 : 68 1510 : for (const auto & cell_id : _cell_ids) 69 : { 70 774 : int32_t index = -1; 71 : 72 774 : int err = openmc_get_cell_index(cell_id, &index); 73 774 : catchOpenMCError(err, "find OpenMC cell with ID " + std::to_string(cell_id)); 74 : 75 774 : if (transform_type == "translation") 76 : { 77 : // If a user tried to apply translation on a cell that doesn't contain a filled universe, 78 : // OpenMC will return an error. 79 128 : err = openmc_cell_set_translation(index, vec.data()); 80 128 : _moose_object._console << "Setting OpenMC cell translation for cell with ID " << cell_id 81 128 : << " to (" << vec[0] << ", " << vec[1] << ", " << vec[2] << ") cm." 82 128 : << std::endl; 83 : } 84 646 : else if (transform_type == "rotation") 85 : { 86 2572 : for (const auto i : index_range(vec)) 87 1932 : if (vec[i] < 0 || vec[i] >= 360) 88 6 : _moose_object.mooseError("Rotation transformation angle ", 89 : rotation_vector_symbols[i], 90 : " must be in the range [0, 360) degrees. Got invalid ", 91 : rotation_vector_symbols[i], 92 : " = ", 93 : vec[i], 94 : " degrees."); 95 : // If a user tried to apply rotation on a cell that doesn't contain a filled universe, 96 : // OpenMC will return an error. 97 640 : err = openmc_cell_set_rotation(index, vec.data(), 3); 98 640 : _moose_object._console << "Setting OpenMC cell rotation for cell with ID " << cell_id 99 640 : << " to (" << vec[0] << ", " << vec[1] << ", " << vec[2] 100 640 : << ") degrees." << std::endl; 101 : } 102 : else 103 0 : _moose_object.mooseError("In transformation, unknown transformation type: ", transform_type); 104 : 105 1536 : catchOpenMCError(err, "transform OpenMC cell OpenMC cell with ID " + std::to_string(cell_id)); 106 : } 107 736 : } 108 : 109 : #endif