netgen/libsrc/include/nginterface_v2.hpp

322 lines
6.6 KiB
C++
Raw Normal View History

2009-07-20 14:36:36 +06:00
#ifndef NGINTERFACE_V2
#define NGINTERFACE_V2
/**************************************************************************/
/* File: nginterface_v2.hpp */
/* Author: Joachim Schoeberl */
/* Date: May 09 */
/**************************************************************************/
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
/*
C++ interface to Netgen
*/
namespace netgen
{
2016-12-11 16:12:05 +05:00
static constexpr int POINTINDEX_BASE = 1;
2014-01-07 16:42:39 +06:00
struct T_EDGE2
{
// int orient:1;
// int nr:31; // 0-based
int nr; // 0-based
2014-01-07 16:42:39 +06:00
};
struct T_FACE2
{
// int orient:3;
// int nr:29; // 0-based
int nr; // 0-based
2014-01-07 16:42:39 +06:00
};
2013-04-03 02:27:12 +06:00
2009-07-20 14:36:36 +06:00
class Ng_Element
2009-07-13 19:03:01 +06:00
{
2009-07-20 14:36:36 +06:00
class Ng_Points
{
public:
2017-02-25 21:11:30 +05:00
size_t num;
2009-07-20 14:36:36 +06:00
const int * ptr;
2009-07-13 19:03:01 +06:00
2017-02-25 21:11:30 +05:00
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
2009-07-20 14:36:36 +06:00
};
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
class Ng_Vertices
{
public:
2017-02-25 21:11:30 +05:00
size_t num;
2009-07-20 14:36:36 +06:00
const int * ptr;
2009-07-13 19:03:01 +06:00
2017-02-25 21:11:30 +05:00
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
2009-07-20 14:36:36 +06:00
};
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
class Ng_Edges
{
public:
2017-02-25 21:11:30 +05:00
size_t num;
2014-01-07 16:42:39 +06:00
const T_EDGE2 * ptr;
2009-07-13 19:03:01 +06:00
2017-02-25 21:11:30 +05:00
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i].nr; }
2009-07-20 14:36:36 +06:00
};
class Ng_Faces
{
public:
2017-02-25 21:11:30 +05:00
size_t num;
2014-01-07 16:42:39 +06:00
const T_FACE2 * ptr;
2009-07-20 14:36:36 +06:00
2017-02-25 21:11:30 +05:00
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i].nr; }
2009-07-20 14:36:36 +06:00
};
class Ng_Facets
{
public:
2017-02-25 21:11:30 +05:00
size_t num;
int base;
const int * ptr;
2017-02-25 21:11:30 +05:00
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-base; }
};
2009-07-20 14:36:36 +06:00
public:
NG_ELEMENT_TYPE type;
2014-12-04 17:39:12 +05:00
int index; // material / boundary condition
2016-02-27 00:30:40 +05:00
const string * mat; // material / boundary label
2009-07-20 14:36:36 +06:00
NG_ELEMENT_TYPE GetType() const { return type; }
2015-01-10 19:48:49 +05:00
int GetIndex() const { return index-1; }
2009-07-20 14:36:36 +06:00
Ng_Points points; // all points
Ng_Vertices vertices;
Ng_Edges edges;
Ng_Faces faces;
Ng_Facets facets;
2015-04-27 14:18:22 +05:00
bool is_curved;
2009-07-13 19:03:01 +06:00
};
2009-04-03 20:39:52 +06:00
2009-09-07 17:50:13 +06:00
class Ng_Point
{
double * pt;
2014-01-07 16:42:39 +06:00
public:
Ng_Point (double * apt) : pt(apt) { ; }
2009-09-07 17:50:13 +06:00
double operator[] (int i)
{ return pt[i]; }
2014-01-07 16:42:39 +06:00
operator const double * () { return pt; }
2009-09-07 17:50:13 +06:00
};
2009-07-20 14:36:36 +06:00
template <int DIM> class Ng_Node;
template <>
class Ng_Node<0>
{
class Ng_Elements
{
public:
int ne;
const int * ptr;
int Size() const { return ne; }
int operator[] (int i) const { return ptr[i]; }
};
public:
Ng_Elements elements;
2016-03-23 12:17:45 +05:00
Ng_Elements bnd_elements;
};
2009-07-20 14:36:36 +06:00
template <>
class Ng_Node<1>
2009-04-03 20:39:52 +06:00
{
2009-07-20 14:36:36 +06:00
class Ng_Vertices
{
public:
const int * ptr;
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
int Size() const { return 2; }
2016-12-11 16:12:05 +05:00
int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; }
2009-07-20 14:36:36 +06:00
};
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
public:
Ng_Vertices vertices;
};
2010-05-17 15:00:30 +06:00
template <>
class Ng_Node<2>
{
class Ng_Vertices
{
public:
int nv;
const int * ptr;
int Size() const { return nv; }
2016-12-11 16:12:05 +05:00
int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; }
2010-05-17 15:00:30 +06:00
};
class Ng_Edges
{
public:
int ned;
const int * ptr;
int Size() const { return ned; }
int operator[] (int i) const { return ptr[i]-1; }
};
public:
Ng_Vertices vertices;
Ng_Edges edges;
2017-05-10 20:41:44 +05:00
int surface_el; // -1 if face not on surface
2010-05-17 15:00:30 +06:00
};
2009-07-20 14:36:36 +06:00
2009-04-03 20:39:52 +06:00
2014-09-08 21:21:09 +06:00
class Mesh;
2009-07-19 23:33:25 +06:00
inline void DummyTaskManager2 (function<void(int,int)> func)
{ func(0,1); }
2013-04-05 16:06:06 +06:00
class DLL_HEADER Ngx_Mesh
2013-04-03 02:27:12 +06:00
{
private:
2014-09-08 21:21:09 +06:00
shared_ptr<Mesh> mesh;
2013-04-03 02:27:12 +06:00
public:
2014-01-20 15:30:17 +06:00
// Ngx_Mesh () { ; }
// Ngx_Mesh(class Mesh * amesh) : mesh(amesh) { ; }
2014-09-08 21:21:09 +06:00
Ngx_Mesh(shared_ptr<Mesh> amesh = NULL);
2014-01-07 16:42:39 +06:00
void LoadMesh (const string & filename);
2014-02-24 01:31:40 +06:00
void LoadMesh (istream & str);
void SaveMesh (ostream & str) const;
2014-10-19 19:53:57 +06:00
void UpdateTopology ();
2014-02-24 01:31:40 +06:00
void DoArchive (ngstd::Archive & archive);
2013-04-03 02:27:12 +06:00
virtual ~Ngx_Mesh();
2014-01-07 16:42:39 +06:00
bool Valid () { return mesh != NULL; }
2013-04-03 02:27:12 +06:00
int GetDimension() const;
int GetNLevels() const;
int GetNElements (int dim) const;
int GetNNodes (int nt) const;
Ng_Point GetPoint (int nr) const;
template <int DIM>
2017-02-25 21:11:30 +05:00
Ng_Element GetElement (size_t nr) const;
2013-04-03 02:27:12 +06:00
template <int DIM>
2017-02-25 21:11:30 +05:00
int GetElementIndex (size_t nr) const;
2013-04-03 02:27:12 +06:00
/// material/boundary label of region, template argument is co-dimension
template <int DIM>
const string & GetMaterialCD (int region_nr) const;
2013-04-03 02:27:12 +06:00
/// Curved Elements:
/// elnr .. element nr
/// xi..... DIM_EL local coordinates
/// x ..... DIM_SPACE global coordinates
/// dxdxi...DIM_SPACE x DIM_EL Jacobian matrix (row major storage)
template <int DIM_EL, int DIM_SPACE>
2013-04-04 20:35:21 +06:00
void ElementTransformation (int elnr,
const double * xi,
double * x,
double * dxdxi) const;
2013-04-03 02:27:12 +06:00
/// Curved Elements:
/// elnr .. element nr
/// npts .. number of points
/// xi..... DIM_EL local coordinates
/// sxi ... step xi
/// x ..... DIM_SPACE global coordinates
/// dxdxi...DIM_SPACE x DIM_EL Jacobian matrix (row major storage)
2016-04-10 09:36:05 +05:00
template <int DIM_EL, int DIM_SPACE, typename T>
2013-04-04 20:35:21 +06:00
void MultiElementTransformation (int elnr, int npts,
2016-04-10 09:36:05 +05:00
const T * xi, size_t sxi,
T * x, size_t sx,
T * dxdxi, size_t sdxdxi) const;
2013-04-04 20:35:21 +06:00
2013-04-03 02:27:12 +06:00
template <int DIM>
2016-03-22 22:16:04 +05:00
const Ng_Node<DIM> GetNode (int nr) const;
2013-04-03 02:27:12 +06:00
template <int DIM>
2013-04-04 20:35:21 +06:00
int GetNNodes ();
2013-04-03 02:27:12 +06:00
// returns domain numbers of domains next to boundary bnr -> (domin, domout)
// 3D only
// std::pair<int,int> GetBoundaryNeighbouringDomains (int bnr);
void Refine (NG_REFINEMENT_TYPE reftype,
void (*taskmanager)(function<void(int,int)>) = &DummyTaskManager2);
2013-04-03 02:27:12 +06:00
// Find element of point, returns local coordinates
template <int DIM>
2013-04-04 20:35:21 +06:00
int FindElementOfPoint
2013-04-03 02:27:12 +06:00
(double * p, double * lami,
bool build_searchtrees = false,
2014-01-07 16:42:39 +06:00
int * const indices = NULL, int numind = 0) const;
2013-04-03 02:27:12 +06:00
2014-12-03 02:50:38 +05:00
2014-12-03 02:53:29 +05:00
#ifdef PARALLEL
2014-12-03 02:50:38 +05:00
std::tuple<int,int*> GetDistantProcs (int nodetype, int locnum) const;
2014-12-03 02:53:29 +05:00
#endif
2014-12-03 02:50:38 +05:00
2016-05-06 20:58:45 +05:00
shared_ptr<Mesh> GetMesh () const { return mesh; }
2014-09-08 21:21:09 +06:00
shared_ptr<Mesh> SelectMesh () const;
2013-04-03 02:27:12 +06:00
};
DLL_HEADER Ngx_Mesh * LoadMesh (const string & filename);
2014-01-07 16:42:39 +06:00
}
2013-04-03 02:27:12 +06:00
2014-01-07 16:42:39 +06:00
#ifdef HAVE_NETGEN_SOURCES
#include <meshing.hpp>
2013-04-03 02:27:12 +06:00
2014-01-07 16:42:39 +06:00
namespace netgen
{
2016-01-07 17:37:48 +05:00
#ifdef __GNUC__
#define NGX_INLINE __attribute__ ((__always_inline__)) inline
#else
2014-01-07 16:42:39 +06:00
#define NGX_INLINE inline
2016-01-07 17:37:48 +05:00
#endif
2014-01-07 16:42:39 +06:00
#include <nginterface_v2_impl.hpp>
2009-07-20 14:36:36 +06:00
}
2014-01-07 16:42:39 +06:00
#endif
2009-07-20 14:36:36 +06:00
#endif