Loading

 

Lesson 5: An Optimization Problem

The present lesson demonstrates how to use an optimization problem solver. We solve the same problem as in Lesson 2 as an optimization problem where Dirichlet boundary conditions are considered as equality constraints. The optimization algorithm is the Truncated Newton algorithm described in function OptimTN. This is not the best method to solve a Laplace equation, but our purpose here is to learn how to use this class.

The Finite Element Code

The main program

Here is a description of the source code. The source file can be found in Example 5 in the examples directory.

A User defined class

We have now to implement class Opt that defines the problem to solve and provides to the objective function and its gradient. The class is defined in file Opt.h that we study here below.

A test

We use here exactly the same mesh file as in the previous lesson. Of course, we obtain the same solution as the previous lesson. The output of the program is the following:



   NIT  NF   CG           F                  GTG

    0    1    0     6.00000000e+000     4.00000000e+001
    1    2    3     1.67852990e+000     4.09059524e+001
    2    3    5     1.50042385e+000     4.09106651e+001
    3    4    8     1.50001179e+000     4.09109024e+001
    4    5   10     1.50000062e+000     4.09109074e+001
    5    6   13     1.50000000e+000     4.09109074e+001
    6    7   15     1.50000000e+000     4.09109074e+001
    7    8   17     1.50000000e+000     4.09109074e+001
    8    9   19     1.50000000e+000     4.09109074e+001


Optimal Function Value = 1.5

Solution :
     1     1.00000000e+000
     2     7.49999986e-001
     3     4.99999972e-001
     4     2.49999994e-001
     5     0.00000000e+000
     6     1.00000000e+000
     7     7.49999988e-001
     8     4.99999982e-001
     9     2.49999978e-001
    10     0.00000000e+000
    11     1.00000000e+000
    12     7.49999989e-001
    13     4.99999982e-001
    14     2.49999978e-001
    15     0.00000000e+000
    16     1.00000000e+000
    17     7.49999986e-001
    18     4.99999972e-001
    19     2.49999994e-001
    20     0.00000000e+000

 
Copyright © 1998-2016 Rachid Touzani