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