Commit b0040535 authored by Praetorius, Simon's avatar Praetorius, Simon

Merge branch 'issue/petsc_3-7' into 'master'

Issue/petsc 3 7

Make AMDiS compatibale to PETSc version 3.7 (since there were some interface changes)

See merge request !12
parents 7aef2864 e92707e7
......@@ -327,7 +327,6 @@ namespace AMDiS
rtol, atol, maxIt);
}
void createSolver(MPI::Intracomm comm, KSP &ksp, Mat m, std::string kspPrefix, int info)
{
KSPCreate(comm, &ksp);
......@@ -341,9 +340,9 @@ namespace AMDiS
KSPSetOptionsPrefix(ksp, kspPrefix.c_str());
if (info >= 10)
KSPMonitorSet(ksp, KSPMonitorDefault, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorDefault), PETSC_NULL, PETSC_NULL);
else if (info >= 20)
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
}
} // end namespace petsc_helper
......
......@@ -31,6 +31,13 @@
#include <petsc.h>
#include "AMDiS_fwd.h"
#if (PETSC_VERSION_MINOR >= 7)
#define PETSC_MONITOR_CAST(...) \
(PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*))(__VA_ARGS__)
#else
#define PETSC_MONITOR_CAST(...) __VA_ARGS__
#endif
namespace AMDiS
{
namespace Parallel
......
......@@ -49,7 +49,7 @@ namespace AMDiS { namespace Parallel {
Parameters::get(name + "->ksp", kspStr);
if (kspStr != "")
PetscOptionsInsertString(kspStr.c_str());
petsc_options_insert_string(kspStr.c_str());
Parameters::get(name + "->remove rhs null space", removeRhsNullspace);
Parameters::get(name + "->has constant null space", hasConstantNullspace);
......
......@@ -33,6 +33,7 @@
#include "AMDiS_fwd.h"
#include "parallel/ParallelCoarseSpaceSolver.h"
#include "solver/PetscTypes.h"
namespace AMDiS
{
......
......@@ -91,9 +91,9 @@ namespace AMDiS { namespace Parallel {
KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN);
#endif
if (getInfo() >= 10)
KSPMonitorSet(ksp, KSPMonitorDefault, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorDefault), PETSC_NULL, PETSC_NULL);
else if (getInfo() >= 20)
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
petsc_helper::setSolver(ksp, "ch_", KSPFGMRES, PCNONE, getRelative(), getTolerance(), getMaxIterations());
KSPSetFromOptions(ksp);
......
......@@ -123,9 +123,9 @@ namespace AMDiS { namespace Parallel {
KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN);
#endif
if (getInfo() >= 10)
KSPMonitorSet(ksp, KSPMonitorDefault, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorDefault), PETSC_NULL, PETSC_NULL);
else if (getInfo() >= 20)
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
petsc_helper::setSolver(ksp, "ch_", KSPFGMRES, PCNONE, getRelative(), getTolerance(), getMaxIterations());
if (useOldInitialGuess)
......
......@@ -1382,9 +1382,9 @@ namespace AMDiS { namespace Parallel {
Parameters::get(name + "->feti->monitor", monitor);
if (monitor) {
if (stokesMode)
KSPMonitorSet(ksp_feti, KSPMonitorFetiStokes, &fetiKspData, PETSC_NULL);
KSPMonitorSet(ksp_feti, PETSC_MONITOR_CAST(KSPMonitorFetiStokes), &fetiKspData, PETSC_NULL);
else
KSPMonitorSet(ksp_feti, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp_feti, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
}
......
......@@ -50,15 +50,15 @@ namespace AMDiS { namespace Parallel {
if (params.matSolverPackage.find(kspSolver) != params.matSolverPackage.end()) {
// direct solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type preonly").c_str());
PetscOptionsInsertString(("-" + kspPrefix + "pc_type lu").c_str());
PetscOptionsInsertString(("-" + kspPrefix + "pc_factor_mat_solver_package " + kspSolver).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_type preonly").c_str());
petsc_options_insert_string(("-" + kspPrefix + "pc_type lu").c_str());
petsc_options_insert_string(("-" + kspPrefix + "pc_factor_mat_solver_package " + kspSolver).c_str());
setMaxIterations(1);
zeroStartVector = true;
matSolverPackage = true;
} else if (params.emptyParam.find(kspSolver) == params.emptyParam.end() && solverName != "petsc") {
// other solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type " + kspSolver).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_type " + kspSolver).c_str());
}
// set the preconditioner
......@@ -70,17 +70,17 @@ namespace AMDiS { namespace Parallel {
Parameters::get(name + "->right precon", precon);
if (!matSolverPackage && params.emptyParam.find(precon) == params.emptyParam.end()) {
precon = (params.preconMap.find(precon) != params.preconMap.end() ? params.preconMap[precon] : precon);
PetscOptionsInsertString(("-" + kspPrefix + "pc_type " + precon).c_str());
petsc_options_insert_string(("-" + kspPrefix + "pc_type " + precon).c_str());
}
PetscOptionsInsertString(("-" + kspPrefix + "ksp_max_it " + boost::lexical_cast<std::string>(getMaxIterations())).c_str());
PetscOptionsInsertString(("-" + kspPrefix + "ksp_rtol " + boost::lexical_cast<std::string>(getRelative())).c_str());
PetscOptionsInsertString(("-" + kspPrefix + "ksp_atol " + boost::lexical_cast<std::string>(getTolerance())).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_max_it " + boost::lexical_cast<std::string>(getMaxIterations())).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_rtol " + boost::lexical_cast<std::string>(getRelative())).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_atol " + boost::lexical_cast<std::string>(getTolerance())).c_str());
if (getInfo() >= 20)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor_true_residual").c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_monitor_true_residual").c_str());
else if (getInfo() >= 10)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor").c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_monitor").c_str());
}
if (!matSolverPackage) {
Parameters::get(name + "->use zero start vector", zeroStartVector);
......
......@@ -189,7 +189,7 @@ namespace AMDiS { namespace Parallel {
#else
KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN);
#endif
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
petsc_helper::setSolver(ksp, "ch_", KSPFGMRES, PCSHELL, getRelative(), getTolerance(), getMaxIterations());
setConstantNullSpace(ksp, componentSpaces[0]->getMesh()->getDim() , true);
}
......
......@@ -123,9 +123,9 @@ namespace AMDiS { namespace Parallel {
KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN);
#endif
if (getInfo() >= 10)
KSPMonitorSet(ksp, KSPMonitorDefault, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorDefault), PETSC_NULL, PETSC_NULL);
else if (getInfo() >= 20)
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
KSPMonitorSet(ksp, PETSC_MONITOR_CAST(KSPMonitorTrueResidualNorm), PETSC_NULL, PETSC_NULL);
petsc_helper::setSolver(ksp, "ns_", KSPFGMRES, PCNONE, getRelative(), getTolerance(), getMaxIterations());
// Create null space information.
......
......@@ -58,7 +58,7 @@ namespace AMDiS {
virtual void init(PC pc, const SolverMatrix<Matrix<DOFMatrix*> >& A, const MatrixType& fullMatrix)
{
PetscOptionsInsertString(("-" + prefix + "pc_type " + name).c_str());
petsc_options_insert_string(("-" + prefix + "pc_type " + name).c_str());
PCSetFromOptions(pc);
}
......
......@@ -47,30 +47,30 @@ namespace AMDiS {
if (params.matSolverPackage[kspSolver]) {
// direct solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type preonly").c_str());
PetscOptionsInsertString(("-" + kspPrefix + "pc_type lu").c_str());
PetscOptionsInsertString(("-" + kspPrefix + "pc_factor_mat_solver_package " + (kspSolver != "direct" ? kspSolver : "umfpack")).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_type preonly").c_str());
petsc_options_insert_string(("-" + kspPrefix + "pc_type lu").c_str());
petsc_options_insert_string(("-" + kspPrefix + "pc_factor_mat_solver_package " + (kspSolver != "direct" ? kspSolver : "umfpack")).c_str());
oem.setMaxIterations(1);
zeroStartVector = true;
matSolverPackage = true;
} else if (!params.emptyParam[kspSolver]) {
// other solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type " + kspSolver).c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_type " + kspSolver).c_str());
}
// set the preconditioner
setPrecon();
if (oem.getInfo() >= 20)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor_true_residual").c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_monitor_true_residual").c_str());
else if (oem.getInfo() >= 10)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor").c_str());
petsc_options_insert_string(("-" + kspPrefix + "ksp_monitor").c_str());
// command line string
std::string kspString = "";
Parameters::get(oem.getName() + "->ksp", kspString);
if (kspString != "")
PetscOptionsInsertString(kspString.c_str());
petsc_options_insert_string(kspString.c_str());
}
......
......@@ -143,6 +143,17 @@ namespace AMDiS {
template< typename Mapper >
void operator>>(const PetscVectorNested& dest, VecMap<SystemVector, Mapper>& rhs);
inline PetscErrorCode petsc_options_insert_string(const char in_str[])
{
#if (PETSC_VERSION_MINOR >= 7)
return PetscOptionsInsertString(NULL, in_str);
#else
return PetscOptionsInsertString(in_str);
#endif
}
} // end namespace AMDiS
#include "solver/PetscTypes.hh"
......
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