Fuzzy Logic for Solving the Water-Energy Management Problem in Standalone Water Desalination Systems: Water-Energy Nexus and Fuzzy System Design

This work investigates an important topic of energy and water security (water-energy nexus). For this purpose, Water-Energy Management Strategy (W-EMS) for a standalone water desalination system powered by PV-Wind source is designed. The proposed W-EMS is based on fuzzy logic. In this context, authors focus on the design phase of the Fuzzy Inference System (FIS) through which three design methods are described and analyzed. The influence of FIS design on W-EMS performance is highlighted. First, it is shown that based on the designer’s knowledge, the handmade-FIS can offer good performance for the W-EMS. Then, the water-energy management is formulated as an optimization problem. Therefore, genetic algorithm is used to optimize the FIS design to reduce iterative hand-tuning trials. Furthermore, the design of the fuzzy W-EMS can be addressed by a data-driven approach as a third step. This method shows its good performance in terms of water production and energy efficiency compared to the designed FISs by the two previous methods (handmade tuning and genetic algorithm).


INTRoDUCTIoN
Energy Management Strategies (EMSs) present a major concern for researchers (Cai et al., 2009) working on complex energy systems such as: decentralized generation systems (Ball et al., 2009), residential applications (Aki et al., 2006), block-chain for smart city (Orecchini et al., 2019), hybrid renewable energy system (Benmessaoud et al., 2019) as well as standalone water pumping/ desalination systems (Sallem et al., 2009;Kyriakarakos et al., 2017).Therefore, several EMSs have been proposed in literature for various complex energy systems, while it is still difficult to determine the best approach in each situation.These EMSs can be classified into two categories: Rule-based and Optimization-based approaches (Salmasi, 2007).Rule-based energy management approaches are well known for their simplicity in implementing rules and their effectiveness for real-time supervisory control of energy flows into a complex energy system (Lee et al., 2000;Tekin et al., 2007).Such rules are designed based on intuition, heuristics, human expertise, even mathematical model, but without a prior knowledge of operating conditions (e.g.electric power profile, driving cycle for electric vehicles, etc.).The rule-based approaches, in turn, can be subdivided into: i) deterministic rule-based methods, and ii) fuzzy rule-based methods.Deterministic rules are generally implemented based on lookup tables (not real-time data) (Han et al., 2014;Garcia et al., 2009) to schedule energy flows between the system components.Fuzzy rule-based methods are widely adopted for complex real-time supervisory control issues enabling to realize a real-time and optimal power split (Arcos- Aviles et al., 2016;Tidjani et al., 2016;Tan et al., 2021;Mitiku et al., 2019;Chanda et al., 2019).Indeed, three main advantages of the fuzzy inference systems can be listed as follows: i) no real-time calculation issues, ii) robustness (tolerance to imprecise measurements), and iii) adaptation (easy tuning) with real-time parameters (Salmasi, 2007;Tie et al., 2013).This paper focuses on the fuzzy logic theory for energy management issue.
For example, in (Zhang et al., 2010) authors presented four EMSs for a local power distribution system of more electric aircraft.The proposed EMSs are based on two multi-objective strategies using fuzzy logic and two simpler mono-objective strategies based on standard PI controller.Simulation and experimental results demonstrated that fuzzy logic is appropriate for: i) multi-objective approaches, ii) processing a large number of input variables, and iii) integrating several constraints.In (Cabrane et al., 2017) a management strategy based on fuzzy logic theory was developed for photovoltaic energy storage in order to maintain the state of charge of batteries and super-capacitors within acceptable levels.The effectiveness of the proposed strategy to continuously meet the energy requirement of the load has been demonstrated.In addition, a Fuzzy Logic-based EMS (denoted FLEMS) for a residential grid-connected micro-grid was presented in (Arcos-Aviles et al., 2016), where the fuzzy inference system was designed for smoothing the grid power profile while keeping the state of charge of the battery within secure limits.Moreover, authors in references (Yin et al., 2016;Naffati et al., 2013) showed some examples of optimal adaptive FLEMS for hybrid electric vehicle with an objective to find the optimal instantaneous power distribution between the different energy sources in the vehicle.
Given the above state of the art, fuzzy logic is successfully used for energy management of complex energy systems with the advantages of: i) the adaptability and easy optimization of its design parameters, and ii) the ability to cover all the expected conditions into the studied system.Nonetheless, relatively small changes in the Fuzzy Inference System (FIS) parameters can signiðcantly affect the EMS performance.Indeed, the performance of a fuzzy logic-based EMS strongly depends on: i) the choice of the number and shape of the membership functions of each fuzzy variable, ii) the choice of fuzzy rules, iii) the type of the Defuzzification method, and iv) many other FIS parameters.Setting the FIS parameters with its control fuzzy rules primarily depends on the designer's expertise with regard to the energy management constraints, the intuitive and practical aspects about the system energy behavior, as well as successive experiments to ensure reliability and robustness of the process (Ferreira et al. 2008).In addition, the choice of these parameters is not deterministic and usually designers need a procedure of adjustment trials to find the suitable design of the FIS.In many cases, the performance of the fuzzy EMS can be improved by further hand tuning of the FIS parameters.
On the other hand, Wang et al. explained in (Wang et al., 2006) that the FIS design can be formulated as a search problem in large space, where each point represents a set of membership functions, control rules, and the corresponding system behavior.According to authors, given certain performance criteria, the system performance constitutes a "hyper-surface" in the space, and determining the optimal FIS design consists of finding the optimal location of this hyper-surface.Wang et al. have demonstrated through (Wang et al., 2006a;Wang et al., 2006b) that evolutionary algorithms (e.g.genetic algorithm) offer a good tool for hyper-surface search than conventional methods.
Another methodology to design the FIS is presented in (Courtecuisse et al., 2010) for fuzzy logic-based supervision of hybrid renewable generation system using a graphical modeling tool.The latter, which is an extension of Petri nets and grafcets approaches, enabled to facilitate the analysis, the determination and the implementation of fuzzy system algorithms.
Besides to the above mentioned techniques (evolutionary algorithms, graphical modeling tool, and hand tuning) to design the FIS for energy management field, neuro-fuzzy hybrid systems have also emerged as an advanced artificial intelligence technique when compared to classical fuzzy inference system (i.e., a Mamdani type structure FIS).Indeed, for this type of FIS, artificial neural networks are used to design the FIS especially when no predetermined model structure exists, but when a collection of input/output data of the target system is available.Those data are usually collected in simulations, physical experiments, or production processes, etc.Among the existing fuzzy-neural hybrid systems, Adaptive Network-based Fuzzy Inference System or also called Adaptive Neuro-Fuzzy Inference System (ANFIS) is the most popular structure and widely used in the energy management field (Ozturk et al., 2013;Cárdenas et al., 2012;García et al., 2013;Mahesh et al., 2016).The ANFIS is a hybrid structure combining fuzzy logic principle and the artificial neural network concept.During the training process driven by the collected input/output data, the trained FIS (a Takagi-Sugeno type structure) is fine-tuned (i.e.,the rules and membership functions) by the neuro-adaptive learning techniques so as to tailor the trained FIS to the input/output data set.For example, an ANFIS-based EMS for a grid-connected micro-grid was synthesized in (Leonori et al., 2017) through a data-driven approach relying on clustering algorithm to set the membership functions and the rule consequent hyperplanes.Moreover, a comparison study between fuzzy logic and neuro-fuzzy algorithm was conducted in (Arshdeep et al., 2012) to control the compressor speed of air conditioning system.The used ANFIS has proven its performance over conventional fuzzy logic to make the air conditioning system adaptive to the room weather with higher energy efficiency.
Fuzzy logic methods can range from the simplest one to the most complex through hybridization of which the list is even longer (Suganthi et al., 2015), such as neuro-fuzzy-genetic algorithm (Kampouropoulos et al., 2014), fuzzy Q-learning using reinforcement learning (Avanija et al., 2022), fuzzy logic and machine learning (Zermane et al., 2020), Mediative micro artificial neural network fuzzy logic (Kocharla et al., 2022), etc.
The use of fuzzy logic theory is widespread in technical literature and the industry, while using it in water-energy management for water desalination system to deal with energy dispatch between two hydro-mechanical processes (i.e.,water pumping and desalination processes) was not issued in literature.In the present work, the studied system consists of an autonomous Brackish Water Reverse Osmosis (BWRO) desalination system powered by renewable energy source (hybrid solar photovoltaic generator and wind turbine) dedicated to the freshwater production for small remote communities without access to freshwater and electrical grid.First of all, this work investigates an important topic of energy and water security (energy-water nexus), considering the increasing population and the scarcity of water in poor or developing areas, combined with the need to mitigate climate change by reducing carbon emissions.Renewable energy-driven RO desalination systems are considered as dynamic systems characterized by multi-domain, non-linear and time-varying variables (electric power, water pressure and flow rates).Therefore, smart and robust control algorithms, such as fuzzy logic techniques, are required to improve the real-time energy control and management strategy of such autonomous systems.A huge number of research work on reverse osmosis desalination systems are published.Most of them focused on eco-design (Peñate et al., 2012;Mohamed et al., 2004), socioeconomic (Ghaffour et al., 2015) and techno-economic (Ghaffour et al., 2013;Gude et al., 2010;Al-Karaghouli et al., 2009;Eltawil et al., 2009;Kaldellis et al., 2004;Agrawal et al., 2016) aspects.However, water-energy management issue for such systems has received less attention and according to the authors' knowledge related work to the fuzzy logic-based water-energy management strategy for desalination systems are strongly limited in literature, if not rare.
Secondly, this paper presents a non-exhaustive study, but reasonably sufficient, of the Fuzzy Inference System (FIS) design for such a specific application.For this purpose, based on their experience, authors present in this paper three different methods, among other, to design the FIS, which are: i) handmade tuning method based on the own designer's expertise, ii) genetic algorithm (fuzzy-genetic algorithm tuning), and iii) neural network algorithm (neuro-fuzzy tuning).Authors explain through this application case (water-energy management for a standalone desalination system) the process of each design method, discuss and analyze the obtained results when applying each designed FIS into the water-energy management strategy.It is evidenced through this study that the design phase is of paramount importance for an efficient and/or optimized water-energy flows management into the system, especially when FIS parameters are changed.Authors highlight the influence of the FIS design on the performance of the Water-Energy Management Strategy (W-EMS); it is demonstrated that by further tuning of the FIS parameters such as the fuzzy partition of the input/output spaces (i.e.,universe of discourse), the choice of the shape and the number of the input/output membership functions, and the fuzzy control rules, the performance of the designed fuzzy logic-based W-EMS can be significantly improved for the autonomous desalination system.Moreover, the comparison between the optimization method by genetic algorithm and neuro-fuzzy system was not given before in the studied field although they are familiar methods.
This paper is organized as follows: the specifications of the system under study and the experiments regarding the system energy behavior are introduced in Section 2.Then, the water-energy management problem is set in Section 3.These elements (i.e.,understanding of the system behavior and the water-energy management constraints) constitute the preliminary phase for the designer to set the initial fuzzy system-based Water-Energy Management Strategy (W-EMS).Section 4 presents the first method to design the fuzzy system, which is made by hand tunings mainly based on the user's expertise.The different steps of the Hand-Made FIS (HMFIS) design, such as Fuzzification, fuzzy inference and the rule base are described in this section.Section 5 is dedicated to analyze the HMFIS performance when applied into the W-EMS.According to the carried-out analysis, the HMFIS design is improved in Section 6.The different improvements and simulation results of the improved HMFIS-based W-EMS are described in this section.Section 7 is reserved to explain the second method for the FIS design, which is based on the genetic algorithm.In this section the usefulness of the genetic algorithm to limit the hand adjustment trials time to find the optimal FIS design is evidenced compared to the improved HMFIS.The third method of the FIS design is described in Section 8, which is the neuro-fuzzy technique (ANFIS), a data-driven method; this technique uses the artificial neural networks to estimate, based on input/output data base, the FIS design.The effectiveness of the ANFIS system to improve the performance of the W-EMS compared to both the handmade FIS and the GA-optimized FIS is demonstrated in this section.Section 9 is dedicated for drawn conclusions.

SPECIFICATIoNS oF THE BWRo DESALINATIoN SySTEM overview of the Studied System
The studied Brackish Water Reverse Osmosis (BWRO) desalination system, depicted in Figure 1, is dedicated to meet freshwater demand of a small community in remote areas with no access to freshwater and electrical grids, but where renewable energy resources are abundant.The system consists of small-scale standalone brackish water pumping and desalination application supplied with a variable generated power offered along wind speed and solar irradiation conditions without battery storage.An experimental BWRO desalination test bench was designed and implemented in the Electrical Systems Laboratory (LSE at the ENIT-UTM in Tunis-Tunisia) to be used as a prototype, where its freshwater production is rated at 7.2 m3/d.This experimental test bench (depicted in Figure 2) is powered by a programmable DC power source rated at 4 kW which physically emulates the power generated by the renewable energy source (photovoltaic PV-wind turbine).The intermittent power dc "given" according to solar and wind conditions is transferred via a DC bus to the hydromechanical processes of the BWRO test bench.Technical information about the experimental test bench are reported in Table 2.The studied system mainly includes two independent hydro-mechanical processes that are decoupled through an elevated water storage tank T1: 1.The first hydro-mechanical subsystem (Water Pumping Process) is dedicated to brackish water conveyance from the well to the storage tank T1, using a single-stage motor-pump (denoted Well Pump, WP) as depicted in Figure1.2. The second hydro-mechanical subsystem (RO-Desalination Process) is devoted to producing freshwater through a Reverse Osmosis (RO) desalination process consisting of a multi-stage High Pressure motor Pump (HPP), feeding at high pressure a RO membrane to produce freshwater.
Indeed, water is a very good storage medium; the electric energy can be stored in the form of water into water storage tanks when renewable energy is abundant.Therefore, brackish water can be simultaneously pumped (stored) and desalinated when the energy supply is abundantly available, and be stored if not.This may alleviate the expensive buck-up systems need in remote areas with good renewable energy resources.Within this configuration the 'gravitational water storage' involves an advantage of great importance in terms of energy efficiency improvement.
It should be pointed out that the experimental test bench was designed such as the hydraulic load (the RO membrane) is modular so that other membranes can be added.That's why two RO membranes are considered during simulations.

Experimental Characterization of the System for Water-Energy Management
The studied system is a complex energy system which complexity is characterized by the combination of components of different natures and functionalities, all interacting within the system under study.Such heterogeneity leads to several physical phenomena coexistence and several system constraints of different domains making difficult the modeling and the energy flows (power, water) management of the system under study.Given the diversification of the system constraints namely, functioning under variable energy supply (i.e.,variable feeding power and pressure), technological constraints of pumping devices (power ranges) and membrane (flow-pressure range), and functioning constraints (filling state of the storage tank), an experimental characterization of the desalination system is then mandatory.Given a hydraulic load characteristic, the suitable power range [pumpmin -pumpmax] of each pumping device was experimentally identified (the operating pressure range of the hydraulic load is intrinsically included).Indeed, the suitable hydraulic load characteristic enabling to achieve a water production- efficiency tradeoff was experimentally determined as depicted in Figure 3 and Figure 4 (for more details please see (Ben Ali et al., 2020)).This is considered a first step to prepare the prerequisites for an effective water-energy management.According to the experimental characterization, the hydro-mechanical processes constraints are summarized in Table 2.It should be noted that these values are corresponding to 4g/L as brackish water salinity and to 4m storage tank elevation.
Regarding the storage tank T1, the amount of the stored water is generally divided into two volumes: the so called "Dead Volume" where water Level L < Lmin.This volume will never be used because it is reserved for sedimentation of pumped water.Generally, we have to reserve 0.2m height for the Dead Volume in the tank.The second part is called "Useful Volume" where water Level is: Lmin ≤ L ≤ Lmax.This volume is reserved to be used by the RO-process to be treated.The maximum level was chosen at Lmax = 2m while reserving the upper 0.1m (total height of tank is 2.1m) as a secure margin to avoid the "tank overflow".
The sought objective of the system is to maximize the freshwater production as much as possible according to the available renewable energy.For this sake, a specific water-energy management strategy is required to meet the objective while taking into account the system constraints.

STATEMENT oF THE WATER-ENERGy MANAGEMENT PRoBLEM FoR THE DESALINATIoN SySTEM
Besides the variable nature of the PV/Wind-turbine generator power supply, the absence of the electrochemical storage device such as batteries, makes the electric energy/water supply a challenging issue for the remote regions.Therefore, a suitable Water-Energy Management Strategy (W-EMS) is required to determine the appropriate electric power dispatching between the two water subsystems with respect to: i) the given generated power dc, ii) the operating power range of each pumping device [pumpmin -pumpmax] , and iii) the current filling state of the storage tank T1: the level L of the stored water in the tank must vary on its specified confines (Lmin ≤ L ≤ Lmax).
In order to resolve such an electric power dispatching problem, a "power sharing factor" (α) is then defined.It enables to instantaneously determine the power dispatching between the two hydro-mechanical processes according to the constrained water-energy management rule expressed by Equation 1.Given that electrochemical storage was replaced by hydraulic storage in water tanks, electric energy management and hydraulic energy (here water) management can be coupled.Accordingly, the defined W-EMS enables to manage simultaneously the electric energy and water flows into the system while fulfilling the technological (electric power range of motor-pumps) and functioning (tank filling state) constraints during the system operation: where dc, HPP and WP denote the generated power from the power source transferred via DC bus, and the assigned electric powers to the HP-Pump (HPP) and the Well-Pump (WP), respectively.It should be pointed out that the considered case study limits the approach to 2 devices (motorpumps), but the methodology may be extrapolated to any number (n>2) of sub systems.

HAND-MADE FUZZy INFERENCE SySTEM (HMFIS) DESIGN FoR THE WATER-ENERGy MANAGEMENT: FIRST STEP
The Fuzzy Inference System (FIS) constitutes the decision-making tool for the proposed W-EMS to determine the aforementioned power sharing factor.The decision-making is made on the basis of input states (i.e.,electric power and tank filling state) taking into consideration constraints of the system elements, and the defined criterion (maximizing freshwater production).
Generally, FIS design is mainly based on heuristics and the knowledge base of the user (the expert).It is usually characterized through the following steps: The Fuzzification, the inference engine and the Defuzzification.

Fuzzification
It consists of determining the "fuzzy subsets" and the linguistic variables for the inputs/outputs: each input and output is divided into a number of overlapped levels (fuzzy subsets) characterized by "membership functions".They are developed based on the pre-defined limits of system components (cf.Table 2).
A two inputs-single output FIS is designed, where the generated power dc and the current Filling State (FS) of the storage tank T1 (given that FS (%) = (L/Lmax)• 100) are defined as the FIS inputs, and the power sharing factor (α) as the FIS output.
Figure 5 shows the Membership Functions (MFs) of the input/output variables describing their boundaries and depicts the shape and universes of discourse.The first input dc is divided according to the operating power range of the two pumps into "four" fuzzy subsets represented by "four" MFs using the linguistic variables {L, M, QH and H}.The acronyms description of linguistic variables and the numerical range of MFs are reported in Table 3. Triangular shape is chosen for {M and QH} membership functions, and Trapezoidal shape for {L and H} membership functions.The range of values varies from 120W to 2820W as the universe of discourse representing respectively the minimum power needed to run the Well Pump (WPmin = 120W), and the sum of maximum functioning powers (WPmax + HPPmax = 2820W).The second input (FS) of the storage tank is divided into "three" fuzzy subsets characterized by "three" Triangle membership functions using the linguistic variables {L, M, and F}.Its universe of discourse is within the range of 10 -100% representing the water level limits in the storage tank.As for the output, it represents the power sharing factor enabling to instantaneously share the current power dc over the two pumps according to Equation 1 while respecting the constraints.The fuzzy output is divided into "five" overlapped levels represented by "five" Triangle membership functions using the linguistic variables {OFF, A, B, C and D}.Where, the first subset (OFF) causes the HP motor Pump (HPP) shutdown.The rest of fuzzy subsets involve its operation, from the subset (A) which limits the use of the HPP to a moderate ratio, until quasiexclusively favoring desalination (D) over the pumping mode.The output universe of discourse is within the range of 0 -1.

Fuzzy Inference and Rule Base
The fuzzy inference can be defined as a "mapping formulation process" from a given input to the output using fuzzy logic based on a fuzzy rule base.The fuzzy inference process includes: i) membership functions, ii) fuzzy logic operators (AND, OR), and iii) "IF-THEN" linguistic rules making possible to transcribe in a simple way the user's expertise (i.e.,the human know-how) acquired from simulations and experimentation with the system installed in our research laboratory LSE.(Figure 2).In order to compute the output value (i.e.,the power sharing factor value) the mapping includes "Fuzzification", "Aggregation" and "Defuzzification" sub-processes as illustrated in Figure 6: the degrees of membership of the "IF" parts of the fired rules are evaluated (Fuzzification phase), and the "THEN" parts of the fired rules are weighted by these degrees of membership, and Aggregated using the OR operator.This gives a resulting surface characterized by a resulting membership function (MF) obtained by forming the maximum of partial MFs, given that the latter are related by the OR operator.At the end, the Defuzzification is applied to the resulting surface to obtain a crisp value of the output factor (see (Lee et al., 1990) for more information on fuzzy logic controller).This factor, in turn, determines the references of the feeding electric powers (HPP* and WP* ) that should be assigned to each motor-pump according to Equation 1.
The designed FIS was implemented using "Mamdani" architecture with 12 fuzzy control rules relating the two inputs with the output factor.The rule base is reported in Table 4.The performance of the designed FIS strongly depends on its fuzzy rule base.The latter is determined so that motorpumps operate on their optimal efficiency region and the tank filling state (FS) varies on its specified confines, with the purpose of maximizing the freshwater production.For instance, in case of Low power generation ("dc[i] is L") and if the storage tank is Full ("FS[i] is F"), the user must take advantage of all generated power for only the desalination process to maximize freshwater production, therefore (" ).This leads to the following rule: IF dc is L AND FS is F THEN α is D In Addition, if the power generation is Quite High ("dc[i] is QH") and if the water level in the tank is Low ("FS[i] is L"), the user should take advantage of the available generated power to thoroughly desalinate the available amount of brackish water while respecting the secure limit (Lmin) of the storage tank.This leads to the following rule: IF dc is QH AND FS is L THEN α is D In other case, if the power generation is abundant (High) ("dc[i] is H") (i.e.,dc[i] > HPPmax) and if the water level in the storage tank is Low ("FS[i] is L"), the power can be shared between the two motor-pumps since the generated power is enough to operate simultaneously the two water processes as long as the tank is not used up.So, the value of the power sharing α should be an average value enabling the system to store brackish water and produce freshwater, as well.This leads to the following rule:

IF 𝒫dc is H AND FS is L THEN α is B
The "AND" method used for the FIS design is "MIN", the implication (THEN) operator is "MIN", the Aggregation is "MAX", and the Defuzziðcation method used is the "Centroid" method.The latter is considered as the most popular Defuzzification method which returns the centroid of area under curve (step 3 in Figure 6).

Introduction to the Analysis
After having designed the FIS, the latter is implemented into the W-EMS in order to evaluate its performance.Simulation results of the fuzzy W-EMS are presented in Figure 7 for a daily power profile.The latter is extracted from real-data of PV-Wind power generation recorded every hour from January to December 2007 of a region in Southeast Tunisia: Djerba-Midoun.The considered sampling period is 2.5 minutes (i.e., the sampling period is Ts = 2.5 x 60 = 150s).Indeed, an interpolation was performed on the recorded power profile in order to modify the sampling period (1 hour) which represents a long time interval for the W-EMS.All simulations were coded in MATLAB© Software.The presented power profile values vary on its universe of discourse (120-2820W) as described in the above section and the initial Filling State is fixed at FS0 = 15%.Simulation results show that the implemented fuzzy rules (Table 4) are coherent with the proposed W-EMS described by Equation 1 and its objective.Moreover, simulation results comply with the system constraints; the water level in the storage tank is kept varying on its confines during the day and the supply power of each pump is within its operating power range.For example, when the generated power (dc) is High and the tank filling state (FS) is also High, we can abundantly produce freshwater while pumping brackish water in a moderate way (i.e.,the WP water flow rate is QWP ≤ QHPP) in order to prevent tank overflow.This way, the designed FIS enables to take benefit of the available generated power while respecting the system constraints.This demonstrates the good performance of the designed FIS in terms of power dispatching and compliance with system constraints.
However, the designed FIS presented some limitations during the treatment of some operating cases out of boundaries leading to affect its performance.In order to evaluate the FIS performance, the power profile amplitude and the initial filling state (FS0) of the tank can be varied.These factors (the power amplitude and FS0) significantly influence the decision making of the FIS.
The outstanding situations are highlighted here in order to analyze the FIS performance.For this reason, a theoretical short-time interval power profile is chosen to focus on each studied case and show in details the influence of these factors on the system behavior and accordingly on the W-EMS performance.The power profile is sampled every five seconds for a total time scale of 200 seconds in the simulation.Then, some constraints are violated in order to investigate their impact on the system behavior.
When observing Figure 8-(b) and Figure 9, a poor decision-making of the fuzzy W-EMS is noticed during some time intervals, that are illustrated through inappropriate behavior of the system in these figures.This is caused by a violation of some constraints related to the system operation.This problem can be split into two sub-problems: • The first one is related to the first FIS-input variable which is the generated power dc.
• The second one is related to the second FIS-input variable which is the filling state FS of the storage tank.
These two problems are analyzed in the following two subsections.This problem is illustrated by Figure 8.The simulation started with a full tank (i.e.,initial tank filling state FS0 = 100%) using a variable power profile denoted (A) (Figure 8-(a)) where its maximum magnitude value is 2820W.This case shows the good performance of the fuzzy W-EMS.Nonetheless, when using the power profile (B) depicted in Figure 8-(b), where the maximum magnitude value reaches 3700W, while maintaining the same initial filling state of the tank, there is inappropriate behavior: the maximum limit in the storage tank is exceeded at the instant t2 (i.e., tank overflow).Indeed, during the interval time [t1 -t3] the input power is no longer into the universe of discourse (i.e., dc > 2820W).As a result, the fuzzy system gives a random value of the power sharing factor (e.g.here α = 0.5).

Influence of the Second FIS-Input Variable: The Tank Filling State (FS)
The effect of the filling state violation reveals through two different cases: in Figure 8-(b) at t ≥ t3, a poor behavior of the system is noticed although the input power is within the universe of discourse: the two pumps operate simultaneously (i.e.,pumping and desalination mode) which is inacceptable because in this case the Well Pump must be switched off.This is explained by the fact that the water level or the filling state (FS) of the tank is actually out of universe of discourse [10 -100%] .Secondly, in case of empty tank (FS0 = 9% < FSmin) as depicted in Figure 9, normally the system should pump water in the well to increase the water level in the storage tank, while the High Pressure Pump (HPP) must be switched Off.However inacceptable behavior is noticed: the two pumps operate simultaneously during the interval time [t0 -t1] .This can be explained by the fact that this case (i.e.,constraint violation on the filling state) has not been treated beforehand (FS0 ∉ [10 -100%] ).As a result, when an input value does not belong to the universe of discourse, it leads to a random decision-making.In the light of the above analysis, the FIS could be effective and offer good performance in terms of power dispatching, when varying the operating conditions of the system and for different input power amplitudes, by providing "the necessary intelligence" to the FIS to be designed.This enables to prevent in real-time approach the occurrence of any mistreated case beforehand (i.e.,during the off-line phase).For this sake, in the next section the FIS design will be improved in order to perfect its intelligence.

HMFIS DESIGN TUNING AND IMPRoVEMENT: SECoND STEP
The performance of the FIS, and accordingly, the fuzzy logic-based W-EMS depends on the number and shape of the membership functions of each fuzzy variable, and on the choice of the fuzzy rules.The adequate choice of these parameters is crucial to reach the water-energy management objective (maximizing the freshwater production of the desalination system following weather conditions) and for maintaining the tank filling state FS within its specified confines.For this purpose, the designed FIS will be improved in this section by adjusting and tuning some setting parameters, namely: • The number of membership functions of the two fuzzy inputs.
• The fuzzy rule base.Indeed, a priori additive fuzzy rules are planned to the previous rule base to deal with the exceptional cases mentioned in the previous section.The improvements are explained below.

Universe of Discourse Tuning
Assuming that we already knew the input power profile, we can predefine the appropriate universe of discourse to this profile.Given the previous power profile (B), we can choose [0 -4000W] as the universe of discourse of the dc variable which is an oversized profile with respect to the system requirements.The chosen range concourse meets the alleged requirements.

Membership Functions Tuning
The chosen universe of discourse can be subdivided more than previously into "six" overlapped levels using the linguistic variables {Quite Low (QL), Low (L), Medium (M), Quite High (QH), High (H) and Very High (VH)}.The membership functions of the input variable are shown in Figure 10.A Trapezoidal shape is chosen for the membership functions {QL and VH}, and Triangle shape for others.

Universe of Discourse Tuning
For the same raisons, the filling state range [0 -105%] is defined as universe of discourse of the FS variable.Indeed, the tank is 2.1m height corresponding to 105% value since we have defined the maximum storage limit (Lmax = 2m) as 100% to prevent tank overflow.

Membership Functions Tuning
Based on the chosen universe of discourse, "five" membership functions {Empty (E), Low (L), Medium (M), Full (F) and Overfilled (OF)} are set.Trapezoidal shape is chosen for the membership functions {E and OF}, and Triangle shape for others (Figure 10).
It should be noted that parameters for the output variable are kept the same as shown in Figure 5.

Improvements on the Rule Base
The new rule base is composed of the initial 12 fuzzy rules given in Table 4 to which are added additive fuzzy rules in order to ensure the robustness and reliability of the process to deal with critical cases.The improved rule base includes now 30 fuzzy rules that are reported in Table 5.

Simulation Results of the Improved HMFIS-Based Water-Energy Management Strategy
Simulation results show that the improved HMFIS is able to properly deal with water-energy management problem discussed in the previous section.In  where the storage tank is initially full, the improved fuzzy water-energy management strategy (W-EMS) reaches to manage simultaneously the electric energy and water flows into the system while respecting the constraints.The FIS gives the priority to the desalination process over pumping process by giving higher values for the power sharing factor (α).In order to prevent tank-overflow the pumping process operates in moderate manner (i.e.,QWP < QHPP) simultaneously with desalination process.This seems very interesting since it leads to take benefit of the abundant renewable energy while respecting the system constraints.Moreover, in Figure 11-(b), where the tank is initially totally empty the improved FIS imposes the HP Pump (HPP) shutdown despite the abundant generated power in order to prevent the "vacuum suction" problem.In such conditions the priority is given to the pumping process where the Well Pump (WP) operates with its maximum water flowrate (QWP = QWPmax).In order to be effective, and after a certain moment, it becomes possible to switch-On the HP pump to operate in moderate manner such as: QWP > QHPP.This permits to take benefit of the abundant renewable power leading to maximize the freshwater production.
In order to evaluate the improved HMFIS performance over a long period of time, a weekly power profile is applied.It is extracted from the real data of PV-Wind power generation of Djerba-Midoune region where the sampling period is set to 2.5 min.Simulation results are shown in Figure 12 demonstrating the good performance of the improved HMFIS in terms of power dispatching and compliance with the system constraints.
In light of the above outcomes, the improved HMFIS-based W-EMS enables, on the one hand to effectively manage the water/power flows into the desalination system, and on the other hand to make good use of the renewable generated power in order to maximize as much as possible the freshwater production while respecting the technological (power ranges) and the functioning (filling state of the tank) constraints of the system.
The next section is dedicated to show how optimization algorithms can significantly reduce the time of hand-adjustment trials and improve the FIS design.

FIS DESIGN oPTIMIZATIoN TECHNIQUE: GENETIC ALGoRITHM-BASED FIS DESIGN (GAFIS)
As previously explained, the design phase of a fuzzy inference system (FIS) consists of the choice of its different parameters, namely:  • The number and shape of membership functions (MFs) per input/output and the location of their characteristic points/parameters.• The fuzzy rules.
• The Defuzzification method.This phase was essentially based on hand and iterative adjustment trials according to the expert analysis of obtained results: first of all, the initial FIS design was set by: i) setting the MFs of input/ output variables (i.e.,number, shape, location and mapping), ii) setting the initial rule base, and iii) choosing the Defuzzification method.Then, the MFs of the input/output variables have been adjusted while tuning the rule base and even the Defuzzification method.Nonetheless, in energy management optimization problems it is very difficult to find an optimal combination of all of these parameters.Indeed, each choice of design parameters leads to a new different FIS that may affect the W-EMS performance as previously explained.The best possible solution provides better power dispatching, but needs lots of human expertise and a huge number of tests to be found.Therefore, to find an optimal FIS design and limit adjustment trials time, an optimization algorithm appropriate for FIS design problems should be used, namely the Genetic Algorithm (GA).In order to make the design optimization more efficient, only the FIS parameters that have major effects on the FIS performance should be considered.Indeed, after an in-depth expertise following the previous study, the designer is able to discern whether the FIS parameter has a great or negligible influence on the final result.Hence, those parameters that most influence the FIS performance (accordingly the performance of the fuzzy W-EMS) for this application are determined as:  5).
The genetic algorithm (GA) optimization process of the improved HMFIS was performed on a daily power profile, where the optimization objective is to maximize the freshwater production.This phase was detailed in (Ben Ali et al., 2018) where the performance of the GA optimized FIS (denoted GAFIS) was evidenced in terms of freshwater production compared to the HMFIS.
The optimized membership functions of the inputs of the GAFIS (genetic algorithm-optimized FIS) in comparison with those of the Hand-Made FIS (HMFIS) are depicted in Figure 13.The optimized rule base is reported in Table 6.The Defuzzification method obtained by the GA optimization is the BISECTOR method instead of the previously chosen Centroid method.
Comparison results between the HMFIS and the GAFIS are reported in Table 7 for different seasonal power profiles.When applying the GAFIS for different input power profiles, better results (i.e., higher freshwater quantity) are always obtained compared to the HMFIS results (improvement of 3.3% during Autumn).In addition to freshwater production, higher stored amount of brackish water (improvement of 63% in Summer) can be noticed in Table 7, and less energy loss are noted when using the GAFIS (based on the consumed energy Ec and non-consumed energy Enc as key performance indicators).These findings demonstrate the usefulness and effectiveness of the genetic algorithm as an optimization tool for FIS design.
Till now, the design phase of a "Mamdani-FIS structure" was introduced.The basic structure of a Mamdani-type FIS is a mapping process that maps input characteristics to input membership functions (MFs), the latter to control rules, in turn, rules to the different output characteristics, then, output characteristics to output MFs, and finally, the output MFs to a single crisp output value.In such a system, MFs and fuzzy rules are either chosen and predetermined by the expert, or obtained based on a tuning procedure using an optimization algorithm to find the optimal design.Another method may also be useful for tuning the FIS parameters that can be classified among data-driven approaches.This approach is explained in the next section.

NEURo-FUZZy DESIGN TECHNIQUE: ANFIS
Adaptive Neuro-Fuzzy Inference System (ANFIS) is a Takagi-Sugeno FIS whose MFs parameters are tuned and adjusted using a given input/output data set (see (Jang, 1993;Jang et al., 1995) for more information about ANFIS).This adjustment enables fuzzy system to learn from data they are modeling.

When to Use Neuro-Adaptive Learning
Supposing that the designer aims to apply a fuzzy inference system to the presented BWRO desalination system for which he already has a collection of input/output data that he wants to use for modeling or other similar scenario.However, the designer does not have a predetermined model structure.In such modeling situations, designer cannot discern what MFs should look like by simply looking at data.Given that the shape of MFs depends on their parameters as previously demonstrated, modifying those parameters may affect the MF shape and, accordingly, the FIS performance.Hence, instead of just looking at the data to choose arbitrarily the MF parameters, the latter here can be automatically identified using Fuzzy Logic Toolbox neuro-adaptive learning techniques so as to tailor the MFs to the input/output data.This enables designer to account for variations in data values.Indeed, the aforementioned Fuzzy Logic Toolbox learning technique is integrated in the 'anfis' function available in MATLAB software, that accomplishes the tuning and adjustment of MF parameters based on the training collected data.

Model Learning and Inference
The neuro-adaptive learning method is a network-type structure working similarly to that of neural network using either back propagation alone or in combination with least squares method for membership function parameters estimation (Jang, 1993).These neuro-adaptive learning techniques offer to the fuzzy modeling procedure a method to learn information about a given data set.So, the fuzzy logic toolbox 'anfis' command allows training the FIS model to emulate the given training data by modifying the MF parameters according to a given error criterion.In other words, it computes the MF parameters that best enable the associated FIS to track the input/output data.

Model Validation Using Testing Data Set
Model validation constitutes the process to check how well the trained FIS model predicts the checking data set output values.During this process, the designer uses a testing (or checking) input/output data set on which the resulting FIS was not trained.Usually, the training and testing data sets are gathered based on observations, simulations, or physical experiments of the target system, and are stored in two separate data files.

ANFIS Design Example
The Neuro-Fuzzy Designer application available in MALAB software is used to generate and train a new Sugeno-type FIS (two inputs-one output as shown in Figure 14) for water-energy management of the BWRO desalination system.The used input/output database here is collected from results of a deterministic rules-based water-energy management strategy which was previously performed (see (Ben Ali et al., 2020)).
Figure 15 depicts the input membership functions of the resulting ANFIS.Table 8 shows the simulation results of the ANFIS-based W-EMS, which are very close to the GAFIS-based W-EMS results during Spring.The presented ANFIS, using the neuro-adaptive learning technique, enables to improve, on the one hand, the total water production of the studied system, and the system energy

CoNCLUSIoN
This work investigates an important topic of energy and water security (water-energy nexus), considering the increasing population and the scarcity of water in poor or developing areas, combined with the need to mitigate climate change by reducing carbon emissions.The main innovation lies in the application field in that the use of the fuzzy logic in water-energy management for desalination systems to deal with energy dispatch between two hydro-mechanical processes (pumping and desalination) was not issued in literature.
In this context, the paper is focused on the detailed description of how a Fuzzy Inference System (FIS) can be designed for water-energy management.For this purpose, based on their experience, authors presented three different methods, among other, to design the FIS, which are: i) handmade tuning method based on the designer's expertise, ii) genetic algorithm (GA), and iii) neural network algorithm (NNA).Authors explained, through a specific application (water-energy management for a standalone renewable energy-driven desalination system without electrical storage device) the process of each design method.Authors highlighted the influence of the FIS design on performance of the Water-Energy Management Strategy (W-EMS).
Firstly, the study showed that the W-EMS performance can be improved by further tuning the design parameters of the fuzzy system (the FIS) such as: i) the fuzzy partition of the input/output spaces (i.e. the universe of discourse), ii) the choice of the input/output membership functions, iii) the fuzzy control rules, and iv) the Defuzzification method.In addition, it was demonstrated that based on human expertise, heuristics, and intuition the choice of these parameters is not deterministic and usually requires an adjustment trial procedure to find the optimal FIS.Relatively small changes in these parameters involve a new fuzzy system requiring large human expertise and a big number of tests to find the optimal design.
Secondly, it was shown that given performance criteria, evolutionary algorithms like GA (or also particle swarm optimization, PSO) offer good tools to find the optimal design, while limiting adjustment time and keeping a minimum of human analysis in the optimization phase.
Thirdly, another interesting design approach of the FIS which is the ANFIS, was also described.It is based on neuro-adaptive learning driven by data that can be collected in simulations, physical experiments, or production processes.This method allows automatically estimating the FIS parameters according a given error criterion so as to tailor the trained FIS to the input/output data.
Nonetheless, although the good performance offered by the FIS in the energy management field, nothing guarantees that the "optimized" or "estimated" parameters of the FIS are still appropriate for different scenarios of the studied system, namely: • Rough changes in weather conditions (e.g.successive cloudy sky or very low wind speed) leading to a drastically difference between the harvested power and that used during the FIS design process, especially for the GA-optimization process.• Modifying the initial filling state, FS0, of the water storage tank (similarly to the state of charge, the SOC, of the battery storage into electrical vehicles) that is different from that used as an operating condition during the GA-optimization process of the FIS design.Indeed, varying the operating conditions to which the GA-optimization process was performed will affect the FIS performance.• Potential measurement errors in the collected data which is used for estimating the ANFIS parameters.
In order to overcome FIS design limitations, survey-based fuzzy inference systems can be an alternative for fuzzy systems design by combining the knowledge from different experts.However, because experts do not all agree, they will determine different FISs with different membership functions and different fuzzy rules.Type-2 fuzzy inference systems enable to combine the knowledge from different experts and to handle this uncertainty (e.g. about the meaning of the words, the rule consequence, the measurements, etc.).
Another solution of great interest is the W-EMS based on adaptive fuzzy system, where several GAFISs that are obtained for different operating conditions (i.e.different FS0 of the water storage tank or different power profiles), are invoked in real-time to be applied in the W-EMS according to the corresponding operating conditions.This solution is under study and one can say that it may offer better results and deal with the GA-optimization drawback.

Figure 1 .
Figure 1.Synoptic of the autonomous BWRO desalination system

Figure
Figure 2. The BWRO desalination experimental test bench

Figure 3 .
Figure 3. Experimental characterization of the water pumping process

Figure 4 .
Figure 4. Experimental characterization of the RO desalination process for brackish water salinity of 4 g/L

Figure 6 .
Figure 6.Computational process of the output factor inside the fuzzy inference system

Figure 7 .
Figure 7. Simulation results of the fuzzy logic-based W-EMS for a daily power profile

Figure 9 .
Figure 9. Simulation results of the fuzzy W-EMS for the power profile (A) and initial tank filling state FS0=9%

Figure 10 .
Figure 10.Membership functions of input variables of the improved Hand-Made FIS (HMFIS)

•
The MF parameters for both input variables: the placement of the first point (i.e., first parameter: a ) for each Triangle MF.Indeed, a Triangle MF is characterized by three parameters: a , b and c , where a and c define the base and b defines the height of the Triangle.• The fuzzy rules (only those presented in bold type in Table

Figure 13 .
Figure 13.Membership functions of the two inputs for the GAFIS and the improved HMFIS

Table 8 . Comparison of fuzzy W-EMS results obtained with the improved HMFIS, the GAFIS and the ANFIS tested during Spring
(by presenting the lowest value of Enc) on the other hand.Therefore, users can apply the obtained ANFIS for real-time energy management. efficiency