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,
111 const Array<OneD, int> ElementiDs)
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,
387 const Array<OneD, int> ElementIDs)
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;
409 for(
int i = 0; i < filenames.size(); ++i)
411 fs::path pfilename(filenames[i]);
412 fullpath = pinfilename / pfilename;
415 TiXmlDocument doc1(fname);
416 bool loadOkay1 = doc1.LoadFile();
418 std::stringstream errstr;
419 errstr <<
"Unable to load file: " << fname << std::endl;
420 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
421 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
435 map<int,vector<int> > FileIDs;
439 for(i = 0; i < elementIDs_OnPartitions.size(); ++i)
441 for(j = 0; j < elementIDs_OnPartitions[i].size(); ++j)
443 FileIDs[elementIDs_OnPartitions[i][j]].push_back(i);
447 for(i = 0; i < ElementIDs.num_elements(); ++i)
449 it = FileIDs.find(ElementIDs[i]);
450 if (it != FileIDs.end())
452 for (j = 0; j < it->second.size(); ++j)
454 LoadFile.insert(it->second[j]);
460 for(iter = LoadFile.begin(); iter != LoadFile.end(); ++iter)
462 fs::path pfilename(filenames[*iter]);
463 fullpath = pinfilename / pfilename;
465 TiXmlDocument doc1(fname);
466 bool loadOkay1 = doc1.LoadFile();
468 std::stringstream errstr;
469 errstr <<
"Unable to load file: " << fname << std::endl;
470 errstr <<
"Reason: " << doc1.ErrorDesc() << std::endl;
471 errstr <<
"Position: Line " << doc1.ErrorRow() <<
", Column " << doc1.ErrorCol() << std::endl;
485 TiXmlDocument doc(infile);
486 bool loadOkay = doc.LoadFile();
488 std::stringstream errstr;
489 errstr <<
"Unable to load file: " << infile << std::endl;
490 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
491 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " <<
492 doc.ErrorCol() << std::endl;
509 const std::vector<std::string> fileNames,
510 std::vector<std::vector<unsigned int> > &elementList,
514 TiXmlDeclaration * decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
515 doc.LinkEndChild(decl);
517 ASSERTL0(fileNames.size() == elementList.size(),
"Outfile names and list of elements ids does not match");
519 TiXmlElement * root =
new TiXmlElement(
"NEKTAR");
520 doc.LinkEndChild(root);
524 for (
int t = 0; t < fileNames.size(); ++t)
526 if(elementList[t].size())
528 TiXmlElement * elemIDs =
new TiXmlElement(
"Partition");
529 root->LinkEndChild(elemIDs);
531 elemIDs->SetAttribute(
"FileName",fileNames[t]);
537 elemIDs->LinkEndChild(
new TiXmlText(IDstring));
541 doc.SaveFile(outFile);
549 std::vector<std::string> &fileNames,
550 std::vector<std::vector<unsigned int> > &elementList,
553 TiXmlDocument doc(inFile);
554 bool loadOkay = doc.LoadFile();
557 std::stringstream errstr;
558 errstr <<
"Unable to load file: " << inFile<< std::endl;
559 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
560 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
564 TiXmlHandle docHandle(&doc);
568 TiXmlElement* master = doc.FirstChildElement(
"NEKTAR");
569 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
572 std::string strPartition =
"Partition";
575 TiXmlElement* fldfileIDs = master->FirstChildElement(strPartition.c_str());
579 strPartition =
"MultipleFldFiles";
580 fldfileIDs = master->FirstChildElement(
"MultipleFldFiles");
583 "Unable to find 'Partition' or 'MultipleFldFiles' tag "
584 "within nektar tag.");
589 const char *attr = fldfileIDs->Attribute(
"FileName");
590 ASSERTL0(attr,
"'FileName' not provided as an attribute of '"
591 + strPartition +
"' tag.");
592 fileNames.push_back(std::string(attr));
594 const char* elementIDs = fldfileIDs->GetText();
595 ASSERTL0(elementIDs,
"Element IDs not specified.");
597 std::string elementIDsStr(elementIDs);
599 std::vector<unsigned int> idvec;
602 elementList.push_back(idvec);
604 fldfileIDs = fldfileIDs->NextSiblingElement(strPartition.c_str());
611 TiXmlDocument doc(filename);
612 bool loadOkay = doc.LoadFile();
614 std::stringstream errstr;
615 errstr <<
"Unable to load file: " << filename << std::endl;
616 errstr <<
"Reason: " << doc.ErrorDesc() << std::endl;
617 errstr <<
"Position: Line " << doc.ErrorRow() <<
", Column " << doc.ErrorCol() << std::endl;
628 TiXmlHandle docHandle(&doc);
629 TiXmlElement* master = 0;
630 TiXmlElement* metadata = 0;
632 master = doc.FirstChildElement(
"NEKTAR");
633 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
634 std::string strLoop =
"NEKTAR";
638 metadata = master->FirstChildElement(
"FIELDMETADATA");
641 TiXmlElement *param = metadata->FirstChildElement(
"P");
645 TiXmlAttribute *paramAttr = param->FirstAttribute();
646 std::string attrName(paramAttr->Name());
647 std::string paramString;
649 if(attrName ==
"PARAM")
651 paramString.insert(0,paramAttr->Value());
655 ASSERTL0(
false,
"PARAM not provided as an attribute in FIELDMETADATA section");
659 std::string paramBodyStr;
661 TiXmlNode *paramBody = param->FirstChild();
663 paramBodyStr += paramBody->ToText()->Value();
665 fieldmetadatamap[paramString] = paramBodyStr;
666 param = param->NextSiblingElement(
"P");
671 metadata = master->FirstChildElement(
"Metadata");
674 TiXmlElement *param = metadata->FirstChildElement();
678 std::string paramString = param->Value();
679 if (paramString !=
"Provenance")
682 TiXmlNode *paramBody = param->FirstChild();
683 std::string paramBodyStr = paramBody->ToText()->Value();
685 fieldmetadatamap[paramString] = paramBodyStr;
687 param = param->NextSiblingElement();
700 TiXmlHandle docHandle(&doc);
701 TiXmlElement* master = NULL;
703 master = doc.FirstChildElement(
"NEKTAR");
704 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
705 std::string strLoop =
"NEKTAR";
706 TiXmlElement* loopXml = master;
708 TiXmlElement *expansionTypes;
711 expansionTypes = master->FirstChildElement(
"EXPANSIONS");
712 ASSERTL0(expansionTypes,
"Unable to find EXPANSIONS tag in file.");
713 loopXml = expansionTypes;
714 strLoop =
"EXPANSIONS";
720 TiXmlElement* element = loopXml->FirstChildElement(
"ELEMENTS");
721 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
726 std::string idString;
727 std::string shapeString;
728 std::string basisString;
729 std::string homoLengthsString;
730 std::string homoZIDsString;
731 std::string homoYIDsString;
732 std::string numModesString;
733 std::string numPointsString;
734 std::string fieldsString;
735 std::string pointsString;
736 bool pointDef =
false;
737 bool numPointDef =
false;
738 TiXmlAttribute *attr = element->FirstAttribute();
741 std::string attrName(attr->Name());
742 if (attrName ==
"FIELDS")
744 fieldsString.insert(0, attr->Value());
746 else if (attrName ==
"SHAPE")
748 shapeString.insert(0, attr->Value());
750 else if (attrName ==
"BASIS")
752 basisString.insert(0, attr->Value());
754 else if (attrName ==
"HOMOGENEOUSLENGTHS")
756 homoLengthsString.insert(0,attr->Value());
758 else if (attrName ==
"HOMOGENEOUSZIDS")
760 homoZIDsString.insert(0,attr->Value());
762 else if (attrName ==
"HOMOGENEOUSYIDS")
764 homoYIDsString.insert(0,attr->Value());
766 else if (attrName ==
"NUMMODESPERDIR")
768 numModesString.insert(0, attr->Value());
770 else if (attrName ==
"ID")
772 idString.insert(0, attr->Value());
774 else if (attrName ==
"POINTSTYPE")
776 pointsString.insert(0, attr->Value());
779 else if (attrName ==
"NUMPOINTSPERDIR")
781 numPointsString.insert(0, attr->Value());
786 std::string errstr(
"Unknown attribute: ");
800 if((loc = shapeString.find_first_of(
"-"))!=string::npos)
802 if(shapeString.find(
"Exp1D")!=string::npos)
811 shapeString.erase(loc,shapeString.length());
815 std::vector<unsigned int> elementIds;
818 ASSERTL0(valid,
"Unable to correctly parse the element ids.");
834 ASSERTL0(valid, std::string(
"Unable to correctly parse the shape type: ").append(shapeString).c_str());
837 std::vector<std::string> basisStrings;
838 std::vector<BasisType> basis;
840 ASSERTL0(valid,
"Unable to correctly parse the basis types.");
841 for (std::vector<std::string>::size_type i = 0; i < basisStrings.size(); i++)
853 ASSERTL0(valid, std::string(
"Unable to correctly parse the basis type: ").append(basisStrings[i]).c_str());
857 std::vector<NekDouble> homoLengths;
861 ASSERTL0(valid,
"Unable to correctly parse the number of homogeneous lengths.");
865 std::vector<unsigned int> homoZIDs;
866 std::vector<unsigned int> homoYIDs;
871 ASSERTL0(valid,
"Unable to correctly parse homogeneous planes IDs.");
877 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in z-direction.");
879 ASSERTL0(valid,
"Unable to correctly parse homogeneous lines IDs in y-direction.");
884 std::vector<PointsType> points;
888 std::vector<std::string> pointsStrings;
890 ASSERTL0(valid,
"Unable to correctly parse the points types.");
891 for (std::vector<std::string>::size_type i = 0; i < pointsStrings.size(); i++)
904 ASSERTL0(valid, std::string(
"Unable to correctly parse the points type: ").append(pointsStrings[i]).c_str());
909 std::vector<unsigned int> numModes;
910 bool UniOrder =
false;
912 if(strstr(numModesString.c_str(),
"UNIORDER:"))
918 ASSERTL0(valid,
"Unable to correctly parse the number of modes.");
921 std::vector<unsigned int> numPoints;
925 ASSERTL0(valid,
"Unable to correctly parse the number of points.");
929 std::vector<std::string> Fields;
931 ASSERTL0(valid,
"Unable to correctly parse the number of fields.");
933 FieldDefinitionsSharedPtr fielddef =
MemoryManager<FieldDefinitions>::AllocateSharedPtr(shape, elementIds, basis, UniOrder, numModes, Fields, numHomoDir, homoLengths, homoZIDs, homoYIDs, points, pointDef, numPoints, numPointDef);
935 fielddefs.push_back(fielddef);
937 element = element->NextSiblingElement(
"ELEMENTS");
939 loopXml = loopXml->NextSiblingElement(strLoop);
947 void FieldIO::ImportFieldData(TiXmlDocument &doc,
const std::vector<FieldDefinitionsSharedPtr> &fielddefs, std::vector<std::vector<NekDouble> > &fielddata)
951 TiXmlHandle docHandle(&doc);
952 TiXmlElement* master = NULL;
954 master = doc.FirstChildElement(
"NEKTAR");
955 ASSERTL0(master,
"Unable to find NEKTAR tag in file.");
960 TiXmlElement* element = master->FirstChildElement(
"ELEMENTS");
961 ASSERTL0(element,
"Unable to find ELEMENTS tag within nektar tag.");
965 TiXmlNode* elementChild = element->FirstChild();
966 ASSERTL0(elementChild,
"Unable to extract the data from the element tag.");
967 std::string elementStr;
970 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
972 elementStr += elementChild->ToText()->ValueStr();
974 elementChild = elementChild->NextSibling();
978 typedef boost::archive::iterators::transform_width<
979 boost::archive::iterators::binary_from_base64<
980 std::string::const_iterator>, 8, 6 > binary_t;
981 std::string vCompressed(binary_t(elementStr.begin()),
982 binary_t(elementStr.end()));
984 std::vector<NekDouble> elementFieldData;
986 "Failed to decompress field data.");
988 fielddata.push_back(elementFieldData);
991 ASSERTL0(fielddata[cntdumps].size() == datasize*fielddefs[cntdumps]->m_fields.size(),
"Input data is not the same length as header infoarmation");
995 element = element->NextSiblingElement(
"ELEMENTS");
997 master = master->NextSiblingElement(
"NEKTAR");
1014 ptime::time_facet *facet =
new ptime::time_facet(
"%d-%b-%Y %H:%M:%S");
1015 std::stringstream wss;
1016 wss.imbue(locale(wss.getloc(), facet));
1017 wss << ptime::second_clock::local_time();
1018 ProvenanceMap[
"Timestamp"] = wss.str();
1021 boost::system::error_code ec;
1022 ProvenanceMap[
"Hostname"] = ip::host_name(ec);
1032 TiXmlElement * infoTag =
new TiXmlElement(
"Metadata");
1033 root->LinkEndChild(infoTag);
1036 FieldMetaDataMap::const_iterator infoit;
1038 TiXmlElement * provTag =
new TiXmlElement(
"Provenance");
1039 infoTag->LinkEndChild(provTag);
1040 for (infoit = ProvenanceMap.begin(); infoit != ProvenanceMap.end(); ++infoit)
1042 v =
new TiXmlElement( (infoit->first).c_str() );
1043 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1044 provTag->LinkEndChild(v);
1051 for(infoit = fieldmetadatamap.begin(); infoit != fieldmetadatamap.end(); ++infoit)
1053 v =
new TiXmlElement( (infoit->first).c_str() );
1054 v->LinkEndChild(
new TiXmlText((infoit->second).c_str()));
1055 infoTag->LinkEndChild(v);
1065 std::string &idString)
1067 std::stringstream idStringStream;
1068 bool setdash =
true;
1069 unsigned int endval;
1071 idStringStream << elmtids[0];
1072 for (
int i = 1; i < elmtids.size(); ++i)
1074 if(elmtids[i] == elmtids[i-1]+1)
1078 idStringStream <<
"-";
1082 if(i == elmtids.size()-1)
1084 idStringStream << elmtids[i];
1088 endval = elmtids[i];
1093 if(setdash ==
false)
1095 idStringStream << endval;
1100 idStringStream <<
"," << elmtids[i];
1103 idString = idStringStream.str();
1111 const std::vector<FieldDefinitionsSharedPtr>& fielddefs,
1114 ASSERTL0(!outname.empty(),
"Empty path given to SetUpOutput()");
1116 int nprocs =
m_comm->GetSize();
1117 int rank =
m_comm->GetRank();
1120 fs::path specPath (outname);
1123 if(
m_comm->RemoveExistingFiles())
1127 fs::remove_all(specPath);
1129 catch (fs::filesystem_error& e)
1131 ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
1132 "Filesystem error: " + string(e.what()));
1139 cout <<
"Writing: " << specPath << endl;
1146 std::vector<unsigned int> elmtnums(nprocs,0);
1147 std::vector<unsigned int> idlist;
1149 for (i = 0; i < fielddefs.size(); ++i)
1151 elmtnums[rank] += fielddefs[i]->m_elementIDs.size();
1152 idlist.insert(idlist.end(), fielddefs[i]->m_elementIDs.begin(),
1153 fielddefs[i]->m_elementIDs.end());
1160 fs::create_directory(specPath);
1162 catch (fs::filesystem_error& e)
1164 ASSERTL0(
false,
"Filesystem error: " +
string(e.what()));
1171 std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
1174 ElementIDs[0] = idlist;
1175 for (i = 1; i < nprocs; ++i)
1177 std::vector<unsigned int> tmp(elmtnums[i]);
1179 ElementIDs[i] = tmp;
1183 std::vector<std::string> filenames;
1184 for(
int i = 0; i < nprocs; ++i)
1186 boost::format pad(
"P%1$07d.fld");
1188 filenames.push_back(pad.str());
1193 specPath / fs::path(
"Info.xml"));
1195 cout <<
"Writing: " << specPath << endl;
1206 boost::format pad(
"P%1$07d.fld");
1210 fs::path poutfile(pad.str());
1211 fs::path fulloutname = specPath / poutfile;
1227 unsigned char* input = (
unsigned char*)(&in[0]);
1229 buffer.resize(
CHUNK);
1232 strm.zalloc = Z_NULL;
1233 strm.zfree = Z_NULL;
1234 strm.opaque = Z_NULL;
1235 ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
1237 ASSERTL0(ret == Z_OK,
"Error initializing Zlib.");
1239 strm.avail_in = in.size() *
sizeof(
NekDouble) /
sizeof(
char);
1240 strm.next_in = input;
1244 strm.avail_out =
CHUNK;
1245 strm.next_out = (
unsigned char*)(&buffer[0]);
1247 ret = deflate(&strm, Z_FINISH);
1251 ASSERTL0(ret != Z_STREAM_ERROR,
"Zlib stream error");
1253 have =
CHUNK - strm.avail_out;
1254 out += buffer.substr(0, have);
1256 }
while (strm.avail_out == 0);
1259 ASSERTL0(strm.avail_in == 0,
"Not all input was used.");
1262 ASSERTL0(ret == Z_STREAM_END,
"Stream not finished");
1265 (
void)deflateEnd(&strm);
1275 std::vector<NekDouble>& out)
1281 buffer.resize(
CHUNK);
1284 strm.zalloc = Z_NULL;
1285 strm.zfree = Z_NULL;
1286 strm.opaque = Z_NULL;
1288 strm.next_in = Z_NULL;
1289 ret = inflateInit(&strm);
1290 ASSERTL0(ret == Z_OK,
"Error initializing zlib decompression.");
1292 strm.avail_in = in.size();
1293 strm.next_in = (
unsigned char*)(&in[0]);
1296 strm.avail_out =
CHUNK;
1297 strm.next_out = (
unsigned char*)(&buffer[0]);
1299 ret = inflate(&strm, Z_NO_FLUSH);
1301 ASSERTL0(ret != Z_STREAM_ERROR,
"Stream error occured.");
1308 (
void)inflateEnd(&strm);
1312 have =
CHUNK - strm.avail_out;
1313 output += buffer.substr(0, have);
1315 }
while (strm.avail_out == 0);
1317 (
void)inflateEnd(&strm);
1319 if (ret == Z_STREAM_END)
1322 unsigned int len = output.size() *
sizeof(*output.c_str())
1324 out.assign( readFieldData, readFieldData + len);
1329 return Z_DATA_ERROR;
1340 if(fielddefs->m_elementIDs.size() == 0)
1346 unsigned int numbasis = 0;
1349 switch(fielddefs->m_shapeType)
1353 if(fielddefs->m_numHomogeneousDir)
1355 numbasis += fielddefs->m_numHomogeneousDir;
1361 if(fielddefs->m_numHomogeneousDir)
1377 ASSERTL0(
false,
"Unsupported shape type.");
1381 unsigned int datasize = 0;
1383 ASSERTL0(fielddefs->m_basis.size() == numbasis,
"Length of basis vector is incorrect");
1385 if(fielddefs->m_uniOrder ==
true)
1387 unsigned int cnt = 0;
1389 switch(fielddefs->m_shapeType)
1393 int l = fielddefs->m_numModes[cnt++];
1394 if(fielddefs->m_numHomogeneousDir == 1)
1396 datasize += l*fielddefs->m_numModes[cnt++];
1398 else if(fielddefs->m_numHomogeneousDir == 2)
1400 int m = fielddefs->m_numModes[cnt++];
1401 datasize += l*m*fielddefs->m_numModes[cnt++];
1411 int l = fielddefs->m_numModes[cnt++];
1412 int m = fielddefs->m_numModes[cnt++];
1414 if(fielddefs->m_numHomogeneousDir == 1)
1417 fielddefs->m_homogeneousZIDs.size();
1427 int l = fielddefs->m_numModes[cnt++];
1428 int m = fielddefs->m_numModes[cnt++];
1429 if(fielddefs->m_numHomogeneousDir == 1)
1431 datasize += l*m*fielddefs->m_homogeneousZIDs.size();
1441 int l = fielddefs->m_numModes[cnt++];
1442 int m = fielddefs->m_numModes[cnt++];
1443 int n = fielddefs->m_numModes[cnt++];
1449 int l = fielddefs->m_numModes[cnt++];
1450 int m = fielddefs->m_numModes[cnt++];
1451 int n = fielddefs->m_numModes[cnt++];
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++];
1472 ASSERTL0(
false,
"Unsupported shape type.");
1476 datasize *= fielddefs->m_elementIDs.size();
1480 unsigned int cnt = 0;
1482 for(i = 0; i < fielddefs->m_elementIDs.size(); ++i)
1484 switch(fielddefs->m_shapeType)
1487 datasize += fielddefs->m_numModes[cnt++];
1491 int l = fielddefs->m_numModes[cnt++];
1492 int m = fielddefs->m_numModes[cnt++];
1498 int l = fielddefs->m_numModes[cnt++];
1499 int m = fielddefs->m_numModes[cnt++];
1505 int l = fielddefs->m_numModes[cnt++];
1506 int m = fielddefs->m_numModes[cnt++];
1507 int n = fielddefs->m_numModes[cnt++];
1513 int l = fielddefs->m_numModes[cnt++];
1514 int m = fielddefs->m_numModes[cnt++];
1515 int n = fielddefs->m_numModes[cnt++];
1521 int l = fielddefs->m_numModes[cnt++];
1522 int m = fielddefs->m_numModes[cnt++];
1523 int n = fielddefs->m_numModes[cnt++];
1529 int l = fielddefs->m_numModes[cnt++];
1530 int m = fielddefs->m_numModes[cnt++];
1531 int n = fielddefs->m_numModes[cnt++];
1536 ASSERTL0(
false,
"Unsupported shape type.");