Commit c6ce8947 authored by Dave Moxey's avatar Dave Moxey
Browse files

Reformat FieldIO header, add shared-filesystem option to enable fix only in shared filesystem mode

parent c74217b4
......@@ -37,10 +37,19 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/assign/list_of.hpp>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include <LibUtilities/BasicUtils/FileSystem.h>
#include <LibUtilities/BasicConst/GitRevision.h>
#include <LibUtilities/Communication/Comm.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include "zlib.h"
#include <set>
......@@ -137,9 +146,9 @@ namespace Nektar
/**
*
*/
FieldIO::FieldIO(
LibUtilities::CommSharedPtr pComm)
: m_comm(pComm)
FieldIO::FieldIO(LibUtilities::CommSharedPtr pComm,
bool sharedFilesystem)
: m_comm(pComm), m_sharedFilesystem(sharedFilesystem)
{
}
......@@ -1145,12 +1154,19 @@ namespace Nektar
{
try
{
if (rank == 0)
if (m_sharedFilesystem)
{
if (rank == 0)
{
fs::remove_all(specPath);
}
m_comm->Block();
}
else
{
fs::remove_all(specPath);
}
m_comm->Block();
}
catch (fs::filesystem_error& e)
{
......@@ -1183,12 +1199,19 @@ namespace Nektar
// Create the destination directory
try
{
if (rank == 0)
if (m_sharedFilesystem)
{
if (rank == 0)
{
fs::create_directory(specPath);
}
m_comm->Block();
}
else
{
fs::create_directory(specPath);
}
m_comm->Block();
}
catch (fs::filesystem_error& e)
{
......
......@@ -36,199 +36,178 @@
#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/CompressData.h>
#include <LibUtilities/Communication/Comm.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/ShapeType.hpp>
#include <LibUtilities/Foundations/Basis.h>
#include <LibUtilities/Foundations/Points.h>
#include <tinyxml.h>
// These are required for the Write(...) and Import(...) functions.
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/assign/list_of.hpp>
namespace Nektar
{
namespace LibUtilities
namespace LibUtilities
{
static std::vector<NekDouble> NullNekDoubleVector;
static std::vector<LibUtilities::PointsType> NullPointsTypeVector;
static std::vector<unsigned int> NullUnsignedIntVector;
typedef std::map<std::string, std::string> FieldMetaDataMap;
static FieldMetaDataMap NullFieldMetaDataMap;
static std::vector<std::vector<NekDouble> > NullVectorNekDoubleVector =
boost::assign::list_of(NullNekDoubleVector);
struct FieldDefinitions
{
FieldDefinitions(
ShapeType shapeType,
const std::vector<unsigned int> &elementIDs,
const std::vector<LibUtilities::BasisType> &basis,
bool uniOrder,
const std::vector<unsigned int> &numModes,
const std::vector<std::string> &fields,
int NumHomoDir = 0,
const std::vector<NekDouble> &HomoLengths
= NullNekDoubleVector,
const std::vector<unsigned int> &HomoZIDs
= NullUnsignedIntVector,
const std::vector<unsigned int> &HomoYIDs
= NullUnsignedIntVector,
const std::vector<LibUtilities::PointsType> &points
= NullPointsTypeVector,
bool pointsDef = false,
const std::vector<unsigned int> &numPoints
= NullUnsignedIntVector,
bool numPointsDef = false)
: m_shapeType(shapeType), m_elementIDs(elementIDs), m_basis(basis),
m_numHomogeneousDir(NumHomoDir), m_homogeneousLengths(HomoLengths),
m_homogeneousZIDs(HomoZIDs), m_homogeneousYIDs(HomoYIDs),
m_points(points), m_pointsDef(pointsDef), m_uniOrder(uniOrder),
m_numModes(numModes), m_numPoints(numPoints),
m_numPointsDef(numPointsDef), m_fields(fields)
{
static std::vector<NekDouble> NullNekDoubleVector;
static std::vector<LibUtilities::PointsType> NullPointsTypeVector;
static std::vector<unsigned int> NullUnsignedIntVector;
typedef std::map<std::string, std::string> FieldMetaDataMap;
static FieldMetaDataMap NullFieldMetaDataMap;
static std::vector<std::vector< NekDouble> > NullVectorNekDoubleVector = boost::assign::list_of(NullNekDoubleVector);
struct FieldDefinitions
{
FieldDefinitions(ShapeType shapeType,
const std::vector<unsigned int> &elementIDs,// vector[2]
const std::vector<LibUtilities::BasisType> &basis,
bool uniOrder,
// UniOrder = vector[dimension] - MixOrder
// = vector[element*dimension]
const std::vector<unsigned int> &numModes,
const std::vector<std::string> &fields,
int NumHomoDir = 0,
const std::vector<NekDouble> &HomoLengths =
NullNekDoubleVector,
const std::vector<unsigned int> &HomoZIDs =
NullUnsignedIntVector,
const std::vector<unsigned int> &HomoYIDs =
NullUnsignedIntVector,
const std::vector<LibUtilities::PointsType> &points =
NullPointsTypeVector,
bool pointsDef = false,
const std::vector<unsigned int> &numPoints =
NullUnsignedIntVector,
bool numPointsDef = false):
m_shapeType(shapeType),
m_elementIDs(elementIDs),
m_basis(basis),
m_numHomogeneousDir(NumHomoDir),
m_homogeneousLengths(HomoLengths),
m_homogeneousZIDs(HomoZIDs),
m_homogeneousYIDs(HomoYIDs),
m_points(points),
m_pointsDef(pointsDef),
m_uniOrder(uniOrder),
m_numModes(numModes),
m_numPoints(numPoints),
m_numPointsDef(numPointsDef),
m_fields(fields)
{
}
ShapeType m_shapeType;
std::vector<unsigned int> m_elementIDs;
std::vector<LibUtilities::BasisType> m_basis;
int m_numHomogeneousDir;
std::vector<NekDouble> m_homogeneousLengths;
std::vector<unsigned int> m_homogeneousZIDs;
std::vector<unsigned int> m_homogeneousYIDs;
/// Define the type of points per direction.
std::vector<LibUtilities::PointsType> m_points;
bool m_pointsDef;
/// Define order of the element group.
/// * UniOrder: same order for each element
/// * MixOrder: definition of a different order for each element.
bool m_uniOrder;
/// Define number of modes per direction.
std::vector<unsigned int> m_numModes;
std::vector<unsigned int> m_numPoints;
bool m_numPointsDef;
std::vector<std::string> m_fields;
};
typedef boost::shared_ptr<FieldDefinitions> FieldDefinitionsSharedPtr;
/// Write a field file in serial only
LIB_UTILITIES_EXPORT void Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
/// Imports an FLD file
LIB_UTILITIES_EXPORT void Import(
const std::string& infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata = NullVectorNekDoubleVector,
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const Array<OneD, int> ElementiDs = NullInt1DArray);
/// Class for operating on FLD files
class FieldIO
{
public:
/// Constructor
LIB_UTILITIES_EXPORT FieldIO(
LibUtilities::CommSharedPtr pComm);
/// Write data in FLD format
LIB_UTILITIES_EXPORT void Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
/// Imports an FLD file.
LIB_UTILITIES_EXPORT void Import(
const std::string& infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata = NullVectorNekDoubleVector,
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const Array<OneD, int> ElementiDs = NullInt1DArray);
/// Imports the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(
std::string filename,
FieldMetaDataMap &fieldmetadatamap);
/// Imports the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(
TiXmlDocument &doc,
FieldMetaDataMap &fieldmetadatamap);
/// Imports the definition of the fields.
LIB_UTILITIES_EXPORT void ImportFieldDefs(
TiXmlDocument &doc,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
bool expChild);
/// Imports the data fileds.
LIB_UTILITIES_EXPORT void ImportFieldData(
TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata);
LIB_UTILITIES_EXPORT void WriteMultiFldFileIDs(
const std::string &outfile,
const std::vector<std::string> fileNames,
std::vector<std::vector<unsigned int> > &elementList,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
private:
/// Communicator to use when writing parallel format
LibUtilities::CommSharedPtr m_comm;
LIB_UTILITIES_EXPORT void AddInfoTag(
TiXmlElement * root,
const FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT void GenerateSeqString(
const std::vector<unsigned int> &elmtids,
std::string &idString);
LIB_UTILITIES_EXPORT std::string SetUpOutput(
const std::string outname,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
const FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT void ImportMultiFldFileIDs(
const std::string &inFile,
std::vector<std::string> &fileNames,
std::vector<std::vector<unsigned int> > &elementList,
FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT int CheckFieldDefinition(
const FieldDefinitionsSharedPtr &fielddefs);
};
typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
}
ShapeType m_shapeType;
std::vector<unsigned int> m_elementIDs;
std::vector<LibUtilities::BasisType> m_basis;
int m_numHomogeneousDir;
std::vector<NekDouble> m_homogeneousLengths;
std::vector<unsigned int> m_homogeneousZIDs;
std::vector<unsigned int> m_homogeneousYIDs;
/// True if filesystem is shared.
bool m_sharedFilesystem;
/// Define the type of points per direction.
std::vector<LibUtilities::PointsType> m_points;
bool m_pointsDef;
/// Define order of the element group.
/// * UniOrder: same order for each element
/// * MixOrder: definition of a different order for each element.
bool m_uniOrder;
/// Define number of modes per direction.
std::vector<unsigned int> m_numModes;
std::vector<unsigned int> m_numPoints;
bool m_numPointsDef;
std::vector<std::string> m_fields;
};
typedef boost::shared_ptr<FieldDefinitions> FieldDefinitionsSharedPtr;
/// Write a field file in serial only
LIB_UTILITIES_EXPORT void Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
/// Imports an FLD file
LIB_UTILITIES_EXPORT void Import(
const std::string &infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata
= NullVectorNekDoubleVector,
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const Array<OneD, int> ElementiDs = NullInt1DArray);
/// Class for operating on FLD files
class FieldIO
{
public:
/// Constructor
LIB_UTILITIES_EXPORT FieldIO(LibUtilities::CommSharedPtr pComm,
bool sharedFilesystem = false);
/// Write data in FLD format
LIB_UTILITIES_EXPORT void Write(
const std::string &outFile,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
const FieldMetaDataMap &fieldinfomap
= NullFieldMetaDataMap);
/// Imports an FLD file.
LIB_UTILITIES_EXPORT void Import(
const std::string &infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata
= NullVectorNekDoubleVector,
FieldMetaDataMap &fieldinfomap
= NullFieldMetaDataMap,
const Array<OneD, int> ElementiDs = NullInt1DArray);
/// Imports the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(
std::string filename,
FieldMetaDataMap &fieldmetadatamap);
/// Imports the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(
TiXmlDocument &doc, FieldMetaDataMap &fieldmetadatamap);
/// Imports the definition of the fields.
LIB_UTILITIES_EXPORT void ImportFieldDefs(
TiXmlDocument &doc,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
bool expChild);
/// Imports the data fileds.
LIB_UTILITIES_EXPORT void ImportFieldData(
TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata);
LIB_UTILITIES_EXPORT void WriteMultiFldFileIDs(
const std::string &outfile,
const std::vector<std::string> fileNames,
std::vector<std::vector<unsigned int> > &elementList,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
private:
/// Communicator to use when writing parallel format
LibUtilities::CommSharedPtr m_comm;
/// True if same filesystem accessible by all processes.
bool m_sharedFilesystem;
LIB_UTILITIES_EXPORT void AddInfoTag(
TiXmlElement *root, const FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT void GenerateSeqString(
const std::vector<unsigned int> &elmtids, std::string &idString);
LIB_UTILITIES_EXPORT std::string SetUpOutput(
const std::string outname,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs,
const FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT void ImportMultiFldFileIDs(
const std::string &inFile,
std::vector<std::string> &fileNames,
std::vector<std::vector<unsigned int> > &elementList,
FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT int CheckFieldDefinition(
const FieldDefinitionsSharedPtr &fielddefs);
};
typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
}
}
#endif
......@@ -121,7 +121,9 @@ namespace Nektar
// Instantiate a field reader/writer
m_fld = MemoryManager<LibUtilities::FieldIO>
::AllocateSharedPtr(m_session->GetComm());
::AllocateSharedPtr(
m_session->GetComm(),
m_session->DefinesCmdLineArgument("shared-filesystem"));
// Read the geometry and the expansion information
m_graph = SpatialDomains::MeshGraph::Read(m_session);
......
......@@ -38,6 +38,7 @@
#include <SpatialDomains/MeshGraph.h>
#include <LibUtilities/Foundations/ManagerAccess.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <vector>
using namespace std;
......
......@@ -38,6 +38,7 @@
#include <SpatialDomains/MeshGraph.h>
#include <LibUtilities/Foundations/ManagerAccess.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <vector>
using namespace std;
......
......@@ -40,6 +40,7 @@
#include <LocalRegions/QuadExp.h>
#include <LibUtilities/Interpreter/AnalyticExpressionEvaluator.hpp>
#include <LibUtilities/Foundations/ManagerAccess.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <vector>
using namespace std;
......
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