powerflow/regulator_test.h

00001 #ifndef _REGULATOR_TEST_H
00002 #define _REGULATOR_TEST_H
00003 
00004 #include <stdlib.h>
00005 #include "node.h"
00006 #include "regulator.h"
00007 
00008 #ifndef _NO_CPPUNIT
00009 
00010 #ifdef VALIDATE_THRESHOLD
00011 #undef VALIDATE_THRESHOLD
00012 #endif
00013 #define VALIDATE_THRESHOLD .0004
00014 
00015 
00029 class regulator_tests : public test_helper 
00030 {   
00031 
00032     void test_three_single_phase_wye_regulator() {
00033         OBJECT *src_obj, *load_obj; // Node objects
00034         OBJECT *reg_obj, *config_obj; // Regulator objects
00035         node *src_node;
00036         load *load_node;
00037         regulator *reg;
00038         regulator_configuration *reg_config;
00039 
00040         // Calculated results
00041         complex node1_phA_I_test(242.49, -88.26);
00042         complex node1_phB_I_test(-214.54, -156.86);
00043         complex node1_phC_I_test(21.47, 307.05);
00044         
00045         complex node2_phA_V_test(7384.6, 0.0);
00046         complex node2_phB_V_test(-3716.1, -6436.5);
00047         complex node2_phC_V_test(-3814.6, 6607.0);
00048 
00049         // setup test objects
00050         CLASS *_class = get_class_by_name("node");
00051         src_obj = gl_create_object(_class, sizeof(node));
00052         src_node = OBJECTDATA(src_obj, node);
00053         src_node->create();
00054 
00055         src_node->phases = PHASE_ABCN;
00056         src_node->phaseA_V = complex(7200.0, 0.0);
00057         src_node->phaseB_V = complex(-3600.0, -6235.4);
00058         src_node->phaseC_V = complex(-3600.0, 6235.4);
00059 
00060         _class = get_class_by_name("load");
00061         load_obj = gl_create_object(_class, sizeof(load));
00062         load_node = OBJECTDATA(load_obj, load);
00063         load_node->create();
00064 
00065         load_node->phases = PHASE_ABCN;
00066         load_node->phaseA_V = complex(7384.6, 0.0);
00067         load_node->phaseB_V = complex(-3716.1, -6436.6);
00068         load_node->phaseC_V = complex(-3789.0, 6562.7);
00069         load_node->phaseA_I = complex(236.43, -86.05);
00070         load_node->phaseB_I = complex(-233.99, -151.95);
00071         load_node->phaseC_I = complex(21.47, 307.05);
00072 
00073         _class = get_class_by_name("regulator_configuration");
00074         config_obj = gl_create_object(_class, sizeof(regulator_configuration));
00075         reg_config = OBJECTDATA(config_obj, regulator_configuration);
00076         reg_config->create();
00077 
00078         reg_config->connect_type = 1;
00079         reg_config->band_center = 120.0;
00080         reg_config->band_width = 2.0;
00081         reg_config->time_delay = 30.0;
00082         reg_config->raise_taps = 16;
00083         reg_config->lower_taps = 16;
00084         reg_config->CT_ratio = 600;
00085         reg_config->PT_ratio = 60;
00086         reg_config->ldc_R_V = 6.0;
00087         reg_config->ldc_X_V = 12.0;
00088         reg_config->CT_phase = PHASE_ABC;
00089         reg_config->PT_phase = PHASE_ABC;
00090         reg_config->regulation = 0.10;
00091         reg_config->V_high = 120.0;
00092         reg_config->tap_pos[0] = 4;
00093         reg_config->tap_pos[1] = 5;
00094         reg_config->tap_pos[2] = 9;
00095 
00096         _class = get_class_by_name("regulator");
00097         reg_obj = gl_create_object(_class, sizeof(regulator));
00098         reg = OBJECTDATA(reg_obj, regulator);
00099         reg->create();
00100 
00101         reg->phases = PHASE_ABCN;
00102         reg->configuration = config_obj;
00103         reg->from = src_obj;
00104         reg->to = load_obj;
00105 
00106         // Now we call init on the objects
00107         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00108 
00109         // Rank?
00110         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00111 
00112         // Run the test
00113         local_callbacks->sync_all(PC_PRETOPDOWN);
00114         local_callbacks->sync_all(PC_BOTTOMUP);
00115 
00116         double rI_1 = src_node->get_phaseA_I_in().Re(); // Real part of the current at node 1
00117         double iI_1 = src_node->get_phaseA_I_in().Im(); // Imaginary part of the current at node 1
00118 
00119         // Get the percentage of the difference between the calculated value and the test value
00120         double validate_re = 1 - (rI_1 <= node1_phA_I_test.Re() ? rI_1 / node1_phA_I_test.Re() : node1_phA_I_test.Re() /rI_1);
00121         double validate_im = 1 - (iI_1 <= node1_phA_I_test.Im() ? iI_1 / node1_phA_I_test.Im() : node1_phA_I_test.Im() /iI_1);
00122 
00123         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00124         CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00125 
00126         src_node->phaseA_V = complex(7200.0, 0.0);
00127         src_node->phaseB_V = complex(-3600.0, -6235.4);
00128         src_node->phaseC_V = complex(-3600.0, 6235.4);
00129 
00130         local_callbacks->sync_all(PC_POSTTOPDOWN);
00131         // check the top down values
00132 
00133         double rV_2 = load_node->phaseA_V.Re();
00134         double iV_2 = load_node->phaseA_V.Im();
00135 
00136         validate_re = 1 - (rV_2 <= node2_phA_V_test.Re() ? (node2_phA_V_test.Re() != 0 ? rV_2 / node2_phA_V_test.Re():rV_2) : (rV_2 != 0 ? node2_phA_V_test.Re() /rV_2 : node2_phA_V_test.Re()));
00137         validate_im = 1 - (iV_2 <= node2_phA_V_test.Im() ? (node2_phA_V_test.Im() != 0 ? iV_2 / node2_phA_V_test.Im():iV_2) : (iV_2 != 0 ? node2_phA_V_test.Im() /iV_2 : node2_phA_V_test.Im()));
00138         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00139 //      CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00140 
00141         rV_2 = load_node->phaseB_V.Re();
00142         iV_2 = load_node->phaseB_V.Im();
00143 
00144         validate_re = 1 - (rV_2 <= node2_phB_V_test.Re() ? rV_2 / node2_phB_V_test.Re() : node2_phB_V_test.Re() /rV_2);
00145         validate_im = 1 - (iV_2 <= node2_phB_V_test.Im() ? iV_2 / node2_phB_V_test.Im() : node2_phB_V_test.Im() /iV_2);
00146         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00147         CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00148 
00149         rV_2 = load_node->phaseC_V.Re();
00150         iV_2 = load_node->phaseC_V.Im();
00151 
00152         validate_re = 1 - (rV_2 <= node2_phC_V_test.Re() ? rV_2 / node2_phC_V_test.Re() : node2_phC_V_test.Re() /rV_2);
00153         validate_im = 1 - (iV_2 <= node2_phC_V_test.Im() ? iV_2 / node2_phC_V_test.Im() : node2_phC_V_test.Im() /iV_2);
00154         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00155         CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00156     }
00157 
00158     void test_two_single_phase_open_delta_ABBC_regulator() {
00159         OBJECT *src_obj, *load_obj; // Node objects
00160         OBJECT *reg_obj, *config_obj; // Regulator objects
00161         node *src_node;
00162         load *load_node;
00163         regulator *reg;
00164         regulator_configuration *reg_config;
00165 
00166         // Calculated results
00167         complex node1_phA_I_test(163.32, -261.37);
00168         complex node1_phB_I_test(-263.44, -18.249);
00169         complex node1_phC_I_test(100.12, 279.62);
00170         
00171         complex node2_phA_V_test(6505.6, -3692.1);
00172         complex node2_phB_V_test(-6450.2, -3692.1);
00173         complex node2_phC_V_test(-55.367,  7384.2);
00174 
00175         // setup test objects
00176         CLASS *_class = get_class_by_name("node");
00177         src_obj = gl_create_object(_class, sizeof(node));
00178         src_node = OBJECTDATA(src_obj, node);
00179         src_node->create();
00180 
00181         src_node->phases = PHASE_ABC;
00182         src_node->phaseA_V = complex(6505.6, -3692.1);
00183         src_node->phaseB_V = complex(-6450.2, -3692.1);
00184         src_node->phaseC_V = complex(-55.367, 7384.2);
00185 
00186         _class = get_class_by_name("load");
00187         load_obj = gl_create_object(_class, sizeof(load));
00188         load_node = OBJECTDATA(load_obj, load);
00189         load_node->create();
00190 
00191         load_node->phases = PHASE_ABC;
00192         load_node->phaseA_V = complex(6505.6, -3692.1);
00193         load_node->phaseB_V = complex(-6450.2, -3692.1);
00194         load_node->phaseC_V = complex(-55.367, 7384.2);
00195         load_node->phaseA_I = complex(157.17, -251.53);
00196         load_node->phaseB_I = complex(-254.81, -21.059);
00197         load_node->phaseC_I = complex(97.614, 272.63);
00198 
00199         _class = get_class_by_name("regulator_configuration");
00200         config_obj = gl_create_object(_class, sizeof(regulator_configuration));
00201         reg_config = OBJECTDATA(config_obj, regulator_configuration);
00202         reg_config->create();
00203 
00204         reg_config->connect_type = 2;
00205         reg_config->band_center = 120.0;
00206         reg_config->band_width = 2.0;
00207         reg_config->time_delay = 30.0;
00208         reg_config->raise_taps = 16;
00209         reg_config->lower_taps = 16;
00210         reg_config->CT_ratio = 500;
00211         reg_config->PT_ratio = (int)103.92;
00212         reg_config->ldc_R_V = 0.8;
00213         reg_config->ldc_X_V = 9.9;
00214         reg_config->CT_phase = PHASE_ABC;
00215         reg_config->PT_phase = PHASE_ABC;
00216         reg_config->regulation = 0.10;
00217         reg_config->V_high = 120.0;
00218         reg_config->tap_pos[0] = 6;
00219         reg_config->tap_pos[1] = 4;
00220         reg_config->tap_pos[2] = 0;
00221 
00222         _class = get_class_by_name("regulator");
00223         reg_obj = gl_create_object(_class, sizeof(regulator));
00224         reg = OBJECTDATA(reg_obj, regulator);
00225         reg->create();
00226 
00227         reg->phases = PHASE_ABC;
00228         reg->configuration = config_obj;
00229         reg->from = src_obj;
00230         reg->to = load_obj;
00231 
00232         // Now we call init on the objects
00233         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00234 
00235         // Rank?
00236         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00237 
00238         // Run the test
00239         local_callbacks->sync_all(PC_PRETOPDOWN);
00240         local_callbacks->sync_all(PC_BOTTOMUP);
00241 
00242         double rI_1 = src_node->get_phaseA_I_in().Re(); // Real part of the current at node 1
00243         double iI_1 = src_node->get_phaseA_I_in().Im(); // Imaginary part of the current at node 1
00244 
00245         // Get the percentage of the difference between the calculated value and the test value
00246         double validate_re = 1 - (rI_1 <= node1_phA_I_test.Re() ? rI_1 / node1_phA_I_test.Re() : node1_phA_I_test.Re() /rI_1);
00247         double validate_im = 1 - (iI_1 <= node1_phA_I_test.Im() ? iI_1 / node1_phA_I_test.Im() : node1_phA_I_test.Im() /iI_1);
00248 
00249         CPPUNIT_ASSERT(fabs(validate_re) < VALIDATE_THRESHOLD);
00250         CPPUNIT_ASSERT(fabs(validate_im) < VALIDATE_THRESHOLD);
00251 
00252         src_node->phaseA_V = complex(6235,  -3599.8);
00253         src_node->phaseB_V = complex(-6235,   -3599.8);
00254         src_node->phaseC_V = complex(0,      7199.6);
00255 
00256         local_callbacks->sync_all(PC_POSTTOPDOWN);
00257         // check the top down values
00258 
00259         double rV_2 = load_node->phaseA_V.Re();
00260         double iV_2 = load_node->phaseA_V.Im();
00261 
00262         validate_re = 1 - (rV_2 <= node2_phA_V_test.Re() ? (node2_phA_V_test.Re() != 0 ? rV_2 / node2_phA_V_test.Re():rV_2) : (rV_2 != 0 ? node2_phA_V_test.Re() /rV_2 : node2_phA_V_test.Re()));
00263         validate_im = 1 - (iV_2 <= node2_phA_V_test.Im() ? (node2_phA_V_test.Im() != 0 ? iV_2 / node2_phA_V_test.Im():iV_2) : (iV_2 != 0 ? node2_phA_V_test.Im() /iV_2 : node2_phA_V_test.Im()));
00264         CPPUNIT_ASSERT(fabs(validate_re) < VALIDATE_THRESHOLD);
00265 //      CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00266 
00267         rV_2 = load_node->phaseB_V.Re();
00268         iV_2 = load_node->phaseB_V.Im();
00269 
00270         validate_re = 1 - (rV_2 <= node2_phB_V_test.Re() ? rV_2 / node2_phB_V_test.Re() : node2_phB_V_test.Re() /rV_2);
00271         validate_im = 1 - (iV_2 <= node2_phB_V_test.Im() ? iV_2 / node2_phB_V_test.Im() : node2_phB_V_test.Im() /iV_2);
00272         CPPUNIT_ASSERT(fabs(validate_re) < VALIDATE_THRESHOLD);
00273         CPPUNIT_ASSERT(fabs(validate_im) < VALIDATE_THRESHOLD);
00274 
00275         rV_2 = load_node->phaseC_V.Re();
00276         iV_2 = load_node->phaseC_V.Im();
00277 
00278         validate_re = 1 - (rV_2 <= node2_phC_V_test.Re() ? rV_2 / node2_phC_V_test.Re() : node2_phC_V_test.Re() /rV_2);
00279         validate_im = 1 - (iV_2 <= node2_phC_V_test.Im() ? iV_2 / node2_phC_V_test.Im() : node2_phC_V_test.Im() /iV_2);
00280         CPPUNIT_ASSERT(fabs(validate_re) < VALIDATE_THRESHOLD);
00281         CPPUNIT_ASSERT(fabs(validate_im) < VALIDATE_THRESHOLD);
00282     }
00283 
00284     void test_two_single_phase_open_delta_ABAC_regulator() {
00285         // No Unit Test values given
00286     }
00287 
00288     void test_two_single_phase_open_delta_ACBC_regulator() {
00289         // No Unit Test values given
00290     }
00291       
00292     /*
00293      * This section creates the suite() method that will be used by the
00294      * CPPUnit testrunner to execute the tests that we have registered.
00295      * This section needs to be in the .h file
00296      */
00297     CPPUNIT_TEST_SUITE(regulator_tests);
00298 
00299     /*
00300      * For each test method defined above, we should have a separate
00301      * CPPUNIT_TEST() line.
00302      */
00303     //CPPUNIT_TEST();
00304     CPPUNIT_TEST(test_three_single_phase_wye_regulator);
00305     CPPUNIT_TEST(test_two_single_phase_open_delta_ABBC_regulator);
00306     CPPUNIT_TEST_SUITE_END();
00307 };
00308 
00309 #endif
00310 #endif  /* _REGULATOR_TEST_H */
00311 

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy