Ejemplo n.º 1
0
    def testStoreLastValues(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])  
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D
        nd = 2
        anglez = radians(5.0)
        rotz = np.array([  [  cos(anglez),  sin(anglez),  0.0 ],
                           [ -sin(anglez),  cos(anglez),  0.0 ],
                           [  0.0,         0.0,           1.0 ] ])

        c2d.calculate_init()

        # Imposing values on rigid body's parameters
        c2d.position = np.array([2.0, 3.0, 0.0])
        c2d.velocity = np.array([0.5, -0.3, 0.0])
        c2d.acceleration = np.array([0.1, 0.2, 0.0])
        c2d.rotation = rotz
        c2d.rotation_euler =  bd.getEulerAngles(rotz)
        c2d.ang_disp = np.array([0.0, 0.0, 0.001])
        c2d.ang_vel = np.array([0.0, 0.0, -0.003])
        c2d.ang_acc = np.array([0.0, 0.0, 0.005])
        c2d.F = np.array([100.0, -300.0, 0.0])
        c2d.M = np.array([0.0, 0.0, 50.0])
        c2d.pivot = c2d.barycenter
        c2d.ux = 0.5
        c2d.uy = 0.05
        c2d.uz = 0.0

        c2d._store_last_values()
        
        npt.assert_equal(c2d.position, c2d.last_position)
        npt.assert_equal(c2d.velocity, c2d.last_velocity)
        npt.assert_equal(c2d.acceleration, c2d.last_acceleration)
        npt.assert_equal(c2d.rotation, c2d.last_rotation)
        npt.assert_equal(c2d.rotation_euler, c2d.last_rotation_euler)
        npt.assert_equal(c2d.ang_disp, c2d.last_ang_disp)
        npt.assert_equal(c2d.ang_vel, c2d.last_ang_vel)
        npt.assert_equal(c2d.ang_acc, c2d.last_ang_acc)
        npt.assert_equal(c2d.F, c2d.last_F)
        npt.assert_equal(c2d.M, c2d.last_M)
        npt.assert_equal(c2d.pivot, c2d.last_pivot)
        npt.assert_equal(c2d.ux, c2d.last_ux)
        npt.assert_equal(c2d.uy, c2d.last_uy)
        npt.assert_equal(c2d.uz, c2d.last_uz)
Ejemplo n.º 2
0
    def testStep(self):
        from proteus import Domain
        from proteus import SpatialTools as st
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd

        # parameters
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        caisson = mst.Rectangle(domain=domain2D,
                                dim=dim,
                                coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain2D)
        c2d = caisson2D
        nd = c2d.nd = 2
        Ix = ((dim[0]**2) / 12.)
        Iy = ((dim[1]**2) / 12.)
        It = Ix + Iy
        mass = 50.0
        I = mass * It
        c2d.mass, c2d.It = mass, It
        init_barycenter, last_position, last_velocity, last_rotation, last_ang_vel = pos, pos * 2.0, np.array(
            [0.05, 0.07,
             0.0]), np.array([0.0, 0.0, 0.0001]), np.array([0., 0., 0.0000002])
        c2d.init_barycenter, c2d.last_position, c2d.last_velocity, c2d.last_rotation, c2d.last_ang_vel = init_barycenter, last_position, last_velocity, last_rotation, last_ang_vel
        F = Fx, Fy, Fz = np.array([200., 300., 0.0])
        M = Mx, My, Mz = np.array([0., 0., 50.0])
        dt, substeps = 0.001, 20
        dt_sub = c2d.dt_sub = float(dt / substeps)
        c2d.F, c2d.substeps, c2d.dt, c2d.acceleration = F, substeps, dt, c2d.getAcceleration(
        )
        c2d.InputMotion = False
        c2d.scheme = 'Forward_Euler'
        h, tra_velocity = bd.forward_euler(last_position, last_velocity,
                                           F / mass, dt)
        rot, rot_velocity = bd.forward_euler(last_rotation, last_ang_vel,
                                             M / I, dt)
        if rot[2] < 0.0: rot[2] = -rot[2]
        # 2d calculation
        caisson.translate(h[:nd]), caisson.rotate(rot[2])
        posTra1, rot1 = caisson.barycenter, caisson.coords_system
        # 2d from bodydynamics
        caisson.translate(-h[:nd]), caisson.rotate(-rot[2])
        c2d.step(dt)
        posTra2, rot2 = c2d.position, c2d.rotation[:nd, :nd]
        npt.assert_allclose(posTra1, posTra2, atol=1e-10)
        npt.assert_allclose(rot1, rot2, atol=1e-10)
Ejemplo n.º 3
0
    def testGetDisplacement(self):
        from proteus import Domain
        from proteus import SpatialTools as st
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd

        # parameters
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        caisson = mst.Rectangle(domain=domain2D,
                                dim=dim,
                                coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain2D)
        c2d = caisson2D
        c2d.nd = 2
        Ix = ((dim[0]**2) / 12.)
        Iy = ((dim[1]**2) / 12.)
        It = Ix + Iy
        mass = 50.0
        c2d.mass, c2d.It = mass, It
        Kx, Ky, Kz = K = [200000., 250000., 0.0]
        Cx, Cy, Cz = C = [2000., 4000., 0.0]
        c2d.Kx, c2d.Ky, c2d.Kz, c2d.Cx, c2d.Cy, c2d.Cz = Kx, Ky, Kz, Cx, Cy, Cz
        init_barycenter, last_position, last_velocity = pos, pos * 2.0, np.array(
            [0.05, 0.07, 0.0])
        c2d.init_barycenter, c2d.last_position, c2d.last_velocity = init_barycenter, last_position, last_velocity
        Fx, Fy, Fz = F = np.array([200., 300., 0.0])
        dt, substeps = 0.001, 50
        dt_sub = c2d.dt_sub = float(dt / substeps)
        c2d.F, c2d.substeps, c2d.dt, c2d.acceleration = F, substeps, dt, c2d.getAcceleration(
        )

        # runge-kutta calculation
        c2d.scheme = 'Runge_Kutta'
        u0 = ux0, uy0, uz0 = last_position - init_barycenter
        v0 = vx0, vy0, vz0 = last_velocity
        a0 = ax0, ay0, az0 = (F - C * v0 - K * u0) / mass
        for ii in range(substeps):
            ux, vx, ax = bd.runge_kutta(ux0, vx0, ax0, dt_sub, substeps, Fx,
                                        Kx, Cx, mass, False)
            uy, vy, ay = bd.runge_kutta(uy0, vy0, ay0, dt_sub, substeps, Fy,
                                        Ky, Cy, mass, False)
            uz, vz, az = bd.runge_kutta(uz0, vz0, az0, dt_sub, substeps, Fz,
                                        Kz, Cz, mass, False)
        h = hx, hy, hz = [ux - ux0, uy - uy0, uz - uz0]
        c2d.h = c2d.getDisplacement(dt)
        npt.assert_equal(c2d.h, h)
Ejemplo n.º 4
0
    def testGetAngularAcceleration(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])    
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D

        F = np.array([100.0, -200.0, 10.0])
        mass = 150.0
        acceleration = old_div(F,mass)

        c2d.F = F
        c2d.mass = mass
        c2d.acceleration = c2d.getAcceleration()
        npt.assert_equal(c2d.acceleration, acceleration)
Ejemplo n.º 5
0
    def testCalculateInit(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])  
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D
        nd = 2
        angle = bd.getEulerAngles(rot)

        c2d.calculate_init()

        npt.assert_equal(c2d.position, pos)
        npt.assert_equal(c2d.last_position, pos)
        npt.assert_equal(c2d.rotation, rot)
        npt.assert_equal(c2d.last_rotation, rot)
        npt.assert_equal(c2d.rotation_euler, angle)
        npt.assert_equal(c2d.last_rotation_euler, angle)
Ejemplo n.º 6
0
#####################     Shape Geometry & Characteristics    ###############################

# --- Circle
b = 2.0 * opts.radius
h = 2.0 * opts.radius

# --- Circle Setup
circle = st.Circle(domain=domain,
                   radius=opts.radius,
                   coords=(0.5, opts.tank_dim[1] / 2),
                   barycenter=(0.5, opts.tank_dim[1] / 2),
                   nPoints=opts.nPoints)

# --- Body properties setup
circle2D = bd.RigidBody(shape=circle)

circle2D.setMass(mass=opts.mass)
I = (3.14 * (opts.radius**4) / 2.) * opts.mass

circle2D.It = I / opts.mass / opts.width
circle2D.setConstraints(free_x=opts.free_x, free_r=opts.free_r)
circle2D.setNumericalScheme(scheme=opts.scheme)
circle2D.inputMotion(InputMotion=opts.InputMotion, At=opts.At, Tt=opts.Tt)
circle2D.setRecordValues(filename='circle2D', all_values=True)

# --- Spring setup

#circle2D.setSprings(springs=opts.springs,  K=[opts.Kx, opts.Ky, 0.0, Krot], C=[opts.Cx, opts.Cy, 0.0, opts.Crot])

################################       Turbulance      ################################
Ejemplo n.º 7
0
    def testGetInertia(self):
        from proteus import Domain  
        from proteus import SpatialTools as st    
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd   

        # 2d case
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        caisson = mst.Rectangle(domain=domain2D, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain2D)      
        c2d = caisson2D
        c2d.nd = 2
        Ix = (old_div((dim[0]**2),12.))
        Iy = (old_div((dim[1]**2),12.))
        It = Ix + Iy 
        mass = 50.0
        I1 = It*mass
        c2d.mass = mass
        c2d.It = It
        I2 = c2d.getInertia()
        npt.assert_equal(I1, I2)

        # 3d case
        pos, dim, caisson = [], [], []
        domain3D = Domain.PiecewiseLinearComplexDomain()
        pos = np.array([0.0, 0.0, 0.0])
        dim = (0.3, 0.385, 0.4)
        angle = radians(10.)
        Ix = (old_div((dim[0]**2),12.))
        Iy = (old_div((dim[1]**2),12.))
        Iz = (old_div((dim[2]**2),12.))
        It = np.array([ [Iz + Iy, 0.0, 0.0],
                        [0.0, Ix + Iz, 0.0],
                        [0.0, 0.0, Ix + Iy] ])
        mass = 50.0
        # rotational axis and versors
        ax, ay, az = axis = np.array([1., 1., 1.])
        mod = np.sqrt((ax**2)+(ay**2)+(az**2))
        axis_ver = (old_div(axis,mod))
        # shape
        caisson = mst.Cuboid(domain=domain3D, dim=dim, coords=[pos[0], pos[1], pos[2]])
        caisson.rotate(rot=angle, axis=axis)
        coords_system = caisson.coords_system
        caisson3D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain3D)      
        # rotational operator for inertia calculation on an arbitrary axis
        rotx, roty, rotz = np.dot(axis_ver, np.linalg.inv(coords_system))
        rot = np.array([ [(rotx**2), rotx*roty, rotx*rotz],
                         [roty*rotx, (roty**2), roty*rotz],
                         [rotz*rotx, rotz*roty, (rotz**2)] ])
        #inertia = np.einsum('ij,ij->', mass*It, rot)
        inertia = np.sum(mass*It*rot)
        # testing from BodyDynamics
        c3d = caisson3D
        c3d.nd = 3
        c3d.mass = mass
        c3d.It = It
        c3d.coords_system = coords_system
        I = c3d.getInertia(vec=axis)
        npt.assert_equal(I, inertia)
Ejemplo n.º 8
0
    dim = (dimx, dimy)
    coords = ctr
    VCG = dim[1] / 2.
    width = opts.width
    mass = opts.mass
    volume = float(dimx * dimy * width)
    density = float(mass / volume)
    inertia = opts.caisson_inertia / mass / width

    # --- Shape properties setup
    caisson = st.Rectangle(domain, dim=dim, coords=coords)
    xc1, yc1 = caisson.vertices[0][0], caisson.vertices[0][1]
    xc2, yc2 = caisson.vertices[1][0], caisson.vertices[1][1]

    # --- Body properties setup
    caisson2D = bd.RigidBody(shape=caisson, substeps=20)
    free_x = np.array(opts.free_x)
    free_r = np.array(opts.free_r)
    caisson2D.setMass(mass)
    caisson2D.setConstraints(free_x=free_x, free_r=free_r)
    rotation = np.radians(opts.rotation_angle)
    caisson.rotate(rotation)
    caisson2D.It = inertia
    caisson2D.setNumericalScheme(scheme=opts.scheme)
    caisson2D.setRecordValues(filename='caisson2D', all_values=True)

##############################################################################################################################################################################################################
# Tank
#########################################################################################################################################################################################################

tank = st.Tank2D(domain, tank_dim)