https://mooseframework.inl.gov
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 
23 registerMooseObject("MooseApp", FEProblem);
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));
48  }
49 
50  // backwards compatibility for AD for objects that depend on initializing derivatives during
51  // construction
53  }
54 
55  if (_num_linear_sys)
56  for (const auto i : index_range(_linear_sys_names))
57  {
58  _linear_systems[i] = std::make_shared<LinearSystem>(*this, _linear_sys_names[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 
85 void
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 
95 void
97 {
98  // set _fe_problem
100  // set _fe_problem
101  parameters.set<FEProblem *>("_fe_problem") = this;
102 }
103 
104 void
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 
124  _line_search =
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 }
std::vector< std::shared_ptr< NonlinearSystem > > _nl_sys
Definition: FEProblem.h:39
bool _use_nonlinear
Definition: FEProblem.h:38
const std::size_t _num_nl_sys
The number of nonlinear systems.
Factory & _factory
The Factory for building objects.
Definition: SubProblem.h:1047
unsigned int n_threads()
virtual void setInputParametersFEProblem(InputParameters &parameters) override
Definition: FEProblem.C:96
virtual void setInputParametersFEProblem(InputParameters &parameters)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:20
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.
virtual void init() override
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
virtual void newAssemblyArray(std::vector< std::shared_ptr< SolverSystem >> &solver_systems)
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:111
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
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::shared_ptr< SolverSystem > > _solver_systems
Combined container to base pointer of every solver system.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void init() override
Definition: FEProblem.C:86
FEProblem(const InputParameters &parameters)
Definition: FEProblem.C:35
std::vector< std::shared_ptr< NonlinearSystemBase > > _nl
The nonlinear systems.
void createTagSolutions()
Create extra tagged solution vectors.
static InputParameters validParams()
Definition: FEProblem.C:26
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
LineSearchType
Type of the line search.
Definition: MooseTypes.h:926
void createTagVectors()
Create extra tagged vectors and matrices.
virtual void addLineSearch(const InputParameters &parameters) override
add a MOOSE line search
Definition: FEProblem.C:105
virtual libMesh::EquationSystems & es() override
std::shared_ptr< AuxiliarySystem > _aux
The auxiliary system.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
virtual void initNullSpaceVectors(const InputParameters &parameters, std::vector< std::shared_ptr< NonlinearSystemBase >> &nl)
const std::vector< NonlinearSystemName > _nl_sys_names
The nonlinear system names.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
const std::vector< LinearSystemName > _linear_sys_names
The linear system names.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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...
static InputParameters validParams()
const std::size_t _num_linear_sys
The number of linear systems.
const bool _use_hash_table_matrix_assembly
Whether to assemble matrices using hash tables instead of preallocating matrix memory.
registerMooseObject("MooseApp", FEProblem)
std::vector< std::shared_ptr< LinearSystem > > _linear_systems
The vector of linear systems.
void prefix_with_name(bool value)
auto index_range(const T &sizable)
std::shared_ptr< LineSearch > _line_search
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.