#of 7 control vertices in 2D.
#Find a set of 7 starting values in x:
ini_x_values = [x1,x2,x3,x4,x5,x6,x7]
#Find a set of 7 starting values in y:
ini_y_values = [y1,y2,y3,y4,y5,y6,y7]
Imatrix = np.identity(N) # the NumPy identity matrix encodes the gradient.
xlist = [] # initialize storage for the AD variables in the X direction
ylist = [] # initialize storage for the AD variables in the y direction
# Give each AD variable a valid gradient, a vector
# linearly independent from the rest
# and a valid hessian matrix, of null values.
for i, val in enumerate(ini_x_values): xlist.append(AD(value = val,
grad = np.matrix(Imatrix[i]),
hess = np.matrix(np.zeros((N,N),float) )))
# Importantly, the gradient of the y variables continues where #
pos = i
for i, val in enumerate(ini_y_values): j = i + pos
ylist.append(AD(value = val,
grad = np.matrix(Imatrix[j]),
hess = np.matrix(np.zeros((N,N),float) )))
# we may ustilize NumPy’s dot product if we store the
# lists above as NumPy arrays:
Vx = np.asarray(xlist) Vy = np.asarray(ylist)
The pseudo-code shown in Listing 5.3 demonstrates how AD objects representing B-spline control vertices are arranged into NumPy arrays for use in B-spline computations. Computing the dot product result in an AD object with the value, gradient, and Hessian of the B-spline curve with respect to it’s control vertices, exactly.
As noted above, the basis functions may be pre-computed and stored for a set of parameter values
NumPy array. Let’s assumet= 0.5for this example. For a cubic B-spline basis forn+ 1 = 7vertices, NumPy produces the following real valued vector.
Nk(0.5) = 0. 0. 0.16666667 0.66666667 0.16666667 0. 0.
Each component represents the value of a basis function att= 0.5.
Equations (5.4) show what the AD routine actually computes when it evaluates the expression
n
P
i=0
component of the curve: qx = n X i=0 xiNi,k(t) = vTxNk(t) (5.4a)
qx.value = equivalent to standard B-spline evaluation (5.4b)
qx.grad = 0. 0. 0.16666667 0.66666667 0.16666667 0. 0. 0. 0. 0. 0. 0. 0. 0. (5.4c)
qx.hess = Null square matrix (5.4d)
For they-component we take the dot product ofVy withNk.
B-splines are linear with respect to the vertex coordinates. Therefore the partial derivatives with respect to the vertex coordinates (free variables in the augmented Lagrangian function) return the B-spline function values as is evident in Equation (5.4c) above. The first seven components of the gradient are for the derivatives with respect to thex-coordinates of the vertices, and the remaining seven components are for the derivatives
with respect to they-coordinates which of course do not play a role inqx. Since the first order derivatives are
constants, the Hessian is a[14×14]null matrix.
In the actual form parameter design, gradients and Hessians will also include the derivatives with respect to the Lagrangian multipliers and the slack variables. It should also be emphasized that the parametric derivatives of the basis functions which are needed for the computation of tangents, curvature, area, etc. are computed with de Boor’s B-spline differentiation algorithm [24]. With our AD class in hand, we will now apply it to the design of B-spline curves.
Chapter 6
Automatic Differentiation of B-splines
This section explains how the automatic differentiation (AD) of Section 5 is tied together with Lagrangian B-spline optimization outlined in Section 4 into the solution of form parameter driven curve design problems. We must account for curve initialization, design variable instantiation for AD, computation of the Lagrangian functional and its derivatives, and the Newton-type iteration with convergence checking which solves the necessary condition for a minimum of the Lagrangian functional. The end result is a fair B-spline curve that satisfies the desired form parameters. The five steps are outlined below.
The augmented fairness functional (4.22) must be differentiated twice with respect to all design variables and Lagrange multipliers. Fortunately, most of the tedious programming work is actually taken care of by the formulation of the AD class (Section 5). Again, more efficient and more general implementations are possible [87]. However, with only first and second order derivatives needed and the comparatively small numberN of unknowns the tool developed here is adequate for our curve design purposes.
1. Initial curve design:
Iterative solution of the generally nonlinear necessary condition for a minimum of the Lagrangian functional requires an initial solution. This suitable initial curve need not satisfy all constraints but should represent a “good guess” at fulfilling the form parameters. The initial curve, however it is generated, is built with standardn+ 1B-spline control verticesVi = (xi, yi)T withi= 0,1,2, . . . , n.
We use the method proposed by Harries [52] to create an initial set of control vertices from form parameters within the curve solver.1 Additionally, we solve a Lagrangian functional for a curve with some of the constraints, and then add additional constraints to produce a more complex form. This 1Note this is distinct from the greater scope of this thesis - where we will be using other (logical, interval) methods to generate the target form parameters themselves.
second method is particularly useful after adding new constraints to the optimization problem. 2. Instantiation of design variables(xi, yi)and Lagrange multipliersλiin AD:
Instantiation proceeds much as in Listing 5.3, with some simple changes to accommodate the Lagrange multipliers and structure of the problem. For our purposes, the solution vectorz(4.24) will contain
first all thexi-coordinates of vertices, then all theyi-coordinates of vertices, and finally all of the mLagrange multipliersλi. Note that the first and last vertexV0andVnare known from the form
parameters and do therefore not appear in the solution vectorz. The dimension of the solution vector
is
N = 2(n−1) + m (6.1)
Instantiation starts with the creation ofN objects of theADclass. The objects are collected into a NumPy array z0. Actual values are taken from the initial control point vertices and Lagrange
multipliers of constraints are set equal to one. The gradient of each solution variablezjcorresponds to
the respective row vectorjin an identity matrixIof size[N×N]. The Hessians are matrices of size [N ×N]which are set to zero.
3. Computation of augmented fairness functional (4.22):
With variables instantiated, the stage is set to compute the automatic differentiated fairness functional of choice. All components making up the functional, from solution variable to functions used, are objects of typeAD. Consequently, the functional valueF(zk)is accompanied by its gradient∇F(zk) and Hessian matrixH F(zk)
. No additional steps are necessary to compute gradient or Hessian ofF.
4. Newton update:
Based on the Newton iteration (4.26) an updated solutionz1is derived. This involves inversion of the Hessian matrix which is accomplished with standard linear algebra algorithms for matrix inversion. Now steps 3 and 4 are repeated, increasing the iteration counterk= 1,2, . . . until the`2-norm of the
gradient of the Lagrangian functionalc=∇F becomes smaller than a pre-defined, small toleranceε.
`2(c) ≡ |c| ≡ v u u t N X j=1 |cj|2 < ε (6.2)
The final solution vectorzis assumed2to minimize the Lagrangian functionalF. Its vertex coordinates
define a B-spline curve which is fair and satisfies the form parameters defined by the user.
2We assume we have a minimum. All we know is that we have a critical point. We could check second order sufficiency criteria but in practice for ship hull design, we only care about whether or not the geometry matches with our engineering purpose. That is what we will check, e.g. does it meet the constraints, are the curves sensible, etc.
Chapter 7
B-spline Curve Design Examples
Some examples shall demonstrate the utility of an AD Lagrangian curve optimization algorithm with regards to curve design for ship hull forms. For complicated curves, best results have been obtained by starting with a reduced number of constraints, initialized via the method of Harris in [52], and progressively adding constraints to the initial curve solution until the desired result is reached. In this way, more complicated curve forms could be built without experiencing solver divergence. Please note that in all examples, fairness functions and approximate arc length function are scaled by a factor of0.5. The fairness pseudo-normsE1, E2,E3, and the approximate arc length function described in section 4 are used throughout the following
examples. No attempt was made to search for optimal scaling values of these functions, as the purpose of the AD sections of this thesis is to describe how AD makes the optimization framework simple to construct, and not to find any particular optimal result. Nevertheless, the examples below are important as demonstrators of the utility and success of the methods outlined in the earlier sections of this paper. As mentioned earlier, knot vectors will be fixed so that the curve is endpoint interpolating, with uniform knot intervals on the interior of the knot vector. In this way the effect of control point manipulation will never be pitted against knot vector transformation within the optimization loop. This increase in efficiency comes at the expense of forcing the algorithm to enforce continuity conditions in explicit geometric form as tangents, curvature and position. Fortunately this is what we typically want as naval architects - as ship hull designers. Continuity is important, especially at the boundaries between curves, but it is often better described in geometric constraint terms within the curves. Then computational procedures outside of the optimization loop can be used to stitch curves together, or split them apart, if need be.
As a first example we present the design of a sectional area curve (SAC) of a ship. The sectional area curve describes the volume distribution over the length of the ship. The SAC curves presented below are
Figure 7.1: initial SAC curve
single B-spline curves. This “single curve” method is a departure from common practice where a SAC curve is created by subdividing the curve into a number of sections and solving for them separately. In the past, this has been done in order to allow local constraints, such as tangent and curvature, to be set at intermediate locations along the length of the SAC curve. However, subdivision of the SAC curve adds to the complexity of enforcing global hull properties. Our solver allows for specifying tangent and curvature constraints at any location along the length of the curve, eliminating the need to split SAC into multiple segments in this instance.
SAC Design and Optimization
For the design of a sectional area curve (SAC), sometimes a smoothly curving (C2 continuous) form is desired, as with say, a classic sailing yacht, or a simple vessel such as a canoe body, and other times a curve with a flat midsection (parallel mid-body) SAC produces the best compromise between production efficiency and fairness of the ship hull itself. Note that the SAC defines the area of a transverse slice of the hull form at any section. Accordingly, the smoothness of the SAC translates into smoothness of volume variation in the actual hull.
In Figure 7.1, a simple SAC curve is designed by form parameter optimization. Constraints are set for area,A, moment,Xc, and starting and ending tangent anglesαBandαE. Note also thatqxandqy denote
curve interpolation constraints in this figure. Such interpolation constraints allow for specific hull features, such as flat of side (this term refers to an portion of the vessel with straight sides parallel to the its centerline),
(a) mid section enforced flat of side
(b) x centroid of area is shifted left. Figure 7.2: SAC curve development
to be implemented between particular points chosen along the hull. Interpolation form parameters can also have an effect on the details of the area distribution. Form parameters for this plot are given in Table 7.1.
In Figure 7.2a, the SAC curve in Figure 7.1 was modified to incorporate a flat mid section with a certain longitudinal center of area,Xc, as well as to have zero curvature at the end points. Note that curvature spines
are shown in this plot scaled up by a factor of 3.5. Form parameters for this plot are given in Table 7.2. In Figure 7.2b, the SAC curve in Figure 7.2a was modified by shifting the center of area while holding all other form parameters constant. This had a significant impact on the curvature. As prescribed, it is zero at the endpoints, but in transition areas, it increases to amounts that are greater than those seen in Figure 7.2a. Here it is again scaled by a factor of 3.5 for visibility. Form parameters for this plot are given in Table 7.3.
Form parameters of initial SAC curve
Target Actual ∆ Form Parameter Symbol Value(1) Value(2) (2)−(1)
h1 Area of SAC curve, (Volume of Ship) A 288.0 288.0 0.0
h2 LCB (Longitudinal Center of Buoyancy), xc 18.0 18.0 0.0
h3 Tangent of Entrance αB 0.0 0.0 0.0
h4 Tangent of Run αE 0.0 0.0 0.0
h5 Curve y Interpolation Constraint qy1 12.0 12.0 0.0
h6 Curve y Interpolation Constraint qy2 12.0 12.0 0.0 Table 7.1: Form parameters of initial SAC curve, Figure (7.1)
Form parameters of SAC curve with flat portion
Target Actual ∆ Form Parameter Symbol Value(1) Value(2) (2)−(1)
h1 Area of SAC curve, (Volume of Ship) A 288.0 288.0 0.0
h2 LCB (Longitudinal Center of Buoyancy), xc 18.0 18.0 0.0
h3 Tangent of Entrance αB 0.0 0.0 0.0
h4 Tangent of Run αE 0.0 0.0 0.0
h5 Curve x Interpolation Constraint qx1 12.0 12.0 0.0
h6 Curve x Interpolation Constraint qx2 24.0 24.0 0.0
h7 Curve y Interpolation Constraint qy1 12.0 12.0 0.0
h8 Curve y Interpolation Constraint qy2 12.0 12.0 0.0
h9 Curvature of Entrance, cB 0.0 0.0 0.0 h10 Curvature of Run, cE 0.0 0.0 0.0 h11 Tangent atqy1 α1 0.0 0.0 0.0 h12 Tangent atqy2 α2 0.0 0.0 0.0 h13 Curvature atqy1 , c1 0.0 0.0 0.0 h14 Curvature atqy2 , c2 0.0 0.0 0.0 Table 7.2: Form parameters of SAC curve with flat portion
Form parameters SAC curve with flat portion and centroid of area shifted
Target Actual ∆ Form Parameter Symbol Value(1) Value(2) (2)−(1)
h1 Area of SAC curve, (Volume of Ship) A 288.0 288.0 0.0
h2 LCB (Longitudinal Center of Buoyancy), xc 16.0 16.0 0.0
h3 Tangent of Entrance αB 0.0 0.0 0.0
h4 Tangent of Run αE 0.0 0.0 0.0
h5 Curve x Interpolation Constraint qx1 12.0 12.0 0.0
h6 Curve x Interpolation Constraint qx2 24.0 24.0 0.0
h7 Curve y Interpolation Constraint qy1 12.0 12.0 0.0
h8 Curve y Interpolation Constraint qy2 12.0 12.0 0.0
h9 Curvature of Entrance, cB 0.0 0.0 0.0 h10 Curvature of Run, cE 0.0 0.0 0.0 h11 Tangent atqy1 α1 0.0 0.0 0.0 h12 Tangent atqy2 α2 0.0 0.0 0.0 h13 Curvature atqy1 , c1 0.0 0.0 0.0 h14 Curvature atqy2 , c2 0.0 0.0 0.0 Table 7.3: Form parameters of SAC curve with flat portion. Centroid of area shifted.
moments of various sections to ensure that the overall curve had the total area and moment desired. Instead, the curve is specified to have a flat section, area, and moment all at the same time, and the solver is able to find the solution.
Design of a Stern Profile Curve
To show some of the complicated geometries that can be developed with the optimization framework given here, in Figure 7.3 the design of the run profile of a container ship is given. In particular, relative constraints are used. These are employed to enforce a relative offset between two control points. Other geometric relations might be imagined in the future.
The shaded area is specified by the area constraint. The stern shape shown in Figure 7.3, is modeled as a single curve, including the flat section where the propeller shaft pierces the hull and the hard cusp in the upper section of the curve. Again, the technique of starting with a simple curve and adding more constraints to previously solved curves is performed. The initial curve is a straight line through the endpoints. The solver required two passes to attain the curve shown here.
The first pass incorporated the cusp atK0 and starting and ending tangency conditions. In Table 7.4, these are the first three form parameters listed. The second pass added the area constraint, tangency angle on
Figure 7.3: Run Profile (This is a single B-spline curve). Note the relative constraints,r1,r2, andr3, as well as the particular cusps,k1 andk2, which enforce user chosen geometry while allowing the local assembly to remain free to move relative to the rest of the control points.
the interior of the curve, and all additional relative constraints and cusps. These are form parameters four through twelve in Table 7.4. In general more passes are sometimes needed when the geometry requirements are more numerous. This can require a bit of trial and error which might be eliminated with a higher level optimization framework that will be the topic of future research. Such an optimization framework would again use optimization to determine the best combination of geometry constraints to develop a given shape, or to find optimum shapes for a given design purpose. That is, a higher level optimization framework is one that optimizes the inputs (in this case form parameters) to a lower level framework.
The propeller hub could be designed in numerous ways. In this case, constraint h10 fixes the lateral distance from the preceding control vertex, and the second hub cusp is specified to have a vertical offset below the initial cusp. Additional constraintsh8andh9are imposed to show how the whole system of hub
Form Parameters of the run profile curve
Target Actual ∆ Form Parameter Symbol Value(1) Value(2) (2)−(1)
h1 tangent angle at start, αb -90.0 -90.0 0.0
h2 tangent angle at end, αe 0.0 0.0 0.0 h3 first knuckle, k0 (10.0,0.) (10.0,0.) 0.0
h4 Area shown in green, A 120.0 120.0 0.0
h5 tangent angle after first knuckle, α1 0.0 0.0 0.0
h6 second knuckle, k1 free free 0.0
h7 third knuckle, k2 free free 0.0 Relative Form Parameters Below
h8 x6−x5 r1 0.0 0.0 0.0
h9 y6−y5 r1 3.0 3.0 0.0
h10 x7−x6 r2 4.0 4.0 0.0
h11 x10−x7 r3 0.0 0.0 0.0
h12 y10−y7 r3 2.0 2.0 0.0
Table 7.4: Relative form parameters allow the solver a prescribed amount of freedom to position the stern