[Gmsh] How can I classify faces of an imported OPEN CASCADE geometry by color?

Wesley Ranger metorm at outlook.com
Mon Dec 9 04:29:12 CET 2019


Thank you, Christophe. I had implemented the function this weekend. My
python code is like below:

```python

ens = gmsh.model.getEntities()
G_INIT_Tags = []
G_SYM_Tags = []
G_HIL_Tags = []
VOLUME_G_Tags = []
for crtEntity in ens:
    crtDim = crtEntity[0]
    crtTag = crtEntity[1]
    crtColor = gmsh.model.getColor(crtDim, crtTag)
    if crtDim == 2:
        physicalType =
AutoMesh.PhysicalType.fromSurfaceColor(crtColor[0], crtColor[1],
crtColor[2])
        if physicalType == AutoMesh.PhysicalType.G_INIT:
            G_INIT_Tags.append(crtTag)
        elif physicalType == AutoMesh.PhysicalType.G_SYM:
            G_SYM_Tags.append(crtTag)
        elif physicalType == AutoMesh.PhysicalType.G_HIL:
            G_HIL_Tags.append(crtTag)

if len(G_INIT_Tags) > 0:
    G_INIT_GroupTag = gmsh.model.addPhysicalGroup(2, G_INIT_Tags)
    gmsh.model.setPhysicalName(2, G_INIT_GroupTag,
str(AutoMesh.PhysicalType.G_INIT.value))
logging.debug("%d initial burn faces in model.", len(G_INIT_Tags))

if len(G_SYM_Tags) > 0:
    G_SYM_GroupTag = gmsh.model.addPhysicalGroup(2, G_SYM_Tags)
    gmsh.model.setPhysicalName(2, G_SYM_GroupTag,
str(AutoMesh.PhysicalType.G_SYM.value))
logging.debug("%d initial grain symmetry faces in model.", len(G_SYM_Tags))

if len(G_HIL_Tags) > 0:
    G_HIL_GroupTag = gmsh.model.addPhysicalGroup(2, G_HIL_Tags)
    gmsh.model.setPhysicalName(2, G_HIL_GroupTag,
str(AutoMesh.PhysicalType.G_HIL.value))
logging.debug("%d initial grain-HIL faces in model.", len(G_HIL_Tags))
```

BTW, if you want to read color information from a *.stp file exported
via Creo, you have to set "step_export_format" option to "ap214_is"
and make sure to check the "datum points & curves" option in the
exporting option window, in order to ensure Gmsh can get the color
information correctly. If you do not do this, the color may look OK in
Creo, but Gmsh recognizes all surface color as pure blue. (Gmsh
version 4.4.1)




Christophe Geuzaine <cgeuzaine at uliege.be> 于2019年11月5日周二 下午11:14写道:
>
>
>
> > On 5 Nov 2019, at 15:32, Wesley Ranger <metorm at outlook.com> wrote:
> >
> > Say we have an uncertain polyhedron, which is built via CAD software. Some of its faces contact with other objects and are thus painted red, and the other faces are painted blue.
> >
> > Naturally, I want to *Merge* the shape into Gmsh, and assign the faces into different physical groups by color. I am glad to see that the OpenCASCADE CAD kernel is now able to read "color & label information" from step files. But I haven't managed to find any clue on utilizing such information to set meshing options.
> >
> > Can someone please show me an example to do this? Either script or API is OK.
> >
>
> See e.g. https://gitlab.onelab.info/gmsh/gmsh/blob/master/demos/api/step_assembly.py, which shows how to exploit labels. Colors can be accessed in a similar way (using getColor instead of getName).
>
> Christophe
>
>
>
>
> > Best Regards
> >
> > Ran Wei
> > _______________________________________________
> > 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
>
>
>


More information about the gmsh mailing list