Example #1
0
    def test_e_arr(self):
        '''Check the convenience constructor for evars
        '''
        #===========================================================================
        # Control variable
        #===========================================================================
        e_arr = np.linspace(0, 0.012, 2)

        m_la, std_la = 10., 1.0
        m_xi, std_xi = 1.0, 0.1

        #===========================================================================
        # Randomization
        #===========================================================================

        s = SPIRRID(
            q=fiber_tt_2p(),
            e_arr=e_arr,
            codegen_type='numpy',
            n_int=10,
            tvars=dict(la=m_la, xi=m_xi),
        )

        max_mu_q = np.max(s.mu_q_arr)
        self.assertAlmostEqual(max_mu_q, 0.12000000000000001, 10)
Example #2
0
def create_demo_object():

    #===========================================================================
    # Control variable
    #===========================================================================
    e_arr = np.linspace(0, 0.012, 80)

    powers = np.linspace(1, math.log(20, 10), 6)
    n_int_range = np.array(np.power(10, powers), dtype=int)

    #===========================================================================
    # Randomization
    #===========================================================================
    tvars = dict(
        fu=RV('weibull_min', 1200.0e6, 200.),
        qf=1500.0,
        # qf = RV('uniform', 1500., 100.),
        L=0.02,  # 
        # L = RV('uniform', 0.02, 0.02 / 2.),
        A=RV('norm', 5.30929158457e-10, .03 * 5.30929158457e-10),
        E_mod=RV('uniform', 70.e9, 250.e9),
        z=RV('uniform', 0.0, 0.03),
        phi=0.0,  # 
        # phi = RV('cos_distr', 0.0, 1.0),
        # phi = RV('uniform', 0.0, 1.0),
        f=RV('uniform', 0.0, 0.03))

    #===========================================================================
    # Integrator object
    #===========================================================================
    s = SPIRRID(
        q=ConstantFrictionFiniteFiber(),
        e_arr=e_arr,
        n_int=10,
        tvars=tvars,
    )

    #===========================================================================
    # Lab
    #===========================================================================
    slab = SPIRRIDLAB(s=s,
                      save_output=False,
                      show_output=True,
                      dpi=300,
                      qname='fiber_po_8p',
                      plot_mode='subplots',
                      n_int_range=n_int_range,
                      extra_compiler_args=True,
                      le_sampling_lst=['LHS', 'PGrid'],
                      le_n_int_lst=[10, 10],
                      plot_sampling_idx=[
                          0,
                          3,
                      ])

    return slab
Example #3
0
    def setup_class(cls):

        np.random.seed(2356)

        #===========================================================================
        # Control variable
        #===========================================================================
        e_arr = np.linspace(0, 0.012, 80)

        cls.m_la, cls.std_la = 10., 1.0
        cls.m_xi, cls.std_xi = 1.0, 0.1

        #===========================================================================
        # Randomization
        #===========================================================================

        cls.s = SPIRRID(
            q=fiber_tt_2p(),
            evars={'e': e_arr},
            codegen_type='numpy',
            n_int=10,
            tvars=dict(la=RV('norm', cls.m_la, cls.std_la),
                       xi=RV('norm', cls.m_xi, cls.std_xi)),
        )
Example #4
0
def create_demo_object():

    D = 26 * 1.0e-6  # m
    A = (D / 2.0)**2 * math.pi

    # set the mean and standard deviation of the two random variables
    la_mean, la_stdev = 0.0, 0.2
    xi_mean, xi_stdev = 0.019027, 0.0022891
    E_mean, E_stdev = 70.0e+9, 15.0e+9
    th_mean, th_stdev = 0.0, 0.01
    A_mean, A_stdev = A * 0.3, 0.7 * A

    do = 'norm'

    if do == 'general':

        # set the mean and standard deviation of the two random variables
        la_mean, la_stdev = 0.0, 0.2
        xi_mean, xi_stdev = 0.019027, 0.0022891
        E_mean, E_stdev = 70.0e+9, 15.0e+9
        th_mean, th_stdev = 0.0, 0.01
        A_mean, A_stdev = A * 0.3, 0.7 * A

        # construct the normal distributions and get the methods
        # for the evaluation of the probability density functions
        g_la = RV('uniform', la_mean, la_stdev)
        g_xi = RV('norm', xi_mean, xi_stdev)
        g_E = RV('uniform', E_mean, E_stdev)
        g_th = RV('uniform', th_mean, th_stdev)
        g_A = RV('uniform', A_mean, A_stdev)

        mu_ex_file = 'fiber_tt_5p_30.txt'
        delimiter = ','

    elif do == 'uniform':

        # set the mean and standard deviation of the two random variables
        la_mean, la_stdev = 0.0, 0.2
        xi_mean, xi_stdev = 0.01, 0.02
        E_mean, E_stdev = 70.0e+9, 15.0e+9
        th_mean, th_stdev = 0.0, 0.01
        A_mean, A_stdev = A * 0.3, 0.7 * A

        # construct the uniform distributions and get the methods
        # for the evaluation of the probability density functions
        g_la = RV('uniform', la_mean, la_stdev)
        g_xi = RV('uniform', xi_mean, xi_stdev)
        g_E = RV('uniform', E_mean, E_stdev)
        g_th = RV('uniform', th_mean, th_stdev)
        g_A = RV('uniform', A_mean, A_stdev)

        mu_ex_file = 'fiber_tt_5p_40_unif.txt'
        delimiter = ' '

    elif do == 'norm':

        # set the mean and standard deviation of the two random variables
        la_mean, la_stdev = 0.1, 0.02
        xi_mean, xi_stdev = 0.019027, 0.0022891
        E_mean, E_stdev = 70.0e+9, 15.0e+9
        th_mean, th_stdev = 0.005, 0.001
        A_mean, A_stdev = 5.3e-10, 1.0e-11

        # construct the normal distributions and get the methods
        # for the evaluation of the probability density functions
        g_la = RV('norm', la_mean, la_stdev)
        g_xi = RV('norm', xi_mean, xi_stdev)
        g_E = RV('norm', E_mean, E_stdev)
        g_th = RV('norm', th_mean, th_stdev)
        g_A = RV('norm', A_mean, A_stdev)

        mu_ex_file = os.path.join(file_dir,
                                  'fiber_tt_5p_n_int_40_norm_exact.txt')
        delimiter = ' '

    # discretize the control variable (x-axis)
    e_arr = np.linspace(0, 0.04, 40)

    # n_int range for sampling efficiency test
    powers = np.linspace(1, math.log(20, 10), 15)
    n_int_range = np.array(np.power(10, powers), dtype=int)

    #===========================================================================
    # Randomization
    #===========================================================================
    s = SPIRRID(
        q=fiber_tt_5p(),
        e_arr=e_arr,
        n_int=10,
        tvars=dict(lambd=g_la, xi=g_xi, E_mod=g_E, theta=g_th, A=g_A),
    )

    # Exact solution
    def mu_q_ex(e):
        data = np.loadtxt(mu_ex_file, delimiter=delimiter)
        x, y = data[:, 0], data[:, 1]
        f = interp1d(x, y, kind='linear')
        return f(e)

    #===========================================================================
    # Lab
    #===========================================================================
    slab = SPIRRIDLAB(s=s,
                      save_output=False,
                      show_output=True,
                      dpi=300,
                      exact_arr=mu_q_ex(e_arr),
                      plot_mode='subplots',
                      n_int_range=n_int_range,
                      extra_compiler_args=True,
                      le_sampling_lst=['LHS', 'PGrid'],
                      le_n_int_lst=[25, 30])

    return slab
Example #5
0
def run():

    sv = SPIRRIDModelView(model = SPIRRID(),
                           rf_values = [ Filament() ])
    sv.configure_traits(view = 'traits_view_tabbed')
Example #6
0
if __name__ == '__main__':

    from stats.spirrid import SPIRRID, Heaviside

    class fiber_tt_2p:

        la = Float(0.1)

        def __call__(self, e, la, xi=0.017):
            ''' Response function of a single fiber '''
            return la * e * Heaviside(xi - e)

    s = SPIRRID(
        q=fiber_tt_2p(),
        sampling_type='LHS',
        evars={'e': [0, 1]},
        tvars={
            'la': 1.0,  # RV( 'norm', 10.0, 1.0 ),
            'xi': RV('norm', 1.0, 0.1)
        })

    print 'tvar_names', s.tvar_names
    print 'tvars', s.tvar_lst
    print 'evar_names', s.evar_names
    print 'evars', s.evar_lst
    print 'var_defaults', s.var_defaults

    #print 'mu_q', s.mu_q_arr

    s = SPIRRID(
        q=fiber_tt_2p(),
        sampling_type='LHS',