diff --git a/Apps/HDF5toVTF/HDF5toVTF.C b/Apps/HDF5toVTF/HDF5toVTF.C index 3e741fca..acd60042 100644 --- a/Apps/HDF5toVTF/HDF5toVTF.C +++ b/Apps/HDF5toVTF/HDF5toVTF.C @@ -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); diff --git a/src/SIM/SIMparameters.C b/src/SIM/SIMparameters.C index def60ace..7c5643b3 100644 --- a/src/SIM/SIMparameters.C +++ b/src/SIM/SIMparameters.C @@ -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; diff --git a/src/Utility/DataExporter.C b/src/Utility/DataExporter.C index 9a9e8f6b..e7e22347 100644 --- a/src/Utility/DataExporter.C +++ b/src/Utility/DataExporter.C @@ -6,6 +6,7 @@ #ifdef PARALLEL_PETSC #include #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++; diff --git a/src/Utility/DataExporter.h b/src/Utility/DataExporter.h index b607fa5e..d6541222 100644 --- a/src/Utility/DataExporter.h +++ b/src/Utility/DataExporter.h @@ -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 diff --git a/src/Utility/HDF5Writer.C b/src/Utility/HDF5Writer.C index 37fb02fb..e2514d28 100644 --- a/src/Utility/HDF5Writer.C +++ b/src/Utility/HDF5Writer.C @@ -2,6 +2,7 @@ #include "HDF5Writer.h" #include "SIMbase.h" +#include "SIMparameters.h" #include "IntegrandBase.h" #include #include @@ -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; +} diff --git a/src/Utility/HDF5Writer.h b/src/Utility/HDF5Writer.h index 63be7e02..93433635 100644 --- a/src/Utility/HDF5Writer.h +++ b/src/Utility/HDF5Writer.h @@ -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); diff --git a/src/Utility/XMLWriter.C b/src/Utility/XMLWriter.C index 45cfb706..e2b65d22 100644 --- a/src/Utility/XMLWriter.C +++ b/src/Utility/XMLWriter.C @@ -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; +} diff --git a/src/Utility/XMLWriter.h b/src/Utility/XMLWriter.h index debc98a9..edf4080a 100644 --- a/src/Utility/XMLWriter.h +++ b/src/Utility/XMLWriter.h @@ -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; };