コード例 #1
0
    def runSimulation(self):
        """
        This method loads the user input and initialize the simulation engine
        """
        options = {
            'physical_cons': {
                'aggregate_YM': self.aggregate_YM.text(),
                'aggregate_TC': self.aggregate_TC.text(),
                'aggregate_CH': self.aggregate_CH.text(),

                'mastic_YM': self.mastic_YM.text(),
                'mastic_TC': self.mastic_TC.text(),
                'mastic_CH': self.mastic_CH.text(),

                'air_YM': self.air_YM.text(),
                'air_TC': self.air_TC.text(),
                'air_CH': self.air_CH.text(),
            },

            'inputs': {
                'force_input': int(self.mechanicalForceEdit.text()),
                'thermal_steps': int(self.thermalSteps.text()),
            }

        }

        slice_id = int(self.sliderSelected.text())

        # Close the dialog before the simulation starts

        self.progressBar = QtGui.QProgressBar(self)
        self.progressBar.setGeometry(QtCore.QRect(self.window_size))
        self.controller = SimulationController(self.collection, slice_id, **options)

        def onFinished():
            self.progressBar.setRange(0, 1)
            self.progressBar.setValue(1)
            self.progressBar.hide()
            data1, data2 = self.controller.getData()
            output_results1 = Result(data1, "data1")
            output_results1.showResults()
            output_results2 = Result(data2, "data2")
            output_results2.showResults()
            QtGui.QMessageBox.about(self, "Information:",
                                    "Simulation done, results saved at Results folder")

        self.controller.finished.connect(onFinished)
        self.controller.start()
        self.progressBar.show()
        self.progressBar.setRange(0, 0)
コード例 #2
0
class ConfigureSimulationDialog(QtGui.QDialog):
    """
    This dialog enables the user to control the simulation parameters after
    the simulation runs
    """

    def __init__(self, collection):
        super(ConfigureSimulationDialog, self).__init__()

        self.collection = collection
        _, _, self.size_Z = self.collection.shape

        self._initUI()

    def _initUI(self):
        self.title = QtGui.QLabel('<b> Select the vertical slice </b>')

        self.slider = QtGui.QSlider()
        self.slider.setGeometry(QtCore.QRect(120, 380, 321, 31))
        self.slider.setOrientation(QtCore.Qt.Horizontal)
        self.slider.setRange(0, self.size_Z)
        self.slider.valueChanged.connect(self.changeText)

        self.sliderSelected = QtGui.QLineEdit()
        self.sliderSelected.setGeometry(QtCore.QRect(112, 280, 331, 20))

        self.mechanicsLabel = QtGui.QLabel("<b> Young's modulus </b>")
        self.modulusAggregateLabel = QtGui.QLabel("Aggregate:")
        self.modulusMasticLabel = QtGui.QLabel("Mastic:")
        self.modulusAirLabel = QtGui.QLabel("Air voids:")
        self.mechanicalForceLabel = QtGui.QLabel("Applied force: ")

        self.aggregate_YM = QtGui.QLineEdit()
        self.mastic_YM = QtGui.QLineEdit()
        self.air_YM = QtGui.QLineEdit()
        self.mechanicalForceEdit = QtGui.QLineEdit()

        self.thermalLabel = QtGui.QLabel("<b> Thermal conductivity </b>")
        self.thermalAggregateLabel = QtGui.QLabel("Aggregate:")
        self.thermalMasticLabel = QtGui.QLabel("Mastic:")
        self.thermalAirLabel = QtGui.QLabel("Air voids:")

        self.aggregate_TC = QtGui.QLineEdit()
        self.mastic_TC = QtGui.QLineEdit()
        self.air_TC = QtGui.QLineEdit()

        self.chemicalLabel = QtGui.QLabel("<b> Chemical constants </b>")
        self.chemicalAggregateLabel = QtGui.QLabel("Chemical value1:")
        self.chemicalMasticLabel = QtGui.QLabel("Chemical value2:")
        self.chemicalAirLabel = QtGui.QLabel("Chemical value3:")

        self.thermalStepsLabel = QtGui.QLabel("Steps:")
        self.thermalSteps = QtGui.QLineEdit()

        self.aggregate_CH = QtGui.QLineEdit()
        self.mastic_CH = QtGui.QLineEdit()
        self.air_CH = QtGui.QLineEdit()

        self.runSimulationButton = QtGui.QPushButton('Run simulation', self)
        self.runSimulationButton.clicked[bool].connect(self.runSimulation)  # Listener

        self.cancelButton = QtGui.QPushButton('Cancel', self)
        self.cancelButton.clicked[bool].connect(self.closeWindow)

        self.grid = QtGui.QGridLayout()
        self.grid.setSpacing(2)

        self.grid.addWidget(self.title, 0, 0)

        self.grid.addWidget(self.slider, 1, 0)
        self.grid.addWidget(self.sliderSelected, 1, 1)

        self.grid.addWidget(self.mechanicsLabel, 2, 0)
        self.grid.addWidget(self.modulusAggregateLabel, 3, 0)
        self.grid.addWidget(self.aggregate_YM, 3, 1)
        self.grid.addWidget(self.mechanicalForceLabel, 3, 2)
        self.grid.addWidget(self.mechanicalForceEdit, 3, 3)
        self.grid.addWidget(self.modulusMasticLabel, 4, 0)
        self.grid.addWidget(self.mastic_YM, 4, 1)
        self.grid.addWidget(self.modulusAirLabel, 5, 0)
        self.grid.addWidget(self.air_YM, 5, 1)

        # ==============================================================================
        # This graphical elements are commented because modifying those values strongly
        # affect the behavior of the simulation
        # ==============================================================================


        self.grid.addWidget(self.thermalLabel, 6, 0)
        #        self.grid.addWidget(self.thermalAggregateLabel, 7, 0)
        #        self.grid.addWidget(self.aggregate_TC, 7, 1)
        #        self.grid.addWidget(self.thermalMasticLabel, 8, 0)
        #        self.grid.addWidget(self.mastic_TC, 8, 1)
        #        self.grid.addWidget(self.thermalAirLabel, 9, 0)
        #        self.grid.addWidget(self.air_TC, 9, 1)
        self.grid.addWidget(self.thermalStepsLabel, 7, 1)
        self.grid.addWidget(self.thermalSteps, 7, 2)

        #        self.grid.addWidget(self.chemicalLabel, 10, 0)
        #        self.grid.addWidget(self.chemicalAggregateLabel, 11, 0)
        #        self.grid.addWidget(self.aggregate_CH, 11, 1)
        #        self.grid.addWidget(self.chemicalMasticLabel, 12, 0)
        #        self.grid.addWidget(self.mastic_CH, 12, 1)
        #        self.grid.addWidget(self.chemicalAirLabel, 13, 0)
        #        self.grid.addWidget(self.air_CH, 13, 1)

        self.grid.addWidget(self.runSimulationButton, 14, 1)
        self.grid.addWidget(self.cancelButton, 14, 2)

        self.setLayout(self.grid)
        self.setGeometry(10, 35, 560, 520)

        window_size = self.geometry()
        left = window_size.left()
        right = window_size.right() - 500
        top = window_size.top() + 200
        bottom = window_size.bottom() - 20

        self.window_size = QtCore.QRect(left, top, bottom, right)
        self.setWindowTitle('Configure Simulation')
        self.setDefaultValues()
        self.show()

    def closeWindow(self):
        self.close()

    def changeText(self, value):
        self.z = value
        self.sliderSelected.setText(str(self.z))

    def setDefaultValues(self):
        """
        This method writes default test values over the configuration dialog
        """
        E2 = 21000000
        E1 = 10000000
        E0 = 100

        conductAsphalt = 0.75
        conductRock = 7.8
        conductAir = 0.026

        steps = 10000
        target_slice = self.size_Z / 2

        mechanical_force = 800

        self.aggregate_YM.setText(str(E2))
        self.mastic_YM.setText(str(E1))
        self.air_YM.setText(str(E0))
        self.aggregate_TC.setText(str(conductRock))
        self.mastic_TC.setText(str(conductAsphalt))
        self.air_TC.setText(str(conductAir))
        self.thermalSteps.setText(str(steps))
        self.mechanicalForceEdit.setText(str(mechanical_force))
        self.sliderSelected.setText(str(target_slice))
        self.aggregate_CH.setText('Chem Aggregate')
        self.mastic_CH.setText('Chem Mastic')
        self.air_CH.setText('Chem Air')

    def runSimulation(self):
        """
        This method loads the user input and initialize the simulation engine
        """
        options = {
            'physical_cons': {
                'aggregate_YM': self.aggregate_YM.text(),
                'aggregate_TC': self.aggregate_TC.text(),
                'aggregate_CH': self.aggregate_CH.text(),

                'mastic_YM': self.mastic_YM.text(),
                'mastic_TC': self.mastic_TC.text(),
                'mastic_CH': self.mastic_CH.text(),

                'air_YM': self.air_YM.text(),
                'air_TC': self.air_TC.text(),
                'air_CH': self.air_CH.text(),
            },

            'inputs': {
                'force_input': int(self.mechanicalForceEdit.text()),
                'thermal_steps': int(self.thermalSteps.text()),
            }

        }

        slice_id = int(self.sliderSelected.text())

        # Close the dialog before the simulation starts

        self.progressBar = QtGui.QProgressBar(self)
        self.progressBar.setGeometry(QtCore.QRect(self.window_size))
        self.controller = SimulationController(self.collection, slice_id, **options)

        def onFinished():
            self.progressBar.setRange(0, 1)
            self.progressBar.setValue(1)
            self.progressBar.hide()
            data1, data2 = self.controller.getData()
            output_results1 = Result(data1, "data1")
            output_results1.showResults()
            output_results2 = Result(data2, "data2")
            output_results2.showResults()
            QtGui.QMessageBox.about(self, "Information:",
                                    "Simulation done, results saved at Results folder")

        self.controller.finished.connect(onFinished)
        self.controller.start()
        self.progressBar.show()
        self.progressBar.setRange(0, 0)