mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-28 18:30:35 +05:00
1882 lines
49 KiB
HTML
Executable File
1882 lines
49 KiB
HTML
Executable File
<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
<title>Modifying Meshes</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
|
<meta name="generator" content="RoboHelp by eHelp Corporation www.ehelp.com"><style>
|
|
<!--
|
|
P { margin-top:0pt; margin-bottom:0pt; }
|
|
LI.kadov-P { }
|
|
-->
|
|
</style><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; font-family:'Times New Roman' , serif; }
|
|
p.whs3 { margin-top:0pt; margin-bottom:0pt; }
|
|
h4.whs4 { margin-top:0pt; margin-bottom:0pt; }
|
|
p.whs5 { margin-top:0.5pt; margin-bottom:0pt; font-family:'Lucida Console' , monospace; }
|
|
p.whs6 { margin-top:0.5pt; margin-bottom:0pt; }
|
|
p.whs7 { margin-top:0pt; margin-bottom:0pt; font-family:'Times New Roman' , serif; font-weight:bold; font-size:13.5pt; }
|
|
p.whs8 { margin-top:0.5pt; margin-bottom:0pt; font-family:'Times New Roman' , serif; }
|
|
p.whs9 { font-family:'Lucida Console' , monospace; }
|
|
p.whs10 { font-family:'Times New Roman' , serif; }
|
|
p.whs11 { margin-left:36px; font-family:'Lucida Console' , monospace; }
|
|
p.whs12 { margin-left:36px; }
|
|
p.whs13 { margin-left:0px; font-family:'Times New Roman' , serif; }
|
|
p.whs14 { font-family:'Lucida Console' , monospace; margin-left:0px; }
|
|
-->
|
|
</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 += "h4.whs4 {margin-top:1pt;margin-bottom:1pt; }";
|
|
strNSS += "p.whs5 {margin-top:1pt;margin-bottom:1pt; }";
|
|
strNSS += "p.whs6 {margin-top:1pt;margin-bottom:1pt; }";
|
|
strNSS += "p.whs7 {margin-top:1pt;margin-bottom:1pt; }";
|
|
strNSS += "p.whs8 {margin-top:1pt;margin-bottom:1pt; }";
|
|
strNSS += "p.whs13 {margin-left:1pt; }";
|
|
strNSS += "p.whs14 {margin-left: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\nModifying Meshes");
|
|
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>Modifying Meshes</h1>
|
|
|
|
<h3><a name=bookmark>Adding Nodes and Elements</a></h3>
|
|
|
|
<h4>Add Node</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add node</p>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">new_id
|
|
= mesh.AddNode(50, 10, 0)</span></p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs1">if new_id == 0:
|
|
print "KO node addition."</p>
|
|
|
|
<p class="whs1">else: print
|
|
"New Node has been added with ID ", new_id </p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<h4>Add Edge</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add node</p>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">n1
|
|
= mesh.AddNode(50, 10, 0)</span></p>
|
|
|
|
<p class="whs1">if n1 == 0: print
|
|
"KO node addition." </p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add edge</p>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">e1
|
|
= mesh.AddEdge([n1, 38])</span></p>
|
|
|
|
<p class="whs1">if e1 == 0: print
|
|
"KO edge addition."</p>
|
|
|
|
<p class="whs1">else: print
|
|
"New Edge has been added with ID ", e1 </p>
|
|
|
|
<h4>Add Triangle</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add node</p>
|
|
|
|
<p class="whs1">n1 = mesh.AddNode(50,
|
|
10, 0)</p>
|
|
|
|
<p class="whs1">if n1 == 0: print
|
|
"KO node addition."</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add triangle</p>
|
|
|
|
<p class="whs1">t1 = mesh.AddFace([n1,
|
|
38, 39])</p>
|
|
|
|
<p class="whs1">if t1 == 0: print
|
|
"KO triangle addition."</p>
|
|
|
|
<p class="whs1">else: print
|
|
"New Triangle has been added with ID ", t1 </p>
|
|
|
|
<h4>Add Quadrangle</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># add node</p>
|
|
|
|
<p class="whs1">n1 = mesh.AddNode(50,
|
|
10, 0)</p>
|
|
|
|
<p class="whs1">if n1 == 0: print
|
|
"KO node addition."</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">n2 = mesh.AddNode(40,
|
|
20, 0)</p>
|
|
|
|
<p class="whs1">if n2 == 0: print
|
|
"KO node addition."</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs3"># add quadrangle</p>
|
|
|
|
<p class="whs1">q1 = mesh.AddFace([n2,
|
|
n1, 38, 39])</p>
|
|
|
|
<p class="whs1">if q1 == 0: print
|
|
"KO quadrangle addition."</p>
|
|
|
|
<p class="whs3"><span style="font-family: 'Lucida Console', monospace;">else:
|
|
print
|
|
"New Quadrangle has been added with ID ", q1</span> </p>
|
|
|
|
<h4>Add Tetrahedron</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add node</p>
|
|
|
|
<p class="whs1">n1 = mesh.AddNode(50,
|
|
10, 0)</p>
|
|
|
|
<p class="whs1">if n1 == 0: print
|
|
"KO node addition."</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add tetrahedron</p>
|
|
|
|
<p class="whs1">t1 = mesh.AddVolume([n1,
|
|
38, 39, 246])</p>
|
|
|
|
<p class="whs1">if t1 == 0: print
|
|
"KO tetrahedron addition."</p>
|
|
|
|
<p class="whs3"><span style="font-family: 'Lucida Console', monospace;">else:
|
|
print
|
|
"New Tetrahedron has been added with ID ", t1</span> </p>
|
|
|
|
<h4>Add Hexahedron</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1">print ""</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add nodes</p>
|
|
|
|
<p class="whs1">nId1 = mesh.AddNode(50,
|
|
10, 0)</p>
|
|
|
|
<p class="whs1">nId2 = mesh.AddNode(47,
|
|
12, 0)</p>
|
|
|
|
<p class="whs1">nId3 = mesh.AddNode(50,
|
|
10, 10)</p>
|
|
|
|
<p class="whs1">nId4 = mesh.AddNode(47,
|
|
12, 10)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">if nId1 == 0 or
|
|
nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># add hexahedron</p>
|
|
|
|
<p class="whs1">vId = mesh.AddVolume([nId2,
|
|
nId1, 38, 39, nId4, nId3, 245, 246])</p>
|
|
|
|
<p class="whs1">if vId == 0: print
|
|
"KO Hexahedron addition."</p>
|
|
|
|
<p class="whs1">else: print
|
|
"New Hexahedron has been added with ID ", vId </p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<h4>Add Polygon</h4>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">import
|
|
math</span></p>
|
|
|
|
<p class="whs1">import salome</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">import smesh</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># create an empty mesh
|
|
structure</p>
|
|
|
|
<p class="whs1">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># a method to build
|
|
a polygonal mesh element with <nb_vert> angles:</p>
|
|
|
|
<p class="whs1">def MakePolygon
|
|
(a_mesh, x0, y0, z0, radius, nb_vert):</p>
|
|
|
|
<p class="whs1"> al
|
|
= 2.0 * math.pi / nb_vert</p>
|
|
|
|
<p class="whs1"> node_ids
|
|
= []</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"> #
|
|
Create nodes for a polygon</p>
|
|
|
|
<p class="whs1"> for
|
|
ii in range(nb_vert):</p>
|
|
|
|
<p class="whs1"> nid
|
|
= mesh.AddNode(x0 + radius * math.cos(ii*al),</p>
|
|
|
|
<p class="whs1"> y0
|
|
+ radius * math.sin(ii*al),</p>
|
|
|
|
<p class="whs1"> z0)</p>
|
|
|
|
<p class="whs1"> node_ids.append(nid)</p>
|
|
|
|
<p class="whs1"> pass</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"> #
|
|
Create a polygon</p>
|
|
|
|
<p class="whs1"> return
|
|
mesh.AddPolygonalFace(node_ids)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># Create three polygons</p>
|
|
|
|
<p class="whs1">f1 = MakePolygon(mesh,
|
|
0, 0, 0,
|
|
30, 13)</p>
|
|
|
|
<p class="whs1">f2 = MakePolygon(mesh,
|
|
0, 0, 10, 21, 9)</p>
|
|
|
|
<p class="whs1">f3 = MakePolygon(mesh,
|
|
0, 0, 20, 13, 6)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<h4>Add Polyhedron</h4>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">import
|
|
salome</span></p>
|
|
|
|
<p class="whs1">import math</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># create an empty mesh
|
|
structure</p>
|
|
|
|
<p class="whs1">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># Create nodes for
|
|
12-hedron with pentagonal faces</p>
|
|
|
|
<p class="whs1">al = 2 * math.pi
|
|
/ 5.0</p>
|
|
|
|
<p class="whs1">cosal = math.cos(al)</p>
|
|
|
|
<p class="whs1">aa = 13</p>
|
|
|
|
<p class="whs1">rr = aa / (2.0 *
|
|
math.sin(al/2.0))</p>
|
|
|
|
<p class="whs1">dr = 2.0 * rr *
|
|
cosal</p>
|
|
|
|
<p class="whs1">r1 = rr + dr</p>
|
|
|
|
<p class="whs1">dh = rr * math.sqrt(2.0
|
|
* (1.0 - cosal * (1.0 + 2.0 * cosal)))</p>
|
|
|
|
<p class="whs1">hh = 2.0 * dh -
|
|
dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">dd = [] <span style="font-family: 'Times New Roman', serif;">#
|
|
top</span></p>
|
|
|
|
<p class="whs1">cc = [] <span style="font-family: 'Times New Roman', serif;">#
|
|
below top</span></p>
|
|
|
|
<p class="whs1">bb = [] <span style="font-family: 'Times New Roman', serif;">#
|
|
above bottom</span></p>
|
|
|
|
<p class="whs1">aa = [] <span style="font-family: 'Times New Roman', serif;">#
|
|
bottom</span></p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">for i in range(5):</p>
|
|
|
|
<p class="whs1"> cos_bot
|
|
= math.cos(i*al)</p>
|
|
|
|
<p class="whs1"> sin_bot
|
|
= math.sin(i*al)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1"> <span
|
|
style="margin-top: 0pt;
|
|
margin-bottom: 0pt;
|
|
font-family: 'Lucida Console', monospace;">cos_top
|
|
= math.cos(i*al + al/2.0)</span></p>
|
|
|
|
<p class="whs1"> sin_top
|
|
= math.sin(i*al + al/2.0)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1"> nd
|
|
= mesh.AddNode(rr * cos_top, rr * sin_top, hh )
|
|
<span style="font-family: 'Times New Roman', serif;"># top</span></p>
|
|
|
|
<p class="whs1"> nc
|
|
= mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) <span style="font-family: 'Times New Roman', serif;">#
|
|
below top</span></p>
|
|
|
|
<p class="whs1"> nb
|
|
= mesh.AddNode(r1 * cos_bot, r1 * sin_bot, dh)
|
|
<span style="font-family: 'Times New Roman', serif;"># above bottom</span></p>
|
|
|
|
<p class="whs1"> na
|
|
= mesh.AddNode(rr * cos_bot, rr * sin_bot, 0)
|
|
<span style="font-family: 'Times New Roman', serif;"># bottom</span></p>
|
|
|
|
<p class="whs1"> dd.append(nd)
|
|
<span style="font-family: 'Times New Roman', serif;"># top</span></p>
|
|
|
|
<p class="whs1"> cc.append(nc)
|
|
<span style="font-family: 'Times New Roman', serif;"># below top</span></p>
|
|
|
|
<p class="whs1"> bb.append(nb)
|
|
<span style="font-family: 'Times New Roman', serif;"># above bottom</span></p>
|
|
|
|
<p class="whs1"> aa.append(na)
|
|
<span style="font-family: 'Times New Roman', serif;"># bottom</span></p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1"> pass</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># Create a polyhedral
|
|
volume (12-hedron with pentagonal faces)</p>
|
|
|
|
<p class="whs1">MeshEditor.AddPolyhedralVolume([dd[0],
|
|
dd[1], dd[2], dd[3], dd[4], <span style="font-family: 'Times New Roman', serif;">#
|
|
top</span></p>
|
|
|
|
<p class="whs1"> dd[0],
|
|
cc[0], bb[1], cc[1], dd[1], #
|
|
-</p>
|
|
|
|
<p class="whs1"> dd[1],
|
|
cc[1], bb[2], cc[2], dd[2], #
|
|
-</p>
|
|
|
|
<p class="whs1"> dd[2],
|
|
cc[2], bb[3], cc[3], dd[3], <span style="font-family: 'Times New Roman', serif;">#
|
|
- below top</span></p>
|
|
|
|
<p class="whs1"> dd[3],
|
|
cc[3], bb[4], cc[4], dd[4], #
|
|
-</p>
|
|
|
|
<p class="whs1"> dd[4],
|
|
cc[4], bb[0], cc[0], dd[0], #
|
|
-</p>
|
|
|
|
<p class="whs1"> aa[4],
|
|
bb[4], cc[4], bb[0], aa[0], #
|
|
.</p>
|
|
|
|
<p class="whs1"> aa[3],
|
|
bb[3], cc[3], bb[4], aa[4], #
|
|
.</p>
|
|
|
|
<p class="whs1"> aa[2],
|
|
bb[2], cc[2], bb[3], aa[3], <span style="font-family: 'Times New Roman', serif;">#
|
|
. above bottom</span></p>
|
|
|
|
<p class="whs1"> aa[1],
|
|
bb[1], cc[1], bb[2], aa[2], #
|
|
.</p>
|
|
|
|
<p class="whs1"> aa[0],
|
|
bb[0], cc[0], bb[1], aa[1], #
|
|
.</p>
|
|
|
|
<p class="whs1"> aa[0],
|
|
aa[1], aa[2], aa[3], aa[4]], <span style="font-family: 'Times New Roman', serif;">#
|
|
bottom</span></p>
|
|
|
|
<p class="whs1"> [5,5,5,5,5,5,5,5,5,5,5,5])</p>
|
|
|
|
<p class="whs1">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<h3><a name=bookmark1>Removing Nodes and Elements</a></h3>
|
|
|
|
<h4 class="whs4">Removing Nodes</h4>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs1"><span style="font-family: 'Lucida Console', monospace;">import
|
|
SMESH_mechanic</span></p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># remove nodes #246
|
|
and #255</p>
|
|
|
|
<p class="whs1">res = mesh.RemoveNodes([246,
|
|
255])</p>
|
|
|
|
<p class="whs1">if res == 1: print
|
|
"Nodes removing is OK!"</p>
|
|
|
|
<p class="whs1">else: print
|
|
"KO nodes removing." </p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<h4>Removing Elements</h4>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"># remove three elements:
|
|
#850, #859 and #814</p>
|
|
|
|
<p class="whs1">res = mesh.RemoveElements([850,
|
|
859, 814])</p>
|
|
|
|
<p class="whs1">if res == 1: print
|
|
"Elements removing is OK!"</p>
|
|
|
|
<p class="whs1">else: print
|
|
"KO Elements removing." </p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<h3><a name=bookmark2>Renumbering Nodes and Elements</a></h3>
|
|
|
|
<p class="whs5">import SMESH_mechanic</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs5">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs6"> </p>
|
|
|
|
<p class="whs6"><span style="font-family: 'Lucida Console', monospace;">mesh.RenumberNodes()</span>
|
|
</p>
|
|
|
|
<h3><a name=bookmark3>Moving Nodes</a></h3>
|
|
|
|
<p class="whs1">import SMESH_mechanic</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># move node #38</p>
|
|
|
|
<p class="whs1">mesh.MoveNode(38,
|
|
20., 10., 0.) </p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs2"> </p>
|
|
|
|
<p class="whs7"><a name=bookmark14
|
|
style="font-weight: bold; font-size: 13.5pt;">Mesh
|
|
through point</a></p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs1">from geompy import
|
|
*</p>
|
|
|
|
<p class="whs1">from smesh import
|
|
*</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">box = MakeBoxDXDYDZ(200,
|
|
200, 200)</p>
|
|
|
|
<p class="whs1"> </p>
|
|
|
|
<p class="whs1">mesh = Mesh( box
|
|
)</p>
|
|
|
|
<p class="whs1">mesh.Segment().AutomaticLength(0.1)</p>
|
|
|
|
<p class="whs1">mesh.Quadrangle()</p>
|
|
|
|
<p class="whs1">mesh.Compute()</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># find node at (0,0,0)</p>
|
|
|
|
<p class="whs1">node000 = None</p>
|
|
|
|
<p class="whs1">for vId in SubShapeAllIDs(
|
|
box, ShapeType["VERTEX"]):</p>
|
|
|
|
<p class="whs1"> if
|
|
node000: break</p>
|
|
|
|
<p class="whs1"> nodeIds
|
|
= mesh.GetSubMeshNodesId( vId, True )</p>
|
|
|
|
<p class="whs1"> for
|
|
node in nodeIds:</p>
|
|
|
|
<p class="whs1"> xyz
|
|
= mesh.GetNodeXYZ( node )</p>
|
|
|
|
<p class="whs1"> if
|
|
xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :</p>
|
|
|
|
<p class="whs1"> node000
|
|
= node</p>
|
|
|
|
<p class="whs1"> pass</p>
|
|
|
|
<p class="whs1"> pass</p>
|
|
|
|
<p class="whs1"> pass</p>
|
|
|
|
<p class="whs1">if not node000:</p>
|
|
|
|
<p class="whs1"> raise
|
|
"node000 not found"</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># find node000 using the
|
|
tested function </p>
|
|
|
|
<p class="whs1">n = mesh.FindNodeClosestTo(
|
|
-1,-1,-1 )</p>
|
|
|
|
<p class="whs1">if not n == node000:</p>
|
|
|
|
<p class="whs1"> raise
|
|
"FindNodeClosestTo() returns " + str( n ) + " != "
|
|
+ str( node000 )</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># check if any node will
|
|
be found for a point inside a box</p>
|
|
|
|
<p class="whs1">n = mesh.FindNodeClosestTo(
|
|
100, 100, 100 )</p>
|
|
|
|
<p class="whs1">if not n > 0:</p>
|
|
|
|
<p class="whs1"> raise
|
|
"FindNodeClosestTo( 100, 100, 100 ) fails"</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># move node000 to a new
|
|
location</p>
|
|
|
|
<p class="whs1">x,y,z = -10, -10,
|
|
-10</p>
|
|
|
|
<p class="whs1">n = mesh.MeshToPassThroughAPoint(
|
|
x,y,z )</p>
|
|
|
|
<p class="whs1">if not n == node000:</p>
|
|
|
|
<p class="whs1"> raise
|
|
"FindNodeClosestTo() returns " + str( n ) + " != "
|
|
+ str( node000 )</p>
|
|
|
|
<p class="whs3"> </p>
|
|
|
|
<p class="whs3"># check the coordinates
|
|
of the node000</p>
|
|
|
|
<p class="whs1">xyz = mesh.GetNodeXYZ(
|
|
node000 )</p>
|
|
|
|
<p class="whs1">if not ( xyz[0]
|
|
== x and xyz[1] == y and xyz[2] == z) :</p>
|
|
|
|
<p class="whs1"> raise
|
|
"Wrong coordinates: " + str( xyz ) + " != " + str(
|
|
[x,y,z] )</p>
|
|
|
|
<h3><a name=bookmark4>Diagonal Inversion</a></h3>
|
|
|
|
<p class="whs5">import salome</p>
|
|
|
|
<p class="whs5">import smesh</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs8"># create an empty mesh
|
|
structure</p>
|
|
|
|
<p class="whs5">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs8"># create the following
|
|
mesh:</p>
|
|
|
|
<p class="whs5"># .----.----.----.</p>
|
|
|
|
<p class="whs5"># | /|
|
|
/|
|
|
/|</p>
|
|
|
|
<p class="whs5"># | /
|
|
| / | /
|
|
|</p>
|
|
|
|
<p class="whs5"># | / |
|
|
/ | / |</p>
|
|
|
|
<p class="whs5"># |/ |/
|
|
|/
|
|
|</p>
|
|
|
|
<p class="whs5"># .----.----.----.</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs5">bb = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs5">tt = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs5">ff = [0, 0, 0, 0,
|
|
0, 0]</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs5">bb[0] = mesh.AddNode(
|
|
0., 0., 0.)</p>
|
|
|
|
<p class="whs5">bb[1] = mesh.AddNode(10.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs5">bb[2] = mesh.AddNode(20.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs5">bb[3] = mesh.AddNode(30.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs5">tt[0] = mesh.AddNode(
|
|
0., 15., 0.)</p>
|
|
|
|
<p class="whs5">tt[1] = mesh.AddNode(10.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs5">tt[2] = mesh.AddNode(20.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs5">tt[3] = mesh.AddNode(30.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs5">ff[0] = mesh.AddFace([bb[0],
|
|
bb[1], tt[1]])</p>
|
|
|
|
<p class="whs5">ff[1] = mesh.AddFace([bb[0],
|
|
tt[1], tt[0]])</p>
|
|
|
|
<p class="whs5">ff[2] = mesh.AddFace([bb[1],
|
|
bb[2], tt[2]])</p>
|
|
|
|
<p class="whs5">ff[3] = mesh.AddFace([bb[1],
|
|
tt[2], tt[1]])</p>
|
|
|
|
<p class="whs5">ff[4] = mesh.AddFace([bb[2],
|
|
bb[3], tt[3]])</p>
|
|
|
|
<p class="whs5">ff[5] = mesh.AddFace([bb[2],
|
|
tt[3], tt[2]])</p>
|
|
|
|
<p class="whs5"> </p>
|
|
|
|
<p class="whs8"># inverse the diagonal
|
|
bb[1] - tt[2]</p>
|
|
|
|
<p class="whs5">print "\nDiagonal
|
|
inversion ... ",</p>
|
|
|
|
<p class="whs5">res = mesh.InverseDiag(bb[1],
|
|
tt[2])</p>
|
|
|
|
<p class="whs5">if not res: print
|
|
"failed!"</p>
|
|
|
|
<p class="whs5">else: print
|
|
"done."</p>
|
|
|
|
<p class="whs6"> </p>
|
|
|
|
<p class="whs6"><span style="font-family: 'Lucida Console', monospace;">salome.sg.updateObjBrowser(1)</span>
|
|
</p>
|
|
|
|
<h3><a name=bookmark5>Uniting two Triangles</a></h3>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9">import smesh</p>
|
|
|
|
<p> </p>
|
|
|
|
<p># create an empty mesh structure</p>
|
|
|
|
<p class="whs9">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p> </p>
|
|
|
|
<p># create the following mesh:</p>
|
|
|
|
<p class="whs9"># .----.----.----.</p>
|
|
|
|
<p class="whs9"># | /|
|
|
/|
|
|
/|</p>
|
|
|
|
<p class="whs9"># | /
|
|
| / | /
|
|
|</p>
|
|
|
|
<p class="whs9"># | / |
|
|
/ | / |</p>
|
|
|
|
<p class="whs9"># |/ |/
|
|
|/
|
|
|</p>
|
|
|
|
<p class="whs9"># .----.----.----.</p>
|
|
|
|
<p> </p>
|
|
|
|
<p class="whs9">bb = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs9">tt = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs9">ff = [0, 0, 0, 0,
|
|
0, 0]</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">bb[0]
|
|
= mesh.AddNode( 0., 0., 0.)</span></p>
|
|
|
|
<p class="whs9">bb[1] = mesh.AddNode(10.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9">bb[2] = mesh.AddNode(20.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9">bb[3] = mesh.AddNode(30.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">tt[0] = mesh.AddNode(
|
|
0., 15., 0.)</p>
|
|
|
|
<p class="whs9">tt[1] = mesh.AddNode(10.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9">tt[2] = mesh.AddNode(20.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9">tt[3] = mesh.AddNode(30.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">ff[0] = mesh.AddFace([bb[0],
|
|
bb[1], tt[1]])</p>
|
|
|
|
<p class="whs9">ff[1] = mesh.AddFace([bb[0],
|
|
tt[1], tt[0]])</p>
|
|
|
|
<p class="whs9">ff[2] = mesh.AddFace([bb[1],
|
|
bb[2], tt[2]])</p>
|
|
|
|
<p class="whs9">ff[3] = mesh.AddFace([bb[1],
|
|
tt[2], tt[1]])</p>
|
|
|
|
<p class="whs9">ff[4] = mesh.AddFace([bb[2],
|
|
bb[3], tt[3]])</p>
|
|
|
|
<p class="whs9">ff[5] = mesh.AddFace([bb[2],
|
|
tt[3], tt[2]]) </p>
|
|
|
|
<p> </p>
|
|
|
|
<p># delete the diagonal bb[1] - tt[2]</p>
|
|
|
|
<p class="whs9">print "\nUnite
|
|
two triangles ... ",</p>
|
|
|
|
<p class="whs9">res = mesh.DeleteDiag(bb[1],
|
|
tt[2])</p>
|
|
|
|
<p class="whs9">if not res: print
|
|
"failed!"</p>
|
|
|
|
<p class="whs9">else: print
|
|
"done."</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p><span style="font-family: 'Lucida Console', monospace;">salome.sg.updateObjBrowser(1)</span>
|
|
</p>
|
|
|
|
<h3><a name=bookmark6>Uniting a Set of Triangles</a></h3>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9">import smesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># create an empty mesh
|
|
structure</p>
|
|
|
|
<p class="whs9">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># create the following
|
|
mesh:</p>
|
|
|
|
<p class="whs9"># .----.----.----.</p>
|
|
|
|
<p class="whs9"># | /|
|
|
/|
|
|
/|</p>
|
|
|
|
<p class="whs9"># | /
|
|
| / | /
|
|
|</p>
|
|
|
|
<p class="whs9"># | / |
|
|
/ | / |</p>
|
|
|
|
<p class="whs9"># |/ |/
|
|
|/
|
|
|</p>
|
|
|
|
<p class="whs9"># .----.----.----.</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">bb = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs9">tt = [0, 0, 0, 0]</p>
|
|
|
|
<p class="whs9">ff = [0, 0, 0, 0,
|
|
0, 0]</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">bb[0]
|
|
= mesh.AddNode( 0., 0., 0.)</span></p>
|
|
|
|
<p class="whs9">bb[1] = mesh.AddNode(10.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9">bb[2] = mesh.AddNode(20.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9">bb[3] = mesh.AddNode(30.,
|
|
0., 0.)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">tt[0] = mesh.AddNode(
|
|
0., 15., 0.)</p>
|
|
|
|
<p class="whs9">tt[1] = mesh.AddNode(10.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9">tt[2] = mesh.AddNode(20.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9">tt[3] = mesh.AddNode(30.,
|
|
15., 0.)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">ff[0] = mesh.AddFace([bb[0],
|
|
bb[1], tt[1]])</p>
|
|
|
|
<p class="whs9">ff[1] = mesh.AddFace([bb[0],
|
|
tt[1], tt[0]])</p>
|
|
|
|
<p class="whs9">ff[2] = mesh.AddFace([bb[1],
|
|
bb[2], tt[2]])</p>
|
|
|
|
<p class="whs9">ff[3] = mesh.AddFace([bb[1],
|
|
tt[2], tt[1]])</p>
|
|
|
|
<p class="whs9">ff[4] = mesh.AddFace([bb[2],
|
|
bb[3], tt[3]])</p>
|
|
|
|
<p class="whs9">ff[5] = mesh.AddFace([bb[2],
|
|
tt[3], tt[2]])</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># unite a set of triangles</p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">print
|
|
"\nUnite a set of triangles ... ",</span></p>
|
|
|
|
<p class="whs9">res = mesh.TriToQuad([ff[2],
|
|
ff[3], ff[4], ff[5]], smesh.FT_MinimumAngle, 60.)</p>
|
|
|
|
<p class="whs9">if not res: print
|
|
"failed!"</p>
|
|
|
|
<p class="whs9">else: print
|
|
"done."</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<h3><a name=bookmark12>Orientation</a></h3>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9">import smesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p># create an empty mesh structure</p>
|
|
|
|
<p class="whs9">mesh = smesh.Mesh()
|
|
</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># build five quadrangles:</p>
|
|
|
|
<p class="whs9">dx = 10</p>
|
|
|
|
<p class="whs9">dy = 20</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">n1
|
|
= mesh.AddNode(0.0
|
|
* dx, 0, 0)</span></p>
|
|
|
|
<p class="whs9">n2 =
|
|
mesh.AddNode(1.0 * dx, 0, 0)</p>
|
|
|
|
<p class="whs9">n3 =
|
|
mesh.AddNode(2.0 * dx, 0, 0)</p>
|
|
|
|
<p class="whs9">n4 =
|
|
mesh.AddNode(3.0 * dx, 0, 0)</p>
|
|
|
|
<p class="whs9">n5 =
|
|
mesh.AddNode(4.0 * dx, 0, 0)</p>
|
|
|
|
<p class="whs9">n6 =
|
|
mesh.AddNode(5.0 * dx, 0, 0)</p>
|
|
|
|
<p class="whs9">n7 =
|
|
mesh.AddNode(0.0 * dx, dy, 0)</p>
|
|
|
|
<p class="whs9">n8 =
|
|
mesh.AddNode(1.0 * dx, dy, 0)</p>
|
|
|
|
<p class="whs9">n9 =
|
|
mesh.AddNode(2.0 * dx, dy, 0)</p>
|
|
|
|
<p class="whs9">n10 = mesh.AddNode(3.0
|
|
* dx, dy, 0)</p>
|
|
|
|
<p class="whs9">n11 = mesh.AddNode(4.0
|
|
* dx, dy, 0)</p>
|
|
|
|
<p class="whs9">n12 = mesh.AddNode(5.0
|
|
* dx, dy, 0)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">f1 = mesh.AddFace([n1,
|
|
n2, n8 , n7 ])</p>
|
|
|
|
<p class="whs9">f2 = mesh.AddFace([n2,
|
|
n3, n9 , n8 ])</p>
|
|
|
|
<p class="whs9">f3 = mesh.AddFace([n3,
|
|
n4, n10, n9 ])</p>
|
|
|
|
<p class="whs9">f4 = mesh.AddFace([n4,
|
|
n5, n11, n10])</p>
|
|
|
|
<p class="whs9">f5 = mesh.AddFace([n5,
|
|
n6, n12, n11]) </p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># Change the orientation
|
|
of the second and the fourth faces.</p>
|
|
|
|
<p class="whs9">mesh.Reorient([2,
|
|
4])</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<h3><a name=bookmark7>Cutting Quadrangles</a></h3>
|
|
|
|
<p class="whs9">import SMESH_mechanic</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">smesh = SMESH_mechanic.smesh</p>
|
|
|
|
<p class="whs9">mesh =
|
|
SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># cut two quadrangles:
|
|
405 and 406</p>
|
|
|
|
<p class="whs9">mesh.QuadToTri([405,
|
|
406], smesh.FT_MinimumAngle) </p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<h3><a name=bookmark8>Smoothing</a></h3>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9">import geompy</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">import SMESH_mechanic</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">smesh
|
|
= SMESH_mechanic.smesh</span></p>
|
|
|
|
<p class="whs9">mesh = SMESH_mechanic.mesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># select the top face</p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">faces
|
|
= geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])</span></p>
|
|
|
|
<p class="whs9">face = faces[3]</p>
|
|
|
|
<p class="whs9">geompy.addToStudyInFather(SMESH_mechanic.shape_mesh,
|
|
face, "face planar with hole")</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># create a group of
|
|
faces to be smoothed</p>
|
|
|
|
<p class="whs9">GroupSmooth = mesh.GroupOnGeom(face,
|
|
"Group of faces (smooth)", smesh.FACE)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># perform smoothing</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># boolean SmoothObject(Object,
|
|
IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)</p>
|
|
|
|
<p class="whs9">res = mesh.SmoothObject(GroupSmooth,
|
|
[], 20, 2., smesh.CENTROIDAL_SMOOTH)</p>
|
|
|
|
<p class="whs9">print "\nSmoothing
|
|
... ",</p>
|
|
|
|
<p class="whs9">if not res: print
|
|
"failed!"</p>
|
|
|
|
<p class="whs9">else: print
|
|
"done."</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<h3><a name=bookmark9>Extrusion</a></h3>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9">import geompy</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">import SMESH_mechanic</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">smesh
|
|
= SMESH_mechanic.smesh</span></p>
|
|
|
|
<p class="whs9">mesh = SMESH_mechanic.mesh
|
|
</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># select the top face</p>
|
|
|
|
<p class="whs9">faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh,
|
|
geompy.ShapeType["FACE"])</p>
|
|
|
|
<p class="whs9">face = faces[7]</p>
|
|
|
|
<p class="whs9">geompy.addToStudyInFather(SMESH_mechanic.shape_mesh,
|
|
face, "face circular top")</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># create a vector
|
|
for extrusion</p>
|
|
|
|
<p class="whs9">point = smesh.PointStruct(0.,
|
|
0., 5.)</p>
|
|
|
|
<p class="whs9">vector = smesh.DirStruct(point)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># create a group to
|
|
be extruded</p>
|
|
|
|
<p class="whs9">GroupTri = mesh.GroupOnGeom(face,
|
|
"Group of faces (extrusion)", smesh.FACE)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># perform extrusion
|
|
of the group</p>
|
|
|
|
<p class="whs9">mesh.ExtrusionSweepObject(GroupTri,
|
|
vector, 5)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"><span style="font-family: 'Lucida Console', monospace;">salome.sg.updateObjBrowser(1)</span>
|
|
</p>
|
|
|
|
<h3><a name=bookmark10>Extrusion along a Path</a></h3>
|
|
|
|
<p class="whs9">import math</p>
|
|
|
|
<p class="whs9">import salome</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># Geometry</p>
|
|
|
|
<p class="whs9">import geompy</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10"># 1. Create points</p>
|
|
|
|
<p class="whs9">points = [[0, 0],
|
|
[50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">iv = 1</p>
|
|
|
|
<p class="whs9">vertices = []</p>
|
|
|
|
<p class="whs9">for point in points:</p>
|
|
|
|
<p class="whs11">vert
|
|
= geompy.MakeVertex(point[0], point[1], 0)</p>
|
|
|
|
<p class="whs11">geompy.addToStudy(vert,
|
|
"Vertex_" + `iv`)</p>
|
|
|
|
<p class="whs11">vertices.append(vert)</p>
|
|
|
|
<p class="whs11">iv
|
|
+= 1</p>
|
|
|
|
<p class="whs11">pass</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10"># 2. Create edges and
|
|
wires</p>
|
|
|
|
<p class="whs9">Edge_straight = geompy.MakeEdge(vertices[0],
|
|
vertices[4])</p>
|
|
|
|
<p class="whs9">Edge_bezierrr = geompy.MakeBezier(vertices)</p>
|
|
|
|
<p class="whs9">Wire_polyline = geompy.MakePolyline(vertices)</p>
|
|
|
|
<p class="whs9">Edge_Circle =
|
|
geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">geompy.addToStudy(Edge_straight,
|
|
"Edge_straight")</p>
|
|
|
|
<p class="whs9">geompy.addToStudy(Edge_bezierrr,
|
|
"Edge_bezierrr")</p>
|
|
|
|
<p class="whs9">geompy.addToStudy(Wire_polyline,
|
|
"Wire_polyline")</p>
|
|
|
|
<p class="whs9">geompy.addToStudy(Edge_Circle
|
|
, "Edge_Circle")</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10"># 3. Explode wire on
|
|
edges, as they will be used for mesh extrusion</p>
|
|
|
|
<p class="whs9">Wire_polyline_edges
|
|
= geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])</p>
|
|
|
|
<p class="whs9">for ii in range(len(Wire_polyline_edges)):</p>
|
|
|
|
<p class="whs11">geompy.addToStudyInFather(Wire_polyline,
|
|
Wire_polyline_edges[ii], "Edge_" + `ii + 1`)</p>
|
|
|
|
<p class="whs11">pass</p>
|
|
|
|
<p class="whs12"> </p>
|
|
|
|
<p class="whs10"># Mesh</p>
|
|
|
|
<p class="whs9">import smesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs13"># Mesh
|
|
the given shape with the given 1d hypothesis</p>
|
|
|
|
<p class="whs14">def
|
|
Mesh1D(shape1d, nbSeg, name):</p>
|
|
|
|
<p class="whs14"> mesh1d_tool
|
|
= smesh.Mesh(shape1d, name)</p>
|
|
|
|
<p class="whs14"> algo
|
|
= mesh1d_tool.Segment()</p>
|
|
|
|
<p class="whs14"> hyp
|
|
= algo.NumberOfSegments(nbSeg)</p>
|
|
|
|
<p class="whs14"> isDone
|
|
= mesh1d_tool.Compute()</p>
|
|
|
|
<p class="whs14"> if
|
|
not isDone: print 'Mesh ', name, ': computation failed'</p>
|
|
|
|
<p class="whs14"> return
|
|
mesh1d_tool</p>
|
|
|
|
<p class="whs13"># Create
|
|
a mesh with six nodes, seven edges and two quadrangle faces</p>
|
|
|
|
<p class="whs14">def
|
|
MakeQuadMesh2(mesh_name):</p>
|
|
|
|
<p class="whs14"> quad_1
|
|
= smesh.Mesh(name = mesh_name)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs14"> <span
|
|
style="font-family: 'Times New Roman', serif;">#
|
|
six nodes</span></p>
|
|
|
|
<p class="whs14"> n1
|
|
= quad_1.AddNode(0, 20, 10)</p>
|
|
|
|
<p class="whs14"> n2
|
|
= quad_1.AddNode(0, 40, 10)</p>
|
|
|
|
<p class="whs14"> n3
|
|
= quad_1.AddNode(0, 40, 30)</p>
|
|
|
|
<p class="whs14"> n4
|
|
= quad_1.AddNode(0, 20, 30)</p>
|
|
|
|
<p class="whs14"> n5
|
|
= quad_1.AddNode(0, 0,
|
|
30)</p>
|
|
|
|
<p class="whs14"> n6
|
|
= quad_1.AddNode(0, 0,
|
|
10)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs14"> <span
|
|
style="font-family: 'Times New Roman', serif;">#
|
|
seven edges</span></p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n1,
|
|
n2]) # 1</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n2,
|
|
n3]) # 2</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n3,
|
|
n4]) # 3</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n4,
|
|
n1]) # 4</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n4,
|
|
n5]) # 5</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n5,
|
|
n6]) # 6</p>
|
|
|
|
<p class="whs14"> quad_1.AddEdge([n6,
|
|
n1]) # 7</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs14"> <span
|
|
style="font-family: 'Times New Roman', serif;">#
|
|
two quadrangle faces</span></p>
|
|
|
|
<p class="whs14"> quad_1.AddFace([n1,
|
|
n2, n3, n4]) # 8</p>
|
|
|
|
<p class="whs14"> quad_1.AddFace([n1,
|
|
n4, n5, n6]) # 9</p>
|
|
|
|
<p class="whs14"> return
|
|
[quad_1, [1,2,3,4,5,6,7], [8,9]]</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># Path
|
|
meshes</p>
|
|
|
|
<p class="whs14">Edge_straight_mesh
|
|
= Mesh1D(Edge_straight, 7, "Edge_straight")</p>
|
|
|
|
<p class="whs14">Edge_bezierrr_mesh
|
|
= Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")</p>
|
|
|
|
<p class="whs14">Wire_polyline_mesh
|
|
= Mesh1D(Wire_polyline, 3, "Wire_polyline")</p>
|
|
|
|
<p class="whs14">Edge_Circle_mesh
|
|
=
|
|
Mesh1D(Edge_Circle ,
|
|
8, "Edge_Circle")</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># Initial
|
|
meshes (to be extruded)</p>
|
|
|
|
<p class="whs14">[quad_1,
|
|
ee_1, ff_1] = MakeQuadMesh2("quad_1")</p>
|
|
|
|
<p class="whs14">[quad_2,
|
|
ee_2, ff_2] = MakeQuadMesh2("quad_2")</p>
|
|
|
|
<p class="whs14">[quad_3,
|
|
ee_3, ff_3] = MakeQuadMesh2("quad_3")</p>
|
|
|
|
<p class="whs14">[quad_4,
|
|
ee_4, ff_4] = MakeQuadMesh2("quad_4")</p>
|
|
|
|
<p class="whs14">[quad_5,
|
|
ee_5, ff_5] = MakeQuadMesh2("quad_5")</p>
|
|
|
|
<p class="whs14">[quad_6,
|
|
ee_6, ff_6] = MakeQuadMesh2("quad_6")</p>
|
|
|
|
<p class="whs14">[quad_7,
|
|
ee_7, ff_7] = MakeQuadMesh2("quad_7")</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># ExtrusionAlongPath</p>
|
|
|
|
<p class="whs13"># IDsOfElements,
|
|
PathMesh, PathShape, NodeStart,</p>
|
|
|
|
<p class="whs13"># HasAngles,
|
|
Angles, HasRefPoint, RefPoint</p>
|
|
|
|
<p class="whs14">refPoint
|
|
= smesh.PointStruct(0, 0, 0)</p>
|
|
|
|
<p class="whs14">a10
|
|
= 10.0*math.pi/180.0</p>
|
|
|
|
<p class="whs14">a45
|
|
= 45.0*math.pi/180.0</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 1.
|
|
Extrusion of two mesh edges along a straight path</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight,
|
|
1,</p>
|
|
|
|
<p class="whs14"> 0,
|
|
[], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 2.
|
|
Extrusion of one mesh edge along a curved path</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,</p>
|
|
|
|
<p class="whs14"> 0,
|
|
[], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 3.
|
|
Extrusion of one mesh edge along a curved path with usage of angles</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,</p>
|
|
|
|
<p class="whs14"> 1,
|
|
[a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 4.
|
|
Extrusion of one mesh edge along the path, which is a part of a meshed
|
|
wire</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0],
|
|
1,</p>
|
|
|
|
<p class="whs14"> 1,
|
|
[a10, a10, a10], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 5.
|
|
Extrusion of two mesh faces along the path, which is a part of a meshed
|
|
wire</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2],
|
|
4,</p>
|
|
|
|
<p class="whs14"> 0,
|
|
[], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 6.
|
|
Extrusion of two mesh faces along a closed path</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,</p>
|
|
|
|
<p class="whs14"> 0,
|
|
[], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs13"># 7.
|
|
Extrusion of two mesh faces along a closed path with usage of angles</p>
|
|
|
|
<p class="whs14">error
|
|
= quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,</p>
|
|
|
|
<p class="whs14"> 1,
|
|
[a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)</p>
|
|
|
|
<p class="whs14"> </p>
|
|
|
|
<p class="whs14">salome.sg.updateObjBrowser(1)
|
|
</p>
|
|
|
|
<h3><a name=bookmark11>Revolution</a></h3>
|
|
|
|
<p class="whs9">import math</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">import SMESH_mechanic</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"><span style="font-family: 'Lucida Console', monospace;">mesh
|
|
= SMESH_mechanic.mesh</span></p>
|
|
|
|
<p class="whs9">smesh = SMESH_mechanic.smesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># create a group of faces
|
|
to be revolved</p>
|
|
|
|
<p class="whs9">FacesRotate = [492,
|
|
493, 502, 503]</p>
|
|
|
|
<p class="whs9">GroupRotate = mesh.CreateGroup(SMESH.FACE,"Group
|
|
of faces (rotate)")</p>
|
|
|
|
<p class="whs9">GroupRotate.Add(FacesRotate)</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10"># define revolution angle
|
|
and axis</p>
|
|
|
|
<p class="whs9">angle45 = 45 * math.pi
|
|
/ 180</p>
|
|
|
|
<p class="whs9">axisXYZ = SMESH.AxisStruct(-38.3128,
|
|
-73.3658, -23.321, -13.3402, -13.3265, 6.66632)</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs10"># perform revolution
|
|
of an object</p>
|
|
|
|
<p class="whs9">mesh.RotationSweepObject(GroupRotate,
|
|
axisXYZ, angle45, 4, 1e-5) </p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<h3><a name=bookmark13>Pattern Mapping</a></h3>
|
|
|
|
<p class="whs9">import geompy</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9">import smesh</p>
|
|
|
|
<p class="whs9"> </p>
|
|
|
|
<p class="whs9"># define the geometry</p>
|
|
|
|
<p class="whs10">Box_1 = geompy.MakeBoxDXDYDZ(200.,
|
|
200., 200.)</p>
|
|
|
|
<p class="whs10">geompy.addToStudy(Box_1,
|
|
"Box_1")</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">faces = geompy.SubShapeAll(Box_1,
|
|
geompy.ShapeType["FACE"])</p>
|
|
|
|
<p class="whs10">Face_1 = faces[0]</p>
|
|
|
|
<p class="whs10">Face_2 = faces[1]</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">geompy.addToStudyInFather(Box_1,
|
|
Face_1, "Face_1")</p>
|
|
|
|
<p class="whs10">geompy.addToStudyInFather(Box_1,
|
|
Face_2, "Face_2")</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs9"># build a quadrangle
|
|
mesh 3x3 on Face_1</p>
|
|
|
|
<p class="whs10">Mesh_1 = smesh.Mesh(Face_1)</p>
|
|
|
|
<p class="whs10">algo1D = Mesh_1.Segment()</p>
|
|
|
|
<p class="whs10">algo1D.NumberOfSegments(3)</p>
|
|
|
|
<p class="whs10">Mesh_1.Quadrangle()</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">isDone = Mesh_1.Compute()</p>
|
|
|
|
<p class="whs10">if not isDone: print
|
|
'Mesh Mesh_1 : computation failed'</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs9"># build a triangle
|
|
mesh on Face_2</p>
|
|
|
|
<p class="whs10">Mesh_2 = smesh.Mesh(Face_2)</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">algo1D = Mesh_2.Segment()</p>
|
|
|
|
<p class="whs10">algo1D.NumberOfSegments(1)</p>
|
|
|
|
<p class="whs10">algo2D = Mesh_2.Triangle()</p>
|
|
|
|
<p class="whs10">algo2D.MaxElementArea(240)</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">isDone = Mesh_2.Compute()</p>
|
|
|
|
<p class="whs10">if not isDone: print
|
|
'Mesh Mesh_2 : computation failed'</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs9"># create a pattern</p>
|
|
|
|
<p class="whs10">pattern = smesh.GetPattern()</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">isDone = pattern.LoadFromFace(Mesh_2.GetMesh(),
|
|
Face_2, 0)</p>
|
|
|
|
<p class="whs10">if (isDone != 1): print
|
|
'LoadFromFace :', pattern.GetErrorCode()</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs9"># apply the pattern
|
|
to a face of the first mesh</p>
|
|
|
|
<p class="whs10">pattern.ApplyToMeshFaces(Mesh_1.GetMesh(),
|
|
[17], 0, 0)</p>
|
|
|
|
<p class="whs10"> </p>
|
|
|
|
<p class="whs10">isDone = pattern.MakeMesh(Mesh_1.GetMesh(),
|
|
0, 0)</p>
|
|
|
|
<p class="whs10">if (isDone != 1): print
|
|
'MakeMesh :', pattern.GetErrorCode() </p>
|
|
|
|
<script type="text/javascript" language="javascript1.2">
|
|
<!--
|
|
if (window.writeIntopicBar)
|
|
writeIntopicBar(0);
|
|
//-->
|
|
</script>
|
|
</body>
|
|
</html>
|