在前面两篇文章1、2中我们分别介绍了图形化界面和内置解析器geo脚本的使用方式。今天来介绍下Gmsh的第三种使用方式:使用Gmsh API将其集成到其他软件中。
意义
将网格生成器与求解器等软件对接形成整体框架。
获取Gmsh API几种方式
- 通过官网下载SDK http://www.gmsh.info/bin/Windows/gmsh-git-Windows64-sdk.zip
- pip install --upgrade gmsh (Python)
- 在编译时加上 cmake -DENABLE_BUILD_DYNAMIC=1 …选项
使用
使用Gmsh API时只需引入导入其对应的库即可,下面以c++版本为例。代码是官方教程的x1.cpp基础上稍作修改,在一些需关注的部分添加了中文注释。在编译时需加上-lgmsh选项以包括动态链接库。
// -----------------------------------------------------------------------------
//
// Gmsh C++ extended tutorial 1
//
// Geometry and mesh data
//
// -----------------------------------------------------------------------------
// The C++ API allows to do much more than what can be done in .geo files. These
// additional features are introduced gradually in the extended tutorials,
// starting with `x1.cpp'.
// In this first extended tutorial, we start by using the API to access basic
// geometrical and mesh data.
#include <iostream>
#include <gmsh.h>
int main(int argc, char **argv)
{
// 判断输入参数数量是否符合要求。
if(argc < 2) {
std::cout << "Usage: " << argv[0] << " file" << std::endl;
return 0;
}
std::cout<<"modify by djm"<<std::endl;
// 在使用Gmsh API之前必须调用的初试函数
gmsh::initialize();
// 命令行输出相关信息
gmsh::option::setNumber("General.Terminal", 1);
// You can run this tutorial on any file that Gmsh can read, e.g. a mesh file
// in the MSH format: `t1.exe file.msh'
// 使用open方法打开参数1的文件
gmsh::open(argv[1]);
// Print the model name and dimension:
std::string name;
gmsh::model::

本文介绍GmshAPI的使用方法,通过示例代码展示如何集成Gmsh到其他软件中,实现网格生成与数据操作。文章涵盖GmshAPI的获取、初始化及网格数据的读取与打印。
最低0.47元/天 解锁文章
1581

被折叠的 条评论
为什么被折叠?



