https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FEProblem.C
Go to the documentation of this file.
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
24
27{
29 params.addClassDescription("A normal (default) Problem object that contains a single "
30 "NonlinearSystem and a single AuxiliarySystem object.");
31
32 return params;
33}
34
36 : FEProblemBase(parameters), _use_nonlinear(getParam<bool>("use_nonlinear"))
37{
38 if (_num_nl_sys)
39 {
40 for (const auto i : index_range(_nl_sys_names))
41 {
42 const auto & sys_name = _nl_sys_names[i];
43 auto & nl = _nl[i];
44 nl = _use_nonlinear ? (std::make_shared<NonlinearSystem>(*this, sys_name))
45 : (std::make_shared<MooseEigenSystem>(*this, sys_name));
46 _nl_sys.push_back(std::dynamic_pointer_cast<NonlinearSystem>(nl));
47 _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
53 }
54
56 for (const auto i : index_range(_linear_sys_names))
57 {
58 _linear_systems[i] = std::make_shared<LinearSystem>(*this, _linear_sys_names[i]);
60 std::dynamic_pointer_cast<SolverSystem>(_linear_systems[i]);
61 }
62
63 if (_solver_systems.size() > 1)
64 for (auto & solver_system : _solver_systems)
65 solver_system->system().prefix_with_name(true);
66
67 _aux = std::make_shared<AuxiliarySystem>(*this, "aux0");
68
70 for (auto & solver_system : _solver_systems)
71 solver_system->system().prefer_hash_table_matrix_assembly(_use_hash_table_matrix_assembly);
72
73 if (_num_nl_sys)
75
76 es().parameters.set<FEProblem *>("_fe_problem") = this;
77
78 // Create extra vectors if any
80
81 // Create extra solution vectors if any
83}
84
85void
87{
88 for (const auto & sys : _solver_systems)
89 if (sys->system().has_static_condensation() && libMesh::n_threads() != 1)
90 mooseError("Static condensation may not be used with multiple threads");
91
93}
94
95void
97{
98 // set _fe_problem
100 // set _fe_problem
101 parameters.set<FEProblem *>("_fe_problem") = this;
102}
103
104void
106{
107 MooseEnum line_search = parameters.get<MooseEnum>("line_search");
108 Moose::LineSearchType enum_line_search = Moose::stringToEnum<Moose::LineSearchType>(line_search);
109 if (enum_line_search == Moose::LS_CONTACT || enum_line_search == Moose::LS_PROJECT)
110 {
111 if (enum_line_search == Moose::LS_CONTACT)
112 {
113 InputParameters ls_params = _factory.getValidParams("PetscContactLineSearch");
114
115 bool affect_ltol = parameters.isParamValid("contact_line_search_ltol");
116 ls_params.set<bool>("affect_ltol") = affect_ltol;
117 ls_params.set<unsigned>("allowed_lambda_cuts") =
118 parameters.get<unsigned>("contact_line_search_allowed_lambda_cuts");
119 ls_params.set<Real>("contact_ltol") = affect_ltol
120 ? parameters.get<Real>("contact_line_search_ltol")
121 : parameters.get<Real>("l_tol");
122 ls_params.set<FEProblem *>("_fe_problem") = this;
123
125 _factory.create<LineSearch>("PetscContactLineSearch", "contact_line_search", ls_params);
126 }
127 else
128 {
129 InputParameters ls_params = _factory.getValidParams("PetscProjectSolutionOntoBounds");
130 ls_params.set<FEProblem *>("_fe_problem") = this;
131
133 "PetscProjectSolutionOntoBounds", "project_solution_onto_bounds_line_search", ls_params);
134 }
135 }
136 else
137 mooseError("Requested line search ", line_search.operator std::string(), " is not supported");
138}
registerMooseObject("MooseApp", FEProblem)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::shared_ptr< AuxiliarySystem > _aux
The auxiliary system.
virtual void init() override
void createTagVectors()
Create extra tagged vectors and matrices.
virtual libMesh::EquationSystems & es() override
std::shared_ptr< LineSearch > _line_search
std::vector< std::shared_ptr< LinearSystem > > _linear_systems
The vector of linear systems.
const bool _use_hash_table_matrix_assembly
Whether to assemble matrices using hash tables instead of preallocating matrix memory.
virtual void newAssemblyArray(std::vector< std::shared_ptr< SolverSystem > > &solver_systems)
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
const std::vector< LinearSystemName > _linear_sys_names
The linear system names.
const std::size_t _num_linear_sys
The number of linear systems.
virtual void initNullSpaceVectors(const InputParameters &parameters, std::vector< std::shared_ptr< NonlinearSystemBase > > &nl)
const std::size_t _num_nl_sys
The number of nonlinear systems.
virtual void setInputParametersFEProblem(InputParameters &parameters)
void createTagSolutions()
Create extra tagged solution vectors.
std::vector< std::shared_ptr< SolverSystem > > _solver_systems
Combined container to base pointer of every solver system.
const std::vector< NonlinearSystemName > _nl_sys_names
The nonlinear system names.
static InputParameters validParams()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition FEProblem.h:21
virtual void setInputParametersFEProblem(InputParameters &parameters) override
Definition FEProblem.C:96
static InputParameters validParams()
Definition FEProblem.C:26
bool _use_nonlinear
Definition FEProblem.h:38
virtual void init() override
Definition FEProblem.C:86
std::vector< std::shared_ptr< NonlinearSystem > > _nl_sys
Definition FEProblem.h:39
std::vector< std::shared_ptr< NonlinearSystemBase > > _nl
The nonlinear systems.
FEProblem(const InputParameters &parameters)
Definition FEProblem.C:35
virtual void addLineSearch(const InputParameters &parameters) override
add a MOOSE line search
Definition FEProblem.C:105
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition Factory.C:142
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Factory & _factory
The Factory for building objects.
T & set(const std::string &)
LineSearchType
Type of the line search.
Definition MooseTypes.h:980
@ LS_PROJECT
Definition MooseTypes.h:987
@ LS_CONTACT
Definition MooseTypes.h:986
unsigned int n_threads()