
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/fluid_dynamics/plot_recycle_valve_energy_loss.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_fluid_dynamics_plot_recycle_valve_energy_loss.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_fluid_dynamics_plot_recycle_valve_energy_loss.py:


Pump recycle valve energy loss
=============================
This example demonstrates how to calculate the recirculation line energy loss if you have the following information:

* Pump suction pressure
* Pump discharge pressure
* Recycle valve outlet pressure
* Recycle valve flow coefficient (:math`Cv`) curve
* Density of the fluid

Note that if the flow rate through the recycle valve is known, the calculation can be simplified and the recycle valve
outlet pressure and :math`Cv` curve are not required.

.. GENERATED FROM PYTHON SOURCE LINES 18-20

We start by making some example dummy data. We ensure that the pump discharge pressure is higher than the suction
pressure, and that the feed pressure is not constant to get more interesting results.

.. GENERATED FROM PYTHON SOURCE LINES 20-40

.. code-block:: default


    import pandas as pd

    from indsl.fluid_dynamics.pump_parameters import recycle_valve_energy_loss, total_head
    from indsl.fluid_dynamics.valve_parameters import flow_through_valve
    from indsl.signals.generator import line, sine_wave


    start_date = pd.Timestamp("2022-1-1")
    end_date = pd.Timestamp("2022-1-2")
    mean_disch_P = 10  # bar
    wave_period_disch_P = pd.Timedelta("10min")
    wave_period_valve_out_P = pd.Timedelta("5hour")
    suction_pressure = sine_wave(start_date, end_date)  # bar
    discharge_pressure = sine_wave(start_date, end_date, wave_period=wave_period_disch_P, wave_mean=mean_disch_P)  # bar
    valve_outlet_P = sine_wave(start_date, end_date, wave_period=wave_period_valve_out_P)  # bar
    SG = 1
    slope = pd.Timedelta("1s") / (end_date - start_date)
    valve_opening = line(start_date, end_date, slope=slope, intercept=0)








.. GENERATED FROM PYTHON SOURCE LINES 41-43

To specify the valve Cv curve, the type of curve has to be given and two points on the curve, the Cv at min adn max
flow rates.

.. GENERATED FROM PYTHON SOURCE LINES 43-48

.. code-block:: default


    type = "EQ"
    min_coef = (0.1, 10)
    max_coef = (0.9, 50)








.. GENERATED FROM PYTHON SOURCE LINES 49-51

The first step step is to calculate the flow through the recycle valve. We assume the pump discharge pressure is equal
to the recycle valve inlet pressure.

.. GENERATED FROM PYTHON SOURCE LINES 51-55

.. code-block:: default

    Q_valve = flow_through_valve(
        discharge_pressure, valve_outlet_P, valve_opening, SG, type, min_coef, max_coef, True
    )  # m3/h








.. GENERATED FROM PYTHON SOURCE LINES 56-57

The second step is to calcualte the total head of the pump.

.. GENERATED FROM PYTHON SOURCE LINES 57-63

.. code-block:: default

    den = 1000 * SG  # kg/m3
    den = line(start_date, end_date, intercept=den)  # kg/m3
    discharge_pressure *= 100000  # Pa
    suction_pressure *= 100000  # Pa
    head = total_head(discharge_pressure, suction_pressure, den, True)  # m








.. GENERATED FROM PYTHON SOURCE LINES 64-65

The last step is to calculate the recycle valve energy loss

.. GENERATED FROM PYTHON SOURCE LINES 65-71

.. code-block:: default

    energy_loss = recycle_valve_energy_loss(Q_valve, head, den, True)  # W
    ax = energy_loss.plot()
    ax.set_title("Recycle valve energy loss")
    ax.set_xlabel("Time")
    _ = ax.set_ylabel("Power (W)")




.. image-sg:: /auto_examples/fluid_dynamics/images/sphx_glr_plot_recycle_valve_energy_loss_001.png
   :alt: Recycle valve energy loss
   :srcset: /auto_examples/fluid_dynamics/images/sphx_glr_plot_recycle_valve_energy_loss_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 72-74

As a simple sanity check, the increasing energy loss with increasing valve opening makes sense, as this means more
fluid flows through the recirculation line.


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.661 seconds)


.. _sphx_glr_download_auto_examples_fluid_dynamics_plot_recycle_valve_energy_loss.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_recycle_valve_energy_loss.py <plot_recycle_valve_energy_loss.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_recycle_valve_energy_loss.ipynb <plot_recycle_valve_energy_loss.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
