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 246715 : FEProblem::validParams() 27 : { 28 246715 : InputParameters params = FEProblemBase::validParams(); 29 246715 : params.addClassDescription("A normal (default) Problem object that contains a single " 30 : "NonlinearSystem and a single AuxiliarySystem object."); 31 : 32 246715 : return params; 33 0 : } 34 : 35 57084 : FEProblem::FEProblem(const InputParameters & parameters) 36 57084 : : FEProblemBase(parameters), _use_nonlinear(getParam<bool>("use_nonlinear")) 37 : { 38 57076 : if (_num_nl_sys) 39 : { 40 112184 : for (const auto i : index_range(_nl_sys_names)) 41 : { 42 56205 : const auto & sys_name = _nl_sys_names[i]; 43 56205 : auto & nl = _nl[i]; 44 112516 : nl = _use_nonlinear ? (std::make_shared<NonlinearSystem>(*this, sys_name)) 45 112516 : : (std::make_shared<MooseEigenSystem>(*this, sys_name)); 46 56205 : _nl_sys.push_back(std::dynamic_pointer_cast<NonlinearSystem>(nl)); 47 56205 : _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 55979 : setCurrentNonlinearSystem(0); 53 : } 54 : 55 57076 : if (_num_linear_sys) 56 2226 : for (const auto i : index_range(_linear_sys_names)) 57 : { 58 1119 : _linear_systems[i] = std::make_shared<LinearSystem>(*this, _linear_sys_names[i]); 59 1119 : _solver_systems[_num_nl_sys + i] = 60 2238 : std::dynamic_pointer_cast<SolverSystem>(_linear_systems[i]); 61 : } 62 : 63 57076 : if (_solver_systems.size() > 1) 64 744 : for (auto & solver_system : _solver_systems) 65 496 : solver_system->system().prefix_with_name(true); 66 : 67 57076 : _aux = std::make_shared<AuxiliarySystem>(*this, "aux0"); 68 : 69 57076 : newAssemblyArray(_solver_systems); 70 114400 : for (auto & solver_system : _solver_systems) 71 57324 : solver_system->system().prefer_hash_table_matrix_assembly(_use_hash_table_matrix_assembly); 72 : 73 57076 : if (_num_nl_sys) 74 55979 : initNullSpaceVectors(parameters, _nl); 75 : 76 57076 : es().parameters.set<FEProblem *>("_fe_problem") = this; 77 : 78 : // Create extra vectors and matrices if any 79 57076 : createTagVectors(); 80 : 81 : // Create extra solution vectors if any 82 57076 : createTagSolutions(); 83 57076 : } 84 : 85 : void 86 55352 : FEProblem::init() 87 : { 88 284 : auto check_threads = [this]() 89 : { 90 284 : if (libMesh::n_threads() != 1) 91 0 : mooseError("Static condensation may not be used with multiple threads"); 92 55636 : }; 93 : 94 109805 : for (const auto nl_sys_index : make_range(_num_nl_sys)) 95 : { 96 54453 : auto & libmesh_sys = _nl_sys[nl_sys_index]->sys(); 97 54453 : if (libmesh_sys.has_static_condensation()) 98 : { 99 284 : check_threads(); 100 568 : for (const auto tid : make_range(libMesh::n_threads())) 101 284 : _assembly[tid][nl_sys_index]->addStaticCondensation(libmesh_sys.get_static_condensation()); 102 : } 103 : } 104 56471 : for (const auto l_sys_index : make_range(_num_linear_sys)) 105 : { 106 1119 : auto & libmesh_sys = _linear_systems[l_sys_index]->linearImplicitSystem(); 107 1119 : if (libmesh_sys.has_static_condensation()) 108 : { 109 0 : check_threads(); 110 0 : for (const auto tid : make_range(libMesh::n_threads())) 111 0 : _assembly[tid][_num_nl_sys + l_sys_index]->addStaticCondensation( 112 : libmesh_sys.get_static_condensation()); 113 : } 114 : } 115 : 116 55352 : FEProblemBase::init(); 117 55352 : } 118 : 119 : void 120 1560476 : FEProblem::setInputParametersFEProblem(InputParameters & parameters) 121 : { 122 : // set _fe_problem 123 1560476 : FEProblemBase::setInputParametersFEProblem(parameters); 124 : // set _fe_problem 125 1560476 : parameters.set<FEProblem *>("_fe_problem") = this; 126 1560476 : } 127 : 128 : void 129 0 : FEProblem::addLineSearch(const InputParameters & parameters) 130 : { 131 0 : MooseEnum line_search = parameters.get<MooseEnum>("line_search"); 132 0 : Moose::LineSearchType enum_line_search = Moose::stringToEnum<Moose::LineSearchType>(line_search); 133 0 : if (enum_line_search == Moose::LS_CONTACT || enum_line_search == Moose::LS_PROJECT) 134 : { 135 0 : if (enum_line_search == Moose::LS_CONTACT) 136 : { 137 0 : InputParameters ls_params = _factory.getValidParams("PetscContactLineSearch"); 138 : 139 0 : bool affect_ltol = parameters.isParamValid("contact_line_search_ltol"); 140 0 : ls_params.set<bool>("affect_ltol") = affect_ltol; 141 0 : ls_params.set<unsigned>("allowed_lambda_cuts") = 142 0 : parameters.get<unsigned>("contact_line_search_allowed_lambda_cuts"); 143 0 : ls_params.set<Real>("contact_ltol") = affect_ltol 144 0 : ? parameters.get<Real>("contact_line_search_ltol") 145 0 : : parameters.get<Real>("l_tol"); 146 0 : ls_params.set<FEProblem *>("_fe_problem") = this; 147 : 148 : _line_search = 149 0 : _factory.create<LineSearch>("PetscContactLineSearch", "contact_line_search", ls_params); 150 0 : } 151 : else 152 : { 153 0 : InputParameters ls_params = _factory.getValidParams("PetscProjectSolutionOntoBounds"); 154 0 : ls_params.set<FEProblem *>("_fe_problem") = this; 155 : 156 0 : _line_search = _factory.create<LineSearch>( 157 0 : "PetscProjectSolutionOntoBounds", "project_solution_onto_bounds_line_search", ls_params); 158 0 : } 159 0 : } 160 : else 161 0 : mooseError("Requested line search ", line_search.operator std::string(), " is not supported"); 162 0 : }