PetscHelper.h 3.7 KB
Newer Older
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
26
27
28
29
// ============================================================================
// ==                                                                        ==
// == 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 PetscHelper.h */

#ifndef AMDIS_PETSCHELPER_H
#define AMDIS_PETSCHELPER_H

#include <mpi.h>
#include <map>
#include <vector>
#include <petsc.h>
30
#include "AMDiS_fwd.h"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

namespace AMDiS {

  using namespace std;

  /** \brief
   * In this namespace, we collect several auxiliary functions for using
   * PETSc in AMDiS. Many of these function may be replaced by new PETSc 
   * function in upcoming versions.
   */
  namespace petsc_helper {

    /// Defines a PETSc matrix column wise
    typedef pair<vector<int>, vector<double> > SparseCol;
    typedef map<int, SparseCol> PetscMatCol;

    /** \brief
     * Returns for a distributed matrix on each rank the local matrix in a
     * sparce column format.
     *
     * \param[in]   mat     PETSc distributerd matrix.
     * \param[out]  matCol  The sparse column represenation of the local matrix.
     */
    void getMatLocalColumn(Mat mat, PetscMatCol &matCol);

    /** \brief
     * Set a local column vector in a distributed matrix.
     *
     * \param[out]  mat     Distributed matrix.
     * \param[in]   column  Column index.
     * \param[in]   vec     Column vector.
     */
    void setMatLocalColumn(Mat mat, int column, Vec vec);

    /** \brief
     * Create a local PETSc vector representing the column of a matrix
     * stored in \ref PetscMatCol type format.
     *
     * \param[in]   column   Sparse column representation.
     * \param[out]  vec      Vector representing one column of the matrix.
     */
    void getColumnVec(const SparseCol &matCol, Vec vec);
73
74
75
76
77
78
79

    /** \brief
     * Computes the matrix matrix product inv(A) B = C. Matrices B and C
     * are distributed matrices. Matrix A is a local matrix on each MPI
     * task. The overall number of rows of local matrices A must be the
     * number of distriubted rows in B.
     *
80
81
82
83
     * \param[in]   mpiComm  MPI Communicator object (must fit with ksp)
     * \param[in]   ksp      inv(A) matrix given by a PETSc solver object.
     * \param[in]   mat0     matrix B
     * \param[out]  mat1     resulting matrix C, is created inside the function
84
     */
85
86
87
88
    void blockMatMatSolve(MPI::Intracomm mpiComm, 
			  KSP ksp, 
			  Mat mat0, 
			  Mat &mat1);
89
90
91
92
93
94
95
96

    /** \brief
     * Converts a 2x2 nested matrix to a MATAIJ matrix (thus not nested).
     *
     * \param[in]  matNest  nested input matrix
     * \param[out] mat      matrix of type MATAIJ, created inside this function.
     */
    void matNestConvert(Mat matNest, Mat &mat);
97

98
    void setSolverWithLu(KSP ksp, 
99
			 const char* kspPrefix,
100
101
			 KSPType kspType, 
			 PCType pcType, 
102
			 const MatSolverPackage matSolverPackage,
103
104
105
106
			 PetscReal rtol = PETSC_DEFAULT,
			 PetscReal atol = PETSC_DEFAULT,
			 PetscInt maxIt = PETSC_DEFAULT);

107
    void setSolver(KSP ksp, 
108
		   const char* kspPrefix,
109
110
111
112
113
		   KSPType kspType, 
		   PCType pcType, 
		   PetscReal rtol = PETSC_DEFAULT,
		   PetscReal atol = PETSC_DEFAULT,
		   PetscInt maxIt = PETSC_DEFAULT);
114
115
116
117
118
  }

}

#endif