From bda771f86f96ccc161bb684a9903a77574666cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sat, 28 Apr 2018 03:42:04 +0200 Subject: [PATCH] more archive --- libsrc/csg/zrefine.cpp | 2 +- libsrc/general/hashtabl.hpp | 27 ++++++++++++ libsrc/general/table.cpp | 36 ++++++++++++++++ libsrc/general/table.hpp | 15 +++++++ libsrc/interface/nginterface_v2.cpp | 2 - libsrc/meshing/meshclass.cpp | 8 ++++ libsrc/meshing/meshtype.cpp | 66 ++++++++++++++++------------- libsrc/meshing/meshtype.hpp | 48 +++++++++++++++++---- libsrc/visualization/vsmesh.cpp | 2 +- 9 files changed, 163 insertions(+), 43 deletions(-) diff --git a/libsrc/csg/zrefine.cpp b/libsrc/csg/zrefine.cpp index 6e0df241..5bcb4e89 100644 --- a/libsrc/csg/zrefine.cpp +++ b/libsrc/csg/zrefine.cpp @@ -259,7 +259,7 @@ namespace netgen first_id.Set(); - if (mesh.GetIdentifications().HasIdentifiedPoints()) + // if (mesh.GetIdentifications().HasIdentifiedPoints()) { INDEX_2_HASHTABLE & identpts = mesh.GetIdentifications().GetIdentifiedPoints (); diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index d8ee3182..0898e58f 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -81,6 +81,8 @@ protected: public: /// + BASE_INDEX_2_HASHTABLE () { ; } + BASE_INDEX_2_HASHTABLE (int size) : hash (size) { }; @@ -113,6 +115,8 @@ class INDEX_2_HASHTABLE : public BASE_INDEX_2_HASHTABLE public: /// + INDEX_2_HASHTABLE () { ; } + INDEX_2_HASHTABLE (int size) : BASE_INDEX_2_HASHTABLE (size), cont(size) { ; } @@ -254,8 +258,19 @@ public: const T & GetData (const Iterator & it) const { return cont[it.BagNr()][it.Pos()]; } + + ngstd::Archive & DoArchive (ngstd::Archive & ar) + { + ar & hash & cont; + return ar; + } + }; + template + inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_2_HASHTABLE & mp) + { return mp.DoArchive(archive); } + template @@ -285,6 +300,7 @@ protected: public: /// + BASE_INDEX_3_HASHTABLE () { ; } BASE_INDEX_3_HASHTABLE (int size) : hash (size) { }; @@ -322,6 +338,7 @@ class INDEX_3_HASHTABLE : private BASE_INDEX_3_HASHTABLE public: /// + inline INDEX_3_HASHTABLE () { ; } inline INDEX_3_HASHTABLE (int size); /// inline void Set (const INDEX_3 & ahash, const T & acont); @@ -419,11 +436,21 @@ public: { return cont[it.BagNr()][it.Pos()]; } + ngstd::Archive & DoArchive (ngstd::Archive & ar) + { + ar & hash & cont; + return ar; + } + }; + template + inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_3_HASHTABLE & mp) + { return mp.DoArchive(archive); } + diff --git a/libsrc/general/table.cpp b/libsrc/general/table.cpp index 7b7b4444..9b3ca2d8 100644 --- a/libsrc/general/table.cpp +++ b/libsrc/general/table.cpp @@ -211,4 +211,40 @@ namespace netgen data[i].size = data[i].maxsize; } + + + ngstd::Archive & BASE_TABLE :: DoArchive (ngstd::Archive & ar, int elemsize) + { + if (ar.Output()) + { + size_t entries = 0, size = data.Size(); + for (size_t i = 0; i < data.Size(); i++) + entries += data[i].size; + ar & size & entries; + for (size_t i = 0; i < data.Size(); i++) + { + ar & data[i].size; + ar.Do ((unsigned char*)data[i].col, data[i].size*elemsize); + } + } + else + { + size_t entries, size; + ar & size & entries; + data.SetSize(size); + oneblock = new char [entries*elemsize]; + char * ptr = oneblock; + for (size_t i = 0; i < data.Size(); i++) + { + ar & data[i].size; + data[i].col = ptr; + data[i].maxsize = data[i].size; + ar.Do ((unsigned char*)data[i].col, data[i].size*elemsize); + ptr += size*elemsize; + } + } + return ar; + } + + } diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index 857ab8ee..e112e135 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -88,6 +88,8 @@ public: size_t UsedElements () const; void SetElementSizesToMaxSizes (); + + ngstd::Archive & DoArchive (ngstd::Archive & ar, int elemsize); }; @@ -235,8 +237,21 @@ public: return FlatArray (data[i-BASE].size, (T*)data[i-BASE].col); } + + ngstd::Archive & DoArchive (ngstd::Archive & ar) + { + return BASE_TABLE::DoArchive(ar, sizeof(T)); + } + }; + +template + inline ngstd::Archive & operator & (ngstd::Archive & archive, TABLE & mp) + { return mp.DoArchive(archive); } + + + template inline ostream & operator<< (ostream & ost, const TABLE & table) diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index c95bfcaa..9bdee1dc 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -71,8 +71,6 @@ namespace netgen void Ngx_Mesh :: DoArchive (ngstd::Archive & archive) { - cout << "ngx_mesh, doarchive, output = " << archive.Output() << endl; - cout << "mesh = " << mesh.get() << endl; if (archive.Input()) mesh = make_shared(); mesh->DoArchive(archive); if (archive.Input()) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 021ea6a8..5d9c669c 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1312,6 +1312,14 @@ namespace netgen archive & segments; archive & facedecoding; archive & materials & bcnames & cd2names; + + if (archive.Output()) + archive & *ident; + else + { + // ident = new Identifications(*this); + archive & *ident; + } if (archive.Input()) { diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index fb5e30d9..161bff3c 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -87,7 +87,7 @@ namespace netgen epgeominfo[1].dist = 0; */ - bcname = 0; + bcname = nullptr; } Segment::Segment (const Segment & other) @@ -2433,25 +2433,31 @@ namespace netgen Identifications :: Identifications (Mesh & amesh) - : mesh(amesh) + : mesh(amesh), identifiedpoints(100), identifiedpoints_nr(100) { - identifiedpoints = new INDEX_2_HASHTABLE(100); - identifiedpoints_nr = new INDEX_3_HASHTABLE(100); + // identifiedpoints = new INDEX_2_HASHTABLE(100); + // identifiedpoints_nr = new INDEX_3_HASHTABLE(100); maxidentnr = 0; } Identifications :: ~Identifications () { - delete identifiedpoints; - delete identifiedpoints_nr; + ; + // delete identifiedpoints; + // delete identifiedpoints_nr; } void Identifications :: Delete () { + identifiedpoints.DeleteData(); + identifiedpoints_nr.DeleteData(); + + /* delete identifiedpoints; identifiedpoints = new INDEX_2_HASHTABLE(100); delete identifiedpoints_nr; identifiedpoints_nr = new INDEX_3_HASHTABLE(100); + */ maxidentnr = 0; } @@ -2459,10 +2465,10 @@ namespace netgen { // (*testout) << "Identification::Add, pi1 = " << pi1 << ", pi2 = " << pi2 << ", identnr = " << identnr << endl; INDEX_2 pair (pi1, pi2); - identifiedpoints->Set (pair, identnr); + identifiedpoints.Set (pair, identnr); INDEX_3 tripl (pi1, pi2, identnr); - identifiedpoints_nr->Set (tripl, 1); + identifiedpoints_nr.Set (tripl, 1); if (identnr > maxidentnr) maxidentnr = identnr; @@ -2476,8 +2482,8 @@ namespace netgen int Identifications :: Get (PointIndex pi1, PointIndex pi2) const { INDEX_2 pair(pi1, pi2); - if (identifiedpoints->Used (pair)) - return identifiedpoints->Get(pair); + if (identifiedpoints.Used (pair)) + return identifiedpoints.Get(pair); else return 0; } @@ -2485,7 +2491,7 @@ namespace netgen bool Identifications :: Get (PointIndex pi1, PointIndex pi2, int nr) const { INDEX_3 tripl(pi1, pi2, nr); - if (identifiedpoints_nr->Used (tripl)) + if (identifiedpoints_nr.Used (tripl)) return 1; else return 0; @@ -2496,12 +2502,12 @@ namespace netgen int Identifications :: GetSymmetric (PointIndex pi1, PointIndex pi2) const { INDEX_2 pair(pi1, pi2); - if (identifiedpoints->Used (pair)) - return identifiedpoints->Get(pair); + if (identifiedpoints.Used (pair)) + return identifiedpoints.Get(pair); pair = INDEX_2 (pi2, pi1); - if (identifiedpoints->Used (pair)) - return identifiedpoints->Get(pair); + if (identifiedpoints.Used (pair)) + return identifiedpoints.Get(pair); return 0; } @@ -2525,12 +2531,12 @@ namespace netgen { cout << "getmap, identnr = " << identnr << endl; - for (int i = 1; i <= identifiedpoints_nr->GetNBags(); i++) - for (int j = 1; j <= identifiedpoints_nr->GetBagSize(i); j++) + for (int i = 1; i <= identifiedpoints_nr.GetNBags(); i++) + for (int j = 1; j <= identifiedpoints_nr.GetBagSize(i); j++) { INDEX_3 i3; int dummy; - identifiedpoints_nr->GetData (i, j, i3, dummy); + identifiedpoints_nr.GetData (i, j, i3, dummy); if (i3.I3() == identnr || !identnr) { @@ -2550,21 +2556,21 @@ namespace netgen identpairs.SetSize(0); if (identnr == 0) - for (int i = 1; i <= identifiedpoints->GetNBags(); i++) - for (int j = 1; j <= identifiedpoints->GetBagSize(i); j++) + for (int i = 1; i <= identifiedpoints.GetNBags(); i++) + for (int j = 1; j <= identifiedpoints.GetBagSize(i); j++) { INDEX_2 i2; int nr; - identifiedpoints->GetData (i, j, i2, nr); + identifiedpoints.GetData (i, j, i2, nr); identpairs.Append (i2); } else - for (int i = 1; i <= identifiedpoints_nr->GetNBags(); i++) - for (int j = 1; j <= identifiedpoints_nr->GetBagSize(i); j++) + for (int i = 1; i <= identifiedpoints_nr.GetNBags(); i++) + for (int j = 1; j <= identifiedpoints_nr.GetBagSize(i); j++) { INDEX_3 i3; int dummy; - identifiedpoints_nr->GetData (i, j, i3 , dummy); + identifiedpoints_nr.GetData (i, j, i3 , dummy); if (i3.I3() == identnr) identpairs.Append (INDEX_2(i3.I1(), i3.I2())); @@ -2574,17 +2580,17 @@ namespace netgen void Identifications :: SetMaxPointNr (int maxpnum) { - for (int i = 1; i <= identifiedpoints->GetNBags(); i++) - for (int j = 1; j <= identifiedpoints->GetBagSize(i); j++) + for (int i = 1; i <= identifiedpoints.GetNBags(); i++) + for (int j = 1; j <= identifiedpoints.GetBagSize(i); j++) { INDEX_2 i2; int nr; - identifiedpoints->GetData (i, j, i2, nr); + identifiedpoints.GetData (i, j, i2, nr); if (i2.I1() > maxpnum || i2.I2() > maxpnum) { i2.I1() = i2.I2() = -1; - identifiedpoints->SetData (i, j, i2, -1); + identifiedpoints.SetData (i, j, i2, -1); } } } @@ -2593,8 +2599,8 @@ namespace netgen void Identifications :: Print (ostream & ost) const { ost << "Identifications:" << endl; - ost << "pairs: " << endl << *identifiedpoints << endl; - ost << "pairs and nr: " << endl << *identifiedpoints_nr << endl; + ost << "pairs: " << endl << identifiedpoints << endl; + ost << "pairs and nr: " << endl << identifiedpoints_nr << endl; ost << "table: " << endl << idpoints_table << endl; } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 067db6d5..9801ac07 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1445,17 +1445,17 @@ namespace netgen class Identifications { public: - enum ID_TYPE { UNDEFINED = 1, PERIODIC = 2, CLOSESURFACES = 3, CLOSEEDGES = 4}; + enum ID_TYPE : unsigned char { UNDEFINED = 1, PERIODIC = 2, CLOSESURFACES = 3, CLOSEEDGES = 4}; private: class Mesh & mesh; /// identify points (thin layers, periodic b.c.) - INDEX_2_HASHTABLE * identifiedpoints; + INDEX_2_HASHTABLE identifiedpoints; /// the same, with info about the id-nr - INDEX_3_HASHTABLE * identifiedpoints_nr; + INDEX_3_HASHTABLE identifiedpoints_nr; /// sorted by identification nr TABLE idpoints_table; @@ -1486,23 +1486,23 @@ namespace netgen bool Get (PointIndex pi1, PointIndex pi2, int identnr) const; bool GetSymmetric (PointIndex pi1, PointIndex pi2, int identnr) const; - bool HasIdentifiedPoints() const { return identifiedpoints != nullptr; } + // bool HasIdentifiedPoints() const { return identifiedpoints != nullptr; } /// INDEX_2_HASHTABLE & GetIdentifiedPoints () { - return *identifiedpoints; + return identifiedpoints; } bool Used (PointIndex pi1, PointIndex pi2) { - return identifiedpoints->Used (INDEX_2 (pi1, pi2)); + return identifiedpoints.Used (INDEX_2 (pi1, pi2)); } bool UsedSymmetric (PointIndex pi1, PointIndex pi2) { return - identifiedpoints->Used (INDEX_2 (pi1, pi2)) || - identifiedpoints->Used (INDEX_2 (pi2, pi1)); + identifiedpoints.Used (INDEX_2 (pi1, pi2)) || + identifiedpoints.Used (INDEX_2 (pi2, pi1)); } /// @@ -1531,9 +1531,39 @@ namespace netgen void SetMaxPointNr (int maxpnum); DLL_HEADER void Print (ostream & ost) const; + + ngstd::Archive & DoArchive (ngstd::Archive & ar) + { + ar & maxidentnr; + ar & identifiedpoints & identifiedpoints_nr; + ar & idpoints_table; + if (ar.Output()) + { + size_t s = type.Size(); + ar & s; + for (auto & t : type) + ar & (unsigned char&)(t); + } + else + { + size_t s; + ar & s; + type.SetSize(s); + for (auto & t : type) + ar & (unsigned char&)(t); + } + + cout << "identifiedpoints = " << identifiedpoints << endl; + cout << "identifiedpoints_nr = " << identifiedpoints_nr << endl; + cout << "idpoints_table = " << idpoints_table << endl; + cout << "type = " << type << endl; + return ar; + } }; - + inline ngstd::Archive & operator & (ngstd::Archive & archive, Identifications & mp) + { return mp.DoArchive(archive); } + } diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index 2a9d8c80..d758c626 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -861,7 +861,7 @@ namespace netgen if (mesh -> HasIdentifications() ) { - if (mesh->GetIdentifications().HasIdentifiedPoints()) + // if (mesh->GetIdentifications().HasIdentifiedPoints()) { INDEX_2_HASHTABLE & idpts = mesh->GetIdentifications().GetIdentifiedPoints();