Commit 2f5be996 authored by Sebastian Aland's avatar Sebastian Aland
Browse files

PetscSolverCahnHilliard geht jetzt auch mit diffuse domain

parent 6ee1c6b6
......@@ -17,6 +17,20 @@
namespace AMDiS {
class Multiplier: public AbstractFunction<double, double>
{
public:
Multiplier(double d_) : AbstractFunction<double, double>(2),d(d_) {};
double operator()(const double& x) const {
return d*x;
}
protected:
double d;
};
using namespace std;
/// solve Cahn-Hilliard Preconditioner
......@@ -38,9 +52,9 @@ namespace AMDiS {
VecDuplicate(b1, &y1);
VecDuplicate(b2, &y2);
// MatGetDiagonal(data->matM, y2);
// VecReciprocal(y2);
// VecPointwiseMult(y1, y2, b1);
// MatGetDiagonal(data->matM, y2);
// VecReciprocal(y2);
// VecPointwiseMult(y1, y2, b1);
KSPSolve(data->kspMass, b1, y1); // M*y1 = b1
MatMultAdd(data->matMinusDeltaK, y1, b2, x1); // -> x1 := b2-delta*K*y1
......@@ -75,8 +89,9 @@ namespace AMDiS {
{
FUNCNAME("PetscSolverCahnHilliard::solvePetscMatrix()");
/* if (useOldInitialGuess) {
VecSet(getVecSolInterior(), 0.0);
/* if (useOldInitialGuess) {
if (getVecSolInterior())
{VecSet(getVecSolInterior(), 0.0);
for (int i = 0; i < solution->getSize(); i++)
{
......@@ -88,7 +103,8 @@ namespace AMDiS {
vecSolAssembly();
KSPSetInitialGuessNonzero(kspInterior, PETSC_TRUE);
}
*/ KSPSetInitialGuessNonzero(kspInterior, PETSC_TRUE);
KSPSetInitialGuessNonzero(kspInterior, PETSC_TRUE);
}*/
PetscSolverGlobalBlockMatrix::solvePetscMatrix(vec, adaptInfo);
}
......@@ -111,7 +127,7 @@ namespace AMDiS {
FUNCNAME("PetscSolverCahnHilliard::initPreconditioner()");
MSG("PetscSolverCahnHilliard::initPreconditioner()\n");
// KSPSetUp(kspInterior);
// KSPSetUp(kspInterior);
PCSetType(pc, PCSHELL);
PCShellSetApply(pc, pcChShell);
......@@ -120,34 +136,68 @@ namespace AMDiS {
const FiniteElemSpace *feSpace = componentSpaces[0];
// === matrix M ===
DOFMatrix laplaceMatrix(feSpace, feSpace);
Operator laplaceOp(feSpace, feSpace);
DOFMatrix massMatrix(feSpace, feSpace);
Operator massOp(feSpace, feSpace);
Simple_ZOT zot;
DOFMatrix deltaKMatrix(feSpace, feSpace);
Operator laplaceOp2(feSpace, feSpace);
if (phase)
{
VecAtQP_ZOT zot(phase, NULL);
massOp.addTerm(&zot);
laplaceOp.addTerm(&zot); // M
VecAtQP_SOT sot2(phase, new Multiplier((*eps)*sqrt(*delta)));
laplaceOp.addTerm(&sot2); // eps*sqrt(delta)*K
VecAtQP_SOT sot(phase, new Multiplier(-(*delta)));
laplaceOp2.addTerm(&sot); // -delta*K
massMatrix.assembleOperator(massOp);
massMatrixSolver = createSubSolver(0, "mass_");
massMatrixSolver->fillPetscMatrix(&massMatrix);
// === matrix (M + eps*sqrt(delta)*K) ===
DOFMatrix laplaceMatrix(feSpace, feSpace);
Operator laplaceOp(feSpace, feSpace);
laplaceMatrix.assembleOperator(laplaceOp);
laplaceMatrixSolver = createSubSolver(0, "laplace_");
laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix);
// === matrix (-delta*K) ===
deltaKMatrix.assembleOperator(laplaceOp2);
deltaKMatrixSolver = createSubSolver(0, "laplace2_");
deltaKMatrixSolver->fillPetscMatrix(&deltaKMatrix);
}
else
{
Simple_ZOT zot;
massOp.addTerm(&zot);
laplaceOp.addTerm(&zot); // M
Simple_SOT sot2((*eps)*sqrt(*delta));
laplaceOp.addTerm(&sot2); // eps*sqrt(delta)*K
Simple_SOT sot(-(*delta));
laplaceOp2.addTerm(&sot); // -delta*K
massMatrix.assembleOperator(massOp);
massMatrixSolver = createSubSolver(0, "mass_");
massMatrixSolver->fillPetscMatrix(&massMatrix);
// === matrix (M + eps*sqrt(delta)*K) ===
laplaceMatrix.assembleOperator(laplaceOp);
laplaceMatrixSolver = createSubSolver(0, "laplace_");
laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix);
// === matrix (-delta*K) ===
DOFMatrix deltaKMatrix(feSpace, feSpace);
Operator laplaceOp2(feSpace, feSpace);
Simple_SOT sot(-(*delta));
laplaceOp2.addTerm(&sot); // -delta*K
deltaKMatrix.assembleOperator(laplaceOp2);
deltaKMatrixSolver = createSubSolver(0, "laplace2_");
deltaKMatrixSolver->fillPetscMatrix(&deltaKMatrix);
}
// === Setup solver ===
......@@ -161,20 +211,20 @@ namespace AMDiS {
matShellContext.mpiCommGlobal= &(meshDistributor->getMpiComm(0));
petsc_helper::setSolver(matShellContext.kspMass, "", KSPCG, PCJACOBI, 0.0, 1e-14, 2);
// petsc_helper::setSolver(matShellContext.kspMass, "mass_", KSPRICHARDSON, PCLU, 0.0, 1e-14, 1);
// {
// PC pc;
// KSPGetPC(matShellContext.kspMass, &pc);
// PCFactorSetMatSolverPackage(pc, MATSOLVERMUMPS);
// }
// petsc_helper::setSolver(matShellContext.kspMass, "mass_", KSPRICHARDSON, PCLU, 0.0, 1e-14, 1);
// {
// PC pc;
// KSPGetPC(matShellContext.kspMass, &pc);
// PCFactorSetMatSolverPackage(pc, MATSOLVERMUMPS);
// }
petsc_helper::setSolver(matShellContext.kspLaplace, "laplace_", KSPRICHARDSON, PCHYPRE, 0.0, 1e-14, 1);
// petsc_helper::setSolver(matShellContext.kspLaplace, "laplace_", KSPRICHARDSON, PCLU, 0.0, 1e-14, 1);
// {
// PC pc;
// KSPGetPC(matShellContext.kspLaplace, &pc);
// PCFactorSetMatSolverPackage(pc, MATSOLVERMUMPS);
// }
// petsc_helper::setSolver(matShellContext.kspLaplace, "laplace_", KSPRICHARDSON, PCLU, 0.0, 1e-14, 1);
// {
// PC pc;
// KSPGetPC(matShellContext.kspLaplace, &pc);
// PCFactorSetMatSolverPackage(pc, MATSOLVERMUMPS);
// }
PCSetFromOptions(pc);
}
......
......@@ -58,11 +58,12 @@ namespace AMDiS {
PetscSolverCahnHilliard(string name, double *epsPtr = NULL, double *deltaPtr = NULL);
void setChData(double *epsPtr, double *deltaPtr, SystemVector* vec)
void setChData(double *epsPtr, double *deltaPtr, SystemVector* vec, DOFVector<double> *p=NULL)
{
eps = epsPtr;
delta = deltaPtr;
solution = vec;
phase = p;
}
protected:
......@@ -84,6 +85,8 @@ namespace AMDiS {
SystemVector* solution;
DOFVector<double> *phase;
double *eps, *delta;
};
......
Supports Markdown
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