mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
archive for CSGeometry
This commit is contained in:
parent
292dbcf5a0
commit
fdfb596e9c
@ -5,6 +5,6 @@ set_target_properties(ngcore PROPERTIES POSITION_INDEPENDENT_CODE ON )
|
|||||||
|
|
||||||
install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen)
|
install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen)
|
||||||
|
|
||||||
install(FILES ngcore.hpp archive.hpp basearchive.hpp version.hpp
|
install(FILES ngcore.hpp archive.hpp basearchive.hpp version.hpp type_traits.hpp
|
||||||
DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel
|
DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel
|
||||||
)
|
)
|
||||||
|
@ -39,18 +39,20 @@ namespace ngcore
|
|||||||
{ return Write(b); }
|
{ return Write(b); }
|
||||||
virtual Archive & operator & (std::string & str)
|
virtual Archive & operator & (std::string & str)
|
||||||
{
|
{
|
||||||
if (ptr > 0) FlushBuffer();
|
|
||||||
int len = str.length();
|
int len = str.length();
|
||||||
fout->write (reinterpret_cast<char*>(&len), sizeof(int));
|
(*this) & len;
|
||||||
fout->write (&str[0], len);
|
FlushBuffer();
|
||||||
|
if(len)
|
||||||
|
fout->write (&str[0], len);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
virtual Archive & operator & (char *& str)
|
virtual Archive & operator & (char *& str)
|
||||||
{
|
{
|
||||||
if (ptr > 0) FlushBuffer();
|
long len = str ? strlen (str) : -1;
|
||||||
int len = strlen (str);
|
(*this) & len;
|
||||||
fout->write (reinterpret_cast<char*>(&len), sizeof(int));
|
FlushBuffer();
|
||||||
fout->write (&str[0], len);
|
if(len > 0)
|
||||||
|
fout->write (&str[0], len);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void FlushBuffer()
|
void FlushBuffer()
|
||||||
@ -113,18 +115,24 @@ namespace ngcore
|
|||||||
virtual Archive & operator & (std::string & str)
|
virtual Archive & operator & (std::string & str)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
Read(len);
|
(*this) & len;
|
||||||
str.resize(len);
|
str.resize(len);
|
||||||
fin->read(&str[0], len);
|
if(len)
|
||||||
|
fin->read(&str[0], len);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
virtual Archive & operator & (char *& str)
|
virtual Archive & operator & (char *& str)
|
||||||
{
|
{
|
||||||
int len;
|
long len;
|
||||||
Read(len);
|
(*this) & len;
|
||||||
str = new char[len+1];
|
if(len == -1)
|
||||||
fin->read(&str[0], len);
|
str = nullptr;
|
||||||
str[len] = '\0';
|
else
|
||||||
|
{
|
||||||
|
str = new char[len+1];
|
||||||
|
fin->read(&str[0], len);
|
||||||
|
str[len] = '\0';
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,9 +192,9 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
virtual Archive & operator & (char *& str)
|
virtual Archive & operator & (char *& str)
|
||||||
{
|
{
|
||||||
int len = strlen (str);
|
long len = str ? strlen (str) : -1;
|
||||||
*fout << len << '\n';
|
*this & len;
|
||||||
if(len)
|
if(len > 0)
|
||||||
{
|
{
|
||||||
fout->write (&str[0], len);
|
fout->write (&str[0], len);
|
||||||
*fout << '\n';
|
*fout << '\n';
|
||||||
@ -239,14 +247,21 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
virtual Archive & operator & (char *& str)
|
virtual Archive & operator & (char *& str)
|
||||||
{
|
{
|
||||||
int len;
|
long len;
|
||||||
*fin >> len;
|
(*this) & len;
|
||||||
char ch;
|
char ch;
|
||||||
fin->get(ch); // '\n'
|
if(len == -1)
|
||||||
|
{
|
||||||
|
str = nullptr;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
str = new char[len+1];
|
str = new char[len+1];
|
||||||
if(len)
|
if(len)
|
||||||
fin->get(&str[0], len, '\0');
|
{
|
||||||
str[len] = 0;
|
fin->get(ch); // \n
|
||||||
|
fin->get(&str[0], len+1, '\0');
|
||||||
|
}
|
||||||
|
str[len] = '\0';
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -7,11 +7,17 @@
|
|||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
{
|
{
|
||||||
std::map<std::string, VersionInfo>& GetLibraryVersions()
|
static std::map<std::string, VersionInfo> library_versions;
|
||||||
|
std::map<std::string, VersionInfo>& Archive :: GetLibraryVersions()
|
||||||
{
|
{
|
||||||
static std::map<std::string, VersionInfo> library_versions;
|
|
||||||
return library_versions;
|
return library_versions;
|
||||||
}
|
}
|
||||||
|
VersionInfo GetLibraryVersion(const std::string& library)
|
||||||
|
{ return library_versions[library]; }
|
||||||
|
|
||||||
|
void SetLibraryVersion(const std::string& library, VersionInfo version)
|
||||||
|
{ library_versions[library] = version; }
|
||||||
|
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
// windows does demangling in typeid(T).name()
|
// windows does demangling in typeid(T).name()
|
||||||
std::string demangle(const char* typeinfo) { return typeinfo; }
|
std::string demangle(const char* typeinfo) { return typeinfo; }
|
||||||
|
@ -5,7 +5,8 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
class VersionInfo;
|
class VersionInfo;
|
||||||
// Libraries using this archive can store their version here to implement backwards compatibility
|
// Libraries using this archive can store their version here to implement backwards compatibility
|
||||||
std::map<std::string, VersionInfo>& GetLibraryVersions();
|
VersionInfo GetLibraryVersion(const std::string& library);
|
||||||
|
void SetLibraryVersion(const std::string& library, VersionInfo version);
|
||||||
|
|
||||||
class Archive;
|
class Archive;
|
||||||
std::string demangle(const char* typeinfo);
|
std::string demangle(const char* typeinfo);
|
||||||
@ -376,6 +377,13 @@ namespace ngcore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const ptr
|
||||||
|
template<typename T>
|
||||||
|
Archive& operator &(const T*& t)
|
||||||
|
{
|
||||||
|
return (*this) & const_cast<T*&>(t);
|
||||||
|
}
|
||||||
|
|
||||||
// Write a read only variable
|
// Write a read only variable
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Archive & operator << (const T & t)
|
Archive & operator << (const T & t)
|
||||||
@ -386,6 +394,9 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void FlushBuffer() {}
|
virtual void FlushBuffer() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static std::map<std::string, VersionInfo>& GetLibraryVersions();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename ... Bases>
|
template<typename T, typename ... Bases>
|
||||||
@ -394,6 +405,8 @@ namespace ngcore
|
|||||||
public:
|
public:
|
||||||
RegisterClassForArchive()
|
RegisterClassForArchive()
|
||||||
{
|
{
|
||||||
|
static_assert(all_of_tmpl<std::is_base_of<Bases,T>::value...>,
|
||||||
|
"Variadic template arguments must be base classes of T");
|
||||||
ClassArchiveInfo info;
|
ClassArchiveInfo info;
|
||||||
info.creator = [this,&info](const std::type_info& ti) -> void*
|
info.creator = [this,&info](const std::type_info& ti) -> void*
|
||||||
{ return typeid(T) == ti ? constructIfPossible<T>()
|
{ return typeid(T) == ti ? constructIfPossible<T>()
|
||||||
|
@ -28,6 +28,7 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
|
|
||||||
// own includes
|
// own includes
|
||||||
|
#include "type_traits.hpp"
|
||||||
#include "basearchive.hpp"
|
#include "basearchive.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include "archive.hpp"
|
#include "archive.hpp"
|
||||||
|
8
libsrc/core/type_traits.hpp
Normal file
8
libsrc/core/type_traits.hpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
namespace ngcore
|
||||||
|
{
|
||||||
|
template<bool... b> struct _BoolArray{};
|
||||||
|
template<bool ... T>
|
||||||
|
constexpr bool all_of_tmpl = std::is_same<_BoolArray<T...>, _BoolArray<(T || true)...>>::value;
|
||||||
|
}
|
@ -4,13 +4,13 @@ namespace ngcore
|
|||||||
class VersionInfo
|
class VersionInfo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
size_t mayor, minor, date, commit_offset;
|
size_t mayor, minor, release, patch;
|
||||||
std::string git_hash;
|
std::string git_hash;
|
||||||
public:
|
public:
|
||||||
VersionInfo() : mayor(0), minor(0), date(0), commit_offset(0), git_hash("") {}
|
VersionInfo() : mayor(0), minor(0), release(0), patch(0), git_hash("") {}
|
||||||
VersionInfo(std::string vstring)
|
VersionInfo(std::string vstring)
|
||||||
{
|
{
|
||||||
minor = date = commit_offset = 0;
|
minor = release = patch = 0;
|
||||||
git_hash = "";
|
git_hash = "";
|
||||||
if(vstring.substr(0,1) == "v")
|
if(vstring.substr(0,1) == "v")
|
||||||
vstring = vstring.substr(1,vstring.size()-1);
|
vstring = vstring.substr(1,vstring.size()-1);
|
||||||
@ -27,13 +27,13 @@ namespace ngcore
|
|||||||
if(vstring.size())
|
if(vstring.size())
|
||||||
{
|
{
|
||||||
dot = vstring.find("-");
|
dot = vstring.find("-");
|
||||||
date = std::stoi(vstring.substr(0,dot));
|
release = std::stoi(vstring.substr(0,dot));
|
||||||
if(dot == size_t(-1)) vstring = "";
|
if(dot == size_t(-1)) vstring = "";
|
||||||
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
|
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
|
||||||
if(vstring.size())
|
if(vstring.size())
|
||||||
{
|
{
|
||||||
dot = vstring.find("-");
|
dot = vstring.find("-");
|
||||||
commit_offset = std::stoi(vstring.substr(0,dot));
|
patch = std::stoi(vstring.substr(0,dot));
|
||||||
if(dot == size_t(-1)) vstring = "";
|
if(dot == size_t(-1)) vstring = "";
|
||||||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
|
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
|
||||||
if(vstring.size())
|
if(vstring.size())
|
||||||
@ -46,15 +46,15 @@ namespace ngcore
|
|||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{ std::string vstring = "v" + std::to_string(mayor);
|
{ std::string vstring = "v" + std::to_string(mayor);
|
||||||
if(minor || date || commit_offset || git_hash.size())
|
if(minor || release || patch || git_hash.size())
|
||||||
{
|
{
|
||||||
vstring += "." + std::to_string(minor);
|
vstring += "." + std::to_string(minor);
|
||||||
if(date || commit_offset || git_hash.size())
|
if(release || patch || git_hash.size())
|
||||||
{
|
{
|
||||||
vstring += "." + std::to_string(date);
|
vstring += "." + std::to_string(release);
|
||||||
if(commit_offset || git_hash.size())
|
if(patch || git_hash.size())
|
||||||
{
|
{
|
||||||
vstring += "-" + std::to_string(commit_offset);
|
vstring += "-" + std::to_string(patch);
|
||||||
if(git_hash.size())
|
if(git_hash.size())
|
||||||
vstring += "-" + git_hash;
|
vstring += "-" + git_hash;
|
||||||
}
|
}
|
||||||
@ -64,13 +64,13 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
bool operator <(const VersionInfo& other) const
|
bool operator <(const VersionInfo& other) const
|
||||||
{
|
{
|
||||||
return std::tie(mayor, minor, date, commit_offset) <
|
return std::tie(mayor, minor, release, patch) <
|
||||||
std::tie(other.mayor, other.minor, other.date, other.commit_offset);
|
std::tie(other.mayor, other.minor, other.release, other.patch);
|
||||||
}
|
}
|
||||||
bool operator ==(const VersionInfo& other) const
|
bool operator ==(const VersionInfo& other) const
|
||||||
{
|
{
|
||||||
return mayor == other.mayor && minor == other.minor && date == other.date
|
return mayor == other.mayor && minor == other.minor && release == other.release
|
||||||
&& commit_offset == other.commit_offset;
|
&& patch == other.patch;
|
||||||
}
|
}
|
||||||
bool operator >(const VersionInfo& other) const { return other < (*this); }
|
bool operator >(const VersionInfo& other) const { return other < (*this); }
|
||||||
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
|
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
|
||||||
@ -78,7 +78,7 @@ namespace ngcore
|
|||||||
|
|
||||||
void DoArchive(Archive& ar)
|
void DoArchive(Archive& ar)
|
||||||
{
|
{
|
||||||
ar & mayor & minor & date & commit_offset & git_hash;
|
ar & mayor & minor & release & patch & git_hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1941,6 +1941,13 @@ void EllipticCone :: GetTriangleApproximation
|
|||||||
<< R << " " << r << endl;
|
<< R << " " << r << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterClassForArchive<QuadraticSurface, OneSurfacePrimitive> regqs;
|
||||||
|
RegisterClassForArchive<Plane, QuadraticSurface> regpl;
|
||||||
|
RegisterClassForArchive<Sphere, QuadraticSurface> regsph;
|
||||||
|
RegisterClassForArchive<Cylinder, QuadraticSurface> regcyl;
|
||||||
|
RegisterClassForArchive<EllipticCylinder, QuadraticSurface> regelcyl;
|
||||||
|
RegisterClassForArchive<Ellipsoid, QuadraticSurface> regell;
|
||||||
|
RegisterClassForArchive<Cone, QuadraticSurface> regcone;
|
||||||
|
RegisterClassForArchive<EllipticCone, QuadraticSurface> regellcone;
|
||||||
|
RegisterClassForArchive<Torus, OneSurfacePrimitive> regtorus;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,11 @@ namespace netgen
|
|||||||
virtual void Print (ostream & str) const;
|
virtual void Print (ostream & str) const;
|
||||||
virtual void Read (istream & ist);
|
virtual void Read (istream & ist);
|
||||||
void PrintCoeff (ostream & ost) const;
|
void PrintCoeff (ostream & ost) const;
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
OneSurfacePrimitive::DoArchive(ar);
|
||||||
|
ar & cxx & cyy & czz & cxy & cxz & cyz & cx & cy & cz & c1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -64,6 +69,14 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
Plane (const Point<3> & ap, Vec<3> an);
|
Plane (const Point<3> & ap, Vec<3> an);
|
||||||
|
// default constructor for archive
|
||||||
|
Plane() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & p & n & eps_base;
|
||||||
|
}
|
||||||
Point<3> P() const { return p; }
|
Point<3> P() const { return p; }
|
||||||
Vec<3> N() const { return n; }
|
Vec<3> N() const { return n; }
|
||||||
virtual void GetPrimitiveData (const char *& classname,
|
virtual void GetPrimitiveData (const char *& classname,
|
||||||
@ -130,6 +143,14 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
Sphere (const Point<3> & ac, double ar);
|
Sphere (const Point<3> & ac, double ar);
|
||||||
|
// default constructor for archive
|
||||||
|
Sphere() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & c & r & invr;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void GetPrimitiveData (const char *& classname,
|
virtual void GetPrimitiveData (const char *& classname,
|
||||||
Array<double> & coeffs) const;
|
Array<double> & coeffs) const;
|
||||||
@ -188,6 +209,14 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
Cylinder (const Point<3> & aa, const Point<3> & ab, double ar);
|
Cylinder (const Point<3> & aa, const Point<3> & ab, double ar);
|
||||||
Cylinder (Array<double> & coeffs);
|
Cylinder (Array<double> & coeffs);
|
||||||
|
// default constructor for archive
|
||||||
|
Cylinder() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & a & b & r & vab;
|
||||||
|
}
|
||||||
Point<3> A() const { return a; }
|
Point<3> A() const { return a; }
|
||||||
Point<3> B() const { return b; }
|
Point<3> B() const { return b; }
|
||||||
double R() const { return r; }
|
double R() const { return r; }
|
||||||
@ -250,7 +279,14 @@ namespace netgen
|
|||||||
EllipticCylinder (const Point<3> & aa,
|
EllipticCylinder (const Point<3> & aa,
|
||||||
const Vec<3> & avl, const Vec<3> & avs);
|
const Vec<3> & avl, const Vec<3> & avs);
|
||||||
EllipticCylinder (Array<double> & coeffs);
|
EllipticCylinder (Array<double> & coeffs);
|
||||||
|
// default constructor for archive
|
||||||
|
EllipticCylinder() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & a & vl & vs & vab & t0vec & t1vec & vabl & t0 & t1;
|
||||||
|
}
|
||||||
|
|
||||||
// static Primitive * CreateDefault ();
|
// static Primitive * CreateDefault ();
|
||||||
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
||||||
@ -299,6 +335,14 @@ namespace netgen
|
|||||||
const Vec<3> & av1,
|
const Vec<3> & av1,
|
||||||
const Vec<3> & av2,
|
const Vec<3> & av2,
|
||||||
const Vec<3> & av3);
|
const Vec<3> & av3);
|
||||||
|
// default constructor for archive
|
||||||
|
Ellipsoid() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & a & v1 & v2 & v3 & rmin;
|
||||||
|
}
|
||||||
///
|
///
|
||||||
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
||||||
///
|
///
|
||||||
@ -339,6 +383,14 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
Cone (const Point<3> & aa, const Point<3> & ab, double ara, double arb);
|
Cone (const Point<3> & aa, const Point<3> & ab, double ara, double arb);
|
||||||
///
|
///
|
||||||
|
// default constructor for archive
|
||||||
|
Cone() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & a & b & ra & rb & minr & vab & t0vec & t1vec & vabl & t0 & t1 & cosphi;
|
||||||
|
}
|
||||||
static Primitive * CreateDefault ();
|
static Primitive * CreateDefault ();
|
||||||
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
||||||
virtual void SetPrimitiveData (Array<double> & coeffs);
|
virtual void SetPrimitiveData (Array<double> & coeffs);
|
||||||
@ -383,7 +435,14 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
EllipticCone (const Point<3> & aa, const Vec<3> & avl,
|
EllipticCone (const Point<3> & aa, const Vec<3> & avl,
|
||||||
const Vec<3> & avs, double ah, double avlr);
|
const Vec<3> & avs, double ah, double avlr);
|
||||||
|
// default constructor for archive
|
||||||
|
EllipticCone() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
QuadraticSurface::DoArchive(ar);
|
||||||
|
ar & a & vl & vs & h & vlr;
|
||||||
|
}
|
||||||
static Primitive * CreateDefault ();
|
static Primitive * CreateDefault ();
|
||||||
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
virtual void GetPrimitiveData (const char *& classname, Array<double> & coeffs) const;
|
||||||
virtual void SetPrimitiveData (Array<double> & coeffs);
|
virtual void SetPrimitiveData (Array<double> & coeffs);
|
||||||
@ -425,6 +484,14 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
/// OK
|
/// OK
|
||||||
Torus (const Point<3> & ac, const Vec<3> & an, double aR, double ar);
|
Torus (const Point<3> & ac, const Vec<3> & an, double aR, double ar);
|
||||||
|
// default constructor for archive
|
||||||
|
Torus() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
OneSurfacePrimitive::DoArchive(ar);
|
||||||
|
ar & c & n & R & r;
|
||||||
|
}
|
||||||
/// OK
|
/// OK
|
||||||
const Point<3> & Center () const { return c; }
|
const Point<3> & Center () const { return c; }
|
||||||
/// OK
|
/// OK
|
||||||
|
@ -523,4 +523,8 @@ void OrthoBrick :: Reduce (const BoxSphere<3> & box)
|
|||||||
surfaceactive.Elem(6) =
|
surfaceactive.Elem(6) =
|
||||||
(box.PMin()(0) < pmax(0)) && (pmax(0) < box.PMax()(0));
|
(box.PMin()(0) < pmax(0)) && (pmax(0) < box.PMax()(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterClassForArchive<Parallelogram3d, Surface> regpar;
|
||||||
|
RegisterClassForArchive<Brick, Primitive> regbrick;
|
||||||
|
RegisterClassForArchive<OrthoBrick, Brick> regob;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,16 @@ namespace netgen
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Parallelogram3d (Point<3> ap1, Point<3> ap2, Point<3> ap3);
|
Parallelogram3d (Point<3> ap1, Point<3> ap2, Point<3> ap3);
|
||||||
|
// default constructor for archive
|
||||||
|
Parallelogram3d() {}
|
||||||
virtual ~Parallelogram3d ();
|
virtual ~Parallelogram3d ();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Surface::DoArchive(ar);
|
||||||
|
ar & p1 & p2 & p3 & p4 & v12 & v13 & n;
|
||||||
|
}
|
||||||
|
|
||||||
void SetPoints (Point<3> ap1, Point<3> ap2, Point<3> ap3);
|
void SetPoints (Point<3> ap1, Point<3> ap2, Point<3> ap3);
|
||||||
|
|
||||||
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
||||||
@ -60,7 +68,15 @@ namespace netgen
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4);
|
Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4);
|
||||||
|
// default constructor for archive
|
||||||
|
Brick() {}
|
||||||
virtual ~Brick ();
|
virtual ~Brick ();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Primitive::DoArchive(ar);
|
||||||
|
ar & p1 & p2 & p3 & p4 & v12 & v13 & v14 & faces;
|
||||||
|
}
|
||||||
static Primitive * CreateDefault ();
|
static Primitive * CreateDefault ();
|
||||||
|
|
||||||
virtual Primitive * Copy () const;
|
virtual Primitive * Copy () const;
|
||||||
@ -116,7 +132,15 @@ namespace netgen
|
|||||||
Point<3> pmin, pmax;
|
Point<3> pmin, pmax;
|
||||||
public:
|
public:
|
||||||
OrthoBrick (const Point<3> & ap1, const Point<3> & ap2);
|
OrthoBrick (const Point<3> & ap1, const Point<3> & ap2);
|
||||||
|
// default constructor for archive
|
||||||
|
OrthoBrick() {}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Brick::DoArchive(ar);
|
||||||
|
ar & pmin & pmax;
|
||||||
|
}
|
||||||
|
|
||||||
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
||||||
virtual void Reduce (const BoxSphere<3> & box);
|
virtual void Reduce (const BoxSphere<3> & box);
|
||||||
};
|
};
|
||||||
|
@ -327,8 +327,10 @@ namespace netgen
|
|||||||
void CSGeometry :: DoArchive(Archive& archive)
|
void CSGeometry :: DoArchive(Archive& archive)
|
||||||
{
|
{
|
||||||
archive & surfaces & solids & toplevelobjects & userpoints & userpoints_ref_factor
|
archive & surfaces & solids & toplevelobjects & userpoints & userpoints_ref_factor
|
||||||
& identpoints & boundingbox & identicsurfaces & isidenticto & ideps
|
& identpoints & boundingbox & isidenticto & ideps
|
||||||
& filename & spline_surfaces; // TODO: & splinecurves2d & splinecurves3d & surf2prim
|
& filename & spline_surfaces & splinecurves2d & splinecurves3d & surf2prim;
|
||||||
|
if(archive.Input())
|
||||||
|
FindIdenticSurfaces(1e-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSGeometry :: SaveSurfaces (ostream & out) const
|
void CSGeometry :: SaveSurfaces (ostream & out) const
|
||||||
|
@ -39,6 +39,8 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
TopLevelObject (Solid * asolid,
|
TopLevelObject (Solid * asolid,
|
||||||
Surface * asurface = NULL);
|
Surface * asurface = NULL);
|
||||||
|
// default constructor for archive
|
||||||
|
TopLevelObject() {}
|
||||||
|
|
||||||
void DoArchive(Archive& archive)
|
void DoArchive(Archive& archive)
|
||||||
{
|
{
|
||||||
|
@ -653,15 +653,15 @@ namespace netgen
|
|||||||
Extrusion :: Extrusion(const SplineGeometry<3> & path_in,
|
Extrusion :: Extrusion(const SplineGeometry<3> & path_in,
|
||||||
const SplineGeometry<2> & profile_in,
|
const SplineGeometry<2> & profile_in,
|
||||||
const Vec<3> & z_dir) :
|
const Vec<3> & z_dir) :
|
||||||
path(path_in), profile(profile_in), z_direction(z_dir)
|
path(&path_in), profile(&profile_in), z_direction(z_dir)
|
||||||
{
|
{
|
||||||
surfaceactive.SetSize(0);
|
surfaceactive.SetSize(0);
|
||||||
surfaceids.SetSize(0);
|
surfaceids.SetSize(0);
|
||||||
|
|
||||||
for(int j=0; j<profile.GetNSplines(); j++)
|
for(int j=0; j<profile->GetNSplines(); j++)
|
||||||
{
|
{
|
||||||
ExtrusionFace * face = new ExtrusionFace(&(profile.GetSpline(j)),
|
ExtrusionFace * face = new ExtrusionFace(&((*profile).GetSpline(j)),
|
||||||
&path,
|
path,
|
||||||
z_direction);
|
z_direction);
|
||||||
faces.Append(face);
|
faces.Append(face);
|
||||||
surfaceactive.Append(true);
|
surfaceactive.Append(true);
|
||||||
@ -872,5 +872,6 @@ namespace netgen
|
|||||||
surfaceactive[i] = true;
|
surfaceactive[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterClassForArchive<ExtrusionFace, Surface> regexf;
|
||||||
|
RegisterClassForArchive<Extrusion, Primitive> regextr;
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,18 @@ namespace netgen
|
|||||||
const Vec<3> & z_direction);
|
const Vec<3> & z_direction);
|
||||||
|
|
||||||
ExtrusionFace(const Array<double> & raw_data);
|
ExtrusionFace(const Array<double> & raw_data);
|
||||||
|
// default constructor for archive
|
||||||
|
ExtrusionFace() {}
|
||||||
|
|
||||||
~ExtrusionFace();
|
~ExtrusionFace();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Surface::DoArchive(ar);
|
||||||
|
ar & profile & path & glob_z_direction & deletable & spline3_path & line_path &
|
||||||
|
x_dir & y_dir & z_dir & loc_z_dir & p0 & profile_tangent & profile_par &
|
||||||
|
profile_spline_coeff & latest_seg & latest_t & latest_point2d & latest_point3d;
|
||||||
|
}
|
||||||
|
|
||||||
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
||||||
|
|
||||||
@ -109,10 +118,10 @@ namespace netgen
|
|||||||
class Extrusion : public Primitive
|
class Extrusion : public Primitive
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const SplineGeometry<3> & path;
|
const SplineGeometry<3>* path;
|
||||||
const SplineGeometry<2> & profile; // closed, clockwise oriented curve
|
const SplineGeometry<2>* profile; // closed, clockwise oriented curve
|
||||||
|
|
||||||
const Vec<3> & z_direction;
|
Vec<3> z_direction;
|
||||||
|
|
||||||
Array<ExtrusionFace*> faces;
|
Array<ExtrusionFace*> faces;
|
||||||
|
|
||||||
@ -122,7 +131,15 @@ namespace netgen
|
|||||||
Extrusion(const SplineGeometry<3> & path_in,
|
Extrusion(const SplineGeometry<3> & path_in,
|
||||||
const SplineGeometry<2> & profile_in,
|
const SplineGeometry<2> & profile_in,
|
||||||
const Vec<3> & z_dir);
|
const Vec<3> & z_dir);
|
||||||
|
// default constructor for archive
|
||||||
|
Extrusion() {}
|
||||||
~Extrusion();
|
~Extrusion();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Primitive::DoArchive(ar);
|
||||||
|
ar & path & profile & z_direction & faces & latestfacenum;
|
||||||
|
}
|
||||||
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
||||||
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
|
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
|
||||||
double eps) const;
|
double eps) const;
|
||||||
|
@ -374,12 +374,13 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
|
|||||||
auto ss = make_shared<stringstream>();
|
auto ss = make_shared<stringstream>();
|
||||||
BinaryOutArchive archive(ss);
|
BinaryOutArchive archive(ss);
|
||||||
archive & self;
|
archive & self;
|
||||||
return py::make_tuple(ss->str());
|
archive.FlushBuffer();
|
||||||
|
return py::make_tuple(py::bytes(ss->str()));
|
||||||
},
|
},
|
||||||
[](py::tuple state)
|
[](py::tuple state)
|
||||||
{
|
{
|
||||||
auto geo = make_shared<CSGeometry>();
|
auto geo = make_shared<CSGeometry>();
|
||||||
auto ss = make_shared<stringstream> (py::cast<string>(state[0]));
|
auto ss = make_shared<stringstream> (py::cast<py::bytes>(state[0]));
|
||||||
BinaryInArchive archive(ss);
|
BinaryInArchive archive(ss);
|
||||||
archive & (*geo);
|
archive & (*geo);
|
||||||
return geo;
|
return geo;
|
||||||
|
@ -640,9 +640,9 @@ namespace netgen
|
|||||||
Revolution :: Revolution(const Point<3> & p0_in,
|
Revolution :: Revolution(const Point<3> & p0_in,
|
||||||
const Point<3> & p1_in,
|
const Point<3> & p1_in,
|
||||||
const SplineGeometry<2> & spline_in) :
|
const SplineGeometry<2> & spline_in) :
|
||||||
p0(p0_in), p1(p1_in), splinecurve(spline_in),
|
p0(p0_in), p1(p1_in)
|
||||||
nsplines(spline_in.GetNSplines())
|
|
||||||
{
|
{
|
||||||
|
auto nsplines = spline_in.GetNSplines();
|
||||||
surfaceactive.SetSize(0);
|
surfaceactive.SetSize(0);
|
||||||
surfaceids.SetSize(0);
|
surfaceids.SetSize(0);
|
||||||
|
|
||||||
@ -650,21 +650,21 @@ namespace netgen
|
|||||||
|
|
||||||
v_axis.Normalize();
|
v_axis.Normalize();
|
||||||
|
|
||||||
if(splinecurve.GetSpline(0).StartPI()(1) <= 0. &&
|
if(spline_in.GetSpline(0).StartPI()(1) <= 0. &&
|
||||||
splinecurve.GetSpline(nsplines-1).EndPI()(1) <= 0.)
|
spline_in.GetSpline(nsplines-1).EndPI()(1) <= 0.)
|
||||||
type = 2;
|
type = 2;
|
||||||
else if (Dist(splinecurve.GetSpline(0).StartPI(),
|
else if (Dist(spline_in.GetSpline(0).StartPI(),
|
||||||
splinecurve.GetSpline(nsplines-1).EndPI()) < 1e-7)
|
spline_in.GetSpline(nsplines-1).EndPI()) < 1e-7)
|
||||||
type = 1;
|
type = 1;
|
||||||
else
|
else
|
||||||
cerr << "Surface of revolution cannot be constructed" << endl;
|
cerr << "Surface of revolution cannot be constructed" << endl;
|
||||||
|
|
||||||
for(int i=0; i<splinecurve.GetNSplines(); i++)
|
for(int i=0; i<spline_in.GetNSplines(); i++)
|
||||||
{
|
{
|
||||||
RevolutionFace * face = new RevolutionFace(splinecurve.GetSpline(i),
|
RevolutionFace * face = new RevolutionFace(spline_in.GetSpline(i),
|
||||||
p0,v_axis,
|
p0,v_axis,
|
||||||
type==2 && i==0,
|
type==2 && i==0,
|
||||||
type==2 && i==splinecurve.GetNSplines()-1);
|
type==2 && i==spline_in.GetNSplines()-1);
|
||||||
faces.Append(face);
|
faces.Append(face);
|
||||||
surfaceactive.Append(1);
|
surfaceactive.Append(1);
|
||||||
surfaceids.Append(0);
|
surfaceids.Append(0);
|
||||||
@ -959,4 +959,7 @@ namespace netgen
|
|||||||
for(int i=0; i<faces.Size(); i++)
|
for(int i=0; i<faces.Size(); i++)
|
||||||
surfaceactive[i] = true;
|
surfaceactive[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterClassForArchive<RevolutionFace, Surface> regrevf;
|
||||||
|
RegisterClassForArchive<Revolution, Primitive> regrev;
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,18 @@ namespace netgen
|
|||||||
const int id_in = 0);
|
const int id_in = 0);
|
||||||
|
|
||||||
RevolutionFace(const Array<double> & raw_data);
|
RevolutionFace(const Array<double> & raw_data);
|
||||||
|
// default constructor for archive
|
||||||
|
RevolutionFace() {}
|
||||||
|
|
||||||
~RevolutionFace();
|
~RevolutionFace();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Surface::DoArchive(ar);
|
||||||
|
ar & isfirst & islast & spline & deletable & p0 & v_axis & id & spline_coefficient
|
||||||
|
& spline_coefficient_shifted & checklines_vec & checklines_start & checklines_normal;
|
||||||
|
}
|
||||||
|
|
||||||
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
virtual int IsIdentic (const Surface & s2, int & inv, double eps) const;
|
||||||
|
|
||||||
virtual double CalcFunctionValue (const Point<3> & point) const;
|
virtual double CalcFunctionValue (const Point<3> & point) const;
|
||||||
@ -96,8 +105,6 @@ namespace netgen
|
|||||||
private:
|
private:
|
||||||
Point<3> p0,p1;
|
Point<3> p0,p1;
|
||||||
Vec<3> v_axis;
|
Vec<3> v_axis;
|
||||||
const SplineGeometry<2> & splinecurve;
|
|
||||||
const int nsplines;
|
|
||||||
|
|
||||||
// 1 ... torus-like
|
// 1 ... torus-like
|
||||||
// 2 ... sphere-like
|
// 2 ... sphere-like
|
||||||
@ -112,9 +119,16 @@ namespace netgen
|
|||||||
Revolution(const Point<3> & p0_in,
|
Revolution(const Point<3> & p0_in,
|
||||||
const Point<3> & p1_in,
|
const Point<3> & p1_in,
|
||||||
const SplineGeometry<2> & spline_in);
|
const SplineGeometry<2> & spline_in);
|
||||||
|
// default constructor for archive
|
||||||
|
Revolution() {}
|
||||||
|
|
||||||
~Revolution();
|
~Revolution();
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Primitive::DoArchive(ar);
|
||||||
|
ar & p0 & p1 & v_axis & type & faces & intersecting_face;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check, whether box intersects solid defined by surface.
|
Check, whether box intersects solid defined by surface.
|
||||||
|
@ -55,6 +55,8 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
Solid (Primitive * aprim);
|
Solid (Primitive * aprim);
|
||||||
Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
|
Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
|
||||||
|
// default constructor for archive
|
||||||
|
Solid () {}
|
||||||
~Solid ();
|
~Solid ();
|
||||||
|
|
||||||
void DoArchive(Archive& archive)
|
void DoArchive(Archive& archive)
|
||||||
|
@ -566,4 +566,8 @@ void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp)
|
|||||||
if (Abs2 (rs) < 1e-24 && i > 1) i = 1;
|
if (Abs2 (rs) < 1e-24 && i > 1) i = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterClassForArchive<Surface> regsurf;
|
||||||
|
RegisterClassForArchive<Primitive> regprim;
|
||||||
|
RegisterClassForArchive<OneSurfacePrimitive, Surface, Primitive> regosf;
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ namespace netgen
|
|||||||
auto ext = dynamic_cast<const SplineSegExt *>(spline);
|
auto ext = dynamic_cast<const SplineSegExt *>(spline);
|
||||||
if(ext)
|
if(ext)
|
||||||
{
|
{
|
||||||
ss3 = dynamic_cast<const SplineSeg3<2> *>(&ext->seg);
|
ss3 = dynamic_cast<const SplineSeg3<2> *>(ext->seg);
|
||||||
ls = dynamic_cast<const LineSeg<2> *>(&ext->seg);
|
ls = dynamic_cast<const LineSeg<2> *>(ext->seg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ namespace netgen
|
|||||||
class SplineSegExt : public SplineSeg<2>
|
class SplineSegExt : public SplineSeg<2>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const SplineSeg<2> & seg;
|
SplineSeg<2>* seg;
|
||||||
|
|
||||||
/// left domain
|
/// left domain
|
||||||
int leftdom;
|
int leftdom;
|
||||||
@ -42,35 +42,43 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
int layer;
|
int layer;
|
||||||
|
|
||||||
SplineSegExt (const SplineSeg<2> & hseg)
|
SplineSegExt (SplineSeg<2> & hseg)
|
||||||
: seg(hseg)
|
: seg(&hseg)
|
||||||
{
|
{
|
||||||
layer = 1;
|
layer = 1;
|
||||||
}
|
}
|
||||||
|
// default constructor for archive
|
||||||
|
SplineSegExt() {}
|
||||||
|
|
||||||
~SplineSegExt ()
|
~SplineSegExt ()
|
||||||
{
|
{
|
||||||
delete &seg;
|
delete seg;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & seg & leftdom & rightdom & reffak & hmax & bc & copyfrom
|
||||||
|
& hpref_left & hpref_right & layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const GeomPoint<2> & StartPI () const
|
virtual const GeomPoint<2> & StartPI () const
|
||||||
{
|
{
|
||||||
return seg.StartPI();
|
return seg->StartPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const GeomPoint<2> & EndPI () const
|
virtual const GeomPoint<2> & EndPI () const
|
||||||
{
|
{
|
||||||
return seg.EndPI();
|
return seg->EndPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Point<2> GetPoint (double t) const
|
virtual Point<2> GetPoint (double t) const
|
||||||
{
|
{
|
||||||
return seg.GetPoint(t);
|
return seg->GetPoint(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Vec<2> GetTangent (const double t) const
|
virtual Vec<2> GetTangent (const double t) const
|
||||||
{
|
{
|
||||||
return seg.GetTangent(t);
|
return seg->GetTangent(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetDerivatives (const double t,
|
virtual void GetDerivatives (const double t,
|
||||||
@ -78,27 +86,27 @@ namespace netgen
|
|||||||
Vec<2> & first,
|
Vec<2> & first,
|
||||||
Vec<2> & second) const
|
Vec<2> & second) const
|
||||||
{
|
{
|
||||||
seg.GetDerivatives (t, point, first, second);
|
seg->GetDerivatives (t, point, first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetCoeff (Vector & coeffs) const
|
virtual void GetCoeff (Vector & coeffs) const
|
||||||
{
|
{
|
||||||
seg.GetCoeff (coeffs);
|
seg->GetCoeff (coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetPoints (int n, Array<Point<2> > & points) const
|
virtual void GetPoints (int n, Array<Point<2> > & points) const
|
||||||
{
|
{
|
||||||
seg.GetPoints (n, points);
|
seg->GetPoints (n, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual double MaxCurvature () const
|
virtual double MaxCurvature () const
|
||||||
{
|
{
|
||||||
return seg.MaxCurvature();
|
return seg->MaxCurvature();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual string GetType () const
|
virtual string GetType () const
|
||||||
{
|
{
|
||||||
return seg.GetType();
|
return seg->GetType();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual double CalcCurvature (double t) const
|
virtual double CalcCurvature (double t) const
|
||||||
@ -112,7 +120,7 @@ namespace netgen
|
|||||||
|
|
||||||
virtual bool InConvexHull (Point<2> p, double eps) const
|
virtual bool InConvexHull (Point<2> p, double eps) const
|
||||||
{
|
{
|
||||||
return seg.InConvexHull (p, eps);
|
return seg->InConvexHull (p, eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -551,11 +551,10 @@ namespace netgen
|
|||||||
template class SplineSeg3<2>;
|
template class SplineSeg3<2>;
|
||||||
template class SplineSeg3<3>;
|
template class SplineSeg3<3>;
|
||||||
|
|
||||||
|
RegisterClassForArchive<SplineSeg<2>> regss2;
|
||||||
|
RegisterClassForArchive<SplineSeg<3>> regss3;
|
||||||
|
RegisterClassForArchive<LineSeg<2>, SplineSeg<2>> regls2;
|
||||||
|
RegisterClassForArchive<LineSeg<3>, SplineSeg<3>> regls3;
|
||||||
|
RegisterClassForArchive<SplineSeg3<2>, SplineSeg<2>> regsss2;
|
||||||
|
RegisterClassForArchive<SplineSeg3<3>, SplineSeg<3>> regsss3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,11 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
GeomPoint (const Point<D> & ap, double aref = 1, double ahpref=0)
|
GeomPoint (const Point<D> & ap, double aref = 1, double ahpref=0)
|
||||||
: Point<D>(ap), refatpoint(aref), hmax(1e99), hpref(ahpref) { ; }
|
: Point<D>(ap), refatpoint(aref), hmax(1e99), hpref(ahpref) { ; }
|
||||||
|
void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
Point<D>::DoArchive(ar);
|
||||||
|
ar & refatpoint & hmax & hpref;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +77,7 @@ namespace netgen
|
|||||||
second = 1.0/sqr(eps) * ( (pr-point)+(pl-point));
|
second = 1.0/sqr(eps) * ( (pr-point)+(pl-point));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar) = 0;
|
||||||
|
|
||||||
/// returns initial point on curve
|
/// returns initial point on curve
|
||||||
virtual const GeomPoint<D> & StartPI () const = 0;
|
virtual const GeomPoint<D> & StartPI () const = 0;
|
||||||
@ -122,6 +128,12 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
LineSeg (const GeomPoint<D> & ap1, const GeomPoint<D> & ap2);
|
LineSeg (const GeomPoint<D> & ap1, const GeomPoint<D> & ap2);
|
||||||
///
|
///
|
||||||
|
// default constructor for archive
|
||||||
|
LineSeg() {}
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & p1 & p2;
|
||||||
|
}
|
||||||
virtual double Length () const;
|
virtual double Length () const;
|
||||||
///
|
///
|
||||||
inline virtual Point<D> GetPoint (double t) const;
|
inline virtual Point<D> GetPoint (double t) const;
|
||||||
@ -172,7 +184,13 @@ namespace netgen
|
|||||||
SplineSeg3 (const GeomPoint<D> & ap1,
|
SplineSeg3 (const GeomPoint<D> & ap1,
|
||||||
const GeomPoint<D> & ap2,
|
const GeomPoint<D> & ap2,
|
||||||
const GeomPoint<D> & ap3);
|
const GeomPoint<D> & ap3);
|
||||||
|
// default constructor for archive
|
||||||
|
SplineSeg3() {}
|
||||||
///
|
///
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & p1 & p2 & p3 & weight & proj_latest_t;
|
||||||
|
}
|
||||||
inline virtual Point<D> GetPoint (double t) const;
|
inline virtual Point<D> GetPoint (double t) const;
|
||||||
///
|
///
|
||||||
virtual Vec<D> GetTangent (const double t) const;
|
virtual Vec<D> GetTangent (const double t) const;
|
||||||
@ -226,6 +244,12 @@ namespace netgen
|
|||||||
CircleSeg (const GeomPoint<D> & ap1,
|
CircleSeg (const GeomPoint<D> & ap1,
|
||||||
const GeomPoint<D> & ap2,
|
const GeomPoint<D> & ap2,
|
||||||
const GeomPoint<D> & ap3);
|
const GeomPoint<D> & ap3);
|
||||||
|
// default constructor for archive
|
||||||
|
CircleSeg() {}
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & p1 & p2 & p3 & pm & radius & w1 & w3;
|
||||||
|
}
|
||||||
///
|
///
|
||||||
virtual Point<D> GetPoint (double t) const;
|
virtual Point<D> GetPoint (double t) const;
|
||||||
///
|
///
|
||||||
@ -270,6 +294,12 @@ namespace netgen
|
|||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
DiscretePointsSeg (const Array<Point<D> > & apts);
|
DiscretePointsSeg (const Array<Point<D> > & apts);
|
||||||
|
// default constructor for archive
|
||||||
|
DiscretePointsSeg() {}
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & pts & p1n & p2n;
|
||||||
|
}
|
||||||
///
|
///
|
||||||
virtual ~DiscretePointsSeg ();
|
virtual ~DiscretePointsSeg ();
|
||||||
///
|
///
|
||||||
@ -624,8 +654,14 @@ namespace netgen
|
|||||||
///
|
///
|
||||||
BSplineSeg (const Array<Point<D> > & apts);
|
BSplineSeg (const Array<Point<D> > & apts);
|
||||||
///
|
///
|
||||||
|
//default constructor for archive
|
||||||
|
BSplineSeg() {}
|
||||||
virtual ~BSplineSeg();
|
virtual ~BSplineSeg();
|
||||||
///
|
///
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & pts & p1n & p2n & ti;
|
||||||
|
}
|
||||||
virtual Point<D> GetPoint (double t) const;
|
virtual Point<D> GetPoint (double t) const;
|
||||||
///
|
///
|
||||||
virtual const GeomPoint<D> & StartPI () const { return p1n; };
|
virtual const GeomPoint<D> & StartPI () const { return p1n; };
|
||||||
|
@ -55,6 +55,10 @@ namespace netgen
|
|||||||
// void SetGrading (const double grading);
|
// void SetGrading (const double grading);
|
||||||
DLL_HEADER void AppendPoint (const Point<D> & p, const double reffac = 1., const bool hpref = false);
|
DLL_HEADER void AppendPoint (const Point<D> & p, const double reffac = 1., const bool hpref = false);
|
||||||
|
|
||||||
|
void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & geompoints & splines;
|
||||||
|
}
|
||||||
|
|
||||||
void AppendSegment(SplineSeg<D> * spline)
|
void AppendSegment(SplineSeg<D> * spline)
|
||||||
{
|
{
|
||||||
|
@ -139,6 +139,14 @@ public:
|
|||||||
~Vector ()
|
~Vector ()
|
||||||
{ if (ownmem) delete [] data; }
|
{ if (ownmem) delete [] data; }
|
||||||
|
|
||||||
|
virtual void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
auto size = s;
|
||||||
|
ar & ownmem & size;
|
||||||
|
if(!ar.Output())
|
||||||
|
SetSize(size);
|
||||||
|
ar.Do(data, size);
|
||||||
|
}
|
||||||
Vector & operator= (const FlatVector & v)
|
Vector & operator= (const FlatVector & v)
|
||||||
{ memcpy (data, &v(0), s*sizeof(double)); return *this; }
|
{ memcpy (data, &v(0), s*sizeof(double)); return *this; }
|
||||||
|
|
||||||
|
@ -68,6 +68,21 @@ public:
|
|||||||
|
|
||||||
class NotRegisteredForArchive : public SharedPtrAndPtrHolder {};
|
class NotRegisteredForArchive : public SharedPtrAndPtrHolder {};
|
||||||
|
|
||||||
|
class ClassWithConstPtr
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int* ptr;
|
||||||
|
public:
|
||||||
|
ClassWithConstPtr(const int* aptr) : ptr(aptr) { }
|
||||||
|
// constructor only for archive
|
||||||
|
ClassWithConstPtr() {}
|
||||||
|
void DoArchive(Archive& ar)
|
||||||
|
{
|
||||||
|
ar & ptr;
|
||||||
|
}
|
||||||
|
const int* getPtr() { return ptr; }
|
||||||
|
};
|
||||||
|
|
||||||
class OneMoreDerivedClass : public SharedPtrAndPtrHolder {};
|
class OneMoreDerivedClass : public SharedPtrAndPtrHolder {};
|
||||||
|
|
||||||
static RegisterClassForArchive<CommonBase> regb;
|
static RegisterClassForArchive<CommonBase> regb;
|
||||||
@ -110,18 +125,36 @@ void testSharedPointer(Archive& in, Archive& out)
|
|||||||
|
|
||||||
void testPointer(Archive& in, Archive& out)
|
void testPointer(Archive& in, Archive& out)
|
||||||
{
|
{
|
||||||
SECTION("Same pointer")
|
PtrHolder holder, holder2;
|
||||||
|
holder.numbers.push_back(new int(3));
|
||||||
|
holder2.numbers = holder.numbers; // same shared ptr
|
||||||
|
out & holder & holder2;
|
||||||
|
out.FlushBuffer();
|
||||||
|
PtrHolder inholder, inholder2;
|
||||||
|
in & inholder & inholder2;
|
||||||
|
CHECK(inholder.numbers.size() == 1);
|
||||||
|
CHECK(inholder.numbers[0] == inholder2.numbers[0]);
|
||||||
|
CHECK(*inholder.numbers[0] == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testConstPointer(Archive& in, Archive& out)
|
||||||
|
{
|
||||||
|
SECTION("Const pointer")
|
||||||
{
|
{
|
||||||
PtrHolder holder, holder2;
|
int* iptr = new int(4);
|
||||||
holder.numbers.push_back(new int(3));
|
double d = 0.1;
|
||||||
holder2.numbers = holder.numbers; // same shared ptr
|
ClassWithConstPtr cls(iptr);
|
||||||
out & holder & holder2;
|
out & cls & iptr & d;
|
||||||
out.FlushBuffer();
|
out.FlushBuffer();
|
||||||
PtrHolder inholder, inholder2;
|
ClassWithConstPtr incls;
|
||||||
in & inholder & inholder2;
|
int* iniptr;
|
||||||
CHECK(inholder.numbers.size() == 1);
|
double ind;
|
||||||
CHECK(inholder.numbers[0] == inholder2.numbers[0]);
|
in & incls & iniptr & ind;
|
||||||
CHECK(*inholder.numbers[0] == 3);
|
CHECK(*incls.getPtr() == 4);
|
||||||
|
CHECK(incls.getPtr() == iniptr);
|
||||||
|
CHECK(ind == 0.1);
|
||||||
|
delete iptr;
|
||||||
|
delete iniptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +238,7 @@ void testMultipleInheritance(Archive& in, Archive& out)
|
|||||||
|
|
||||||
void testLibraryVersion(Archive& in, Archive& out)
|
void testLibraryVersion(Archive& in, Archive& out)
|
||||||
{
|
{
|
||||||
GetLibraryVersions()["netgen"] = "v6.2.1812";
|
SetLibraryVersion("netgen","v6.2.1812");
|
||||||
CHECK(in.getVersion("netgen") == "v6.2.1811");
|
CHECK(in.getVersion("netgen") == "v6.2.1811");
|
||||||
CHECK(out.getVersion("netgen") == "v6.2.1812");
|
CHECK(out.getVersion("netgen") == "v6.2.1812");
|
||||||
}
|
}
|
||||||
@ -214,12 +247,25 @@ void testArchive(Archive& in, Archive& out)
|
|||||||
{
|
{
|
||||||
SECTION("Empty String")
|
SECTION("Empty String")
|
||||||
{
|
{
|
||||||
out << string("") << 1;
|
char* cstr = nullptr;
|
||||||
|
char* empty = new char[1];
|
||||||
|
char* simple = new char[7] {'s','i','m','p','l','e','\0'};
|
||||||
|
empty[0] = '\0';
|
||||||
|
out << string("") << cstr << empty << simple << string("simple") << long(1);
|
||||||
out.FlushBuffer();
|
out.FlushBuffer();
|
||||||
string str; int i;
|
string str; long i; char* readempty; char* readsimple;
|
||||||
in & str & i;
|
string simplestr;
|
||||||
|
in & str & cstr & readempty & readsimple & simplestr & i;
|
||||||
CHECK(str == "");
|
CHECK(str == "");
|
||||||
|
CHECK(cstr == nullptr);
|
||||||
|
CHECK(strcmp(readempty,"") == 0);
|
||||||
|
CHECK(strcmp(readsimple,"simple") == 0);
|
||||||
CHECK(i == 1);
|
CHECK(i == 1);
|
||||||
|
CHECK(simplestr == "simple");
|
||||||
|
delete[] readempty;
|
||||||
|
delete[] empty;
|
||||||
|
delete[] simple;
|
||||||
|
delete[] readsimple;
|
||||||
}
|
}
|
||||||
SECTION("SharedPtr")
|
SECTION("SharedPtr")
|
||||||
{
|
{
|
||||||
@ -229,6 +275,10 @@ void testArchive(Archive& in, Archive& out)
|
|||||||
{
|
{
|
||||||
testPointer(in, out);
|
testPointer(in, out);
|
||||||
}
|
}
|
||||||
|
SECTION("Const Pointer")
|
||||||
|
{
|
||||||
|
testConstPointer(in, out);
|
||||||
|
}
|
||||||
SECTION("Multiple inheritance")
|
SECTION("Multiple inheritance")
|
||||||
{
|
{
|
||||||
testMultipleInheritance(in, out);
|
testMultipleInheritance(in, out);
|
||||||
@ -250,7 +300,7 @@ void testArchive(Archive& in, Archive& out)
|
|||||||
|
|
||||||
TEST_CASE("BinaryArchive")
|
TEST_CASE("BinaryArchive")
|
||||||
{
|
{
|
||||||
GetLibraryVersions()["netgen"] = "v6.2.1811";
|
SetLibraryVersion("netgen","v6.2.1811");
|
||||||
auto stream = make_shared<stringstream>();
|
auto stream = make_shared<stringstream>();
|
||||||
BinaryOutArchive out(stream);
|
BinaryOutArchive out(stream);
|
||||||
BinaryInArchive in(stream);
|
BinaryInArchive in(stream);
|
||||||
@ -259,7 +309,7 @@ TEST_CASE("BinaryArchive")
|
|||||||
|
|
||||||
TEST_CASE("TextArchive")
|
TEST_CASE("TextArchive")
|
||||||
{
|
{
|
||||||
GetLibraryVersions()["netgen"] = "v6.2.1811";
|
SetLibraryVersion("netgen","v6.2.1811");
|
||||||
auto stream = make_shared<stringstream>();
|
auto stream = make_shared<stringstream>();
|
||||||
TextOutArchive out(stream);
|
TextOutArchive out(stream);
|
||||||
TextInArchive in(stream);
|
TextInArchive in(stream);
|
||||||
|
40
tests/pytest/test_pickling.py
Normal file
40
tests/pytest/test_pickling.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
import netgen.csg as csg
|
||||||
|
import pickle, numpy
|
||||||
|
from ngsolve import Draw, Mesh
|
||||||
|
|
||||||
|
def test_pickle_csg():
|
||||||
|
geo = csg.CSGeometry()
|
||||||
|
geo.Add(csg.Sphere(csg.Pnt(0,0,0), 2).bc("sphere"))
|
||||||
|
brick = csg.OrthoBrick(csg.Pnt(-3,-3,-3), csg.Pnt(3,3,3))
|
||||||
|
geo.Add(csg.Cylinder(csg.Pnt(0,0,0), csg.Pnt(1,0,0), 0.5) * brick)
|
||||||
|
geo.Add(csg.Ellipsoid(csg.Pnt(0,0,0), csg.Vec(1,0,0), csg.Vec(0,1,0), csg.Vec(0,0,0.5)))
|
||||||
|
geo.Add(csg.Cone(csg.Pnt(0,0,0), csg.Pnt(3,0,0), 1, 0.5) * brick)
|
||||||
|
geo.Add(csg.EllipticCone(csg.Pnt(0,0,0), csg.Vec(2,0,0), csg.Vec(0,1,0), 3, 0.5) * brick)
|
||||||
|
geo.Add(csg.Torus(csg.Pnt(0,0,0), csg.Vec(0,1,0), 0.3, 0.05))
|
||||||
|
pts2d = [[1,1], [1,-1], [-1,-1], [-1,1]]
|
||||||
|
segs = [[0,1], [1,2], [2,3], [3,0]]
|
||||||
|
curve = csg.SplineCurve2d()
|
||||||
|
pnrs = [curve.AddPoint(*p) for p in pts2d]
|
||||||
|
for s in segs:
|
||||||
|
curve.AddSegment(pnrs[s[0]], pnrs[s[1]])
|
||||||
|
geo.Add(csg.Revolution(csg.Pnt(0,0,0), csg.Pnt(1,0,0), curve))
|
||||||
|
path = csg.SplineCurve3d()
|
||||||
|
pnts = [(0,0,0), (2,0,0), (2,2,0)]
|
||||||
|
segs = [(0,1,2)]
|
||||||
|
for pnt in pnts:
|
||||||
|
path.AddPoint (*pnt)
|
||||||
|
|
||||||
|
for seg in segs:
|
||||||
|
path.AddSegment (*seg)
|
||||||
|
geo.Add(csg.Extrusion(path, curve, csg.Vec(0,0,1)))
|
||||||
|
|
||||||
|
geo_dump = pickle.dumps(geo)
|
||||||
|
geo2 = pickle.loads(geo_dump)
|
||||||
|
vd1 = geo._visualizationData()
|
||||||
|
vd2 = geo2._visualizationData()
|
||||||
|
for val1, val2 in zip(vd1.values(), vd2.values()):
|
||||||
|
assert numpy.array_equal(val1, val2)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_pickle_csg()
|
Loading…
Reference in New Issue
Block a user