libMesh
nonlinear_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 // C++ includes
21 
22 // Local Includes
23 #include "libmesh/nonlinear_solver.h"
24 #include "libmesh/petsc_nonlinear_solver.h"
25 #include "libmesh/trilinos_nox_nonlinear_solver.h"
26 #include "libmesh/auto_ptr.h"
27 #include "libmesh/solver_configuration.h"
28 
29 namespace libMesh
30 {
31 
32 
33 //------------------------------------------------------------------
34 // NonlinearSolver members
35 #if defined(LIBMESH_HAVE_PETSC) || defined(LIBMESH_TRILINOS_HAVE_NOX)
36 template <typename T>
37 UniquePtr<NonlinearSolver<T>>
39 {
40  // Build the appropriate solver
41  switch (solver_package)
42  {
43 
44 #ifdef LIBMESH_HAVE_PETSC
45  case PETSC_SOLVERS:
47 #endif // LIBMESH_HAVE_PETSC
48 
49 #if defined(LIBMESH_TRILINOS_HAVE_NOX) && defined(LIBMESH_TRILINOS_HAVE_EPETRA)
50  case TRILINOS_SOLVERS:
52 #endif
53 
54  default:
55  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
56  }
57 
58  libmesh_error_msg("We'll never get here!");
60 }
61 
62 #else // LIBMESH_HAVE_PETSC || LIBMESH_TRILINOS_HAVE_NOX
63 
64 template <typename T>
67 {
68  libmesh_not_implemented_msg("ERROR: libMesh was compiled without nonlinear solver support");
69 }
70 #endif
71 
72 
73 template <typename T>
74 void
76 {
77  if (this->_is_initialized)
78  libmesh_error_msg("Preconditioner must be attached before the solver is initialized!");
79 
80  _preconditioner = preconditioner;
81 }
82 
83 template <typename T>
85 {
86  _solver_configuration = &solver_configuration;
87 }
88 
89 
90 //------------------------------------------------------------------
91 // Explicit instantiations
92 template class NonlinearSolver<Number>;
93 
94 } // namespace libMesh
SolverPackage
Defines an enum for various linear solver packages.
void attach_preconditioner(Preconditioner< T > *preconditioner)
Attaches a Preconditioner object to be used during the linear solves.
The libMesh namespace provides an interface to certain functionality in the library.
This class provides an interface to PETSc iterative solvers that is compatible with the libMesh Nonli...
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
This class provides a uniform interface for preconditioners.
This class provides an interface to nox iterative solvers that is compatible with the libMesh Nonline...
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:255
This class provides a specific system class.
This class stores solver configuration data, e.g.
static UniquePtr< 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.