Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

ELEKTRO-E 22008

Examensarbete 15 hp
06/2022

Leakage detection system


An improved monitor and detection system
constructed for HVDC valve cooling

Ghaith Ghadri
Marcus Stoppert
Farat Ghader Kourehpaz

KEYWORDS: Leakage detection, HVDC, Modelling, Python, Control system, Analysis, Data processing

Civilingenjörsprogrammet i elektroteknik
1
ABSTRACT
The target of this project is to improve a leakage detection system in a HVDC-environment. The
present system is not capable to detect various leakages which have caused plant downtime and
maintenance. It has a high tolerance of how much coolant can be leaked before alarming and the
system is not as responsive as it needs to be in order to prevent facility damage from leakages. To
find the best possible solution to these flaws, market research was conducted with the aim of
exploring what different companies offers within the area. Despite the market research being
insightful and instructive, it was decided to develop the present system. In part, because there was a
lot of potential for future development around the present system, and more importantly, many of
the solutions on the market are either not suitable or are too expensive to implement.

The developed model is more efficient, both in terms of minimizing the permitted amount of
leakage, and the speed of triggering an alarm. It is based on previous samples imported from a csv-
file containing data from the studied facility. Moreover, statistical calculations and curve-fitting
methods has been performed on the dataset to detect anomalies and predict future values. The
latter method helps to find a trend in the time-series data, consequently, a leak can be detected at
an earlier stage. Finally, the developed model has been tested extensively to verify that the
requirements for the project are met.

Teknisk-naturvetenskapliga fakulteten

Uppsala universitet, Utgivningsort Uppsala/Visby

Handledare: Tommy Andersson, Erik Dore Ämnesgranskare: Mats Ekberg


Examinator: Mikael Bergkvist

2
PREFACE

This report has been written in the spring of 2022 in a 12-week project at Hitachi Energy HVDC under
supervision of Tommy Andersson and Erik Doré. With collaboration at Uppsala university,
supervision of Mats Ekberg has also been given. We would like to thank Tommy and Erik for giving us
an insight of Hitachi which have allowed us to evolve within HVDC-technology. We are grateful for
the guidance and the experience it has given us. We would also like to give a special thanks to
Fredrik Nohrstedt, Ola Hedlund and Afsaneh Behrouz for their support and belief which ultimately
made it possible to realize this project.

During our time at Hitachi, we have developed a leakage detection system within HVDC-valve
cooling. This development comes in form of a control system in an external environment to Hitachi´s
present control system for leakage detection. With a background within electrical engineering,
control systems stand for a big part of our experience and earlier projects. With knowledge within
the area, we have been able to in short amount of time come up with a model which with future
development hopefully can be a part of the control system at the HVDC-facilities of Hitachi Energy.

3
Table of Contents

1. NOMENCLATURE................................................................................................................................. 6
1.1 Terminology ............................................................................................................................ 6
1.2 Abbreviations and Acronyms .................................................................................................. 6
2. INDTRODUCTION ................................................................................................................................ 7
2.1 Background ................................................................................................................................... 7
2.2 Purpose ......................................................................................................................................... 7
2.3 Goals ............................................................................................................................................. 8
2.4 Boundaries .................................................................................................................................... 8
3. THEORY ............................................................................................................................................... 9
3.1 Earlier work ................................................................................................................................... 9
3.1.1 Technology behind the existing leakage detection system ................................................... 9
3.1.2 Technologies on the market ................................................................................................ 10
3.2 Mathematical concepts .............................................................................................................. 11
3.2.1 R-squared ............................................................................................................................. 12
3.2.2 Mean .................................................................................................................................... 12
3.2.3 Linear regression .................................................................................................................. 12
3.2.4 Determine the best fit line ................................................................................................... 12
3.2.5 Gradient descent.................................................................................................................. 13
3.2.6 Polynomial regression .......................................................................................................... 16
3.2.7 Standard deviation ............................................................................................................... 16
3.2.8 Normal distribution .............................................................................................................. 16
4. WORK MODELS AND METHOLOGY ................................................................................................... 17
4.1 Methods ...................................................................................................................................... 17
4.1.1 Possible development of existing model ............................................................................. 17
4.1.2 Possible implementation of solutions available on the market .......................................... 17
4.2 Models ........................................................................................................................................ 19
4.2.1 Gantt-chart ........................................................................................................................... 19
4.2.2 Work breakdown structure.................................................................................................. 19
4.3 Model-structure .......................................................................................................................... 20
4.3.1 Model expressed as flowchart with explanation ................................................................. 20
4.3.2 Model verification testing .................................................................................................... 23
4.3.3 Correlations with effect on volume measurement .............................................................. 23

4
4.3.4 UML sequence diagram ....................................................................................................... 23
5. System requirement ......................................................................................................................... 24
5.1 Technical requirement specification....................................................................................... 24
5.2 Software requirement specification ....................................................................................... 25
6. RESULTS............................................................................................................................................. 27
6.1 Mathematical relationships ........................................................................................................ 27
6.2 Model interface........................................................................................................................... 32
6.3 Model testing .............................................................................................................................. 34
6.4 Model requirements ................................................................................................................... 40
6.4.1 Responsivity ......................................................................................................................... 40
6.4.2 Limits of detection ............................................................................................................... 41
7. DISCUSSION AND CONCLUSION ........................................................................................................ 42
7.1 Further improvement ................................................................................................................. 42
7.1.1 Correlation implementation ................................................................................................ 42
7.1.2 Adjustability and implementation ....................................................................................... 42
7.2 Model performance and sources of error .................................................................................. 43
REFERENCE ............................................................................................................................................ 44
APPENDICES .......................................................................................................................................... 44

5
1. NOMENCLATURE

1.1 Terminology
Expression Explanation
Valve The valve consists of the HVDC-converting power
electronics

Sample A measurement/datapoint

Sample rate Sample rate defines by how often a set of data points
are read or measured. Often expressed in samples per
second.

HiDraw Control system of Hitachi Energy which operate and


monitor alarm and cooling system.

Python Python is a high-level, interpreted, general-purpose


programming language.

1.2 Abbreviations and Acronyms


Abbreviation Meaning
HVDC High Voltage Direct Current

SW Software

Exp.ves Expansion vessel

Exp.Press Expansion vessel pressure

Amb.temp Ambient temperature

Cool.Temp Cooler temperature

Exp.Level Expansion vessel volume level

Ret.Temp Return temperature

Supp.Temp Supply temperature

Supp.Press Supply pressure

UML Unified Modeling Language

6
2. INDTRODUCTION

2.1 Background
With the rise of HVDC transmission lines, power electric technologies play crucial role in the power
grid. The advantages of these power lines come mainly from their asynchronous behaviour and loss
reductions. However, if a fault occurs, it can threaten grid stability and cause damages in power
electronics. Small leaks of coolant and expanding cracks in the cooling system pipes are known to be
a safety hazard. They can cause plant downtime with multiple hours or even months of maintenance
and repair if unlucky. Having a system that can detect these issues is an integral part of a plant's
safety policy.

To detect leakages and protect the system, Hitachi Energy uses a 24-hour detection in some of their
leakage detection systems. This means that a leak can be detected at the earliest 24 hours after the
first drop has been leaked. By sampling the coolant level in an expansion vessel and process this
measurement in the control system, the existing system will alert if a leakage of more than 100
liter/day occurs, where the alarming is based on a calculation of the difference between the present
level read by the sensor, and the level 24 hours earlier. Leakages that are below 100 liter/day is
allowed in the existing system, which is still a large amount of leaked coolant. The system can thus
be improved where the limit for the amount of leakage allowed can be reduced, which reduces the
risk of damaging semiconductors and other parts of the system.

Other parameters available in the cooling circuit are measurements of pressure, temperature,
conductivity, and flowrate. These parameters together with the coolant level in the expansion vessel
does likely share a connection but are not involved in the current leakage detection system.

2.2 Purpose
There are three main areas that define the purpose of this study. These are the following:

• Bring awareness to leakage detection solutions on the market today


• Find weaknesses in the implemented leakage detection system
• Improve the implemented leakage detection system

The vision with having these three areas is that this study will leave a result which is both practical
and immediate as well as theoretical and a foundation for future improvement. Since a valuable
implementation of an improved leakage detection system is difficult to achieve in 12 weeks of time,
it is of high value to deliver qualitative research of the market together with a plan of
implementation of the systems offered by the market. With the difficulty mentioned above
regarding achieving a valuable implementable solution, focus will thereby also lay in developing a
qualitative model which in an external system can run in parallel with the existing system and show
its functionality based on historic or real time data extracted from the existing system.

7
2.3 Goals
To concretize the desired behaviour and functionalities of an improved leakage detection system,
the following goals have been stated below.

• Create a model which is able to detect a lower leakage volume from the existing 100
liter/day to 20 liter/day.
• Utilize more of given data by analysing more samples and allow more data to control the
leakage detection system for multiple timespans.
• Decrease the current delay which obstruct the alarming of the system for 24 hours. The
system should alarm when leakage is detected with no delay.
• Deliver a runnable extern leakage detection system modelled in Python. The model shall be
runnable from a csv/excel file which contains historic or real time updated data from a
facility.

2.4 Boundaries
In order to make progress and be able to deliver a model at the end of the project, boundaries have
to be set. These boundaries limit the content of the final project, they allow the group to dive into
some areas of relevant development. Limitations in form of facility downtime, remote work or time
budget are parameters which affects the project as well. The boundaries and limitations of highest
importance are stated below:

• The model will not be implemented in HiDraw as a HiDraw-code. The model will instead be
an external system.
• The project group works remote, therefore there is a limitation where the group relies on
personnel on site to deliver data and vital information regarding the system.
• A time budget of 12 weeks where about two hours of weakly guidance in meetings are
given.

8
3. THEORY

3.1 Earlier work


3.1.1 Technology behind the existing leakage detection system
The present leakage detection system is divided into multiple subsystems where each subsystem
serves a different role. For large leakages, there is a critical detection system which serves to shut
down the facility immediately. In addition, there is a detection system which operate in less critical
conditions which serves to send a signal and warn the facility user.

The technology behind both detection systems is based on software implemented in the control
system HiDraw. HiDraw gets input from various sensors placed in vessels and pipelines which
measures temperature, volume level, pressure, flowrate, and conductivity. Figure 1 below presents a
schematic overview of the cooling circuit. The main flow of coolant passes through the valve, pump
and air-cooler, whereas only a fraction passes through a treatment circuit. It is in the treatment
circuit that the coolant gets deionized as well as measured in the expansion vessel for leakage
detection. Leakages may occur in various places in the cooling circuit, however, only leakage in the
valve can cause severe damage to the facility. The position of where the leak occurs is not possible
today to detect since the detection system covers the whole cooling circuit.

Multiple of the sensors mentioned above are located at the expansion vessel as well as at the in- and
outlet of the valve, allowing surveillance of inlet and outlet temperature of the valve as well as the
flowrate through the valve. Moreover, these sensors monitor the volume level, temperature and
pressure of the expansion vessel.

Figure 1: Cooling-circuit schematic

9
Functionality regarding the less critical detection system, which is what this study is focused on, was
presented in 2.1 Background.

3.1.2 Technologies on the market


3.1.2.1 Induction cable
One technology that has been tested in a HDVC environment is the use of induction cable with a
corresponding control unit. The working principle of this leakage device is when a leakage occurs,
the induction cable, composed of four different types of wires, will send a signal to a
microprocessor. Consequently, after the signal has been processed, the leakage is localized, and an
alarm is given at the same time. The induction cable consists of two conductive polymers which are
winded around the pipes in the cooling circuit. When there is no leakage, the current between the
two conductors is normal. However, when there is a leakage, the two conductive polymers are
shortened and the measured current changes resulting in an alarm. Figure 2 displays the structure
sketch of the induction wires [1].

Figure 2: Cross-section of inductive cable together with circuit overview [1].

3.1.2.2 Flowmeters at in- and outlet


Another technology that the market offers is to use two flowmeters and two temperature sensors.
These sensors measure the flow rate and the temperature at the outlet and inlet of the cooling
circuit. This technology is based on flowmeters and temperature sensors that are highly accurate. By
mounting one of the flowmeters at the inlet and the other at the outlet, the flowrate can be
measured. The temperature sensors need to be mounted close to the flowmeters to allow
compensation of the temperature-dependent variation in coolant volumes, see figure 3 for system
schematic. This compensation is done by describing the temperature dependent density of the
coolant using a highly accurate 4th degree polynomial [2]. This method ensures that the comparison
between the inlet and outlet volume flow is very accurate and stable and thereby detection of very
small leaks can be found. This solution is something Endress+Hauser is offering as a package deal on

10
the market. According to their article Leakage detection system for critical cooling circuits [2], they
offer a precision of detecting differences in inlet and outlet flow that are larger than 0.1%.

Figure 3: Picture of the whole system including flowmeters, temperature sensors and the microprocessor [2].

3.1.2.3 Ultrasonic detection


Ultrasonic detection is another new technology that the market offers. Locating leaks becomes
easier and faster when using Ultrasound because it has the following characteristics:

- The directional nature of sound waves helps locate the source.


- Signal strength: the closer you are, the more sound you hear.
- Easily located even in noisy factory environments due to the fixed frequency.
- A leak orifice generates a turbulent flow that can be detected by high-frequency
components whenever a fluid passes through it.

The way that this technology works is when using an Ultraprobe to scan the test area, a leak can be
heard or seen on the display as rushing sound. A closer instrument to the leak will cause the
instrument to make a louder rushing sound and to give a higher reading [3].

3.2 Mathematical concepts


Vital mathematical concepts have been used in this project. These are operators, statistical models,
and curve-fitting methods.

11
3.2.1 R-squared
R-squared is a statistical method used when it is of interest to find the portion of the variance of a
dependent variable being explained by independent variables in a regression model. R-squared
represents the portion of variance as a number between zero and one, which can be seen as a
percentage of how much of the observed variation can be explained by the model of regression [4].
𝑆𝑢𝑚 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒𝑠 𝑜𝑓 𝑟𝑒𝑠𝑖𝑑𝑢𝑎𝑙𝑠
𝑅2 = 1 − (1)
𝑇𝑜𝑡𝑎𝑙 𝑠𝑢𝑚 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒𝑠

3.2.2 Mean [5]


𝑛
1
𝑀𝑒𝑎𝑛 = ∑ 𝑥𝑘 (2)
𝑛
𝑘=0

• 𝑥 is the feature value


• 𝑛 is number of samples

3.2.3 Linear regression [6]


To find a relationship between one or more independent variables and a continuous target, linear
regression is used. The linear regression model can be presented by the following equation

𝑌̂ = 𝜆0 + 𝜆1 𝑥1 + 𝜆2 𝑥2 + ⋯ + 𝜆𝑛 𝑥𝑛 (3)

• 𝑌̂ is predicted value.
• 𝜆0 is the biased term.
• 𝜆1 , … , 𝜆𝑛 are the model parameters.
• 𝑥1 , 𝑥2 , … , 𝑥𝑛 are the feature values.

3.2.4 Determine the best fit line


The line with the smallest error between the predicted and the observed values is called the
regression line. The errors are called residuals. These residuals can be illustrated by vertical lines
from the observed data samples to the regression line. The error is defined and measured by the
cost function as the sum of squares of the residuals. The cost function is described by mean square
error (MSE) model

12
𝑚
1 2
𝐽(𝜆) = ∑(𝑌𝑘 − 𝑌̂𝑘 ) (4)
𝑚
𝑘=1

• 𝑌𝑘 are the actual values.


• 𝑌̂𝑘 are the predicted values.
• 𝑚 is the total number samples in the dataset.

The task is to find the model parameters that make the cost function minimum. Gradient descent is
an algorithm that realizes this objective. An overview of how residuals and regression line correlate
to data sample is presented in figure 4 below [7].

Figure 4: Linear regression based on sample data

3.2.5 Gradient descent


Gradient descent is an optimization algorithm, that iteratively tweaks the parameters of the model
to minimize the cost function.

• Firstly, the model parameters get initialized with some random values, which
is called random initialization.
• Second, changes of the cost function are measured when it’s parameters
changes. Hence, the partial derivative of the cost function is taken with
respect to the model parameters 𝜆0 , 𝜆1 , … , 𝜆𝑛 .

13
𝑚
𝜕𝐽(𝜆) 2
= − ∑(𝑌𝑘 − 𝑌̂𝑘 )
𝜕𝜆0 𝑚
𝑘=1

𝑚
𝜕𝐽(𝜆) 2
= − ∑(𝑌𝑘 − 𝑌̂𝑘 )𝑥1
𝜕𝜆1 𝑚
𝑘=1

Similarly, the general partial derivative of the cost function is denoted by


𝑚
𝜕𝐽(𝜆) 2
= − ∑(𝑌𝑘 − 𝑌̂𝑘 ) 𝑥𝑛 (5)
𝜕𝜆𝑛 𝑚
𝑘=1

The partial derivative for all parameters can be computed simultaneously by using

𝜕𝐽(𝜆)
𝜕𝜆0
𝜕𝐽(𝜆) 2 𝑇
𝜕𝜆1 = − 𝑚 𝑥 (𝑌 − 𝑌̂) (6)

𝜕𝐽(𝜆)
[ 𝜕𝜆𝑛 ]

where 𝑌̂ = 𝜆0 + 𝜆1 𝑥1 + 𝜆2 𝑥2 + ⋯ + 𝜆𝑛 𝑥𝑛 and 𝑥 𝑇 = [𝑥1 𝑥2 … 𝑥𝑛 ]

• After the computation of the derivatives, the parameters will be updated

𝑚
2𝛼
𝜆′0 = 𝜆0 + ∑(𝑌𝑘 − 𝑌̂𝑘 )
𝑚
𝑘=1

𝑚
2𝛼
𝜆′1 = 𝜆1 + ∑(𝑌𝑘 − 𝑌̂𝑘 ) 𝑥1
𝑚
𝑘=1

General equation for all 𝜆’


𝑚
2𝛼
𝜆𝑛′
= 𝜆𝑛 + ∑(𝑌𝑘 − 𝑌̂𝑘 ) 𝑥𝑛 (7)
𝑚
𝑘=1

where 𝛼 is the learning rate, and the updated parameter is denoted by a prime. All
parameters will get updated simultaneously by following vector computation

14
𝜕𝐽(𝜆)
𝜕𝜆0
𝜆′0 𝜆0
𝜕𝐽(𝜆)
𝜆′ 𝜆
[ 1 ] = [ 1 ] − α 𝜕𝜆1 (8)
⋮ ⋮
𝜆′𝑛 𝜆𝑛 ⋮
𝜕𝐽(𝜆)
[ 𝜕𝜆𝑛 ]

Step 2 and 3 will be repeated until the cost function converges to a minimum value.

If 𝛼 is too small, then gradient descent can be very slow due to the small steps taken towards local
minimum. However, if 𝛼 is too large, then gradient descent can overshoot the lowest point.
Consequently, it can fail to find the minimum. The left graphs in figure 5 demonstrates how the best
fit line gets affected when 𝛼 is too small or large. The challenge is to find 𝛼 that takes optimal steps
towards it’s end goal, the local minimum. [8]

Figure 5: Gradient descent graph generated by the authors.

15
3.2.6 Polynomial regression
Polynomial regression works the same way as linear regression given the optimization algorithm.
However, it is a higher order equation. Second degree polynomial can be written as

𝑦 = 𝜃0 + 𝜃1 𝑥 + 𝜃2 𝑥 2
In general, a n:th degree polynomial regression is written as

𝑦𝑛 = 𝜃0 + 𝜃1 𝑥+. . . +𝜃𝑛 𝑥 𝑛 (9)

Polynomial regression is used when linear regression does not capture the pattern in the data.
Usually, the more complex the pattern gets, the higher polynomial degree is applied. However, it is
crucial to not over-fit the data, because the model will be prone to a higher percentage of
uncertainty [9].

3.2.7 Standard deviation [10]


Standard deviation is the measurement of variation of a set of values. Low standard deviation is an
indication of values close to the mean, or the expected values. However, high standard deviation
indicates that the values are spread over a wider range. It is defined as

𝑛
1
𝑠 = √ ∑(𝑥𝑖 − 𝑥̂)2 (10)
𝑛−1
𝑖=1

• n is number of samples
• 𝑥𝑖 are the data values
• 𝑥̂ is the mean of over the sample data

3.2.8 Normal distribution [11]


Normal distribution is a probability distribution, and it is shaped as a bell curved graph, where most
common values are clustered around a central region. The distribution can be described by the
standard deviation and the mean. Standard deviation is the scale parameter, and the mean is the
location parameter, where it determines the location of the peak. The total area under the curve is
100% or 1.

1 (𝑥−𝜇)2

𝑦 = 𝑒 2𝜎2 (11)
𝜎√2𝜋
• 𝜎 is the standard deviation parameter
• 𝜇 is the mean

16
4. WORK MODELS AND METHOLOGY

4.1 Methods
4.1.1 Possible development of existing model
There are multiple issues and flaws with how the existing leakage detection system works. The main
flaws are listed below.

• If a leak occurs which the system will detect, it will wait for 24 hours before alarming the
facility user.
- If the leak is constant, there will be an unnecessary amount of coolant which will leak
before the alarm goes off.
• A leak which is big enough (100 liter/day) to trigger the alarm is not small enough to prevent
damage to the facility caused by leakage.
- The tolerance of allowed leakage each day is generous, thereby risking equipment and
facility downtime.
• The detection system is primarily based on one parameter, the volume measurement in the
expansion vessel. This volume measurement has however in an early stage been modest
compensated for temperature.
- Parameters from various other sensors such as pressure, flowrate or conductivity have
not been taken under consideration for leakage detection.

From the difficulties and flaws mentioned above, there is a clear pathway of improvements to the
model of detection, whereas the main aspects of performance lays within responsivity and precision.
To get rid of the unwanted properties of the existing system, improvements regarding the points
above must be made. These improvements will for example make sure to alarm the facility user in a
shorter time when leakage occurs, and in addition less leakage will be necessary to trigger the alarm.

4.1.2 Possible implementation of solutions available on the market


The solution presented in 3.1.2.2 Flowmeters at in- and outlet from Endress+Hauser is highly
relevant for this application. The package-deal the company offers for the detection system are the
following:

• Flowmeter at in- and outlet.


• Temperature sensor at in- and outlet.
• Control panel/overview display.
• Alarm and safety software.

This detection system is based on a different technology which enables leakage detection, and
localization of the detection. Since only a chosen part of the cooling circuit is being measured,
preferably the valve, it is possible to detect a leakage with potential of damaging the facility. An
implementation of this system is possible if the software Endress+Hauser is offering is compatible

17
with HiDraw. Since the existing system will not be replaced completely, it must work in parallel and
thus share a connection in software.

For the system to be an improvement it must perform better than the current 24H leakage detection
system in a few aspects. The most critical aspect of performance is detection of leakage at an earlier
stage. Furthermore, the detection must be accurate, thereby avoid false alarms. Fulfilling these
requirements, it would be possible to replace a lot of the existing detection system with
Endress+Hauser’s system.

The solution presented in 3.2.2.1 Induction cable have according to the article Research on New
Leakage Detection Technology for Converter Valve Cooling System [1] been implemented in HVDC-
environment. It is from the article known that the cable needs to be wired around any cooling
pipeline where a leakage may occur. To wire this induction cable around critical parts or straight
cooling parts may have potential. The reason to why this proposal is not further researched in this
project is because there are several unknown parameters and one problem that is not discussed in
the report. There is no detailed information about the specific material that is being used in the
induction cable besides two wires made of polymer. Furthermore, no consequential discussion has
been made around the effect of the high voltage environment to the induction cable. It is critical
that no conductive element is used in a high voltage environment due to noise and electrostatic
discharges. But the authors have not discussed this important factor. To summarize, this technology
has a lot of potential in detection of leakage in pipelines. However, it is not compatible with
pipelines close to the HVDC.

The solution presented in 3.1.2.3 Ultrasonic detection is a technology which with the right
implementation would be interesting for leakage detection within HVDC. The technology is as
explained by UE systems useful for localization leakages in smaller pipes. Since it is not possible to
enter the valve when it is running, this solution would be difficult to implement. It is also not
possible to let personnel walk around the pipes to manually investigate where a leak has occurred.
This would cost plenty of time and resources since the pipes cover a long distance over difficult
terrain. However, Ultrasonic detection can be implemented in a larger scale solution. By sending and
receiving ultrasonic waves in pipes, distorted waves can be analyzed and correlated with leakage and
thereby also locating the leakage. Long straight pipelines would most likely be the environment
where a technology like this could be interesting to research. Since a HVDC-environment contains
pipelines of multiple branches and turns, ultrasonic detection feels intuitively difficult to implement
as a system which could compete with the existing systems.

18
4.2 Models

4.2.1 Gantt-chart
To obtain structure and a clear work path, a Gantt-chart was created. The Gantt-chart serves a
multipurpose role where it shows both deadlines, milestones, and a general time budget. The
project is structured in a classic project organizational structure where the time budget can be
represented by three larger blocks. Initially the existing system and options on the market are being
studied. After, time spent is on modelling, mathematical correlations, and general system
improvement, which later is followed by analysis, report, and presentation of the thesis. Gantt-chart
available as (1) Gantt-chart in appendix.

4.2.2 Work breakdown structure

To get an overview of the most crucial parts in the project, a work breakdown structure was created,
which is displayed in figure 6.

Figure 6: Working breakdown structure displaying the most significant parts of the project.

19
4.3 Model-structure

4.3.1 Model expressed as flowchart with explanation


To give a clearer understanding of the course of events in the model, a moderately detailed
flowchart has been created. This flowchart is presented in figure 7 below and are meant to
graphically illustrate how the model is structured.

Figure 7: Flowchart which illustrate the functionalities and course of events in the model

20
The new model that is built entails improvements primarily in two areas, data processing and
response time. The model can be divided into the following blocks:

Data collection

In the new model, the compensated level is the only parameter that is used. This is because the
values of the level obtained from a site belonging to Hitachi Energy are stable. However, if the
fluctuation is large, one of these proposals can be implemented to be able to use the new model:

• Better compensation of the level


• Including the other parameters such as pressure and temperature, and analysing how theses
parameters relate to each other (which is discussed in 6.1 MATHEMATICAL RELATIONSHIPS)

The sampling that has been received in form of an Excel file, took place every 10 seconds for a 4-
week period, unlike the current model which receives a sample every 3 minutes. To detect a leak at
an early stage with good precision, many samples are required, which is filled with one sample every
10 seconds. Date, time, and level values were extracted from the file and then saved.

Sorting data

In the present system, a leak will be detected when it has exceeded 100 liter/day. In addition, the
system alarms 24 hours after the leak has begun. Therefore, the goal of the project being the
reduction of the leakage limit, resulted in more comparisons of samples in the dataset. The principle
in the new model is thus to compare the differences between the present volume level in the
expansion vessel and the respective values for 1, 3, 6, 12 and 24-hours earlier, as well as 5 and 10
days back. Consequently, the model will at a continuous rate keep track of the data-stream. As a
result, the detection of a leak will occur at an earlier stage, which in turn restricts a lower amount of
leakage out of the pipelines. The reason for having 5- and 10-days comparisons is to detect small
leakages that goes on for a long period of time, which are too small to be detected by the 1, 3-, 6-,
12- and 24-hour comparisons.

The difference between the present value and the value 1 hour earlier is saved in a list, and the
same applies to the remaining differences. These lists will constantly be replenished with new
differences, where the average of the last 100 values is calculated by using equation 2. With the help
of this, different warning signals can be sent to the user depending on what the average value
shows.

The warning system

The requirement regarding the minimum permissible leakage amount in this project was set to 20
liter/day. To decide which thresholds are credible for the different time interval comparisons, a
thorough analysis was made on the data. This analysis was achieved by using normal distribution,
see section 3.2.8. Normal distributed volume comparisons are presented below in figure 8 where the
upper row shows single value comparisons for respective time interval. The lower row illustrates the
mean over 100 differences for every time interval comparison made over the whole dataset. If the
average value of the last 100 differences for respective volume comparison exceeds the decided
limits, then a warning signal is sent that a leak has been detected.

21
The basis for the limits that have been set for the different time intervals are shown by the plots at
the lower row in figure 8. These limits are presented in section 6.4.2.

Figure 8: Normal distributed volume differences for given time interval.

Curve fitting

Another detail that has been added to this model is to curve fit the level values as a function of
number of samples. The purpose of this is to predict future values and thus be able to detect a
leakage trend. The type of curve fitting that has been implemented is linear regression, which is
most suitable due to the low fluctuation in the time-series data. This method is imported from
Python’s scikit-learn library, and it follows the same logic explained in equation 3-8.

Visualization of data

In this model, various tables, and figures, which are presented in section 6.2, have been created to
show statistics on the previously mentioned calculations. Examples of calculations shown in the
tables are:

• The level for 1, 3, 6, 12, and 24 hours earlier, as well as 5 and 10 days back.
• The difference between the present level and the above-mentioned levels.
• The mean of the last 100 differences for the above-mentioned levels.
• The equation for the first-degree curve fitting.
• The expected level 4320 samples forward, which corresponds to 12 hours, based on the
curve adjustment.

The graph-interface shows 24 hours' worth of volume measurements on the y-axis and time on the
x-axis, curve fitting based on the last 12 hours are also presented in the graph-interface. The
interface is updated for each sample read.

22
4.3.2 Model verification testing
One of the most significant parts of this project is the test and verification of the created model. The
purpose of the tests is finding errors in the system. Subsequently, these flaws will get filtered out. To
test and verify that the developed model, which is described in section 4.3.1, works as intended, the
model must be subjected to leakage. The goal for the result is fulfil the requirements specified in
section 5.1 and 5.2. To mimic a leakage scenario, a test environment has been created where the
user could expose the model to an expected leakage. This is done by generating decreasing volume
measurements after a certain time, which should correspond to a leakage. This test proved to be
very effective and tests the model's ability and speed to detect a leakage. The results of these tests
are presented in section 6.3.

4.3.3 Correlations with effect on volume measurement


To enhance the possibility of measuring the volume in the expansion vessel with high accuracy, it is
of interest to analyse how other parameters affects the measurement. As stated earlier, the leakage
detection system is based on this one parameter, volume. In hopes to decrease the fluctuation of
the volume measurement, a correlation to other parameters can be the answer. With data
belonging to one of Hitachi’s facilities, a correlation between all the measured parameters in the
cooling circuit can be done. With a correlation between these, with an arbitrary coefficient of
correlation, volume can be expressed as a function of both time as well as the correlated
parameters. This is done by finding a polynomial expression which express how these parameters
correlate to the volume in the expansion vessel. To verify that the coefficient of correlation is high,
the statistic method of R-squared presented in equation 1 is usable.

4.3.4 UML sequence diagram


The UML sequence diagram briefly shows the functionality of the leakage detection software from
start to end, see figure 9.

23
Figure 9: UML sequence diagram generated in Lucid chart.

5. System requirement

5.1 Technical requirement specification

Req. Req. Text Component Category Validation/ Test Testing unit


ID Verification method
TR. The leakage Leakage SW Verification Testing Uppsala
1.1 detection system detection required University
shall be able to model.
detect at least 20
liter per day.
TR. The leakage Leakage SW Verification Testing Uppsala
1.2 detection system detection required University
shall be able to model.
detect leakage
trend in real time
and send
warning signal.
TR. The leakage Leakage SW Verification Testing Uppsala
1.3 detection system detection required University
shall be able to model.

24
compare real-
time data with
1h, 3h, 6h, 12h,
24h back in time,
as well as 5 and
10 days back.
TR. The leakage Leakage SW Verification Testing Uppsala
1.4 detection system detection required University
shall be able to model.
alert as fast as
one of the
conditions is
met.
TR. The leakage Leakage SW Verification Testing Uppsala
1.5 detection system detection required University/Hi
shall be able to model. tachi Energy
give an actual
alert with 99%
reliability.
TR. The leakage Leakage SW Verification Testing Hitachi
1.6 detection model detection required Energy
shall be able to model.
work as both an
external and an
internal system.
Tabell 1: Technical requirement specifications that are set for the project.

5.2 Software requirement specification

Requirement ID Title System Requirement


Description
SRS. 1.1 Data processing Save at least 24 hours data
of coolant level in the
expansion vessel.
SRS. 1.2 Real time data access The leakage detection
system shall process real
time data.
SRS. 1.3 Data visualization The leakage detection
system shall visualize the
data according to the
model.
SRS. 1.4 Self-checking The last 100 data points of
the level in the expansion
vessel shall be subtracted
with the same number
older data points (time is
specified in TR. 1.3). Then
the mean value of the

25
differences shall be
calculated.
SRS. 1.5 Leakage trend warning The leakage detection
system shall send a
warning “string” in the
python environment when
leakage trend is detected.
SRS. 1.6 Prediction The leakage detection
system shall predict future
values with the help of
linear regression.
SRS. 1.7 Alarm The leakage detection
system shall give an alarm
if one of the predefined
conditions is met, except
for 1h and 3h where both
conditions must be met.
Table 2: Software requirement specifications that are set for the project.

26
6. RESULTS

6.1 Mathematical relationships


There are multiple mathematical relationships which connects various measurements within the
cooling circuit. Based on four weeks of data withdrawn from a facility belonging to Hitachi, a few of
these relationships have been analysed. Mathematical relationships between the measurements
given from the data-file can be used to decrease the fluctuation of the volume measurement. These
measurements are presented below in figure 10, where temperature measurements are shown as
well as in figure 11 where flow-, pressure- and level-measurements are shown.

27
Figure 10: Flow and pressure measurements based on four weeks of data collection from the facility. Four weeks of data
correlates to 241 921 datapoint which represents the x-axis of the plots above.

Figure 11: Temperature measurements based on four weeks of data collection from the facility. Four weeks of data
correlates to 241 921 datapoint which represents the x-axis of the plots above.

What is clear from figure 10, volume in Exp.Ves plot, is that the volume fluctuation in the expansion
vessel is modest over time. A modest fluctuating is preferable for leakage detection, this fluctuation
is highly depended on facility properties such as circuit size, software, compensation etc. Therefore,
to decrease volume fluctuation in less qualitative volume measurement facilities is desirable, other
parameters can adjust and compensate for this fluctuation. Parameters that are directly correlated
to volume level in the expansion vessel can be found by doing a correlation analysis of the
measurements above in figure 10 and figure 11. A correlation plot of the same data as above is
presented in figure 12 below.

28
Figure 12: Correlation plot based on 4 weeks of data (241 921 samples) of a variety of sensor measurements from the
facility.

Pressure and volume in the expansion vessel shares a strong correlation. According to the colour-
analysis, the parameters share an opposite correlation with each other. This is highly relevant since
the leakage detection can be based on the volume and the pressure. Since it is now clear that
pressure affects the volume level, it is of interest to analyse volume in the expansion vessel as a
function of pressure. Firstly, a polynomial which connects volume and pressure needs to be found. A
linear curve fit as well as a representative 2nd and 4th degree polynomial can be determined from
figure 13 below which plots volume as a function of pressure.

29
Figure 13: Volume expressed as a function of pressure over time, in this case over a time period of 4 weeks’ worth of data
from a facility belonging to Hitachi energy.

𝟒𝒕𝒉 − 𝒅𝒆𝒈𝒓𝒆𝒆 𝒑𝒐𝒍𝒚𝒏𝒐𝒎𝒊𝒂𝒍:

𝑦 = (−1.566𝑒 − 04)𝑥 4 + (1.305𝑒 − 01)𝑥 3 − (4.078𝑒 + 01)𝑥 2 + (5.657𝑒 + 03)𝑥 − (2.930 + 05)

𝟐𝒏𝒅 − 𝒅𝒆𝒈𝒓𝒆𝒆 𝒑𝒐𝒍𝒚𝒏𝒐𝒎𝒊𝒂𝒍:

𝑦 = (−2.249𝑒 − 02)𝑥 2 + (8.995)𝑥 + (1.564 )

𝟏𝒕𝒉 − 𝒅𝒆𝒈𝒓𝒆𝒆 𝒑𝒐𝒍𝒚𝒏𝒐𝒎𝒊𝒂𝒍:


𝑦 = (−5.864)𝑥 + 1.175𝑒 + 03

With these polynomials defined, an analysis of volume level improvement regarding correlated
parameters can be made. Volume level as a function of the 1st, 2nd, and 4th degree polynomial as well
as the default level is shown in figure 14 below.

30
Figure 14: Volume in expansion vessel based on pressure correlation. Volume level based on four weeks of data collection
from the facility. Four weeks of data correlates to 241 921 datapoint which represents the x-axis of the plots above.

From figure 14, both polynomials contribute to an improved volume measurement which fluctuate
less than the default volume. This is useful especially in applications where the volume fluctuation is
even stronger. To validate the credibility of the polynomials, the three compensated volume plots in
figure 14 can be compared to the default volume plot by the statistic model of R-squared presented
in equation 1. R-squared model used as a function in python gives the correlation of the data in
percentage. This function applied on the given data gives 65.1% correlation for the 1st-degree, 71.5%
for the 2nd-degree and 79.3% for the 4th -degree compensated data.

Figure 15 shows the normal distribution, see equation 11, over the differences between the real and
expected volume level which is derived from the fourth degree polynomial. The plot below clarifies
the correlation graph, it is clear that the most common differences are less than 6 liter.

31
Consequently, it is safe to assume that adding more parameters would help the accuracy of the
leakage detection model as discussed earlier.

Figure 15: Normal distribution over the difference between real and expected volume level of the 4th-degree polynomial.

6.2 Model interface


The leakage detection model contains an overview of the volume measurement of 24 hours back in
time. This is what figure 16 below presents.

Figure 16: Volume measurement plotted over a period of 24 hours, which corresponds to 8 640 samples at a rate of 6
samples/min. The data in above plot has not been manipulated.

32
As the model is active, a result table is also presented which indicates differences, volume levels,
warnings etc. Figure 17 below presents the corresponding result table to figure 16 which updates for
every iteration.

Figure 17: Result table with multifunctional purpose. The table shows multiple features such as warning, volume
calculations etc.

The result presented in the top table contains mean difference and volume level at given sample for
the five specified time intervals. The mean difference is, as explained in section 4.3.1, the volume
difference at the present time, to the historic volume level at the specified time interval, which is
specified under Volume level at given sample in figure 17.

The result presented in the bottom table contains the following:

• Curve fit
- A linear curve approximation of the last 12 hours of volume measurement.
• Leakage detection status
- An alarm function which activates if the differences given under Mean difference at
given sample in the top table exceeds a given threshold.
• Leakage trend detection status
- A warning system which is activated if the approximated volume level in 12 hours is
larger than 1.25 % of the current volume level. This approximated volume level in 12
hours is based on the linear regression.
• Deviation of volume in exp.ves in 12h

33
- Based on the linear regression, the volume level in the exp.ves can be predicted. The
percentage of deviation of the volume level 12 hours ahead of time compared to the
current volume level is what the Deviation of volume in exp.ves in 12h shows.

• Volume in exp.ves in 12h


- The predicted volume level in the exp.ves 12 hours ahead of time is presented. This is
the volume level which the deviation above is based on.
• Current Timestamp
- The timestamp which the sample was taken is presented in Current Timestamp. Since
the model will show the last 24 hours, the current time is presented furthers to the
right, while 24 hours back in time is presented furthers to the left in the time axis in
figure 15.
• Current Sample
- Each timestamp has a correlated sample. The data has a sample rate of 6
samples/minute. As one day have passed, the timestamp will relap while the sample
count will continue to grow.

6.3 Model testing


Testing and verification of the functionality of the model can, as mentioned in section 4.3.2, be done
in a test environment. This is done by exposing the model to various types of leakage-scenarios
which will simulate a possible leakage. The model has been verified against Five different leakage-
scenarios; these are the following:

• Continuous small leakage over 24 hours


• Continuous medium leakage over 12 hours
• Continuous heavily leakage over 1 hour
• Heavily leakage with stabilisation
• Continuous drop leakage over ten days

where the three former tests all result in a total of roughly 20L over the given timespan. When the
model is exposed to test-environment generated data, a small ripple has been added to the desired
leakage characteristic. This detail is added to simulate noise and small variation in the volume.

- Continuous small leakage over 24 hours


A leakage of 25L/24h is generated in this test. The continuity of this test result in a leakage
detection triggered from the 24-hours detection. Result follows below in figure 18 with
corresponding result in figure 19.

34
Figure 18: Leakage simulation of 25L/24h

Figure 19: Results from leakage simulation of 25L/24h

35
- Continuous medium leakage over 12 hours
A leakage of 20L/12h is generated in this test. Since the leakage is generated after 12 hours,
there is a minor difference between 24 and 12 hours back as well as five and ten days back.
The leakage triggers both the 12- and 24-hours detection. Result follows below in figure 20
with corresponding result-table in figure 21.

Figure 20: Leakage simulation of 20L/12h

Figure 21: Results from leakage simulation of 20L/12h

36
- Continuous heavy leakage over 1 hour
A leakage of 20L/1h is generated in this test. A large jump between the current volume level
and one hour back result in leakage detection regarding all time intervals within 24 hours. If
the leak continuous at this rate, five- and ten-days detection will soon be triggered as well.
Result follows below in figure 22 with corresponding result-table in figure 23.

Figure 22: Leakage simulation of 20L/1h

Figure 23: Results from leakage simulation of 20L/1h

37
- Heavy leakage with stabilisation
Heavily leakage of roughly 20L over a span of two hours which later stabilises. Since the
volume stabilises, one-, three-, six- and 12-hour detection are not in this moment of time
triggered. However, the 24-hours detection is triggered since the difference of volume to
that time interval is large enough. Since the stabilisation came before further amount of
coolant could leak, both the five- and ten-days detection will not be triggered by this
scenario. Result follows below in figure 24 with corresponding result-table in figure 25.

Figure 24: Leakage simulation of roughly 20L over two hours which later stabilises.

Figure 25: Results from leakage simulation of 20L over roughly one hour which later stabilises

38
- Continuous drop leakage over ten days
In this case, a drop leakage of 80L over a span of ten days has been generated. A small drop
leakage is not enough to trigger the alarm within 24h, however, with time there will be a
difference large enough to trigger both the five- and ten-day alarm. Result follows below in
figure 26 with corresponding result-table in figure 27.

Figure 26: Leakage simulation of roughly 80L over ten days.

Figure 27: Results from leakage simulation of roughly 80L over ten days.

39
The results from the tests above together with results from 5. System requirements are presented
below in the three following tables.

Test Result
Continuous small leakage over 24 hours Pass
Continuous medium leakage over 12 hours Pass
Continuous heavily leakage over 1 hour Pass
Heavily leakage with stabilisation Pass
Continuous drop leakage over 10 days Pass
Table 3: Model test result

Result from the system requirements:

Req. ID Result
TR. 1 Pass
TR. 2 Pass
TR. 3 Pass
TR. 4 Pass
TR. 5 Pass
TR. 6 N/A
Table 4: Result of 5.1 Technical requirement specification.

Req. ID Result
SRS. 1 Pass
SRS. 2 Pass
SRS. 3 Pass
SRS. 4 Pass
SRS. 5 Pass
SRS. 6 Pass
SRS. 7 Pass
Table 5: Result of 5.1 Software requirement specification.

6.4 Model requirements

6.4.1 Responsivity
The reaction time of the detection model is dependent on the leakage situation. Consequently, if
one of the conditions that are specified in section 5.1. is met, then a leakage alarm will be sent. This
means that the reaction time varies depending on the size of a leakage. Thereby, a large leakage will
presumably trigger the one- and three-hour detection conditions, resulting in a fast response time.
Furthermore, if a drop leakage occurs, the model will most likely detect this within a couple of days,
resulting in a response time of a couple of days. What is important to understand is that the system
is able to alarm with every iteration, thereby the response time is not affected by a time delay.

40
6.4.2 Limits of detection
The system can detect 20 liter/day, which is based on volume measurement from seven-time
intervals. In addition, the limits are based on the normal distribution. The leakage tolerance for each
time interval is specified below in table 6.

Time interval Leakage tolerance [L]


1h 8.25
3h 11
6h 16
12h 18.7
24h 20
5 days 30
10 days 50
Table 6: Leakage tolerance for given time interval

41
7. DISCUSSION AND CONCLUSION

7.1 Further improvement


7.1.1 Correlation implementation

To implement correlations of other parameters to the model is a way to improve the model even
further. With the insight and knowledge, the project group has assessed it is difficult to deliver a
model that with certainty will work as good as expected. There are many uncertainties which affect
the model in the pressure-volume-correlation. Uncertainties which the project group can not control
or get educated about within the timespan of this project. One of these uncertainties is the fact that
the pressure in the expansion vessel is adjusted to keep it within a preferred level, by doing this
adjustment, the volume level indirectly gets adjusted according to their correlation.

How the volume and pressure is affected when a leakage occurs is also an uncertainty which holds
back the possibility of implementation. If data of observed leakages can be analysed, it would be
possible to confirm the correlations between these and thereby confirm the polynomials presented
in 5.1 MATHEMATICAL RELATIONSHIPS. If these uncertainties become certainties, then they can be
considered. Hence, there could be a great possibility of implementation of correlations which would
enhance the performance of the model even further.

7.1.2 Adjustability and implementation

The program that is used in Hitachi's facilities is HiDraw, while the newly developed model is written
in Python. This is thus another area for improvement where the aim is to overwrite the model to
HiDraw. Model transfer is a step that probably takes time as HiDraw, and Python are two different
programming languages. The advantage of the transfer is that the model can then be tested on a site
before it replaces the existing system. Alternatively, the model can be run in parallel with HiDraw
without translation from Python to HiDraw. However, this would be more complicated, therefore, a
model transfer would be better and smoother. In addition, rewriting the model to HiDraw requires
knowledge of that language, as a result, this could be a continuation project that involves learning
HiDraw and then overwriting the model.

Another possible improvement is to allow the user to select the sample rate as well as the limit of
the minimum allowable leakage amount. This can be accomplished by adding a function in Python
that allows the user to make an input. The advantage of this improvement is that the model can be
changed and be adaptable for different sites in case the fluctuation varies.

42
7.2 Model performance and sources of error
In general, the model meets the requirements that have been set in section 4.2.1 and 4.2.2. The
acquired model has reduced the permitted amount of leakage from 100 liter/day to 20 liter/day,
which is an improvement and better protection for the equipment. One of the main goals (see
section 2.3) was to run the model in parallel with HiDraw, where the aim was to compare them with
each other. This was not feasible because the Python environment is not compatible with Hitachi's
present software system.

As mentioned in section 5.3, the model has been tested to verify its ability and speed to detect
leakage. Therefore, different leakage scenarios have been created to mimic a real leak as much as
possible. The result was as expected, where the model managed to send warning signals of a
leakage. In addition, access to real leakage data was requested, however, that was not possible due
to lack of logged data. Consequently, the verification model was only built on simulated leakage.

The developed model is primarily adapted for data obtained from a site belonging to Hitachi Energy,
where the fluctuation is stable. Data from another site was also received at a later stage, which had
a greater fluctuation compared to the first one. Nonetheless, the model was still capable to detect
leakage thresholds that were set in the requirement specification. In addition, greater fluctuation
would lead to a deeper analysis regarding the influence of relevant parameters. Alternatively, a
better compensation of the volume would decrease fluctuation, as a result, the present model can
be applied.

The goal at initial stage was to reduce the permitted amount of leakage to 20 liter/day. Since the
model is based on subtraction of volumes, theoretically, there is a possibility to reduce the border to
a lower limit. However, the reason why the border was not lowered further was due to avoidance of
false alarms.

Finally, despite the moderate fluctuation, a relatively sensitive leakage detection could be realized.
The model can detect 20 liter/day, with no false alarms. Combining more features, e.g., pressure in
expansion level and ambient temperature, would result in a more sensitive leakage detection model.
Because the system would react on a lower leakage threshold, but at the same time it would require
more conditions from the different features to detect anomalies in the system. However, due to
small data accessibility, it is difficult to draw any conclusions regarding the relation between the
different features, since the reliability of an anomaly detection is low with a small data package.

43
REFERENCE
[1] Research on New Leakage Detection Technology for Converter Valve Cooling System, Rongxing Yu
et al 2019 IOP Conf. Ser.: Mater. Sci. Eng. 612 032063, available at:
https://iopscience.iop.org/article/10.1088/1757-899X/612/3/032063/pdf [2022 May 18]

[2] Leakage detection system for critical cooling circuits, Endress+Hauser AB, available at:
https://portal.endress.com/dla/5000232/1505/000/01/IN00012SEN_04_EN_02.15.pdf
[2022 April 22]

[3] Ultrasonic leak detection, UE systems INC, the ultrasound approach, available at:
https://www.uesystems.com/applications/ultrasonic-leak-detection/?gclid=CjwKCAjw9-
KTBhBcEiwAr19igwWKHP5nLH5ReqdY8bsLOfbCeF10ZS5VqfnyF2BFI7pJ0JAVup4sdxoC6dAQAvD_BwE
[2022 May 15]

[4] R-squared, Jason Fernano, published 2021 September 12, available at:
https://www.investopedia.com/terms/r/r-squared.asp [2022 May 27]

[5] PHYSICS HANDBOOK for Science and Engineering, Nordling and Österman, Ninth Edition, p.463.

[6] PHYSICS HANDBOOK for Science and Engineering, Nordling and Österman, Ninth Edition, p.457.

[7] 9.1.5 Mean Squared Error (MSE), Hossein Pishro, published 2020 September 12, available at:
Mean Squared Error (MSE) (probabilitycourse.com)

[8] Understanding the mathematics behind gradient descent, Parul Pandey, published 2019 may 18,
available at: Understanding the Mathematics behind Gradient Descent. | by Parul Pandey | Towards
Data Science [2022 May 27]

[9] PHYSICS HANDBOOK for Science and Engineering, Nordling and Österman, Ninth Edition, p.458.

[10] STANDARD DEVIATION, National Library of Medicine, retrieved 2022 May 26, available at:
https://www.nlm.nih.gov/nichsr/stats_tutorial/section2/mod8_sd.html [2022 May 27]

[11] Normal distribution, Adam Augustyn, updated 2022 May 26, available at:
https://www.britannica.com/topic/normal-distribution [2022 May 27]

APPENDICES
(1) Gantt-chart
(2) Python-script of the model
(3) Python-script of test environment (Data manipulation generator)

44
Gantt-chart:

Tidsschema Kandidatarbete
Instudering befintligt system
Träff 1
Datainsamling, materiell
Avgränsningar, Mål
Projektplan
Projektplangodkännande
Moment

Genomförande
Träff 2
Sammanställande, Analys
Rapportskrivning
Rapportdeadline
Presentationskrivning
Träff 3
Presentation Hitachi Energy

1 2 3 4 5 6 7 8 9 10 11
Arbetsvecka

Python-script of the model:

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import statistics
import numpy as np
from sklearn.linear_model import LinearRegression
from tabulate import tabulate

plt.style.use('fivethirtyeight')

data = pd.read_csv('leakgen.csv')
df = data.head(86400)
x = list(range(0, 8639))
yett = list((df['BASEP2_VCCP_EXPV_LEVEL_TO_OWS'])*23.32)
timebuff = list(df['$Time'])

difflist1h = []

45
difflist3h= []
difflist6h = []
difflist12h = []
difflist24h = []
difflist5d = []
difflist10d = []

def animate(i):

data = pd.read_csv('leakgen.csv')
x.append(8639+i)
timebuff.append(data.iloc[8640+i,0])
yett.append(data.iloc[86400+i,1]*23.32)
timelist = timebuff[-8640:]
y1 = yett[-8640:]

difflist1h.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[86040+i,1]*23.32)))
difflist3h.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[85320+i,1]*23.32)))
difflist6h.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[84240+i,1]*23.32)))
difflist12h.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[82080+i,1]*23.32)))
difflist24h.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[77760+i,1]*23.32)))
difflist5d.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[43200+i,1]*23.32)))
difflist10d.append(abs(((data.iloc[86400+i,1])*23.32) - (data.iloc[1+i,1]*23.32)))

m1h = statistics.mean(difflist1h[-100:])
m3h = statistics.mean(difflist3h[-100:])
m6h = statistics.mean(difflist6h[-100:])
m12h = statistics.mean(difflist12h[-100:])
m24h = statistics.mean(difflist24h[-100:])
m5d = statistics.mean(difflist5d[-100:])
m10d = statistics.mean(difflist10d[-100:])
plt.cla()

if (m1h > (8.25) and m3h > (11)) or m6h > (16) or m12h > 18.7 or m24h > 20 or m5d > 30
or m10d > 50:
b=('Leakage detected')
else:
b=('No leakage detected')
x1 = np.arange(4320).reshape(-1, 1)
y2 = y1[-4320:]
xtest = timelist[-4320:]
modelone = LinearRegression().fit(x1, y2)
if modelone.intercept_ >= 0:

46
c = f'+{modelone.intercept_}'
else:
c = modelone.intercept_

future12h = (modelone.coef_*(8640+i)) + modelone.intercept_


futurediff = 100*(future12h/(data.iloc[(86400+i),1]*23.32))

if futurediff > 101.12 or futurediff < 98.75:


a=('Leakagetrend detected, inspect graph')
else:
a=('No leakagetrend detected')

approxone = modelone.predict(x1)
curvfit = f'{modelone.coef_}x{c}'

plt.plot(timelist, y1, label ='Vol.exp.ves', color = "red")


plt.plot(xtest, approxone, label = 'Curve fit Vol.exp.ves', color = "black")
# plt.plot(timelist[::20], y1[::20], label ='Vol.exp.ves', color = "red")
# plt.plot(xtest[::20], approxone[::20], label = 'Curve fit Vol.exp.ves', color = "black")

low = min(y1) - 4
high = max(y1) + 4
plt.ylim(low,high)
plt.xticks([0, 1440, 2880, 4320, 5760, 7200, 8638])
# plt.xticks([0, 86, 172, 258, 344, 430])
plt.legend(loc='lower left')
plt.title('Leakage detection model')
plt.ylabel('Volume [L]')
plt.xlabel('Time')

tableone = [['', 'Mean differance at given sample', 'Volume level at given sample'],
['Current sample', 0, data.iloc[86400+i,1]*23.32],
['1h back', m1h, data.iloc[86040+i,1]*23.32],
['3h back', m3h, data.iloc[85320+i,1]*23.32],
['6h back', m6h, data.iloc[84240+i,1]*23.32],
['12h back', m12h, data.iloc[82080+i,1]*23.32],
['24h back', m24h, data.iloc[77760+i,1]*23.32],
['5d back', m5d, data.iloc[43200+i,1]*23.32],
['10d back', m10d, data.iloc[1+i,1]*23.32]]

tabletwo = [['Curve fit: ', curvfit],


['Leakage detection status: ', b],
['Leakagetrend detection status: ', a],

47
['Deviation of volume in exp.ves in 12h: ', f'{abs(100-futurediff)}%'],
['Volume in exp.ves in 12h: ', future12h],
['Current Timestamp: ', timelist[-1:]],
['Current Sample: ', x[-1:]]]

print(tabulate(tableone, tablefmt='fancy_grid'))
print(tabulate(tabletwo, tablefmt='fancy_grid'))

plt.tight_layout()

ani = FuncAnimation(plt.gcf(), animate)


plt.show()

Python-script of test environment (Data manipulation generator):

import csv
import pandas as pd
i=0
y_value = 1050
x_value = 0

fieldnames = ["$Time", "BASEP2_VCCP_EXPV_LEVEL_TO_OWS"]


data = pd.read_csv('mergedd.csv')

with open('leakgen.csv', 'w') as csv_file:


csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
csv_writer.writeheader()

while True:

with open('leakgen.csv', 'a') as csv_file:


csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

info = {
"$Time": x_value,
"BASEP2_VCCP_EXPV_LEVEL_TO_OWS": y_value,
}

csv_writer.writerow(info)
if i < 84000:
y_value = data.iloc[i,4]
x_value = data.iloc[i,1]
i += 1
# elif i > 84000 and i < 85000:

48
# y_value = data.iloc[i,4]-((5/3816)+random.uniform(-0.005, 0.005))
# x_value = data.iloc[i,1]
# i += 1
else:
y_value = (y_value-(25/10494))
x_value = data.iloc[i,1]
i += 1

print(i,x_value, y_value)

#
#20L/12h : 25/125928 : i=82080
#20L/1h: 25/10494 : i=86040
#25L/24h : 25/251856: i= 77760
#85L/10d : 5/125928: i=1

49

You might also like