def o(self, ind=None, imin=None, imax=None, decim=None): """ o == Generator of values for observers. Parameters ----------- ind: int or None, optional Index of the observer. If None, values for every observers are returned (default). imin: int or None, optional Starting index. If None, imin=0 (default). imax: int or None, Stoping index. If None, imax=simu.config['nt'] (default). decim: int or None, decimation factor. If None, decim = int(simu.config['nt']/1000) (default) Returns ------- ps_generator: generator A python generator of scalar discrete sources power value ps[i] for each time step i starting from index imin to index imax with decimation factor decim (i.e. the value is generated if i-imin % decim == 0), with ps[i] = u[i] dot y[i]. """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } obs_expr = [ e.subs(self.subs()) for e in self.method.observers.values() ] obs_symbs = free_symbols(obs_expr) index = len(self.method.args()) - len(obs_expr) obs_args, obs_inds = find(obs_symbs, self.method.args()[:index]) obs = lambdify(obs_args, obs_expr, theano=self.config['theano']) obs_args = lambdify(self.method.args()[:index], obs_args, theano=self.config['theano']) if ind is None: for arg in self.args(**options): yield obs(*obs_args(*arg)) else: for arg in self.args(**options): yield obs(*obs_args(*arg))[ind]
def pd(self, imin=None, imax=None, decim=None): """ pd == Generator of discrete dissipated power values. Parameters ----------- imin: int or None, optional Starting index. If None, imin=0 (default). imax: int or None, Stoping index. If None, imax=simu.config['nt'] (default). decim: int or None, decimation factor. If None, decim = int(simu.config['nt']/1000) (default) Returns ------- pd_generator: generator A python generator of scalar discrete dissipated power value pd[i] for each time step i starting from index imin to index imax with decimation factor decim (i.e. the value is generated if i-imin % decim == 0), with pd[i] = w[i] dot z[i]. """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } R_expr = self.method.R().subs(self.subs()) R_symbs = free_symbols(R_expr) R_args, R_inds = find(R_symbs, self.method.args()) R = lambdify(R_args, R_expr, theano=self.config['theano']) R_args = lambdify(self.method.args(), R_args, theano=self.config['theano']) for w, z, a, b, args, o in zip(self.w(**options), self.z(**options), self.a(**options), self.b(**options), self.args(**options), self.o(**options)): yield scalar_product(w, z) + \ scalar_product(a, a, R(*R_args(*(list(args)+list(o)))))
def E(self, imin=None, imax=None, decim=None): """ E === Generator of discrete energy's values. Parameters ----------- imin: int or None, optional Starting index. If None, imin=0 (default). imax: int or None, Stoping index. If None, imax=simu.config['nt'] (default). decim: int or None, decimation factor. If None, decim = int(simu.config['nt']/1000) (default) Returns ------- E_generator: generator A python generator of scalar discrete energy's value E[i] for each time step i starting from index imin to index imax with decimation factor decim (i.e. the value is generated if i-imin % decim == 0). """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } H_expr = self.method.H.subs(self.method.subs) H_symbs = free_symbols(H_expr) H_args, H_inds = find(H_symbs, self.method.args()) H = lambdify(H_args, H_expr, theano=self.config['theano']) H_args = lambdify(self.method.args(), H_args, theano=self.config['theano']) for args, o in zip(self.args(**options), self.o(**options)): a = (list(args) + list(o)) yield H(*H_args(*a))
def dtE(self, imin=None, imax=None, decim=None, DtE='DxhDtx'): """ dtE === Generator of discrete energy's time variation values. Parameters ----------- imin: int or None, optional Starting index. If None, imin=0 (default). imax: int or None, Stoping index. If None, imax=simu.config['nt'] (default). decim: int or None, decimation factor. If None, decim = int(simu.config['nt']/1000) (default) DtE: str in {'deltaH', 'DxhDtx'}, optional Method for the computation of discrete energy's time variation. If DtE is 'deltaH', the output with index i is (H[t[i+1]]-H[t[i]]) * samplerate. If DtE is 'DxhDtx', the output with index i is (dxH[i] dot dtx[i]). Returns ------- dtE_generator: generator A python generator of scalar discrete energy's time variation value DtE[i] for each time step i starting from index imin to index imax with decimation factor decim (i.e. the value is generated if i-imin % decim == 0). """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } if DtE == 'deltaH': H = lambdify(self.core.x, self.core.H.subs(self.core.subs)) for x, dx in zip(self.x(**options), self.dx(**options)): xpost = map(lambda tup: numpy.array(sum(tup)), zip(x, dx)) x = map(numpy.array, x) yield (H(*xpost) - H(*x)) * self.config['fs'] elif DtE == 'DxhDtx': for dtx, dxh in zip(self.dtx(**options), self.dxH(**options)): yield scalar_product(dtx, dxh)
def dtE(self, imin=None, imax=None, decim=None, modeDtE='DxhDtx'): """ Energy variation """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } if modeDtE == 'deltaH': H = lambdify(self.core.x, self.core.H.subs(self.core.subs)) for x, dx in zip(self.x(**options), self.dx(**options)): xpost = map(sum, zip(x, dx)) yield (H(*xpost) - H(*x)) * self.config['fs'] elif modeDtE == 'DxhDtx': for dtx, dxh in zip(self.dtx(**options), self.dxH(**options)): yield scalar_product(dtx, dxh)
def dtE(self, imin=None, imax=None, decim=None, DtE='DxhDtx'): """ dtE === Generator of discrete energy's time variation values. Parameters ----------- imin: int or None, optional Starting index. If None, imin=0 (default). imax: int or None, Stoping index. If None, imax=simu.config['nt'] (default). decim: int or None, decimation factor. If None, decim = int(simu.config['nt']/1000) (default) DtE: str in {'deltaH', 'DxhDtx'}, optional Method for the computation of discrete energy's time variation. If DtE is 'deltaH', the output with index i is (H[t[i+1]]-H[t[i]]) * samplerate. If DtE is 'DxhDtx', the output with index i is (dxH[i] dot dtx[i]). Returns ------- dtE_generator: generator A python generator of scalar discrete energy's time variation value DtE[i] for each time step i starting from index imin to index imax with decimation factor decim (i.e. the value is generated if i-imin % decim == 0). """ options = self.config['load'] options = { 'imin': options['imin'] if imin is None else imin, 'imax': options['imax'] if imax is None else imax, 'decim': options['decim'] if decim is None else decim } if DtE == 'deltaH': H_expr = self.method.H.subs(self.method.subs) H_symbs = free_symbols(H_expr) H_args, H_inds = find(H_symbs, self.method.args()) H = lambdify(H_args, H_expr, theano=self.config['theano']) H_args = lambdify(self.method.args(), H_args, theano=self.config['theano']) Hpost_expr = self.method.H.subs(self.subs()) subs = {} for x, dx in zip(self.method.x, self.method.dx()): subs.update({x: x + dx}) Hpost_expr = Hpost_expr.subs(subs) Hpost_symbs = free_symbols(Hpost_expr) Hpost_args, Hpost_inds = find(Hpost_symbs, self.method.args()) Hpost = lambdify(Hpost_args, Hpost_expr, theano=self.config['theano']) Hpost_args = lambdify(self.method.args(), Hpost_args, theano=self.config['theano']) for args, o in zip(self.args(**options), self.o(**options)): a = (list(args) + list(o)) yield (Hpost(*Hpost_args(*a)) - H(*H_args(*a))) * self.config['fs'] elif DtE == 'DxhDtx': for dtx, dxh in zip(self.dtx(**options), self.dxH(**options)): yield scalar_product(dtx, dxh)