Skip to content
Snippets Groups Projects
Commit 5b20dc34 authored by Van Dung Nguyen's avatar Van Dung Nguyen
Browse files

add create matrix function

parent a93a5168
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ class linearSystemBase { ...@@ -26,6 +26,7 @@ class linearSystemBase {
void setParameter (std::string key, std::string value); void setParameter (std::string key, std::string value);
virtual void insertInSparsityPattern(int _row, int _col){}; virtual void insertInSparsityPattern(int _row, int _col){};
virtual double normInfRightHandSide() const = 0; virtual double normInfRightHandSide() const = 0;
virtual void createMatrix() {};
}; };
template <class scalar> template <class scalar>
......
...@@ -79,6 +79,7 @@ class linearSystemPETSc : public linearSystem<scalar> { ...@@ -79,6 +79,7 @@ class linearSystemPETSc : public linearSystem<scalar> {
std::vector<scalar> getData(); std::vector<scalar> getData();
std::vector<int> getRowPointers(); std::vector<int> getRowPointers();
std::vector<int> getColumnsIndices(); std::vector<int> getColumnsIndices();
virtual void createMatrix();
}; };
class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > { class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > {
......
...@@ -131,6 +131,29 @@ void linearSystemPETSc<scalar>::allocate(int nbRows) ...@@ -131,6 +131,29 @@ void linearSystemPETSc<scalar>::allocate(int nbRows)
_entriesPreAllocated = false; _entriesPreAllocated = false;
} }
template<class scalar>
void linearSystemPETSc<scalar>::createMatrix(){
if (isAllocated())
#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
_try(MatDestroy(&_a));
#else
_try(MatDestroy(_a));
#endif
_try(MatCreate(_comm, &_a));
_try(MatSetSizes(_a, _localSize, _localSize, _globalSize, _globalSize));
// override the default options with the ones from the option
// database (if any)
if (this->_parameters.count("petscOptions"))
_try(PetscOptionsInsertString(this->_parameters["petscOptions"].c_str()));
if (this->_parameters.count("petscPrefix"))
_try(MatAppendOptionsPrefix(_a, this->_parameters["petscPrefix"].c_str()));
_try(MatSetFromOptions(_a));
_entriesPreAllocated = false;
_matrixModified = true;
_isAllocated = true;
};
template <class scalar> template <class scalar>
void linearSystemPETSc<scalar>::print() void linearSystemPETSc<scalar>::print()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment