Engineering Design by Genetic Algorithms and Finite Element Methods

Giorgi Tskhondia
8 min readJan 7, 2022

1. Introduction

Engineering design of structural components is a tedious and tiring process where one has to do a lot of geometry alterations before resulting in final design. However, nowadays, this process can be automated by means of artificial intelligence. One approach of such an automation is by using reinforcement learning and finite element methods, [1]. More conventional way, nevertheless, is by means of genetic algorithms that have proven their effectiveness in topological optimisation problems. Hence, combining genetic algorithms with finite element methods for the purpose of engineering design is the key topic of this paper.

On the one hand, according to Wikipedia, in computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimisation and search problems by relying on biologically inspired operators such as mutation, crossover and selection. In a genetic algorithm, a population of candidate solutions (called individuals, creatures, or phenotypes) to an optimisation problem is evolved toward better solutions. Each candidate solution has a set of properties (its chromosomes or genotype) which can be mutated and altered; traditionally, solutions are represented in binary as strings of 0s and 1s, but other encodings are also possible (with e.g., continuous variables). The evolution usually starts from a population of randomly generated individuals, and is an iterative process, with the population in each iteration called a generation. In each generation, the fitness of every individual in the population is evaluated; the fitness is usually the value of the objective function in the optimisation problem being solved. The more fit individuals are stochastically selected from the current population, and each individual’s genome is modified (recombined and possibly randomly mutated) to form a new generation. The new generation of candidate solutions is then used in the next iteration of the algorithm. Commonly, the algorithm terminates when either a maximum number of generations has been produced, or a satisfactory fitness level has been reached for the population.

A good introductory book for GAs, extensively used in this article, is [2]. It uses python as a primary programming language and DEAP framework for implementing genetic algorithms. DEAP is a novel evolutionary computation framework for rapid prototyping and testing of ideas. It seeks to make algorithms explicit and data structures transparent. It works in perfect harmony with parallelisation mechanism such as multiprocessing and SCOOP, [3].

On the other hand, the finite element method (FEM) is a widely used method for numerically solving differential equations arising in engineering and mathematical modelling. The FEM is a general numerical method for solving partial differential equations in two or three space variables . To solve a problem, the FEM subdivides a large system into smaller, simpler parts that are called finite elements. This is achieved by a particular space discretisation in the space dimensions, which is implemented by the construction of a mesh of the object: the numerical domain for the solution, which has a finite number of points. The finite element method formulation of a boundary value problem finally results in a system of algebraic equations . The method approximates the unknown function over the domain. The simple equations that model these finite elements are then assembled into a larger system of equations that models the entire problem. The FEM then approximates a solution by minimising an associated error function via the calculus of variations (source Wikipedia).

In this paper, the main idea is to use genetic algorithms with fitness function that of finite element analysis.

FEM models for this article were taken from, [4].

2. Design of a bridge

First model was that of two‐dimensional bridge‐like plane truss fixed at its leftmost and rightmost bottom nodes. It was loaded in the middle node in downward vertical direction. Optimization objective was to minimise the middle node displacement.

The following steps describe the main parts of GA program:

1. We start by setting the lower and upper boundary for each of the values representing some bridge intermediate nodes:

BOUNDS_LOW =  [0, 0, 2, 5, 5, 5]
BOUNDS_HIGH = [5, 5, 9, 12, 14, 14]

2. Since our goal is to minimise the middle node displacement, we define a single objective, minimisation fitness strategy (because of negative displacement, it is actually maximisation):

creator.create("FitnessMax", base.Fitness, weights=(1.0,))

3. Now comes a particularly interesting part: since the solution is represented by a list of float values, each of a different range, we use the following loop to iterate over all pairs of lower-bound, upper-bound values. For each entry in data , we create a separate toolbox operator, which will be used to generate random float values in the appropriate range:

for i in range(NUM_OF_PARAMS):
toolbox.register("hyperparameter_" + str(i),
random.uniform, BOUNDS_LOW[i], BOUNDS_HIGH[i])

4. Then, we create the parameter tuple, which contains the separate float number generators we just created for each parameter:

for i in range(NUM_OF_PARAMS):
hyperparameters = hyperparameters + (toolbox.__getattribute__("hyperparameter_" + str(i)),)

5. Now, we can use this parameter tuple, in conjunction with DEAP’s built-in initCycle() operator, to create a new individualCreator operator that fills up an individual instance with a combination of randomly generated parameter values:

toolbox.register("individualCreator",
tools.initCycle,
creator.Individual,
hyperparameters,
n=1)

6. Then, we instruct the genetic algorithm to use the FEM method instance for fitness evaluation:

def femStatic(individual):
x1=individual[0]
x2=individual[1]
x3=individual[2]
x5=individual[3]
x6=individual[4]
x7=individual[5]

coord=np.array([0.0,0.0,
x1,3.0,
x2,0.0,
x3,3.0,
7.0,0.0,
x5,3.0,
x6,3.0,
x7,0.0,
14.0,0.0]).reshape(9,2)

displ = FEA_u(coord,
elcon=np.array([[0, 1],[0, 2],[1, 2],[1, 3],[2, 3],
[2, 4],[3, 4],[3, 5],[4, 5],[4, 7],
[5, 7],[5, 6],[6, 7],[6, 8],[7, 8]]),
bc_u_elim=[0,1,16,17],
f_after_u_elim=np.array([0,0,0,0,0,0,0,-10,0,0,0,0,0,0]),
A=1, E=2e5)
return displ[9],

7. Now, we need to define the genetic operators. While, for the selection operator, we use the usual tournament selection with a tournament size of 2, we choose crossover and mutation operators that are specialised for bounded float-list chromosomes and provide them with the boundaries we defined for each parameter:

toolbox.register(“select”, tools.selTournament, tournsize=2)
toolbox.register(“mate”,
tools.cxSimulatedBinaryBounded,
low=BOUNDS_LOW,
up=BOUNDS_HIGH,
eta=CROWDING_FACTOR)toolbox.register(“mutate”,

tools.mutPolynomialBounded,
low=BOUNDS_LOW,
up=BOUNDS_HIGH,
eta=CROWDING_FACTOR,
indpb=1.0 / NUM_OF_PARAMS)

8. In addition, we use the elitist approach, where the HOF (hall-of-fame) members — the current best individuals — are always passed untouched to the next generation:

hof = tools.HallOfFame(HALL_OF_FAME_SIZE)population, logbook = elitism.eaSimpleWithElitism(population,
toolbox,
cxpb=P_CROSSOVER,
mutpb=P_MUTATION,
ngen=MAX_GENERATIONS,
stats=stats,
halloffame=hof,
verbose=True)

Results of the modelling is the optimised bridge design (fig.2).

Fig.1 Initial design of a bridge before applying GA
Fig 2. Final design of a bridge after applying GA and FEM

To compare, the middle node displacement for the initial design (fig.1) is -0.0008888; for the final design (fig.2), it is -0.000819, i.e. the strength has increased for the GA design.

3. Design of Bionic Partition

Bionic partition for Airbus A 320 cabin interiors is well know achievement of design by genetic algorithms, [5]. Here, I tried to recreate the results at smaller scale.

The objective was to minimise the weight of the structure (total length of all elements) and maximise the strength ( minimise maximum out of plane displacement) for space frame structure, [4].

Some steps of the modelling are described below:

  1. Define a single objective, minimising fitness strategy:
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))

2. Create the Individual class based on list

creator.create("Individual", list, fitness=creator.FitnessMin)

3. Create an operator that randomly returns 0 or 1:

toolbox.register("zeroOrOne", random.randint, 0, 1)

4. Create the individual operator to fill up an Individual instance

toolbox.register("individualCreator", 
tools.initRepeat,
creator.Individual,
toolbox.zeroOrOne,
len(possible_lines))

5. Create the population operator to generate a list of individuals:

toolbox.register("populationCreator", 
tools.initRepeat,
list,
toolbox.individualCreator)

6. Then, we instruct the genetic algorithm to use the FEM method instance for fitness evaluation:

def staticFEM(individual):

coord, elcon, bc_u_elim, f_after_u_elim = utils(individual)

try:
FEA_output_arr=FEA(coord, elcon, bc_u_elim, f_after_u_elim)
except:
return PENALTY_VALUE,

strength=max_u(FEA_output_arr)

weight=total_length(coord,elcon)

return weight*abs(strength), # return a tuple

7. Set genetic operators:

toolbox.register("select", tools.selTournament, tournsize=2)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutFlipBit, indpb=1.0/len(possible_lines))

Results of the modelling is the produced design of “Bionic partition” (fig.3).

Fig.3 Design of “Bionic partition” by GA and FEM

Maximum lateral displacement was -0.000311866415297223.

4. Conclusion

Engineering design by genetic algorithm and finite element methods has proven to be an effective approach.

For the conclusion I would like to compare the designs obtained by reinforcement learning[1] and those by genetic algorithms of this paper.

For the bridge:

Fig.4 Design of a bridge by reinforcement learning and FEM
Fig.5 Design of a bridge by GA and FEM

Can you spot the difference? To compare, the middle node displacement for the reinforcement learning design (fig.4) is -0.00083877531; for the GA design (fig.5), it is -0.000819, i.e. the strength is higher for the GA design in this case.

For the Bionic partition:

Fig.6 Design of Bionic partition by reinforcement learning and FEM
Fig.7 Design of Bionic partition by GA and FEM

It is easier to spot the difference, is not it? To compare, the maximum out of plane displacement (strength) for the reinforcement learning design (fig.6) is -0.00044097384751047965 and the total length of the structure (weight) is 31.384776310; for the GA design (fig.7), the strength is -0.000311866415297223 and the weight is 15.07106781, i.e. the strength is higher, whereas the weight is lower for GA design case. However, here should be noted that the reinforcement learning design model was set under a bit different settings than that of GA design one.

Final remark:

I think that it is easier and more natural to program GA model rather than that of reinforcement learning one, however more investigation of the two methods shall be done. The two methods comparison (namely, the similarities of produced designs) shows the strengths of both methods and promise for their successful applications in engineering.

Full code for the paper can be found in [6], in section of Design by Genetic Algorithms and Finite Element Analysis.

To keep up with the project please see https://gigala.io/

Sponsor me at https://www.paypal.me/gigatskhondia

[1] https://gigatskhondia.medium.com/engineering-design-by-reinforcement-learning-and-finite-element-methods-82eb57796424

[2] Hands-On Genetic Algorithms with Python: Applying genetic algorithms to solve real-world deep learning and artificial intelligence problems. Wirsansky, Eyal.

[3] https://deap.readthedocs.io/en/master/

[4] MATLAB Guide to Finite Elements. An Interactive Approach, Peter I. Kattan, 2nd edition

[5] https://www.youtube.com/watch?v=IxF1FItQV4Y

[6] https://github.com/gigatskhondia/gigala

--

--

Giorgi Tskhondia

An adept of reinforcement learning and finite element methods. Unlocking fabric of reality @Gigala