Commit a21c01e0 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

BaseProblems updated and some Warnings removed

parent 57117087
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
#include "time/RosenbrockStationary.h" #include "time/RosenbrockStationary.h"
#include "CouplingTimeInterface.h" #include "CouplingTimeInterface.h"
#include "VtuReader.h" #include "VtuReader.h"
#include "pugixml.hpp"
using namespace AMDiS; using namespace AMDiS;
const Flag MESH_ADOPTED = 1<<2; const Flag MESH_ADOPTED = 1<<2;
const Flag DATA_ADOPTED = 1<<3; const Flag DATA_ADOPTED = 1<<3;
template<typename ProblemType=ProblemStat> template<typename ProblemType=ProblemStat, bool safeguard = false>
class BaseProblem : public ProblemIterationInterface, class BaseProblem : public ProblemIterationInterface,
public ProblemInstatBase public ProblemInstatBase
{ {
...@@ -163,14 +164,13 @@ public: ...@@ -163,14 +164,13 @@ public:
/// for rosenbrock-problems a special time-operator can be added /// for rosenbrock-problems a special time-operator can be added
void addTimeOperator(RosenbrockStationary *prob, int i, int j); void addTimeOperator(RosenbrockStationary *prob, int i, int j);
template<typename T>
static void initFileWriterFromFile(AdaptInfo* adaptInfo, FileWriterTemplated<T>& fileWriter, bool keep_all = false);
protected: protected:
ProblemType *prob; ProblemType *prob;
/// catch errors and exceptions in solve-block and continue with last iteration on failure
/// standard: false
bool secureIteration;
/// dimension of the mesh (set in \ref initialize(...) ) /// dimension of the mesh (set in \ref initialize(...) )
unsigned dim; unsigned dim;
......
using namespace AMDiS; using namespace AMDiS;
template<typename ProblemType> template<typename ProblemType, bool safeguard>
BaseProblem<ProblemType>::BaseProblem(const std::string &name_, bool createProblem) BaseProblem<ProblemType, safeguard>::BaseProblem(const std::string &name_, bool createProblem)
: ProblemInstatBase(name_,NULL), : ProblemInstatBase(name_,NULL),
prob(NULL), prob(NULL),
secureIteration(false),
dim(1), dim(1),
dow(1), dow(1),
nTimesteps(-1), nTimesteps(-1),
...@@ -16,13 +15,11 @@ BaseProblem<ProblemType>::BaseProblem(const std::string &name_, bool createProbl ...@@ -16,13 +15,11 @@ BaseProblem<ProblemType>::BaseProblem(const std::string &name_, bool createProbl
prob = new ProblemType(name + "->space"); prob = new ProblemType(name + "->space");
dow = Global::getGeo(WORLD); dow = Global::getGeo(WORLD);
Initfile::get(name + "->secure iteration", secureIteration);
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::initialize(Flag initFlag, void BaseProblem<ProblemType, safeguard>::initialize(Flag initFlag,
ProblemStat *adoptProblem, ProblemStat *adoptProblem,
Flag adoptFlag) Flag adoptFlag)
{ FUNCNAME("BaseProblem::initialize()"); { FUNCNAME("BaseProblem::initialize()");
...@@ -34,8 +31,8 @@ void BaseProblem<ProblemType>::initialize(Flag initFlag, ...@@ -34,8 +31,8 @@ void BaseProblem<ProblemType>::initialize(Flag initFlag,
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) Flag BaseProblem<ProblemType, safeguard>::initDataFromFile(AdaptInfo *adaptInfo)
{ {
FUNCNAME("BaseProblem::initDataFromFile()"); FUNCNAME("BaseProblem::initDataFromFile()");
...@@ -53,7 +50,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -53,7 +50,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
// read data and mesh from arh-files/dat-files // read data and mesh from arh-files/dat-files
MSG("read data from file...\n"); MSG("read data from file...\n");
if (readFormat == "arh") { if (readFormat == "arh")
{
std::string filename = ""; std::string filename = "";
Initfile::get(name + "->value file", filename); Initfile::get(name + "->value file", filename);
if (filename.size() == 0) return initFlag; if (filename.size() == 0) return initFlag;
...@@ -65,7 +63,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -65,7 +63,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
solutions.push_back(prob->getSolution()->getDOFVector(i)); solutions.push_back(prob->getSolution()->getDOFVector(i));
ArhReader::read(filename, prob->getMesh(), solutions); ArhReader::read(filename, prob->getMesh(), solutions);
} }
else if (readFormat == "dat") { else if (readFormat == "dat")
{
bool preserveMacroFileInfo = false; bool preserveMacroFileInfo = false;
Parameters::get(prob->getMesh()->getName() + "->preserve macroFileInfo", preserveMacroFileInfo); Parameters::get(prob->getMesh()->getName() + "->preserve macroFileInfo", preserveMacroFileInfo);
if (prob->getMesh()->getMacroFileInfo() == NULL || !preserveMacroFileInfo) if (prob->getMesh()->getMacroFileInfo() == NULL || !preserveMacroFileInfo)
...@@ -79,7 +78,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -79,7 +78,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
ValueReader::readValue(filename,prob->getMesh(),prob->getSolution()->getDOFVector(i),prob->getMesh()->getMacroFileInfo()); ValueReader::readValue(filename,prob->getMesh(),prob->getSolution()->getDOFVector(i),prob->getMesh()->getMacroFileInfo());
} }
} }
else if (readFormat == "vtu") { else if (readFormat == "vtu")
{
std::vector<std::string> filenames; std::vector<std::string> filenames;
Initfile::get(name + "->value file", filenames); Initfile::get(name + "->value file", filenames);
if (filenames.size() == 0) if (filenames.size() == 0)
...@@ -115,7 +115,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -115,7 +115,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
} else } else
throw(std::runtime_error("You have to specify a .vtu file!")); throw(std::runtime_error("You have to specify a .vtu file!"));
} }
else if (readFormat == "multi-vtu") { else if (readFormat == "multi-vtu")
{
size_t numFiles = 0; size_t numFiles = 0;
Initfile::get(name + "->number of files", numFiles); Initfile::get(name + "->number of files", numFiles);
for (size_t n = 0; n < numFiles; n++) { for (size_t n = 0; n < numFiles; n++) {
...@@ -159,6 +160,17 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -159,6 +160,17 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
throw(std::runtime_error("Parameter 'read data from file' set to 'true', but no parameter 'read format' specified!")); throw(std::runtime_error("Parameter 'read data from file' set to 'true', but no parameter 'read format' specified!"));
} }
bool readPvdFromFile = false;
Initfile::get(name + "->read pvd from file", readPvdFromFile, 2);
if (readPvdFromFile) {
vector<FileWriterInterface*>& fileWriters = prob->getFileWriterList();
for (size_t i = 0; i < fileWriters.size(); i++) {
FileWriterTemplated<double>* fileWriter = dynamic_cast<FileWriterTemplated<double>*>(fileWriters[i]);
if (fileWriter)
initFileWriterFromFile(adaptInfo, *fileWriter);
}
}
initFlag.setFlag(DATA_ADOPTED); initFlag.setFlag(DATA_ADOPTED);
initFlag.setFlag(MESH_ADOPTED); initFlag.setFlag(MESH_ADOPTED);
...@@ -166,8 +178,36 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo) ...@@ -166,8 +178,36 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::beginIteration(AdaptInfo *adaptInfo) template<typename T>
void BaseProblem<ProblemType, safeguard>::initFileWriterFromFile(AdaptInfo* adaptInfo, FileWriterTemplated<T>& fileWriter, bool keep_all)
{
using namespace pugi;
if(!boost::filesystem::exists(fileWriter.getFilename() + ".pvd"))
return;
xml_document vtu;
if(!vtu.load_file((fileWriter.getFilename() + ".pvd").c_str()))
throw(std::runtime_error("Could not load pvd file! Error in xml structure."));
xml_node VTKFile = vtu.child("VTKFile");
xml_node Collection = VTKFile.child("Collection");
std::vector<std::pair<double, std::string> >& paraviewAnimationFrames = fileWriter.getParaviewAnimationFrames();
for (xml_node DataSet = Collection.child("DataSet"); DataSet; DataSet = DataSet.next_sibling("DataSet")) {
std::string timestepStr = DataSet.attribute("timestep").value();
std::string fileStr = DataSet.attribute("file").value();
double time = boost::lexical_cast<double>(timestepStr);
if (keep_all || time <= adaptInfo->getStartTime())
paraviewAnimationFrames.push_back(std::make_pair(time, fileStr));
}
}
template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType, safeguard>::beginIteration(AdaptInfo *adaptInfo)
{ FUNCNAME("BaseProblem::beginIteration()"); { FUNCNAME("BaseProblem::beginIteration()");
MSG("\n"); MSG("\n");
...@@ -190,8 +230,8 @@ void BaseProblem<ProblemType>::beginIteration(AdaptInfo *adaptInfo) ...@@ -190,8 +230,8 @@ void BaseProblem<ProblemType>::beginIteration(AdaptInfo *adaptInfo)
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo, Flag BaseProblem<ProblemType, safeguard>::oneIteration(AdaptInfo *adaptInfo,
Flag toDo) Flag toDo)
{ {
FUNCNAME("BaseProblem::oneIteration()"); FUNCNAME("BaseProblem::oneIteration()");
...@@ -220,7 +260,7 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo, ...@@ -220,7 +260,7 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo,
#endif #endif
if (toDo.isSet(SOLVE)) { if (toDo.isSet(SOLVE)) {
if (secureIteration) { if (safeguard) {
try { try {
prob->solve(adaptInfo); prob->solve(adaptInfo);
} catch(std::exception &e) { } catch(std::exception &e) {
...@@ -250,8 +290,8 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo, ...@@ -250,8 +290,8 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo,
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::endIteration(AdaptInfo *adaptInfo) void BaseProblem<ProblemType, safeguard>::endIteration(AdaptInfo *adaptInfo)
{ FUNCNAME("BaseProblem::endIteration()"); { FUNCNAME("BaseProblem::endIteration()");
MSG("\n"); MSG("\n");
...@@ -259,20 +299,15 @@ void BaseProblem<ProblemType>::endIteration(AdaptInfo *adaptInfo) ...@@ -259,20 +299,15 @@ void BaseProblem<ProblemType>::endIteration(AdaptInfo *adaptInfo)
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::closeTimestep(AdaptInfo *adaptInfo) void BaseProblem<ProblemType, safeguard>::closeTimestep(AdaptInfo *adaptInfo)
{ {
int outputPeriod = 1; writeFiles(adaptInfo, false);
Initfile::get("user parameter->write every ith timestep", outputPeriod);
if (adaptInfo->getTimestepNumber() % outputPeriod == 0
&& adaptInfo->getStartTime() < adaptInfo->getEndTime()) {
writeFiles(adaptInfo, false);
}
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::addTimeOperator(ProblemStat *prob, int i, int j) void BaseProblem<ProblemType, safeguard>::addTimeOperator(ProblemStat *prob, int i, int j)
{ {
Operator *op = new Operator(prob->getFeSpace(i), prob->getFeSpace(j)); Operator *op = new Operator(prob->getFeSpace(i), prob->getFeSpace(j));
op->addZeroOrderTerm(new Simple_ZOT); op->addZeroOrderTerm(new Simple_ZOT);
...@@ -284,8 +319,8 @@ void BaseProblem<ProblemType>::addTimeOperator(ProblemStat *prob, int i, int j) ...@@ -284,8 +319,8 @@ void BaseProblem<ProblemType>::addTimeOperator(ProblemStat *prob, int i, int j)
} }
template<typename ProblemType> template<typename ProblemType, bool safeguard>
void BaseProblem<ProblemType>::addTimeOperator(RosenbrockStationary *prob, int i, int j) void BaseProblem<ProblemType, safeguard>::addTimeOperator(RosenbrockStationary *prob, int i, int j)
{ {
prob->addTimeOperator(i,j); prob->addTimeOperator(i,j);
} }
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