def __init__(self,parent=None): super(MainWindow,self).__init__(parent) self.setupUi(self) self.syst=DynSystem() self.nodes_spinBox.setValue(self.syst.n_nodes) self.nodes_spinBox.setMinimum(2) self.ResExplorer=ResultExplorer() #initialize tables self.ConnTableRowCount,self.MassTableRowCount,self.DispTableRowCount,self.ForceTableRowCount=0,0,0,0 self.initTables([self.ConnTable,self.MassTable,self.DispTable,self.ForceTable,self.tableWidgetInitCon]) self.connect(self.actionSave, SIGNAL("triggered()"), self.fileSave) self.connect(self.actionOpen, SIGNAL("triggered()"), self.fileOpen) self.comboBoxPeaks.setCurrentIndex(1)
class MainWindow(QMainWindow,oddsFormMain.Ui_MainWindow): def __init__(self,parent=None): super(MainWindow,self).__init__(parent) self.setupUi(self) self.syst=DynSystem() self.nodes_spinBox.setValue(self.syst.n_nodes) self.nodes_spinBox.setMinimum(2) self.ResExplorer=ResultExplorer() #initialize tables self.ConnTableRowCount,self.MassTableRowCount,self.DispTableRowCount,self.ForceTableRowCount=0,0,0,0 self.initTables([self.ConnTable,self.MassTable,self.DispTable,self.ForceTable,self.tableWidgetInitCon]) self.connect(self.actionSave, SIGNAL("triggered()"), self.fileSave) self.connect(self.actionOpen, SIGNAL("triggered()"), self.fileOpen) self.comboBoxPeaks.setCurrentIndex(1) def fileSave(self): fname = unicode(QFileDialog.getSaveFileName(self,"ODDS - Choose File Name", "system.ods","ODDS files (*.ods);;All files (*.* *)")) if fname=="": return try: pickle.dump(self.syst, open(fname, 'wb')) except: QMessageBox.warning(self, "Error","File was not saved") def fileOpen(self): fname = unicode(QFileDialog.getOpenFileName(self,"ODDS - Choose File Name", "","ODDS files (*.ods);;All files (*.* *)")) if fname=="": return try: self.syst=pickle.load(file(fname)) self.update_interface() except: QMessageBox.warning(self, "Error","File was not opened") def initTables(self,tables): for table in tables: table.setAlternatingRowColors(True) table.setEditTriggers(QTableWidget.NoEditTriggers) table.setSelectionBehavior(QTableWidget.SelectRows) table.setSelectionMode(QTableWidget.SingleSelection) #def on_lineEdit_DispInit_returnPressed(self): @pyqtSignature("QString") def on_lineEdit_DispInit_textEdited(self,string1): #print "changed, displ" self.SetInit() # print "\n Displacement DOF 0" # print self.syst.initDisp[0][self.syst.DOF[0]] # print "\n Displacement DOF 1" # print self.syst.initDisp[0][self.syst.DOF[1]] #def on_lineEdit_VelInit_returnPressed(self): @pyqtSignature("QString") def on_lineEdit_VelInit_textEdited(self,string1): self.SetInit() # print "\n Velocity DOF 0" # print self.syst.initVel[0][self.syst.DOF[0]] # print "\n Velocity DOF 1" # print self.syst.initVel[0][self.syst.DOF[1]] @pyqtSignature("int") def on_tabWidget_currentChanged(self,index): if index==1: self.syst.prepare_system() if len(self.syst.DOF)==0: return self.comboBox_DOF.clear() for i in self.syst.DOF: self.comboBox_DOF.addItem(str(i+1)) self.update_init_cond_list() self.on_comboBox_DOF_currentIndexChanged(0) @pyqtSignature("int") def on_comboBox_DOF_currentIndexChanged(self,index): # print "\n changing Displacement DOF 0" # print self.syst.initDisp[0][self.syst.DOF[0]] # print "\n Changing Displacement DOF 1" # print self.syst.initDisp[0][self.syst.DOF[1]] # print "\n Changing Velocity DOF 0" # print self.syst.initVel[0][self.syst.DOF[0]] # print "\n Changing Velocity DOF 1" # print self.syst.initVel[0][self.syst.DOF[1]] currentDOF=index self.lineEdit_DispInit.setText(str(self.syst.initDisp[0][self.syst.DOF[currentDOF]])) self.lineEdit_VelInit.setText(str(self.syst.initVel[0][self.syst.DOF[currentDOF]])) @pyqtSignature("") def SetInit(self): currentDOF=self.comboBox_DOF.currentIndex() Disp=self.lineEdit_DispInit.text().toFloat()[0] Vel=self.lineEdit_VelInit.text().toFloat()[0] self.syst.initDisp[0][self.syst.DOF[currentDOF]]=Disp self.syst.initVel[0][self.syst.DOF[currentDOF]]=Vel self.update_init_cond_list() def update_init_cond_list(self): length=len(self.syst.DOF) self.tableWidgetInitCon.clearContents() self.tableWidgetInitCon.setRowCount(length) for i in range(0,length): print i, self.syst.DOF[i], self.tableWidgetInitCon.setItem(i,0,QTableWidgetItem(str(self.syst.DOF[i]+1))) self.tableWidgetInitCon.setItem(i,1,QTableWidgetItem(str(self.syst.initDisp[0][self.syst.DOF[i]]))) self.tableWidgetInitCon.setItem(i,2,QTableWidgetItem(str(self.syst.initVel[0][self.syst.DOF[i]]))) self.tableWidgetInitCon.resizeColumnsToContents() self.tableWidgetInitCon.resizeRowsToContents() @pyqtSignature("") def on_pushButton_Solve_clicked(self): #self.syst.prepare_system() self.ResExplorer.clear() Npoints,res=0,0 Npeaks=self.lineEdit_Npeaks.text().toFloat()[0] NpeaskSS=self.lineEdit_NpeaksSS.text().toFloat()[0] init_con=self.syst.form_init_conditions() print init_con #init_con=[0]*len(self.syst.DOF)*2 if self.radioButton_constantNpeak.isChecked(): Npoints=self.lineEdit_constNpeak.text().toFloat()[0] else: N=self.lineEdit_varNpeak.text().toFloat()[0] if N!=0: res=1.0/N if self.radioButton_SingleFreq.isChecked(): start_time=self.lineStartTime.text().toFloat()[0] freq=self.lineEdit_SingleFreq.text().toFloat()[0] if self.comboBoxPeaks.currentIndex()==1: Npeaks=Npeaks*freq self.syst.form_displacement_functions(Npeaks/freq,freq,10000,start_time) t,result=self.syst.solve_for_frequency(freq,init_con,Npeaks,Npoints,res,start_time) self.syst.find_natural_frequencies() for i in range(0,len(self.syst.DOF)): self.ResExplorer.add_result("Displacement - node #"+str(self.syst.DOF[i]), t, result[i*2], "Time [sec]", "Displacement") self.ResExplorer.add_result("Velocity - node # "+str(self.syst.DOF[i]), t, result[i*2+1], "Time [sec]", "Velocity") self.ResExplorer.add_custom_text("Undamped frequency Wn"+str(i)+" = "+str(self.syst.nat_freq[i])) self.ResExplorer.add_custom_text("Undamped mode shape M"+str(i)+" = "+str(self.syst.mode_shapes[i])) for i in range(0,len(self.syst.displacements)): if self.syst.displacements[i]!=-1: vel_base,disp_base=[],[] for time in t: xj,vj=self.syst.displacements[i].getValue(freq*2*pi,time) disp_base.append(xj);vel_base.append(vj) self.ResExplorer.add_result("Displacement (base) - node #"+str(i), t, disp_base, "Time [sec]", "Displacement") self.ResExplorer.add_result("Velocity (base) - node #"+str(i), t, vel_base, "Time [sec]", "Velocity") self.syst.find_natural_frequencies() # plt.figure() # plt.plot(t,result[0]) # plt.show() else: start=self.lineEdit_FreqStart.text().toFloat()[0] stop=self.lineEdit_FreqStop.text().toFloat()[0] step=self.lineEdit_FreqStep.text().toFloat()[0] frequency,response=self.syst.frequency_sweep(start,stop,step,self.progressBar_Solution,NpeaskSS,Npeaks,Npoints,res) for i in range(0,len(self.syst.DOF)): self.ResExplorer.add_result("Displacement - node #"+str(self.syst.DOF[i]), frequency, response[i*2], "Frequency [Hz]", "Displacement") self.ResExplorer.add_result("Velocity - node # "+str(self.syst.DOF[i]), frequency, response[i*2+1], "Frequency [Hz]", "Velocity") # # plt.figure() # plt.plot(frequency,response[0]) # plt.show() self.ResExplorer.set_default_result(0) self.ResExplorer.show() @pyqtSignature("") def on_testODE_clicked(self): pickle.dump(self.syst, open('system.out', 'wb')) self.syst.omega=5 print "A =",self.syst.omega self.syst=pickle.load(file("system.out")) print "B=",self.syst.omega @pyqtSignature("") def on_ForceAddButton_clicked(self): available_nodes=self.syst.get_available_force_nodes() if len(available_nodes)==0: QMessageBox.warning(self, "Error","Define masses first") return F=Force() if F.configure(available_nodes): self.syst.addForce(available_nodes[F.node],F) self.ForceTableRowCount=self.ForceTableRowCount+1 self.ForceTable.setRowCount(self.ForceTableRowCount) self.setForceTableData(self.ForceTableRowCount-1,F,available_nodes[F.node]) def update_interface(self): tables=[self.ConnTable,self.MassTable,self.DispTable,self.ForceTable,self.tableWidgetInitCon] for table in tables: table.clearContents() table.update() m_row,f_row,d_row,c_row=1,1,1,1 self.ConnTableRowCount,self.MassTableRowCount,self.DispTableRowCount,self.ForceTableRowCount=0,0,0,0 for i in range(0,self.syst.n_nodes): c_mass=self.syst.masses[0][i] c_disp=self.syst.displacements[i] c_force=self.syst.forces[i] if c_mass!=0: self.MassTable.setRowCount(m_row) self.setMassTableData(m_row-1,c_mass,i) m_row=m_row+1 if c_disp!=-1: self.DispTable.setRowCount(d_row) self.setDispTableData(d_row-1, c_disp, i) d_row=d_row+1 if c_force!=-1: self.ForceTable.setRowCount(f_row) self.setForceTableData(f_row-1, c_force, i) f_row=f_row+1 for j in range(i+1,self.syst.n_nodes): if self.syst.springs[i][j]!=0: self.ConnTable.setRowCount(c_row) self.setConnTableData(c_row-1, 0, i, j, self.syst.springs[i][j]) c_row=c_row+1 if self.syst.dampers[i][j]!=0: self.ConnTable.setRowCount(c_row) self.setConnTableData(c_row-1, 1, i, j, self.syst.dampers[i][j]) c_row=c_row+1 self.ConnTableRowCount,self.MassTableRowCount,self.DispTableRowCount,self.ForceTableRowCount=c_row-1,m_row-1,d_row-1,f_row-1 @pyqtSignature("") def on_ForceEditButton_clicked(self): if self.ForceTable.hasFocus(): if self.ForceTableRowCount==0: return row=self.ForceTable.currentRow() node=self.ForceTable.item(row,0).text().toInt()[0] available_nodes=self.syst.get_available_force_nodes() available_nodes.append(node-1) available_nodes.sort() F=self.syst.forces[node-1] if F.configure(available_nodes,available_nodes.index(node-1)+1): self.syst.addForce(node-1, delete_flag=1) self.syst.addForce(available_nodes[F.node], F) self.setForceTableData(row, F,available_nodes[F.node]) @pyqtSignature("") def on_ForceDeleteButton_clicked(self): if self.ForceTable.hasFocus(): if self.ForceTableRowCount==0: return row=self.ForceTable.currentRow() node=self.ForceTable.item(row,0).text().toInt()[0] self.syst.addForce(node-1,delete_flag=1) self.ForceTableRowCount=self.ForceTableRowCount-1 self.ForceTable.removeRow(row) else: QMessageBox.information(self, "Note","Please select item at force table") @pyqtSignature("") def on_DispAddButton_clicked(self): available_nodes=self.syst.get_available_mass_nodes() if len(available_nodes)==0: QMessageBox.warning(self, "Error","No more available nodes for displacements") return Disp=Displacement(available_nodes) if Disp.configure(available_nodes): print Disp.node self.syst.addDisplacement(available_nodes[Disp.node], Disp) self.DispTableRowCount=self.DispTableRowCount+1 self.DispTable.setRowCount(self.DispTableRowCount) self.setDispTableData(self.DispTableRowCount-1, Disp,available_nodes[Disp.node]) def setForceTableData(self,row,F,node): func=F.custFunc.supported[F.custFunc.type] value=F.custFunc.getString() self.ForceTable.setItem(row,0,QTableWidgetItem(str(node+1))) self.ForceTable.setItem(row,1,QTableWidgetItem(func)) self.ForceTable.setItem(row,2,QTableWidgetItem(value)) self.ForceTable.resizeColumnsToContents() self.ForceTable.resizeRowsToContents() @pyqtSignature("") def on_DispEditButton_clicked(self): if self.DispTable.hasFocus(): if self.DispTableRowCount==0: return row=self.DispTable.currentRow() node=self.DispTable.item(row,0).text().toInt()[0] available_nodes=self.syst.get_available_mass_nodes() available_nodes.append(node-1) available_nodes.sort() Displacement=self.syst.displacements[node-1] if Displacement.configure(available_nodes,available_nodes.index(node-1)+1): self.syst.addDisplacement(node-1, delete_flag=1) self.syst.addDisplacement(available_nodes[Displacement.node], Displacement) self.setDispTableData(row, Displacement,available_nodes[Displacement.node]) @pyqtSignature("") def on_DispDelButton_clicked(self): if self.DispTable.hasFocus(): if self.DispTableRowCount==0: return row=self.DispTable.currentRow() node=self.DispTable.item(row,0).text().toInt()[0] self.syst.addDisplacement(node-1,delete_flag=1) self.DispTableRowCount=self.DispTableRowCount-1 self.DispTable.removeRow(row) else: QMessageBox.information(self, "Note","Please select item at mass or displacement table") def setDispTableData(self,row,Disp,node): func={1:'0',2:Disp.custFunc.supported[Disp.custFunc.type]}[Disp.funcType] type1={1:'Displacement',2:Disp.supportedMovement[Disp.movementType]}[Disp.funcType] value={1:'0',2:Disp.custFunc.getString()}[Disp.funcType] self.DispTable.setItem(row,0,QTableWidgetItem(str(node+1))) self.DispTable.setItem(row,1,QTableWidgetItem(type1)) self.DispTable.setItem(row,2,QTableWidgetItem(func)) self.DispTable.setItem(row,3,QTableWidgetItem(value)) self.DispTable.resizeColumnsToContents() self.DispTable.resizeRowsToContents() @pyqtSignature("") def on_MassAddButton_clicked(self): available_mass_nodes=self.syst.get_available_mass_nodes() if len(available_mass_nodes)==0: QMessageBox.warning(self, "Error","No more available nodes for masses") return MassDlg=MassDialog(available_mass_nodes) if MassDlg.exec_(): index1,value1=MassDlg.retrieve_data() node=available_mass_nodes[index1] self.syst.addMass(node,value1) self.MassTableRowCount=self.MassTableRowCount+1 self.MassTable.setRowCount(self.MassTableRowCount) self.setMassTableData(self.MassTableRowCount-1, value1, node) @pyqtSignature("") def on_MassDeleteButton_clicked(self): if self.MassTable.hasFocus(): if self.MassTableRowCount==0: return row=self.MassTable.currentRow() node,value1=self.getMassTableData(row) self.syst.addMass(node-1,delete_flag=1) self.MassTableRowCount=self.MassTableRowCount-1 self.MassTable.removeRow(row) else: QMessageBox.information(self, "Note","Please select item at mass or displacement table") @pyqtSignature("") def on_MassEditButton_clicked(self): if self.MassTable.hasFocus(): if self.MassTableRowCount==0: return row=self.MassTable.currentRow() node,value1=self.getMassTableData(row) available_mass_nodes=self.syst.get_available_mass_nodes() available_mass_nodes.append(node-1) available_mass_nodes.sort() node_no=available_mass_nodes.index(node-1) MassDlg=MassDialog(available_mass_nodes,value1=value1,current_node=node_no) if MassDlg.exec_(): index1,value1=MassDlg.retrieve_data() self.syst.addMass(node-1,delete_flag=1) node=available_mass_nodes[index1] self.syst.addMass(node,value1) self.setMassTableData(row,value1,node) @pyqtSignature("") def on_ConnAddButton_clicked(self): self.syst.find_natural_frequencies() nat_freq,masses=[],[] if len(self.syst.DOF)>0: nat_freq,masses=self.syst.nat_freq, self.syst.masses[0][self.syst.DOF] AddEditConnDlg=AddEditConnDialog(0,0,self.syst.n_nodes,nat_freq,masses) if AddEditConnDlg.exec_(): type1,start,end,value=AddEditConnDlg.retrieve_data() self.syst.addConnector(type1, start, end, value) self.ConnTableRowCount=self.ConnTableRowCount+1 self.ConnTable.setRowCount(self.ConnTableRowCount) self.setConnTableData(self.ConnTableRowCount-1, type1, start, end, value) #self.ConnTable.resizeColumnsToContents() @pyqtSignature("") def on_ConnEditButton_clicked(self): if self.ConnTable.hasFocus(): if self.ConnTableRowCount==0: return row=self.ConnTable.currentRow() start,end,type1,old_value=self.getConnTableData(row) self.syst.find_natural_frequencies() nat_freq,masses=[],[] if len(self.syst.DOF)>0: nat_freq,masses=self.syst.nat_freq, self.syst.masses[0][self.syst.DOF] AddEditConnDlg=AddEditConnDialog(type1,old_value,self.syst.n_nodes,nat_freq,masses,start-1,end-1) old_type,old_start,old_end=type1,start,end if AddEditConnDlg.exec_(): type1,start,end,value=AddEditConnDlg.retrieve_data() if old_type!=type1: self.syst.addConnector(old_type, old_start-1, old_end-1, 0,1,old_value) self.syst.addConnector(type1, start, end, value,0,old_value) else: self.syst.addConnector(type1, start, end, value,1,old_value) self.setConnTableData(row, type1, start, end, value) # print start,end,type1,old_value @pyqtSignature("") def on_ConnDelButton_clicked(self): if self.ConnTable.hasFocus(): if self.ConnTableRowCount==0: return row=self.ConnTable.currentRow() start,end,type1,old_value=self.getConnTableData(row) self.syst.addConnector(type1, start-1, end-1, -old_value) self.ConnTableRowCount=self.ConnTableRowCount-1 self.ConnTable.removeRow(row) else: QMessageBox.information(self, "Note","Please select item from connection table") def getConnTableData(self,row): start=self.ConnTable.item(row,0).text().toInt()[0] end=self.ConnTable.item(row,1).text().toInt()[0] type1=1 if self.ConnTable.item(row,2).text()=="Spring": type1=0 value=self.ConnTable.item(row,3).text().toFloat()[0] return start,end,type1,value def setConnTableData(self,row,type1,start,end,value): self.ConnTable.setItem(row,0,QTableWidgetItem(str(start+1))) self.ConnTable.setItem(row,1,QTableWidgetItem(str(end+1))) type_string=QString("Spring") if type1: type_string=QString("Damper") self.ConnTable.setItem(row,2,QTableWidgetItem(type_string)) self.ConnTable.setItem(row,3,QTableWidgetItem(str(value))) self.ConnTable.resizeRowsToContents() def getMassTableData(self,row): node=self.MassTable.item(row,0).text().toInt()[0] value1=self.MassTable.item(row,1).text().toFloat()[0] return node, value1 def setMassTableData(self,row,value1,node): self.MassTable.setItem(row,0,QTableWidgetItem(str(node+1))) self.MassTable.setItem(row,1,QTableWidgetItem(str(value1))) self.MassTable.resizeRowsToContents() @pyqtSignature("") def on_printSyst_clicked(self): print "masses=",self.syst.masses print "displacements=",self.syst.displacements print "forces=",self.syst.forces print "springs=",self.syst.springs print "dampers=",self.syst.dampers print "initDisp",self.syst.initDisp print "initVel",self.syst.initVel self.syst.find_natural_frequencies() print "K_matrix",self.syst.K_matrix print "M_matrix",self.syst.M_matrix @pyqtSignature("int") def on_nodes_spinBox_valueChanged(self,value): self.syst.ChangeSize(value) self.update_interface()