Commit 2003ee04 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

CahnHilliard preconditioner updated

parent 7b38ea10
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "ProblemInstat.h" #include "ProblemInstat.h"
#include "RefinementManager3d.h" #include "RefinementManager3d.h"
#include "Debug.h" #include "Debug.h"
#include "Timer.h"
namespace AMDiS { namespace Parallel { namespace AMDiS { namespace Parallel {
...@@ -719,9 +720,7 @@ namespace AMDiS { namespace Parallel { ...@@ -719,9 +720,7 @@ namespace AMDiS { namespace Parallel {
if (mesh->getDim() != 3) if (mesh->getDim() != 3)
return; return;
MPI::COMM_WORLD.Barrier(); Timer t;
double first = MPI::Wtime();
// === Create set of all edges and all macro element indices in rank's === // === Create set of all edges and all macro element indices in rank's ===
// === subdomain. === // === subdomain. ===
...@@ -829,8 +828,7 @@ namespace AMDiS { namespace Parallel { ...@@ -829,8 +828,7 @@ namespace AMDiS { namespace Parallel {
} }
MPI::COMM_WORLD.Barrier(); MSG("Fix 3D mesh refinement needed %.5f seconds\n", t.elapsed());
MSG("Fix 3D mesh refinement needed %.5f seconds\n", MPI::Wtime() - first);
} }
...@@ -1070,7 +1068,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1070,7 +1068,7 @@ namespace AMDiS { namespace Parallel {
MPI::Intracomm &mpiComm = MPI::COMM_WORLD; MPI::Intracomm &mpiComm = MPI::COMM_WORLD;
mpiComm.Barrier(); mpiComm.Barrier();
double first = MPI::Wtime(); Timer t;
int skip = 0; int skip = 0;
Parameters::get("parallel->debug->skip check mesh change", skip); Parameters::get("parallel->debug->skip check mesh change", skip);
...@@ -1155,7 +1153,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1155,7 +1153,7 @@ namespace AMDiS { namespace Parallel {
} }
mpiComm.Barrier(); mpiComm.Barrier();
MSG("Parallel mesh adaption needed %.5f seconds\n", MPI::Wtime() - first); MSG("Parallel mesh adaption needed %.5f seconds\n", t.elapsed());
// === Update the DOF numbering and mappings. === // === Update the DOF numbering and mappings. ===
...@@ -1419,8 +1417,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1419,8 +1417,7 @@ namespace AMDiS { namespace Parallel {
if (repartitioning == 0) if (repartitioning == 0)
return; return;
mpiComm.Barrier(); Timer t;
double timePoint = MPI::Wtime();
#if (DEBUG != 0) #if (DEBUG != 0)
ParallelDebug::testDoubleDofs(mesh); ParallelDebug::testDoubleDofs(mesh);
...@@ -1473,7 +1470,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1473,7 +1470,7 @@ namespace AMDiS { namespace Parallel {
mpiComm.Barrier(); mpiComm.Barrier();
repartitioningFailed = repartitioningWaitAfterFail;; repartitioningFailed = repartitioningWaitAfterFail;;
MSG("Mesh partitioner created empty partition!\n"); MSG("Mesh partitioner created empty partition!\n");
MSG("Mesh repartitioning needed %.5f seconds\n", MPI::Wtime() - timePoint); MSG("Mesh repartitioning needed %.5f seconds\n", t.elapsed());
return; return;
} }
...@@ -1487,7 +1484,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1487,7 +1484,7 @@ namespace AMDiS { namespace Parallel {
if (!partitioningSucceed || !partitioner->meshChanged()) { if (!partitioningSucceed || !partitioner->meshChanged()) {
mpiComm.Barrier(); mpiComm.Barrier();
repartitioningFailed = repartitioningWaitAfterFail;; repartitioningFailed = repartitioningWaitAfterFail;;
MSG("Mesh repartitioning needed %.5f seconds\n", MPI::Wtime() - timePoint); MSG("Mesh repartitioning needed %.5f seconds\n", t.elapsed());
return; return;
} }
} }
...@@ -1706,7 +1703,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1706,7 +1703,7 @@ namespace AMDiS { namespace Parallel {
mpiComm.Barrier(); mpiComm.Barrier();
MSG("Mesh repartitioning needed %.5f seconds\n", MPI::Wtime() - timePoint); MSG("Mesh repartitioning needed %.5f seconds\n", t.elapsed());
} }
...@@ -1746,9 +1743,9 @@ namespace AMDiS { namespace Parallel { ...@@ -1746,9 +1743,9 @@ namespace AMDiS { namespace Parallel {
{ {
FUNCNAME("MeshDistributor::createBoundaryDofs()"); FUNCNAME("MeshDistributor::createBoundaryDofs()");
Timer *t = NULL;
if (printTimings) if (printTimings)
MPI::COMM_WORLD.Barrier(); t = new Timer();
double first = MPI::Wtime();
// === Create DOF communicator. === // === Create DOF communicator. ===
...@@ -1805,9 +1802,9 @@ namespace AMDiS { namespace Parallel { ...@@ -1805,9 +1802,9 @@ namespace AMDiS { namespace Parallel {
} }
} }
if (printTimings) { if (printTimings && t) {
MPI::COMM_WORLD.Barrier(); MSG("MESHDIST 01 (createBoundaryDofs) needed %.5f seconds\n", t->elapsed());
MSG("MESHDIST 01 (createBoundaryDofs) needed %.5f seconds\n", MPI::Wtime() - first); delete t;
} }
} }
...@@ -1828,8 +1825,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1828,8 +1825,7 @@ namespace AMDiS { namespace Parallel {
{ {
FUNCNAME("MeshDistributor::updateLocalGlobalNumbering()"); FUNCNAME("MeshDistributor::updateLocalGlobalNumbering()");
MPI::COMM_WORLD.Barrier(); Timer t;
double first = MPI::Wtime();
mesh->dofCompress(); mesh->dofCompress();
...@@ -1927,8 +1923,7 @@ namespace AMDiS { namespace Parallel { ...@@ -1927,8 +1923,7 @@ namespace AMDiS { namespace Parallel {
debugOutputDir + "mpi-dbg", "dat"); debugOutputDir + "mpi-dbg", "dat");
#endif #endif
MPI::COMM_WORLD.Barrier(); MSG("Rebuild of parallel data structures needed %.5f seconds\n", t.elapsed());
MSG("Rebuild of parallel data structures needed %.5f seconds\n", MPI::Wtime() - first);
} }
...@@ -1936,9 +1931,9 @@ namespace AMDiS { namespace Parallel { ...@@ -1936,9 +1931,9 @@ namespace AMDiS { namespace Parallel {
{ {
FUNCNAME("MeshDistributor::updateParallelDofMappings()"); FUNCNAME("MeshDistributor::updateParallelDofMappings()");
Timer *t = NULL;
if (printTimings) if (printTimings)
MPI::COMM_WORLD.Barrier(); t = new Timer();
double first = MPI::Wtime();
TEST_EXIT(dofMaps.size())("No DOF mapping defined!\n"); TEST_EXIT(dofMaps.size())("No DOF mapping defined!\n");
...@@ -1956,9 +1951,9 @@ namespace AMDiS { namespace Parallel { ...@@ -1956,9 +1951,9 @@ namespace AMDiS { namespace Parallel {
#endif #endif
} }
if (printTimings) { if (printTimings && t) {
MPI::COMM_WORLD.Barrier(); MSG("MESHDIST 02 (update DOF mappings) needed %.5f seconds\n", t->elapsed());
MSG("MESHDIST 02 (update DOF mappings) needed %.5f seconds\n", MPI::Wtime() - first); delete t;
} }
} }
......
...@@ -26,20 +26,6 @@ ...@@ -26,20 +26,6 @@
namespace AMDiS { namespace Parallel { namespace AMDiS { namespace Parallel {
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
...@@ -89,7 +75,8 @@ namespace AMDiS { namespace Parallel { ...@@ -89,7 +75,8 @@ namespace AMDiS { namespace Parallel {
deltaKMatrixSolver(NULL), deltaKMatrixSolver(NULL),
useOldInitialGuess(false), useOldInitialGuess(false),
eps(epsPtr), eps(epsPtr),
delta(deltaPtr) { delta(deltaPtr)
{
Parameters::get(initFileStr + "->use old initial guess", useOldInitialGuess); Parameters::get(initFileStr + "->use old initial guess", useOldInitialGuess);
} }
...@@ -120,15 +107,15 @@ namespace AMDiS { namespace Parallel { ...@@ -120,15 +107,15 @@ namespace AMDiS { namespace Parallel {
void PetscSolverCahnHilliard::initSolver(KSP &ksp) void PetscSolverCahnHilliard::initSolver(KSP &ksp)
{ {
FUNCNAME("PetscSolverCahnHilliard::initSolver()");
// Create FGMRES based outer solver // Create FGMRES based outer solver
KSPCreate(meshDistributor->getMpiComm(0), &ksp); KSPCreate(meshDistributor->getMpiComm(0), &ksp);
KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN); KSPSetOperators(ksp, getMatInterior(), getMatInterior(), SAME_NONZERO_PATTERN);
if (getInfo() >= 10)
KSPMonitorSet(ksp, KSPMonitorDefault, PETSC_NULL, PETSC_NULL);
else if (getInfo() >= 20)
KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL); KSPMonitorSet(ksp, KSPMonitorTrueResidualNorm, PETSC_NULL, PETSC_NULL);
petsc_helper::setSolver(ksp, "ch_", KSPFGMRES, PCNONE, 1e-6, 1e-8, 1000); petsc_helper::setSolver(ksp, "ch_", KSPFGMRES, PCNONE, getRelative(), getTolerance(), getMaxIterations());
KSPSetFromOptions(ksp); KSPSetFromOptions(ksp);
} }
...@@ -137,6 +124,8 @@ namespace AMDiS { namespace Parallel { ...@@ -137,6 +124,8 @@ namespace AMDiS { namespace Parallel {
FUNCNAME("PetscSolverCahnHilliard::initPreconditioner()"); FUNCNAME("PetscSolverCahnHilliard::initPreconditioner()");
MSG("PetscSolverCahnHilliard::initPreconditioner()\n"); MSG("PetscSolverCahnHilliard::initPreconditioner()\n");
TEST_EXIT(eps && delta)("eps and/or delta pointers not set!\n");
// KSPSetUp(kspInterior); // KSPSetUp(kspInterior);
PCSetType(pc, PCSHELL); PCSetType(pc, PCSHELL);
...@@ -155,14 +144,13 @@ namespace AMDiS { namespace Parallel { ...@@ -155,14 +144,13 @@ namespace AMDiS { namespace Parallel {
DOFMatrix deltaKMatrix(feSpace, feSpace); DOFMatrix deltaKMatrix(feSpace, feSpace);
Operator laplaceOp2(feSpace, feSpace); Operator laplaceOp2(feSpace, feSpace);
if (phase) if (phase) {
{
VecAtQP_ZOT zot(phase, NULL); VecAtQP_ZOT zot(phase, NULL);
massOp.addTerm(&zot); massOp.addTerm(&zot);
laplaceOp.addTerm(&zot); // M laplaceOp.addTerm(&zot); // M
VecAtQP_SOT sot2(phase, new Multiplier((*eps)*sqrt(*delta))); VecAtQP_SOT sot2(phase, NULL, (*eps)*sqrt(*delta));
laplaceOp.addTerm(&sot2); // eps*sqrt(delta)*K laplaceOp.addTerm(&sot2); // eps*sqrt(delta)*K
VecAtQP_SOT sot(phase, new Multiplier(-(*delta))); VecAtQP_SOT sot(phase, NULL, -(*delta));
laplaceOp2.addTerm(&sot); // -delta*K laplaceOp2.addTerm(&sot); // -delta*K
massMatrix.assembleOperator(massOp); massMatrix.assembleOperator(massOp);
massMatrixSolver = createSubSolver(0, "mass_"); massMatrixSolver = createSubSolver(0, "mass_");
...@@ -173,16 +161,13 @@ namespace AMDiS { namespace Parallel { ...@@ -173,16 +161,13 @@ namespace AMDiS { namespace Parallel {
laplaceMatrixSolver = createSubSolver(0, "laplace_"); laplaceMatrixSolver = createSubSolver(0, "laplace_");
laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix); laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix);
// === matrix (-delta*K) === // === matrix (-delta*K) ===
deltaKMatrix.assembleOperator(laplaceOp2); deltaKMatrix.assembleOperator(laplaceOp2);
deltaKMatrixSolver = createSubSolver(0, "laplace2_"); deltaKMatrixSolver = createSubSolver(0, "laplace2_");
deltaKMatrixSolver->fillPetscMatrix(&deltaKMatrix); deltaKMatrixSolver->fillPetscMatrix(&deltaKMatrix);
} } else {
else
{
Simple_ZOT zot; Simple_ZOT zot;
massOp.addTerm(&zot); massOp.addTerm(&zot);
laplaceOp.addTerm(&zot); // M laplaceOp.addTerm(&zot); // M
...@@ -200,7 +185,6 @@ namespace AMDiS { namespace Parallel { ...@@ -200,7 +185,6 @@ namespace AMDiS { namespace Parallel {
laplaceMatrixSolver = createSubSolver(0, "laplace_"); laplaceMatrixSolver = createSubSolver(0, "laplace_");
laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix); laplaceMatrixSolver->fillPetscMatrix(&laplaceMatrix);
// === matrix (-delta*K) === // === matrix (-delta*K) ===
deltaKMatrix.assembleOperator(laplaceOp2); deltaKMatrix.assembleOperator(laplaceOp2);
deltaKMatrixSolver = createSubSolver(0, "laplace2_"); deltaKMatrixSolver = createSubSolver(0, "laplace2_");
...@@ -228,7 +212,7 @@ namespace AMDiS { namespace Parallel { ...@@ -228,7 +212,7 @@ namespace AMDiS { namespace Parallel {
// 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, 2);
// 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;
......
...@@ -63,7 +63,7 @@ namespace AMDiS { namespace Parallel { ...@@ -63,7 +63,7 @@ namespace AMDiS { namespace Parallel {
void setChData(double *epsPtr, double *deltaPtr, SystemVector* vec, DOFVector<double> *p=NULL) void setChData(double *epsPtr, double *deltaPtr, SystemVector* vec, DOFVector<double> *p=NULL)
{ {
eps = epsPtr; eps = epsPtr;
delta = deltaPtr; delta = deltaPtr; // sqrt(tau)
solution = vec; solution = vec;
phase = p; phase = p;
} }
......
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