LCOV - code coverage report
Current view: top level - src/actions - OpenMCInitAction.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: 93e9c4 Lines: 23 26 88.5 %
Date: 2026-07-16 12:06:10 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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        3112 : OpenMCInitAction::validParams()
      28             : {
      29        3112 :   InputParameters params = Action::validParams();
      30        3112 :   params.addClassDescription(
      31             :       "Initializes OpenMC when an OpenMCCellAverageProblem is present in the input.");
      32        3112 :   return params;
      33           0 : }
      34             : 
      35        3112 : OpenMCInitAction::OpenMCInitAction(const InputParameters & parameters) : Action(parameters) {}
      36             : 
      37             : void
      38        2746 : 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        2746 :   if (!isOpenMCCellAverageProblemRequested(xml_directory))
      45             :     return;
      46             : 
      47             :   // Initialize OpenMC
      48        2340 :   initOpenMC(xml_directory);
      49             : }
      50             : 
      51             : bool
      52        2746 : OpenMCInitAction::isOpenMCCellAverageProblemRequested(std::string & xml_directory) const
      53             : {
      54             :   // Retrieve all CreateProblemAction actions
      55        2746 :   const auto & problem_actions = _awh.getActions<CreateProblemAction>();
      56             : 
      57             :   // Search for an OpenMCCellAverageProblem
      58        2971 :   for (const auto * action : problem_actions)
      59             :   {
      60        5130 :     if (action->getParam<std::string>("type") == "OpenMCCellAverageProblem")
      61             :     {
      62        4680 :       xml_directory = action->getObjectParams().get<FileName>("xml_directory");
      63             :       return true;
      64             :     }
      65             :   }
      66             :   return false;
      67        2746 : }
      68             : 
      69             : void
      70        2340 : 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        2340 :   std::vector<std::string> argv_vec = {"openmc"};
      75        9360 :   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        2340 :   argv_vec.push_back(xml_directory);
      83             : 
      84             :   std::vector<char *> argv;
      85        7020 :   for (const auto & arg : argv_vec)
      86             :   {
      87        4680 :     argv.push_back(const_cast<char *>(arg.data()));
      88             :   }
      89             : 
      90             :   // Add terminating nullptr
      91        2340 :   argv.push_back(nullptr);
      92             : 
      93             :   // Initialize OpenMC
      94        2340 :   openmc_init(argv.size() - 1, argv.data(), &_communicator.get());
      95        2340 : }
      96             : 
      97             : #endif

Generated by: LCOV version 1.14