37 #include <boost/algorithm/string.hpp>
42 #include <boost/format.hpp>
53 namespace LibUtilities
61 MPI_Initialized(&init);
70 MPI_Comm_size(MPI_COMM_WORLD, &size);
72 "This static function is not available in parallel. Please "
73 "instantiate a FieldIO object for parallel use.");
78 p.
Import(inFile, ptsField);
86 MPI_Initialized(&init);
95 MPI_Comm_size(MPI_COMM_WORLD, &size);
97 "This static function is not available in parallel. Please "
98 "instantiate a FieldIO object for parallel use.");
103 p.
Write(outFile, ptsField);
107 :
FieldIO(pComm, sharedFilesystem)
121 std::string infile = inFile;
123 fs::path pinfilename(infile);
126 if (fs::is_directory(pinfilename))
128 fs::path infofile(
"Info.xml");
129 fs::path fullpath = pinfilename / infofile;
132 std::vector<std::string> filenames;
133 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
136 infile, filenames, elementIDs_OnPartitions, fieldmetadatamap);
143 boost::format pad(
"P%1$07d.%2$s");
145 filenames.push_back(pad.str());
147 for (
int i = 0; i < filenames.size(); ++i)
149 fs::path pfilename(filenames[i]);
150 fullpath = pinfilename / pfilename;
153 TiXmlDocument doc1(fname);
154 bool loadOkay1 = doc1.LoadFile();
156 std::stringstream errstr;
157 errstr <<
"Unable to load file: " << fname << std::endl;
158 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
159 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column "
160 << doc1.ErrorCol() << std::endl;
168 TiXmlDocument doc(infile);
169 bool loadOkay = doc.LoadFile();
171 std::stringstream errstr;
172 errstr <<
"Unable to load file: " << infile << std::endl;
173 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
174 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column "
175 << doc.ErrorCol() << std::endl;
191 int nTotvars = ptsField->GetNFields() + ptsField->GetDim();
192 int np = ptsField->GetNpoints();
198 std::ofstream ptsFile;
199 ptsFile.open(filename.c_str());
201 ptsFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << endl;
202 ptsFile <<
"<NEKTAR>" << endl;
203 ptsFile <<
" <POINTS ";
204 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
205 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
206 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
207 ptsFile <<
">" << endl;
210 ptsField->GetPts(pts);
211 for (
int i = 0; i < np; ++i)
214 ptsFile << pts[0][i];
215 for (
int j = 1; j < nTotvars; ++j)
217 ptsFile <<
" " << pts[j][i];
221 ptsFile <<
" </POINTS>" << endl;
222 ptsFile <<
"</NEKTAR>" << endl;
266 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
267 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
269 int err = points->QueryIntAttribute(
"DIM", &dim);
271 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
273 std::string fields = points->Attribute(
"FIELDS");
275 vector<string> fieldNames;
282 "Unable to process list of field variable in FIELDS attribute: " +
288 const char *ptinfo = points->Attribute(
"PTSINFO");
289 if(ptinfo&&boost::iequals(ptinfo,
"EquiSpaced"))
295 err = points->QueryIntAttribute(
"PTSPERELMTEDGE",&np);
296 if(err == TIXML_SUCCESS)
301 int nfields = fieldNames.size();
302 int totvars = dim + nfields;
304 TiXmlNode *pointsBody = points->FirstChild();
306 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
308 vector<NekDouble> ptsSerial;
314 while (!pointsDataStrm.fail())
316 pointsDataStrm >> ptsStream;
318 ptsSerial.push_back(ptsStream);
323 ASSERTL0(
false,
"Unable to read Points data.");
326 int npts = ptsSerial.size() / totvars;
328 for (
int i = 0; i < totvars; ++i)
333 for (
int i = 0; i <
npts; ++i)
335 for (
int j = 0; j < totvars; ++j)
337 pts[j][i] = ptsSerial[i * totvars + j];
346 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
348 int nprocs =
m_comm->GetSize();
349 int rank =
m_comm->GetRank();
351 fs::path specPath(outname);
358 std::vector<std::string> filenames;
359 std::vector<std::vector<unsigned int> > ElementIDs;
360 for (
int i = 0; i < nprocs; ++i)
362 boost::format pad(
"P%1$07d.%2$s");
364 filenames.push_back(pad.str());
366 std::vector<unsigned int> tmp;
368 ElementIDs.push_back(tmp);
375 cout <<
"Writing: " << specPath << endl;
#define ASSERTL0(condition, msg)
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void ImportMultiFldFileIDs(const std::string &inFile, std::vector< std::string > &fileNames, std::vector< std::vector< unsigned int > > &elementList, FieldMetaDataMap &fieldmetadatamap)
std::string SetUpOutput(const std::string outname)
std::map< std::string, std::string > FieldMetaDataMap
CommFactory & GetCommFactory()
boost::shared_ptr< PtsField > PtsFieldSharedPtr
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
PtsIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void ImportFieldData(TiXmlDocument docInput, PtsFieldSharedPtr &ptsField)
void Write(const string &outFile, const PtsFieldSharedPtr &ptsField)
Save a pts field to a file.
virtual std::string GetFileEnding() const
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
void Import(const string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap)
Import a pts field from file.
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
void WriteMultiFldFileIDs(const std::string &outfile, const std::vector< std::string > fileNames, std::vector< std::vector< unsigned int > > &elementList, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
static map< PtsInfo, int > NullPtsInfoMap
void SetUpFieldMetaData(const std::string outname)
Class for operating on FLD files.
void ImportFieldMetaData(std::string filename, FieldMetaDataMap &fieldmetadatamap)
Imports the definition of the meta data.
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap)
Write a field file in serial only.