Skip to content

Commit

Permalink
Working on test_4sbase test harness case. Added code that sets the nu…
Browse files Browse the repository at this point in the history
…mber 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.
  • Loading branch information
garydblack committed Dec 6, 2020
1 parent 20ac981 commit d230104
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions state-estimator/include/SELoopWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ using json = nlohmann::json;
#endif
#endif

#ifdef TEST_HARNESS_DIR
// macro to set precision of value to a fixed number of decimal digits
#define SET_PRECISION(val) round(val*1e+12)/1e+12
//#define SET_PRECISION(val) round(val*1e+6)/1e+6

double SET_SIGNIFICANT(double value, uint digits) {
if (value == 0.0)
return 0.0;

double factor = pow(10.0, digits - ceil(log10(fabs(value))));
return round(value*factor)/factor;
}
#endif

// This class listens for system state messages
class SELoopWorker {
Expand Down Expand Up @@ -1538,6 +1549,9 @@ class SELoopWorker {
#else
double *rhs = (double *)calloc(zqty*zqty, sizeof(double));
#endif
#ifdef TEST_HARNESS_DIR
double condnum;
#endif

try {
// Initialize klusolve variables
Expand Down Expand Up @@ -1570,6 +1584,10 @@ class SELoopWorker {
// KLU condition number estimation
(void)klu_condest(Supd->p,Supd->x,klusym,klunum,&klucom);
*selog << "klu_condest Supd condition number estimate: " << klucom.condest << "\n" << std::flush;
#ifdef TEST_HARNESS_DIR
condnum = klucom.condest;
*selog << timestamp << "," << condnum << ",SupdCondNum\n" << std::flush;
#endif
#endif

// initialize an identity right-hand side
Expand Down Expand Up @@ -1636,6 +1654,15 @@ class SELoopWorker {
free(rhs);
#endif

#ifdef TEST_HARNESS_DIR
// determine number of significant digits based on condition number
uint digits = 15 - floor(log10(condnum));
// set all elements of Supd^-1 to the desired number of significant
// figures for MATLAB comparison
for (uint i=0; i<K3->nzmax; i++)
K3->x[i] = SET_SIGNIFICANT(K3->x[i], digits);
#endif

#ifdef DEBUG_PRIMARY
if ( K3 ) *selog << "K3 is " << K3->m << " by " << K3->n <<
" with " << K3->nzmax << " entries\n" << std::flush;
Expand Down
1 change: 1 addition & 0 deletions state-estimator/src/state-estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//#define TEST_HARNESS_DIR "test_4"
//#define TEST_HARNESS_DIR "test_4vinj"
//#define TEST_HARNESS_DIR "test_4net"
//#define TEST_HARNESS_DIR "test_4sbase"
//#define TEST_HARNESS_DIR "test_13assets"
#ifdef TEST_HARNESS_DIR
// whether to get node_vnoms from file or hardwire to 1
Expand Down

0 comments on commit d230104

Please sign in to comment.