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 ...
随机推荐
-
Unity3D上可以发布到IOS使用的SQLite数据库
地址:https://github.com/codecoding/SQLite4Unity3d Unity5.1.1f 发布,在IOS 8.3上亲测可用,Android好像有点问题. 也可用参考下这个 ...
-
配置php.ini实现PHP文件上传功能
本文介绍了如何配置php.ini实现PHP文件上传功能.其中涉及到php.ini配置文件中的upload_tmp_dir.upload_max_filesize.post_max_size等选项,这些 ...
-
liunx 多个tomcat 产生的新问题
今天在给 tomcat 版本7.0.57升级到7.0.72的时候,碰到一个奇怪的问题,启动 tomcat7.0.72 的时候报错,找不到tomcat7.0.57/bin/setclasspath.sh ...
-
JSON 语法规则详解
JSON 的语法规则十分简单,无论用何种方法总结都只有数条而已,它参考了 C 语言家族的一些习惯,学习起来并不会感到陌生. 回顾JSON 的五点语法 1)- 数组(Array)用方括号("[ ...
-
IOS苹果购买PHP服务器端验证(订阅购买和一次性购买通用)
// 正式环境验证地址 $ios_verify_url = 'https://buy.itunes.apple.com/verifyReceipt'; // 测试环境验证地址 $ios_sandbox ...
-
加速 lucene 的搜索速度 ImproveSearchingSpeed
* Be sure you really need to speed things up. Many of the ideas here are simple to try, but others w ...
-
OpenCV探索之路(二十三):特征检测和特征匹配方法汇总
一幅图像中总存在着其独特的像素点,这些点我们可以认为就是这幅图像的特征,成为特征点.计算机视觉领域中的很重要的图像特征匹配就是一特征点为基础而进行的,所以,如何定义和找出一幅图像中的特征点就非常重要. ...
-
玩转Spring MVC(三)----spring基本配置文件
这篇文章总结一下spring mvc的基本配置,首先贴一张我的项目的目录截图,有一些多余的文件,大家不必在意: 用到的一些jar包在这:<a>http://download.csdn.ne ...
-
hibernate-第二章-关系映射
一,持久化类 持久化类就是之前写过的实体类 持久化类必须符合javabean规范,属性必须有set和get方法; 持久化类的属性类型可以是8种基本类型或对应的包装类,通常定义包装类型,因为包装类型可以 ...
-
C语言 goto语句
/* goto语句 */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* goto语句也 ...