archiving the mesh

This commit is contained in:
Joachim Schöberl 2018-04-27 08:36:06 +02:00
parent a985a7bfb1
commit 633376972f
8 changed files with 154 additions and 18 deletions

View File

@ -774,6 +774,28 @@ namespace netgen
}
template <typename T, int BASE, typename TIND>
ngstd::Archive & operator & (ngstd::Archive & archive, Array<T,BASE,TIND> & 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

View File

@ -39,20 +39,6 @@ namespace netgen
{ return MPI_DOUBLE; }
template <int S, typename T> class Vec;
template <>
inline MPI_Datatype MyGetMPIType<Vec<3, double> > ()
{
static MPI_Datatype MPI_T = 0;
if (!MPI_T)
{
MPI_Type_contiguous ( 3, MPI_DOUBLE, &MPI_T);
MPI_Type_commit ( &MPI_T );
}
return MPI_T;
};
inline void MyMPI_Send (int i, int dest, int tag)
{
int hi = i;

View File

@ -21,6 +21,7 @@
#include "parthreads.hpp"
// #include "moveablemem.hpp"
#include "dynamicmem.hpp"
#include "archive_base.hpp"
#include "template.hpp"
#include "array.hpp"
@ -44,7 +45,6 @@
#include "mpi_interface.hpp"
#include "netgenout.hpp"
#include "gzstream.h"
#include "archive_base.hpp"
#include "ngsimd.hpp"

View File

@ -396,6 +396,20 @@ namespace netgen
};
#ifdef PARALLEL
template <>
inline MPI_Datatype MyGetMPIType<Vec<3, double> > ()
{
static MPI_Datatype MPI_T = 0;
if (!MPI_T)
{
MPI_Type_contiguous ( 3, MPI_DOUBLE, &MPI_T);
MPI_Type_commit ( &MPI_T );
}
return MPI_T;
};
#endif
}

View File

@ -71,7 +71,16 @@ 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>();
mesh->DoArchive(archive);
if (archive.Input())
{
netgen::mesh = mesh;
SetGlobalMesh (mesh);
}
/*
if (archive.Output())
{
stringstream str;
@ -86,6 +95,7 @@ namespace netgen
stringstream str(st);
LoadMesh (str);
}
*/
}
void Ngx_Mesh :: UpdateTopology ()

View File

@ -1303,7 +1303,34 @@ namespace netgen
}
void Mesh :: DoArchive (ngstd::Archive & archive)
{
archive & dimension;
archive & points;
archive & surfelements;
archive & volelements;
archive & facedecoding;
if (archive.Input())
{
RebuildSurfaceElementLists();
for (int faceindex = 1; faceindex <= GetNFD(); faceindex++)
{
Array<SurfaceElementIndex> seia;
GetSurfaceElementsOfFace (faceindex, seia);
cout << "seia = " << seia.Size() << endl;
}
CalcSurfacesOfNode ();
if (ntasks == 1) // sequential run only
{
topology.Update();
clusters -> Update();
}
SetNextMajorTimeStamp();
}
}
void Mesh :: Merge (const string & filename, const int surfindex_offset)

View File

@ -509,6 +509,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 ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal = OPT_QUALITY);

View File

@ -170,8 +170,14 @@ namespace netgen
#else
enum { BASE = 1 };
#endif
ngstd::Archive & DoArchive (ngstd::Archive & ar) { return 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;
@ -240,8 +246,15 @@ namespace netgen
SurfaceElementIndex & operator++ () { ++i; return *this; }
SurfaceElementIndex & operator-- () { --i; return *this; }
SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; }
ngstd::Archive & DoArchive (ngstd::Archive & ar) { return 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;
@ -324,8 +337,23 @@ namespace netgen
static MPI_Datatype MyGetMPIType ( );
#endif
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); }
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));
@ -349,7 +377,7 @@ namespace netgen
PointGeomInfo geominfo[ELEMENT2D_MAXPOINTS];
/// surface nr
int index:16;
short int index;
///
ELEMENT_TYPE typ;
/// number of points
@ -473,6 +501,22 @@ namespace netgen
///
const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar)
{
short _np, _typ;
bool _curved, _vis, _deleted;
if (ar.Output())
{ _np = np; _typ = typ; _curved = is_curved;
_vis = visible; _deleted = deleted; }
ar & _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];
return ar;
}
void SetIndex (int si) { index = si; }
///
@ -590,6 +634,8 @@ namespace netgen
#endif
};
inline ngstd::Archive & operator & (ngstd::Archive & archive, Element2d & mp)
{ return mp.DoArchive(archive); }
ostream & operator<<(ostream & s, const Element2d & el);
@ -731,7 +777,20 @@ namespace netgen
PointIndex & PNumMod (int i) { return pnum[(i-1) % np]; }
///
const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
ngstd::Archive & DoArchive (ngstd::Archive & ar)
{
short _np, _typ;
if (ar.Output())
{ _np = np; _typ = typ; }
ar & _np & _typ & index;
if (ar.Input())
{ np = _np; typ = ELEMENT_TYPE(_typ); }
for (size_t i = 0; i < np; i++)
ar & pnum[i];
return ar;
}
///
void SetIndex (int si) { index = si; }
///
@ -873,6 +932,9 @@ 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);
@ -1079,8 +1141,22 @@ namespace netgen
SurfaceElementIndex FirstElement() { return firstelement; }
// friend ostream & operator<<(ostream & s, const FaceDescriptor & fd);
friend class Mesh;
ngstd::Archive & DoArchive (ngstd::Archive & ar)
{
return ar & surfnr & domin & domout & tlosurf & bcprop
& surfcolour.X() & surfcolour.Y() & surfcolour.Z()
// & bcname // how to do that ?
// & firstelement // don't need it
& domin_singular & domout_singular ;
}
};
inline ngstd::Archive & operator & (ngstd::Archive & archive, FaceDescriptor & mp)
{ return mp.DoArchive(archive); }
ostream & operator<< (ostream & s, const FaceDescriptor & fd);