fictive cp and tnmh model

This commit is contained in:
Dominik Demuth 2023-06-01 20:09:11 +02:00
parent eb1e657dab
commit edc6af2762
3 changed files with 195 additions and 122 deletions

View File

@ -17,19 +17,27 @@ class Ui_Dialog(object):
Dialog.resize(1176, 714) Dialog.resize(1176, 714)
self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout") self.gridLayout.setObjectName("gridLayout")
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 2, 3, 1, 1)
self.graphicsView = PlotWidget(Dialog) self.graphicsView = PlotWidget(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth())
self.graphicsView.setSizePolicy(sizePolicy) self.graphicsView.setSizePolicy(sizePolicy)
self.graphicsView.setObjectName("graphicsView") self.graphicsView.setObjectName("graphicsView")
self.gridLayout.addWidget(self.graphicsView, 0, 3, 1, 1) self.gridLayout.addWidget(self.graphicsView, 0, 3, 1, 1)
self.graphicsView_2 = PlotWidget(Dialog)
self.graphicsView_2.setObjectName("graphicsView_2")
self.gridLayout.addWidget(self.graphicsView_2, 1, 3, 1, 1)
self.formLayout = QtWidgets.QFormLayout() self.formLayout = QtWidgets.QFormLayout()
self.formLayout.setObjectName("formLayout") self.formLayout.setObjectName("formLayout")
self.label = QtWidgets.QLabel(Dialog) self.label = QtWidgets.QLabel(Dialog)
self.label.setObjectName("label") self.label.setObjectName("label")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label) self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label)
self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit = QtWidgets.QLineEdit(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -37,10 +45,10 @@ class Ui_Dialog(object):
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy) self.lineEdit.setSizePolicy(sizePolicy)
self.lineEdit.setObjectName("lineEdit") self.lineEdit.setObjectName("lineEdit")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.lineEdit) self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.lineEdit)
self.label_2 = QtWidgets.QLabel(Dialog) self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setObjectName("label_2") self.label_2.setObjectName("label_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_2) self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_2)
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog) self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -48,10 +56,10 @@ class Ui_Dialog(object):
sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth())
self.lineEdit_3.setSizePolicy(sizePolicy) self.lineEdit_3.setSizePolicy(sizePolicy)
self.lineEdit_3.setObjectName("lineEdit_3") self.lineEdit_3.setObjectName("lineEdit_3")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.lineEdit_3) self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_3)
self.label_3 = QtWidgets.QLabel(Dialog) self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setObjectName("label_3") self.label_3.setObjectName("label_3")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_3) self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_3)
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog) self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -59,10 +67,10 @@ class Ui_Dialog(object):
sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth())
self.lineEdit_2.setSizePolicy(sizePolicy) self.lineEdit_2.setSizePolicy(sizePolicy)
self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_2.setObjectName("lineEdit_2")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2) self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2)
self.label_4 = QtWidgets.QLabel(Dialog) self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setObjectName("label_4") self.label_4.setObjectName("label_4")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_4) self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_4)
self.lineEdit_4 = QtWidgets.QLineEdit(Dialog) self.lineEdit_4 = QtWidgets.QLineEdit(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -70,19 +78,13 @@ class Ui_Dialog(object):
sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth())
self.lineEdit_4.setSizePolicy(sizePolicy) self.lineEdit_4.setSizePolicy(sizePolicy)
self.lineEdit_4.setObjectName("lineEdit_4") self.lineEdit_4.setObjectName("lineEdit_4")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4) self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4)
self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton.setObjectName("pushButton") self.pushButton_2.setObjectName("pushButton_2")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.pushButton) self.formLayout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.pushButton_2)
self.listWidget_2 = QtWidgets.QListWidget(Dialog) self.gridLayout.addLayout(self.formLayout, 0, 1, 2, 1)
self.listWidget_2.setObjectName("listWidget_2") self.verticalLayout = QtWidgets.QVBoxLayout()
self.formLayout.setWidget(5, QtWidgets.QFormLayout.SpanningRole, self.listWidget_2) self.verticalLayout.setObjectName("verticalLayout")
self.gridLayout.addLayout(self.formLayout, 0, 1, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 3, 1, 1)
self.listWidget = QtWidgets.QListWidget(Dialog) self.listWidget = QtWidgets.QListWidget(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Expanding) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
@ -90,7 +92,19 @@ class Ui_Dialog(object):
sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth())
self.listWidget.setSizePolicy(sizePolicy) self.listWidget.setSizePolicy(sizePolicy)
self.listWidget.setObjectName("listWidget") self.listWidget.setObjectName("listWidget")
self.gridLayout.addWidget(self.listWidget, 0, 0, 1, 1) self.verticalLayout.addWidget(self.listWidget)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.listWidget_2 = QtWidgets.QListWidget(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.listWidget_2.sizePolicy().hasHeightForWidth())
self.listWidget_2.setSizePolicy(sizePolicy)
self.listWidget_2.setObjectName("listWidget_2")
self.verticalLayout.addWidget(self.listWidget_2)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 2, 1)
self.retranslateUi(Dialog) self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
@ -104,5 +118,6 @@ class Ui_Dialog(object):
self.label_2.setText(_translate("Dialog", "β")) self.label_2.setText(_translate("Dialog", "β"))
self.label_3.setText(_translate("Dialog", "ΔH/R / K")) self.label_3.setText(_translate("Dialog", "ΔH/R / K"))
self.label_4.setText(_translate("Dialog", "x")) self.label_4.setText(_translate("Dialog", "x"))
self.pushButton.setText(_translate("Dialog", "PushButton")) self.pushButton_2.setText(_translate("Dialog", "Fictive Cp"))
self.pushButton.setText(_translate("Dialog", "Calculate Tg"))
from pyqtgraph import PlotWidget from pyqtgraph import PlotWidget

View File

@ -21,13 +21,15 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self._dsc = {} self._dsc = {}
self._tg_baselines = {} self._tg_baselines = {}
self._tg_value_plot = [] self._tg_value_plot = {}
self.limits = RegionItem(), RegionItem() self.limits = RegionItem(), RegionItem()
for lim in self.limits: for lim in self.limits:
self.graphicsView.addItem(lim) self.graphicsView.addItem(lim)
self.add_sets() self.add_sets()
self.listWidget.itemClicked.connect(self.show_tg_values)
def __call__(self): def __call__(self):
self.clear() self.clear()
self.add_sets() self.add_sets()
@ -100,11 +102,46 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
lines.append(plt) lines.append(plt)
self._tg_baselines[key] = lines self._tg_baselines[key] = lines
tg_plot = PlotItem(array(list(tg_results.values())), pen=None, symbolBrush=color, symbol='o') tg_plot = PlotItem(array(list(tg_results.values())), pen=None, symbolBrush=color, symbol='o')
self._tg_value_plot.append(tg_plot) self._tg_value_plot[key] = (tg_results, tg_plot)
self.graphicsView.addItem(tg_plot) self.graphicsView.addItem(tg_plot)
def show_tg_values(self, item):
values, _ = self._tg_value_plot.get(item.data(QtCore.Qt.UserRole), ({}, None))
if values is not None:
self.listWidget_2.clear()
for name, pos in values.items():
tg_item = QtWidgets.QListWidgetItem(f'{name.capitalize()}: {pos[0]:.2f} K')
self.listWidget_2.addItem(tg_item)
@QtCore.pyqtSlot(name='on_pushButton_2_clicked')
def get_fictive(self):
baselines = tuple(lim.getRegion() for lim in self.limits)
if baselines[0][0] > baselines[1][0]:
baselines = baselines[1], baselines[0]
for idx in range(self.listWidget.count()):
item = self.listWidget.item(idx)
key = item.data(QtCore.Qt.UserRole)
color = item.foreground()
_, data = self._dsc[key]
cp, tg = data.get_fictive_cp(*baselines)
plt = PlotItem(cp.x, cp.y)
plt.set_line(color=color.color())
self.graphicsView_2.addItem(plt)
self._tg_value_plot[key][0]['fictive'] = (tg, 0)
tg_plot = PlotItem(array(list(self._tg_value_plot[key][0].values())), pen=None, symbolBrush=color, symbol='o')
self.graphicsView.addItem(tg_plot)
res = data.calculate_tnmh([100, 0.5, 1, 2e5], *baselines, return_fictive=False)
plt = PlotItem(res.x, res.y)
print(res.pprint())
plt.set_line(style=2, color=color.color())
self.graphicsView_2.addItem(plt)
def close(self) -> bool: def close(self) -> bool:
self.clear() self.clear()
return super().close() return super().close()

View File

@ -14,99 +14,7 @@
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="3"> <item row="2" column="3">
<widget class="PlotWidget" name="graphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>τ&lt;sub&gt;g&lt;/sub&gt; / s</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>β</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>ΔH/R / K</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>x</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QListWidget" name="listWidget_2"/>
</item>
</layout>
</item>
<item row="1" column="3">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -116,7 +24,101 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="3">
<widget class="PlotWidget" name="graphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="PlotWidget" name="graphicsView_2"/>
</item>
<item row="0" column="1" rowspan="2">
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>τ&lt;sub&gt;g&lt;/sub&gt; / s</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>β</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>ΔH/R / K</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>x</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Fictive Cp</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" rowspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"> <widget class="QListWidget" name="listWidget">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding"> <sizepolicy hsizetype="Maximum" vsizetype="Expanding">
@ -126,6 +128,25 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Calculate Tg</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>