Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
solvernonlinearpetsc.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2007-07-02
7 
8  Copyright (C) 2007-2011 Universite Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __SolverNonLinearPetsc_H
30 #define __SolverNonLinearPetsc_H 1
31 
32 #include <feel/feelcore/feel.hpp>
36 
37 // Petsc include files.
38 #if defined( FEELPP_HAS_PETSC_H )
39 
40 #ifndef USE_COMPLEX_NUMBERS
41 extern "C" {
42 # include <petscversion.h>
43 # include <petsc.h>
44 # include <petscsnes.h>
45 }
46 #else
47 # include <petscversion.h>
48 # include <petsc.h>
49 # include <petscsnes.h>
50 #endif
51 
52 
53 
60 namespace Feel
61 {
62 
72 template<typename T>
73 class SolverNonLinearPetsc
74  :
75 public SolverNonLinear<T>
76 {
77  typedef SolverNonLinear<T> super;
78 public:
79 
80 
84 
85  typedef SolverNonLinearPetsc<T> self_type;
86 
87  typedef typename super::value_type value_type;
88  typedef typename super::real_type real_type;
89  typedef typename super::sparse_matrix_ptrtype sparse_matrix_ptrtype;
90  typedef typename super::vector_ptrtype vector_ptrtype;
91 
92  typedef typename super::dense_matrix_type dense_matrix_type;
93  typedef typename super::dense_vector_type dense_vector_type;
94 
95  //eigen
96  typedef typename super::map_dense_matrix_type map_dense_matrix_type;
97  typedef typename super::map_dense_vector_type map_dense_vector_type;
98 
99  typedef DataMap datamap_type;
100  typedef boost::shared_ptr<datamap_type> datamap_ptrtype;
101 
103 
107 
111  SolverNonLinearPetsc(WorldComm const& worldComm=Environment::worldComm());
112  SolverNonLinearPetsc( SolverNonLinearPetsc const & );
113 
117  ~SolverNonLinearPetsc();
118 
122  virtual void init ();
123 
125 
129 
130 
132 
136 
138 
142  void setReuse( int jac=1, int prec=1 );
144 
148 
152  virtual void clear ();
153 
158  virtual std::pair<int, real_type> solve ( sparse_matrix_ptrtype&, // System Jacobian Matrix
159  vector_ptrtype&, // Solution vector
160  vector_ptrtype&, // Residual vector
161  const double, // Stopping tolerance
162  const unsigned int ); // N. Iterations
163 
164  virtual std::pair<unsigned int, real_type> solve ( dense_matrix_type&, // System Jacobian Matrix
165  dense_vector_type&, // Solution vector
166  dense_vector_type&, // Residual vector
167  const double, // Stopping tolerance
168  const unsigned int ); // N. Iterations
169 
170  //use eigen
171  virtual std::pair<unsigned int, real_type> solve ( map_dense_matrix_type&, // System Jacobian Matrix
172  map_dense_vector_type&, // Solution vector
173  map_dense_vector_type&, // Residual vector
174  const double, // Stopping tolerance
175  const unsigned int ); // N. Iterations
176 
177 
178 
180  datamap_type const& mapRow() const
181  {
182  return *M_mapRow;
183  }
184  datamap_type const& mapCol() const
185  {
186  return *M_mapCol;
187  }
188  datamap_ptrtype const& mapRowPtr() const
189  {
190  return M_mapRow;
191  }
192  datamap_ptrtype const& mapColPtr() const
193  {
194  return M_mapCol;
195  }
196 
197  void setMapRow( datamap_ptrtype const& d )
198  {
199  M_mapRow=d;
200  }
201  void setMapCol( datamap_ptrtype const& d )
202  {
203  M_mapCol=d;
204  }
205 
206 private:
211  void setPetscNlSolverType ();
212 
217  void setPetscKspSolverType ();
218 
223  void setPetscPreconditionerType ();
224 
225 
229  SNES M_snes;
230 
231  uint16_type M_prec_mat_structure;
232 
236  PC M_pc;
237 
241  KSP M_ksp;
242 
243 
244  datamap_ptrtype M_mapRow,M_mapCol;
245 
246 };
247 
248 template <typename T>
249 inline
250 SolverNonLinearPetsc<T>::SolverNonLinearPetsc(WorldComm const& worldComm)
251 :
252  super(worldComm),
253  M_mapRow(new datamap_type(worldComm)),
254  M_mapCol(new datamap_type(worldComm))
255 {}
256 
257 
258 
259 template <typename T>
260 inline
261 SolverNonLinearPetsc<T>::~SolverNonLinearPetsc ()
262 {
263  this->clear ();
264 }
265 
266 } // Feel
267 
268 #endif /* FEELPP_HAS_PETSC */
269 #endif /* __SolverNonLinearPetsc_H */

Generated on Sun Dec 22 2013 13:11:13 for Feel++ by doxygen 1.8.5