#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::~ProblemInstat() { } void ProblemInstat::initialize(Flag initFlag, ProblemInstat *adoptProblem/* = NULL*/, Flag adoptFlag /* = INIT_NOTHING*/) { FUNCNAME("ProblemInstat::initialize()"); } 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(char* name_, ProblemScal *prob, ProblemStatBase *initialProb) : ProblemInstat(name_, initialProb), problemStat(prob),oldSolution(NULL) {}; ProblemInstatScal::~ProblemInstatScal() { DELETE oldSolution; } void ProblemInstatScal::initialize(Flag initFlag, ProblemInstat *adoptProblem/* = NULL*/, Flag adoptFlag /* = INIT_NOTHING*/) { 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->refineInterpol(true); 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(char* name_, ProblemVec *prob, ProblemStatBase *initialProb) : ProblemInstat(name_, initialProb), problemStat(prob),oldSolution(NULL) {}; ProblemInstatVec::~ProblemInstatVec() { DELETE oldSolution; } void ProblemInstatVec::initialize(Flag initFlag, ProblemInstat *adoptProblem/* = NULL*/, Flag adoptFlag /* = INIT_NOTHING*/) { 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)->refineInterpol(true); 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())); } void ProblemInstatScal::startDelayedTimestepCalculation() { problemStat->writeDelayedFiles(); } void ProblemInstatVec::startDelayedTimestepCalculation() { problemStat->writeDelayedFiles(); } bool ProblemInstatScal::existsDelayedCalculation() { return problemStat->existsDelayedCalculation(); } bool ProblemInstatVec::existsDelayedCalculation() { return problemStat->existsDelayedCalculation(); } }