def check_var(self, dae_t, *args, **kwargs): # Storage: # Output values is in the first col. # Latest values are stored in /appended to the last column self.rewind = False if dae_t == 0: self._v_mem[:] = self.u.v[:, None] elif dae_t < self.t[-1]: self.rewind = True self.t[-1] = dae_t self._v_mem[:, -1] = self.u.v elif dae_t == self.t[-1]: self._v_mem[:, -1] = self.u.v elif dae_t > self.t[-1]: if self.mode == 'step': self.t[:-1] = self.t[1:] self.t[-1] = dae_t self._v_mem[:, :-1] = self._v_mem[:, 1:] self._v_mem[:, -1] = self.u.v else: self.t = np.append(self.t, dae_t) self._v_mem = np.hstack((self._v_mem, self.u.v[:, None])) if dae_t - self.t[0] > self.delay: t_interp = dae_t - self.delay idx = np.argmax(self.t >= t_interp) - 1 v_interp = interp_n2(t_interp, self.t[idx:idx + 2], self._v_mem[:, idx:idx + 2]) self.t[idx] = t_interp self._v_mem[:, idx] = v_interp self.t = np.delete(self.t, np.arange(0, idx)) self._v_mem = np.delete(self._v_mem, np.arange(0, idx), axis=1) self.v[:] = self._v_mem[:, 0]
def run(self, **kwargs): succeed = False system = self.system self.singular_idx = np.array([], dtype=int) if system.PFlow.converged is False: logger.warning( 'Power flow not solved. Eig analysis will not continue.') return succeed else: if system.TDS.initialized is False: system.TDS.init() system.TDS._itm_step() if system.dae.n == 0: logger.error('No dynamic model. Eig analysis will not continue.') else: if sum(system.dae.Tf != 0) != len(system.dae.Tf): self.singular_idx = np.argwhere(np.equal( system.dae.Tf, 0.0)).ravel().astype(int) logger.info( f"System contains {len(self.singular_idx)} zero time constants. " ) logger.debug([system.dae.x_name[i] for i in self.singular_idx]) self.x_name = np.array(system.dae.x_name) self.x_name = np.delete(self.x_name, self.singular_idx) self.summary() t1, s = elapsed() self.calc_state_matrix() self.remove_singular_rc() self.calc_part_factor() if not self.system.files.no_output: self.report() if system.options.get('state_matrix') is True: self.export_state_matrix() if self.config.plot: self.plot() _, s = elapsed(t1) logger.info('Eigenvalue analysis finished in {:s}.'.format(s)) succeed = True system.exit_code = 0 if succeed else 1 return succeed
def remove_singular_rc(self): """ Remove rows and cols associated with zero time constant. """ self.As = np.delete(self.As, self.singular_idx, axis=0) self.As = np.delete(self.As, self.singular_idx, axis=1)