def cont(self, file_name, **opts): """Continue previous numerical solution from input file""" # Load solution object t, Xt, (sysopts, sysargs) = load_csv(file_name, parameters=True) sysinst = self._make_sode(*sysargs, **sysopts) if not sysinst: return -1 if opts['params']: print sysinst.get_description() return 0 if opts['stdout']: self.save_solution(sysinst, t, Xt, '-') append_file = sys.stdout else: append_file = open(file_name, 'a') while True: # Find final state to use as initial conditions here t1 = t[-1] x0 = Xt[-1, :] del t, Xt # Extend solution t = np.arange(t1, t1 + opts['T'] + opts['dtout'], opts['dtout']) Xt = solve(sysinst, x0, t, opts['dtmax'], method=opts['method']) # Remove repeated time t = t[1:] Xt = Xt[1:, :] # Save to same file or write to stdout save_csv(sysinst, t, Xt, append_file, header=False, titles=False) append_file.flush()
def solve(self, *args, **opts): """Solve numerically using random realisation of noise If neither of plot or outputfile is specified, the solution will be written to stdout. """ # Default to stdout if not (opts['output_file'] or opts['plot'] or opts['plot_file']): opts['output_file'] = '-' # Create system with args sysinst = self._make_sode(*args, **opts) if not sysinst: return 1 if opts['params']: print sysinst.get_description() return 0 # Create solution t = np.arange(opts['t1'], opts['t2'] + opts['dtout'], opts['dtout']) x0 = sysinst.get_x0() Xt = solve(sysinst, x0, t, opts['dtmax'], method=opts['method']) # Ouput file is contained in opts (no-op if not provided) self.save_solution(sysinst, t, Xt, **opts) # Plot (no-op) if plot options not provided fig = self.figure(**opts) if fig: ax = fig.add_subplot(1, 1, 1) self.plot_solution(ax, t, Xt, 'k') self.show(fig, **opts)