[Gmsh] Constrained Delaunay. Generating mesh using line boundaries
Christophe Geuzaine
cgeuzaine at uliege.be
Mon Nov 5 22:27:30 CET 2018
Here's an example:
import gmsh
import sys
import math
gmsh.initialize(sys.argv)
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("2d surface mesh with purely discrete boundary");
# create a discrete curve with N nodes and N line elements
gmsh.model.addDiscreteEntity(1, 100)
N = 50
dt = 2*math.pi/N
pts = [[math.cos(i * dt), math.sin(i * dt), 0] for i in range(N)]
flat_pts = [item for sublist in pts for item in sublist]
gmsh.model.mesh.setNodes(1, 100, range(1, N+1), flat_pts)
n = [item for sublist in [[i, i+1] for i in range(1, N+1)] for item in sublist]
n[-1] = 1
gmsh.model.mesh.setElements(1, 100, [1], [range(1, N+1)], [n])
# create a plane surface from the discrete curve
gmsh.model.geo.addCurveLoop([100], 101)
gmsh.model.geo.addPlaneSurface([101], 102)
gmsh.model.geo.synchronize()
# mesh the surface
gmsh.model.mesh.generate(2)
gmsh.fltk.run()
gmsh.finalize()
> On 5 Nov 2018, at 18:46, Oleg Kmechak <ofcrashbash at gmail.com> wrote:
>
> Dear All,
>
> I am trying to generate mesh using api functions setElements and setNodes. But encountering few problems.
>
> Mesh should be generated on square region inside of each are boundary lines(this structures looks similar to binary tree or simple biological tree with root bounded to square boundary).
>
> Proof of concept I have done using geo module:
>
> gmsh::initialize();
> model::add("square");
> geo::addPoint(0, 0, 0, 0.1, 1);
> geo::addPoint(0.5, 0, 0, 0.1, 2);
> geo::addPoint(1, 0, 0, 0.1, 3);
> geo::addPoint(1, 1, 0, 0.1, 4);
> geo::addPoint(0, 1, 0, 0.1, 5);
> geo::addPoint(0.5, 0.2, 0, 0.1, 6);
> geo::addLine(1, 2, 1);
> geo::addLine(2, 3, 2);
> geo::addLine(3, 4, 3);
> geo::addLine(4, 5, 4);
> geo::addLine(5, 1, 5);
> geo::addLine(2, 6, 6);
> geo::addLine(6, 2, 7);
> geo::addCurveLoop({1, 2, 3, 4, 5, 6, 7}, 1);
> geo::addPlaneSurface({1}, 6);
> geo::synchronize();
> model::mesh::generate(2);
>
> pay attention on these two lines its workaround to generate mesh properly
>
> geo::addLine(2, 6, 6);
> geo::addLine(6, 2, 7);
>
> For me is more convenient to use setElements and setNodes, there is even nice example discrete.cpp which creates "by hand" two mesh triangles.
> I also tried to create(adopting the discrete.cpp sample) "by hand" region using line elements.
> but it fails saying next:
>
> Error : Wrong type of element for Surface 1
>
> I used next code:
> model::addDiscreteEntity(2, 1);
>
> msh::setNodes(2, 1,
> {1, 2, 3, 4},
> {0., 0., 0., //node 1
> 1., 0., 0., //node 2
> 1., 1., 0., //node 3
> 0., 1., 0.}); //node 4
>
> msh::setElements(2, 1,
> {1},//line element
> {{1,2,3,4}},//line tags
> {{1,2,2,3,3,4,4,1}}); //lines
> model::mesh::generate(2);
>
>
> Also I tried instead of line elements(1) to use point elements(15), error was the same.
> How to generate such mesh without using geo module?
>
> With regards,
> Oleg Kmechak
>
>
>
>
>
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh
—
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine
Free software: http://gmsh.info | http://getdp.info | http://onelab.info
More information about the gmsh
mailing list