def gen_dim1sin_E_Igamv_the_aDmagDt_bilinear():
    """Test case generation for dim1sin_E_Igamv_the_aDmagDt_bilinear

    2014-03-22"""

    #dim1sin_E_Igamv_the_aDmagDt_bilinear(m, eigs, tvals, Igamv, a, mag_vs_depth, mag_vs_time, omega_phase = None, dT=1.0):
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    mag_vs_time = PolyLine([0,2,4],[0,2,2])
    mag_vs_depth = PolyLine([0, 1], [1, 2])#y = (1+z)

    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)

    fn=OrderedDict()

    fn['single_load'] = {'m': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
               'a':a,
                'mag_vs_depth': [mag_vs_depth], 'mag_vs_time': [mag_vs_time]}
    fn['double_load'] = {'m': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
               'a':a,
                'mag_vs_depth': [mag_vs_depth]*2, 'mag_vs_time': [mag_vs_time]*2}
    fn['omega_phase'] = {'m': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
               'a':a,
                'mag_vs_depth': [mag_vs_depth], 'mag_vs_time': [mag_vs_time],'omega_phase': [omega_phase]}

    for k, v in fn.items():
        print(k)
        print (dim1sin_E_Igamv_the_aDmagDt_bilinear(**v))
        print('#'*10+'\n')
Example #2
0
class test_dim1sin_E_Igamv_the_abmag_bilinear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_abmag_bilinear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    because this fn is basically a glorified wrapper we really just need to
    test if all the args are passed properly.

    """
    #dim1sin_E_Igamv_the_abmag_bilinear(m, eigs, tvals, Igamv, a, b, mag_vs_depth, mag_vs_time, omega_phase=None, dT=1.0):


    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    mag_vs_time = PolyLine([0,2,4],[0,2,2])
    mag_vs_depth = PolyLine([0, 1], [1, 2])#y = (1+z)

    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)





    def test_single_load(self):
        assert_allclose(dim1sin_E_Igamv_the_abmag_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a, 'b':self.b,
                'mag_vs_depth': [self.mag_vs_depth], 'mag_vs_time': [self.mag_vs_time]}),

                                  np.array([[ 0.81302649,  3.71707495],
                                            [ 1.16885336,  5.34387942],
                                            [ 0.91557876,  4.18593358]]))

    def test_double_load(self):
        assert_allclose(dim1sin_E_Igamv_the_abmag_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a, 'b':self.b,
                'mag_vs_depth': [self.mag_vs_depth]*2, 'mag_vs_time': [self.mag_vs_time]*2}),

                                  2*np.array([[ 0.81302649,  3.71707495],
                                            [ 1.16885336,  5.34387942],
                                            [ 0.91557876,  4.18593358]]))
    def test_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_abmag_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a, 'b':self.b,
                'mag_vs_depth': [self.mag_vs_depth], 'mag_vs_time': [self.mag_vs_time], 'omega_phase': [self.omega_phase]}),

                                  np.array([[-0.72431765, -1.13467717],
                                           [-1.04132046, -1.63127676],
                                           [-0.81568051, -1.27780132]]))
Example #3
0
class test_dim1sin_E_Igamv_the_aDmagDt_bilinear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_aDmagDt_bilinear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    because this fn is basically a glorified wrapper we really just need to
    test if all the args are passed properly.

    """
    #dim1sin_E_Igamv_the_aDmagDt_bilinear(m, eigs, tvals, Igamv, a, mag_vs_depth, mag_vs_time, omega_phase = None, dT=1.0):


    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    mag_vs_time = PolyLine([0,2,4],[0,2,2])
    mag_vs_depth = PolyLine([0, 1], [1, 2])#y = (1+z)

    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)





    def test_single_load(self):
        assert_allclose(dim1sin_E_Igamv_the_aDmagDt_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a,
                'mag_vs_depth': [self.mag_vs_depth], 'mag_vs_time': [self.mag_vs_time]}),

                                  np.array([[ 0.81245149,  0.40883755],
                                       [ 1.19316194,  0.60041665],
                                       [ 0.99156737,  0.4989713 ]]))

    def test_double_load(self):
        assert_allclose(dim1sin_E_Igamv_the_aDmagDt_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a,
                'mag_vs_depth': [self.mag_vs_depth]*2, 'mag_vs_time': [self.mag_vs_time]*2}),

                                  2*np.array([[ 0.81245149,  0.40883755],
                                       [ 1.19316194,  0.60041665],
                                       [ 0.99156737,  0.4989713 ]]))
    def test_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_aDmagDt_bilinear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'a':self.a,
                'mag_vs_depth': [self.mag_vs_depth], 'mag_vs_time': [self.mag_vs_time], 'omega_phase': [self.omega_phase]}),

                                  np.array([[-0.85117901,  1.38905894],
                                           [-1.25003698,  2.03996458],
                                           [-1.0388329 ,  1.69529571]]))
Example #4
0
class test_dim1sin_E_Igamv_the_deltamag_linear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_deltamag_linear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    because this fn is basically a glorified wrapper we really just need to
    test if all the args are passed properly.

    """
    #dim1sin_E_Igamv_the_deltamag_linear(m, eigs, tvals, Igamv, zvals, a, mag_vs_time, omega_phase=None, dT=1.0):


    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    mag_vs_time = PolyLine([0,2,4],[0,2,2])
    mag_vs_depth = PolyLine([0, 1], [1, 2])#y = (1+z)

    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)
    zvals=[0.2]
    pseudo_k=[1000]



    def test_single_load(self):
        assert_allclose(dim1sin_E_Igamv_the_deltamag_linear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'zvals':self.zvals, 'pseudo_k':self.pseudo_k,
                'mag_vs_time': [self.mag_vs_time]}),

                                  np.array([[  73.08636239,  334.14346275],
                                       [ 143.25900215,  654.9656801 ],
                                       [ 207.72035757,  949.67648264]]))

    def test_double_load(self):
        assert_allclose(dim1sin_E_Igamv_the_deltamag_linear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'zvals':self.zvals*2, 'pseudo_k':self.pseudo_k*2,
                 'mag_vs_time': [self.mag_vs_time]*2}),

                                  2*np.array([[  73.08636239,  334.14346275],
                                               [ 143.25900215,  654.9656801 ],
                                               [ 207.72035757,  949.67648264]]))
    def test_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_deltamag_linear(
            **{'m': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
               'zvals':self.zvals, 'pseudo_k':self.pseudo_k,
                'mag_vs_time': [self.mag_vs_time], 'omega_phase': [self.omega_phase]}),

                                  np.array([[ -65.11195277, -102.00089187],
                                           [-127.62809745, -199.93533007],
                                           [-185.05611264, -289.89897759]]))
def gen_dim1sin_E_Igamv_the_BC_aDfDt_linear():
    """Test case generation for dim1sin_E_Igamv_the_BC_aDfDt_linear.

    2014-03-22"""

    #dim1sin_E_Igamv_the_BC_aDfDt_linear(drn, m, eigs, tvals, Igamv, a, top_vs_time, bot_vs_time, top_omega_phase=None, bot_omega_phase=None, dT=1.0):
    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)


    fn=OrderedDict()

    fn['no_bc'] = {'drn': 0, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
        'a': a,  'top_vs_time': None, 'bot_vs_time':None}
    fn['top_vs_time_drn_0']={'drn': 0, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,  'top_vs_time': [top_vs_time], 'bot_vs_time':None}
    fn['top_vs_time_drn_1']={'drn': 1, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,  'top_vs_time': [top_vs_time], 'bot_vs_time':None}
    fn['bot_vs_time_drn_0']={'drn': 0, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,  'top_vs_time': None,'bot_vs_time':[bot_vs_time]}
    fn['bot_vs_time_top_vs_time_drn_1']={'drn': 1, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,  'top_vs_time': [top_vs_time],'bot_vs_time':[bot_vs_time]}
    fn['test_top_vs_time_drn_0_omega_phase']={'drn': 0, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,
            'top_vs_time': [top_vs_time],
            'bot_vs_time':None,
            'top_omega_phase': [omega_phase]}
    fn['test_bot_vs_time_drn_0_omega_phase']={'drn': 0, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,
            'top_vs_time': None,
            'bot_vs_time':[bot_vs_time],
            'bot_omega_phase': [omega_phase]}
    fn['bot_vs_time_top_vs_time_drn_1_double_loads']={'drn': 1, 'm': m, 'eigs':eigs, 'tvals':tvals,'Igamv':Igamv,
            'a': a,  'top_vs_time': [top_vs_time, top_vs_time],'bot_vs_time':[bot_vs_time, bot_vs_time]}
#    print(dim1sin_E_Igamv_the_BC_abf_linear(0,m,eigs,tvals,Igamv, a,b, top_vs_time=None, bot_vs_time=None))

    for k, v in fn.items():
        print(k)
        print (dim1sin_E_Igamv_the_BC_aDfDt_linear(**v))
        print('#'*10+'\n')
Example #6
0
def test_check_attribute_PolyLines_have_same_x_limits():
    """test for check_attribute_PolyLines_have_same_x_limits function"""
    #check_attribute_PolyLines_have_same_x_limits(obj, attributes=[])

    a = EmptyClass()

    a.a = None
    a.b = PolyLine([0,4],[4,5])
    a.c = [PolyLine([0,4],[6,3]), PolyLine([0,5],[6,3])]
    a.d = PolyLine([0,2,4], [3,2,4])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['a','b','c','d']])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['c']])

    assert_equal(check_attribute_PolyLines_have_same_x_limits(a,
                  attributes=[['a','b','d']]), None)
Example #7
0
class test_dim1sin_E_Igamv_the_BC_deltaf_linear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_BC_deltaf_linear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time
     - I've not included layers in  the a part
     - I've the test case data was generated by evaluating the function
       i.e. it's not an independant test.  I think it is OK because
       the Speccon1dVR testing whcih uses all these fns uses independant data
    """
    #dim1sin_E_Igamv_the_BC_deltaf_linear(drn, m, eigs, tvals, Igamv, zvals, pseudo_k, top_vs_time, bot_vs_time, top_omega_phase=None, bot_omega_phase=None, dT=1.0)

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)
    zvals=[0.2]
    pseudo_k=[1000]

    def test_no_BC(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': None, 'bot_vs_time':None}),

                                  np.array([[ 0.,  0.],
                                            [ 0.,  0.],
                                            [ 0.,  0.]]))

    def test_top_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[  58.46908991,  267.3147702 ],
       [ 114.60720172,  523.97254408],
       [ 166.17628606,  759.74118611]]))


    def test_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[  73.08636239,  334.14346275],
       [ 143.25900215,  654.9656801 ],
       [ 207.72035757,  949.67648264]]))


    def test_bot_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': None, 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[  14.61727248,   66.82869255],
       [  28.65180043,  130.99313602],
       [  41.54407151,  189.93529653]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[   87.70363487,   400.97215531],
       [  171.91080258,   785.95881612],
       [  249.26442909,  1139.61177917]]))

    def test_top_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,
            'top_vs_time': [self.top_vs_time],
            'bot_vs_time':None,
            'top_omega_phase': [self.omega_phase]}),

                                  np.array([[ -52.08956221,  -81.6007135 ],
       [-102.10247796, -159.94826406],
       [-148.04489011, -231.91918207]]))

    def test_bot_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,
            'top_vs_time': None,
            'bot_vs_time':[self.bot_vs_time],
            'bot_omega_phase': [self.omega_phase]}),

                                  np.array([[-13.02239055, -20.40017837],
       [-25.52561949, -39.98706601],
       [-37.01122253, -57.97979552]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_deltaf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'zvals': self.zvals, 'pseudo_k':self.pseudo_k,  'top_vs_time': [self.top_vs_time,self.top_vs_time], 'bot_vs_time':[self.bot_vs_time,self.bot_vs_time]}),

                                  np.array([[  175.40726974,   801.94431061],
       [  343.82160516,  1571.91763224],
       [  498.52885818,  2279.22355834]]))
Example #8
0
class test_dim1sin_E_Igamv_the_BC_aDfDt_linear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_BC_aDfDt_linear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time
     - I've not included layers in  the a part
     - I've the test case data was generated by evaluating the function
       i.e. it's not an independant test.  I think it is OK because
       the Speccon1dVR testing whcih uses all these fns uses independant data
    """
    #dim1sin_E_Igamv_the_BC_aDfDt_linear(drn, m, eigs, tvals, Igamv, a, top_vs_time, bot_vs_time, top_omega_phase=None, bot_omega_phase=None, dT=1.0):

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)


    def test_no_BC(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': None, 'bot_vs_time':None}),

                                  np.array([[ 0.,  0.],
                                            [ 0.,  0.],
                                            [ 0.,  0.]]))

    def test_top_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[ 0.14946707,  0.07521403],
       [ 0.25246136,  0.12704228],
       [ 0.28406245,  0.14294441]]))


    def test_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[ 0.48095928,  0.24202579],
       [ 0.72281165,  0.36372947],
       [ 0.63781491,  0.32095785]]))


    def test_bot_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': None, 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.33149221,  0.16681176],
       [ 0.47035029,  0.23668719],
       [ 0.35375246,  0.17801345]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.81245149,  0.40883755],
       [ 1.19316194,  0.60041665],
       [ 0.99156737,  0.4989713 ]]))

    def test_top_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,
            'top_vs_time': [self.top_vs_time],
            'bot_vs_time':None,
            'top_omega_phase': [self.omega_phase]}),

                                  np.array([[-0.15659179,  0.2555458 ],
       [-0.26449556,  0.4316365 ],
       [-0.297603  ,  0.48566529]]))

    def test_bot_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,
            'top_vs_time': None,
            'bot_vs_time':[self.bot_vs_time],
            'bot_omega_phase': [self.omega_phase]}),

                                  np.array([[-0.34729361,  0.56675657],
       [-0.49277071,  0.80416404],
       [-0.37061495,  0.60481521]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_aDfDt_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time,self.top_vs_time], 'bot_vs_time':[self.bot_vs_time,self.bot_vs_time]}),

                                  np.array([[ 1.62490297,  0.8176751 ],
                                   [ 2.38632387,  1.20083331],
                                   [ 1.98313474,  0.9979426 ]]))
Example #9
0
class test_dim1sin_E_Igamv_the_BC_D_aDf_linear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_BC_D_aDf_linear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time
     - I've not included layers in  the a part
     - I've the test case data was generated by evaluating the function
       i.e. it's not an independant test.  I think it is OK because
       the Speccon1dVR testing whcih uses all these fns uses independant data
    """
    #dim1sin_E_Igamv_the_BC_D_aDf_linear(drn, m, eigs, tvals, Igamv, a, top_vs_time, bot_vs_time, top_omega_phase=None, bot_omega_phase=None, dT=1.0):

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)


    def test_no_BC(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': None, 'bot_vs_time':None}),

                                  np.array([[ 0.,  0.],
                                            [ 0.,  0.],
                                            [ 0.,  0.]]))

    def test_top_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[-0.16911333, -0.77316906],
       [-0.26048565, -1.19091408],
       [-0.24402578, -1.11566119]]))


    def test_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.]]))


    def test_bot_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': None, 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.16911333,  0.77316906],
                               [ 0.26048565,  1.19091408],
                               [ 0.24402578,  1.11566119]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time], 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.16911333,  0.77316906],
                                   [ 0.26048565,  1.19091408],
                                   [ 0.24402578,  1.11566119]]))

    def test_top_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,
            'top_vs_time': [self.top_vs_time],
            'bot_vs_time':None,
            'top_omega_phase': [self.omega_phase]}),

                                  np.array([[ 0.15066148,  0.23601818],
                                   [ 0.23206422,  0.36353935],
                                   [ 0.21740027,  0.3405676 ]]))

    def test_bot_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,
            'top_vs_time': None,
            'bot_vs_time':[self.bot_vs_time],
            'bot_omega_phase': [self.omega_phase]}),

                                  np.array([[-0.15066148, -0.23601818],
                                   [-0.23206422, -0.36353935],
                                   [-0.21740027, -0.3405676 ]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_D_aDf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a,  'top_vs_time': [self.top_vs_time,self.top_vs_time], 'bot_vs_time':[self.bot_vs_time,self.bot_vs_time]}),

                                  np.array([[ 0.33822666,  1.54633812],
                                   [ 0.52097131,  2.38182817],
                                   [ 0.48805155,  2.23132237]]))
Example #10
0
class test_dim1sin_E_Igamv_the_BC_abf_linear(unittest.TestCase):
    """tests for dim1sin_E_Igamv_the_BC_abf_linear

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time
     - I've the test case data was generated by evaluating the function
       i.e. it's not an independant test.  I think it is OK because
       the Speccon1dVR testing whcih uses all these fns uses independant data
    """
    #dim1sin_E_Igamv_the_BC_abf_linear(drn, m, eigs, tvals, Igamv, a, b, top_vs_time, bot_vs_time, top_omega_phase=None, bot_omega_phase=None, dT=1.0):

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    b = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3
    Igamv = np.identity(3)
    eigs = np.ones(3)


    def test_no_BC(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': None, 'bot_vs_time':None}),

                                  np.array([[ 0.,  0.],
                                            [ 0.,  0.],
                                            [ 0.,  0.]]))

    def test_top_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[ 0.13262919,  0.60636726],
                                       [ 0.21993155,  1.00550484],
                                       [ 0.23855946,  1.09066975]]))


    def test_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': [self.top_vs_time], 'bot_vs_time':None}),

                                  np.array([[ 0.47282784,  2.1617211 ],
                                       [ 0.69439245,  3.17469213],
                                       [ 0.57706911,  2.63830166]]))


    def test_bot_vs_time_drn_0(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': None, 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.34019865,  1.55535384],
                                   [ 0.4744609 ,  2.16918729],
                                   [ 0.33850965,  1.54763191]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': [self.top_vs_time], 'bot_vs_time':[self.bot_vs_time]}),

                                  np.array([[ 0.81302649,  3.71707495],
                                       [ 1.16885336,  5.34387942],
                                       [ 0.91557876,  4.18593358]]))

    def test_top_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b,
            'top_vs_time': [self.top_vs_time],
            'bot_vs_time':None,
            'top_omega_phase': [self.omega_phase]}),

                                  np.array([[-0.1181581 , -0.18510014],
                                   [-0.19593495, -0.30694118],
                                   [-0.21253038, -0.33293869]]))

    def test_bot_vs_time_drn_0_omega_phase(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 0, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b,
            'top_vs_time': None,
            'bot_vs_time':[self.bot_vs_time],
            'bot_omega_phase': [self.omega_phase]}),

                                  np.array([[-0.30307978, -0.47478852],
                                   [-0.42269275, -0.66216779],
                                   [-0.30157506, -0.47243132]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):
        assert_allclose(dim1sin_E_Igamv_the_BC_abf_linear(
            **{'drn': 1, 'm': self.m, 'eigs':self.eigs, 'tvals':self.tvals,'Igamv':self.Igamv,
            'a': self.a, 'b':self.b, 'top_vs_time': [self.top_vs_time,self.top_vs_time], 'bot_vs_time':[self.bot_vs_time,self.bot_vs_time]}),

                                  np.array([[  1.62605298,   7.43414989],
                                   [  2.33770671,  10.68775884],
                                   [  1.83115753,   8.37186715]]))
def gen_dim1sin_integrate_af():
    """Test case data generation for dim1sin_integrate_af."""

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0, 2.0, 3.0])
    v_E_Igamv_the = np.ones((3, 2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0, 2, 4], [0, 2, 2])
    bot_vs_time = PolyLine([0, 2, 4], [0, 2, 2])
    omega_phase = (1, 2)
    a = PolyLine([0, 1], [1, 2])  # y = 1 + z
    g = np.array([1.0,
                  2.0])  # this is interpolated from top_vs_time at t = 1, 3

    z1_, z2_, z_, m_, g_, t_, omega_, phase_ = sympy.symbols(
        'z1_, z2_, z_, m_, g_, t_, omega_, phase_')

    top1 = g_ * (1 - z_)
    top2 = g_
    bot1 = g_ * z_
    print(g[np.newaxis, :] * z1[:, np.newaxis])
    mapping = [('z1_', 'z1[:,np.newaxis]'), ('z2_', 'z2[:,np.newaxis]'),
               ('m_', 'm[np.newaxis,:]'), ('g_', 'g[np.newaxis,:]'),
               ('t_', 'tvals[np.newaxis,:]'), ('omega_', 'omega_phase[0]'),
               ('phase_', 'omega_phase[1]')]
    fn = OrderedDict()
    fn['no_bc'] = sympy.integrate(
        sympy.sin(m_ * z_) * (1 + z_), (z_, z1_, z2_))
    #anything other than fn['no_bc'] only contains the bc part
    fn['top_vs_time_drn_0'] = sympy.integrate(top1 * (1 + z_), (z_, z1_, z2_))
    fn['top_vs_time_drn_1'] = sympy.integrate(top2 * (1 + z_), (z_, z1_, z2_))
    fn['bot_vs_time_drn_0'] = sympy.integrate(bot1 * (1 + z_), (z_, z1_, z2_))
    fn['bot_vs_time_top_vs_time_drn_1'] = sympy.integrate(
        (top2 + bot1) * (1 + z_), (z_, z1_, z2_))
    fn['top_vs_time_drn_0_omega_phase'] = sympy.integrate(
        sympy.cos(omega_ * t_ + phase_) * top1 * (1 + z_), (z_, z1_, z2_))
    fn['bot_vs_time_drn_0_omega_phase'] = sympy.integrate(
        sympy.cos(omega_ * t_ + phase_) * bot1 * (1 + z_), (z_, z1_, z2_))
    fn['bot_vs_time_top_vs_time_drn_1_double_loads'] = 2 * sympy.integrate(
        (top2 + bot1) * (1 + z_), (z_, z1_, z2_))
    #no_bc part
    sout = str(fn['no_bc'])
    for k, v in mapping:
        sout = sout.replace(k, v)
    print('no_bc')
    print(sout)
    print('#' * 10)
    if SAFE:
        no_bc = (np.dot(eval(sout), v_E_Igamv_the))
    print(no_bc)
    print('#' * 10 + '\n')

    for s, f in fn.items():
        if s == "no_bc":
            continue
        sout = str(f)
        for k, v in mapping:
            sout = sout.replace(k, v)

        print(s)
        print(sout)
        print('#' * 10)
        if SAFE:
            print(no_bc + eval(sout))
        print('#' * 10 + '\n')
Example #12
0
class test_plot_generic_loads(temp_cls):
    """tests for plot_generic_loads"""
    #    plot_generic_loads(load_triples, load_names, ylabels=None,
    #                        trange = None, H = 1.0, RLzero=None, prop_dict={})

    vs_time1 = PolyLine(np.array([0, 10]), np.array([0, 1]))
    vs_depth1 = PolyLine(np.array([0, 0.4, 1]), np.array([1.0, 1.0, 0.5]))
    omega_phase1 = (0.5, 0.3)
    triple1 = (vs_time1, vs_depth1, omega_phase1)

    vs_time2 = PolyLine(np.array([0, 9]), np.array([0, 2]))
    vs_depth2 = PolyLine(np.array([0, 0.4, 1]), np.array([1.0, 1.0, 0.8]))
    omega_phase2 = None
    triple2 = (vs_time2, vs_depth2, omega_phase2)

    load_names = ['a', 'b']

    def test_defaults(self):

        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names)

        assert_equal(len(fig.get_axes()), 4)

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]
        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]
        ax3 = fig.get_axes()[2]
        line3 = ax3.get_lines()[0]
        ax4 = fig.get_axes()[3]
        line4 = ax4.get_lines()[0]

        #first row of charts
        assert_allclose(line1.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line1.get_xydata()[-1],
                        np.array([10, 1 * np.cos(0.5 * 10 + 0.3)]))

        assert_allclose(line2.get_xydata()[0], np.array([1, 0]))
        assert_allclose(line2.get_xydata()[-1], np.array([0.5, 1]))

        #2nd row of charts
        assert_allclose(line3.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line3.get_xydata()[-1], np.array([9, 2]))

        assert_allclose(line4.get_xydata()[0], np.array([1, 0]))
        assert_allclose(line4.get_xydata()[-1], np.array([0.8, 1]))

        assert_equal(ax1.get_xlabel(), '')
        assert_equal(ax1.get_ylabel(), 'y0')
        assert_equal(ax2.get_xlabel(), '')
        assert_equal(ax2.get_ylabel(), 'Depth, z')

        assert_equal(ax3.get_xlabel(), 'Time')
        assert_equal(ax3.get_ylabel(), 'y1')
        assert_equal(ax4.get_xlabel(), 'Load factor')
        assert_equal(ax4.get_ylabel(), 'Depth, z')

        assert_equal(line1.get_label(), 'a0')
        assert_equal(line2.get_label(), 'a0')
        assert_equal(line3.get_label(), 'b0')
        assert_equal(line4.get_label(), 'b0')

        ok_(not ax1.get_legend() is None)
        ok_(not ax3.get_legend() is None)

    def test_ylabels(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 ylabels=['one', 'two'])

        ax1 = fig.get_axes()[0]
        ax3 = fig.get_axes()[2]

        assert_equal(ax1.get_ylabel(), 'one')
        assert_equal(ax3.get_ylabel(), 'two')

    def test_trange(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 trange=(2, 3))

        ax1 = fig.get_axes()[0]
        ax3 = fig.get_axes()[2]

        assert_allclose(ax1.get_xlim(), (2, 3))
        assert_allclose(ax3.get_xlim(), (2, 3))

    def test_H(self):

        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 H=2.0)

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]
        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]
        ax3 = fig.get_axes()[2]
        line3 = ax3.get_lines()[0]
        ax4 = fig.get_axes()[3]
        line4 = ax4.get_lines()[0]

        #first row of charts
        assert_allclose(line1.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line1.get_xydata()[-1],
                        np.array([10, 1 * np.cos(0.5 * 10 + 0.3)]))

        assert_allclose(line2.get_xydata()[0], np.array([1, 0]))
        assert_allclose(line2.get_xydata()[-1], np.array([0.5, 2]))

        #2nd row of charts
        assert_allclose(line3.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line3.get_xydata()[-1], np.array([9, 2]))

        assert_allclose(line4.get_xydata()[0], np.array([1, 0]))
        assert_allclose(line4.get_xydata()[-1], np.array([0.8, 2]))

    def test_RLzero(self):

        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 H=2.0,
                                 RLzero=1)

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]
        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]
        ax3 = fig.get_axes()[2]
        line3 = ax3.get_lines()[0]
        ax4 = fig.get_axes()[3]
        line4 = ax4.get_lines()[0]

        #first row of charts
        assert_allclose(line1.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line1.get_xydata()[-1],
                        np.array([10, 1 * np.cos(0.5 * 10 + 0.3)]))

        assert_allclose(line2.get_xydata()[0], np.array([1, 1]))
        assert_allclose(line2.get_xydata()[-1], np.array([0.5, -1]))

        #2nd row of charts
        assert_allclose(line3.get_xydata()[0], np.array([0, 0]))
        assert_allclose(line3.get_xydata()[-1], np.array([9, 2]))

        assert_allclose(line4.get_xydata()[0], np.array([1, 1]))
        assert_allclose(line4.get_xydata()[-1], np.array([0.8, -1]))

        assert_equal(ax2.get_ylabel(), 'RL')
        assert_equal(ax4.get_ylabel(), 'RL')

    def test_propdict_fig_prop_figsize(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 prop_dict={'fig_prop': {
                                     'figsize': (8, 9)
                                 }})

        assert_allclose(fig.get_size_inches(), (8, 9))

    def test_propdict_has_legend(self):

        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 prop_dict={'has_legend': False})
        ax1 = fig.get_axes()[0]
        ax3 = fig.get_axes()[2]

        assert_equal(ax1.get_legend(), None)
        assert_equal(ax3.get_legend(), None)

    def test_prop_dict_styles(self):
        fig = plot_generic_loads(
            [[self.triple1], [self.triple2]],
            load_names=self.load_names,
            prop_dict={
                'styles': [{
                    'markersize': 12,
                    'marker': '^'
                }, {
                    'markersize': 3,
                    'marker': 's'
                }]
            })

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]
        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]
        ax3 = fig.get_axes()[2]
        line3 = ax3.get_lines()[0]
        ax4 = fig.get_axes()[3]
        line4 = ax4.get_lines()[0]

        assert_equal(line1.get_marker(), '^')
        assert_equal(line1.get_markersize(), 12)
        assert_equal(line2.get_marker(), '^')
        assert_equal(line2.get_markersize(), 12)

        assert_equal(line3.get_marker(), 's')
        assert_equal(line3.get_markersize(), 3)
        assert_equal(line4.get_marker(), 's')
        assert_equal(line4.get_markersize(), 3)

    def test_prop_dict_time_axis_label(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 prop_dict={'time_axis_label': 'hello'})

        ax1 = fig.get_axes()[0]
        ax3 = fig.get_axes()[2]
        assert_equal(ax1.get_xlabel(), '')
        assert_equal(ax3.get_xlabel(), 'hello')

    def test_prop_dict_depth_axis_label(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 prop_dict={'depth_axis_label': 'hello'})

        ax2 = fig.get_axes()[1]
        ax4 = fig.get_axes()[3]
        assert_equal(ax2.get_xlabel(), '')
        assert_equal(ax4.get_xlabel(), 'hello')

    def test_propdict_legend_prop_title(self):
        fig = plot_generic_loads([[self.triple1], [self.triple2]],
                                 load_names=self.load_names,
                                 prop_dict={'legend_prop': {
                                     'title': 'abc'
                                 }})
        ax1 = fig.get_axes()[0]
        ax3 = fig.get_axes()[2]
        assert_equal(ax1.get_legend().get_title().get_text(), 'abc')
        assert_equal(ax3.get_legend().get_title().get_text(), 'abc')
Example #13
0
class test_plot_single_material_vs_depth(temp_cls):
    """tests for plot_single_material_vs_depth"""

    #    plot_single_material_vs_depth(z_x, xlabels, H = 1.0, RLzero=None,
    #                    prop_dict={})

    z1 = np.array([0., 0.5, 1.])
    x1 = np.array([1., 1.5, 2.])
    x2 = np.array([2., 2.5, 3.])

    a = PolyLine(z1, x1)
    b = PolyLine(z1, x2)

    xlabels = ['a', 'b']

    def test_defaults(self):
        fig = plot_single_material_vs_depth((self.a, self.b), self.xlabels)

        assert_equal(len(fig.get_axes()), 2)
        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]

        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]

        assert_allclose(line1.get_xydata()[0], np.array([1., 0.]))
        assert_allclose(line1.get_xydata()[-1], np.array([2., 1]))

        assert_allclose(line2.get_xydata()[0], np.array([2., 0.]))
        assert_allclose(line2.get_xydata()[-1], np.array([3., 1]))

        assert_equal(ax1.get_xlabel(), 'a')
        assert_equal(ax2.get_xlabel(), 'b')

        assert_equal(ax1.get_ylabel(), 'Depth, z')
        assert_equal(ax2.get_ylabel(), '')

    def test_prop_dict_ylabel(self):
        fig = plot_single_material_vs_depth((self.a, self.b),
                                            self.xlabels,
                                            prop_dict={'ylabel': 'hello'})
        ax1 = fig.get_axes()[0]

        assert_equal(ax1.get_ylabel(), 'hello')

    def test_H(self):

        fig = plot_single_material_vs_depth((self.a, self.b),
                                            self.xlabels,
                                            H=2)

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]

        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]

        assert_allclose(line1.get_xydata()[0], np.array([1., 0.]))
        assert_allclose(line1.get_xydata()[-1], np.array([2., 2]))

        assert_allclose(line2.get_xydata()[0], np.array([2., 0.]))
        assert_allclose(line2.get_xydata()[-1], np.array([3., 2]))

    def test_RLzero(self):

        fig = plot_single_material_vs_depth((self.a, self.b),
                                            self.xlabels,
                                            H=2,
                                            RLzero=1)

        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]

        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]

        assert_allclose(line1.get_xydata()[0], np.array([1., 1]))
        assert_allclose(line1.get_xydata()[-1], np.array([2., -1]))

        assert_allclose(line2.get_xydata()[0], np.array([2., 1]))
        assert_allclose(line2.get_xydata()[-1], np.array([3., -1]))

        assert_equal(ax1.get_ylabel(), 'RL')

    def test_propdict_fig_prop_figsize(self):
        fig = plot_single_material_vs_depth(
            (self.a, self.b),
            self.xlabels,
            prop_dict={'fig_prop': {
                'figsize': (8, 9)
            }})
        assert_allclose(fig.get_size_inches(), (8, 9))

    def test_prop_dict_styles(self):
        fig = plot_single_material_vs_depth(
            (self.a, self.b),
            self.xlabels,
            prop_dict={'styles': [{
                'markersize': 12,
                'marker': '^'
            }]})
        ax1 = fig.get_axes()[0]
        line1 = ax1.get_lines()[0]

        ax2 = fig.get_axes()[1]
        line2 = ax2.get_lines()[0]

        assert_equal(line1.get_marker(), '^')
        assert_equal(line1.get_markersize(), 12)
        assert_equal(line2.get_marker(), '^')
        assert_equal(line2.get_markersize(), 12)
Example #14
0
def test_SpecBeam_const_mat_deflection_shape_stationary_load():
    """static point load at beam centre, analytical vs numerical
    properties from moving load case (but with k3=0) in Figure 7 of ding et al"""

    # expected values are digitised from Ding et al 2012.
    expected_50terms_x = np.array([
        70.68, 71.275, 71.785, 72.189, 72.529, 72.848, 73.209, 73.677, 74.06,
        74.378, 74.74, 75.122, 75.505, 75.781, 76.079, 76.312, 76.525, 76.716,
        76.95, 77.12, 77.418, 77.715, 77.907, 78.204, 78.459, 78.778, 79.224,
        79.522, 79.883, 80.181, 80.436, 80.606, 80.776, 81.01, 81.137, 81.307,
        81.477, 81.626, 81.902, 82.179, 82.497, 82.774, 82.986, 83.263, 83.539,
        84.028, 84.368, 84.623, 84.878, 85.239, 85.728, 86.153, 86.684, 87.386,
        87.853, 88.363, 88.81, 89.341, 89.788
    ])

    # this was generated with use_analytical=False
    expected_50terms_displacement = np.array([
        1.65264432e-04, 2.63028987e-04, 2.72285077e-04, 2.14305202e-04,
        1.15107602e-04, -2.68417019e-05, -1.91982014e-04, -4.49035633e-04,
        -6.36376878e-04, -7.29821557e-04, -8.36195689e-04, -7.26860083e-04,
        -5.95623829e-04, -3.27010071e-04, 3.04509524e-05, 3.09942290e-04,
        6.76583319e-04, 1.05404663e-03, 1.51648858e-03, 1.85245069e-03,
        2.52742529e-03, 3.22449986e-03, 3.67513393e-03, 4.31941644e-03,
        4.85502315e-03, 5.52505664e-03, 6.09193410e-03, 6.46152111e-03,
        6.55576573e-03, 6.55576573e-03, 6.51361055e-03, 6.30277232e-03,
        6.09193410e-03, 5.80172148e-03, 5.64421292e-03, 5.34652107e-03,
        4.98944993e-03, 4.67648758e-03, 4.09677209e-03, 3.47328742e-03,
        2.72692475e-03, 2.07679122e-03, 1.64296844e-03, 1.09554783e-03,
        5.50103467e-04, -9.78991467e-05, -5.05740583e-04, -6.39483464e-04,
        -7.26860083e-04, -8.42366564e-04, -6.98673331e-04, -5.42409810e-04,
        -2.50752820e-04, 7.72841199e-05, 2.20332813e-04, 2.93525229e-04,
        2.50445556e-04, 1.59399796e-04, 3.45668416e-05
    ])

    #no longer correct:
    expected_200terms_x = np.array([
        70.064, 70.404, 70.723, 71.02, 71.36, 71.679, 71.955, 72.317, 72.614,
        72.976, 73.273, 73.571, 73.911, 74.23, 74.527, 74.867, 75.165, 75.505,
        75.866, 76.164, 76.483, 76.801, 77.12, 77.418, 77.779, 78.098, 78.438,
        78.693, 79.033, 79.352, 79.671, 79.989, 80.308, 80.648, 80.967, 81.286,
        81.583, 81.924, 82.264, 82.582, 82.88, 83.199, 83.539, 83.815, 84.134,
        84.495, 84.793, 85.112, 85.43, 85.749, 86.047, 86.429, 86.727, 87.046,
        87.365, 87.683, 87.981, 88.342, 88.64, 88.959, 89.277, 89.617, 89.958
    ])

    expected_200terms_displacement = np.array([
        -2.90800000e-05, -2.90800000e-05, -6.13900000e-05, -7.75400000e-05,
        -7.75400000e-05, -1.09900000e-04, -1.26000000e-04, -1.26000000e-04,
        -1.26000000e-04, -1.42200000e-04, -1.09900000e-04, -1.09900000e-04,
        -9.37000000e-05, -2.90800000e-05, 3.55400000e-05, 1.64800000e-04,
        2.94000000e-04, 4.55600000e-04, 7.30200000e-04, 1.02100000e-03,
        1.40900000e-03, 1.86100000e-03, 2.37800000e-03, 2.99200000e-03,
        3.68700000e-03, 4.43000000e-03, 5.22100000e-03, 5.96400000e-03,
        6.67500000e-03, 7.27300000e-03, 7.58000000e-03, 7.48300000e-03,
        6.95000000e-03, 6.06100000e-03, 4.99500000e-03, 3.88000000e-03,
        2.83000000e-03, 1.94200000e-03, 1.16600000e-03, 5.20200000e-04,
        5.17000000e-05, -2.55300000e-04, -4.33000000e-04, -5.46000000e-04,
        -5.78400000e-04, -5.62200000e-04, -4.81400000e-04, -4.33000000e-04,
        -3.19900000e-04, -2.39100000e-04, -1.74500000e-04, -1.26000000e-04,
        -4.52300000e-05, -1.29200000e-05, 1.93900000e-05, 1.93900000e-05,
        3.55400000e-05, 6.78500000e-05, 3.55400000e-05, 5.17000000e-05,
        3.55400000e-05, 1.93900000e-05, 1.93900000e-05
    ])

    t = np.linspace(0, 160 / 2 / 20, 400)

    xvals = np.linspace(0, 160, 200)
    #see Dingetal2012 Table 2 for material properties
    pdict = OrderedDict(
        E=6.998 * 1e9,  #Pa
        rho=2373,  #kg/m3
        L=160,  #m
        #v_norm=0.01165,
        kf=5.41e-4,
        #Fz_norm=1.013e-4,
        mu_norm=39.263,
        k1_norm=97.552,
        #k3_norm=2.497e6,
        nterms=50,
        BC="SS",
        nquad=20,
        #            moving_loads_x_norm=[[0]],
        #            moving_loads_Fz_norm=[[1.013e-4]],
        #            moving_loads_v_norm=[0.01165,],
        #            stationary_loads_x=None,
        #            stationary_loads_vs_t=None,
        #            stationary_loads_omega_phase=None,
        stationary_loads_x_norm=[0.5],
        stationary_loads_vs_t_norm=[
            PolyLine([0, t[-1] / 160 * np.sqrt(6.998 * 1e9 / 2373.)],
                     [1.013e-4, 1.013e-4])
        ],
        #self.L * np.sqrt(self.E / self.rho)
        #            stationary_loads_omega_phase_norm=None,
        tvals=t,
        xvals=xvals,
        use_analytical=False,
        implementation="vectorized",
        #            implementation="fortran",
    )

    a = SpecBeam(**pdict)
    a.runme()

    #    a = SpecBeam(**pdict)
    #
    #    a.calulate_qk(t=t)

    yall = a.defl[:,
                  -1]  #a.wofx(x=xvals, tslice=slice(-1, None, None), normalise_w=False)[:,0]
    ycompare = np.interp(expected_50terms_x, xvals, yall)
    print(repr(ycompare))

    if DEBUG:

        title = 'SpecBeam, stationary load, analytical vs numerical, deflection shape for point load applied at midpoint\n prop from moving load Figure 7 of Ding et al (2012)'
        print(title)
        print(' '.join(['{:>9s}'] * 4).format('t', 'expect', 'calc', 'diff'))
        for i, j, k in zip(expected_50terms_x, expected_50terms_displacement,
                           ycompare):
            print(' '.join(['{:9.4f}'] * 4).format(i, j, k, j - k))
        print()

        fig = plt.figure(figsize=(10, 6))
        ax = fig.add_subplot("111")
        ax.set_xlabel("x, m")
        ax.set_ylabel("w, m")
        ax.set_xlim(70, 90)
        ax.set_title(title)

        ax.plot(expected_50terms_x,
                expected_50terms_displacement,
                label="expect n=50",
                color='green',
                marker='o',
                ls='-')
        ax.plot(expected_200terms_x,
                expected_200terms_displacement,
                label="expect n=200",
                color='black',
                marker=None,
                ls='-')

        ax.plot(xvals, yall, label="calc n=50")
        ax.plot(expected_50terms_x,
                ycompare,
                label="calc, n=50 (compare)",
                color='red',
                marker='s',
                ms=4,
                ls=':')
        ax.grid()
        leg = ax.legend(loc='upper left')
        leg.draggable()

        plt.show()

    assert_allclose(expected_50terms_displacement, ycompare, atol=2.4e-4)
Example #15
0
def test_SpecBeam_const_mat_midpoint_defl_runme_analytical_200():
    """Test SpecBeam for constant mat: close to Ding et al Figure 8, displacement vs time at
    beam midpoint (using the runme method) but with k3=0"""

    start_time0 = time.time()
    ftime = datetime.datetime.fromtimestamp(start_time0).strftime(
        '%Y-%m-%d %H%M%S')

    # expected values are digitised from Ding et al 2012.
    expected_50terms_t = np.array([
        3.511, 3.553, 3.576, 3.605, 3.621, 3.637, 3.651, 3.661, 3.676, 3.693,
        3.701, 3.717, 3.733, 3.743, 3.761, 3.777, 3.79, 3.804, 3.822, 3.833,
        3.848, 3.862, 3.877, 3.899, 3.919, 3.94, 3.956, 3.97, 3.978, 3.99,
        4.001, 4.014, 4.025, 4.041, 4.052, 4.064, 4.076, 4.086, 4.094, 4.104,
        4.112, 4.123, 4.134, 4.146, 4.159, 4.172, 4.18, 4.192, 4.212, 4.221,
        4.234, 4.255, 4.273, 4.292, 4.324, 4.357, 4.373, 4.399, 4.418, 4.445
    ])

    #old values for k3~=0
    #    expected_50terms_displacement = np.array(
    #      [ -1.30900000e-04,   8.85900000e-05,   2.63900000e-04,
    #         3.30200000e-04,   3.30500000e-04,   2.87100000e-04,
    #         2.00000000e-04,   9.09500000e-05,  -8.36000000e-05,
    #        -3.01800000e-04,  -4.32800000e-04,  -6.07300000e-04,
    #        -7.59900000e-04,  -8.90900000e-04,  -9.99800000e-04,
    #        -1.02100000e-03,  -9.99100000e-04,  -8.67700000e-04,
    #        -5.61300000e-04,  -2.11300000e-04,   2.04300000e-04,
    #         7.29200000e-04,   1.42900000e-03,   2.41300000e-03,
    #         3.46300000e-03,   4.29400000e-03,   5.08100000e-03,
    #         5.62800000e-03,   5.86800000e-03,   6.19600000e-03,
    #         6.39300000e-03,   6.52500000e-03,   6.59100000e-03,
    #         6.48200000e-03,   6.32900000e-03,   6.02300000e-03,
    #         5.69600000e-03,   5.45500000e-03,   5.06200000e-03,
    #         4.75600000e-03,   4.40700000e-03,   3.90400000e-03,
    #         3.35800000e-03,   2.87800000e-03,   2.35300000e-03,
    #         1.82900000e-03,   1.52300000e-03,   9.98700000e-04,
    #         5.18300000e-04,   2.12500000e-04,  -4.95200000e-05,
    #        -2.67600000e-04,  -3.76500000e-04,  -3.76100000e-04,
    #        -2.00600000e-04,   1.87300000e-05,   1.06500000e-04,
    #         1.94500000e-04,   1.94900000e-04,   1.30000000e-04])

    expected_50terms_displacement = np.array([
        -1.74400116e-05, 2.56595529e-04, 3.64963938e-04, 3.96163257e-04,
        3.52239419e-04, 2.55908617e-04, 1.36296573e-04, 3.12193756e-05,
        -1.48035583e-04, -3.73050108e-04, -4.80427236e-04, -6.84847774e-04,
        -8.61705766e-04, -9.44268811e-04, -1.02333177e-03, -1.00753661e-03,
        -9.18192599e-04, -7.32771117e-04, -3.72382730e-04, -7.79760498e-05,
        4.06998900e-04, 9.37679667e-04, 1.57072235e-03, 2.58323632e-03,
        3.52928135e-03, 4.47726082e-03, 5.12406706e-03, 5.61329890e-03,
        5.84231170e-03, 6.13309619e-03, 6.32505191e-03, 6.46203546e-03,
        6.49032925e-03, 6.39329339e-03, 6.23960924e-03, 5.99242067e-03,
        5.67177967e-03, 5.35598822e-03, 5.07919623e-03, 4.69552191e-03,
        4.37030991e-03, 3.90678952e-03, 3.43034780e-03, 2.90774639e-03,
        2.35231514e-03, 1.82145021e-03, 1.51724930e-03, 1.09014092e-03,
        4.86434682e-04, 2.61200867e-04, -5.02752907e-06, -2.99906282e-04,
        -4.26188536e-04, -4.46910518e-04, -3.09328219e-04, -6.53887601e-05,
        4.77786782e-05, 1.84483472e-04, 2.30390682e-04, 2.18090273e-04
    ])

    expected_200terms_t = np.array([
        3.503, 3.519, 3.539, 3.556, 3.576, 3.595, 3.613, 3.632, 3.651, 3.667,
        3.69, 3.708, 3.727, 3.746, 3.766, 3.782, 3.801, 3.822, 3.84, 3.856,
        3.878, 3.896, 3.915, 3.933, 3.951, 3.97, 3.99, 4.009, 4.027, 4.046,
        4.067, 4.085, 4.102, 4.122, 4.141, 4.159, 4.178, 4.197, 4.217, 4.234,
        4.252, 4.273, 4.291, 4.31, 4.329, 4.347, 4.368, 4.386, 4.405, 4.423,
        4.442, 4.46, 4.479, 4.495
    ])

    expected_200terms_displacement = np.array([
        7.04000000e-08, 2.22800000e-05, 2.27000000e-05, 1.23200000e-06,
        2.35100000e-05, 2.39300000e-05, 2.46400000e-06, -1.89700000e-05,
        -6.22700000e-05, -1.27500000e-04, -1.70700000e-04, -2.57800000e-04,
        -3.44800000e-04, -4.53600000e-04, -5.40600000e-04, -5.84000000e-04,
        -5.61700000e-04, -4.73800000e-04, -2.54900000e-04, 1.17100000e-04,
        6.85900000e-04, 1.51700000e-03, 2.50100000e-03, 3.70300000e-03,
        5.01500000e-03, 6.26200000e-03, 7.20200000e-03, 7.61800000e-03,
        7.39900000e-03, 6.74400000e-03, 5.91400000e-03, 5.01800000e-03,
        4.10100000e-03, 3.22700000e-03, 2.50600000e-03, 1.85000000e-03,
        1.32600000e-03, 9.11400000e-04, 5.84000000e-04, 3.00200000e-04,
        1.47600000e-04, 3.87500000e-05, -4.82900000e-05, -1.13400000e-04,
        -1.13000000e-04, -1.34500000e-04, -1.34000000e-04, -1.33600000e-04,
        -1.11400000e-04, -6.72600000e-05, -6.68400000e-05, -6.64500000e-05,
        -4.41700000e-05, -4.38200000e-05
    ])

    t = np.linspace(0, 4.5, 400)

    #see Dingetal2012 Table 2 for material properties
    pdict = OrderedDict(
        E=6.998 * 1e9,  #Pa
        rho=2373,  #kg/m3
        L=160,  #m
        #v_norm=0.01165,
        kf=5.41e-4,
        #Fz_norm=1.013e-4,
        mu_norm=39.263,
        k1_norm=97.552,
        #            k3_norm=2.497e6,
        nterms=200,
        BC="SS",
        nquad=20,
        k1bar=PolyLine([0, 0.5], [0.5, 1], [1, 1], [1, 1]),
        #            k1bar=PolyLine([0,0.5],[0.5,1],[2,1],[2,1]),
        moving_loads_x_norm=[[0]],
        moving_loads_Fz_norm=[[1.013e-4]],
        moving_loads_v_norm=[
            0.01165,
        ],
        tvals=t,
        #            tvals=np.array([4.0]),
        xvals_norm=np.array([0.5]),
        use_analytical=True,
        implementation="vectorized",
        #            implementation="fortran",
        force_calc=True,
    )

    a = SpecBeam(**pdict)
    a.runme()

    #    a.calulate_qk(t=t)
    #
    #    yall = a.wofx(x_norm=0.5, normalise_w=False)
    ycompare = np.interp(expected_200terms_t, t, a.defl[0, :])
    #    print(repr(ycompare))

    print("n=", pdict['nterms'])
    end_time0 = time.time()
    elapsed_time = (end_time0 - start_time0)
    print("Total run time={}".format(str(timedelta(seconds=elapsed_time))))

    if DEBUG:

        title = 'SpecBeam, const mat prop vs Ding et al (2012) \nFigure 8 Displacement at Midpoint of beam but with k3=0'
        print(title)
        print(' '.join(['{:>9s}'] * 4).format('t', 'expect', 'calc', 'diff'))
        for i, j, k in zip(expected_200terms_t, expected_200terms_displacement,
                           ycompare):
            print(' '.join(['{:9.4f}'] * 4).format(i, j, k, j - k))
        print()

        fig = plt.figure(figsize=(10, 6))
        ax = fig.add_subplot("111")
        ax.set_xlabel("time, s")
        ax.set_ylabel("w, m")
        ax.set_xlim(3.5, 4.5)
        ax.set_title(title)

        ax.plot(expected_50terms_t,
                expected_50terms_displacement,
                label="expect n=50",
                color='green',
                marker='o',
                ls='-')
        ax.plot(expected_200terms_t,
                expected_200terms_displacement,
                label="expect n=200",
                color='black',
                marker=None,
                ls='-')

        ax.plot(t, a.defl, label="calc n=200")
        ax.plot(expected_200terms_t,
                ycompare,
                label="calc, n=200 (compare)",
                color='red',
                marker='s',
                ms=4,
                ls=':')

        leg = ax.legend(loc='upper left')
        leg.draggable()

        plt.show()

    assert_allclose(expected_200terms_displacement, ycompare, atol=2.4e-4)
Example #16
0
def test_SpecBeam_const_mat_midpoint_defl():
    """Test SpecBeam for constant mat: Figure 8, displacement vs time at beam midpoint"""

    # expected values are digitised from Ding et al 2012.
    expected_50terms_t = np.array([
        3.511, 3.553, 3.576, 3.605, 3.621, 3.637, 3.651, 3.661, 3.676, 3.693,
        3.701, 3.717, 3.733, 3.743, 3.761, 3.777, 3.79, 3.804, 3.822, 3.833,
        3.848, 3.862, 3.877, 3.899, 3.919, 3.94, 3.956, 3.97, 3.978, 3.99,
        4.001, 4.014, 4.025, 4.041, 4.052, 4.064, 4.076, 4.086, 4.094, 4.104,
        4.112, 4.123, 4.134, 4.146, 4.159, 4.172, 4.18, 4.192, 4.212, 4.221,
        4.234, 4.255, 4.273, 4.292, 4.324, 4.357, 4.373, 4.399, 4.418, 4.445
    ])

    expected_50terms_displacement = np.array([
        -1.30900000e-04, 8.85900000e-05, 2.63900000e-04, 3.30200000e-04,
        3.30500000e-04, 2.87100000e-04, 2.00000000e-04, 9.09500000e-05,
        -8.36000000e-05, -3.01800000e-04, -4.32800000e-04, -6.07300000e-04,
        -7.59900000e-04, -8.90900000e-04, -9.99800000e-04, -1.02100000e-03,
        -9.99100000e-04, -8.67700000e-04, -5.61300000e-04, -2.11300000e-04,
        2.04300000e-04, 7.29200000e-04, 1.42900000e-03, 2.41300000e-03,
        3.46300000e-03, 4.29400000e-03, 5.08100000e-03, 5.62800000e-03,
        5.86800000e-03, 6.19600000e-03, 6.39300000e-03, 6.52500000e-03,
        6.59100000e-03, 6.48200000e-03, 6.32900000e-03, 6.02300000e-03,
        5.69600000e-03, 5.45500000e-03, 5.06200000e-03, 4.75600000e-03,
        4.40700000e-03, 3.90400000e-03, 3.35800000e-03, 2.87800000e-03,
        2.35300000e-03, 1.82900000e-03, 1.52300000e-03, 9.98700000e-04,
        5.18300000e-04, 2.12500000e-04, -4.95200000e-05, -2.67600000e-04,
        -3.76500000e-04, -3.76100000e-04, -2.00600000e-04, 1.87300000e-05,
        1.06500000e-04, 1.94500000e-04, 1.94900000e-04, 1.30000000e-04
    ])

    expected_200terms_t = np.array([
        3.503, 3.519, 3.539, 3.556, 3.576, 3.595, 3.613, 3.632, 3.651, 3.667,
        3.69, 3.708, 3.727, 3.746, 3.766, 3.782, 3.801, 3.822, 3.84, 3.856,
        3.878, 3.896, 3.915, 3.933, 3.951, 3.97, 3.99, 4.009, 4.027, 4.046,
        4.067, 4.085, 4.102, 4.122, 4.141, 4.159, 4.178, 4.197, 4.217, 4.234,
        4.252, 4.273, 4.291, 4.31, 4.329, 4.347, 4.368, 4.386, 4.405, 4.423,
        4.442, 4.46, 4.479, 4.495
    ])

    expected_200terms_displacement = np.array([
        7.04000000e-08, 2.22800000e-05, 2.27000000e-05, 1.23200000e-06,
        2.35100000e-05, 2.39300000e-05, 2.46400000e-06, -1.89700000e-05,
        -6.22700000e-05, -1.27500000e-04, -1.70700000e-04, -2.57800000e-04,
        -3.44800000e-04, -4.53600000e-04, -5.40600000e-04, -5.84000000e-04,
        -5.61700000e-04, -4.73800000e-04, -2.54900000e-04, 1.17100000e-04,
        6.85900000e-04, 1.51700000e-03, 2.50100000e-03, 3.70300000e-03,
        5.01500000e-03, 6.26200000e-03, 7.20200000e-03, 7.61800000e-03,
        7.39900000e-03, 6.74400000e-03, 5.91400000e-03, 5.01800000e-03,
        4.10100000e-03, 3.22700000e-03, 2.50600000e-03, 1.85000000e-03,
        1.32600000e-03, 9.11400000e-04, 5.84000000e-04, 3.00200000e-04,
        1.47600000e-04, 3.87500000e-05, -4.82900000e-05, -1.13400000e-04,
        -1.13000000e-04, -1.34500000e-04, -1.34000000e-04, -1.33600000e-04,
        -1.11400000e-04, -6.72600000e-05, -6.68400000e-05, -6.64500000e-05,
        -4.41700000e-05, -4.38200000e-05
    ])

    t = np.linspace(0, 4.5, 400)

    #see Dingetal2012 Table 2 for material properties
    pdict = OrderedDict(
        E=6.998 * 1e9,  #Pa
        rho=2373,  #kg/m3
        L=160,  #m
        #v_norm=0.01165,
        kf=5.41e-4,
        #Fz_norm=1.013e-4,
        mu_norm=39.263,
        k1_norm=97.552,
        k3_norm=2.497e6,
        nterms=50,
        BC="SS",
        nquad=20,
        k1bar=PolyLine([0, 0.5], [0.5, 1], [1, 1], [1, 1]),
        moving_loads_x_norm=[[0]],
        moving_loads_Fz_norm=[[1.013e-4]],
        moving_loads_v_norm=[
            0.01165,
        ],
        tvals=t,
        xvals_norm=0.5)

    a = SpecBeam(**pdict)
    a.calulate_qk(t=t)

    yall = a.wofx(x_norm=0.5, normalise_w=False)
    ycompare = np.interp(expected_50terms_t, t, yall)

    if DEBUG:

        title = 'SpecBeam, const mat prop vs Ding et al (2012) \nFigure 8 Displacement at Midpoint of beam'
        print(title)
        print(' '.join(['{:>9s}'] * 4).format('t', 'expect', 'calc', 'diff'))
        for i, j, k in zip(expected_50terms_t, expected_50terms_displacement,
                           ycompare):
            print(' '.join(['{:9.4f}'] * 4).format(i, j, k, j - k))
        print()

        fig = plt.figure(figsize=(10, 6))
        ax = fig.add_subplot("111")
        ax.set_xlabel("time, s")
        ax.set_ylabel("w, m")
        ax.set_xlim(3.5, 4.5)
        ax.set_title(title)

        ax.plot(expected_50terms_t,
                expected_50terms_displacement,
                label="expect n=50",
                color='green',
                marker='o',
                ls='-')
        ax.plot(expected_200terms_t,
                expected_200terms_displacement,
                label="expect n=200",
                color='black',
                marker=None,
                ls='-')

        ax.plot(t, yall, label="calc n=50")
        ax.plot(expected_50terms_t,
                ycompare,
                label="calc, n=50 (compare)",
                color='red',
                marker='s',
                ms=4,
                ls=':')

        leg = ax.legend(loc='upper left')
        leg.draggable()

        plt.show()

    assert_allclose(expected_50terms_displacement, ycompare, atol=2.4e-4)
    x = np.zeros(len(alphas))
    y = np.zeros(len(alphas))
    for j, alpha in enumerate(alphas):

        v_crit = np.sqrt(2 / pdict["rho"] / pdict["A"] *
                         np.sqrt(pdict["k1"] * pdict["E"] * pdict["I"]))
        v_raw = v_crit * alpha

        c_crit = np.sqrt(4 * pdict["rho"] * pdict["A"] * pdict["k1"])
        c_raw = c_crit * beta

        tmax = pdict["L"] / v_raw

        if end_damp == 0:
            pdict["mu"] = c_raw
            pdict["mubar"] = PolyLine([0, 1], [1, 1])
        else:
            if beta == 0:
                pdict["mu"] = c_crit
                pdict["mubar"] = PolyLine(
                    [0, end_damp, end_damp, 1 - end_damp, 1 - end_damp, 1],
                    [1, 1, 0, 0, 1, 1])
            else:
                pdict["mu"] = c_raw
                pdict["mubar"] = PolyLine(
                    [0, end_damp, end_damp, 1 - end_damp, 1 - end_damp, 1], [
                        c_crit / c_raw, c_crit / c_raw, 1, 1, c_crit / c_raw,
                        c_crit / c_raw
                    ])

        pdict["tvals"] = np.linspace(tmax * xeval[0], tmax * xeval[1], nt)
Example #18
0
class test_dim1sin_integrate_af(unittest.TestCase):
    """tests for dim1sin_integrate_af

    see geotecha.speccon.test.speccon1d_test_data_gen.py
    for test case data generation

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time

    """
    #dim1sin_integrate_af(m, z, tvals, v_E_Igamv_the, drn, a, top_vs_time = None, bot_vs_time=None, top_omega_phase=None, bot_omega_phase=None)

#    artificallially create 3 eigs, 2 zs and 2 ts

    outz = np.array([[0.2, 0.4], [0.4, 0.6]])
    z1 = outz[:, 0]
    z2 = outz[:, 1]
    m = np.array([1.0,2.0, 3.0])
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    a = PolyLine([0, 1], [1, 2])# y = 1 + z
    g = np.array([1.0,2.0])# this is interpolated from top_vs_time at t = 1, 3

    def test_no_BC(self):
        #expected is from:

        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  a = self.a),

                                  np.array([[ 0.42612566,  0.42612566],
                                            [ 0.69057191,  0.69057191]]))

    def test_top_vs_time_drn_0(self):

        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  a=self.a,
                                  top_vs_time = [self.top_vs_time]),

                                  np.array([[ 0.60745899,  0.78879232],
                                            [ 0.83990524,  0.98923858]]))
#
    def test_top_vs_time_drn_1(self):
        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  a = self.a,
                                  top_vs_time = [self.top_vs_time]),

                                  np.array([[ 0.68612566,  0.94612566],
                                            [ 0.99057191,  1.29057191]]))
#
    def test_bot_vs_time_drn_0(self):


        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  a=self.a,
                                  bot_vs_time = [self.bot_vs_time]),

                                  np.array([[ 0.50479232,  0.58345899],
                                            [ 0.84123858,  0.99190524]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):


        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  a=self.a,
                                  top_vs_time = [self.top_vs_time],
                                  bot_vs_time = [self.bot_vs_time]),

                                  np.array([[ 0.76479232,  1.10345899],
                                            [ 1.14123858,  1.59190524]]))

    def test_top_vs_time_drn_0_omega_phase(self):


        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  a=self.a,
                                  top_vs_time = [self.top_vs_time],
                                  top_omega_phase=[self.omega_phase]),

                                  np.array([[ 0.24660702,  0.52900048],
                                            [ 0.54273303,  0.77529235]]))

    def test_bot_vs_time_drn_0_omega_phase(self):


        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  a=self.a,
                                  bot_vs_time = [self.bot_vs_time],
                                  bot_omega_phase=[self.omega_phase]),

                                  np.array([[ 0.34824625,  0.47075517],
                                            [ 0.54141304,  0.77604878]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):

        assert_allclose(dim1sin_integrate_af(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  a=self.a,
                                  top_vs_time = [self.top_vs_time, self.top_vs_time],
                                  bot_vs_time = [self.bot_vs_time, self.bot_vs_time]),

                                  np.array([[ 1.10345899,  1.78079232],
                                            [ 1.59190524,  2.49323858]]))
Example #19
0
 def test_check_attributes_that_should_have_same_x_limits(self):
     a = InputFileLoaderCheckerSaver()
     a.a = PolyLine([0, 1], [2, 5])
     a.c = PolyLine([0, 7], [5, 6])
     a._attributes_that_should_have_same_x_limits = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Example #20
0
class test_dim1sin_f(unittest.TestCase):
    """tests for dim1sin_f

    These are not exhasutive tests.

     - I've used top_vs_time=bot_vs_time, top_omega_phase=bot_omega_phase,
       so I can't tell if the code uses each correctly of if I've typed
       bot_vs_time instead of top_vs_time

    """
    #dim1sin_f(m, outz, tvals, v_E_Igamv_the, drn, top_vs_time, bot_vs_time, top_omega_phase, bot_omega_phase)

#    artificallially create 3 eigs, 2 zs and 2 ts

    outz = np.array([0.2, 0.4])
    m = np.array([1.0,2.0, 3.0]) #1x2
    v_E_Igamv_the = np.ones((3,2), dtype=float)
    tvals = np.array([1.0, 3])
    top_vs_time = PolyLine([0,2,4],[0,2,2])
    bot_vs_time = PolyLine([0,2,4],[0,2,2])
    omega_phase = (1,2)
    def test_no_BC(self):
        #expected is from:
        #np.dot(np.sin(outz[:,np.newaxis] * m[np.newaxis,:]), v_E_Igamv_the)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0),

                                  np.array([[ 1.15273015,  1.15273015],
                                            [ 2.03881352,  2.03881352]]))
    def test_top_vs_time_drn_0(self):
        #expected is from:
        #test no_bc + top_vs time interplolated at tvals and depth z (mag_vs_depth reduces to zero at bottom)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  top_vs_time = [self.top_vs_time]),

                                  np.array([[ 1*0.8+1.15273015,  2*0.8+1.15273015],
                                            [ 1*0.6+2.03881352,  2*0.6+2.03881352]]))

    def test_top_vs_time_drn_1(self):
        #expected is from:
        #test no_bc + top_vs time interplolated at tvals and depth z (mag vs depth is uniform top to bottom)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  top_vs_time = [self.top_vs_time]),

                                  np.array([[ 1+1.15273015,  2+1.15273015],
                                            [ 1+2.03881352,  2+2.03881352]]))

    def test_bot_vs_time_drn_0(self):
        #expected is from:
        #test no_bc + bot_vs time interplolated at tvals and depth z (mag_vs_depth reduces to zero at top)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  bot_vs_time = [self.bot_vs_time]),

                                  np.array([[ 1*0.2+1.15273015,  2*0.2+1.15273015],
                                            [ 1*0.4+2.03881352,  2*0.4+2.03881352]]))

    def test_bot_vs_time_top_vs_time_drn_1(self):
        #expected is from:
        #test no_bc + top_vs_time and bot_vs time interplolated at tvals and depth z (mag_vs_depth is uniform from top plus reduces to zero at top)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  top_vs_time = [self.top_vs_time],
                                  bot_vs_time = [self.bot_vs_time]),

                                  np.array([[ 1+1*0.2+1.15273015,  2+2*0.2+1.15273015],
                                            [ 1+1*0.4+2.03881352,  2+2*0.4+2.03881352]]))

    def test_top_vs_time_drn_0_omega_phase(self):
        #expected is from:
        #test no_bc + cos(omega*t+phase)  multiplied top_vs time interplolated at tvals and depth z (mag_vs_depth reduces to zero at bottom)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  top_vs_time = [self.top_vs_time],
                                  top_omega_phase=[self.omega_phase]),

                                  np.array([[ 1*0.8*np.cos(1*1+2)+1.15273015,  2*0.8*np.cos(1*3+2)+1.15273015],
                                            [ 1*0.6*np.cos(1*1+2)+2.03881352,  2*0.6*np.cos(1*3+2)+2.03881352]]))
    def test_bot_vs_time_drn_0_omega_phase(self):
        #expected is from:
        #test no_bc + bot_vs time interplolated at tvals and depth z (mag_vs_depth reduces to zero at top)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=0,
                                  bot_vs_time = [self.bot_vs_time],
                                  bot_omega_phase=[self.omega_phase]),

                                  np.array([[ 1*0.2*np.cos(1*1+2)+1.15273015,  2*0.2*np.cos(1*3+2)+1.15273015],
                                            [ 1*0.4*np.cos(1*1+2)+2.03881352,  2*0.4*np.cos(1*3+2)+2.03881352]]))

    def test_bot_vs_time_top_vs_time_drn_1_double_loads(self):
        #expected is from:
        #test no_bc + top_vs_time and bot_vs time interplolated at tvals and depth z (mag_vs_depth is uniform from top plus reduces to zero at top)

        assert_allclose(dim1sin_f(self.m,
                                  self.outz,
                                  self.tvals,
                                  self.v_E_Igamv_the,
                                  drn=1,
                                  top_vs_time = [self.top_vs_time, self.top_vs_time],
                                  bot_vs_time = [self.bot_vs_time, self.bot_vs_time]),

                                  np.array([[ 2+2*0.2+1.15273015,  4+4*0.2+1.15273015],
                                            [ 2+2*0.4+2.03881352,  4+4*0.4+2.03881352]]))