The application of mathematical modeling and simulation-based tools in chemical science helps to link scientific theories to real-time complex dynamic chemical processes. In this work, Modelica programming language is applied to model the general corrosion of copper pipes during stagnation of water in the pipes. The corrosion process was simulated in OpenModelica simulation environment. The simulation package is based on three general corrosion sub-processes: copper oxidation by dissolved oxygen present in water; precipitation of malachite on the pipe surface; dissolution of malachite from the pipe surface. These sub-processes also affect the physico-chemical quality of water, i.e., pH, alkalinity, ionic strength, chemical complex formation, etc. In the model setup, the chemical reactions describing the processes were first expressed as rate equations. The rate equations and other equations describing the system were then transferred to the OpenModelica software environment. The simulation package was validated by simulating two different laboratory corrosion experiments and comparing the simulation results with the results of the experiments. The developed simulation package effectively simulated generalized copper pipe corrosion during water stagnation in pipes.

## INTRODUCTION

With the introduction of mathematical modeling in chemical science, it has become easy to describe and predict the behavior of chemical systems with a high degree of certainty. This saves time and capital often invested in carrying out a wide range of experiments in the laboratory. Empirical data from experiments are often required to validate mathematical models. Once a model has been validated, it can be used to predict the behavior of systems under specific conditions. Although mathematical modeling has its merits, it must be said that models usually are a simplified representation of physical systems and therefore must be used with caution (Loosdrecht et al. 2008).

Chemical processes are very complex and are influenced by many factors. This complexity is reflected in the systems of mathematical equations describing the chemical process. The mathematical equations are often very complex, requiring numerical approximations implemented by computer programming techniques.

In this work, Modelica programing language was used. Developed in 1996, the Modelica language is applied in both commercial and open source simulation software such as Dymola, MapleSim, Mathmodelica, SimulationX, OpenModelica, etc. (Fritzson & Bonus 2006).

Modelica language has been used in industry since the year 2000 with many applications in the domain of mechanical and electrical engineering. However, in the field of chemical science, the use of Modelica language has only a few published applications (Tummescheit & Eborn 2002; Baharev & Arnold 2012). In this work, the Modelica programming language is used in the OpenModelica simulation environment to model and simulate general copper pipe corrosion during stagnation of drinking water in the pipes.

During stagnation of water, copper pipes are exposed to localized or general corrosion processes (Bardel 2004). However, this work focuses on general (uniform) corrosion during stagnation.

The corrosion of copper pipes used in water supply is a common cause of copper contamination in drinking water, with the copper content increasing during stagnation of water in the pipes (ATSDR 2004). Health hazards associated with copper contamination of drinking water may include gastrointestinal distress in the case of short-term exposure and liver or kidney damage in the case of long-term exposure. To prevent health problems, the mean copper concentration in drinking water has been limited to 2 mg/L. According to the United States Environmental Protection Agency, the action level of copper is 1.3 mg/L. If more than 10% of the water samples exceed the copper concentration of 1.3 mg/L additional steps to prevent pipe corrosion should be taken.

Many copper corrosion prevention measures are being practiced by water supply companies. These measures include: slight adjustment of water pH; addition of phosphate-based corrosion inhibitors; addition of silica-based corrosion inhibitors. Much scientific research has been carried out to understand the mechanism of action of these corrosion inhibitors with standard and alternative laboratory test methods for studying copper corrosion processes already in existence (Dartmann et al. 2005; Armanious & Johannsen 2012). The complex nature of the corrosion process has made it difficult for researchers to clearly determine the role of these corrosion inhibitors as well as the theoretical bases of the corrosion process. The application of OpenModelica in the modeling and simulation of generalized corrosion may serve as a valuable contribution in linking corrosion theories to laboratory or field experiments.

### General or uniform corrosion process description

The general (uniform) corrosion of copper pipes during drinking water stagnation in water distribution systems can be described by three dynamic chemical processes: copper oxidation, precipitation, and dissolution of solid copper phases (Shock & Lytle 1995; Alex & Johannsen 2001; Merkel & Pehkonen 2006). The copper ions released from the pipes during corrosion may form different copper precipitates in water, e.g., copper oxide (CuO), copper hydroxide (Cu(OH)2), and malachite (Cu2(OH)2CO3). However, malachite is the most stable copper precipitate found on the inner walls of copper pipes in drinking water distribution systems (Shock & Lytle 1995; Merkel 2003). Owing to the absence of flow during stagnation, the corrosion of copper pipes initiated by dissolved oxygen (DO) present in water can be considered as a batch process. The three dynamic processes involved in copper pipe corrosion cause an initial increase in copper(II) ions content of water. The copper(II) ions content of the water reaches a maximum and drops toward malachite equilibrium (Figure 1).

Figure 1

Corrosion model curve showing the sub-process of general corrosion.

Figure 1

Corrosion model curve showing the sub-process of general corrosion.

## METHODOLOGY

### Model setup

#### Copper oxidation

During copper oxidation in water, DO oxidizes metallic copper releasing copper(I) and copper(II) ions. The predominant ionic copper species present in water is copper(II) due to further oxidation of copper(I) ions (Shock & Lytle 1995). The copper oxidation rate for the production of copper(II) ions (Equations (1) and (2)) is a first-order rate equation (Merkel 2003; Dartmann et al. 2005). The rate of consumption of DO in contact with the pipe surface is proportional to the copper(II) ions released during oxidation (). To simplify the modeling process, the ionic strength of the medium was taken as zero. The chemical species in the mathematical equations are therefore expressed in concentration terms and not in terms of activity.

Copper oxidation equation
1
Rate equation
2

3
O2kor denotes DO involved in corrosion, denotes copper(II) ions released by oxidation, A denotes pipe surface area, and Kox denotes oxidation rate constant.
The time derivative of a variable, e.g., is represented in Modelica language as der(O2kor). The chemical rate equations (Equations (2) and (3)) were introduced in the OpenModelica environment as shown

#### Precipitation and dissolution of malachite

The precipitation and dissolution of malachite influences the free copper(II) ion (Cu2+) content of water during stagnation. Precipitation leads to copper(II) ion reduction while dissolution increases copper(II) ions in water (Equation (4)).
4
Kpre denotes the precipitation rate constant while Kdiss denotes the dissolution rate constant.

Alex & Johannsen (2001) proposed a rate equation for malachite precipitation and dissolution (Equation (5)).

Rate equation
5
denotes the copper(II) ions involved in malachite formation and Cu2+ denotes the free copper(II) ions in solution.
At equilibrium, the rate of dissolution equals the rate of precipitation. The rate constant for malachite dissolution (Kdiss) is therefore equal to the product of the rate constant for malachite precipitation (Kpre) and the solubility product of malachite (Kmalachite).
6
The OH ions are related to the H+ ions by the ionic product of water (Kw).
7
The Modelica line corresponding to Equation (5) is shown as
To generate a rate expression for the total copper(II) ions (TOTCu2+) in the medium, the individual rate equations for oxidation and precipitation/dissolution were combined.
8
The corresponding Modelica language line for the combined equation is shown as
The constants Kpre and Kox are specific for each corrosion process. They are determined by testing different Kpre and Kox values in different simulation runs. The accepted values for the constants are values which give simulation results that are very close to the experimental results.

#### Complex formation

The total copper(II) ions (TOTCu2+) in the medium are a combination of the free copper(II) ions (Cu2+) and the copper complexes formed between copper(II) and anionic species present in water. The anionic species present in solution depends on the pH of the medium. The chemical equilibria influencing copper(II) ions in water are shown in Table 1. The equilibrium reactions shown in Table 1 were expressed as mathematical equations and transferred to the OpenModelica environment.

Table 1

Chemical equilibria influencing Cu2+ in solution

Reaction Log K at 25 °C Reference
Cu2+ + H2O ⇔ Cu(OH)+ + H+ −7.16 Shock & Lytle (1995)
Cu2+ +2H2O ⇔ Cu(OH)2o +2H+ −16.24 Shock & Lytle (1995)
Cu2+ +3H2O ⇔ Cu(OH)3 +3H+ −26.9 Shock & Lytle (1995)
Cu2+ +4H2O ⇔ Cu(OH)42– +4H+ −39.56 Shock & Lytle (1995)
2Cu2+ + H2O ⇔ Cu2(OH)3+ + H+ −6.08 IUPAC Technical Report (2007)
2Cu2+ +2H2O ⇔ Cu2(OH)22+ +2H+ −10.58 Shock & Lytle (1995)
3Cu2+ +4H2O ⇔ Cu3(OH)42+ +4H+ −20.76 Shock & Lytle (1995)
Cu2+ + HCO3 ⇔ CuHCO3+ 1.6 IUPAC Technical Report (2007)
Cu2+ + HCO3 ⇔ CuCO3° + H+ −3.55 IUPAC Technical Report (2007)
Cu2+ +2HCO3 ⇔ Cu(CO3)22– +2H+ −10.42 IUPAC Technical Report (2007)
H2CO3 ⇔ H+ + HCO3 −6.39 Shock & Lytle (1995)
HCO3 ⇔ H+ + CO32– −10.38 Shock & Lytle (1995)
Reaction Log K at 25 °C Reference
Cu2+ + H2O ⇔ Cu(OH)+ + H+ −7.16 Shock & Lytle (1995)
Cu2+ +2H2O ⇔ Cu(OH)2o +2H+ −16.24 Shock & Lytle (1995)
Cu2+ +3H2O ⇔ Cu(OH)3 +3H+ −26.9 Shock & Lytle (1995)
Cu2+ +4H2O ⇔ Cu(OH)42– +4H+ −39.56 Shock & Lytle (1995)
2Cu2+ + H2O ⇔ Cu2(OH)3+ + H+ −6.08 IUPAC Technical Report (2007)
2Cu2+ +2H2O ⇔ Cu2(OH)22+ +2H+ −10.58 Shock & Lytle (1995)
3Cu2+ +4H2O ⇔ Cu3(OH)42+ +4H+ −20.76 Shock & Lytle (1995)
Cu2+ + HCO3 ⇔ CuHCO3+ 1.6 IUPAC Technical Report (2007)
Cu2+ + HCO3 ⇔ CuCO3° + H+ −3.55 IUPAC Technical Report (2007)
Cu2+ +2HCO3 ⇔ Cu(CO3)22– +2H+ −10.42 IUPAC Technical Report (2007)
H2CO3 ⇔ H+ + HCO3 −6.39 Shock & Lytle (1995)
HCO3 ⇔ H+ + CO32– −10.38 Shock & Lytle (1995)

#### Alkalinity and pH

The corrosion process influences the acidity, alkalinity, ionic strength, and pH of water. Copper oxidation increases pH due to hydroxide ion (OH) release while malachite precipitation consumes hydroxide ions. The consumption of carbonate ions during malachite precipitation affects the total inorganic carbon (TOTC) (Equation (9)). The rate of change of alkalinity is proportional to the rate of change of total copper(II) ions in solution (Equation (10)).

Rate equation
9

10
The corresponding Modelica line for Equations (9) and (10) are

The total inorganic carbon of the medium is the sum of the alkalinity and acidity. Equations (11)–(16) are all algebraic equations. These equations were also introduced into OpenModelica.
11

12

13

14

15

16

### Simulation experiments and model validation

#### OpenModelica package for general copper pipe corrosion during stagnation

OpenModelica is an object-oriented modeling software. Object-oriented modeling involves the following software engineering principles: message-passing, encapsulation, class to subclass inheritance, and polymorphism, i.e., same procedure applied on different types of data. The developed OpenModelica simulation package (titled ‘corrosion’) is composed of a class for the thermodynamic constants (named ‘constants'), a class for the copper complexes (named ‘complex’), and a model for copper corrosion (named ‘coppercorrosion’). The class ‘complex’ and the class ‘constants’ were extended to the main model class, i.e., ‘coppercorrosion’ as subclasses. The package is shown in Annex I (available online at http://www.iwaponline.com/jws/064/123.pdf).

#### Model validation

Laboratory copper pipe corrosion studies use different test methods, e.g., pipe rig experiments according to the German standard DIN 50931-1 (Merkel 2004; Dartmann et al. 2005); laboratory scale setup (Armanious & Johannsen 2012; Eun Lee et al. 2012). The simulation package developed in this work was validated by comparing the simulation results to two experimental results obtained in different test methods.
• Experiment 1: laboratory scale corrosion experiment using a simple laboratory batch setup (Figure 2) similar to the setup of Armanious & Johannsen (2012).

• Experiment 2: copper pipe corrosion experiment according to the German DIN 50931-1 pipe rig test method by Merkel (2004). The experimental conditions of the Merkel experiment are shown in Table 2.

Figure 2

Laboratory scale experimental setup for generalized copper pipe corrosion (adapted from Armanious & Johannsen (2012)).

Figure 2

Laboratory scale experimental setup for generalized copper pipe corrosion (adapted from Armanious & Johannsen (2012)).

Table 2

Characteristics of water used in the corrosion experiment by Merkel (adapted from Merkel (2004))

Parameter Parameter
pH 7.13 Magnesium 11.4 mg/L
Alkalinity 1.11 mmol/L Potassium 3.1 mg/L
Total inorganic carbona 1.41 mmol/L Nitrate 13.5 mg/l
DO 5.3 mg/L Sulfate 52.5 mg/L
Calcium 120 mg/L Dissolved organic carbon 1.4 mg/L
Parameter Parameter
pH 7.13 Magnesium 11.4 mg/L
Alkalinity 1.11 mmol/L Potassium 3.1 mg/L
Total inorganic carbona 1.41 mmol/L Nitrate 13.5 mg/l
DO 5.3 mg/L Sulfate 52.5 mg/L
Calcium 120 mg/L Dissolved organic carbon 1.4 mg/L

aCalculated from alkalinity and pH.

The initial conditions of the laboratory experiments were used as the initial conditions for the simulation while the experimental results were used to fine-tune and validate the simulation package.

## RESULTS AND DISCUSSION

### Simulation of experiment 1

The experimental conditions of the laboratory scale corrosion experiment (pH, total inorganic carbon and alkalinity of the water) as shown in Figure 2 were introduced into the OpenModelica corrosion package. The simulation run time was set at 8 hours, which is exactly the same as the time for the corrosion experiment. The oxidation rate constant (Kox) and the malachite precipitation rate constants (Kpre) were adjusted in order to fit the data obtained during simulation with the results obtained in the laboratory experiment. Figure 3 shows the similarity between the experimental results and results obtained by simulation. The oxidation rate constants and malachite precipitation rate constants which gave the best simulation outcomes were
Figure 3

Total copper(II) ions released in water during general corrosion of copper pipe: a comparison between the simulation results and experimental results.

Figure 3

Total copper(II) ions released in water during general corrosion of copper pipe: a comparison between the simulation results and experimental results.

The simulation results for other parameters such as pH and residual DO content of water also fitted well with the results of the experiment (Figures 4 and 5). The rise in pH observed in Figure 4 is due to the release of OH into the medium during copper oxidation (Equation (1)) coupled to the consumption of OH ions during malachite formation (Equation (4)). The drop in residual DO of the water (Figure 5) is due to consumption of DO during oxidation.

Figure 4

Variation of pH during general corrosion of copper pipe: simulation results and experimental results compared.

Figure 4

Variation of pH during general corrosion of copper pipe: simulation results and experimental results compared.

Figure 5

Residual DO content of water during general corrosion of copper pipe: simulation results and experimental results compared.

Figure 5

Residual DO content of water during general corrosion of copper pipe: simulation results and experimental results compared.

From the results shown in Figures 35, it can be concluded that the OpenModelica simulation package developed in this work can be effectively used to simulate this copper corrosion experiment.

### Simulation of experiment 2

The OpenModelica simulation package was also used in the simulation of the copper pipe corrosion experiment performed by Merkel (2004). Merkel performed different stagnation experiments using copper pipes of different operating periods. The OpenModelica package was used to simulate a corrosion experiment of copper pipes which had already been in operation for 9 weeks. The characteristics of the corroding water which was used in the experiment by Merkel are shown in Table 2. The pH, alkalinity, DO, and total carbon were introduced as initial conditions into the package and the process was simulated. The Kpre and Kox were adjusted in order to get the best fit between the simulation results and the experimental results (Figure 6). The best fit was obtained for
Figure 6

Total copper(II) ions released in water during pipe corrosion: simulation results compared to the results obtained by Merkel (2004).

Figure 6

Total copper(II) ions released in water during pipe corrosion: simulation results compared to the results obtained by Merkel (2004).

Slight deviations were observed between the experimental result and the result obtained by simulation. This deviation may be due to the high complexity of the water used in the experiment. The water contained a relatively high amount of ions which may have increased the ionic strength of the medium causing an increase in copper solubility. In developing the simulation package, the ionic strength was assumed negligible in order to simplify the process. The influence of the ionic strength may therefore contribute to the deviation observed between the experimental data and the simulation result. In addition, the organic carbon content of the water (Table 2) may also affect copper solubility in water contributing to the observed deviation. The effect of the organic carbon content was not considered in the model setup.

## CONCLUSIONS

The application of Modelica programming language in modeling and simulation of chemical processes opens up new possibilities in the field of chemical science. It integrates chemical principles, basic computer programming, and experimental science. This work has presented a simple methodology for the application of OpenModelica in the modeling and simulation of copper pipe corrosion. With OpenModelica, it is therefore possible to bring together different mathematical equations which describe different processes in a system and solve these equations using built in numerical methods. OpenModelica does not require a high level of programming skills.

The simulation package, as well as the models used in this work, has its limitations. The applicability of this package decreases with increased complexity of the physico-chemical quality of the water. With increasing complexity of the water quality, the model must be modified to include other chemical concepts that may influence copper corrosion, such as precipitation of other copper compounds, ionic strength calculations, temperature variations, etc. With slight modifications and increased flexibility, this model can be used to simulate the effect of the corrosion inhibitors used by water supply companies. Further improvement and implementation of this simulation package may significantly reduce the cost of corrosion-related water quality control strategies.

## REFERENCES

REFERENCES
Alex
T.
Johannsen
K.
2001
CiDS – A Kinetic Model to Simulate the Copper By-Product Release in Drinking Water Systems
.
American Water Works Association
,
Denver, CO
.
Armanious
A.
Johannsen
K.
2012
.
Mater. Corros.
63
,
438
444
.
ATSDR
.
2004
Toxicological Profile for Copper
.
Agency for Toxic Substances and Disease Registry (ATSDR)
,
Atlanta, GA
.
Baharev
A.
Arnold
N.
2012
Chemical Process Modeling in Modelica
.
Modelica
,
Munich
,
Germany
.
Bardal
E.
2004
Corrosion and Protection
.
Springer Verlag
,
London
.
Dartmann
J.
Dorsch
T.
Merkel
T.
Johannsen
K.
2005
Effect of Phosphate on Copper Corrosion in Household Installation
.
American Water Works Association
,
Denver, CO
.
Eun Lee
J. E.
Lee
H. D.
Kim
G. E.
2012
.
Environ. Eng. Res.
17
,
17
25
.
Fritzson
P.
Bonus
P.
2006
Introduction to object-oriented modeling and simulation with OpenModelica
.
Tutorial
,
Vienna
.
IUPAC Technical Report
.
2007
Chemical speciation of environmentally significant metals with inorganic ligands
.
Pure Appl. Chem.
79
,
895
950
.
Loosdrecht
M. C. V.
Ekama
G. A.
Wentzel
M. C.
Brdjanovic
D.
Hooijmans
C. M.
2008
Modelling activated sludge processes
. In:
Biological Wastewater Treatment: Principles Modelling and Design
(
Henze
M.
van Loosdrecht
M. C. M.
Ekama
G. A.
Brdjanovic
D.
, eds).
IWA Publishing
,
London
, pp.
361
391
.
Merkel
T. H.
2003
Untersuchengen zu den chemischen Reaktionen bei der Flächenkorrosion des kupfers in Trinkwasserinstallationen (Studies on the chemical reactions at the surface corrosion of copper in drinking water installations). University of Karlsruhe
.
Merkel
T. H.
2004
Copper corrosion: understanding and modelling general orrosion
.
Water Sci. Technol.
49
(
2
),
63
71
.
Merkel
T. H.
Pehkonen
S. O.
2006
.
Corrosion Eng. Sci. Technol.
41
,
21
37
.
Shock
M. R.
Lytle
A. D.
1995
Effect of pH, DIC, Orthophosphate and Sulfate on Drinking Water Cuprosolvency
.
EPA
,
Cincinnati, OH
.
Tummescheit
H.
Eborn
J.
2002
Chemical reaction modeling with ThermoFluid/MF and MultiFlash
. In:
2nd International Modelica Conference
,
Oberpfaffenhofen
,
Germany
, pp.
31
39
.