mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
Merge remote-tracking branch 'origin/master' into parallel_meshing
This commit is contained in:
commit
55ab122f35
@ -10,6 +10,7 @@
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <type_traits> // for declval, enable_if_t, false_type, is_co...
|
||||
#include <cstddef> // for std::byte
|
||||
#include <typeinfo> // for type_info
|
||||
#include <utility> // for move, swap, pair
|
||||
#include <vector> // for vector
|
||||
@ -93,6 +94,17 @@ namespace ngcore
|
||||
template<typename T>
|
||||
constexpr bool is_archivable = detail::is_Archivable_struct<T>::value;
|
||||
|
||||
|
||||
template <typename T, typename ... Trest>
|
||||
constexpr size_t TotSize ()
|
||||
{
|
||||
if constexpr (sizeof...(Trest) == 0)
|
||||
return sizeof(T);
|
||||
else
|
||||
return sizeof(T) + TotSize<Trest...> ();
|
||||
}
|
||||
|
||||
|
||||
// Base Archive class
|
||||
class NGCORE_API Archive
|
||||
{
|
||||
@ -307,6 +319,55 @@ namespace ngcore
|
||||
val.DoArchive(*this); return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// pack elements to binary
|
||||
template <typename ... Types>
|
||||
Archive & DoPacked (Types & ... args)
|
||||
{
|
||||
if (true) // (isbinary)
|
||||
{
|
||||
constexpr size_t totsize = TotSize<Types...>(); // (args...);
|
||||
std::byte mem[totsize];
|
||||
if (is_output)
|
||||
{
|
||||
CopyToBin (&mem[0], args...);
|
||||
Do(&mem[0], totsize);
|
||||
}
|
||||
else
|
||||
{
|
||||
Do(&mem[0], totsize);
|
||||
CopyFromBin (&mem[0], args...);
|
||||
}
|
||||
}
|
||||
// else
|
||||
// cout << "DoPacked of non-binary called --> individual pickling" << endl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename ... Trest>
|
||||
constexpr void CopyToBin (std::byte * ptr, T & first, Trest & ...rest) const
|
||||
{
|
||||
memcpy (ptr, &first, sizeof(first));
|
||||
CopyToBin(ptr+sizeof(first), rest...);
|
||||
}
|
||||
constexpr void CopyToBin (std::byte * ptr) const { }
|
||||
|
||||
template <typename T, typename ... Trest>
|
||||
constexpr void CopyFromBin (std::byte * ptr, T & first, Trest & ...rest) const
|
||||
{
|
||||
memcpy (&first, ptr, sizeof(first));
|
||||
CopyFromBin(ptr+sizeof(first), rest...);
|
||||
}
|
||||
constexpr void CopyFromBin (std::byte * ptr) const { }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Archive shared_ptrs =================================================
|
||||
template <typename T>
|
||||
Archive& operator & (std::shared_ptr<T>& ptr)
|
||||
@ -705,6 +766,7 @@ namespace ngcore
|
||||
{ return Write(i); }
|
||||
Archive & operator & (bool & b) override
|
||||
{ return Write(b); }
|
||||
|
||||
Archive & operator & (std::string & str) override
|
||||
{
|
||||
int len = str.length();
|
||||
@ -731,6 +793,11 @@ namespace ngcore
|
||||
ptr = 0;
|
||||
}
|
||||
}
|
||||
Archive & Do (std::byte * d, size_t n) override
|
||||
{
|
||||
FlushBuffer();
|
||||
stream->write(reinterpret_cast<char*>(d), n*sizeof(std::byte)); return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
@ -808,6 +875,8 @@ namespace ngcore
|
||||
return *this;
|
||||
}
|
||||
|
||||
Archive & Do (std::byte * d, size_t n) override
|
||||
{ stream->read(reinterpret_cast<char*>(d), n*sizeof(std::byte)); return *this; } // NOLINT
|
||||
Archive & Do (double * d, size_t n) override
|
||||
{ stream->read(reinterpret_cast<char*>(d), n*sizeof(double)); return *this; } // NOLINT
|
||||
Archive & Do (int * i, size_t n) override
|
||||
|
@ -1124,26 +1124,6 @@ namespace netgen
|
||||
is_curved = typ != TET; // false;
|
||||
}
|
||||
|
||||
void Element :: DoArchive (Archive & ar)
|
||||
{
|
||||
short _np, _typ;
|
||||
bool _curved;
|
||||
if (ar.Output())
|
||||
{ _np = np; _typ = typ; _curved = is_curved; }
|
||||
ar & _np;
|
||||
|
||||
// placement new to init flags
|
||||
if (ar.Input())
|
||||
new (this) Element(_np);
|
||||
|
||||
ar & _typ & index & _curved;
|
||||
typ = ELEMENT_TYPE(_typ);
|
||||
is_curved = _curved;
|
||||
|
||||
static_assert(sizeof(int) == sizeof (PointIndex));
|
||||
ar.Do( (int*)&pnum[0], np);
|
||||
}
|
||||
|
||||
void Element :: SetOrder (const int aorder)
|
||||
{
|
||||
orderx = aorder;
|
||||
|
@ -378,9 +378,10 @@ namespace netgen
|
||||
void DoArchive (Archive & ar)
|
||||
{
|
||||
// ar & x[0] & x[1] & x[2] & layer & singular;
|
||||
ar.Do(&x[0], 3);
|
||||
ar & layer & singular;
|
||||
ar & (unsigned char&)(type);
|
||||
// ar.Do(&x[0], 3);
|
||||
// ar & layer & singular;
|
||||
// ar & (unsigned char&)(type);
|
||||
ar.DoPacked (x[0], x[1], x[2], layer, singular, (unsigned char&)(type));
|
||||
}
|
||||
};
|
||||
|
||||
@ -558,13 +559,18 @@ namespace netgen
|
||||
if (ar.Output())
|
||||
{ _np = np; _typ = typ; _curved = is_curved;
|
||||
_vis = visible; _deleted = deleted; }
|
||||
ar & _np & _typ & index & _curved & _vis & _deleted;
|
||||
// ar & _np & _typ & index & _curved & _vis & _deleted;
|
||||
ar.DoPacked (_np, _typ, index, _curved, _vis, _deleted);
|
||||
// ar & next; don't need
|
||||
if (ar.Input())
|
||||
{ np = _np; typ = ELEMENT_TYPE(_typ); is_curved = _curved;
|
||||
visible = _vis; deleted = _deleted; }
|
||||
/*
|
||||
for (size_t i = 0; i < np; i++)
|
||||
ar & pnum[i];
|
||||
*/
|
||||
static_assert(sizeof(int) == sizeof (PointIndex));
|
||||
ar.Do( (int*)&pnum[0], np);
|
||||
}
|
||||
|
||||
#ifdef PARALLEL
|
||||
@ -838,7 +844,35 @@ namespace netgen
|
||||
///
|
||||
const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
|
||||
|
||||
void DoArchive (Archive & ar);
|
||||
void DoArchive (Archive & ar)
|
||||
{
|
||||
short _np, _typ;
|
||||
bool _curved;
|
||||
if (ar.Output())
|
||||
{ _np = np; _typ = typ; _curved = is_curved; }
|
||||
// ar & _np & _typ & index & _curved;
|
||||
ar.DoPacked (_np, _typ, index, _curved);
|
||||
|
||||
if (ar.Input())
|
||||
{
|
||||
np = _np;
|
||||
typ = ELEMENT_TYPE(_typ);
|
||||
is_curved = _curved;
|
||||
flags.marked = 1;
|
||||
flags.badel = 0;
|
||||
flags.reverse = 0;
|
||||
flags.illegal = 0;
|
||||
flags.illegal_valid = 0;
|
||||
flags.badness_valid = 0;
|
||||
flags.refflag = 1;
|
||||
flags.strongrefflag = false;
|
||||
flags.deleted = 0;
|
||||
flags.fixed = 0;
|
||||
}
|
||||
|
||||
static_assert(sizeof(int) == sizeof (PointIndex));
|
||||
ar.Do( (int*)&pnum[0], np);
|
||||
}
|
||||
|
||||
#ifdef PARALLEL
|
||||
static MPI_Datatype MyGetMPIType();
|
||||
|
Loading…
Reference in New Issue
Block a user