Skip to content

Commit

Permalink
Add phase in a bunch of places
Browse files Browse the repository at this point in the history
Probably some still remain
  • Loading branch information
ibell committed Aug 8, 2023
1 parent c00a194 commit 3ccf75f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions GUI/panels/pdsim_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ class StateChooser(wx.Dialog):
"""
A dialog used to select the state
"""
def __init__(self,Fluid,T,rho,parent=None,id=-1,Fluid_fixed = False):
def __init__(self,Fluid,T,rho,parent=None,id=-1,Fluid_fixed = False, phase='gas'):
wx.Dialog.__init__(self,parent,id,"State Chooser",size=(300,310))

class StateChoices(wx.Choicebook):
Expand All @@ -2250,8 +2250,9 @@ def __init__(self, parent, id=-1,):
self.plabel1, self.p1 = LabeledItem(self.pageT_p,label="Pressure [kPa]",value='300')
self.p1.default_units = 'kPa'
self.p1.Bind(wx.EVT_CONTEXT_MENU,self.OnChangeUnits)
self.phaselabel, self.phase = LabeledItem(self.pageT_p,label="Phase",value='gas')
sizer=wx.FlexGridSizer(cols=2,hgap=3,vgap=3)
sizer.AddMany([self.Tlabel1, self.T1,self.plabel1, self.p1])
sizer.AddMany([self.Tlabel1, self.T1,self.plabel1, self.p1, self.phaselabel, self.phase])
self.pageT_p.SetSizer(sizer)

def OnChangeUnits(self, event):
Expand Down Expand Up @@ -2306,7 +2307,7 @@ def OnChangeUnits(self, event):
self.SetSizer(sizer)
self.Fluids.SetStringSelection(Fluid)

state = CP.State(Fluid, dict(T=T,D=rho))
state = CP.State(Fluid, dict(T=T,D=rho), phase=phase)
Tt = state.Props(CoolProp.iT_triple)
Tc = state.Props(CoolProp.iT_critical)
pt = state.Props(CoolProp.iP_triple)
Expand All @@ -2325,7 +2326,7 @@ def OnChangeUnits(self, event):
self.SC.SetSelection(0) ## The page of Tsat,DTsh
else:
#Pressure from temperature and density
state = CP.State(Fluid, dict(T=T,D=rho))
state = CP.State(Fluid, dict(T=T,D=rho), phase=phase)
p = state.p
self.SC.T1.SetValue(str(T))
self.SC.p1.SetValue(str(p))
Expand Down Expand Up @@ -2436,7 +2437,8 @@ def OnUpdateVals(self,event=None):
# Temperature and pressure are given
T = float(self.SC.T1.GetValue())
p = float(self.SC.p1.GetValue())
state = CP.State(Fluid, dict(T=T,P=p))
phase = self.SC.phase.GetValue()
state = CP.State(Fluid, dict(T=T,P=p), phase=phase)
rho = state.rho
else:
raise NotImplementedError
Expand Down Expand Up @@ -2465,10 +2467,12 @@ def __init__(self, parent, id = -1, CPState = None, Fluid_fixed = False):
self.Tlabel, self.T = LabeledItem(self,label="Temperature [K]",value=str(CPState.T))
self.plabel, self.p = LabeledItem(self,label="Pressure [kPa]",value=str(CPState.p))
self.rholabel, self.rho = LabeledItem(self,label="Density [kg/m\xb3]",value=str(CPState.rho))
self.phaselabel, self.phase = LabeledItem(self,label="Imposed phase",value=CPState.phase)
sizer.AddMany([self.Fluidlabel, self.Fluid,
self.Tlabel, self.T,
self.plabel, self.p,
self.rholabel, self.rho])
self.rholabel, self.rho,
self.phaselabel, self.phase])

for box in [self.T,self.p,self.rho,self.Fluid]:
#Make the box not editable
Expand All @@ -2492,13 +2496,14 @@ def GetState(self):
Fluid = str(self.Fluid.GetValue())
T = float(self.T.GetValue())
rho = float(self.rho.GetValue())
return State(Fluid,dict(T = T, D = rho))
phase = self.phase.GetValue()
return State(Fluid,dict(T = T, D = rho), phase=phase)

def GetValue(self):
return self.GetState()

def SetValue(self, State_val):
self.set_state(State_val.Fluid, dict(T = State_val.T, D = State_val.rho))
self.set_state(State_val.Fluid, dict(T = State_val.T, D = State_val.rho), phase=State_val.phase)

def set_state(self, Fluid, **kwargs):
"""
Expand Down Expand Up @@ -2593,7 +2598,7 @@ def __init__(self, parent, config, **kwargs):
PDPanel.__init__(self, parent, **kwargs)

# The CoolProp State instance
inletState = State(config['inletState']['Fluid'], dict(T = config['inletState']['T'], D = config['inletState']['rho']))
inletState = State(config['inletState']['Fluid'], dict(T = config['inletState']['T'], D = config['inletState']['rho']), phase='gas')

# Create the sizers
sizer = wx.BoxSizer(wx.VERTICAL)
Expand Down Expand Up @@ -2813,22 +2818,23 @@ def get_script_chunks(self, plugin_chunks = None):

return textwrap.dedent(
"""
inletState = State.State("{Ref}", {{'T': {Ti}, 'P' : {pi} }})
inletState = State.State("{Ref}", {{'T': {Ti}, 'P' : {pi} }}, phase="{phase}")
outlet_temperature_guess = {outlet_temperature_guess} # [K]
if outlet_temperature_guess > 0:
# Use the specified guess for outlet temperature
T2s = outlet_temperature_guess
else:
T2s = sim.guess_outlet_temp(inletState,{po})
outletState = State.State("{Ref}", {{'T':T2s,'P':{po} }})
outletState = State.State("{Ref}", {{'T':T2s,'P':{po} }}, phase="{phase}")
# The rotational speed (over-written if motor map provided)
sim.omega = {omega}
""".format(Ref = inletState.Fluid.decode(),
Ti = str(inletState.T),
pi = str(inletState.p),
po = str(discPressure),
phase = inletState.phase.decode(),
outlet_temperature_guess = str(outlet_temperature_guess),
omega = str(omega)
)
Expand Down

0 comments on commit 3ccf75f

Please sign in to comment.