Commit 3df2f6cc authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

cahn-hilliard demo

parent 042e5dfb
#include "AMDiS.h"
#include "CouplingTimeInterface.h"
#include "Refinement.h"
#include "MeshFunction_Level.h"
#include "CahnHilliard.h"
#include "Views.h"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace AMDiS;
using namespace boost::posix_time;
class RefinementTimeInterface : public CouplingTimeInterface
{
public:
RefinementTimeInterface(CahnHilliard *chProb_) :
chProb(chProb_),
refFunction(NULL),
refinement(NULL)
{
addTimeInterface(chProb);
}
~RefinementTimeInterface()
{
if (refFunction)
delete refFunction;
if (refinement)
delete refinement;
}
virtual void initTimeInterface()
{
chProb->initTimeInterface();
}
/// Called at the end of each timestep.
virtual void closeTimestep(AdaptInfo *adaptInfo)
{
CouplingTimeInterface::closeTimestep(adaptInfo);
refinement->refine(2);
}
/// Set initial condition and perform initial refinement
virtual void solveInitialProblem(AdaptInfo *adaptInfo)
{
refFunction= new PhaseFieldRefinement(chProb->getMesh());
refinement= new RefinementLevelDOF(
chProb->getProblem(0)->getFeSpace(),
refFunction,
new PhaseDOFView<double>(chProb->getProblem(0)->getSolution()->getDOFVector(0)));
// initial refinement
refinement->refine(0);
// refine until interfaces is solved
for (int i = 0; i < 3; ++i) {
chProb->solveInitialProblem(adaptInfo);
refinement->refine((i < 4 ? 4 : 10));
}
CouplingTimeInterface::solveInitialProblem(adaptInfo);
}
protected:
CahnHilliard *chProb;
PhaseFieldRefinement* refFunction;
RefinementLevelDOF *refinement;
};
int main(int argc, char** argv)
{ FUNCNAME("main");
AMDiS::init(argc, argv);
CahnHilliard chProb("ch");
chProb.initialize(INIT_ALL);
RefinementTimeInterface timeInterface(&chProb);
// Adapt-Infos
AdaptInfo adaptInfo("adapt", chProb.getNumComponents());
AdaptInstationary adaptInstat("adapt", chProb, adaptInfo, timeInterface, adaptInfo);
ptime start_time = microsec_clock::local_time();
timeInterface.initTimeInterface(); // fill operators and BC
int error_code = adaptInstat.adapt();
time_duration td = microsec_clock::local_time()-start_time;
MSG("elapsed time= %d sec\n", td.total_seconds());
AMDiS::finalize();
return error_code;
};
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