Skip to content

Commit

Permalink
Merge pull request #23 from jinningwang/busang
Browse files Browse the repository at this point in the history
Example
  • Loading branch information
jinningwang authored Jan 21, 2024
2 parents 4712a41 + 777e973 commit c538084
Show file tree
Hide file tree
Showing 7 changed files with 960 additions and 27 deletions.
18 changes: 15 additions & 3 deletions ams/routines/dcopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def __init__(self, system, config):
self.rate_a = RParam(info='long-term flow limit',
name='rate_a', tex_name=r'R_{ATEA}',
unit='MVA', model='Line',)
# --- line angle difference ---
self.amax = NumOp(u=self.rate_a, fun=np.ones_like,
rfun=np.dot, rargs=dict(b=np.pi),
name='amax', tex_name=r'\theta_{max}',
info='max line angle difference',
no_parse=True,)
# --- shunt ---
self.gsh = RParam(info='shunt conductance',
name='gsh', tex_name=r'g_{sh}',
Expand All @@ -99,9 +105,9 @@ def __init__(self, system, config):
name='Cl', tex_name=r'C_{l}',
model='mats', src='Cl',
no_parse=True, sparse=True,)
self.Cft = RParam(info='Line connection matrix',
name='Cft', tex_name=r'C_{ft}',
model='mats', src='Cft',
self.CftT = RParam(info='Transpose of line connection matrix',
name='CftT', tex_name=r'C_{ft}^T',
model='mats', src='CftT',
no_parse=True, sparse=True,)
self.Csh = RParam(info='Shunt connection matrix',
name='Csh', tex_name=r'C_{sh}',
Expand Down Expand Up @@ -158,6 +164,12 @@ def __init__(self, system, config):
self.plfub = Constraint(info='line flow upper bound',
name='plfub', type='uq',
e_str='Bf@aBus + Pfinj - rate_a',)
self.alflb = Constraint(info='line angle difference lower bound',
name='alflb', type='uq',
e_str='-CftT@aBus - amax',)
self.alfub = Constraint(info='line angle difference upper bound',
name='alfub', type='uq',
e_str='CftT@aBus - amax',)

# --- objective ---
obj = 'sum(mul(c2, power(pg, 2)))'
Expand Down
3 changes: 0 additions & 3 deletions ams/routines/dopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def __init__(self, system, config):
self.qmin = RParam(info='generator minimum reactive power',
name='qmin', tex_name=r'q_{min}', unit='p.u.',
model='StaticGen', src='qmin',)
self.CftT = RParam(info='Line connectivity matrix transpose',
name='CftT', tex_name=r'C_{ft}^{T}',
model='mats', src='CftT', no_parse=True,)
# --- load ---
self.qd = RParam(info='reactive demand',
name='qd', tex_name=r'q_{d}', unit='p.u.',
Expand Down
2 changes: 2 additions & 0 deletions ams/routines/ed.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def __init__(self, system, config):
self.plf.info = '2D Line flow'
self.plflb.e_str = '-Bf@aBus - Pfinj@tlv - rate_a@tlv'
self.plfub.e_str = 'Bf@aBus + Pfinj@tlv - rate_a@tlv'
self.alflb.e_str = '-CftT@aBus - amax@tlv'
self.alfub.e_str = 'CftT@aBus - amax@tlv'

# --- power balance ---
self.pb.e_str = 'Bbus@aBus + Pbusinj@tlv + Cl@pds + Csh@gsh@tlv - Cg@pg'
Expand Down
33 changes: 14 additions & 19 deletions ams/routines/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get(self, src: str, idx, attr: str = 'v',
Index of the variable or parameter.
attr: str
Attribute name.
horizon: int, str, or list, optional
horizon: list, optional
Horizon index.
"""
if src not in self.__dict__.keys():
Expand Down Expand Up @@ -201,24 +201,19 @@ def get(self, src: str, idx, attr: str = 'v',
if item.horizon is None:
raise ValueError(f"horizon is not defined for {self.class_name}.{src}.")
horizon_all = item.horizon.get_idx()
if isinstance(horizon, int):
horizon = [horizon]
if isinstance(horizon, str):
horizon = [int(horizon)]
if isinstance(horizon, np.ndarray):
horizon = horizon.tolist()
if isinstance(horizon, list):
loc_h = [
horizon_all.index(idxe) if idxe in horizon_all else None
for idxe in horizon
]
if None in loc_h:
idx_none = [idxe for idxe in horizon if idxe not in horizon_all]
msg = f"Var <{self.class_name}.{src}> does not contain horizon with idx={idx_none}"
raise ValueError(msg)
out = out[:, loc_h]
if out.shape[1] == 1:
out = out[:, 0]
if not isinstance(horizon, list):
raise TypeError(f"horizon must be a list, not {type(horizon)}.")
loc_h = [
horizon_all.index(idxe) if idxe in horizon_all else None
for idxe in horizon
]
if None in loc_h:
idx_none = [idxe for idxe in horizon if idxe not in horizon_all]
msg = f"Var <{self.class_name}.{src}> does not contain horizon with idx={idx_none}"
raise ValueError(msg)
out = out[:, loc_h]
if out.shape[1] == 1:
out = out[:, 0]
return out

def set(self, src: str, idx, attr: str = "v", value=0.0):
Expand Down
6 changes: 4 additions & 2 deletions ams/routines/uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ def __init__(self, system, config):
# --- line ---
self.plf.horizon = self.timeslot
self.plf.info = '2D Line flow'
self.plflb.e_str = '-plf - mul(rate_a, tlv)'
self.plfub.e_str = 'plf - mul(rate_a, tlv)'
self.plflb.e_str = '-Bf@aBus - Pfinj - mul(rate_a, tlv)'
self.plfub.e_str = 'Bf@aBus + Pfinj - mul(rate_a, tlv)'
self.alflb.e_str = '-CftT@aBus - amax@tlv'
self.alfub.e_str = 'CftT@aBus - amax@tlv'

# --- unserved load ---
self.pdu = Var(info='unserved demand',
Expand Down
1 change: 1 addition & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ folder of the repository
../_examples/ex3.ipynb
../_examples/ex4.ipynb
../_examples/ex5.ipynb
../_examples/ex6.ipynb
Loading

0 comments on commit c538084

Please sign in to comment.