Netgen mesh library : nglib

eryar@163.com

摘要Abstract:本文主是对Netgen的库nglib的用法进行介绍。主要参考资料是Netgen用户指南。最后给出一个具体程序实例。

关键字Key Words:Netgen, nglib, Mesh

一、引言 Introduction

Netgen网格生成库nglib是以C++源程序形式提供,可以编译为Unix/Linux或Windows上的库文件。程序开发使用的接口文件是nglib.h。

二、头文件 The Header File

接口文件中包含了一些类型定义和函数调用,所有的Netgen类型和函数都带有前缀Ng。类型和函数首字母大写,所有常量都是大写。

三、类型和常量 Types and Constants

// ** Constants used within Netgen *********************
/// Maximum allowed number of nodes per volume element
#define NG_VOLUME_ELEMENT_MAXPOINTS 10 /// Maximum allowed number of nodes per surface element
#define NG_SURFACE_ELEMENT_MAXPOINTS 8 // *** Data-types for accessing Netgen functionality ***
/// Data type for NETGEN mesh
typedef void * Ng_Mesh; /// Data type for NETGEN CSG geometry
typedef void * Ng_CSG_Geometry; /// Data type for NETGEN 2D geometry
typedef void * Ng_Geometry_2D; /// Data type for NETGEN STL geometry
typedef void * Ng_STL_Geometry; // *** Special Enum types used within Netgen ***********
/// Currently implemented surface element types
enum Ng_Surface_Element_Type
{ NG_TRIG = , NG_QUAD = , NG_TRIG6 = , NG_QUAD6 = , NG_QUAD8 = }; /// Currently implemented volume element types
enum Ng_Volume_Element_Type
{ NG_TET = , NG_PYRAMID = , NG_PRISM = , NG_TET10 = }; /// Values returned by Netgen functions
enum Ng_Result
{
NG_ERROR = -,
NG_OK = ,
NG_SURFACE_INPUT_ERROR = ,
NG_VOLUME_FAILURE = ,
NG_STL_INPUT_ERROR = ,
NG_SURFACE_FAILURE = ,
NG_FILE_NOT_FOUND =
}; // *** Classes required for use within Netgen **********
/// Netgen Meshing Parameters class
class Ng_Meshing_Parameters
{
public:
int uselocalh; //!< Switch to enable / disable usage of local mesh size modifiers
double maxh; //!< Maximum global mesh size allowed
double minh; //!< Minimum global mesh size allowed double fineness; //!< Mesh density: 0...1 (0 => coarse; 1 => fine)
double grading; //!< Mesh grading: 0...1 (0 => uniform mesh; 1 => aggressive local grading)
double elementsperedge; //!< Number of elements to generate per edge of the geometry
double elementspercurve; //!< Elements to generate per curvature radius

Ng_Mesh表示Netgen网格的数据结构。Ng_STL_Geometry表示STL几何。可以通过Ng_Meshing_Parameters来指定生成网格时的参数。Netgen函数的返回值类型是Ng_Result。

四、初始化 Initialization

分别调用如下两个函数对netgen初始化和析构:

/*! \brief Initialise the Netgen library and prepare for use
*/
DLL_HEADER void Ng_Init ();
/*! \brief Exit the Netgen meshing kernel in a clean manner
*/
DLL_HEADER void Ng_Exit ();

五、网格的访问 Mesh access

Netgen网格可以通过如下函数来处理。一个网格包含nodes, surface elements和volume elements。都是从1开始计数的。

// Generates new mesh structure
Ng_Mesh * Ng_NewMesh ();
void Ng_DeleteMesh (Ng_Mesh * mesh);
// feeds points, surface elements and volume elements to the mesh
void Ng_AddPoint (Ng_Mesh * mesh, double * x);
void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, int * pi);
void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, int * pi);
// ask for number of points, surface and volume elements
int Ng_GetNP (Ng_Mesh * mesh);
int Ng_GetNSE (Ng_Mesh * mesh);
int Ng_GetNE (Ng_Mesh * mesh);
// return point coordinates
void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x);
// return surface and volume element in pi
Ng_Surface_Element_Type
Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi);
Ng_Volume_Element_Type
Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi);

更多信息请参考其头文件nglib.h。

在生成网格时,用户可以指定网格大小及一些约束。函数Ng_GenerateVolumeMesh从曲面生成网格。

/*! \brief Apply a global restriction on mesh element size
*/
DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h); /*! \brief Locally restrict the mesh element size at the given point
*/
DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h); /*! \brief Locally restrict the mesh element size within a specified box
*/
DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h);
/*! \brief Create a 3D Volume Mesh given a Surface Mesh
*/
DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp);

六、STL几何 STL Geometry

STL几何数据可以从STL文件(ASCII或二进制)读取,也可以由一个个的三角形组装而成。

// loads geometry from STL file
DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary = ); // generate new STL Geometry
DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry (); // fills STL Geometry
// positive orientation
// normal vector may be null-pointer
DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom,
double * p1, double * p2, double * p3,
double * nv = NULL); // add (optional) edges :
DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom,
double * p1, double * p2); // after adding triangles (and edges) initialize
DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom); // automatically generates edges:
DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
Ng_Mesh* mesh,
Ng_Meshing_Parameters * mp); // generates mesh, empty mesh must be already created.
DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
Ng_Mesh * mesh,
Ng_Meshing_Parameters * mp);

七、示例程序 Example Code

在Netgen的安装目录下的nglib文件夹中有两个示例程序ng_vol.cpp和ng_stl.cpp。其中ng_vol.cpp程序开始时从cube.surf文件读入点坐标和曲面的三角形,生成的volumne mesh输出到文件:cuve.vol。经过测试,程序可以运行,修改过的代码如下所示:

#include <iostream>
#include <fstream> namespace nglib {
#include <nglib.h>
} #pragma comment(lib, "nglib.lib") int main(int argc, char* argv[])
{
std::cout << "Netgen Testing..." << std::endl; int i = ;
int np = ;
int nse = ;
int ne = ;
int trig[] = {};
int tet[] = {}; double point[] = {0.0}; std::string strMeshFile = (argc > )? argv[]: "cube.surf";
std::ifstream meshFile(strMeshFile.c_str()); // initialize the Netgen library.
nglib::Ng_Init(); // Generate new mesh structure.
nglib::Ng_Mesh* mesh = nglib::Ng_NewMesh(); // Read surface mesh from file.
// feed points to the mesh.
meshFile >> np;
std::cout << "Reading " << np << " points..." << std::endl;
for (int i = ; i < np; ++i)
{
meshFile >> point[] >> point[] >> point[];
nglib::Ng_AddPoint(mesh, point);
}
std::cout << "done." << std::endl; // feed surface elements to the mesh.
meshFile >> nse;
std::cout << "Reading " << nse << " faces..." << std::endl;
for (int i = ; i < nse; ++i)
{
meshFile >> trig[] >> trig[] >> trig[];
nglib::Ng_AddSurfaceElement(mesh, nglib::NG_TRIG, trig);
}
std::cout << "done." << std::endl; // generate volume mesh.
nglib::Ng_Meshing_Parameters mp;
mp.maxh = 1e6;
mp.fineness = ;
mp.second_order = ; std::cout << "start meshing..." << std::endl;
nglib::Ng_GenerateVolumeMesh(mesh, &mp);
std::cout << "meshing done." << std::endl; // volume mesh output.
np = nglib::Ng_GetNP(mesh);
std::cout << "Points: " << np << std::endl;
for (int i = ; i <= np; ++i)
{
nglib::Ng_GetPoint(mesh, i, point);
std::cout << i << ": " << point[] << ", " << point[] << ", " << point[] << std::endl;
} ne = nglib::Ng_GetNE(mesh);
std::cout << "Elements: " << ne << std::endl;
for (int i = ; i <= ne; ++i)
{
nglib::Ng_GetVolumeElement(mesh, i, tet);
std::cout << i << ": " << tet[] << ", " << tet[] << ", " << tet[] << ", " << tet[] << std::endl;
} // Save mesh.
nglib::Ng_SaveMesh(mesh, "test.vol"); // deconstruct Netgen library.
nglib::Ng_Exit(); return ;
}

Netgen mesh library : nglib的更多相关文章

  1. Hello Netgen

    Hello Netgen eryar@163.com 摘要Abstract:本文主要介绍如何对下载的Netgen源码进行编译生成Netgen程序和程序开发所需要的库nglib. 关键字Key Word ...

  2. nRF5 SDK for Mesh(四) 源码编译

    官方文档教程编译源码: http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk%2Fdita%2Fs ...

  3. CG&CAD resource

    Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...

  4. software collection

    software software Table of Contents 1. Privacy 2. GFW 2.1. google search 2.2. 修改 DNS 服务器 2.2.1. 修改ip ...

  5. Computer Graphics Research Software

    Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...

  6. EasyMesh - A Two-Dimensional Quality Mesh Generator

    EasyMesh - A Two-Dimensional Quality Mesh Generator eryar@163.com Abstract. EasyMesh is developed by ...

  7. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  8. Mesh Algorithm in OpenCascade

    Mesh Algorithm in OpenCascade eryar@163.com Abstract. Rendering a generic surface is a two steps pro ...

  9. What’s a service mesh? And why do I need one?

    https://buoyant.io/2017/04/25/whats-a-service-mesh-and-why-do-i-need-one/ Update 2018-02-06: Since t ...

随机推荐

  1. PowerPoint

    工具/原料 PowerPoint 2007 百度经验:jingyan.baidu.com 一.PowerPoint2007基础知识 1 桌面快捷方式:也可以“开始”菜单→程序→Microsoft Of ...

  2. 原创 Datareader 导出为csv文件方法

    DataReader 是游标只读数据, 如果是大数据导出,用Datatable 将耗费巨大内存资源.因为Datatable 其实就是内存中的一个数据表 代码如下 /// <summary> ...

  3. 【整理】--【GPIO】OK6410

    S3C6410的GPIO引脚相对来说比较多,而且大部分引脚都具有多重复用功能,如何在linux上用最简单的方式来控制GPIO这需要我们好好研究一下底层的代码了,其实方法有很多种,鉴于在操作系统端控制G ...

  4. NancyFx开发-Razor视图using外部Dll解决方案

    问题:NancyFx框架 Razor视图无法using 其他项目DLL   解决方案: Nancyfx框架Razor需要在web.config 中声明要引入的命名空间(包括system这些)   &l ...

  5. 将EnyimMemcached从.NET Core RC1升级至RC2

    .NET Core RC1时project.json中的配置如下: { "version": "3.2.4", "summary": &qu ...

  6. Syncfusion 复选框 ComboBoxAdv

    XAML: <syncfusion:GridTemplateColumn.EditTemplate> <DataTemplate DataType="viewModel:C ...

  7. [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格Meshes

    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格Meshes 本篇分享一下第5个已完工的视频,即<beginner Graphics – ...

  8. HttpContext.Current:异步模式下的疑似陷阱之源

    最近园子里首页有好几篇文章都是讲异步编程的,尤其是几篇讲博客园自身的异步化建设的文章,看了以后很有收获. 闲暇之余再重新查查资料温故知新学习一遍,重新认识了SynchronizationContext ...

  9. 据说每个大牛、小牛都应该有自己的库——JavaScript原生对象拓展

    在据说每个大牛.小牛都应该有自己的库——框架篇中我扬言要做个小牛,没想到一天没更新,小伙儿伴们就戏谑的问我,油哥是不是要太监了?其实事情是这个样子的,这不是太监的节奏,一是,关于写个自己的库的想法由来 ...

  10. Lucene系列-分析器

    分析器介绍 搜索的基础是对文本信息进行分析,Lucene的分析工具在org.apache.lucene.analysis包中.分析器负责对文本进行分词.语言处理得到词条,建索引和搜索的时候都需要用到分 ...