|
Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
|
This example demonstrates the use of NEKO-TOP with the Method of Moving Asymptotes (MMA) to solve a simple unconstrained optimization problem on a 3D field design. For this example, we read a simple mesh file (box.nmsh)—typically a spectral element mesh for a box generated by the genmeshbox tool in Neko.
In the driver.f90 file, the distribution of a scalar field in the mesh is defined as the design field (des) using the simplefield_design_t type.
Note: The design variables are defined at every GLL point in the mesh.
Each GLL node has one design variable associated with it, so the total number of design variables equals the number of GLL points in the mesh.
The simplefield_design_t has four vectors:
These represent the design variable value, and the x-, y-, and z-coordinates of its corresponding GLL point. All four vectors have a length equal to the total number of GLL points in the mesh. For simplicity, in this file, we use des.values instead of des.values.x. (Please check the vector_t description in Neko)
Minimize the mean squared difference between the design variable at each mesh node and the node’s physical coordinate:
\[ f(\mathbf{x}) = \frac{1}{n} \sum_{j=1}^{n} \big(\texttt{des.values}(j) - \texttt{des.x}(j)\big)^2 \]
where:
The sensitivity (gradient) of the objective with respect to each design variable, assuming \([d_1, d_2, \ldots, d_n]\) denote the vector of design variables, is:
\[ \frac{\partial f}{\partial d_j} = \frac{2}{n} \left( \texttt{des.values}(j) - \texttt{des.x}(j) \right) \]
None (unconstrained problem).
The full optimization problem can be stated as:
\[ \begin{aligned} &\min \frac{1}{n} \sum_{j=1}^n (d_j - x_j)^2, \ & d_j \in [\texttt{xmin}, \texttt{xmax}], \quad j=1,\ldots,n, \end{aligned} \]
where:
Since the objective is minimized when the design field matches the x-coordinates, the expected optimal solution is:
\[ d_j = x_j, \quad \forall j=1,\ldots,n \]
If the mesh $x$-coordinates exceed the design variable bounds "xmin": 0.0 and "xmax": 5.0, the optimizer will cap the design variables accordingly.
driver.f90: Main program that sets up and runs the optimization problem.example_problem.f90: Contains custom definition for the objective function and sensitivity.box.nmsh: Mesh file defining the spectral element grid.The mesh file box.nmsh can be generated using the mesh.sh script with the following syntax:
For detailed usage, refer to the mesh.sh documentation in the Neko-top repository.
A quick example of how to use mesh.sh:
This creates a 3D box mesh with:
x = 0–10, y = 0–1, z = 0–164 elements along x, 4 along y, and 4 along zThe output mesh is saved at:
Ensure the environment is correctly set up before running the script. Typically, this can be done by creating a prepare.env file in the main directory of Neko-top to configure the necessary dependency paths for mesh.sh: