37 #include <boost/algorithm/string.hpp>
42 #include <boost/format.hpp>
54 namespace LibUtilities
73 std::string infile = inFile;
75 fs::path pinfilename(infile);
78 if (fs::is_directory(pinfilename))
80 fs::path infofile(
"Info.xml");
81 fs::path fullpath = pinfilename / infofile;
84 std::vector<std::string> filenames;
85 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
88 infile, filenames, elementIDs_OnPartitions, fieldmetadatamap);
93 if (filenames.size() ==
m_comm->GetSize())
99 filenames.push_back(pad.str());
102 for (
int i = 0; i < filenames.size(); ++i)
104 fs::path pfilename(filenames[i]);
105 fullpath = pinfilename / pfilename;
108 TiXmlDocument doc1(fname);
109 bool loadOkay1 = doc1.LoadFile();
111 std::stringstream errstr;
112 errstr <<
"Unable to load file: " << fname << std::endl;
113 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
114 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column "
115 << doc1.ErrorCol() << std::endl;
127 newPtsField->GetPts(pts);
128 ptsField->AddPoints(pts);
135 TiXmlDocument doc(infile);
136 bool loadOkay = doc.LoadFile();
138 std::stringstream errstr;
139 errstr <<
"Unable to load file: " << infile << std::endl;
140 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
141 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column "
142 << doc.ErrorCol() << std::endl;
159 int nTotvars = ptsField->GetNFields() + ptsField->GetDim();
160 int np = ptsField->GetNpoints();
162 std::string filename =
SetUpOutput(outFile,
true, backup);
166 std::ofstream ptsFile;
167 ptsFile.open(filename.c_str());
169 ptsFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << endl;
170 ptsFile <<
"<NEKTAR>" << endl;
171 ptsFile <<
" <POINTS ";
172 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
173 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
174 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
175 ptsFile <<
">" << endl;
178 ptsField->GetPts(pts);
179 for (
int i = 0; i < np; ++i)
182 ptsFile << pts[0][i];
183 for (
int j = 1; j < nTotvars; ++j)
185 ptsFile <<
" " << pts[j][i];
189 ptsFile <<
" </POINTS>" << endl;
190 ptsFile <<
"</NEKTAR>" << endl;
234 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
235 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
237 int err = points->QueryIntAttribute(
"DIM", &dim);
239 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
241 std::string fields = points->Attribute(
"FIELDS");
243 vector<string> fieldNames;
250 "Unable to process list of field variable in FIELDS attribute: " +
256 const char *ptinfo = points->Attribute(
"PTSINFO");
257 if(ptinfo&&boost::iequals(ptinfo,
"EquiSpaced"))
263 err = points->QueryIntAttribute(
"PTSPERELMTEDGE",&np);
264 if(err == TIXML_SUCCESS)
269 int nfields = fieldNames.size();
270 int totvars = dim + nfields;
272 TiXmlNode *pointsBody = points->FirstChild();
274 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
276 vector<NekDouble> ptsSerial;
282 while (!pointsDataStrm.fail())
284 pointsDataStrm >> ptsStream;
286 ptsSerial.push_back(ptsStream);
291 ASSERTL0(
false,
"Unable to read Points data.");
294 int npts = ptsSerial.size() / totvars;
296 for (
int i = 0; i < totvars; ++i)
301 for (
int i = 0; i <
npts; ++i)
303 for (
int j = 0; j < totvars; ++j)
305 pts[j][i] = ptsSerial[i * totvars + j];
314 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
316 int nprocs =
m_comm->GetSize();
317 int rank =
m_comm->GetRank();
319 fs::path specPath(outname);
326 std::vector<std::string> filenames;
327 std::vector<std::vector<unsigned int> > ElementIDs;
328 for (
int i = 0; i < nprocs; ++i)
332 filenames.push_back(pad.str());
334 std::vector<unsigned int> tmp;
336 ElementIDs.push_back(tmp);
343 cout <<
"Writing: " << specPath << endl;
static std::map< PtsInfo, int > NullPtsInfoMap
#define ASSERTL0(condition, msg)
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
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)
Read file containing element ID to partition mapping.
std::map< std::string, std::string > FieldMetaDataMap
boost::shared_ptr< PtsField > PtsFieldSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void ImportFieldData(TiXmlDocument docInput, PtsFieldSharedPtr &ptsField)
virtual std::string GetFileEnding() const
Helper function that determines default file extension.
DataSourceSharedPtr ImportFieldMetaData(const std::string &filename, FieldMetaDataMap &fieldmetadatamap)
Import the metadata from a field file.
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
void WriteMultiFldFileIDs(const std::string &outfile, const std::vector< std::string > fileNames, std::vector< std::vector< unsigned int > > &elementList, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Write out a file containing element ID to partition mapping.
void Import(const string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap)
Import a pts field from file.
std::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
void SetUpFieldMetaData(const std::string outname)
void Write(const string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.