|
[Sponsors] |
[Salome] How to set the Reversed Edges in Python script (Start and End Length)? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 16, 2017, 15:40 |
How to set the Reversed Edges in Python script (Start and End Length)?
|
#1 |
Member
Join Date: May 2017
Posts: 47
Rep Power: 9 |
Hello,
I need to make Start and End Length sub-mesh using Python script. Currently, I'm typing the number of the edge that I saw in the "graphical interface" to set the reversed edges, just like: Code:
Regular_1D_2 = Mesh_1.Segment(geom=externoVertical) Start_and_End_Length_1 = Regular_1D_2.StartEndLength(0.1, 0.6, [ 11, 114, 124, 18, 186, 196, 28, 6, 66, 76 ]) Start_and_End_Length_1.SetObjectEntry( 'Partition_1' ) Does anybody have some idea how I could set the reversed edges to aways be on the right direction? Thanks in advance. |
|
September 17, 2017, 03:55 |
|
#2 |
Senior Member
Niels Nielsen
Join Date: Mar 2009
Location: NJ - Denmark
Posts: 556
Rep Power: 27 |
I have not done this myself, but if you build the geomtry in Salome you can always create the correct direction.
If you make two points and then a line between these 2 points the direction will be from the first point you select to the second point. This extends to extrusions and cuts, etc. the order in which you do things matter. If the geometry comes from some place else you need to check the direction of each line, the ones that are wrong direction you can store in an array and use that in the mesh creation. You can explode the geometry into lines and loop through each of them. Maybe there is a direct way of doing this but I haven't seen it. http://docs.salome-platform.org/7/gu...ools_page.html
__________________
Linnemann PS. I do not do personal support, so please post in the forums. |
|
September 19, 2017, 10:53 |
|
#3 | |
Member
Join Date: May 2017
Posts: 47
Rep Power: 9 |
Thanks for the reply.
To make sub-meshes, the geometry selected (the lines) should be a sub-shape of the main geometry of the mesh (a block, for example). Therefore, I can't create lines because they won't be sub-shapes of the block. Quote:
|
||
September 19, 2017, 15:43 |
|
#4 |
Senior Member
Niels Nielsen
Join Date: Mar 2009
Location: NJ - Denmark
Posts: 556
Rep Power: 27 |
Ok.
Well the way I would do it, you will get some pseudo code here Code:
box1 = geompy.MakeBoxDXDYDZ(10, 20, 30) # Or whatever sub geometry you have here lineIDs = geompy.SubShapeAllIDs(box1, 5) # get all IDs of the lines in the box lines = geompy.SubShapeAll(box1, 5) # 5 is the actual line objects from the box for i,l in enumerate(lines): p1,p2 = geompy.SubShapeAll(l, 2) # 2 is points coords1 = geompy.PointCoordinates(p1) coords2 = geompy.PointCoordinates(p2) make some vector calculations here from p1 to p2 and use some criteria to compare and put into a list you can use later in the mesh study from the lineIDs list and i. You can also create a group in the GEOM module to use in the Mesh module for the reversed edges. Again your main problem is identifying the edges in the wrong direction.
__________________
Linnemann PS. I do not do personal support, so please post in the forums. |
|
September 20, 2017, 19:03 |
|
#5 |
Member
Join Date: May 2017
Posts: 47
Rep Power: 9 |
Thank you very much! I've managed to set the reversed edges with a few modifications. Here's the code:
Code:
import sys import salome salome.salome_init() theStudy = salome.myStudy import salome_notebook notebook = salome_notebook.NoteBook(theStudy) sys.path.insert( 0, r'C:/Users/Renan/Desktop') ### ### GEOM component ### import GEOM from salome.geom import geomBuilder import math import SALOMEDS geompy = geomBuilder.New(theStudy) O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) Box_1 = geompy.MakeBoxDXDYDZ(10, 20, 30) # Or whatever sub geometry you have here lineIDs = geompy.SubShapeAllIDs(Box_1, geompy.ShapeType["EDGE"]) # get all IDs of the lines in the box lines = geompy.SubShapeAll(Box_1, geompy.ShapeType["EDGE"]) #print(lineIDs) Group_1 = geompy.CreateGroup(Box_1, geompy.ShapeType["EDGE"]) geompy.UnionIDs(Group_1, [25, 30, 26, 29]) # A group of the edges oriented in the X axis for testing count = 0 N = len(lineIDs) rvEdges = [0] * N for i,l in enumerate(lines): p1,p2 = geompy.SubShapeAll(l, geompy.ShapeType["VERTEX"]) # 2 is points coords1 = geompy.PointCoordinates(p1) # point of the arrow coords2 = geompy.PointCoordinates(p2) # first point if coords2[0] < coords1[0]: # An example condition for reversed edges rvEdges[count] = lineIDs[i] count = count + 1 #print(rvEdges) # Making a vector of the reversed edges without zeros ------ count = 0 for i in range(0, N): if rvEdges[i] == 0: break count = count + 1 rvEdges2 = [0] * count for i in range(0, count): rvEdges2[i] = rvEdges[i] #print(rvEdges2) # ----------------------------------------------------------- geompy.addToStudy( O, 'O' ) geompy.addToStudy( OX, 'OX' ) geompy.addToStudy( OY, 'OY' ) geompy.addToStudy( OZ, 'OZ' ) geompy.addToStudy( Box_1, 'Box_1' ) geompy.addToStudyInFather( Box_1, Group_1, 'Group_1' ) ### ### SMESH component ### import SMESH, SALOMEDS from salome.smesh import smeshBuilder smesh = smeshBuilder.New(theStudy) Mesh_1 = smesh.Mesh(Box_1) Regular_1D = Mesh_1.Segment() Nb_Segments_1 = Regular_1D.NumberOfSegments(5) Quadrangle_2D = Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE) Hexa_3D = Mesh_1.Hexahedron(algo=smeshBuilder.Hexa) # THE SUB-MESH ------------ Regular_1D_1 = Mesh_1.Segment(geom=Group_1) Start_and_End_Length_1 = Regular_1D_1.StartEndLength(3.74166,0.5, rvEdges2) # These numbers are arbitrary Start_and_End_Length_1.SetObjectEntry( 'Box_1' ) # ------------------------- isDone = Mesh_1.Compute() Sub_mesh_1 = Regular_1D_1.GetSubMesh() ## Set names of Mesh objects smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D') smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D') smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D') smesh.SetName(Start_and_End_Length_1, 'Start and End Length_1') smesh.SetName(Nb_Segments_1, 'Nb. Segments_1') smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') smesh.SetName(Sub_mesh_1, 'Sub-mesh_1') if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(1) |
|
September 4, 2018, 13:30 |
|
#6 |
New Member
Marlos
Join Date: Sep 2018
Posts: 1
Rep Power: 0 |
How do I get the nodes of the edges of the sub-mesh, after having generated the sub-mesh. I need to build a script in python. Thank you very much in advance.
|
|
Tags |
edges, length, opposite, reversed, salome |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Centrifugal fan-reverse flow in outlet lesds to a mass in flow field | xiexing | CFX | 3 | March 29, 2017 11:00 |
Error - Solar absorber - Solar Thermal Radiation | MichaelK | CFX | 12 | September 1, 2016 06:15 |
Problem with an old Simulation | FrankW | CFX | 3 | February 8, 2016 05:28 |
An error has occurred in cfx5solve: | volo87 | CFX | 5 | June 14, 2013 18:44 |
RPM in Wind Turbine | Pankaj | CFX | 9 | November 23, 2009 05:05 |