Commit 80e5bc8f authored by Kilian Lackhove's avatar Kilian Lackhove
Browse files

backup: port from member to write parameter

parent 505054bc
......@@ -235,7 +235,8 @@ FieldIOSharedPtr FieldIO::CreateForFile(
void Write(const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap)
const FieldMetaDataMap &fieldinfomap,
const bool backup)
{
#ifdef NEKTAR_USE_MPI
int size;
......@@ -257,7 +258,7 @@ void Write(const std::string &outFile,
#endif
CommSharedPtr c = GetCommFactory().CreateInstance("Serial", 0, 0);
FieldIOSharedPtr f = GetFieldIOFactory().CreateInstance("Xml", c, false);
f->Write(outFile, fielddefs, fielddata, fieldinfomap);
f->Write(outFile, fielddefs, fielddata, fieldinfomap, backup);
}
/**
......@@ -310,7 +311,7 @@ LIB_UTILITIES_EXPORT void Import(
* @brief Constructor for FieldIO base class.
*/
FieldIO::FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
: m_comm(pComm), m_sharedFilesystem(sharedFilesystem), m_backup(false)
: m_comm(pComm), m_sharedFilesystem(sharedFilesystem)
{
}
......@@ -396,7 +397,7 @@ void FieldIO::AddInfoTag(TagWriterSharedPtr root,
*
* @return Absolute path to resulting file.
*/
std::string FieldIO::SetUpOutput(const std::string outname, bool perRank)
std::string FieldIO::SetUpOutput(const std::string outname, bool perRank, bool backup)
{
ASSERTL0(!outname.empty(), "Empty path given to SetUpOutput()");
......@@ -407,7 +408,7 @@ std::string FieldIO::SetUpOutput(const std::string outname, bool perRank)
// serial.
fs::path specPath(outname), fulloutname;
if (m_backup && (rank == 0 || !m_sharedFilesystem))
if (backup && (rank == 0 || !m_sharedFilesystem))
{
fs::path newPath = specPath;
int cnt = 0;
......
......@@ -184,7 +184,8 @@ LIB_UTILITIES_EXPORT void Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const bool backup = false);
LIB_UTILITIES_EXPORT void Import(
const std::string &infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
......@@ -234,7 +235,8 @@ public:
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const bool backup = false);
LIB_UTILITIES_EXPORT inline void Import(
const std::string &infilename,
......@@ -248,9 +250,6 @@ public:
const std::string &filename,
FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT bool GetDoBackup();
LIB_UTILITIES_EXPORT void SetDoBackup(bool backup);
LIB_UTILITIES_EXPORT static const std::string GetFileType(
const std::string &filename, CommSharedPtr comm);
LIB_UTILITIES_EXPORT virtual const std::string &GetClassName() const = 0;
......@@ -266,8 +265,6 @@ protected:
LibUtilities::CommSharedPtr m_comm;
/// Boolean dictating whether we are on a shared filesystem.
bool m_sharedFilesystem;
/// Boolean dictating whether we should backup existing files
bool m_backup;
LIB_UTILITIES_EXPORT void AddInfoTag(
TagWriterSharedPtr root,
......@@ -285,14 +282,15 @@ protected:
}
LIB_UTILITIES_EXPORT std::string SetUpOutput(
const std::string outname, bool perRank);
const std::string outname, bool perRank, bool backup = false);
/// @copydoc FieldIO::Write
LIB_UTILITIES_EXPORT virtual void v_Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap) = 0;
const FieldMetaDataMap &fieldinfomap,
const bool backup = false) = 0;
/// @copydoc FieldIO::Import
LIB_UTILITIES_EXPORT virtual void v_Import(
......@@ -322,9 +320,10 @@ typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
inline void FieldIO::Write(const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap)
const FieldMetaDataMap &fieldinfomap,
const bool backup)
{
v_Write(outFile, fielddefs, fielddata, fieldinfomap);
v_Write(outFile, fielddefs, fielddata, fieldinfomap, backup);
}
/**
......
......@@ -173,7 +173,8 @@ FieldIOHdf5::FieldIOHdf5(LibUtilities::CommSharedPtr pComm,
void FieldIOHdf5::v_Write(const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldmetadatamap)
const FieldMetaDataMap &fieldmetadatamap,
const bool backup)
{
std::stringstream prfx;
prfx << m_comm->GetRank() << ": FieldIOHdf5::v_Write(): ";
......@@ -184,7 +185,7 @@ void FieldIOHdf5::v_Write(const std::string &outFile,
tm0 = m_comm->Wtime();
}
SetUpOutput(outFile, false);
SetUpOutput(outFile, false, backup);
// We make a number of assumptions in this code:
// 1. All element ids have the same type: unsigned int
......
......@@ -241,7 +241,8 @@ private:
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const bool backup = false);
LIB_UTILITIES_EXPORT virtual void v_Import(
const std::string &infilename,
......
......@@ -87,7 +87,8 @@ FieldIOXml::FieldIOXml(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
void FieldIOXml::v_Write(const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldmetadatamap)
const FieldMetaDataMap &fieldmetadatamap,
const bool backup)
{
double tm0 = 0.0, tm1 = 0.0;
if (m_comm->GetRank() == 0)
......@@ -112,7 +113,7 @@ void FieldIOXml::v_Write(const std::string &outFile,
// Prepare to write out data. In parallel, we must create directory and
// determine the full pathname to the file to write out. Any existing
// file/directory which is in the way is removed.
std::string filename = SetUpOutput(outFile, true);
std::string filename = SetUpOutput(outFile, true, backup);
SetUpFieldMetaData(outFile, fielddefs, fieldmetadatamap);
// Create the file (partition)
......
......@@ -242,7 +242,8 @@ private:
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const bool backup = false);
LIB_UTILITIES_EXPORT virtual DataSourceSharedPtr v_ImportFieldMetaData(
const std::string &filename, FieldMetaDataMap &fieldmetadatamap);
......
......@@ -153,12 +153,13 @@ void PtsIO::Import(const string &inFile,
* @param ptsField the pts field
*/
void PtsIO::Write(const string &outFile,
const Nektar::LibUtilities::PtsFieldSharedPtr &ptsField)
const Nektar::LibUtilities::PtsFieldSharedPtr &ptsField,
const bool backup)
{
int nTotvars = ptsField->GetNFields() + ptsField->GetDim();
int np = ptsField->GetNpoints();
std::string filename = SetUpOutput(outFile, true);
std::string filename = SetUpOutput(outFile, true, backup);
SetUpFieldMetaData(outFile);
// until tinyxml gains support for line break, write the xml manually
......
......@@ -77,7 +77,8 @@ public:
FieldMetaDataMap &fieldmetadatamap = NullFieldMetaDataMap);
LIB_UTILITIES_EXPORT void Write(const string &outFile,
const PtsFieldSharedPtr &ptsField);
const PtsFieldSharedPtr &ptsField,
const bool backup = false);
LIB_UTILITIES_EXPORT void ImportFieldData(TiXmlDocument docInput,
PtsFieldSharedPtr &ptsField);
......
......@@ -124,7 +124,6 @@ namespace Nektar
// Instantiate a field reader/writer
m_fld = LibUtilities::FieldIO::CreateDefault(m_session);
m_fld->SetDoBackup(true);
// Read the geometry and the expansion information
m_graph = SpatialDomains::MeshGraph::Read(m_session);
......@@ -2102,7 +2101,7 @@ namespace Nektar
LibUtilities::FieldMetaDataMap fieldMetaDataMap(m_fieldMetaDataMap);
mapping->Output( fieldMetaDataMap, outname);
m_fld->Write(outname, FieldDef, FieldData, fieldMetaDataMap);
m_fld->Write(outname, FieldDef, FieldData, fieldMetaDataMap, true);
}
......
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