36 #include <boost/algorithm/string.hpp> 41 #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;
117 newPtsField->GetPts(pts);
118 ptsField->AddPoints(pts);
139 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
140 size_t np = ptsField->GetNpoints();
142 std::string filename =
SetUpOutput(outFile,
true, backup);
146 std::ofstream ptsFile;
147 ptsFile.open(filename.c_str());
149 ptsFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << endl;
150 ptsFile <<
"<NEKTAR>" << endl;
151 ptsFile <<
" <POINTS ";
152 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
153 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
154 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
155 ptsFile <<
">" << endl;
158 ptsField->GetPts(pts);
159 for (
size_t i = 0; i < np; ++i)
162 ptsFile << pts[0][i];
163 for (
size_t j = 1; j < nTotvars; ++j)
165 ptsFile <<
" " << pts[j][i];
169 ptsFile <<
" </POINTS>" << endl;
170 ptsFile <<
"</NEKTAR>" << endl;
219 TiXmlDocument docInput(inFile);
220 bool loadOkay1 = docInput.LoadFile();
222 std::stringstream errstr;
223 errstr <<
"Unable to load file: " << inFile << std::endl;
224 errstr <<
"Reason: " << docInput.ErrorDesc() << std::endl;
225 errstr <<
"Position: Line " << docInput.ErrorRow() <<
", Column " 226 << docInput.ErrorCol() << std::endl;
229 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
230 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
232 int err = points->QueryIntAttribute(
"DIM", &dim);
234 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
236 std::string fields = points->Attribute(
"FIELDS");
238 vector<string> fieldNames;
245 "Unable to process list of field variable in FIELDS attribute: " +
251 const char *ptinfo = points->Attribute(
"PTSINFO");
252 if(ptinfo&&boost::iequals(ptinfo,
"EquiSpaced"))
258 err = points->QueryIntAttribute(
"PTSPERELMTEDGE",&np);
259 if(err == TIXML_SUCCESS)
264 size_t nfields = fieldNames.size();
265 size_t totvars = dim + nfields;
267 TiXmlNode *pointsBody = points->FirstChild();
269 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
271 vector<NekDouble> ptsSerial;
277 while (!pointsDataStrm.fail())
279 pointsDataStrm >> ptsStream;
281 ptsSerial.push_back(ptsStream);
289 size_t npts = ptsSerial.size() / totvars;
291 for (
size_t i = 0; i < totvars; ++i)
296 for (
size_t i = 0; i < npts; ++i)
298 for (
size_t j = 0; j < totvars; ++j)
300 pts[j][i] = ptsSerial[i * totvars + j];
309 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
311 int nprocs =
m_comm->GetSize();
312 int rank =
m_comm->GetRank();
314 fs::path specPath(outname);
321 std::vector<std::string> filenames;
322 std::vector<std::vector<unsigned int> > ElementIDs;
323 for (
int i = 0; i < nprocs; ++i)
327 filenames.push_back(pad.str());
329 std::vector<unsigned int> tmp;
331 ElementIDs.push_back(tmp);
338 cout <<
"Writing: " << specPath << endl;
static std::map< PtsInfo, int > NullPtsInfoMap
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
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::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField)
std::map< std::string, std::string > FieldMetaDataMap
void Import(const std::string &inFile, PtsFieldSharedPtr &ptsField, FieldMetaDataMap &fieldmetadatamap=NullFieldMetaDataMap)
Import a pts field from file.
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
virtual std::string GetFileEnding() const
Helper function that determines default file extension.
std::shared_ptr< PtsField > PtsFieldSharedPtr
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
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.
virtual void v_ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField)
void SetUpFieldMetaData(const std::string outname)