Skip to content

Commit

Permalink
Default dae.t to -1 for power flow. TDS initialization will set `…
Browse files Browse the repository at this point in the history
…dae.t` to 0.
  • Loading branch information
cuihantao committed Sep 19, 2023
1 parent 8f0d18c commit ebbf5cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion andes/core/discrete.py
Expand Up @@ -1633,8 +1633,13 @@ def check_var(self, dae_t, *args, niter=None, err=None, **kwargs):
return

# allow unlimited switching in power flow
if dae_t == 0.0:
if dae_t < 0.0:
self.t_enable[:] = 1.0

# reset `t_last` upon TDS initialization
elif dae_t == 0.0:
self.t_last = np.zeros_like(self.v.v)

# consider delay for time-domain simulation
else:
self.t_enable[:] = (dae_t - self.t_last - self.dt.v) >= 0
Expand Down
8 changes: 4 additions & 4 deletions andes/models/static/pq.py
Expand Up @@ -211,12 +211,12 @@ def __init__(self, system=None, config=None):
# To modify P and Q during TDS, use `alter` to set values to `Ppf` and `Qpf`
# after, before simulation, setting `config.p2p=1` and `config.q2q=1`.

self.a.e_str = "u * Indicator(dae_t <= 0) * " \
self.a.e_str = "u * Indicator(dae_t < 0) * " \
"(p0 * vcmp_zi + Rlb * vcmp_zl * v**2 + Rub * vcmp_zu * v**2) + " \
"u * Indicator(dae_t > 0) * " \
"u * Indicator(dae_t >= 0) * " \
"(p2p * Ppf + p2i * Ipeq * v + p2z * Req * v**2)"

self.v.e_str = "u * Indicator(dae_t <= 0) * " \
self.v.e_str = "u * Indicator(dae_t < 0) * " \
"(q0 * vcmp_zi + Xlb * vcmp_zl * v**2 + Xub * vcmp_zu * v**2) + " \
"u * Indicator(dae_t > 0) * " \
"u * Indicator(dae_t >= 0) * " \
"(q2q * Qpf + q2i * Iqeq * v + q2z * Xeq * v**2)"
5 changes: 3 additions & 2 deletions andes/routines/tds.py
Expand Up @@ -197,6 +197,7 @@ def init(self):
# restore power flow solutions
system.dae.x[:len(system.PFlow.x_sol)] = system.PFlow.x_sol
system.dae.y[:len(system.PFlow.y_sol)] = system.PFlow.y_sol
system.dae.t -= system.dae.t # set `dae.t` to zero

# Note:
# calling `set_address` on `system.exist.pflow_tds` will point all variables
Expand Down Expand Up @@ -347,8 +348,8 @@ def run(self, no_summary=False, **kwargs):
if no_summary is False and (system.dae.t == 0):
self.summary()

# only initializing at t=0 allows to continue when `run` is called again.
if system.dae.t == 0:
# only initializing at t<0 allows to continue when `run` is called again.
if system.dae.t < 0:
self.init()
else: # resume simulation
self.init_resume()
Expand Down
2 changes: 1 addition & 1 deletion andes/variables/dae.py
Expand Up @@ -306,7 +306,7 @@ class DAE:

def __init__(self, system):
self.system = system
self.t = np.array(0.0, dtype=float)
self.t = np.array(-1.0, dtype=float)
self.ts = DAETimeSeries(self)
self.kcount = 0 # time step count

Expand Down
8 changes: 8 additions & 0 deletions docs/source/release-notes.rst
Expand Up @@ -6,6 +6,14 @@ Release notes

The APIs before v3.0.0 are in beta and may change without prior notice.

v1.9 Notes
==========

v1.9.0 (2023-09-XX)
-------------------
- Initially, ``dae.t`` is set to ``-1.0`` during power flow calculation. TDS
initialization will set ``dae.t = 0.0``.

v1.8 Notes
==========

Expand Down

0 comments on commit ebbf5cf

Please sign in to comment.