Commit b26c7ec3 authored by Thomas Witkowski's avatar Thomas Witkowski

PetscSolverGlobalMatrix works now for multiple rhs.

parent e73db218
......@@ -94,6 +94,20 @@ namespace AMDiS {
MatAssemblyBegin(petscMatrix, MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(petscMatrix, MAT_FINAL_ASSEMBLY);
// === Init PETSc solver. ===
KSPCreate(PETSC_COMM_WORLD, &solver);
KSPGetPC(solver, &pc);
KSPSetOperators(solver, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
KSPSetTolerances(solver, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
KSPSetType(solver, KSPBCGS);
KSPMonitorSet(solver, myKSPMonitor, PETSC_NULL, 0);
KSPSetFromOptions(solver);
PCSetFromOptions(pc);
// Do not delete the solution vector, use it for the initial guess.
if (!zeroStartVector)
KSPSetInitialGuessNonzero(solver, PETSC_TRUE);
MSG("Fill petsc matrix needed %.5f seconds\n", MPI::Wtime() - wtime);
}
......@@ -138,20 +152,6 @@ namespace AMDiS {
VecAssemblyEnd(petscSolVec);
}
// === Init PETSc solver. ===
KSPCreate(PETSC_COMM_WORLD, &solver);
KSPGetPC(solver, &pc);
KSPSetOperators(solver, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
KSPSetTolerances(solver, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
KSPSetType(solver, KSPBCGS);
KSPMonitorSet(solver, myKSPMonitor, PETSC_NULL, 0);
KSPSetFromOptions(solver);
PCSetFromOptions(pc);
// Do not delete the solution vector, use it for the initial guess.
if (!zeroStartVector)
KSPSetInitialGuessNonzero(solver, PETSC_TRUE);
// PETSc.
KSPSolve(solver, petscRhsVec, petscSolVec);
......@@ -182,17 +182,27 @@ namespace AMDiS {
// === Destroy PETSc's variables. ===
#ifdef HAVE_PETSC_DEV
MatDestroy(&petscMatrix);
VecDestroy(&petscRhsVec);
#else
VecDestroy(petscRhsVec);
#endif
}
void PetscSolverGlobalMatrix::destroyMatrixData()
{
FUNCNAME("PetscSolverGlobalMatrix::destroyMatrixData()");
#ifdef HAVE_PETSC_DEV
MatDestroy(&petscMatrix);
KSPDestroy(&solver);
VecDestroy(&petscSolVec);
VecDestroy(&petscTmpVec);
KSPDestroy(&solver);
#else
MatDestroy(petscMatrix);
VecDestroy(petscRhsVec);
KSPDestroy(solver);
VecDestroy(petscSolVec);
VecDestroy(petscTmpVec);
KSPDestroy(solver);
#endif
}
......
......@@ -50,8 +50,7 @@ namespace AMDiS {
void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);
void destroyMatrixData()
{}
void destroyMatrixData();
protected:
/// Creates a new non zero pattern structure for the PETSc matrix.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment