1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
#ifndef NGINTERFACE_V2
#define NGINTERFACE_V2
/**************************************************************************/
/* File: nginterface_v2.hpp */
/* Author: Joachim Schoeberl */
/* Date: May 09 */
/**************************************************************************/
#include "mydefs.hpp"
#include <core/mpi_wrapper.hpp>
/*
C++ interface to Netgen
*/
#ifndef NGINTERFACE
// implemented element types:
enum NG_ELEMENT_TYPE {
NG_PNT = 0,
NG_SEGM = 1, NG_SEGM3 = 2,
NG_TRIG = 10, NG_QUAD=11, NG_TRIG6 = 12, NG_QUAD6 = 13, NG_QUAD8 = 14,
NG_TET = 20, NG_TET10 = 21,
NG_PYRAMID = 22, NG_PRISM = 23, NG_PRISM12 = 24, NG_PRISM15 = 27, NG_PYRAMID13 = 28,
NG_HEX = 25, NG_HEX20 = 26, NG_HEX7 = 29
};
enum NG_REFINEMENT_TYPE { NG_REFINE_H = 0, NG_REFINE_P = 1, NG_REFINE_HP = 2 };
#endif
// #ifndef PARALLEL
// typedef int MPI_Comm;
// #endif
namespace netgen
{
using namespace std;
using namespace ngcore;
static constexpr int POINTINDEX_BASE = 1;
typedef int T_EDGE2;
typedef int T_FACE2;
template <typename T>
class Ng_Buffer
{
size_t s;
T * data;
public:
Ng_Buffer (size_t as, T * adata)
: s(as), data(adata) { ; }
Ng_Buffer (Ng_Buffer && buffer)
: s(buffer.Size()), data(buffer.Release()) { ; }
~Ng_Buffer () { delete [] data; }
size_t Size() const { return s; }
T * Release() { T * hd = data; data = nullptr; return hd; }
};
template <typename T, int S>
class Ng_BufferMS
{
size_t s;
T data[S];
public:
Ng_BufferMS (size_t as) : s(as) { ; }
size_t Size() const { return s; }
T & operator[] (size_t i) { return data[i]; }
T operator[] (size_t i) const { return data[i]; }
};
class Ng_Element
{
class Ng_Points
{
public:
size_t num;
const int * ptr;
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
};
class Ng_Vertices
{
public:
size_t num;
const int * ptr;
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
};
class Ng_Facets
{
public:
size_t num;
int base;
const int * ptr;
size_t Size() const { return num; }
int operator[] (size_t i) const { return ptr[i]-base; }
};
public:
NG_ELEMENT_TYPE type;
int index; // material / boundary condition
string_view mat; // material / boundary label
NG_ELEMENT_TYPE GetType() const { return type; }
int GetIndex() const { return index-1; }
Ng_Points points; // all points
Ng_Vertices vertices;
FlatArray<T_EDGE2> edges;
FlatArray<T_FACE2> faces;
Ng_Facets facets;
bool is_curved;
int8_t newest_vertex;
};
class Ng_Point
{
double * pt;
public:
Ng_Point (double * apt) : pt(apt) { ; }
double operator[] (size_t i)
{ return pt[i]; }
operator const double * () { return pt; }
};
template <int DIM> class Ng_Node;
template <>
class Ng_Node<0>
{
class Ng_Elements
{
public:
size_t ne;
const int * ptr;
size_t Size() const { return ne; }
int operator[] (size_t i) const { return ptr[i]; }
};
public:
Ng_Elements elements;
Ng_Elements bnd_elements;
};
template <>
class Ng_Node<1>
{
class Ng_Vertices
{
public:
const int * ptr;
size_t Size() const { return 2; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
};
public:
Ng_Vertices vertices;
};
template <>
class Ng_Node<2>
{
class Ng_Vertices
{
public:
size_t nv;
const int * ptr;
size_t Size() const { return nv; }
int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; }
};
/*
class Ng_Edges
{
public:
size_t ned;
const int * ptr;
size_t Size() const { return ned; }
int operator[] (size_t i) const { return ptr[i]-1; }
};
*/
public:
Ng_Vertices vertices;
// Ng_Edges edges;
int surface_el; // -1 if face not on surface
};
class Mesh;
inline void DummyTaskManager2 (function<void(int,int)> func)
{ func(0,1); }
inline void DummyTracer2 (string, bool) { ; }
class DLL_HEADER Ngx_Mesh
{
private:
shared_ptr<Mesh> mesh;
public:
// Ngx_Mesh () { ; }
// Ngx_Mesh(class Mesh * amesh) : mesh(amesh) { ; }
/** reuse a netgen-mesh **/
Ngx_Mesh (shared_ptr<Mesh> amesh);
/** load a new mesh **/
Ngx_Mesh (string filename, NgMPI_Comm acomm = NgMPI_Comm{});
void LoadMesh (const string & filename, NgMPI_Comm comm = NgMPI_Comm{});
void LoadMesh (istream & str, NgMPI_Comm comm = NgMPI_Comm{});
void SaveMesh (ostream & str) const;
void UpdateTopology ();
void DoArchive (Archive & archive);
const NgMPI_Comm & GetCommunicator() const;
virtual ~Ngx_Mesh();
bool Valid () const { return mesh != NULL; }
int GetDimension() const;
int GetNLevels() const;
size_t GetNVLevel (int level) const;
int GetNElements (int dim) const;
int GetNNodes (int nt) const;
Ng_Point GetPoint (int nr) const;
template <int DIM>
Ng_Element GetElement (size_t nr) const;
template <int DIM>
int GetElementIndex (size_t nr) const;
/// material/boundary label of region, template argument is co-dimension
template <int DIM>
string_view GetMaterialCD (int region_nr) const;
/// 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>
void ElementTransformation (int elnr,
const double * xi,
double * x,
double * dxdxi) const;
/// 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)
template <int DIM_EL, int DIM_SPACE, typename T>
void MultiElementTransformation (int elnr, int npts,
const T * xi, size_t sxi,
T * x, size_t sx,
T * dxdxi, size_t sdxdxi) const;
template <int DIM>
const Ng_Node<DIM> GetNode (int nr) const;
Ng_BufferMS<int,4> GetFaceEdges (int fnr) const;
template <int DIM>
int GetNNodes ();
// returns domain numbers of domains next to boundary bnr -> (domin, domout)
// 3D only
// std::pair<int,int> GetBoundaryNeighbouringDomains (int bnr);
template <int DIM>
void SetRefinementFlag (size_t elnr, bool flag);
void Curve (int order);
int GetCurveOrder ();
void EnableTable (string name, bool set);
void Refine (NG_REFINEMENT_TYPE reftype, bool onlyonce,
void (*taskmanager)(function<void(int,int)>) = &DummyTaskManager2,
void (*tracer)(string, bool) = &DummyTracer2);
int GetHPElementLevel (int ei, int dir) const;
void GetParentNodes (int ni, int * parents) const;
int GetParentElement (int ei) const;
int GetParentSElement (int ei) const;
bool HasParentEdges() const;
std::tuple<int, std::array<int,3>> GetParentEdges (int enr) const;
std::tuple<int, std::array<int,4>> GetParentFaces (int fnr) const;
int GetNIdentifications() const;
int GetIdentificationType(int idnr) const;
Ng_Buffer<int[2]> GetPeriodicVertices(int idnr) const;
// Find element of point, returns local coordinates
template <int DIM>
int FindElementOfPoint
(double * p, double * lami,
bool build_searchtrees = false,
int * const indices = NULL, int numind = 0, double tol = 1e-4) const;
// for MPI-parallel
FlatArray<int> GetDistantProcs (int nodetype, int locnum) const;
size_t GetGlobalVertexNum (int locnum) const;
shared_ptr<Mesh> GetMesh () const { return mesh; }
shared_ptr<Mesh> SelectMesh () const;
inline auto GetTimeStamp() const;
// also added from nginterface.h, still 1-based, need redesign
void HPRefinement (int levels, double parameter = 0.125,
bool setorders = true,bool ref_level = false);
void SplitAlfeld ();
size_t GetNP() const;
int GetSurfaceElementSurfaceNumber (size_t ei) const;
int GetSurfaceElementFDNumber (size_t ei) const;
int GetElementOrder (int enr) const;
void GetElementOrders (int enr, int * ox, int * oy, int * oz) const;
void SetElementOrder (int enr, int order);
void SetElementOrders (int enr, int ox, int oy, int oz);
int GetSurfaceElementOrder (int enr) const;
void GetSurfaceElementOrders (int enr, int * ox, int * oy) const;
void SetSurfaceElementOrder (int enr, int order);
void SetSurfaceElementOrders (int enr, int ox, int oy);
int GetClusterRepVertex (int vi) const;
int GetClusterRepEdge (int edi) const;
int GetClusterRepFace (int fai) const;
int GetClusterRepElement (int eli) const;
// just copied from nginterface, now 0-based
int GetElement_Faces (int elnr, int * faces, int * orient = 0) const;
int GetSurfaceElement_Face (int selnr, int * orient = 0) const;
};
DLL_HEADER Ngx_Mesh * LoadMesh (const string & filename);
}
#ifdef HAVE_NETGEN_SOURCES
#include <meshing.hpp>
namespace netgen
{
#ifdef __GNUC__
#define NGX_INLINE __attribute__ ((__always_inline__)) inline
#else
#define NGX_INLINE inline
#endif
#include <nginterface_v2_impl.hpp>
}
#endif
#endif
|