Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    def plot(self, input_file=None, **opts):
        """Plot previously saved solution file"""
        # Load solution object
        if input_file is None:
            input_file = sys.stdin
        t, Xt = load_csv(input_file, parameters=False)

        # figure is no-op without plotopts: force plot
        if not opts['plot_file']:
            opts['plot'] = True

        # And plot
        fig = self.figure(**opts)
        if not fig:
            raise Error("Unable to open plot window")

        # Actually plot
        ax = fig.add_subplot(1, 1, 1)
        self.plot_solution(ax, t, Xt, 'k')
        self.show(fig, **opts)
Пример #4
0
    def plot(self, input_file=None, **opts):
        """Plot previously saved solution file"""
        # Load solution object
        if input_file is None:
            input_file = sys.stdin
        t, Xt = load_csv(input_file, parameters=False)

        # figure is no-op without plotopts: force plot
        if not opts['plot_file']:
            opts['plot'] = True

        # And plot
        fig = self.figure(**opts)
        if not fig:
            raise Error("Unable to open plot window")

        # Actually plot
        ax = fig.add_subplot(1, 1, 1)
        self.plot_solution(ax, t, Xt, 'k')
        self.show(fig, **opts)