0
$\begingroup$

Given the following code, how can I perform a mesh generation around the line, to make a 2D form in GMSH API? Extrude or Mirror functions? I want to add a mesh around the line, for example, 1cm to left and 1cm to right.

#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;
}
$\endgroup$
1
$\begingroup$

You have several options.

Option A. Go for the gmsh::model::geo::extrude

The API call specification is given, as follows:

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);

therefore, in your case, it is much easier if you are drawing not a central line of the planned surface, but a left/right border.

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);

The code above assumes that your line with ID 1 is a border, not a center line going along the X-axis, and you intend to have a width along the Y-axis.

The second GMSH tutorial (available in GEO and C++ API versions) is helpful here.

Option B. Draw the surface yourself

Sometimes, it is just easier to draw the surface yourself without using any extrusions if it is simple enough. I think the code for your case is relatively straightforward.

Option C. Use OpenCASCADE factory.

Sample: tutorial 16 using C++ API.

Useful, since Rectangles are available in GMSH with OpenCASCADE kernel.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.