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:
parent
5db0af6a64
commit
b5dc82285f
@ -219,10 +219,10 @@ int main (int argc, char** argv)
|
|||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
int block = 0;
|
int block = 0;
|
||||||
for (int i = 0; i <= levels && ok; i+= skip) {
|
double time=0;
|
||||||
if (levels > 0) std::cout <<"\nTime level "<< i << std::endl;
|
for (int i = 0; i <= levels && ok; i += skip) {
|
||||||
|
if (levels > 0) std::cout <<"\nTime level "<< i << " (t=" << time << ")" << std::endl;
|
||||||
VTFList vlist, slist;
|
VTFList vlist, slist;
|
||||||
pit = processlist.begin();
|
|
||||||
for (pit = processlist.begin(); pit != processlist.end(); ++pit) {
|
for (pit = processlist.begin(); pit != processlist.end(); ++pit) {
|
||||||
for (it = pit->second.begin(); it != pit->second.end() && ok; ++it) {
|
for (it = pit->second.begin(); it != pit->second.end() && ok; ++it) {
|
||||||
std::cout <<"Reading \""<< it->name <<"\""<< std::endl;
|
std::cout <<"Reading \""<< it->name <<"\""<< std::endl;
|
||||||
@ -259,9 +259,11 @@ int main (int argc, char** argv)
|
|||||||
writeFieldBlocks(vlist,slist,myVtf,i+1);
|
writeFieldBlocks(vlist,slist,myVtf,i+1);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
myVtf.writeState(i+1,"Step %g",(float)(i+skip)/skip,1);
|
myVtf.writeState(i+1,"Time %g",time,0);
|
||||||
else
|
else
|
||||||
return 3;
|
return 3;
|
||||||
|
pit = processlist.begin();
|
||||||
|
time += pit->second.begin()->timestep*skip;
|
||||||
}
|
}
|
||||||
hdf.closeFile(levels,true);
|
hdf.closeFile(levels,true);
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ bool SIMparameters::increment ()
|
|||||||
if (time.t+time.dt*epsT >= stopTime)
|
if (time.t+time.dt*epsT >= stopTime)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (tInc.size() <= (size_t)step)
|
||||||
|
tInc.push_back(time.dt);
|
||||||
|
|
||||||
time.t += time.dt;
|
time.t += time.dt;
|
||||||
|
|
||||||
if (time.t > stopTime)
|
if (time.t > stopTime)
|
||||||
@ -40,6 +43,7 @@ bool SIMparameters::increment ()
|
|||||||
// Adjust the size of the last time step
|
// Adjust the size of the last time step
|
||||||
time.dt += stopTime - time.t;
|
time.dt += stopTime - time.t;
|
||||||
time.t = stopTime;
|
time.t = stopTime;
|
||||||
|
tInc.back() = time.dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifdef PARALLEL_PETSC
|
#ifdef PARALLEL_PETSC
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "SIMparameters.h"
|
||||||
|
|
||||||
|
|
||||||
DataWriter::DataWriter (const std::string& name) : m_name(name)
|
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)
|
if (m_level == -1)
|
||||||
m_level = this->getWritersTimeLevel()+1;
|
m_level = this->getWritersTimeLevel()+1;
|
||||||
@ -90,6 +91,8 @@ bool DataExporter::dumpTimeLevel()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tp)
|
||||||
|
(*it2)->writeTimeInfo(m_level,*tp);
|
||||||
(*it2)->closeFile(m_level);
|
(*it2)->closeFile(m_level);
|
||||||
}
|
}
|
||||||
m_level++;
|
m_level++;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class DataWriter;
|
class DataWriter;
|
||||||
|
class SIMparameters;
|
||||||
|
|
||||||
class DataExporter
|
class DataExporter
|
||||||
{
|
{
|
||||||
@ -45,7 +46,7 @@ class DataExporter
|
|||||||
|
|
||||||
bool setFieldValue(const std::string& name, void* data, void* data2=NULL);
|
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.
|
//! \brief Loads last time level with first registered writer by default.
|
||||||
//! param[in] level Time level to load, defaults to last time level
|
//! 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 void writeSIM(int level, const DataEntry& entry) = 0;
|
||||||
virtual bool readSIM(int level, const DataEntry& entry) = 0;
|
virtual bool readSIM(int level, const DataEntry& entry) = 0;
|
||||||
|
|
||||||
|
virtual bool writeTimeInfo(int level, SIMparameters& tp) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_name; //!< File name
|
std::string m_name; //!< File name
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "HDF5Writer.h"
|
#include "HDF5Writer.h"
|
||||||
#include "SIMbase.h"
|
#include "SIMbase.h"
|
||||||
|
#include "SIMparameters.h"
|
||||||
#include "IntegrandBase.h"
|
#include "IntegrandBase.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -372,3 +373,10 @@ bool HDF5Writer::checkGroupExistence(int parent, const char* path)
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
virtual bool readVector(int level, const DataEntry& entry);
|
virtual bool readVector(int level, const DataEntry& entry);
|
||||||
virtual void writeSIM(int level, const DataEntry& entry);
|
virtual void writeSIM(int level, const DataEntry& entry);
|
||||||
virtual bool readSIM(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,
|
bool readField(int level, const std::string& name,
|
||||||
Vector& vec, SIMbase* sim, int components);
|
Vector& vec, SIMbase* sim, int components);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "XMLWriter.h"
|
#include "XMLWriter.h"
|
||||||
#include "SIMbase.h"
|
#include "SIMbase.h"
|
||||||
|
#include "SIMparameters.h"
|
||||||
#include "IntegrandBase.h"
|
#include "IntegrandBase.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "tinyxml.h"
|
#include "tinyxml.h"
|
||||||
@ -13,6 +14,7 @@ XMLWriter::XMLWriter(const std::string& name) : DataWriter(name+".xml")
|
|||||||
{
|
{
|
||||||
m_doc = NULL;
|
m_doc = NULL;
|
||||||
m_node = NULL;
|
m_node = NULL;
|
||||||
|
m_dt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,11 +50,19 @@ void XMLWriter::closeFile(int level, bool close)
|
|||||||
|
|
||||||
TiXmlElement element2("levels");
|
TiXmlElement element2("levels");
|
||||||
TiXmlNode *pNewNode = m_node->InsertEndChild(element2);
|
TiXmlNode *pNewNode = m_node->InsertEndChild(element2);
|
||||||
char temp[8];
|
char temp[32];
|
||||||
sprintf(temp,"%i",level);
|
sprintf(temp,"%i",level);
|
||||||
TiXmlText value(temp);
|
TiXmlText value(temp);
|
||||||
pNewNode->InsertEndChild(value);
|
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);
|
m_doc->SaveFile(m_name);
|
||||||
delete m_doc;
|
delete m_doc;
|
||||||
m_doc = NULL;
|
m_doc = NULL;
|
||||||
@ -66,6 +76,7 @@ void XMLWriter::readInfo()
|
|||||||
TiXmlHandle handle(&doc);
|
TiXmlHandle handle(&doc);
|
||||||
TiXmlElement* elem = handle.FirstChild("info").
|
TiXmlElement* elem = handle.FirstChild("info").
|
||||||
FirstChild("entry").ToElement();
|
FirstChild("entry").ToElement();
|
||||||
|
TiXmlElement* timestep = handle.FirstChild("info").FirstChild("timestep").ToElement();
|
||||||
while (elem) {
|
while (elem) {
|
||||||
if (strcasecmp(elem->Attribute("type"),"field") == 0) {
|
if (strcasecmp(elem->Attribute("type"),"field") == 0) {
|
||||||
Entry entry;
|
Entry entry;
|
||||||
@ -74,6 +85,10 @@ void XMLWriter::readInfo()
|
|||||||
entry.patches = atoi(elem->Attribute("patches"));
|
entry.patches = atoi(elem->Attribute("patches"));
|
||||||
entry.components = atoi(elem->Attribute("components"));
|
entry.components = atoi(elem->Attribute("components"));
|
||||||
entry.type = elem->Attribute("type");
|
entry.type = elem->Attribute("type");
|
||||||
|
if (timestep)
|
||||||
|
entry.timestep = atof(timestep->FirstChild()->Value());
|
||||||
|
else
|
||||||
|
entry.timestep = 0;
|
||||||
if (elem->Attribute("basis"))
|
if (elem->Attribute("basis"))
|
||||||
entry.basis = elem->Attribute("basis");
|
entry.basis = elem->Attribute("basis");
|
||||||
m_entry.push_back(entry);
|
m_entry.push_back(entry);
|
||||||
@ -159,3 +174,9 @@ void XMLWriter::addField (const std::string& name,
|
|||||||
element.SetAttribute("components",components);
|
element.SetAttribute("components",components);
|
||||||
m_node->InsertEndChild(element);
|
m_node->InsertEndChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XMLWriter::writeTimeInfo(int level, SIMparameters& tp)
|
||||||
|
{
|
||||||
|
m_dt = tp.time.dt;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
class TiXmlDocument;
|
class TiXmlDocument;
|
||||||
class TiXmlNode;
|
class TiXmlNode;
|
||||||
|
class SIMparameters;
|
||||||
|
|
||||||
|
|
||||||
class XMLWriter : public DataWriter
|
class XMLWriter : public DataWriter
|
||||||
@ -17,6 +18,7 @@ public:
|
|||||||
std::string basis;
|
std::string basis;
|
||||||
int patches;
|
int patches;
|
||||||
int components;
|
int components;
|
||||||
|
double timestep;
|
||||||
std::string type;
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ public:
|
|||||||
virtual bool readVector(int level, const DataEntry& entry);
|
virtual bool readVector(int level, const DataEntry& entry);
|
||||||
virtual void writeSIM(int level, const DataEntry& entry);
|
virtual void writeSIM(int level, const DataEntry& entry);
|
||||||
virtual bool readSIM(int level, const DataEntry& entry);
|
virtual bool readSIM(int level, const DataEntry& entry);
|
||||||
|
virtual bool writeTimeInfo(int level, SIMparameters& tp);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addField(const std::string& name, const std::string& description,
|
void addField(const std::string& name, const std::string& description,
|
||||||
@ -45,4 +48,5 @@ protected:
|
|||||||
|
|
||||||
TiXmlDocument* m_doc;
|
TiXmlDocument* m_doc;
|
||||||
TiXmlNode* m_node;
|
TiXmlNode* m_node;
|
||||||
|
double m_dt;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user