Commit 45770bed authored by Chris Cantwell's avatar Chris Cantwell
Browse files

Encapsulated FieldIO in a class.

Moved SetUpOutput to FieldIO class.
Tidied up code.
Added support for parallel IO to utilities and demos.
parent 706f9e80
......@@ -29,6 +29,8 @@ int main(int argc, char *argv[])
exit(1);
}
LibUtilities::FieldIOSharedPtr fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph1D = MemoryManager<SpatialDomains::MeshGraph1D>::AllocateSharedPtr(vSession);
......@@ -113,7 +115,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//----------------------------------------------
//----------------------------------------------
......
......@@ -41,6 +41,8 @@ int main(int argc, char *argv[])
exit(1);
}
LibUtilities::FieldIOSharedPtr fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph2D = MemoryManager<SpatialDomains::MeshGraph2D>::AllocateSharedPtr(vSession);
......@@ -151,7 +153,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
......
......@@ -40,6 +40,8 @@ int main(int argc, char *argv[])
exit(1);
}
LibUtilities::FieldIOSharedPtr fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph3D =
......@@ -149,7 +151,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
//----------------------------------------------
......
......@@ -43,6 +43,8 @@ int main(int argc, char *argv[])
exit(1);
}
LibUtilities::FieldIOSharedPtr fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph2D = MemoryManager<SpatialDomains::MeshGraph2D>::AllocateSharedPtr(vSession);
......@@ -141,7 +143,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
......
......@@ -33,9 +33,13 @@ int main(int argc, char *argv[])
try
{
LibUtilities::FieldIOSharedPtr fld =
MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph1D = MemoryManager<SpatialDomains::MeshGraph1D>::AllocateSharedPtr(vSession);
SpatialDomains::MeshGraphSharedPtr graph1D =
SpatialDomains::MeshGraph::Read(vSession);
//----------------------------------------------
//----------------------------------------------
......@@ -128,7 +132,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//----------------------------------------------
//----------------------------------------------
......
......@@ -43,6 +43,9 @@ int main(int argc, char *argv[])
try
{
LibUtilities::FieldIOSharedPtr fld =
MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vSession->GetComm());
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph2D =
......@@ -152,12 +155,7 @@ int main(int argc, char *argv[])
//-----------------------------------------------
// Write solution to file
string out = vSession->GetSessionName();
if (vSession->GetComm()->GetSize() > 1)
{
out += "_P" + boost::lexical_cast<string>(vSession->GetComm()->GetRank());
}
out += ".fld";
string out = vSession->GetSessionName() + ".fld";
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
= Exp->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
......@@ -168,7 +166,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
//----------------------------------------------
......
......@@ -81,6 +81,9 @@ int main(int argc, char *argv[])
try
{
LibUtilities::FieldIOSharedPtr fld =
MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph3D =
......@@ -205,7 +208,7 @@ int main(int argc, char *argv[])
FieldDef[i]->m_fields.push_back("u");
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
if(ex_sol)
......
......@@ -32,6 +32,8 @@ int main(int argc, char *argv[])
exit(1);
}
LibUtilities::FieldIOSharedPtr fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(vComm);
//----------------------------------------------
// Read in mesh from input file
SpatialDomains::MeshGraphSharedPtr graph2D = MemoryManager<SpatialDomains::MeshGraph2D>::AllocateSharedPtr(vSession);
......@@ -144,7 +146,7 @@ int main(int argc, char *argv[])
Exp->AppendFieldData(FieldDef[i], FieldData[i]);
}
LibUtilities::Write(out, FieldDef, FieldData);
fld->Write(out, FieldDef, FieldData);
//-----------------------------------------------
vSession->Finalise();
......
......@@ -302,8 +302,6 @@ namespace expt
template<typename Expression>
static typename Expression::ResultType Evaluate(const Expression& expression)
{
typedef typename Expression::Indices Indices;
// Perform the optimizations on the parse three.
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedNodeType OptimizedParseTree;
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedIndicesType TransformedIndicesType;
......@@ -320,8 +318,6 @@ namespace expt
template<typename Expression>
static void Evaluate(const Expression& expression, typename Expression::ResultType& accum)
{
typedef typename Expression::Indices Indices;
// Perform the optimizations on the parse three.
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedNodeType OptimizedParseTree;
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedIndicesType TransformedIndicesType;
......@@ -341,8 +337,6 @@ namespace expt
template<typename Expression>
static void EvaluateWithoutAliasingCheck(const Expression& expression, typename Expression::ResultType& accum)
{
typedef typename Expression::Indices Indices;
// Perform the optimizations on the parse three.
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedNodeType OptimizedParseTree;
typedef typename RemoveUnecessaryTemporaries<Expression>::TransformedIndicesType TransformedIndicesType;
......
This diff is collapsed.
......@@ -36,6 +36,8 @@
#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_FIELDIO_H
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/Communication/Comm.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/ShapeType.hpp>
#include <LibUtilities/Foundations/Basis.h>
......@@ -65,27 +67,27 @@ namespace Nektar
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):
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),
......@@ -103,45 +105,39 @@ namespace Nektar
{
}
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;
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;
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;
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;
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;
/* --- FLD handling routines ---- */
LIB_UTILITIES_EXPORT void WriteMultiFldFileIDs(const std::string &outfile,
const std::vector<std::string> fileNames,
std::vector<Array<OneD, int > > &elementList,
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
/// 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,
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
/// Imports an FLD file.
/// Imports an FLD file
LIB_UTILITIES_EXPORT void Import(
const std::string& infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
......@@ -149,41 +145,93 @@ namespace Nektar
FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap,
const Array<OneD, int> ElementiDs = NullInt1DArray);
LIB_UTILITIES_EXPORT bool ImportMultiFldFileIDs(const std::string &inFile,
std::vector<std::string> &fileNames,
FieldMetaDataMap &fieldmetadatamap,
std::vector<std::vector<unsigned int > > &elementList);
/// Imports the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(std::string filename,
FieldMetaDataMap &fieldmetadatamap);
/// 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 the definition of the meta data
LIB_UTILITIES_EXPORT void ImportFieldMetaData(
/// Imports an FLD file.
LIB_UTILITIES_EXPORT void Import(
const std::string& infilename,
std::vector<FieldDefinitionsSharedPtr> &fielddefs,
std::vector<std::vector<NekDouble> > &fielddata,
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(
/// 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(
/// 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 int CheckFieldDefinition(
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 WriteMultiFldFileIDs(
const std::string &outfile,
const std::vector<std::string> fileNames,
std::vector<std::vector<unsigned int> > &elementList,
const FieldMetaDataMap &fieldinfomap = NullFieldMetaDataMap);
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);
LIB_UTILITIES_EXPORT int Deflate(
LIB_UTILITIES_EXPORT int Deflate(
std::vector<NekDouble>& in,
string& out);
LIB_UTILITIES_EXPORT int Inflate(string& in,
std::vector<NekDouble>& out);
LIB_UTILITIES_EXPORT int Inflate(string& in,
std::vector<NekDouble>& out);
};
typedef boost::shared_ptr<FieldIO> FieldIOSharedPtr;
}
}
#endif
......@@ -57,7 +57,7 @@
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_iterator.hpp>
#include <boost/graph/detail/edge.hpp>
#include <boost/format.hpp>
namespace Nektar
{
......@@ -111,8 +111,9 @@ namespace Nektar
std::string dirname = pSession->GetSessionName() + "_xml";
fs::path pdirname(dirname);
std::string vFilename = "P" + boost::lexical_cast<std::string>(rank) + ".xml";
fs::path pFilename(vFilename);
boost::format pad("P%1$07d.xml");
pad % rank;
fs::path pFilename(pad.str());
if(rank == 0)
{
......
......@@ -57,6 +57,7 @@ using namespace std;
#include <LibUtilities/BasicUtils/FileSystem.h>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
namespace po = boost::program_options;
namespace io = boost::iostreams;
......@@ -1377,7 +1378,14 @@ namespace Nektar
}
m_comm->Block();
m_filename = GetSessionNameRank() + ".xml";
std::string dirname = GetSessionName() + "_xml";
fs::path pdirname(dirname);
boost::format pad("P%1$07d.xml");
pad % m_comm->GetRank();
fs::path pFilename(pad.str());
fs::path fullpath = pdirname / pFilename;
m_filename = PortablePath(fullpath);
if (m_xmlDoc)
{
......
......@@ -35,6 +35,8 @@
#ifndef NEKTAR_LIB_UTILITIES_COMM_H
#define NEKTAR_LIB_UTILITIES_COMM_H
#include <vector>
#include <boost/enable_shared_from_this.hpp>
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
......@@ -85,8 +87,10 @@ namespace Nektar
LIB_UTILITIES_EXPORT inline void Block();
LIB_UTILITIES_EXPORT inline void Send(int pProc, Array<OneD, NekDouble>& pData);
LIB_UTILITIES_EXPORT inline void Send(int pProc, Array<OneD, int>& pData);
LIB_UTILITIES_EXPORT inline void Send(int pProc, std::vector<unsigned int>& pData);
LIB_UTILITIES_EXPORT inline void Recv(int pProc, Array<OneD, NekDouble>& pData);
LIB_UTILITIES_EXPORT inline void Recv(int pProc, Array<OneD, int>& pData);
LIB_UTILITIES_EXPORT inline void Recv(int pProc, std::vector<unsigned int>& pData);
LIB_UTILITIES_EXPORT inline void SendRecv(int pSendProc,
Array<OneD, NekDouble>& pSendData,
int pRecvProc,
......@@ -107,6 +111,8 @@ namespace Nektar
enum ReduceOperator pOp);
LIB_UTILITIES_EXPORT inline void AllReduce(Array<OneD, int >& pData,
enum ReduceOperator pOp);
LIB_UTILITIES_EXPORT inline void AllReduce(std::vector<unsigned int>& pData,
enum ReduceOperator pOp);
LIB_UTILITIES_EXPORT inline void AlltoAll(Array<OneD, NekDouble>& pSendData,
Array<OneD, NekDouble>& pRecvData);
LIB_UTILITIES_EXPORT inline void AlltoAll(Array<OneD, int>& pSendData,
......@@ -141,8 +147,10 @@ namespace Nektar
virtual void v_Block() = 0;
virtual void v_Send(int pProc, Array<OneD, NekDouble>& pData) = 0;
virtual void v_Send(int pProc, Array<OneD, int>& pData) = 0;
virtual void v_Send(int pProc, std::vector<unsigned int>& pData) = 0;
virtual void v_Recv(int pProc, Array<OneD, NekDouble>& pData) = 0;
virtual void v_Recv(int pProc, Array<OneD, int>& pData) = 0;
virtual void v_Recv(int pProc, std::vector<unsigned int>& pData) = 0;
virtual void v_SendRecv(int pSendProc,
Array<OneD, NekDouble>& pSendData,
int pRecvProc,
......@@ -165,6 +173,8 @@ namespace Nektar
enum ReduceOperator pOp) = 0;
virtual void v_AllReduce(Array<OneD, int >& pData,
enum ReduceOperator pOp) = 0;
virtual void v_AllReduce(std::vector<unsigned int>& pData,
enum ReduceOperator pOp) = 0;
virtual void v_AlltoAll(Array<OneD, NekDouble>& pSendData,
Array<OneD, NekDouble>& pRecvData) = 0;
virtual void v_AlltoAll(Array<OneD, int>& pSendData,
......@@ -258,6 +268,22 @@ namespace Nektar
v_Recv(pProc, pData);
}
/**
*
*/
inline void Comm::Send(int pProc, std::vector<unsigned int>& pData)
{
v_Send(pProc, pData);
}
/**
*
*/
inline void Comm::Recv(int pProc, std::vector<unsigned int>& pData)
{
v_Recv(pProc, pData);
}
/**
*
*/
......@@ -339,7 +365,16 @@ namespace Nektar
}
/**
/**
*
*/
inline void Comm::AllReduce(std::vector<unsigned int>& pData, enum ReduceOperator pOp)
{
v_AllReduce(pData, pOp);
}
/**
*
*/
inline void Comm::AlltoAll(Array<OneD, NekDouble>& pSendData,Array<OneD, NekDouble>& pRecvData)
......
......@@ -214,6 +214,51 @@ namespace Nektar
}
/**
*
*/
void CommMpi::v_Send(int pProc, std::vector<unsigned int>& pData)
{
if (MPISYNC)
{
MPI_Ssend( &pData[0],
(int) pData.size(),
MPI_UNSIGNED,
pProc,
0,
m_comm);
}
else
{
MPI_Send( &pData[0],
(int) pData.size(),
MPI_UNSIGNED,
pProc,
0,
m_comm);
}
}
/**
*