diff --git a/docs/_static/images/basics/rankine_ts_diagram.svg b/docs/_static/images/basics/rankine_ts_diagram.svg new file mode 100644 index 000000000..ad8a048eb --- /dev/null +++ b/docs/_static/images/basics/rankine_ts_diagram.svg @@ -0,0 +1,3261 @@ + + + + + + + + 2024-05-23T08:06:38.979522 + image/svg+xml + + + Matplotlib v3.7.2, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/_static/images/basics/rankine_ts_diagram_darkmode.svg b/docs/_static/images/basics/rankine_ts_diagram_darkmode.svg new file mode 100644 index 000000000..3f4cfebbe --- /dev/null +++ b/docs/_static/images/basics/rankine_ts_diagram_darkmode.svg @@ -0,0 +1,3261 @@ + + + + + + + + 2024-05-23T08:06:22.317888 + image/svg+xml + + + Matplotlib v3.7.2, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/basics/rankine_cycle.rst b/docs/basics/rankine_cycle.rst index 9ac3c31e5..9c3728b7d 100644 --- a/docs/basics/rankine_cycle.rst +++ b/docs/basics/rankine_cycle.rst @@ -81,6 +81,50 @@ water return flow temperature. After rerunning, we will see that the condensation temperature and pressure are both automatically calculated by the specified terminal temperature value. +Generating T-s Diagram +^^^^^^^^^^^^^^^^^^^^^^ +To visualize the Rankine cycle, we generate a temperature (T) versus entropy (s) +diagram using the fluprodia (Fluid Property Diagram) package. + +.. dropdown:: Click to expand to code section + + .. literalinclude:: /../tutorial/basics/rankine.py + :language: python + :start-after: [sec_5] + :end-before: [sec_6] + +The steps involved in generating the T-s diagram are as follows: + +- Import the Package: Import fluprodia and create an object by passing the + alias of the fluid. +- Specify the Unit System: Set the unit system for all fluid properties. +- Specify Custom Isolines: Define custom isolines for the diagram. +- Calculate and draw isolines: Calculate and draw the background isolines. +- Calculate and draw process points and change of state +- Save and Export the Diagram: Save and export the completed T-s diagram. + +.. figure:: /_static/images/basics/rankine_ts_diagram.svg + :align: center + :alt: T-s Diagram of Rankine Cycle + :figclass: only-light + + Figure: T-s Diagram of Rankine Cycle + +.. figure:: /_static/images/basics/rankine_ts_diagram_darkmode.svg + :align: center + :alt: T-s Diagram of Rankine Cycle + :figclass: only-dark + + Figure: T-s Diagram of Rankine Cycle + +Besides visualization, this feature is also useful for analysis purposes. +For example, if the T-s diagram forms a closed loop, validating the accuracy of +the model and that the operating fluid completes a successful Rankine Cycle. By +applying fluprodia, we can create and customize different types of diagrams for +all pure and pseudo-pure fluids available in CoolProp. For more information on +fluprodia, we refer users to the +`fluprodia documentation `__. + Assess Electrical Power ^^^^^^^^^^^^^^^^^^^^^^^ To assess the electrical power output we want to consider the power generated @@ -92,8 +136,8 @@ both components to the bus. .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_5] - :end-before: [sec_6] + :start-after: [sec_6] + :end-before: [sec_7] .. note:: @@ -121,11 +165,11 @@ replacing the mass flow specification at connection 1: .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_6] - :end-before: [sec_7] + :start-after: [sec_7] + :end-before: [sec_8] -Analyze Efficiency and Powergeneration -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Analyze Efficiency and power generation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In this section, we will analyze the power production and the efficiency of the cycle, given constant steam mass flow and with varying values for the @@ -144,8 +188,8 @@ can disable the printout of the convergence history. .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_7] - :end-before: [sec_8] + :start-after: [sec_8] + :end-before: [sec_9] .. figure:: /_static/images/basics/rankine_parametric.svg :align: center @@ -218,24 +262,24 @@ offdesign simulations. .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_8] - :end-before: [sec_9] + :start-after: [sec_9] + :end-before: [sec_10] We have to save the design state of the network and run the :code:`solve` method with the :code:`design_path` specified. .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_9] - :end-before: [sec_10] + :start-after: [sec_10] + :end-before: [sec_11] Finally, we can alter the mass flow from its design value of 20 kg/s to only 50 % of its value. In this example, we calculate the efficiency and plot it. .. literalinclude:: /../tutorial/basics/rankine.py :language: python - :start-after: [sec_10] - :end-before: [sec_11] + :start-after: [sec_11] + :end-before: [sec_12] .. figure:: /_static/images/basics/rankine_partload.svg :align: center diff --git a/docs/whats_new.rst b/docs/whats_new.rst index 5d6796f1a..2268fa26b 100644 --- a/docs/whats_new.rst +++ b/docs/whats_new.rst @@ -3,6 +3,7 @@ What's New Discover notable new features and improvements in each release +.. include:: whats_new/v0-7-5.rst .. include:: whats_new/v0-7-4.rst .. include:: whats_new/v0-7-3.rst .. include:: whats_new/v0-7-2.rst diff --git a/docs/whats_new/v0-7-5.rst b/docs/whats_new/v0-7-5.rst new file mode 100644 index 000000000..61f04ca5d --- /dev/null +++ b/docs/whats_new/v0-7-5.rst @@ -0,0 +1,13 @@ +v0.7.5 - Under development +++++++++++++++++++++++++++ + +Documentation +############# +- The Rankine cycle example has been adopted to integrate a T-s diagram of the + process into the results. + (`PR #514 `__). + +Contributors +############ +- Francesco Witte (`@fwitte `__) +- `@Nzb0731 `__ diff --git a/pyproject.toml b/pyproject.toml index dd3340450..838b42258 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ exclude = ["docs/_build"] [project] name = "tespy" -version = "0.7.4" +version = "0.7.5" description = "Thermal Engineering Systems in Python (TESPy)" readme = "README.rst" authors = [ @@ -66,6 +66,7 @@ Changelog = "https://tespy.readthedocs.io/en/main/whats_new.html" dev = [ "build", "flit", + "fluprodia", "furo", "iapws", "pyromat", diff --git a/tutorial/basics/rankine.py b/tutorial/basics/rankine.py index 19115cff1..163ade647 100755 --- a/tutorial/basics/rankine.py +++ b/tutorial/basics/rankine.py @@ -51,7 +51,69 @@ my_plant.solve(mode='design') my_plant.print_results() + # %%[sec_5] +# Adding feature to plot the T-s Diagram using fluprodia library +# Importing necessary library +import matplotlib.pyplot as plt +import numpy as np +from fluprodia import FluidPropertyDiagram + +# Initial Setup +diagram = FluidPropertyDiagram('water') +diagram.set_unit_system(T='°C', p='bar', h='kJ/kg') + +# Storing the model result in the dictionary +result_dict = {} +result_dict.update( + {cp.label: cp.get_plotting_data()[1] for cp in my_plant.comps['object'] + if cp.get_plotting_data() is not None}) + +# Iterate over the results obtained from TESPy simulation +for key, data in result_dict.items(): + # Calculate individual isolines for T-s diagram + result_dict[key]['datapoints'] = diagram.calc_individual_isoline(**data) + +# Create a figure and axis for plotting T-s diagram +fig, ax = plt.subplots(1, figsize=(20, 10)) +isolines = { + 'Q': np.linspace(0, 1, 2), + 'p': np.array([1, 2, 5, 10, 20, 50, 100, 300]), + 'v': np.array([]), + 'h': np.arange(500, 3501, 500) +} + +# Set isolines for T-s diagram +diagram.set_isolines(**isolines) +diagram.calc_isolines() + +# Draw isolines on the T-s diagram +diagram.draw_isolines(fig, ax, 'Ts', x_min=0, x_max=7500, y_min=0, y_max=650) + +# Adjust the font size of the isoline labels +for text in ax.texts: + text.set_fontsize(10) + +# Plot T-s curves for each component +for key in result_dict.keys(): + datapoints = result_dict[key]['datapoints'] + _ = ax.plot(datapoints['s'], datapoints['T'], color='#ff0000', linewidth=2) + _ = ax.scatter(datapoints['s'][0], datapoints['T'][0], color='#ff0000') + +# Set labels and title for the T-s diagram +ax.set_xlabel('Entropy, s in J/kgK', fontsize=16) +ax.set_ylabel('Temperature, T in °C', fontsize=16) +ax.set_title('T-s Diagram of Rankine Cycle', fontsize=20) + +# Set font size for the x-axis and y-axis ticks +ax.tick_params(axis='x', labelsize=12) +ax.tick_params(axis='y', labelsize=12) +plt.tight_layout() + +# Save the T-s diagram plot as an SVG file +fig.savefig('rankine_ts_diagram.svg') + +# %%[sec_6] from tespy.connections import Bus powergen = Bus("electrical power output") @@ -65,18 +127,16 @@ my_plant.solve(mode='design') my_plant.print_results() -# %%[sec_6] +# %%[sec_7] powergen.set_attr(P=-10e6) c1.set_attr(m=None) my_plant.solve(mode='design') my_plant.print_results() -# %%[sec_7] +# %%[sec_8] my_plant.set_attr(iterinfo=False) c1.set_attr(m=20) powergen.set_attr(P=None) -import matplotlib.pyplot as plt -import numpy as np # make text reasonably sized plt.rc('font', **{'size': 18}) @@ -144,18 +204,18 @@ ax[4].set_xlabel('Feed water temperature in °C') ax[5].set_xlabel('Live steam pressure in bar') plt.tight_layout() -fig.savefig('rankine_parametric.svg') +fig.savefig('rankine_parametric-darkmode.svg') plt.close() -# %%[sec_8] +# %%[sec_9] mc.set_attr(design=["ttd_u"], offdesign=["kA"]) c11.set_attr(offdesign=["v"]) c12.set_attr(design=["T"]) c1.set_attr(design=["p"]) tu.set_attr(offdesign=["cone"]) -# %%[sec_9] +# %%[sec_10] my_plant.solve("design") my_plant.save("rankine_design") -# %%[sec_10] +# %%[sec_11] partload_efficiency = [] partload_m_range = np.linspace(20, 10, 11) @@ -174,4 +234,4 @@ plt.tight_layout() fig.savefig('rankine_partload.svg') plt.close() -# %%[sec_11] +# %%[sec_12]