Ejemplo n.º 1
0
 def step(self):
     self.sensors = rk4(self._derivs, self.sensors, [0, self.dt])
     self.sensors = self.sensors[-1]
     if self.hasRenderer():
         self.getRenderer().updateData(self.sensors)
         if self.delay: 
             time.sleep(0.05)    
Ejemplo n.º 2
0
 def step(self):
     self.sensors = rk4(self._derivs, self.sensors, [0, self.dt])
     self.sensors = self.sensors[-1]
     if self.hasRenderer():
         self.getRenderer().updateData(self.sensors)
         if self.delay:
             time.sleep(0.05)
Ejemplo n.º 3
0
    def iterate(self,
                fullt,
                steps,
                autogen_fname=None,
                localdefs=None,
                autogen='autogen'):
        """
        Iterates over the system of equations 
        """
        if autogen_fname is not None:
            autogen = autogen_fname
            del autogen_fname
            util.warn(
                "parameter 'autogen_fname' is deprecated. Use 'autogen' instead."
            )

        # setting up the timesteps
        dt = fullt / float(steps)
        self.t = [dt * i for i in range(steps)]

        # generates the initializator and adds the timestep
        self.init_text = self.generate_init(localdefs=localdefs)
        self.init_text += '\ndt = %s' % dt

        #print init_text

        # generates the derivatives
        self.func_text = self.generate_function()
        #print func_text

        self.dynamic_code = self.init_text + '\n' + self.func_text

        try:
            fp = open('%s.py' % autogen, 'wt')
            fp.write('%s\n' % self.init_text)
            fp.write('%s\n' % self.func_text)
            fp.close()

            import os
            import sys
            path_backup = sys.path
            sys.path.append(os.path.split(os.path.abspath('autogen.py'))[0])
            autogen_mod = __import__(autogen)
            sys.path = path_backup
            try:
                os.remove('%s.pyc' % autogen)
            except OSError:
                pass  # must be a read only filesystem
            reload(autogen_mod)
        except Exception as exc:
            msg = "'%s' in:\n%s\n*** dynamic code error ***\n%s" % (
                exc, self.dynamic_code, exc)
            util.error(msg)

        # x0 has been auto generated in the initialization
        self.alldata = rk4(autogen_mod.derivs, autogen_mod.x0, self.t)

        for index, node in enumerate(self.nodes):
            self.lazy_data[node] = [row[index] for row in self.alldata]
Ejemplo n.º 4
0
 def rk4(f, pts, dt):
     new_pts = [mlab.rk4(f, xy, [0, dt])[-1] for xy in pts]
     return new_pts
Ejemplo n.º 5
0
 def rk4(f, pts, dt):
     new_pts = [mlab.rk4(f, p, [0, dt])[-1] for p in pts]
     return new_pts
Ejemplo n.º 6
0
 def _step(self):
     """
     perform a single step within the episode and update the rendering
     """
     self.sensors = rk4(self._derivs, self.sensors, [0, self.dt])
     self.sensors = self.sensors[-1]
Ejemplo n.º 7
0
 def _update(self):
     self.sensors = rk4(self._derivs, self.sensors, [0, self.dt])
     self.sensors = self.sensors[-1]
     if self.renderer:
         self.renderer.updateData(self.sensors)
         time.sleep(0.05)