Automating sandstone acidizing using a rule-based system

An expert system for automating sandstone acidizing has been developed in this study. The system consists of six stages, which were built following an acidizing logic structure that is presented in the form of decision trees. The six stages consist of formation oil displacement, formation water displacement, acetic acid, HCl pre-flush, main acid, and over-flush stage. The acid blends recommended by the system are damage-type specific, and account for the compatibility between the injected acid and the in situ crude in order to avoid formation of asphaltene sludge, or emulsions. The acidizing expert system has been implemented as an online web-based application. Applicability of this expert system to acidizing design has been illustrated using three documented actual field cases spanning the Niger Delta region, Algyo Oil field in Hungary, and the Dulang oil field in Malaysia. For Niger Delta field and the Algyo field cases the expert system produced an optimal main acid job design with recommended pre- and post-flushes that are in perfect agreement with successful field treatment. For the Dulang oil field, in actual practice, an organic clay acid was injected for removing problems of fines migration in a reservoir that has a high calcite content, with a moderate amount of feldspar and chlorite clay. The acidizing expert system recommended a chelant-based acid, which is a recent innovation that is considered a more cost-effective acid solution for dissolving fines in presence of calcite and other sensitive clay minerals.


Introduction
The selection of an appropriate acid type, concentration and volume needed to be injected along with the required additives and their concentrations for various temperature and mineralogical environments can be a very perplexing task. Part of this problem stems from the complex and heterogeneous nature of most sandstone rocks. In addition, the interactions between the many different mineral species and the injected acid depend not only on their chemical compositions but also on temperature, and on surface morphology (Boyer 1983).
Sandstone formations are challenging to acidize because of the presence of alumino-silicates such as clays, zeolites, and feldspars, which may lead to unwanted precipitates in contact with mud acids as a result of secondary and tertiary reaction products. For instance, smectite and mixed layer clays are unstable in HCl at temperatures of approximately 150°F. Chlorite is unstable in presence of HCl at temperatures above 125°F. When contacted with HCl, the clay structure may disintegrate, releasing iron which may precipitate in presence of HCl acid (Rae and Di Lullo 2003). Therefore, formations with high levels of chlorite respond best to acid formulations based on acetic acid rather than hydrochloric acid, since the former limits iron liberation and thereby reduces the risk of precipitates from iron reaction products (Nasr-El-Din and Al-Humaidan 2001;Hashem et al. 1999). In formations with high levels of feldspar ([20 %), a common practice is to limit the strength of HF acid stages to reduce the formation of complex fluorosilicate precipitates and other species that would result from excessive dissolution of the mineral by stronger acid (Coulter and Jennings 1997).
Illite clays are troublesome when using HF acid due to the presence of potassium in this clay structure. When dissolved, the potassium is readily available to react with the HF-alumino-silicate reaction products, forming the insoluble potassium hexa-fluosilicate. Illite is unstable in HCl at temperatures above approximately 150°F. Kaolinite clay is considered the most detrimental from a migration standpoint (Coulter and Jennings 1997). It becomes unstable in HCl only at higher temperatures (greater than *200°F).
Zeolites are secondary minerals in the form of hydrated silicates of aluminum, calcium, sodium, and potassium. They are occasionally found in sedimentary rocks, with the most common form being analcite (analcime). The significance of zeolites is that they either decompose and/or gelatinize in hydrochloric acid at temperatures above approximately 75°F (Coulter and Jennings 1997).
The reasons for the disparity between the successful sandstone matrix acidizing jobs and those treatments that were unsuccessful may be grouped as follows: a. Poor candidate selection b. Lack of mineralogical information c. Wrong acid design (strength, volume, etc.) d. Use of inappropriate acid additives e. Insufficient iron control f. Use of contaminated/dirty fluids or neglecting to pickle tubing string g. Improper placement of acid (e.g., lack of diversion, plugged perforations) h. Long shut-in time without recovering injected fluids.
A long residence time of the injected fluids in the reservoir causes formation of insoluble precipitates and formation of very stable emulsions in the near well-bore region (Barker et al. 2007). Acid formulation requires careful mineralogical analysis of core samples. For instance, a sandstone formation containing authigenic iron chlorite clay within its pore spaces, even with low volume fraction, may not respond to treatment with HF in any concentration, and can be detrimental in response to HCl treatment as well (Nwoke et al. 2004). On the other hand, traditional guidelines, based on bulk mineralogy, might suggest treatment with mild or moderate strength HF for low total chlorite content regardless of the clay distribution in the pore space (Coulter and Jennings 1997).
A large number of interacting variables come into play for the selection of appropriate acid design job. For some conditions, the design solution may not be a unique solution. However, there are many inappropriate design solutions that could be formulated, if individuals supervising these jobs do not pay careful attention to the intricate interactions between the rock, the injected acid, and the in situ fluids.
In the last 20 years, few publications have emerged related to expert system development for designing sandstone acidizing (Blackburn et al. 1990;Chiu et al. 1992;Domelon et al. 1992;Nitters et al. 2000;Xiong and Holditch 1994). Both Domelon et al. (1992) and Xiong and Holditch (1994) introduced robust rule-based systems for acid fluid selection that are damage-type specific, and depend primarily on the formation mineralogy and the produced fluid composition. Bartko et al. (1996) developed an integrated matrix stimulation model that aids in diagnosing the formation damage type, optimizes injected acid type, and provides a pressure-skin response of the acid treatment. In all of these systems, however, the acid fluid selection follows guidelines that do not reflect the recent technological advances in acidizing blends formulations, such as phosphonic acid blends and acid chelating blends. Instead, the acid selection is primarily based on mud acids, organic acids, and clay acids. In addition, these rule-based systems ignored the clay distribution in the rock, and were rather forgiving with respect to the crude-acid interaction.
This research aims at the development and implementation of a Web-based acidizing expert system that accounts for (i) the mineral distribution in the rock, (ii) compatibility of the injected acid with the in situ crude, (iii) reservoir temperature, (iv) compatibility of the injected acid with the reservoir mineralogical composition, and (vi) for the damage type. The base-fluid selection in our system will depend primarily on recent novel acid blends introduced in the industry that proved useful in preventing a number of secondary and tertiary reaction products associated with the use of regular mud acids. The remainder of the manuscript reports the development of the reasoning logic of the sandstone acidizing expert system, as well as the implementation of the expert system.

Acidizing decision trees
The knowledge and reasoning logic incorporated in the sandstone acidizing expert system take into account input data such as rock mineralogy, clay type and distribution, reservoir temperature, and formation fluids-acid compatibility. The treatment design is constructed following a sandstone acidizing structure that includes the following stages: Stage 1 Formation oil displacement Stage 2 Formation water displacement Stage 3 Acetic acid pre-flush Stage 4 HCl pre-flush Stage 5 Main acid injection Stage 6 Over-flush In this structure, the pre-flush is no longer a single-stage, and may be stretched to multiple stages. In fact, individual Stages 1-4, or a combination of these may make-up the needed pre-flush stage, depending on the conditions of the rock after drilling, its mineralogy, presence of organic deposits, the formation water salinity, and the calcite content. The acidizing treatment design undertaken by Stages 1-6 is based on knowledge and experience extracted from human experts and arranged in hierarchical (tree) forms, which may be termed as decision trees which are used in the current work to represent the acquired knowledge and reasoning logic. A decision tree is a tree-like decision support tool that uses a graph to convey decisions and their possible consequences (Adamo 1980;Yuan and Shaw 1995). It contains mainly three types of nodes: decision nodes associated with conditions and statements to support decision making, chance nodes to represent derived decisions and events that are likely to occur, and end nodes corresponding to situations and end goals to be obtained. Decision trees are essential to understand and follow up the logic of the system. They may be considered as references and means of communication between the expert and the developer. Moreover, they facilitate maintaining, checking, modifying and extending the knowledge and logic of the system. Stage 1 addresses the cleaning of whole mud losses that take place during the drilling phase. It is also concerned with the cleaning of organic deposits in the formation. The decision tree for Stage 1 is given in Fig. 1. This stage prepares the surfaces for the main treatment fluids. Hydrocarbon solvents are used to clean oil films and paraffin deposits so that the main acid systems can contact the mineral surfaces. In Stage 2, brine containing ammonium chloride is used to help remove and dilute acid-incompatible species, such as potassium or calcium (Fig. 2). This process helps avoid precipitation of some of the most detrimental precipitates produced in sandstone acidizing such as sodium and potassium fluorosilicates. Ammonium chloride is also used to condition the clays that might come in contact with injected acids. The lower the formation water salinity is, the higher the concentration of ammonium chloride is needed to suppress the electrical double layer of clays. A linear relationship between ammonium chloride concentration and water salinity has been adopted in this study. This is inspired from estimates of the critical salt concentration needed for clay stability (Schechter 1992). The boundary points of this linear relationship consist of 8 % ammonium chloride solution for 0.1 % water salinity, and 3 % ammonium chloride solution for 5 % water salinity, or greater. Stage 3 is reserved for formations that bear ironrich minerals, or iron-rich clays like chlorite (Fig. 3). Injection of HCl acid in these rocks is likely to precipitate iron scales when iron-rich minerals are present (Coulter and Jennings 1997). In order to alleviate these problems, HCl is substituted with acetic acid when the volume fraction of these authigenic species is [6 % (Fig. 3). Acetic acid lessens the risk of precipitates from iron reaction products. Compatibility of the main acid with formation fluids is another consideration for pre-flushes. A number of crudes may sludge in contact with certain acidic mixtures (Houchin et al. 1990). These situations may require buffering acetic acid as a pre-flush. In the absence of sludge and emulsion problems, HCl pre-flush (Stage 4) in sandstone acidizing becomes extremely important. The function of an HCl preflush is to remove the bacteria that may exist with injection wells, calcareous material growth in the pore system, or to remove CaCO 3 inorganic scale deposits, and the calcite cementing material that may precipitate calcium fluoride deposits in contact with HF acid of the main stage. HCl preflush also reduces the potential precipitation of insoluble or slightly soluble reaction products like calcium fluoride, and sodium and potassium hexafluorosilicates. The decision tree for HCl pre-flush is shown in Fig. 4.
Selection of the main acid treatment as a function of rock mineralogy for removing fines migration problems is represented in the decision tree shown in Fig. 5. The selection process follows the subsequent general guidelines: 1. Conventional mud acids are used only in very special circumstances and in general in low concentrations in order to avoid the precipitation of many damaging reactants, maintain formation integrity, and dissolve any fines. Indeed, mud acid is restricted for treating clay-clean formations at relatively low temperatures with insignificant amounts of calcite, Feldspar, or zeolite. 2. Organic acids are recommended for clean rocks that bear a minimum amount of clays, but at relatively high temperatures. Shaly rocks that are free of either calcite or zeolites are treated with a clay acid. 3. Shaly rocks that bear significant chlorite presence are treated with a clay acid, a reducing agent like erythorbic acid, and a sequestering agent like EDTA. 4. Shaly rocks that bear significant chlorite, feldspar or zeolites but with low calcite content are treated with a phosphonic acid blend. 5. Formations with low clay content, at high temperatures and with significant calcite content are treated with acid chelating blends. 6. Fracture option is reserved for reservoirs that bear highly non-paraffinic crudes that may develop rigid emulsions or asphaltene sludge upon contact with HCl (Houchin et al. 1990).
The purpose of the over-flush (Stage 6) is to eliminate damage in the near-wellbore area caused by the precipitation potential of the spent acid of the main fluid stage (Fig. 6). This is accomplished by displacing the main fluid stage more than 3-4 ft away from the wellbore, and by diluting the portion of the main fluid stage that is not displaced. Over-flush fluids are chosen carefully to be aqueous based, and have dilution potential for the spent acid. The fluids used in the over-flush stage must be miscible with the previous stages.
The final design is reduced to include only necessary steps, though. A great emphasis is placed on Stages 4 and 5. In other words, Stage 1 is skipped if none of the diamond conditions of decision tree shown in Fig. 1 are satisfied. Stage 3 is skipped, if the rock has no zeolite material, iron minerals, illite, chlorite, or mixed layer clays. Stage 4 is skipped if the conditions of the 'OR-Test S4-1', shown in Fig. 7a, are not satisfied. Decision trees that match the damage types and initial formation conditions for the six treatment stages have been constructed in this study. These decision trees make the logical foundation for the expert system decision-making process (Figs. 1,2,3,4,5,6), covering the following damage types: In an effort to extend the life of the acid treatment and improve the outcome of the acidizing job, alternative acid blends to the conventional HCl-HF acid systems were set as part of the remedies employed in the decision trees (Fig. 5). In one of the improved chemistry systems, HCl is replaced with a phosphonic acid complex which has five available hydrogen ions that dissociate at different stoichiometric conditions. For this reason, the phosphonic acid complex is referred to as a five-hydrogen (HV) complex (Nwoke et al. 2004;Uchendu and Nwoke 2004;Rae and Di Lullo 2007). The HV acid reacts with ammonium bifluoride (NH 4 HF 2 ) or with ammonium fluoride to produce HF acid. In order to produce a 1 % HF acid solution, 20 gal of HV acid per 1,000 gal of water are required to react with approximately 123 lbm of NH 4 HF 2 (Uchendu et al. 2006). This self-generating reaction of HF acid reduces the rate at which the acid system reacts, and therefore, allows an increased depth of penetration of live HF acid into the  Fig. 1 Decision tree for formation oil displacement-Stage 1

Stage 2: Formation Water Displacement
Inject water with ammonium chloride (NH 4 Cl) at concentrations between 3% and 8% depending on the formation water salinity  formation. This slow reaction reduces the risk of formation deconsolidation in the near-wellbore area, unlike the conventional HF treatment which may deconsolidate the formation in the near-wellbore region.
In addition, the reaction of the HV:HF system with clays forms a thin aluminum silicate phosphonate coating on the clay. This coating, in return, prevents further spending of the HF acid and reduces the reaction rate on high surface area clays. As a consequence, the volume of silica material that can be dissolved is increased, causing further improvement to the near-wellbore permeability (Obadare et al. 2006). The production of ammonium phosphonate salt, while HF is evolved from the HV acid, eliminates the generation of insoluble precipitates as the pH of the spent acid system rises. This is a common problem with conventional HF acid systems. Furthermore, the rock substrate is conditioned to be water wet with this HV:HF chemistry. Water-wet condition improves the acid contact with the targeted alumino-silicate material. Precipitation of fluorosilicates, hexafluorosilicates, alumino-fluorosilicates, iron compounds and calcium fluoride, commonly generated during acidizing with conventional HF are prevented as a consequence of the strong chelating property of the HV:HF acid system (Nwoke et al., 2004). These numerous properties of the HV:HF acid system are, indeed, the reason for the improved success rate of acid jobs in several case histories.
To satisfy the need for a longer-lasting stimulation effect without the generation of unwanted second-reaction and third-reaction precipitates in sensitive sandstone formations, the expert system deploys another blend referred to as the acidic chelant-based blends (Urraca and Ferenc 2009;Rae and Di Lullo 2007;Nasr-El-Din et al. 2002. The use of these acidic chelant-based blends is restricted to high temperatures formations, with relatively high carbonate content and low clay content. The advantages of these acid blends consist of their ability to: • Dissolve both calcium and alumino-silicates.
• Prevent the possible precipitation of reaction byproducts by sequestering many of the metal ions present in the aqueous solution: Ca 2? , Fe 2? , Al 3? ions. • Treat formations with high calcite content.
• Treat formations with high iron content.
• Treat formations with zeolite bearing minerals.

System implementation
Implementation of the acidizing expert system has been achieved in five phases as shown in Fig. 8. The first phase is knowledge acquisition in which knowledge is elicited from the expert in the field. In this phase, the necessary knowledge is built up progressively through a series of consultation sessions between the domain expert and the artificial intelligence specialist, the knowledge engineer. Knowledge acquired during these sessions is recorded, refined and structured so that it could be used in the reasoning process.
The main task of the second phase is to arrange the acquired knowledge in decision trees, which are considered as the main communication tools between the domain expert and the system developer. Decision trees prepared for Stages 1-6 are shown in Figs. 1, 2, 3, 4, 5, 6, respectively. Main development and coding of the ''Acidizing Expert System'' are performed in phase three.
The software used in the implementation of the system is Exsys Corvid, which is supported and licensed by Exsys Ò Inc. Corvid is an expert system development tool that can be used to automate decision-making processes (Exsys Inc. 2010). Expert system development in Corvid is achieved using object structures, logic blocks, action blocks and interactive Java-based tools for Web delivery.
The first step in phase three is to formulate the system by identifying and defining the variables that will be used in the reasoning process. Variables are either input variables that are acquired through interaction with the user or decision variables that are inferred and concluded by the reasoning process. The next step in phase three is to represent the knowledge, arranged as decision trees, in IF-THEN rules format. The expert system is then constructed using the development mode of Exsys Corvid. This includes defining the variables, followed by building the questions and defining the interaction with the user. The knowledge base is then constructed by coding the IF-THEN rules taking into account the inference mechanism to be used in deriving the conclusions. During the development phase, interaction with the user is performed using Java Applet.
The developed expert system is tested and validated in stage four. Ideally, testing and validation are performed by Using the decision trees, the reasoning process is followed for each combination and the conclusions of the system are validated against the end nodes of the tree. Actual validation of the developed system is then performed by running a set of case studies that reflect practical applications. System implementation is finally concluded in stage five by delivering it to the end user. In Exsys Corvid, the developed expert system may be delivered using Java Applet or Servlet Runtime. The former is for standalone applications, while the latter is for Web-based applications.

Reasoning structure
The structure of the acidizing expert system is shown in Fig. 9. Each stage in the hierarchy corresponds to a Logic  Block consisting of rule sets specialized in modeling the logic and deriving the required decisions. Moreover, each stage corresponds to a decision tree representing the knowledge elicited from the expert. Decision trees are constructed in the previous section and illustrated in Figs. 1, 2, 3, 4, 5, 6. An acidizing consultation session starts by processing the first three stages sequentially, followed by asking about the type(s) of damage. Stages 1 and 2 are designed to treat damage type 1. Stage 3 scrutinizes conditions that wave HCl injections for preventing sludging, rigid emulsions, and iron precipitates. The reasoning process is then directed to infer the rules associated to Stage 4 and/or Stage 5, based on the selected damage type(s). Damage types 3, 4, 5, 6 and 7 are covered by the HCl pre-flush of Stage 4 (Fig. 4). The reasoning process then proceeds to Stages 5 for deriving the recommendations for treatment of fines migration (damage type 2, Fig. 5). Finally, the reasoning process proceeds to Stage 6 which is concerned with the fluid selection for the post-flush (Fig. 6).
The reasoning protocol outlined above is defined in Exsys Corvid using a ''Command Block'', which is shown in the Exsys Corvid Window capture shown in Fig. 10. The statements listed in the command block are normally executed sequentially. After displaying the title page (TITLE statement), the system is directed to derive the value of the ''Confidence'' variable [Stage_Two]. Consequently, backward chaining will be invoked, which would The third statement/command is RESULTS, which displays the results or conclusions reached so far. This is followed by a command to derive the ''Confidence'' variable [Stage_Three].
The command block shown in Fig. 10  This would result in nesting the backward chaining reasoning back to the logic block for Stage 1, followed by processing the logic blocks related to the stages down the hierarchy (Fig. 9).
Rules are expressed in Exsys Corvid using ''Logic Modules''. They include a set of IF-THEN rules describing a reasoning logic. An example logic module describing the logic in Stage 1 is shown in Fig. 11. Moreover, the IF-THEN representation of the first rule of this logic module is shown in Fig. 12 Only one decision is derived from Stage 2 (see Fig. 2). For the acetic acid pre-flush stage (Stage 3), reasoning is mainly based on the iron, clay and zeolite contents in the formation. As shown in Fig. 3, two conclusions are possible for this stage: ''No action needed'' if the formation does not have iron, clay or zeolite, and ''Inject acetic acid'' if they exist. Moreover, the system suggests the volume of acetic acid, which is determined based on the calcite (CaCO 3 ) content, expressed as a percentage out of the total rock bulk volume.
The reasoning logic for Stage 4 checks sludge and/or emulsion potential logic shown in Fig. 13. If the statements in either one of the logical TRUE blocks are true, then the sludge and/or emulsion potentials are inferred as high. Another two logical tests needed for Stage 4 reasoning are ''OR Test S4-1'' and ''OR Test S4-2'', which are shown in Fig. 7a and b, respectively. The outcome of this stage is nine decisions, seven of which are recommending the composition of the main acid to be injected for the pre-flush stage. Asphaltene sludging is likely to take place when a highly non-paraffinic crude, with API gravity C27 and stock tank asphaltene content is less or equal to 3 % by weight, is in contact with HCl, or HCl/HF blends. Rigid emulsions, on the other hand, would take place for the same conditions when the crude is highly non-paraffinic with API gravity B22 and stock tank asphaltene content is C4 % by weight (Houchin et al. 1990).
Acid formulation for Stage 5 is designed to treat specifically fines migration damage. The decision tree used in developing the logic module for this stage is shown in Fig. 5. In addition to the two OR tests used in Stage 4 (Fig. 7a, b), Stage 5 starts by checking one more OR test, which is ''OR Test S5-1'' shown in Fig. 7c. The outcome of this stage is a recommendation on the type of main acid to be used (see Fig. 5).  Fig. 13 Testing for sludge and/ or emulsion potential, used in Stage 4 The last logic module to process is Stage 6. As shown in Fig. 6, the reasoning process derives the recommendation to use one of the four options for acid over-flush. The acidizing expert system has been developed as a web-based application. A snapshot of the main page of the system is shown in Fig. 14. The same website hosts another expert system for accessing formation damage, which is the subject of another future publication. Sample results page listing the recommendations of an acidizing session is shown in Fig. 15.

Acidizing system validation
Prior to starting a session in the acidizing expert system, the following data should be prepared by the user: 1. Volume fractions of iron-rich minerals such as pyrite, siderite, hematite, magnetite, and antecerite. 2. Volume fractions of chlorite, mixed layer clays and illite, and Na-feldspar and K-feldspar. 3. Volume fractions of calcite and zeolites (analcime, natrolite).  Fig. 15 Recommendations of the acidizing expert system for the Niger Delta field case 4. Whether the clays, iron-rich minerals, calcite and feldspars exist as authigenic, detrital or crystal growth. 5. API gravity of crude, whether it is highly paraffinic or non-paraffinic, and the stock tank weight percent of asphaltenes. 6. The reservoir temperature and thickness. 7. Whether there were any whole mud losses during drilling of the well. 8. Whether the studied well is an injection or a production well. 9. Whether there is any bacteria growth on the wellbore face. 10. Whether there were any polymer flooding performed prior to the acidizing job. 11. Whether there are any natural fractures, and whether there is any filling of these fractures by calcite material. 12. The type of damage that is required to remove. The acidizing expert system has been validated with a number of field cases from oil fields around the world. Three actual field cases will be discussed and reported in this study. They include the Niger Delta region, Algyo Oil field in Hungary, and the Dulang oil field in Malaysia.

Case no. 1: Niger Delta region
This case study is related to a low-pressure sandstone oil producer well in the Niger Delta region of southern Nigeria. Rock properties were gathered for a number of layers of this reservoir (Obadare et al. 2006). A representative mineralogical distribution used by the expert system is displayed in Table 1. Permeability ranges from 100 to 5,000 mD. Clay constituents, composition and distribution were mapped for the concerned layers with a reasonable statistical accuracy. The crude has a 0.663 downhole specific gravity, and the reservoir temperature is 188°F. The pay thickness is approximately 21.7 ft. The main concern with this well is the high potential of gelatinous precipitates that may form in presence of zeolites, feldspar, clay, and fines migration material. In addition to the data given so far, following are further information that answers the queries of the system: 1. Existence of mud losses to the formation because the well was drilled overbalanced with a water-based mud, and the reservoir unit has a fairly high permeability value. 2. A finite amount of polymer residue may have been left in the formation, as a consequence of the lost circulation material during drilling. 3. Crude is paraffinic. 4. Iron-rich minerals exist as authigenic. 5. Feldspar material exists as detrital. 6. Intermediate matrix treatment is needed because of the high rock permeability.
For the given data and information, the acidizing expert system recommended the following acid treatment (see Fig. 15): Stage One: Formation oil displacement stage: inject a mixture of diesel and toluene at 75:25 ratio. Soak overnight and flow back. Inject a mutual solvent.
Stage Two: Formation water displacement stage: inject water with ammonium chloride at concentrations between 3 and 8 %, depending on the formation water salinity.
Stage Three: Acetic acid pre-flush: no action is needed for this stage.
Stage Five: Main acid stage: inject phosphonic acid. Stage Six: Over-flush stage: inject 8 % NH 4 Cl. As reported by Obadare et al. (2006), the actual treatment used for the Niger Delta well consisted of a solvent spearhead ? 10 % HCl pre-flush ? HF phosphonic acid system ? 5 % HCl ? 3 % ammonium chloride containing a clay stabilizer and a mutual solvent. This acid blend is in perfect agreement with the blend recommended by the acidizing expert system. The slight discrepancy is that the expert system followed a conservative approach in adding fluoboric acid, erythorbic acid and EDTA in the pre-flush recommendation. In fact, fluoboric acid assures the disintegration of any clay cementing material, erythorbic acid  assures the reduction of iron, while EDTA assures the sequestration of iron released from iron-rich material, siderite and pyrite. Even though these two minerals exist in minute amounts, they have been assumed to exist as authigenic within the rock pores, a fact that makes their presence a potential cause for unwanted precipitates, if not properly dealt with. The applied acid system mitigated challenges associated with rock mineralogy. Prior to the introduction of this acid blend, the success rate for acidizing was 12 %. The applied acid blend improved production rate after acidizing by 400 % compared to mud acid systems used previously in the Niger Delta Basin (Obadare et al. 2006).

Case no. 2: Algyo oil field in Hungary
The second case study is related to an injector well in the AP-13 reservoir unit of the Algyo oil field in Hungary (Urraca and Udvari 2009). This sandstone reservoir presents a number of challenges. The well is depleted, has low-permeability (15 mD) clay-rich sandstone that is at high temperature (252°F) with relatively high calcite content, and with a long production interval. Mud acids have been used in the past on Algyo injector wells in an attempt to improve injectivity by alleviating fines migration problems in this mineralogically complex rock. From special core analysis, it was determined that the inflicted damage was related to iron compounds, clays, and presence of calcite material. It was not possible to sustain the injection rate after previous mud acid treatments with suspected rock disintegration in the near-wellbore area. The above data have been augmented by answers to the following queries: 1. No reports of mud losses to the formation, confirmed by the low-permeability value of the rock (15 mD). 2. No polymer residue might have been entrapped in the formation as a consequence of insignificant mud filtrate seepage. 3. The crude is paraffinic. 4. Iron-rich minerals do not exist as reported from the mineralogical description. 5. Feldspar material exist as detrital. 6. Near-Wellbore treatment is needed because of the low rock permeability.
The acidizing expert system recommended the following treatment procedure: Stage One: Formation oil displacement stage: No action is needed.
Stage Two: Formation water displacement stage: Inject water with ammonium chloride at concentrations between 3 and 8 %, depending on the formation water salinity.
Stage Six: Over-flush stage: Inject 8 % NH 4 Cl. According to Urraca and Udvari (2009), a chelating acid blend was used to efficiently stimulate the Ap-13 reservoir. The injector well was indeed treated with this technology. Two years after this treatment, stable injection rates at optimum surface pressures were still maintained without the need of re-stimulation. The main acid injection was preceded with a pre-flush of ammonium chloride of 6 m 3 with 10 % of mutual solvent. This acid blend is in perfect agreement with the blend recommended by the acidizing expert system. The need of acid chelating blend, as the main acid, emanates from the relatively high calcite content ([6 %), and the high reservoir temperature (252°F). The acetic acid recommended by the expert system was meant to dissolve calcite cementing material while at the same time eliminating the potential precipitates of iron released by the potential disintegration of chlorite material.

Case no. 3: Dulang oil field
This case study is related to an acidizing job on a producing oil well in the Dulang oil field in Malay Basin Malaysia (Ali et al. 2005). This is a shaly sandstone reservoir with original oil in place estimated at 700 million STB, and with a crude gravity averaging 39°API. The bottom hole temperature of this reservoir unit, which is about 30 ft thick, is approximately 250°F. According to the drilling and workover reports, there were no significant losses of the drilling mud, eliminating damage caused by drilling mud invasion. The inflicting damage is mainly attributed to clay swelling and fines migration. X-ray diffraction data are shown in Table 1. Core samples analyzed displayed a consistent content of about 15 % clays and 15 % carbonate with the presence of some chlorite and zeolites. Liquid permeability measured parallel to the bedding plane of 20 core samples from various reservoir sections, at connate water saturation, give a geometric mean of approximately 37.1 mD (Nadeason et al. 2001). The above data have been augmented by answers to the following queries: 6. Near-Wellbore treatment is needed because of the insignificant mud losses. The acidizing expert system recommended the following treatment procedure: Stage One: Formation oil displacement stage: No action is needed.
Stage Two: Formation water displacement stage: inject water with ammonium chloride at concentrations between 3 and 8 %, depending on the formation water salinity.
Stage Six: Over-flush stage: inject 8 % NH 4 Cl. The actual treatment fluid, which was reported by Ali et al. (2005), consisted of a 10 % acetic acid pre-flush, an organic clay acid and an organic mud acid as the main acid. The well showed an insignificant production improvement of approximately 100 bbl/day production. Even though organic mud acid has the ability to dissolve fines at this high reservoir temperature, the occurrence of secondary and tertiary reactions in presence of moderate amounts of chlorite and feldspar makes the use of mud acid a gamble. Organic clay acid would be useful for removing problems of fines migration at high reservoir temperature, provided that the calcite content is low. However, at this combination of high temperature, high calcite content, presence of moderate amount of feldspar and chlorite in addition to fines migration problem, a better main acid solution becomes the chelantbased acid recommended by the acidizing expert system.

Conclusions
This manuscript documents the development of an expert system for automating the design of sandstone acidizing. The system has been implemented, tested and validated with actual field data.
The acidizing system has been developed using revised acidizing guidelines that are formation damage specific, and are also specific to rock mineralogical composition and distribution. Traditional guidelines have been modified with respect to certain mineral sensitivities. Specifically, these modifications included more explicit consideration for the presence of acid-sensitive minerals such as zeolites, chloride, and feldspars, and their distribution in the rock matrix and in the pore space. These guidelines have been also augmented with respect to certain acid blends such as phosphonic acids and acid chelant systems which are more tolerant to temperature, calcium and zeolite presence, and to clay sensitivity.
The treatment design approach, implemented in the acidizing expert system, is developed following an acidizing structure that includes guidelines prepared in the form of decision trees for six stages, namely: (i) the formation oil displacement stage, (ii) the formation water displacement stage, (iii) the acetic acid stage, (iv) the HCl pre-flush stage, (v) the main acid stage, and (vi) the over-flush stage.
Integration of rules honoring the compatibility between the acid injected and the rock mineralogy, and fluids present in the rock, yields an optimal acid job design with recommended main acid volumes, pre-and post-flush fluids. The acidizing system is only applicable for a reservoir permeability not \10 mD for oil-bearing layers, and not \1 mD for gas-bearing layers. This permeability cut-off, at reasonable layer thickness, should provide oil and gas production at profitable rates after damage removal. For permeability values less than these cut-off values, hydraulic fracturing becomes a viable option.