def _delf(self, t, xval, uval): # calculates the jump term assuming the field switches # between fplus and fminus at (t, x) params = np.concatenate(([t], xval, uval)) dphi = self.dphi(xval) # determine if going from f- to f+ # or vice-versa if matmult(dphi[:self.dim],xval[-self.dim:]) > 0: fp = self._fplus.func(*params) fm = self._fmins.func(*params) else: fp = self._fmins.func(*params) fm = self._fplus.func(*params) #out = 2*np.outer(fp-fm, dphi)/np.abs(matmult(fm+fp, dphi)) #out = np.outer(fp-fm, dphi)/np.abs(matmult(fm, dphi)) out = np.outer(fp, dphi)/matmult(dphi, fm) \ #+ np.eye(len(fp)) - np.outer(dphi, dphi)/np.dot(dphi,dphi) #Tracer()() #out = np.zeros((2*self.dim, 2*self.dim)) #for i in range(self.dim): # out[self.si, i] = -M[self.si, i] return out
def _delf(self, t, xval, uval): # calculates the jump term assuming the field switches # between fplus and fminus at (t, x) params = np.concatenate(([t], xval, uval)) dphi = self.dphi(xval) # determine if going from f- to f+ # or vice-versa if matmult(dphi[:self.dim], xval[-self.dim:]) > 0: fp = self._fplus.func(*params) fm = self._fmins.func(*params) else: fp = self._fmins.func(*params) fm = self._fplus.func(*params) #out = 2*np.outer(fp-fm, dphi)/np.abs(matmult(fm+fp, dphi)) #out = np.outer(fp-fm, dphi)/np.abs(matmult(fm, dphi)) out = np.outer(fp, dphi)/matmult(dphi, fm) \ #+ np.eye(len(fp)) - np.outer(dphi, dphi)/np.dot(dphi,dphi) #Tracer()() #out = np.zeros((2*self.dim, 2*self.dim)) #for i in range(self.dim): # out[self.si, i] = -M[self.si, i] return out
def dfdu(self, t, xval, uval=[0, 0]): # choose between dfxm and dfxp if xval[self.si] > 0: func = self._dfup.func else: func = self._dfum.func vals = np.concatenate([[t], xval, uval]) return func(*vals)
def f(self, t, xval, uval=[0, 0], ctrl=None): # choose between _fplus and _fmins # depending on the configuration # assume that ctrl is a rule for substituting u if xval[self.si] >= 0: func = self._fplus.func else: func = self._fmins.func vals = np.concatenate([[t], xval, uval]) return func(*vals)
def _makefp(self, params): zdot = self.x[self.dim:] out = np.concatenate(( zdot, np.dot( self.Mzi, -tn.einsum('i,ijk,k', zdot, self.dMz, zdot) + tn.einsum('i,ikl,k', zdot, self.dMz, zdot) / 2 + self.dVz) + matmult( tn.subs(self._dPsi, self.qtoz), self.Mqi, # here we might need subs self.u))) out = tn.SymExpr(tn.subs(out, self.ztox)) out.callable(*params) return out
def _makefp(self, params): zdot = self.x[self.dim:] out = np.concatenate((zdot, np.dot(self.Mzi, - tn.einsum( 'i,ijk,k', zdot, self.dMz, zdot) + tn.einsum( 'i,ikl,k', zdot, self.dMz, zdot) / 2 + self.dVz) + matmult( tn.subs(self._dPsi, self.qtoz), self.Mqi, # here we might need subs self.u) )) out = tn.SymExpr(tn.subs(out, self.ztox)) out.callable(*params) return out
def _delf(self, t, xval, uval): # calculates the jump term assuming the field switches # between fplus and fminus at (t, x) params = np.concatenate(([t], xval, uval)) fp = self._fplus.func(*params) fm = self._fmins.func(*params) dphi = self.dphi(xval) # this assumes x = [z, zdot] M = tn.eval(self.Mz, self.z, xval[:self.dim]) M = scipy.linalg.block_diag(M, np.eye(self.dim)) #dphi = matmult(M, dphi) out = -np.outer(fp-fm, dphi)/np.abs(np.inner(fp, dphi)) #Tracer()() #out = np.zeros((2*self.dim, 2*self.dim)) #for i in range(self.dim): # out[self.si, i] = -M[self.si, i] return out
def _makefm(self, params): zdot = self.x[self.dim:] OhmP = tn.subs(self._Ohm, zip(self.z, self._P)) OhmI = tn.subs(self._dPsi, zip(self.q, OhmP)) zz = self._P zzdot = np.dot(self._dP, zdot) out = -tn.einsum('i,ijk,k', zzdot, self.dMzz, zzdot) \ + tn.einsum('i,ikj,k', zzdot, self.dMzz, zzdot) / 2 out = np.dot(self.Mzzi, out + self.dVzz) out = out - tn.einsum('ijk,j,k', tn.diff(self._dP, self.z), zdot, zdot) out = out + matmult(OhmI, self.Mqi, self.u) # in general, there should be a subs here out = matmult(self._dPi, out) out = np.concatenate((zdot, out)) out = tn.SymExpr(tn.subs(out, self.ztox)) out.callable(*params) return out