PetscSolverGlobalMatrix.h 3.83 KB
Newer Older
Thomas Witkowski's avatar
Thomas Witkowski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// 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.



/** \file PetscSolverGlobalMatrix.h */

#ifndef AMDIS_PETSC_SOLVER_GLOBAL_MATRIX_H
#define AMDIS_PETSC_SOLVER_GLOBAL_MATRIX_H

26
#include <boost/tuple/tuple.hpp>
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include "AMDiS_fwd.h"
28
#include "parallel/MatrixNnzStructure.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
29
30
31
32
33
34
#include "parallel/PetscSolver.h"

namespace AMDiS {

  using namespace std;

35

Thomas Witkowski's avatar
Thomas Witkowski committed
36
37
38
39
40
  class PetscSolverGlobalMatrix : public PetscSolver
  {
  public:
    PetscSolverGlobalMatrix()
      : PetscSolver(),
Thomas Witkowski's avatar
Thomas Witkowski committed
41
	petscSolVec(PETSC_NULL),
Thomas Witkowski's avatar
Thomas Witkowski committed
42
	lastMeshNnz(0),
43
	zeroStartVector(false),
44
	alwaysCreateNnzStructure(false)
Thomas Witkowski's avatar
Thomas Witkowski committed
45
    {
46
      Parameters::get("parallel->use zero start vector", zeroStartVector);
47
48
      Parameters::get("parallel->always create nnz structure", 
		      alwaysCreateNnzStructure);
Thomas Witkowski's avatar
Thomas Witkowski committed
49
50
    }

51
52
    void fillPetscMatrix(Matrix<DOFMatrix*> *mat);

53
54
55
56
    /// This function is just a small wrapper that creates a 1x1 matrix that
    /// contains exactly one DOFMatrix and than calls \ref fillPetscMatrix
    void fillPetscMatrix(DOFMatrix *mat);

57
58
    void fillPetscMatrixWithCoarseSpace(Matrix<DOFMatrix*> *mat);

59
    void fillPetscRhs(SystemVector *vec);
Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
62

    void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);    

63
64
    void solveGlobal(Vec &rhs, Vec &sol);

65
    void destroyMatrixData();
66

67
68
    void destroyVectorData();

69
  protected:
70
71
    bool checkMeshChange(Matrix<DOFMatrix*> *mat, bool localMatrix = false);

72
73
    void createFieldSplit(PC pc);

74
75
76
77
    virtual void initPreconditioner(PC pc);

    virtual void exitPreconditioner(PC pc);

Thomas Witkowski's avatar
Thomas Witkowski committed
78
    /// Takes a DOF matrix and sends the values to the global PETSc matrix.
79
    void setDofMatrix(DOFMatrix* mat, int nRowMat = 0, int nColMat = 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
80
81

    /// Takes a DOF vector and sends its values to a given PETSc vector.
Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
84
    void setDofVector(Vec vecInterior,
		      Vec vecCoarse,
		      DOFVector<double>* vec, 
85
		      int nRowVec, bool rankOnly = false);
Thomas Witkowski's avatar
Thomas Witkowski committed
86

87
88
89
90
    void removeDirichletBcDofs(Matrix<DOFMatrix*> *mat);

    void removeDirichletBcDofs(SystemVector *vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
93
94
95
96
97
98
    inline void setDofVector(Vec vecInterior,
			     DOFVector<double>* vec, 
			     int nRowVec, bool rankOnly = false)
    {
      setDofVector(vecInterior, PETSC_NULL, vec, nRowVec, rankOnly);
    }


Thomas Witkowski's avatar
Thomas Witkowski committed
99
  protected:
100
    MatrixNnzStructure nnzInterior, nnzCoarse;
101

102
    MatrixNnzStructure nnzIntCoarse, nnzCoarseInt;
Thomas Witkowski's avatar
Thomas Witkowski committed
103

104
105
    Vec petscSolVec;

106
107
108
109
    /// Stores the mesh change index of the mesh the nnz structure was created for.
    /// Therefore, if the mesh change index is higher than this value, we have to create
    /// a new nnz structure for PETSc matrices, because the mesh has been changed and
    /// therefore also the assembled matrix structure.
Thomas Witkowski's avatar
Thomas Witkowski committed
110
111
112
    int lastMeshNnz;

    bool zeroStartVector;
113
114
115
116
117
118
119
120

    /// If this variable is set to true, the non-zero matrix structure is
    /// created each time from scratch by calling \ref createPetscNnzStrcuture.
    /// This can be necessary if the number of non-zeros in the matrix varies
    /// though the mesh does not change. This may happen if there are many
    /// operators using DOFVectors from old timestep containing many zeros due to
    /// some phase fields.
    bool alwaysCreateNnzStructure;
Thomas Witkowski's avatar
Thomas Witkowski committed
121
122
123
124
125
126
127
  };


}

#endif