LCOV - code coverage report
Current view: top level - src/actions - CreateProblemDefaultAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 37 39 94.9 %
Date: 2025-07-17 01:28:37 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 "CreateProblemDefaultAction.h"
      11             : 
      12             : #include "Factory.h"
      13             : #include "FEProblem.h"
      14             : #include "EigenProblem.h"
      15             : #include "MooseApp.h"
      16             : #include "CreateExecutionerAction.h"
      17             : #include "CreateProblemAction.h"
      18             : 
      19             : registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default");
      20             : registerMooseAction("MooseApp", CreateProblemDefaultAction, "determine_system_type");
      21             : 
      22             : InputParameters
      23       61934 : CreateProblemDefaultAction::validParams()
      24             : {
      25       61934 :   InputParameters params = Action::validParams();
      26       61934 :   params.addPrivateParam<bool>("_solve");
      27       61934 :   return params;
      28           0 : }
      29             : 
      30       61934 : CreateProblemDefaultAction::CreateProblemDefaultAction(const InputParameters & parameters)
      31       61934 :   : Action(parameters)
      32             : {
      33       61934 : }
      34             : 
      35             : void
      36      115628 : CreateProblemDefaultAction::act()
      37             : {
      38      115628 :   if (_current_task == "determine_system_type")
      39             :   {
      40             :     // Determine whether the Executioner is derived from EigenExecutionerBase and
      41             :     // set a flag on MooseApp that can be used during problem construction.
      42       57816 :     bool use_nonlinear = true;
      43       57816 :     bool use_eigenvalue = false;
      44       57816 :     auto p = _awh.getActionByTask<CreateExecutionerAction>("setup_executioner");
      45       57816 :     if (p)
      46             :     {
      47       57780 :       auto & exparams = p->getObjectParams();
      48       57780 :       use_nonlinear = !(exparams.isParamValid("_eigen") && exparams.get<bool>("_eigen"));
      49       57780 :       use_eigenvalue =
      50       57780 :           (exparams.isParamValid("_use_eigen_value") && exparams.get<bool>("_use_eigen_value"));
      51             :     }
      52             : 
      53       57816 :     _app.useNonlinear() = use_nonlinear;
      54       57816 :     _app.useEigenvalue() = use_eigenvalue;
      55       57816 :     return;
      56             :   }
      57             : 
      58             :   // act only if we have mesh
      59       57812 :   if (_mesh.get() != NULL)
      60             :   {
      61             :     // Make sure the problem hasn't already been created elsewhere
      62       57812 :     if (!_problem)
      63             :     {
      64       54807 :       std::string type;
      65       54807 :       if (_app.useEigenvalue())
      66         480 :         type = "EigenProblem";
      67             :       else
      68       54327 :         type = "FEProblem";
      69       54807 :       auto params = _factory.getValidParams(type);
      70             : 
      71             :       // apply common parameters of the object held by CreateProblemAction to honor user inputs in
      72             :       // [Problem]
      73       54807 :       auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
      74       54807 :       if (p)
      75       18170 :         params.applyParameters(p->getObjectParams());
      76             : 
      77       54807 :       params.set<MooseMesh *>("mesh") = _mesh.get();
      78       54807 :       params.set<bool>("use_nonlinear") = _app.useNonlinear();
      79       54807 :       if (_pars.isParamValid("_solve"))
      80           1 :         params.set<bool>("solve") = getParam<bool>("_solve");
      81             : 
      82       54807 :       _problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
      83       54799 :     }
      84             :     else
      85             :     {
      86             :       // otherwise perform necessary sanity checks
      87        3005 :       if (_app.useEigenvalue() && !(std::dynamic_pointer_cast<EigenProblem>(_problem)))
      88           0 :         mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
      89             :                    "eigen executioner");
      90             :     }
      91             :   }
      92             : }

Generated by: LCOV version 1.14