My thesis explores the construction of a neural network model for diagnosing defects in gray and nodular cast iron castings, with an emphasis on sand foundry defects. The motivation came from the fact that cast iron components are widely used in industry, but the casting process is complex and often results in high rejection rates due to various defects. Traditional defect analysis relies heavily on empirical judgment, which is subjective and time-consuming. Therefore, I developed a systematic database of defects and their influencing factors, built a neural network model trained by a hybrid genetic algorithm, and designed a user-friendly software system for defect prediction and prevention. Throughout this research, I aimed to address the challenge of sand foundry defects by offering a computational tool that can quickly identify likely defect types and suggest corrective actions.
1. Introduction and Background
Gray cast iron is one of the most widely used casting alloys because of its excellent castability, low cost, and good vibration damping properties. However, like all sand foundry products, gray iron castings are susceptible to a range of defects that can compromise their quality and mechanical performance. Nodular (ductile) cast iron, developed in the 1940s, offers higher strength and ductility than gray iron due to the spherical shape of graphite, but it also suffers from specific casting defects. The need to diagnose sand foundry defects in a reliable and rapid manner prompted me to combine artificial neural networks (ANNs) with genetic algorithms (GAs) for this purpose.
In the foundry industry, casting defects are inevitable due to the many process variables involved, such as melting, molding, pouring, and solidification. The traditional approach to defect diagnosis involves visual inspection, metallographic analysis, and expert knowledge. While effective, this approach is slow and often fails to predict defects before they occur. An ANN can learn the nonlinear mapping between process parameters and defect occurrence, and a GA can optimize the network’s weights without the limitations of gradient-based methods. Thus, I selected five typical sand foundry defects for gray iron — subcutaneous blowholes, slag inclusions, chill (white iron), coarse graphite, and shrinkage porosity — and analogously defined five defects for nodular iron, such as graphite floatation and nodularity degradation.
In the following sections, I describe the defect analysis, the construction of the neural network model, the use of a hybrid genetic algorithm to learn network weights, the development of application software, and finally the results and conclusions of the work.
2. Analysis of Sand Foundry Defects in Iron Castings
2.1 Defects in Gray Cast Iron
Gray iron castings exhibit fewer visible defects than other alloys, but certain typical sand foundry defects still arise. I focused on five common ones, each discussed below with respect to its morphology, formation mechanism, influencing factors, and preventive measures.
2.1.1 Subcutaneous Blowholes
Subcutaneous blowholes are gas porosities located just below the casting surface, often appearing as spherical, teardrop, or elongated cavities. They are typically found after machining or shot blasting. The gas source is mainly from hydrogen generated by the reaction of hot metal with moisture in the sand mold. The formation condition can be expressed by the pressure balance equation:
$$P_{H_2} + P_{\text{atm}} + \rho g h + \frac{2\sigma}{r} \le P_{\text{gas}}$$
where $P_{H_2}$ is the hydrogen partial pressure, $P_{\text{atm}}$ is the atmospheric pressure, $\rho$ is the metal density, $g$ is the gravitational acceleration, $h$ is the metal head above the bubble, $\sigma$ is the surface tension, and $r$ is the bubble radius. A lower surface tension makes bubble formation easier, so elements like sulfur and manganese, which reduce surface tension, tend to promote subcutaneous blowholes.
Key influencing factors include:
- Sulfur and manganese content: Both are surface-active elements; their combined presence above a threshold increases the risk.
- Residual aluminum: The dangerous range is about 0.01–0.1% for gray iron.
- Wall thickness: Medium walls (10–40 mm) are most sensitive.
- Pouring temperature: Too low or too high can both cause issues.
- Moisture content of molding sand: Higher water content generates more steam, intensifying the reaction.
- Sand compactness and permeability: These affect gas escape.
Preventive actions include maintaining low sulfur, using proper molding sand with reduced moisture (<4%), adding coal dust or hematite powder, controlling pouring temperature, and designing a good gating system to avoid turbulent flow.
2.1.2 Slag Inclusions
Slag inclusions are non-metallic particles embedded in the casting. They can be classified as primary inclusions (formed during melting and before pouring) and secondary inclusions (formed during pouring and filling due to oxidation). The formation is governed by the thermodynamics of oxide formation, often written as:
$$A + B O \rightarrow AO + B$$
The Gibbs free energy change $\Delta G$ determines the tendency:
$$\Delta G = -RT \ln K$$
where $K$ is the equilibrium constant. In gray iron, the most stable oxides are those of silicon and manganese. To minimize slag defects, sulfur content should be kept low, silicon should be higher than manganese to form a low-melting-point slag, and the pouring system should include slag traps.
2.1.3 Chill (White Iron)
Chill refers to the formation of white iron (cementite) instead of gray iron, usually on the surface or in thin sections due to rapid cooling. The carbon equivalent (CE) is the main factor. If the CE is too low, the liquid solidifies according to the metastable system, forming cementite. Non-graphitizing elements like sulfur increase the chill tendency, while manganese counteracts sulfur. The critical relationship is often expressed as:
$$\text{Mn} \approx 1.7 \times \text{S} + 0.3\%$$
Prevention is achieved by inoculating the melt with silicon-containing alloys, controlling carbon and silicon contents, and adjusting pouring temperature.
2.1.4 Coarse Graphite
Coarse graphite appears as large flake graphite clusters that weaken the casting and cause surface defects after machining. It is caused by slow cooling and excessive carbon equivalent, which permits extensive graphite growth. Factors include high CE, excessive inoculation, thick sections, and high pouring temperature. Remedies include reducing carbon equivalent using steel scrap, proper inoculation, and adding chill.
2.1.5 Shrinkage Porosity and Cavities
Shrinkage defects result from the volume contraction during solidification. The total shrinkage is composed of liquid shrinkage and solidification shrinkage. The liquid shrinkage rate can be written as:
$$\varepsilon_{l} = \alpha_{l} (T_{\text{pour}} – T_{\text{liquidus}})$$
where $\alpha_{l}$ is the liquid contraction coefficient. For gray cast iron, the solidification shrinkage is reduced by graphite expansion. The net shrinkage rate $\varepsilon$ is given by:
$$\varepsilon = \varepsilon_{l} + \varepsilon_{s}$$
When graphite is precipitated, the expansion can compensate for contraction. Critical factors include carbon equivalent, pouring temperature, mold rigidity, and gating design. To avoid shrinkage porosity, one must control CE, maintain adequate mold hardness, and use proper risers and chills.
2.2 Defects in Nodular Cast Iron
Nodular cast iron has its own typical sand foundry defects, such as subcutaneous blowholes, shrinkage porosity, slag inclusions, graphite floatation, and nodularity degradation. The influencing factors are summarized in Table 1.
| Parameter | Subcutaneous blowholes | Shrinkage porosity | Slag inclusions | Graphite floatation | Nodularity degradation |
|---|---|---|---|---|---|
| Carbon equivalent | ● | ● | ● | ||
| Residual magnesium | ● | ● | |||
| Rare earth content | ● | ● | ● | ||
| Section thickness | ● | ● | ● | ● | ● |
| Pouring temperature | ● | ● | ● | ● | |
| Melting temperature | ● | ● | ● | ||
| Inoculation | ● | ● | |||
| Mold moisture | ● | ● | |||
| Mold compactness | ● | ● | |||
| Permeability | ● | ||||
| Gating design | ● | ● | ● | ||
| Riser design | ● | ● | ● | ||
| Chill | ● | ● | |||
| Slag removal | ● |
Note: ● indicates a strong influence.
This comprehensive analysis of sand foundry defects formed the knowledge base for the neural network model.
3. Construction of the Neural Network Diagnosis Model
3.1 Model Overview
The goal of the model is to map a set of process parameters (input vector) to a set of defect types (output vector). For gray iron, I selected 14 input parameters: carbon content, silicon content, phosphorus content, sulfur content, manganese content, aluminum content, inoculant amount, wall thickness, pouring temperature, melting temperature, sand moisture, compactness, permeability, and molding sand type (treated as a binary value). For nodular iron, 16 input parameters were chosen, including rare earth content, magnesium content, etc. The output layer consists of five nodes for gray iron and five nodes for nodular iron, each representing the probability of a specific defect being present.
The input-output mapping is a nonlinear function $f: \mathbf{x} \in \mathbb{R}^n \rightarrow \mathbf{y} \in \mathbb{R}^m$. A three-layer feedforward neural network with one hidden layer is sufficient for such approximation tasks. The network structure is shown schematically in my thesis, but here I describe it mathematically.
3.2 Network Structure
Let the input vector be $\mathbf{x} = (x_1, x_2, \ldots, x_n)^T$. The hidden layer outputs are computed as:
$$h_j = f\left( \sum_{i=1}^{n} w_{ji}^{(1)} x_i – \theta_j \right) \quad j = 1, \ldots, H$$
where $w_{ji}^{(1)}$ are the weights between input and hidden layers, $\theta_j$ are the thresholds of hidden neurons, and $f(\cdot)$ is the activation function. The output layer is:
$$y_k = f\left( \sum_{j=1}^{H} w_{kj}^{(2)} h_j – \phi_k \right) \quad k = 1, \ldots, m$$
with $w_{kj}^{(2)}$ being the weights between hidden and output layers, and $\phi_k$ the output thresholds. I chose the sigmoid activation function:
$$f(u) = \frac{1}{1 + e^{-u}}$$
because it is nonlinear, differentiable, and behaves like a threshold function for large inputs while approximating a linear function for small inputs.
The number of hidden neurons $H$ was selected using the rule $H = \sqrt{n \cdot m}$, giving $H \approx 8$ for gray iron (n=14, m=5) and $H \approx 9$ for nodular iron (n=16, m=5). I later adjusted these values based on training performance.
3.3 Sample Data and Normalization
I collected production data from foundries, constructing a database of defect samples. Each sample consisted of the input process parameters and the corresponding output defect status (1 for present, 0 for absent). The total number of samples was determined by an empirical formula: $N \ge \frac{H \cdot n}{m}$ or similar, and I used about 30 samples for gray iron and 28 for nodular iron. All input values were normalized to the range $[0,1]$ or $[-1,1]$ using a nonlinear transformation to balance their magnitudes. For example, a parameter $x$ was transformed to:
$$\tilde{x} = \frac{1}{1 + \exp\left( -\frac{x – x_{\text{min}}}{x_{\text{max}} – x_{\text{min}}} \right)}$$
This prevents large-valued parameters from dominating the smaller ones.
3.4 Hybrid Genetic Algorithm for Weight Learning
Training a neural network with the traditional backpropagation (BP) algorithm often suffers from slow convergence and getting stuck in local minima. To overcome this, I used a genetic algorithm (GA) to evolve the network weights. The GA is a global search method that does not require the error function to be continuous or differentiable. The hybrid approach uses GA first to find a good initial set of weights, then switches to BP for fine-tuning.
The steps are as follows:
3.4.1 Encoding
For a network with $n$ input neurons, $H$ hidden neurons, and $m$ output neurons, the total number of weights and biases is:
$$L = (n+1) \cdot H + (H+1) \cdot m$$
Each individual in the GA population represents a vector of these $L$ real numbers. Unlike binary encoding, I used real-valued encoding, which is more natural for continuous optimization problems. Each gene is a floating-point number.
3.4.2 Initialization
The initial population of size $P$ (e.g., $P=30$ to $50$) is randomly generated within a specified range $[-R, R]$. The range depends on the activation function; for the sigmoid, $R=5$ is typical.
3.4.3 Fitness Function
I used the mean squared error between the network output and the expected output as the basis for fitness. The error for the $p$-th training sample is:
$$E_p = \frac{1}{2} \sum_{k=1}^{m} (y_{k,p} – d_{k,p})^2$$
where $y_{k,p}$ is the actual output and $d_{k,p}$ is the desired output. The total error over all $N$ samples is:
$$E = \sum_{p=1}^{N} E_p$$
The fitness can be defined as:
$$F = \frac{1}{1 + E}$$
which is always positive, so a smaller error yields a higher fitness.
3.4.4 Selection
I employed a roulette-wheel selection method. The selection probability of individual $i$ is:
$$p_i = \frac{F_i}{\sum_{j=1}^{P} F_j}$$
To preserve the best solution, I also used elitism by copying the fittest individual directly into the next generation.
3.4.5 Crossover
For real-valued encoding, uniform crossover or arithmetic crossover works well. I selected two parents and exchanged a randomly chosen half of their genes. The crossover probability $P_c$ was set to $0.7$–$0.8$.
3.4.6 Mutation
Mutation adds a small random perturbation to each gene with probability $P_m$ (e.g., $0.01$–$0.05$). In my implementation, the mutation value was generated from a uniform distribution within a shrinking interval to maintain diversity while allowing convergence.
3.4.7 Termination and Local Search
The GA iterates for a fixed number of generations or until the best fitness no longer improves. I then used the resulting weights as the starting point for the scaled conjugate gradient (a variant of BP) to refine the solution. This hybrid strategy significantly shortened the training time and improved accuracy.
4. Development of the Diagnosis Software
Based on the model, I developed a Windows application using Visual C++ 6.0 and the MFC library. The software has a full Chinese user interface, which is convenient for foundry engineers. It consists of two main parts: a database and an application module.
4.1 Database Design
I designed two databases:
- Sample database: Stores the defect samples used for training. It is divided into gray iron and nodular iron sub-databases. Each record contains the process parameters and the defect status fields. The structure is shown in Table 2 and Table 3.
- Weight database: Stores the trained network weights. To facilitate fast access, I used binary stream files rather than a relational database.
| Field | Description | Data type |
|---|---|---|
| No. | Sequence number | Integer |
| C | Carbon content | Real |
| Si | Silicon content | Real |
| P | Phosphorus content | Real |
| S | Sulfur content | Real |
| Mn | Manganese content | Real |
| Al | Aluminum content | Real |
| Inoculant | Inoculant amount | Real |
| Thickness | Wall thickness | Real |
| Pour temp | Pouring temperature | Real |
| Melt temp | Melting temperature | Real |
| Moisture | Moisture content of sand | Real |
| Compact | Sand compactness | Real |
| Permeability | Sand permeability | Real |
| Subcutaneous blowholes | Defect output | Boolean |
| Slag inclusions | Defect output | Boolean |
| Chill | Defect output | Boolean |
| Coarse graphite | Defect output | Boolean |
| Shrinkage | Defect output | Boolean |
| Field | Description | Data type |
|---|---|---|
| No. | Sequence number | Integer |
| C | Carbon content | Real |
| Si | Silicon content | Real |
| P | Phosphorus content | Real |
| S | Sulfur content | Real |
| RE | Rare earth content | Real |
| Mg | Magnesium content | Real |
| Al | Aluminum content | Real |
| Thickness | Wall thickness | Real |
| Pour temp | Pouring temperature | Real |
| Melt temp | Melting temperature | Real |
| Inoc temp | Inoculation temperature | Real |
| Holding time | Holding time | Real |
| Moisture | Moisture content of sand | Real |
| Compact | Sand compactness | Real |
| Permeability | Sand permeability | Real |
| Subcutaneous blowholes | Defect output | Boolean |
| Shrinkage porosity | Defect output | Boolean |
| Slag inclusions | Defect output | Boolean |
| Graphite floatation | Defect output | Boolean |
| Nodularity degradation | Defect output | Boolean |
The sample databases were constructed using the Microsoft Access format, which allows easy editing and querying. The weight databases were stored as simple binary files to enable fast input/output operations during network calculations.
4.2 Application Modules
The software includes three main modules: system maintenance, defect prediction, and help.
System maintenance allows authorized users to edit the sample database and retrain the network. The training module uses the hybrid genetic algorithm described earlier. I provided two methods for initializing weights: random initialization (used on first training) and loading from the weight file (to continue training without starting over). The user can monitor the training error graphically.
Defect prediction is the core function. The user inputs the process parameters in a dialog window, and the software performs a forward pass through the network, computing the output probabilities for each defect. If any probability exceeds 0.5, the corresponding defect is considered likely, and the system displays recommended preventive measures. The results can be saved to a database for record-keeping.
Report generation was implemented using the Report Works component, which allows the user to preview and print a formatted defect diagnosis report. The report shows the input parameters, the predicted probabilities for each defect, and the suggested actions.
To illustrate the production environment of the foundry, I include an image of an automatic pouring line used in modern sand foundry processes below.

5. System Implementation and Results
5.1 Training and Testing
I collected 28 samples of gray iron and 24 samples of nodular iron from practical production. For gray iron, 24 samples were used for training and 4 for testing; for nodular iron, I used 20 for training and 4 for testing. The training was performed using the hybrid genetic algorithm. The error function decreased rapidly during the first few generations and then gradually converged. After switching to the scaled conjugate gradient method, the final error reached $E = 0.01$ or less.
To test the model, I ran the prediction for the test samples. Table 4 shows an example of the measured process parameters for nodular iron, and Table 5 presents the predicted probabilities versus the actual defect status.
| No. | C (%) | Si (%) | P (%) | S (%) | RE (%) | Mg (%) | Al (%) | Thickness (mm) | Pour temp (°C) | Melt temp (°C) | Moisture (%) | Compactness (%) | Permeability |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3.8 | 2.2 | 0.03 | 0.02 | 0.04 | 0.05 | 0.01 | 25 | 1350 | 1480 | 3.8 | 45 | 80 |
| 2 | 3.6 | 2.5 | 0.04 | 0.01 | 0.05 | 0.06 | 0.02 | 40 | 1300 | 1450 | 4.2 | 50 | 75 |
| 3 | 4.0 | 1.8 | 0.02 | 0.03 | 0.03 | 0.04 | 0.01 | 15 | 1380 | 1500 | 3.5 | 42 | 90 |
| 4 | 3.7 | 2.0 | 0.05 | 0.02 | 0.06 | 0.05 | 0.02 | 30 | 1320 | 1460 | 4.0 | 48 | 85 |
| No. | Defect | Predicted probability | Actual status |
|---|---|---|---|
| 1 | Subcutaneous blowholes | 0.87 | Present |
| Shrinkage porosity | 0.12 | Absent | |
| Slag inclusions | 0.23 | Absent | |
| Graphite floatation | 0.05 | Absent | |
| Nodularity degradation | 0.09 | Absent | |
| 2 | Subcutaneous blowholes | 0.34 | Absent |
| Shrinkage porosity | 0.78 | Present | |
| Slag inclusions | 0.45 | Absent | |
| Graphite floatation | 0.15 | Absent | |
| Nodularity degradation | 0.30 | Absent | |
| 3 | Subcutaneous blowholes | 0.95 | Present |
| Shrinkage porosity | 0.20 | Absent | |
| Slag inclusions | 0.08 | Absent | |
| Graphite floatation | 0.02 | Absent | |
| Nodularity degradation | 0.10 | Absent | |
| 4 | Subcutaneous blowholes | 0.18 | Absent |
| Shrinkage porosity | 0.65 | Present | |
| Slag inclusions | 0.70 | Present | |
| Graphite floatation | 0.40 | Absent | |
| Nodularity degradation | 0.55 | Present |
For gray iron, similar results were obtained. I measured the overall correct response rate by comparing the predicted binary decision (≥0.5) with the actual defect status. For the test set, the correct response rate exceeded 90%. In a few cases, the network predicted a probability near 0.5 for defects that actually occurred, which suggests some borderline samples where the separation between defect and non-defect is not sharp.
5.2 Error Analysis
The training error after convergence was about $E=0.01$. Since the output uses a sigmoid function, this error translates to an average error of about $\sqrt{2E/N} = \sqrt{2 \times 0.01 / (24 \times 5)} \approx 0.013$ per output, which is quite small. The high correct response rate confirms that the neural network model is capable of diagnosing sand foundry defects accurately.
One reason for the occasional incorrect prediction is that the number of training samples is limited. The sample database contains only a small fraction of the enormous variety of process conditions. Adding more real production data would improve the network generalization. Another reason is that some defects share similar influencing factors, making it difficult for the network to distinguish them. However, the overall performance is satisfactory for practical use.
6. Conclusion and Future Work
In this thesis, I have demonstrated that a neural network model, trained by a hybrid genetic algorithm, can effectively predict common sand foundry defects in gray and nodular iron castings. The main conclusions are:
- Feasibility: The proposed method successfully predicts defects and recommends preventive measures, significantly reducing casting rejections when applied in a production environment.
- Advantages of GA: Using a genetic algorithm to initialize neural network weights avoids the local minima problem of BP and speeds up convergence. This is particularly beneficial for large networks.
- Extensibility: The same architecture can be easily adapted to diagnose other types of casting defects by simply rebuilding the defect database and retraining the network.
- User-friendliness: The developed software has a complete Chinese interface, making it easy for foundry technicians to operate.
- Industrial relevance: This work expands the application of computer intelligence in the foundry industry.
Future improvements include extending the system to cover more defect types and more alloys, and quantitatively representing process measures (such as molding method, gating system type) as input features. In addition, integrating the software with on-line process monitoring systems would allow real-time defect prediction, further improving casting quality and reducing costs.
In summary, this research provides a practical and reliable tool for diagnosing sand foundry defects, combining the strengths of neural networks and genetic algorithms in a way that is both effective and easy to use.
