242 lines
6.7 KiB
Python
242 lines
6.7 KiB
Python
import marimo
|
|
|
|
__generated_with = "0.8.15"
|
|
app = marimo.App(width="medium")
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
import marimo as mo
|
|
import os
|
|
return mo, os
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
from refDLL import RefProp, RegDllCall
|
|
# from diagram_PH import Diagram_PH
|
|
return RefProp, RegDllCall
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
return
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
import pandas as pd
|
|
# create a function to remove a specifique column from dataframe
|
|
return pd,
|
|
|
|
|
|
@app.cell
|
|
def __(mo, os):
|
|
def setup_refrigerant_selector():
|
|
try:
|
|
directory_path = os.path.join(r"C:\Users\serameza\impact\EMEA_MBD_GitHub\Diagram_PH",'IPM_DLL')
|
|
refrigerant_files = []
|
|
|
|
for filename in os.listdir(directory_path):
|
|
if filename.startswith('R') and filename.endswith('.dll'):
|
|
refrigerant_files.append(filename[:-4])
|
|
|
|
refrigerant_selector = mo.ui.dropdown(
|
|
label="Select Refrigerant File",
|
|
options={file: file for file in refrigerant_files},
|
|
value=refrigerant_files[0] if refrigerant_files else "No files found"
|
|
)
|
|
return refrigerant_selector
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
return None
|
|
|
|
refrigerant_selector = setup_refrigerant_selector()
|
|
refrigerant_selector
|
|
return refrigerant_selector, setup_refrigerant_selector
|
|
|
|
|
|
@app.cell
|
|
def __(RefProp, mo):
|
|
# Create a dictionary to map Enum to string representations for the dropdown
|
|
state_options = {
|
|
"Pressure-Temperature": RefProp.PT,
|
|
"Pressure-Quality": RefProp.PX,
|
|
"Temperature-Saturation Quality": RefProp.TSX,
|
|
"Pressure-Enthalpy": RefProp.PH
|
|
}
|
|
|
|
# Define the dropdown selector
|
|
state_selector = mo.ui.dropdown(
|
|
label="Select State Variable",
|
|
options={name: name for name in state_options.keys()},
|
|
value="Pressure-Temperature" # Default selection
|
|
)
|
|
# Define inputs that will be dynamically displayed based on state
|
|
pressure_input = mo.ui.number(label="Pressure (kPa)", start=0, stop=2000, value=101.3)
|
|
temperature_input = mo.ui.number(label="Temperature (°C)", start=-50, stop=100, value=25)
|
|
quality_input = mo.ui.number(label="Quality", start=0, stop=1, step=0.01, value=0.5)
|
|
enthalpy_input = mo.ui.number(label="Enthalpy (kJ/kg)", start=0, stop=5000, value=1500)
|
|
return (
|
|
enthalpy_input,
|
|
pressure_input,
|
|
quality_input,
|
|
state_options,
|
|
state_selector,
|
|
temperature_input,
|
|
)
|
|
|
|
|
|
@app.cell(hide_code=True)
|
|
def __(mo, state_selector):
|
|
def render_inputs(selected_state):
|
|
if selected_state == "Pressure-Temperature":
|
|
Label1="Pressure (kPa) "
|
|
Label2="Temperature (°C)"
|
|
start1= 0
|
|
stop1= 10000
|
|
value1 = 1500
|
|
start2 = -100
|
|
stop2 = 150
|
|
value2 = 5
|
|
elif selected_state == "Pressure-Quality":
|
|
Label1="Pressure (kPa)"
|
|
Label2="Quality "
|
|
start1= 0
|
|
stop1= 10000
|
|
value1 = 1500
|
|
start2= 0
|
|
stop2= 1
|
|
value2 = 1
|
|
elif selected_state == "Temperature-Saturation Quality":
|
|
Label1="Saturation Temperature (°C)"
|
|
Label2="Quality "
|
|
start1= -100
|
|
stop1= 150
|
|
value1 = 69
|
|
start2= 0
|
|
stop2= 1
|
|
value2 = 1
|
|
elif selected_state == "Pressure-Enthalpy":
|
|
Label1="Pressure (kPa)"
|
|
Label2="Enthalpy (kJ/kg)"
|
|
start1= 0
|
|
stop1= 10000
|
|
value1 = 1500
|
|
start2= 0
|
|
stop2= 2000
|
|
value2 = 200
|
|
|
|
|
|
form1 = (
|
|
mo.md('''
|
|
{input1}
|
|
|
|
{input2}
|
|
''')
|
|
.batch(
|
|
input1=mo.ui.number(label=Label1, start=start1, stop=stop1,value = value1),
|
|
input2=mo.ui.number(label=Label2,start=start2, stop=stop2 ,value = value2),
|
|
)
|
|
.form(show_clear_button=True, bordered=False)
|
|
)
|
|
return form1
|
|
form1 = render_inputs(state_selector.value)
|
|
mo.vstack([state_selector,form1])
|
|
return form1, render_inputs
|
|
|
|
|
|
@app.cell
|
|
def __(
|
|
RefProp,
|
|
RegDllCall,
|
|
form1,
|
|
mo,
|
|
refrigerant_selector,
|
|
state_options,
|
|
state_selector,
|
|
):
|
|
refrigerant_handler = RegDllCall(refrigerant_selector.value)
|
|
# Dummy functions for calculation (replace with actual logic)
|
|
def calculate_enthalpy(pressure, temperature):
|
|
return refrigerant_handler.H_pT(pressure*1e3,temperature+273.15)
|
|
|
|
def calculate_temperature(pressure, quality):
|
|
return refrigerant_handler.T_px(pressure*1e3,quality)
|
|
|
|
def calculate_quality(pressure, enthalpy):
|
|
return refrigerant_handler.T_px(pressure*1e3,enthalpy)
|
|
|
|
# Define a function to handle the compute button click
|
|
def on_compute_click():
|
|
selected_state_string = state_selector.value
|
|
selected_state = state_options[selected_state_string]
|
|
|
|
|
|
if selected_state == RefProp.PT:
|
|
temperature = form1.value["input2"]
|
|
pressure = form1.value["input1"]
|
|
enthalpy = calculate_enthalpy(pressure, temperature)
|
|
return mo.md(f"**Calculated Enthalpy**: {enthalpy:.2f} kJ/kg")
|
|
elif selected_state == RefProp.PX:
|
|
pressure = form1.value["input1"]
|
|
quality = form1.value["input2"]
|
|
temperature = calculate_temperature(pressure, quality)
|
|
return mo.md(f"**Calculated Temperature**: {temperature:.2f} °C")
|
|
elif selected_state == RefProp.PH:
|
|
enthalpy = form1.value["input2"]
|
|
quality = calculate_quality(form1.value["input1"], enthalpy)
|
|
return mo.md(f"**Calculated Quality**: {quality:.2f}")
|
|
|
|
# Define the compute button and pass the `on_click` function directly
|
|
compute_button = mo.ui.button(label="Compute")
|
|
return (
|
|
calculate_enthalpy,
|
|
calculate_quality,
|
|
calculate_temperature,
|
|
compute_button,
|
|
on_compute_click,
|
|
refrigerant_handler,
|
|
)
|
|
|
|
|
|
@app.cell
|
|
def __(form1, mo, on_compute_click):
|
|
mo.stop(form1.value is None, mo.md("**Submit the form to continue.**"))
|
|
on_compute_click()
|
|
return
|
|
|
|
|
|
@app.cell
|
|
def __(refrigerant_handler):
|
|
refrigerant_handler.saturation_table(273.15+50,273.15+150,5)
|
|
return
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
from refrigerant_propertites import RefProperties
|
|
return RefProperties,
|
|
|
|
|
|
@app.cell
|
|
def __(RefProperties, refrigerant_selector):
|
|
refrigerant_hd = RefProperties(refrigerant_selector.value)
|
|
return refrigerant_hd,
|
|
|
|
|
|
@app.cell
|
|
def __(refrigerant_hd):
|
|
refrigerant_hd.T_px(25e5,0.5)
|
|
return
|
|
|
|
|
|
@app.cell
|
|
def __():
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|