|
98 | 98 | ) |
99 | 99 | if st.button('Simulate Ageing'): |
100 | 100 | 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() |
159 | 162 | """ |
160 | 163 | Units: |
161 | 164 |
|
|
0 commit comments