# Fuzzy Regulator for Two-Phase Gas-Liquid Pipe Flows Control
## 5 Implementation  
The fuzzy regulator was implemented according to a schema shown in Figure 2.  
The regulator consists of:  
1. The module for input signal fuzzification (1) that contains the first class (measurement data) (2) and second class (flow type) (3) signals fuzzification modules,
2. The diagnostic signals (\(Z_{1}\), \(Z_{2}\), \(Z_{3}\)) retrieved from the measurement instruments,
3. The flow type reference signal set by the user (\(Z_{4}\)),
4. The inference rules module (4),
5. The inference module based on the modified fuzzified Mamdani implication,
6. The defuzzification module that implements the center of sums defuzzification method (5) and which processes the fuzzified control signals (\(Z^{\prime}{}_{1}\) and \(Z^{\prime}{}_{2}\)),
7. The module of the crisp sets (\(n_{1}\) and \(n_{2}\)) (6). The first step of implementation is to determine the membership functions that can transform the domain of the measured signal (i.e., streams of gas and liquid) from crisp into fuzzy form. The most proper solution for this is to use function (3) with the acquisition time interval \(t\) equal to 15 s. The data acquisition frequency results from the period for a single complete measurement frame acquisition (about 1 Hz). Next, the trapezoidal-shape membership function must be determined to split the measurement range of gas and liquid streams into the values of the first-class linguistic variables (_fuzzified gas stream_ and _fuzzified liquid stream_). These membership functions are used in premises and conclusions of the inference rules. To correctly determine the shape of the membership function, it is required to collect a series of test measurement data. This should be done in the presence of an expert who can recognize (classify) the two-phase flow types. The gas and liquid streams intensity was changing sequentially within the discrete measurement range of the pump and compressor to generate all possible flow types. Next, each stabilized state was evaluated. The expert, not being aware of the values of the current settings, assessed the flow type in the pipeline only based on observations. Then, all the flow types should be printed on the chart as depicted in Figure 3. All flows' series, observed in the whole measurement range, are split into all flow type occurrence areas. To better clarify this description, the implementation of the control strategy and the obtained results are shown in Section 6 for two specific flow configurations, plus one case which is transitional between the two. The procedure explained here is analogous for the other flow types, for both horizontal and vertical pipelines. For the test data presented in Figure 3 it is possible to determine the following membership functions (using clustering or expert method):  
* For the linguistic variable--fuzzified gas stream: \[\mu_{small\;gas^{\prime}}(x)=\left\{ \begin{array}{c}1\to\;x\leq 5\\ (-x+6)^{fumLoG(a)}\to x\in(5;6)\\ 0\to\;x\geq 6\end{array} \right.\] (9) \[\mu_{middle\;small\;gas^{\prime}}(x)=\left\{ \begin{array}{c}0\to\;x \leq 4\\ (0.5x-2)^{fumMLoG1(a)}\to x\in(4;6)\\ 1\to x\in(6;15)\\ (-x+16)^{fumLoG2(a)}\to x\in(15;16)\\ 0\to x\geq 16\end{array} \right.\] (10)  
Figure 3: The decomposition types of the test flows’ series are determined within the whole measurement range. \[H_{middle\;large\;gas^{\prime}}(x)=\left\{ \begin{array}{c}0\to\;x\leq 14.5\\ (0.5x-7.25)^{funMLaG1(a)}\to x\in(14.5;16,5)\\ 1\to\;x\in(16.5;36)\\ (-x+16.5)^{funMLaG2(a)}\to x\in(36;37)\\ 0\to\;x\geq 37\end{array} \right. \tag{11}\]  
\[\mu_{large\;gas^{\prime}}(x)=\left\{ \begin{array}{c}0\to x\geq 35\\ (0.5x-17.5)^{funLaG1(a)}\to x\in(35;37)\\ 1\to\;x\leq 37\end{array} \right.