diff --git a/CMakeLists.txt b/CMakeLists.txt index ef0ee424..6f4bfd9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,7 @@ macro(get_dll_from_lib dll_path lib_path) get_filename_component(lib_name ${lib} name) endmacro() -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) if(WIN32) get_WIN32_WINNT(ver) add_definitions(-D_WIN32_WINNT=${ver} -DWNT -DWNT_WINDOW -DNOMINMAX) diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index 89dc88a5..eb67d688 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(core) add_subdirectory(general) add_subdirectory(gprim) add_subdirectory(linalg) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt new file mode 100644 index 00000000..d49da46b --- /dev/null +++ b/libsrc/core/CMakeLists.txt @@ -0,0 +1,8 @@ +add_definitions(-DNGINTERFACE_EXPORTS) +add_library(ngcore OBJECT basearchive.cpp) + +set_target_properties(ngcore PROPERTIES POSITION_INDEPENDENT_CODE ON ) + +install(FILES ngcore.hpp archive.hpp basearchive.hpp + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel +) diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp new file mode 100644 index 00000000..639102f4 --- /dev/null +++ b/libsrc/core/archive.hpp @@ -0,0 +1,218 @@ +#ifndef NG_ARCHIVE_HPP +#define NG_ARCHIVE_HPP + +namespace ngcore +{ + // BinaryOutArchive ====================================================================== + class BinaryOutArchive : public Archive + { + std::shared_ptr fout; + size_t ptr = 0; + enum { BUFFERSIZE = 1024 }; + char buffer[BUFFERSIZE]; + public: + BinaryOutArchive (std::shared_ptr afout) : Archive(true), fout(afout) { ; } + BinaryOutArchive (std::string filename) + : BinaryOutArchive(std::make_shared(filename)) {} + virtual ~BinaryOutArchive () { FlushBuffer(); } + + virtual Archive & operator & (double & d) + { return Write(d); } + virtual Archive & operator & (int & i) + { return Write(i); } + virtual Archive & operator & (short & i) + { return Write(i); } + virtual Archive & operator & (long & i) + { return Write(i); } + virtual Archive & operator & (size_t & i) + { return Write(i); } + virtual Archive & operator & (unsigned char & i) + { return Write(i); } + virtual Archive & operator & (bool & b) + { return Write(b); } + virtual Archive & operator & (std::string & str) + { + if (ptr > 0) FlushBuffer(); + int len = str.length(); + fout->write (reinterpret_cast(&len), sizeof(int)); + fout->write (&str[0], len); + return *this; + } + virtual Archive & operator & (char *& str) + { + if (ptr > 0) FlushBuffer(); + int len = strlen (str); + fout->write (reinterpret_cast(&len), sizeof(int)); + fout->write (&str[0], len); + return *this; + } + void FlushBuffer() + { + if (ptr > 0) + { + fout->write(&buffer[0], ptr); + ptr = 0; + } + } + + private: + template + Archive & Write (T x) + { + if (unlikely(ptr > BUFFERSIZE-sizeof(T))) + { + fout->write(&buffer[0], ptr); + * (T*) (&buffer[0]) = x; + ptr = sizeof(T); + return *this; + } + * (T*) (&buffer[ptr]) = x; + ptr += sizeof(T); + return *this; + } + }; + + // BinaryInArchive ====================================================================== + class BinaryInArchive : public Archive + { + std::shared_ptr fin; + public: + BinaryInArchive (std::shared_ptr afin) : Archive(false), fin(afin) { ; } + BinaryInArchive (std::string filename) + : BinaryInArchive(std::make_shared(filename)) {} + + virtual Archive & operator & (double & d) + { Read(d); return *this; } + virtual Archive & operator & (int & i) + { Read(i); return *this; } + virtual Archive & operator & (short & i) + { Read(i); return *this; } + virtual Archive & operator & (long & i) + { Read(i); return *this; } + virtual Archive & operator & (size_t & i) + { Read(i); return *this; } + virtual Archive & operator & (unsigned char & i) + { Read(i); return *this; } + virtual Archive & operator & (bool & b) + { Read(b); return *this; } + virtual Archive & operator & (std::string & str) + { + int len; + Read(len); + str.resize(len); + fin->read(&str[0], len); + return *this; + } + virtual Archive & operator & (char *& str) + { + int len; + Read(len); + str = new char[len+1]; + fin->read(&str[0], len); + str[len] = '\0'; + return *this; + } + + virtual Archive & Do (double * d, size_t n) + { fin->read(reinterpret_cast(d), n*sizeof(double)); return *this; } + virtual Archive & Do (int * i, size_t n) + { fin->read(reinterpret_cast(i), n*sizeof(int)); return *this; } + virtual Archive & Do (size_t * i, size_t n) + { fin->read(reinterpret_cast(i), n*sizeof(size_t)); return *this; } + + private: + template + inline void Read(T& val) + { fin->read(reinterpret_cast(&val), sizeof(T)); } + }; + + // TextOutArchive ====================================================================== + class TextOutArchive : public Archive + { + std::shared_ptr fout; + public: + TextOutArchive (std::shared_ptr afout) : Archive(true), fout(afout) { } + TextOutArchive (std::string filename) : + TextOutArchive(std::make_shared(filename.c_str())) { } + + using Archive::operator&; + virtual Archive & operator & (double & d) + { *fout << d << '\n'; return *this; } + virtual Archive & operator & (int & i) + { *fout << i << '\n'; return *this; } + virtual Archive & operator & (short & i) + { *fout << i << '\n'; return *this; } + virtual Archive & operator & (long & i) + { *fout << i << '\n'; return *this; } + virtual Archive & operator & (size_t & i) + { *fout << i << '\n'; return *this; } + virtual Archive & operator & (unsigned char & i) + { *fout << int(i) << '\n'; return *this; } + virtual Archive & operator & (bool & b) + { *fout << (b ? 't' : 'f') << '\n'; return *this; } + virtual Archive & operator & (std::string & str) + { + int len = str.length(); + *fout << len << '\n'; + fout->write(&str[0], len); + *fout << '\n'; + return *this; + } + virtual Archive & operator & (char *& str) + { + int len = strlen (str); + *fout << len << '\n'; + fout->write (&str[0], len); + *fout << '\n'; + return *this; + } + }; + + // TextInArchive ====================================================================== + class TextInArchive : public Archive + { + std::shared_ptr fin; + public: + TextInArchive (std::shared_ptr afin) : Archive(false), fin(afin) { ; } + TextInArchive (std::string filename) + : TextInArchive(std::make_shared(filename)) {} + + using Archive::operator&; + virtual Archive & operator & (double & d) + { *fin >> d; return *this; } + virtual Archive & operator & (int & i) + { *fin >> i; return *this; } + virtual Archive & operator & (short & i) + { *fin >> i; return *this; } + virtual Archive & operator & (long & i) + { *fin >> i; return *this; } + virtual Archive & operator & (size_t & i) + { *fin >> i; return *this; } + virtual Archive & operator & (unsigned char & i) + { int _i; *fin >> _i; i = _i; return *this; } + virtual Archive & operator & (bool & b) + { char c; *fin >> c; b = (c=='t'); return *this; } + virtual Archive & operator & (std::string & str) + { + int len; + *fin >> len; + char ch; + fin->get(ch); // '\n' + str.resize(len); + fin->get(&str[0], len+1, '\0'); + return *this; + } + virtual Archive & operator & (char *& str) + { + int len; + *fin >> len; + char ch; + fin->get(ch); // '\n' + str = new char[len+1]; + fin->get(&str[0], len, '\0'); + str[len] = 0; + return *this; + } + }; +} +#endif // NG_ARCHIVE_HPP diff --git a/libsrc/core/basearchive.cpp b/libsrc/core/basearchive.cpp new file mode 100644 index 00000000..1fcbe8b8 --- /dev/null +++ b/libsrc/core/basearchive.cpp @@ -0,0 +1,11 @@ + +#include "ngcore.hpp" + +namespace ngcore +{ + std::map>& GetArchiveRegister() + { + static std::map> type_register = {}; + return type_register; + } +} diff --git a/libsrc/core/basearchive.hpp b/libsrc/core/basearchive.hpp new file mode 100644 index 00000000..a43c4bc0 --- /dev/null +++ b/libsrc/core/basearchive.hpp @@ -0,0 +1,266 @@ +#ifndef NG_BASEARCHIVE_HPP +#define NG_BASEARCHIVE_HPP + +namespace ngcore +{ + class Archive; + + // Type trait to check if a class implements a 'void DoArchive(Archive&)' function + template + struct has_DoArchive + { + private: + template + static constexpr auto check(T2*) -> + typename std::is_same().DoArchive(std::declval())),void>::type; + template + static constexpr std::false_type check(...); + typedef decltype(check(0)) type; + public: + static constexpr bool value = type::value; + }; + + std::map>& GetArchiveRegister(); + + // Base Archive class + class Archive + { + bool is_output; + // how many different shared_ptr/pointer have been (un)archived + int shared_ptr_count, ptr_count; + // maps for archived shared pointers and pointers + std::map shared_ptr2nr, ptr2nr; + // vectors for storing the unarchived (shared) pointers + std::vector> nr2shared_ptr; + std::vector nr2ptr; + public: + Archive (bool ais_output) : is_output(ais_output), shared_ptr_count(0), ptr_count(0) { ; } + virtual ~Archive() { ; } + + bool Output () { return is_output; } + bool Input () { return !is_output; } + + // Pure virtual functions that have to be implemented by In-/OutArchive + virtual Archive & operator & (double & d) = 0; + virtual Archive & operator & (int & i) = 0; + virtual Archive & operator & (long & i) = 0; + virtual Archive & operator & (size_t & i) = 0; + virtual Archive & operator & (short & i) = 0; + virtual Archive & operator & (unsigned char & i) = 0; + virtual Archive & operator & (bool & b) = 0; + virtual Archive & operator & (std::string & str) = 0; + virtual Archive & operator & (char *& str) = 0; + + + // Archive std classes ================================================ + template + Archive& operator & (std::complex& c) + { + if(is_output) + (*this) << c.real() << c.imag(); + else + { + T tmp; + (*this) & tmp; + c.real(tmp); + (*this) & tmp; + c.imag(tmp); + } + return (*this); + } + template + Archive& operator & (std::vector& v) + { + size_t size; + if(is_output) + size = v.size(); + (*this) & size; + if(!is_output) + v.reserve(size); + Do(&v[0], size); + return (*this); + } + // Archive arrays ===================================================== + template + Archive & Do (T * data, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; + + virtual Archive & Do (double * d, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; + + virtual Archive & Do (int * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; + + virtual Archive & Do (long * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; + + virtual Archive & Do (size_t * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; + + virtual Archive & Do (short * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; + + virtual Archive & Do (unsigned char * i, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; + + virtual Archive & Do (bool * b, size_t n) + { for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; + + // Archive a class implementing a (void DoArchive(Archive&)) method ======= + template::value>> + Archive& operator & (T& val) + { + val.DoArchive(*this); return *this; + } + + // Archive shared_ptrs ================================================= + template + Archive& operator & (std::shared_ptr& ptr) + { + if(Output()) + { + // save -2 for nullptr + if(!ptr) + return (*this) << -2; + auto pos = shared_ptr2nr.find((void*) ptr.get()); + // if not found store -1 and the pointer + if(pos == shared_ptr2nr.end()) + { + shared_ptr2nr[(void*) ptr.get()] = shared_ptr_count++; + auto p = ptr.get(); + return (*this) << -1 & p; + } + // if found store the position + return (*this) << pos->second; + } + else // Input + { + int nr; + (*this) & nr; + if(nr == -2) + ptr = nullptr; + else if (nr == -1) + { + T* p; + (*this) & p; + ptr = std::shared_ptr(p); + nr2shared_ptr.push_back(ptr); + } + else + ptr = std::reinterpret_pointer_cast(nr2shared_ptr[nr]); + } + return *this; + } + + // Archive pointers ======================================================= + template + Archive & operator& (T *& p) + { + if (Output()) + { + // if the pointer is null store -2 + if (!p) + { + int m2 = -2; + (*this) & m2; + return *this; + } + auto pos = ptr2nr.find( (void*) p); + // if the pointer is not found in the map create a new entry + if (pos == ptr2nr.end()) + { + ptr2nr[(void*) p] = ptr_count++; + if(typeid(*p) == typeid(T)) + if constexpr (std::is_constructible::value) + { + return (*this) << -1 & (*p); + } + else + throw std::runtime_error(std::string("Archive error: Class ") + + typeid(*p).name() + " does not provide a default constructor!"); + else + { + // We want this special behaviour only for our classes that implement DoArchive + if constexpr(has_DoArchive::value) + { + if(GetArchiveRegister().count(typeid(*p).name()) == 0) + throw std::runtime_error(std::string("Archive error: Polimorphic type ") + + typeid(*p).name() + + " not registered for archive"); + else + return (*this) << -3 << std::string(typeid(*p).name()) & (*p); + } + else + throw std::runtime_error(std::string("Archive error: Class ") + + typeid(*p).name() + + " is polymorphic but not registered for archiving"); + } + } + else + { + (*this) & pos->second; + } + } + else + { + int nr; + (*this) & nr; + // cout << "in, got nr " << nr << endl; + if (nr == -2) + { + p = nullptr; + } + else if (nr == -1) + { + if constexpr (std::is_constructible::value) + { + p = new T; + // cout << "create new ptr, p = " << p << endl; + (*this) & *p; + nr2ptr.push_back(p); + } + else + throw std::runtime_error("Class isn't registered properly"); + + } + else if(nr == -3) + { + // We want this special behaviour only for our classes that implement DoArchive + if constexpr(has_DoArchive::value) + { + std::string name; + (*this) & name; + p = reinterpret_cast(GetArchiveRegister()[name]()); + nr2ptr.push_back(p); + } + else + throw std::runtime_error("Class isn't registered properly"); + } + else + { + p = (T*)nr2ptr[nr]; + // cout << "reuse ptr " << nr << ": " << p << endl; + } + } + return *this; + } + + // Write a read only variable + template + Archive & operator << (const T & t) + { + T ht(t); + (*this) & ht; + return *this; + } + }; + + template + void RegisterClassForArchive() + { + static_assert(std::is_constructible_v, "Class registered for archive must be default constructible"); + GetArchiveRegister()[std::string(typeid(T).name())] = []() -> void* { return new T; }; + } +} + +#endif // NG_BASEARCHIVE_HPP diff --git a/libsrc/core/ngcore.hpp b/libsrc/core/ngcore.hpp new file mode 100644 index 00000000..e93a506c --- /dev/null +++ b/libsrc/core/ngcore.hpp @@ -0,0 +1,30 @@ +#ifndef NG_CORE_HPP +#define NG_CORE_HPP + +// std includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#if defined(__GNUC__) + inline bool likely (bool x) { return __builtin_expect((x), true); } + inline bool unlikely (bool x) { return __builtin_expect((x), false); } +#else + inline bool likely (bool x) { return x; } + inline bool unlikely (bool x) { return x; } +#endif + +// own includes +#include "basearchive.hpp" +#include "archive.hpp" + +#endif // NG_CORE_HPP diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 40dda44e..3226e538 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -324,6 +324,12 @@ namespace netgen } + void CSGeometry :: DoArchive(Archive& archive) + { + archive & surfaces & surf2prim & solids & toplevelobjects & userpoints & userpoints_ref_factor + & identpoints & boundingbox & identicsurfaces & isidenticto & ideps + & filename & spline_surfaces; // TODO: & splinecurves2d & splinecurves3d + } void CSGeometry :: SaveSurfaces (ostream & out) const { diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index f9266de4..ee9e1260 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -124,6 +124,11 @@ namespace netgen UserPoint() = default; UserPoint (Point<3> p, int _index) : Point<3>(p), index(_index) { ; } int GetIndex() const { return index; } + void DoArchive(Archive& archive) + { + archive & index; + Point<3>::DoArchive(archive); + } }; private: @@ -198,6 +203,8 @@ namespace netgen void SetSplineCurve (const char * name, SplineGeometry<3> * spl); const SplineGeometry<2> * GetSplineCurve2d (const string & name) const; const SplineGeometry<3> * GetSplineCurve3d (const string & name) const; + + void DoArchive(Archive& archive); void SetFlags (const char * solidname, const Flags & flags); diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index b99ea2d5..05ac4acc 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -360,37 +360,32 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! py::class_> (m, "CSGeometry") .def(py::init<>()) - .def("__init__", - [](CSGeometry *instance, const string & filename) - { - cout << "load geometry"; - ifstream ist(filename); - ParseCSG(ist, instance); - instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize()); - }) - .def("__init__", - [](CSGeometry *instance, const py::list & solidlist) - { - cout << "csg from list"; - new (instance) CSGeometry(); - for (int i = 0; i < len(solidlist); i++) - { - py::object obj = solidlist[i]; - cout << "obj " << i << endl; - - py::extract> solid(solidlist[i]); - if(solid.check()) - { - cout << "its a solid" << endl; - solid()->AddSurfaces (*instance); - solid()->GiveUpOwner(); - int tlonr = instance->SetTopLevelObject (solid()->GetSolid()); - instance->GetTopLevelObject(tlonr) -> SetMaterial(solid()->GetMaterial()); - } - } - instance -> FindIdenticSurfaces(1e-8 * instance->MaxSize()); - }) - + .def(py::init([](const string& filename) + { + ifstream ist (filename); + auto geo = make_shared(); + ParseCSG(ist, geo.get()); + geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); + return geo; + }), py::arg("filename")) + .def(py::pickle( + [](CSGeometry& self) + { + stringstream ss; + self.Save(ss); + cout << "pickle = " << endl << ss.str() << endl; + return py::make_tuple(ss.str()); + }, + [](py::tuple state) + { + auto geo = make_shared(); + auto val = py::cast(state[0]); + cout << "unpickle = " << endl << val << endl; + stringstream ss(py::cast(state[0])); + // geo->Load(ss); + // geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); + return geo; + })) .def("Save", FunctionPointer([] (CSGeometry & self, string filename) { cout << "save geometry to file " << filename << endl; diff --git a/libsrc/csg/surface.hpp b/libsrc/csg/surface.hpp index 5e9afbdf..39a6ceee 100644 --- a/libsrc/csg/surface.hpp +++ b/libsrc/csg/surface.hpp @@ -63,6 +63,12 @@ namespace netgen //@} public: + virtual void DoArchive(Archive& archive) + { + archive & inverse & maxh & name & bcprop & bcname + & p1 & p2 & ex & ey & ez; + } + void SetName (const char * aname); const char * Name () const { return name; } @@ -234,6 +240,9 @@ namespace netgen class Primitive { + protected: + Array surfaceids; + Array surfaceactive; public: @@ -241,6 +250,10 @@ namespace netgen virtual ~Primitive(); + virtual void DoArchive(Archive& archive) + { + archive & surfaceids & surfaceactive; + } /* Check, whether box intersects solid defined by surface. @@ -299,9 +312,6 @@ namespace netgen virtual Surface & GetSurface (int i = 0) = 0; virtual const Surface & GetSurface (int i = 0) const = 0; - Array surfaceids; - Array surfaceactive; - int GetSurfaceId (int i = 0) const; void SetSurfaceId (int i, int id); int SurfaceActive (int i) const { return surfaceactive[i]; } @@ -329,6 +339,12 @@ namespace netgen OneSurfacePrimitive(); ~OneSurfacePrimitive(); + virtual void DoArchive(Archive& archive) + { + Surface::DoArchive(archive); + Primitive::DoArchive(archive); + } + virtual INSOLID_TYPE PointInSolid (const Point<3> & p, double eps) const; virtual INSOLID_TYPE VecInSolid (const Point<3> & p, diff --git a/libsrc/general/CMakeLists.txt b/libsrc/general/CMakeLists.txt index 5faf7c6c..00c59ea2 100644 --- a/libsrc/general/CMakeLists.txt +++ b/libsrc/general/CMakeLists.txt @@ -11,7 +11,7 @@ set_target_properties( gen PROPERTIES POSITION_INDEPENDENT_CODE ON ) install( FILES ngexception.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel ) install(FILES - archive_base.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp + array.hpp autodiff.hpp autoptr.hpp bitarray.hpp dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp ngsimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp diff --git a/libsrc/general/archive_base.hpp b/libsrc/general/archive_base.hpp deleted file mode 100644 index 9e74b0e5..00000000 --- a/libsrc/general/archive_base.hpp +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef NGS_ARCHIVE_BASE -#define NGS_ARCHIVE_BASE - -// copied from netgen - -#include -#include - -namespace ngstd -{ - - class Archive - { - bool is_output; - public: - Archive (bool ais_output) : is_output(ais_output) { ; } - virtual ~Archive() { ; } - - bool Output () { return is_output; } - bool Input () { return !is_output; } - - virtual Archive & operator & (double & d) = 0; - virtual Archive & operator & (int & i) = 0; - virtual Archive & operator & (long & i) = 0; - virtual Archive & operator & (size_t & i) = 0; - virtual Archive & operator & (short & i) = 0; - virtual Archive & operator & (unsigned char & i) = 0; - virtual Archive & operator & (bool & b) = 0; - virtual Archive & operator & (string & str) = 0; - virtual Archive & operator & (char *& str) = 0; - - template - Archive & Do (T * data, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; - - - virtual Archive & Do (double * d, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; - - virtual Archive & Do (int * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (long * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (size_t * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (short * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (unsigned char * i, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & i[j]; }; return *this; }; - - virtual Archive & Do (bool * b, size_t n) - { for (size_t j = 0; j < n; j++) { (*this) & b[j]; }; return *this; }; - - - // nvirtual Archive & Do (string * str, size_t n) - // { 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; - - /* - // necessary for msvc ??? - Archive & operator& (string* & ps) - { - return operator& (ps); - } - */ - - 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) - { - T ht(t); - (*this) & ht; - return *this; - } - }; - - -} - - -#endif diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index ead43dac..8f8263e8 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -400,6 +400,19 @@ namespace netgen ownmem = false; return data; } + + void DoArchive(Archive& archive) + { + if(archive.Output()) + archive << size; + else + { + size_t s; + archive & s; + SetSize(s); + } + archive.Do(data, size); + } private: @@ -778,30 +791,6 @@ namespace netgen if(in2.Contains(in1[i]) && in3.Contains(in1[i])) out.Append(in1[i]); } - - - - - template - ngstd::Archive & operator & (ngstd::Archive & archive, Array & a) - { - if (archive.Output()) - archive << a.Size(); - else - { - size_t size; - archive & size; - a.SetSize (size); - } - - /* - for (auto & ai : a) - archive & ai; - */ - archive.Do (&a[BASE], a.Size()); - return archive; - } - } #endif diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index 0898e58f..4d8fadc8 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -259,20 +259,13 @@ public: const T & GetData (const Iterator & it) const { return cont[it.BagNr()][it.Pos()]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & hash & cont; - return ar; } }; - template - inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_2_HASHTABLE & mp) - { return mp.DoArchive(archive); } - - - template inline ostream & operator<< (ostream & ost, const INDEX_2_HASHTABLE & ht) { @@ -436,24 +429,15 @@ public: { return cont[it.BagNr()][it.Pos()]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & hash & cont; - return ar; } }; - - template - inline ngstd::Archive & operator & (ngstd::Archive & archive, INDEX_3_HASHTABLE & mp) - { return mp.DoArchive(archive); } - - - - template inline ostream & operator<< (ostream & ost, const INDEX_3_HASHTABLE & ht) { diff --git a/libsrc/general/myadt.hpp b/libsrc/general/myadt.hpp index 7c4374d8..601a3da0 100644 --- a/libsrc/general/myadt.hpp +++ b/libsrc/general/myadt.hpp @@ -17,11 +17,15 @@ #include "../include/mydefs.hpp" +#include "../core/ngcore.hpp" +namespace netgen +{ + using namespace ngcore; +} #include "ngexception.hpp" #include "parthreads.hpp" // #include "moveablemem.hpp" #include "dynamicmem.hpp" -#include "archive_base.hpp" #include "template.hpp" #include "array.hpp" diff --git a/libsrc/general/symbolta.hpp b/libsrc/general/symbolta.hpp index c246347f..b599ea42 100644 --- a/libsrc/general/symbolta.hpp +++ b/libsrc/general/symbolta.hpp @@ -69,6 +69,8 @@ public: /// Deletes symboltable inline void DeleteAll (); + void DoArchive(Archive& archive) { archive & names & data;} + inline T & operator[] (int i) { return data[i]; } inline const T & operator[] (int i) const diff --git a/libsrc/general/table.cpp b/libsrc/general/table.cpp index 6769e03c..c964c470 100644 --- a/libsrc/general/table.cpp +++ b/libsrc/general/table.cpp @@ -213,7 +213,7 @@ namespace netgen - ngstd::Archive & BASE_TABLE :: DoArchive (ngstd::Archive & ar, int elemsize) + void BASE_TABLE :: DoArchive (Archive & ar, int elemsize) { if (ar.Output()) { @@ -248,7 +248,6 @@ namespace netgen cnt += data[i].size*elemsize; } } - return ar; } diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index e112e135..6a08b3dc 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -89,7 +89,7 @@ public: void SetElementSizesToMaxSizes (); - ngstd::Archive & DoArchive (ngstd::Archive & ar, int elemsize); + void DoArchive (Archive & ar, int elemsize); }; @@ -238,21 +238,13 @@ public: return FlatArray (data[i-BASE].size, (T*)data[i-BASE].col); } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { - return BASE_TABLE::DoArchive(ar, sizeof(T)); + 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/gprim/geomobjects.hpp b/libsrc/gprim/geomobjects.hpp index 388e9a54..ad215278 100644 --- a/libsrc/gprim/geomobjects.hpp +++ b/libsrc/gprim/geomobjects.hpp @@ -64,6 +64,12 @@ namespace netgen const T & operator() (int i) const { return x[i]; } operator const T* () const { return x; } + + void DoArchive(Archive& archive) + { + for(int i=0; i @@ -117,6 +123,12 @@ namespace netgen operator const T* () const { return x; } + void DoArchive(Archive& archive) + { + for(int i=0; i Save (ost); } - void Ngx_Mesh :: DoArchive (ngstd::Archive & archive) + void Ngx_Mesh :: DoArchive (Archive & archive) { if (archive.Input()) mesh = make_shared(); mesh->DoArchive(archive); diff --git a/libsrc/meshing/CMakeLists.txt b/libsrc/meshing/CMakeLists.txt index e9e6e211..e4eb56d9 100644 --- a/libsrc/meshing/CMakeLists.txt +++ b/libsrc/meshing/CMakeLists.txt @@ -4,6 +4,7 @@ if(NOT WIN32) $ $ $ + $ ) endif(NOT WIN32) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index c93742fd..2291d365 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1304,7 +1304,7 @@ namespace netgen } - void Mesh :: DoArchive (ngstd::Archive & archive) + void Mesh :: DoArchive (Archive & archive) { archive & dimension; archive & points; diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 2de6d3ee..fe72de2a 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -517,7 +517,7 @@ namespace netgen DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0); - DLL_HEADER void DoArchive (ngstd::Archive & archive); + DLL_HEADER void DoArchive (Archive & archive); /// DLL_HEADER void ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal = OPT_QUALITY); diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index cdfa7c7c..baed182e 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -148,9 +148,9 @@ namespace netgen return *this; } - ngstd::Archive & Segment :: DoArchive (ngstd::Archive & ar) + void Segment :: DoArchive (Archive & ar) { - return ar & pnums[0] & pnums[1] & pnums[2] + ar & pnums[0] & pnums[1] & pnums[2] & edgenr & singedge_left & singedge_right & si & cd2i & domin & domout & tlosurf & surfnr1 & surfnr2 @@ -2427,9 +2427,9 @@ namespace netgen bcn = &default_bcname; } - ngstd::Archive & FaceDescriptor :: DoArchive (ngstd::Archive & ar) + void FaceDescriptor :: DoArchive (Archive & ar) { - return ar & surfnr & domin & domout & tlosurf & bcprop + ar & surfnr & domin & domout & tlosurf & bcprop & surfcolour.X() & surfcolour.Y() & surfcolour.Z() & bcname & domin_singular & domout_singular ; @@ -2482,7 +2482,7 @@ namespace netgen maxidentnr = 0; } - ngstd::Archive & Identifications :: DoArchive (ngstd::Archive & ar) + void Identifications :: DoArchive (Archive & ar) { ar & maxidentnr; ar & identifiedpoints & identifiedpoints_nr; @@ -2503,7 +2503,6 @@ namespace netgen for (auto & t : type) ar & (unsigned char&)(t); } - return ar; } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 5fe1d8a6..e8737e93 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -171,13 +171,9 @@ namespace netgen enum { BASE = 1 }; #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } + void DoArchive (Archive & ar) { ar & i; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, PointIndex & mp) - { return mp.DoArchive(archive); } - - inline istream & operator>> (istream & ist, PointIndex & pi) { int i; ist >> i; pi = PointIndex(i); return ist; @@ -247,14 +243,9 @@ namespace netgen SurfaceElementIndex & operator-- () { --i; return *this; } SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) { return ar & i; } + void DoArchive (Archive & ar) { ar & i; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, SurfaceElementIndex & mp) - { return mp.DoArchive(archive); } - - - inline istream & operator>> (istream & ist, SurfaceElementIndex & pi) { int i; ist >> i; pi = i; return ist; @@ -337,19 +328,13 @@ namespace netgen static MPI_Datatype MyGetMPIType ( ); #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { ar & x[0] & x[1] & x[2] & layer & singular; ar & (unsigned char&)(type); - return ar; } }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, MeshPoint & mp) - { return mp.DoArchive(archive); } - - - inline ostream & operator<<(ostream & s, const MeshPoint & pt) { return (s << Point<3> (pt)); @@ -497,7 +482,7 @@ namespace netgen /// const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { short _np, _typ; bool _curved, _vis, _deleted; @@ -511,7 +496,6 @@ namespace netgen visible = _vis; deleted = _deleted; } for (size_t i = 0; i < np; i++) ar & pnum[i]; - return ar; } void SetIndex (int si) { index = si; } @@ -630,9 +614,6 @@ namespace netgen #endif }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Element2d & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Element2d & el); @@ -774,7 +755,7 @@ namespace netgen /// const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; } - ngstd::Archive & DoArchive (ngstd::Archive & ar) + void DoArchive (Archive & ar) { short _np, _typ; if (ar.Output()) @@ -784,7 +765,6 @@ namespace netgen { np = _np; typ = ELEMENT_TYPE(_typ); } for (size_t i = 0; i < np; i++) ar & pnum[i]; - return ar; } /// @@ -928,9 +908,6 @@ namespace netgen int hp_elnr; }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Element & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Element & el); @@ -1049,12 +1026,9 @@ namespace netgen #else int GetPartition () const { return 0; } #endif - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, Segment & mp) - { return mp.DoArchive(archive); } - ostream & operator<<(ostream & s, const Segment & seg); @@ -1142,13 +1116,9 @@ namespace netgen // friend ostream & operator<<(ostream & s, const FaceDescriptor & fd); friend class Mesh; - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - inline ngstd::Archive & operator & (ngstd::Archive & archive, FaceDescriptor & mp) - { return mp.DoArchive(archive); } - - ostream & operator<< (ostream & s, const FaceDescriptor & fd); @@ -1516,12 +1486,8 @@ namespace netgen DLL_HEADER void Print (ostream & ost) const; - ngstd::Archive & DoArchive (ngstd::Archive & ar); + void DoArchive (Archive & ar); }; - - inline ngstd::Archive & operator & (ngstd::Archive & archive, Identifications & mp) - { return mp.DoArchive(archive); } - }