libMesh
nonlinear_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // Local Includes
21 #include "libmesh/auto_ptr.h" // libmesh_make_unique
22 #include "libmesh/nonlinear_solver.h"
23 #include "libmesh/petsc_nonlinear_solver.h"
24 #include "libmesh/trilinos_nox_nonlinear_solver.h"
25 #include "libmesh/solver_configuration.h"
26 #include "libmesh/enum_solver_package.h"
27 
28 namespace libMesh
29 {
30 
31 
32 //------------------------------------------------------------------
33 // NonlinearSolver members
34 #if defined(LIBMESH_HAVE_PETSC) || defined(LIBMESH_TRILINOS_HAVE_NOX)
35 template <typename T>
36 std::unique_ptr<NonlinearSolver<T>>
38 {
39  // Build the appropriate solver
40  switch (solver_package)
41  {
42 
43 #ifdef LIBMESH_HAVE_PETSC
44  case PETSC_SOLVERS:
45  return libmesh_make_unique<PetscNonlinearSolver<T>>(s);
46 #endif // LIBMESH_HAVE_PETSC
47 
48 #if defined(LIBMESH_TRILINOS_HAVE_NOX) && defined(LIBMESH_TRILINOS_HAVE_EPETRA)
49  case TRILINOS_SOLVERS:
50  return libmesh_make_unique<NoxNonlinearSolver<T>>(s);
51 #endif
52 
53  default:
54  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
55  }
56 }
57 
58 #else // LIBMESH_HAVE_PETSC || LIBMESH_TRILINOS_HAVE_NOX
59 
60 template <typename T>
61 std::unique_ptr<NonlinearSolver<T>>
63 {
64  libmesh_not_implemented_msg("ERROR: libMesh was compiled without nonlinear solver support");
65 }
66 #endif
67 
68 
69 template <typename T>
70 void
72 {
73  if (this->_is_initialized)
74  libmesh_error_msg("Preconditioner must be attached before the solver is initialized!");
75 
76  _preconditioner = preconditioner;
77 }
78 
79 template <typename T>
81 {
82  _solver_configuration = &solver_configuration;
83 }
84 
85 
86 //------------------------------------------------------------------
87 // Explicit instantiations
88 template class NonlinearSolver<Number>;
89 
90 } // namespace libMesh
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::PETSC_SOLVERS
Definition: enum_solver_package.h:36
libMesh::NonlinearSolver< Number >
libMesh::NonlinearSolver::set_solver_configuration
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
Definition: nonlinear_solver.C:80
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::NonlinearSolver::attach_preconditioner
void attach_preconditioner(Preconditioner< T > *preconditioner)
Attaches a Preconditioner object to be used during the linear solves.
Definition: nonlinear_solver.C:71
libMesh::NonlinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
Definition: nonlinear_implicit_system.h:54
libMesh::Preconditioner
This class provides a uniform interface for preconditioners.
Definition: preconditioner.h:66
libMesh::TRILINOS_SOLVERS
Definition: enum_solver_package.h:37
libMesh::libMeshPrivateData::_is_initialized
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:246
libMesh::SolverConfiguration
This class stores solver configuration data, e.g.
Definition: solver_configuration.h:39
libMesh::NonlinearSolver::build
static std::unique_ptr< NonlinearSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NonlinearSolver using the nonlinear solver package specified by solver_package.
Definition: nonlinear_solver.C:37