Netgen mesh library : nglib
Netgen mesh library : nglib
摘要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 ;
}
![]()
PDF Version: Netgen mesh library : nglib
Netgen mesh library : nglib的更多相关文章
- Hello Netgen
Hello Netgen eryar@163.com 摘要Abstract:本文主要介绍如何对下载的Netgen源码进行编译生成Netgen程序和程序开发所需要的库nglib. 关键字Key Word ...
- nRF5 SDK for Mesh(四) 源码编译
官方文档教程编译源码: http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk%2Fdita%2Fs ...
- CG&CAD resource
Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...
- software collection
software software Table of Contents 1. Privacy 2. GFW 2.1. google search 2.2. 修改 DNS 服务器 2.2.1. 修改ip ...
- Computer Graphics Research Software
Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...
- EasyMesh - A Two-Dimensional Quality Mesh Generator
EasyMesh - A Two-Dimensional Quality Mesh Generator eryar@163.com Abstract. EasyMesh is developed by ...
- Mesh Data Structure in OpenCascade
Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...
- Mesh Algorithm in OpenCascade
Mesh Algorithm in OpenCascade eryar@163.com Abstract. Rendering a generic surface is a two steps pro ...
- 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 ...
随机推荐
- 解决VS2010子目录中的.cpp文件引用上一级目录的stdafx.h找不到定义的问题
Source目录 |-- stdafx.h |--Util目录 |--Util.h |--Util.cpp 现在的发现Util.cpp各种变量的定义全是红色波浪线,找不到定义,但是却能够编译过 问题就 ...
- Python学习之路-Day4
1.函数 函数定义 def func(aa): def:表示函数的关键字 func:函数名,即函数的名称,可根据函数名调用函数 print('.....') prin ...
- Software Project Management hw1
I just want to say something about my java project that I did last year. Our task is to finish a lin ...
- 第56讲:Scala中Self Types实战详解
今天学习了self type的内容,让我们来看下代码 package scala.learn class Self{ self => val tmp = "Scala" ...
- 让你的Android程序更省电
app主要耗电的原因如下: 1 cpu频繁的运转 -----控制线程 2 大数据量的传输----- 数据压缩传输 3 不停的在网络间切换------------判断网络状体 4 人开发的程序后台都 ...
- Smack 3.3.1 发布,Java 的 XMPP 开发包
Smack 3.3.1 发布了,这是一个小更新版本,主要更新包括: [SMACK-441] - Memory leak in KeepAliveManager [SMACK-447] - Compre ...
- 微信公共平台开发-(.net实现)3--发送文本消息
最近,项目这边比较忙,没来得及续写,哎,先吐吐槽吧,在这个周六还得来上班,以后每个周六多要上,一天的滋味真有点受不鸟呀.还不习惯ing... 嗯,别的不说了现在开始接着上次http://www.cnb ...
- nodejs安装/运行脚本
本文主要介绍nodejs在windows下安装及运行脚本. 安装nodejs 先从nodejs官网:http://nodejs.org/下载对应的系统的安装包,比如用于64位系统的最新0.10.21的 ...
- MySQL中VARCHAR与CHAR格式数据的区别
区别 CHAR与VARCHAR类型类似,但它们保存和检索的方式不同.CHAR有固定的长度,而VARCHAR属于可变长的字符类型.它们最大长度和是否尾部空格被保留等方面也不同.在存储和检索过程中不进行大 ...
- mongodb(mongoose-redis-cache)
在传统的项目中,我们经常会用到缓存来优化数据库的读取,比如java中,我们利用spring的AOP能力,在读写数据库前增加对缓存的操作. 在node与mongodb的项目中也仍然会存在类似问题,本文参 ...