Commit 7b38ea10 authored by Praetorius, Simon's avatar Praetorius, Simon

some changes in PetscSolverGlobalMatrix

parent 923b0774
...@@ -29,7 +29,7 @@ namespace AMDiS { ...@@ -29,7 +29,7 @@ namespace AMDiS {
VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv, VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv,
AbstractFunction<double, double> *af, AbstractFunction<double, double> *af,
WorldVector<double> *wv) WorldVector<double> *wv)
: FirstOrderTerm(af->getDegree()), vec(dv), f(af), b(wv) : FirstOrderTerm(af ? af->getDegree() : dv->getFeSpace()->getBasisFcts()->getDegree()), vec(dv), f(af), b(wv)
{ {
TEST_EXIT(dv)("No vector!\n"); TEST_EXIT(dv)("No vector!\n");
...@@ -39,7 +39,7 @@ namespace AMDiS { ...@@ -39,7 +39,7 @@ namespace AMDiS {
VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv, VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv,
AbstractFunction<double, double> *af, AbstractFunction<double, double> *af,
int bIdx) int bIdx)
: FirstOrderTerm(af->getDegree()), vec(dv), f(af) : FirstOrderTerm(af ? af->getDegree() : dv->getFeSpace()->getBasisFcts()->getDegree()), vec(dv), f(af)
{ {
TEST_EXIT(dv)("No vector!\n"); TEST_EXIT(dv)("No vector!\n");
...@@ -69,14 +69,29 @@ namespace AMDiS { ...@@ -69,14 +69,29 @@ namespace AMDiS {
const int nPoints = static_cast<int>(Lb.size()); const int nPoints = static_cast<int>(Lb.size());
if (bOne > -1) { if (bOne > -1) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
lb_one(grdLambda, Lb[iq], (*f)(vecAtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
lb_one(grdLambda, Lb[iq], (*f)(vecAtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
lb_one(grdLambda, Lb[iq], vecAtQPs[iq]);
}
} else if (b) { } else if (b) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
lb(grdLambda, *b, Lb[iq], (*f)(vecAtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
lb(grdLambda, *b, Lb[iq], (*f)(vecAtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
lb(grdLambda, *b, Lb[iq], vecAtQPs[iq]);
}
} else { } else {
for (int iq = 0; iq < nPoints; iq++) if (f) {
l1(grdLambda, Lb[iq], (*f)(vecAtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
l1(grdLambda, Lb[iq], (*f)(vecAtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
l1(grdLambda, Lb[iq], vecAtQPs[iq]);
}
} }
} }
...@@ -91,7 +106,7 @@ namespace AMDiS { ...@@ -91,7 +106,7 @@ namespace AMDiS {
if (num_rows(grdUhAtQP) > 0) { if (num_rows(grdUhAtQP) > 0) {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double factor = (*f)(vecAtQPs[iq]); double factor = (f ? (*f)(vecAtQPs[iq]) : vecAtQPs[iq]);
double resultQP = 0.0; double resultQP = 0.0;
for (int i = 0; i < dow; i++) for (int i = 0; i < dow; i++)
resultQP += grdUhAtQP[iq][i]; resultQP += grdUhAtQP[iq][i];
...@@ -522,7 +537,11 @@ namespace AMDiS { ...@@ -522,7 +537,11 @@ namespace AMDiS {
Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *af, BinaryAbstractFunction<double, double, double> *af,
WorldVector<double> *b_) WorldVector<double> *b_)
: FirstOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af), b(b_) : FirstOrderTerm(af ?
af->getDegree() :
dv1->getFeSpace()->getBasisFcts()->getDegree()
+ dv2->getFeSpace()->getBasisFcts()->getDegree()),
vec1(dv1), vec2(dv2), f(af), b(b_)
{ {
TEST_EXIT(dv1)("No first vector!\n"); TEST_EXIT(dv1)("No first vector!\n");
TEST_EXIT(dv2)("No second vector!\n"); TEST_EXIT(dv2)("No second vector!\n");
...@@ -534,7 +553,11 @@ namespace AMDiS { ...@@ -534,7 +553,11 @@ namespace AMDiS {
Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *af, BinaryAbstractFunction<double, double, double> *af,
int bIdx) int bIdx)
: FirstOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af) : FirstOrderTerm(af ?
af->getDegree() :
dv1->getFeSpace()->getBasisFcts()->getDegree()
+ dv2->getFeSpace()->getBasisFcts()->getDegree()),
vec1(dv1), vec2(dv2), f(af)
{ {
TEST_EXIT(dv1)("No first vector!\n"); TEST_EXIT(dv1)("No first vector!\n");
TEST_EXIT(dv2)("No second vector!\n"); TEST_EXIT(dv2)("No second vector!\n");
...@@ -559,14 +582,29 @@ namespace AMDiS { ...@@ -559,14 +582,29 @@ namespace AMDiS {
const int nPoints = static_cast<int>(Lb.size()); const int nPoints = static_cast<int>(Lb.size());
if (bOne > -1) { if (bOne > -1) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
lb_one(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
lb_one(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
lb_one(grdLambda, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq]);
}
} else if (b) { } else if (b) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
lb(grdLambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
lb(grdLambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
lb(grdLambda, *b, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq]);
}
} else { } else {
for (int iq = 0; iq < nPoints; iq++) if (f) {
l1(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
l1(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
} else {
for (int iq = 0; iq < nPoints; iq++)
l1(grdLambda, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq]);
}
} }
} }
...@@ -577,9 +615,15 @@ namespace AMDiS { ...@@ -577,9 +615,15 @@ namespace AMDiS {
mtl::dense_vector<double>& result, mtl::dense_vector<double>& result,
double fac) double fac)
{ {
if (num_rows(grdUhAtQP) > 0) if (num_rows(grdUhAtQP) > 0) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq]) * ((*b) * grdUhAtQP[iq]); for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
} else {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * vec1AtQPs[iq] * vec2AtQPs[iq] * ((*b) * grdUhAtQP[iq]);
}
}
} }
...@@ -590,7 +634,11 @@ namespace AMDiS { ...@@ -590,7 +634,11 @@ namespace AMDiS {
DOFVectorBase<double> *dv3, DOFVectorBase<double> *dv3,
TertiaryAbstractFunction<double, double, double, double> *f_, TertiaryAbstractFunction<double, double, double, double> *f_,
WorldVector<double> *bvec) WorldVector<double> *bvec)
: FirstOrderTerm(f_->getDegree()), : FirstOrderTerm(f_ ?
f_->getDegree() :
dv1->getFeSpace()->getBasisFcts()->getDegree()
+ dv2->getFeSpace()->getBasisFcts()->getDegree()
+ dv3->getFeSpace()->getBasisFcts()->getDegree()),
vec1(dv1), vec1(dv1),
vec2(dv2), vec2(dv2),
vec3(dv3), vec3(dv3),
...@@ -607,7 +655,11 @@ namespace AMDiS { ...@@ -607,7 +655,11 @@ namespace AMDiS {
DOFVectorBase<double> *dv3, DOFVectorBase<double> *dv3,
TertiaryAbstractFunction<double, double, double, double> *f_, TertiaryAbstractFunction<double, double, double, double> *f_,
int b) int b)
: FirstOrderTerm(f_->getDegree()), : FirstOrderTerm(f_ ?
f_->getDegree() :
dv1->getFeSpace()->getBasisFcts()->getDegree()
+ dv2->getFeSpace()->getBasisFcts()->getDegree()
+ dv3->getFeSpace()->getBasisFcts()->getDegree()),
vec1(dv1), vec1(dv1),
vec2(dv2), vec2(dv2),
vec3(dv3), vec3(dv3),
...@@ -635,14 +687,28 @@ namespace AMDiS { ...@@ -635,14 +687,28 @@ namespace AMDiS {
const int nPoints = static_cast<int>(Lb.size()); const int nPoints = static_cast<int>(Lb.size());
if (bOne > -1) { if (bOne > -1) {
for (int iq = 0; iq < nPoints; iq++) if (f) {
lb_one(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq])); for (int iq = 0; iq < nPoints; iq++)
} else { lb_one(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
for (int iq = 0; iq < nPoints; iq++) { } else {
if (b) for (int iq = 0; iq < nPoints; iq++)
lb(grdLambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq])); lb_one(grdLambda, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq] * vec3AtQPs[iq]);
else }
l1(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq])); } else {
if (f) {
for (int iq = 0; iq < nPoints; iq++) {
if (b)
lb(grdLambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
else
l1(grdLambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
}
} else {
for (int iq = 0; iq < nPoints; iq++) {
if (b)
lb(grdLambda, *b, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq] * vec3AtQPs[iq]);
else
l1(grdLambda, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq] * vec3AtQPs[iq]);
}
} }
} }
} }
...@@ -660,9 +726,15 @@ namespace AMDiS { ...@@ -660,9 +726,15 @@ namespace AMDiS {
if (bOne > -1) { if (bOne > -1) {
ERROR_EXIT("Not yet implemented!\n"); ERROR_EXIT("Not yet implemented!\n");
} else { } else {
for (int iq = 0; iq < nPoints; iq++) if (f) {
result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq] ,vec3AtQPs[iq]) * for (int iq = 0; iq < nPoints; iq++)
((*b) * grdUhAtQP[iq]); result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq] ,vec3AtQPs[iq]) *
((*b) * grdUhAtQP[iq]);
} else {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * vec1AtQPs[iq] * vec2AtQPs[iq] * vec3AtQPs[iq] *
((*b) * grdUhAtQP[iq]);
}
} }
} }
......
...@@ -187,8 +187,11 @@ namespace AMDiS { ...@@ -187,8 +187,11 @@ namespace AMDiS {
// ========== VecAtQP_SOT ========== // ========== VecAtQP_SOT ==========
VecAtQP_SOT::VecAtQP_SOT(DOFVectorBase<double> *dv, VecAtQP_SOT::VecAtQP_SOT(DOFVectorBase<double> *dv,
AbstractFunction<double, double> *af) AbstractFunction<double, double> *af,
: SecondOrderTerm(af ? af->getDegree() : dv->getFeSpace()->getBasisFcts()->getDegree()), vec(dv), f(af) double factor_
)
: SecondOrderTerm(af ? af->getDegree() : dv->getFeSpace()->getBasisFcts()->getDegree()),
vec(dv), f(af), factor(factor_)
{ {
setSymmetric(true); setSymmetric(true);
...@@ -220,10 +223,10 @@ namespace AMDiS { ...@@ -220,10 +223,10 @@ namespace AMDiS {
if (f) { if (f) {
for (int iq = 0; iq < nPoints; iq++) for (int iq = 0; iq < nPoints; iq++)
l1lt(grdLambda, LALt[iq], (*f)(vecAtQPs[iq])); l1lt(grdLambda, LALt[iq], factor*(*f)(vecAtQPs[iq]));
} else { } else {
for (int iq = 0; iq < nPoints; iq++) for (int iq = 0; iq < nPoints; iq++)
l1lt(grdLambda, LALt[iq], vecAtQPs[iq]); l1lt(grdLambda, LALt[iq], factor*vecAtQPs[iq]);
} }
} }
...@@ -237,19 +240,20 @@ namespace AMDiS { ...@@ -237,19 +240,20 @@ namespace AMDiS {
int dow = Global::getGeo(WORLD); int dow = Global::getGeo(WORLD);
if (num_rows(D2UhAtQP) > 0) { if (num_rows(D2UhAtQP) > 0) {
double fac_ = factor * fac;
if (f) { if (f) {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double resultQP = 0.0; double resultQP = 0.0;
for (int i = 0; i < dow; i++) for (int i = 0; i < dow; i++)
resultQP += D2UhAtQP[iq][i][i]; resultQP += D2UhAtQP[iq][i][i];
result[iq] += fac * (*f)(vecAtQPs[iq]) * resultQP; result[iq] += fac_ * (*f)(vecAtQPs[iq]) * resultQP;
} }
} else { } else {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double resultQP = 0.0; double resultQP = 0.0;
for (int i = 0; i < dow; i++) for (int i = 0; i < dow; i++)
resultQP += D2UhAtQP[iq][i][i]; resultQP += D2UhAtQP[iq][i][i];
result[iq] += fac * vecAtQPs[iq] * resultQP; result[iq] += fac_ * vecAtQPs[iq] * resultQP;
} }
} }
} }
...@@ -261,13 +265,13 @@ namespace AMDiS { ...@@ -261,13 +265,13 @@ namespace AMDiS {
int nPoints = grdUhAtQP.size(); int nPoints = grdUhAtQP.size();
if (f) { if (f) {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double factor = (*f)(vecAtQPs[iq]); double fac_ = factor * (*f)(vecAtQPs[iq]);
axpy(factor, grdUhAtQP[iq], result[iq]); axpy(fac_, grdUhAtQP[iq], result[iq]);
} }
} else { } else {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double factor = vecAtQPs[iq]; double fac_ = factor * vecAtQPs[iq];
axpy(factor, grdUhAtQP[iq], result[iq]); axpy(fac_, grdUhAtQP[iq], result[iq]);
} }
} }
} }
...@@ -276,8 +280,11 @@ namespace AMDiS { ...@@ -276,8 +280,11 @@ namespace AMDiS {
// ========== Vec2AtQP_SOT ========== // ========== Vec2AtQP_SOT ==========
Vec2AtQP_SOT::Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, Vec2AtQP_SOT::Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *af) BinaryAbstractFunction<double, double, double> *af,
: SecondOrderTerm(af ? af->getDegree() : 2*dv1->getFeSpace()->getBasisFcts()->getDegree()), vec1(dv1), vec2(dv2), f(af) double factor_
)
: SecondOrderTerm(af ? af->getDegree() : 2*dv1->getFeSpace()->getBasisFcts()->getDegree()),
vec1(dv1), vec2(dv2), f(af), factor(factor_)
{ {
setSymmetric(true); setSymmetric(true);
...@@ -304,9 +311,9 @@ namespace AMDiS { ...@@ -304,9 +311,9 @@ namespace AMDiS {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
if (f) if (f)
l1lt(grdLambda, LALt[iq], (*f)(vecAtQPs1[iq], vecAtQPs2[iq])); l1lt(grdLambda, LALt[iq], factor * (*f)(vecAtQPs1[iq], vecAtQPs2[iq]));
else else
l1lt(grdLambda, LALt[iq], vecAtQPs1[iq] * vecAtQPs2[iq]); l1lt(grdLambda, LALt[iq], factor * vecAtQPs1[iq] * vecAtQPs2[iq]);
} }
} }
...@@ -321,15 +328,16 @@ namespace AMDiS { ...@@ -321,15 +328,16 @@ namespace AMDiS {
if (num_rows(D2UhAtQP) > 0) { if (num_rows(D2UhAtQP) > 0) {
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double factor = 1.0; double fac_ = 1.0;
if (f) if (f)
factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]); fac_ = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
else else
factor = vecAtQPs1[iq] * vecAtQPs2[iq]; fac_ = vecAtQPs1[iq] * vecAtQPs2[iq];
fac_ *= fac * factor;
double resultQP = 0.0; double resultQP = 0.0;
for (int i = 0; i < dow; i++) for (int i = 0; i < dow; i++)
resultQP += D2UhAtQP[iq][i][i]; resultQP += D2UhAtQP[iq][i][i];
result[iq] += fac * factor * resultQP; result[iq] += fac_ * resultQP;
} }
} }
} }
...@@ -339,12 +347,13 @@ namespace AMDiS { ...@@ -339,12 +347,13 @@ namespace AMDiS {
{ {
int nPoints = grdUhAtQP.size(); int nPoints = grdUhAtQP.size();
for (int iq = 0; iq < nPoints; iq++) { for (int iq = 0; iq < nPoints; iq++) {
double factor = 1.0; double fac_ = 1.0;
if (f) if (f)
factor = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]); fac_ = (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
else else
factor = vecAtQPs1[iq] * vecAtQPs2[iq]; fac_ = vecAtQPs1[iq] * vecAtQPs2[iq];
axpy(factor, grdUhAtQP[iq], result[iq]); fac_ *= factor;
axpy(fac_, grdUhAtQP[iq], result[iq]);
} }
} }
......
...@@ -362,7 +362,8 @@ namespace AMDiS { ...@@ -362,7 +362,8 @@ namespace AMDiS {
{ {
public: public:
/// Constructor. /// Constructor.
VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af = NULL); VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af = NULL,
double factor_ = 1.0);
/// Implementation of \ref OperatorTerm::initElement(). /// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo, SubAssembler* subAssembler, void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
...@@ -398,6 +399,8 @@ namespace AMDiS { ...@@ -398,6 +399,8 @@ namespace AMDiS {
/// Function evaluated at \ref vecAtQPs. /// Function evaluated at \ref vecAtQPs.
AbstractFunction<double, double> *f; AbstractFunction<double, double> *f;
double factor;
}; };
/** /**
...@@ -414,7 +417,8 @@ namespace AMDiS { ...@@ -414,7 +417,8 @@ namespace AMDiS {
/// Constructor. /// Constructor.
Vec2AtQP_SOT(DOFVectorBase<double> *dv1, Vec2AtQP_SOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2, DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *af = NULL); BinaryAbstractFunction<double, double, double> *af = NULL,
double factor_ = 1.0);
/// Implementation of \ref OperatorTerm::initElement(). /// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo, SubAssembler* subAssembler, void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
...@@ -444,6 +448,8 @@ namespace AMDiS { ...@@ -444,6 +448,8 @@ namespace AMDiS {
/// Function evaluated at \ref vecAtQPs. /// Function evaluated at \ref vecAtQPs.
BinaryAbstractFunction<double, double, double> *f; BinaryAbstractFunction<double, double, double> *f;
double factor;
}; };
......
...@@ -28,59 +28,73 @@ ...@@ -28,59 +28,73 @@
namespace AMDiS { namespace Parallel { namespace AMDiS { namespace Parallel {
PetscSolverGlobalMatrix::PetscSolverGlobalMatrix(string name) PetscSolverGlobalMatrix::PetscSolverGlobalMatrix(string name, bool setOptions)
: PetscSolver(name), : PetscSolver(name),
zeroStartVector(false), zeroStartVector(false),
printMatInfo(false) printMatInfo(false)
{ { FUNCNAME_DBG("PetscSolverGlobalMatrix()");
PetscParameters params;
bool matSolverPackage = false; bool matSolverPackage = false;
if (setOptions) {
// set the solver PetscParameters params;
std::string solverName = "petsc";
Parameters::get(name, solverName); // set the solver
if (solverName == "petsc") std::string solverName = "petsc";
Parameters::get(name + "->ksp_type", solverName); Parameters::get(name, solverName);
if (solverName == "petsc")
std::string kspSolver = params.solverMap[solverName]; Parameters::get(name + "->ksp_type", solverName);
if (params.matSolverPackage[kspSolver]) { std::string kspSolver = params.solverMap[solverName];
// direct solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type preonly").c_str()); if (params.matSolverPackage.find(kspSolver) != params.matSolverPackage.end()) {
PetscOptionsInsertString(("-" + kspPrefix + "pc_type lu").c_str()); // direct solvers
PetscOptionsInsertString(("-" + kspPrefix + "pc_factor_mat_solver_package " + (kspSolver != "direct" ? kspSolver : "mumps")).c_str()); PetscOptionsInsertString(("-" + kspPrefix + "ksp_type preonly").c_str());
setMaxIterations(1); PetscOptionsInsertString(("-" + kspPrefix + "pc_type lu").c_str());
zeroStartVector = true; PetscOptionsInsertString(("-" + kspPrefix + "pc_factor_mat_solver_package " + kspSolver).c_str());
matSolverPackage = true; setMaxIterations(1);
} else if (!params.emptyParam[kspSolver]) { zeroStartVector = true;
// other solvers matSolverPackage = true;
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type " + kspSolver).c_str()); } else if (params.emptyParam.find(kspSolver) == params.emptyParam.end() && solverName != "petsc") {
} // other solvers
PetscOptionsInsertString(("-" + kspPrefix + "ksp_type " + kspSolver).c_str());
}
// set the preconditioner
string precon = ""; // set the preconditioner
Parameters::get(name + "->pc_type", precon); string precon = "";
if (!precon.size()) Parameters::get(name + "->pc_type", precon);
Parameters::get(name + "->left precon", precon); if (!precon.size())
if (!matSolverPackage && !params.emptyParam[precon]) { Parameters::get(name + "->left precon", precon);
precon = (params.preconMap.find(precon) != params.preconMap.end() ? params.preconMap[precon] : precon); if (!matSolverPackage && params.emptyParam.find(precon) == params.emptyParam.end()) {
PetscOptionsInsertString(("-" + kspPrefix + "pc_type " + precon).c_str()); precon = (params.preconMap.find(precon) != params.preconMap.end() ? params.preconMap[precon] : precon);
PetscOptionsInsertString(("-" + 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());
if (getInfo() >= 20)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor_true_residual").c_str());
else if (getInfo() >= 10)
PetscOptionsInsertString(("-" + kspPrefix + "ksp_monitor").c_str());
} }
PetscOptionsInsertString(("-" + kspPrefix + "ksp_max_it " + boost::lexical_cast<std::string>(getMaxIterations())).c_str());