nonlinear_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
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
TRILINOS_SOLVERS
Definition: libmesh.C:244
void attach_preconditioner(Preconditioner< T > *preconditioner)
void set_solver_configuration(SolverConfiguration &solver_configuration)
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
static std::unique_ptr< NonlinearSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())