From 639bbb2c0ae8e6a23cbdc33b9351d84ce097c94b Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Sun, 30 May 2021 18:52:27 +0200 Subject: [PATCH] .vol.bin format (using archiver) --- libsrc/meshing/meshclass.cpp | 15 +++++++++++++++ libsrc/meshing/python_mesh.cpp | 32 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index c6db8fb7..436b3c0b 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -413,6 +413,13 @@ namespace netgen void Mesh :: Save (const string & filename) const { + if (filename.find(".vol.bin") != string::npos) + { + BinaryOutArchive in(filename); + in & const_cast(*this); + return; + } + ostream * outfile; if (filename.find(".vol.gz")!=string::npos) outfile = new ogzstream(filename.c_str()); @@ -872,6 +879,14 @@ namespace netgen void Mesh :: Load (const string & filename) { cout << "filename = " << filename << endl; + + if (filename.find(".vol.bin") != string::npos) + { + BinaryInArchive in(filename); + in & (*this); + return; + } + istream * infile = NULL; if (filename.find(".vol.gz") != string::npos) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index f7b685aa..2a811b0c 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -685,29 +685,33 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) return; } - istream * infile; + istream * infile = nullptr; NgArray buf; // for distributing geometry! int strs; if( id == 0) { - - if (filename.substr (filename.length()-3, 3) == ".gz") + if (filename.substr (filename.length()-8, 8) == ".vol.bin") + mesh -> Load(filename); + else if (filename.substr (filename.length()-3, 3) == ".gz") infile = new igzstream (filename.c_str()); else infile = new ifstream (filename.c_str()); - mesh -> Load(*infile); - // make string from rest of file (for geometry info!) - // (this might be empty, in which case we take the global ng_geometry) - stringstream geom_part; - geom_part << infile->rdbuf(); - string geom_part_string = geom_part.str(); - strs = geom_part_string.size(); - // buf = new char[strs]; - buf.SetSize(strs); - memcpy(&buf[0], geom_part_string.c_str(), strs*sizeof(char)); + if(infile) + { + mesh -> Load(*infile); + // make string from rest of file (for geometry info!) + // (this might be empty, in which case we take the global ng_geometry) + stringstream geom_part; + geom_part << infile->rdbuf(); + string geom_part_string = geom_part.str(); + strs = geom_part_string.size(); + // buf = new char[strs]; + buf.SetSize(strs); + memcpy(&buf[0], geom_part_string.c_str(), strs*sizeof(char)); + delete infile; + } - delete infile; if (ntasks > 1) {