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 "FEProblem.h" 11 : 12 : #include "Assembly.h" 13 : #include "AuxiliarySystem.h" 14 : #include "MooseEigenSystem.h" 15 : #include "NonlinearSystem.h" 16 : #include "LinearSystem.h" 17 : #include "LineSearch.h" 18 : #include "MooseEnum.h" 19 : 20 : #include "libmesh/nonlinear_implicit_system.h" 21 : #include "libmesh/linear_implicit_system.h" 22 : 23 : registerMooseObject("MooseApp", FEProblem); 24 : 25 : InputParameters 26 258770 : FEProblem::validParams() 27 : { 28 258770 : InputParameters params = FEProblemBase::validParams(); 29 258770 : params.addClassDescription("A normal (default) Problem object that contains a single " 30 : "NonlinearSystem and a single AuxiliarySystem object."); 31 : 32 258770 : return params; 33 0 : } 34 : 35 62128 : FEProblem::FEProblem(const InputParameters & parameters) 36 186384 : : FEProblemBase(parameters), _use_nonlinear(getParam<bool>("use_nonlinear")) 37 : { 38 62128 : if (_num_nl_sys) 39 : { 40 121942 : for (const auto i : index_range(_nl_sys_names)) 41 : { 42 61091 : const auto & sys_name = _nl_sys_names[i]; 43 61091 : auto & nl = _nl[i]; 44 122298 : nl = _use_nonlinear ? (std::make_shared<NonlinearSystem>(*this, sys_name)) 45 122298 : : (std::make_shared<MooseEigenSystem>(*this, sys_name)); 46 61091 : _nl_sys.push_back(std::dynamic_pointer_cast<NonlinearSystem>(nl)); 47 61091 : _solver_systems[i] = std::dynamic_pointer_cast<SolverSystem>(nl); 48 : } 49 : 50 : // backwards compatibility for AD for objects that depend on initializing derivatives during 51 : // construction 52 60851 : setCurrentNonlinearSystem(0); 53 : } 54 : 55 62128 : if (_num_linear_sys) 56 2667 : for (const auto i : index_range(_linear_sys_names)) 57 : { 58 1340 : _linear_systems[i] = std::make_shared<LinearSystem>(*this, _linear_sys_names[i]); 59 1340 : _solver_systems[_num_nl_sys + i] = 60 2680 : std::dynamic_pointer_cast<SolverSystem>(_linear_systems[i]); 61 : } 62 : 63 62128 : if (_solver_systems.size() > 1) 64 909 : for (auto & solver_system : _solver_systems) 65 606 : solver_system->system().prefix_with_name(true); 66 : 67 62128 : _aux = std::make_shared<AuxiliarySystem>(*this, "aux0"); 68 : 69 62128 : newAssemblyArray(_solver_systems); 70 124559 : for (auto & solver_system : _solver_systems) 71 62431 : solver_system->system().prefer_hash_table_matrix_assembly(_use_hash_table_matrix_assembly); 72 : 73 62128 : if (_num_nl_sys) 74 60851 : initNullSpaceVectors(parameters, _nl); 75 : 76 124256 : es().parameters.set<FEProblem *>("_fe_problem") = this; 77 : 78 : // Create extra vectors if any 79 62128 : createTagVectors(); 80 : 81 : // Create extra solution vectors if any 82 62128 : createTagSolutions(); 83 62128 : } 84 : 85 : void 86 60392 : FEProblem::init() 87 : { 88 121059 : for (const auto & sys : _solver_systems) 89 60667 : if (sys->system().has_static_condensation() && libMesh::n_threads() != 1) 90 0 : mooseError("Static condensation may not be used with multiple threads"); 91 : 92 60392 : FEProblemBase::init(); 93 60392 : } 94 : 95 : void 96 1731100 : FEProblem::setInputParametersFEProblem(InputParameters & parameters) 97 : { 98 : // set _fe_problem 99 1731100 : FEProblemBase::setInputParametersFEProblem(parameters); 100 : // set _fe_problem 101 3462200 : parameters.set<FEProblem *>("_fe_problem") = this; 102 1731100 : } 103 : 104 : void 105 0 : FEProblem::addLineSearch(const InputParameters & parameters) 106 : { 107 0 : MooseEnum line_search = parameters.get<MooseEnum>("line_search"); 108 0 : Moose::LineSearchType enum_line_search = Moose::stringToEnum<Moose::LineSearchType>(line_search); 109 0 : if (enum_line_search == Moose::LS_CONTACT || enum_line_search == Moose::LS_PROJECT) 110 : { 111 0 : if (enum_line_search == Moose::LS_CONTACT) 112 : { 113 0 : InputParameters ls_params = _factory.getValidParams("PetscContactLineSearch"); 114 : 115 0 : bool affect_ltol = parameters.isParamValid("contact_line_search_ltol"); 116 0 : ls_params.set<bool>("affect_ltol") = affect_ltol; 117 0 : ls_params.set<unsigned>("allowed_lambda_cuts") = 118 0 : parameters.get<unsigned>("contact_line_search_allowed_lambda_cuts"); 119 0 : ls_params.set<Real>("contact_ltol") = affect_ltol 120 0 : ? parameters.get<Real>("contact_line_search_ltol") 121 0 : : parameters.get<Real>("l_tol"); 122 0 : ls_params.set<FEProblem *>("_fe_problem") = this; 123 : 124 : _line_search = 125 0 : _factory.create<LineSearch>("PetscContactLineSearch", "contact_line_search", ls_params); 126 0 : } 127 : else 128 : { 129 0 : InputParameters ls_params = _factory.getValidParams("PetscProjectSolutionOntoBounds"); 130 0 : ls_params.set<FEProblem *>("_fe_problem") = this; 131 : 132 0 : _line_search = _factory.create<LineSearch>( 133 0 : "PetscProjectSolutionOntoBounds", "project_solution_onto_bounds_line_search", ls_params); 134 0 : } 135 0 : } 136 : else 137 0 : mooseError("Requested line search ", line_search.operator std::string(), " is not supported"); 138 0 : }