Esempio n. 1
0
 def guess_mapper(sol):
     n_c = len(constants_of_motion)
     if n_c == 0:
         return sol
     sol_out = Solution()
     sol_out.t = copy.copy(sol.t)
     sol_out.y = np.array([[fn(*sol.y[0]) for fn in states_2_states_fn]])
     sol_out.q = sol.q
     if len(quads) > 0:
         sol_out.q = -0.0 * np.array([np.ones((len(quads)))])
     sol_out.dynamical_parameters = sol.dynamical_parameters
     sol_out.dynamical_parameters[-n_c:] = np.array(
         [fn(*sol.y[0]) for fn in states_2_constants_fn])
     sol_out.nondynamical_parameters = sol.nondynamical_parameters
     sol_out.aux = sol.aux
     return sol_out
Esempio n. 2
0
    def load(self):
        """
        Loads solution data using dill if not already loaded
        """
        if not self.is_loaded:
            logging.info("Loading datafile " + self.filename + "...")
            out = loadmat(self.filename)

            if 'output' in out:
                out = out['output']['result'][0][0][0][0]
            soldata = out['solution']['phase'][0][0][0][0]

            # if 'solution' not in self._data:
            #     self.is_loaded = False
            #     logging.error("Solution missing in data file :"+self.filename)
            #     raise RuntimeError("Solution missing in data file :"+self.filename)
            # if 'problem_data' not in self._data:
            #     self.is_loaded = False
            #     logging.error("Problem data missing in data file :"+self.filename)
            #     raise RuntimeError("Problem data missing in data file :"+self.filename)
            #
            _sol = Solution()

            tf = max(soldata['time'])
            _sol.x = soldata['time'][:, 0] / tf
            _sol.y = np.r_[soldata['state'].T, soldata['costate'].T,
                           np.ones_like(soldata['time']).T * tf]
            _sol.u = soldata['control'].T

            if 'tf' not in self.problem_data['state_list']:
                self.problem_data['state_list'] = tuple(
                    self.problem_data['state_list']) + ('tf', )

            _sol.arcs = ((0, len(_sol.x) - 1), )

            if self._const is not None:
                _sol.aux = {'const': self._const}

            self._sol = [[_sol]]
            logging.info('Loaded solution from data file')

            self.is_loaded = True