nonlinear_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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
27 #include "libmesh/auto_ptr.h"
28 
29 namespace libMesh
30 {
31 
32 
33 //------------------------------------------------------------------
34 // NonlinearSolver members
35 #if defined(LIBMESH_HAVE_PETSC) || defined(LIBMESH_HAVE_NOX)
36 template <typename T>
37 AutoPtr<NonlinearSolver<T> >
39 {
41 
42  // Build the appropriate solver
43  switch (solver_package)
44  {
45 
46 #ifdef LIBMESH_HAVE_PETSC
47  case PETSC_SOLVERS:
48 #if PETSC_VERSION_LESS_THAN(3,3,0)
49  ap.reset(new PetscNonlinearSolver<T>(s));
50  break;
51 #else
52  if (libMesh::on_command_line ("--use-petsc-dm")){
54  }
55  else {
56  ap.reset(new PetscNonlinearSolver<T>(s));
57  }
58  break;
59 #endif
60 #endif // LIBMESH_HAVE_PETSC
61 
62 #ifdef LIBMESH_HAVE_NOX
63  case TRILINOS_SOLVERS:
64  ap.reset(new NoxNonlinearSolver<T>(s));
65  break;
66 #endif
67 
68  default:
69  libMesh::err << "ERROR: Unrecognized solver package: "
70  << solver_package
71  << std::endl;
72  libmesh_error();
73  }
74 
75  return ap;
76 }
77 #else // LIBMESH_HAVE_PETSC || LIBMESH_HAVE_NOX
78 template <typename T>
81 {
82  libMesh::err << "ERROR: libMesh was compiled without nonlinear solver support"
83  << std::endl;
84  libmesh_not_implemented();
85 }
86 #endif
87 
88 
89 template <typename T>
90 void
92 {
93  if(this->_is_initialized)
94  {
95  libMesh::err << "Preconditioner must be attached before the solver is initialized!"<<std::endl;
96  libmesh_error();
97  }
98 
99  _preconditioner = preconditioner;
100 }
101 
102 
103 //------------------------------------------------------------------
104 // Explicit instantiations
105 template class NonlinearSolver<Number>;
106 
107 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo