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.");
187 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
188 doc.LinkEndChild(decl);
190 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
191 doc.LinkEndChild(root);
195 for (
int f = 0; f < fielddefs.size(); ++f)
199 TiXmlElement * elemTag =
new TiXmlElement(
"ELEMENTS");
200 root->LinkEndChild(elemTag);
203 std::string fieldsString;
205 std::stringstream fieldsStringStream;
207 for (std::vector<int>::size_type i = 0; i
208 < fielddefs[f]->m_fields.size(); i++)
211 fieldsStringStream <<
",";
212 fieldsStringStream << fielddefs[f]->m_fields[i];
215 fieldsString = fieldsStringStream.str();
217 elemTag->SetAttribute(
"FIELDS", fieldsString);
220 std::string shapeString;
222 std::stringstream shapeStringStream;
223 shapeStringStream <<
ShapeTypeMap[fielddefs[f]->m_shapeType];
224 if(fielddefs[f]->m_numHomogeneousDir == 1)
226 shapeStringStream <<
"-HomogenousExp1D";
228 else if (fielddefs[f]->m_numHomogeneousDir == 2)
230 shapeStringStream <<
"-HomogenousExp2D";
233 if (fielddefs[f]->m_homoStrips)
235 shapeStringStream <<
"-Strips";
238 shapeString = shapeStringStream.str();
240 elemTag->SetAttribute(
"SHAPE", shapeString);
243 std::string basisString;
245 std::stringstream basisStringStream;
247 for (std::vector<BasisType>::size_type i = 0; i < fielddefs[f]->m_basis.size(); i++)
250 basisStringStream <<
",";
255 basisString = basisStringStream.str();
257 elemTag->SetAttribute(
"BASIS", basisString);
260 if(fielddefs[f]->m_numHomogeneousDir)
262 std::string homoLenString;
264 std::stringstream homoLenStringStream;
266 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
269 homoLenStringStream <<
",";
271 << fielddefs[f]->m_homogeneousLengths[i];
274 homoLenString = homoLenStringStream.str();
276 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
280 if(fielddefs[f]->m_numHomogeneousDir)
282 if(fielddefs[f]->m_homogeneousYIDs.size() > 0)
284 std::string homoYIDsString;
286 std::stringstream homoYIDsStringStream;
288 for(
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size(); i++)
291 homoYIDsStringStream <<
",";
292 homoYIDsStringStream << fielddefs[f]->m_homogeneousYIDs[i];
295 homoYIDsString = homoYIDsStringStream.str();
297 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
300 if(fielddefs[f]->m_homogeneousZIDs.size() > 0)
302 std::string homoZIDsString;
304 std::stringstream homoZIDsStringStream;
306 for(
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size(); i++)
309 homoZIDsStringStream <<
",";
310 homoZIDsStringStream << fielddefs[f]->m_homogeneousZIDs[i];
313 homoZIDsString = homoZIDsStringStream.str();
315 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
318 if(fielddefs[f]->m_homogeneousSIDs.size() > 0)
320 std::string homoSIDsString;
322 std::stringstream homoSIDsStringStream;
324 for(
int i = 0; i < fielddefs[f]->m_homogeneousSIDs.size(); i++)
327 homoSIDsStringStream <<
",";
328 homoSIDsStringStream << fielddefs[f]->m_homogeneousSIDs[i];
331 homoSIDsString = homoSIDsStringStream.str();
333 elemTag->SetAttribute(
"HOMOGENEOUSSIDS", homoSIDsString);
338 std::string numModesString;
340 std::stringstream numModesStringStream;
342 if (fielddefs[f]->m_uniOrder)
344 numModesStringStream <<
"UNIORDER:";
347 for (std::vector<int>::size_type i = 0; i
348 < fielddefs[f]->m_basis.size(); i++)
351 numModesStringStream <<
",";
352 numModesStringStream << fielddefs[f]->m_numModes[i];
358 numModesStringStream <<
"MIXORDER:";
360 for (std::vector<int>::size_type i = 0; i
361 < fielddefs[f]->m_numModes.size(); i++)
364 numModesStringStream <<
",";
365 numModesStringStream << fielddefs[f]->m_numModes[i];
370 numModesString = numModesStringStream.str();
372 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
377 std::string idString;
379 std::stringstream idStringStream;
382 elemTag->SetAttribute(
"ID", idString);
383 elemTag->SetAttribute(
"COMPRESSED",
389 elemTag->SetAttribute(
"BITSIZE",
391 std::string base64string;
393 fielddata[f], base64string),
394 "Failed to compress field data.");
396 elemTag->LinkEndChild(
new TiXmlText(base64string));
399 doc.SaveFile(filename);
407 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
408 std::vector<std::vector<NekDouble> > &fielddata,
413 std::string infile = infilename;
415 fs::path pinfilename(infilename);
417 if(fs::is_directory(pinfilename))
419 fs::path infofile(
"Info.xml");
420 fs::path fullpath = pinfilename / infofile;
423 std::vector<std::string> filenames;
424 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
435 for(
int i = 0; i < filenames.size(); ++i)
437 fs::path pfilename(filenames[i]);
438 fullpath = pinfilename / pfilename;
441 TiXmlDocument doc1(fname);
442 bool loadOkay1 = doc1.LoadFile();
444 std::stringstream errstr;
445 errstr <<
"Unable to load file: " << fname << std::endl;
446 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
447 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
461 map<int,vector<int> > FileIDs;
465 for(i = 0; i < elementIDs_OnPartitions.size(); ++i)
467 for(j = 0; j < elementIDs_OnPartitions[i].size(); ++j)
469 FileIDs[elementIDs_OnPartitions[i][j]].push_back(i);
473 for(i = 0; i < ElementIDs.num_elements(); ++i)
475 it = FileIDs.find(ElementIDs[i]);
476 if (it != FileIDs.end())
478 for (j = 0; j < it->second.size(); ++j)
480 LoadFile.insert(it->second[j]);
486 for(iter = LoadFile.begin(); iter != LoadFile.end(); ++iter)
488 fs::path pfilename(filenames[*iter]);
489 fullpath = pinfilename / pfilename;
491 TiXmlDocument doc1(fname);
492 bool loadOkay1 = doc1.LoadFile();
494 std::stringstream errstr;
495 errstr <<
"Unable to load file: " << fname << std::endl;
496 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
497 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
511 TiXmlDocument doc(infile);
512 bool loadOkay = doc.LoadFile();
514 std::stringstream errstr;
515 errstr <<
"Unable to load file: " << infile << std::endl;
516 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
517 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " <<
518 doc.ErrorCol() << std::endl;
535 const std::vector<std::string> fileNames,
536 std::vector<std::vector<unsigned int> > &elementList,
540 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
541 doc.LinkEndChild(decl);
543 ASSERTL0(fileNames.size() == elementList.size(),
"Outfile names and list of elements ids does not match");
545 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
546 doc.LinkEndChild(root);
550 for (
int t = 0; t < fileNames.size(); ++t)
552 if(elementList[t].size())
554 TiXmlElement * elemIDs =
new TiXmlElement(
"Partition");
555 root->LinkEndChild(elemIDs);
557 elemIDs->SetAttribute(
"FileName",fileNames[t]);
563 elemIDs->LinkEndChild(
new TiXmlText(IDstring));
567 doc.SaveFile(outFile);
575 std::vector<std::string> &fileNames,
576 std::vector<std::vector<unsigned int> > &elementList,
579 TiXmlDocument doc(inFile);
580 bool loadOkay = doc.LoadFile();
583 std::stringstream errstr;
584 errstr <<
"Unable to load file: " << inFile<< std::endl;
585 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
586 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
590 TiXmlHandle docHandle(&doc);
594 TiXmlElement* master = doc.FirstChildElement(
"NEKTAR");
595 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
598 std::string strPartition =
"Partition";
601 TiXmlElement* fldfileIDs = master->FirstChildElement(strPartition.c_str());
605 strPartition =
"MultipleFldFiles";
606 fldfileIDs = master->FirstChildElement(
"MultipleFldFiles");
609 "Unable to find 'Partition' or 'MultipleFldFiles' tag "
610 "within nektar tag.");
615 const char *attr = fldfileIDs->Attribute(
"FileName");
616 ASSERTL0(attr,
"'FileName' not provided as an attribute of '"
617 + strPartition +
"' tag.");
618 fileNames.push_back(std::string(attr));
620 const char* elementIDs = fldfileIDs->GetText();
621 ASSERTL0(elementIDs,
"Element IDs not specified.");
623 std::string elementIDsStr(elementIDs);
625 std::vector<unsigned int> idvec;
628 elementList.push_back(idvec);
630 fldfileIDs = fldfileIDs->NextSiblingElement(strPartition.c_str());
637 TiXmlDocument doc(filename);
638 bool loadOkay = doc.LoadFile();
640 std::stringstream errstr;
641 errstr <<
"Unable to load file: " << filename << std::endl;
642 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
643 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
654 TiXmlHandle docHandle(&doc);
655 TiXmlElement* master = 0;
656 TiXmlElement* metadata = 0;
658 master = doc.FirstChildElement(
"NEKTAR");
659 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
660 std::string strLoop =
"NEKTAR";
664 metadata = master->FirstChildElement(
"FIELDMETADATA");
667 TiXmlElement *param = metadata->FirstChildElement(
"P");
671 TiXmlAttribute *paramAttr = param->FirstAttribute();
672 std::string attrName(paramAttr->Name());
673 std::string paramString;
675 if(attrName ==
"PARAM")
677 paramString.insert(0,paramAttr->Value());
681 ASSERTL0(
false,
"PARAM not provided as an attribute in FIELDMETADATA section");
685 std::string paramBodyStr;
687 TiXmlNode *paramBody = param->FirstChild();
689 paramBodyStr += paramBody->ToText()->Value();
691 fieldmetadatamap[paramString] = paramBodyStr;
692 param = param->NextSiblingElement(
"P");
697 metadata = master->FirstChildElement(
"Metadata");
700 TiXmlElement *param = metadata->FirstChildElement();
704 std::string paramString = param->Value();
705 if (paramString !=
"Provenance")
708 TiXmlNode *paramBody = param->FirstChild();
709 std::string paramBodyStr = paramBody->ToText()->Value();
711 fieldmetadatamap[paramString] = paramBodyStr;
713 param = param->NextSiblingElement();
726 TiXmlHandle docHandle(&doc);
727 TiXmlElement* master = NULL;
729 master = doc.FirstChildElement(
"NEKTAR");
730 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
731 std::string strLoop =
"NEKTAR";
732 TiXmlElement* loopXml = master;
734 TiXmlElement *expansionTypes;
737 expansionTypes = master->FirstChildElement(
"EXPANSIONS");
738 ASSERTL0(expansionTypes,
"Unable to find EXPANSIONS tag in file.");
739 loopXml = expansionTypes;
740 strLoop =
"EXPANSIONS";
746 TiXmlElement* element = loopXml->FirstChildElement(
"ELEMENTS");
747 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
752 std::string idString;
753 std::string shapeString;
754 std::string basisString;
755 std::string homoLengthsString;
756 std::string homoSIDsString;
757 std::string homoZIDsString;
758 std::string homoYIDsString;
759 std::string numModesString;
760 std::string numPointsString;
761 std::string fieldsString;
762 std::string pointsString;
763 bool pointDef =
false;
764 bool numPointDef =
false;
765 TiXmlAttribute *attr = element->FirstAttribute();
768 std::string attrName(attr->Name());
769 if (attrName ==
"FIELDS")
771 fieldsString.insert(0, attr->Value());
773 else if (attrName ==
"SHAPE")
775 shapeString.insert(0, attr->Value());
777 else if (attrName ==
"BASIS")
779 basisString.insert(0, attr->Value());
781 else if (attrName ==
"HOMOGENEOUSLENGTHS")
783 homoLengthsString.insert(0,attr->Value());
785 else if (attrName ==
"HOMOGENEOUSSIDS")
787 homoSIDsString.insert(0,attr->Value());
789 else if (attrName ==
"HOMOGENEOUSZIDS")
791 homoZIDsString.insert(0,attr->Value());
793 else if (attrName ==
"HOMOGENEOUSYIDS")
795 homoYIDsString.insert(0,attr->Value());
797 else if (attrName ==
"NUMMODESPERDIR")
799 numModesString.insert(0, attr->Value());
801 else if (attrName ==
"ID")
803 idString.insert(0, attr->Value());
805 else if (attrName ==
"POINTSTYPE")
807 pointsString.insert(0, attr->Value());
810 else if (attrName ==
"NUMPOINTSPERDIR")
812 numPointsString.insert(0, attr->Value());
815 else if (attrName ==
"COMPRESSED")
817 if(!boost::iequals(attr->Value(),
820 WARNINGL0(
false,
"Compressed formats do not "
823 +
" but got "+
string(attr->Value()));
826 else if (attrName ==
"BITSIZE")
835 std::string errstr(
"Unknown attribute: ");
847 if(shapeString.find(
"Strips")!=string::npos)
857 if((loc = shapeString.find_first_of(
"-"))!=string::npos)
859 if(shapeString.find(
"Exp1D")!=string::npos)
868 shapeString.erase(loc,shapeString.length());
872 std::vector<unsigned int> elementIds;
875 ASSERTL0(valid,
"Unable to correctly parse the element ids.");
891 ASSERTL0(valid, std::string(
"Unable to correctly parse the shape type: ").append(shapeString).c_str());
894 std::vector<std::string> basisStrings;
895 std::vector<BasisType> basis;
897 ASSERTL0(valid,
"Unable to correctly parse the basis types.");
898 for (std::vector<std::string>::size_type i = 0; i < basisStrings.size(); i++)
910 ASSERTL0(valid, std::string(
"Unable to correctly parse the basis type: ").append(basisStrings[i]).c_str());
914 std::vector<NekDouble> homoLengths;
918 ASSERTL0(valid,
"Unable to correctly parse the number of homogeneous lengths.");
922 std::vector<unsigned int> homoSIDs;
926 ASSERTL0(valid,
"Unable to correctly parse homogeneous strips IDs.");
929 std::vector<unsigned int> homoZIDs;
930 std::vector<unsigned int> homoYIDs;
935 ASSERTL0(valid,
"Unable to correctly parse homogeneous planes IDs.");
941 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in z-direction.");
943 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in y-direction.");
948 std::vector<PointsType> points;
952 std::vector<std::string> pointsStrings;
954 ASSERTL0(valid,
"Unable to correctly parse the points types.");
955 for (std::vector<std::string>::size_type i = 0; i < pointsStrings.size(); i++)
968 ASSERTL0(valid, std::string(
"Unable to correctly parse the points type: ").append(pointsStrings[i]).c_str());
973 std::vector<unsigned int> numModes;
974 bool UniOrder =
false;
976 if(strstr(numModesString.c_str(),
"UNIORDER:"))
982 ASSERTL0(valid,
"Unable to correctly parse the number of modes.");
985 std::vector<unsigned int> numPoints;
989 ASSERTL0(valid,
"Unable to correctly parse the number of points.");
993 std::vector<std::string> Fields;
995 ASSERTL0(valid,
"Unable to correctly parse the number of fields.");
999 elementIds, basis, UniOrder, numModes, Fields, numHomoDir,
1000 homoLengths, strips, homoSIDs, homoZIDs, homoYIDs,
1001 points, pointDef, numPoints, numPointDef);
1003 fielddefs.push_back(fielddef);
1005 element = element->NextSiblingElement(
"ELEMENTS");
1007 loopXml = loopXml->NextSiblingElement(strLoop);
1015 void FieldIO::ImportFieldData(TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs, std::vector<std::vector<NekDouble> > &fielddata)
1019 TiXmlHandle docHandle(&doc);
1020 TiXmlElement* master = NULL;
1022 master = doc.FirstChildElement(
"NEKTAR");
1023 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
1028 TiXmlElement* element = master->FirstChildElement(
"ELEMENTS");
1029 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
1033 TiXmlNode* elementChild = element->FirstChild();
1034 ASSERTL0(elementChild,
"Unable to extract the data from the element tag.");
1035 std::string elementStr;
1038 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1040 elementStr += elementChild->ToText()->ValueStr();
1042 elementChild = elementChild->NextSibling();
1045 std::vector<NekDouble> elementFieldData;
1048 const char *CompressStr = element->Attribute(
"COMPRESSED");
1051 if(!boost::iequals(CompressStr,
1054 WARNINGL0(
false,
"Compressed formats do not match. "
1057 +
" but got "+
string(CompressStr));
1064 "Failed to decompress field data.");
1067 fielddata.push_back(elementFieldData);
1070 ASSERTL0(fielddata[cntdumps].size() == datasize*fielddefs[cntdumps]->m_fields.size(),
"Input data is not the same length as header infoarmation");
1074 element = element->NextSiblingElement(
"ELEMENTS");
1076 master = master->NextSiblingElement(
"NEKTAR");
1093 ptime::time_facet *facet =
new ptime::time_facet(
"%d-%b-%Y %H:%M:%S");
1094 std::stringstream wss;
1095 wss.imbue(locale(wss.getloc(), facet));
1096 wss << ptime::second_clock::local_time();
1097 ProvenanceMap[
"Timestamp"] = wss.str();
1100 boost::system::error_code ec;
1101 ProvenanceMap[
"Hostname"] = ip::host_name(ec);
1111 TiXmlElement * infoTag =
new TiXmlElement(
"Metadata");
1112 root->LinkEndChild(infoTag);
1115 FieldMetaDataMap::const_iterator infoit;
1117 TiXmlElement * provTag =
new TiXmlElement(
"Provenance");
1118 infoTag->LinkEndChild(provTag);
1119 for (infoit = ProvenanceMap.begin(); infoit != ProvenanceMap.end(); ++infoit)
1121 v =
new TiXmlElement( (infoit->first).c_str() );
1122 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1123 provTag->LinkEndChild(v);
1130 for(infoit = fieldmetadatamap.begin(); infoit != fieldmetadatamap.end(); ++infoit)
1132 v =
new TiXmlElement( (infoit->first).c_str() );
1133 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1134 infoTag->LinkEndChild(v);
1144 std::string &idString)
1146 std::stringstream idStringStream;
1147 bool setdash =
true;
1148 unsigned int endval;
1150 idStringStream << elmtids[0];
1151 for (
int i = 1; i < elmtids.size(); ++i)
1153 if(elmtids[i] == elmtids[i-1]+1)
1157 idStringStream <<
"-";
1161 if(i == elmtids.size()-1)
1163 idStringStream << elmtids[i];
1167 endval = elmtids[i];
1172 if(setdash ==
false)
1174 idStringStream << endval;
1179 idStringStream <<
"," << elmtids[i];
1182 idString = idStringStream.str();
1191 ASSERTL0(!outname.empty(),
"Empty path given to SetUpOutput()");
1193 int nprocs =
m_comm->GetSize();
1194 int rank =
m_comm->GetRank();
1198 fs::path specPath (outname);
1199 fs::path fulloutname;
1203 fulloutname = specPath;
1208 boost::format pad(
"P%1$07d.%2$s");
1212 fs::path poutfile(pad.str());
1213 fulloutname = specPath / poutfile;
1217 if (
m_comm->RemoveExistingFiles())
1227 fs::remove_all(fulloutname);
1229 catch (fs::filesystem_error& e)
1231 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1232 "Filesystem error: " + string(e.what()));
1243 fs::remove_all(specPath);
1245 catch (fs::filesystem_error& e)
1247 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1248 "Filesystem error: " + string(e.what()));
1258 cout <<
"Writing: " << specPath << endl;
1267 fs::create_directory(specPath);
1270 catch (fs::filesystem_error& e)
1272 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
1283 const string outname,
1284 const vector< FieldDefinitionsSharedPtr > &fielddefs,
1287 ASSERTL0(!outname.empty(),
"Empty path given to SetUpFieldMetaData()");
1289 int nprocs =
m_comm->GetSize();
1290 int rank =
m_comm->GetRank();
1292 fs::path specPath (outname);
1297 std::vector<unsigned int> elmtnums(nprocs,0);
1298 std::vector<unsigned int> idlist;
1300 for (i = 0; i < fielddefs.size(); ++i)
1302 elmtnums[rank] += fielddefs[i]->m_elementIDs.size();
1303 idlist.insert(idlist.end(), fielddefs[i]->m_elementIDs.begin(),
1304 fielddefs[i]->m_elementIDs.end());
1312 std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
1315 ElementIDs[0] = idlist;
1316 for (i = 1; i < nprocs; ++i)
1318 std::vector<unsigned int> tmp(elmtnums[i]);
1320 ElementIDs[i] = tmp;
1324 std::vector<std::string> filenames;
1325 for(
int i = 0; i < nprocs; ++i)
1327 boost::format pad(
"P%1$07d.%2$s");
1329 filenames.push_back(pad.str());
1334 specPath / fs::path(
"Info.xml"));
1336 cout <<
"Writing: " << specPath << endl;
1356 if(fielddefs->m_elementIDs.size() == 0)
1362 unsigned int numbasis = 0;
1365 switch(fielddefs->m_shapeType)
1369 if(fielddefs->m_numHomogeneousDir)
1371 numbasis += fielddefs->m_numHomogeneousDir;
1377 if(fielddefs->m_numHomogeneousDir)
1393 ASSERTL0(
false,
"Unsupported shape type.");
1397 unsigned int datasize = 0;
1399 ASSERTL0(fielddefs->m_basis.size() == numbasis,
"Length of basis vector is incorrect");
1401 if(fielddefs->m_uniOrder ==
true)
1403 unsigned int cnt = 0;
1405 switch(fielddefs->m_shapeType)
1409 int l = fielddefs->m_numModes[cnt++];
1410 if(fielddefs->m_numHomogeneousDir == 1)
1412 datasize += l*fielddefs->m_numModes[cnt++];
1414 else if(fielddefs->m_numHomogeneousDir == 2)
1416 int m = fielddefs->m_numModes[cnt++];
1417 datasize += l*m*fielddefs->m_numModes[cnt++];
1427 int l = fielddefs->m_numModes[cnt++];
1428 int m = fielddefs->m_numModes[cnt++];
1430 if(fielddefs->m_numHomogeneousDir == 1)
1433 fielddefs->m_homogeneousZIDs.size();
1443 int l = fielddefs->m_numModes[cnt++];
1444 int m = fielddefs->m_numModes[cnt++];
1445 if(fielddefs->m_numHomogeneousDir == 1)
1447 datasize += l*m*fielddefs->m_homogeneousZIDs.size();
1457 int l = fielddefs->m_numModes[cnt++];
1458 int m = fielddefs->m_numModes[cnt++];
1459 int n = fielddefs->m_numModes[cnt++];
1465 int l = fielddefs->m_numModes[cnt++];
1466 int m = fielddefs->m_numModes[cnt++];
1467 int n = fielddefs->m_numModes[cnt++];
1473 int l = fielddefs->m_numModes[cnt++];
1474 int m = fielddefs->m_numModes[cnt++];
1475 int n = fielddefs->m_numModes[cnt++];
1481 int l = fielddefs->m_numModes[cnt++];
1482 int m = fielddefs->m_numModes[cnt++];
1483 int n = fielddefs->m_numModes[cnt++];
1488 ASSERTL0(
false,
"Unsupported shape type.");
1492 datasize *= fielddefs->m_elementIDs.size();
1496 unsigned int cnt = 0;
1498 for(i = 0; i < fielddefs->m_elementIDs.size(); ++i)
1500 switch(fielddefs->m_shapeType)
1504 int l = fielddefs->m_numModes[cnt++];
1505 if(fielddefs->m_numHomogeneousDir == 1)
1507 datasize += l*fielddefs->m_numModes[cnt++];
1509 else if(fielddefs->m_numHomogeneousDir == 2)
1511 int m = fielddefs->m_numModes[cnt++];
1512 datasize += l*m*fielddefs->m_numModes[cnt++];
1522 int l = fielddefs->m_numModes[cnt++];
1523 int m = fielddefs->m_numModes[cnt++];
1524 if(fielddefs->m_numHomogeneousDir == 1)
1527 fielddefs->m_homogeneousZIDs.size();
1538 int l = fielddefs->m_numModes[cnt++];
1539 int m = fielddefs->m_numModes[cnt++];
1540 if(fielddefs->m_numHomogeneousDir == 1)
1542 datasize += l*m*fielddefs->
1543 m_homogeneousZIDs.size();
1554 int l = fielddefs->m_numModes[cnt++];
1555 int m = fielddefs->m_numModes[cnt++];
1556 int n = fielddefs->m_numModes[cnt++];
1562 int l = fielddefs->m_numModes[cnt++];
1563 int m = fielddefs->m_numModes[cnt++];
1564 int n = fielddefs->m_numModes[cnt++];
1570 int l = fielddefs->m_numModes[cnt++];
1571 int m = fielddefs->m_numModes[cnt++];
1572 int n = fielddefs->m_numModes[cnt++];
1578 int l = fielddefs->m_numModes[cnt++];
1579 int m = fielddefs->m_numModes[cnt++];
1580 int n = fielddefs->m_numModes[cnt++];
1585 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)