Skip to content

Commit 0772e97

Browse files
committed
Fix pressure editing handling in water dew point page
1 parent 3bf88c2 commit 0772e97

File tree

7 files changed

+123
-106
lines changed

7 files changed

+123
-106
lines changed

pages/0_TP_flash.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383
# Check if the dataframe is empty
8484
if st.session_state.tp_flash_data.empty:
8585
st.error('No data to perform calculations. Please input temperature and pressure values.')
86+
elif (st.edited_dfTP['Pressure (bara)'] <= 0).any():
87+
st.error('Pressure must be greater than 0 bara. Please update the pressure inputs before running calculations.')
8688
else:
8789
# Initialize a list to store results
8890
results_list = []
8991
neqsim_fluid = fluid_df(st.edited_df, lastIsPlusFraction=isplusfluid, add_all_components=False).autoSelectModel()
90-
92+
9193
# Iterate over each row and perform calculations
9294
for idx, row in st.edited_dfTP.dropna().iterrows():
9395
temp = row['Temperature (C)']
@@ -97,12 +99,12 @@
9799
TPflash(neqsim_fluid)
98100
#results_df = st.data_editor(dataFrame(neqsim_fluid))
99101
results_list.append(dataFrame(neqsim_fluid))
100-
102+
101103
st.success('Flash calculations finished successfully!')
102104
st.subheader("Results:")
103105
# Combine all results into a single dataframe
104106
combined_results = pd.concat(results_list, ignore_index=True)
105-
107+
106108
# Display the combined results
107109
#st.subheader('Combined TP Flash Results')
108110
#st.dataframe(combined_results)

pages/10_Gas_Hydrate.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,26 @@
7676
# Check if water's MolarComposition[-] is greater than 0
7777
water_row = st.edited_df[st.edited_df['ComponentName'] == 'water'] # Adjust 'ComponentName' and 'water' as necessary
7878
if not water_row.empty and water_row['MolarComposition[-]'].iloc[0] > 0:
79-
neqsim_fluid = fluid_df(st.edited_df, lastIsPlusFraction=False, add_all_components=False).autoSelectModel()
80-
results_list = []
81-
pres_list = []
82-
fluid_results_list = []
83-
for pres in st.edited_dfTP.dropna():
84-
pressure = pres
85-
pres_list.append(pressure)
86-
neqsim_fluid.setPressure(pressure, 'bara')
87-
results_list.append(hydt(neqsim_fluid)-273.15)
88-
fluid_results_list.append(dataFrame(neqsim_fluid))
89-
st.session_state['tp_data'] = pd.DataFrame({
90-
'Pressure (bara)': pres_list, # Default example pressure
91-
'Temperature (C)': results_list # Default temperature
92-
})
93-
st.session_state['tp_data'] = st.session_state['tp_data'].sort_values('Pressure (bara)')
94-
st.success('Hydrate calculation finished successfully!')
95-
combined_results = pd.concat(fluid_results_list, ignore_index=True)
79+
if (st.edited_dfTP['Pressure (bara)'] <= 0).any():
80+
st.error('Pressure must be greater than 0 bara. Please update the pressure inputs before running calculations.')
81+
else:
82+
neqsim_fluid = fluid_df(st.edited_df, lastIsPlusFraction=False, add_all_components=False).autoSelectModel()
83+
results_list = []
84+
pres_list = []
85+
fluid_results_list = []
86+
for pres in st.edited_dfTP.dropna():
87+
pressure = pres
88+
pres_list.append(pressure)
89+
neqsim_fluid.setPressure(pressure, 'bara')
90+
results_list.append(hydt(neqsim_fluid)-273.15)
91+
fluid_results_list.append(dataFrame(neqsim_fluid))
92+
st.session_state['tp_data'] = pd.DataFrame({
93+
'Pressure (bara)': pres_list, # Default example pressure
94+
'Temperature (C)': results_list # Default temperature
95+
})
96+
st.session_state['tp_data'] = st.session_state['tp_data'].sort_values('Pressure (bara)')
97+
st.success('Hydrate calculation finished successfully!')
98+
combined_results = pd.concat(fluid_results_list, ignore_index=True)
9699

97100
if st.session_state.get('refresh', True):
98101
st.edited_dfTP2 = st.data_editor(

pages/30_Water Dew Point.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
st.divider()
5252

5353
st.edited_dfTP = st.data_editor(
54-
st.session_state.tp_data['Pressure (bara)'].dropna().reset_index(drop=True),
54+
st.session_state.tp_data[['Pressure (bara)']].dropna().reset_index(drop=True),
5555
num_rows='dynamic', # Allows dynamic number of rows
5656
column_config={
5757
'Pressure (bara)': st.column_config.NumberColumn(
@@ -68,26 +68,29 @@
6868
# Check if water's MolarComposition[-] is greater than 0
6969
water_row = st.edited_df[st.edited_df['ComponentName'] == 'water'] # Adjust 'ComponentName' and 'water' as necessary
7070
if not water_row.empty and water_row['MolarComposition[-]'].iloc[0] > 0:
71-
neqsim_fluid = fluid_df(st.edited_df, lastIsPlusFraction=False, add_all_components=False).autoSelectModel()
72-
results_list = []
73-
results_list2 = []
74-
pres_list = []
75-
fluid_results_list = []
76-
for pres in st.edited_dfTP.dropna():
77-
pressure = pres
78-
pres_list.append(pressure)
79-
neqsim_fluid.setPressure(pressure, 'bara')
80-
results_list.append(hydt(neqsim_fluid)-273.15)
81-
results_list2.append(waterdewt(neqsim_fluid)-273.15)
82-
fluid_results_list.append(dataFrame(neqsim_fluid))
83-
st.session_state['tp_data'] = pd.DataFrame({
84-
'Pressure (bara)': pres_list, # Default example pressure
85-
'Hydrate Temperature (C)': results_list, # Default temperature
86-
'Aqueous Temperature (C)': results_list2 # Default temperature
87-
})
88-
st.session_state['tp_data'] = st.session_state['tp_data'].sort_values('Pressure (bara)')
89-
st.success('Hydrate calculation finished successfully!')
90-
combined_results = pd.concat(fluid_results_list, ignore_index=True)
71+
pressure_values = st.edited_dfTP['Pressure (bara)']
72+
if (pressure_values <= 0).any():
73+
st.error('Pressure must be greater than 0 bara. Please update the pressure inputs before running calculations.')
74+
else:
75+
neqsim_fluid = fluid_df(st.edited_df, lastIsPlusFraction=False, add_all_components=False).autoSelectModel()
76+
results_list = []
77+
results_list2 = []
78+
pres_list = []
79+
fluid_results_list = []
80+
for pressure in pressure_values.dropna():
81+
pres_list.append(pressure)
82+
neqsim_fluid.setPressure(pressure, 'bara')
83+
results_list.append(hydt(neqsim_fluid)-273.15)
84+
results_list2.append(waterdewt(neqsim_fluid)-273.15)
85+
fluid_results_list.append(dataFrame(neqsim_fluid))
86+
st.session_state['tp_data'] = pd.DataFrame({
87+
'Pressure (bara)': pres_list, # Default example pressure
88+
'Hydrate Temperature (C)': results_list, # Default temperature
89+
'Aqueous Temperature (C)': results_list2 # Default temperature
90+
})
91+
st.session_state['tp_data'] = st.session_state['tp_data'].sort_values('Pressure (bara)')
92+
st.success('Hydrate calculation finished successfully!')
93+
combined_results = pd.concat(fluid_results_list, ignore_index=True)
9194

9295
if st.session_state.get('refresh', True):
9396
st.edited_dfTP2 = st.data_editor(

pages/40_LNGageing.py

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -98,64 +98,67 @@
9898
)
9999
if st.button('Simulate Ageing'):
100100
if st.edited_df['MolarComposition[-]'].sum() > 0:
101-
# Create fluid from user input
102-
fluid = fluid_df(st.edited_df).autoSelectModel()
103-
fluid.setPressure(pressure_transport, 'bara')
104-
fluid.setTemperature(-160.0, "C") # setting a guessed initial temperature
105-
106-
# Creating ship system for LNG ageing
107-
ship = jneqsim.fluidmechanics.flowsystem.twophaseflowsystem.shipsystem.LNGship(fluid, volume_initial, BOR / 100.0)
108-
ship.useStandardVersion("", standard_version)
109-
ship.getStandardISO6976().setEnergyRefT(energy_ref_temp)
110-
ship.getStandardISO6976().setVolRefT(volume_ref_temp)
111-
ship.setEndTime(time_transport)
112-
ship.createSystem()
113-
ship.solveSteadyState(0)
114-
ship.solveTransient(0)
115-
ageingresults = ship.getResults("temp")
116-
117-
ageingresults = ship.getResults("temp")
118-
# Assuming ageingresults is already obtained from the simulation
119-
results = ageingresults[1:] # Data rows
120-
columns = ageingresults[0] # Column headers
121-
122-
# Clean the column names to ensure uniqueness and handle empty or None values
123-
cleaned_columns = []
124-
seen = set()
125-
for i, col in enumerate(columns):
126-
new_col = col if col not in (None, '') else f"Unnamed_{i}"
127-
if new_col in seen:
128-
new_col = f"{new_col}_{i}"
129-
seen.add(new_col)
130-
cleaned_columns.append(new_col)
131-
132-
# Creating DataFrame from results with cleaned column names
133-
resultsDF = pd.DataFrame([[float(str(j).replace(',', '')) for j in i] for i in results], columns=cleaned_columns)
134-
resultsDF.columns = ['time', 'temperature','WI','GCV','density','volume','C1','C2','C3','iC4','nC4','iC5','nC5','C6','N2','energy', 'GCV_mass', 'gC1','gC2','gC3','giC4','gnC4','giC5','gnC5','gC6','gN2']
135-
136-
# Display the DataFrame
137-
#print(resultsDF.head()) # or use st.dataframe(resultsDF) in Streamlit
138-
139-
# Displaying the results DataFrame in Streamlit
140-
st.subheader('Ageing Simulation Results')
141-
st.dataframe(resultsDF)
142-
143-
# Function to convert DataFrame to Excel and offer download
144-
def convert_df_to_excel(df):
145-
output = BytesIO()
146-
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
147-
df.to_excel(writer, index=False)
148-
processed_data = output.getvalue()
149-
return processed_data
150-
151-
# Download button for the results in Excel format
152-
# if st.button('Download Results as Excel'):
153-
excel_data = convert_df_to_excel(resultsDF)
154-
st.download_button(label='📥 Download Excel',
155-
data=excel_data,
156-
file_name='lng_ageing_results.xlsx',
157-
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
158-
st.divider()
101+
if pressure_transport <= 0:
102+
st.error('Transport pressure must be greater than 0 bara. Please update the pressure before running calculations.')
103+
else:
104+
# Create fluid from user input
105+
fluid = fluid_df(st.edited_df).autoSelectModel()
106+
fluid.setPressure(pressure_transport, 'bara')
107+
fluid.setTemperature(-160.0, "C") # setting a guessed initial temperature
108+
109+
# Creating ship system for LNG ageing
110+
ship = jneqsim.fluidmechanics.flowsystem.twophaseflowsystem.shipsystem.LNGship(fluid, volume_initial, BOR / 100.0)
111+
ship.useStandardVersion("", standard_version)
112+
ship.getStandardISO6976().setEnergyRefT(energy_ref_temp)
113+
ship.getStandardISO6976().setVolRefT(volume_ref_temp)
114+
ship.setEndTime(time_transport)
115+
ship.createSystem()
116+
ship.solveSteadyState(0)
117+
ship.solveTransient(0)
118+
ageingresults = ship.getResults("temp")
119+
120+
ageingresults = ship.getResults("temp")
121+
# Assuming ageingresults is already obtained from the simulation
122+
results = ageingresults[1:] # Data rows
123+
columns = ageingresults[0] # Column headers
124+
125+
# Clean the column names to ensure uniqueness and handle empty or None values
126+
cleaned_columns = []
127+
seen = set()
128+
for i, col in enumerate(columns):
129+
new_col = col if col not in (None, '') else f"Unnamed_{i}"
130+
if new_col in seen:
131+
new_col = f"{new_col}_{i}"
132+
seen.add(new_col)
133+
cleaned_columns.append(new_col)
134+
135+
# Creating DataFrame from results with cleaned column names
136+
resultsDF = pd.DataFrame([[float(str(j).replace(',', '')) for j in i] for i in results], columns=cleaned_columns)
137+
resultsDF.columns = ['time', 'temperature','WI','GCV','density','volume','C1','C2','C3','iC4','nC4','iC5','nC5','C6','N2','energy', 'GCV_mass', 'gC1','gC2','gC3','giC4','gnC4','giC5','gnC5','gC6','gN2']
138+
139+
# Display the DataFrame
140+
#print(resultsDF.head()) # or use st.dataframe(resultsDF) in Streamlit
141+
142+
# Displaying the results DataFrame in Streamlit
143+
st.subheader('Ageing Simulation Results')
144+
st.dataframe(resultsDF)
145+
146+
# Function to convert DataFrame to Excel and offer download
147+
def convert_df_to_excel(df):
148+
output = BytesIO()
149+
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
150+
df.to_excel(writer, index=False)
151+
processed_data = output.getvalue()
152+
return processed_data
153+
154+
# Download button for the results in Excel format
155+
# if st.button('Download Results as Excel'):
156+
excel_data = convert_df_to_excel(resultsDF)
157+
st.download_button(label='📥 Download Excel',
158+
data=excel_data,
159+
file_name='lng_ageing_results.xlsx',
160+
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
161+
st.divider()
159162
"""
160163
Units:
161164

pages/50_Property Generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ def main():
384384
total_molar_frac = st.edited_df["MolarComposition[-]"].sum()
385385
if total_molar_frac <= 0:
386386
st.error("Total Molar Composition must be greater than 0.")
387+
elif min_pres <= 0 or max_pres <= 0:
388+
st.error("Pressure range values must be greater than 0 bara. Please update the minimum and maximum pressure inputs.")
387389
else:
388390
# 2) Normalize fluid composition
389391
normalized_df = st.edited_df.copy()

pages/60_Hydrogen.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@
7474
if st.button('Run Hydrogen Property Calculations'):
7575
if st.session_state.tp_flash_data.empty:
7676
st.error('No data to perform calculations. Please input temperature and pressure values.')
77+
elif (st.session_state.tp_flash_data['Pressure (bara)'] <= 0).any():
78+
st.error('Pressure must be greater than 0 bara. Please update the pressure inputs before running calculations.')
7779
else:
7880
results_list = []
7981
neqsim_fluid = fluid("srk") # Use SRK EoS
8082
neqsim_fluid.addComponent('hydrogen', 1.0, "mol/sec") # Add hydrogen component
81-
83+
8284
for idx, row in st.session_state.tp_flash_data.iterrows():
8385
temp = row['Temperature (C)']
8486
pressure = row['Pressure (bara)']
@@ -88,11 +90,11 @@
8890
neqsim_fluid.initThermoProperties()
8991
neqsim_fluid.getPhase(0).getPhysicalProperties().setViscosityModel("Muzny_mod")
9092
neqsim_fluid.initPhysicalProperties()
91-
92-
93+
94+
9395
# Check number of phases
9496
num_phases = neqsim_fluid.getNumberOfPhases()
95-
97+
9698
if num_phases > 0:
9799
phase = neqsim_fluid.getPhase(0)
98100
try:
@@ -130,7 +132,7 @@
130132
break
131133
else:
132134
st.error("No valid phases found for Leachman model calculations.")
133-
135+
134136
st.success('Hydrogen property calculations completed!')
135137
st.subheader("Results:")
136138
combined_results = pd.DataFrame(results_list)

pages/70_Helium.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@
5959
if st.button('Run Helium Property Calculations'):
6060
if st.session_state.tp_flash_data.empty:
6161
st.error('No data to perform calculations. Please input temperature and pressure values.')
62+
elif (st.session_state.tp_flash_data['Pressure (bara)'] <= 0).any():
63+
st.error('Pressure must be greater than 0 bara. Please update the pressure inputs before running calculations.')
6264
else:
6365
results_list = []
6466
neqsim_fluid = fluid("srk") # Use SRK EoS (VEGA EoS needs implementation)
6567
neqsim_fluid.addComponent('helium', 1.0, "mol/sec") # Add helium component
66-
68+
6769
for idx, row in st.session_state.tp_flash_data.iterrows():
6870
temp = row['Temperature (C)']
6971
pressure = row['Pressure (bara)']
@@ -74,7 +76,7 @@
7476
neqsim_fluid.getPhase(0).getPhysicalProperties().setViscosityModel("KTA_mod")
7577
neqsim_fluid.initPhysicalProperties()
7678

77-
79+
7880
# Check number of phases
7981
num_phases = neqsim_fluid.getNumberOfPhases()
8082
#st.write(f"Number of detected phases: {num_phases}")

0 commit comments

Comments
 (0)