PetscSolver.h 2.55 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
32
33
34
35
#include "AMDiS_fwd.h"
#include "Global.h"
#include "Parameters.h"
#include "DOFMatrix.h"
#include "parallel/MeshDistributor.h"

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

namespace AMDiS {

42
43
  using namespace std;

44

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

53
    virtual ~PetscSolver() {}
54

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

61
62
63
64
65
66
67
68
69
    /** \brief
     * Create a PETSc matrix and PETSc vectors. The given DOF matrices are used to
     * create the nnz structure of the PETSc matrix and the values are transfered to it.
     * The given DOF vectors are used to the the values of the PETSc rhs vector.
     *
     * \param[in] mat
     * \param[in] vec
     */
    virtual void fillPetscMatrix(Matrix<DOFMatrix*> *mat, SystemVector *vec) = 0;
70

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

Thomas Witkowski's avatar
Thomas Witkowski committed
74
75
76
77
78
    virtual Flag getBoundaryDofRequirement()
    {
      return 0;
    }

79
80
81
82
83
  protected:
    void printSolutionInfo(AdaptInfo* adaptInfo,
			   bool iterationCounter = true,
			   bool residual = true);

84
  protected:
85
    MeshDistributor *meshDistributor;
86
87
    
    int mpiRank;
88
89
90
91
92
93
94
95
96
97
98
99
100

    /// 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;
101
102
  };

103

104
} // namespace AMDiS
105
106

#endif