Skip to content

Commit

Permalink
Patched Line.flags.tds=True; set address in TDS for all models to h…
Browse files Browse the repository at this point in the history
…ave Bus share the memory of the extended `dae.y`
  • Loading branch information
cuihantao committed Jul 29, 2020
1 parent 06e73e7 commit a5ad5af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Expand Up @@ -10,8 +10,8 @@
- [x] Improve the speed of `DAETimeSeries.unpack`.
- [x] Allow simulating to a time, pause, and continue to a new ending time.
- [x] Store TDS data as NumPy compressed format `npz`; allow to reload both `npy` and `npz`.
- [x] Power flow model variables erroneously point to the old `dae.y` array (fixed)
* Allow loading default config for `selftest`
* Power flow model variables erroneously point to the old `dae.y` array

## Later Versions
* Generalize two-terminal and multi-terminal devices
Expand Down
1 change: 1 addition & 0 deletions andes/models/line.py
Expand Up @@ -44,6 +44,7 @@ def __init__(self, system=None, config=None):
Model.__init__(self, system, config)
self.group = 'ACLine'
self.flags.pflow = True
self.flags.tds = True

self.a1 = ExtAlgeb(model='Bus', src='a', indexer=self.bus1, tex_name='a_1',
info='phase angle of the from bus')
Expand Down
16 changes: 11 additions & 5 deletions andes/routines/tds.py
Expand Up @@ -61,7 +61,6 @@ def __init__(self, system=None, config=None):
self.deltatmax = 0
self.h = 0
self.next_pc = 0
self.eye = None
self.Teye = None
self.qg = np.array([])
self.tol_zero = self.config.tol / 100
Expand Down Expand Up @@ -100,17 +99,25 @@ def init(self):

self._reset()
self._load_pert()
system.set_address(models=system.exist.tds)

# Note:
# calling `set_address` on `system.exist.pflow_tds` will point all variables
# to the new array after extending `dae.y`
system.set_address(models=system.exist.pflow_tds)

system.set_dae_names(models=system.exist.tds)

system.dae.clear_ts()
system.store_sparse_pattern(models=system.exist.pflow_tds)
system.store_adder_setter(models=system.exist.pflow_tds)
system.vars_to_models()

# Initialize `system.exist.tds` only to avoid Bus overwriting power flow solutions
system.init(system.exist.tds)
system.store_switch_times(system.exist.tds)
self.eye = spdiag([1] * system.dae.n)
self.Teye = spdiag(system.dae.Tf.tolist()) * self.eye

# Build mass matrix into `self.Teye`
self.Teye = spdiag(system.dae.Tf.tolist())
self.qg = np.zeros(system.dae.n + system.dae.m)

self.initialized = self.test_init()
Expand Down Expand Up @@ -708,7 +715,6 @@ def _reset(self):
self.deltatmax = 0
self.h = 0
self.next_pc = 0.1
self.eye = None
self.Teye = None
self.qg = np.array([])

Expand Down

0 comments on commit a5ad5af

Please sign in to comment.