PetscSolverGlobalMatrix.h 4.39 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
36
37
38
  /** 
   * PETSc solver which creates a globally distributed matrix. Supports also
   * coarse space assembling.
   */
Thomas Witkowski's avatar
Thomas Witkowski committed
39
40
41
  class PetscSolverGlobalMatrix : public PetscSolver
  {
  public:
42
43
44
45
46
47
48
49
50
51
52
53
54
    /// Creator class
    class Creator : public OEMSolverCreator
    {
    public:
      virtual ~Creator() {}

      /// Returns a new PetscSolver object.
      OEMSolver* create() 
      { 
	return new PetscSolverGlobalMatrix(this->name); 
      }
    };
    
55
    PetscSolverGlobalMatrix(string name);
Thomas Witkowski's avatar
Thomas Witkowski committed
56

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

59
60
    void fillPetscMatrixWithCoarseSpace(Matrix<DOFMatrix*> *mat);

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

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

65
66
    void solveGlobal(Vec &rhs, Vec &sol);

67
    void destroyMatrixData();
68

69
70
    void destroyVectorData();

71
  protected:
72
    void removeDirichletRows(Matrix<DOFMatrix*> *seqMat);
73

74
    void removeDirichletRows(SystemVector *seqVec);
75

76
77
    /// Reads field split information and creats a splitting based on 
    /// component numbers.
78
79
    void createFieldSplit(PC pc);

80
81
82
83
84
85
86
87
88
89
90
    /** \brief 
     * Creates a new field split for a preconditioner object.
     *
     * \param[in] pc          PETSc preconditioner object, must be of
     *                        type PCFIELDSPLIT
     * \param[in] splitName   Name of the field split, can be used to set other
     *                        parameters of the PCFIELDSPLIT preconditioner on
     *                        the command line.
     * \param[in] components  System component numbers of the field split. At
     *                        the moment only continuous splits are allowed.
     */
91
    void createFieldSplit(PC pc, const char* splitName, vector<int> &components);
92

93
    /// Wrapper to create field split from only one component.
94
    void createFieldSplit(PC pc, const char* splitName, int component)
95
96
97
98
99
100
    {
      vector<int> components;
      components.push_back(component);
      createFieldSplit(pc, splitName, components);
    }

101
    virtual void initSolver(KSP &ksp);
102
103
104

    virtual void exitSolver(KSP ksp);

105
106
107
108
    virtual void initPreconditioner(PC pc);

    virtual void exitPreconditioner(PC pc);

Thomas Witkowski's avatar
Thomas Witkowski committed
109
    /// Takes a DOF matrix and sends the values to the global PETSc matrix.
Thomas Witkowski's avatar
Thomas Witkowski committed
110
    void setDofMatrix(DOFMatrix* mat, int rowComp = 0, int colComp = 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
111
112

    /// Takes a DOF vector and sends its values to a given PETSc vector.
Thomas Witkowski's avatar
Thomas Witkowski committed
113
114
115
    void setDofVector(Vec vecInterior,
		      Vec vecCoarse,
		      DOFVector<double>* vec, 
Thomas Witkowski's avatar
Thomas Witkowski committed
116
117
		      int rowCompxo, 
		      bool rankOnly = false);
Thomas Witkowski's avatar
Thomas Witkowski committed
118

Thomas Witkowski's avatar
Thomas Witkowski committed
119
120
    inline void setDofVector(Vec vecInterior,
			     DOFVector<double>* vec, 
Thomas Witkowski's avatar
Thomas Witkowski committed
121
122
			     int rowComp, 
			     bool rankOnly = false)
Thomas Witkowski's avatar
Thomas Witkowski committed
123
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
124
      setDofVector(vecInterior, PETSC_NULL, vec, rowComp, rankOnly);
Thomas Witkowski's avatar
Thomas Witkowski committed
125
126
    }

127
128
129
130
131
132
133
134
135
    inline void setDofVector(Vec vecInterior, 
			     SystemVector &vec, 
			     bool rankOnly = false)
    {
      for (int i = 0; i < vec.getSize(); i++)
	setDofVector(vecInterior, PETSC_NULL, vec.getDOFVector(i), i, rankOnly);
    }

    PetscSolver* createSubSolver(int component, string kspPrefix);
Thomas Witkowski's avatar
Thomas Witkowski committed
136

137
138
    void setConstantNullSpace(KSP ksp, int constFeSpace, bool test = false);

Thomas Witkowski's avatar
blub  
Thomas Witkowski committed
139
140
    void setConstantNullSpace(KSP ksp);

Thomas Witkowski's avatar
Thomas Witkowski committed
141
142
  protected:
    bool zeroStartVector;
143

144
145
146
    /// If true, after parallel assembling, information about the matrix
    /// are printed.
    bool printMatInfo;
Thomas Witkowski's avatar
Thomas Witkowski committed
147
148
149
150
151
152
153
  };


}

#endif