diff --git a/andes/core/model.py b/andes/core/model.py index ed87a5be8..bcd02d20e 100644 --- a/andes/core/model.py +++ b/andes/core/model.py @@ -79,6 +79,9 @@ def refresh(self, name=None): ---------- name : str, list, optional name or list of cached to refresh, by default None for refreshing all + + TODO: bug found in Example notebook 2. Time domain initialization fails + after refreshing. """ if name is None: for name in self._callbacks.keys(): diff --git a/andes/system.py b/andes/system.py index 8a9510440..96d44b3a8 100644 --- a/andes/system.py +++ b/andes/system.py @@ -710,6 +710,12 @@ def store_adder_setter(self, models): if not mdl.n: continue + # Fixes an issue if the cache was manually built but stale + # after assigning addresses for simulation + # Assigning memory will affect the cache of `v_adders` and `e_adders`. + + mdl.cache.refresh() + # ``getters` that retrieve variable values from DAE for var in mdl.cache.v_getters.values(): self._getters[var.v_code].append(var) diff --git a/examples/2. inspect_data.ipynb b/examples/2. inspect_data.ipynb index eb3314e63..f2a30c96f 100644 --- a/examples/2. inspect_data.ipynb +++ b/examples/2. inspect_data.ipynb @@ -108,144 +108,36 @@ "name": "stderr", "output_type": "stream", "text": [ - "Working directory: \"/home/hcui7/repos/andes/examples\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded generated Python code in \"~/.andes/pycode\".\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Input file parsed in 0.2970 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "System internal structure set up in 0.0402 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "-> System connectivity check results:\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " No islanded bus detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " A total of 1 island(s) detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " Each island has a slack bus correctly defined and enabled.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "Working directory: \"/home/hcui7/repos/andes/examples\"\n", + "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", + "Loaded generated Python code in \"/home/hcui7/.andes/pycode\".\n", + "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n", + "Input file parsed in 0.1595 seconds.\n", + "System internal structure set up in 0.0293 seconds.\n", + "-> System connectivity check results:\n", + " No islanded bus detected.\n", + " A total of 1 island(s) detected.\n", + " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", - " Sparse addition: Fast in-place (kvxopt)\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Power flow initialized.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "0: |F(x)| = 14.9282832\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "1: |F(x)| = 3.608627841\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2: |F(x)| = 0.1701107882\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "3: |F(x)| = 0.002038626956\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "4: |F(x)| = 3.745103977e-07\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Converged in 5 iterations in 0.0067 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Report saved to \"kundur_full_out.txt\" in 0.0011 seconds.\n" + " Sparse addition: Fast in-place (kvxopt)\n", + "Power flow initialized.\n", + "0: |F(x)| = 14.9282832\n", + "1: |F(x)| = 3.608627841\n", + "2: |F(x)| = 0.1701107882\n", + "3: |F(x)| = 0.002038626956\n", + "4: |F(x)| = 3.745103977e-07\n", + "Converged in 5 iterations in 0.0072 seconds.\n", + "Report saved to \"kundur_full_out.txt\" in 0.0008 seconds.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "-> Single process finished in 0.4579 seconds.\n" + "-> Single process finished in 0.2939 seconds.\n" ] } ], @@ -281,35 +173,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "Working directory: \"/home/hcui7/repos/andes/examples\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded generated Python code in \"~/.andes/pycode\".\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Input file parsed in 0.1007 seconds.\n" + "Working directory: \"/home/hcui7/repos/andes/examples\"\n", + "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", + "Reloaded generated Python code of module \"pycode\".\n", + "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n", + "Input file parsed in 0.0412 seconds.\n" ] } ], @@ -376,102 +244,24 @@ "name": "stderr", "output_type": "stream", "text": [ - "System internal structure set up in 0.0383 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "-> System connectivity check results:\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " No islanded bus detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " A total of 1 island(s) detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " Each island has a slack bus correctly defined and enabled.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "System internal structure set up in 0.0347 seconds.\n", + "-> System connectivity check results:\n", + " No islanded bus detected.\n", + " A total of 1 island(s) detected.\n", + " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", - " Sparse addition: Fast in-place (kvxopt)\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Power flow initialized.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "0: |F(x)| = 14.9282832\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "1: |F(x)| = 3.601770103\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2: |F(x)| = 0.1535494157\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "3: |F(x)| = 0.001799769945\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "4: |F(x)| = 3.667672734e-07\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Converged in 5 iterations in 0.0153 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Report saved to \"kundur_full_out.txt\" in 0.0032 seconds.\n" + " Sparse addition: Fast in-place (kvxopt)\n", + "Power flow initialized.\n", + "0: |F(x)| = 14.9282832\n", + "1: |F(x)| = 3.601770103\n", + "2: |F(x)| = 0.1535494157\n", + "3: |F(x)| = 0.001799769945\n", + "4: |F(x)| = 3.667672734e-07\n", + "Converged in 5 iterations in 0.0069 seconds.\n", + "Report saved to \"kundur_full_out.txt\" in 0.0010 seconds.\n" ] }, { @@ -564,151 +354,37 @@ "name": "stderr", "output_type": "stream", "text": [ - "Working directory: \"/home/hcui7/repos/andes/examples\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loaded generated Python code in \"~/.andes/pycode\".\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur.raw\"...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " MODIFIED KUNDUR'S TWO-AREA TEST SYSTEM, DISTRIBUTED WITH ANDES\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " SEE THE BOOK \"POWER SYSTEM STABILITY AND CONTROL\" FOR ORIGINAL DATA\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Input file parsed in 0.0046 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Parsing additional file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.dyr\"...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Addfile parsed in 0.1368 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "System internal structure set up in 0.0348 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "-> System connectivity check results:\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " No islanded bus detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " A total of 1 island(s) detected.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - " Each island has a slack bus correctly defined and enabled.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "Working directory: \"/home/hcui7/repos/andes/examples\"\n", + "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", + "Reloaded generated Python code of module \"pycode\".\n", + "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur.raw\"...\n", + " MODIFIED KUNDUR'S TWO-AREA TEST SYSTEM, DISTRIBUTED WITH ANDES\n", + " SEE THE BOOK \"POWER SYSTEM STABILITY AND CONTROL\" FOR ORIGINAL DATA\n", + "Input file parsed in 0.0039 seconds.\n", + "Parsing additional file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.dyr\"...\n", + "Addfile parsed in 0.0864 seconds.\n", + "System internal structure set up in 0.0298 seconds.\n", + "-> System connectivity check results:\n", + " No islanded bus detected.\n", + " A total of 1 island(s) detected.\n", + " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", - " Sparse addition: Fast in-place (kvxopt)\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Power flow initialized.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "0: |F(x)| = 3.175850023\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "1: |F(x)| = 3.176155228e-08\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Converged in 2 iterations in 0.0049 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Report saved to \"kundur_out.txt\" in 0.0034 seconds.\n" + " Sparse addition: Fast in-place (kvxopt)\n", + "Power flow initialized.\n", + "0: |F(x)| = 3.175850023\n", + "1: |F(x)| = 3.176155228e-08\n", + "Converged in 2 iterations in 0.0024 seconds.\n", + "Report saved to \"kundur_out.txt\" in 0.0005 seconds.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "-> Single process finished in 0.3654 seconds.\n" + "-> Single process finished in 0.2672 seconds.\n" ] } ], @@ -2061,132 +1737,26 @@ "-> Time Domain Simulation Summary:\n", "Sparse Solver: KLU\n", "Simulation time: 0-20.0 s.\n", - "Fixed step size: h=33.33 ms. Shrink if not converged.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Suspect initialization issue! Simulation may crash!\n", - "\n", - " Name | Var. Value | Eqn. Mismatch\n", - "----------------+------------+--------------\n", - " delta GENROU 1 | 2.840 | 753.982 \n", - " delta GENROU 2 | 2.248 | 753.982 \n", - " delta GENROU 3 | 1.878 | 753.982 \n", - " delta GENROU 4 | 2.423 | 753.982 \n", - " a Bus 1 | 0.570 | -21.804 \n", - " a Bus 2 | 0.378 | -21.000 \n", - " a Bus 3 | 0.196 | -21.000 \n", - " a Bus 4 | 0.378 | -21 \n", - " v Bus 1 | 1.000 | -3.284 \n", - " v Bus 2 | 1.000 | -6.841 \n", - " v Bus 3 | 1.000 | -6.972 \n", - " v Bus 4 | 1.000 | -3.183 \n", - " vd GENROU 1 | 1.502 | -1.473 \n", - " vd GENROU 2 | 1.357 | -0.804 \n", - " vd GENROU 3 | 1.353 | -0.719 \n", - " vd GENROU 4 | 1.481 | -1.182 \n", - " vq GENROU 1 | 1.320 | -3.928 \n", - " vq GENROU 2 | 1.469 | -3.527 \n", - " vq GENROU 3 | 1.473 | -3.167 \n", - " vq GENROU 4 | 1.344 | -3.602 \n", - " tm GENROU 1 | 14.536 | -14.536 \n", - " tm GENROU 2 | 14 | -14 \n", - " tm GENROU 3 | 14.000 | -14.000 \n", - " tm GENROU 4 | 14.000 | -14.000 \n", - " te GENROU 1 | 14.536 | 29.072 \n", - " te GENROU 2 | 14 | 28 \n", - " te GENROU 3 | 14.000 | 28.000 \n", - " te GENROU 4 | 14.000 | 28.000 \n", - " vf GENROU 1 | 3.793 | -3.793 \n", - " vf GENROU 2 | 4.039 | -4.039 \n", - " vf GENROU 3 | 4.052 | -4.052 \n", - " vf GENROU 4 | 3.703 | -3.703 \n", - " Pe GENROU 1 | 14.536 | 29.072 \n", - " Pe GENROU 2 | 14 | 28 \n", - " Pe GENROU 3 | 14.000 | 28.000 \n", - " Pe GENROU 4 | 14.000 | 28.000 \n", - " Qe GENROU 1 | 2.189 | 4.379 \n", - " Qe GENROU 2 | 4.561 | 9.122 \n", - " Qe GENROU 3 | 4.648 | 9.295 \n", - " Qe GENROU 4 | 2.122 | 4.244 \n", - " wd TGOV1 1 | 0 | -1 \n", - " wd TGOV1 2 | 0 | -1 \n", - " wd TGOV1 3 | 0 | -1 \n", - " wd TGOV1 4 | 0 | -1 \n", - " vout EXDC2 1 | 3.793 | 3.793 \n", - " vout EXDC2 2 | 4.039 | 4.039 \n", - " vout EXDC2 3 | 4.052 | 4.052 \n", - " vout EXDC2 4 | 3.703 | 3.703 \n", - "\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Initialization for dynamics failed in 0.0368 seconds.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\r", - " 0%| | 0/100 [00:00: Line.Line_8 status changed to 0 at t=2.0 sec.\n", + "100%|███████████████████████████████| 100/100 [00:00<00:00, 104.52%/s]" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Simulation terminated at t=0.0000 s.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Simulation completed in 1.0414 seconds.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "TimeSeries does not contain any time stamp.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Outputs to \"kundur_out.lst\" and \"kundur_out.npz\".\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Outputs written in 0.0014 seconds.\n" + "Simulation completed in 0.9577 seconds.\n", + "Outputs to \"kundur_out.lst\" and \"kundur_out.npz\".\n", + "Outputs written in 0.0187 seconds.\n" ] }, { @@ -2199,7 +1769,7 @@ { "data": { "text/plain": [ - "False" + "True" ] }, "execution_count": 22, @@ -2230,7 +1800,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 23, @@ -2280,7 +1850,7 @@ { "data": { "text/plain": [ - "(0,)" + "(603,)" ] }, "execution_count": 24, @@ -2311,7 +1881,7 @@ { "data": { "text/plain": [ - "(0, 0)" + "(603, 204)" ] }, "execution_count": 25, @@ -2342,7 +1912,7 @@ { "data": { "text/plain": [ - "200" + "204" ] }, "execution_count": 26, @@ -2381,17 +1951,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "\r\n", - " _ _ | Version 1.4.2.post116.dev0+g832274a7\r\n", - " /_\\ _ _ __| |___ ___ | Python 3.9.6 on Linux, 09/26/2021 05:41:55 PM\r\n", - " / _ \\| ' \\/ _` / -_|_-< | \r\n", - " /_/ \\_\\_||_\\__,_\\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.\r\n", - "\r\n", - "\"/home/hcui7/repos/andes/examples/kundur_out.lst\" removed.\r\n", - "\"/home/hcui7/repos/andes/examples/kundur_full_out.txt\" removed.\r\n", - "\"/home/hcui7/repos/andes/examples/kundur_full_out.npz\" removed.\r\n", - "\"/home/hcui7/repos/andes/examples/kundur_out.npz\" removed.\r\n", - "\"/home/hcui7/repos/andes/examples/kundur_full_out.lst\" removed.\r\n" + "\n", + " _ _ | Version 1.5.1.post2.dev0+ge8465ce0\n", + " /_\\ _ _ __| |___ ___ | Python 3.9.6 on Linux, 10/25/2021 11:50:35 AM\n", + " / _ \\| ' \\/ _` / -_|_-< | \n", + " /_/ \\_\\_||_\\__,_\\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.\n", + "\n", + "\"/home/hcui7/repos/andes/examples/kundur_out.lst\" removed.\n", + "\"/home/hcui7/repos/andes/examples/kundur_out.txt\" removed.\n", + "\"/home/hcui7/repos/andes/examples/kundur_full_out.txt\" removed.\n", + "\"/home/hcui7/repos/andes/examples/kundur_out.npz\" removed.\n" ] } ], @@ -2418,7 +1987,7 @@ ], "metadata": { "interpreter": { - "hash": "4c42303ec617988e96980582546035234a0dbb343f6614254a1d5bddbb9babb9" + "hash": "491bc57f30212ab10e081de3c9da13bbea8cb936a32794256be1d301e32fe2dd" }, "kernelspec": { "display_name": "Python 3.9.6 64-bit ('a': conda)",