======================
Comparison with Hammer
======================

During the development process, we have consistently compared TSNet results with
Bentley Hammer [HAMMER]_ using different networks and many different transient events.
In this section, we present the comparison between TSNet and Hammer results.
The Hammer models used to generate the events is also included
in the GitHub example directory (https://github.com/glorialulu/TSNet/tree/master/examples/networks)
for the user's reference.


Tnet 0
^^^^^^^^^

We first show the comparison for a simple network,
consisting of one reservoir, two pipes, and one valve, as illustrated in :numref:`tnet0_network`.
The wave speed for both pipes is :math:`1200m/s`, and lengths and diameters are given in the figure.
The transient event is generated by closing the end-valve at the beginning of the simulation
during 2s; thus, the flow rate at the end valve decreases linearly from :math:`0.05m^3/s` at :math:`t=0s` to
:math:`0m^3/s` at :math:`t=2s` and remains zero thereafter.
:numref:`tnet0_hammer` (a) shows the flow rate through the valve, and
:numref:`tnet0_hammer` (b) presents the pressure transients generated at node N-1 during 60s simulation period.
The solid line represents TSNet results and the dashed-dotted line shows Hammer results.
These results indicate a perfect match between TSNet and Hammer simulation results for this simple network.


.. _tnet0_network:
.. figure:: figures/tnet0_network.png
   :width: 500
   :alt: tnet0_network

   Topology of a simple network.

.. _tnet0_hammer:
.. figure:: figures/tnet0_calibration.png
   :width: 500
   :alt: tnet0_hammer

   Comparison of TSNet and Hammer results: (a) flow at the valve; (b) pressure head at N-1.


Tnet 3
^^^^^^^

We then show the comparison between TSNet and Hammer results for
a more complicated network, Tnet3,
for three different transient events:

1. Shut down of PUMP-1,

2. Burst at JUNCTION-73, and

3. Closure of VALVE-1.

The results for the three transient-generating events are shown in
:numref:`pump_hammer`, :numref:`burst_hammer`, and :numref:`valve_hammer`, respectively.

.. The Hammer model that was used to generate the events is also included
   in the GitHub example directory for the user's reference.

*   We would like to note beforehand that we do not expect to
    obtain the exact same results from TSNet
    as Hammer since different numerical schemes were implemented,
    such as wave speed adjustment, pressure dependent demand, and boundary conditions.

.. In fact, due to the fact that Hammer is a closed-source software,
   we do not know precisely what numerical schemes are implemented in Hammer,
   which directly motivated us to develop TSNet in the first place.


Pump shut-down
~~~~~~~~~~~~~~~~~

Both TSNet and Hammer are utilized to simulate
the shut down of PUMP-1.
The time step is specified as 0.002s in both software.
:numref:`pump_hammer` reports the pressure change with respect to the nominal pressure
at multiple junctions, where the solid lines represent TSNet results
and the dashed lines show Hammer results.
TSNet and Hammer results are very similar to each other
in terms of attenuation and phase shift throughout the 20s simulation period,
despite slight discrepancies, which can be explained by
the different wave speed adjustment schemes and boundary condition configurations adopted
by the two software.

.. _pump_hammer:
.. figure:: figures/tnet3_pump_hammer_002.png
   :width: 500
   :alt: pump_hammer

   Comparison of pressure transients at multiple junctions generated by shutting down PUMP-1 in TNet3:
   TSNet (solid lines) Hammer (dashed lines) results.

.. Moreover, we tested the consistency of the solution when altering
    the time step of the simulation in TSNet and Hammer.
    We simulated the pump shut-down event with different time steps, i.e., :math:`dt = \{0.002s, 0.0055, 0.0115s\}`
    and plot the results in :numref:`convergence`.
    The green and purple lines represent the pressure at JUNCTION-30, and JUNCTION-90, respectively,
    and the different line types (solid, dashed, dotted) represent different time steps (see legend).
    :numref:`convergence` (a) represents the results from TSNet, and
    :numref:`convergence` (b) shows the results from Hammer.
    We observe that the pressure transients simulated by TSNet with different time steps, resemble closely
    with each other, and all of pressure traces disclose anticipated level of details about the reflection,
    transmission, propagation, and attenuation of the pressure waves.
    However, the Hammer predicts significantly different and uncharacteristic results with time steps larger than
    0.002s (i.e., :math:`dt =\{0.0055s, 0.0115s\}`), with small transient amplitude, delayed pressure peaks,
    and high attenuation.
    The pressure transients exhibit consistency only when the time step is smaller than 0.002s,
    which is the reason why we chose time step as 0.002s to compare the results from Hammer and TSNet.




Burst event
~~~~~~~~~~~

Aburst event was simulated at Junction-73 using both TSNet and Hammer.
:numref:`burst_hammer` reports the pressure change with respect to the nominal pressure
at multiple junctions, where the solid lines represent TSNet results,
and the dashed lines show Hammer results.
It can be observed that during the first transient cycle, i.e., around 0-8s,
TSNet and Hammer results exhibit very good agreement with each other.
Although the discrepancies increase a bit in terms of attenuation and phase shift during the latter period,
the overall match is satisfactory considering that different time step and wave speed adjustment schemes
are adopted in the two software.


.. _burst_hammer:
.. figure:: figures/tnet3_burst_hammer.png
   :width: 500
   :alt: burst_hammer

   Comparison of pressure transients at multiple junctions generated by the burst at JUNCTION-73 in Tnet3:
   TSNet (solid lines) Hammer (dashed lines) results.

Valve closure
~~~~~~~~~~~~~

Both TSNet and Hammer are utilized to simulate
the closure of VALVE-1.
The comparison of the results is presented in :numref:`valve_hammer`.
Again, adequate resemblance can be observed between the TSNet (a) and
Hammer results (b). Considering that pressure transients are of smaller amplitude and
more chaotic, the results are presented in two separate plots with same scale for clarity.

.. _valve_hammer:
.. figure:: figures/tnet3_valve_hammer.png
   :width: 500
   :alt: valve_hammer

   Comparison of pressure transients at multiple junctions generated by closing VALVE-1 in Tnet3:
   (a): TSNet results, (b): Hammer results.


.. In summary, we are able to show adequate consistency between TSNet and Hammer
   results in two networks undergoing different transient events.
   In the Reservoir-Pipe-Valve network, shown in :numref:`tnet0_network`, TSNet and Hammer predict exact same
   pressure and flow results when a transient event is generated by gradually closing the end-valve.
   In the larger network, TSNet and Hammer results are remarkably similar with each other despite minor discrepancies
   due to the differences in modeling and numerical schemes.
   Moreover, as presented in :numref:`convergence`,
   TSNet performs better with relatively large time step than Hammer.