Skip to content

Fix Generator vmin_pu/vmax_pu setters not persisting to C engine#106

Open
matheusduartedm wants to merge 1 commit intoPauloRadatz:masterfrom
matheusduartedm:fix/generators-vminpu-vmaxpu-write
Open

Fix Generator vmin_pu/vmax_pu setters not persisting to C engine#106
matheusduartedm wants to merge 1 commit intoPauloRadatz:masterfrom
matheusduartedm:fix/generators-vminpu-vmaxpu-write

Conversation

@matheusduartedm
Copy link
Copy Markdown

Summary

  • Bug: dss.generators.vmin_pu and dss.generators.vmax_pu property setters call GeneratorsF with C API indices 11/13, but the C library handler for those indices doesn't write to the active Generator object — it only echoes the parameter back. This causes silent data corruption in power flow results (OpenDSS uses defaults 0.90/1.10 instead of the intended values).
  • Fix: Replace the broken C API calls in _vmax_pu_write and _vmin_pu_write with text command workarounds (Generator.<name>.Vmaxpu=<value> / Vminpu=<value>), following the same pattern used elsewhere (e.g., LoadShapesV.py, SettingsV.py).
  • Read operations (indices 10/12) are unaffected and remain unchanged.

Reproduction

dss.generators.name = "sgen_0"
dss.generators.vmin_pu = 0.0

# Getter looks OK:
print(dss.generators.vmin_pu)                    # → 0.0

# But the C engine was NOT updated:
print(dss.text("? Generator.sgen_0.Vminpu"))     # → 0.90 (default!)

After this fix, the text command correctly returns 0.0.

Root cause

The bug is in the OpenDSS C library (libOpenDSSC.so), not in py-dss-interface's Python code. The GeneratorsF function handler for parameter indices 11 and 13 reads the argument but doesn't assign it to the active Generator's Vmaxpu/Vminpu fields. The equivalent DSSLoadsF handler (indices 29/35) works correctly for loads.

Test plan

  • Verified fix with manual test: set vmin_pu=0.0, vmax_pu=2.0, confirmed via text command read-back
  • Existing tests in test_generators.py (note: test suite has pre-existing setup issues on Linux due to missing .so in linux/cpp/ directory — not related to this change)

The GeneratorsF C API calls (indices 11 and 13) for writing Vmaxpu and
Vminpu do not actually write to the active Generator object in the C
library — they only echo the parameter back. This causes silent data
corruption in power flow results.

Replace the broken C API calls with text command workarounds that
correctly persist values via `Generator.<name>.Vmaxpu=<value>` and
`Generator.<name>.Vminpu=<value>`. Read operations (indices 10/12)
remain unchanged as they work correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PauloRadatz
Copy link
Copy Markdown
Owner

Hi @matheusduartedm, thank you so much for reporting this issue. I replicated it on my side. I will work on fixing it in the OpenDSS source code.

Please let me know if you have seen this in other properties.

Again, thank you so much.

@PauloRadatz
Copy link
Copy Markdown
Owner

I just noticed that this type of issues is not related to generators and C++ version. It is in some elements and also in Delphi. I will need to work on the OpenDSS source codes (Delphi and C++).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants