You are on page 1of 13

Hull Hydrostatic Calculations

Tutorial in Matlab
Version 7

JAKOB KUTTENKEULER

Stockholm 23 November 2014

Centre for Naval


Architecture

Hull Hydrostatic Calculations

This tutorial contains a set of exercises designed guide through the implementation,
validation and verification of numerical hydrostatic calculations in the Matlab environment.
The exercises guides the active reader though the basic implementation of sections and the
numerical representation to analyze hydrostatic properties through to similar calculations on
the full 3D hull. The exercises are in sequential order so that the reader simply starts at the
beginning and work through the exercises.

The aim and scope


The aim is to create a toolbox in the form of computer code with which you can perform basic
hydrostatic calculations on ship hulls, barges and virtually all other floating objects, here
called hull. The code will be based on the assumption of the possibility to subdivide the hull
in longitudinal sections as shown in Figure 1. The code you will produce has the potential to
handle mono-hulls as well as multi-hulls for all angles of heel and reasonable pitch angles.

Figure 1. An example of the numerical representation of the hull defined by


offset-points (marked as dots) which for clarity are joined by lines in the plot.
This binder deals with the hydrostatics of one arbitrary section of the hull.

The code is supposed to form the foundation on which special tailored analysis of equilibrium
of flotation can be build. As an example, all rule-based assessment of the stability is left out
but can easily be included.

Hull Hydrostatic Calculations

Getting started (a contract between you and me)


Before we get on with it, there are a few things to consider and rules to follow:
1. You need access to Matlab, get access to it by installation on your computer or
through an account in a computer classroom.
2. Agree on the definition of the global right-handed Cartezian coordinate
system shown in Figure 1, where x-coordinate has direction from stern to bow, y
from starboard to port and z from keel upwards. The degrees of freedom used in
this tutorial is roll (as positive rotation around x-axis), heave (translation along zaxis) and pitch (or trim, as positive rotation around y-axis). Note that as a
consequence positive trim thus equals nose down.
3. The water density is naturally a parameter that we can change. Unless specified
3
the density of water is here assumed to be 1000 kg/m .
4. As a rule, do not edit the scripts that I supply to help you, unless I ask you to.
The risk is that you mess things up ;-)
5. Agree on the principle that I ask you to generate code and to check your results
against mine. Moreover, you always need to take on a somewhat watchful
attitude to both your own and mine code and thus the results. By this I mean
that I want you to check results to find both bugs and limitations of your code. This
is your responsibility.
6. Keep things simple. The code I ask you to create will be short, typically not more
that 1-10 lines of code per task. If your code gets complicated you are most certain
on the wrong track J
7. Always do angular calculations in radians but when you display data to the user
degrees are preferable for clarity. All functional codes etc must be done in radians.
8. The term KG is sometimes used here in the sense and meaning of the vertical
coordinate of center of gravity above the x-axis.
9. The exercises will take you through many steps. Make sure to save copies of your
code so that you can see what you did and to make debugging easier.
10. Most
of
the
stuff
you
need
is
distributed
http://flygmac7.flyg.kth.se/~msy/msy_container/sd2707_innovation/

through

Hull Hydrostatic Calculations

2D Sections
The first step is to handle two-dimensional (2D) sections. By 2D section we here mean a
slice of the hull where no changes in properties occurs in the x-direction. We can thus in the
2D world express the hull as a cross section geometry and maybe a scalar value for the xextension. No pitch is thus considered here.
Fundamental calculations
We start by defining an example section to practice on before attacking a more complex hull.
For simplicity we use a rectangular section. The term section here refers to a length-wise
portion of a hull with assumed constant geometry. This means that all sections are treated as
prismatic with nicely cut front and back edges all in the y-z-plane. The code below defines the
section geometry completely where our assumption is that all offset-points (also called
nodes) are in the same y-z plane, i.e. having the same x coordinate.
offsets

= [-2 1 % [m] pairs of y,z coords defining the section


-2 -1
2 -1
2 1];

Exercise 1. Plot the section with dots at the offset-points and lines in between. Hint:
You can modify the prepared script plot_section.m if you like.
Exercise 2. Heel your section by use of the function heel_offsets (which you write)
which rotates your section offsets around the x-axis. Your call of the
function shall look like this:
heeled_offsets = heel_offsets(offsets,heel)
Hint: A simple matrix multiplication does the job pretty easily. Note: Make
sure that the rotation is done in the correct direction. A positive heel angle
will turn the ship clockwise when looking from behind. Plot your heeled
section. This is what I get when I heel the section +15.

Exercise 3. Compute and cut the submerged (wet) part of your section by using
the prepared function cut_wet_section which also have the
parameter zwl which defines the z-coordinate of the water surface. Your
call shall look like this
wet_offsets
= cut_wet_section(heeled_offsets,zwl)
Plot your wet section in the same plot as your heeled section. Hint: the
command hold on might be useful. In short, the function

Hull Hydrostatic Calculations

cut_wet_section loops through your offset points in sequence to


discover the intersection between the line between two offset points and
the horizontal waterline. If a cross section is found, an extra offset point is
created and the point in the air is omitted from the set of wet points.
When all offset points are looped through only the wet points remains. This
is what I get for +15 heel and zwl=0.1.

Exercise 4. Calculate the center of buoyancy CB and wet area Aw for the
submerged part of your section by using the prepared functions as shown
here:
CB_global
= polygonCentroid(wet_offsets)
Aw
= abs(polygonArea(wet_offsets))
Note that polygonArea calcs the signed area!! Read the script header.
I get CB=[-0.2079, -0.4749] and Aw=4.4141.
Exercise 5. Add the position of CB to your plot.
Exercise 6. Verify CB and AW. Play around with the powerful tool you just created
and e.g. verify that you get the same results as I do:
Case
Heel
Zwl
CB y/z
Aw
2
[deg]
[m]
[m]
[m ]
1
0
0.0
0.0000/-0.5000
4.0000
2
5
0.1
-0.0668/-0.4527
4.4015
3
10
-0.1
-0.1661/-0.5651
3.5938
4
15
0.0
-0.2281/-0.5292
4.0000
Exercise 7. Are there any limitations regarding the heel angle or are you capable of
calculating the hydrostatics for all heel angles [- to ]?
Exercise 8. Investigate how your code reacts inputs where the waterline is at
extreme values, i.e. when your section is 100% out of water and 100%
submerged. Does everything work?
Exercise 9. Verify that the center of buoyancy CB is calculated correctly for
various combinations of zwl and heel.

Hull Hydrostatic Calculations

Draught, or actually the waterline height zwl


By now you already have a lot of the fundamentals to do some useful calculations. I will now
help you through the process of finding the equilibrium in flotation by studying the vertical
degree of freedom. Basically we simply match the mass m of the hull (or section) to the
displaced mass by changing the parameter zwl. Since we must calculate displacement we
need to introduce the section length dL (=x-wise extension).
Exercise 10. Add the concept of vertical equilibrium to your code to calculate the
section draught. To do this we first need to do is to a new function which
you call residual_2D_H (H for Heave degree of freedom) which shall be
called
upon
according
to
the
following
Res_H=residual_2D_H(zwl,offsets,heel,m,dL) the output H is
the residual expressed in vertical mass, i.e. difference in mass
displacement and mass. Also, for reasons of conditioning I want you to
normalize the mass residual with the mass itself. Create the function and
play around with your function until you are fairly certain that it works ok.
By playing around I mean guess zwl to find the equilibrium H=0. Also, do
this for different heel. Do not forget to plot your results using the
plot_section. Note that what choose to move the waterline in contrast to
the possibility to move the section vertically. Do you object?
Exercise 11. Automate the calculation of equilibrium zwl by the use of a numerical
solver. So far you have guessed the position of the waterline zwl. The
objective function to be minimized is already defined in the earlier task so
now we only need to hook on a numerical search scheme. I suggest the
Matlab build in function fsolve. Lern what fsolve does (e.g. type help
fsolve) and try to implement a solver using it on your function
residual_2D_H. Note that since your objective function i parametrized
(i.e. uses more input parameters than the free parameter zwl) we must use
the matlab strategy of @ to indicate which is the problem-dependent
parameter. Thus, your call might look like this:
zwl=fsolve(@(zwl)residual_2D_H(zwl,offsets,heel,m,dL),[0.1]).

Verify your automation by several tests. Is strange initial guesses a


problem? Does your code handle various heel angles ok?
Exercise 12. Introduce a new V-shaped section geometry according to:

offsets = [-2.0,
-1.7.
0.0,
1.7,
2.0,

1.5
0.5
0.0
0.5
1.5];

Play around and get confident with your search for zwl. I get that the
equilibrium zwl for the V-shaped section with m=3000kg, heel=10 and
dL=2.0m is zwl= 0.6656m, do you agree? Do not forget to plot!

Hull Hydrostatic Calculations

Transverse stability
So far we have been studying the single degree of freedom of vertical equilibrium, the heel
has been locked. Now we (you that is :-) will add the degree of freedom of heel in the
calculations. As we add a degree of freedom in the model we need to also add an equation to
solve the problem. This new equation is naturally the issue of transverse stability. Transverse
stability can be expressed as the restoring (rightning) moment created by the transverse
distance between the two forces active. All you need to do to is thus to keep track of the
center of buoyancy (CB which you already have in your code) and center of gravity (CG) of
the section itself actually dead simple. Just remember that the center of gravity moves
when section is rotated. In your main program do the following:
Exercise 13. Learn to calculate the new position of CG after heel in the global
coordinate system as function of heel angle (called CG_global). Plot the
position of CG in the graph of the heeled section as a visual verification. To
do this, you assume the center of gravity CG (in the un-heeled condition) is
given by the transverse center of gravity TCG and vertical center of gravity
above keel KG in the hull-fixed un-healed local coordinate system.
Exercise 14. Add the calculation of the restoring lever arm, called GZ (i.e. horizontal
(y-wise) distance between CB and CG in global coords) for your section.
After calculating the equilibrium zwl for the V-shaped section with
m=3000kg, heel=10 and dL=2.0m, TCG=-0.1 and KG=1.2 m I get zwl=
0.6656m and GZ= 0.1798m, do you agree? When I change to heel= 20 I
get zwl= 0.5699m and GZ= 0.3530m, you too? When I change to
heel= -20 I get zwl= 0.5699m and GZ= -0.5410m, you too? Plot your
results. Is it sound that GZ differs between the cases of heel= 20 and
heel= -20?
Exercise 15. Plot the curve of GZ as function of heel in the interval [-50,50]. Use
your 1D automated calculation of zwl (residual_2D_H) to ensure that all
plotted GZ corresponds to a section in vertical equilibrium. For V-shaped
section with m=3000, dL=2.0, TCG=-0.1, KG=1.2 I get the following plot,
do you agree?

Hull Hydrostatic Calculations

Exercise 16. Add the heel degree of freedom to your equilibrium-calculations by


creating a new residual function with both vertical and heel degrees of
freedom. The idea is to solve a set of two equations using two free
variables. The equations to solve are 1) vertical force=0 and 2) GZ=0. The
free variables are correspondingly the zwl and heel. Thus we create a new
function with the name residual_2D_HR, where HR is short for
Heave&Roll. Hint: Using the same technique as above with the fsolve
function Matlab now in the 2D case requires us to define the input and
output as vectors instead of scalars. Thus, define the input as the array
zwl_heel, which contains two elements, for zwl and heel respectively. In
the same way the function output, now called H_R will contain the
residuals from the two equations to solve. The call of the function shall thus
look like this:
Res_H_R = residual_2D_HR(zwl_heel,offsets,m,dL,TCG,KG)
When I run it with for the V-shaped section with m=3000, dL=2.0,
TCG=-0.1, KG=1.2, zwl_heel=[0.5 15*pi/180] as indata I get
Res_H_R=[ -0.2553 0.3125], you too?
Exercise 17. Automate the calculation of equilibrium zwl & heel by the use of a
numerical solver, fsolve just in the same way as you did earlier but now
you use residual_2D_HR. You call might thus look like:
zwl_heel=fsolve(@(zwl_heel)
residual_2D_HR(zwl_heel,offsets,m,dL,TCG,KG),[0.2,0])
Play around with your calculations and verify that I got the right results for
m=3000,
dL=2.0,
TCG=-0.1,
KG=1.2,
I get zwl_heel =[0.6859 0.0602].
Hint: You may want to think about what a good value is for the starting
guess of zwl & heel, above set to [0.2,0].
Exercise 18. Verify your automation by several tests. Is strange initial guesses a
problem? What are the limitations of your code?
Exercise 19. Reproduce the milk box experiments you did in real life. Produce the
same curves as in your water experiment and compare and reflect on your
results.

Hull Hydrostatic Calculations

3D Hulls
So far we have probably been occupied with the 2D problems in the form of single sections.
Now we will take the step into the world of 3D so that we can calculate the hydrostatics of a
full hull with shapes changing with x-coordinate. The code will build on what you did earlier.
There are some things to consider though. For example we need to load geometries from file
and we need to include the third degree of freedom, trim (rotation around y-axis). Let me
guide you J
Exercise 1. Start with a new empty Matlab script to not mess up your earlier 2D code
now when we need to make some changes.
Exercise 2. Read hull geometries from file. I have prepared a script that loads the hull
geometry from Britfair type file formats. The Britfair format is basically a
structured syntax storing sectional offsets in a text file, see appendix A for
more details. Right now you do not have to worry about the format, just run
the
script
by
typing
in
this
command
[sections,name]=Read_Britfair('AxelJohnson.bri'); which
loads the geometry of the container ship hull called AxelJohnsson. You now
got two data variables, sections and name. Lets have a look at the variable
sections. If you first type sections in the Matlab command line you will see
that this is an array of structured variables called section. This simply
means that if you type sections(1) you get the first of the 19 sections in
sections. You also saw that the structured variable section contains 2
variables, x and offsets. x is simply the x-location of the section and offsets
is the y & z coordinates of the section. Thus, you can look at the offset
points of section #5 by typing sections(5).offsets. You can also create a
list of the x-coordinates of all sections by typing [sections.x].
Exercise 3. Plot all sections of the hull in one plot by looping through all sections
and using the line line plot_section(sections(ii).offsets),
where ii is the counter.
Exercise 4. Plot the entire hull in 3D with heel by calling the script plotHull.m. Try
feeding the plotHull function with a heel angle. Use your old function
heel_offsets.m.
Exercise 5. Plot the entire hull in 3D with trim by feeding the function plotHull.m
with a trim angle It crashes right?! It looks like you need to create a
function (trimming one section) with the following call
trimmed_offsets = trim_offsets(heeled_offsets,x,trim);
where x is the x-coordinate of the section and trim is the trim angle. Hint:
Implement the trim as a rotation around the y-axis at x=0 and assume small
trim angles by only letting the trim subroutine only affect the z-coordinates
of the sections. Thus, x and y coordinates are to be left as before. Also, if
this function contains more than 4 lines of code you are likely on the wrong
track Remember that positive trim should be nose-down according to our
definition of coordinate system.

Hull Hydrostatic Calculations

Exercise 6. Calculate the wet area and CB of each sections by looping through the
sections and use your old known functions by adding the following lines
wet_offsets
= cut_wet_section(trimmed_offsets,zwl);
Aw(isec)
= polygonArea(wet_offsets);
CB_global(isec,:) = polygonCentroid(wet_offsets);

which will produce vectors with data you need. Reflect on your results.
Exercise 7. Secure the situation where Aw=0. The problem here is that the function
polygonCentroid has problems when Aw(isec)=0. You can solve this with
a conditional if-statement that sets CB_global(isec) = [0 0] if Aw=0,
Exercise 8. Calculate the total displacement V by summing up (integrating) the
section displacements. The hint is to use trapezoidal numerical integration
by using the matlab function trapz on the vectors of sectional xcoordinates and wet areas Aw. When I use zwl=8m, heel = 10 and trim =
2, I get Aw = [0.6373 5.7032 28.8845 61.1443 100.9885 142.2518
215.0586 248.1260 266.7087 248.8315 203.0536 139.8171 108.7790
77.6559 50.3250 30.4761 9.2519 2.0492 0] and V =2.5618e+04. Do you
agree?
Exercise 9. Calculate the LCB, TCB and KB in global coordinates. Each calculation is
most easilly written as a one-liner using the trapz-command for trapezoidal
integration. I used the following lines to calculate the displacement and the
LCB:
V = trapz(x,Aw); LCB = trapz(x,x.*Aw)/V
When I use zwl=8m, heel = 10 and trim = 2, I get
CB_global = [80.1127 -2.0951 3.3066]. Do you agree? Hint: If
you have problems with the KB (the third position of CB_global) then you
might have forgotten the effect of the trim angle
Exercise 10. Transform CG from local to global cords in two steps (one line each).
First you heel the local CG and calculate the vector CG_heeled, then you
trim the ship to calculate the vector CG_global. When I test-run with the
CG_local = [65,0.3,10], trim=2 and heel = 10 as an example I get
CG_global=[ 65.0000 -1.4410 7.6317]. Do you agree?
Exercise 11. Calculate the residuals in 3D, by adding 3 lines looking like this
jmv
gz_transverse
gz_longitudinal

= (rho*V-m)/m;
% [-]
= CB_global(2)-CG_global(2); % [m]
= CB_global(1)-CG(1);
% [m]

where jmv describes the non-dimensional difference between the


gravitational and buoyant forces and the gz:s describe the rightning arms in
around the x and y axes. For m= 14700000kg and CG_local = [65, 0.3, 10];
I get jmv_gzt_gzl =[0.7427 -0.6541 15.1127]. Do you agree?
Exercise 12. Create a function for the residuals in 3D by using the code you just
created. The call shall look like this
jmv_gzt_gzl=residual_3DOF(zwl_heel_trim,sections,m,CG_local)

which naturally shall produce exact the same results as in the previous
excercise. This function shall contain around 60 lines of code, not much
more.

10

Hull Hydrostatic Calculations

Exercise 13. Use residual_3DOF to manually find the equilibrium flotation for
m=14700000kg and CG_local = [65, 0.3, 10] by playing around with the
input. Easy?
Exercise 14. Use fsolve to automize the search for equilibrium flotation using your
residual_3DOF function. The call shall be a one-liner looking like this
zwl_heel_trim=fsolve(@(zwl_heel_trim)residual_3DOF(zwl_heel_tr
im,sections,m,CG_local),[2,0.0,0.0]). Make sure that fsolve

converges and produces residuals that are close to zero. For


m=14700000kg and CG_local = [65, 0.3, 10] I get the equilibrium solution
zwl=9.76, heel= -7.00 and trim= -2.28.
Exercise 15. Plot the hull at equilibrium heel & trim.
Well done J

11

Hull Hydrostatic Calculations

Appendix A: Short introduction to the Britfair format for hull definition


The Britfair is a fairly powerful, yet straight forward hull geometry definition data format. This document
briefly explains the most basic data format for the definition of sequential sections forming a hull. When
you create your hull keep in mind that:

Data separation is usually done using blanks (mellanslag) and not tab.

The coordinate system is defined as x being the length coordinate from stern to bow, y is positive
to port and z from keel upwards, usually with the hull lower point as z=0. For sailboats, usually the
lowest point of the canoe-body is used as z=0.

Define the sections in sequence starting with the aft-most section.

Define each section with the offset points sequentially starting at the keel and then in counterclockwise direction.

You only need to define the right (starboard) side of the hull if the hull is symmetric.

You shall save your file as an ASCII text file with extension .txt or .bri (not .doc or similar).
The following is an example of a Britfair file with explanations:
File content :

Explanation :

Britta
1
8
-4.42
-4.42
0.00
0.00
0.04
0.00
0.04
9.20
3.52
9.88
6.28
10.68
8.84
12.08
10.32
13.76
11.12
16.24
0
11
0
0
0.00
0.00
0.16
0.00
0.24
5.00
0.56
7.20
1.40
8.12
2.68
8.72
6.52
10.04
8.76
11.16
10.52
12.76
11.56
14.60
11.96
16.20
0
...
...
...
...
0
8
162
162
0.0
3.5
0.0
4.0
0.0
6.0
0.0
8.0
0.0
10.0
0.0
12.0
0.0
14.0
1.0
16.44
0
0
0
0

Arbitrary hull name.


Start of section 1 definition it has to be here, just accept that J
No of section offsets
section x-coord.
section x-coord.
y z
y z
y z
etc ....

S
E
C
T
I
O
N
1

End of section 1.
No of section offsets
y z
y z
etc ...

section x-coord.

section x-coord.
S
E
C
T
I
O
N
2

End of section 2.
Section nr 3
etc...
...
...
End of section xx.
No of section offsets
y z
y z
osv...

E
T
C
section x-coord.

section x-coord.

S
E
C
T
I
O
N
n

End of section
End of file indicator.

12

Hull Hydrostatic Calculations

13

You might also like