Commit a1f6ce9c authored by Thomas Witkowski's avatar Thomas Witkowski

Added some nice to have features for using PETSc solver.

parent aa1ec307
......@@ -38,14 +38,18 @@ namespace AMDiS {
}
void DofComm::Iterator::setNextFeMap()
bool DofComm::Iterator::setNextFeMap()
{
FUNCNAME("DofComm::Iterator::setNextFeMap()");
if (dataIter != dofComm.data.end()) {
TEST_EXIT_DBG(dataIter->second.size())("Should not happen!\n");
feMapIter = dataIter->second.begin();
if (traverseFeSpace != NULL) {
TEST_EXIT_DBG(dataIter->second.count(traverseFeSpace))
("Should not happen!\n");
if ((dataIter->second.count(traverseFeSpace) == 0))
return false;
while (feMapIter->first != traverseFeSpace &&
feMapIter != dataIter->second.end())
......@@ -56,11 +60,11 @@ namespace AMDiS {
("Should not happen!\n");
}
if (feMapIter != dataIter->second.end())
dofIter = feMapIter->second.begin();
dofIter = feMapIter->second.begin();
dofCounter = 0;
}
return true;
}
}
......@@ -77,7 +77,8 @@ namespace AMDiS {
dataIter = dofComm.data.begin();
setNextFeMap();
while (setNextFeMap() == false)
++dataIter;
}
inline bool end()
......@@ -87,9 +88,9 @@ namespace AMDiS {
inline void nextRank()
{
++dataIter;
setNextFeMap();
do {
++dataIter;
} while (setNextFeMap() == false);
}
inline void nextFeSpace()
......@@ -101,9 +102,9 @@ namespace AMDiS {
{
++feMapIter;
if (feMapIter == dataIter->second.end()) {
++dataIter;
setNextFeMap();
do {
++dataIter;
} while (setNextFeMap() == false);
} else {
dofIter = feMapIter->second.begin();
dofCounter = 0;
......@@ -122,15 +123,17 @@ namespace AMDiS {
++feMapIter;
}
TEST_EXIT_DBG(feMapIter != dataIter->second.end())
("Should not happen!\n");
dofIter = feMapIter->second.begin();
dofCounter = 0;
if (feMapIter != dataIter->second.end()) {
dofIter = feMapIter->second.begin();
dofCounter = 0;
}
}
inline bool endDofIter()
{
if (feMapIter == dataIter->second.end())
return true;
return (dofIter == feMapIter->second.end());
}
......@@ -171,7 +174,7 @@ namespace AMDiS {
}
protected:
void setNextFeMap();
bool setNextFeMap();
protected:
DofComm &dofComm;
......
......@@ -31,26 +31,30 @@ namespace AMDiS {
{
FUNCNAME("PetscProblemStat::PetscProblemStat()");
string name("");
Parameters::get("parallel->solver", name);
string tmp("");
Parameters::get("parallel->solver", tmp);
if (name == "petsc-schur") {
if (tmp == "petsc-schur") {
petscSolver = new PetscSolverSchur();
} else if (name == "petsc-feti") {
} else if (tmp == "petsc-feti") {
petscSolver = new PetscSolverFeti();
} else if (name == "petsc-block") {
} else if (tmp == "petsc-block") {
petscSolver = new PetscSolverGlobalBlockMatrix();
} else if (name == "petsc" || name == "") {
} else if (tmp == "petsc" || tmp == "") {
petscSolver = new PetscSolverGlobalMatrix();
} else if (name == "bddcml") {
} else if (tmp == "bddcml") {
#ifdef HAVE_BDDC_ML
petscSolver = new BddcMlSolver();
#else
ERROR_EXIT("AMDiS was compiled without BDDC-ML support!\n");
#endif
} else {
ERROR_EXIT("No parallel solver %s available!\n", name.c_str());
ERROR_EXIT("No parallel solver %s available!\n", tmp.c_str());
}
tmp = "";
Parameters::get(nameStr + "->solver->petsc prefix", tmp);
petscSolver->setKspPrefix(tmp);
}
......
......@@ -18,6 +18,18 @@ namespace AMDiS {
using namespace std;
PetscSolver::PetscSolver()
: meshDistributor(NULL),
mpiRank(-1),
kspPrefix("")
{
string kspStr = "";
Parameters::get("parallel->solver->petsc->ksp", kspStr);
if (kspStr != "")
PetscOptionsInsertString(kspStr.c_str());
}
void PetscSolver::printSolutionInfo(AdaptInfo *adaptInfo,
bool iterationCounter,
bool residual)
......
......@@ -46,10 +46,7 @@ namespace AMDiS {
class PetscSolver
{
public:
PetscSolver()
: meshDistributor(NULL),
mpiRank(-1)
{}
PetscSolver();
virtual ~PetscSolver() {}
......@@ -96,6 +93,11 @@ namespace AMDiS {
return pc;
}
void setKspPrefix(std::string s)
{
kspPrefix = s;
}
protected:
void printSolutionInfo(AdaptInfo* adaptInfo,
bool iterationCounter = true,
......@@ -135,15 +137,18 @@ namespace AMDiS {
/// 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.
*/
/// PETSc's vector structures for the rhs vector, the solution vector and a
/// temporary vector for calculating the final residuum.
Vec petscRhsVec, petscSolVec, petscTmpVec;
/// PETSc solver object
KSP solver;
/// PETSc preconditioner object
PC pc;
/// KSP database prefix
string kspPrefix;
};
......
......@@ -10,6 +10,7 @@
// See also license.opensource.txt in the distribution.
#include "AMDiS.h"
#include "parallel/PetscSolverGlobalMatrix.h"
#include "parallel/StdMpi.h"
#include "parallel/MpiHelper.h"
......@@ -113,6 +114,7 @@ namespace AMDiS {
KSPSetOperators(solver, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
KSPSetTolerances(solver, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
KSPSetType(solver, KSPBCGS);
KSPSetOptionsPrefix(solver, kspPrefix.c_str());
KSPSetFromOptions(solver);
PCSetFromOptions(pc);
......@@ -171,7 +173,11 @@ namespace AMDiS {
}
// PETSc.
KSPSolve(solver, petscRhsVec, petscSolVec);
PetscErrorCode solverError = KSPSolve(solver, petscRhsVec, petscSolVec);
if (solverError != 0) {
AMDiS::finalize();
exit(-1);
}
// === Transfere values from PETSc's solution vectors to the DOF vectors. ===
PetscScalar *vecPointer;
......
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