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 "CreateExecutionerAction.h" 11 : #include "Factory.h" 12 : #include "PetscSupport.h" 13 : #include "MooseApp.h" 14 : #include "Executioner.h" 15 : #include "Eigenvalue.h" 16 : #include "FEProblem.h" 17 : #include "EigenProblem.h" 18 : 19 : registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner"); 20 : 21 : InputParameters 22 65056 : CreateExecutionerAction::validParams() 23 : { 24 65056 : InputParameters params = MooseObjectAction::validParams(); 25 130112 : params.addClassDescription("Add an Executioner object to the simulation."); 26 130112 : params.addParam<bool>( 27 : "auto_preconditioning", 28 130112 : true, 29 : "When true and a [Preconditioning] block does not exist, the application will attempt to use " 30 : "the correct preconditioning given the Executioner settings."); 31 65056 : return params; 32 0 : } 33 : 34 63771 : CreateExecutionerAction::CreateExecutionerAction(const InputParameters & params) 35 127538 : : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning")) 36 : { 37 63767 : } 38 : 39 : void 40 62886 : CreateExecutionerAction::act() 41 : { 42 62886 : std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem); 43 62886 : if (eigen_problem) 44 1764 : _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get(); 45 125772 : _moose_object_pars.set<SubProblem *>("_subproblem") = static_cast<SubProblem *>(_problem.get()); 46 : 47 : std::shared_ptr<Executioner> executioner = 48 125772 : _factory.create<Executioner>(_type, "Executioner", _moose_object_pars); 49 : 50 : std::shared_ptr<Eigenvalue> eigen_executioner = 51 62858 : std::dynamic_pointer_cast<Eigenvalue>(executioner); 52 : 53 62858 : if ((eigen_problem == nullptr) != (eigen_executioner == nullptr)) 54 0 : mooseError("Executioner is not consistent with each other; EigenExecutioner needs an " 55 : "EigenProblem, and Steady and Transient need a FEProblem"); 56 : 57 : // If enabled, automatically create a Preconditioner if the [Preconditioning] block is not found 58 310158 : if (_auto_preconditioning && !_awh.hasActions("add_preconditioning") && 59 239156 : _moose_object_pars.isParamValid("solve_type")) 60 34009 : setupAutoPreconditioning(); 61 : 62 62858 : _app.setExecutioner(std::move(executioner)); 63 62858 : } 64 : 65 : void 66 34009 : CreateExecutionerAction::setupAutoPreconditioning() 67 : { 68 : // If using NEWTON or LINEAR then automatically create SingleMatrixPreconditioner object with 69 : // full=true 70 34009 : const MooseEnum & solve_type = _moose_object_pars.get<MooseEnum>("solve_type"); 71 183536 : if (((solve_type.find("NEWTON") != solve_type.items().end()) && (solve_type == "NEWTON")) || 72 129461 : ((solve_type.find("LINEAR") != solve_type.items().end()) && (solve_type == "LINEAR"))) 73 21248 : for (const auto & nl_sys_name : _problem->getNonlinearSystemNames()) 74 : { 75 : // Action Parameters 76 31878 : InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction"); 77 10626 : params.set<std::string>("type") = "SMP"; 78 : 79 : // Associate errors with "solve_type" 80 21252 : associateWithParameter(_moose_object_pars, "solve_type", params); 81 : 82 : // Create the Action that will build the Preconditioner object 83 10626 : std::shared_ptr<Action> ptr = _action_factory.create( 84 : "SetupPreconditionerAction", 85 21252 : MooseUtils::join( 86 42504 : std::vector<std::string>({"_moose_auto", static_cast<std::string>(nl_sys_name)}), 87 : "_"), 88 21252 : params); 89 : 90 : // Set 'full=true' 91 10626 : std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr); 92 10626 : InputParameters & mo_params = moa_ptr->getObjectParams(); 93 21252 : mo_params.set<bool>("full") = true; 94 10626 : mo_params.set<NonlinearSystemName>("nl_sys") = nl_sys_name; 95 : 96 10626 : _awh.addActionBlock(ptr); 97 10626 : } 98 65887 : }