How to use the andes.utils.math.zeros function in andes

To help you get started, we’ve selected a few andes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuihantao / andes / andes / variables / dae.py View on Github external
def resize(self):
        """Resize dae and and extend for init1 variables
        """
        yext = self.m - len(self.y)
        xext = self.n - len(self.x)

        if yext > 0:
            yzeros = zeros(yext, 1)
            yones = ones(yext, 1)
            self.y = matrix([self.y, yzeros], (self.m, 1), 'd')
            self.g = matrix([self.g, yzeros], (self.m, 1), 'd')
            self.uy = matrix([self.uy, yones], (self.m, 1), 'd')
            self.zymin = matrix([self.zymin, yones], (self.m, 1), 'd')
            self.zymax = matrix([self.zymax, yones], (self.m, 1), 'd')
        else:
            logger.debug('Skip extending DAE algeb arrays. Did you call `tds.init()` more than once or '
                         'have no dynamic components?')
        if xext > 0:
            xzeros = zeros(xext, 1)
            xones = ones(xext, 1)
            self.x = matrix([self.x, xzeros], (self.n, 1), 'd')
            self.f = matrix([self.f, xzeros], (self.n, 1), 'd')
            self.ux = matrix([self.ux, xones], (self.n, 1), 'd')
            self.zxmin = matrix([self.zxmin, xones], (self.n, 1), 'd')
github cuihantao / andes / andes / models / windturbine.py View on Github external
# rotor speed
        omega = 1 * (ageb(mva * Pg, self.Sn)) + \
            mul(0.5 + 0.5 * mul(Pg, toSn),
                aandb(agtb(Pg, 0), altb(mva * Pg, self.Sn))) + \
            0.5 * (aleb(mva * Pg, 0))

        slip = 1 - omega
        theta = mul(self.Kp, mround(1000 * (omega - 1)) / 1000)
        theta = mmax(theta, 0)

        # prepare for the iterations

        irq = mul(-x1, toSb, (2 * omega - 1), div(1, Vc), div(1, xmu),
                  div(1, omega))
        isd = zeros(*irq.size)
        isq = zeros(*irq.size)

        # obtain ird isd isq
        for i in range(self.n):
            A = sparse([[-rs[i], vsq[i]], [x1[i], -vsd[i]]])
            B = matrix([vsd[i] - xmu[i] * irq[i], Qg[i]])
            linsolve(A, B)
            isd[i] = B[0]
            isq[i] = B[1]
        ird = -div(vsq + mul(rs, isq) + mul(x1, isd), xmu)
        vrd = -mul(rr, ird) + mul(
            slip,
            mul(x2, irq) + mul(xmu, isq))  # todo: check x1 or x2
        vrq = -mul(rr, irq) - mul(slip, mul(x2, ird) + mul(xmu, isd))

        # main iterations
github cuihantao / andes / andes / models / agc.py View on Github external
self.copy_data_ext('Synchronous', field='e1q', dest='e1q', idx=self.syn)
        self.copy_data_ext('Synchronous', field='e2d', dest='e2d', idx=self.syn)
        self.copy_data_ext('Synchronous', field='e2q', dest='e2q', idx=self.syn)

        self.copy_data_ext('Governor', field='xg1', dest='xg1', idx=self.tg)
        self.copy_data_ext('Governor', field='xg2', dest='xg2', idx=self.tg)
        self.copy_data_ext('Governor', field='xg3', dest='xg3', idx=self.tg)
        self.copy_data_ext('Governor', field='pin', dest='pin', idx=self.tg)

        self.copy_data_ext('AVR', field='vm', dest='vm', idx=self.avr)
        self.copy_data_ext('AVR', field='vr1', dest='vr1', idx=self.avr)
        self.copy_data_ext('AVR', field='vr2', dest='vr2', idx=self.avr)
        self.copy_data_ext('AVR', field='vfout', dest='vfout', idx=self.avr)

        dae.y[self.dpin] = 0
        self.dpin0 = zeros(self.n, 1)

        # build state/ input /other algebraic idx array
        self.xidx = matrix([self.delta, self.omega, self.e1d, self.e1q, self.e2d, self.e2q, self.xg1, self.xg2,
                            self.xg3, self.vm, self.vr1, self.vr2, self.vfout])
        self.x0 = dae.x[self.xidx]
        self.x = zeros(len(self.xidx), 1)
        self.dx = zeros(len(self.xidx), 1)
        self.xlast = dae.x[self.xidx]

        self.uidx = matrix([self.dpin])
        self.ulast = zeros(self.n, 1)
        self.dpin_calc = zeros(self.n, 1)

        self.widx = self.system.PQ.a
        self.w0 = self.system.PQ.p0
        self.wlast = matrix(self.w0)
github cuihantao / andes / andes / models / vsc.py View on Github external
def setup(self):
        super().setup()
        self.K = mul(self.K, self.droop)
        self.R = matrix(0, (self.n, 1), 'd')
        self.Zsh = self.rsh + 1j * self.xsh
        self.Ysh = div(1, self.Zsh)

        self.PQ = zeros(self.n, 1)
        self.PV = zeros(self.n, 1)
        self.vV = zeros(self.n, 1)
        self.vQ = zeros(self.n, 1)
        for idx, cc in enumerate(self.control):
            if cc not in ['PQ', 'PV', 'vV', 'vQ']:
                raise KeyError(
                    'VSC {0} control parameter {1} is invalid.'.format(
                        self.name[idx], cc))
            self.__dict__[cc][idx] = 1
github cuihantao / andes / andes / variables / dae.py View on Github external
def init_f(self, resetz=True):
        self.zxmax = ones(self.n, 1)
        self.zxmin = ones(self.n, 1)
        self.f = zeros(self.n, 1)
github cuihantao / andes / andes / models / fault.py View on Github external
def setup(self):
        super().setup()
        self.xf += 1e-8
        Y = div(1, self.rf + 1j * self.xf)
        self.gf = Y.real()
        self.bf = Y.imag()
        self.u = zeros(self.n, 1)
github cuihantao / andes / andes / models / agc.py View on Github external
def init1(self, dae):
        self.ace = [[]] * self.n
        for idx, item in enumerate(self.BA):
            self.ace[idx] = self.read_data_ext('BArea', field='ace', idx=item)

        self.en = zeros(self.n, 1)
github cuihantao / andes / andes / variables / dae.py View on Github external
def init_g(self, resetz=True):
        self.zymax = ones(self.m, 1)
        self.zymin = ones(self.m, 1)
        self.g = zeros(self.m, 1)
github cuihantao / andes / andes / models / agc.py View on Github external
self.copy_data_ext('AVR', field='vr2', dest='vr2', idx=self.avr)
        self.copy_data_ext('AVR', field='vfout', dest='vfout', idx=self.avr)

        dae.y[self.dpin] = 0
        self.dpin0 = zeros(self.n, 1)

        # build state/ input /other algebraic idx array
        self.xidx = matrix([self.delta, self.omega, self.e1d, self.e1q, self.e2d, self.e2q, self.xg1, self.xg2,
                            self.xg3, self.vm, self.vr1, self.vr2, self.vfout])
        self.x0 = dae.x[self.xidx]
        self.x = zeros(len(self.xidx), 1)
        self.dx = zeros(len(self.xidx), 1)
        self.xlast = dae.x[self.xidx]

        self.uidx = matrix([self.dpin])
        self.ulast = zeros(self.n, 1)
        self.dpin_calc = zeros(self.n, 1)

        self.widx = self.system.PQ.a
        self.w0 = self.system.PQ.p0
        self.wlast = matrix(self.w0)

        self.yidx = self.omega
        self.yidx_in_x = [index(self.xidx, y)[0] for y in self.yidx]
        yidx = np.delete(np.arange(dae.m), np.array(self.uidx))
        self.yxidx = matrix(yidx)

        # optimization problem
        self.uvar = cp.Variable((len(self.uidx), self.H), 'u')
        self.prob = None

        self.t_store = []