Commit 0a79fc7f authored by Thomas Witkowski's avatar Thomas Witkowski

Added some support for block preconditioners.

parent 842726b8
...@@ -92,11 +92,12 @@ namespace AMDiS { ...@@ -92,11 +92,12 @@ namespace AMDiS {
matAssembly(); matAssembly();
// === Init PETSc solver. ===
KSPCreate(mpiCommGlobal, &kspInterior); // === Init PETSc solver and preconditioner objects. ===
KSPSetOperators(kspInterior, getMatInterior(), getMatInterior(),
SAME_NONZERO_PATTERN); initSolver(kspInterior);
KSPSetFromOptions(kspInterior); KSPGetPC(kspInterior, &pcInterior);
initPreconditioner(pcInterior);
MSG("Fill petsc matrix needed %.5f seconds\n", MPI::Wtime() - wtime); MSG("Fill petsc matrix needed %.5f seconds\n", MPI::Wtime() - wtime);
} }
...@@ -131,14 +132,45 @@ namespace AMDiS { ...@@ -131,14 +132,45 @@ namespace AMDiS {
} }
void PetscSolverGlobalBlockMatrix::initSolver(KSP &ksp)
{
FUNCNAME("PetscSolverGlobalBlockMatrix::initSolver()");
KSPCreate(mpiCommGlobal, &ksp);
KSPSetOperators(ksp, getMatInterior(), getMatInterior(),
SAME_NONZERO_PATTERN);
KSPSetOptionsPrefix(ksp, kspPrefix.c_str());
KSPSetFromOptions(ksp);
}
void PetscSolverGlobalBlockMatrix::exitSolver(KSP ksp)
{
FUNCNAME("PetscSolverGlobalBlockMatrix::exitSolver()");
KSPDestroy(&ksp);
}
void PetscSolverGlobalBlockMatrix::initPreconditioner(PC pc)
{
FUNCNAME("PetscSolverGlobalBlockMatrix::initPreconditioner()");
PCSetFromOptions(pc);
}
void PetscSolverGlobalBlockMatrix::exitPreconditioner(PC pc)
{
FUNCNAME("PetscSolverGlobalBlockMatrix::exitPreconditioner()");
}
void PetscSolverGlobalBlockMatrix::solvePetscMatrix(SystemVector &vec, void PetscSolverGlobalBlockMatrix::solvePetscMatrix(SystemVector &vec,
AdaptInfo *adaptInfo) AdaptInfo *adaptInfo)
{ {
FUNCNAME("PetscSolverGlobalBlockMatrix::solvePetscMatrix()"); FUNCNAME("PetscSolverGlobalBlockMatrix::solvePetscMatrix()");
KSPGetPC(kspInterior, &pcInterior);
setBlockPreconditioner(pcInterior);
const FiniteElemSpace *feSpace = componentSpaces[0]; const FiniteElemSpace *feSpace = componentSpaces[0];
VecDuplicate(getVecRhsInterior(), &petscSolVec); VecDuplicate(getVecRhsInterior(), &petscSolVec);
...@@ -181,7 +213,9 @@ namespace AMDiS { ...@@ -181,7 +213,9 @@ namespace AMDiS {
matDestroy(); matDestroy();
KSPDestroy(&kspInterior); exitPreconditioner(pcInterior);
exitSolver(kspInterior);
} }
......
...@@ -58,12 +58,14 @@ namespace AMDiS { ...@@ -58,12 +58,14 @@ namespace AMDiS {
/// Takes a DOF vector and sends its values to a given PETSc vector. /// Takes a DOF vector and sends its values to a given PETSc vector.
void setDofVector(Vec& petscVec, DOFVector<double>* vec); void setDofVector(Vec& petscVec, DOFVector<double>* vec);
virtual void initSolver(KSP &ksp);
virtual void setBlockPreconditioner(PC &pc) virtual void exitSolver(KSP ksp);
{
PCSetFromOptions(pc);
}
virtual void initPreconditioner(PC pc);
virtual void exitPreconditioner(PC pc);
protected: protected:
vector<Mat> nestMat; vector<Mat> nestMat;
......
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