// ============================================================================ // == == // == 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 PetscSolver.h */ #ifndef AMDIS_PETSC_SOLVER_H #define AMDIS_PETSC_SOLVER_H #include #include #include #include "AMDiS_fwd.h" #include "Global.h" #include "Initfile.h" #include "DOFMatrix.h" #include "parallel/MeshDistributor.h" #include #include #include #include namespace AMDiS { using namespace std; class PetscSolver { public: PetscSolver() : meshDistributor(NULL), mpiRank(-1) {} virtual ~PetscSolver() {} void setMeshDistributor(MeshDistributor *m) { meshDistributor = m; mpiRank = meshDistributor->getMpiRank(); } /** \brief * Create a PETSc matrix. The given DOF matrices are used to create the nnz * structure of the PETSc matrix and the values are transfered to it. * * \param[in] mat */ virtual void fillPetscMatrix(Matrix *mat) = 0; /** \brief * Create a PETSc vector and fills it with the rhs values of the system. * * \param[in] vec */ virtual void fillPetscRhs(SystemVector *vec) = 0; /// Use PETSc to solve the linear system of equations virtual void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo) = 0; /// Destroys all matrix data structures. virtual void destroyMatrixData() = 0; virtual Flag getBoundaryDofRequirement() { return 0; } KSP getSolver() { return solver; } PC getPc() { return pc; } protected: void printSolutionInfo(AdaptInfo* adaptInfo, bool iterationCounter = true, bool residual = true); /** \brief * Copies between to PETSc vectors by using different index sets for the * origin and the destination vectors. * * \param[in] originVec The PETSc vector from which we copy from. * \param[out] destVec The PETSc vector we copy too. * \param[in] originIndex Set of global indices referring to the * origin vector. * \param[in] destIndex Set of global indices referring to the * destination vector. */ void copyVec(Vec& originVec, Vec& destVec, vector& originIndex, vector& destIndex); /// Checks if all given FE spaces are handled by the mesh distributor. void checkFeSpaces(vector& feSpaces); /// Returns a vector with the FE spaces of each row in the matrix. Thus, the /// resulting vector may contain the same FE space multiple times. vector getFeSpaces(Matrix *mat); /// Returns a vector with the FE spaces of all components of a system vector. vector getFeSpaces(SystemVector *vec); protected: MeshDistributor *meshDistributor; int mpiRank; /// Petsc's matrix structure. Mat petscMatrix; /** \brief * PETSc's vector structures for the rhs vector, the solution vector and a * temporary vector for calculating the final residuum. */ Vec petscRhsVec, petscSolVec, petscTmpVec; KSP solver; PC pc; }; } // namespace AMDiS #endif