// ============================================================================ // == == // == 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_PETSCSOLVER_H #define AMDIS_PETSCSOLVER_H #include "AMDiS_fwd.h" #include "Global.h" #include "MeshDistributor.h" #include "ProblemVec.h" #include "ProblemInstat.h" #include "ParallelProblemStatBase.h" #include "petsc.h" #include "petscsys.h" #include "petscao.h" namespace AMDiS { class PetscSolver : public ParallelProblemStatBase { public: PetscSolver(std::string nameStr, ProblemIterationInterface *problemIteration = NULL) : ParallelProblemStatBase(nameStr, problemIteration), d_nnz(NULL), o_nnz(NULL), lastMeshNnz(0) {} ~PetscSolver() {} void solve(AdaptInfo *adaptInfo, bool fixedMatrix = false); protected: /// Creates a new non zero pattern structure for the Petsc matrix. void createPetscNnzStructure(Matrix<DOFMatrix*> *mat); /** \brief * Create a PETSc matrix and PETSc vectors. The given DOF matrices are used to * create the nnz structure of the PETSc matrix and the values are transfered to it. * The given DOF vectors are used to the the values of the PETSc rhs vector. * * \param[in] mat * \param[in] vec */ void fillPetscMatrix(Matrix<DOFMatrix*> *mat, SystemVector *vec); /// Takes a dof matrix and sends the values to the global petsc matrix. void setDofMatrix(DOFMatrix* mat, int dispMult = 1, int dispAddRow = 0, int dispAddCol = 0); /// Takes a dof vector and sends its values to a given petsc vector. void setDofVector(Vec& petscVec, DOFVector<double>* vec, int disMult = 1, int dispAdd = 0); void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo); protected: /// 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; /// Arrays definig the non zero pattern of Petsc's matrix. int *d_nnz, *o_nnz; /** \brief * Stores the mesh change index of the mesh the nnz structure was created for. * Therefore, if the mesh change index is higher than this value, we have to create * a new nnz structure for PETSc matrices, because the mesh has been changed and * therefore also the assembled matrix structure. */ int lastMeshNnz; }; typedef PetscSolver ParallelProblemStat; } //namespace AMDiS #endif