Skip to content
Snippets Groups Projects
PetscSolverGlobalBlockMatrix.h 2.18 KiB
// ============================================================================
// ==                                                                        ==
// == 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 PetscSolverGlobalBlockMatrix.h */

#ifndef AMDIS_PETSC_SOLVER_GLOBAL_BLOCK_MATRIX_H
#define AMDIS_PETSC_SOLVER_GLOBAL_BLOCK_MATRIX_H

#include "AMDiS_fwd.h"
#include "parallel/PetscSolver.h"

namespace AMDiS {

  using namespace std;


  class PetscSolverGlobalBlockMatrix : public PetscSolver
  {
  public:
    PetscSolverGlobalBlockMatrix()
      : PetscSolver(),
	nComponents(0),
	nBlocks(-1)
    {}

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

    void fillPetscRhs(SystemVector *vec);

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

    void destroyMatrixData();

  protected:
    /// Takes a DOF matrix and sends the values to the global PETSc matrix.
    void setDofMatrix(Mat& petscMat, DOFMatrix* mat,
		      int dispRowBlock, int dispColBlock);

    /// Takes a DOF vector and sends its values to a given PETSc vector.
    void setDofVector(Vec& petscVec, DOFVector<double>* vec);

    
    virtual void setBlockPreconditioner(PC &pc)
    {
      PCSetFromOptions(pc);    
    }

  protected:
    vector<Mat> nestMat;

    vector<Vec> nestVec;

    /// Number of components (= number of unknowns in the PDE)
    int nComponents;

    /// Number of blocks for the solver, must be 1 <= nBlocks <= nComponents
    int nBlocks;

    /// Maps to each component number the block number the component is in.
    map<int, int> componentInBlock;
  };


}

#endif