def sinh(ent): """Polymorphic sinh function that adapts to either a numeric or symbolic string input.""" if isinstance(ent,str): return symstr('sinh('+ent+')') else: return scipy.sinh(ent)
def GetAugSymMat(self): """Similar to GetSymMat, this method returns a symbolic transfer matrix for the element. By default, it calls self.GetAugSymMat(s, sym=True) with s as a symstr.""" s = symstr("s") symmat = self.GetAugMat(s, sym=True) return SymstrMattoMaxima(symmat, self.symname)
def GetSymAugMat(self, s): """Return the augmented element transfer matrix for the SAMIIAccelFB element. If sym=True, 's' must be a symbolic string and a matrix of strings will be returned. Otherwise, 's' is a numeric value (probably complex) and the matrix returned will be complex.""" s = rwkmisc.symstr(s) return self.GetAugMat(s, self.symparams)
def bendmaty(s,params,EIstr='EI1',symlabel=''): """Return a 4x4 transfer matrix for a beam in bending about the y-axis. This function is used for part of the GetMat function of an 8x8 or 12x12 beam. It will be the entire 4x4 transfer matrix if usez=False for the beam element.""" EI=params[EIstr] mu=params['mu'] L=params['L'] #[ c(1), -1/2*L*c(4)/beta, -1/2*a*c(3)/beta^2, -1/2*L*a*c(2)/beta^3] #[ -1/2*beta*c(2)/L, c(1), 1/2*a*c(4)/beta/L, 1/2*a*c(3)/beta^2] #[ -1/2*beta^2*c(3)/a, 1/2*beta*L*c(2)/a, c(1), 1/2*L*c(4)/beta] #[ -1/2*beta^3*c(4)/L/a, 1/2*beta^2*c(3)/a, 1/2*beta*c(2)/L, c(1)] # # This matrix is derived in bending_about_y_axis.m originally in # E:\GT\Research\SAmii\modeling\transfer_matrix\threeD_beam_derivations # # The states that multipy the matrix are [w_z;theta_y;M_y;V_z] and I have gone away from using -w as the state i.e. +w_z is the first state. if isinstance(s,str): beta=symstr('beta'+symlabel) a=symstr('a'+symlabel) c1=symstr('c1'+symlabel) c2=symstr('c2'+symlabel) c3=symstr('c3'+symlabel) c4=symstr('c4'+symlabel) else: beta=pow((-1*s*s*L**4*mu/EI),0.25) a=L*L/EI c1=0.5*cos(beta)+0.5*cosh(beta) c2=-sin(beta)+sinh(beta) c3=-cos(beta)+cosh(beta) c4=sin(beta)+sinh(beta) outmat=array([[c1,-0.5*L*c4/beta,-0.5*a*c3/(beta*beta),-0.5*L*a*c2/beta**3],[-0.5*beta*c2/L,c1,0.5*a*c4/beta/L,0.5*a*c3/(beta*beta)],[-0.5*(beta*beta)*c3/a,0.5*beta*L*c2/a,c1,0.5*L*c4/beta],[-0.5*beta**3*c4/L/a,0.5*(beta*beta)*c3/a,0.5*beta*c2/L,c1]]) return outmat
def GetSymMat(self): """This function is called by self.GetMaximaLines to get the symoblic element transfer function. By default, it simply calls self.GetMat(s, sym=True) where s is a symstr. This function could be overridden by a derived element if for some reason self.GetMat cannot be written in such a way that in can output either a symoblic or numeric transfer matrix. As long as self.GetMat can return a symbolic transfer matrix for the element, this function does not need to be overridden by derived elements.""" s = symstr("s") symmat = self.GetMat(s, sym=True) return SymstrMattoMaxima(symmat, self.symname)
def __init__( self, link0symlabel, joint1symlabel, link1symlabel, avssymlabel, Ga=1, axis=1, maxsize=4, label="", **kwargs ): L0 = "L" + link0symlabel L1 = "L" + link1symlabel m1 = "m" + link1symlabel r1 = "r" + link1symlabel Iz1 = "I" + link1symlabel c1 = "c" + joint1symlabel k1 = "k" + joint1symlabel tau = "tau" + avssymlabel gain = "Ka" + avssymlabel Gc = "Gc" + avssymlabel values = [L0, L1, m1, r1, Iz1, c1, k1, tau, gain, Gc, Ga] keys = ["L0", "L1", "m1", "r1", "Iz1", "c1", "k1", "tau", "gain", "Gc", "Ga"] params = {} for key, value in zip(keys, values): params[key] = rwkmisc.symstr(value) # params[key]=ModelSpec.Par(value) params["axis"] = axis TMMElementLHT.__init__(self, "accelfb", params, maxsize=maxsize, label=label, **kwargs)
def bendmatz(s, params, EIstr='EI2', symlabel='', subparams=False, debug=0): """Return a 4x4 transfer matrix for a beam in bending about the z-axis. This function is used for part of the GetMat function of an 8x8 or 12x12 beam. It will be the entire 4x4 transfer matrix if usez=True for the beam element.""" if debug>0: print('In bendmatz') EI=params[EIstr] mu=params['mu'] L=params['L'] # [ mys(1), 1/2*L*mys(4)/beta, -1/2*a*mys(3)/beta^2, -1/2*L*a*mys(2)/beta^3] # [ 1/2*beta*mys(2)/L, mys(1), 1/2*a*mys(4)/beta/L, 1/2*a*mys(3)/beta^2] # [ -1/2*beta^2*mys(3)/a, 1/2*beta*L*mys(2)/a, mys(1), -1/2*L*mys(4)/beta] # [ -1/2*beta^3*mys(4)/L/a, 1/2*beta^2*mys(3)/a, -1/2*beta*mys(2)/L, mys(1)] # # This matrix is derived in bending_about_z_axis.m originally in # E:\GT\Research\SAmii\modeling\transfer_matrix\threeD_beam_derivations # # The states that multipy the matrix are [w_y;theta_z;M_z;V_y] and I have gone away from using -w as the state i.e. +w_y is the first state. if isinstance(s,str): beta=symstr('beta'+symlabel) if subparams: a=L*L/EI c1=0.5*cos(beta)+0.5*cosh(beta) c2=-sin(beta)+sinh(beta) c3=cos(beta)-cosh(beta) c4=sin(beta)+sinh(beta) else: a=symstr('a'+symlabel) c1=symstr('c1'+symlabel) c2=symstr('c2'+symlabel) c3=symstr('c3'+symlabel) c4=symstr('c4'+symlabel) else: beta=pow((-1*s*s*L**4*mu/EI),0.25) # there is an error in my thesis and this is it: (eqn 285) #a = beta/(L**2)#to check Brian Posts work a=L*L/EI if debug>0: print('thesis='+str(thesis)) print('a='+str(a)) print('beta='+str(beta)) c1=0.5*cos(beta)+0.5*cosh(beta) c2=-sin(beta)+sinh(beta) c3=cos(beta)-cosh(beta) c4=sin(beta)+sinh(beta) clist = [c1,c2,c3,c4] if debug>0: for ind, c in enumerate(clist): print('c'+str(ind+1)+'='+str(c)) # outmat=array([[c1,0.5*L*c4/beta,-0.5*a*c3/(beta*beta),-0.5*L*a*c2/beta**3],[0.5*beta*c2/L,c1,0.5*a*c4/beta/L,0.5*a*c3/(beta*beta)],[-0.5*(beta*beta)*c3/a,0.5*beta*L*c2/a,c1,-0.5*L*c4/beta],[-0.5*beta**3*c4/L/a,0.5*(beta*beta)*c3/a,-0.5*beta*c2/L,c1]]) # outmat=zeros((4,4),'D') # outmat[0,:]=[c1,0.5*L*c4/beta,-0.5*a*c3/(beta*beta),-0.5*L*a*c2/beta**3] # outmat[1,:]=[0.5*beta*c2/L,c1,0.5*a*c4/beta/L,0.5*a*c3/(beta*beta)] # outmat[2,:]=[-0.5*(beta*beta)*c3/a,0.5*beta*L*c2/a,c1,-0.5*L*c4/beta] # outmat[3,:]=[-0.5*beta**3*c4/L/a,0.5*(beta*beta)*c3/a,-0.5*beta*c2/L,c1] row1=[c1,0.5*L*c4/beta,-0.5*a*c3/(beta*beta),-0.5*L*a*c2/beta**3] row2=[0.5*beta*c2/L,c1,0.5*a*c4/beta/L,0.5*a*c3/(beta*beta)] row3=[-0.5*(beta*beta)*c3/a,0.5*beta*L*c2/a,c1,-0.5*L*c4/beta] row4=[-0.5*beta**3*c4/L/a,0.5*(beta*beta)*c3/a,-0.5*beta*c2/L,c1] outmat=array([row1,row2,row3,row4]) return outmat
def GetAugMat(self, s): s = rwkmisc.symstr(s) # s=ModelSpec.Par(s) return SAMIIAccelFB.GetAugMat(self, s)
def __init__( self, link0, joint1, link1, avs, Ga=1, axis=1, maxsize=4, label="", symlabel="accelfb", symname="Uaccelfb", compensators="Ga", **extraargs ): """Initializes the accelerometer feedback element. link0, joint1, link1, and avs are all TMMElement's that must be passed in. Their parameters are used in creating the transfer matrix for acceleration feedback.""" l0params = link0.params # a = -(L0*m1*r1*s^2-c1*s-k1)/(c1*s+k1); # b = -((L0*m1*r1^2-L0*L1*m1*r1+Iz1*L0)*s^2+(c1*L1+c1*L0)*s+k1*L1+k1*L0)/(c1*s+k1); # c = L0/(c1*s+k1); # d = L0*L1/(c1*s+k1); L0 = l0params["L"] l1params = link1.params L1 = l1params["L"] m1 = l1params["m"] r1 = l1params["r"] Iz1 = l1params["I"] j1params = joint1.params c1 = j1params["c"] k1 = j1params["k"] gain = avs.params["Ka"] Gc = avs.params["Gc"] params = { "L0": L0, "L1": L1, "m1": m1, "r1": r1, "Iz1": Iz1, "c1": c1, "k1": k1, "axis": axis, "gain": gain, "Gc": Gc, "Ga": Ga, } if avs.params.has_key("tau"): params["tau"] = avs.params["tau"] for curkey, curvalue in params.iteritems(): if curkey != "Ga": if shape(curvalue): curvalue = copy.deepcopy(curvalue)[0] params[curkey] = curvalue TMMElementLHT.__init__( self, "accelfb", params, maxsize=maxsize, label=label, symlabel=symlabel, symname=symname, compensators=compensators, **extraargs ) # set up symbolic params sL0 = "L" + link0.symlabel sL1 = "L" + link1.symlabel sm1 = "m" + link1.symlabel sr1 = "r" + link1.symlabel sIz1 = "I" + link1.symlabel sc1 = "c" + joint1.symlabel sk1 = "k" + joint1.symlabel stau = "tau" + avs.symlabel sgain = "Ka" + avs.symlabel sGc = "Gc" + avs.symlabel sGa = "Ga" values = [sL0, sL1, sm1, sr1, sIz1, sc1, sk1, stau, sgain, sGc, sGa] keys = ["L0", "L1", "m1", "r1", "Iz1", "c1", "k1", "tau", "gain", "Gc", "Ga"] symparams = {} for key, value in zip(keys, values): symparams[key] = rwkmisc.symstr(value) # params[key]=ModelSpec.Par(value) symparams["axis"] = axis self.symparams = symparams
def __init__( self, elemtype, params, maxsize=12, label="", symname="", symlabel="", symsub=False, unknownparams=None, functionparams=None, compensators=None, subparams=False, ): """Create a TMMElement instance. Since the class is not intended to be used without deriving from it, this code should be called from each derived methods __init__ method. It contains code that should be common to all __init__methods for all TMMElement classes. subparams was added on 5/17/07 to fascilitate substituting in symstr expressions for parameters. It is currently only utilized in the bendmatz part of the beam element.""" self.elemtype = self.parsetype(elemtype) self.params = params self.maxsize = maxsize self.label = label self.symlabel = symlabel if not symname and symlabel: symname = "U" + symlabel self.symname = symname self.symsub = symsub self.subparams = subparams if functionparams is not None: if not shape(functionparams): functionparams = [functionparams] self.functionparams = functionparams self.compensators = compensators if isinstance(elemtype, str): self.elemstr = elemtype else: self.elemstr = "" # setup symparams keylist = self.params.keys() symvals = [] for key, value in self.params.iteritems(): if not isscalar(value): if len(value) > 1: inds = range(len(value)) cursym = [symstr(key + str(item) + self.symlabel) for item in inds] else: cursym = [symstr(key + self.symlabel)] else: cursym = symstr(key + self.symlabel) symvals.append(cursym) self.symparams = dict(zip(keylist, symvals)) # if unknownparams is not None: # self.unknownparams=rwkmisc.flatten([self.symparams[key] for key in unknownparams]) # else: self.unknownparams = unknownparams