【网格生成】Gmsh快速入门教程 --3.Gmsh API

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

在前面两篇文章12中我们分别介绍了图形化界面和内置解析器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::
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值