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 "FEProblem.h" 16 : #include "EigenProblem.h" 17 : #include "EigenProblemSolve.h" 18 : 19 : registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner"); 20 : 21 : InputParameters 22 64336 : CreateExecutionerAction::validParams() 23 : { 24 64336 : InputParameters params = MooseObjectAction::validParams(); 25 128672 : params.addClassDescription("Add an Executioner object to the simulation."); 26 128672 : params.addParam<bool>( 27 : "auto_preconditioning", 28 128672 : 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 64336 : return params; 32 0 : } 33 : 34 61793 : CreateExecutionerAction::CreateExecutionerAction(const InputParameters & params) 35 123583 : : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning")) 36 : { 37 61790 : } 38 : 39 : void 40 61073 : CreateExecutionerAction::act() 41 : { 42 61073 : std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem); 43 61073 : if (eigen_problem) 44 1695 : _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get(); 45 122146 : _moose_object_pars.set<SubProblem *>("_subproblem") = static_cast<SubProblem *>(_problem.get()); 46 : 47 : std::shared_ptr<Executioner> executioner = 48 122146 : _factory.create<Executioner>(_type, "Executioner", _moose_object_pars); 49 : 50 61052 : if ((eigen_problem != nullptr) != executioner->hasSolveObject<EigenProblemSolve>()) 51 0 : mooseError("Executioner is not consistent with each other; EigenExecutioner needs an " 52 : "EigenProblem, and Steady and Transient need a FEProblem"); 53 : 54 : // If enabled, automatically create a Preconditioner if the [Preconditioning] block is not found 55 301301 : if (_auto_preconditioning && !_awh.hasActions("add_preconditioning") && 56 232439 : _moose_object_pars.isParamValid("solve_type")) 57 31449 : setupAutoPreconditioning(); 58 : 59 61052 : _app.setExecutioner(std::move(executioner)); 60 61052 : } 61 : 62 : void 63 31449 : CreateExecutionerAction::setupAutoPreconditioning() 64 : { 65 : // If using NEWTON or LINEAR then automatically create SingleMatrixPreconditioner object with 66 : // full=true 67 31449 : const MooseEnum & solve_type = _moose_object_pars.get<MooseEnum>("solve_type"); 68 170726 : if (((solve_type.find("NEWTON") != solve_type.items().end()) && (solve_type == "NEWTON")) || 69 121751 : ((solve_type.find("LINEAR") != solve_type.items().end()) && (solve_type == "LINEAR"))) 70 18569 : for (const auto & nl_sys_name : _problem->getNonlinearSystemNames()) 71 : { 72 : // Action Parameters 73 27855 : InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction"); 74 9285 : params.set<std::string>("type") = "SMP"; 75 : 76 : // Associate errors with "solve_type" 77 18570 : associateWithParameter(_moose_object_pars, "solve_type", params); 78 : 79 : // Create the Action that will build the Preconditioner object 80 9285 : std::shared_ptr<Action> ptr = _action_factory.create( 81 : "SetupPreconditionerAction", 82 18570 : MooseUtils::join( 83 37140 : std::vector<std::string>({"_moose_auto", static_cast<std::string>(nl_sys_name)}), 84 : "_"), 85 18570 : params); 86 : 87 : // Set 'full=true' 88 9285 : std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr); 89 9285 : InputParameters & mo_params = moa_ptr->getObjectParams(); 90 18570 : mo_params.set<bool>("full") = true; 91 9285 : mo_params.set<NonlinearSystemName>("nl_sys") = nl_sys_name; 92 : 93 9285 : _awh.addActionBlock(ptr); 94 9285 : } 95 59304 : }