[Gmsh] Problem with physical groups to label surface in GMSH
Quang Ha
haqthinh at gmail.com
Sun Jun 21 06:24:53 CEST 2020
Hi all,
I'm having some troubles setting the ID for the physical group of the
boundary and then extract them later in Python. Here's my main.geo file:
// Gmsh project created on Sat Jun 20 11:28:19 2020
Mesh.Algorithm = 6;
Mesh.CharacteristicLengthMin = 0.4;
Mesh.CharacteristicLengthMax = 0.4;
SetFactory("OpenCASCADE");
//+
Box(1) = {-2, -2, -2, 4, 4, 4};
// Surface for Box
box_bnd[] = Boundary{Volume{1};};
Physical Surface("boundary", 1) = box_bnd[];
//+
Sphere(3) = {0, 0, 0, 1.0, -Pi/2, Pi/2, 2*Pi};
sphere_bnd[] = Boundary{Volume{3};};
Physical Surface("boundary", 1) += sphere_bnd[];
// Cut
BooleanDifference(5) = {Volume{1}; Delete;}{Volume{3}; Delete;};
Physical Volume("internal", 2) = {5};
Having run this inside Gmsh and generate main.msh, I try to explore this
mesh inside Python and extract out the coordinates on the boundary for
checking. Here is my extract.py:
import matplotlib.pyplot as plt
import gmsh
# Mesh characteristic length
char_length = 0.4
# Some reference dimension
max_coord, min_coord = -2.0, 2.0
# Sphere radius
a = 1.0
# Tolerance allowed in the mesh point
tol = 1e-12
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.open("main.msh".format(char_length))
# all mesh node coordinates
nodeTags, nodeCoords, _ = gmsh.model.mesh.getNodes()
# just the boundary coordinates
bTags, bCoords, = gmsh.model.mesh.getNodesForPhysicalGroup(3, 1)
gmsh.finalize()
which seems to give me empty arrays of bTags and bCoords, i.e.:
In [7]: run extract.py
Warning : Gmsh has aleady been initialized
Info : Reading 'main.msh'...
Info : 33 entities
Info : 1260 nodes
Info : 6524 elements
Info : Done reading 'main.msh'
/usr/local/lib/python3.7/site-packages/numpy/ctypeslib.py:523:
RuntimeWarning: A builtin ctypes object gave a PEP3118 format string
that does not match its itemsize, so a best-guess will be made of the
data type. Newer versions of python may behave correctly.
return array(obj, copy=False)
In [8]: bTags
Out[8]: array([], dtype=uint64)
In [9]: bCoords
Out[9]: array([], dtype=float64)
Any suggestions on where I have made a mistake?
Thanks,
Quang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20200621/dd52b940/attachment.html>
More information about the gmsh
mailing list