Energy Minimization for 2D Problems

After familiarizing yourself with the formulation, it is time to apply the knowledge to a practical example. This tutorial will go over varying penalization weights for a geometry in 2D.

Setup the genie object and initialize the B-spline

from lsdo_genie import Genie2D
from lsdo_genie.utils.geometric_shapes import Multi_circle
import numpy as np

num_surface_pts = 25
centers = [[-13.,-0.5],[-7.,2.],[2.,0.],[10.,-4.]]
radii = [2.,2.,4.,3.]
geom_shape = Multi_circle(centers,radii)
surface_points = geom_shape.surface_points(num_surface_pts)
surface_normals = geom_shape.unit_normals(num_surface_pts)
custom_domain = np.array([
    [-18.,18.],
    [-8.,8.]
])
genie = Genie2D(verbose=False)
genie.input_point_cloud(
    surface_points=surface_points,
    surface_normals=surface_normals,
)
genie.config(
    domain=custom_domain,
    max_control_points=30,
    min_ratio=0.75,
)
print("Initial B-spline error:")
genie.compute_errors()
Initial B-spline error:
Relative surface error: 
   Max: 4.873e-03
   RMS: 2.563e-03
Gradient error: 
   Max: 2.146e-01 
   RMS: 7.325e-02

Optimize with specific the penalization weights

After optimization, the error terms of the function will decrease, sometimes by multiple orders of magnitude.

genie.solve_energy_minimization(
    Ln=1e0,
    Lr=1e-4,
)
print(f"Time to solve: {genie.timetosolve:1.3f} seconds")
print("Optimized B-spline error:")
genie.compute_errors()
Time to solve:  0.013741899999999418
Optimized B-spline error:
Relative surface error: 
   Max: 5.594e-05
   RMS: 1.831e-05
Gradient error: 
   Max: 5.789e-03 
   RMS: 1.732e-03

Varying the penalization weights

The choice of penalization weights is purely empirical. It is recommended to try different weights to find the best for your geometric shape. You may check this by visualizing the B-spline and printing the error terms.

  • It is always recommended that \(\lambda_n>\lambda_r\).

for Ln in [1e2, 1e-2]:
    for Lr in [1e-2, 1e-6]:
        genie.solve_energy_minimization(
            Ln=Ln,
            Lr=Lr,
        )
        print(f"Ln={Ln:1.0e}, Lr={Lr:1.0e}")
        genie.visualize()
        genie.compute_errors()
        print("--------------------------")
Ln=1e+02, Lr=1e-02
../../../../_images/9c952bdf1d296d60dc594245d6ca33a92fc7a20d7aeb1a82d73ba337aae98114.png ../../../../_images/346f559064c7b5a1f67ff2b64183cbd0c519380f53d3cb091923965fc391f0b7.png ../../../../_images/57f4d5b219dfeeed52044c1e54066c30a0b0a89735b3f852f3261a1dab00727b.png
Relative surface error: 
   Max: 4.136e-04
   RMS: 8.656e-05
Gradient error: 
   Max: 5.513e-03 
   RMS: 1.592e-03
--------------------------
Ln=1e+02, Lr=1e-06
../../../../_images/90268356901e28456e27403163cbe8d7b24f39dd89010f72e535f95151fbbee7.png ../../../../_images/22375a3852ae8e2b7950c05a9260c38e78cbad9c489d203b9f996428d3a0aaa3.png ../../../../_images/d6d13a2c857d656604c1363df2432e2e458eb32e45657b7154f6332e9409ed93.png
Relative surface error: 
   Max: 4.272e-04
   RMS: 7.890e-05
Gradient error: 
   Max: 3.303e-03 
   RMS: 1.067e-03
--------------------------
Ln=1e-02, Lr=1e-02
../../../../_images/8d19401b0d392a6eee9e388594c2f0a67d0752ab462a426227e7063bcdeb4c2b.png ../../../../_images/feaf2095322a66298601b8beeb2e7b2d34d3d16cfd44ad9f9ba5292b6bb875c1.png ../../../../_images/f5a0ab90a0a95ae2c0dfba2ed2bcfb4e331815a80c990e559bff073d00d34dfc.png
Relative surface error: 
   Max: 1.015e-04
   RMS: 3.915e-05
Gradient error: 
   Max: 2.770e-01 
   RMS: 1.242e-01
--------------------------
Ln=1e-02, Lr=1e-06
../../../../_images/93fff7b0735b35dfd07e6211b9f12ccd68831d63fe27d8c7aeef07a8a25d1ed0.png ../../../../_images/ea166e2602b51d67ed6389a9c5de27e419e50080263fa6df0297038061f3583f.png ../../../../_images/a6b86ba46d7b00f2a21ea197e9afe2c231756d61c5627e75daf4548f404f1c44.png
Relative surface error: 
   Max: 2.487e-05
   RMS: 6.491e-06
Gradient error: 
   Max: 4.671e-03 
   RMS: 1.970e-03
--------------------------