libMesh
trilinos_nox_nonlinear_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 #ifndef LIBMESH_TRILINOS_NOX_NONLINEAR_SOLVER_H
21 #define LIBMESH_TRILINOS_NOX_NONLINEAR_SOLVER_H
22 
23 // It is possible to build Trilinos with NOX, but without Epetra. The
24 // way that libmesh uses NOX requires Epetra, however, so we have to
25 // check for both.
26 #if defined(LIBMESH_TRILINOS_HAVE_NOX) && defined(LIBMESH_TRILINOS_HAVE_EPETRA)
27 
28 // Local includes
29 #include "libmesh/nonlinear_solver.h"
30 
31 // Trilinos includes
32 #include "libmesh/ignore_warnings.h"
33 #include "Epetra_Vector.h"
34 #include "Epetra_Operator.h"
35 #include "Epetra_RowMatrix.h"
36 #include "NOX_Epetra_Interface_Required.H" // base class
37 #include "NOX_Epetra_Interface_Jacobian.H" // base class
38 #include "NOX_Epetra_Interface_Preconditioner.H" // base class
39 #include "NOX.H"
40 #include "libmesh/restore_warnings.h"
41 
42 // C++ includes
43 #include <cstddef>
44 
45 namespace libMesh
46 {
47 
48 // Forward declarations
49 class Problem_Interface;
50 
51 
60 template <typename T>
62 {
63 public:
68 
72  explicit
74 
78  virtual ~NoxNonlinearSolver ();
79 
83  virtual void clear () override;
84 
88  virtual void init (const char * name = nullptr) override;
89 
94  virtual std::pair<unsigned int, Real>
95  solve (SparseMatrix<T> &, // System Jacobian Matrix
96  NumericVector<T> &, // Solution vector
97  NumericVector<T> &, // Residual vector
98  const double, // Stopping tolerance
99  const unsigned int) override; // N. Iterations
103  virtual int get_total_linear_iterations() override;
104 
112  virtual unsigned get_current_nonlinear_iteration_number() const override
113  { libmesh_not_implemented(); return 0; }
114 
115 private:
116 
120  NOX::Solver::Generic * _solver;
121 
126 
131 };
132 
133 
134 /*----------------------- functions ----------------------------------*/
135 template <typename T>
136 inline
138  NonlinearSolver<T>(system),
139  _solver(nullptr),
140  _interface(nullptr),
141  _n_linear_iterations(0)
142 {
143 }
144 
145 
146 
147 template <typename T>
148 inline
150 {
151  this->clear ();
152 }
153 
154 
155 } // namespace libMesh
156 
157 
158 #endif // LIBMESH_TRILINOS_HAVE_NOX && LIBMESH_TRILINOS_HAVE_EPETRA
159 #endif // LIBMESH_TRILINOS_NOX_NONLINEAR_SOLVER_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
virtual int get_total_linear_iterations() override
Get the total number of linear iterations done in the last solve.
int _n_linear_iterations
Stores the total number of linear iterations from the last solve.
virtual void init(const char *name=nullptr) override
Initialize data structures if not done so already.
Problem_Interface * _interface
Solver interface.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
This base class can be inherited from to provide interfaces to nonlinear solvers from different packa...
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int) override
Call the Nox solver.
The libMesh namespace provides an interface to certain functionality in the library.
NOX::Solver::Generic * _solver
Nonlinear solver context.
virtual void clear() override
Release all memory and clear data structures.
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
const sys_type & system() const
This class provides an interface to nox iterative solvers that is compatible with the libMesh Nonline...
NonlinearImplicitSystem sys_type
The type of system.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
NoxNonlinearSolver(sys_type &system)
Constructor.
virtual unsigned get_current_nonlinear_iteration_number() const override