Skip to content

Commit

Permalink
[WIP] Add function for generating network admittance matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuihantao committed Mar 19, 2024
1 parent b79a8cf commit 5b7acbd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions andes/models/line/line.py
Expand Up @@ -3,8 +3,10 @@
"""

import numpy as np

from andes.core import (ModelData, IdxParam, NumParam, DataParam,
Model, ExtAlgeb, ConstService)
from andes.shared import spmatrix


class LineData(ModelData):
Expand Down Expand Up @@ -241,3 +243,30 @@ def get_tf_idx(self):
"""

return np.array(self.idx.v)[self.istf]

def build_y(self):
"""
Build bus admittance matrix. Store the matrix in ``self.Y``.
Returns
-------
Y : spmatrix
Bus admittance matrix.
"""

nb = self.system.Bus.n

y1 = self.u.v * (self.g1.v + self.b1.v * 1j)
y2 = self.u.v * (self.g2.v + self.b2.v * 1j)
y12 = self.u.v / (self.r.v + self.x.v * 1j)
m = self.tap.v * np.exp(1j * self.phi.v)
m2 = self.tap.v**2
mconj = np.conj(m)

# build self and mutual admittances into Y
self.Y = spmatrix((y12 + y1 / m2), self.a1.a, self.a1.a, (nb, nb), 'z')
self.Y -= spmatrix(y12 / mconj, self.a1.a, self.a2.a, (nb, nb), 'z')
self.Y -= spmatrix(y12 / m, self.a2.a, self.a1.a, (nb, nb), 'z')
self.Y += spmatrix(y12 + y2, self.a2.a, self.a2.a, (nb, nb), 'z')

return self.Y

0 comments on commit 5b7acbd

Please sign in to comment.