From f85b51496f93f02733585729fc8e93d7ac3ac8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 27 Apr 2018 22:34:25 +0200 Subject: [PATCH] persistent archiving of pointers --- libsrc/general/archive_base.hpp | 63 +++++++++++++++++++++++++++++++++ libsrc/meshing/meshclass.cpp | 9 ++--- libsrc/meshing/meshtype.hpp | 22 ++++++++---- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/libsrc/general/archive_base.hpp b/libsrc/general/archive_base.hpp index 7febab84..798f6501 100644 --- a/libsrc/general/archive_base.hpp +++ b/libsrc/general/archive_base.hpp @@ -3,6 +3,9 @@ // copied from netgen +#include +#include + namespace ngstd { @@ -57,6 +60,66 @@ namespace ngstd // { for (size_t j = 0; j < n; j++) { (*this) & str[j]; }; return *this; }; // virtual Archive & operator & (char *& str) = 0; + + // archive a pointer ... + + int cnt = 0; + std::map ptr2nr; + std::vector nr2ptr; + + template + Archive & operator& (T *& p) + { + if (Output()) + { + if (!p) + { + int m2 = -2; + (*this) & m2; + return *this; + } + auto pos = ptr2nr.find( (void*) p); + if (pos == ptr2nr.end()) + { + ptr2nr[p] = cnt; + int m1 = -1; + (*this) & m1; + cnt++; + (*this) & (*p); + } + else + { + (*this) & pos->second; + } + } + else + { + int nr; + (*this) & nr; + // cout << "in, got nr " << nr << endl; + if (nr == -2) + { + p = nullptr; + } + else if (nr == -1) + { + p = new T; + // cout << "create new ptr, p = " << p << endl; + (*this) & *p; + nr2ptr.push_back(p); + } + else + { + p = (T*)nr2ptr[nr]; + // cout << "reuse ptr " << nr << ": " << p << endl; + } + } + return *this; + } + + + + template Archive & operator << (const T & t) { diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 0c3e75b7..021ea6a8 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1309,18 +1309,13 @@ namespace netgen archive & points; archive & surfelements; archive & volelements; + archive & segments; archive & facedecoding; + archive & materials & bcnames & cd2names; if (archive.Input()) { RebuildSurfaceElementLists(); - - for (int faceindex = 1; faceindex <= GetNFD(); faceindex++) - { - Array seia; - GetSurfaceElementsOfFace (faceindex, seia); - cout << "seia = " << seia.Size() << endl; - } CalcSurfacesOfNode (); if (ntasks == 1) // sequential run only diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 98b71989..067db6d5 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -340,11 +340,7 @@ namespace netgen ngstd::Archive & DoArchive (ngstd::Archive & ar) { ar & x[0] & x[1] & x[2] & layer & singular; - unsigned char _type; - if (ar.Output()) - { _type = type; ar & _type; } - else - { ar & _type; type = POINTTYPE(_type); } + ar & (unsigned char&)(type); return ar; } }; @@ -1053,8 +1049,20 @@ namespace netgen #else int GetPartition () const { return 0; } #endif + ngstd::Archive & DoArchive (ngstd::Archive & ar) + { + return ar & pnums[0] & pnums[1] & pnums[2] + & edgenr & singedge_left & singedge_right + & si & cd2i & domin & domout & tlosurf + & surfnr1 & surfnr2 + & bcname; + } + }; + inline ngstd::Archive & operator & (ngstd::Archive & archive, Segment & mp) + { return mp.DoArchive(archive); } + ostream & operator<<(ostream & s, const Segment & seg); @@ -1146,9 +1154,9 @@ namespace netgen { return ar & surfnr & domin & domout & tlosurf & bcprop & surfcolour.X() & surfcolour.Y() & surfcolour.Z() - // & bcname // how to do that ? - // & firstelement // don't need it + & bcname & domin_singular & domout_singular ; + // don't need: firstelement } };