Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 1/8

Organization (S): EDF-R & D/AMA
Handbook of Utilization
U7.0- booklet: Data exchanges
Document: U7.03.03

Python methods of control of GMSH

Summary:

This document introduces the supervisor making it possible to control GMSH since Python, and thus since the file of
order Aster.

This supervisor produces any type of grids 2D by using software GMSH (www.geuz.org/gmsh). He is
in particular used in Aster by the tool for postprocessing interactive STANLEY in order to generate elements of
grids for postprocessing, but can be extended to other applications: parametric grid,
mending of meshes, etc

Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 2/8

1 Mode
of employment

There are four stages to follow to produce a grid with supervisor GMSH:

· Definition of the geometry;
· Definition of the discretizations;
· Creation of grid GMSH and the group_ma and associated Physical objects;
· Importation of grid GMSH in Aster.

Simple example of use:

In the following example, one uses the functionalities of the supervisor to generate the grid of one
rectangular plate:

Geometry

From sup_gmsh importation *

larg = 5.
H_beton = 3.
H_S1 = 4.
t_beton = 25.
prog_S1 = 1.1


One imports the module and one defines some parameters.

# Geometry
O = Not (0, 0)
With = Point (larg, 0)
B = Point (larg, H_beton)
C = Not (0, H_beton)
D = Not (0, - H_S1)
E = Point (larg, - H_S1)

OA = Line (O, A)
AB = Line (A, B)
BC = Line (B, C)
OC = Line (O, C)

OD = Line (O, D)
OF = Line (D, E)
AE = Line (A, E)

S2 = Surface (OA, AB, BC, OC)
S1 = Surface (OD, OF, AE, OA)

Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 3/8

One creates points, lines between the points and of surfaces starting from the lines.

# Discretization
OA.Transfinite (1)
BC.Transfinite (1)
DE.Transfinite (1)

N_beton = int (H_beton/t_beton + 0.5)
AB.Transfinite (N_beton)
OC.Transfinite (N_beton)

N_S1 = Progress (H_S1, r=prog_S1, h=t_beton)
OD.Transfinite (N_S1, prog_S1)
AE.Transfinite (N_S1, prog_S1)

S2.Transfinite ()
S1.Transfinite ()


One defines the discretization of the lines and surfaces.

# Grid
mesh = Mesh ()
mesh.Physical (“FOND”, OF)
mesh.Physical (“LAT_G”, OC, OD)
mesh.Physical (“LAT_D', AB, AE)
mesh.Physical (“INTERFAC”, OA)
mesh.Physical (“HAUT”, BC)
mesh.Physical (“S2”, S2)
mesh.Physical (“S1”, S1)


One creates the object grid and one defines the groups of meshs which will be group_ma in the SD
Aster grid and of Physical in GMSH (the latter will be named GM1, GM2, etc…).

MA = mesh.LIRE_GMSH (
MODI_QUAD = “YES”
)


Importation of the grid in Aster: MA is a Aster grid.

Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 4/8

2
List functions available

The list of the functions is extracted directly from the source, sup_gmsh.py, which explains why it is in
English.

2.1
Classify generic for the geometrical objects

class Geometric:


private attribute
parameters: dictionary off the attributes (except relation and parameters itself)
see __getattr__ and __setattr__

Attributes
num: index among gmsh objects
Mandelevium: mesh descriptor
mesh: related mesh object
relation: model object in box off coincidence


Public methods
Is_point: return true is the object inherits off the Point class

Is_line: return true is the object inherits off the Line class

Is_surface: return true is the object inherits off the Surface class

Is_volume: return true is the object inherits off the Volume class

Is_same_dimension: return true is both objects are off the same dimension
(not, line, surface gold volume)
in - > object to compares to coil

Duplicate: duplicate year object and bases its mesh_descriptor
one the mesh_descriptor off the model

Coincide: assert that year object is coincides with has model one
Al the attributes are then automatically read from
the model object (see __setattr__ and __getattr__).
in - > model object

Private method

Root:
Provides the root object off year object, IE the object itself yew there is No relation
however the deepest model in box off relation.

Geometric_coincide: check yew has geometrical coincidence is possible
return information butt the coincidence, false else.
in - > model object

Deep_coincide: proceed recursively to depending ensure coincidence off the sub-objects
in - > model object
in - > corresponds (information returned by Geometric_coincide)
Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 5/8


__setattr__: distinguish two sets off attributes
relation (to express train has relation with has model object in box off coincidence)
Al the other attributes which are stored in the dictionary parameters
instead off the usual __dict__ yew there is No relation (see Coincide)
and in the model object yew there is has coincidence

__getattr__: yew the object is related (relation <> None) the attribute is read
in the model object. Else, it is read in the current object, actually
in the dictionary parameters (see __setattr__)

Thanks to thesis two overloaded methods, the accesses to the attributes is usual yew
there is No relation whereas the attributes off the model object are accessed
transparently yew there is has relation.

__cmp__:
The comparison off two objects involves possible coincidence. It is No more the object ids
that are compared goal the object roots (.relation yew any).

Gmsh: produce the source codes for Gmsh
in - > mesh

Gmsh_send: send has line code to the gmsh to interpret
in - > line_code (string)

Intermediate_meshing: produce the source codes for the intermediate objects
in - > mesh

Object meshing: produce the source codes for the current object
VAr - > object number (modified yew several objects are created)

2.2
Functions for objects POINT

class Point (Geometric):

Public methods
__init__:
in - > coordinates (the 3rd is zero by default)

Size: set the size off the neighbouring elements
in - > size

Attractor: define the not have year attractor
in - > scale_x: size amplification Factor in the X-direction
in - > scale_y: size amplification Factor in the there-direction
in - > distance: influence distance for the disturbance

Attributes
coor: coordinates
size: neighbouring element size
attractor: parameters off the attractor

Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 6/8

2.3
Functions for objects LIGNE

class Line (Geometric):

LINE OBJECT

Public methods

Attractor: define the not have year attractor
in - > scale_x: size amplification Factor in the X-direction
in - > scale_y: size amplification Factor in the there-direction
in - > distance: influence distance for the disturbance

class Circle (Line):

CIRCLE OBJECT


def Curve (l_x, l_y, l_z=None):

CURVE OBJECT (in - > list off points)

2.4
Functions for the SURFACE objects

class Surface (Geometric):

SURFACE OBJECT (inherit from the Geometric class)

Public methods
__init__:
in - > lines: external bounday off the surface (lines should Be connected)

Holes: set the internal holes (surfaces)
in - > holes: list off holes

Boundary: checks that the boundary is has closed loop and returns the orientation off the edges

Ruled: the surface is declares has ruled one

Relocate: relocate the surface
in - > tran: (numpy) vector off translation

Recombine: recombine the surface (try to mesh with quadrangles instead off triangles)

Transfinite: The mesh to Be transfinite declares


Attributes
lines: list off external boundary lines
holes: list off internal holes (surfaces)
ruled: indicates (false gold true) yew the surface is has ruled surface
loops: list off boundary (external and internal) loops (computed when meshing)
Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 7/8

2.5
Functions for the operations on the grids

class Mesh_Descriptor:

Attributes
relation Another mesh descriptor provides the mesh parameters
parameters dictionary off the mesh parameters
size Point size
transfinite Transfinite mesh (0 gold 1)
number Number off elements along has line (transfinite)
Progression progression off element size (transfinite)
recombine Recombine mesh gold not

Specific accesses:
md.parameter_name = xxx - > the relation is destroyed (set to None)
xxx = md.parameter_name - > yew there is has relation, the effective
parameter is looked for recursively

Deep copying: relation is set to the model instead has off has true Copy

class Mesh:
def __init__ (coil, algo = 2, gmsh=' gmsh'):

def Physical (coil, name, * l_obj): creation off Physical (GMSH object)

def Save (coil, file = “fort.geo”): save the geo file

def View (coil): launch GMSH with the current geo file

def Create (coil, file = “fort.19”): save the geo file and create the msh file

def Name (coil, MA, CREA_GROUP_NO): create the group_ma and/gold the group_no

def LIRE_GMSH (coil,
UNITE_GMSH = 19,
UNITE_MAILLAGE = 20,
MODI_QUAD = “NOT”,
CREA_GROUP_NO = “YES”
):

Reading of the grid (Aster format) from its definition
(format sup_gmsh)
UNITE_GMSH = logical Numero of unit for the file msh
UNITE_MAILLAGE = logical Numero of unit for the file mall
MODI_QUAD = “OUI” if line->quad, “NON” if not
CREA_GROUP_NO = “OUI” if the group_no are created, “NON” if not

2.6
Functions for the geometrical transformations

def VectorProduct (U, v):

def VectorNorm (U):

class Rotation:
in - > A, C, B
Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python methods of control of GMSH


Date:
04/01/05
Author (S):
A. Key ASSIRE
:
U7.03.03-A Page
: 8/8

Intentionally white left page.
Handbook of Utilization
U7.0- booklet: Data exchanges
HT-66/05/004/A

Outline document