def model_free(self, tau_loc, tau_shape, tau_scale): xi_shape = 6.7 #xi_scale = 3243. / (182e3 * (pi * 3.5e-3 **2 * 50.)**(-1./xi_shape)*gamma(1+1./xi_shape)) xi_scale = 7.6e-3 #CS=8. #mu_tau = 1.3 * self.r * 3.6 * (1.-0.01) / (2. * 0.01 * CS) #tau_scale = (mu_tau - tau_loc)/tau_shape #xi_scale = 0.0077 #xi_shape = 6.7 #tau_scale = (mu_tau - tau_loc)/tau_shape cb = CBClampedRandXi(pullout=False) spirrid = SPIRRID(q=cb, sampling_type='LHS') tau = RV('gamma', shape=tau_shape, scale=tau_scale, loc=tau_loc) w = self.w spirrid.eps_vars = dict(w=w) spirrid.theta_vars = dict(tau=tau, E_f=self.Ef, V_f=self.V_f, r=self.r, m=xi_shape, sV0=xi_scale) spirrid.n_int = 5000 sigma_c = spirrid.mu_q_arr / self.r**2 plt.plot(w, sigma_c) return sigma_c
def hybrid(): cb = CBClampedRandXi() w = np.linspace(0.0, 2.5, 1000) spirrid = SPIRRID(q=cb, sampling_type='PGrid', eps_vars=dict(w=w), theta_vars=dict(tau=0.5, E_f=180e3, V_f=0.01, r=0.00345, m=7.0, sV0=0.0026, lm=1000.), n_int=100) sigma_c1 = spirrid.mu_q_arr / spirrid.theta_vars['r'] ** 2 plt.plot(w, sigma_c1, label='1') spirrid.theta_vars['E_f'] = 70e3 spirrid.theta_vars['r'] = 0.013 spirrid.theta_vars['sV0'] = 0.015 spirrid.theta_vars['m'] = 20. sigma_c2 = spirrid.mu_q_arr / spirrid.theta_vars['r'] ** 2 plt.plot(w, sigma_c2, label='2') plt.plot(w, sigma_c2 + sigma_c1) plt.ylim(0, 20) plt.legend() plt.show()
def _get_model_extrapolate(self): cb = CBClampedRandXi(pullout=False) spirrid = SPIRRID(q=cb, sampling_type='LHS') sV0 = self.sV0 V_f = 1.0 r = 3.5e-3 m = self.m tau = RV('gamma', shape=self.tau_shape, scale=self.tau_scale, loc=self.tau_loc) n_int = self.n_int w = self.w2 lm = self.lm spirrid.eps_vars = dict(w=w) spirrid.theta_vars = dict(tau=tau, E_f=self.Ef, V_f=V_f, r=r, m=m, sV0=sV0, lm=lm) spirrid.n_int = n_int sigma_c = spirrid.mu_q_arr / self.r**2 return sigma_c
def _get_model_extrapolate(self): cb = CBClampedRandXi(pullout=False) spirrid = SPIRRID(q=cb, sampling_type='LHS') sV0 = self.sV0 V_f = 1.0 r = 3.5e-3 m = self.m tau = RV('gamma', shape=self.tau_shape, scale=self.tau_scale, loc=self.tau_loc) n_int = self.n_int w = self.w2 lm = self.lm spirrid.eps_vars = dict(w=w) spirrid.theta_vars = dict(tau=tau, E_f=self.Ef, V_f=V_f, r=r, m=m, sV0=sV0, lm=lm) spirrid.n_int = n_int sigma_c = spirrid.mu_q_arr / self.r ** 2 return sigma_c
def model_clamped(self, tau_shape, tau_scale, tau_loc): cb = CBClampedRandXi(pullout=True) spirrid = SPIRRID(q=cb, sampling_type='LHS') sV0 = self.sV0 V_f = self.V_f r = self.r m = self.m tau = RV('gamma', shape=tau_shape, scale=tau_scale, loc=tau_loc) n_int = self.n_int w = self.w2 lm = self.lm spirrid.eps_vars = dict(w=w) spirrid.theta_vars = dict(tau=tau, E_f=self.Ef, V_f=V_f, r=r, m=m, sV0=sV0, lm=lm) spirrid.n_int = n_int sigma_c = spirrid.mu_q_arr / self.r ** 2 return sigma_c
def model_free(self, tau_loc, tau_shape, tau_scale): xi_shape = 6.7 #xi_scale = 3243. / (182e3 * (pi * 3.5e-3 **2 * 50.)**(-1./xi_shape)*gamma(1+1./xi_shape)) xi_scale = 7.6e-3 #CS=8. #mu_tau = 1.3 * self.r * 3.6 * (1.-0.01) / (2. * 0.01 * CS) #tau_scale = (mu_tau - tau_loc)/tau_shape #xi_scale = 0.0077 #xi_shape = 6.7 #tau_scale = (mu_tau - tau_loc)/tau_shape cb = CBClampedRandXi(pullout=False) spirrid = SPIRRID(q=cb, sampling_type='LHS') tau = RV('gamma', shape=tau_shape, scale=tau_scale, loc=tau_loc) w = self.w spirrid.eps_vars = dict(w=w) spirrid.theta_vars = dict(tau=tau, E_f=self.Ef, V_f=self.V_f, r=self.r, m=xi_shape, sV0=xi_scale) spirrid.n_int = 5000 sigma_c = spirrid.mu_q_arr / self.r ** 2 plt.plot(w, sigma_c) return sigma_c
def _get_model_rand(self): cb = CBResidualRandXi() spirrid = SPIRRID(q=cb, sampling_type='PGrid') sV0 = self.sV0 tau_scale = self.tau_scale V_f = 1.0 r = 3.5e-3 m = self.m tau = RV('weibull_min', shape=self.tau_shape, scale=tau_scale, loc=self.tau_loc) n_int = self.n_int w = self.w spirrid.eps_vars=dict(w=w) spirrid.theta_vars=dict(tau=tau, E_f=self.Ef, V_f=V_f, r=r, m=m, sV0=sV0) spirrid.n_int=n_int if isinstance(r, RV): r_arr = np.linspace(r.ppf(0.001), r.ppf(0.999), 300) Er = np.trapz(r_arr ** 2 * r.pdf(r_arr), r_arr) else: Er = r ** 2 sigma_c = spirrid.mu_q_arr / Er return sigma_c
def hybrid(): cb = CBClampedRandXi() w = np.linspace(0.0, 2.5, 1000) spirrid = SPIRRID(q=cb, sampling_type='PGrid', eps_vars=dict(w=w), theta_vars=dict(tau=0.5, E_f=180e3, V_f=0.01, r=0.00345, m=7.0, sV0=0.0026, lm=1000.), n_int=100) sigma_c1 = spirrid.mu_q_arr / spirrid.theta_vars['r']**2 plt.plot(w, sigma_c1, label='1') spirrid.theta_vars['E_f'] = 70e3 spirrid.theta_vars['r'] = 0.013 spirrid.theta_vars['sV0'] = 0.015 spirrid.theta_vars['m'] = 20. sigma_c2 = spirrid.mu_q_arr / spirrid.theta_vars['r']**2 plt.plot(w, sigma_c2, label='2') plt.plot(w, sigma_c2 + sigma_c1) plt.ylim(0, 20) plt.legend() plt.show()
def simplified(): cb = CBClampedRandXi() spirrid = SPIRRID(q=cb, sampling_type='PGrid', theta_vars=dict(tau=RV('gamma', loc=0.0055, scale=0.7, shape=0.2), E_f=200e3, V_f=0.01, r=0.00345, m=7.0, sV0=0.0042, lm=1000.), n_int=200) def sigmac(w, lm): spirrid.eps_vars['w'] = np.array([w]) spirrid.theta_vars['lm'] = lm sigma_c = spirrid.mu_q_arr / spirrid.theta_vars['r']**2 return sigma_c def maxsigma(lm): def minfunc(w): res = sigmac(w, lm) return -res * (w < 200.) + 1e-5 * w**2 w_max = minimize_scalar(minfunc, bracket=(0.0001, 0.0002)) return w_max.x, sigmac(w_max.x, lm) / spirrid.theta_vars['V_f'] sigmaf = [] w_lst = [] lcs = 1. / np.linspace(8.4, 300.0, 20) for lcsi in lcs: print lcsi wi, sigi = maxsigma(1. / lcsi) sigmaf.append(sigi) w_lst.append(wi) plt.plot(lcs, sigmaf) plt.plot(1. / 13.7, 1201, 'ro') plt.plot(1. / 9.7, 1373, 'bo') plt.errorbar(1. / 13.7, 1201, 104.4) plt.errorbar(1. / 9.7, 1373, 36.4) plt.ylim(0) plt.figure() plt.plot(lcs, w_lst) plt.plot(1. / 13.7, 0.088, 'ro') plt.plot(1. / 9.7, 0.05, 'bo') plt.errorbar(1. / 13.7, 0.088, 0.003) plt.errorbar(1. / 9.7, 0.05, 0.005) plt.ylim(0) plt.show()
def mechanisms(): m = 5.15004407 sV0 = 0.00915595 r = 3.5e-3 Ef = 181e3 cb = CBClampedRandXi(pullout=False) spirrid = SPIRRID(q=cb, sampling_type='LHS', theta_vars=dict(E_f=Ef, sV0=sV0, V_f=1.0, r=r, m=m, tau=RV('gamma', shape=0.03684979, scale=3.75278102, loc=0.0), lm=1000.), n_int=100, ) lm_arr = np.linspace(1000., 3., 20) sigma_u_hommech = [] for lm_i in lm_arr: spirrid.theta_vars['lm'] = lm_i max_w = min(30., lm_i * 0.07) w_arr = np.linspace(0.0, max_w, 200) spirrid.eps_vars = dict(w=w_arr) sig_w = spirrid.mu_q_arr / r ** 2 plt.plot(w_arr, sig_w) plt.show() sigma_u_hommech.append(np.max(sig_w)) sigma_u_hommech = np.array(sigma_u_hommech) plt.plot(lm_arr, sigma_u_hommech)#/np.min(sigma_u_hommech)) plt.xlabel('crack spacing') plt.ylabel('normalized strength') plt.show()
def short_fibers_CHOB(): cb = CBShortFiber() Ef = 200e3 Vf = 0.015 r = 0.088 Lc = 400. Ac = 1600. lf = 14. spirrid = SPIRRID(q=cb, sampling_type='PGrid', eps_vars=dict(w=np.array([100.0])), theta_vars=dict(tau=1.8, E_f=Ef, r=r, le=RV('uniform', scale=lf / 2., loc=0.0), phi=RV('sin2x', scale=1.0), snub=.87, xi=20e10), n_int=100) spirrid.codegen.implicit_var_eval = True var_e = spirrid.var_q_arr mu_e = spirrid.mu_q_arr Af = pi * r**2 p = lf / 2. / Lc n = Ac * Lc * Vf / Af / lf mu_strength = Ef * Vf / 2. * mu_e var_strength = (Ef * Vf / 2.)**2 / n / p * (var_e + (1. - p) * mu_e**2) n = np.arange(10) distr = norm(loc=mu_strength, scale=var_strength**(0.5)) sig_arr = np.linspace(mu_strength / 2., mu_strength * 1.5, 1000) CDF1 = distr.cdf(sig_arr) CDF2 = 1 - (1 - CDF1)**2 CDF10 = 1 - (1 - CDF1)**10 plt.figure() plt.plot(sig_arr, CDF1, label='strength distr 1') plt.plot(sig_arr, CDF2, label='strength distr 2') plt.plot(sig_arr, CDF10, label='strength distr 10') plt.figure() cracks = np.linspace(1, 100, 500) plt.plot(cracks, distr.ppf(1. - 0.5**(1. / cracks)), label='0.5') plt.plot(cracks, distr.ppf(1. - 0.99999**(1. / cracks)), label='0.000001') plt.ylim(1.0, 3.0) plt.legend() plt.show()
# print self.count / (30**3)*100, 'percent' # print 'current params:', [sV0, m, tau], 'best params:', self.x0 # print 'current residuum:', resid, 'best:', self.residuum return if __name__ == '__main__': from quaducom.micro.resp_func.CB_rigid_mtrx_rand_xi import CBResidualRandXi from spirrid.spirrid import SPIRRID from spirrid.rv import RV from matplotlib import pyplot as plt from scipy.special import gamma, gammainc from math import pi cb = CBResidualRandXi() spirrid = SPIRRID(q=cb, sampling_type='PGrid') def model_rand(params, *args): w = args[0] sV0, tau_scale = params E_f = 180e3 V_f = 1.0 r = 3.45e-3 m = 4. tau = RV('weibull_min', shape=.4, scale=tau_scale, loc=0.009) # a_lower = 0.0 # tau = RV('piecewise_uniform', shape=0.0, scale=1.0) # tau._distr.distr_type.distribution.a_lower = a_lower # tau._distr.distr_type.distribution.a_upper = a_upper # tau._distr.distr_type.distribution.b_lower = a_upper # tau._distr.distr_type.distribution.b_upper = b_upper
from matplotlib import pyplot as plt from scipy.stats import weibull_min from stats.pdistrib.weibull_fibers_composite_distr import fibers_MC, fibers_CB_rigid, fibers_dry from scipy.optimize import minimize_scalar import pickle from stats.spirrid import make_ogrid as orthogonalize from mayavi import mlab from math import pi from scipy.stats import norm cb = CBClampedRandXi() spirrid = SPIRRID(q=cb, sampling_type='PGrid', theta_vars=dict(tau=0.1, E_f=200e3, V_f=0.01, r=0.00345, m=5.0, sV0=0.0026, lm=1000.), n_int=100) def fiber(): cb = CBClamped() w = np.linspace(0.0, 1., 300) sigmaCB = [] sigmaMC = [] for wi in w: sigmaCB.append(cb(wi, .1, 240e3, 0.01, 0.0035, 7.0, 0.0046, 5000., 0.5)) sigmaMC.append(cb(wi, .1, 240e3, 0.01, 0.0035, 7.0, 0.0046, 20., 0.5))
def _get_spirrid_filament(self): resp_func = self.micro_model.FilamentCB() spirrid = SPIRRID(q=resp_func) return spirrid