PetscSolverGlobalMatrix.h 2.79 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(),
41
	zeroStartVector(false),
42
	printMatInfo(false)
Thomas Witkowski's avatar
Thomas Witkowski committed
43
    {
44
      Parameters::get("parallel->use zero start vector", zeroStartVector);
45
      Parameters::get("parallel->print matrix info", printMatInfo);
Thomas Witkowski's avatar
Thomas Witkowski committed
46
47
    }

48
49
    void fillPetscMatrix(Matrix<DOFMatrix*> *mat);

50
51
52
53
    /// 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);

54
55
    void fillPetscMatrixWithCoarseSpace(Matrix<DOFMatrix*> *mat);

56
    void fillPetscRhs(SystemVector *vec);
Thomas Witkowski's avatar
Thomas Witkowski committed
57
58
59

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

60
61
    void solveGlobal(Vec &rhs, Vec &sol);

62
    void destroyMatrixData();
63

64
65
    void destroyVectorData();

66
  protected:
67
68
    void createFieldSplit(PC pc);

69
70
71
72
    virtual void initPreconditioner(PC pc);

    virtual void exitPreconditioner(PC pc);

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
84
85
86
87
88
89
    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
90
91
  protected:
    bool zeroStartVector;
92

93
94
95
    /// If true, after parallel assembling, information about the matrix
    /// are printed.
    bool printMatInfo;
Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
98
99
100
101
102
  };


}

#endif