Beispiel #1
0
def arc(r0, R, e, n, phi0, phi):
    e1 = e / np.sqrt(np.sum(e * e))  # normalize
    en = n / np.sqrt(np.sum(n * n))  # normalize
    ip = np.argmax(phi > phi0)  # find end index
    e2 = np.cross(en, e1)
    cp = np.cos(np.radians(phi[:ip]))
    sp = np.sin(np.radians(phi[:ip]))
    #    r  = cp*e1+sp*e2
    r = np.zeros((3, ip))
    r[0, :] = r0[0] + R * (cp * e1[0] + sp * e2[0])
    r[1, :] = r0[1] + R * (cp * e1[1] + sp * e2[1])
    r[2, :] = r0[2] + R * (cp * e1[2] + sp * e2[2])
    return r
Beispiel #2
0
    def drawArc(self, centerxy, startxy, endxy):

        v1 = np.array([startxy[0] - centerxy[0], startxy[1] - centerxy[1]])
        v2 = np.array([endxy[0] - centerxy[0], endxy[1] - centerxy[1]])
        cos夹角 = (v1[0] * v2[0] + v1[1] * v2[1]) / (np.sqrt(v1.dot(v1)) *
                                                   np.sqrt(v2.dot(v2)))
        angle_between = np.arccos(cos夹角)

        radius = np.sqrt(v1.dot(v1))
        angle_start = np.arctan2(v1[1], v1[0])
        angle_end = angle_start + angle_between

        self.ctx.move_to(startxy[0], startxy[1])
        self.ctx.arc(centerxy[0], centerxy[1], radius, angle_start, angle_end)
        # self.ctx.arc_negative(centerxy[0], centerxy[1], radius, angle_start, angle_end)
        return []
Beispiel #3
0
def gauss(x, p, mode='eval'):
    """Gaussian defined by amplitide

    Function:
       :math:`f(x) = k + m*x + p_2 \exp\left(\\frac{-(x - p_0)^2}{2p_1^2}\\right)`

    """
    try:
        if mode == 'eval':
            cent=p[0];wid=p[1];amp=p[2];const=p[3];slope=p[4]
            #out = const + amp * np.exp(-1.0 * (x - cent)**2 / (2 * wid**2))
            #Inserted the 0.5* because we want FWHM out, not HWHM
            #out = const + slope*x + amp * np.exp(-1.0 * (x - cent)**2 / (2 * (0.5*wid)**2))
            conversion =2.0*np.sqrt(2.0*np.log(2))      #Hutchings et al. Introduction to the characterisation of residual stress by neutron diffraction.2005. Page 159 
            #conversion = 2.0
            out = const + slope*x + amp * np.exp(-1.0 * (x - cent)**2 / (2 * (wid/conversion)**2))
        elif mode == 'params':
            out = ['cent', 'sigma', 'amp', 'const', 'slope']
        elif mode == 'name':
            out = "Gaussian"
        elif mode == 'guess':
            g = fitfuncs.peakguess(x, p)
            out = [g[0], g[1] / (4 * np.log(2)), g[3], g[4], g[5]]
        else:
            out = []
    except:
        out = [0,0,0,0,0]

    return out
Beispiel #4
0
def ltfree(lK, Rg, alpha, beta, delta, omegat):
    ltx = np.cos(alpha) * np.cos(np.radians(omegat) + delta) + np.cos(
        beta) * lK - np.cos(np.radians(omegat)) * Rg
    lty = np.sin(np.radians(omegat) + delta) - np.sin(np.radians(omegat)) * Rg
    ltz = -np.sin(alpha) * np.cos(np.radians(omegat) +
                                  delta) + np.sin(beta) * lK
    return np.sqrt(ltx * ltx + lty * lty + ltz * ltz)
Beispiel #5
0
def cosgammag(lK, Rg, beta, delta, omegat):
    alpha  = 0.5*np.pi-beta
    cb     =  np.cos(beta)
    sb     =  np.sin(beta)
    cot    =  np.cos(np.radians(omegat))
    sot    =  np.sin(np.radians(omegat))
    cotd   =  np.cos(np.radians(omegat)+delta)
    sotd   =  np.sin(np.radians(omegat)+delta)
    ltx    =  np.cos(alpha)*cotd + cb*lK - cot*Rg
    lty    =                sotd         - sot*Rg
    ltz    = -np.sin(alpha)*cotd + sb*lK
    Rwx    =  cot*Rg
    Rwy    =  sot*Rg
    Rwz    =  0
    lt     =  np.sqrt(ltx*ltx+lty*lty+ltz*ltz)
    return (Rwx*lty-Rwy*ltx)/(lt*Rg)
Beispiel #6
0
def vt(lK, Rg, beta, delta, omegat):
    alpha  = 0.5*np.pi-beta
    cb     =  np.cos(beta)
    sb     =  np.sin(beta)
    ca     =  np.cos(alpha)
    sa     =  np.sin(alpha)
    cot    =  np.cos(np.radians(omegat))
    sot    =  np.sin(np.radians(omegat))
    cotd   =  np.cos(np.radians(omegat)+delta)
    sotd   =  np.sin(np.radians(omegat)+delta)
    ltx    =  ca*cotd + cb*lK - cot*Rg
    lty    =     sotd         - sot*Rg
    ltz    = -sa*cotd + sb*lK
    lt     =  np.sqrt(ltx*ltx+lty*lty+ltz*ltz)
    dltxdt = -ca*sotd         + sot*Rg
    dltydt =     cotd         - cot*Rg
    dltzdt =  sa*sotd
    return (ltx*dltxdt+lty*dltydt+ltz*dltzdt)/lt
Beispiel #7
0
def cosgammak(lK, Rg, beta, delta, omegat):
    alpha  = 0.5*np.pi-beta
    cb     =  np.cos(beta)
    sb     =  np.sin(beta)
    ca     =  np.cos(alpha)
    sa     =  np.sin(alpha)
    cot    =  np.cos(np.radians(omegat))
    sot    =  np.sin(np.radians(omegat))
    cotd   =  np.cos(np.radians(omegat)+delta)
    sotd   =  np.sin(np.radians(omegat)+delta)
    Rax    =  ca*cotd
    Ray    =     sotd
    Raz    = -sa*cotd
    ltx    =  Rax + cb*lK - cot*Rg
    lty    =  Ray         - sot*Rg
    ltz    =  Raz + sb*lK
    lt     =  np.sqrt(ltx*ltx+lty*lty+ltz*ltz)
    return (sa*(Ray*ltz-Raz*lty) + ca*(Rax*lty-Ray*ltx))/lt
Beispiel #8
0
def gammak2(lK, Rg, beta, delta, omegat):
    alpha = 0.5 * np.pi - beta
    cb = np.cos(beta)
    sb = np.sin(beta)
    cot = np.cos(np.radians(omegat))
    sot = np.sin(np.radians(omegat))
    cotd = np.cos(np.radians(omegat) + delta)
    sotd = np.sin(np.radians(omegat) + delta)
    cotdt = np.cos(np.radians(omegat + 90) + delta)
    sotdt = np.sin(np.radians(omegat + 90) + delta)
    ltx = np.cos(alpha) * cotd + cb * lK - cot * Rg
    lty = sotd - sot * Rg
    ltz = -np.sin(alpha) * cotd + sb * lK
    eyrx = np.cos(alpha) * cotdt
    eyry = sotdt
    eyrz = -np.sin(alpha) * cotdt
    lt = np.sqrt(ltx * ltx + lty * lty + ltz * ltz)
    return np.degrees(np.arccos((eyrx * ltx + eyry * lty + eyrz * ltz) / lt))
Beispiel #9
0
    def FitRange(self,rngnum=-1):
        rngtbl=self.ui.range_tbl
        start = rngnum
        end = rngnum +1
        if (rngnum == -1):
            start = 0
            end = len(self.rangeList)

        self.CalcBG()
        
        wedisconnected = False
        try:
            rngtbl.cellChanged.disconnect()     #otherwise this function might be called recursively
            wedisconnected = True
        except:
            True
        
        for i in range(start, end): 
            rng = self.rangeList[i]
            #xdata = rng.line.get_xdata(True)
            #ydata = rng.line.get_ydata(True)
            xdata = self.scanman.datasrc.x[rng.start:rng.stop]
            ydata = self.scanman.datasrc.y[rng.start:rng.stop]
            #xdata_smooth = np.linspace(xdata[0],xdata[-1],100)
            xwidth = xdata[1:]-xdata[:-1]
            
            if ((len(xdata) < 4) or (len(ydata) < 4)): continue                 #break out if the range was chosen wrong
            if (min(ydata) == max(ydata)):                                      #No difference in values detected - cannto fit peak
                gparams = [0.0]*5
                stdev = [0.0]*4
                fitted = ydata
                True
            else:       #Try to fit the data
                gparams = gauss(xdata, ydata, 'guess')
                gparamsfix = [0]*len(gparams)
                gparams[4] = 0.0    #slope
                gparamsfix[4] = 1
                if (rng.position_fix): 
                    gparams[0] = rng.position
                    gparamsfix[0] = 1
                if (rng.fwhm_fix): 
                    gparams[1] = rng.fwhm
                    gparamsfix[1] = 1
                if (rng.intensity_fix): 
                    gparams[2] = rng.intensity
                    gparamsfix[2] = 1
                if (rng.background_fix): 
                    #gparams[3] = rng.background
                    #gparamsfix[3] = 1
                    gparams[3] = rng.bgndfitparms[1]
                    gparamsfix[3] = 1
                    gparams[4] = rng.bgndfitparms[0]
                    gparamsfix[4] = 1
                fitob = fit.fit(x=xdata, y=ydata, guess=gparams, ifix=gparamsfix ,quiet=True, funcs=[gauss], r2min=-100000, optimizer='mpfit')
            
                if ((min(gparams) == max(gparams)) and min(gparams)==0):      #Could not find any possible peak
                    fitted = ydata
                    stdev = gparams
                    rng.r2 = 0
                    rng.niter = 0
                    rng.time = 0
                else:
                    fitob.go(interactive=False)
                    gparams=fitob.result
                    rng.bgndfitparms[1] = gparams[3]
                    rng.bgndfitparms[0] = gparams[4]
                    stdev=fitob.stdev
                    fitted = gauss(xdata,gparams)
                    #fitted_smooth= gauss(xdata_smooth,gparams)
                    rng.chi2 = fitob.chi2
                    rng.r2 = fitob.r2
                    rng.niter = fitob._niter
                    rng.time = fitob._lastRunTime
            
            #rng.fittedline.set_data(rng.line.get_xdata(True), fitted)
            #rng.diffline.set_data(rng.line.get_xdata(True), rng.line.get_ydata(True) - fitted)
            rng.fittedline.set_data(xdata, fitted)
            #rng.fittedline.set_data(xdata_smooth, fitted_smooth)
            rng.diffline.set_data(xdata, ydata - fitted)
            rng.position = gparams[0]
            rng.fwhm = gparams[1]
            rng.intensity = gparams[2]
            rng.background = gparams[3]
            rng.position_stdev = stdev[0]
            rng.fwhm_stdev = stdev[1]
            rng.intensity_stdev = stdev[2]
            if (self.bgmode=="Single fixed" or self.bgmode=="All fixed" or self.bgmode=="Auto"): rng.background_stdev = stdev[3]
            
            
            #Determine if the calculated fits are valid
            rng.position_valid = True
            rng.fwhm_valid = True
            if (rng.fwhm <= 0) or (rng.fwhm_stdev/rng.fwhm >= 0.2) or (rng.fwhm_stdev == 0 and rng.fwhm_fix==False):
                rng.fwhm_valid = False
                rng.position_valid = False
            
            if (rng.intensity <= 0) or (rng.intensity_stdev/rng.intensity >= 0.3) or (rng.intensity_stdev == 0  and rng.intensity_fix==False):
                rng.intensity_valid = False
                rng.position_valid = False 
            else:
                rng.intensity_valid = True
            #if (rng.intensity == False): rng.position_valid = False  
                
            if (rng.background != 0):
                if (rng.intensity / rng.background < 1.1): rng.position_valid = False  
                
            if (rng.position < xdata.min()) or (rng.position > xdata.max()):
                rng.position_valid = False
                
            
            ybgnd = fitfuncs.linear(xdata, rng.bgndfitparms,"eval")    
            rng.intensity_sum = np.sum(fitted-ybgnd)
            rng.intensity_area = np.sum(abs((fitted-ybgnd)[:-1]*xwidth))
            rng.counts = np.sum(ydata)
            #cmnerrterm = np.sqrt(2.0*rng.position_stdev*rng.position_stdev/rng.position/rng.position)*1e6
            if self.scanman.axistype == "d-spacing":
                #rng.errustrain = np.sqrt(2.0*rng.position_stdev*rng.position_stdev/rng.position/rng.position)/rng.position*1e6
                rng.errustrain = np.sqrt(2.0)*rng.position_stdev/rng.position*1e6
            #elif self.scanman.axistype =="Angle":
                #pos = np.sin(np.deg2rad(rng.position/2.0))
                #err = np.sin(np.deg2rad(rng.position_stdev/2.0))
                #rng.errustrain = np.sqrt(2.0*err*err/pos/pos)/pos*1e6
            else:
                rng.errustrain=0.0
                    
            rngtbl.item(self.position_row, i*2).setForeground(qt.QBrush(qt.QColor('Black' if rng.position_valid else 'Red')))
            rngtbl.item(self.position_row, i*2).setText("{0:.4f}".format(rng.position))
            rngtbl.item(self.position_row, i*2 + 1).setText("{0:.3e}".format(rng.position_stdev))
            rngtbl.item(self.fwhm_row, i*2).setForeground(qt.QBrush(qt.QColor('Black' if rng.fwhm_valid else 'Red')))
            rngtbl.item(self.fwhm_row, i*2).setText("{0:.4f}".format(rng.fwhm))
            rngtbl.item(self.fwhm_row, i*2 + 1).setText("{0:.3e}".format(rng.fwhm_stdev))
            rngtbl.item(self.intensity_row, i*2).setForeground(qt.QBrush(qt.QColor('Black' if rng.intensity_valid else 'Red')))
            rngtbl.item(self.intensity_row, i*2).setText("{0:.4f}".format(rng.intensity))
            rngtbl.item(self.intensity_row, i*2 + 1).setText("{0:.3e}".format(rng.intensity_stdev))
            rngtbl.item(self.background_row, i*2).setText("{0:.4f}".format(rng.background))
            rngtbl.item(self.background_row, i*2 + 1).setText("{0:.3e}".format(rng.background_stdev))
            rngtbl.item(self.chi2_row, i*2).setText("{0:.3e}".format(rng.chi2))
            rngtbl.item(self.r2_row, i*2).setText("{0:.4f}".format(rng.r2))
            rngtbl.item(self.niter_row, i*2).setText("{0:.4f}".format(rng.niter))
            rngtbl.item(self.time_row, i*2).setText("{0:.4f}".format(rng.time))
            rngtbl.item(self.intensity_sum_row, i*2).setText("{0:.4f}".format(rng.intensity_sum))
            rngtbl.item(self.intensity_area_row, i*2).setText("{0:.4f}".format(rng.intensity_area))
            rngtbl.item(self.counts_row, i*2).setText("{0:.4f}".format(rng.counts))
            rngtbl.item(self.errustrain_row, i*2).setText("{0:.4f}".format(rng.errustrain))
           
            
        #self.scanman.ui.graph.draw()
        
        ymin = y = 0.0
        ymax = x = 0.0
        for rng in self.rangeList:
            if (len(rng.diffline._y) > 0):
                y = min(rng.diffline.get_ydata(True))
                if (y < ymin): ymin = y
                y = max(rng.diffline.get_ydata(True))
                if (y > ymax): ymax = y
        ybuf = (ymax - ymin) * 0.1
        if ybuf == 0: ybuf = 1.0
        self.scanman.ui.diffgraph.figure.axes[0].set_ylim(ymin - ybuf, ymax + ybuf)
            
                 
        #self.scanman.ui.diffgraph.draw()
        
    
        if (wedisconnected): rngtbl.cellChanged.connect(self.CellValueChanged)   #Reconnect the signal
        self.fittedsignal.emit()        #To call any listeners
        True
    
    #**************************************************************************************
#if __name__ == '__main__':
    
#    app = qt.QApplication(sys.argv)
#    window=FitDEF()
#    window.show()
#    sys.exit(app.exec_())

        
Beispiel #10
0
def zcopt(CL, G):
    #   return 4./27.*CL*G**2
    return 4. / 27. * CL * (1 + G**2) / G * np.sqrt(1 + G**2)
Beispiel #11
0
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1],
                color='k',
                alpha=.2)
ax.set_xlabel('Date')
ax.set_ylabel('infected')

plt.legend()
# plt.savefig('./Figures/decemberPrediction.png', bbox_inches = 'tight' )
plt.show()
#
y_predicted = prediction.predicted_mean
y_real = df['2020-10-01']
mse = ((y_predicted - y_real)**2).mean()
print('The Mean Squared Error of our forecasts is {}'.format(round(mse, 2)))
print('The Root Mean Squared Error of our forecasts is {}'.format(
    round(np.sqrt(mse), 2)))

# future prediction
# future = results.get_forecast(steps=100)
# pred_ci = future.conf_int()
#
# ax = df.plot(label='observed', figsize=(14,7))
# future.predicted_mean.plot(ax=ax,label= 'forecast')
# ax.fill_between(pred_ci.index, pred_ci.iloc[:,0], pred_ci.iloc[:,1], color='k', alpha=.25)
# ax.set_xlabel('Date')
# ax.set_ylabel('Infected')
#
# plt.legend()
# plt.show()
Beispiel #12
0
    def draw_spmsm(self, acm_variant):
        # Rotor Core
        list_regions_1 = acm_variant.rotorCore.draw(self,
                                                    bool_draw_whole_model=True)
        # self.bMirror = False
        # self.iRotateCopy = acm_variant.rotorCore.p*2
        # region1 = self.prepareSection(list_regions_1)

        # Shaft
        # list_regions = acm_variant.shaft.draw(self)
        # self.bMirror = False
        # self.iRotateCopy = 1
        # region0 = self.prepareSection(list_regions)

        # Rotor Magnet
        list_regions = acm_variant.rotorMagnet.draw(self,
                                                    bool_draw_whole_model=True)
        # self.bMirror = False
        # self.iRotateCopy = acm_variant.rotorMagnet.notched_rotor.p*2
        # region2 = self.prepareSection(list_regions, bRotateMerge=False, color=color_rgb_B)

        # Sleeve
        # list_regions = acm_variant.sleeve.draw(self)
        # self.bMirror = False
        # self.iRotateCopy = acm_variant.rotorMagnet.notched_rotor.p*2
        # regionS = self.prepareSection(list_regions)

        # Stator Core
        list_regions = acm_variant.stator_core.draw(self,
                                                    bool_draw_whole_model=True)
        # self.bMirror = True
        # self.iRotateCopy = acm_variant.stator_core.Q
        # region3 = self.prepareSection(list_regions)

        # Stator Winding
        # list_regions = acm_variant.coils.draw(self, bool_draw_whole_model=True)
        # self.bMirror = False
        # self.iRotateCopy = acm_variant.coils.stator_core.Q
        # region4 = self.prepareSection(list_regions)

        self.apply_stroke()
        self.save()

        if False:
            # 根据绕组的形状去计算可以放铜导线的面积,然后根据电流密度计算定子电流
            EX = acm_variant.template.d['EX']
            CurrentAmp_in_the_slot = acm_variant.coils.mm2_slot_area * EX[
                'WindingFill'] * EX['Js'] * 1e-6 * np.sqrt(2)  #/2.2*2.8
            CurrentAmp_per_conductor = CurrentAmp_in_the_slot / EX['DriveW_zQ']
            CurrentAmp_per_phase = CurrentAmp_per_conductor * EX[
                'wily'].number_parallel_branch  # 跟几层绕组根本没关系!除以zQ的时候,就已经变成每根导体的电流了。

            # Maybe there is a bug here... regarding the excitation for suspension winding...
            variant_DriveW_CurrentAmp = CurrentAmp_per_phase  # this current amp value is for non-bearingless motor
            variant_BeariW_CurrentAmp = CurrentAmp_per_conductor * 1  # number_parallel_branch is 1 for suspension winding
            EX['CurrentAmp_per_phase'] = CurrentAmp_per_phase
            EX['DriveW_CurrentAmp'] = acm_variant.template.fea_config_dict[
                'TORQUE_CURRENT_RATIO'] * variant_DriveW_CurrentAmp
            EX['BeariW_CurrentAmp'] = acm_variant.template.fea_config_dict[
                'SUSPENSION_CURRENT_RATIO'] * variant_DriveW_CurrentAmp

            slot_current_utilizing_ratio = (
                EX['DriveW_CurrentAmp'] +
                EX['BeariW_CurrentAmp']) / EX['CurrentAmp_per_phase']
            # print('[FEMM_SlidingMesh.py]---Heads up! slot_current_utilizing_ratio is', slot_current_utilizing_ratio, '  (PS: =1 means it is combined winding)')

        return True
Beispiel #13
0
def zetar(CL, G, f):
    #    return CL*f*(np.sqrt(1+G**2*(1-f)**2)-f)**2/np.sqrt(1+G**2) # was wrong
    return CL * f * (np.sqrt(1 + G**2 *
                             (1 - f**2)) - f)**2 / (G * np.sqrt(1 + G**2))
Beispiel #14
0
def zetar(CL, G, f):
    return CL*(f/np.sqrt(1 + G**2))*(np.sqrt(1 + (1/G**2) - f**2) - (f/G))**2
Beispiel #15
0
def zetar(CL, G, f):
    return CL*f*(np.sqrt(1+G**2*(1-f)**2)-f)**2/np.sqrt(1+G**2)
Beispiel #16
0
def zetac(CL, G, f):
    #   return CL*G**2*f*(1-f)**2 # was wrong
    return CL * f * (1 - f)**2 * (1 + G**2) / G * np.sqrt(1 + G**2)
Beispiel #17
0
    def redraw_cross_section_outline_with_pyx(tool_tikz, no_repeat_stator,
                                              no_repeat_rotor,
                                              mm_rotor_outer_radius,
                                              mm_air_gap_length,
                                              mm_rotor_outer_steel_radius,
                                              mm_rotor_inner_radius):
        # PyX
        tool_tikz.c = pyx.canvas.canvas(
        )  # clear the canvas because we want to redraw 90 deg with the data tool_tikz.track_path

        print('Index   | Path data')
        p_stator = None  #pyx.path.path()
        p_rotor = None  #pyx.path.path()
        for index, path in enumerate(
                tool_tikz.track_path
        ):  # track_path is passed by reference and is changed by mirror
            # Failed to fill the closed path, because there is no arc-like path available.
            # p = pyx.path.line(4, 0, 5, 0) << pyx.path.line(5, 0, 5, 1) << pyx.path.line(5, 1, 4, 1)
            # p.append(path.closepath())
            # tool_tikz.c.stroke(p)
            # tool_tikz.c.stroke(path.rect(0, 0, 1, 1), [pyx.style.linewidth.Thick,
            #                      pyx.color.rgb.red,
            #                      pyx.deco.filled([pyx.color.rgb.green])])

            path_mirror = deepcopy(path)
            # for mirror copy (along x-axis)
            path_mirror[1] = path[1] * -1
            path_mirror[3] = path[3] * -1
            # for mirror copy (along y-axis)
            # path_mirror[0] = path[0]*-1
            # path_mirror[2] = path[2]*-1

            bool_exclude_path = False

            # rotate path and plot
            if is_at_stator(path, mm_rotor_outer_radius, mm_air_gap_length):
                Q = no_repeat_stator
            else:
                Q = no_repeat_rotor * 2

            EPS = 1e-6
            if is_at_stator(path, mm_rotor_outer_radius, mm_air_gap_length):
                # 按照Eric的要求,把不必要的线给删了。
                if abs(path[1] + path[3]) < EPS:  # 镜像对称线
                    bool_exclude_path = True
                if abs(path[0] - path[2]) + np.cos(
                        2 * np.pi / Q / 2) < EPS:  # 旋转对称线(特别情况,tan(90°) = ∞
                    bool_exclude_path = True
                else:
                    if abs(
                            abs((path[1] - path[3]) / (path[0] - path[2])) -
                            abs(np.tan(2 * np.pi / Q / 2))) < EPS:  # 旋转对称线
                        bool_exclude_path = True

            if not is_at_stator(path, mm_rotor_outer_radius,
                                mm_air_gap_length):
                # 按照Eric的要求,把不必要的线给删了。
                if  (abs(np.sqrt(path[0]**2+path[1]**2) - mm_rotor_inner_radius)<EPS or abs(np.sqrt(path[2]**2+path[3]**2) - mm_rotor_inner_radius)<EPS) \
                    and (len(path)==4): # 转子铁芯内径到外径的直线(len(path)==4)
                    bool_exclude_path = True

            #     # 特别的是,画永磁体的时候,边界要闭合哦。
            #     if abs(np.sqrt(path[0]**2+path[1]**2) - mm_rotor_outer_steel_radius) < EPS or abs(np.sqrt(path[2]**2+path[3]**2) - mm_rotor_outer_steel_radius) < EPS:
            #         bool_exclude_path = False

            # A trick that makes sure models with different outer diameters have the same scale.
            # tool_tikz.draw_arc([125,0], [-125,0], relangle=sign*180, untrack=True)
            tool_tikz.c.fill(
                pyx.path.circle(0, 0, 125), [pyx.color.transparency(1)]
            )  # use this if THICK is used. <- Warn: Transparency not available in PostScript, proprietary ghostscript extension code inserted. (save as eps format)
            # tool_tikz.c.fill(pyx.path.circle(0, 0, 125), [pyx.color.rgb.white]) # use this if THICK is used. <- this will over-write everthing... how to change zorder?

            _ = 2 * np.pi / Q

            if True:  # full model
                for counter in range(Q):

                    # 转子:旋转复制
                    if not is_at_stator(path, mm_rotor_outer_radius,
                                        mm_air_gap_length):
                        path[0], path[1] = rotate(_, path[0], path[1])
                        path[2], path[3] = rotate(_, path[2], path[3])
                        路径 = tool_tikz.pyx_draw_path(
                            path,
                            sign=1,
                            bool_exclude_path=bool_exclude_path,
                            bool_stroke=True)
                        if 路径 is not None:
                            if p_rotor is None:
                                p_rotor = 路径
                            else:
                                p_rotor = p_rotor << 路径

                    # 定子:镜像+旋转复制
                    if is_at_stator(path, mm_rotor_outer_radius,
                                    mm_air_gap_length):

                        path[0], path[1] = rotate(_, path[0], path[1])
                        path[2], path[3] = rotate(_, path[2], path[3])
                        路径 = tool_tikz.pyx_draw_path(
                            path,
                            sign=1,
                            bool_exclude_path=bool_exclude_path,
                            bool_stroke=True)
                        # print(index, '\t|', ',\t'.join(['%g'%(el) for el in path]))
                        if 路径 is not None:
                            if p_stator is None:
                                p_stator = 路径
                            else:
                                p_stator = p_stator << 路径

                        path_mirror[0], path_mirror[1] = rotate(
                            _, path_mirror[0], path_mirror[1])
                        path_mirror[2], path_mirror[3] = rotate(
                            _, path_mirror[2], path_mirror[3])
                        路径 = tool_tikz.pyx_draw_path(
                            path_mirror,
                            sign=-1,
                            bool_exclude_path=bool_exclude_path,
                            bool_stroke=True)
                        if 路径 is not None:
                            if p_stator is None:
                                p_stator = 路径
                            else:
                                p_stator = p_stator << 路径

                    # break
            else:  # backup

                # 转子:旋转复制
                if not is_at_stator(path, mm_rotor_outer_radius,
                                    mm_air_gap_length):
                    path[0], path[1] = rotate(0.5 * np.pi - 0.5 * 0.5 * _,
                                              path[0], path[1])
                    path[2], path[3] = rotate(0.5 * np.pi - 0.5 * 0.5 * _,
                                              path[2], path[3])
                    pyx_draw_path(tool_tikz,
                                  path,
                                  sign=1,
                                  bool_exclude_path=bool_exclude_path)
                    # print(index, '\t|', ',\t'.join(['%g'%(el) for el in path]))

                    # path[0], path[1] = rotate(0.5*np.pi - 0*0.5*_, path[0], path[1])
                    # path[2], path[3] = rotate(0.5*np.pi - 0*0.5*_, path[2], path[3])
                    # pyx_draw_path(tool_tikz, path, sign=1, bool_exclude_path=bool_exclude_path)

                # 定子:镜像+旋转复制
                if is_at_stator(path, mm_rotor_outer_radius,
                                mm_air_gap_length):

                    path[0], path[1] = rotate(0.5 * np.pi - 0.5 * _, path[0],
                                              path[1])
                    path[2], path[3] = rotate(0.5 * np.pi - 0.5 * _, path[2],
                                              path[3])
                    pyx_draw_path(tool_tikz,
                                  path,
                                  sign=1,
                                  bool_exclude_path=bool_exclude_path)
                    # print(index, '\t|', ',\t'.join(['%g'%(el) for el in path]))

                    path_mirror[0], path_mirror[1] = rotate(
                        0.5 * np.pi - 0.5 * _, path_mirror[0], path_mirror[1])
                    path_mirror[2], path_mirror[3] = rotate(
                        0.5 * np.pi - 0.5 * _, path_mirror[2], path_mirror[3])
                    pyx_draw_path(tool_tikz,
                                  path_mirror,
                                  sign=-1,
                                  bool_exclude_path=bool_exclude_path)

                    # 注意,所有 tack_path 中的 path 都已经转动了90度了!
                    # for mirror copy (along y-axis)
                    path[0] *= -1
                    path[2] *= -1
                    pyx_draw_path(tool_tikz,
                                  path,
                                  sign=-1,
                                  bool_exclude_path=bool_exclude_path)

                    path_mirror[0] *= -1
                    path_mirror[2] *= -1
                    pyx_draw_path(tool_tikz,
                                  path_mirror,
                                  sign=1,
                                  bool_exclude_path=bool_exclude_path)
Beispiel #18
0
def is_at_stator(path, mm_rotor_outer_radius, mm_air_gap_length):
    return np.sqrt(path[0]**2 + path[1]**2
                   ) > mm_rotor_outer_radius + 0.5 * mm_air_gap_length
Beispiel #19
0
from pylab import sum, np
from scipy.special.orthogonal import p_roots


def gauss(f, n, a, b):
    [x, w] = p_roots(n + 1)
    G = 0.5 * (b - a) * sum(w * f(0.5 * (b - a) * x + 0.5 * (b + a)))
    return G


print(gauss(lambda x: x/(np.sqrt((x**2)+2)), 50, 0.8, 2))
# 0.8246820618559857
Beispiel #20
0
def dzrdf(f, CL, G):
    r = np.sqrt(1 + G**2 * (1 - f**2))
    #   return CL*(f-r)*(2*f*(G**2*(1-f)+r)+(f-r)*r)/(np.sqrt(G**2+1)*r) # this is still wrong!
    return CL / (G * np.sqrt(1 + G**2)) * (r - f) * (r - 3 * f -
                                                     2 * G**2 * f**2 / r)
Beispiel #21
0
    def draw(self, drawer, bool_draw_whole_model=False):

        drawer.getSketch(self.name, self.color)

        alpha_st = self.deg_alpha_st * np.pi / 180
        alpha_so = -self.deg_alpha_so * np.pi / 180
        r_si = self.mm_r_si
        d_so = self.mm_d_so
        d_sp = self.mm_d_sp
        d_st = self.mm_d_st
        d_sy = self.mm_d_sy
        w_st = self.mm_w_st
        r_st = self.mm_r_st
        r_sf = self.mm_r_sf
        r_sb = self.mm_r_sb
        Q = self.Q

        alpha_slot_span = 360 / Q * np.pi / 180

        P1 = [r_si, 0]
        P2 = [r_si * cos(alpha_st * 0.5), r_si * -sin(alpha_st * 0.5)]
        P3_temp = [d_so * cos(alpha_st * 0.5), d_so * -sin(alpha_st * 0.5)]
        P3_local_rotate = [
            cos(alpha_so) * P3_temp[0] + sin(alpha_so) * P3_temp[1],
            -sin(alpha_so) * P3_temp[0] + cos(alpha_so) * P3_temp[1]
        ]
        P3 = [P3_local_rotate[0] + P2[0], P3_local_rotate[1] + P2[1]]

        三角形的底 = r_si + d_sp
        三角形的高 = w_st * 0.5
        三角形的角度 = arctan(三角形的高 / 三角形的底)
        P4 = [三角形的底 * cos(三角形的角度), 三角形的底 * -sin(三角形的角度)]

        P5 = [P4[0] + d_st, P4[1]]

        # Option 1
        # 6 [94.01649113009418, -25.191642873516543] 97.33303383272235
        # Radius_InnerStatorYoke = r_si+d_sp+d_st
        # print('Radius_InnerStatorYoke #1:', Radius_InnerStatorYoke)
        # Option 2
        Radius_InnerStatorYoke = np.sqrt(P5[0]**2 + P5[1]**2)
        # print('Radius_InnerStatorYoke #2:', Radius_InnerStatorYoke)
        P6 = [
            Radius_InnerStatorYoke * cos(alpha_slot_span * 0.5),
            Radius_InnerStatorYoke * -sin(alpha_slot_span * 0.5)
        ]

        P7 = [(r_si + d_sp + d_st + d_sy) * cos(alpha_slot_span * 0.5),
              (r_si + d_sp + d_st + d_sy) * -sin(alpha_slot_span * 0.5)]
        P8 = [r_si + d_sp + d_st + d_sy, 0]

        list_segments = []
        if bool_draw_whole_model:
            P2_Mirror = [P2[0], -P2[1]]  # = iPark(P2, alpha_st)
            P3_Mirror = [P3[0], -P3[1]]
            P4_Mirror = [P4[0], -P4[1]]
            P5_Mirror = [P5[0], -P5[1]]

            def iPark(P, theta):
                return [
                    P[0] * np.cos(theta) + P[1] * -np.sin(theta),
                    P[0] * np.sin(theta) + P[1] * np.cos(theta)
                ]

            def draw_fraction(list_segments, P2, P3, P4, P5, P2_Mirror,
                              P3_Mirror, P4_Mirror, P5_Mirror):
                P5_Rotate = iPark(P5, alpha_slot_span)
                list_segments += drawer.drawArc([0, 0], P2, P2_Mirror)
                list_segments += drawer.drawLine(P2, P3)
                list_segments += drawer.drawLine(P2_Mirror, P3_Mirror)
                list_segments += drawer.drawLine(P3, P4)
                list_segments += drawer.drawLine(P3_Mirror, P4_Mirror)
                list_segments += drawer.drawLine(P4, P5)
                list_segments += drawer.drawLine(P4_Mirror, P5_Mirror)
                list_segments += drawer.drawArc([0, 0], P5_Mirror, P5_Rotate)

            for i in range(Q):
                draw_fraction(
                    list_segments,
                    iPark(P2, i * alpha_slot_span),
                    iPark(P3, i * alpha_slot_span),
                    iPark(P4, i * alpha_slot_span),
                    iPark(P5, i * alpha_slot_span),
                    iPark(P2_Mirror, i * alpha_slot_span),
                    iPark(P3_Mirror, i * alpha_slot_span),
                    iPark(P4_Mirror, i * alpha_slot_span),
                    iPark(P5_Mirror, i * alpha_slot_span),
                )
                # raise
            # draw a circle (this is officially suggested)
            list_segments += drawer.drawArc([0, 0], P8, [-P8[0], P8[1]])
            list_segments += drawer.drawArc([0, 0], [-P8[0], P8[1]], P8)
        else:
            list_segments += drawer.drawArc([0, 0], P2, P1)
            list_segments += drawer.drawLine(P2, P3)
            list_segments += drawer.drawLine(P3, P4)
            list_segments += drawer.drawLine(P4, P5)
            list_segments += drawer.drawArc([0, 0], P6, P5)
            list_segments += drawer.drawLine(P6, P7)
            list_segments += drawer.drawArc([0, 0], P7, P8)
            list_segments += drawer.drawLine(P8, P1)

        # DEBUG
        # for ind, point in enumerate([P1, P2, P3, P4, P5, P6, P7, P8]):
        #     print(ind+1, point, np.sqrt(point[0]**2+point[1]**2))

        self.innerCoord = (0.5 * (P1[0] + P5[0]), 0.5 * (P1[1] + P5[1]))

        # return [list_segments]
        return {
            'innerCoord': self.innerCoord,
            'list_regions': [list_segments],
            'mirrorAxis': [(P8[0] + 5, P8[1]), (P8[0] + 15, P8[1])]
        }
Beispiel #22
0
 def is_at_stator(im, path):
     return np.sqrt(path[0]**2 + path[1]**2
                    ) > im.Radius_OuterRotor + 0.5 * im.Length_AirGap
    def draw(self, drawer):

        drawer.getSketch(self.name, self.color)

        alpha_st = self.deg_alpha_st * np.pi / 180
        alpha_so = -self.deg_alpha_so * np.pi / 180
        r_si = self.mm_r_si
        d_so = self.mm_d_so
        d_sp = self.mm_d_sp
        d_st = self.mm_d_st
        d_sy = self.mm_d_sy
        w_st = self.mm_w_st
        r_st = self.mm_r_st
        r_sf = self.mm_r_sf
        r_sb = self.mm_r_sb
        Q = self.Q

        alpha_slot_span = 360 / Q * np.pi / 180

        P1 = [r_si, 0]
        P2 = [r_si * cos(alpha_st * 0.5), r_si * -sin(alpha_st * 0.5)]
        P3_temp = [d_so * cos(alpha_st * 0.5), d_so * -sin(alpha_st * 0.5)]
        P3_local_rotate = [
            cos(alpha_so) * P3_temp[0] + sin(alpha_so) * P3_temp[1],
            -sin(alpha_so) * P3_temp[0] + cos(alpha_so) * P3_temp[1]
        ]
        P3 = [P3_local_rotate[0] + P2[0], P3_local_rotate[1] + P2[1]]

        三角形的底 = r_si + d_sp
        三角形的高 = w_st * 0.5
        三角形的角度 = arctan(三角形的高 / 三角形的底)
        P4 = [三角形的底 * cos(三角形的角度), 三角形的底 * -sin(三角形的角度)]

        P5 = [P4[0] + d_st, P4[1]]

        # Option 1
        # 6 [94.01649113009418, -25.191642873516543] 97.33303383272235
        # Radius_InnerStatorYoke = r_si+d_sp+d_st
        # print('Radius_InnerStatorYoke #1:', Radius_InnerStatorYoke)
        # Option 2
        Radius_InnerStatorYoke = np.sqrt(P5[0]**2 + P5[1]**2)
        # print('Radius_InnerStatorYoke #2:', Radius_InnerStatorYoke)
        P6 = [
            Radius_InnerStatorYoke * cos(alpha_slot_span * 0.5),
            Radius_InnerStatorYoke * -sin(alpha_slot_span * 0.5)
        ]

        P7 = [(r_si + d_sp + d_st + d_sy) * cos(alpha_slot_span * 0.5),
              (r_si + d_sp + d_st + d_sy) * -sin(alpha_slot_span * 0.5)]
        P8 = [r_si + d_sp + d_st + d_sy, 0]

        list_segments = []
        list_segments += drawer.drawArc([0, 0], P2, P1)
        list_segments += drawer.drawLine(P2, P3)
        list_segments += drawer.drawLine(P3, P4)
        list_segments += drawer.drawLine(P4, P5)
        list_segments += drawer.drawArc([0, 0], P6, P5)
        # print(P4, P5)
        # print(P6, P5)
        list_segments += drawer.drawLine(P6, P7)

        # l, vA = drawer.drawArc([0,0], P6, P5, returnVertexName=True)
        # list_segments += l
        # l, vB = drawer.drawLine(P6, P7, returnVertexName=True)
        # list_segments += l
        # drawer.addConstraintCocentricity(vA[0], vB[0])
        # raise

        list_segments += drawer.drawArc([0, 0], P7, P8)
        list_segments += drawer.drawLine(P8, P1)

        # DEBUG
        # for ind, point in enumerate([P1, P2, P3, P4, P5, P6, P7, P8]):
        #     print(ind+1, point, np.sqrt(point[0]**2+point[1]**2))

        innerCoord = (0.5 * (P1[0] + P5[0]), 0.5 * (P1[1] + P5[1]))

        # return [list_segments]
        return {
            'innerCoord': innerCoord,
            'list_regions': [list_segments],
            'mirrorAxis': [(P8[0] + 5, P8[1]), (P8[0] + 15, P8[1])]
        }
Beispiel #24
0
def dzrdf(f, CL, G):
    r= np.sqrt(G**2*(1-f)**2+1)
    return CL*(f-r)*(2*f*(G**2*(1-f)+r)+(f-r)*r)/(np.sqrt(G**2+1)*r)
Beispiel #25
0
Ma = Pnom / omega
S = np.pi * (Rko * Rko - Rk * Rk)

alpha = np.radians(60)  # Initial value
betas = np.radians(0)  # Initial value
a, b, c, d = Marzmean(lKRk, RgRk, alpha, betas, beta, delta)
alpha = a
betas = b
MaRF = c
MgRF = d
Fakz = Ma / (MaRF * Rk)
sa = np.sin(alpha)
ca = np.cos(alpha)
sb = np.sin(betas)
cb = np.cos(betas)
L = Fakz * np.sqrt(sb * sb * sa * sa + ca * ca)
D = Fakz * cb * sa
LoD = L / D
CL = 2 * L / (rho * S * vw * vw)
CD = 2 * D / (rho * S * vw * vw)
CM = 2 * Ma / (rho * Rko * S * vw * vw)
Cp = lam * CM
aeff = np.arccos(cb * ca)
Ftrxam = Ftrxminmax(lKRk, RgRk, alpha, betas, beta, delta)
Ftryam = Ftryminmax(lKRk, RgRk, alpha, betas, beta, delta)
h = np.sin(beta) * lK - sa * Rko

print "Pnom  : ", Pnom
print "lK/Rk : ", lKRk
print "Rg/Rk : ", RgRk