if (Lead2nd_Enable): Contact2_1 = Group_surface[2] Contact2_2 = Group_surface[3] encap_inner_ROI2 = Group_volume[5] encap_outer_ROI2 = Group_volume[3] ROI2 = Group_volume[4] Rest_1 = Group_volume[6] import SMESH, SALOMEDS from salome.smesh import smeshBuilder anode_mesh_max = 0.005 cathode_mesh_max = 0.1 smesh = smeshBuilder.New(theStudy) Mesh_1 = smesh.Mesh(Partition_profile) NETGEN_1D_2D_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D) NETGEN_3D_Parameters_1 = NETGEN_1D_2D_3D.Parameters() NETGEN_3D_Parameters_1.SetMaxSize(0.225) NETGEN_3D_Parameters_1.SetSecondOrder(0) NETGEN_3D_Parameters_1.SetOptimize(1) NETGEN_3D_Parameters_1.SetFineness(0) NETGEN_3D_Parameters_1.SetMinSize(0.1) NETGEN_3D_Parameters_1.SetUseSurfaceCurvature(1) NETGEN_3D_Parameters_1.SetFuseEdges(1) NETGEN_3D_Parameters_1.SetQuadAllowed(0) NETGEN_1D_2D = Mesh_1.Triangle(algo=smeshBuilder.NETGEN_1D2D, geom=Contact1_1) Sub_mesh_1 = NETGEN_1D_2D.GetSubMesh() NETGEN_2D_Parameters_1 = NETGEN_1D_2D.Parameters() NETGEN_2D_Parameters_1.SetMaxSize(anode_mesh_max)
geompy.addToStudy(Line_3, 'Line_3') geompy.addToStudy(Partition_1, 'Partition_1') geompy.addToStudyInFather(Partition_1, inletPrimary, 'inletPrimary') geompy.addToStudyInFather(Partition_1, inletSecondary, 'inletSecondary') geompy.addToStudyInFather(Partition_1, inletAmbient, 'inletAmbient') geompy.addToStudyInFather(Partition_1, wallInletNozzle, 'wallInletNozzle') geompy.addToStudyInFather(Partition_1, wallInlet, 'wallInlet') geompy.addToStudyInFather(Partition_1, wallOuter, 'wallOuter') geompy.addToStudyInFather(Partition_1, outlet, 'outlet') geompy.addToStudyInFather(Partition_1, wedgeFace1, 'wedgeFace1') geompy.addToStudyInFather(Partition_1, edges12, 'edges12') geompy.addToStudyInFather(Partition_1, edges3, 'edges3') geompy.addToStudyInFather(Partition_1, edges6, 'edges6') geompy.addToStudyInFather(Partition_1, edges20, 'edges20') geompy.addToStudyInFather(Partition_1, edgesOuter, 'edgesOuter') geompy.addToStudyInFather(Partition_1, edgesMiddle, 'edgesMiddle') ### ### SMESH component ### import SMESH, SALOMEDS from salome.smesh import smeshBuilder smesh = smeshBuilder.New() #smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: # multiples meshes built in parallel, complex and numerous mesh edition (performance) if salome.sg.hasDesktop(): salome.sg.updateObjBrowser()
def GUI_EOL(context): import salome from salome.smesh import smeshBuilder import SMESH from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import (QPushButton, QLabel, QCheckBox, QHBoxLayout, QVBoxLayout, QLineEdit, QFileDialog) from numpy import array, zeros import pyvtk from MODAL_EOL import MODAL_EOL import pandas as pd study = context.study studyId = context.studyId sg = context.sg smesh = smeshBuilder.New(salome.myStudy) class APP_MODAL_EOL(QDialog): def __init__(self, parent=None): super(APP_MODAL_EOL, self).__init__() self.init_ui() self.show() self.mesh_b.clicked.connect(self.mesh_b_click) self.nodesCc_b.clicked.connect(self.nodesCc_b_click) self.nacele_b.clicked.connect(self.nacele_b_click) self.hub_b.clicked.connect(self.hub_b_click) self.blades_b.clicked.connect(self.blades_b_click) self.tower_b.clicked.connect(self.tower_b_click) self.compute.clicked.connect(lambda: self.compute_click( self.x.isChecked(), self.y.isChecked(), self.z.isChecked(), self.rx.isChecked(), self.ry.isChecked(), self.rz.isChecked(), self.nacele_E_l.text(), self.nacele_nu_l.text(), self.nacele_rho_l.text(), self.hub_E_l.text(), self.hub_nu_l.text(), self.hub_rho_l.text(), self.hub_t_l.text( ), self.blades_E_l.text(), self.blades_nu_l.text(), self.blades_rho_l.text(), self.blades_t_l.text(), self.tower_E_l.text(), self.tower_nu_l.text(), self.tower_rho_l.text(), self.tower_t_l.text(), self.k_l.text( ))) self.save.clicked.connect(lambda: self.save_vtk( self.modei_l.text(), self.scale_l.text())) def init_ui(self): self.mesh_b = QPushButton('MESH') self.mesh_l = QLineEdit() h_boxMesh = QHBoxLayout() h_boxMesh.addWidget(self.mesh_b) h_boxMesh.addWidget(self.mesh_l) self.div = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.nodesCc_lb = QLabel('BOUNDARY CONDITIONS') self.nodesCc_l = QLineEdit() self.nodesCc_b = QPushButton('GROUP OF NODES') self.x = QCheckBox('Ux') self.y = QCheckBox('Uy') self.z = QCheckBox('Uz') self.rx = QCheckBox('Rx') self.ry = QCheckBox('Ry') self.rz = QCheckBox('Rz') h_boxNodesCc = QHBoxLayout() h_boxNodesCc.addWidget(self.nodesCc_lb) h_boxNodesCc.addWidget(self.nodesCc_l) h_boxNodesCc.addWidget(self.nodesCc_b) h_boxCheck = QHBoxLayout() h_boxCheck.addWidget(self.x) h_boxCheck.addWidget(self.y) h_boxCheck.addWidget(self.z) h_boxCheck.addWidget(self.rx) h_boxCheck.addWidget(self.ry) h_boxCheck.addWidget(self.rz) v_boxNodesCc = QVBoxLayout() v_boxNodesCc.addLayout(h_boxNodesCc) v_boxNodesCc.addLayout(h_boxCheck) self.div2 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.hub_lb = QLabel('HUB') self.hub_b = QPushButton('GROUP OF ELEMENTS') self.hub_l = QLineEdit() self.hub_E_lb = QLabel('MODULUS OF ELASTICITY') self.hub_E_l = QLineEdit() self.hub_nu_lb = QLabel('COEF. POISSON') self.hub_nu_l = QLineEdit() self.hub_rho_lb = QLabel('DENSITY OF MASSES') self.hub_rho_l = QLineEdit() self.hub_t_lb = QLabel('THICKNESS') self.hub_t_l = QLineEdit() h_box_hub = QHBoxLayout() h_box_hub.addWidget(self.hub_lb) h_box_hub.addWidget(self.hub_l) h_box_hub.addWidget(self.hub_b) h_box_hub_E = QHBoxLayout() h_box_hub_E.addWidget(self.hub_E_lb) h_box_hub_E.addWidget(self.hub_E_l) h_box_hub_nu = QHBoxLayout() h_box_hub_nu.addWidget(self.hub_nu_lb) h_box_hub_nu.addWidget(self.hub_nu_l) h_box_hub_rho = QHBoxLayout() h_box_hub_rho.addWidget(self.hub_rho_lb) h_box_hub_rho.addWidget(self.hub_rho_l) h_box_hub_t = QHBoxLayout() h_box_hub_t.addWidget(self.hub_t_lb) h_box_hub_t.addWidget(self.hub_t_l) v_box_hub = QVBoxLayout() v_box_hub.addLayout(h_box_hub) v_box_hub.addLayout(h_box_hub_E) v_box_hub.addLayout(h_box_hub_nu) v_box_hub.addLayout(h_box_hub_rho) v_box_hub.addLayout(h_box_hub_t) self.div3 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.blades_lb = QLabel('BLADES') self.blades_b = QPushButton('GROUP OF ELEMENTS') self.blades_l = QLineEdit() self.blades_E_lb = QLabel('MODULUS OF ELASTICITY') self.blades_E_l = QLineEdit() self.blades_nu_lb = QLabel('COEF. POISSON') self.blades_nu_l = QLineEdit() self.blades_rho_lb = QLabel('DENSITY OF MASSES') self.blades_rho_l = QLineEdit() self.blades_t_lb = QLabel('THICKNESS') self.blades_t_l = QLineEdit() h_box_blades = QHBoxLayout() h_box_blades.addWidget(self.blades_lb) h_box_blades.addWidget(self.blades_l) h_box_blades.addWidget(self.blades_b) h_box_blades_E = QHBoxLayout() h_box_blades_E.addWidget(self.blades_E_lb) h_box_blades_E.addWidget(self.blades_E_l) h_box_blades_nu = QHBoxLayout() h_box_blades_nu.addWidget(self.blades_nu_lb) h_box_blades_nu.addWidget(self.blades_nu_l) h_box_blades_rho = QHBoxLayout() h_box_blades_rho.addWidget(self.blades_rho_lb) h_box_blades_rho.addWidget(self.blades_rho_l) h_box_blades_t = QHBoxLayout() h_box_blades_t.addWidget(self.blades_t_lb) h_box_blades_t.addWidget(self.blades_t_l) v_box_blades = QVBoxLayout() v_box_blades.addLayout(h_box_blades) v_box_blades.addLayout(h_box_blades_E) v_box_blades.addLayout(h_box_blades_nu) v_box_blades.addLayout(h_box_blades_rho) v_box_blades.addLayout(h_box_blades_t) self.div4 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.tower_lb = QLabel('TOWER') self.tower_b = QPushButton('GROUP OF ELEMENTS') self.tower_l = QLineEdit() self.tower_E_lb = QLabel('MODULUS OF ELASTICITY') self.tower_E_l = QLineEdit() self.tower_nu_lb = QLabel('COEF. POISSON') self.tower_nu_l = QLineEdit() self.tower_rho_lb = QLabel('DENSITY OF MASSES') self.tower_rho_l = QLineEdit() self.tower_t_lb = QLabel('THICKNESS') self.tower_t_l = QLineEdit() h_box_tower = QHBoxLayout() h_box_tower.addWidget(self.tower_lb) h_box_tower.addWidget(self.tower_l) h_box_tower.addWidget(self.tower_b) h_box_tower_E = QHBoxLayout() h_box_tower_E.addWidget(self.tower_E_lb) h_box_tower_E.addWidget(self.tower_E_l) h_box_tower_nu = QHBoxLayout() h_box_tower_nu.addWidget(self.tower_nu_lb) h_box_tower_nu.addWidget(self.tower_nu_l) h_box_tower_rho = QHBoxLayout() h_box_tower_rho.addWidget(self.tower_rho_lb) h_box_tower_rho.addWidget(self.tower_rho_l) h_box_tower_t = QHBoxLayout() h_box_tower_t.addWidget(self.tower_t_lb) h_box_tower_t.addWidget(self.tower_t_l) v_box_tower = QVBoxLayout() v_box_tower.addLayout(h_box_tower) v_box_tower.addLayout(h_box_tower_E) v_box_tower.addLayout(h_box_tower_nu) v_box_tower.addLayout(h_box_tower_rho) v_box_tower.addLayout(h_box_tower_t) self.div5 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.nacele_lb = QLabel('NACELE') self.nacele_b = QPushButton('GROUP OF ELEMENTS') self.nacele_l = QLineEdit() self.nacele_E_lb = QLabel('MODULUS OF ELASTICITY') self.nacele_E_l = QLineEdit() self.nacele_nu_lb = QLabel('COEF. POISSON') self.nacele_nu_l = QLineEdit() self.nacele_rho_lb = QLabel('DENSITY OF MASSES') self.nacele_rho_l = QLineEdit() h_box_nacele = QHBoxLayout() h_box_nacele.addWidget(self.nacele_lb) h_box_nacele.addWidget(self.nacele_l) h_box_nacele.addWidget(self.nacele_b) h_box_nacele_E = QHBoxLayout() h_box_nacele_E.addWidget(self.nacele_E_lb) h_box_nacele_E.addWidget(self.nacele_E_l) h_box_nacele_nu = QHBoxLayout() h_box_nacele_nu.addWidget(self.nacele_nu_lb) h_box_nacele_nu.addWidget(self.nacele_nu_l) h_box_nacele_rho = QHBoxLayout() h_box_nacele_rho.addWidget(self.nacele_rho_lb) h_box_nacele_rho.addWidget(self.nacele_rho_l) v_box_nacele = QVBoxLayout() v_box_nacele.addLayout(h_box_nacele) v_box_nacele.addLayout(h_box_nacele_E) v_box_nacele.addLayout(h_box_nacele_nu) v_box_nacele.addLayout(h_box_nacele_rho) self.div6 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.k_lb = QLabel('MAX MODOS TO FIND') self.k_l = QLineEdit() h_box_k = QHBoxLayout() h_box_k.addWidget(self.k_lb) h_box_k.addWidget(self.k_l) self.compute = QPushButton('COMPUTE') self.modei_lb = QLabel('MODE') self.modei_l = QLineEdit() self.scale_lb = QLabel('SCALE') self.scale_l = QLineEdit() h_box_vtk = QHBoxLayout() h_box_vtk.addWidget(self.modei_lb) h_box_vtk.addWidget(self.modei_l) h_box_vtk.addWidget(self.scale_lb) h_box_vtk.addWidget(self.scale_l) self.save = QPushButton('SAVE') v_box = QVBoxLayout() v_box.addLayout(h_boxMesh) v_box.addWidget(self.div) v_box.addLayout(v_boxNodesCc) v_box.addWidget(self.div2) v_box.addLayout(v_box_nacele) v_box.addWidget(self.div3) v_box.addLayout(v_box_hub) v_box.addWidget(self.div4) v_box.addLayout(v_box_blades) v_box.addWidget(self.div5) v_box.addLayout(v_box_tower) v_box.addWidget(self.div6) v_box.addLayout(h_box_k) v_box.addWidget(self.compute) v_box.addLayout(h_box_vtk) v_box.addWidget(self.save) self.setLayout(v_box) self.setWindowTitle('CODE_MAMNE/MODAL_EOL') def mesh_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.mesh = None objId = salome.sg.getSelected(0) if objId: mm = study.FindObjectID(objId).GetObject() mesh = None try: mm.Load() mesh = mm except BaseException: mesh = None self.mesh_l.setText('Select a valid mesh') pass if mesh: name = smeshBuilder.GetName(mm) self.mesh_l.setText(name) self.mesh = mm nodes_id = list(self.mesh.GetElementsByType(SMESH.NODE)) self.coord = array( [self.mesh.GetNodeXYZ(i) for i in nodes_id], float) def nodesCc_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.cc = None objId = salome.sg.getSelected(0) if objId: cc = study.FindObjectID(objId).GetObject() Cc = None try: cc.GetNodeIDs() Cc = cc except BaseException: Cc = None self.nodesCc_l.setText('Select a valid group') pass if Cc: name = cc.GetName() self.nodesCc_l.setText(name) self.nodesr = array(cc.GetNodeIDs(), int) - 1 def hub_b_click(self): objId = salome.sg.getSelected(0) if objId: group = study.FindObjectID(objId).GetObject() Group = None try: ids = list(group.GetIDs()) A = zeros((5, 3), int) A[2] = self.mesh.GetElemNodes(ids[0]) Group = ids except BaseException: Group = None self.hub_l.setText('Select a valid group') pass if Group: name = group.GetName() self.hub_l.setText(name) self.connec_hub = array( [self.mesh.GetElemNodes(i) for i in Group], int) - 1 def blades_b_click(self): objId = salome.sg.getSelected(0) if objId: group = study.FindObjectID(objId).GetObject() Group = None try: ids = list(group.GetIDs()) A = zeros((5, 3), int) A[2] = self.mesh.GetElemNodes(ids[0]) Group = ids except BaseException: Group = None self.blades_l.setText('Select a valid group') pass if Group: name = group.GetName() self.blades_l.setText(name) self.connec_blades = array( [self.mesh.GetElemNodes(i) for i in Group], int) - 1 def tower_b_click(self): objId = salome.sg.getSelected(0) if objId: group = study.FindObjectID(objId).GetObject() Group = None try: ids = list(group.GetIDs()) A = zeros((5, 3), int) A[2] = self.mesh.GetElemNodes(ids[0]) Group = ids except BaseException: Group = None self.tower_l.setText('Select a valid group') pass if Group: name = group.GetName() self.tower_l.setText(name) self.connec_tower = array( [self.mesh.GetElemNodes(i) for i in Group], int) - 1 def nacele_b_click(self): objId = salome.sg.getSelected(0) if objId: group = study.FindObjectID(objId).GetObject() Group = None try: ids = list(group.GetIDs()) A = zeros((5, 4), int) A[2] = self.mesh.GetElemNodes(ids[0]) Group = ids except BaseException: Group = None self.nacele_l.setText('Select a valid group') pass if Group: name = group.GetName() self.nacele_l.setText(name) self.connec_nacele = array( [self.mesh.GetElemNodes(i) for i in Group], int) - 1 def compute_click(self, Ux, Uy, Uz, Rx, Ry, Rz, E_nacele, nu_nacele, rho_nacele, E_hub, nu_hub, rho_hub, t_hub, E_blades, nu_blades, rho_blades, t_blades, E_tower, nu_tower, rho_tower, t_tower, k): self.compute.setText('COMPUTING') self.gr = [Ux, Uy, Uz, Rx, Ry, Rz] self.E_nacele = float(E_nacele) self.nu_nacele = float(nu_nacele) self.rho_nacele = float(rho_nacele) self.E_hub = float(E_hub) self.nu_hub = float(nu_hub) self.rho_hub = float(rho_hub) self.t_hub = float(t_hub) self.E_blades = float(E_blades) self.nu_blades = float(nu_blades) self.rho_blades = float(rho_blades) self.t_blades = float(t_blades) self.E_tower = float(E_tower) self.nu_tower = float(nu_tower) self.rho_tower = float(rho_tower) self.t_tower = float(t_tower) self.k = int(k) self.MODOS = MODAL_EOL( self.coord, self.nodesr, self.gr, self.connec_nacele, self.E_nacele, self.nu_nacele, self.rho_nacele, self.connec_hub, self.E_hub, self.nu_hub, self.rho_hub, self.t_hub, self.connec_blades, self.E_blades, self.nu_blades, self.rho_blades, self.t_blades, self.connec_tower, self.E_tower, self.nu_tower, self.rho_tower, self.t_tower, self.k) path = str( QFileDialog.getExistingDirectory(self, "Select Directory")) + '/' raw_data = {'NATURAL FREQUENCIES': self.MODOS.hz} df = pd.DataFrame(raw_data, columns=['NATURAL FREQUENCIES']) df.to_csv(path + 'MODAL_EOL.csv') self.compute.setText('COMPUTE') def save_vtk(self, modei, scale): path = str( QFileDialog.getExistingDirectory(self, "Select Directory")) + '/' print path U = self.MODOS.coord.copy() nnos = self.MODOS.nnos ngl = self.MODOS.ngl nodesr = self.MODOS.nodesr nodesl = list(set(range(nnos)) - set(nodesr)) scale = float(scale) modei = int(modei) - 1 g = self.MODOS.g U_i = zeros((nnos, g), float) U_i[nodesl] = self.MODOS.modo[:, modei].reshape( self.MODOS.modo[:, modei].size / g, g) Ux, Uy, Uz = U_i[:, 0].copy(), U_i[:, 1].copy(), U_i[:, 2].copy() Rx, Ry, Rz = U_i[:, 3].copy(), U_i[:, 4].copy(), U_i[:, 5].copy() U_i = U_i * scale U = U + U_i[:, [0, 1, 2]] connec_volume = self.MODOS.connec_nacele connec_face = array(self.MODOS.connec_hub.tolist() + self.MODOS.connec_tower.tolist() + self.MODOS.connec_blades.tolist()) vtk = pyvtk.VtkData( pyvtk.UnstructuredGrid(U, triangle=connec_face, tetra=connec_volume), pyvtk.PointData(pyvtk.Scalars(Ux, name='Ux'), pyvtk.Scalars(Uy, name='Uy'), pyvtk.Scalars(Uz, name='Uz'), pyvtk.Scalars(Rx, name='Rx'), pyvtk.Scalars(Ry, name='Ry'), pyvtk.Scalars(Rz, name='Rz'))) vtk.tofile(path + 'MODAL_' + str(modei + 1)) app = APP_MODAL_EOL() app.exec_()
def GUI_CST(context): import salome from salome.smesh import smeshBuilder import SMESH from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import ( QPushButton, QLabel, QCheckBox, QHBoxLayout, QVBoxLayout, QLineEdit) from numpy import array, zeros from MODAL_CST import MODAL_CST import pandas as pd study = context.study studyId = context.studyId sg = context.sg smesh = smeshBuilder.New(salome.myStudy) class APP_MODAL_CST(QDialog): def __init__(self, parent=None): super(APP_MODAL_CST, self).__init__() self.init_ui() self.show() self.mesh_b.clicked.connect(self.mesh_b_click) self.nodesCc_b.clicked.connect(self.nodesCc_b_click) self.compute.clicked.connect( lambda: self.compute_click( self.x.isChecked(), self.y.isChecked(), self.E_l.text(), self.nu_l.text(), self.rho_l.text(), self.t_l.text())) def init_ui(self): self.mesh_b = QPushButton('MESH') self.mesh_l = QLineEdit() h_boxMesh = QHBoxLayout() h_boxMesh.addWidget(self.mesh_b) h_boxMesh.addWidget(self.mesh_l) self.div = QLabel( '---------------------------------------------------------------------------------------------------------') self.nodesCc_lb = QLabel('BOUNDARY CONDITIONS') self.nodesCc_l = QLineEdit() self.nodesCc_b = QPushButton('GROUP OF NODES') self.x = QCheckBox('Ux') self.y = QCheckBox('Uy') h_boxNodesCc = QHBoxLayout() h_boxNodesCc.addWidget(self.nodesCc_lb) h_boxNodesCc.addWidget(self.nodesCc_l) h_boxNodesCc.addWidget(self.nodesCc_b) h_boxCheck = QHBoxLayout() h_boxCheck.addWidget(self.x) h_boxCheck.addWidget(self.y) v_boxNodesCc = QVBoxLayout() v_boxNodesCc.addLayout(h_boxNodesCc) v_boxNodesCc.addLayout(h_boxCheck) self.div2 = QLabel( '---------------------------------------------------------------------------------------------------------') self.E_lb = QLabel('MODULUS OF ELASTICITY') self.E_l = QLineEdit() self.nu_lb = QLabel('COEF. POISSON') self.nu_l = QLineEdit() self.rho_lb = QLabel('DENSITY OF MASSES') self.rho_l = QLineEdit() self.t_lb = QLabel('THICKNESS') self.t_l = QLineEdit() h_box_E = QHBoxLayout() h_box_E.addWidget(self.E_lb) h_box_E.addWidget(self.E_l) h_box_nu = QHBoxLayout() h_box_nu.addWidget(self.nu_lb) h_box_nu.addWidget(self.nu_l) h_box_rho = QHBoxLayout() h_box_rho.addWidget(self.rho_lb) h_box_rho.addWidget(self.rho_l) h_box_t = QHBoxLayout() h_box_t.addWidget(self.t_lb) h_box_t.addWidget(self.t_l) self.div3 = QLabel( '---------------------------------------------------------------------------------------------------------') self.compute = QPushButton('COMPUTE') v_box = QVBoxLayout() v_box.addLayout(h_boxMesh) v_box.addWidget(self.div) v_box.addLayout(v_boxNodesCc) v_box.addWidget(self.div2) v_box.addLayout(h_box_E) v_box.addLayout(h_box_nu) v_box.addLayout(h_box_rho) v_box.addLayout(h_box_t) v_box.addWidget(self.div3) v_box.addWidget(self.compute) self.setLayout(v_box) self.setWindowTitle('CODE_MAMNE/MODAL_CST') def mesh_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.mesh = None objId = salome.sg.getSelected(0) if objId: mm = study.FindObjectID(objId).GetObject() mesh = None try: mm.Load() mesh = mm except BaseException: mesh = None self.mesh_l.setText('Select a valid mesh') pass if mesh: name = smeshBuilder.GetName(mm) self.mesh_l.setText(name) self.mesh = mm nodes_id = list(self.mesh.GetElementsByType(SMESH.NODE)) self.coord = array([self.mesh.GetNodeXYZ(i) for i in nodes_id], float) face_id = list(self.mesh.GetElementsByType(SMESH.FACE)) self.connec_face = array( [self.mesh.GetElemNodes(i) for i in face_id], int) - 1 def nodesCc_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.cc = None objId = salome.sg.getSelected(0) if objId: cc = study.FindObjectID(objId).GetObject() Cc = None try: cc.GetNodeIDs() Cc = cc except BaseException: Cc = None self.nodesCc_l.setText('Select a valid group') pass if Cc: name = cc.GetName() self.nodesCc_l.setText(name) self.nodesr = array(cc.GetNodeIDs(), int) - 1 def compute_click(self, Ux, Uy, E, nu, rho, t): self.gr = [Ux, Uy] self.E = float(E) self.nu = float(nu) self.rho = float(rho) self.t = float(t) self.MODOS = MODAL_CST(self.coord, self.connec_face, self.nodesr, self.E, self.nu, self.t, self.rho, self.gr) raw_data = {'NATURAL FREQUENCIES': self.MODOS.hz} df = pd.DataFrame(raw_data, columns=['NATURAL FREQUENCIES']) df.to_csv('MODAL_DKT.csv') app = APP_MODAL_CST() app.exec_()
def proceed(self): temp_file = tempfile.mkstemp(suffix='.brep')[1] selected = salome.sg.getSelected(0) selection = salome.myStudy.FindObjectID(selected).GetObject() if not selection: QMessageBox.critical(None, "GMSHMesh macro", "An object has to be selected to run gmsh!") ## Export a part in step format geompy.ExportBREP(selection, temp_file) selection_name = selection.GetName() ## Mesh temporaly file file_format = 'med' temp_mesh_file = tempfile.tempdir + path_sep + selection_name + '_Mesh.' + file_format ## OPTIONS GMSH: clmax = self.sb_max_element_size.text() clmin = self.sb_min_element_size.text() cmd_line_opt = self.le_cmd_line_opt.text() algo = self.cmb_algorithm.currentText() mesh_order = self.sb_mesh_order.text() if self.cb_optimized.isChecked(): cmd_optimize = ' -optimize' else: cmd_optimize = '' if self.rb_3D.isChecked(): dim = ' -3 ' if self.rb_2D.isChecked(): dim = ' -2 ' if self.rb_1D.isChecked(): dim = ' -1 ' if self.cb_max_elme_size.isChecked(): max_size = ' -clmax ' + clmax else: max_size = '' if self.cb_min_elme_size.isChecked(): min_size = ' -clmin ' + clmin else: min_size = '' if self.cb_mesh_order.isChecked(): order = ' -order ' + mesh_order else: order = '' options = ' -algo ' + algo + max_size + min_size + cmd_optimize + order + cmd_line_opt # RUN GMSH command = gmsh_bin + ' ' + temp_file + dim + '-format ' + file_format + ' -o ' + temp_mesh_file + '' + options try: if system() == "Linux": if self.cb_interact.isChecked(): output = subprocess.check_output( [xterm_bin_linux + command, '-1'], shell=True, stderr=subprocess.STDOUT, ) else: output = subprocess.check_output( [command, '-1'], shell=True, stderr=subprocess.STDOUT, ) elif system() == "Windows": output = subprocess.check_output( command, shell=True, stderr=subprocess.STDOUT, ) else: output = subprocess.check_output( [command, '-1'], shell=True, stderr=subprocess.STDOUT, ) smesh = smeshBuilder.New(theStudy) ([Mesh_1], status) = smesh.CreateMeshesFromMED(temp_mesh_file) smesh.SetName(Mesh_1.GetMesh(), selection_name) if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(1) #self.close() #d.close() print "Succefull" except: QMessageBox.critical(None, "GMSHMesh macro", "Unexpected error in GMSHMesh macro!") finally: try: del temp_file except: pass try: del temp_mesh_file except: pass
### Store presentation parameters of displayed objects import iparameters ipar = iparameters.IParameters( theStudy.GetModuleParameters("Interface Applicative", "GEOM", 1)) #Set up entries: # set up entry GEOM_1 (Sommet_1) parameters objId = geompy.getObjectID(Sommet_1) ### ### SMESH component ### import SMESH from salome.smesh import smeshBuilder smesh = smeshBuilder.New(salome.myStudy) import StdMeshers Maillage_1 = smesh.Mesh(Ligne_1) Regular_1D = Maillage_1.Segment() Nb_Segments_1 = Regular_1D.NumberOfSegments(10) Nb_Segments_1.SetDistrType(0) isDone = Maillage_1.Compute() Encastre_1 = Maillage_1.GroupOnGeom(Encastre, 'Encastre', SMESH.NODE) Effort_1 = Maillage_1.GroupOnGeom(Effort, 'Effort', SMESH.NODE) TOUT = Maillage_1.GroupOnGeom(Ligne_1, 'Ligne_1', SMESH.EDGE) TOUT.SetName('TOUT') ## set object names smesh.SetName(Maillage_1.GetMesh(), 'Maillage_1') smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
def create(self): # Read data from input file with open(self.dataFilename) as dataFile: data = json.load(dataFile) elements = data["elements"] connections = data["connections"] # --> Delete this reference data and repopulate it with the objects # while going through elements for conn in connections: conn["relatedElements"] = [] # End <-- meshSize = self.meshSize dec = 7 # 4 decimals for length in mm tol = 10**(-dec - 3 + 1) self.tolLoc = tol * 10 * 2 tolLoc = self.tolLoc NEW_SALOME = int(salome_version.getVersion()[0]) >= 9 salome.salome_init() theStudy = salome.myStudy notebook = salome_notebook.NoteBook(theStudy) ### ### GEOM component ### import GEOM from salome.geom import geomBuilder import math import SALOMEDS gg = salome.ImportComponentGUI("GEOM") if NEW_SALOME: geompy = geomBuilder.New() else: geompy = geomBuilder.New(theStudy) self.geompy = geompy O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) geompy.addToStudy(O, "O") geompy.addToStudy(OX, "OX") geompy.addToStudy(OY, "OY") geompy.addToStudy(OZ, "OZ") if len([e for e in elements if e["geometryType"] == "line"]) > 0: buildingShapeType = "EDGE" if len([e for e in elements if e["geometryType"] == "surface"]) > 0: buildingShapeType = "FACE" ### Define entities ### start_time = time.time() print("Defining Object Geometry") init_time = start_time # Loop 1 for el in elements: el["elemObj"] = self.makeObject(el["geometry"], el["geometryType"]) el["connObjs"] = [None for _ in el["connections"]] el["linkObjs"] = [None for _ in el["connections"]] el["linkPointObjs"] = [[None, None] for _ in el["connections"]] for j, rel in enumerate(el["connections"]): conn = [ c for c in connections if c["referenceName"] == rel["relatedConnection"] ][0] if rel["eccentricity"]: rel["index"] = len(conn["relatedElements"]) + 1 conn["relatedElements"].append(rel) if not rel["eccentricity"]: el["connObjs"][j] = self.makeObject( conn["geometry"], conn["geometryType"]) else: if conn["geometryType"] == "point": geometry = self.getLinkGeometry( rel["eccentricity"], el["orientation"], conn["geometry"]) el["connObjs"][j] = self.makeObject( geometry[0], conn["geometryType"]) el["linkPointObjs"][j][0] = self.geompy.MakeVertex( geometry[0][0], geometry[0][1], geometry[0][2]) el["linkPointObjs"][j][1] = self.geompy.MakeVertex( geometry[1][0], geometry[1][1], geometry[1][2]) el["linkObjs"][j] = self.geompy.MakeLineTwoPnt( el["linkPointObjs"][j][0], el["linkPointObjs"][j][1]) else: print("Eccentricity defined for a %s geometryType" % conn["geometryType"]) el["partObj"] = self.makePartition( [el["elemObj"]] + el["connObjs"], el["geometryType"]) el["elemObj"] = geompy.GetInPlace(el["partObj"], el["elemObj"], True) for j, rel in enumerate(el["connections"]): el["connObjs"][j] = geompy.GetInPlace(el["partObj"], el["connObjs"][j], True) for conn in connections: conn["connObj"] = self.makeObject(conn["geometry"], conn["geometryType"]) # Make assemble of Building Object bldObjs = [] bldObjs.extend([el["partObj"] for el in elements]) bldObjs.extend( flatten([[link for link in el["linkObjs"] if link] for el in elements])) bldObjs.extend([conn["connObj"] for conn in connections]) bldComp = geompy.MakeCompound(bldObjs) # bldComp = geompy.MakePartition(bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1) geompy.addToStudy(bldComp, "bldComp") # Loop 2 for el in elements: # geompy.addToStudy(el['partObj'], self.getGroupName(el['referenceName'])) geompy.addToStudyInFather(el["partObj"], el["elemObj"], self.getGroupName(el["referenceName"])) for j, rel in enumerate(el["connections"]): conn = [ c for c in connections if c["referenceName"] == rel["relatedConnection"] ][0] rel["conn_string"] = None if conn["geometryType"] == "point": rel["conn_string"] = "_0DC_" if conn["geometryType"] == "line": rel["conn_string"] = "_1DC_" if conn["geometryType"] == "surface": rel["conn_string"] = "_2DC_" geompy.addToStudyInFather( el["partObj"], el["connObjs"][j], self.getGroupName(el["referenceName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]), ) if rel["eccentricity"]: pass # geompy.addToStudy(el['linkObjs'][j], self.getGroupName(el['referenceName']) + '_1DR_' + self.getGroupName(rel['relatedConnection'])) # geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['referenceName'])) # geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index']) for conn in connections: # geompy.addToStudy(conn['connObj'], self.getGroupName(conn['referenceName'])) geompy.addToStudyInFather(conn["connObj"], conn["connObj"], self.getGroupName(conn["referenceName"])) elapsed_time = time.time() - init_time init_time += elapsed_time print("Building Geometry Defined in %g sec" % (elapsed_time)) # Define and add groups for all curve and surface members if len([e for e in elements if e["geometryType"] == "line"]) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e["elemObj"] for e in elements if e["geometryType"] == "line" ]) # Define group object and add to study curveCompound = geompy.GetInPlace(bldComp, compoundTemp, True) geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers") if len([e for e in elements if e["geometryType"] == "surface"]) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e["elemObj"] for e in elements if e["geometryType"] == "surface" ]) # Define group object and add to study surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp, True) geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers") # Loop 3 for el in elements: # el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0] geompy.addToStudyInFather(bldComp, el["elemObj"], self.getGroupName(el["referenceName"])) for j, rel in enumerate(el["connections"]): geompy.addToStudyInFather( bldComp, el["connObjs"][j], self.getGroupName(el["referenceName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]), ) if rel["eccentricity"]: # point geometry geompy.addToStudyInFather( bldComp, el["linkObjs"][j], self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), ) geompy.addToStudyInFather( bldComp, el["linkPointObjs"][j][0], self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["referenceName"]), ) geompy.addToStudyInFather( bldComp, el["linkPointObjs"][j][1], self.getGroupName(rel["relatedConnection"]) + "_0DC_%g" % rel["index"], ) for conn in connections: # conn['connObj'] = geompy.RestoreGivenSubShapes(bldComp, [conn['connObj']], GEOM.FSM_GetInPlace, False, False)[0] geompy.addToStudyInFather(bldComp, conn["connObj"], self.getGroupName(conn["referenceName"])) elapsed_time = time.time() - init_time init_time += elapsed_time print("Building Geometry Groups Defined in %g sec" % (elapsed_time)) ### ### SMESH component ### import SMESH from salome.smesh import smeshBuilder print("Defining Mesh Components") if NEW_SALOME: smesh = smeshBuilder.New() else: smesh = smeshBuilder.New(theStudy) bldMesh = smesh.Mesh(bldComp) Regular_1D = bldMesh.Segment() Local_Length_1 = Regular_1D.LocalLength(meshSize, None, tolLoc) if buildingShapeType == "FACE": NETGEN2D_ONLY = bldMesh.Triangle(algo=smeshBuilder.NETGEN_2D) NETGEN2D_Pars = NETGEN2D_ONLY.Parameters() NETGEN2D_Pars.SetMaxSize(meshSize) NETGEN2D_Pars.SetOptimize(1) NETGEN2D_Pars.SetFineness(2) NETGEN2D_Pars.SetMinSize(meshSize / 5.0) NETGEN2D_Pars.SetUseSurfaceCurvature(1) NETGEN2D_Pars.SetQuadAllowed(1) NETGEN2D_Pars.SetSecondOrder(0) NETGEN2D_Pars.SetFuseEdges(254) isDone = bldMesh.Compute() ## Set names of Mesh objects smesh.SetName(Regular_1D.GetAlgorithm(), "Regular_1D") smesh.SetName(Local_Length_1, "Local_Length_1") if buildingShapeType == "FACE": smesh.SetName(NETGEN2D_ONLY.GetAlgorithm(), "NETGEN2D_ONLY") smesh.SetName(NETGEN2D_Pars, "NETGEN2D_Pars") smesh.SetName(bldMesh.GetMesh(), "bldMesh") elapsed_time = time.time() - init_time init_time += elapsed_time print("Meshing Operations Completed in %g sec" % (elapsed_time)) # Define and add groups for all curve and surface members if len([e for e in elements if e["geometryType"] == "line"]) > 0: tempgroup = bldMesh.GroupOnGeom(curveCompound, "CurveMembers", SMESH.EDGE) smesh.SetName(tempgroup, "CurveMembers") if len([e for e in elements if e["geometryType"] == "surface"]) > 0: tempgroup = bldMesh.GroupOnGeom(surfaceCompound, "SurfaceMembers", SMESH.FACE) smesh.SetName(tempgroup, "SurfaceMembers") # Define groups in Mesh for el in elements: if el["geometryType"] == "line": shapeType = SMESH.EDGE if el["geometryType"] == "surface": shapeType = SMESH.FACE tempgroup = bldMesh.GroupOnGeom( el["elemObj"], self.getGroupName(el["referenceName"]), shapeType) smesh.SetName(tempgroup, self.getGroupName(el["referenceName"])) for j, rel in enumerate(el["connections"]): tempgroup = bldMesh.GroupOnGeom( el["connObjs"][j], self.getGroupName(el["referenceName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]), SMESH.NODE, ) smesh.SetName( tempgroup, self.getGroupName(el["referenceName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]), ) rel["node"] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0] if rel["eccentricity"]: tempgroup = bldMesh.GroupOnGeom( el["linkObjs"][j], self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), SMESH.EDGE, ) smesh.SetName( tempgroup, self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), ) tempgroup = bldMesh.GroupOnGeom( el["linkPointObjs"][j][0], self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["referenceName"]), SMESH.NODE, ) smesh.SetName( tempgroup, self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["referenceName"]), ) rel["eccNode"] = (bldMesh.GetIDSource( tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0] tempgroup = bldMesh.GroupOnGeom( el["linkPointObjs"][j][1], self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(rel["relatedConnection"]), SMESH.NODE, ) smesh.SetName( tempgroup, self.getGroupName(rel["relatedConnection"]) + "_0DC_%g" % rel["index"], ) for conn in connections: tempgroup = bldMesh.GroupOnGeom( conn["connObj"], self.getGroupName(conn["referenceName"]), SMESH.NODE) smesh.SetName(tempgroup, self.getGroupName(conn["referenceName"])) nodesId = bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE) tempgroup = bldMesh.Add0DElementsToAllNodes( nodesId, self.getGroupName(conn["referenceName"])) smesh.SetName(tempgroup, self.getGroupName(conn["referenceName"] + "_0D")) if conn["geometryType"] == "point": conn["node"] = nodesId.GetIDs()[0] if conn["geometryType"] == "line": tempgroup = bldMesh.GroupOnGeom( conn["connObj"], self.getGroupName(conn["referenceName"]), SMESH.EDGE) smesh.SetName(tempgroup, self.getGroupName(conn["referenceName"])) if conn["geometryType"] == "surface": tempgroup = bldMesh.GroupOnGeom( conn["connObj"], self.getGroupName(conn["referenceName"]), SMESH.FACE) smesh.SetName(tempgroup, self.getGroupName(conn["referenceName"])) # create 1D SEG2 spring elements for el in elements: for j, rel in enumerate(el["connections"]): conn = [ c for c in connections if c["referenceName"] == rel["relatedConnection"] ][0] if conn["geometryType"] == "point": grpName = bldMesh.CreateEmptyGroup( SMESH.EDGE, self.getGroupName(el["referenceName"]) + "_1DS_" + self.getGroupName(rel["relatedConnection"]), ) smesh.SetName( grpName, self.getGroupName(el["referenceName"]) + "_1DS_" + self.getGroupName(rel["relatedConnection"]), ) if not rel["eccentricity"]: conn = [ conn for conn in connections if conn["referenceName"] == rel["relatedConnection"] ][0] grpName.Add( [bldMesh.AddEdge([conn["node"], rel["node"]])]) else: grpName.Add( [bldMesh.AddEdge([rel["eccNode"], rel["node"]])]) self.mesh = bldMesh self.meshNodes = bldMesh.GetNodesId() elapsed_time = time.time() - init_time init_time += elapsed_time print("Mesh Groups Defined in %g sec" % (elapsed_time)) try: if NEW_SALOME: bldMesh.ExportMED( self.medFilename, auto_groups=0, minor=40, overwrite=1, meshPart=None, autoDimension=0, ) else: bldMesh.ExportMED(self.medFilename, 0, SMESH.MED_V2_2, 1, None, 0) except: print("ExportMED() failed. Invalid file name?") if salome.sg.hasDesktop(): if NEW_SALOME: salome.sg.updateObjBrowser() else: salome.sg.updateObjBrowser(1) elapsed_time = init_time - start_time print("ALL Operations Completed in %g sec" % (elapsed_time))
def GUI_TETRA(context): import salome from salome.smesh import smeshBuilder import SMESH from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import (QPushButton, QLabel, QCheckBox, QHBoxLayout, QVBoxLayout, QLineEdit, QFileDialog) from numpy import array, zeros import pyvtk from MODAL_TETRA import MODAL_TETRA import pandas as pd study = context.study studyId = context.studyId sg = context.sg smesh = smeshBuilder.New(salome.myStudy) class APP_MODAL_TETRA(QDialog): def __init__(self, parent=None): super(APP_MODAL_TETRA, self).__init__() self.init_ui() self.show() self.mesh_b.clicked.connect(self.mesh_b_click) self.nodesCc_b.clicked.connect(self.nodesCc_b_click) self.compute.clicked.connect( lambda: self.compute_click(self.x.isChecked( ), self.y.isChecked(), self.z.isChecked(), self.E_l.text( ), self.nu_l.text(), self.rho_l.text(), self.k_l.text())) self.save.clicked.connect(lambda: self.save_vtk( self.modei_l.text(), self.scale_l.text())) def init_ui(self): self.mesh_b = QPushButton('MESH') self.mesh_l = QLineEdit() h_boxMesh = QHBoxLayout() h_boxMesh.addWidget(self.mesh_b) h_boxMesh.addWidget(self.mesh_l) self.div = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.nodesCc_lb = QLabel('BOUNDARY CONDITIONS') self.nodesCc_l = QLineEdit() self.nodesCc_b = QPushButton('GROUP OF NODES') self.x = QCheckBox('Ux') self.y = QCheckBox('Uy') self.z = QCheckBox('Uz') h_boxNodesCc = QHBoxLayout() h_boxNodesCc.addWidget(self.nodesCc_lb) h_boxNodesCc.addWidget(self.nodesCc_l) h_boxNodesCc.addWidget(self.nodesCc_b) h_boxCheck = QHBoxLayout() h_boxCheck.addWidget(self.x) h_boxCheck.addWidget(self.y) h_boxCheck.addWidget(self.z) v_boxNodesCc = QVBoxLayout() v_boxNodesCc.addLayout(h_boxNodesCc) v_boxNodesCc.addLayout(h_boxCheck) self.div2 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.E_lb = QLabel('MODULUS OF ELASTICITY') self.E_l = QLineEdit() self.nu_lb = QLabel('COEF. POISSON') self.nu_l = QLineEdit() self.rho_lb = QLabel('DENSITY OF MASSES') self.rho_l = QLineEdit() h_box_E = QHBoxLayout() h_box_E.addWidget(self.E_lb) h_box_E.addWidget(self.E_l) h_box_nu = QHBoxLayout() h_box_nu.addWidget(self.nu_lb) h_box_nu.addWidget(self.nu_l) h_box_rho = QHBoxLayout() h_box_rho.addWidget(self.rho_lb) h_box_rho.addWidget(self.rho_l) self.div3 = QLabel( '---------------------------------------------------------------------------------------------------------' ) self.k_lb = QLabel('MAX MODOS TO FIND') self.k_l = QLineEdit() h_box_k = QHBoxLayout() h_box_k.addWidget(self.k_lb) h_box_k.addWidget(self.k_l) self.compute = QPushButton('COMPUTE') self.modei_lb = QLabel('MODE') self.modei_l = QLineEdit() self.scale_lb = QLabel('SCALE') self.scale_l = QLineEdit() h_box_vtk = QHBoxLayout() h_box_vtk.addWidget(self.modei_lb) h_box_vtk.addWidget(self.modei_l) h_box_vtk.addWidget(self.scale_lb) h_box_vtk.addWidget(self.scale_l) self.save = QPushButton('SAVE') v_box = QVBoxLayout() v_box.addLayout(h_boxMesh) v_box.addWidget(self.div) v_box.addLayout(v_boxNodesCc) v_box.addWidget(self.div2) v_box.addLayout(h_box_E) v_box.addLayout(h_box_nu) v_box.addLayout(h_box_rho) v_box.addWidget(self.div3) v_box.addLayout(h_box_k) v_box.addWidget(self.compute) v_box.addLayout(h_box_vtk) v_box.addWidget(self.save) self.setLayout(v_box) self.setWindowTitle('CODE_MAMNE/MODAL_TETRA') def mesh_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.mesh = None objId = salome.sg.getSelected(0) if objId: mm = study.FindObjectID(objId).GetObject() mesh = None try: mm.Load() mesh = mm except BaseException: mesh = None self.mesh_l.setText('Select a valid mesh') pass if mesh: name = smeshBuilder.GetName(mm) self.mesh_l.setText(name) self.mesh = mm nodes_id = list(self.mesh.GetElementsByType(SMESH.NODE)) self.coord = array( [self.mesh.GetNodeXYZ(i) for i in nodes_id], float) volume_id = list(self.mesh.GetElementsByType(SMESH.VOLUME)) self.connec_volume = array( [self.mesh.GetElemNodes(i) for i in volume_id], int) - 1 def nodesCc_b_click(self): # sg.getObjectBrowser().selectionChanged.connect(self.select) self.cc = None objId = salome.sg.getSelected(0) if objId: cc = study.FindObjectID(objId).GetObject() Cc = None try: cc.GetNodeIDs() Cc = cc except BaseException: Cc = None self.nodesCc_l.setText('Select a valid group') pass if Cc: name = cc.GetName() self.nodesCc_l.setText(name) self.nodesr = array(cc.GetNodeIDs(), int) - 1 def compute_click(self, Ux, Uy, Uz, E, nu, rho, k): self.compute.setText('COMPUTING') self.gr = [Ux, Uy, Uz] self.E = float(E) self.nu = float(nu) self.rho = float(rho) self.k = int(k) self.MODOS = MODAL_TETRA(self.coord, self.connec_volume, self.nodesr, self.E, self.nu, self.rho, self.gr, self.k) path = str( QFileDialog.getExistingDirectory(self, "Select Directory")) + '/' raw_data = {'NATURAL FREQUENCIES': self.MODOS.hz} df = pd.DataFrame(raw_data, columns=['NATURAL FREQUENCIES']) df.to_csv(path + 'MODAL_TETRA.csv') self.compute.setText('COMPUTE') def save_vtk(self, modei, scale): path = str( QFileDialog.getExistingDirectory(self, "Select Directory")) + '/' print path U = self.MODOS.coord.copy() nnos = self.MODOS.nnos ngl = self.MODOS.ngl nodesr = self.MODOS.nodesr nodesl = list(set(range(nnos)) - set(nodesr)) scale = float(scale) modei = int(modei) - 1 g = self.MODOS.g U_i = zeros((nnos, g), float) U_i[nodesl] = self.MODOS.modo[:, modei].reshape( self.MODOS.modo[:, modei].size / g, g) Ux, Uy, Uz = U_i[:, 0].copy(), U_i[:, 1].copy(), U_i[:, 2].copy() U_i = U_i * scale U = U + U_i connec_volume = self.MODOS.connec_volume vtk = pyvtk.VtkData( pyvtk.UnstructuredGrid(U, tetra=connec_volume), pyvtk.PointData(pyvtk.Scalars(Ux, name='Ux'), pyvtk.Scalars(Uy, name='Uy'), pyvtk.Scalars(Uz, name='Uz'))) vtk.tofile(path + 'MODAL_' + str(modei + 1)) app = APP_MODAL_TETRA() app.exec_()
def __init__(self, geompy, shape, lattice_model="D2Q9", maxDim=(0,0,0)): # Basic elements self.lmodel = DdQq(lattice_model) self.shape = shape self.geompy = geompy self.Tolerance = 0.707107 self.mg = {} # Integer bounding box if self.lmodel.D() == 3: BBox = geompy.BoundingBox(shape, True) self.Box = geompy.MakeBoxTwoPnt( geompy.MakeVertex( np.ceil(BBox[0]), np.ceil(BBox[2]), np.ceil(BBox[4]) ), geompy.MakeVertex( np.ceil(BBox[1]), np.ceil(BBox[3]), np.ceil(BBox[5])) ) geompy.addToStudy( self.Box, 'Bounding box' ) else: Vertex_0 = geompy.MakeVertex(0, 0, 0) Vertex_1 = geompy.MakeVertex(np.ceil(maxDim[0]), 0, 0) Vertex_2 = geompy.MakeVertex(np.ceil(maxDim[0]), np.ceil(maxDim[1]), 0) Vertex_3 = geompy.MakeVertex(0, np.ceil(maxDim[1]), 0) Line_0 = geompy.MakeLineTwoPnt(Vertex_0, Vertex_1) Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Vertex_2) Line_2 = geompy.MakeLineTwoPnt(Vertex_2, Vertex_3) Line_3 = geompy.MakeLineTwoPnt(Vertex_3, Vertex_0) Wire_1 = geompy.MakeWire([Line_0, Line_1, Line_2, Line_3], 1e-07) self.Box = geompy.MakeFaceWires([Wire_1], 1) geompy.addToStudy( self.Box, 'Bounding box' ) # SMESH Hypotesis if self.lmodel.D() == 3: self.smesh = smeshBuilder.New() Local_Length = self.smesh.CreateHypothesis('LocalLength') Local_Length.SetLength( 1 ) Local_Length.SetPrecision( 1e-07 ) self.Mesh = self.smesh.Mesh( self.Box ) Cartesian_3D = self.Mesh.BodyFitted() Body_Fitting_Parameters = Cartesian_3D.SetGrid([ [ '1' ], [ 0, 1 ]],[ [ '1' ], [ 0, 1 ]],[ [ '1' ], [ 0, 1 ]],2,0) Body_Fitting_Parameters.SetFixedPoint( SMESH.PointStruct ( 0, 0, 0 ), 1 ) Body_Fitting_Parameters.SetAxesDirs( SMESH.DirStruct( SMESH.PointStruct ( 1, 0, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 1, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 1 )) ) else: self.smesh = smeshBuilder.New() self.Mesh = self.smesh.Mesh(self.Box) Regular_1D = self.Mesh.Segment() Local_Length_1 = Regular_1D.LocalLength(1,None,1e-07) Quadrangle_2D = self.Mesh.Quadrangle(algo=smeshBuilder.QUADRANGLE) pass
def writeMesh(name,couche,position,the_center,tolerance,direction=0): 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) Lcordon = 3. LZat = 10. LSub = 30. ESub = 20. Passe = [1,2] if direction == 1: Passe=[2,3] poSects= [-10.,0.,position,position+10.,90.,100.] Sommets=[] for sect in poSects: Sommets.append(geompy.MakeVertex(0, sect, 0)) # Sommet_1 Sommets.append(geompy.MakeVertex(Lcordon, sect, 0)) # Sommet_2 Sommets.append(geompy.MakeVertex(LZat, sect, 0)) # Sommet_3 Sommets.append(geompy.MakeVertex(LSub, sect, 0)) # Sommet_4 Sommets.append(geompy.MakeVertex(0, sect, -Lcordon)) # Sommet_5 Sommets.append(geompy.MakeVertex(Lcordon, sect, -Lcordon)) # Sommet_6 Sommets.append(geompy.MakeVertex(0, sect, -LZat)) # Sommet_7 Sommets.append(geompy.MakeVertex(LZat, sect, -LZat)) # Sommet_8 Sommets.append(geompy.MakeVertex(0, sect, -ESub)) # Sommet_9 Sommets.append(geompy.MakeVertex(LSub, sect, -ESub)) # Sommet_10 Sommets.append(geompy.MakeVertex(0, sect,Lcordon)) # Sommet_11 Sommets.append(geompy.MakeVertex(Lcordon, sect,Lcordon)) # Sommet_12 nbParSect = 12 Lignes=[] print '----Construction des lignes des sections' for i,sect in enumerate(poSects): Lignes.append(geompy.MakeLineTwoPnt(Sommets[0+i*nbParSect], Sommets[1+i*nbParSect])) # Ligne_1 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[1+i*nbParSect], Sommets[2+i*nbParSect])) # Ligne_2 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[2+i*nbParSect], Sommets[3+i*nbParSect])) # Ligne_3 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[3+i*nbParSect], Sommets[9+i*nbParSect])) # Ligne_4 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[9+i*nbParSect], Sommets[8+i*nbParSect])) # Ligne_5 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[8+i*nbParSect], Sommets[6+i*nbParSect])) # Ligne_6 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[6+i*nbParSect], Sommets[4+i*nbParSect])) # Ligne_7 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[4+i*nbParSect], Sommets[0+i*nbParSect])) # Ligne_8 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[5+i*nbParSect], Sommets[4+i*nbParSect])) # Ligne_9 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[5+i*nbParSect], Sommets[1+i*nbParSect])) # Ligne_10 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[5+i*nbParSect], Sommets[7+i*nbParSect])) # Ligne_11 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[7+i*nbParSect], Sommets[9+i*nbParSect])) # Ligne_12 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[7+i*nbParSect], Sommets[6+i*nbParSect])) # Ligne_13 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[7+i*nbParSect], Sommets[2+i*nbParSect])) # Ligne_14 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[0+i*nbParSect], Sommets[10+i*nbParSect])) # Ligne_15 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[10+i*nbParSect], Sommets[11+i*nbParSect]))# Ligne_16 = Lignes.append(geompy.MakeLineTwoPnt(Sommets[1+i*nbParSect], Sommets[11+i*nbParSect])) # Ligne_17 = print '----Construction des faces des sections' Faces=[] numFacesSectDeb=[0] for i,sect in enumerate(poSects): Faces.append(geompy.MakeFaceWires([Lignes[0+i*17], Lignes[7+i*17], Lignes[8+i*17], Lignes[9+i*17]], 1)) # Face_1 = Faces.append(geompy.MakeFaceWires([Lignes[1+i*17], Lignes[9+i*17], Lignes[10+i*17], Lignes[13+i*17]], 1)) # Face_2 = Faces.append(geompy.MakeFaceWires([Lignes[6+i*17], Lignes[8+i*17], Lignes[10+i*17], Lignes[12+i*17]], 1)) # Face_3 = Faces.append(geompy.MakeFaceWires([Lignes[2+i*17], Lignes[3+i*17], Lignes[11+i*17], Lignes[13+i*17]], 1)) # Face_4 = Faces.append(geompy.MakeFaceWires([Lignes[4+i*17], Lignes[5+i*17], Lignes[11+i*17], Lignes[12+i*17]], 1)) # Face_5 = Faces.append(geompy.MakeFaceWires([Lignes[0+i*17], Lignes[16+i*17], Lignes[15+i*17], Lignes[14+i*17]], 1)) # Face_6 = numFacesSectDeb.append(len(Faces)) numLigneBase = len(Lignes) print '----------------Nombre de Lignes de base:',numLigneBase,' nombre de ligne par section:',numLigneBase/len(poSects) numFaceBase = len(Faces) print '----------------Nombre de Faces de base:',numFaceBase,' nombre de face par section:',numFaceBase/len(poSects) print '----Construction des lignes liant les sections' for i in range(len(poSects)-1): for j in range(nbParSect): Lignes.append(geompy.MakeLineTwoPnt(Sommets[j+i*nbParSect],Sommets[j+(i+1)*nbParSect])) #print 'Nombre de Lignes:',len(Lignes) numFacesJoint=[len(Faces)] print '----Construction des faces liant les sections' for i in range(len(poSects)-1): Faces.append(geompy.MakeFaceWires([Lignes[0+i*17], Lignes[17+i*17], Lignes[numLigneBase+i*nbParSect], Lignes[numLigneBase+1+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[1+i*17], Lignes[18+i*17], Lignes[numLigneBase+1+i*nbParSect], Lignes[numLigneBase+2+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[2+i*17], Lignes[19+i*17], Lignes[numLigneBase+2+i*nbParSect], Lignes[numLigneBase+3+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[3+i*17], Lignes[20+i*17], Lignes[numLigneBase+3+i*nbParSect], Lignes[numLigneBase+9+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[4+i*17], Lignes[21+i*17], Lignes[numLigneBase+8+i*nbParSect], Lignes[numLigneBase+9+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[5+i*17], Lignes[22+i*17], Lignes[numLigneBase+6+i*nbParSect], Lignes[numLigneBase+8+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[6+i*17], Lignes[23+i*17], Lignes[numLigneBase+4+i*nbParSect], Lignes[numLigneBase+6+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[7+i*17], Lignes[24+i*17], Lignes[numLigneBase+i*nbParSect], Lignes[numLigneBase+4+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[9+i*17], Lignes[26+i*17], Lignes[numLigneBase+1+i*nbParSect], Lignes[numLigneBase+5+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[10+i*17], Lignes[27+i*17], Lignes[numLigneBase+5+i*nbParSect], Lignes[numLigneBase+7+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[12+i*17], Lignes[29+i*17], Lignes[numLigneBase+6+i*nbParSect], Lignes[numLigneBase+7+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[11+i*17], Lignes[28+i*17], Lignes[numLigneBase+7+i*nbParSect], Lignes[numLigneBase+9+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[13+i*17], Lignes[30+i*17], Lignes[numLigneBase+2+i*nbParSect], Lignes[numLigneBase+7+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[8+i*17] , Lignes[25+i*17], Lignes[numLigneBase+4+i*nbParSect], Lignes[numLigneBase+5+i*nbParSect]], 1)) if (i in Passe): Faces.append(geompy.MakeFaceWires([Lignes[14+i*17] , Lignes[31+i*17], Lignes[numLigneBase+i*nbParSect], Lignes[numLigneBase+10+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[15+i*17] , Lignes[32+i*17], Lignes[numLigneBase+10+i*nbParSect], Lignes[numLigneBase+11+i*nbParSect]], 1)) Faces.append(geompy.MakeFaceWires([Lignes[16+i*17] , Lignes[33+i*17], Lignes[numLigneBase+1+i*nbParSect], Lignes[numLigneBase+11+i*nbParSect]], 1)) numFacesJoint.append(len(Faces)) numLigne = len(Lignes) print '----------------Nombre de Lignes:',numLigne,' nombre de ligne par section:',numLigneBase/len(poSects) numFace = len(Faces) print '----------------Nombre de Faces:',numFace,' nombre de face par section:',numFaceBase/len(poSects) print numFacesSectDeb,numFacesJoint Coques=[] print for i in range(len(poSects)-1): #print [0+numFacesSectDeb[i], 6+numFacesSectDeb[i], numFacesJoint[i], 7+numFacesJoint[i], 8+numFacesJoint[i],13+numFacesJoint[i]] Coques.append(geompy.MakeShell([Faces[0+numFacesSectDeb[i]], Faces[6+numFacesSectDeb[i]],Faces[numFacesJoint[i]], Faces[7+numFacesJoint[i]], Faces[8+numFacesJoint[i]],Faces[13+numFacesJoint[i]]])) Coques.append(geompy.MakeShell([Faces[1+numFacesSectDeb[i]], Faces[7+numFacesSectDeb[i]],Faces[1+numFacesJoint[i]], Faces[8+numFacesJoint[i]], Faces[9+numFacesJoint[i]],Faces[12+numFacesJoint[i]]])) Coques.append(geompy.MakeShell([Faces[2+numFacesSectDeb[i]], Faces[8+numFacesSectDeb[i]],Faces[6+numFacesJoint[i]], Faces[9+numFacesJoint[i]], Faces[10+numFacesJoint[i]],Faces[13+numFacesJoint[i]]])) Coques.append(geompy.MakeShell([Faces[3+numFacesSectDeb[i]], Faces[9+numFacesSectDeb[i]],Faces[2+numFacesJoint[i]], Faces[3+numFacesJoint[i]], Faces[11+numFacesJoint[i]],Faces[12+numFacesJoint[i]]])) Coques.append(geompy.MakeShell([Faces[4+numFacesSectDeb[i]], Faces[10+numFacesSectDeb[i]],Faces[11+numFacesJoint[i]], Faces[10+numFacesJoint[i]],Faces[4+numFacesJoint[i]], Faces[5+numFacesJoint[i]]])) if (i in Passe): Coques.append(geompy.MakeShell([Faces[5+numFacesSectDeb[i]], Faces[11+numFacesSectDeb[i]], Faces[0+numFacesJoint[i]], Faces[14+numFacesJoint[i]], Faces[15+numFacesJoint[i]], Faces[16+numFacesJoint[i]]])) Solides=[] for i,coque in enumerate(Coques): solide = geompy.MakeSolid([coque]) Solides.append(solide) Eprouv = geompy.MakeCompound(Solides) Solides = geompy.ExtractShapes(Eprouv, geompy.ShapeType["SOLID"], True) GLS=[] GSS=[] for i,sol in enumerate(Solides): localAretes = geompy.ExtractShapes(sol, geompy.ShapeType["EDGE"], True) longIDS=[] sectIDS=[] for arete in localAretes: angleY=geompy.GetAngle(arete,OY) iidd = geompy.GetSubShapeID(sol,arete) if angleY==0: longIDS.append(iidd) else: sectIDS.append(iidd) GroupeL = geompy.CreateGroup(sol, geompy.ShapeType["EDGE"]) GroupeS = geompy.CreateGroup(sol, geompy.ShapeType["EDGE"]) geompy.UnionIDs(GroupeL, longIDS) geompy.UnionIDs(GroupeS,sectIDS) GLS.append(GroupeL) GSS.append(GroupeS) ### ### SMESH component ### print '---Maillage' import SMESH, SALOMEDS from salome.smesh import smeshBuilder from salome.StdMeshers import StdMeshersBuilder smesh = smeshBuilder.New(theStudy) Maillage_1 = smesh.Mesh(Eprouv) Regular_1D = Maillage_1.Segment() Local_Length_1 = Regular_1D.LocalLength(0.5,None,1e-07) Quadrangle_2D = Maillage_1.Quadrangle(algo=smeshBuilder.QUADRANGLE) Quadrangle_Parameters_1 = Quadrangle_2D.QuadrangleParameters(StdMeshersBuilder.QUAD_QUADRANGLE_PREF,-1,[],[]) Hexa_3D = Maillage_1.Hexahedron(algo=smeshBuilder.Hexa) SSML=[] SSMS=[] # for gl in GLS: # Regular_1D_1 = Maillage_1.Segment(geom=gl) # Nb_Segments_1 = Regular_1D_1.NumberOfSegments(20) # SSML.append( Regular_1D_1.GetSubMesh()) for gs in GSS: Regular_1D_2 = Maillage_1.Segment(geom=gs) Nb_Segments_2 = Regular_1D_2.NumberOfSegments(8) SSMS.append(Regular_1D_2.GetSubMesh()) isDone = Maillage_1.Compute() coincident_nodes_on_part = Maillage_1.FindCoincidentNodesOnPart( Maillage_1, 1e-05, [], 0 ) Maillage_1.MergeNodes(coincident_nodes_on_part) tol2 = tolerance**2 node_inside_ids = [] for node_id in Maillage_1.GetNodesId(): x, y, z = Maillage_1.GetNodeXYZ(node_id) d=0. #d = (x - the_center[0])**2 d += (y - the_center[1])**2 d += (z - the_center[2])**2 if d < tol2: node_inside_ids.append(node_id) grp = Maillage_1.CreateEmptyGroup(SMESH.NODE, "inside") grp.Add(node_inside_ids) print '---Ecriture du fichier MED' Maillage_1.ExportMED(name, 0, SMESH.MED_V2_2, 1, None ,1)
def __init__(self, object=None, allEdges=False): ''' Construct from the supplied Salome mesh. object - the mesh object (must be a triangular surface mesh). If no object is supplied, the current Salome selection is used. allEdges - If true, all edges on the mesh are included as feature edges, otherwise only edges contained in groups are included NOTE: All face groups are assumed to represent patches. No face subsets are written. All edge groups are added as feature edge subsets. All point groups are added as point subsets. ''' # ============================================================================= # Initialize salome import salome import SMESH, SALOMEDS from salome.smesh import smeshBuilder from operator import itemgetter from collections import OrderedDict import SMESH, SALOMEDS # ============================================================================= # Get the Salome mesh object if object is None: selected = salome.sg.getAllSelected() if len(selected) != 1: raise RuntimeError( 'A single Salome mesh object must be selected.') object = salome.myStudy.FindObjectID(selected[0]).GetObject() try: object.GetMesh() except: raise RuntimeError('Supplied object is not a Salome SMESH mesh.') smesh = smeshBuilder.New(salome.myStudy) mesh = smesh.Mesh(object) print "Converting SMESH Mesh '%s'" % mesh.GetName() # ============================================================================= # Get basic mesh info nNodes = mesh.NbNodes() nFaces = mesh.NbFaces() nTris = mesh.NbTriangles() nEdges = mesh.NbEdges() nodeIds = mesh.GetNodesId() faceIds = mesh.GetElementsByType(SMESH.FACE) edgeIds = mesh.GetElementsByType(SMESH.EDGE) # Check that mesh is strictly triangular if nFaces != nTris: raise RuntimeError('Mesh is not strictly triangular') # Get patch and subset names & ids # All SMESH.FACE groups are assumed to be patches # All SMESH.EDGE groups are assumed to be feature subsets # All SMESH.NODE groups are assumed to be point subsets patches = OrderedDict() pointSubsets = OrderedDict() featureEdgeSubsets = OrderedDict() for group in mesh.GetGroups(): if group.GetType() == SMESH.FACE: patches[group.GetName()] = group.GetIDs() elif group.GetType() == SMESH.EDGE: featureEdgeSubsets[group.GetName()] = group.GetIDs() elif group.GetType() == SMESH.NODE: pointSubsets[group.GetName()] = group.GetIDs() # ============================================================================= # Process faces and patches # Get patchId for each face lastPatchId = len(patches) patchIds = [lastPatchId] * max(faceIds) patchId = 0 for name, ids in patches.iteritems(): for faceId in ids: if patchIds[faceId - 1] == lastPatchId: patchIds[faceId - 1] = patchId else: print "Face %d is assigned to both groups %s and %s" % ( faceId, name, patches.keys()[patchIds[faceId - 1]]) raise RuntimeError( 'Groups of faces are not unique, i.e. they overlap.') patchId += 1 # Compact and reorder patchIds to match faceIds patchIds = [patchIds[faceId - 1] for faceId in faceIds] # Reorder faces by increasing group id faceAndpatchIds = sorted(zip(faceIds, patchIds), key=itemgetter(1)) faceIds, patchIds = zip(*faceAndpatchIds) # Add unused faces to the default patch defaultFaces = [ faceId for faceId, patchId in faceAndpatchIds if patchId == lastPatchId ] if len(defaultFaces) > 0: patches['defaultFaces'] = defaultFaces defaultFaces = None # ============================================================================= # Process feature edges if not allEdges: edgeIds = [] for name, ids in featureEdgeSubsets.iteritems(): edgeIds += ids edgeIds = list(set(edgeIds)) nEdges = len(edgeIds) # Reverse mapping of edge ids since they aren't necessarily numbered 1..nEdges if len(edgeIds): edgeMap = [-1] * max(edgeIds) else: edgeMap = [] i = 0 for edgeId in edgeIds: edgeMap[edgeId - 1] = i i += 1 # ============================================================================= # Process nodes # Reverse mapping of node ids since nodes aren't necessarily numbered 1..nNodes nodeMap = [-1] * max(nodeIds) i = 0 for nodeId in nodeIds: nodeMap[nodeId - 1] = i i += 1 # ============================================================================= self._mesh = mesh self._nodeIds = nodeIds self._edgeIds = edgeIds self._faceIds = faceIds self._nodeMap = nodeMap self._edgeMap = edgeMap self._faceMap = [] self._patches = patches self._pointSubsets = pointSubsets self._featureEdgeSubsets = featureEdgeSubsets self._faceSubsets = {} print 'Done'