CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Special Topics > Mesh Generation & Pre-Processing

python script to create geometry for salome, and then mesh

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 13, 2017, 13:09
Smile python script to create geometry for salome, and then mesh
  #1
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 12
6863523 is on a distinguished road
Dear All,
I am trying to create the geometry for salome via Python script.
The geometry is like in the attachment.
I exported the original Python script from salome via dump study and changed the coordinates for the small squares.
But when I load the script in salome, there is an error like:
Code:
>>> execfile(r"/home/LEPT/ywang/OpenFOAM/ywang-3.0.1/run/salome/UCUCscript.py")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/LEPT/ywang/OpenFOAM/ywang-3.0.1/run/salome/UCUCscript.py", line 52, in <module>
    Edge_8 = geompy.MakeEdge(Vertex_8, Edge_5_vertex_2)
  File "/usr/local/salome/INSTALL/GEOM/lib/python2.7/site-packages/salome/salome/geom/geomBuilder.py", line 284, in OpenCallClose
    res = theFunction(self, *args, **kwargs)
  File "/usr/local/salome/INSTALL/GEOM/lib/python2.7/site-packages/salome/salome/geom/geomBuilder.py", line 4562, in MakeEdge
    RaiseIfFailed("MakeEdge", self.ShapesOp)
  File "/usr/local/salome/INSTALL/GEOM/lib/python2.7/site-packages/salome/salome/geom/geomBuilder.py", line 299, in RaiseIfFailed
    raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()
RuntimeError: MakeEdge : The end points are too close
The Python script is
Code:
import sys
import salome

salome.salome_init()
theStudy = salome.myStudy

import salome_notebook
notebook = salome_notebook.NoteBook(theStudy)
sys.path.insert( 0, r'/home/LEPT/ywang/OpenFOAM/ywang-3.0.1/run/salome')

###
### GEOM component
###

import GEOM
from salome.geom import geomBuilder
import math
import SALOMEDS
import numpy as np


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)
Vertex_1 = geompy.MakeVertex(0, 0, 0)
Vertex_2 = geompy.MakeVertex(1, 0, 0)
Vertex_3 = geompy.MakeVertex(1, 1, 0)
Vertex_4 = geompy.MakeVertex(0, 1, 0)
Edge_1 = geompy.MakeEdge(Vertex_1, Vertex_2)
Edge_2 = geompy.MakeEdge(Vertex_2, Vertex_3)
Edge_3 = geompy.MakeEdge(Vertex_3, Vertex_4)
Edge_1_vertex_2 = geompy.GetSubShape(Edge_1, [2])
Edge_4 = geompy.MakeEdge(Vertex_4, Edge_1_vertex_2)

Vertex_5 = geompy.MakeVertex(19.138425, 21.870465, 0)
Vertex_6 = geompy.MakeVertex(29.745015, 21.870465, 0)
Vertex_7 = geompy.MakeVertex(29.745015, 32.477055, 0)
Vertex_8 = geompy.MakeVertex(19.138425, 21.870465, 0)
Edge_5 = geompy.MakeEdge(Vertex_5, Vertex_6)
Edge_6 = geompy.MakeEdge(Vertex_6, Vertex_7)
Edge_7 = geompy.MakeEdge(Vertex_7, Vertex_8)
Edge_5_vertex_2 = geompy.GetSubShape(Edge_5, [2])
Edge_8 = geompy.MakeEdge(Vertex_8, Edge_5_vertex_2)

Vertex_9 = geompy.MakeVertex(3.051645, 11.103165, 0)
Vertex_10 = geompy.MakeVertex(13.658235, 11.103165, 0)
Vertex_11 = geompy.MakeVertex(13.658235, 21.709755, 0)
Vertex_12 = geompy.MakeVertex(3.051645, 11.103165, 0)
Edge_9 = geompy.MakeEdge(Vertex_9, Vertex_10)
Edge_10 = geompy.MakeEdge(Vertex_10, Vertex_11)
Edge_11 = geompy.MakeEdge(Vertex_11, Vertex_12)
Edge_9_vertex_2 = geompy.GetSubShape(Edge_9, [2])
Edge_12 = geompy.MakeEdge(Vertex_12, Edge_9_vertex_2)
# Face_1 = geompy.MakeFaceWires([Edge_1, Edge_2, Edge_3, Edge_4, Edge_5, Edge_6, Edge_7, Edge_8], 1)
geompy.addToStudy( O, 'O' )
geompy.addToStudy( OX, 'OX' )
geompy.addToStudy( OY, 'OY' )
geompy.addToStudy( OZ, 'OZ' )
geompy.addToStudy( Vertex_1, 'Vertex_1' )
geompy.addToStudy( Vertex_2, 'Vertex_2' )
geompy.addToStudy( Vertex_3, 'Vertex_3' )
geompy.addToStudy( Vertex_4, 'Vertex_4' )
geompy.addToStudy( Vertex_5, 'Vertex_5' )
geompy.addToStudy( Vertex_6, 'Vertex_6' )
geompy.addToStudy( Vertex_7, 'Vertex_7' )
geompy.addToStudy( Vertex_8, 'Vertex_8' )
geompy.addToStudy( Vertex_9, 'Vertex_9' )
geompy.addToStudy( Vertex_10, 'Vertex_10' )
geompy.addToStudy( Vertex_11, 'Vertex_11' )
geompy.addToStudy( Vertex_12, 'Vertex_12' )
geompy.addToStudy( Edge_1, 'Edge_1' )
geompy.addToStudy( Edge_2, 'Edge_2' )
geompy.addToStudy( Edge_3, 'Edge_3' )
geompy.addToStudyInFather( Edge_1, Edge_1_vertex_2, 'Edge_1:vertex_2' )
geompy.addToStudy( Edge_4, 'Edge_4' )
geompy.addToStudy( Edge_5, 'Edge_5' )
geompy.addToStudy( Edge_6, 'Edge_6' )
geompy.addToStudy( Edge_7, 'Edge_7' )
geompy.addToStudyInFather( Edge_5, Edge_5_vertex_2, 'Edge_5:vertex_2' )
geompy.addToStudy( Edge_8, 'Edge_8' )
geompy.addToStudy( Edge_9, 'Edge_9' )
geompy.addToStudy( Edge_10, 'Edge_10' )
geompy.addToStudy( Edge_11, 'Edge_11' )
geompy.addToStudyInFather( Edge_9, Edge_9_vertex_2, 'Edge_9:vertex_2' )
geompy.addToStudy( Edge_12, 'Edge_12' )
#geompy.addToStudy( Face_1, 'Face_1' )

if salome.sg.hasDesktop():
  salome.sg.updateObjBrowser(1)
Thank you in advance for any suggestions.
Best Regards,
Bill
Attached Images
File Type: jpg 2squares.jpg (10.4 KB, 32 views)
6863523 is offline   Reply With Quote

Old   January 15, 2017, 20:06
Default
  #2
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi bill,

Could it be because vertex5 and vertex8 have the exact same coordinates?

Best regards
Nicolas
nsf is offline   Reply With Quote

Old   January 16, 2017, 06:22
Smile rectangle function in Salome
  #3
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 12
6863523 is on a distinguished road
Dear Nicolas,
Yes, you are right. I made a mistake about the vortex coordinates. I changed the coordinates and it works fine now.
Thank you.
Best Regards,
Bill
Attached Images
File Type: png 2squares.png (1.3 KB, 24 views)

Last edited by 6863523; January 16, 2017 at 11:37.
6863523 is offline   Reply With Quote

Old   January 22, 2017, 05:10
Default draw fine mesh in Salome
  #4
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 12
6863523 is on a distinguished road
Dear,
I want to draw fine mesh of the structure mentioned above.
I have used the "traditional" approach (mesh: 3D extrusion, sub-meshes: 2D mesh front face, 2D projection to the back, 1D elements in the third direction).
However, if the number of the small squares increases, it is a nightmare to chose the edges in order to apply 1D elements in the third direction.

I wonder if you guys could give me some suggestions on how to draw finer mesh for this complex structure.
A sample of Salome file is also preferred.
Thank you in advance.
Best Regards,
Bill
6863523 is offline   Reply With Quote

Old   March 18, 2017, 10:00
Default
  #5
Member
 
Join Date: Feb 2016
Posts: 41
Rep Power: 10
LeeRuns is on a distinguished road
I have built meshes with python scripts and ran them in salome. I built 3d geometry with the python script then made the men in the same script. Did u get that far?

I've never used submeshes so I cannot really help with that part.

Sent from my SM-G930V using CFD Online Forum mobile app
LeeRuns is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 13:37.