## 1. Introduction

Computational fluid dynamics (CFD)-based optimization approach has been growing rapidly in the past decades. The demand of optimizing the product designs with high reliability and the time constraints have promoted engineers and researchers to develop the frameworks tackling the problems, in which CFD simulation becomes one of the key roles. In addition, the computing power has raised the performance over 10,000 times in comparison with the point in the mid-1980s. Thus, the computing tasks now could adapt in much complex and bigger models. In other words, the computing century has changed the way engineers finding the solutions, and traditional approaches like experimental ones now are moving apart to modeling approaches.

In fact, the capability of CFD-based optimization has been early deployed in aerospace field to generate the wing profiles, which could reduce the drag force [1]. Jameson [2, 3, 4] firstly proposed a shape optimization method for aerodynamic design using the control theory. In this methodology, the authors used adjoint equations. The design space could be extended to the number of coordinate transformations or cost functions. It is also called as nonparametric method. Following that, several studies on shape optimization in this field have been published [5, 6, 7]. The other methodology, so-called the parametric method, was also successfully applied in this field such as the research of Eero Immonen [8], which investigated the CFD-based optimization framework for the NACA airfoil using response surface method (RSM).

In the branch of thermal design, CFD-based optimization is applied in various objects such as the optimization of chemical reactor [9], steam turbine blade cascade [10], or plate-fin heat exchanger [11]. Also, several CFD-based optimization studies on other fields were published in literature including ship hull [12], car [13, 14], vascular [15], or engine [16].

However, in this chapter, instead of describing all the above techniques, we introduce a parametric approach of CFD-based optimization that couples CFD and evolution algorithms since this approach could be applied in more complex systems of equations as well as the complex physical models. Although evolution algorithm tree has several branches, we are going to focus only on the popular type, genetic algorithm (GA). A general concept is illustrated to help readers to follow easily. Finally, a study case that uses CFD and single-objective genetic algorithm (SOGA) to optimize the uniformity of flow in the manifold is investigated.

## 2. A brief introduction about GAs

### 2.1. Definition of gas

Genetic algorithms are first proposed by John Holland in the 1960s and were continuously developed together with his students during the 70th decade. The idea of the generic algorithm is inspired by the natural selection and the famous Darwin’s law, survival of the fittest.

The characteristics of GAs show some advantages in comparison with the classical optimization method, especially when coupling them with CFD simulation. At first, GAs can generate the individuals (or chromosomes) of populations independently. In the complex systems, CFD solver may cost much time to reach to convergence. The simultaneous running takes advantage of modern computing power. Each job will be solved separately and then synchronized when GAs do their operators. Moreover, we could restart the work at interrupt point if there is any corruption, whereas this may be difficult when an individual is produced iteratively like the way gradient-based methods operate. Second, since the cost function in GAs is constant, GAs may overcome the numerical noise, which normally occurs in a CFD problem due to the limit of grid resolution or residual.

### 2.2. The genetic operators

In GAs, the population is generated toward the best solution by improving the quality of individuals. During the evaluation process, a population is generated through the three main generic operators including selection, crossover, and mutation. An individual could be alive, reproduced, or removed from population depending on its fitness value and the probability of randomly modifying itself, called mutation. The evaluation process of GAs is operated as follows:

**Initializing the population**—At the starting point, GAs will randomly produce a number of individuals.**Selection operator**—In this step, the individuals are evaluated by a fitness function. The fitness value is the best answer according to the specific problem. The individuals then are sorted based on their fitness value. The purpose of selection operator is to determine the candidates to pass their characteristics to the next generation.**Crossover operator**—This operator works in two selected individuals to generate two new individuals or offspring. The numbers of characteristics of an individual will be swapped to the other with the corresponding length. The new offspring created in this step will be put into the next generation of the population. By this way, the populations move toward the better solution.**Mutation operator**—This is an important operator of GAs, which keeps the results of GAs away from local optima. A small probability of individual’s characteristics is modified randomly.**Stop condition**—The selection, crossover, and mutation are looping in a number of evaluations. The quality of population is improved after each iteration, but there is no way to be sure that the present results are the best solutions. Thus, we need a strategy to stop GAs in the constraint of time of project or when population reaches to an approximation in which the result is placed around the best-known space.

The flow chart of the general GAs is shown in **Figure 1**.

## 3. CFD coupled GAs for shape optimization

In the present case, the procedure is deployed relying on the open-source software OpenFOAM in CFD block, the DAKOTA in algorithm block, and the interface script to connect two blocks. All programs run on Linux system. The flow chart of coupling GAs and CFD simulation is shown in **Figure 2**.

The working flow of coupled procedure could be mainly described by the following five steps:

### 3.1. Template declaration

Before running the coupled procedure, all the template files must be implemented. In CFD block, we create a geometry, a mesh file, boundary types, a solver, and a sampling template. The design parameters are declared in the templates as variables and can be changed during the evaluation of GA block. By this way, the evaluation can run in parallel. The simulation script copies the CFD templates for each separated job, inserts the values, and starts the solver. As mentioned before, since all individuals can be evaluated independently in each generation, this approach can adjust to adapt the scale of computing power. As a result, it can save the running time on the specific hardware. Moreover, there is no limit of license running on stations, so this structure shows the economy when deploying on the multi-node cluster.

### 3.2. Geometry and grid generation

In this step, the CFD block will generate geometry and grid. In the first cycle, GA block initializes the population and then triggers and parses control parameters to CFD block. The control parameters are selected depending on the objectives of problem. We can adjust boundary, geometry, and solver to adapt the purpose of simulation.

The geometry can be created by OpenSCAD or Salome, both are open-source software. In some cases, if the geometry is not so complex, OpenFOAM supports block-mesh and snappy-hex-mesh utilities, which can be used to generate the geometry and grid. For complex geometry, some commercial meshing programs such as Pointwise or ICEM CFD show their advantages. We may also consider other open-source meshing programs like cfMesh or Salome.

### 3.3. CFD simulation

After generating the grid, CFD solver will be triggered by batch command. Various solver types are implemented in OpenFOAM, and we need to choose an appropriate one for our problem. OpenFOAM also supports a simple way to create our boundary type or modifying solver for the specific models. However, we need to validate them with the experimental data, and then the configuration can be used as template.

### 3.4. Post-processing

For steady-state simulation, after convergence, the post-processing will export the selected raw data. A python script is then implemented to calculate the results. This approach is flexible in preparing the clean data. In the case of transient simulation, it is most important to choose the right collecting periods to warrant the correctness as of physical model.

### 3.5. Generic operator

When the post-processing completes, interface script will trigger and parse the data to GA block. GA block then does its operator as demonstrated. When GA block is completed, in turn, interface script triggers and parses data back to CFD block. The coupled procedure will stop if it finishes the predefined evaluation step. The best results and running history are finally archived. All steps are automatically driven by an interface script.

## 4. Optimization of the maldistribution of flow in a manifold

### 4.1. Introduction

In designing air-cooled heat exchanger, nonuniformity of flow in manifolds is one of the common issues. The maldistribution of flow could significantly affect to the performance and efficiency of heat exchanger. Thus, analyzing the behavior of flow in manifolds or header is necessary to improve the design.

In practical design, flow maldistribution in manifolds can be induced by the geometry and operating conditions [17]. Jiao et al. [18] investigated experimentally the effect of various geometry parameters including the inlet pipe diameter, the first header’s diameter, and the second header’s diameter. The authors reported that the flow distribution can be significantly improved by optimum design of header configuration. The study of Wen and Li [19] showed a serious flow maldistribution problem in heat exchanger using conventional header. They recommended to install a baffle with small-sized holes to improve the uniform of flow. Wang et al. [20] presented five modified inlet headers to enhance the uniform of liquid flow distribution in the compact heat exchangers.

Besides of using experiments, various studies used modeling approaches to analyze the flow distribution. Tonomura et al. [21] demonstrated a CFD approach to discover the effect of design header on the uniform of flow. The results in this study showed that the shape of manifolds, the length and location of inside fins, and the inlet flow rate significantly affected the flow uniformity. The authors also proposed a CFD-based optimization method to find the optimal design of plate-fine microdevices. Wang et al. [22] proposed a different computational approach. The authors presented a Lattice Boltzmann method for shape optimization of distributor. Recently, Facão [23] developed a correlation model to improve the uniform of flow in solar collector. The model was then validated by the CFD simulation.

In this chapter, we demonstrated another approach to optimize the flow distribution by coupling the CFD simulation and a genetic algorithm. It comes from the fact that the uniform of flow could depend on various parameters and has no general form for specific applications. Hence, combination of GA and CFD would be a good solution to save time and design cost.

### 4.2. Numerical model

#### 4.2.1. Mathematical model

In this study, two-phase flow of refrigerant is simulated using OpenFOAM software. The working fluid is R134a. Since the experimental test was taken under the adiabatic condition, the simulation will only solve the continuity and momentum equations. VOF method, therefore, has been implemented. VOF solver in OpenFOAM calculates one momentum and one continuity equation for both liquid and gas phases of R134a. The physical properties of one phase are determined based on the volume fraction, α, of two phases in a cell. The continuity equation is defined as follows:

The momentum equation is determined as follows:

where F_{s} is the surface tension force at free surfaces and is defined as

where κ is the curvature of the interface and n is a unit vector normal to the interface. κ and n are calculated as follows:

and

Volume fraction, α, in a cell is 0 if it is completely filled by vapor phase, and, on the contrary, volume fraction equals 1 if a cell is completely filled by liquid phase. Volume fraction is calculated by a transport equation as follows:

The compression of the surface in OpenFOAM is defined as follows:

where *U _{r}* is a suitable velocity field to compress the interface.

The properties of two-phase flow of R134a are obtained in REFPROP 8 and are listed in **Table 1**.

#### 4.2.2. Geometry and grid

The dimensions of manifold are referred from a report of Fei and Hrnjak [24]. In the first phase, we set up a model to validate with the experiment. A three-dimensional model was then created. To reduce the computational cost as well as enhance the accuracy and stability of simulation, the grid was manually generated with hexahedral meshes. In addition, to validate the independence of grid, three types of mesh with the total elements of 377,540, 415,644, and 453,748 were also made, and the last mesh was chosen for the simulation in this study. The detailed dimension of manifold is illustrated in **Table 2**. The sample of grid is shown in **Figure 3**.

Saturation temp. (°C) | Pressure (kPa) | Density of liquid (kg/m^{3}) | Density of vapor (kg/m^{3}) | Viscosity of liquid (Pa.s) | Viscosity of vapor (Pa.s) |
---|---|---|---|---|---|

24.473 | 665 | 1208.7 | 31.841 | 1.96E−4 | 1.17E−5 |

**Figure 4** shows a time history of the simulation for volume fraction at the outlets. In this case, the total mass flow rate of two-phase is 10 g/s, and the vapor quality is 0.2. The trend shows that volume fraction in the first outlet firstly raises and quickly drops when the pattern of flow is formed. The liquid phase is then accumulated in the second outlet. The volume fraction in the fifth outlet increases steeply from the sixth to ninth second since the flow bouncing back from the ending wall almost returns to this channel. The fourth outlet, in consequent, has the lowest volume fraction. It turns out that the mass flow rate and the body shape of header are strongly influent to the uniform of flow. The contour of liquid fraction is illustrated in detail in **Figure 5**.

The result demonstrates that the maldistribution is difficult to avoid within the conventional design of manifold. This problem could be overcome by modifying the inlet type, changing the body shape of manifolds or adding the baffles. In this work, we modified the inside of the conventional manifold by generating the baffles between each outlet channel. The ideal is that supplied fluid is enough for all outlets, and the flow would be uniform. Hence, we created five subsections inside the manifold. Each subsection works as a liquid pool to accumulate and to distribute liquid. However, the baffle height needs to be designed carefully to archive the purpose of optimization. The work can be tackled by using GA in which the design space is the height of baffles, and the object is the average mean difference of liquid flow rate at the outlet. The cost function, therefore, can be determined as follows:

where ṁ_{f} is the mass flow rate (kg/s) of liquid phase and k is the number of outlet.

#### 4.2.3. Optimization

In the second phase, we proposed a new geometry with the baffles between each outlet channel. Since the baffles divide the header to subsections, the geometry now can be reduced to 2D problem. A geometry and grid now are generated using C code. The schematic of proposed header and sample of grid are shown in **Figure 6**.

In this study, a single-objective genetic algorithm (SOGA) was implemented. The purpose of algorithm is to minimize the mean difference between the flow rate in each outlet and the average mass flow rate of liquid phase. The fitness type was set as the domination count. The crossover was 80%, the mutation scale was 10%, and the number of evaluation was set as 500. SOGA script automatically generates baffle dimension and updates the boundary conditions as described in the previous part. In addition, another script drives the CFD code run and exports the results for the next evaluation in SOGA.

**Figure 7** illustrates the variation of baffle height and the mean difference of flow rate during the evaluation of GA. The height of baffle is ranged from 0.1 to 7.9 mm, and 16 populations were created. The optimal point is found at evaluation 372nd with the baffle height of 7.52 mm.

The improvement factor is shown in **Figure 8**. The results show that the optimal design improves the mean difference of liquid flow rate about 6 and 15 times in comparison with the general manifold without baffle and the worst case of manifold with baffles, respectively.

## 5. Conclusions

In this chapter, we demonstrated a CFD-based optimization framework that couples a CFD block and a GA block. In addition, a CFD simulation and the optimization of two-phase flow distribution of R134a in a manifold were also investigated. The optimal design shows much improvement in comparison with the general case. Although only single object is produced, this framework can easily expand to multi-objects.