Exemplo n.º 1
0
def run():
    # Quantities for the response function
    # and randomization

    # construct a default response function for a single filament

    rf = ConstantFrictionFiniteFiber(fu = 1200e15, qf = 1200,
                                     L = 0.02, A = 0.00000002,
                                     E = 210.e9, z = 0.004,
                                     phi = 0.5, f = 0.01)

    # construct the integrator and provide it with the response function.

    s = SPIRRID(rf = rf,
                 min_eps = 0.00, max_eps = 0.0008, n_eps = 380)

    # construct the random variables

    n_int = 25

    s.add_rv('E_mod', distribution = 'uniform', loc = 170.e9, scale = 250.e9, n_int = n_int)
    s.add_rv('L', distribution = 'uniform', loc = 0.02, scale = 0.03, n_int = n_int)
    s.add_rv('phi', distribution = 'sin_distr', loc = 0., scale = 1., n_int = n_int)
    s.add_rv('z', distribution = 'uniform', loc = 0, scale = rf.L / 2., n_int = n_int)

    # define a tables with the run configurations to start in a batch

    run_list = [
                (
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'bx-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) $ - %4.2f sec'
                 ),
                (
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : False },
                 'r-2',
                 '$\mathrm{P}_{e} ( \mathrm{C}_{\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) ) $ - %4.2f sec',
                 ),
                (
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'go-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
                  ),
                (
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : False,
                  'compiled_eps_loop' : False },
                 'b--',
                 '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
                 ),
                ]

    for idx, run in enumerate(run_list):
        run_options, plot_options, legend_string = run
        print 'run', idx,
        s.set(**run_options)
        s.mean_curve.plot(plt, plot_options, linewidth = 2, label = legend_string % s.exec_time)
        print 'execution time', s.exec_time

#    def f():
#        print 'exec_time', s.exec_time
#
#    global f
#
#    import cProfile
#
#    cProfile.run('f()', 'spirrid.tprof')
#    import pstats
#    p = pstats.Stats('spirrid.tprof')
#    p.strip_dirs()
#    print 'cumulative'
#    p.sort_stats('cumulative').print_stats(50)
#    print 'time'
#    p.sort_stats('time').print_stats(50)

    plt.xlabel('strain [-]')
    plt.ylabel('stress')
    plt.legend(loc = 'lower right')

    plt.title(s.rf.title)
    plt.show()
Exemplo n.º 2
0
def run():
    # Quantities for the response function
    # and randomization
    # 
    #E_mod = 70 * 1e+9 # Pa
    #sig_u = 1.25 * 1e+9 # Pa
    #D = 26 * 1.0e-6 # m
    #A = ( D / 2.0 ) ** 2 * pi
    #xi_u = sig_u / E_mod

    # construct a default response function for a single filament
    dict_var = {'fu':1200.0e6,
                'qf':1500.,
                'L':0.02,
                'A':5.30929158457e-10,
                'E_mod':70.0e9,
                'z':0.0,
                'phi':0.0,
                'f':0.0}

    # random variable dictionary
    n_int = 20 # 10
    dict_rv = {
               'fu':{'variable':'fu', 'distribution':'weibull_min', 'loc':1200.0e6, 'scale':200., 'n_int':n_int },
               'qf':{'variable':'qf', 'distribution':'uniform', 'loc':1500., 'scale':100., 'n_int':n_int },
               'L':{'variable':'L', 'distribution':'uniform', 'loc':0.02, 'scale':0.02 / 2., 'n_int':n_int},
               'A':{'variable':'A', 'distribution':'uniform', 'loc':5.30929158457e-10, 'scale':.03 * 5.30929158457e-10, 'n_int':n_int },
               'E_mod':{'variable':'E_mod', 'distribution':'uniform', 'loc':70.e9, 'scale':250.e9, 'n_int':n_int},
               'z':{'variable':'z', 'distribution':'uniform', 'loc':0., 'scale':.03, 'n_int':n_int },
               'phi':{'variable':'phi', 'distribution':'sin_distr', 'loc':0., 'scale':1., 'n_int':n_int},
               'f':{'variable':'f', 'distribution':'uniform', 'loc':0., 'scale':.03, 'n_int':n_int },
               }

    # list of all combinations of response function parameters
    rv_comb_list = list(powerset(dict_rv))

    # define a tables with the run configurations to start in a batch
    run_list = [
                (
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'bx-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) $ - %4.2f sec'
                 ),
                (
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : False },
                 'r-2',
                 '$\mathrm{P}_{e} ( \mathrm{C}_{\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) ) $ - %4.2f sec',
                 ),
                 (
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : False,
                  'compiled_eps_loop' : False },
                 'y--',
                 '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
                 ),
                (
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'go-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
                  ),
                ]

    outfile = open('pullout_comb_stat.dat', 'w')
    sp1_outfile = open('pullout_comb_1.dat', 'w')
    sp2_outfile = open('pullout_comb_2.dat', 'w')

    plot = True

    for id, rv_comb in enumerate(rv_comb_list[163:219]):#[0,-1]
        for i in range(0, 2):
            num_rv = len(rv_comb) # number of randomized variables
            if i == 0:
                sp1_outfile.write('%i \t %i' % (id, num_rv))
            else:
                sp2_outfile.write('%i \t %i' % (id, num_rv))
            # construct a default response function
            rf = ConstantFrictionFiniteFiber()
            rf.set(**dict_var)

            # construct the integrator and provide it with the response function.  
            s = SPIRRID(rf = rf,
                        min_eps = 0.00, max_eps = 0.012, n_eps = 40) # max_eps = 0.05

            for rv in rv_comb:#['fu', 'A', 'E_mod', 'z', 'f']:
                s.add_rv(**dict_rv[rv])

            if plot == True:
                legend = []

            print 'Combination', rv_comb, ' -- ', i
            outfile.write("Combination %s -- %i\n" % (rv_comb, i))
            outfile.write("%s \t %s\n" % ("Run", "Time"))

            for idx, run in enumerate(run_list):
                run_options, plot_options, legend_string = run
                print 'run', idx,
                s.set(**run_options)
                if plot == True:
                    plt.figure(id)
                    #s.mean_curve.plot(plt, plot_options)
                    plt.plot(np.linspace(s.min_eps, s.max_eps, s.n_eps), s.mu_q_arr, plot_options)
                    legend.append(legend_string % s.exec_time)
                print 'execution time', s.exec_time
                outfile.write("%s \t %.6f\n" % (idx, s.exec_time))

                if i == 0:
                    sp1_outfile.write("\t %.6f" % (s.exec_time))
                else:
                    sp2_outfile.write("\t %.6f" % (s.exec_time))
            plt.show()

            outfile.write("=================\n")
            outfile.flush()

            if i == 0:
                sp1_outfile.write('\t %s\n' % str(rv_comb))
                sp1_outfile.flush()
            else:
                sp2_outfile.write('\t %s\n' % str(rv_comb))
                sp2_outfile.flush()
            if plot == True:
                plt.xlabel('strain [-]')
                plt.ylabel('stress')
                plt.legend(legend)
                plt.title(s.rf.title)

        del s


    outfile.close()
    sp1_outfile.close()
    sp2_outfile.close()
    if plot == True:
        plt.show()
Exemplo n.º 3
0
 def _child_default( self ):
     return SPIRRID()
    n_params = len(rf.param_keys)

    width = 0.08
    time_plot = []

    for idx in range(n_params):
        offset = idx * width
        n_rv = idx + 1

        n_int = int(pow(memsize, 1 / float(n_rv)))
        print 'n_int', n_int


        s = SPIRRID(rf = rf,
                     min_eps = 0.00, max_eps = 1.0, n_eps = 20,
                     compiler_verbose = 0
                     )


        for rv in range(n_rv):
            param_key = rf.param_keys[ rv ]
            s.add_rv(param_key, n_int = n_int)
        time_plot.append(run_study(s, run_dict, offset, width)[1])

    plt.figure(0)
    plt.plot(range(1, len(rf.param_keys) + 1), time_plot, '-o', color = 'black', linewidth = 1)

    plt.figure(1)
    plt.plot([1.0, 2.0 + width * n_params], [1.0, 1.0], '-o', color = 'black')

    plt.figure(0)
Exemplo n.º 5
0
from rf_view import RFModelView
from rv_view import RVModelView
from result_view import ResultView
from spirrid_view import SPIRRIDModelView

from quaducom.resp_func.brittle_filament import Filament

# ---------------------------------------
#    TREE STRUCTURE FOR SPIRRID VIEW
# ---------------------------------------

if __name__ == '__main__':

    # CREATE INSTANCES #
    default_rf = Filament()
    spirrid = SPIRRID(rf=default_rf, implicit_var_eval=True)

    spirrid_view = SPIRRIDModelView(model=spirrid)

    result_view = ResultView(spirrid_view=spirrid_view)

    # defining classes for tree nodes at first and second level


    class SPIRRIDUI(HasTraits):
        title = Str('simvisage SPIRRID')
        image = Image('pics/spirrid.png')
        comp_parts = List()

    class Preprocessor(HasTraits):
        title = Str('preprocessor')
Exemplo n.º 6
0
def run():
    # Quantities for the response function
    # and randomization
    #
    E_mod = 70 * 1e+9  # Pa
    sig_u = 1.25 * 1e+9  # Pa
    D = 26 * 1.0e-6  # m
    A = (D / 2.0)**2 * pi
    xi_u = sig_u / E_mod

    # construct a default response function for a single filament

    rf = Filament(E_mod=70.e9, xi=0.02, A=A, theta=0, lambd=0)

    # construct the integrator and provide it with the response function.

    s = SPIRRID(rf=rf, min_eps=0.00, max_eps=0.05, n_eps=20)

    # construct the random variables

    n_int = 40

    s.add_rv('xi',
             distribution='weibull_min',
             scale=0.02,
             shape=10.,
             n_int=n_int)
    s.add_rv('E_mod',
             distribution='uniform',
             loc=70e+9,
             scale=15e+9,
             n_int=n_int)
    s.add_rv('theta', distribution='uniform', loc=0.0, scale=0.01, n_int=n_int)
    s.add_rv('lambd', distribution='uniform', loc=0.0, scale=.2, n_int=n_int)
    s.add_rv('A',
             distribution='uniform',
             loc=A * 0.3,
             scale=0.7 * A,
             n_int=n_int)

    # define a tables with the run configurations to start in a batch

    run_list = [
        ({
            'cached_dG': False,
            'compiled_QdG_loop': True,
            'compiled_eps_loop': True
        }, 'bx-',
         '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) $ - %4.2f sec'
         ),
        (
            {
                'cached_dG': False,
                'compiled_QdG_loop': True,
                'compiled_eps_loop': False
            },
            'r-2',
            '$\mathrm{P}_{e} ( \mathrm{C}_{\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) ) $ - %4.2f sec',
        ),
        (
            {
                'cached_dG': True,
                'compiled_QdG_loop': True,
                'compiled_eps_loop': True
            },
            'go-',
            '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
        ),
        ({
            'cached_dG': True,
            'compiled_QdG_loop': False,
            'compiled_eps_loop': False
        }, 'y--',
         '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
         ),
    ]

    legend = []

    for idx, run in enumerate(run_list):
        run_options, plot_options, legend_string = run
        print 'run', idx,
        s.set(**run_options)
        print 'xdata', s.mean_curve.xdata
        print 'ydata', s.mean_curve.ydata
        s.mean_curve.plot(plt, plot_options)

        print 'integral of the pdf theta', s.eval_i_dG_grid()
        print 'execution time', s.exec_time
        legend.append(legend_string % s.exec_time)

    plt.xlabel('strain [-]')
    plt.ylabel('stress')
    plt.legend(legend)

    plt.title(s.rf.title)
    plt.show()
Exemplo n.º 7
0
    traits_view = View( VSplit( 

                                HGroup( 
                                    Item( 'rv_list', editor = rv_list_editor, show_label = False ),
                                    id = 'rid.tview.randomization.rv',
                                    label = 'Model variables',
                                ),
                                HGroup( 
                                    Item( 'selected_var@', show_label = False, resizable = True ),
                                    id = 'rid.tview.randomization.distr',
                                    label = 'Distribution',
                                ),

                                scrollable = True,
                                id = 'rid.tview.tabs',
                                dock = 'tab',
                        ),

                        title = 'RANDOM VARIABLES',
                        id = 'rid.ridview',
                        dock = 'tab',
                        resizable = True,
                        height = 1.0, width = 1.0
                        )

if __name__ == '__main__':
    s = SPIRRID( rf = Filament() )
    r = RVModelView( model = s )
    r.configure_traits()
Exemplo n.º 8
0
    plot = False

    for id, rv_comb in enumerate(rv_comb_list[15:25]):#[0,-1]
        for i in range(0, 1):#2
            num_rv = len(rv_comb) # number of randomized variables
            if i == 0:
                sp1_outfile.write('%i \t %i' % (id, num_rv))
            else:
                sp2_outfile.write('%i \t %i' % (id, num_rv))
            # construct a default response function
            rf = Filament()
            rf.set(**dict_var)

            # construct the integrator and provide it with the response function.  
            s = SPIRRID(rf = rf,
                        min_eps = 0.00, max_eps = 0.04, n_eps = 20) # max_eps = 0.05

            for rv in rv_comb:
                s.add_rv(**dict_rv[rv])

            if plot == True:
                legend = []

            print 'Combination', rv_comb, ' -- ', i
            outfile.write("Combination %s -- %i\n" % (rv_comb, i))
            outfile.write("%s \t %s\n" % ("Run", "Time"))

            for idx, run in enumerate(run_list):
                run_options, plot_options, legend_string = run
                print 'run', idx,
Exemplo n.º 9
0
def run():
    # Quantities for the response function
    # and randomization
    # 
    E_mod = 70 * 1e+9 # Pa
    sig_u = 1.25 * 1e+9 # Pa
    D = 26 * 1.0e-6 # m
    A = ( D / 2.0 ) ** 2 * pi
    xi_u = sig_u / E_mod

    # construct a default response function for a single filament

    rf = Filament( E_mod = 70.e9, xi = 0.02, A = A, theta = 0, lambd = 0 )

    # construct the integrator and provide it with the response function.

    s = SPIRRID( rf = rf,
                 min_eps = 0.00, max_eps = 0.05, n_eps = 20 )

    # construct the random variables

    n_int = 40

    s.add_rv( 'xi', distribution = 'weibull_min', scale = 0.02, shape = 10., n_int = n_int )
    s.add_rv( 'E_mod', distribution = 'uniform', loc = 70e+9, scale = 15e+9, n_int = n_int )
    s.add_rv( 'theta', distribution = 'uniform', loc = 0.0, scale = 0.01, n_int = n_int )
    s.add_rv( 'lambd', distribution = 'uniform', loc = 0.0, scale = .2, n_int = n_int )
    s.add_rv( 'A', distribution = 'uniform', loc = A * 0.3, scale = 0.7 * A, n_int = n_int )

    # define a tables with the run configurations to start in a batch

    run_list = [
                ( 
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'bx-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) $ - %4.2f sec'
                 ),
                ( 
                 {'cached_dG'         : False,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : False },
                 'r-2',
                 '$\mathrm{P}_{e} ( \mathrm{C}_{\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) ) $ - %4.2f sec',
                 ),
                ( 
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : True,
                  'compiled_eps_loop' : True },
                  'go-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
                  ),
                ( 
                 {'cached_dG'         : True,
                  'compiled_QdG_loop'  : False,
                  'compiled_eps_loop' : False },
                 'y--',
                 '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
                 ),
                ]

    legend = []

    for idx, run in enumerate( run_list ):
        run_options, plot_options, legend_string = run
        print 'run', idx,
        s.set( **run_options )
        print 'xdata', s.mean_curve.xdata
        print 'ydata', s.mean_curve.ydata
        s.mean_curve.plot( plt, plot_options )

        print 'integral of the pdf theta', s.eval_i_dG_grid()
        print 'execution time', s.exec_time
        legend.append( legend_string % s.exec_time )

    plt.xlabel( 'strain [-]' )
    plt.ylabel( 'stress' )
    plt.legend( legend )

    plt.title( s.rf.title )
    plt.show()
Exemplo n.º 10
0
def run():
    # Quantities for the response function
    # and randomization

    # construct a default response function for a single filament

    rf = ConstantFrictionFiniteFiber(fu=1200e15,
                                     qf=1200,
                                     L=0.02,
                                     A=0.00000002,
                                     E=210.e9,
                                     z=0.004,
                                     phi=0.5,
                                     f=0.01)

    # construct the integrator and provide it with the response function.

    s = SPIRRID(rf=rf, min_eps=0.00, max_eps=0.0008, n_eps=380)

    # construct the random variables

    n_int = 25

    s.add_rv('E_mod',
             distribution='uniform',
             loc=170.e9,
             scale=250.e9,
             n_int=n_int)
    s.add_rv('L', distribution='uniform', loc=0.02, scale=0.03, n_int=n_int)
    s.add_rv('phi', distribution='sin_distr', loc=0., scale=1., n_int=n_int)
    s.add_rv('z', distribution='uniform', loc=0, scale=rf.L / 2., n_int=n_int)

    # define a tables with the run configurations to start in a batch

    run_list = [
        ({
            'cached_dG': False,
            'compiled_QdG_loop': True,
            'compiled_eps_loop': True
        }, 'bx-',
         '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) $ - %4.2f sec'
         ),
        (
            {
                'cached_dG': False,
                'compiled_QdG_loop': True,
                'compiled_eps_loop': False
            },
            'r-2',
            '$\mathrm{P}_{e} ( \mathrm{C}_{\\theta} ( q(e,\\theta) \cdot g[\\theta_1]  g[\\theta_2] \dots g[\\theta_n] ) ) $ - %4.2f sec',
        ),
        (
            {
                'cached_dG': True,
                'compiled_QdG_loop': True,
                'compiled_eps_loop': True
            },
            'go-',
            '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
        ),
        ({
            'cached_dG': True,
            'compiled_QdG_loop': False,
            'compiled_eps_loop': False
        }, 'b--',
         '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
         ),
    ]

    for idx, run in enumerate(run_list):
        run_options, plot_options, legend_string = run
        print 'run', idx,
        s.set(**run_options)
        s.mean_curve.plot(plt,
                          plot_options,
                          linewidth=2,
                          label=legend_string % s.exec_time)
        print 'execution time', s.exec_time


#    def f():
#        print 'exec_time', s.exec_time
#
#    global f
#
#    import cProfile
#
#    cProfile.run('f()', 'spirrid.tprof')
#    import pstats
#    p = pstats.Stats('spirrid.tprof')
#    p.strip_dirs()
#    print 'cumulative'
#    p.sort_stats('cumulative').print_stats(50)
#    print 'time'
#    p.sort_stats('time').print_stats(50)

    plt.xlabel('strain [-]')
    plt.ylabel('stress')
    plt.legend(loc='lower right')

    plt.title(s.rf.title)
    plt.show()
Exemplo n.º 11
0
    n_params = len(rf.param_keys)

    width = 0.08
    time_plot = []

    for idx in range(n_params):
        offset = idx * width
        n_rv = idx + 1

        n_int = int(pow(memsize, 1 / float(n_rv)))
        print 'n_int', n_int

        s = SPIRRID(rf=rf,
                    min_eps=0.00,
                    max_eps=1.0,
                    n_eps=20,
                    compiler_verbose=0)

        for rv in range(n_rv):
            param_key = rf.param_keys[rv]
            s.add_rv(param_key, n_int=n_int)
        time_plot.append(run_study(s, run_dict, offset, width)[1])

    plt.figure(0)
    plt.plot(range(1,
                   len(rf.param_keys) + 1),
             time_plot,
             '-o',
             color='black',
             linewidth=1)