37#include <boost/algorithm/string.hpp>
41#include <boost/format.hpp>
71 std::string infile = inFile;
73 fs::path pinfilename(infile);
76 if (fs::is_directory(pinfilename))
78 fs::path infofile(
"Info.xml");
79 fs::path fullpath = pinfilename / infofile;
82 std::vector<std::string> filenames;
83 std::vector<std::vector<unsigned int>> elementIDs_OnPartitions;
91 if (filenames.size() ==
m_comm->GetSpaceComm()->GetSize())
97 filenames.push_back(pad.str());
100 for (
int i = 0; i < filenames.size(); ++i)
102 fs::path pfilename(filenames[i]);
103 fullpath = pinfilename / pfilename;
115 newPtsField->GetPts(pts);
116 ptsField->AddPoints(pts);
136 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
137 size_t np = ptsField->GetNpoints();
139 std::string filename =
SetUpOutput(outFile,
true, backup);
143 std::ofstream ptsFile;
144 ptsFile.open(filename.c_str());
146 ptsFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << endl;
147 ptsFile <<
"<NEKTAR>" << endl;
148 ptsFile <<
" <POINTS ";
149 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
150 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
151 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
152 ptsFile <<
">" << endl;
155 ptsField->GetPts(pts);
156 for (
size_t i = 0; i < np; ++i)
159 ptsFile << pts[0][i];
160 for (
size_t j = 1; j < nTotvars; ++j)
162 ptsFile <<
" " << pts[j][i];
166 ptsFile <<
" </POINTS>" << endl;
167 ptsFile <<
"</NEKTAR>" << endl;
217 boost::ignore_unused(Range);
218 TiXmlDocument docInput(inFile);
219 bool loadOkay1 = docInput.LoadFile();
221 std::stringstream errstr;
222 errstr <<
"Unable to load file: " << inFile << std::endl;
223 errstr <<
"Reason: " << docInput.ErrorDesc() << std::endl;
224 errstr <<
"Position: Line " << docInput.ErrorRow() <<
", Column "
225 << docInput.ErrorCol() << std::endl;
228 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
229 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
231 int err = points->QueryIntAttribute(
"DIM", &dim);
233 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
235 std::string fields = points->Attribute(
"FIELDS");
237 vector<string> fieldNames;
243 "Unable to process list of field variable in FIELDS attribute: " +
249 const char *ptinfo = points->Attribute(
"PTSINFO");
250 if (ptinfo && boost::iequals(ptinfo,
"EquiSpaced"))
256 err = points->QueryIntAttribute(
"PTSPERELMTEDGE", &np);
257 if (err == TIXML_SUCCESS)
262 size_t nfields = fieldNames.size();
263 size_t totvars = dim + nfields;
265 TiXmlNode *pointsBody = points->FirstChild();
267 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
269 vector<NekDouble> ptsSerial;
275 while (!pointsDataStrm.fail())
277 pointsDataStrm >> ptsStream;
279 ptsSerial.push_back(ptsStream);
287 size_t npts = ptsSerial.size() / totvars;
289 for (
size_t i = 0; i < totvars; ++i)
294 for (
size_t i = 0; i < npts; ++i)
296 for (
size_t j = 0; j < totvars; ++j)
298 pts[j][i] = ptsSerial[i * totvars + j];
308 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
310 int nprocs =
m_comm->GetSpaceComm()->GetSize();
311 int rank =
m_comm->GetSpaceComm()->GetRank();
313 fs::path specPath(outname);
320 std::vector<std::string> filenames;
321 std::vector<std::vector<unsigned int>> ElementIDs;
322 for (
int i = 0; i < nprocs; ++i)
326 filenames.push_back(pad.str());
328 std::vector<unsigned int> tmp;
330 ElementIDs.push_back(tmp);
337 cout <<
"Writing: " << specPath << endl;
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
DataSourceSharedPtr ImportFieldMetaData(const std::string &filename, FieldMetaDataMap &fieldmetadatamap)
Import the metadata from a field 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.
std::string GetFileEnding() const
Helper function that determines default file extension.
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.
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 Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
PtsIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
virtual void v_ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField, DomainRangeShPtr &Range=NullDomainRangeShPtr)
void SetUpFieldMetaData(const std::string outname)
void ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField, DomainRangeShPtr &Range=NullDomainRangeShPtr)
void Import(const std::string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap, DomainRangeShPtr &Range=NullDomainRangeShPtr)
Import a pts field from file.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
static std::map< PtsInfo, int > NullPtsInfoMap
std::map< std::string, std::string > FieldMetaDataMap
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::shared_ptr< PtsField > PtsFieldSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
The above copyright notice and this permission notice shall be included.