SHARE
TWEET

Untitled

a guest Jan 3rd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Form implementation generated from reading ui file 'okno.ui'
  4. #
  5. # Created by: PyQt5 UI code generator 5.10.1
  6. #
  7. # WARNING! All changes made in this file will be lost!
  8.  
  9. from PyQt5 import QtCore, QtGui, QtWidgets
  10. from PyQt5.QtWidgets import QMessageBox
  11. import pyqtgraph as pg
  12. import matplotlib.pyplot as plt
  13. from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  14. from math import tan, cos, pi, sqrt, sin,exp, fabs, atan
  15. import numpy as np
  16.  
  17.  
  18. class Ui_MainWindow(object):
  19.     def setupUi(self, MainWindow):
  20.         MainWindow.setObjectName("MainWindow")
  21.         MainWindow.resize(700, 500)
  22.         self.centralwidget = QtWidgets.QWidget(MainWindow)
  23.         self.centralwidget.setObjectName("centralwidget")
  24.         self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
  25.         self.tableWidget.setGeometry(QtCore.QRect(30, 10, 650, 520))
  26.         self.tableWidget.setObjectName("tableWidget")
  27.         self.tableWidget.setColumnCount(0)
  28.         self.tableWidget.setRowCount(0)
  29.         self.pushButton = QtWidgets.QPushButton(self.centralwidget)
  30.         self.pushButton.setGeometry(QtCore.QRect(350, 450, 89, 25))
  31.         self.pushButton.setObjectName("pushButton")
  32.         self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
  33.         self.lineEdit_2.setGeometry(QtCore.QRect(350, 130, 113, 25))
  34.         self.lineEdit_2.setObjectName("lineEdit_2")
  35.         self.lineEdit_2.setText("50")
  36.         self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
  37.         self.lineEdit_3.setGeometry(QtCore.QRect(350, 160, 113, 25))
  38.         self.lineEdit_3.setObjectName("lineEdit_3")
  39.         self.lineEdit_3.setText("0.59")
  40.         self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
  41.         self.lineEdit_4.setGeometry(QtCore.QRect(350, 190, 113, 25))
  42.         self.lineEdit_4.setObjectName("lineEdit_4")
  43.         self.lineEdit_4.setText("1.65")
  44.         self.label_2 = QtWidgets.QLabel(self.centralwidget)
  45.         self.label_2.setGeometry(QtCore.QRect(270, 130, 67, 17))
  46.         self.label_2.setObjectName("label_2")
  47.         self.label_3 = QtWidgets.QLabel(self.centralwidget)
  48.         self.label_3.setGeometry(QtCore.QRect(80, 160, 241, 21))
  49.         self.label_3.setObjectName("label_3")
  50.         self.label_4 = QtWidgets.QLabel(self.centralwidget)
  51.         self.label_4.setGeometry(QtCore.QRect(40, 180, 331, 41))
  52.         self.label_4.setObjectName("label_4")
  53.         self.label_5 = QtWidgets.QLabel(self.centralwidget)
  54.         self.label_5.setGeometry(QtCore.QRect(80, 40, 571, 31))
  55.         self.label_5.setObjectName("label_5")
  56.         self.label_7 = QtWidgets.QLabel(self.centralwidget)
  57.         self.label_7.setGeometry(QtCore.QRect(126, 220, 211, 20))
  58.         self.label_7.setObjectName("label_7")
  59.         self.label_9 = QtWidgets.QLabel(self.centralwidget)
  60.         self.label_9.setGeometry(QtCore.QRect(196, 260, 141, 20))
  61.         self.label_9.setObjectName("label_9")
  62.         self.label_10 = QtWidgets.QLabel(self.centralwidget)
  63.         self.label_10.setGeometry(QtCore.QRect(116, 300, 211, 21))
  64.         self.label_10.setObjectName("label_10")
  65.         self.label_11 = QtWidgets.QLabel(self.centralwidget)
  66.         self.label_11.setGeometry(QtCore.QRect(116, 340, 211, 21))
  67.         self.label_11.setObjectName("label_11")
  68.         self.label_12 = QtWidgets.QLabel(self.centralwidget)
  69.         self.label_12.setGeometry(QtCore.QRect(116, 380, 211, 21))
  70.         self.label_12.setObjectName("label_12")
  71.         self.lineEdit_6 = QtWidgets.QLineEdit(self.centralwidget)
  72.         self.lineEdit_6.setGeometry(QtCore.QRect(350, 220, 113, 25))
  73.         self.lineEdit_6.setObjectName("lineEdit_6")
  74.         self.lineEdit_6.setText("0.002")
  75.         self.lineEdit_8 = QtWidgets.QLineEdit(self.centralwidget)
  76.         self.lineEdit_8.setGeometry(QtCore.QRect(350, 260, 113, 25))
  77.         self.lineEdit_8.setObjectName("lineEdit_8")
  78.         self.lineEdit_8.setText("0")
  79.         self.lineEdit_9 = QtWidgets.QLineEdit(self.centralwidget)
  80.         self.lineEdit_9.setGeometry(QtCore.QRect(350, 300, 113, 25))
  81.         self.lineEdit_9.setObjectName("lineEdit_9")
  82.         self.lineEdit_9.setText("500")
  83.         self.lineEdit_10 = QtWidgets.QLineEdit(self.centralwidget)
  84.         self.lineEdit_10.setGeometry(QtCore.QRect(350, 340, 113, 25))
  85.         self.lineEdit_10.setObjectName("lineEdit_10")
  86.         self.lineEdit_11 = QtWidgets.QLineEdit(self.centralwidget)
  87.         self.lineEdit_11.setGeometry(QtCore.QRect(350, 380, 113, 25))
  88.         self.lineEdit_11.setObjectName("lineEdit_11")
  89.         self.lineEdit_11.setText("0.1")
  90.         self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
  91.         self.pushButton_2.setGeometry(QtCore.QRect(250, 450, 89, 25))
  92.         self.pushButton_2.setObjectName("pushButton_2")
  93.         MainWindow.setCentralWidget(self.centralwidget)
  94.         self.menubar = QtWidgets.QMenuBar(MainWindow)
  95.         self.menubar.setGeometry(QtCore.QRect(0, 0, 500, 22))
  96.         self.menubar.setObjectName("menubar")
  97.         MainWindow.setMenuBar(self.menubar)
  98.         self.statusbar = QtWidgets.QStatusBar(MainWindow)
  99.         self.statusbar.setObjectName("statusbar")
  100.         MainWindow.setStatusBar(self.statusbar)
  101.  
  102.         self.retranslateUi(MainWindow)
  103.         QtCore.QMetaObject.connectSlotsByName(MainWindow)
  104.         self.pushButton.clicked.connect(self.buttonClicked)
  105.  
  106.     def retranslateUi(self, MainWindow):
  107.         _translate = QtCore.QCoreApplication.translate
  108.         MainWindow.setWindowTitle(_translate("MainWindow", "Электронная пушка"))
  109.         self.pushButton.setText(_translate("MainWindow", "ОК"))
  110.         self.label_2.setText(_translate("MainWindow", "Длина:"))
  111.         self.label_3.setText(_translate("MainWindow", "Коэффициент теплопроводности:"))
  112.         self.label_4.setText(_translate("MainWindow", "Коэффициент объёмной теплоёмкости:"))
  113.         self.label_5.setText(_translate("MainWindow", "Процесс остывания корпуса электронной пушки"))
  114.         self.label_7.setText(_translate("MainWindow", "Коэффициент теплоотдачи:"))
  115.         self.label_9.setText(_translate("MainWindow", "Момент времени:"))
  116.         self.label_10.setText(_translate("MainWindow", "Колличество слагаемых ряда:"))
  117.         self.label_11.setText(_translate("MainWindow", "Погрешность:"))
  118.         self.label_12.setText(_translate("MainWindow", "Толщина стенки трубки:"))
  119.         self.pushButton_2.setText(_translate("MainWindow", "Закрыть"))
  120.  
  121.     def buttonClicked(self):
  122.         er = True
  123.         err = ""
  124.        erre = ""
  125.         errn = ""
  126.        try:
  127.            L = float(self.lineEdit_2.text())
  128.        except:
  129.            err += "L введено неправильно \n"
  130.        try:
  131.            k = float(self.lineEdit_3.text())
  132.        except:
  133.            err += "k введено неправильно \n"
  134.        try:
  135.            c = float(self.lineEdit_4.text())
  136.        except:
  137.            err += "с введено неправильно \n"
  138.        try:
  139.            d = float(self.lineEdit_11.text())
  140.        except:
  141.            err += "d введено неправильно \n"
  142.        try:
  143.            a = float(self.lineEdit_6.text())
  144.        except:
  145.            err += "a введено неправильно \n"
  146.        #u_c = float(self.lineEdit_7.text())
  147.        try:
  148.            t = float(self.lineEdit_8.text())
  149.        except:
  150.            err += "t введено неправильно \n"
  151.        try:
  152.            n = int(self.lineEdit_9.text())
  153.        except:
  154.            errn += "n введено неправильно \n"
  155.        try:
  156.            eps = float(self.lineEdit_10.text())
  157.        except:
  158.            erre += "Погрешность введена неправильно \n"
  159.  
  160.        if (len(errn) != 0 and len(erre) != 0):
  161.            er = False
  162.            QMessageBox.about(gun, "Ошибка", erre)
  163.  
  164.        if len(err) != 0:
  165.            er = False
  166.            QMessageBox.about(gun, "Ошибка", err)
  167.        def nubmer_sum(n,L,a,t,c,k):
  168.            return (2*L*c*exp(-2*a*t/(c*d))*exp((-(pi*(1+2*n)/(2*L))**2)*k*t*c))/(pi*pi*((1 + 2*(n+1))**2)*k*t)
  169.        
  170.        def series_sum(L,k,c,a,t,n,z):
  171.            sum = 0
  172.            for i in range(n):
  173.                sum = sum + sin(pi*(1+2*i)/4)*(4/(pi*(1+2*i)))*cos(z*pi*(1+2*i)/(2*L))*exp(-((2*a/(k*d) + (pi*(1+2*i)/(2*L))**2)*k*t)/c)
  174.            return sum
  175.  
  176.        if er == True:
  177.            if t != 0:
  178.                if len(erre) == 0:
  179.                    i = 0;
  180.                    while nubmer_sum(i,L,a,t,c,k) > eps:
  181.                        i = i + 1
  182.                    self.lineEdit_9.setText("%.i" % i)
  183.                    n = i
  184.                    print(n)
  185.                elif len(erre) != 0 and len(errn) != 0:
  186.                    erre += "Погрешность введена неправильно; \n"
  187.                    QMessageBox.about(gun, "Ошибка", erre)
  188.            if t == 0 and len(erre) == 0:
  189.                err += "Оценка остатка ряда расходится; \n"
  190.                QMessageBox.about(gun, "Ошибка", err)
  191.  
  192.            if len(err) != 0 and len(errn) != 0:
  193.                er = False
  194.                QMessageBox.about(gun, "Ошибка", err)
  195.            
  196.            if er == True:
  197.                arr = np.linspace(0, L, 500).tolist()
  198.                fourier_arr=[]
  199.                for elem in arr:
  200.                    fourier_arr.append(series_sum(L,k,c,a,t,n, elem))
  201.                fig, ax = plt.subplots()
  202.                ax.plot(arr, fourier_arr, color="red", label="Распределение Температуры")
  203.                ax.set_xlabel("Длина трубки")
  204.                ax.set_ylabel("w(x,t)")
  205.                plt.grid()
  206.                plt.show(True)
  207.  
  208.  
  209.  
  210. if __name__ == "__main__":
  211.    import sys
  212.    app = QtWidgets.QApplication(sys.argv)
  213.    gun = QtWidgets.QMainWindow()
  214.    ui = Ui_MainWindow()
  215.    ui.setupUi(gun)
  216.    gun.show()
  217.    sys.exit(app.exec_())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top