36 #include <boost/format.hpp>
37 #include <boost/date_time/posix_time/posix_time.hpp>
38 #include <boost/date_time/posix_time/posix_time_io.hpp>
39 #include <boost/asio/ip/host_name.hpp>
40 #include <boost/archive/iterators/base64_from_binary.hpp>
41 #include <boost/archive/iterators/binary_from_base64.hpp>
42 #include <boost/archive/iterators/transform_width.hpp>
43 #include <boost/iostreams/copy.hpp>
44 #include <boost/iostreams/filter/zlib.hpp>
45 #include <boost/iostreams/filtering_stream.hpp>
46 #include <boost/assign/list_of.hpp>
64 #ifndef NEKTAR_VERSION
65 #define NEKTAR_VERSION "Unknown"
68 namespace ptime = boost::posix_time;
69 namespace ip = boost::asio::ip;
70 namespace berrc = boost::system::errc;
74 namespace LibUtilities
81 void Write(
const std::string &outFile,
82 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
83 std::vector<std::vector<NekDouble> > &fielddata,
89 MPI_Initialized(&init);
98 MPI_Comm_size( MPI_COMM_WORLD, &size );
100 "This static function is not available in parallel. Please"
101 "instantiate a FieldIO object for parallel use.");
106 f.
Write(outFile, fielddefs, fielddata, fieldinfomap);
116 const std::string& infilename,
117 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
118 std::vector<std::vector<NekDouble> > &fielddata,
122 #ifdef NEKTAR_USE_MPI
125 MPI_Initialized(&init);
134 MPI_Comm_size( MPI_COMM_WORLD, &size );
136 "This static function is not available in parallel. Please"
137 "instantiate a FieldIO object for parallel use.");
142 f.
Import(infilename, fielddefs, fielddata, fieldinfomap, ElementiDs);
150 bool sharedFilesystem) :
152 m_sharedFilesystem(sharedFilesystem)
161 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
162 std::vector<std::vector<NekDouble> > &fielddata,
166 ASSERTL1(fielddefs.size() == fielddata.size(),
167 "Length of fielddefs and fielddata incompatible");
168 for (
int f = 0; f < fielddefs.size(); ++f)
171 "Fielddata vector must contain at least one value.");
174 fielddefs[f]->m_fields.size() *
176 "Invalid size of fielddata vector.");
183 if (
m_comm->GetSize() > 1)
190 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
191 doc.LinkEndChild(decl);
193 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
194 doc.LinkEndChild(root);
198 for (
int f = 0; f < fielddefs.size(); ++f)
202 TiXmlElement * elemTag =
new TiXmlElement(
"ELEMENTS");
203 root->LinkEndChild(elemTag);
206 std::string fieldsString;
208 std::stringstream fieldsStringStream;
210 for (std::vector<int>::size_type i = 0; i
211 < fielddefs[f]->m_fields.size(); i++)
214 fieldsStringStream <<
",";
215 fieldsStringStream << fielddefs[f]->m_fields[i];
218 fieldsString = fieldsStringStream.str();
220 elemTag->SetAttribute(
"FIELDS", fieldsString);
223 std::string shapeString;
225 std::stringstream shapeStringStream;
226 shapeStringStream <<
ShapeTypeMap[fielddefs[f]->m_shapeType];
227 if(fielddefs[f]->m_numHomogeneousDir == 1)
229 shapeStringStream <<
"-HomogenousExp1D";
231 else if (fielddefs[f]->m_numHomogeneousDir == 2)
233 shapeStringStream <<
"-HomogenousExp2D";
236 if (fielddefs[f]->m_homoStrips)
238 shapeStringStream <<
"-Strips";
241 shapeString = shapeStringStream.str();
243 elemTag->SetAttribute(
"SHAPE", shapeString);
246 std::string basisString;
248 std::stringstream basisStringStream;
250 for (std::vector<BasisType>::size_type i = 0; i < fielddefs[f]->m_basis.size(); i++)
253 basisStringStream <<
",";
258 basisString = basisStringStream.str();
260 elemTag->SetAttribute(
"BASIS", basisString);
263 if(fielddefs[f]->m_numHomogeneousDir)
265 std::string homoLenString;
267 std::stringstream homoLenStringStream;
269 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
272 homoLenStringStream <<
",";
274 << fielddefs[f]->m_homogeneousLengths[i];
277 homoLenString = homoLenStringStream.str();
279 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
283 if(fielddefs[f]->m_numHomogeneousDir)
285 if(fielddefs[f]->m_homogeneousYIDs.size() > 0)
287 std::string homoYIDsString;
289 std::stringstream homoYIDsStringStream;
291 for(
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size(); i++)
294 homoYIDsStringStream <<
",";
295 homoYIDsStringStream << fielddefs[f]->m_homogeneousYIDs[i];
298 homoYIDsString = homoYIDsStringStream.str();
300 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
303 if(fielddefs[f]->m_homogeneousZIDs.size() > 0)
305 std::string homoZIDsString;
307 std::stringstream homoZIDsStringStream;
309 for(
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size(); i++)
312 homoZIDsStringStream <<
",";
313 homoZIDsStringStream << fielddefs[f]->m_homogeneousZIDs[i];
316 homoZIDsString = homoZIDsStringStream.str();
318 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
321 if(fielddefs[f]->m_homogeneousSIDs.size() > 0)
323 std::string homoSIDsString;
325 std::stringstream homoSIDsStringStream;
327 for(
int i = 0; i < fielddefs[f]->m_homogeneousSIDs.size(); i++)
330 homoSIDsStringStream <<
",";
331 homoSIDsStringStream << fielddefs[f]->m_homogeneousSIDs[i];
334 homoSIDsString = homoSIDsStringStream.str();
336 elemTag->SetAttribute(
"HOMOGENEOUSSIDS", homoSIDsString);
341 std::string numModesString;
343 std::stringstream numModesStringStream;
345 if (fielddefs[f]->m_uniOrder)
347 numModesStringStream <<
"UNIORDER:";
350 for (std::vector<int>::size_type i = 0; i
351 < fielddefs[f]->m_basis.size(); i++)
354 numModesStringStream <<
",";
355 numModesStringStream << fielddefs[f]->m_numModes[i];
361 numModesStringStream <<
"MIXORDER:";
363 for (std::vector<int>::size_type i = 0; i
364 < fielddefs[f]->m_numModes.size(); i++)
367 numModesStringStream <<
",";
368 numModesStringStream << fielddefs[f]->m_numModes[i];
373 numModesString = numModesStringStream.str();
375 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
380 std::string idString;
382 std::stringstream idStringStream;
385 elemTag->SetAttribute(
"ID", idString);
386 elemTag->SetAttribute(
"COMPRESSED",
392 elemTag->SetAttribute(
"BITSIZE",
394 std::string base64string;
396 fielddata[f], base64string),
397 "Failed to compress field data.");
399 elemTag->LinkEndChild(
new TiXmlText(base64string));
402 doc.SaveFile(filename);
410 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
411 std::vector<std::vector<NekDouble> > &fielddata,
416 std::string infile = infilename;
418 fs::path pinfilename(infilename);
420 if(fs::is_directory(pinfilename))
422 fs::path infofile(
"Info.xml");
423 fs::path fullpath = pinfilename / infofile;
426 std::vector<std::string> filenames;
427 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
438 for(
int i = 0; i < filenames.size(); ++i)
440 fs::path pfilename(filenames[i]);
441 fullpath = pinfilename / pfilename;
444 TiXmlDocument doc1(fname);
445 bool loadOkay1 = doc1.LoadFile();
447 std::stringstream errstr;
448 errstr <<
"Unable to load file: " << fname << std::endl;
449 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
450 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
464 map<int,vector<int> > FileIDs;
468 for(i = 0; i < elementIDs_OnPartitions.size(); ++i)
470 for(j = 0; j < elementIDs_OnPartitions[i].size(); ++j)
472 FileIDs[elementIDs_OnPartitions[i][j]].push_back(i);
476 for(i = 0; i < ElementIDs.num_elements(); ++i)
478 it = FileIDs.find(ElementIDs[i]);
479 if (it != FileIDs.end())
481 for (j = 0; j < it->second.size(); ++j)
483 LoadFile.insert(it->second[j]);
489 for(iter = LoadFile.begin(); iter != LoadFile.end(); ++iter)
491 fs::path pfilename(filenames[*iter]);
492 fullpath = pinfilename / pfilename;
494 TiXmlDocument doc1(fname);
495 bool loadOkay1 = doc1.LoadFile();
497 std::stringstream errstr;
498 errstr <<
"Unable to load file: " << fname << std::endl;
499 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
500 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
514 TiXmlDocument doc(infile);
515 bool loadOkay = doc.LoadFile();
517 std::stringstream errstr;
518 errstr <<
"Unable to load file: " << infile << std::endl;
519 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
520 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " <<
521 doc.ErrorCol() << std::endl;
538 const std::vector<std::string> fileNames,
539 std::vector<std::vector<unsigned int> > &elementList,
543 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
544 doc.LinkEndChild(decl);
546 ASSERTL0(fileNames.size() == elementList.size(),
"Outfile names and list of elements ids does not match");
548 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
549 doc.LinkEndChild(root);
553 for (
int t = 0; t < fileNames.size(); ++t)
555 if(elementList[t].size())
557 TiXmlElement * elemIDs =
new TiXmlElement(
"Partition");
558 root->LinkEndChild(elemIDs);
560 elemIDs->SetAttribute(
"FileName",fileNames[t]);
566 elemIDs->LinkEndChild(
new TiXmlText(IDstring));
570 doc.SaveFile(outFile);
578 std::vector<std::string> &fileNames,
579 std::vector<std::vector<unsigned int> > &elementList,
582 TiXmlDocument doc(inFile);
583 bool loadOkay = doc.LoadFile();
586 std::stringstream errstr;
587 errstr <<
"Unable to load file: " << inFile<< std::endl;
588 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
589 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
593 TiXmlHandle docHandle(&doc);
597 TiXmlElement* master = doc.FirstChildElement(
"NEKTAR");
598 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
601 std::string strPartition =
"Partition";
604 TiXmlElement* fldfileIDs = master->FirstChildElement(strPartition.c_str());
608 strPartition =
"MultipleFldFiles";
609 fldfileIDs = master->FirstChildElement(
"MultipleFldFiles");
612 "Unable to find 'Partition' or 'MultipleFldFiles' tag "
613 "within nektar tag.");
618 const char *attr = fldfileIDs->Attribute(
"FileName");
619 ASSERTL0(attr,
"'FileName' not provided as an attribute of '"
620 + strPartition +
"' tag.");
621 fileNames.push_back(std::string(attr));
623 const char* elementIDs = fldfileIDs->GetText();
624 ASSERTL0(elementIDs,
"Element IDs not specified.");
626 std::string elementIDsStr(elementIDs);
628 std::vector<unsigned int> idvec;
631 elementList.push_back(idvec);
633 fldfileIDs = fldfileIDs->NextSiblingElement(strPartition.c_str());
640 TiXmlDocument doc(filename);
641 bool loadOkay = doc.LoadFile();
643 std::stringstream errstr;
644 errstr <<
"Unable to load file: " << filename << std::endl;
645 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
646 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
657 TiXmlHandle docHandle(&doc);
658 TiXmlElement* master = 0;
659 TiXmlElement* metadata = 0;
661 master = doc.FirstChildElement(
"NEKTAR");
662 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
663 std::string strLoop =
"NEKTAR";
667 metadata = master->FirstChildElement(
"FIELDMETADATA");
670 TiXmlElement *param = metadata->FirstChildElement(
"P");
674 TiXmlAttribute *paramAttr = param->FirstAttribute();
675 std::string attrName(paramAttr->Name());
676 std::string paramString;
678 if(attrName ==
"PARAM")
680 paramString.insert(0,paramAttr->Value());
684 ASSERTL0(
false,
"PARAM not provided as an attribute in FIELDMETADATA section");
688 std::string paramBodyStr;
690 TiXmlNode *paramBody = param->FirstChild();
692 paramBodyStr += paramBody->ToText()->Value();
694 fieldmetadatamap[paramString] = paramBodyStr;
695 param = param->NextSiblingElement(
"P");
700 metadata = master->FirstChildElement(
"Metadata");
703 TiXmlElement *param = metadata->FirstChildElement();
707 std::string paramString = param->Value();
708 if (paramString !=
"Provenance")
711 TiXmlNode *paramBody = param->FirstChild();
712 std::string paramBodyStr = paramBody->ToText()->Value();
714 fieldmetadatamap[paramString] = paramBodyStr;
716 param = param->NextSiblingElement();
729 TiXmlHandle docHandle(&doc);
730 TiXmlElement* master = NULL;
732 master = doc.FirstChildElement(
"NEKTAR");
733 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
734 std::string strLoop =
"NEKTAR";
735 TiXmlElement* loopXml = master;
737 TiXmlElement *expansionTypes;
740 expansionTypes = master->FirstChildElement(
"EXPANSIONS");
741 ASSERTL0(expansionTypes,
"Unable to find EXPANSIONS tag in file.");
742 loopXml = expansionTypes;
743 strLoop =
"EXPANSIONS";
749 TiXmlElement* element = loopXml->FirstChildElement(
"ELEMENTS");
750 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
755 std::string idString;
756 std::string shapeString;
757 std::string basisString;
758 std::string homoLengthsString;
759 std::string homoSIDsString;
760 std::string homoZIDsString;
761 std::string homoYIDsString;
762 std::string numModesString;
763 std::string numPointsString;
764 std::string fieldsString;
765 std::string pointsString;
766 bool pointDef =
false;
767 bool numPointDef =
false;
768 TiXmlAttribute *attr = element->FirstAttribute();
771 std::string attrName(attr->Name());
772 if (attrName ==
"FIELDS")
774 fieldsString.insert(0, attr->Value());
776 else if (attrName ==
"SHAPE")
778 shapeString.insert(0, attr->Value());
780 else if (attrName ==
"BASIS")
782 basisString.insert(0, attr->Value());
784 else if (attrName ==
"HOMOGENEOUSLENGTHS")
786 homoLengthsString.insert(0,attr->Value());
788 else if (attrName ==
"HOMOGENEOUSSIDS")
790 homoSIDsString.insert(0,attr->Value());
792 else if (attrName ==
"HOMOGENEOUSZIDS")
794 homoZIDsString.insert(0,attr->Value());
796 else if (attrName ==
"HOMOGENEOUSYIDS")
798 homoYIDsString.insert(0,attr->Value());
800 else if (attrName ==
"NUMMODESPERDIR")
802 numModesString.insert(0, attr->Value());
804 else if (attrName ==
"ID")
806 idString.insert(0, attr->Value());
808 else if (attrName ==
"POINTSTYPE")
810 pointsString.insert(0, attr->Value());
813 else if (attrName ==
"NUMPOINTSPERDIR")
815 numPointsString.insert(0, attr->Value());
818 else if (attrName ==
"COMPRESSED")
820 if(!boost::iequals(attr->Value(),
823 WARNINGL0(
false,
"Compressed formats do not "
826 +
" but got "+
string(attr->Value()));
829 else if (attrName ==
"BITSIZE")
838 std::string errstr(
"Unknown attribute: ");
850 if(shapeString.find(
"Strips")!=string::npos)
860 if((loc = shapeString.find_first_of(
"-"))!=string::npos)
862 if(shapeString.find(
"Exp1D")!=string::npos)
871 shapeString.erase(loc,shapeString.length());
875 std::vector<unsigned int> elementIds;
878 ASSERTL0(valid,
"Unable to correctly parse the element ids.");
894 ASSERTL0(valid, std::string(
"Unable to correctly parse the shape type: ").append(shapeString).c_str());
897 std::vector<std::string> basisStrings;
898 std::vector<BasisType> basis;
900 ASSERTL0(valid,
"Unable to correctly parse the basis types.");
901 for (std::vector<std::string>::size_type i = 0; i < basisStrings.size(); i++)
913 ASSERTL0(valid, std::string(
"Unable to correctly parse the basis type: ").append(basisStrings[i]).c_str());
917 std::vector<NekDouble> homoLengths;
921 ASSERTL0(valid,
"Unable to correctly parse the number of homogeneous lengths.");
925 std::vector<unsigned int> homoSIDs;
929 ASSERTL0(valid,
"Unable to correctly parse homogeneous strips IDs.");
932 std::vector<unsigned int> homoZIDs;
933 std::vector<unsigned int> homoYIDs;
938 ASSERTL0(valid,
"Unable to correctly parse homogeneous planes IDs.");
944 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in z-direction.");
946 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in y-direction.");
951 std::vector<PointsType> points;
955 std::vector<std::string> pointsStrings;
957 ASSERTL0(valid,
"Unable to correctly parse the points types.");
958 for (std::vector<std::string>::size_type i = 0; i < pointsStrings.size(); i++)
971 ASSERTL0(valid, std::string(
"Unable to correctly parse the points type: ").append(pointsStrings[i]).c_str());
976 std::vector<unsigned int> numModes;
977 bool UniOrder =
false;
979 if(strstr(numModesString.c_str(),
"UNIORDER:"))
985 ASSERTL0(valid,
"Unable to correctly parse the number of modes.");
988 std::vector<unsigned int> numPoints;
992 ASSERTL0(valid,
"Unable to correctly parse the number of points.");
996 std::vector<std::string> Fields;
998 ASSERTL0(valid,
"Unable to correctly parse the number of fields.");
1002 elementIds, basis, UniOrder, numModes, Fields, numHomoDir,
1003 homoLengths, strips, homoSIDs, homoZIDs, homoYIDs,
1004 points, pointDef, numPoints, numPointDef);
1006 fielddefs.push_back(fielddef);
1008 element = element->NextSiblingElement(
"ELEMENTS");
1010 loopXml = loopXml->NextSiblingElement(strLoop);
1018 void FieldIO::ImportFieldData(TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs, std::vector<std::vector<NekDouble> > &fielddata)
1022 TiXmlHandle docHandle(&doc);
1023 TiXmlElement* master = NULL;
1025 master = doc.FirstChildElement(
"NEKTAR");
1026 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
1031 TiXmlElement* element = master->FirstChildElement(
"ELEMENTS");
1032 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
1036 TiXmlNode* elementChild = element->FirstChild();
1037 ASSERTL0(elementChild,
"Unable to extract the data from the element tag.");
1038 std::string elementStr;
1041 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1043 elementStr += elementChild->ToText()->ValueStr();
1045 elementChild = elementChild->NextSibling();
1048 std::vector<NekDouble> elementFieldData;
1051 const char *CompressStr = element->Attribute(
"COMPRESSED");
1054 if(!boost::iequals(CompressStr,
1057 WARNINGL0(
false,
"Compressed formats do not match. "
1060 +
" but got "+
string(CompressStr));
1067 "Failed to decompress field data.");
1070 fielddata.push_back(elementFieldData);
1073 ASSERTL0(fielddata[cntdumps].size() == datasize*fielddefs[cntdumps]->m_fields.size(),
"Input data is not the same length as header infoarmation");
1077 element = element->NextSiblingElement(
"ELEMENTS");
1079 master = master->NextSiblingElement(
"NEKTAR");
1096 ptime::time_facet *facet =
new ptime::time_facet(
"%d-%b-%Y %H:%M:%S");
1097 std::stringstream wss;
1098 wss.imbue(locale(wss.getloc(), facet));
1099 wss << ptime::second_clock::local_time();
1100 ProvenanceMap[
"Timestamp"] = wss.str();
1103 boost::system::error_code ec;
1104 ProvenanceMap[
"Hostname"] = ip::host_name(ec);
1114 TiXmlElement * infoTag =
new TiXmlElement(
"Metadata");
1115 root->LinkEndChild(infoTag);
1118 FieldMetaDataMap::const_iterator infoit;
1120 TiXmlElement * provTag =
new TiXmlElement(
"Provenance");
1121 infoTag->LinkEndChild(provTag);
1122 for (infoit = ProvenanceMap.begin(); infoit != ProvenanceMap.end(); ++infoit)
1124 v =
new TiXmlElement( (infoit->first).c_str() );
1125 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1126 provTag->LinkEndChild(v);
1133 for(infoit = fieldmetadatamap.begin(); infoit != fieldmetadatamap.end(); ++infoit)
1135 v =
new TiXmlElement( (infoit->first).c_str() );
1136 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1137 infoTag->LinkEndChild(v);
1147 std::string &idString)
1149 std::stringstream idStringStream;
1150 bool setdash =
true;
1151 unsigned int endval;
1153 idStringStream << elmtids[0];
1154 for (
int i = 1; i < elmtids.size(); ++i)
1156 if(elmtids[i] == elmtids[i-1]+1)
1160 idStringStream <<
"-";
1164 if(i == elmtids.size()-1)
1166 idStringStream << elmtids[i];
1170 endval = elmtids[i];
1175 if(setdash ==
false)
1177 idStringStream << endval;
1182 idStringStream <<
"," << elmtids[i];
1185 idString = idStringStream.str();
1194 ASSERTL0(!outname.empty(),
"Empty path given to SetUpOutput()");
1196 int nprocs =
m_comm->GetSize();
1197 int rank =
m_comm->GetRank();
1201 fs::path specPath (outname);
1202 fs::path fulloutname;
1206 fulloutname = specPath;
1211 boost::format pad(
"P%1$07d.%2$s");
1215 fs::path poutfile(pad.str());
1216 fulloutname = specPath / poutfile;
1220 if (
m_comm->RemoveExistingFiles())
1230 fs::remove_all(fulloutname);
1232 catch (fs::filesystem_error& e)
1234 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1235 "Filesystem error: " + string(e.what()));
1246 fs::remove_all(specPath);
1248 catch (fs::filesystem_error& e)
1250 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1251 "Filesystem error: " + string(e.what()));
1261 cout <<
"Writing: " << specPath << endl;
1270 fs::create_directory(specPath);
1273 catch (fs::filesystem_error& e)
1275 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
1286 const string outname,
1287 const vector< FieldDefinitionsSharedPtr > &fielddefs,
1290 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
1292 int nprocs =
m_comm->GetSize();
1293 int rank =
m_comm->GetRank();
1295 fs::path specPath (outname);
1300 std::vector<unsigned int> elmtnums(nprocs,0);
1301 std::vector<unsigned int> idlist;
1303 for (i = 0; i < fielddefs.size(); ++i)
1305 elmtnums[rank] += fielddefs[i]->m_elementIDs.size();
1306 idlist.insert(idlist.end(), fielddefs[i]->m_elementIDs.begin(),
1307 fielddefs[i]->m_elementIDs.end());
1315 std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
1318 ElementIDs[0] = idlist;
1319 for (i = 1; i < nprocs; ++i)
1321 std::vector<unsigned int> tmp(elmtnums[i]);
1323 ElementIDs[i] = tmp;
1327 std::vector<std::string> filenames;
1328 for(
int i = 0; i < nprocs; ++i)
1330 boost::format pad(
"P%1$07d.%2$s");
1332 filenames.push_back(pad.str());
1337 specPath / fs::path(
"Info.xml"));
1339 cout <<
"Writing: " << specPath << endl;
1359 if(fielddefs->m_elementIDs.size() == 0)
1365 unsigned int numbasis = 0;
1368 switch(fielddefs->m_shapeType)
1372 if(fielddefs->m_numHomogeneousDir)
1374 numbasis += fielddefs->m_numHomogeneousDir;
1380 if(fielddefs->m_numHomogeneousDir)
1396 ASSERTL0(
false,
"Unsupported shape type.");
1400 unsigned int datasize = 0;
1402 ASSERTL0(fielddefs->m_basis.size() == numbasis,
"Length of basis vector is incorrect");
1404 if(fielddefs->m_uniOrder ==
true)
1406 unsigned int cnt = 0;
1408 switch(fielddefs->m_shapeType)
1412 int l = fielddefs->m_numModes[cnt++];
1413 if(fielddefs->m_numHomogeneousDir == 1)
1415 datasize += l*fielddefs->m_numModes[cnt++];
1417 else if(fielddefs->m_numHomogeneousDir == 2)
1419 int m = fielddefs->m_numModes[cnt++];
1420 datasize += l*m*fielddefs->m_numModes[cnt++];
1430 int l = fielddefs->m_numModes[cnt++];
1431 int m = fielddefs->m_numModes[cnt++];
1433 if(fielddefs->m_numHomogeneousDir == 1)
1436 fielddefs->m_homogeneousZIDs.size();
1446 int l = fielddefs->m_numModes[cnt++];
1447 int m = fielddefs->m_numModes[cnt++];
1448 if(fielddefs->m_numHomogeneousDir == 1)
1450 datasize += l*m*fielddefs->m_homogeneousZIDs.size();
1460 int l = fielddefs->m_numModes[cnt++];
1461 int m = fielddefs->m_numModes[cnt++];
1462 int n = fielddefs->m_numModes[cnt++];
1468 int l = fielddefs->m_numModes[cnt++];
1469 int m = fielddefs->m_numModes[cnt++];
1470 int n = fielddefs->m_numModes[cnt++];
1476 int l = fielddefs->m_numModes[cnt++];
1477 int m = fielddefs->m_numModes[cnt++];
1478 int n = fielddefs->m_numModes[cnt++];
1484 int l = fielddefs->m_numModes[cnt++];
1485 int m = fielddefs->m_numModes[cnt++];
1486 int n = fielddefs->m_numModes[cnt++];
1491 ASSERTL0(
false,
"Unsupported shape type.");
1495 datasize *= fielddefs->m_elementIDs.size();
1499 unsigned int cnt = 0;
1501 for(i = 0; i < fielddefs->m_elementIDs.size(); ++i)
1503 switch(fielddefs->m_shapeType)
1507 int l = fielddefs->m_numModes[cnt++];
1508 if(fielddefs->m_numHomogeneousDir == 1)
1510 datasize += l*fielddefs->m_numModes[cnt++];
1512 else if(fielddefs->m_numHomogeneousDir == 2)
1514 int m = fielddefs->m_numModes[cnt++];
1515 datasize += l*m*fielddefs->m_numModes[cnt++];
1525 int l = fielddefs->m_numModes[cnt++];
1526 int m = fielddefs->m_numModes[cnt++];
1527 if(fielddefs->m_numHomogeneousDir == 1)
1530 fielddefs->m_homogeneousZIDs.size();
1541 int l = fielddefs->m_numModes[cnt++];
1542 int m = fielddefs->m_numModes[cnt++];
1543 if(fielddefs->m_numHomogeneousDir == 1)
1545 datasize += l*m*fielddefs->
1546 m_homogeneousZIDs.size();
1557 int l = fielddefs->m_numModes[cnt++];
1558 int m = fielddefs->m_numModes[cnt++];
1559 int n = fielddefs->m_numModes[cnt++];
1565 int l = fielddefs->m_numModes[cnt++];
1566 int m = fielddefs->m_numModes[cnt++];
1567 int n = fielddefs->m_numModes[cnt++];
1573 int l = fielddefs->m_numModes[cnt++];
1574 int m = fielddefs->m_numModes[cnt++];
1575 int n = fielddefs->m_numModes[cnt++];
1581 int l = fielddefs->m_numModes[cnt++];
1582 int m = fielddefs->m_numModes[cnt++];
1583 int n = fielddefs->m_numModes[cnt++];
1588 ASSERTL0(
false,
"Unsupported shape type.");
#define ASSERTL0(condition, msg)
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
void ImportFieldDefs(TiXmlDocument &doc, std::vector< FieldDefinitionsSharedPtr > &fielddefs, bool expChild)
Imports the definition of the fields.
int getNumberOfCoefficients(int Na, int Nb, int Nc)
static bool GenerateOrderedVector(const char *const str, std::vector< unsigned int > &vec)
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
const char *const BasisTypeMap[]
void ImportFieldData(TiXmlDocument &doc, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata)
Imports the data fileds.
const std::string kPointsTypeStr[]
FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
Constructor.
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata=NullVectorNekDoubleVector, FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap, const Array< OneD, int > ElementiDs=NullInt1DArray)
Imports an FLD file.
boost::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
void ImportMultiFldFileIDs(const std::string &inFile, std::vector< std::string > &fileNames, std::vector< std::vector< unsigned int > > &elementList, FieldMetaDataMap &fieldmetadatamap)
std::string SetUpOutput(const std::string outname)
int getNumberOfCoefficients(int Na, int Nb, int Nc)
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
std::map< std::string, std::string > FieldMetaDataMap
CommFactory & GetCommFactory()
int CheckFieldDefinition(const FieldDefinitionsSharedPtr &fielddefs)
const char *const ShapeTypeMap[]
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
void GenerateSeqString(const std::vector< unsigned int > &elmtids, std::string &idString)
std::string GetCompressString(void)
bool m_sharedFilesystem
True if same filesystem accessible by all processes.
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void AddInfoTag(TiXmlElement *root, const FieldMetaDataMap &fieldmetadatamap)
add information about provenance and fieldmetadata
const std::string kGitSha1
#define LIB_UTILITIES_EXPORT
#define WARNINGL0(condition, msg)
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
int getNumberOfCoefficients(int Na, int Nb)
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
const std::string kGitBranch
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
int ZlibEncodeToBase64Str(std::vector< T > &in, std::string &out64)
void SetUpFieldMetaData(const std::string outname, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, const FieldMetaDataMap &fieldmetadatamap)
int getNumberOfCoefficients(int Na, int Nb, int Nc)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::string GetBitSizeStr(void)
void WriteMultiFldFileIDs(const std::string &outfile, const std::vector< std::string > fileNames, std::vector< std::vector< unsigned int > > &elementList, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Class for operating on FLD files.
void ImportFieldMetaData(std::string filename, FieldMetaDataMap &fieldmetadatamap)
Imports the definition of the meta data.
virtual std::string GetFileEnding() const
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Write data in FLD format.
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap)
Write a field file in serial only.
static Array< OneD, int > NullInt1DArray
static bool GenerateUnOrderedVector(const char *const str, std::vector< NekDouble > &vec)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
static FieldMetaDataMap NullFieldMetaDataMap
int ZlibDecodeFromBase64Str(std::string &in64, std::vector< T > &out)