PetscSolver.h 4.46 KB
 Thomas Witkowski committed Feb 09, 2010 1 2 3 4 // ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == ==  Thomas Witkowski committed Dec 16, 2010 5 // == http://www.amdis-fem.org ==  Thomas Witkowski committed Feb 09, 2010 6 7 // == == // ============================================================================  Thomas Witkowski committed Dec 16, 2010 8 9 10 11 12 13 14 15 16 17 18 19 // // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution.  Thomas Witkowski committed Feb 09, 2010 20   Thomas Witkowski committed Aug 09, 2010 21 /** \file PetscSolver.h */  Thomas Witkowski committed Feb 09, 2010 22   Thomas Witkowski committed Mar 18, 2011 23 24 #ifndef AMDIS_PETSC_SOLVER_H #define AMDIS_PETSC_SOLVER_H  Thomas Witkowski committed Feb 09, 2010 25   Thomas Witkowski committed Apr 05, 2011 26 27 28 29 #include #include #include  Thomas Witkowski committed Mar 31, 2011 30 31 #include "AMDiS_fwd.h" #include "Global.h"  Praetorius, Simon committed Jun 03, 2011 32 #include "Initfile.h"  Thomas Witkowski committed Mar 31, 2011 33 34 #include "DOFMatrix.h" #include "parallel/MeshDistributor.h"  Thomas Witkowski committed Aug 20, 2012 35 #include "parallel/ParallelCoarseSpaceMatVec.h"  Thomas Witkowski committed Apr 05, 2011 36 37 38 #include #include #include  Backofen, Rainer committed May 31, 2011 39 #include  Thomas Witkowski committed Feb 09, 2010 40 41 42  namespace AMDiS {  Thomas Witkowski committed Mar 18, 2011 43 44  using namespace std;  45 46 47 48 49 50  /** * Create an abstract interface to an arbitrary PETSc solver. This class is * based on \ref ParallelCoarseSpaceMatVec to support for solvers which make * use of a coarse grid problem. */ class PetscSolver : public ParallelCoarseSpaceMatVec  Thomas Witkowski committed Mar 18, 2011 51  {  Thomas Witkowski committed Mar 31, 2011 52  public:  Thomas Witkowski committed Feb 13, 2012 53  PetscSolver();  Thomas Witkowski committed Feb 09, 2010 54   Thomas Witkowski committed Mar 18, 2011 55  virtual ~PetscSolver() {}  Thomas Witkowski committed Feb 09, 2010 56   Thomas Witkowski committed Mar 31, 2011 57  /** \brief  Thomas Witkowski committed Nov 11, 2011 58 59  * Create a PETSc matrix. The given DOF matrices are used to create the nnz * structure of the PETSc matrix and the values are transfered to it.  Thomas Witkowski committed Mar 31, 2011 60 61  * * \param[in] mat  Thomas Witkowski committed Nov 11, 2011 62 63 64 65 66 67  */ virtual void fillPetscMatrix(Matrix *mat) = 0; /** \brief * Create a PETSc vector and fills it with the rhs values of the system. *  Thomas Witkowski committed Mar 31, 2011 68 69  * \param[in] vec */  Thomas Witkowski committed Nov 11, 2011 70  virtual void fillPetscRhs(SystemVector *vec) = 0;  Thomas Witkowski committed Mar 18, 2011 71   Thomas Witkowski committed Mar 31, 2011 72 73  /// Use PETSc to solve the linear system of equations virtual void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo) = 0;  Thomas Witkowski committed Mar 17, 2011 74   Thomas Witkowski committed May 15, 2012 75 76 77 78  virtual void solve(Vec &rhs, Vec &sol); virtual void solveGlobal(Vec &rhs, Vec &sol);  Thomas Witkowski committed Nov 11, 2011 79 80 81  /// Destroys all matrix data structures. virtual void destroyMatrixData() = 0;  Thomas Witkowski committed Apr 12, 2012 82 83 84  /// Detroys all vector data structures. virtual void destroyVectorData() = 0;  Thomas Witkowski committed Apr 08, 2011 85 86 87 88 89  virtual Flag getBoundaryDofRequirement() { return 0; }  Thomas Witkowski committed Feb 06, 2012 90 91  KSP getSolver() {  Thomas Witkowski committed May 15, 2012 92  return kspInterior;  Thomas Witkowski committed Feb 06, 2012 93  }  Praetorius, Simon committed Jan 16, 2012 94   Thomas Witkowski committed Feb 06, 2012 95 96  PC getPc() {  Thomas Witkowski committed May 15, 2012 97  return pcInterior;  Thomas Witkowski committed Feb 06, 2012 98  }  Praetorius, Simon committed Jan 16, 2012 99   Thomas Witkowski committed Feb 13, 2012 100 101 102 103 104  void setKspPrefix(std::string s) { kspPrefix = s; }  Thomas Witkowski committed Jun 12, 2012 105  void setRemoveRhsNullspace(bool b)  Thomas Witkowski committed Mar 14, 2012 106  {  Thomas Witkowski committed Jun 12, 2012 107  removeRhsNullspace = b;  Thomas Witkowski committed Mar 14, 2012 108 109  }  Thomas Witkowski committed Jun 07, 2012 110 111 112 113 114 115  /// Adds a new vector to the basis of the operator's nullspace. void addNullspaceVector(SystemVector *vec) { nullspace.push_back(vec); }  Thomas Witkowski committed Jul 31, 2012 116 117 118 119 120 121 122 123 124 125 126 127 128  /// Sets the nullspace to be constant for some specific components. void setConstantNullspace(vector &components) { constNullspaceComponent = components; } /// Sets the nullspace to be constant for a specific component. void setConstantNullspace(int component) { constNullspaceComponent.clear(); constNullspaceComponent.push_back(component); }  Thomas Witkowski committed May 15, 2012 129  protected:  Thomas Witkowski committed Jan 03, 2012 130 131 132 133 134 135 136 137 138 139 140 141 142 143  /** \brief * Copies between to PETSc vectors by using different index sets for the * origin and the destination vectors. * * \param[in] originVec The PETSc vector from which we copy from. * \param[out] destVec The PETSc vector we copy too. * \param[in] originIndex Set of global indices referring to the * origin vector. * \param[in] destIndex Set of global indices referring to the * destination vector. */ void copyVec(Vec& originVec, Vec& destVec, vector& originIndex, vector& destIndex);  Thomas Witkowski committed Feb 09, 2010 144  protected:  Thomas Witkowski committed Feb 13, 2012 145  /// PETSc solver object  Thomas Witkowski committed May 15, 2012 146  KSP kspInterior;  147   Thomas Witkowski committed Feb 13, 2012 148  /// PETSc preconditioner object  Thomas Witkowski committed May 15, 2012 149  PC pcInterior;  Thomas Witkowski committed Feb 13, 2012 150   Thomas Witkowski committed Jun 07, 2012 151 152 153  /// A set of vectors that span the null space of the operator. vector nullspace;  Thomas Witkowski committed Feb 13, 2012 154 155  /// KSP database prefix string kspPrefix;  Thomas Witkowski committed Mar 14, 2012 156 157 158  /// If true, the constant null space is projected out of the RHS vector. It /// depends on the specific PETSc solver if it considers this value.  Thomas Witkowski committed Jun 12, 2012 159 160 161  bool removeRhsNullspace; bool hasConstantNullspace;  Thomas Witkowski committed Jun 22, 2012 162 163  vector constNullspaceComponent;  Thomas Witkowski committed Feb 09, 2010 164 165  };  166   Thomas Witkowski committed Mar 18, 2011 167 } // namespace AMDiS  Thomas Witkowski committed Feb 09, 2010 168 169  #endif