def w_x_results( self, w_arr, x ): epsm = np.zeros( ( len( w_arr ), len( x ) ) ) mu_epsf = np.zeros( ( len( w_arr ), len( x ) ) ) sigma_c = [] for i, w in enumerate( w_arr ): self.model.w = w epsm_line = MFnLineArray( xdata = self.x_arr, ydata = self.epsm_arr ) mu_epsf_line = MFnLineArray( xdata = self.x_arr, ydata = self.mu_epsf_arr ) epsm[i, :] = epsm_line.get_values( x ) mu_epsf[i, :] = mu_epsf_line.get_values( x ) sigma_c.append( self.sigma_c ) return epsm, mu_epsf, np.array( sigma_c )
def _get__epsm_arr(self): if len(self.sorted_reinf_lst[0]) != 0 and len(self.sorted_reinf_lst[1]) != 0: epsm_cont_interp = MFnLineArray(xdata=self.cont_fibers.x_arr, ydata=self.cont_fibers.epsm_arr) epsm_short_interp = MFnLineArray(xdata=self.short_fibers.x_arr, ydata=self.short_fibers.epsm_arr) added_epsm_cont = self.cont_fibers.epsm_arr + epsm_short_interp.get_values(self.cont_fibers.x_arr) added_epsm_short = self.short_fibers.epsm_arr + epsm_cont_interp.get_values(self.short_fibers.x_arr) sorted_unique_idx = np.unique(np.hstack((self.cont_fibers.x_arr, self.short_fibers.x_arr)), return_index=True)[1] return np.hstack((added_epsm_cont, added_epsm_short))[sorted_unique_idx] elif len(self.sorted_reinf_lst[0]) != 0: return self.cont_fibers.epsm_arr elif len(self.sorted_reinf_lst[1]) != 0: self.short_fibers.w = self.w return self.short_fibers.epsm_arr
def w_x_results(self, w_arr, x): epsm = np.zeros((len(w_arr), len(x))) mu_epsf = np.zeros((len(w_arr), len(x))) sigma_c = [] for i, w in enumerate(w_arr): self.model.w = w epsm_line = MFnLineArray(xdata=self.x_arr, ydata=self.epsm_arr) mu_epsf_line = MFnLineArray(xdata=self.x_arr, ydata=self.mu_epsf_arr) epsm[i, :] = epsm_line.get_values(x) mu_epsf[i, :] = mu_epsf_line.get_values(x) sigma_c.append(self.sigma_c) return epsm, mu_epsf, np.array(sigma_c)
def ppf( self, x ): self.check() if len( self.cdf_values ) != 0: xx, cdf = self.x_values, self.cdf_values else: xx, cdf = self.x_values, self.cdf( self.x_values ) ppf_mfn_line = MFnLineArray( xdata = cdf, ydata = xx ) return ppf_mfn_line.get_values( x )
def get_epsm_x(self, w): """ evaluates the matrix strain profile at given load """ self.CB_model.w = w if self.CB_model.Ll > self.CB_model.Lr: epsm_interp = MFnLineArray(xdata=-self.CB_model._x_arr[::-1], ydata=self.CB_model._epsm_arr[::-1]) else: epsm_interp = MFnLineArray(xdata=self.CB_model._x_arr, ydata=self.CB_model._epsm_arr) return epsm_interp.get_values(self.x)
def get_epsf_x(self, w): ''' evaluates the mean fiber strain profile at given load ''' self.CB_model.w = w if self.CB_model.Ll > self.CB_model.Lr: epsf_interp = MFnLineArray(xdata=-self.CB_model._x_arr[::-1], ydata=self.CB_model._epsf_arr[::-1]) else: epsf_interp = MFnLineArray(xdata=self.CB_model._x_arr, ydata=self.CB_model._epsf_arr) return epsf_interp.get_values(self.x)
def _get__epsm_arr(self): if len(self.sorted_reinf_lst[0]) != 0 and len( self.sorted_reinf_lst[1]) != 0: epsm_cont_interp = MFnLineArray(xdata=self.cont_fibers.x_arr, ydata=self.cont_fibers.epsm_arr) epsm_short_interp = MFnLineArray(xdata=self.short_fibers.x_arr, ydata=self.short_fibers.epsm_arr) added_epsm_cont = self.cont_fibers.epsm_arr + epsm_short_interp.get_values( self.cont_fibers.x_arr) added_epsm_short = self.short_fibers.epsm_arr + epsm_cont_interp.get_values( self.short_fibers.x_arr) sorted_unique_idx = np.unique(np.hstack( (self.cont_fibers.x_arr, self.short_fibers.x_arr)), return_index=True)[1] return np.hstack( (added_epsm_cont, added_epsm_short))[sorted_unique_idx] elif len(self.sorted_reinf_lst[0]) != 0: return self.cont_fibers.epsm_arr elif len(self.sorted_reinf_lst[1]) != 0: self.short_fibers.w = self.w return self.short_fibers.epsm_arr
def get_epsf_x(self, w): ''' evaluates the mean fiber strain profile at given load ''' self.CB_model.w = w if self.CB_model.Ll > self.CB_model.Lr: epsf_interp = MFnLineArray(xdata=-self.CB_model._x_arr[::-1], ydata=self.CB_model._epsf_arr[::-1]) else: epsf_interp = MFnLineArray(xdata=self.CB_model._x_arr, ydata=self.CB_model._epsf_arr) return epsf_interp.get_values(self.x)
def _get_pdf_array( self ): # get the normed histogram implemented in the base class YMBHist h, b = self.normed_hist b_cen = ( b[1:] + b[:-1] ) / 2. mask = ( h != 0. ) h = h[mask] b_cen = b_cen[mask] b = hstack( [min( b ), b_cen, max( b )] ) h = hstack( [0, h, 0] ) h = h / trapz( h, b ) p = MFnLineArray( xdata=b, ydata=h ) return p.get_values( self.x_array )
def _get_matrix_strength(self): # evaluates a random field # realization and creates a spline representation rf = self.random_field.random_field rf_spline = MFnLineArray(xdata=self.random_field.xgrid, ydata=rf) return rf_spline.get_values(self.x_arr)
def get_L(self, Ll, Lr): self.result_values BC_line = MFnLineArray(xdata=self.BC_range, ydata=self.BC_range, extrapolate='constant') return BC_line.get_values([Ll, Lr])
def get_sigma_m_x_input( self, sigma ): self.apply_load( sigma ) line = MFnLineArray( xdata = self.x_arr, ydata = self.epsm_arr ) return line.get_values( self.x_input )
def eta(self, psi): psi_line = MFnLineArray(xdata=self.psi_line.ydata, ydata=self.psi_line.xdata) return psi_line.get_values(psi, k=1)
def get_L( self, Ll, Lr ): self.result_values BC_line = MFnLineArray( xdata = self.BC_range, ydata = self.BC_range, extrapolate = 'constant' ) return BC_line.get_values( [Ll, Lr] )
def eta(self, psi): psi_line = MFnLineArray(xdata=self.psi_line.ydata, ydata=self.psi_line.xdata) return psi_line.get_values(psi, k=1)
def _get_matrix_strength(self): # evaluates a random field # realization and creates a spline reprezentation rf = self.random_field.random_field rf_spline = MFnLineArray(xdata=self.random_field.xgrid, ydata=rf) return rf_spline.get_values(self.x_arr)
for w in w_arr: cdfs.append(self.Pw(w)) return cdfs if __name__ == '__main__': ac = AnalyticalCracks(l0=1., d=0.007, tau=0.1, sigma0=2200., s=2.0, rho=5.0, c=1.0, x=np.linspace(0.0, 5.0, 500)) for s in [1., 3., 5.0]: ac.s = s pdf_x = ac.p_x(s, ac.x) pdf_x = pdf_x / np.trapz(pdf_x, ac.x) cdf_x = np.hstack((0., cumtrapz(pdf_x, ac.x))) sf = MFnLineArray(xdata=cdf_x + 1e-12 * ac.x, ydata=ac.x) rand_vals1 = sf.get_values(np.random.rand(10000)) rand_vals2 = sf.get_values(np.random.rand(10000)) cracks = ac.w_func(rand_vals1, rand_vals2) plt.hist(cracks, bins=40, normed=True, label=str(s), cumulative=True) w_arr = np.linspace(0.0, 7.0, 100) cdf_w = ac.CDF_w(w_arr) plt.plot(w_arr, cdf_w, color='black', lw=2) plt.ylim(0, 1.2) plt.legend() plt.show()
def Pw(self, w): mask = self.cached_pdfs[3] < w dx2 = (self.x[-1]-self.x[-2])**2 return np.sum(self.cached_pdfs[2] * mask * dx2) def CDF_w(self, w_arr): cdfs = [] for w in w_arr: cdfs.append(self.Pw(w)) return cdfs if __name__ == '__main__': ac = AnalyticalCracks(l0=1., d=0.007, tau=0.1, sigma0=2200., s=2.0, rho=5.0, c=1.0, x=np.linspace(0.0, 5.0, 500)) for s in [1., 3., 5.0]: ac.s = s pdf_x = ac.p_x(s, ac.x) pdf_x = pdf_x / np.trapz(pdf_x, ac.x) cdf_x = np.hstack((0., cumtrapz(pdf_x, ac.x))) sf = MFnLineArray(xdata=cdf_x + 1e-12 * ac.x, ydata=ac.x) rand_vals1 = sf.get_values(np.random.rand(10000)) rand_vals2 = sf.get_values(np.random.rand(10000)) cracks = ac.w_func(rand_vals1, rand_vals2) plt.hist(cracks, bins=40, normed=True, label=str(s), cumulative=True) w_arr = np.linspace(0.0,7.0,100) cdf_w = ac.CDF_w(w_arr) plt.plot(w_arr, cdf_w, color='black', lw=2) plt.ylim(0,1.2) plt.legend() plt.show()
def get_sigma_m_x_input(self, sigma): self.apply_load(sigma) line = MFnLineArray(xdata=self.x_arr, ydata=self.epsm_arr) return line.get_values(self.x_input)