Hermes2D  3.0
nox_solver.h
1 // This file is part of HermesCommon
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://www.hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __H2D_NEWTON_SOLVER_NOX_H_
23 #define __H2D_NEWTON_SOLVER_NOX_H_
24 
25 #include "solvers/linear_matrix_solver.h"
26 #include "solvers/interfaces/epetra.h"
27 #if(defined HAVE_NOX && defined HAVE_EPETRA && defined HAVE_TEUCHOS)
28 #include <NOX.H>
29 #ifdef _POSIX_C_SOURCE
30 # undef _POSIX_C_SOURCE // pyconfig.h included by NOX_Epetra defines it
31 #endif
32 #ifdef _XOPEN_SOURCE
33 # undef _XOPEN_SOURCE // pyconfig.h included by NOX_Epetra defines it
34 #endif
35 #undef interface
36 #include <NOX_Epetra.H>
37 #include "exceptions.h"
38 #include "discrete_problem.h"
39 
40 namespace Hermes
41 {
42  namespace Hermes2D
43  {
44  template <typename Scalar> class NewtonSolverNOX;
45 
48  template <typename Scalar>
49  class HERMES_API DiscreteProblemNOX :
50  public Hermes::Hermes2D::DiscreteProblem<Scalar>,
51  public NOX::Epetra::Interface::Required,
52  public NOX::Epetra::Interface::Jacobian,
53  public NOX::Epetra::Interface::Preconditioner
54  {
55  public:
57  DiscreteProblemNOX(WeakFormSharedPtr<Scalar> wf, std::vector<SpaceSharedPtr<Scalar> > spaces);
59  DiscreteProblemNOX(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space);
61  DiscreteProblemNOX();
62  ~DiscreteProblemNOX();
63 
65  void set_precond(Teuchos::RCP<Hermes::Preconditioners::EpetraPrecond<Scalar> > &pc);
66 
68  Teuchos::RCP<Hermes::Preconditioners::EpetraPrecond<Scalar> > get_precond();
69 
70  // that is generated by the Interface class.
71  EpetraMatrix<Scalar> *get_jacobian();
72 
74  virtual bool computeF(const Epetra_Vector &x, Epetra_Vector &f, FillType flag = Residual);
75 
77  virtual bool computeJacobian(const Epetra_Vector &x, Epetra_Operator &op);
78 
81  virtual bool computePreconditioner(const Epetra_Vector &x, Epetra_Operator &m,
82  Teuchos::ParameterList *precParams = 0);
83 
84  private:
86  EpetraMatrix<Scalar>* jacobian;
88  Teuchos::RCP<Hermes::Preconditioners::EpetraPrecond<Scalar> > precond;
89 
90  friend class NewtonSolverNOX < Scalar > ;
91  };
92 
95  template <typename Scalar>
96  class HERMES_API NewtonSolverNOX : public Hermes::Mixins::Loggable
97  {
98  private:
99  Teuchos::RCP<Teuchos::ParameterList> nl_pars;
100  public:
102  NewtonSolverNOX(DiscreteProblemNOX<Scalar> *problem);
104  NewtonSolverNOX(WeakFormSharedPtr<Scalar> wf, std::vector<SpaceSharedPtr<Scalar> > spaces);
106  NewtonSolverNOX(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space);
107 
109  void init();
110 
111  virtual ~NewtonSolverNOX();
112 
114  virtual void set_time(double time);
115  virtual void set_time_step(double time_step);
116 
117  virtual void solve(Scalar* coeff_vec = nullptr);
118  virtual void solve(std::vector<MeshFunctionSharedPtr<Scalar> > initial_guess);
119  virtual void solve(MeshFunctionSharedPtr<Scalar> initial_guess);
120 
121  Scalar* get_sln_vector();
122 
123  virtual int get_num_iters();
124  virtual double get_residual();
125  int get_num_lin_iters();
126  double get_achieved_tol();
127 
135  void set_output_flags(int flags);
136 
146  void set_ls_type(const char *type);
148  void set_ls_max_iters(int iters);
150  void set_ls_tolerance(double tolerance);
152  void set_ls_sizeof_krylov_subspace(int size);
154 
161  void set_norm_type(NOX::Abstract::Vector::NormType type);
165  void set_scale_type(NOX::StatusTest::NormF::ScaleType type);
167  void set_conv_iters(int iters);
169  void set_conv_abs_resid(double resid);
171  void set_conv_rel_resid(double resid);
173  void disable_abs_resid();
175  void disable_rel_resid();
177  void set_conv_update(double update);
181  void set_conv_wrms(double rtol, double atol);
183 
196  void set_precond_reuse(const char * pc_reuse);
200  void set_precond_max_age(int max_age);
203  virtual void set_precond(Hermes::Preconditioners::EpetraPrecond<Scalar> &pc);
210  virtual void set_precond(const char *pc);
211 
212  Scalar* sln_vector;
213  DiscreteProblemNOX<Scalar> *dp;
214 
216  bool own_dp;
217 
218  protected:
219  int num_iters;
220  double residual;
221  int num_lin_iters;
222  double achieved_tol;
223 
224  // convergence params
225  struct conv_t
226  {
227  int max_iters;
228  double abs_resid;
229  double rel_resid;
231  NOX::StatusTest::NormF::ScaleType stype;
232  double update;
233  double wrms_rtol;
234  double wrms_atol;
235  } conv;
236 
237  struct conv_flag_t
238  {
239  unsigned absresid : 1;
240  unsigned relresid : 1;
241  unsigned wrms : 1;
242  unsigned update : 1;
243  } conv_flag;
244  };
245  }
246 }
247 #endif
248 #endif
Definition: adapt.h:24
::xsd::cxx::tree::flags flags
Parsing and serialization flags.
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
::xsd::cxx::tree::type type
C++ type corresponding to the anyType XML Schema built-in type.