Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circuit_Get_Losses segfaults #114

Closed
keegit opened this issue Jul 12, 2022 · 6 comments
Closed

Circuit_Get_Losses segfaults #114

keegit opened this issue Jul 12, 2022 · 6 comments

Comments

@keegit
Copy link

keegit commented Jul 12, 2022

I have the following Rust binding to the Circuit_Get_Losses function. Calling it produces a segmentation fault and core dump.

dss_c::Circuit_Get_Losses(result_ptr, result_cnt);

output:

Segmentation fault (core dumped)

I'm assuming there's some state initialization that I haven't done, but I'm unsure what needs to be initialized.

@PMeira
Copy link
Member

PMeira commented Jul 12, 2022

Which branch/commit are you using?

@PMeira
Copy link
Member

PMeira commented Jul 12, 2022

I'm assuming there's some state initialization that I haven't done, but I'm unsure what needs to be initialized.

Yep. See also #56

@PMeira
Copy link
Member

PMeira commented Jul 12, 2022

If you're using the master branch and 0.12 beta releases, please provide the sequence of calls so I can try to reproduce.

If it's 0.10.x, avoid opening new issues for that. Although there are a few more places that need state checks (per #56), half of the code has been rewritten since 0.10.x.

Worst case scenario, link to the debug version of DSS C-API and you should get detailed info -- either started through a debugger like GDB or load the core dump afterwards. Some general info at https://github.com/dss-extensions/dss_capi/blob/master/docs/debug.md

@keegit
Copy link
Author

keegit commented Jul 13, 2022

I'm using the master branch, here is the sequence of calls I make:

DSS_Start(0);
Text_Set_Command("Redirect <path to dss file>");
Solution_Set_Mode(0); // 0 for snapshot mode
Circuit_Set_ActiveElement();
Loads_Set_kW();
Loads_Set_kvar();
// conditionals
if device == reg {
  RegControls_Set_Name();
  RegControls_Set_TapNumber();
  RegControls_Set_Max_TapChange();
}
if device == cap {
  Capacitors_Set_Name();
  Capacitors_Set_States([0]);
}
Solution_Solve();
Circuit_Get_Losses(); <-- Segfault

@PMeira
Copy link
Member

PMeira commented Jul 13, 2022

hm... seems fine. Are you initializing the two pointers for that function?

Solution_Set_Mode(0); // 0 for snapshot mode
There is an enum for that:

enum SolveModes {
SolveModes_SnapShot = 0, // Solve a single snapshot power flow
SolveModes_Daily = 1, // Solve following Daily load shapes
SolveModes_Yearly = 2, // Solve following Yearly load shapes
SolveModes_Monte1 = 3, // Monte Carlo Mode 1
SolveModes_LD1 = 4, // Load-duration Mode 1
SolveModes_PeakDay = 5, // Solves for Peak Day using Daily load curve
SolveModes_DutyCycle = 6, // Solve following Duty Cycle load shapes
SolveModes_Direct = 7, // Solve direct (forced admittance model)
SolveModes_MonteFault = 8, // Monte carlo Fault Study
SolveModes_FaultStudy = 9, // Fault study at all buses
SolveModes_Monte2 = 10, // Monte Carlo Mode 2
SolveModes_Monte3 = 11, // Monte Carlo Mode 3
SolveModes_LD2 = 12, // Load-Duration Mode 2
SolveModes_AutoAdd = 13, // Auto add generators or capacitors
SolveModes_Dynamic = 14, // Solve for dynamics
SolveModes_Harmonic = 15 // Harmonic solution mode
};

I noticed you're not checking for DSS errors. Check Error_Get_Number() -- if that is non-zero, Error_Get_Description() should list the error message.

@keegit
Copy link
Author

keegit commented Jul 13, 2022

Figured it out - the issue was that I was not properly initializing the pointers passed to the function.

@keegit keegit closed this as completed Jul 13, 2022
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

No branches or pull requests

2 participants