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>
55 #ifndef NEKTAR_VERSION
56 #define NEKTAR_VERSION "Unknown"
59 namespace ptime = boost::posix_time;
60 namespace ip = boost::asio::ip;
61 namespace berrc = boost::system::errc;
65 namespace LibUtilities
72 void Write(
const std::string &outFile,
73 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
74 std::vector<std::vector<NekDouble> > &fielddata,
80 MPI_Initialized(&init);
89 MPI_Comm_size( MPI_COMM_WORLD, &size );
91 "This static function is not available in parallel. Please"
92 "instantiate a FieldIO object for parallel use.");
97 f.
Write(outFile, fielddefs, fielddata, fieldinfomap);
107 const std::string& infilename,
108 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
109 std::vector<std::vector<NekDouble> > &fielddata,
113 #ifdef NEKTAR_USE_MPI
116 MPI_Initialized(&init);
125 MPI_Comm_size( MPI_COMM_WORLD, &size );
127 "This static function is not available in parallel. Please"
128 "instantiate a FieldIO object for parallel use.");
133 f.
Import(infilename, fielddefs, fielddata, fieldinfomap, ElementiDs);
151 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
152 std::vector<std::vector<NekDouble> > &fielddata,
156 ASSERTL1(fielddefs.size() == fielddata.size(),
157 "Length of fielddefs and fielddata incompatible");
158 for (
int f = 0; f < fielddefs.size(); ++f)
161 "Fielddata vector must contain at least one value.");
164 fielddefs[f]->m_fields.size() *
166 "Invalid size of fielddata vector.");
172 std::string filename =
SetUpOutput(outFile, fielddefs, fieldmetadatamap);
176 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
177 doc.LinkEndChild(decl);
179 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
180 doc.LinkEndChild(root);
184 for (
int f = 0; f < fielddefs.size(); ++f)
188 TiXmlElement * elemTag =
new TiXmlElement(
"ELEMENTS");
189 root->LinkEndChild(elemTag);
192 std::string fieldsString;
194 std::stringstream fieldsStringStream;
196 for (std::vector<int>::size_type i = 0; i
197 < fielddefs[f]->m_fields.size(); i++)
200 fieldsStringStream <<
",";
201 fieldsStringStream << fielddefs[f]->m_fields[i];
204 fieldsString = fieldsStringStream.str();
206 elemTag->SetAttribute(
"FIELDS", fieldsString);
209 std::string shapeString;
211 std::stringstream shapeStringStream;
212 shapeStringStream <<
ShapeTypeMap[fielddefs[f]->m_shapeType];
213 if(fielddefs[f]->m_numHomogeneousDir == 1)
215 shapeStringStream <<
"-HomogenousExp1D";
217 else if (fielddefs[f]->m_numHomogeneousDir == 2)
219 shapeStringStream <<
"-HomogenousExp2D";
222 shapeString = shapeStringStream.str();
224 elemTag->SetAttribute(
"SHAPE", shapeString);
227 std::string basisString;
229 std::stringstream basisStringStream;
231 for (std::vector<BasisType>::size_type i = 0; i < fielddefs[f]->m_basis.size(); i++)
234 basisStringStream <<
",";
239 basisString = basisStringStream.str();
241 elemTag->SetAttribute(
"BASIS", basisString);
244 if(fielddefs[f]->m_numHomogeneousDir)
246 std::string homoLenString;
248 std::stringstream homoLenStringStream;
250 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
253 homoLenStringStream <<
",";
255 << fielddefs[f]->m_homogeneousLengths[i];
258 homoLenString = homoLenStringStream.str();
260 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
264 if(fielddefs[f]->m_numHomogeneousDir)
266 if(fielddefs[f]->m_homogeneousYIDs.size() > 0)
268 std::string homoYIDsString;
270 std::stringstream homoYIDsStringStream;
272 for(
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size(); i++)
275 homoYIDsStringStream <<
",";
276 homoYIDsStringStream << fielddefs[f]->m_homogeneousYIDs[i];
279 homoYIDsString = homoYIDsStringStream.str();
281 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
284 if(fielddefs[f]->m_homogeneousZIDs.size() > 0)
286 std::string homoZIDsString;
288 std::stringstream homoZIDsStringStream;
290 for(
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size(); i++)
293 homoZIDsStringStream <<
",";
294 homoZIDsStringStream << fielddefs[f]->m_homogeneousZIDs[i];
297 homoZIDsString = homoZIDsStringStream.str();
299 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
304 std::string numModesString;
306 std::stringstream numModesStringStream;
308 if (fielddefs[f]->m_uniOrder)
310 numModesStringStream <<
"UNIORDER:";
313 for (std::vector<int>::size_type i = 0; i
314 < fielddefs[f]->m_basis.size(); i++)
317 numModesStringStream <<
",";
318 numModesStringStream << fielddefs[f]->m_numModes[i];
324 numModesStringStream <<
"MIXORDER:";
326 for (std::vector<int>::size_type i = 0; i
327 < fielddefs[f]->m_numModes.size(); i++)
330 numModesStringStream <<
",";
331 numModesStringStream << fielddefs[f]->m_numModes[i];
336 numModesString = numModesStringStream.str();
338 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
343 std::string idString;
345 std::stringstream idStringStream;
348 elemTag->SetAttribute(
"ID", idString);
350 std::string compressedDataString;
352 "Failed to compress field data.");
358 switch (compressedDataString.length() % 3)
361 compressedDataString +=
'\0';
363 compressedDataString +=
'\0';
368 typedef boost::archive::iterators::base64_from_binary<
369 boost::archive::iterators::transform_width<
370 std::string::const_iterator, 6, 8> > base64_t;
371 std::string base64string(base64_t(compressedDataString.begin()),
372 base64_t(compressedDataString.end()));
373 elemTag->LinkEndChild(
new TiXmlText(base64string));
376 doc.SaveFile(filename);
384 std::vector<FieldDefinitionsSharedPtr> &fielddefs,
385 std::vector<std::vector<NekDouble> > &fielddata,
390 std::string infile = infilename;
392 fs::path pinfilename(infilename);
394 if(fs::is_directory(pinfilename))
396 fs::path infofile(
"Info.xml");
397 fs::path fullpath = pinfilename / infofile;
400 std::vector<std::string> filenames;
401 std::vector<std::vector<unsigned int> > elementIDs_OnPartitions;
412 for(
int i = 0; i < filenames.size(); ++i)
414 fs::path pfilename(filenames[i]);
415 fullpath = pinfilename / pfilename;
418 TiXmlDocument doc1(fname);
419 bool loadOkay1 = doc1.LoadFile();
421 std::stringstream errstr;
422 errstr <<
"Unable to load file: " << fname << std::endl;
423 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
424 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
438 map<int,vector<int> > FileIDs;
442 for(i = 0; i < elementIDs_OnPartitions.size(); ++i)
444 for(j = 0; j < elementIDs_OnPartitions[i].size(); ++j)
446 FileIDs[elementIDs_OnPartitions[i][j]].push_back(i);
450 for(i = 0; i < ElementIDs.num_elements(); ++i)
452 it = FileIDs.find(ElementIDs[i]);
453 if (it != FileIDs.end())
455 for (j = 0; j < it->second.size(); ++j)
457 LoadFile.insert(it->second[j]);
463 for(iter = LoadFile.begin(); iter != LoadFile.end(); ++iter)
465 fs::path pfilename(filenames[*iter]);
466 fullpath = pinfilename / pfilename;
468 TiXmlDocument doc1(fname);
469 bool loadOkay1 = doc1.LoadFile();
471 std::stringstream errstr;
472 errstr <<
"Unable to load file: " << fname << std::endl;
473 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
474 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
488 TiXmlDocument doc(infile);
489 bool loadOkay = doc.LoadFile();
491 std::stringstream errstr;
492 errstr <<
"Unable to load file: " << infile << std::endl;
493 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
494 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " <<
495 doc.ErrorCol() << std::endl;
512 const std::vector<std::string> fileNames,
513 std::vector<std::vector<unsigned int> > &elementList,
517 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
518 doc.LinkEndChild(decl);
520 ASSERTL0(fileNames.size() == elementList.size(),
"Outfile names and list of elements ids does not match");
522 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
523 doc.LinkEndChild(root);
527 for (
int t = 0; t < fileNames.size(); ++t)
529 if(elementList[t].size())
531 TiXmlElement * elemIDs =
new TiXmlElement(
"Partition");
532 root->LinkEndChild(elemIDs);
534 elemIDs->SetAttribute(
"FileName",fileNames[t]);
540 elemIDs->LinkEndChild(
new TiXmlText(IDstring));
544 doc.SaveFile(outFile);
552 std::vector<std::string> &fileNames,
553 std::vector<std::vector<unsigned int> > &elementList,
556 TiXmlDocument doc(inFile);
557 bool loadOkay = doc.LoadFile();
560 std::stringstream errstr;
561 errstr <<
"Unable to load file: " << inFile<< std::endl;
562 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
563 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
567 TiXmlHandle docHandle(&doc);
571 TiXmlElement* master = doc.FirstChildElement(
"NEKTAR");
572 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
575 std::string strPartition =
"Partition";
578 TiXmlElement* fldfileIDs = master->FirstChildElement(strPartition.c_str());
582 strPartition =
"MultipleFldFiles";
583 fldfileIDs = master->FirstChildElement(
"MultipleFldFiles");
586 "Unable to find 'Partition' or 'MultipleFldFiles' tag "
587 "within nektar tag.");
592 const char *attr = fldfileIDs->Attribute(
"FileName");
593 ASSERTL0(attr,
"'FileName' not provided as an attribute of '"
594 + strPartition +
"' tag.");
595 fileNames.push_back(std::string(attr));
597 const char* elementIDs = fldfileIDs->GetText();
598 ASSERTL0(elementIDs,
"Element IDs not specified.");
600 std::string elementIDsStr(elementIDs);
602 std::vector<unsigned int> idvec;
605 elementList.push_back(idvec);
607 fldfileIDs = fldfileIDs->NextSiblingElement(strPartition.c_str());
614 TiXmlDocument doc(filename);
615 bool loadOkay = doc.LoadFile();
617 std::stringstream errstr;
618 errstr <<
"Unable to load file: " << filename << std::endl;
619 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
620 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
631 TiXmlHandle docHandle(&doc);
632 TiXmlElement* master = 0;
633 TiXmlElement* metadata = 0;
635 master = doc.FirstChildElement(
"NEKTAR");
636 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
637 std::string strLoop =
"NEKTAR";
641 metadata = master->FirstChildElement(
"FIELDMETADATA");
644 TiXmlElement *param = metadata->FirstChildElement(
"P");
648 TiXmlAttribute *paramAttr = param->FirstAttribute();
649 std::string attrName(paramAttr->Name());
650 std::string paramString;
652 if(attrName ==
"PARAM")
654 paramString.insert(0,paramAttr->Value());
658 ASSERTL0(
false,
"PARAM not provided as an attribute in FIELDMETADATA section");
662 std::string paramBodyStr;
664 TiXmlNode *paramBody = param->FirstChild();
666 paramBodyStr += paramBody->ToText()->Value();
668 fieldmetadatamap[paramString] = paramBodyStr;
669 param = param->NextSiblingElement(
"P");
674 metadata = master->FirstChildElement(
"Metadata");
677 TiXmlElement *param = metadata->FirstChildElement();
681 std::string paramString = param->Value();
682 if (paramString !=
"Provenance")
685 TiXmlNode *paramBody = param->FirstChild();
686 std::string paramBodyStr = paramBody->ToText()->Value();
688 fieldmetadatamap[paramString] = paramBodyStr;
690 param = param->NextSiblingElement();
703 TiXmlHandle docHandle(&doc);
704 TiXmlElement* master = NULL;
706 master = doc.FirstChildElement(
"NEKTAR");
707 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
708 std::string strLoop =
"NEKTAR";
709 TiXmlElement* loopXml = master;
711 TiXmlElement *expansionTypes;
714 expansionTypes = master->FirstChildElement(
"EXPANSIONS");
715 ASSERTL0(expansionTypes,
"Unable to find EXPANSIONS tag in file.");
716 loopXml = expansionTypes;
717 strLoop =
"EXPANSIONS";
723 TiXmlElement* element = loopXml->FirstChildElement(
"ELEMENTS");
724 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
729 std::string idString;
730 std::string shapeString;
731 std::string basisString;
732 std::string homoLengthsString;
733 std::string homoZIDsString;
734 std::string homoYIDsString;
735 std::string numModesString;
736 std::string numPointsString;
737 std::string fieldsString;
738 std::string pointsString;
739 bool pointDef =
false;
740 bool numPointDef =
false;
741 TiXmlAttribute *attr = element->FirstAttribute();
744 std::string attrName(attr->Name());
745 if (attrName ==
"FIELDS")
747 fieldsString.insert(0, attr->Value());
749 else if (attrName ==
"SHAPE")
751 shapeString.insert(0, attr->Value());
753 else if (attrName ==
"BASIS")
755 basisString.insert(0, attr->Value());
757 else if (attrName ==
"HOMOGENEOUSLENGTHS")
759 homoLengthsString.insert(0,attr->Value());
761 else if (attrName ==
"HOMOGENEOUSZIDS")
763 homoZIDsString.insert(0,attr->Value());
765 else if (attrName ==
"HOMOGENEOUSYIDS")
767 homoYIDsString.insert(0,attr->Value());
769 else if (attrName ==
"NUMMODESPERDIR")
771 numModesString.insert(0, attr->Value());
773 else if (attrName ==
"ID")
775 idString.insert(0, attr->Value());
777 else if (attrName ==
"POINTSTYPE")
779 pointsString.insert(0, attr->Value());
782 else if (attrName ==
"NUMPOINTSPERDIR")
784 numPointsString.insert(0, attr->Value());
789 std::string errstr(
"Unknown attribute: ");
803 if((loc = shapeString.find_first_of(
"-"))!=string::npos)
805 if(shapeString.find(
"Exp1D")!=string::npos)
814 shapeString.erase(loc,shapeString.length());
818 std::vector<unsigned int> elementIds;
821 ASSERTL0(valid,
"Unable to correctly parse the element ids.");
837 ASSERTL0(valid, std::string(
"Unable to correctly parse the shape type: ").append(shapeString).c_str());
840 std::vector<std::string> basisStrings;
841 std::vector<BasisType> basis;
843 ASSERTL0(valid,
"Unable to correctly parse the basis types.");
844 for (std::vector<std::string>::size_type i = 0; i < basisStrings.size(); i++)
856 ASSERTL0(valid, std::string(
"Unable to correctly parse the basis type: ").append(basisStrings[i]).c_str());
860 std::vector<NekDouble> homoLengths;
864 ASSERTL0(valid,
"Unable to correctly parse the number of homogeneous lengths.");
868 std::vector<unsigned int> homoZIDs;
869 std::vector<unsigned int> homoYIDs;
874 ASSERTL0(valid,
"Unable to correctly parse homogeneous planes IDs.");
880 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in z-direction.");
882 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in y-direction.");
887 std::vector<PointsType> points;
891 std::vector<std::string> pointsStrings;
893 ASSERTL0(valid,
"Unable to correctly parse the points types.");
894 for (std::vector<std::string>::size_type i = 0; i < pointsStrings.size(); i++)
907 ASSERTL0(valid, std::string(
"Unable to correctly parse the points type: ").append(pointsStrings[i]).c_str());
912 std::vector<unsigned int> numModes;
913 bool UniOrder =
false;
915 if(strstr(numModesString.c_str(),
"UNIORDER:"))
921 ASSERTL0(valid,
"Unable to correctly parse the number of modes.");
924 std::vector<unsigned int> numPoints;
928 ASSERTL0(valid,
"Unable to correctly parse the number of points.");
932 std::vector<std::string> Fields;
934 ASSERTL0(valid,
"Unable to correctly parse the number of fields.");
936 FieldDefinitionsSharedPtr fielddef =
MemoryManager<FieldDefinitions>::AllocateSharedPtr(shape, elementIds, basis, UniOrder, numModes, Fields, numHomoDir, homoLengths, homoZIDs, homoYIDs, points, pointDef, numPoints, numPointDef);
938 fielddefs.push_back(fielddef);
940 element = element->NextSiblingElement(
"ELEMENTS");
942 loopXml = loopXml->NextSiblingElement(strLoop);
950 void FieldIO::ImportFieldData(TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs, std::vector<std::vector<NekDouble> > &fielddata)
954 TiXmlHandle docHandle(&doc);
955 TiXmlElement* master = NULL;
957 master = doc.FirstChildElement(
"NEKTAR");
958 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
963 TiXmlElement* element = master->FirstChildElement(
"ELEMENTS");
964 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
968 TiXmlNode* elementChild = element->FirstChild();
969 ASSERTL0(elementChild,
"Unable to extract the data from the element tag.");
970 std::string elementStr;
973 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
975 elementStr += elementChild->ToText()->ValueStr();
977 elementChild = elementChild->NextSibling();
981 typedef boost::archive::iterators::transform_width<
982 boost::archive::iterators::binary_from_base64<
983 std::string::const_iterator>, 8, 6 > binary_t;
984 std::string vCompressed(binary_t(elementStr.begin()),
985 binary_t(elementStr.end()));
987 std::vector<NekDouble> elementFieldData;
989 "Failed to decompress field data.");
991 fielddata.push_back(elementFieldData);
994 ASSERTL0(fielddata[cntdumps].size() == datasize*fielddefs[cntdumps]->m_fields.size(),
"Input data is not the same length as header infoarmation");
998 element = element->NextSiblingElement(
"ELEMENTS");
1000 master = master->NextSiblingElement(
"NEKTAR");
1017 ptime::time_facet *facet =
new ptime::time_facet(
"%d-%b-%Y %H:%M:%S");
1018 std::stringstream wss;
1019 wss.imbue(locale(wss.getloc(), facet));
1020 wss << ptime::second_clock::local_time();
1021 ProvenanceMap[
"Timestamp"] = wss.str();
1024 boost::system::error_code ec;
1025 ProvenanceMap[
"Hostname"] = ip::host_name(ec);
1035 TiXmlElement * infoTag =
new TiXmlElement(
"Metadata");
1036 root->LinkEndChild(infoTag);
1039 FieldMetaDataMap::const_iterator infoit;
1041 TiXmlElement * provTag =
new TiXmlElement(
"Provenance");
1042 infoTag->LinkEndChild(provTag);
1043 for (infoit = ProvenanceMap.begin(); infoit != ProvenanceMap.end(); ++infoit)
1045 v =
new TiXmlElement( (infoit->first).c_str() );
1046 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1047 provTag->LinkEndChild(v);
1054 for(infoit = fieldmetadatamap.begin(); infoit != fieldmetadatamap.end(); ++infoit)
1056 v =
new TiXmlElement( (infoit->first).c_str() );
1057 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1058 infoTag->LinkEndChild(v);
1068 std::string &idString)
1070 std::stringstream idStringStream;
1071 bool setdash =
true;
1072 unsigned int endval;
1074 idStringStream << elmtids[0];
1075 for (
int i = 1; i < elmtids.size(); ++i)
1077 if(elmtids[i] == elmtids[i-1]+1)
1081 idStringStream <<
"-";
1085 if(i == elmtids.size()-1)
1087 idStringStream << elmtids[i];
1091 endval = elmtids[i];
1096 if(setdash ==
false)
1098 idStringStream << endval;
1103 idStringStream <<
"," << elmtids[i];
1106 idString = idStringStream.str();
1114 const std::vector<FieldDefinitionsSharedPtr>& fielddefs,
1117 ASSERTL0(!outname.empty(),
"Empty path given to SetUpOutput()");
1119 int nprocs =
m_comm->GetSize();
1120 int rank =
m_comm->GetRank();
1123 fs::path specPath (outname);
1126 if(
m_comm->RemoveExistingFiles())
1130 fs::remove_all(specPath);
1132 catch (fs::filesystem_error& e)
1134 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1135 "Filesystem error: " + string(e.what()));
1142 cout <<
"Writing: " << specPath << endl;
1149 std::vector<unsigned int> elmtnums(nprocs,0);
1150 std::vector<unsigned int> idlist;
1152 for (i = 0; i < fielddefs.size(); ++i)
1154 elmtnums[rank] += fielddefs[i]->m_elementIDs.size();
1155 idlist.insert(idlist.end(), fielddefs[i]->m_elementIDs.begin(),
1156 fielddefs[i]->m_elementIDs.end());
1163 fs::create_directory(specPath);
1165 catch (fs::filesystem_error& e)
1167 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
1174 std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
1177 ElementIDs[0] = idlist;
1178 for (i = 1; i < nprocs; ++i)
1180 std::vector<unsigned int> tmp(elmtnums[i]);
1182 ElementIDs[i] = tmp;
1186 std::vector<std::string> filenames;
1187 for(
int i = 0; i < nprocs; ++i)
1189 boost::format pad(
"P%1$07d.fld");
1191 filenames.push_back(pad.str());
1196 specPath / fs::path(
"Info.xml"));
1198 cout <<
"Writing: " << specPath << endl;
1209 boost::format pad(
"P%1$07d.fld");
1213 fs::path poutfile(pad.str());
1214 fs::path fulloutname = specPath / poutfile;
1230 unsigned char* input = (
unsigned char*)(&in[0]);
1232 buffer.resize(
CHUNK);
1235 strm.zalloc = Z_NULL;
1236 strm.zfree = Z_NULL;
1237 strm.opaque = Z_NULL;
1238 ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
1240 ASSERTL0(ret == Z_OK,
"Error initializing Zlib.");
1242 strm.avail_in = in.size() *
sizeof(
NekDouble) /
sizeof(
char);
1243 strm.next_in = input;
1247 strm.avail_out =
CHUNK;
1248 strm.next_out = (
unsigned char*)(&buffer[0]);
1250 ret = deflate(&strm, Z_FINISH);
1254 ASSERTL0(ret != Z_STREAM_ERROR,
"Zlib stream error");
1256 have =
CHUNK - strm.avail_out;
1257 out += buffer.substr(0, have);
1259 }
while (strm.avail_out == 0);
1262 ASSERTL0(strm.avail_in == 0,
"Not all input was used.");
1265 ASSERTL0(ret == Z_STREAM_END,
"Stream not finished");
1268 (
void)deflateEnd(&strm);
1278 std::vector<NekDouble>& out)
1284 buffer.resize(
CHUNK);
1287 strm.zalloc = Z_NULL;
1288 strm.zfree = Z_NULL;
1289 strm.opaque = Z_NULL;
1291 strm.next_in = Z_NULL;
1292 ret = inflateInit(&strm);
1293 ASSERTL0(ret == Z_OK,
"Error initializing zlib decompression.");
1295 strm.avail_in = in.size();
1296 strm.next_in = (
unsigned char*)(&in[0]);
1299 strm.avail_out =
CHUNK;
1300 strm.next_out = (
unsigned char*)(&buffer[0]);
1302 ret = inflate(&strm, Z_NO_FLUSH);
1304 ASSERTL0(ret != Z_STREAM_ERROR,
"Stream error occured.");
1311 (
void)inflateEnd(&strm);
1315 have =
CHUNK - strm.avail_out;
1316 output += buffer.substr(0, have);
1318 }
while (strm.avail_out == 0);
1320 (
void)inflateEnd(&strm);
1322 if (ret == Z_STREAM_END)
1325 unsigned int len = output.size() *
sizeof(*output.c_str())
1327 out.assign( readFieldData, readFieldData + len);
1332 return Z_DATA_ERROR;
1343 if(fielddefs->m_elementIDs.size() == 0)
1349 unsigned int numbasis = 0;
1352 switch(fielddefs->m_shapeType)
1356 if(fielddefs->m_numHomogeneousDir)
1358 numbasis += fielddefs->m_numHomogeneousDir;
1364 if(fielddefs->m_numHomogeneousDir)
1380 ASSERTL0(
false,
"Unsupported shape type.");
1384 unsigned int datasize = 0;
1386 ASSERTL0(fielddefs->m_basis.size() == numbasis,
"Length of basis vector is incorrect");
1388 if(fielddefs->m_uniOrder ==
true)
1390 unsigned int cnt = 0;
1392 switch(fielddefs->m_shapeType)
1396 int l = fielddefs->m_numModes[cnt++];
1397 if(fielddefs->m_numHomogeneousDir == 1)
1399 datasize += l*fielddefs->m_numModes[cnt++];
1401 else if(fielddefs->m_numHomogeneousDir == 2)
1403 int m = fielddefs->m_numModes[cnt++];
1404 datasize += l*m*fielddefs->m_numModes[cnt++];
1414 int l = fielddefs->m_numModes[cnt++];
1415 int m = fielddefs->m_numModes[cnt++];
1417 if(fielddefs->m_numHomogeneousDir == 1)
1420 fielddefs->m_homogeneousZIDs.size();
1430 int l = fielddefs->m_numModes[cnt++];
1431 int m = fielddefs->m_numModes[cnt++];
1432 if(fielddefs->m_numHomogeneousDir == 1)
1434 datasize += l*m*fielddefs->m_homogeneousZIDs.size();
1444 int l = fielddefs->m_numModes[cnt++];
1445 int m = fielddefs->m_numModes[cnt++];
1446 int n = fielddefs->m_numModes[cnt++];
1452 int l = fielddefs->m_numModes[cnt++];
1453 int m = fielddefs->m_numModes[cnt++];
1454 int n = fielddefs->m_numModes[cnt++];
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++];
1475 ASSERTL0(
false,
"Unsupported shape type.");
1479 datasize *= fielddefs->m_elementIDs.size();
1483 unsigned int cnt = 0;
1485 for(i = 0; i < fielddefs->m_elementIDs.size(); ++i)
1487 switch(fielddefs->m_shapeType)
1490 datasize += fielddefs->m_numModes[cnt++];
1494 int l = fielddefs->m_numModes[cnt++];
1495 int m = fielddefs->m_numModes[cnt++];
1501 int l = fielddefs->m_numModes[cnt++];
1502 int m = fielddefs->m_numModes[cnt++];
1508 int l = fielddefs->m_numModes[cnt++];
1509 int m = fielddefs->m_numModes[cnt++];
1510 int n = fielddefs->m_numModes[cnt++];
1516 int l = fielddefs->m_numModes[cnt++];
1517 int m = fielddefs->m_numModes[cnt++];
1518 int n = fielddefs->m_numModes[cnt++];
1524 int l = fielddefs->m_numModes[cnt++];
1525 int m = fielddefs->m_numModes[cnt++];
1526 int n = fielddefs->m_numModes[cnt++];
1532 int l = fielddefs->m_numModes[cnt++];
1533 int m = fielddefs->m_numModes[cnt++];
1534 int n = fielddefs->m_numModes[cnt++];
1539 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[]
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
void ImportFieldData(TiXmlDocument &doc, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata)
Imports the data fileds.
const std::string kPointsTypeStr[]
std::string SetUpOutput(const std::string outname, const std::vector< FieldDefinitionsSharedPtr > &fielddefs, const FieldMetaDataMap &fieldmetadatamap)
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)
FieldIO(LibUtilities::CommSharedPtr pComm)
Constructor.
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)
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
void AddInfoTag(TiXmlElement *root, const FieldMetaDataMap &fieldmetadatamap)
add information about provenance and fieldmetadata
int Inflate(string &in, std::vector< NekDouble > &out)
const std::string kGitSha1
#define LIB_UTILITIES_EXPORT
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 getNumberOfCoefficients(int Na, int Nb, int Nc)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
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.
int Deflate(std::vector< NekDouble > &in, string &out)
void ImportFieldMetaData(std::string filename, FieldMetaDataMap &fieldmetadatamap)
Imports the definition of the meta data.
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