37#include <boost/algorithm/string.hpp>
41#include <boost/format.hpp>
69 std::string infile = inFile;
71 fs::path pinfilename(infile);
74 if (fs::is_directory(pinfilename))
76 fs::path infofile(
"Info.xml");
77 fs::path fullpath = pinfilename / infofile;
80 std::vector<std::string> filenames;
81 std::vector<std::vector<unsigned int>> elementIDs_OnPartitions;
89 if (filenames.size() ==
m_comm->GetSpaceComm()->GetSize())
95 filenames.push_back(pad.str());
98 for (
int i = 0; i < filenames.size(); ++i)
100 fs::path pfilename(filenames[i]);
101 fullpath = pinfilename / pfilename;
113 newPtsField->GetPts(pts);
114 ptsField->AddPoints(pts);
134 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
135 size_t np = ptsField->GetNpoints();
137 std::string filename =
SetUpOutput(outFile,
true, backup);
141 std::ofstream ptsFile;
142 ptsFile.open(filename.c_str());
144 ptsFile << R
"(<?xml version="1.0" encoding="utf-8" ?>)" << endl;
145 ptsFile << "<NEKTAR>" << endl;
146 ptsFile <<
" <POINTS ";
147 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
148 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
149 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
150 ptsFile <<
">" << endl;
153 ptsField->GetPts(pts);
154 for (
size_t i = 0; i < np; ++i)
157 ptsFile << pts[0][i];
158 for (
size_t j = 1; j < nTotvars; ++j)
160 ptsFile <<
" " << pts[j][i];
164 ptsFile <<
" </POINTS>" << endl;
165 ptsFile <<
"</NEKTAR>" << endl;
177 TiXmlDocument docInput(inFile);
178 bool loadOkay1 = docInput.LoadFile();
180 std::stringstream errstr;
181 errstr <<
"Unable to load file: " << inFile << std::endl;
182 errstr <<
"Reason: " << docInput.ErrorDesc() << std::endl;
183 errstr <<
"Position: Line " << docInput.ErrorRow() <<
", Column "
184 << docInput.ErrorCol() << std::endl;
187 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
188 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
190 int err = points->QueryIntAttribute(
"DIM", &dim);
192 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
194 std::string fields = points->Attribute(
"FIELDS");
196 vector<string> fieldNames;
202 "Unable to process list of field variable in FIELDS attribute: " +
208 const char *ptinfo = points->Attribute(
"PTSINFO");
209 if (ptinfo && boost::iequals(ptinfo,
"EquiSpaced"))
215 err = points->QueryIntAttribute(
"PTSPERELMTEDGE", &np);
216 if (err == TIXML_SUCCESS)
221 size_t nfields = fieldNames.size();
222 size_t totvars = dim + nfields;
224 TiXmlNode *pointsBody = points->FirstChild();
226 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
228 vector<NekDouble> ptsSerial;
234 while (!pointsDataStrm.fail())
236 pointsDataStrm >> ptsStream;
238 ptsSerial.push_back(ptsStream);
246 size_t npts = ptsSerial.size() / totvars;
248 for (
size_t i = 0; i < totvars; ++i)
253 for (
size_t i = 0; i < npts; ++i)
255 for (
size_t j = 0; j < totvars; ++j)
257 pts[j][i] = ptsSerial[i * totvars + j];
270 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
272 int nprocs =
m_comm->GetSpaceComm()->GetSize();
273 int rank =
m_comm->GetSpaceComm()->GetRank();
275 fs::path specPath(outname);
282 std::vector<std::string> filenames;
283 std::vector<std::vector<unsigned int>> ElementIDs;
284 for (
int i = 0; i < nprocs; ++i)
288 filenames.push_back(pad.str());
290 std::vector<unsigned int> tmp;
292 ElementIDs.push_back(tmp);
299 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)
void SetUpFieldMetaData(const std::string outname)
virtual void v_ImportPtsFieldData(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
static std::string PortablePath(const fs::path &path)
create portable path on different platforms for std::filesystem path.
std::shared_ptr< PtsField > PtsFieldSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.