smesh/doc/salome/gui/SMESH/smesh_py_introduction.htm

209 lines
5.6 KiB
HTML
Raw Normal View History

<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<head>
<title>Introduction to MESH module python interface</title>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<meta name="generator" content="RoboHelp by eHelp Corporation www.ehelp.com"><style type="text/css">
<!--
p.whs1 { margin-top:0pt; margin-bottom:0pt; font-family:'Lucida Console' , monospace; }
p.whs2 { margin-top:0pt; margin-bottom:0pt; }
p.whs3 { font-family:'Lucida Console' , monospace; margin-top:0px; margin-bottom:0px; }
p.whs4 { margin-top:0px; margin-bottom:0px; }
p.whs5 { margin-top:0px; margin-bottom:0px; font-family:'Times New Roman' , serif; }
-->
</style><script type="text/javascript" language="JavaScript">
<!--
if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
{
var strNSS = "<style type='text/css'>";
strNSS += "p.whs1 {margin-top:1pt;margin-bottom:1pt; }";
strNSS += "p.whs2 {margin-top:1pt;margin-bottom:1pt; }";
strNSS += "p.whs3 {margin-top:1pt;margin-bottom:1pt; }";
strNSS += "p.whs4 {margin-top:1pt;margin-bottom:1pt; }";
strNSS += "p.whs5 {margin-top:1pt;margin-bottom:1pt; }";
strNSS +="</style>";
document.write(strNSS);
}
//-->
</script>
<script type="text/javascript" language="JavaScript" title="WebHelpInlineScript">
<!--
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
//-->
</script>
<style type="text/css">
<!--
div.WebHelpPopupMenu { position:absolute; left:0px; top:0px; z-index:4; visibility:hidden; }
p.WebHelpNavBar { text-align:right; }
-->
</style><script type="text/javascript" language="javascript1.2" src="whmsg.js"></script>
<script type="text/javascript" language="javascript" src="whver.js"></script>
<script type="text/javascript" language="javascript1.2" src="whproxy.js"></script>
<script type="text/javascript" language="javascript1.2" src="whutils.js"></script>
<script type="text/javascript" language="javascript1.2" src="whtopic.js"></script>
<script type="text/javascript" language="javascript1.2">
<!--
if (window.gbWhTopic)
{
if (window.setRelStartPage)
{
addTocInfo("MESH module\nTUI Scripts\nIntroduction to MESH module python interface");
addButton("show",BTN_IMG,"Show","","","","",0,0,"whd_show0.gif","whd_show2.gif","whd_show1.gif");
addButton("hide",BTN_IMG,"Hide","","","","",0,0,"whd_hide0.gif","whd_hide2.gif","whd_hide1.gif");
}
if (window.setRelStartPage)
{
setRelStartPage("index.htm");
autoSync(1);
sendSyncInfo();
sendAveInfoOut();
}
}
else
if (window.gbIE4)
document.location.reload();
//-->
</script>
</head>
<body><script type="text/javascript" language="javascript1.2">
<!--
if (window.writeIntopicBar)
writeIntopicBar(4);
//-->
</script>
<h1>Introduction to MESH module python interface</h1>
<p><a href="smeshpy_doc/namespacesmesh.html">Package smesh</a> provides a standard API for meshes creation and edition.
<p>Below you can see an example of package <b>smesh</b> usage for 3d mesh generation.
<p>&nbsp;
<h3><a name=bookmark>Example of 3d mesh generation with NETGEN</a></h3>
<br>from geompy import *
<br>
<br>import smesh
<br>
<br># Geometry
<br># ========
<br>
<br># an assembly of a box, a cylinder and a truncated cone meshed with tetrahedral.
<br>
<br># Define values
<br># -------------
<br>
<br>name = "ex21_lamp"
<br>
<br>cote = 60
<br>
<br>section = 20
<br>size = 200
<br>
<br>radius_1 = 80
<br>radius_2 = 40
<br>height = 100
<br>
<br># Build a box
<br># -----------
<br>
<br>box = MakeBox(-cote, -cote, -cote, +cote, +cote, +cote)
<br>
<br># Build a cylinder
<br># ----------------
<br>
<br>pt1 = MakeVertex(0, 0, cote/3)
<br>di1 = MakeVectorDXDYDZ(0, 0, 1)
<br>cyl = MakeCylinder(pt1, di1, section, size)
<br>
<br># Build a truncated cone
<br># ----------------------
<br>
<br>pt2 = MakeVertex(0, 0, size)
<br>cone = MakeCone(pt2, di1, radius_1, radius_2, height)
<br>
<br># Fuse
<br># ----
<br>
<br>box_cyl = MakeFuse(box, cyl)
<br>piece = MakeFuse(box_cyl, cone)
<br>
<br># Add in study
<br># ------------
<br>
<br>addToStudy(piece, name)
<br>
<br># Create a group of faces
<br># -----------------------
<br>
<br>group = CreateGroup(piece, ShapeType["FACE"])
<br>
<br>group_name = name + "_grp"
<br>addToStudy(group, group_name)
<br>group.SetName(group_name)
<br>
<br># Add faces in the group
<br># ----------------------
<br>
<br>faces = SubShapeAllIDs(piece, ShapeType["FACE"])
<br>
<br>UnionIDs(group, faces)
<br>
<br># Create a mesh
<br># =============
<br>
<br># Define a mesh on a geometry
<br># ---------------------------
<br>
<br>tetra = smesh.Mesh(piece, name)
<br>
<br># Define 1D hypothesis
<br># --------------------
<br>
<br>algo1d = tetra.Segment()
<br>algo1d.LocalLength(10)
<br>
<br># Define 2D hypothesis
<br># --------------------
<br>
<br>algo2d = tetra.Triangle()
<br>algo2d.LengthFromEdges()
<br>
<br># Define 3D hypothesis
<br># --------------------
<br>
<br>algo3d = tetra.Tetrahedron(smesh.NETGEN)
<br>algo3d.MaxElementVolume(100)
<br>
<br># Compute the mesh
<br># ----------------
<br>
<br>tetra.Compute()
<br>
<br># Create a groupe of faces
<br># ------------------------
<br>
<br>tetra.Group(group)
<script type="text/javascript" language="javascript1.2">
<!--
if (window.writeIntopicBar)
writeIntopicBar(0);
//-->
</script>
</body>
</html>