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}

    e_arr = np.linspace(0, 0.012, 40)

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

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

    # define a tables with the run configurations to start in a batch
    run_list = [
                ('c',
                 {'cached_dG'         : False,
                  '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'
                 ),
                ('c',
                 {'cached_dG'         : False,
                  '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',
                 ),
                ('numpy',
                 { },
                  'go-',
                  '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec',
                  ),
                 ('c',
                 {'cached_dG'         : True,
                  'compiled_eps_loop' : False },
                 'y--',
                 '$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec'
                 ),
                ]

    outfile = open('pullout_comb_stat_new.dat', 'w')
    sp1_outfile = open('pullout_comb_1_new.dat', 'w')
    sp2_outfile = open('pullout_comb_2_new.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

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

            tvars_up = dict_var
            for rv in rv_comb:
                tvars_up[rv] = tvars[rv]

            if plot == True:
                legend = []

            s = SPIRRID(q = ConstantFrictionFiniteFiber(),
                e_arr = e_arr,
                n_int = 20,
                tvars = tvars_up,
                )
            s.sampling_type = 'TGrid'
            s.recalc = True
            s.sampling.recalc = True
            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):
                code, run_options, plot_options, legend_string = run
                s.codegen_type = code
                s.codegen.set(**run_options)
                print 'run', idx,
                if plot == True:
                    plt.figure(id)
                    plt.plot(s.evar_list[0], 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()
Example #2
0
                tvars = tvars,
                )

    #===========================================================================
    # Lab
    #===========================================================================
    slab = SPIRRIDLAB(s = s, save_output = True, show_output = True,
                      qname = 'fiber_po_8p',
                      )

    #===========================================================================
    # Compare efficiency of sampling types 
    #===========================================================================
    powers = np.linspace(1, math.log(20, 10), 6)
    n_int_range = np.array(np.power(10, powers), dtype = int)
    #slab.sampling_efficiency(n_int_range = n_int_range)

    #===========================================================================
    # Compare the structure of sampling
    #===========================================================================

    #slab.sampling_structure(ylim = 10.0, xlim = 0.012, plot_idx = [0, 3])

    #===========================================================================
    # Compare the code efficiency
    #===========================================================================

    s.sampling_type = 'TGrid'
    slab.codegen_efficiency()

from stats.spirrid.sampling import PGrid, TGrid, FunctionRandomization
from stats.spirrid import SPIRRID

class C(FunctionRandomization):

    sampling_type = Trait('T-grid', {'T-grid' : TGrid,
                            'P-grid' : PGrid}, input_change = True)

    sampling = Property(depends_on = '+input_change')
    @cached_property
    def _get_sampling(self):
        print '... recalculating result ...',
        return self.sampling_type_(randomization = self)

c = C()
print 'got', c.sampling
c.sampling_type = 'P-grid'
print 'got', c.sampling
c.sampling_type = 'T-grid'
print 'got', c.sampling
print 'got', c.sampling

print '====='
s = SPIRRID()
print 'got', s.sampling
s.sampling_type = 'P-grid'
print 'got', s.sampling
s.sampling_type = 'T-grid'
print 'got', s.sampling
print 'got', s.sampling
Example #4
0
                      exact_arr = mu_q_ex(e_arr))

    #===========================================================================
    # Compare efficiency of sampling types 
    #===========================================================================
    powers = np.linspace(1, math.log(20, 10), 15)
    n_int_range = np.array(np.power(10, powers), dtype = int)

    #slab.sampling_efficiency(n_int_range = n_int_range)

    #===========================================================================
    # Compare the structure of sampling
    #===========================================================================

    #slab.sampling_structure( ylim = 1.1, xlim = 0.04 )

    #===========================================================================
    # Compare the code efficiency
    #===========================================================================

    s.set(e_arr = np.linspace(0, 0.04, 20), n_int = 40)
    s.sampling_type = 'PGrid'
    slab.codegen_efficiency()

    #===========================================================================
    # Compare the efficiency wrt. order and number of RV (combinations)
    #===========================================================================

    #slab.combination_efficiency(tvars_det = dict(lambd = la_mean, xi = xi_mean, E_mod = E_mean, theta = th_mean, A = A_mean),
    #                            tvars_rand = dict(lambd = g_la, xi = g_xi, E_mod = g_E, theta = g_th, A = g_A))