Skip to content

Commit

Permalink
minor fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbfs committed May 11, 2019
1 parent eb2ec51 commit 469717b
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 106 deletions.
145 changes: 70 additions & 75 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Sindri/Controllers/PureSubstanceController.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ def genDiagrams(self):
try:
if self.diagramsView.le_isotherms.text().strip() != "":
self.isotherms_range = [
float(i) for i in self.diagramsView.le_isotherms.text().replace(',', ' ').split()

float(i)
for i in self.diagramsView.le_isotherms.text()
.replace(",", " ")
.split()
]
else:
self.isotherms_range = []
Expand Down Expand Up @@ -231,7 +233,7 @@ def plotDiagrams(self):
lnscale=self.diagramsView.checkBox_logscale.isChecked(),
grid=self.diagramsView.checkBox_grid.isChecked(),
smooth=self.diagramsView.checkBox_smooth.isChecked(),
plotisothermals=self.diagramsView.checkBox_isotherms.isChecked()
plotisothermals=self.diagramsView.checkBox_isotherms.isChecked(),
)
elif choice == "TS":
self.diag.plotTS(
Expand Down
15 changes: 8 additions & 7 deletions Sindri/Models/LiquidModel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from fortran.UNIFAC import getgamma as _helper_getGamma2

# from fortran.UNIFAC import getgamma as _helper_getGamma2

import db

Expand Down Expand Up @@ -95,13 +96,13 @@ def __init__(self, subs_ids):
# cursor.close()

def getGamma(self, x, T: float):
return _helper_getGamma2(
x, T,self.amk, self.vk, self.Rk, self.Qk
)
# x = np.atleast_1d(x)
# return _helper_getGamma(
# x, T, self.amk, self.vk, self.Rk, self.Qk
# return _helper_getGamma2(
# x, T,self.amk, self.vk, self.Rk, self.Qk
# )
# x = np.atleast_1d(x)
return _helper_getGamma(
x, T, self.n, self.m, self.amk, self.vk, self.Rk, self.Qk
)


from numba import njit
Expand Down
1 change: 0 additions & 1 deletion Sindri/Views/AddAliasView.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, controller, parent=None):

self.btn_ok.clicked.connect(self.ok_clicked)
self.btn_cancel.clicked.connect(self.cancel_clicked)


def ok_clicked(self):
self.controller.ok_clicked()
Expand Down
7 changes: 1 addition & 6 deletions Sindri/Views/PureSubstanceDiagramsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@


class PureSubstanceDiagramsView(QtWidgets.QWidget, Ui_Form_PureSubstanceDiagrams):
def __init__(
self,
controller,
model: PureSubstanceModel,
parent=None,
):
def __init__(self, controller, model: PureSubstanceModel, parent=None):
super().__init__(parent)
self.setupUi(self)

Expand Down
4 changes: 3 additions & 1 deletion Sindri/db_addSubstanceProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def __init__(self, parent=None):
QtGui.QPixmap(":/images/antoine_correlation_equation.png")
)

self.tableWidget_aliases.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft)
self.tableWidget_aliases.horizontalHeader().setDefaultAlignment(
QtCore.Qt.AlignLeft
)

def confirm_clicked(self):

Expand Down
4 changes: 3 additions & 1 deletion Sindri/db_editSubstanceProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def __init__(self, parent=None, hl_row=None):
)

# alias
self.tableWidget_aliases.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft)
self.tableWidget_aliases.horizontalHeader().setDefaultAlignment(
QtCore.Qt.AlignLeft
)
self.btn_add_alias.clicked.connect(self.addAlias)
self.btn_remove_alias.clicked.connect(self.removeAlias)
self.loadAliases()
Expand Down
36 changes: 25 additions & 11 deletions Sindri/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"S": "Entropy",
}


class IsothermalPVStruct:
def __init__(self, T: List[float], V:List[float],P:List[List[float]]):
def __init__(self, T: List[float], V: List[float], P: List[List[float]]):
self.T = T
self.V = V
self.P = P
Expand All @@ -49,7 +50,7 @@ def __init__(
self.compound = compound
self.eosname = eosname
self.eoseq = eoseq
self.isotherms :IsothermalPVStruct = isotherms
self.isotherms: IsothermalPVStruct = isotherms

self.Tliq, self.Tvap = np.zeros(self.n), np.zeros(self.n)
self.Pliq, self.Pvap = np.zeros(self.n), np.zeros(self.n)
Expand All @@ -70,7 +71,7 @@ def __init__(
self.lnscale = False
self.grid = True
self.smooth = True
self.plotisotherms= False
self.plotisotherms = False

for i in range(self.n):
self.Tliq[i], self.Tvap[i] = self.propsliq[i].T, self.propsvap[i].T
Expand Down Expand Up @@ -102,8 +103,15 @@ def __init__(
else:
self.has_isotherms = False


def plotPV(self, xunit: str, yunit: str, lnscale=True, smooth=True, grid=True, plotisothermals=False):
def plotPV(
self,
xunit: str,
yunit: str,
lnscale=True,
smooth=True,
grid=True,
plotisothermals=False,
):
self.x_letter, self.y_letter = "V", "P"
self.xliq, self.yliq = self.Vliq, self.Pliq
self.xvap, self.yvap = self.Vvap, self.Pvap
Expand Down Expand Up @@ -245,16 +253,22 @@ def _plot(self):

try:
if self.plotisotherms and self.has_isotherms:
v = conv_unit(np.atleast_1d(self.isotherms.V), SI_dict[self.x_letter], self.xunit)
v = conv_unit(
np.atleast_1d(self.isotherms.V), SI_dict[self.x_letter], self.xunit
)
if self.lnscale:
v = np.log(v)
for i in range(len(self.isotherms.T)):
t = self.isotherms.T[i]
p = conv_unit(np.atleast_1d(self.isotherms.P[i]), SI_dict[self.y_letter], self.yunit)
p = conv_unit(
np.atleast_1d(self.isotherms.P[i]),
SI_dict[self.y_letter],
self.yunit,
)
if self.lnscale:
p = np.log(p)
label = "isothermal at {:.3f} K".format(t)
ax.plot(v, p, label=label, linestyle='--')
ax.plot(v, p, label=label, linestyle="--")
except Exception as e:
print("Error plotting isothermal data\n{}".format(str(e)))
raise
Expand Down Expand Up @@ -320,8 +334,8 @@ def helper_P_guess(_T):
tmp.append(p)
PV_isotherms.append(tmp)

PV_isotherms = IsothermalPVStruct(isotherms, list(v_iso_space.tolist()), PV_isotherms)
PV_isotherms = IsothermalPVStruct(
isotherms, list(v_iso_space.tolist()), PV_isotherms
)

return (retliq, retvap, critical_point, PV_isotherms)


Loading

0 comments on commit 469717b

Please sign in to comment.