def AttachModel(self, model): """ Attaches a CasADi model to this object, sets the model up for its eventual evaluation. Call like: AttachModel(model) """ self.model = model() self.model.init() self.neq = self.model.input(cs.DAE_X).size() self.ParamCount = self.model.input(cs.DAE_P).size() # Some of this syntax is borrowed from Peter St. John. self.ylabels = [self.model.inputExpr(cs.DAE_X)[i].getName() for i in xrange(self.neq)] self.plabels = [self.model.inputExpr(cs.DAE_P)[i].getName() for i in xrange(self.ParamCount)] self.pdict = {} self.ydict = {} for par,ind in zip(self.plabels,range(0,self.ParamCount)): self.pdict[par] = ind for par,ind in zip(self.ylabels,range(0,self.neq)): self.ydict[par] = ind # Model now attached to object along with its contents. print "Model attached."
for i,d1 in enumerate(der1s)]) self.ymax = np.array([spi(self.tmax[i]) for i,spi in enumerate(sps)]) self.tmin = np.array([d1.roots()[der2s[i](d1.roots()) > 0] for i,d1 in enumerate(der1s)]) self.ymin = np.array([spi(self.tmin[i]) for i,spi in enumerate(sps)]) if __name__ == "__main__": from Models.tyson_model import model, param, EqCount lap = jha.laptimer() # initialize with 1s tyson = Oscillator(model(), param, np.ones(EqCount)) print tyson.y0, 'setup time = %0.3f' %(lap() ) # find a spot on LC tyson.y0 = np.ones(EqCount) tyson.burn_trans() print tyson.y0, 'y0 burn time = %0.3f' %(lap() ) # or find a max and the approximate period tyson.approx_y0_T() print tyson.y0, tyson.T, 'y0 approx time = %0.3f' %(lap() ) # find the period and y0 using a BVP solution tyson.solve_bvp(method='scipy') print tyson.y0, tyson.T, 'y0 scipy bvp time = %0.3f' %(lap() )