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 59730 : CreateExecutionerAction::validParams() 23 : { 24 59730 : InputParameters params = MooseObjectAction::validParams(); 25 59730 : params.addClassDescription("Add an Executioner object to the simulation."); 26 179190 : params.addParam<bool>( 27 : "auto_preconditioning", 28 119460 : 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 59730 : return params; 32 0 : } 33 : 34 58462 : CreateExecutionerAction::CreateExecutionerAction(const InputParameters & params) 35 58462 : : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning")) 36 : { 37 58458 : } 38 : 39 : void 40 57629 : CreateExecutionerAction::act() 41 : { 42 57629 : std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem); 43 57629 : if (eigen_problem) 44 562 : _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get(); 45 57629 : _moose_object_pars.set<SubProblem *>("_subproblem") = static_cast<SubProblem *>(_problem.get()); 46 : 47 : std::shared_ptr<Executioner> executioner = 48 57629 : _factory.create<Executioner>(_type, "Executioner", _moose_object_pars); 49 : 50 : std::shared_ptr<Eigenvalue> eigen_executioner = 51 57601 : std::dynamic_pointer_cast<Eigenvalue>(executioner); 52 : 53 57601 : 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 169012 : if (_auto_preconditioning && !_awh.hasActions("add_preconditioning") && 59 111411 : _moose_object_pars.isParamValid("solve_type")) 60 31530 : setupAutoPreconditioning(); 61 : 62 57601 : _app.setExecutioner(std::move(executioner)); 63 57601 : } 64 : 65 : void 66 31530 : CreateExecutionerAction::setupAutoPreconditioning() 67 : { 68 : // If using NEWTON or LINEAR then automatically create SingleMatrixPreconditioner object with 69 : // full=true 70 31530 : const MooseEnum & solve_type = _moose_object_pars.get<MooseEnum>("solve_type"); 71 107242 : if (((solve_type.find("NEWTON") != solve_type.items().end()) && (solve_type == "NEWTON")) || 72 75712 : ((solve_type.find("LINEAR") != solve_type.items().end()) && (solve_type == "LINEAR"))) 73 19576 : for (const auto & nl_sys_name : _problem->getNonlinearSystemNames()) 74 : { 75 : // Action Parameters 76 9790 : InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction"); 77 9790 : params.set<std::string>("type") = "SMP"; 78 : 79 : // Associate errors with "solve_type" 80 9790 : associateWithParameter(_moose_object_pars, "solve_type", params); 81 : 82 : // Create the Action that will build the Preconditioner object 83 9790 : std::shared_ptr<Action> ptr = _action_factory.create( 84 : "SetupPreconditionerAction", 85 29370 : MooseUtils::join( 86 48950 : std::vector<std::string>({"_moose_auto", static_cast<std::string>(nl_sys_name)}), 87 : "_"), 88 9790 : params); 89 : 90 : // Set 'full=true' 91 9790 : std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr); 92 9790 : InputParameters & mo_params = moa_ptr->getObjectParams(); 93 9790 : mo_params.set<bool>("full") = true; 94 9790 : mo_params.set<NonlinearSystemName>("nl_sys") = nl_sys_name; 95 : 96 9790 : _awh.addActionBlock(ptr); 97 9790 : } 98 51110 : }