#include "ProblemInstat.h" #include "FileWriter.h" #include "AdaptStationary.h" #include "AdaptInstationary.h" #include "Estimator.h" #include "ProblemScal.h" #include "StandardProblemIteration.h" namespace AMDiS { ProblemInstat::~ProblemInstat() {} void ProblemInstat::initialize(Flag initFlag, ProblemInstat *adoptProblem/* = NULL*/, Flag adoptFlag /* = INIT_NOTHING*/) {} void ProblemInstat::solveInitialProblem(AdaptInfo *adaptInfo) { AdaptStationary initialAdapt((name + "->initial->adapt").c_str(), new StandardProblemIteration(initialProblem), adaptInfo); initialAdapt.adapt(); } void ProblemInstatScal::transferInitialSolution(AdaptInfo *adaptInfo) { TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime()) ("after initial solution: time != start time\n"); problemStat->writeFiles(adaptInfo, true); } void ProblemInstatVec::transferInitialSolution(AdaptInfo *adaptInfo) { TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime()) ("after initial solution: time != start time\n"); problemStat->writeFiles(adaptInfo, true); } ProblemInstatScal::ProblemInstatScal(std::string sname, ProblemScal *prob, ProblemStatBase *initialProb) : ProblemInstat(sname, initialProb), problemStat(prob), oldSolution(NULL) {} ProblemInstatScal::ProblemInstatScal(std::string sname, ProblemScal& prob) : ProblemInstat(sname, NULL), problemStat(&prob), oldSolution(NULL) {} ProblemInstatScal::ProblemInstatScal(std::string sname, ProblemScal& prob, ProblemStatBase& initialProb) : ProblemInstat(sname, &initialProb), problemStat(&prob), oldSolution(NULL) {} ProblemInstatScal::~ProblemInstatScal() { delete oldSolution; } void ProblemInstatScal::initialize(Flag initFlag, ProblemInstat *adoptProblem, Flag adoptFlag) { FUNCNAME("ProblemInstat::initialize()"); ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag); // === create vector for old solution === if (oldSolution) { WARNING("oldSolution already created\n"); } else { if (initFlag.isSet(INIT_UH_OLD)) createUhOld(); if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) { ProblemInstatScal* _adoptProblem = dynamic_cast(adoptProblem); TEST_EXIT(_adoptProblem) ("can't adopt oldSolution from problem which is not instationary and scalar"); TEST_EXIT(!oldSolution)("oldSolution already created"); oldSolution = _adoptProblem->getOldSolution(); } } if (!oldSolution) WARNING("no oldSolution created\n"); } void ProblemInstatScal::createUhOld() { if (oldSolution) { WARNING("oldSolution already created\n"); } else { // create oldSolution oldSolution = new DOFVector(problemStat->getFESpace(), name + "->uOld"); oldSolution->setCoarsenOperation(COARSE_INTERPOL); if (problemStat->getEstimator()) dynamic_cast(problemStat->getEstimator()) ->addUhOldToSystem(0, oldSolution); } } void ProblemInstatScal::closeTimestep(AdaptInfo *adaptInfo) { bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime()); problemStat->writeFiles(adaptInfo, force); } void ProblemInstatVec::closeTimestep(AdaptInfo *adaptInfo) { bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime()); problemStat->writeFiles(adaptInfo, force); } ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec *prob, ProblemStatBase *initialProb) : ProblemInstat(sname, initialProb), problemStat(prob), oldSolution(NULL) {} ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec &prob) : ProblemInstat(sname, NULL), problemStat(&prob), oldSolution(NULL) {} ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec &prob, ProblemStatBase &initialProb) : ProblemInstat(sname, &initialProb), problemStat(&prob), oldSolution(NULL) {} ProblemInstatVec::~ProblemInstatVec() { delete oldSolution; } void ProblemInstatVec::initialize(Flag initFlag, ProblemInstat *adoptProblem, Flag adoptFlag) { FUNCNAME("ProblemInstatVec::initialize()"); ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag); // === create vector for old solution === if (oldSolution) { WARNING("oldSolution already created\n"); } else { if (initFlag.isSet(INIT_UH_OLD)) createUhOld(); if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) { ProblemInstatVec* _adoptProblem = dynamic_cast(adoptProblem); TEST_EXIT(_adoptProblem) ("can't adopt oldSolution from problem which is not instationary and vectorial"); TEST_EXIT(!oldSolution)("oldSolution already created"); oldSolution = _adoptProblem->getOldSolution(); } } if (!oldSolution) WARNING("no oldSolution created\n"); } void ProblemInstatVec::createUhOld() { if (oldSolution) { WARNING("oldSolution already created\n"); } else { int size = problemStat->getNumComponents(); // create oldSolution oldSolution = new SystemVector("old solution", problemStat->getFESpaces(), size); for (int i = 0; i < size; i++) { oldSolution->setDOFVector(i, new DOFVector(problemStat->getFESpace(i), name + "->uOld")); oldSolution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL); if (problemStat->getEstimator(i)) problemStat->getEstimator(i)-> addUhOldToSystem(i, oldSolution->getDOFVector(i)); } } } void ProblemInstatScal::initTimestep(AdaptInfo *adaptInfo) { oldSolution->copy(*(problemStat->getSolution())); } void ProblemInstatVec::initTimestep(AdaptInfo *adaptInfo) { oldSolution->copy(*(problemStat->getSolution())); } }