36 #include <boost/algorithm/string.hpp>
41 #include <boost/format.hpp>
56 namespace LibUtilities
76 std::string infile = inFile;
78 fs::path pinfilename(infile);
81 if (fs::is_directory(pinfilename))
83 fs::path infofile(
"Info.xml");
84 fs::path fullpath = pinfilename / infofile;
87 std::vector<std::string> filenames;
88 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
91 infile, filenames, elementIDs_OnPartitions, fieldmetadatamap);
96 if (filenames.size() ==
m_comm->GetSize())
102 filenames.push_back(pad.str());
105 for (
int i = 0; i < filenames.size(); ++i)
107 fs::path pfilename(filenames[i]);
108 fullpath = pinfilename / pfilename;
120 newPtsField->GetPts(pts);
121 ptsField->AddPoints(pts);
142 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
143 size_t np = ptsField->GetNpoints();
145 std::string filename =
SetUpOutput(outFile,
true, backup);
149 std::ofstream ptsFile;
150 ptsFile.open(filename.c_str());
152 ptsFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << endl;
153 ptsFile <<
"<NEKTAR>" << endl;
154 ptsFile <<
" <POINTS ";
155 ptsFile <<
"DIM=\"" << ptsField->GetDim() <<
"\" ";
156 string fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
157 ptsFile <<
"FIELDS=\"" << fn <<
"\" ";
158 ptsFile <<
">" << endl;
161 ptsField->GetPts(pts);
162 for (
size_t i = 0; i < np; ++i)
165 ptsFile << pts[0][i];
166 for (
size_t j = 1; j < nTotvars; ++j)
168 ptsFile <<
" " << pts[j][i];
172 ptsFile <<
" </POINTS>" << endl;
173 ptsFile <<
"</NEKTAR>" << endl;
222 boost::ignore_unused(Range);
223 TiXmlDocument docInput(inFile);
224 bool loadOkay1 = docInput.LoadFile();
226 std::stringstream errstr;
227 errstr <<
"Unable to load file: " << inFile << std::endl;
228 errstr <<
"Reason: " << docInput.ErrorDesc() << std::endl;
229 errstr <<
"Position: Line " << docInput.ErrorRow() <<
", Column "
230 << docInput.ErrorCol() << std::endl;
233 TiXmlElement *nektar = docInput.FirstChildElement(
"NEKTAR");
234 TiXmlElement *points = nektar->FirstChildElement(
"POINTS");
236 int err = points->QueryIntAttribute(
"DIM", &dim);
238 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute DIM.");
240 std::string fields = points->Attribute(
"FIELDS");
242 vector<string> fieldNames;
249 "Unable to process list of field variable in FIELDS attribute: " +
255 const char *ptinfo = points->Attribute(
"PTSINFO");
256 if(ptinfo&&boost::iequals(ptinfo,
"EquiSpaced"))
262 err = points->QueryIntAttribute(
"PTSPERELMTEDGE",&np);
263 if(err == TIXML_SUCCESS)
268 size_t nfields = fieldNames.size();
269 size_t totvars = dim + nfields;
271 TiXmlNode *pointsBody = points->FirstChild();
273 std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
275 vector<NekDouble> ptsSerial;
281 while (!pointsDataStrm.fail())
283 pointsDataStrm >> ptsStream;
285 ptsSerial.push_back(ptsStream);
293 size_t npts = ptsSerial.size() / totvars;
295 for (
size_t i = 0; i < totvars; ++i)
300 for (
size_t i = 0; i < npts; ++i)
302 for (
size_t j = 0; j < totvars; ++j)
304 pts[j][i] = ptsSerial[i * totvars + j];
313 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
315 int nprocs =
m_comm->GetSize();
316 int rank =
m_comm->GetRank();
318 fs::path specPath(outname);
325 std::vector<std::string> filenames;
326 std::vector<std::vector<unsigned int> > ElementIDs;
327 for (
int i = 0; i < nprocs; ++i)
331 filenames.push_back(pad.str());
333 std::vector<unsigned int> tmp;
335 ElementIDs.push_back(tmp);
342 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.
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.
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)
virtual std::string GetFileEnding() const
Helper function that determines default file extension.
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.