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

v0.12.x mega-merge #109

Merged
merged 27 commits into from
May 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e2c2a9e
Squashed changes, docs pending
PMeira Mar 7, 2022
6ce62e6
Builds: cross-compile to macOS ARM64/aarch64, including GitHub Actions.
PMeira Mar 8, 2022
a754bba
User-models: update headers; remove from legacy models; consolidate f…
PMeira Mar 9, 2022
ece66dd
Add COMHelp with instructions on where to download it.
PMeira Mar 16, 2022
5777b58
Properties/RegControl.PTPhase: fix corner case in hybrid enum
PMeira Mar 17, 2022
6ea25cd
AlwaysResetYPrimInvalid: Reduce number of bits to fit in a int32 (and…
PMeira Mar 17, 2022
9b7d7b4
A few microoptimizations
PMeira Mar 17, 2022
35eed4d
Load, ZIPV model: apply some manual optimizations
PMeira Mar 17, 2022
d909f68
YMatrix_SolveSystem: fix NIL check and tweak params
PMeira Mar 19, 2022
ec0c572
Solution: check for infinites in MaxError
PMeira Mar 22, 2022
b7bebd4
CktElement/API: To match SVN, add CktElement_Set_Variable/CktElement_…
PMeira Mar 22, 2022
a8ea2ed
CIM: port recent changes.
PMeira Mar 22, 2022
d3d1f6b
InvControl(2): remove infinite loop
PMeira Mar 27, 2022
38691b2
API: fix/add invalid state checks.
PMeira Mar 27, 2022
eb8ecff
Spectrum: Fix issue when reading fewer items than specified from CSV.
PMeira Mar 30, 2022
53cd601
ExportCIMXML: port recent changes (from multiple revisions)
PMeira Mar 31, 2022
215c3b1
ExportCIMXML: port a few SVN commits
PMeira Apr 11, 2022
3e55121
Recloser: in `Sample`, check if `MonitoredObj` (`MonitoredElement`) w…
PMeira Apr 11, 2022
ecaae7e
DOScmd: introduce toggle flag and matching functions; default to disa…
PMeira Apr 11, 2022
4388b7d
ReduceAlgs, from SVN: "Checking for bus in the KeepList when reducing…
PMeira Apr 12, 2022
0d7cfb7
Capacitors/API: Fix error in format string
PMeira Apr 13, 2022
5e55d38
Port from SVN: "Fixing issues when using ActiveActor=* within a scrip…
PMeira Apr 14, 2022
c943b2b
ZIP: better error and filename handling
PMeira Apr 15, 2022
d960bd7
ZIP/API: add ZIP_Extract to get the contents of a compressed file
PMeira Apr 20, 2022
166585b
ZIP/API: Add Contains and List, and comments.
PMeira Apr 20, 2022
533b025
PVSystems: Update units in `Irradiance` comments
PMeira Apr 21, 2022
fbe465e
README: Update the basic text and diagrams
PMeira May 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
A few microoptimizations
PMeira committed Mar 19, 2022
commit 9b7d7b4f3f82da323195e71b51bf07fbf8f82dda
59 changes: 46 additions & 13 deletions src/Common/CktElement.pas
Original file line number Diff line number Diff line change
@@ -34,8 +34,9 @@ TDSSCktElement = class(TDSSObject)
procedure Set_Freq(Value: Double); // set freq and recompute YPrim.

procedure Set_Nconds(Value: Int8);
function Get_ActiveTerminal(): Int8; inline;
procedure Set_ActiveTerminal(value: Int8);
function Get_ConductorClosed(Index: Integer): Boolean;
function Get_ConductorClosed(Index: Integer): Boolean; inline;
procedure Set_YprimInvalid(const Value: Boolean);
function Get_FirstBus: String;
function Get_NextBus: String;
@@ -133,7 +134,7 @@ TDSSCktElement = class(TDSSObject)
property MaxPower[idxTerm: Integer]: Complex READ Get_MaxPower; // Total power in active terminal
property MaxCurrent[idxTerm: Integer]: Double READ Get_MaxCurrent; // Max current in active terminal
property MaxVoltage[idxTerm: Integer]: Double READ Get_MaxVoltage; // Max voltage in active terminal
property ActiveTerminalIdx: Int8 READ FActiveTerminal WRITE Set_ActiveTerminal;
property ActiveTerminalIdx: Int8 READ Get_ActiveTerminal WRITE Set_ActiveTerminal;
property Closed[Index: Integer]: Boolean READ Get_ConductorClosed WRITE Set_ConductorClosed;
procedure SumCurrents;

@@ -190,7 +191,7 @@ constructor TDSSCktElement.Create(ParClass: TDSSClass);
// Make list for a small number of controls with an increment of 1
ControlElementList := TDSSPointerList.Create(1);

FActiveTerminal := 1;
FActiveTerminal := 0;
// LastTerminalChecked := 0;

// Indicates which solution Itemp is computed for
@@ -241,12 +242,17 @@ procedure TDSSCktElement.Set_YprimInvalid(const Value: Boolean);
ActiveCircuit.Solution.SystemYChanged := TRUE;
end;

function TDSSCktElement.Get_ActiveTerminal(): Int8; inline;
begin
Result := FActiveTerminal + 1;
end;

procedure TDSSCktElement.Set_ActiveTerminal(value: Int8);
begin
if (Value > 0) and (Value <= fNterms) then
begin
FActiveTerminal := Value;
ActiveTerminal := @Terminals[Value - 1];
FActiveTerminal := Value - 1;
ActiveTerminal := @Terminals[FActiveTerminal];
end;
end;

@@ -255,7 +261,7 @@ procedure TDSSCktElement.Set_Handle(value: Integer);
FHandle := value;
end;

function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean;
function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean; inline;
// return state of selected conductor
// if index=0 return true if all phases closed, else false
var
@@ -266,7 +272,7 @@ function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean;
Result := TRUE;
for i := 1 to Fnphases do
begin
if not Terminals[FActiveTerminal - 1].ConductorsClosed[i - 1] then
if not Terminals[FActiveTerminal].ConductorsClosed[i - 1] then
begin
Result := FALSE;
Break;
@@ -275,7 +281,7 @@ function TDSSCktElement.Get_ConductorClosed(Index: Integer): Boolean;
end
else
if (Index > 0) and (Index <= Fnconds) then
Result := Terminals[FActiveTerminal - 1].ConductorsClosed[Index - 1]
Result := Terminals[FActiveTerminal].ConductorsClosed[Index - 1]
else
Result := FALSE;
end;
@@ -286,16 +292,16 @@ procedure TDSSCktElement.Set_ConductorClosed(Index: Integer; Value: Boolean);
begin
if (Index = 0) then
begin // Do all conductors
for i := 1 to Fnphases do
Terminals[FActiveTerminal - 1].ConductorsClosed[i - 1] := Value;
for i := 0 to Fnphases - 1 do
Terminals[FActiveTerminal].ConductorsClosed[i] := Value;
// DSS.ActiveCircuit.Solution.SystemYChanged := TRUE; // force Y matrix rebuild
YPrimInvalid := TRUE; // this also sets the global SystemYChanged flag
end
else
begin
if (Index > 0) and (Index <= Fnconds) then
begin
Terminals[FActiveTerminal - 1].ConductorsClosed[index - 1] := Value;
Terminals[FActiveTerminal].ConductorsClosed[index - 1] := Value;
// DSS.ActiveCircuit.Solution.SystemYChanged := TRUE;
YPrimInvalid := TRUE;
end;
@@ -1054,15 +1060,42 @@ procedure TDSSCktElement.ComputeVterminal;
// Put terminal voltages in an array
var
i: Integer;
vterm: PDouble;
nref: PInteger;
nv0, nv: PDouble;
begin
with ActiveCircuit.solution do
begin
vterm := PDouble(VTerminal);
nref := PInteger(NodeRef);
nv0 := PDouble(NodeV);
for i := 1 to Yorder do
VTerminal^[i] := NodeV^[NodeRef^[i]];
begin
nv := nv0 + 2 * nref^;
vterm^ := nv^;
(vterm + 1)^ := (nv + 1)^;
inc(vterm, 2);
inc(nref);
// VTerminal^[i] := NodeV^[NodeRef^[i]];
end;
end;
end;

procedure TDSSCktElement.ZeroITerminal; inline;
var
i: Integer;
it: PDouble;
begin
FillDWord(ITerminal^, Yorder * ((SizeOf(Double) * 2) div 4), 0);
// Somehow this is slower?! FillDWord(ITerminal^, Yorder * ((SizeOf(Double) * 2) div 4), 0);
it := PDouble(Iterminal);
for i := 1 to Yorder do
begin
it^ := 0;
(it + 1)^ := 0;
inc(it, 2);
end;
//for i := 1 to Yorder do
// ITerminal[i] := CZERO;
end;

procedure TDSSCktElement.MakeLike(OtherObj: Pointer);
4 changes: 2 additions & 2 deletions src/PCElements/Load.pas
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ TLoadObj = class(TPCElement)
procedure DoZIPVModel;
procedure DoMotorTypeLoad;
function GrowthFactor(Year: Integer): Double;
procedure StickCurrInTerminalArray(TermArray: pComplexArray; const Curr: Complex; i: Integer);
procedure StickCurrInTerminalArray(TermArray: pComplexArray; const Curr: Complex; i: Integer); inline;
function InterpolateY95_YLow(const Vmag: Double): Complex; inline;
function InterpolateY95I_YLow(const Vmag: Double): Complex; inline; // ***Added by Celso & Paulo
function Get_Unserved: Boolean;
@@ -1174,7 +1174,7 @@ procedure TLoadObj.CalcYPrim;
inherited CalcYPrim;
end;

procedure TLoadObj.StickCurrInTerminalArray(TermArray: pComplexArray; const Curr: Complex; i: Integer);
procedure TLoadObj.StickCurrInTerminalArray(TermArray: pComplexArray; const Curr: Complex; i: Integer); inline;
// Put the current into the proper location according to connection
var
j: Integer;
8 changes: 4 additions & 4 deletions src/Shared/DSSUcomplex.pas
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ polar = record
cZERO: Complex = (re: 0.0; im: 0.0);
cONE: Complex = (re: 1.0; im: 0.0);

function cmplx(const a, b: Double): complex;
function cabs(const a: complex): Double;
function cmplx(const a, b: Double): complex; inline;
function cabs(const a: complex): Double; inline;
Function cabs2(const a:complex):double; // best when you don't need sqrt -- TODO: rename?
function cang(const a: complex): Double;
function cdang(const a: complex): Double; // angle of complex number, degrees
@@ -40,13 +40,13 @@ function pclx(const magn, angle: Double): complex;

implementation

function CMPLX(const a, b: Double): complex;
function CMPLX(const a, b: Double): complex; inline;
begin
Result.RE := A;
Result.IM := B
end;

function Cabs(const a: complex): Double;
function Cabs(const a: complex): Double; inline;
begin
Result := SQRT(A.RE * A.RE + A.IM * A.IM)
end;
4 changes: 2 additions & 2 deletions src/Shared/Ucmatrix.pas
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ TcMatrix = class(TObject)
procedure AddElemsym(i, j: Integer; Value: Complex);
function GetElement(i, j: Integer): Complex;
function GetErrorCode: Integer;
procedure MVmult(b, x: pComplexArray); {inline;} {b = Ax}
procedure MVmult(b, x: pComplexArray); inline; {b = Ax}
function GetValuesArrayPtr(var Order: Integer): pComplexArray;
procedure ZeroRow(iRow: Integer);
procedure ZeroCol(iCol: Integer);
@@ -143,7 +143,7 @@ function TcMatrix.IsColRowZero(n: Integer): Boolean; // This only check for exac
end;
end;

procedure TcMatrix.MvMult(b, x: pComplexArray); {inline;}
procedure TcMatrix.MvMult(b, x: pComplexArray); inline;
{$IFDEF DSS_CAPI_MVMULT}
begin
KLUSolve.mvmult(Norder, b, values, x);