powerflow/triplexline_test.h

00001 #ifndef _TRIPLEXLINE_TEST_H
00002 #define _TRIPLEXLINE_TEST_H
00003 
00004 #include "line.h"
00005 
00006 #ifndef _NO_CPPUNIT
00007 
00012 class triplex_line_tests : public test_helper
00013 {
00014     
00015     
00016 public:
00017     triplex_line_tests(){}
00022     void setUp(){
00023     }
00024 
00025     void tearDown(){
00026         local_callbacks->remove_objects();
00027     }
00028 
00038     /*void test_create(){
00039         CLASS *cl = get_class_by_name("sample");
00040         CPPUNIT_ASSERT(cl != NULL);
00041         obj = gl_create_object(cl,sizeof(sample_obj)); // Sample_obj is the name of the cpp class or struct.
00042         CPPUNIT_ASSERT(obj != NULL);
00043         
00044     }*/
00045 
00054     void test_triplex_line(){
00055         OBJECT *node1,*node2; // Triplex Node objects
00056         OBJECT *tpl1; // Triplex line object
00057         // Test values
00058         complex* node1_phA_I_test = new complex(159.91,-79.788);
00059         complex* node1_phB_I_test = new complex(-199.4,106.36);
00060         complex* node1_phC_I_test = new complex(39.494,-26.569);
00061 
00062         complex* node2_phA_V_test = new complex(115.44,-.26192);
00063         complex* node2_phB_V_test = new complex(122.45,-2.542);
00064         complex* node2_phC_V_test = new complex(0,0);
00065 
00066         CLASS *cl = get_class_by_name("triplex_node");
00067         node1 = gl_create_object(cl,sizeof(triplex_node));
00068         OBJECTDATA(node1,triplex_node)->create();
00069         cl = get_class_by_name("triplex_node");
00070         node2 = gl_create_object(cl,sizeof(triplex_node));
00071         OBJECTDATA(node2,triplex_node)->create();
00072         cl = get_class_by_name("triplex_line");
00073         tpl1 = gl_create_object(cl,sizeof(triplex_line));
00074         OBJECTDATA(tpl1,triplex_line)->create();
00075 
00076         OBJECTDATA(tpl1,triplex_line)->from = node1;
00077         OBJECTDATA(tpl1,triplex_line)->to = node2;
00078         OBJECTDATA(tpl1,triplex_line)->length = 100;
00079 
00080         // Next we set up the parameters needed for the test
00081         OBJECTDATA(tpl1,triplex_line)->phases = PHASE_ABCN;
00082         OBJECTDATA(node1,triplex_node)->phases = PHASE_ABCN;
00083         OBJECTDATA(node2,triplex_node)->phases = PHASE_ABCN;
00084         OBJECTDATA(node1,triplex_node)->phaseA_V = OBJECTDATA(node2,triplex_node)->phaseA_V = complex(115.44,-0.26192);
00085         OBJECTDATA(node2,triplex_node)->phaseA_I = complex(159.91,-79.788);
00086         OBJECTDATA(node1,triplex_node)->phaseB_V = OBJECTDATA(node2,triplex_node)->phaseB_V = complex(122.45,-2.5421);
00087         OBJECTDATA(node2,triplex_node)->phaseB_I = complex(-199.4,106.36);
00088         OBJECTDATA(node1,triplex_node)->phaseC_V = OBJECTDATA(node2,triplex_node)->phaseC_V = complex(0,0);
00089         OBJECTDATA(node2,triplex_node)->phaseC_I = complex(39.494,-26.569);
00090         
00091         cl = get_class_by_name("triplex_line_conductor");
00092         OBJECT *olc_a = gl_create_object(cl,sizeof(triplex_line_conductor)); // L1 conductor
00093         OBJECTDATA(olc_a,triplex_line_conductor)->geometric_mean_radius = 0.0111;
00094         OBJECTDATA(olc_a,triplex_line_conductor)->resistance = 0.97;
00095 
00096         OBJECT *olc_b = gl_create_object(cl,sizeof(triplex_line_conductor)); // L2 conductor
00097         OBJECTDATA(olc_b,triplex_line_conductor)->geometric_mean_radius = 0.0111;
00098         OBJECTDATA(olc_b,triplex_line_conductor)->resistance = 0.97;
00099 
00100         OBJECT *olc_c = gl_create_object(cl,sizeof(triplex_line_conductor)); // LN conductor
00101         OBJECTDATA(olc_c,triplex_line_conductor)->geometric_mean_radius = 0.0111;
00102         OBJECTDATA(olc_c,triplex_line_conductor)->resistance = 0.97;
00103 
00104         // Do I need to set up the other conductors and set them to INF?
00105         cl = get_class_by_name("triplex_line_configuration");
00106         OBJECT *line_config = gl_create_object(cl,sizeof(triplex_line_configuration));
00107         triplex_line_configuration *lc = OBJECTDATA(line_config,triplex_line_configuration);
00108         //lc->line_spacing = ls;
00109         lc->phaseA_conductor = olc_a;
00110         lc->phaseB_conductor = olc_b;
00111         lc->phaseC_conductor = olc_c;
00112         lc->phaseN_conductor = NULL;
00113         lc->ins_thickness = 0.08; // replace with test value
00114         lc->diameter = 0.368; // replace with test value
00115         
00116         OBJECTDATA(tpl1,triplex_line)->configuration = line_config;
00117         
00118         // Now we call init on the objects
00119         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00120 
00121         // Rank?
00122         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00123 
00124         // Run the test
00125         local_callbacks->sync_all(PC_PRETOPDOWN);
00126         local_callbacks->sync_all(PC_BOTTOMUP);
00127 
00128         // Check the bottom-up pass values
00129         double rI_1 = OBJECTDATA(node1,triplex_node)->get_phaseA_I_in().Re(); // Real part of the current at node 1
00130         double iI_1 = OBJECTDATA(node1,triplex_node)->get_phaseA_I_in().Im(); // Imaginary part of the current at node 1
00131 
00132         // Get the percentage of the difference between the calculated value and the test value
00133         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);
00134         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);
00135 
00136         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00137         CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00138 
00139         
00140         OBJECTDATA(node1,triplex_node)->phaseA_V = -1024.9;
00141         OBJECTDATA(node1,triplex_node)->phaseA_V.SetImag(2108.2);
00142         local_callbacks->sync_all(PC_POSTTOPDOWN);
00143         // check the top down values
00144 
00145         double rV_2 = OBJECTDATA(node2,triplex_node)->phaseA_V.Re();
00146         double iV_2 = OBJECTDATA(node2,triplex_node)->phaseA_V.Im();
00147 
00148         validate_re = 1 - (rV_2 <= node2_phA_V_test->Re() ? rV_2 / node2_phA_V_test->Re() : node2_phA_V_test->Re() /rV_2);
00149         validate_im = 1 - (iV_2 <= node2_phA_V_test->Im() ? iV_2 / node2_phA_V_test->Im() : node2_phA_V_test->Im() /iV_2);
00150         CPPUNIT_ASSERT(validate_re < VALIDATE_THRESHOLD);
00151         CPPUNIT_ASSERT(validate_im < VALIDATE_THRESHOLD);
00152 
00153     }
00154 
00155     /*
00156      * This section creates the suite() method that will be used by the
00157      * CPPUnit testrunner to execute the tests that we have registered.
00158      * This section needs to be in the .h file
00159      */
00160     CPPUNIT_TEST_SUITE(triplex_line_tests);
00161     /*
00162      * For each test method defined above, we should have a separate
00163      * CPPUNIT_TEST() line.
00164      */
00165     CPPUNIT_TEST(test_triplex_line);
00166     CPPUNIT_TEST_SUITE_END();
00167 
00168     
00169 };
00170 
00171 #endif
00172 #endif

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