##### Personal tools
You are here: Home Use 2D simple examples

# 2D simple examples

Up to Use
• ### 2D simple examples

Posted by Isabel at February 27. 2006
Hello to everybody!

I am a beginner in using Salome and I would like to get a 2D simple example (or a simple tutorial) to know how to create the geometry and the mesh in 2D dimension.
I would be really grateful if you could give me such information.

Best regards and thank-you very much
Isa
• ### Re: 2D simple examples

Posted by Kloss Francis at February 27. 2006
Hello Isabel,

See next a simply sample in python code:
- the geometric piece:
- a first great rectangle
- another rectangle inside the great
- this piece is meshed with quadrangles

Cordially,

Francis KLOSS
--------------------------------------------
# 2005, Francis KLOSS (OCC)
# =====================

from geompy import *

import smesh

# Géométrie
# =========

# Mailler en quadrangle un rectangle dont les longueurs sont des suites de segment. Des conditions limites doivent être posées sur ces segments.

# Les utilitaires 2D
# ------------------

def point(x, y):
return MakeVertex(x, y, 0)

def ligne(pt1, pt2):
x, y, z = PointCoordinates(pt1)
pt3 = MakeVertex(x, y, 50)
return MakePlaneThreePnt(pt1, pt2, pt3, 1000)

# Les points
# ----------

lon = 2.0
lar = 1.0

rect_b_g = point(0.0, 0.0)
rect_b_d = point(lon, 0.0)
rect_h_g = point(0.0, lar)
rect_h_d = point(lon, lar)

seg_b1_g = point(0.3, 0.0)
seg_b1_d = point(0.4, 0.0)
seg_b2_g = point(1.6, 0.0)
seg_b2_d = point(1.8, 0.0)

seg_h1_g = point(0.4, lar)
seg_h1_d = point(0.6, lar)
seg_h2_g = point(1.7, lar)
seg_h2_d = point(1.9, lar)

# Les edges
# ---------

def contour(l):
r = []
i = 1
n = len(l)
p = l[0]
while i<=n:
if i==n:
q = l[0]
else:
q = l[i]
e = MakeEdge(p, q)
r.append(e)
p = q
i = i + 1
return r

edges = contour([rect_b_g, seg_b1_g, seg_b1_d, seg_b2_g, seg_b2_d, rect_b_d, rect_h_d, seg_h2_d, seg_h2_g, seg_h1_d, seg_h1_g, rect_h_g])

# Le rectangle découpé en vue du maillage
# ---------------------------------------

contour = MakeWire(edges)

rectangle = MakeFace(contour, 1)

outils = []
outils.append(ligne(seg_h1_g, seg_b1_g))
outils.append(ligne(seg_h1_d, seg_b1_d))
outils.append(ligne(seg_h2_g, seg_b2_g))
outils.append(ligne(seg_h2_d, seg_b2_d))

piece = MakePartition([rectangle], outils, [], [], ShapeType["FACE"])

piece_nom = "rectangle"

# =========================

# La création du maillage
# -----------------------

a1.NumberOfSegments(5)

# Les hypothèses locales
# ----------------------

def locale(i, d):
e = GetInPlace(piece, edges[i])
a.NumberOfSegments(d)
a.Propagation()

locale(1, 10)
locale(3, 10)
locale(5, 20)

# Le calcul du maillage
# ---------------------