added: store time step info in the XML

this allows for setting time in the HDF5toVTF converter.
note this currently only supports a fixed step size, variable
steps will have to be stored in the HDF5 file when we need it

git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1060 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
akva 2011-06-16 13:00:36 +00:00 committed by Knut Morten Okstad
parent 5db0af6a64
commit b5dc82285f
8 changed files with 53 additions and 7 deletions

View File

@ -219,10 +219,10 @@ int main (int argc, char** argv)
bool ok = true;
int block = 0;
for (int i = 0; i <= levels && ok; i+= skip) {
if (levels > 0) std::cout <<"\nTime level "<< i << std::endl;
double time=0;
for (int i = 0; i <= levels && ok; i += skip) {
if (levels > 0) std::cout <<"\nTime level "<< i << " (t=" << time << ")" << std::endl;
VTFList vlist, slist;
pit = processlist.begin();
for (pit = processlist.begin(); pit != processlist.end(); ++pit) {
for (it = pit->second.begin(); it != pit->second.end() && ok; ++it) {
std::cout <<"Reading \""<< it->name <<"\""<< std::endl;
@ -259,9 +259,11 @@ int main (int argc, char** argv)
writeFieldBlocks(vlist,slist,myVtf,i+1);
if (ok)
myVtf.writeState(i+1,"Step %g",(float)(i+skip)/skip,1);
myVtf.writeState(i+1,"Time %g",time,0);
else
return 3;
pit = processlist.begin();
time += pit->second.begin()->timestep*skip;
}
hdf.closeFile(levels,true);

View File

@ -33,6 +33,9 @@ bool SIMparameters::increment ()
if (time.t+time.dt*epsT >= stopTime)
return false;
if (tInc.size() <= (size_t)step)
tInc.push_back(time.dt);
time.t += time.dt;
if (time.t > stopTime)
@ -40,6 +43,7 @@ bool SIMparameters::increment ()
// Adjust the size of the last time step
time.dt += stopTime - time.t;
time.t = stopTime;
tInc.back() = time.dt;
}
return true;

View File

@ -6,6 +6,7 @@
#ifdef PARALLEL_PETSC
#include <mpi.h>
#endif
#include "SIMparameters.h"
DataWriter::DataWriter (const std::string& name) : m_name(name)
@ -65,7 +66,7 @@ bool DataExporter::setFieldValue(const std::string& name,
}
bool DataExporter::dumpTimeLevel()
bool DataExporter::dumpTimeLevel(SIMparameters* tp)
{
if (m_level == -1)
m_level = this->getWritersTimeLevel()+1;
@ -90,6 +91,8 @@ bool DataExporter::dumpTimeLevel()
break;
}
}
if (tp)
(*it2)->writeTimeInfo(m_level,*tp);
(*it2)->closeFile(m_level);
}
m_level++;

View File

@ -8,6 +8,7 @@
class DataWriter;
class SIMparameters;
class DataExporter
{
@ -45,7 +46,7 @@ class DataExporter
bool setFieldValue(const std::string& name, void* data, void* data2=NULL);
bool dumpTimeLevel();
bool dumpTimeLevel(SIMparameters* tp=NULL);
//! \brief Loads last time level with first registered writer by default.
//! param[in] level Time level to load, defaults to last time level
@ -84,6 +85,8 @@ public:
virtual void writeSIM(int level, const DataEntry& entry) = 0;
virtual bool readSIM(int level, const DataEntry& entry) = 0;
virtual bool writeTimeInfo(int level, SIMparameters& tp) = 0;
protected:
std::string m_name; //!< File name

View File

@ -2,6 +2,7 @@
#include "HDF5Writer.h"
#include "SIMbase.h"
#include "SIMparameters.h"
#include "IntegrandBase.h"
#include <sstream>
#include <sys/stat.h>
@ -372,3 +373,10 @@ bool HDF5Writer::checkGroupExistence(int parent, const char* path)
#endif
return result;
}
// TODO: implement for variable timesteps
// (named time series to allow different timelevels for different fields)
bool HDF5Writer::writeTimeInfo(int level, SIMparameters& tp)
{
return true;
}

View File

@ -23,6 +23,7 @@ public:
virtual bool readVector(int level, const DataEntry& entry);
virtual void writeSIM(int level, const DataEntry& entry);
virtual bool readSIM(int level, const DataEntry& entry);
virtual bool writeTimeInfo(int level, SIMparameters& tp);
bool readField(int level, const std::string& name,
Vector& vec, SIMbase* sim, int components);

View File

@ -2,6 +2,7 @@
#include "XMLWriter.h"
#include "SIMbase.h"
#include "SIMparameters.h"
#include "IntegrandBase.h"
#include "StringUtils.h"
#include "tinyxml.h"
@ -13,6 +14,7 @@ XMLWriter::XMLWriter(const std::string& name) : DataWriter(name+".xml")
{
m_doc = NULL;
m_node = NULL;
m_dt = 0;
}
@ -48,11 +50,19 @@ void XMLWriter::closeFile(int level, bool close)
TiXmlElement element2("levels");
TiXmlNode *pNewNode = m_node->InsertEndChild(element2);
char temp[8];
char temp[32];
sprintf(temp,"%i",level);
TiXmlText value(temp);
pNewNode->InsertEndChild(value);
// TODO: support variable time steps
TiXmlElement element3("timestep");
element3.Attribute("constant",&m_dt);
pNewNode = m_node->InsertEndChild(element3);
sprintf(temp,"%f",m_dt);
TiXmlText value2(temp);
pNewNode->InsertEndChild(value2);
m_doc->SaveFile(m_name);
delete m_doc;
m_doc = NULL;
@ -66,6 +76,7 @@ void XMLWriter::readInfo()
TiXmlHandle handle(&doc);
TiXmlElement* elem = handle.FirstChild("info").
FirstChild("entry").ToElement();
TiXmlElement* timestep = handle.FirstChild("info").FirstChild("timestep").ToElement();
while (elem) {
if (strcasecmp(elem->Attribute("type"),"field") == 0) {
Entry entry;
@ -74,6 +85,10 @@ void XMLWriter::readInfo()
entry.patches = atoi(elem->Attribute("patches"));
entry.components = atoi(elem->Attribute("components"));
entry.type = elem->Attribute("type");
if (timestep)
entry.timestep = atof(timestep->FirstChild()->Value());
else
entry.timestep = 0;
if (elem->Attribute("basis"))
entry.basis = elem->Attribute("basis");
m_entry.push_back(entry);
@ -159,3 +174,9 @@ void XMLWriter::addField (const std::string& name,
element.SetAttribute("components",components);
m_node->InsertEndChild(element);
}
bool XMLWriter::writeTimeInfo(int level, SIMparameters& tp)
{
m_dt = tp.time.dt;
return true;
}

View File

@ -6,6 +6,7 @@
class TiXmlDocument;
class TiXmlNode;
class SIMparameters;
class XMLWriter : public DataWriter
@ -17,6 +18,7 @@ public:
std::string basis;
int patches;
int components;
double timestep;
std::string type;
};
@ -35,6 +37,7 @@ public:
virtual bool readVector(int level, const DataEntry& entry);
virtual void writeSIM(int level, const DataEntry& entry);
virtual bool readSIM(int level, const DataEntry& entry);
virtual bool writeTimeInfo(int level, SIMparameters& tp);
protected:
void addField(const std::string& name, const std::string& description,
@ -45,4 +48,5 @@ protected:
TiXmlDocument* m_doc;
TiXmlNode* m_node;
double m_dt;
};