/** \file BaseProblem.h */ #ifndef BASE_PROBLEM_H #define BASE_PROBLEM_H #include "AMDiS.h" #include "time/RosenbrockStationary.h" #include "CouplingTimeInterface.h" #include "VtuReader.h" #include "pugixml.hpp" using namespace AMDiS; const Flag MESH_ADOPTED = 1<<2; const Flag DATA_ADOPTED = 1<<3; template class BaseProblem : public ProblemIterationInterface, public ProblemInstatBase { public: BaseProblem(const std::string &name_, bool createProblem = true); ~BaseProblem() { if (prob) delete prob; } /// Initialisation of the problem. void initialize(Flag initFlag, ProblemStat *adoptProblem = NULL, Flag adoptFlag = INIT_NOTHING); /// Initialisation of DOFVectors and AbstractFunctions, /// is called in \ref initTimeInteface after feSpace and mesh are initialized virtual void initData() {}; /// calls \ref initData, \ref fillOperators and \ref fillBoundaryConditions in this ordering virtual void initTimeInterface() { initData(); fillOperators(); fillBoundaryConditions(); } /// read solution DOFVectors from .arh, .dat or .vtu files virtual Flag initDataFromFile(AdaptInfo *adaptInfo); /// calls \ref initDataFromFile virtual void solveInitialProblem(AdaptInfo *adaptInfo) { Flag initFlag = initDataFromFile(adaptInfo); } /// calls \ref writeFiles virtual void transferInitialSolution(AdaptInfo *adaptInfo) { oldMeshChangeIdx = getMesh()->getChangeIndex(); writeFiles(adaptInfo, false); } /// This method is called before \ref beginIteration, \ref oneIteration and \ref endIteration. virtual void initTimestep(AdaptInfo *adaptInfo) {} /// calls \ref writeFiles virtual void closeTimestep(AdaptInfo *adaptInfo); virtual void beginIteration(AdaptInfo *adaptInfo); virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION); virtual void endIteration(AdaptInfo *adaptInfo); /// Calls writeFiles of the problem virtual void writeFiles(AdaptInfo *adaptInfo, bool force) { prob->writeFiles(adaptInfo, force); } // getting methods /// pointer to the solution of the problem SystemVector *getSolution() { return prob->getSolution(); } /// pointer to the mesh of the problem inline Mesh* getMesh(int comp = 0) { return prob->getMesh(comp); } /// pointer to the feSpace of the problem inline const FiniteElemSpace* getFeSpace(int comp = 0) { return prob->getFeSpace(comp); } /// name of the baseBroblem std::string getName() { return name; } int getNumProblems() { return 1; } int getNumComponents() { return prob->getNumComponents(); } ProblemType *getProblem(int number = 0) { if (number < 0 || number >= getNumProblems()) throw(std::runtime_error("problem with given number does not exist")); if (number == 0) return prob; return NULL; } ProblemType *getProblem(std::string name) { if (name == "prob") return prob; else throw(std::runtime_error("problem with given name '" + name + "' does not exist")); } // setting methods void setAssembleMatrixOnlyOnce_butTimestepChange(int i, int j) { fixedMatrixTimestep.push_back(std::make_pair(i,j)); } void setNumberOfTimesteps(int nTimesteps_) { nTimesteps= nTimesteps_; } void serialize(std::ostream&) {} void deserialize(std::istream&) {} /// method where operators are added to the problem virtual void fillOperators() {} /// method where boundary conditions are added to the problem virtual void fillBoundaryConditions() {} /// classical backward-euler time-discretization void addTimeOperator(ProblemStat *prob, int i, int j); /// for rosenbrock-problems a special time-operator can be added void addTimeOperator(RosenbrockStationary *prob, int i, int j); template static void initFileWriterFromFile(AdaptInfo* adaptInfo, FileWriterTemplated& fileWriter, bool keep_all = false); protected: ProblemType *prob; /// dimension of the mesh (set in \ref initialize(...) ) unsigned dim; /// dimension of world (set in constructur) unsigned dow; int nTimesteps; int oldMeshChangeIdx; double oldTimestep; private: std::vector > fixedMatrixTimestep; }; #include "BaseProblem.hh" typedef BaseProblem StandardBaseProblem; #endif // BASE_PROBLEM_H