def _redraw( self ): s = SPIRRID( rf = rf, # min_eps = 0.00, max_eps = 20.00, n_eps = 80, min_eps = 0.00, max_eps = 0.3, n_eps = 100, cached_qg = True, compiled_qg_loop = False, compiled_eps_loop = False ) # construct the random variables n_int = 30 #s.add_rv( 'tau1', distribution='uniform', loc=2. / 1000, scale=10.0 / 1000, n_int=n_int ) #s.add_rv( 'l', distribution='uniform', loc=0.01, scale=.01, n_int=n_int ) #s.add_rv( 'xi', distribution='weibull_min', shape=8.64, scale=0.0287, n_int=n_int ) s.rv_dict['theta'] = RV( pd = self.pdf_theta, name = 'theta', n_int = n_int ) s.rv_dict['l'] = RV( pd = self.pdf_l, name = 'l', n_int = n_int ) s.rv_dict['phi'] = RV( pd = self.pdf_phi, name = 'phi', n_int = n_int ) s.mean_curve.plot( self.figure, linewidth = 2, label = 'mean CB per filament response' ) plt.xlabel( 'crack opening w[mm]' ) plt.ylabel( 'force P[N]' ) plt.legend( loc = 'best' ) plt.figure( 10 ) plt.show()
def run(): # Quantities for the response function # and randomization # construct a default response function for a single filament rf = ConstantFrictionFreeLengthFiniteFiber( tau = 0.5e6, l = 0.01, E = 70e9, A = 0.89e-6, slack = 0.0, L = 0.3, sigma_fu = 200e6 ) # construct the integrator and provide # it with the response function. max_u = 1.8 s = SPIRRID( rf = rf, min_eps = 0.00, max_eps = max_u, n_eps = 80, cached_dG = True, compiled_QdG_loop = False, compiled_eps_loop = False ) # construct the correlated integrator and # provide it with the response function. sc = CorSPIRRID( rf = rf, rho = -0.99, min_eps = 0.00, max_eps = max_u, n_eps = 80, cached_dG = True, compiled_QdG_loop = False, compiled_eps_loop = False ) n_int = 100 s.add_rv( 'tau', distribution = 'norm', loc = 0.3e6, scale = 0.1e6, n_int = n_int ) s.add_rv( 'l', distribution = 'norm', loc = 0.03, scale = 0.01, n_int = n_int ) sc.add_rv( 'tau', distribution = 'norm', loc = 0.3e6, scale = 0.1e6, n_int = n_int ) sc.add_rv( 'l', distribution = 'norm', loc = 0.03, scale = 0.01, n_int = n_int ) # define a tables with the run configurations to start in a batch print 'sum', sum( sc.dG_grid ) print 'sum', sum( s.dG_grid ) # z = sc.pdf_theta_grid # x, y = mgrid[-4:4:50j, -4:4:50j] # # mlab.surf(x, y, z) # mlab.show() s.mean_curve.plot( plt, color = 'red', linewidth = 2, label = 'spirrid' ) sc.mean_curve.plot( plt, color = 'blue', linewidth = 2, label = 'cor spirrid' ) plt.xlabel( 'strain [-]' ) plt.ylabel( 'stress' ) plt.legend( loc = 'lower right' ) plt.title( s.rf.title ) plt.show()
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)
def _get_s_inner( self ): s = SPIRRID( rf = self.rf, cached_dG = True, compiled_QdG_loop = False, compiled_eps_loop = False ) # construct the random variables n_int = 10 s.add_rv( 'xi', distribution = 'weibull_min', scale = 0.02, shape = 10., n_int = n_int ) s.add_rv( 'theta', distribution = 'uniform', loc = self.loc_theta, scale = 0.01, n_int = n_int ) #.add_rv('lambd', distribution = 'uniform', loc = 0.0, scale = 0.01, n_int = n_int) return s
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
def create_demo_object(): m_la, std_la = 10., 1.0 m_xi, std_xi = 1.0, 0.1 # discretize the control variable (x-axis) e_arr = np.linspace(0, 2.0, 80) # n_int range for sampling efficiency test powers = np.linspace(1, math.log(500, 10), 50) n_int_range = np.array(np.power(10, powers), dtype=int) #=========================================================================== # Randomization #=========================================================================== s = SPIRRID( q=fiber_tt_2p(), e_arr=e_arr, n_int=10, tvars=dict(la=RV('norm', m_la, std_la), xi=RV('norm', m_xi, std_xi)), ) #=========================================================================== # Exact solution #=========================================================================== def mu_q_ex(e, m_xi, std_xi, m_la): return e * (0.5 - 0.5 * erf(0.5 * math.sqrt(2) * (e - m_xi) / std_xi)) * m_la #=========================================================================== # Lab #=========================================================================== slab = SPIRRIDLAB(s=s, save_output=False, show_output=True, dpi=300, exact_arr=mu_q_ex(e_arr, m_xi, std_xi, m_la), plot_mode='subplots', n_int_range=n_int_range, extra_compiler_args=True, le_sampling_lst=['LHS', 'PGrid'], le_n_int_lst=[440, 5000]) return slab
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)), )
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', evars = {'e' : [0, 1], 'la' : [0, 1]}, tvars = {'xi': RV('norm', 1.0, 0.1),
def run(): m_mu, std_mu = 3., 0.68 m_cov, std_cov = 0.18, 0.067 # discretize the control variable (x-axis) x_arr = np.linspace(0, 6.0, 1000)[1:] #=========================================================================== # Randomization #=========================================================================== s = SPIRRID(q = BasicPDF(), e_arr = x_arr, n_int = 100, tvars = dict(mu = RV('norm', m_mu, std_mu), #RV('beta', m_cov, std_cov),#BETA('beta', mu = m_mu, sig = std_mu, a = a, b = b), cov = RV('norm', m_cov, std_cov) ), sampling_type = 'TGrid', codegen_type = 'numpy', ) #=========================================================================== # Calculate #=========================================================================== # calculate compounded distribution values cpd_pdf = s.mu_q_arr cpd_cdf = np.cumsum(cpd_pdf) * np.diff(x_arr)[0] # calculate first raw moment raw_1 = np.trapz(cpd_pdf * x_arr, x_arr) # calculate second raw moment raw_2 = np.trapz(cpd_pdf * x_arr ** 2, x_arr) std = np.sqrt(raw_2 - raw_1 ** 2) # calculate values of lognormal distrib lognorm_pdf = lognormal_pdf(x_arr, raw_1, std) lognorm_cdf = lognormal_cdf(x_arr, raw_1, std) # calculate error rms_err = rms_error(lognorm_pdf, cpd_pdf) max_err = max_error(lognorm_pdf, cpd_pdf) chi_err = chi_error(lognorm_pdf, cpd_pdf) # generate samples samples = s.sampling.get_samples(20) sample_args = [ sam[:, np.newaxis] for sam in samples] q_arr = s.q(x_arr[None, :], *sample_args) #=========================================================================== # Print #=========================================================================== print 'check unity\t', np.trapz(cpd_pdf, x_arr) print 'mean\t\t', raw_1 print 'std\t\t', std print 'rms error\t', rms_err print 'max error\t', max_err print 'chi error\t', chi_err #=========================================================================== # Plot #=========================================================================== p.figure() # plot samples #p.plot(x_arr, q_arr.T, color = 'gray') # plot compounded distribution p.plot(x_arr, cpd_pdf, 'b-') # plot lognormal distribution, method of moments p.plot(x_arr, lognorm_pdf, color = 'red', linewidth = 2) data = np.loadtxt('maple_cpd.txt', delimiter = ',') p.plot(data[:, 0], data[:, 1], color = 'violet') p.figure() p.plot(x_arr, cpd_cdf, 'b-') # plot lognormal CDF, method of moments p.plot(x_arr, lognorm_cdf, color = 'red', linewidth = 2) p.show()
q = 0.0; }else{ q = la * eps; } ''' 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, n_int = 10, tvars = dict(la = RV('norm', m_la, std_la), xi = RV('norm', m_xi, std_xi) ), ) #=========================================================================== # Exact solution #=========================================================================== def mu_q_ex(e, m_xi, std_xi, m_la): return e * (0.5 - 0.5 * erf(0.5 * math.sqrt(2) * (e - m_xi) / std_xi)) * m_la #=========================================================================== # Lab #=========================================================================== slab = SPIRRIDLAB(s = s, save_output = True, show_output = True,
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, "xi": RV("norm", 1.0, 0.1)}, # RV( 'norm', 10.0, 1.0 ), ) print "tvar_names", s.tvar_names print "tvars", s.tvar_list print "evar_names", s.evar_names print "evars", s.evar_list print "var_defaults", s.var_defaults # print 'mu_q', s.mu_q_arr s = SPIRRID( q=fiber_tt_2p(), sampling_type="LHS", evars={"e": [0, 1], "la": [0, 1]},
def run(mu, cov, plot = True): # discretize the control variable (x-axis) x_arr = np.linspace(0, 10.0, 1000)[1:] #=========================================================================== # Randomization #=========================================================================== s = SPIRRID(q = BasicPDF(), e_arr = x_arr, n_int = 100, tvars = dict(mu = mu, cov = cov ), sampling_type = 'TGrid', codegen_type = 'numpy', ) #s.codegen.cached_dG = False #s.codegen.compiled_eps_loop = False #=========================================================================== # Calculate #=========================================================================== # calculate compounded distribution values cpd_pdf = s.mu_q_arr cpd_cdf = np.cumsum(cpd_pdf) * np.diff(x_arr)[0] # calculate first raw moment raw_1 = np.trapz(cpd_pdf * x_arr, x_arr) # calculate second raw moment raw_2 = np.trapz(cpd_pdf * x_arr ** 2, x_arr) std = np.sqrt(raw_2 - raw_1 ** 2) # calculate values of lognormal distrib lognorm_pdf = lognormal_pdf(x_arr, raw_1, std) lognorm_cdf = lognormal_cdf(x_arr, raw_1, std) # calculate error rms_err = rms_error(lognorm_pdf, cpd_pdf) max_err = max_error(lognorm_pdf, cpd_pdf) chi_err = chi_error(lognorm_pdf, cpd_pdf) ks_err = ks_error(lognorm_cdf, cpd_cdf) # generate samples samples = s.sampling.get_samples(50) sample_args = [ sam[:, np.newaxis] for sam in samples] q_arr = s.q(x_arr[None, :], *sample_args) emp_data = np.loadtxt('data_emp.txt', delimiter = '\t') #=========================================================================== # Print #=========================================================================== print 'check unity\t', np.trapz(cpd_pdf, x_arr) print 'mean\t\t', raw_1 print 'std\t\t', std print 'rms error\t', rms_err print 'max error\t', max_err print 'chi error\t', chi_err print 'ks error\t', ks_err #=========================================================================== # Plot #=========================================================================== if plot: p.figure() p.title(mu.type) # plot samples #p.plot(x_arr, q_arr.T, color = 'gray') for s in q_arr: p.plot(x_arr, s, color = 'gray', linewidth = mu.pdf((s * x_arr).sum() / 100.) * 5) # plot compounded distribution p.plot(x_arr, cpd_pdf, 'b-', label = 'cpd') # plot lognormal distribution, method of moments p.plot(x_arr, lognorm_pdf, color = 'red', linewidth = 2, label = 'lognorm') p.plot(x_arr, lognormal_pdf(x_arr, np.mean(emp_data[:, 0]), np.std(emp_data[:, 0])), color = 'cyan', linewidth = 2, label = 'lognorm_data') p.plot(x_arr, mu.pdf(x_arr), color = 'green', label = 'mu_dist') p.legend(loc = 0) p.figure() p.title(mu.type) p.plot(emp_data[:, 0], emp_data[:, 1], 'k-', linewidth = 3, label = 'emp') p.plot(x_arr, cpd_cdf, 'b-', label = 'cpd') # plot lognormal CDF, method of moments p.plot(x_arr, lognorm_cdf, color = 'red', linewidth = 2, label = 'lognorm') p.plot(x_arr, lognormal_cdf(x_arr, np.mean(emp_data[:, 0]), np.std(emp_data[:, 0])), color = 'cyan', linewidth = 2, label = 'lognorm_data') p.legend(loc = 0) p.figure() p.title(mu.type) p.loglog(emp_data[:, 0], emp_data[:, 1], 'k-', linewidth = 3, label = 'emp') p.loglog(x_arr, cpd_cdf, 'b-', label = 'cpd') p.loglog(x_arr, lognorm_cdf, color = 'red', linewidth = 2, label = 'lognorm') p.loglog(x_arr, lognormal_cdf(x_arr, np.mean(emp_data[:, 0]), np.std(emp_data[:, 0])), color = 'cyan', linewidth = 2, label = 'lognorm_data') p.ylim(1e-4, 1) p.xlim(1, 10) p.legend(loc = 0) #p.show() return rms_err
def run(): # Quantities for the response function # and randomization # xx = 10 # Pa yy = 20 # Pa zz = 30 aa = 40 # construct a default response function for a single filament rf = Filament( x=xx, y=yy, z=zz, a=aa ) # construct the integrator and provide it with the response function. s = SPIRRID( rf=rf, min_eps=0.00, max_eps=0.05, n_eps=1 ) # construct the random variables n_int = 80 s.add_rv( 'x', distribution='norm', scale=10., shape=2., n_int=n_int ) s.add_rv( 'y', distribution='norm', loc=10., scale=2., n_int=n_int ) s.add_rv( 'z', distribution='norm', loc=10., scale=2., n_int=n_int ) s.add_rv( 'a', distribution='norm', loc=10., scale=2., n_int=n_int ) # define a tables with the run configurations to start in a batch run_list = [ ( {'cached_qg' : False, 'compiled_qg_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_qg' : False, 'compiled_qg_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_qg' : True, 'compiled_qg_loop' : True, 'compiled_eps_loop' : True }, 'go-', '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec', ), ( {'cached_qg' : True, 'compiled_qg_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 ) s.mean_curve.plot( plt, plot_options ) 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()
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_mod=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=80 ) # construct the random variables n_int = 15 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='cos_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_qg' : False, 'compiled_qg_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_qg' : False, 'compiled_qg_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_qg' : True, 'compiled_qg_loop' : True, 'compiled_eps_loop' : True }, 'go-', '$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec', ), ( {'cached_qg' : True, 'compiled_qg_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, s.mu_q_peak plt.xlabel( 'strain [-]' ) plt.ylabel( 'stress' ) plt.legend( loc='lower right' ) plt.title( s.rf.title ) plt.show()
# discretize the control variable (x-axis) e_arr = np.linspace(0, 1.2, 40) # Exact solution def mu_q_ex(e, m_xi, std_xi, m_la): return e * (0.5 - 0.5 * erf(0.5 * math.sqrt(2) * (e - m_xi) / std_xi)) * m_la mu_q_ex_arr = mu_q_ex(e_arr, m_xi, std_xi, m_la) g_la = RV('norm', m_la, std_la) g_xi = RV('norm', m_xi, std_xi) s = SPIRRID( q=fiber_tt_2p, e_arr=e_arr, n_int=10, tvars=dict(la=g_la, xi=g_xi), ) mu_q_ex_arr = mu_q_ex(e_arr, m_xi, std_xi, m_la) slab = SPIRRIDLAB(s=s, save_output=False, show_output=True, exact_arr=mu_q_ex(e_arr, m_xi, std_xi, m_la)) slab.configure_traits(kind='live') # powers = np.linspace(1, math.log(200, 10), 50) # n_int_range = np.array(np.power(10, powers), dtype = int) #
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
print 'input', s.cv, 'output', r return r if __name__ == '__main__': rf = Yarn() # control variable - strains # can be a float number or array cv = linspace( 0.0, 0.06, 10 ) # construct the outer integrator and provide it with the response function. s_outer = SPIRRID( rf = rf, cv = cv, cached_dG = True, compiled_QdG_loop = False, compiled_eps_loop = False ) # construct the random variables n_int = 3 s_outer.add_rv( 'loc_theta', distribution = 'uniform', loc = 0.00, scale = 0.01, n_int = n_int ) # plot the mean filament and mean yarn response plt.plot( cv, rf( cv, 0.01 ), linewidth = 2, label = 'random filament properties' ) plt.plot( cv, s_outer.results[0], linewidth = 2, label = 'random bundle properties' )
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 = 'fiber_tt_5p_40_norm.txt' delimiter = ' ' # discretize the control variable (x-axis) e_arr = np.linspace(0, 0.04, 1000) #=========================================================================== # Randomization #=========================================================================== s = SPIRRID(q = fiber_tt_5p(), e_arr = e_arr, n_int = 30, 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 = True, show_output = True, exact_arr = mu_q_ex(e_arr))
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 dict_var = {'E_mod':70.e9, 'xi':0.02, 'A':A, 'theta':0, 'lambd':0} outfile = open( 'filament_comb_stat.dat', 'w' ) comb = 0 while_cond = 1 while while_cond == 1: #for comb in range( 1, n_com + 1 ): comb += 1 for i in range( 0, 2 ): # construct a default response function for a single filament 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.05, n_eps=80 ) # construct the random variables n_int = 32 dict_rv = { 'xi':{'variable':'xi', 'distribution':'weibull_min', 'scale':0.02, 'shape':10., 'n_int':n_int}, 'E_mod':{'variable':'E_mod', 'distribution':'uniform', 'loc':70e+9, 'scale':15e+9, 'n_int':n_int}, 'theta':{'variable':'theta', 'distribution':'uniform', 'loc':0.0, 'scale':0.01, 'n_int':n_int}, 'lambd':{'variable':'lambd', 'distribution':'uniform', 'loc':0.0, 'scale':.2, 'n_int':n_int}, 'A':{'variable':'A', 'distribution':'uniform', 'loc':A * 0.3, 'scale':0.7 * A, 'n_int':n_int}, } n_var = len( dict_rv ) n_com = 0 for k in range( 0, n_var ): n_com += choose( n_var, k ) print 'The only last combination' comb = n_com # end of the while loop if comb == n_com: while_cond = 0 list_rv_comb = list( powerset( dict_rv ) ) for rv in list_rv_comb[comb]: s.add_rv( **dict_rv[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', ), ] legend = [] print 'Combination', list_rv_comb[comb], ' -- ', i outfile.write( "Combination %s -- %i\n" % ( list_rv_comb[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 ) plt.figure( comb ) s.mean_curve.plot( plt, plot_options ) print 'execution time', s.exec_time outfile.write( "%s \t %s\n" % ( idx, s.exec_time ) ) legend.append( legend_string % s.exec_time ) outfile.write( "=================\n" ) plt.xlabel( 'strain [-]' ) plt.ylabel( 'stress' ) plt.legend( legend ) plt.title( s.rf.title ) del s plt.show()
def run(): sv = SPIRRIDModelView(model = SPIRRID(), rf_values = [ Filament() ]) sv.configure_traits(view = 'traits_view_tabbed')
def run(): # Quantities for the response function # and randomization # 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., 'f':0.0} outfile = open( 'pullout_comb_stat.dat', 'w' ) comb = 0 while_cond = 1 while while_cond == 1: #for comb in range( 1, n_com + 1 ): comb += 1 for i in range( 0, 2 ): # construct a default response function for a single filament 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.05, n_eps=80 ) # construct the random variables n_int = 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':rf.L / 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':'cos_distr', 'loc':0., 'scale':1., 'n_int':n_int}, 'f':{'variable':'f', 'distribution':'uniform', 'loc':0., 'scale':.03, 'n_int':n_int }, } n_var = len( dict_rv ) n_com = 0 for k in range( 6, 7 ): n_com += choose( n_var, k ) # end of the while loop if comb == n_com: while_cond = 0 list_rv_comb = list( powerset( dict_rv, par=6 ) ) for rv in list_rv_comb[comb]: s.add_rv( **dict_rv[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' : 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' ), ] print 'Combination', list_rv_comb[comb], ' -- ', i outfile.write( "Combination %s -- %i\n" % ( list_rv_comb[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 ) plt.figure( comb ) s.mean_curve.plot( plt, plot_options, linewidth=2, label=legend_string % s.exec_time ) print 'execution time', s.exec_time, s.mu_q_peak outfile.write( "%s \t %s\n" % ( idx, s.exec_time ) ) outfile.write( "=================\n" ) plt.xlabel( 'strain [-]' ) plt.ylabel( 'stress' ) plt.legend( loc='lower right' ) plt.title( s.rf.title ) del s plt.show()
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=80 ) # construct the random variables n_int = 70 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 ) s.mean_curve.plot( plt, plot_options ) 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()
q_x = q_x * Heaviside(x + Ll) * Heaviside(Lr - x) q_x = q_x * Heaviside(q_x) return q_x q = CBClampedFiberSP() s = SPIRRID( q=q, sampling_type='LHS', evars=dict(w=np.linspace(0.0, 0.4, 50), x=np.linspace(-20.1, 20.5, 100), Lr=np.linspace(0.1, 20.0, 50)), tvars=dict( tau=RV('uniform', 0.7, 1.0), l=RV('uniform', 5.0, 10.0), D_f=26e-3, E_f=72e3, theta=0.0, xi=RV('weibull_min', scale=0.017, shape=8, n_int=10), phi=1.0, Ll=50.0, # Lr = 1.0 ), n_int=5) e_arr = make_ogrid(s.evar_lst) n_e_arr = [e / np.max(np.fabs(e)) for e in e_arr] max_mu_q = np.max(np.fabs(s.mu_q_arr)) n_mu_q_arr = s.mu_q_arr / max_mu_q n_std_q_arr = np.sqrt(s.var_q_arr) / max_mu_q
def run(): # Quantities for the response function # and randomization # dict_var = {'x' : 10, 'y' : 20, 'z' : 30, 'a' : 40} n_var = len( dict_var ) n_com = 0 for k in range( 0, n_var ): n_com += choose( n_var, k ) outfile = open( 'simple_comb_stat.dat', 'w' ) for comb in range( 1, n_com + 1 ): for i in range( 0, 2 ): # construct a default response function for a single filament rf = Filament() rf.set( **dict_var ) # (x=10, y=20, ...) # construct the integrator and provide it with the response function. s = SPIRRID( rf=rf, min_eps=0.00, max_eps=0.05, n_eps=1 ) # construct the random variables n_int = 35 dict_rv = { 'x':{'variable':'x', 'distribution':'norm', 'loc':10., 'scale':2., 'n_int':n_int}, 'y':{'variable':'y', 'distribution':'norm', 'loc':10., 'scale':2., 'n_int':n_int}, 'z':{'variable':'z', 'distribution':'norm', 'loc':10., 'scale':2., 'n_int':n_int}, 'a':{'variable':'a', 'distribution':'norm', 'loc':10., 'scale':2., 'n_int':n_int}, } list_rv_comb = list( powerset( dict_rv ) ) for rv in list_rv_comb[comb]: s.add_rv( **dict_rv[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' : 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 = [] print 'Combination', list_rv_comb[comb], ' -- ', i outfile.write( "Combination %s -- %i\n" % ( list_rv_comb[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 ) s.mean_curve.plot( plt, plot_options ) print 'execution time', s.exec_time, s.mu_q_peak outfile.write( "%s \t %s\n" % ( idx, s.exec_time ) ) legend.append( legend_string % s.exec_time ) outfile.write( "=================\n" ) plt.xlabel( 'strain [-]' ) plt.ylabel( 'stress' ) plt.legend( legend ) plt.title( s.rf.title ) del s plt.show() outfile.close()
def run(): # Quantities for the response function # and randomization # dict_var = {"x": 10, "y": 20, "z": 30, "a": 40} n_var = len(dict_var) n_com = 0 for k in range(0, n_var): n_com += choose(n_var, k) outfile = open("simple_comb_loop_stat.dat", "w") for comb in range(1, n_com + 1): for i in range(0, 2): # construct a default response function for a single filament rf = Filament() rf.set(**dict_var) # (x=10, y=20, ...) # construct the integrator and provide it with the response function. s = SPIRRID(rf=rf, min_eps=0.00, max_eps=0.05, n_eps=1) # construct the random variables n_int = 35 dict_rv = { "x": {"variable": "x", "distribution": "norm", "loc": 10.0, "scale": 2.0, "n_int": n_int}, "y": {"variable": "y", "distribution": "norm", "loc": 10.0, "scale": 2.0, "n_int": n_int}, "z": {"variable": "z", "distribution": "norm", "loc": 10.0, "scale": 2.0, "n_int": n_int}, "a": {"variable": "a", "distribution": "norm", "loc": 10.0, "scale": 2.0, "n_int": n_int}, } list_rv_comb = list(powerset(dict_rv)) for rv in list_rv_comb[comb]: s.add_rv(**dict_rv[rv]) # define a tables with the run configurations to start in a batch run_list = [ ( {"cached_qg": False, "compiled_qg_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_qg": False, "compiled_qg_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_qg": True, "compiled_qg_loop": True, "compiled_eps_loop": True}, "go-", "$\mathrm{C}_{e,\\theta} ( q(e,\\theta) \cdot G[\\theta] ) $ - %4.2f sec", ), ( {"cached_qg": True, "compiled_qg_loop": False, "compiled_eps_loop": False}, "y--", "$\mathrm{P}_{e} ( \mathrm{N}_{\\theta} ( q(e,\\theta) \cdot G[\\theta] ) ) $ - %4.2f sec", ), ] legend = [] print "Combination", list_rv_comb[comb], " -- ", i outfile.write("Combination %s -- %i\n" % (list_rv_comb[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) s.mean_curve.plot(plt, plot_options) print "execution time", s.exec_time, s.mu_q_peak outfile.write("%s \t %s\n" % (idx, s.exec_time)) legend.append(legend_string % s.exec_time) outfile.write("=================\n") plt.xlabel("strain [-]") plt.ylabel("stress") plt.legend(legend) plt.title(s.rf.title) del s plt.show() outfile.close()
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 = 30, 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)
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()
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
def _get_s(self): return SPIRRID(rf=self.rf, min_eps=0.00, max_eps=1.0, n_eps=20, compiler_verbose=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',