PetscSolver.h 2.7 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
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.


20

Thomas Witkowski's avatar
Thomas Witkowski committed
21
/** \file PetscSolver.h */
22

23
24
#ifndef AMDIS_PETSC_SOLVER_H
#define AMDIS_PETSC_SOLVER_H
25

26
27
28
29
#include <set>
#include <map>
#include <mpi.h>

30
31
#include "AMDiS_fwd.h"
#include "Global.h"
32
#include "Initfile.h"
33
34
35
#include "DOFMatrix.h"
#include "parallel/MeshDistributor.h"

36
37
38
#include <petsc.h>
#include <petscsys.h>
#include <petscao.h>
39
#include <petscksp.h>
40
41
42

namespace AMDiS {

43
44
  using namespace std;

45

46
47
  class PetscSolver
  {
48
  public:
49
    PetscSolver()
50
51
      : meshDistributor(NULL),
	mpiRank(-1)
52
53
    {}

54
    virtual ~PetscSolver() {}
55

56
57
58
    void setMeshDistributor(MeshDistributor *m)
    {
      meshDistributor = m;
59
      mpiRank = meshDistributor->getMpiRank();
60
61
    }

62
    /** \brief
63
64
     * 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.
65
66
     *
     * \param[in] mat
67
68
69
70
71
72
     */
    virtual void fillPetscMatrix(Matrix<DOFMatrix*> *mat) = 0;

    /** \brief
     * Create a PETSc vector and fills it with the rhs values of the system.
     *
73
74
     * \param[in] vec
     */
75
    virtual void fillPetscRhs(SystemVector *vec) = 0;
76

77
78
    /// Use PETSc to solve the linear system of equations
    virtual void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo) = 0;
79

80
81
82
    /// Destroys all matrix data structures.
    virtual void destroyMatrixData() = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
83
84
85
86
87
    virtual Flag getBoundaryDofRequirement()
    {
      return 0;
    }

88
89
90
91
92
  protected:
    void printSolutionInfo(AdaptInfo* adaptInfo,
			   bool iterationCounter = true,
			   bool residual = true);

93
  protected:
94
    MeshDistributor *meshDistributor;
95
96
    
    int mpiRank;
97
98
99
100
101
102
103
104
105
106
107
108
109

    /// Petsc's matrix structure.
    Mat petscMatrix;

    /** \brief
     * PETSc's vector structures for the rhs vector, the solution vector and a
     * temporary vector for calculating the final residuum.
     */
    Vec petscRhsVec, petscSolVec, petscTmpVec;

    KSP solver;

    PC pc;
110
111
  };

112

113
} // namespace AMDiS
114
115

#endif