PetscSolverGlobalMatrix.h 4.82 KB
Newer Older
 Thomas Witkowski committed Apr 08, 2011 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  Thomas Witkowski committed Apr 08, 2011 27 28 29 30 31 32 33 #include "AMDiS_fwd.h" #include "parallel/PetscSolver.h" namespace AMDiS { using namespace std;  Thomas Witkowski committed Jan 25, 2012 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 73 74 75 76 77 78 79 80 81  /** \brief * Defines for each system component a mapping for sets of global DOF indices * to global matrix indices. The mapping is defined for all DOFs in rank's * subdomain. When periodic boundary conditions are used, then the mapping * stores also information for the periodic associations of rank's DOF on * periodic boundaries. */ class DofToMatIndex { public: DofToMatIndex() {} /// Reset the data structure. inline void clear() { data.clear(); } /// Add a new mapping. inline void add(int component, DegreeOfFreedom dof, int globalMatIndex) { data[component][dof] = globalMatIndex; } /// Map a global DOF index to the global matrix index for a specific /// system component number. inline int get(int component, DegreeOfFreedom dof) { FUNCNAME("DofToMatIndex::get()"); TEST_EXIT_DBG(data.count(component)) ("No mapping data for component %d available!\n", component); TEST_EXIT_DBG(data[component].count(dof)) ("Mapping for DOF %d in component %d does not exists!\n", dof, component); return data[component][dof]; } private: /// The mapping data. For each system component there is a specific map that /// maps global DOF indices to global matrix indices. map > data; };  Thomas Witkowski committed Apr 08, 2011 82 83 84 85 86 87 88 89  class PetscSolverGlobalMatrix : public PetscSolver { public: PetscSolverGlobalMatrix() : PetscSolver(), d_nnz(NULL), o_nnz(NULL), lastMeshNnz(0),  Thomas Witkowski committed Nov 29, 2011 90  zeroStartVector(false),  Thomas Witkowski committed Feb 20, 2012 91 92  alwaysCreateNnzStructure(false), removeRhsNullSpace(false)  Thomas Witkowski committed Apr 08, 2011 93  {  Thomas Witkowski committed Apr 18, 2011 94  Parameters::get("parallel->use zero start vector", zeroStartVector);  Thomas Witkowski committed Nov 29, 2011 95 96  Parameters::get("parallel->always create nnz structure", alwaysCreateNnzStructure);  Thomas Witkowski committed Feb 20, 2012 97 98  Parameters::get("parallel->remove rhs null space", removeRhsNullSpace);  Thomas Witkowski committed Apr 08, 2011 99 100  }  Thomas Witkowski committed Nov 11, 2011 101 102 103  void fillPetscMatrix(Matrix *mat); void fillPetscRhs(SystemVector *vec);  Thomas Witkowski committed Apr 08, 2011 104 105 106  void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);  Thomas Witkowski committed Nov 14, 2011 107  void destroyMatrixData();  Thomas Witkowski committed Nov 11, 2011 108   Thomas Witkowski committed Apr 08, 2011 109 110 111 112 113  protected: /// Creates a new non zero pattern structure for the PETSc matrix. void createPetscNnzStructure(Matrix *mat); /// Takes a DOF matrix and sends the values to the global PETSc matrix.  Thomas Witkowski committed Jan 31, 2012 114  void setDofMatrix(DOFMatrix* mat, int nRowMat = 0, int nColMat = 0);  Thomas Witkowski committed Apr 08, 2011 115 116 117  /// Takes a DOF vector and sends its values to a given PETSc vector. void setDofVector(Vec& petscVec, DOFVector* vec,  Thomas Witkowski committed Jan 31, 2012 118  int nRowVec, bool rankOnly = false);  Thomas Witkowski committed Apr 08, 2011 119   Thomas Witkowski committed Jan 18, 2012 120 121  void createGlobalDofMapping(vector &feSpaces);  Thomas Witkowski committed Apr 08, 2011 122 123 124 125 126 127 128 129 130 131 132 133 134  protected: /// 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; bool zeroStartVector;  Thomas Witkowski committed Nov 29, 2011 135 136 137 138 139 140 141 142  /// If this variable is set to true, the non-zero matrix structure is /// created each time from scratch by calling \ref createPetscNnzStrcuture. /// This can be necessary if the number of non-zeros in the matrix varies /// though the mesh does not change. This may happen if there are many /// operators using DOFVectors from old timestep containing many zeros due to /// some phase fields. bool alwaysCreateNnzStructure;  Thomas Witkowski committed Jan 18, 2012 143   Thomas Witkowski committed Jan 25, 2012 144 145 146  /// Mapping from global DOF indices to global matrix indices under /// consideration of possibly multiple components. DofToMatIndex dofToMatIndex;  Thomas Witkowski committed Feb 20, 2012 147 148 149  /// If true, the constant null space is projected out of the RHS vector. bool removeRhsNullSpace;  Thomas Witkowski committed Apr 08, 2011 150 151 152 153 154 155 156  }; } #endif