围绕一维线创建网格以形成二维对象

计算科学 网格生成 gmsh
2021-12-28 15:25:36

给定以下代码,我如何围绕线执行网格生成,以在 GMSH API 中制作 2D 形式?ExtrudeMirror功能?我想在线条周围添加一个网格,例如,向左 1 厘米,向右 1 厘米。

#include <gmsh.h>

int main(int argc, char **argv)
{

  gmsh::option::setNumber("General.Terminal", 1);


  gmsh::model::add("t1");


  double lc = 1e-2;
  gmsh::model::geo::addPoint(0, 0, 0, lc, 1);
  gmsh::model::geo::addPoint(.1, 0,  0, lc, 2);

  gmsh::model::geo::addLine(1, 2, 1);

  gmsh::model::geo::synchronize();

  gmsh::model::mesh::generate(2);

  gmsh::write("t1.msh");

  gmsh::finalize();
  return 0;
}
1个回答

你有几个选择。

选项 A. 选择gmsh::model::geo::extrude

给出API调用规范,如下

GMSH_API void extrude(const gmsh::vectorpair & dimTags,
                        const double dx,
                        const double dy,
                        const double dz,
                        gmsh::vectorpair & outDimTags,
                        const std::vector<int> & numElements = std::vector<int>(),
                        const std::vector<double> & heights = std::vector<double>(),
                        const bool recombine = false);

因此,在您的情况下,如果您绘制的不是计划表面的中心线,而是左/右边界,则会容易得多。

std::vector<std::pair<int, int>> line; // this will store a pair {dimension, line_id}
line.first = 1; // line is a 1-D entity
line.second = 1; // and as per your code the line to extrude has ID1
std::vector<std::pair<int, int>> surface; //this will store the result of the extrusion {dimension, surface_id}
gmsh::model::geo::extrude(line, 0, 0.02, 0, surface);

上面的代码假设lineID 为 1 的您是边框,而不是沿 X 轴的中心线,并且您打算沿 Y 轴有一个宽度。

第二个 GMSH 教程(在 GEO 和C++ API版本中可用)在这里很有帮助。

选项 B. 自己绘制曲面

有时,如果足够简单,自己绘制表面而不使用任何挤压会更容易。我认为您的案例的代码相对简单。

选项 C. 使用 OpenCASCADE 工厂

示例:使用 C++ API 的教程 16

很有用,因为Rectangles在带有 OpenCASCADE 内核的 GMSH 中可用