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 "MooseStaticCondensationPreconditioner.h" 11 : 12 : #include "FEProblem.h" 13 : #include "MooseUtils.h" 14 : #include "NonlinearSystemBase.h" 15 : #include "MooseVariableFieldBase.h" 16 : #include "libmesh/implicit_system.h" 17 : #include "libmesh/static_condensation.h" 18 : 19 : registerMooseObjectAliased("MooseApp", MooseStaticCondensationPreconditioner, "StaticCondensation"); 20 : 21 : InputParameters 22 14373 : MooseStaticCondensationPreconditioner::validParams() 23 : { 24 14373 : InputParameters params = SingleMatrixPreconditioner::validParams(); 25 14373 : params.addClassDescription("Static condensation preconditioner"); 26 14373 : params.set<bool>("full") = true; 27 14373 : params.suppressParameter<bool>("full"); 28 14373 : params.addParam<std::vector<NonlinearVariableName>>( 29 : "dont_condense_vars", 30 : {}, 31 : "A list of variables for whom to not statically condense their degrees of freedom out of the " 32 : "system. By default all degrees of freedom on element interiors are condensed out."); 33 : // Need to make this non-defaulted so that isParamValid doesn't always return true 34 14373 : params.set<MooseEnum>("mffd_type") = ""; 35 14373 : return params; 36 0 : } 37 : 38 54 : MooseStaticCondensationPreconditioner::MooseStaticCondensationPreconditioner( 39 54 : const InputParameters & params) 40 54 : : SingleMatrixPreconditioner(params) 41 : { 42 108 : auto check_param = [this](const auto & param_name) 43 : { 44 108 : if (isParamValid(param_name)) 45 0 : paramError(param_name, 46 : "This class prefixes every PETSc option so that it applies to the condensed " 47 : "system. Given that, there are multiple issues with setting '", 48 : param_name, 49 : "': 1) it applies to the nonlinear solver algorithm whereas the prefix this class " 50 : "applies makes PETSc options conceptually applicable only to the linear solve of " 51 : "the statically condensed system 2) these are singleton MOOSE-wrapped PETSc " 52 : "options. Consequently even if having multiple prefixes for a system's nonlinear " 53 : "solver options made sense, we don't support it. E.g. if you specify '", 54 : param_name, 55 : "' in both this object's block and the Executioner block, then there will be a " 56 : "logical conflict"); 57 162 : }; 58 54 : check_param("mffd_type"); 59 54 : check_param("solve_type"); 60 : 61 : // Now check the solve type set in the Executioner 62 54 : if (_fe_problem.solverParams(_nl.number())._type != Moose::ST_PJFNK) 63 0 : mooseError( 64 : "Static condensation preconditioning should use a PJFNK solve type. This is because it " 65 : "provides a means to compute the action of the Jacobian on vectors, which we otherwise " 66 : "would not have because when using static condensation, the Jacobian is never formed. Note " 67 : "that actions of the Jacobian on a vector are necessary for things like: GMRES, printing " 68 : "of linear residuals, or application of line searches like cubic backtracking. These " 69 : "particular operations can be avoided by using '-ksp_type preonly', disabling printing of " 70 : "linear residuals, and using the 'cp' or 'basic' line search."); 71 : 72 54 : auto * const implicit_sys = dynamic_cast<libMesh::ImplicitSystem *>(&_nl.system()); 73 54 : if (!implicit_sys) 74 0 : mooseError("Static condensation can only be used with implicit systems"); 75 54 : implicit_sys->create_static_condensation(); 76 54 : auto & sc = implicit_sys->get_static_condensation(); 77 54 : std::unordered_set<unsigned int> uncondensed_vars; 78 64 : for (auto & nl_var_name : getParam<std::vector<NonlinearVariableName>>("dont_condense_vars")) 79 10 : uncondensed_vars.insert(_nl.getVariable(0, nl_var_name).number()); 80 54 : sc.dont_condense_vars(uncondensed_vars); 81 54 : } 82 : 83 : void 84 54 : MooseStaticCondensationPreconditioner::initialSetup() 85 : { 86 54 : Moose::PetscSupport::storePetscOptions(_fe_problem, "-" + _nl.name() + "_condensed_", *this); 87 54 : }