LCOV - code coverage report
Current view: top level - src/actions - StochasticToolsAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 41 51 80.4 %
Date: 2025-07-25 05:00:46 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "StochasticToolsAction.h"
      11             : #include "ActionWarehouse.h"
      12             : #include "ActionFactory.h"
      13             : #include "MooseEnum.h"
      14             : #include "SetupMeshAction.h"
      15             : #include "CreateProblemAction.h"
      16             : 
      17             : registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_mesh");
      18             : registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_problem");
      19             : registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_executioner");
      20             : 
      21             : InputParameters
      22       39308 : StochasticToolsAction::validParams()
      23             : {
      24       39308 :   InputParameters params = Action::validParams();
      25       39308 :   params.addClassDescription(
      26             :       "Action for performing some common functions for running stochastic simulations.");
      27       78616 :   params.addParam<bool>(
      28             :       "auto_create_mesh",
      29       78616 :       true,
      30             :       "Automatically setup the Mesh block for a master application without a simulation.");
      31       78616 :   params.addParam<bool>(
      32             :       "auto_create_problem",
      33       78616 :       true,
      34             :       "Automatically setup the Problem block for a master application without a simulation.");
      35       78616 :   params.addParam<bool>(
      36             :       "auto_create_executioner",
      37       78616 :       true,
      38             :       "Automatically setup the Executioner block for a master application without a simulation.");
      39       39308 :   return params;
      40           0 : }
      41             : 
      42       39308 : StochasticToolsAction::StochasticToolsAction(const InputParameters & params) : Action(params) {}
      43             : 
      44             : void
      45       40116 : StochasticToolsAction::act()
      46             : {
      47             :   // [Mesh]
      48      106976 :   if (_current_task == "auto_create_mesh" && getParam<bool>("auto_create_mesh") &&
      49       66860 :       !_awh.hasActions("setup_mesh"))
      50             :   {
      51             :     // Build the Action parameters
      52       12800 :     InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
      53       12800 :     action_params.set<std::string>("type") = "GeneratedMesh";
      54             : 
      55             :     // Associate errors with "auto_create_mesh"
      56       12800 :     associateWithParameter("auto_create_mesh", action_params);
      57             : 
      58             :     // Create The Action
      59             :     auto action = std::static_pointer_cast<MooseObjectAction>(
      60       25600 :         _action_factory.create("SetupMeshAction", "Mesh", action_params));
      61             : 
      62             :     // Set the object parameters
      63             :     InputParameters & params = action->getObjectParams();
      64       25600 :     params.set<MooseEnum>("dim") = "1";
      65       12800 :     params.set<unsigned int>("nx") = 1;
      66             : 
      67             :     // Add Action to the warehouse
      68       38400 :     _awh.addActionBlock(action);
      69       12800 :   }
      70             : 
      71             :   // [Problem]
      72       54060 :   else if (_current_task == "auto_create_problem" && getParam<bool>("auto_create_problem"))
      73             :   {
      74       26744 :     if (_awh.hasActions("create_problem"))
      75             :     {
      76           0 :       for (const auto & act : _awh.getActionListByName("create_problem"))
      77             :       {
      78           0 :         auto * action = dynamic_cast<CreateProblemAction *>(act);
      79           0 :         if (action)
      80             :         {
      81             :           InputParameters & params = action->getObjectParams();
      82             : 
      83           0 :           if (!params.isParamSetByUser("solve"))
      84           0 :             params.set<bool>("solve") = false;
      85             : 
      86           0 :           if (!params.isParamSetByUser("kernel_coverage_check"))
      87           0 :             params.set<MooseEnum>("kernel_coverage_check") = "false";
      88             : 
      89           0 :           if (!params.isParamSetByUser("skip_nl_system_check"))
      90           0 :             params.set<bool>("skip_nl_system_check") = true;
      91             :         }
      92             :       }
      93             :     }
      94             :     else
      95             :     {
      96             :       // Build the Action parameters
      97       13372 :       InputParameters action_params = _action_factory.getValidParams("CreateProblemAction");
      98             : 
      99             :       // Associate errors with "auto_create_problem"
     100       13372 :       associateWithParameter("auto_create_problem", action_params);
     101             : 
     102             :       // Create the action
     103             :       auto action = std::static_pointer_cast<MooseObjectAction>(
     104       26744 :           _action_factory.create("CreateProblemAction", "Problem", action_params));
     105             : 
     106             :       // Set the object parameters
     107             :       InputParameters & params = action->getObjectParams();
     108       13372 :       params.set<bool>("solve") = false;
     109       26744 :       params.set<MooseEnum>("kernel_coverage_check") = "false";
     110       13372 :       params.set<bool>("skip_nl_system_check") = true;
     111             : 
     112             :       // Add Action to the warehouse
     113       40116 :       _awh.addActionBlock(action);
     114       13372 :     }
     115             :   }
     116             : 
     117             :   // [Executioner]
     118       13944 :   else if (_current_task == "auto_create_executioner" &&
     119       55110 :            getParam<bool>("auto_create_executioner") && !_awh.hasActions("setup_executioner"))
     120             :   {
     121             :     // Build the Action parameters
     122       11278 :     InputParameters action_params = _action_factory.getValidParams("CreateExecutionerAction");
     123       11278 :     action_params.set<std::string>("type") = "Steady";
     124             : 
     125             :     // Associate errors with "auto_create_executioner"
     126       11278 :     associateWithParameter("auto_create_executioner", action_params);
     127             : 
     128             :     // Create the action
     129             :     auto action = std::static_pointer_cast<MooseObjectAction>(
     130       22556 :         _action_factory.create("CreateExecutionerAction", "Executioner", action_params));
     131             : 
     132             :     // Add Action to the warehouse
     133       33834 :     _awh.addActionBlock(action);
     134       11278 :   }
     135       40116 : }

Generated by: LCOV version 1.14