Blending Hull Forms

Maxsurf provides a function to parametrically modify a design to a have a different length, draft or block coefficient. This maintains the same body shape, but alters the dimensions. Through Maxsurf Automation, we can do the opposite and alter a hull shape while maintaining the existing parameters.

Resources

The spreadsheet associated with this example is located in C:\Program Files\Maxsurf\Automation Samples\Maxsurf\Blending Hulls.xls or in the directory in which Maxsurf is installed. The example is based around the racing yacht hull form in C:\Program Files\Maxsurf\Sample Designs\SailingYachts\ AC hull_7Surface.msd.

Using the Example File

Opening up the spreadsheet shows three lists of coordinates, these are the control point locations for the original hull (yellow), the modified hull shape (green) and the blended hull (blue). The blended hull control point coordinates are proportional between the two other coordinate sets, in the ratio specified by the blending ratio (Cell C2), ranging from 0 to 1 (entirely modified shape, to entirely original shape)

Figure 16 The Blending Hulls Example Spreadsheet. The three columns of coordinates are control points for the two parent hulls (left) and the blended hull (right)

To create a blended hull form;

·   Load the design into Maxsurf if it is not already loaded, by clicking on the “Load Maxsurf Design” button.

·   Type in a blending ratio between 0 and 1 into Cell C2 (0 is a good starting point, to show the extreme shape)

·   Press enter or select another cell to finish editing cell C2

·   Select the “Generate Blended Hull” Button.

View the modified hull form in Maxsurf. Creating Hulls at the two extremes (0 and 1) gives the following two hull shapes

Figure 17 The two extremes for the blended hulls, Blending ratio 0 on the Left and blending ratio 1 on the Right

Code in the Example File

The majority of the code in this example has been described previously in this manual, so only the code regarding the blending of hulls will be described below.

 

Most of the work in this example takes place outside of Macros. The values for the blended hulls’ control points are calculated using formulas in the Excel cells (select one of the cells to see the formula). The control point data for the two parent hull forms has been manually inserted into Excel using cut and paste from Maxsurf’s control point’s window, this process could have been automated too.

 

The following code makes up the cmdMoveControlPoints_Click() procedure that is run when the “Generate Blended Hulls” command button is clicked. The code has been broken up and annotated throughout.

 

Sub cmdMoveControlPoints_Click()

    Dim NumRows As Long

    Dim NumCols As Long

    Dim TheSurf As Surface

 

    For i = 2 To msApp.Design.Surfaces.Count

        msApp.Design.Surfaces(i).Visible = False

    Next i

 

Turning all surfaces except the hull surface is a prelude to calculating the Hydrostatics. The hydrostatic data is calculated only on the visible surfaces.

 

 

    msApp.Design.Surfaces(1).ControlPointLimits NumRows, NumCols

    n = 9

    For R = 1 To NumRows

        For C = 1 To NumCols

            msApp.Design.Surfaces(1).SetControlPoint R, C, Cells(n, 8), Cells(n, 9), Cells(n, 10)

            n = n + 1

        Next C

    Next R

 

The section above sets the new control point locations, the first set of coordinates is in row 9, hence the n = 9 before the For Next statement. Each successive loop increases n by 1, to move to the next set of coordinates.

 

    msApp.Trimming = True

    msApp.Design.Hydrostatics.Transform Cells(4, 6), Cells(5, 6), Cells(6, 6), Cells(4, 3), 0.953, Cells(6, 3), Cells(5, 3), True, True, True, False, False

 

This method performs a parametric transformation on the hull; this ensures that the blended hull form has the same characteristics as the parent hulls. Trimming has been turned on so that the hydrostatics will not be not affected. The following statement calculates the new hull’s hydrostatics and stores them in column 13 (cells M10 to M34)

 

    msApp.Design.Hydrostatics.Calculate 1025, 0

 

    Cells(10, 13) = msApp.Design.Hydrostatics.Displacement

    Cells(11, 13) = msApp.Design.Hydrostatics.Volume

    Cells(12, 13) = msApp.Design.Hydrostatics.Draft

    Cells(13, 13) = msApp.Design.Hydrostatics.LWL

    Cells(14, 13) = msApp.Design.Hydrostatics.BeamWL

    Cells(15, 13) = msApp.Design.Hydrostatics.WSA

    Cells(16, 13) = msApp.Design.Hydrostatics.MaxCrossSectArea

    Cells(17, 13) = msApp.Design.Hydrostatics.WaterplaneArea

    Cells(18, 13) = msApp.Design.Hydrostatics.Cp

    Cells(19, 13) = msApp.Design.Hydrostatics.Cb

    Cells(20, 13) = msApp.Design.Hydrostatics.Cm

    Cells(21, 13) = msApp.Design.Hydrostatics.Cwp

    Cells(22, 13) = msApp.Design.Hydrostatics.LCB

    Cells(23, 13) = msApp.Design.Hydrostatics.LCF

    Cells(24, 13) = msApp.Design.Hydrostatics.KB

    Cells(25, 13) = msApp.Design.Hydrostatics.KG

    Cells(26, 13) = msApp.Design.Hydrostatics.BMt

    Cells(27, 13) = msApp.Design.Hydrostatics.BMl

    Cells(28, 13) = msApp.Design.Hydrostatics.GMt

    Cells(29, 13) = msApp.Design.Hydrostatics.GMl

    Cells(30, 13) = msApp.Design.Hydrostatics.KMt

    Cells(31, 13) = msApp.Design.Hydrostatics.KMl

    Cells(32, 13) = msApp.Design.Hydrostatics.ImmersedDepth

    Cells(33, 13) = msApp.Design.Hydrostatics.MTc

    Cells(34, 13) = msApp.Design.Hydrostatics.RM

   

    For i = 2 To msApp.Design.Surfaces.Count

        msApp.Design.Surfaces(i).Visible = True

    Next i

   

   

    msApp.Refresh

End Sub

 

This example shows some of the potential for refining and optimising a hull form. This process could easily be applied to other hull forms, giving the potential to perform non-parametric transformation, as well as parametric transformations.

Handling Errors

When writing any program it is a good practice to elegantly handle any errors that may arise during the execution of the code. When writing scripts in VBA the On Error command is used to specify the action to be taken when an error occurs.
In the subroutines presented above, the On Error command is used to specify that in the event of an error, execution of the script will be redirect to the label ErrorHandler. This label is at the very bottom of the subroutines and is followed by three lines of code that firstly determine if an error occurred and then report the error message to the user using the standard message box dialog. It is important to test for an error, as these lines will be executed whenever the subroutines are executed irrespective of whether an error occurred or not.