Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 3
0
 def save_solution(self, sysinst, t, Xt, output_file, **opts):
     """Save solution t, Xt to output_file ('-' for stdout)"""
     if not output_file:
         return
     if output_file == '-':
         fout = sys.stdout
     else:
         fout = open(output_file, 'w')
     save_csv(sysinst, t, Xt, fout)
Exemplo n.º 4
0
 def save_solution(self, sysinst, t, Xt, output_file, **opts):
     """Save solution t, Xt to output_file ('-' for stdout)"""
     if not output_file:
         return
     if output_file == '-':
         fout = sys.stdout
     else:
         fout = open(output_file, 'w')
     save_csv(sysinst, t, Xt, fout)