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 "OpenMCInitAction.h" 22 : #include "CreateProblemAction.h" 23 : 24 : registerMooseAction("CardinalApp", OpenMCInitAction, "openmc_init"); 25 : 26 : InputParameters 27 3178 : OpenMCInitAction::validParams() 28 : { 29 3178 : InputParameters params = Action::validParams(); 30 3178 : params.addClassDescription( 31 : "Initializes OpenMC when an OpenMCCellAverageProblem is present in the input."); 32 3178 : return params; 33 0 : } 34 : 35 3178 : OpenMCInitAction::OpenMCInitAction(const InputParameters & parameters) : Action(parameters) {} 36 : 37 : void 38 2812 : OpenMCInitAction::act() 39 : { 40 : // Directory containing XML files for OpenMC initialization 41 : std::string xml_directory; 42 : 43 : // Leave if no OpenMCCellAverageProblem requested in the input file 44 2812 : if (!isOpenMCCellAverageProblemRequested(xml_directory)) 45 : return; 46 : 47 : // Initialize OpenMC 48 2399 : initOpenMC(xml_directory); 49 : } 50 : 51 : bool 52 2812 : OpenMCInitAction::isOpenMCCellAverageProblemRequested(std::string & xml_directory) const 53 : { 54 : // Retrieve all CreateProblemAction actions 55 2812 : const auto & problem_actions = _awh.getActions<CreateProblemAction>(); 56 : 57 : // Search for an OpenMCCellAverageProblem 58 3044 : for (const auto * action : problem_actions) 59 : { 60 5262 : if (action->getParam<std::string>("type") == "OpenMCCellAverageProblem") 61 : { 62 4798 : xml_directory = action->getObjectParams().get<FileName>("xml_directory"); 63 : return true; 64 : } 65 : } 66 : return false; 67 2812 : } 68 : 69 : void 70 2399 : OpenMCInitAction::initOpenMC(const std::string & xml_directory) 71 : { 72 : // Suppress OpenMC output when the language server is active by 73 : // decreasing the verbosity to level 1 (the lowest). 74 2399 : std::vector<std::string> argv_vec = {"openmc"}; 75 9596 : if (_app.isParamValid("language_server") && _app.getParam<bool>("language_server")) 76 : { 77 0 : argv_vec.push_back("-q"); 78 0 : argv_vec.push_back("1"); 79 : } 80 : 81 : // Add xml_directory 82 2399 : argv_vec.push_back(xml_directory); 83 : 84 : std::vector<char *> argv; 85 7197 : for (const auto & arg : argv_vec) 86 : { 87 4798 : argv.push_back(const_cast<char *>(arg.data())); 88 : } 89 : 90 : // Add terminating nullptr 91 2399 : argv.push_back(nullptr); 92 : 93 : // Initialize OpenMC 94 2399 : openmc_init(argv.size() - 1, argv.data(), &_communicator.get()); 95 2399 : } 96 : 97 : #endif