Example #1
0
 # Plot equilibrium scene
 angles = np.array([phi,theta,0])
 position = np.array([0.,0.,dz])
 cgPos_e = cgZ+position
 plot.plot_scene(shape,w,angles,position,cgPos_e)
 # ax = plt.gca()
 #ax.elev = 90
 #ax.azim = 0
 if not NOT_CONTOURS:
     xs = np.linspace(-1,1,51)
     ys = np.linspace(-1,1,51)
     ycs = np.zeros((51,51))
     zcs = np.zeros((51,51))
     for i,x in enumerate(xs):
         cs = geo.cross_section(shape.length/2*(x+1),
                                shape.length,shape.keel,
                                shape.waterline,shape.bottom, 26)
         ycs[i,:] = np.append(-1*cs[0,:0:-1],cs[0,:])
         zcs[i,:] = np.append(cs[1,:0:-1],cs[1,:])
         plt.figure()
         wls = plt.contour(xs,ys,zcs, [-dz])
     plt.figure()
     for wlc in wls.collections:
         wl = wlc.get_paths()[0]
         v = wl.vertices
         xnorm = v[:,0]
         ynorm = v[:,1]
         fy_spl = interpolate.RectBivariateSpline(xs,ys,ycs)
         x_wl = shape.length/2*(xnorm+1)
         y_wl = fy_spl.ev(xnorm,ynorm)
         plt.plot(x_wl,y_wl,'b')
Example #2
0
        self.length = length
        self.keel   = lambda x: geo.normal_pol4(x,depth/length)
        self.cap    = lambda x: -1*geo.normal_pol4(x,height/length)
        self.waterline   = lambda x: -1*geo.normal_pol4(x,width/length)
        self.bottom   = lambda x: geo.oval(x,pwr,root)
        self.top   = lambda x: -1*geo.normal_pol4(x,1)

if __name__=="__main__":
    shape = BuoyShape(L,Prof,Aber,alt,4,2)
    xs = np.linspace(-1,1,21)
    STTS = list()
    for i,x in enumerate(xs):
        offset = 0
        if i==0:
            offset = 0.001
        elif i==20:
            offset = -0.001
            station = shape.length/2*(x+1) + offset
        STTS.append(station)
        cs_b = geo.cross_section(station,
                                 shape.length,shape.keel,
                                 shape.waterline,shape.bottom, 50)
        cs_t = geo.cross_section(station,
                                 shape.length,shape.cap,
                                 shape.waterline,shape.top, 50)
        cs = np.hstack((cs_b,cs_t[:,-2::-1]))*1000
        np.savetxt('./results/cs_{:02d}.dat'.format(i),cs.T,
                   delimiter=',',fmt='%.5f',header='HULL SECTION')

    np.savetxt('./results/offsets.dat',np.array(STTS)*1000,fmt='%.3f')
Example #3
0
def buoyancy_actions(shape,angles,translate,cg_pos):
    """ Returns buoyancy actions: force and moment with respec to cg
    as a function of buoy orientation and vertical displacement """
    # TODO: A diagram explaining reference axis and origin conventions

    l           = shape.length
    waterline_f = shape.waterline
    
    # Auxiliar variables
    buoy_orig = np.array([l/2,0,0])

    # Cross section types
    parts = ['top','bottom']
    # Stations
    stt = np.linspace(0,l,100)

    # Force and Moment Initialization
    F_z = 0;
    M_x = 0;
    M_y = 0;
    for p in parts:
        if p=='top':
            center_f = shape.cap
            cross_f  = shape.top
        elif p=='bottom':
            center_f = shape.keel
            cross_f  = shape.bottom
        areas = list()
        ct_pos = np.empty((3,0))
        for s in stt:
            # Get the cross section
            cs = geo.cross_section(s,l,center_f,waterline_f,cross_f)
            cs = np.hstack((np.vstack((cs[0,:0:-1],cs[1,:0:-1])),
                            np.vstack((-1*cs[0,:],cs[1,:]))))
            csB = np.vstack((s*np.ones((1,cs.shape[1])),cs)) - \
                  buoy_orig[:,np.newaxis]*np.ones((1,cs.shape[1]))
            # Get the coordinates on the earth reference system
            csE = buoy_to_earth(csB,angles,translate)
            # Only get the points with Ze<0 (underwater points)
            csE_cs_uw = underwater_part(csE[1:,:])
            if csE_cs_uw is None:
                areas.append(0)
                ct_pos = np.hstack((ct_pos,np.array([[0.],[0.],[0.]])))
                continue
            x_uw = np.interp(csE_cs_uw[:,0],csE[1,:],csE[0,:])
            csE_uw = np.vstack((x_uw,csE_cs_uw.T))
            # Transform underwater points back to buoy reference system
            # and calculate underwater area and centroid position
            csB_uw = earth_to_buoy(csE_uw,angles,translate)
            (uw_area_i, Ct_B) = geo.centroid_and_area(csB_uw.T)
            Ct_E = buoy_to_earth(Ct_B[:,np.newaxis],angles,translate)
            # Append to the list of areas and centroid positions on the
            # earth reference system
            areas.append(uw_area_i)
            ct_pos = np.hstack((ct_pos,Ct_E))

        areas = np.array(areas)
        ct_pos = ct_pos.T
        # For the force, just integrate the submerged areas over the station
        # positions and multiply by water density and gravity
        F_z += integrate.simps(areas,stt)*RHO_W*GRAV

        # For the moment, split into two components (Mx and My) by integrating
        # the product of forces by their relative distances to the CG
        cgE = buoy_to_earth(cg_pos[:,np.newaxis],angles,translate)
        dY_vec  = ct_pos[:,Y_AX] - cgE[Y_AX]
        dX_vec  = ct_pos[:,X_AX] - cgE[X_AX]
        M_x += integrate.simps(areas*dY_vec.T,stt)*RHO_W*GRAV
        M_y += -1*integrate.simps(areas*dX_vec.T,stt)*RHO_W*GRAV

    return (F_z, M_x, M_y)