Skip to content

Commit d230104

Browse files
committed
Working on test_4sbase test harness case. Added code that sets the number of significant figures for the Supd inverse (K3) based on the magnitude of the condition number estimate. Also conditionalize the SET_PRECISION calls so they are only done for the test harness.
1 parent 20ac981 commit d230104

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

state-estimator/include/SELoopWorker.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,19 @@ using json = nlohmann::json;
6565
#endif
6666
#endif
6767

68+
#ifdef TEST_HARNESS_DIR
6869
// macro to set precision of value to a fixed number of decimal digits
6970
#define SET_PRECISION(val) round(val*1e+12)/1e+12
71+
//#define SET_PRECISION(val) round(val*1e+6)/1e+6
72+
73+
double SET_SIGNIFICANT(double value, uint digits) {
74+
if (value == 0.0)
75+
return 0.0;
76+
77+
double factor = pow(10.0, digits - ceil(log10(fabs(value))));
78+
return round(value*factor)/factor;
79+
}
80+
#endif
7081

7182
// This class listens for system state messages
7283
class SELoopWorker {
@@ -1538,6 +1549,9 @@ class SELoopWorker {
15381549
#else
15391550
double *rhs = (double *)calloc(zqty*zqty, sizeof(double));
15401551
#endif
1552+
#ifdef TEST_HARNESS_DIR
1553+
double condnum;
1554+
#endif
15411555

15421556
try {
15431557
// Initialize klusolve variables
@@ -1570,6 +1584,10 @@ class SELoopWorker {
15701584
// KLU condition number estimation
15711585
(void)klu_condest(Supd->p,Supd->x,klusym,klunum,&klucom);
15721586
*selog << "klu_condest Supd condition number estimate: " << klucom.condest << "\n" << std::flush;
1587+
#ifdef TEST_HARNESS_DIR
1588+
condnum = klucom.condest;
1589+
*selog << timestamp << "," << condnum << ",SupdCondNum\n" << std::flush;
1590+
#endif
15731591
#endif
15741592

15751593
// initialize an identity right-hand side
@@ -1636,6 +1654,15 @@ class SELoopWorker {
16361654
free(rhs);
16371655
#endif
16381656

1657+
#ifdef TEST_HARNESS_DIR
1658+
// determine number of significant digits based on condition number
1659+
uint digits = 15 - floor(log10(condnum));
1660+
// set all elements of Supd^-1 to the desired number of significant
1661+
// figures for MATLAB comparison
1662+
for (uint i=0; i<K3->nzmax; i++)
1663+
K3->x[i] = SET_SIGNIFICANT(K3->x[i], digits);
1664+
#endif
1665+
16391666
#ifdef DEBUG_PRIMARY
16401667
if ( K3 ) *selog << "K3 is " << K3->m << " by " << K3->n <<
16411668
" with " << K3->nzmax << " entries\n" << std::flush;

state-estimator/src/state-estimator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//#define TEST_HARNESS_DIR "test_4"
1818
//#define TEST_HARNESS_DIR "test_4vinj"
1919
//#define TEST_HARNESS_DIR "test_4net"
20+
//#define TEST_HARNESS_DIR "test_4sbase"
2021
//#define TEST_HARNESS_DIR "test_13assets"
2122
#ifdef TEST_HARNESS_DIR
2223
// whether to get node_vnoms from file or hardwire to 1

0 commit comments

Comments
 (0)