Skip to content

Commit

Permalink
Merge pull request #461 from CURENT/develop
Browse files Browse the repository at this point in the history
Regular minor release.
  • Loading branch information
cuihantao committed Jun 22, 2023
2 parents 53d5726 + 7fe579e commit d20c689
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: '3.9.2'
hooks:
- id: flake8
32 changes: 23 additions & 9 deletions andes/core/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,21 +502,32 @@ def set(self, src, idx, attr, value):
bool
True when successful.
"""

uid = self.idx2uid(idx)
self.__dict__[src].__dict__[attr][uid] = value
instance = self.__dict__[src]

instance.__dict__[attr][uid] = value

# update differential equations' time constants stored in `dae.Tf`

if attr == "v":
for state in self.states.values():
if (state.t_const is instance) and len(state.a) > 0:
self.system.dae.Tf[state.a[uid]] = instance.v[uid]

return True

def alter(self, src, idx, value):
"""
Alter values of input parameters or constant service.
If the method operates on an input parameter, the new data should be in
the same base as that in the input file. This function will convert the
new value to per unit in the system base.
the same base as that in the input file. This function will convert
``value`` to per unit in the system base whenever necessary.
The values for storing the input data, i.e., the ``vin`` field of the
parameter, will be overwritten, thus the update will be reflected in the
dumped case file.
The values for storing the input data, i.e., the parameter's ``vin``
field, will be overwritten. As a result, altered values will be
reflected in the dumped case file.
Parameters
----------
Expand All @@ -527,11 +538,14 @@ def alter(self, src, idx, value):
value : float
The desired value
"""

instance = self.__dict__[src]

if hasattr(instance, 'vin') and (instance.vin is not None):
self.set(src, idx, 'vin', value)
instance.v[:] = instance.vin * instance.pu_coeff

uid = self.idx2uid(idx)
self.set(src, idx, 'v', value * instance.pu_coeff[uid])
else:
self.set(src, idx, 'v', value)

Expand Down Expand Up @@ -1333,7 +1347,7 @@ def post_init_check(self):
for item in self.services_icheck.values():
item.check()

def numba_jitify(self, parallel=False, cache=True, nopython=False):
def numba_jitify(self, parallel=False, cache=True, nopython=True):
"""
Convert equation residual calls, Jacobian calls, and variable service
calls into JIT compiled functions.
Expand Down Expand Up @@ -1678,7 +1692,7 @@ def _eval_discrete(instance, allow_adjust=True,
def to_jit(func: Union[Callable, None],
parallel: bool = False,
cache: bool = False,
nopython: bool = False,
nopython: bool = True,
):
"""
Helper function for converting a function to a numba jit-compiled function.
Expand Down
5 changes: 3 additions & 2 deletions andes/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self,
('dime_address', 'ipc:///tmp/dime2'),
('numba', 0),
('numba_parallel', 0),
('numba_nopython', 0),
('numba_nopython', 1),
('yapf_pycode', 0),
('save_stats', 0),
('np_divide', 'warn'),
Expand Down Expand Up @@ -824,7 +824,7 @@ def init(self, models: OrderedDict, routine: str):

self.s_update_post(models)

# store the inverse of time constants
# store time constants associated with differential equations
self._store_tf(models)

def store_adder_setter(self, models):
Expand Down Expand Up @@ -1255,6 +1255,7 @@ def connectivity(self, info=True):
to + fr + fr + to,
(n, n),
'd')
temp = sparse(temp) # need to drop allocated zero values

cons = temp[0, :]
nelm = len(cons.J)
Expand Down
14 changes: 14 additions & 0 deletions docs/source/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ The APIs before v3.0.0 are in beta and may change without prior notice.
v1.8 Notes
==========

v1.8.9 (2023-06-22)
-------------------
- Fix `Model.alter()` for parameters that are time constants for differential
equations. Altered time constants are now properly updated in ``dae.Tf`` and
will be correctly reflected in simulation results.
- Fix a bug in connectivity check.
- Support numba for Python 3.11.

v1.8.8 (2023-04-24)
-------------------
- Repository transferred to `github.com/curent/andes`.
- Fix for frequency-dependent load model ``FLoad`` by not exporting the external
`bus` parameter.

v1.8.7 (2023-03-10)
-------------------
- Added IEEE 39-bus test case with dynamics in the ANDES xlsx format.
Expand Down
2 changes: 0 additions & 2 deletions requirements-extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ myst-parser==0.15.2 # dev, doc
myst-nb==0.13.2 # dev, doc
pre-commit # dev

numba # dev, perf

pandapower # interop

# below work around a bug with tqdm bar with ipywidgets 8.0.1
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coloredlogs
chardet
psutil
texttable
numba
37 changes: 37 additions & 0 deletions tests/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ def test_alter_param(self):
self.assertEqual(self.ss.PV.v0.v[1], 0.98)
self.ss.PFlow.run()

def test_alter_param_time_const_before_pflow(self):
"""
Test altering parameter for time constants of diff eq.
"""

self.ss.GENCLS.alter("M", [2, 3], [2., 2.])
np.testing.assert_array_equal(self.ss.GENCLS.M.v, [8., 6., 4., 12.])
self.ss.PFlow.run()

self.ss.TDS.init()
np.testing.assert_array_equal(self.ss.dae.Tf[self.ss.GENCLS.omega.a], [8., 6., 4., 12.])

def test_alter_param_time_const_after_pflow(self):
"""
Test altering parameter for time constants of diff eq.
"""

self.ss.PFlow.run()
self.ss.GENCLS.alter("M", [2, 3], [2., 2.])
np.testing.assert_array_equal(self.ss.GENCLS.M.v, [8., 6., 4., 12.])

self.ss.TDS.init()
np.testing.assert_array_equal(self.ss.dae.Tf[self.ss.GENCLS.omega.a], [8., 6., 4., 12.])

def test_multiple_disconnected_line(self):
"""
Test connectivity check for systems with disconnected lines.
These disconnected lines (zeros) was not excluded when counting
connected buses, causing an out-of-bound error.
"""

self.ss.Line.u.v[[0, 6]] = 0
self.ss.PFlow.run()
self.assertEqual(len(self.ss.Bus.islands), 1)
self.assertEqual(self.ss.Bus.n_islanded_buses, 0)


class TestKundur2AreaEIG(unittest.TestCase):
"""
Expand Down

0 comments on commit d20c689

Please sign in to comment.