1 Introduction

Fresh water is essential for humans, and modern societies concentrate around sources of fresh water. However, between 10% [1] and 25% of the world’s population does not have adequate access to fresh water [2]. Moreover, increases in the global population, coupled with drought and desertification due to climate change, will undoubtedly aggravate water security. Water desalination substations provide a useful solution to remedy these problems. However, an inherent problem in these substations is the need for electric energy and the high cost of the desalination seawater or brackish water, which could be resolved by using innovative energy solutions that can participate in helping 18% of the global population that lacks access to electricity [1]. This problem has led to researchers investigating the use of renewable energy systems (RESs) for water desalination, especially for remote communities without access to electricity. With the vast expanse of Saudi Arabia, water scarcity is a critical issue for remote areas. Most remote societies without access to electricity use diesel engines to power desalination substation, which could cause a shortage of fresh water when there is no fuel. Therefore, RESs provide a suitable alternative to supply these communities with their needs from electric power.

Many types of water desalination systems have been introduced in the literature [2,3,4,5,6,7,8,9,10], including solar distillation, vacuum distillation, multi-stage flash distillation, multiple-effect distillation, vapor compression distillation, reverse osmosis (RO), membrane distillation, etc. The use of RES for driving reverse osmosis desalination systems (RODSs) is one of the best options in remote areas because it does need fuel transmission, and it provides a safe, feasible, and reliable source of energy. Moreover, RODS technology is advancing, it is widespread in many places worldwide, its price is continuously dropping, and it produces fresh water with relatively lower energy consumption than other technologies. Fresh water can be produced from both seawater and brackish water using a RODS [2,3,4,5,6,7,8,9]. A review of the drawbacks of using renewable energy systems in water desalination and other application are shown in [11]. For these reasons, RODS technology was selected to be investigated in this paper as water desalination technology. The RODS size is computed according to the amount of fresh water produced, while RES-rated values are designed to satisfy the required energy for a RODS to produce the required amount of fresh water based on the wind speed and solar irradiance of the site.

Different sources of RESs with and without storage systems can be used to supply a RODS with the electric energy needed for its operation. Some researchers have introduced RODSs working from wind energy systems without an energy storage system [3]. Other researchers introduced photovoltaic (PV) energy systems without battery storage [4,5,6,7,8,9]. These systems are very cost-effective because the expensive and short-lived storage system is not included in these systems. However, RODSs working from RESs without energy storage systems are unreliability due to the intermittent nature of the RES sources, such as wind or photovoltaic energy systems. Therefore, many RODSs use hybrid RESs with battery storage and/or fuel cells and hydrogen tanks to store energy when needed [12, 13]. Some studies recommend using a water tank to store extra desalinated water for later use when water production is lower than consumer needs [2]. Using a water tank reduces the size of the battery storage required to store the surplus energy required to account for shortages from RES generation. An exergy analysis of a hydrogen and water production by using a solar-driven transcritical CO2 power cycle with Stirling engine is introduced in [14, 15]. This study aimed to further utilizes the highest possible exergy using a novel system for hydrogen and fresh water production. This system used a Stirling engine instead of a condenser in abundant access places to solar radiation and brackish or sea water.

Hybrid RESs are containing wind turbines (WTs), PV modules, battery systems, and water tanks can be used together to increase the reliability of the system. An iterative technique [7] was used to obtain the sizing of the RES required to minimize the cost of fresh water production. Another iterative procedure using a RES and other sources, such as an electric utility or diesel generation system, was introduced by Koutroulis and Kolokotsa [2] without performing economic optimization. The connection of different components of the hybrid system can be accomplished based on three different configurations in which the components can be connected to the common DC busbar, AC busbar, or mixed between DC and AC busbars. Each configuration has its advantages and disadvantages, which have been discussed extensively in [16]. Based on this study, a mix between AC and DC busbars was selected for this research because of its superior performance and high efficiency compared with the other configurations shown in Fig. 1. The reliability of the operation of the RODS is a function of the size of the energy storage systems. Therefore, it is important to compromise between the cost of the energy storage system and the adequate reliability of the water supply. Moreover, for the highest reliability and lowest cost, it is necessary to perform optimization operations to select each system component’s optimal size. Many iterative techniques have been used to determine the best option for sizing the RES for supplying a RODS. One of these techniques is using the iterative procedure to design the optimal size of a PV system for a RODS [17,18,19]. These iterative techniques provide a suitable option for sizing the RES and RODS, but there is no guarantee that this solution is the optimal one. Hybrid RESs with several components and several factors inherent in each component provide a challenge to using iterative techniques to perform the optimal design of the hybrid RES for RODS applications. Modern soft computing techniques, such as swarm techniques, can be useful for the selection of the optimal size of the RES that can supply the RODS with the required amount of electric energy. The particle swarm optimization (PSO) technique has been used several times to optimally design a hybrid RES for RODS [20,21,22]. The PSO technique is a powerful optimization tool that can be used for this purpose, but it may capture local optima. Moreover, the PSO optimization time is sometimes long, especially with a higher number of variables. The Genetic Algorithm (GA) optimization technique has also been used in several studies [23, 24]. The GA is one of the evolutionary techniques that can be trapped in one of the local optima and is suffering from complexity and long convergence time. Simulated annealing (SA) [25] and gray wolf optimization (GWO) [26] techniques have also been used for the optimal design of a hybrid RES for use in supplying a RODS. Other researchers have used hybrid optimization techniques, such as PSO-GWO, for this purpose to accurately determine the global optimal values and to improve the convergence speed [27]. The results obtained from this hybrid optimization technique [27] have been compared with the results obtained from each optimization technique separately. The results obtained from the hybrid PSO-GWO showed better performance than using PSO or GWO alone. However, this technique introduced complexity into the system, and the improvements in this hybrid technique are not clear. Moreover, this hybrid optimization technique requires substantial effort to tune the control parameters of PSO and GWO. Therefore, it is essential to find another optimization technique to conduct these optimization requirements without adding complexity or lowering the convergence speed and reliability of capturing the optimal solution. The bat algorithm (BA) optimization technique, which was introduced in 2010 [28], is a modification of the PSO technique. This technique is characterized by a very fast and accurate convergence performance for low-dimensional problems [29, 30] such as the case studies presented in this paper. This powerful optimization tool has never been used in the design of the renewable desalination system, and for this reason, it was selected for investigation in this paper. A modern optimization technique, called the social mimic optimization (SMO) technique [31, 32], was also be used in the optimization of the hybrid system, and it was compared with the well-known PSO and BA optimization techniques.

Fig. 1
figure 1

Configuration of the reverse osmosis desalination system

In this paper, we conduct optimization of a RODS powered by a RES for supplying fresh water to Arar City located in the northeast of Saudi Arabia. The proposed RES contains WTs, PV modules, batteries, and a water tank, along with their control systems and power conditioner. A new optimal matching between the site and the WTs was introduced in the sizing processes. A total of 10 market-available WTs were studied to select the best one for the Arar site which include the WT matching strategy with the sizing of the RES components. Moreover, the optimal sizing of the RES components was used to determine the lowest cost and highest reliability of fresh water produced from the system. The loss of supply probability (LOSP) is used to evaluate the reliability of the proposed system during the year. A detailed cost analysis of the proposed system was conducted to cover all details of the proposed system, taking into consideration the salvage value and operating and maintenance costs. The optimization techniques used in this problem were PSO, BA, and SMO. The latter two techniques have not been used before in the design of desalination systems, and for this reason, they were used and compared with the previously used PSO technique. Results are shown for different levels of reliability to see the effect of the high LOSP level on the cost of desalinated cubic meters of fresh water. This paper indicates that lower LOSP leads to higher confidence from the RODS system and higher costs of the generated energy and fresh water produced and vice versa.

The rest of the paper is structured to show the proposed system in Sect. 2. Section 3 shows the power flow in a RES and the energy balance between the generation, battery, and the load. Section 4 presents the cost analysis and economic issues used in the simulation section. Section 5 introduces the three optimization techniques understudy, while Sect. 6 shows the simulation work. Recommendations and conclusions are summarized in the final section.

2 Proposed System

Different renewable energy sources with different storage systems can be used to feed a RODS with the energy it requires. Wind turbine-only RODSs can be used at low cost to effectively produce desalinated water. However, although a wind energy system without battery storage has a lower cost, its reliability is very low since fresh water can only be produced when wind speed and solar irradiances are sufficient to satisfy RODS requirements. A water tank can solve part of the problem, as the water stored in a tank can feed the customer during the electric power generated using a RES is deficient. Moreover, battery storage can also be used to store the surplus generated electric energy for use during deficit periods. The proposed hybrid RES and RODS is shown in Fig. 1. This system uses WTs and a PV array as a renewable generation system. Lead–acid batteries will be used as an electric storage system. The configuration of the system uses a mixed configuration between DC and AC busbars, which shows better performance and higher efficiency [16]. The operating characteristics of these components are provided in the following sections.

2.1 Wind Energy System Modeling

WTs can have different performance characteristics from site to site, and for this reason, it is necessary to match the site with an appropriate WT. Statistical analysis was conducted to determine the capacity factor (CF), where the CF represents the relationship between the average generated power from a WT and its rated power. The WT with the highest performance can be selected as the best option based on technical considerations. Meanwhile, selecting the best WT should take technological and economic parameters into consideration [33].

Hourly wind speed, u, is modeled using the Weibull distribution where its probability density function can be expressed in terms of Weibull parameters, scale parameter, c, and shape parameter, k, as shown in Eq. (1). The value of k and c can be determined from the iterative process presented by Stevens and Smulders [34], as shown in Eqs. (2) and (3), respectively. The CF of using WT parameters and site wind speed is shown in Eq. (4). The average amount of power generated from a WT at a certain site is equal to the CF multiplied by the rated power of the WT as shown in Eq. (5) [35].

$$ f\left( u \right) = \frac{k}{c}\left( \frac{u}{c} \right)^{k - 1} \exp \left( { - \left( \frac{u}{c} \right)^{k} } \right),\,\,\,\,\,\,\,\left( {k > 0,\,u > 0,\,\,c > 1} \right)\,\,\, $$
(1)
$$ k = \left( {\frac{{\sum\limits_{j = 1}^{N} {u_{j}^{k} \ln \left( {u_{j} } \right)} }}{{\sum\limits_{j = 1}^{N} {u_{j}^{k} } }} - \frac{{\sum\limits_{j = 1}^{N} {\ln \left( {u_{j} } \right)} }}{N}} \right)^{ - 1} $$
(2)
$$ c = \left( {\sum\limits_{j = 1}^{N} {u_{j}^{k} } /N} \right)^{\frac{1}{k}} $$
(3)
$$ C_{F} = \frac{{\exp \left[ { - \left( {u_{C} /c} \right)^{k} } \right] - \exp \left[ { - \left( {u_{r} /c} \right)^{k} } \right]}}{{\left( {u_{r} /c} \right)^{k} - \left( {u_{C} /c} \right)^{k} }} - \exp \left[ { - \left( {u_{F} /c} \right)^{k} } \right] $$
$$ P_{W,av} = C_{F} *P_{R} $$

where uj is the wind speed at time step j, N is the number of time steps, and PR is the rated power of the WT.

The hourly generated power at wind speed u from a WT was calculated following Tzen et al. [10].

$$ P_{w} \left( v \right) = \left\{ {\begin{array}{*{20}l} 0 \hfill & {u \le U_{C} \;\& \;u \ge U_{F} } \hfill \\ {P_{R} *\frac{{u^{k} - U_{C}^{k} }}{{U_{R}^{k} - U_{C}^{k} }},} \hfill & {U_{C} \le u \le U_{R} } \hfill \\ {P_{R} } \hfill & {U_{R} \le u \le U_{F} U_{R} \le u \le U_{F} } \hfill \\ \end{array} } \right\} $$
(6)

where UC, UR, and UF are the WT cut-in speed, rated speed, and cutoff speed, respectively.

2.2 Photovoltaic Energy System Modeling

The electric power generated from the PV system is substantially affected by the irradiance falling on the PV as well as its area. It is recommended to tilt the PV modules with an optimal tilt angle to increase the irradiance and, consequently, the energy generated from a PV system. This optimal tilt angle is chosen to be equal to the latitude angle of the site [16]. The hourly generated power from the PV array was determined using Eq. (7).

$$ P_{PV} \left( t \right) = H_{t} \left( t \right)*PVA*\eta_{c} \left( t \right) $$
(7)

where Ht is the solar radiation on an optimally tilted surface, PVA is the total area of PV array, and ηc(t) is the hourly efficiency of a PV array, which was obtained using Eq. (8).

$$ \eta_{c} \left( t \right) = \eta_{cr} \left[ {1 - \beta_{t} \times \left( {T_{c} \left( t \right) - T_{cr} } \right)} \right] $$

where βt is the temperature coefficient, which was set at 0.005 per °C following [36], Tcr and ηcr are the solar cell temperature and efficiency, respectively. Tc(t) is the instantaneous solar cell temperature at the ambient temperature (Ta), which was obtained using Eq. (9).

$$ T_{c} \left( t \right) = T_{a} + 3H_{t} \left( t \right) $$
(9)

2.3 Battery Storage Model

When a battery is being used, it loses some of its charge whenever it is charging, discharging, or storing energy. The factor that characterizes the loss of its energy is called the self-discharge rate. The equation that shows the state of charge (SOC) of the battery due to the self-discharge rate (SDR) is given by Kaabeche et al. [37].

$$ E_{B} \left( {t + 1} \right) = E_{B} \left( t \right)\,\left( {1 - \sigma } \right) $$
(10)

where EB is the rated energy of the battery bank and σ is the battery SDR, which was taken to be equal to 0.2% per day in this study [38]. To protect batteries during overcharge and undercharge operating conditions, the SOC of batteries should follow the restriction in Eq. (11).

$$ E_{B,\min } \le E_{B} \left( t \right) \le E_{B,\max } $$
(11)

where EB,max and EB,min are the maximum and minimum allowable storage capacities of the battery bank, respectively. EB,min is a function of the allowable depth of discharge (DOD), which is recommended by the manufacture of the battery, as shown in Eq. (12). In the simulation in this paper, the value of DOD was chosen to be 70%, and the value of maximum allowable energy of the battery, EB,max, was chosen to be equal to the nominal storage capacity of the battery bank, EBR.

$$ E_{B,\min } = (1 - DOD)\,\,\,\,E_{BR} $$
(12)

2.4 Reverse Osmosis Desalination Unit Production

Various mathematical models of RODSs are presented in the literature. The cost of fresh water production depends on the pressure level used in the RO pipes and the water salinity. The energy required to produce one cubic meter of water from a RODS varies from 2 to 10 kWh. The RODS model used in Dashtpour et al. [39] was used in the simulation program. The specific energy consumption from this model is 2.44 kWh/m3.

The well-known formula for calculating the head loss due to friction and the formula for calculating the power consumption is given in Eqs. (13) and (14) following Dashtpour et al. [39]:

$$ H_{f} = \frac{{8fLQ^{2} }}{{g\pi^{2} D^{5} }} $$
(13)
$$ P = \frac{\rho ghQ}{\eta } $$
(14)

where f is the friction coefficient, L and D are the length and diameter of the pipe, Q is the flow rate m3/h, g is the gravitational acceleration, and η is the efficiency of RO system.

2.5 Energy Balance

Three different configuration systems can be used to interface the components of the hybrid system, DC, AC, and mixed AC and DC configurations [16]. In the DC system, all the components are connected to the main DC busbar where all the generating sources should be transferred to the DC source and there is only one inverter to convert the DC power to AC to be suitable for the RODS system. The main problem of this system is the low efficiency due to rectifying the power from AC sources, such as diesel or WTs to DC and then reinverting it again to AC. Moreover, all power transferred from DC to the load should be converted to AC power through an inverter, which reduces the efficiency of the system [16]. In the AC configuration, all components should be connected to the main AC bus. So, the power from DC sources, such as fuel cells, should be converted to AC first, and this power can be transferred to load or it may be rectified again to DC power to feed the battery, which may reduce the overall efficiency. The best option is to use a DC bus and AC bus, as shown in Fig. 1, which is called a mixed AC/DC configuration [16]. In this figure, the wind energy system is connected to an AC bus because its output is AC. Meanwhile, the PV and batteries are connected to a DC bus because their output is DC. This configuration will increase the overall efficiency where each component is connected to the appropriate busbar type (also see [16, 40]). The primary finding of these studies is that the mixed AC/DC configuration has the best efficiency. Therefore, it is used in this study.

A configuration containing the fuel cell, electrolyzer, and hydrogen tank has been introduced in many studies [41, 42]. The battery is still more economically feasible compared with the fuel cell, but with the fast development in fuel cell technology, its price is getting lower, and it may compete with batteries in the near future. A detailed comparison between the use of batteries versus the hydrogen tank is shown in [43]. The results obtained from [41,42,43] showed that the battery is still a cheaper and more reliable storage option. Therefore, it is used in this study. The energy balance of a mixed AC/DC system is shown in the following sections.

2.5.1 Charging Mode

The charging mode means that more electric power is generated from a RES than the amount of power needed for a RODS, and the surplus electric power can be fed to the battery system if its SOC is lower than the maximum value, EB,max. The surplus power should be discarded when the batteries are full and there is surplus power from the RES systems. The logic behind this mode of operation is shown in the following equations.

If \(P_{W} \left( t \right) > P_{RO}\) and \(E_{B} (t) < E_{B,\max }\), then the surplus power will charge the battery by PBC(t) as shown in (Eq. 15); meanwhile, the discharging power from the battery, PBD(t), is zero.

$$ P_{BC} \left( t \right) = \left[ {\left( {P_{W} \left( t \right) - P_{RO} } \right)\,\eta_{inv} + P_{PV} \left( t \right)} \right]\,\,\eta_{BC} $$
(15)

If \(P_{W} \left( t \right) > P_{RO}\) and \(E_{B} (t) \ge E_{B,\max }\), then the battery will not be able to obtain extra energy, and the control system will get rid of the extra power by controlling the output power from WTs and the PV system.

$$ P_{BC} \left( t \right) = P_{BD} \left( t \right) = 0 $$
(16)

If \(P_{W} \left( t \right) < P_{RO}\), meanwhile \(\left[ {P_{W} \left( t \right) + \left( {P_{PV} \left( t \right)\,} \right)\eta_{inv} } \right] > P_{RO}\) and the batteries are not fully charged, \(E_{B} (t) < E_{B,\max }\), then the extra power will be transferred to charge the batteries, as shown in the following equation:

$$ P_{BC} \left( t \right) = \left[ {P_{W} \left( t \right) + \left( {P_{PV} \left( t \right)\,\eta_{inv} } \right) - P_{RO} } \right]\,\,\eta_{BC} $$
(17)

If \(P_{W} \left( t \right) < P_{RO} \left( t \right)\), \(\left[ {P_{W} \left( t \right) + \left( {P_{PV} \left( t \right)\,\eta_{inv} } \right)} \right] > P_{RO} \left( t \right)\) and \(E_{B} (t) \ge E_{B,\max }\), then the control system will discard the extra power by controlling the generated power from WT and PV systems, and for this reason Eq. (18) is used.

$$ P_{BC} \left( t \right) = P_{BD} \left( t \right) = 0 $$
(18)

2.5.2 Discharging Mode

During this mode of operation, the RODS power, PRO, is higher than the electric power available from the RES, and the difference is supplied from the battery system until the SOC in the battery reaches the minimum allowed energy, EB,min. When the stored energy reaches this lower limit, the RODS will not be able to work at full operation, and there will be a loss of power supply. These conditions are summarized below.

If \(\left[ {P_{W} \left( t \right) + \left( {P_{PV} \left( t \right)\,\eta_{inv} } \right)} \right] < P_{RO}\) and \(E_{B} (t) > E_{B,\min }\), then the power needed for the RODS will be as shown in the following equation:

$$ P_{BD} \left( t \right) = \frac{{\left[ {P_{RO} - P_{W} \left( t \right) - P_{PV} \left( t \right)\,\eta_{inv} } \right]}}{{\eta_{inv} \,\eta_{BD} }}, $$
(19)

If the generated power from the RES is lower than the requirement of the RODS and the battery is at the lower allowable limit of its charging condition \(\left[ {P_{w} \left( t \right) + \left( {P_{PV} \left( t \right)\,\eta_{inv} } \right)} \right] < P_{RO} \left( t \right)\) and \(E_{B} (t) \le E_{B,\min }\), then the discharging power from the battery is zero and the loss of power supply probability will be increased by one occurrence;

$$ P_{BD} \left( t \right) = 0\,\, $$
(20)
$$ LOSP = LOSP + 1 $$
(21)

In this case, the accumulated deficit in the generated energy, Ed, can be obtained as shown in Eq. (22).

$$ Ed = Ed + P_{RO} - \left[ {P_{W} \left( t \right) + \left( {P_{PV} \left( t \right)*\eta_{inv} } \right)} \right] $$
(22)

where ηinv is the efficiency of the inverter.

The battery state loses σ % of its capacity every hour during the simulation, where the SOC can be extracted from (23).

$$ E_{B} \left( t \right) = \sigma \,E_{B} (t - 1)\,\, $$
(23)

The flowchart explaining the logic of the energy balance steps is shown in detail in Fig. 2.

Fig. 2
figure 2

Fitness function, including the energy balance and cost estimation (EBCE), of the reverse osmosis desalination system

3 Cost Analysis

The primary objective of this section is to determine the cost of desalinating one cubic meter of fresh water, which can be obtained by using the levelized cost of water (LCW) factor according to Eq. (24). In this calculation, all the factors affecting the price during the operation of the RODS are considered as the price at the start of project, taking into consideration interest and inflation rates. The total present value (TPV) was used to determine the LCW to better choose the best size of each component of the RES, as shown in Eq. (24) [44]. Many studies introduced economical methodologies to calculate the cost of the desalinated cubic meter of water depending on many assumptions. The TPV of the system components, OMC, and the price of salvage parts are introduced in [45,46,47]. The TPV was used to determine the cost of water production from a RODS supplied by a RES.

$$ LCW = \frac{TPV*CRF}{{YW}} $$
(24)

where YW is the annual total cubic meters of the fresh water and CRF is the capital recovery factor which is shown in Eq. (25).

$$ CRF = \frac{{r\left( {1 + r} \right)^{T} }}{{\left( {1 + r} \right)^{T} - 1}} $$
(25)

where T is the project lifetime in years and r is the net interest rate.

The value of TPV can be determined from Eq. (26).

$$ TPV = CC + RC + OMC - PSV $$
(26)

where CC is the capital cost of the whole system including the installation cost, RC is the replacement cost, OMC is the operation and maintenance cost, and PSV is the present value of the salvage [44]. The detailed descriptions of the variables shown in Eq. (26) are shown in the sections below.

3.1 Capital Cost

The capital cost (CC) of the RES and RODS, including the price of all parts of the system, such as the installation cost, was calculated using Eq. (27) [48].

$$ CC = WEP + PVP + BAP + ROP $$
(27)

where WEP is the price of wind energy system, including installation, power electronics conditioners, and the price of all components required for the wind energy system, PVP is the total price of the PV energy system, including the installation, civil work, power electronics conditioner, and control system. BAP is the total price of the battery system with the all required components for this system. ROP is the total price of RODS with all required components and installation.

3.2 Replacement Cost

The components that have a lifetime less than the lifetime of the project should be replaced during the operation of the project. These replaced components will be bought at the time of the replacement. The cost of these components should be calculated as a present value when the project started taking into consideration the interest rate, r, and inflation rate, l. The cost of replacement of any component of the system at the beginning of the project, RC, is shown in Eq. (28) [37].

$$ RC = RCU\sum\limits_{j = 1}^{{N_{rep} }} {\left( {\left( {\frac{1 + l}{{1 + r}}} \right)^{{T*j/(N_{rep} + 1)}} } \right)} $$
(28)

where RCU is the current replacement cost of the components that will be replaced during the project period and Nrep represents the times that the component is replaced during the lifetime of the project, T.

3.3 Operation and Maintenance Cost

The proposed system needs an OMC during the lifetime of the project. There is no exact evaluation for the OMC for each price, but the value used for it is obtained from experts and previous research work or as recommended by the manufactures of the components. These values will be shown in detail in the simulation section.

The present value of OMC of any component in the RES or RODS can be determined from Eq. (29) [7].

$$ OMC = OMC_{0} *\left( {\frac{1 + l}{{r - l}}} \right)*\left( {1 - \left( {\frac{1 + l}{{1 + r}}} \right)^{T} } \right),\quad r \ne l $$
(29)

4 The Present Salvage Value

The old components that are replaced with new ones during the operation of the project should be sold at the time of replacement. The values of these components should be calculated at the start of the project which is called the PSV which can be calculated as shown in Eq. (30) [7].

$$ PSV = \sum\limits_{j = 1}^{{N_{rep} + 1}} {SV*\left( {\frac{1 + i}{{1 + r}}} \right)^{{T*j/(N_{rep} + 1)}} } $$
(30)

where SV is the scrap or salvage value.

5 Optimization Techniques

Three different optimization techniques are introduced in this paper to perform the optimal design of the RES and RODS to obtain the minimal cost of water desalinated at the lowest LOSP. The three proposed techniques are chosen with two well know techniques, and one recently introduced optimization technique. The three techniques are the BA, PSO, and SMO [7, 31] algorithms.

The optimization used a multiobjective function to minimize both the cost per cubic meters of fresh water and LOSP values, as shown in Eq. (31).

$$ F = LOSP + M*LCW/m^{3} $$
(31)

where F is the fitness function, LCW is the levelized cost of water, which is the cost of desalinating one cubic meter of fresh water, and M is the weight value required to give the LCW a weight relative to the LOSP value.

5.1 Optimization Techniques Initialization

Before using the optimization techniques, values were assigned to the optimization variables (NWT, PVA, and EBR) with numbers of particles called swarm size. It is recommended that the initial values in the original optimization techniques are random, but random values for these variables could increase the convergence time, and it may cause the optimization technique to capture one of the local peaks. So, it is recommended to have random values within reasonable limits of these variables. The initial values of NWT, PVA, and EBR were fed to the energy balance and cost estimation (EBCE) subroutines, and the values of the objective function shown in Eq. (31) collected \(F_{0}^{1:n}\). The minimum value of the objective function was determined as \(F_{best} = \min (F_{0}^{1:n} )\) and the corresponding best bat, \(d_{best}\), was determined.

5.2 PSO for Designing the Renewable Energy System for Reverse Osmosis Desalinization System Applications

The PSO technique is a very popular optimization technique that is used in numerous applications. This technique imitates the behavior of many flocks of animals, such as fish or birds, in searching for their food to use the same searching technique in capturing the optimal solutions of real-world applications. This technique was introduced in 1995 (15 years before BA) by Kennedy and Eberhart (1995) [49]. The idea behind this technique is to send many solutions, called the swarm, and each solution, called a particle, to search for the optimal solution. The experience gained from the searching step will be transferred to offspring in the next step. The particles share their experience among other particles in the swarm (social-experience) and use their private experience (self-experience) to modify the searching technique.

The searching performance PSO is performed using Eqs. (32) and (33). Equation (32) is used to determine the velocity or trajectory of particles in the new iterations \(v_{i + 1}^{k}\). The velocity of the particles in the next step \(v_{i + 1}^{1:n}\) is obtained from three different terms, which are summarized in the following points:

  • The previous velocity, \(v_{i}^{1:n}\), is multiplied by the weight function ω to enhance the stability of searching performance. This value can be used as a constant around 0.7, or it can be linearly decreased from 0.9 to 0.4 to enhance the social confidence at the beginning of iterations and to enhance the self-confidence at the end of searching procedures and many modification strategies [50].

  • The second term is using the difference between the particle’s best value and the current solution and multiplies this difference by a factor called self-experience parameter, cl. Increasing the value of this parameter will enhance the self-confidence of searching, and it increases the convergence speed, but it may increase the possibility of capturing a local peak.

  • The third term is the difference between the global best obtained from the previous iteration and the current solution and multiplies this difference by a factor called a social experience parameter, cg. Increasing the value of this parameter will enhance the social confidence of searching.

The values of cl and cg should be compromised to balance between the self- and social search, which differ from fitness function to another. This velocity or trajectory was added to the previous position of particles \(d_{i}^{1:n}\) to get the new values of particles [51]. The flowchart showing the logic used in the optimal sizing of RES in RODS by PSO is shown in Fig. 3.

$$ v_{i + 1}^{1:n} = \omega \,v_{i}^{1:n} + c_{l} r_{l} (d_{best}^{1:n} - d_{i}^{1:n} ) + c_{g} r_{g} (G_{best} - d_{i}^{1:n} ) $$
(32)
$$ d_{i + 1}^{k} = d_{i}^{k} + v_{i + 1}^{k} , $$
(33)

where ω is called the inertia weight cl and cg are the self- and social experience parameters, respectively. \(d_{best}^{1:n}\) is the personal best position of each particle, Gbest is the global best position, n is the number of searching agents (swarm size), and rl and rg are random values in between [0 1], i is the iteration order, which starts at one to the end of iterations when i = it.

Fig. 3
figure 3

Flowchart showing the logic used in the optimal sizing of RES in RODS by PSO

5.3 The BA in Designing of the RES for RODS Applications

Like most of the swarm optimization techniques, BA imitates bats in search of their food or prey. The BA was first developed by Yang [28]. This optimization technique is very fast and provides an accurate convergence. The results obtained from this technique were compared to the results obtained from PSO and SMO techniques. In nature, bats search for their food by using the echolocation technique, in which they emit numbers of impulses with different levels and different frequencies and receive an echo of these sound pulses. The bats get information about the food or prey from the received sounds to decide on their direction and speed in the next movement. Bats can identify the distance and size of the prey by measuring the time between pulses and the intensity of echoed sound pulses, respectively. The searching behavior of bats has inspired researchers to imitate them in searching for the optimal solution for different life problems. Many generalized rules should be taken into consideration in the mathematical modeling of the BA [28]. The following sections explain the logic of using the BA to optimally design the RES system to supply the RODS with electric power. As with the other optimization techniques used in this paper, the BA will use the number of WTs, NWT, the area of the PV array, PVA, and the size of the batteries, EBR as optimization variables. The fitness function is introduced in Eq. (32).

The initial velocity \(v_{0}^{1:n}\) and initial frequency \(f_{0}^{1:n}\) of all bats are set to zero (where n is the swarm size). The initial values of pulse rate, r0, loudness, A0, and many initialization parameters are set as recommended in [28].

The new position of the particles, \(d_{i}^{1:n}\), can be determined from Eq. (36) after determining the bat velocity, \(v_{i}^{1:n}\) as shown in Eq. (35). The frequency of the particles can be determined from Eq. (34).

$$ f_{i}^{1:n} = f_{\min } + \left( {f_{\max } - f_{\min } } \right)\beta $$
(34)
$$ v_{i}^{1:n} = \omega \,v_{i - 1}^{1:n} + \left( {d_{best} - d_{i - 1}^{1:n} } \right)f_{i}^{1:n} $$
(35)
$$ d_{i}^{1:n} = d_{i - 1}^{1:n} + v_{i}^{1:n} $$
(36)

where the values of fmin and fmax are the minimum and maximum frequency range and are chosen to be 0 and 2, respectively [28]. β is a random value, β ∈ [0,1], and ω is the inertia weight.

After determining the new position from Eq. (36), a random walk around this position should be performed to get the new position of the bats, as shown in Eq. (37) [29]. If the pulse emission ri is less than a random number, then the position di is replaced by the value obtained from Eq. (37).

$$ d_{i}^{1:n(new)} = d_{best} + \varepsilon \varphi \left\langle {A_{i}^{1:n} } \right\rangle $$
(37)

where ε is a random number, ε ∈ [− 1,1], and ϕ is a positive constant equal to 0.001 [11], while \(\left\langle {A_{i}^{1:n} } \right\rangle\) is the average loudness of bats at the current iteration.

The value of loudness (Ai) decreases with iterations; meanwhile, the pulse rate, ri, increases. The variation in Ai and ri with iteration numbers is shown in Eq. (38) and Eq. (39), respectively [7].

$$ A_{i}^{1:n} = \alpha A_{i - 1}^{1:n} $$
(38)
$$ r_{i}^{1:n} = r_{0}^{1:n} \,[1 - e^{( - \gamma i)} ] $$
(39)

where the values of α and γ have been chosen to be equal to 0.9 in many types of research [28].

The new values of the bat’s positions, \(d_{i}^{1:n}\), were fed into the fitness function (EBCE) to obtain its corresponding objective values \(F_{i}^{1:n}\). After performing the above logic, the iterations start and repeated until the logic stops based on the stopping criterion. The flowchart of using BA in the design of RODS is shown in Fig. 4.

Fig. 4
figure 4

Flowchart of the bat algorithm used for optimal sizing of RES in RODS application

5.4 The SMO in Designing of the RES for RODS Applications

A modern optimization technique called the SMO [31] was used to compare with the PSO and BA in designing the RODS. This algorithm mimics the human face and body reactions. This newly proposed technique has been used with many optimization functions, and it shows good convergence performance. This technique is characterized, but there are no control parameters to be optimized, as in the case of BA and PSO, which make it a good option to use with low experience optimization researchers. The operating logic of SMO is shown in Fig. 5 and detailed in the following steps:

  • SMO1: The first step is to initialize the particles \(d_{0}^{1:n}\) and then calculate the fitness function \(F_{0}^{1:n}\).

  • SMO2: Determine the minimum optimization function, FFbest (called a leader), and set its corresponding position to dbest.

  • SMO3: Determine the difference between the value of best fitness function (leader) and the value of a function of each particle “Flower” as shown in the following equation:

    $$ DF_{i}^{k} = (FF_{best} - F_{i - 1}^{k} )/F_{i - 1}^{k} $$
    (40)
  • SMO4: Check if \(DF_{i}^{k} = 0\), set it its value to–rand and go to the next step, otherwise go to the next step.

  • SMO5: Determine the new position of the particles using the following equation:

    $$ d_{i}^{k} = d_{i - 1}^{k} + DF_{i}^{k} \times d_{i - 1}^{k} $$
    (41)
  • SMO6: Send the new position of particles \(d_{i}^{k}\) to the EBCE and determine the corresponding fitness function \(f_{i}^{k}\).

  • SMO7: Check if \(F_{i}^{k} < FF_{best}\), then \(FF_{best} = F_{i}^{k}\), and go to the next step, otherwise go to the next step without modification.

  • SMO8: Check if all particles are performed, if yes go to the next step otherwise go to SMO3.

  • SMO9: Check the stopping criterion is valid, print the values of dbest and FFbest,, otherwise go to SMO3.

Fig. 5
figure 5

Flowchart of the SMO, which was used for optimal sizing of RES in RODS application

6 Simulation Results

The simulation study was performed for Arar City in the northeast part of Saudi Arabia (30.9599° N, 41.0596° E). With 2.44 kWh/m specific energy consumption, the required power from the RES to produce 1000 m3 of fresh water was 2440 kW. The weather data for this site were collected, such as hourly wind speed, solar irradiance, and temperature [53]. Figure 6 shows the wind speed distribution in this site on 40 m elevations. The maximum and average monthly wind speed is shown in Table 1, which shows the monthly average wind speed, solar irradiance on the horizontal surface, temperature for Arar City on 40 m height [52]. The wind speed distribution is shown in Fig. 6. The average wind speed at 40 m height is 5.8 m/s [52]. The hourly solar irradiance and temperature for the Arar site were collected from the PV geographical information system [53].

Fig. 6
figure 6

Monthly weather data for Arar City

Table 1 Wind speed, solar irradiance on a horizontal surface, temperature for Arar City, collected at 40 m above sea level [52]

6.1 Pairing Between the Study Site and Wind Turbines

The frequency distribution of the wind speed of Arar City at a 40 m elevation is shown in Fig. 7. These data will be used with the data of WTs to get the best WT for this site. Ten WTs have been used to choose the best WT among them where the WT with the best CF was selected. The data of WTs and the CF of each WT are shown in Table 2. It is clear from this table that the highest CF was associated with the AE-Italia [54] WT. Therefore, this WT was used in the simulation.

Fig. 7
figure 7

Wind speed distribution of Arar City on 40 m elevation

Table 2 Wind turbine data, capacity factor, and number of wind turbines at the Arar site

6.2 Overall Data of the Proposed System

After selecting the best WT to be used in the Arar site, the data for all systems used in the simulation are shown in Table 3. These data were collected from many references, and the reasonable values of each component were selected.

Table 3 Input data for the optimization program [12, 27, 64,65,66,67,68,69,70,71,72,73]

The optimization results of using the RES to feed the RODS were calculating PSO, BA, and SMO optimization tools. Three different studies are introduced in the simulation results, as shown in the following sections:

  1. 1.

    Evaluation of the best optimization technique

  2. 2.

    The variation in the weight factor, M

  3. 3.

    The detailed results of the optimization technique for the best solution obtained.

6.3 Evaluation of the Best Optimization Technique

We evaluated the detailed results of using the three different strategies PSO, BA, and SMO to choose the best one. In all the optimization techniques used in this study, the program suggests size value for each RES component and these components are used as input to the power dispatch unit where it can determine the hourly generated power and the SoC of the batteries and how the power flows in each component. After determining the total generated energy from the power dispatch unit, it will be used in the cost estimation part to determine the LCW which depends on the cost analysis (Sect. 3) section introduced above. In this part, the program calculates the capital cost for all components as shown in Eq. (27). The replacements of each component should be calculated based on the formula shown in Eq. (28). The operation and maintenance cost will be after that calculated from Eq. (29). The present salvage values of each component of the RES should be calculated from Eq. (30) to be subtracted from all expenses of the RES to determine the total present value (TPV) as shown in Eq. (26). The TPV will be used to determine the levelized cost of water (LCW) as shown in Eq. (24). These cost study uses the sizes of the RES components and their price as shown in Table 3. The evaluation criteria were based on the lowest failure rate and the fastest convergence time. In this analysis, the weight value, M, which is shown in Eq. (31), was selected to be M = 10. For fair evaluation, the swarm size for all optimization tools was equal to 50. Also, the parameters used in each technique are shown in Table 3. The optimization performance of these optimization tools was performed for 10 different optimization runs, as shown in Figs. 8, 9 and 10, respectively. Figure 8 shows that the PSO captured the minimum fitness value in 10 runs out of 10 with about nine iterations. Meanwhile, as shown in Fig. 9, the BA captured the minimum value of fitness functions in all the 10 runs and about six iterations. For SMO, as shown in Fig. 10, this technique captured the minimum fitness value in nine runs out of 10 with about 13 iterations to capture the optimal solution. From these results, it is evident that the BA is the fastest optimization technique, as it captured the minimum solution with six iterations compared with nine and 13 for PSO and SMO, respectively. Also, BA and PSO captured the optimal solution without any failure. Meanwhile, SMO failed one time out of ten times. Therefore, we advise using the BA for this application, and it was used in the following simulation studies. The simulation results shown in Figs. 8, 9 and 10 are showing how the fast and reliable response of BA compared to the obtained results from PSO and SMO which proves the superiority of using BA optimizing in the sizing problem of the HES in water desalination application and other applications.

Fig. 8
figure 8

Convergence performance of the particle swarm optimization technique

Fig. 9
figure 9

Convergence performance of the bat algorithm technique

Fig. 10
figure 10

Convergence performance of the social mimic optimization technique

6.4 The Variation in Weight Factor, M

From the above study, the BA provided the best performance compared with the other two techniques. Therefore, it was used in the next two simulation studies. The objective function used to reduce the cost and the LOSP is shown in Eq. (31). The weight value, M, was multiplied by the LCW to provide the required weight to the LCW compared with LOSP. The simulation in this study was performed for different values of M to determine the response of the LCW and LOSP. Figure 11 shows the variation in the fitness function, LCW, and LOSP along with the value of M. Figure 11 shows that with a low value of M, the cost is dropping very fast where it drops from $0.92/m3 when M = 2 to $0.754/m3 when M = 10. Meanwhile, during this period, the LOSP increased from 0.1% to 0.6%. When there was a high value of M, the cost was saturated at $0.6/m3, while the LOSP increased to about 9%. Therefore, it is appropriate to choose M = 10 to reduce the cost from $0.92/m3 to $0.754/m3 while the LOSP is still 0.6%. The variation in the number of WTs, PV area, and size of the batteries along with M is shown in Fig. 12. It is evident from this figure that when M is increased, it gives the cost more weight than LOSP and the WT number increases while the area of the PV and the size of the batteries are reduced. This indicates that the cost is directly proportional to the wind energy system size and inversely with the PV area and battery size for optimal operation.

Fig. 11
figure 11

Variation in the fitness function, LCW, and LOSP along with the weight value, M

Fig. 12
figure 12

Variation in wind turbine number, photovoltaic area, and battery size along with the weight value, M

6.5 The Detailed Results of Optimization Technique for the Best Solution

As indicated in the first study, the BA is the best optimization technique compared with the other two techniques under study. Therefore, it was selected for use in this study. Also, the value of M is a function in the cost and LOSP (Fig. 11). The value of M was chosen to be M = 10 to reduce the cost from $0.92/m3 to $0.754/m3 and LOSP to 0.6%. The hourly variation in wind speed, solar irradiance, generated power from WT, generated power from the PV system, and SOC of the batteries are shown in Fig. 13. It is evident from this figure that the SOC of the batteries varied between 100 and 30%. The batteries were not able to provide the energy required when their SOC was 30%, which occurred at t ≈8000 h, as shown in Fig. 13. The optimum design of the hybrid RES was 126 WTs, 36,560 m2 of PV area, and a 75.45 kWh battery size. These results shown in Fig. 13 show the stable operation and the superiority of using BA optimization techniques in sizing of the RES for water desalination application.

Fig. 13
figure 13

Hourly operating performance of RES

7 Conclusions

The reverse osmosis desalination systems (RODSs) are a good option to supply fresh water to remote communities. Supplying a RODS from renewable energy sources (RES) can feed these remote communities with their required fresh water without a need for extending the electric utility grid to these communities. Moreover, renewable energy sources can increase the security of the power supply because they do not need fuels or emits any pollutions. Moreover, RES can avoid the dependency of the fossil fuels transportation which can increase the system security. Wind and photovoltaic (PV) power can secure the required electric power for the RODS. Due to the intermittent nature of these sources, a battery storage bank is used to store the energy when the generated power is more than the RODS requires, and it can feed it when the generated power is less than required. The sizing of the components of the hybrid RES requires smart techniques to get the lowest cost at the minimum loss of supply probability (LOSP). Three different swarm techniques have been used to design the hybrid RES. These techniques are PSO, BA, and SMO. The results showed that the BA has the best convergence performance compared with the other two techniques. The cost of producing a cubic meter of fresh water is $0.75, with 99.4% reliability.