Skip to content

Commit

Permalink
SolutionAbort: check and set in a few more places.
Browse files Browse the repository at this point in the history
This should avoid some catastrophic pointer issues if the initial steps were aborted already.
  • Loading branch information
PMeira committed Jun 22, 2023
1 parent af0a7fa commit 0dea44c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

# Versions 0.13.x

## Version 0.13.4 (2023-06-xx)

Bugfix release (upcoming)

- Handle better how the internal `SolutionAbort` is used. Some invalid states where not being handled on absence of float-point exceptions, leading to potential useless results (NaN) and even crashes.
- `VSource`: Abort the solution if Z1 is zero.

## Version 0.13.3 (2023-06-11)

Bugfix release for some components. No other major changes.
Expand Down
17 changes: 17 additions & 0 deletions src/Common/Solution.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ procedure TSolutionObj.DoPFLOWsolution;
end;
end;

if DSS.SolutionAbort then
Exit;

// The above resets the active sparse set to hY
SolutionInitialized := TRUE;
end;
Expand Down Expand Up @@ -1297,7 +1300,14 @@ function TSolutionObj.SolveCircuit: Integer;
{$ENDIF}
BuildYMatrix(DSS, WHOLEMATRIX, TRUE); // Side Effect: Allocates V
end;

if DSS.SolutionAbort then
Exit;

DoPFLOWsolution;

if DSS.SolutionAbort then
Exit;
except
ON E: EEsolv32Problem do
begin
Expand All @@ -1312,6 +1322,13 @@ procedure TSolutionObj.ZeroInjCurr;
var
I: Integer;
begin
if Currents = NIL then
begin
DoSimpleMsg(DSS, _('General error: internal Currents vector is NIL. Please check your input data and retry.'), 11002);
DSS.SolutionAbort := True;
Exit;
end;

for i := 0 to DSS.ActiveCircuit.NumNodes do
Currents[i] := 0;
end;
Expand Down
9 changes: 7 additions & 2 deletions src/Common/Ymatrix.pas
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ procedure InitializeNodeVbase(DSS: TDSSContext);
i: Integer;

begin
if DSS.ActiveCircuit.Solution.NodeVbase = NIL then
begin
DoSimpleMsg(DSS, _('General error: internal NodeVbase is NIL. Please check your input data and retry.'), 11002);
DSS.SolutionAbort := True;
Exit;
end;

with DSS.ActiveCircuit, Solution do
begin
for i := 1 to NumNodes do
Expand Down Expand Up @@ -368,14 +375,12 @@ procedure BuildYMatrix(DSS: TDSSContext; BuildOption: Integer; AllocateVI: Boole
ReCalcInvalidYPrims(DSS.ActiveCircuit);
end;


if DSS.SolutionAbort then
begin
DoSimpleMsg(DSS, _('Y matrix build aborted due to error in primitive Y calculations.'), 11001);
Exit; // Some problem occured building Yprims
end;


FrequencyChanged := FALSE;

if LogEvents then
Expand Down

0 comments on commit 0dea44c

Please sign in to comment.