def integrate(F,t,y,tEnd,h, **opt): def run_kut4(F,t,y,h): K0 = h*F(t,y) K1 = h*F(t + h/2.0, y + K0/2.0) K2 = h*F(t + h/2.0, y + K1/2.0) K3 = h*F(t + h, y + K2) return (K0 + 2.0*K1 + 2.0*K2 + K3)/6.0 step = 0 initialStep = 0 if opt and opt["step"]: initialStep = opt["step"] T = [t] Y = [y] progress = ProgressBar('Runge Kutta 4', t, tEnd) while t < tEnd: y = y + run_kut4(F,t,y,h) t = t + h if initialStep == 0 or t >= step: T.append(t) Y.append(y) step += initialStep progress.setValue(t) return array(T), transpose(array(Y))
def integrate(F, t, y, tEnd, h, tol=1.0e-6, **opt): C = array([37.0 / 378, 0.0, 250.0 / 621, 125.0 / 594, 0.0, 512.0 / 1771]) D = array([ 2825.0 / 27648, 0.0, 18575.0 / 48384, 13525.0 / 55296, 277.0 / 14336, 1.0 / 4 ]) n = len(y) def run_kut5(F, t, y, h): # Runge--Kutta-Fehlberg formulas K = zeros((6, n)) K[0] = h * F(t, y) K[1] = h * F(t + 1. / 5 * h, y + 1. / 5 * K[0]) K[2] = h * F(t + 3. / 10 * h, y + 3. / 40 * K[0] + 9. / 40 * K[1]) K[3] = h * F(t + 3. / 5 * h, y + 3. / 10 * K[0] - 9. / 10 * K[1] + 6. / 5 * K[2]) K[4] = h * F( t + h, y - 11. / 54 * K[0] + 5. / 2 * K[1] - 70. / 27 * K[2] + 35. / 27 * K[3]) K[5] = h * F( t + 7. / 8 * h, y + 1631. / 55296 * K[0] + 175. / 512 * K[1] + 575. / 13824 * K[2] + 44275. / 110592 * K[3] + 253. / 4096 * K[4]) # Initialize arrays {dy} and {E} E = zeros(n) dy = zeros(n) # Compute solution increment {dy} and per-step error {E} for i in range(6): dy = dy + C[i] * K[i] E = E + (C[i] - D[i]) * K[i] # Compute RMS error e e = sqrt(sum(E**2) / n) return dy, e step = 0.0 initialStep = 0 if opt and opt["step"]: initialStep = opt["step"] pb = opt["pb"] if "pb" in opt else True if pb: progress = ProgressBar('Runge Kutta 5 Adaptive', t, tEnd) T = [t] Y = [y] tEnd += h * 10 while t < tEnd: dy, e = run_kut5(F, t, y, h) # Accept integration step if error e is within tolerance if e <= tol: y = y + dy t = t + h if initialStep == 0 or t >= step: T.append(t) Y.append(y) if pb: progress.setValue(t) # Compute next step size from Eq. (7.24) if e != 0.0: h = 0.9 * h * (tol / e)**0.2 return array(T), transpose(array(Y))
def redraw_graphs(self): def ts(x): return x.total_seconds() if self.list_of_files !=None: # get data from the list of files given # we'll open the files one by one, fetch the line # get the timestamp from the line contaning ===Current Time=== # and then looking for any of the selected metrics # put the results in the the pandas dataframe #and then call the redraw events self.metric_column=self.metric_column_d[self.metric] rows_list=[] self.first_time=False priortime=None nfiles=len(self.list_of_files) pbar=ProgressBar(desc="Loading Files") n=.5/nfiles for fname in self.list_of_files: if fname[-3:]=="bz2": datfile=bz2.BZ2File(fname) else: datfile=open(fname,'r') lines=datfile.readlines() cellname=fname[fname.rindex('_',)+1:fname.index('.',fname.rindex('_',))] pbar.setDescription("opening:"+os.path.basename(fname)) pbar.setValue(100*n) n+=.5/nfiles QtWidgets.QApplication.processEvents() # print ("cellname=",cellname) for s1 in lines: s=s1.rstrip().decode("utf-8") #print(s) if re.search("PM|AM$",s)!=None: # get the date after that timeint=dt.datetime.strptime(s,"%m/%d/%Y %I:%M:%S %p") timest=timeint.strftime("%Y-%m-%d_%H:%M:%S") if priortime is None: timedelta=0 else: timedelta=(timeint-priortime).total_seconds() priortime=timeint else: if self.devices=='.': mre=re.search("^nvme|^sd[a-l] .*$",s) else: mre=re.search("^"+self.devices+" .*$",s) # mre=re.search("^nvme0n1 .*$",s) if mre!=None: #disk=s[0:mre.span()[0]].rstrip() #print(s) l2f=s.split() #print(timeint,float(l2f[3])) data_list={'Cell':cellname, 'Type':('Flash' if l2f[0][0]=='n' else 'Disk'), 'Disk':l2f[0],'Metric':float(l2f[self.metric_column]),'Timestamp':timeint} rows_list.append(data_list) datfile.close() pbar.setValue(100*n) n+=.5/nfiles QtWidgets.QApplication.processEvents() self.current_metrics=pd.DataFrame(rows_list)#, ignore_index=True) #print(self.current_metrics.head()) pbar.close() for i in self.metric_graph: self.metric_graph[i].remove_graph() for i in self.current_metrics.Cell.unique(): self.metric_graph[i]=CellGraphrtPage(self,i,False) self.metric_graph[i+'A']=CellGraphrtPage(self,i,True) self.metric_graph[i].redraw_events() self.metric_graph[i+'A'].redraw_events()