From d00d226f9c9e15481e325019b0dc468517c65284 Mon Sep 17 00:00:00 2001 From: Reid Gomillion Date: Wed, 8 May 2024 12:21:59 -0400 Subject: [PATCH 1/7] Added Scalable Microgrid Example - Added example of scalable microgrid with arbitrary size --- CMakeLists.txt | 3 + Examples/CMakeLists.txt | 1 + Examples/Scale_Microgrid/CMakeLists.txt | 13 + Examples/Scale_Microgrid/Scale_Microgrid.cpp | 317 +++++++++++++++++++ Examples/Scale_Microgrid/microgrid_N2.txt | 70 ++++ Examples/Scale_Microgrid/microgrid_N4.txt | 142 +++++++++ Examples/Scale_Microgrid/microgrid_N8.txt | 286 +++++++++++++++++ 7 files changed, 832 insertions(+) create mode 100644 Examples/Scale_Microgrid/CMakeLists.txt create mode 100644 Examples/Scale_Microgrid/Scale_Microgrid.cpp create mode 100644 Examples/Scale_Microgrid/microgrid_N2.txt create mode 100644 Examples/Scale_Microgrid/microgrid_N4.txt create mode 100644 Examples/Scale_Microgrid/microgrid_N8.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index badea53a8..1659d61d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,9 @@ set(CMAKE_MACOSX_RPATH 1) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake) +# Add source directory to macros for file access +add_compile_definitions("SOURCE_ROOT=${CMAKE_SOURCE_DIR}") + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath # use, i.e. don't skip the full RPATH for the build tree set(CMAKE_SKIP_BUILD_RPATH FALSE) diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 0965f5688..f23dfdc1b 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -58,6 +58,7 @@ add_subdirectory(MatPowerTesting) add_subdirectory(RLCircuit) add_subdirectory(Microgrid) +add_subdirectory(Scale_Microgrid) add_subdirectory(SparseTest) add_subdirectory(DistributedGeneratorTest) diff --git a/Examples/Scale_Microgrid/CMakeLists.txt b/Examples/Scale_Microgrid/CMakeLists.txt new file mode 100644 index 000000000..8ffc91d81 --- /dev/null +++ b/Examples/Scale_Microgrid/CMakeLists.txt @@ -0,0 +1,13 @@ + + + + +add_executable(scalemicrogrid Scale_Microgrid.cpp) +target_link_libraries(scalemicrogrid GRIDKIT::powerelec_disgen + GRIDKIT::powerelec_mircoline + GRIDKIT::powerelec_microload + GRIDKIT::solvers_dyn + GRIDKIT::powerelec_mircobusdq) + +add_test(NAME ScaleMicrogrid COMMAND $) +install(TARGETS scalemicrogrid RUNTIME DESTINATION bin) diff --git a/Examples/Scale_Microgrid/Scale_Microgrid.cpp b/Examples/Scale_Microgrid/Scale_Microgrid.cpp new file mode 100644 index 000000000..70d4148c9 --- /dev/null +++ b/Examples/Scale_Microgrid/Scale_Microgrid.cpp @@ -0,0 +1,317 @@ + + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include +#include +#include + +//macro to get macro +#define STRING(x) #x +#define XSTRING(x) STRING(x) + +int main(int argc, char const *argv[]) +{ + double abstol = 1.0e-8; + double reltol = 1.0e-8; + size_t max_step_amount = 3000; + bool usejac = true; + + //TODO:setup as named parameters + //Create circuit model + ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_amount); + + + //The amount of DG line load cobinations to generate for scale + size_t Nsize = 8; + + //Set to false if the parameters choosen are not used to generate data files + bool orgparams = true; + + //Modeled after the problem in the paper + // Every Bus has the same virtual resistance. This is due to the numerical stability as mentioned in the paper. + double RN = 1.0e4; + + //DG Params Vector + //All DGs have the same set of parameters except for the first two. + ModelLib::DistributedGeneratorParameters DG_parms1; + DG_parms1.wb_ = 2.0*M_PI*50.0; + DG_parms1.wc_ = 31.41; + DG_parms1.mp_ = 9.4e-5; + DG_parms1.Vn_ = 380.0; + DG_parms1.nq_ = 1.3e-3; + DG_parms1.F_ = 0.75; + DG_parms1.Kiv_ = 420.0; + DG_parms1.Kpv_ = 0.1; + DG_parms1.Kic_ = 2.0e4; + DG_parms1.Kpc_ = 15.0; + DG_parms1.Cf_ = 5.0e-5; + DG_parms1.rLf_ = 0.1; + DG_parms1.Lf_ = 1.35e-3; + DG_parms1.rLc_ = 0.03; + DG_parms1.Lc_ = 0.35e-3; + + ModelLib::DistributedGeneratorParameters DG_parms2; + DG_parms2.wb_ = 2.0*M_PI*50.0; + DG_parms2.wc_ = 31.41; + DG_parms2.mp_ = 12.5e-5; + DG_parms2.Vn_ = 380.0; + DG_parms2.nq_ = 1.5e-3; + DG_parms2.F_ = 0.75; + DG_parms2.Kiv_ = 390.0; + DG_parms2.Kpv_ = 0.05; + DG_parms2.Kic_ = 16.0e3; + DG_parms2.Kpc_ = 10.5; + DG_parms2.Cf_ = 50.0e-6; + DG_parms2.rLf_ = 0.1; + DG_parms2.Lf_ = 1.35e-3; + DG_parms2.rLc_ = 0.03; + DG_parms2.Lc_ = 0.35e-3; + + std::vector> DGParams_list(2*Nsize, DG_parms2); + + DGParams_list[0] = DG_parms1; + DGParams_list[1] = DG_parms1; + + //line vector params + //Every odd line has the same parameters and every even line has the same parameters + double rline1 = 0.23; + double Lline1 = 0.1 / (2.0 * M_PI * 50.0); + double rline2 = 0.35; + double Lline2 = 0.58 / (2.0 * M_PI * 50.0); + std::vector rline_list(2*Nsize-1, 0.0); + std::vector Lline_list(2*Nsize-1, 0.0); + for (size_t i = 0; i < rline_list.size(); i++) + { + rline_list[i] = (i % 2) ? rline2 : rline1; + Lline_list[i] = (i % 2) ? Lline2 : Lline1; + } + + + //load parms + //Only the first load has the same paramaters. + double rload1 = 3.0; + double Lload1 = 2.0 / (2.0 * M_PI * 50.0); + double rload2 = 2.0; + double Lload2 = 1.0 / (2.0 * M_PI * 50.0); + + std::vector rload_list(Nsize, rload2); + std::vector Lload_list(Nsize, Lload2); + rload_list[0] = rload1; + Lload_list[0] = Lload1; + + // DGs + - refframe Lines + Loads + size_t vec_size_internals = 13*(2*Nsize) - 1 + (2 + 4*(Nsize - 1)) + 2*Nsize; + // \omegaref + BusDQ + size_t vec_size_externals = 1 + 2*(2*Nsize); + + std::vector vdqbus_index(2*Nsize,0); + vdqbus_index[0] = vec_size_internals + 1; + for (size_t i = 1; i < vdqbus_index.size(); i++) + { + vdqbus_index[i] = vdqbus_index[i-1] + 2; + } + + //Total size of the vector setup + size_t vec_size_total = vec_size_internals + vec_size_externals; + + + //Create the reference DG + ModelLib::DistributedGenerator *dg_ref = new ModelLib::DistributedGenerator(0, DGParams_list[0], true); + //ref motor + dg_ref->setExternalConnectionNodes(0,vec_size_internals); + //outputs + dg_ref->setExternalConnectionNodes(1,vdqbus_index[0]); + dg_ref->setExternalConnectionNodes(2,vdqbus_index[0] + 1); + //"grounding" of the difference + dg_ref->setExternalConnectionNodes(3,-1); + //internal connections + for (size_t i = 0; i < 12; i++) + { + + dg_ref->setExternalConnectionNodes(4 + i,i); + } + sysmodel->addComponent(dg_ref); + + //Keep track of models and index location + size_t indexv = 12; + size_t model_id = 1; + //Add all other DGs + for (size_t i = 1; i < 2*Nsize; i++) + { + + //current DG to add + ModelLib::DistributedGenerator *dg = new ModelLib::DistributedGenerator(model_id++, DGParams_list[i], false); + //ref motor + dg->setExternalConnectionNodes(0,vec_size_internals); + //outputs + dg->setExternalConnectionNodes(1,vdqbus_index[i]); + dg->setExternalConnectionNodes(2,vdqbus_index[i] + 1); + //internal connections + for (size_t j = 0; j < 13; j++) + { + + dg->setExternalConnectionNodes(3 + j,indexv + j); + } + indexv += 13; + sysmodel->addComponent(dg); + } + + // Load all the Line compoenents + for (size_t i = 0; i < 2*Nsize - 1; i++) + { + //line + ModelLib::MicrogridLine *line_model = new ModelLib::MicrogridLine(model_id++, rline_list[i], Lline_list[i]); + //ref motor + line_model->setExternalConnectionNodes(0,vec_size_internals); + //input connections + line_model->setExternalConnectionNodes(1,vdqbus_index[i]); + line_model->setExternalConnectionNodes(2,vdqbus_index[i] + 1); + //output connections + line_model->setExternalConnectionNodes(3,vdqbus_index[i+1]); + line_model->setExternalConnectionNodes(4,vdqbus_index[i+1] + 1); + //internal connections + for (size_t j = 0; j < 2; j++) + { + line_model->setExternalConnectionNodes(5 + j,indexv + j); + } + indexv += 2; + sysmodel->addComponent(line_model); + } + + // Load all the Load components + for (size_t i = 0; i < Nsize; i++) + { + ModelLib::MicrogridLoad *load_model = new ModelLib::MicrogridLoad(model_id++, rload_list[i], Lload_list[i]); + //ref motor + load_model->setExternalConnectionNodes(0,vec_size_internals); + //input connections + load_model->setExternalConnectionNodes(1,vdqbus_index[2*i]); + load_model->setExternalConnectionNodes(2,vdqbus_index[2*i] + 1); + //internal connections + for (size_t j = 0; j < 2; j++) + { + + load_model->setExternalConnectionNodes(3 + j,indexv + j); + } + indexv += 2; + sysmodel->addComponent(load_model); + } + + //Add all the microgrid Virtual DQ Buses + for (size_t i = 0; i < 2*Nsize; i++) + { + ModelLib::MicrogridBusDQ *virDQbus_model = new ModelLib::MicrogridBusDQ( + model_id++, RN); + + virDQbus_model->setExternalConnectionNodes(0, vdqbus_index[i]); + virDQbus_model->setExternalConnectionNodes(1, vdqbus_index[i] + 1); + sysmodel->addComponent(virDQbus_model); + } + + //allocate all the intial conditions + sysmodel->allocate(vec_size_total); + + std::cout << sysmodel->y().size() << std::endl; + std::cout << vec_size_internals << ", " << vec_size_externals << "\n"; + + //Create Intial points for states. Every state is to specified to the zero intially + for (size_t i = 0; i < vec_size_total; i++) + { + sysmodel->y()[i] = 0.0; + sysmodel->yp()[i] = 0.0; + } + + // Create Intial derivatives specifics generated in MATLAB + for (size_t i = 0; i < 2*Nsize; i++) + { + sysmodel->yp()[13*i - 1 + 3] = DGParams_list[i].Vn_; + sysmodel->yp()[13*i - 1 + 5] = DGParams_list[i].Kpv_ * DGParams_list[i].Vn_; + sysmodel->yp()[13*i - 1 + 7] = (DGParams_list[i].Kpc_ * DGParams_list[i].Kpv_ * DGParams_list[i].Vn_) / DGParams_list[i].Lf_; + } + + //since the intial P_com = 0, the set the intial vector to the reference frame + sysmodel->y()[vec_size_internals] = DG_parms1.wb_; + + sysmodel->initialize(); + sysmodel->evaluateResidual(); + + std::vector& fres = sysmodel->getResidual(); + std::cout << "Verify Intial Resisdual is Zero: {\n"; + for (size_t i = 0; i < fres.size(); i++) + { + printf("%lu : %.16e \n", i, fres[i]); + } + std::cout << "}\n"; + + sysmodel->updateTime(0.0, 1.0e-8); + sysmodel->evaluateJacobian(); + std::cout << "Intial Jacobian with alpha:\n"; + + + //Create numerical integrator and configure it for the generator model + AnalysisManager::Sundials::Ida* idas = new AnalysisManager::Sundials::Ida(sysmodel); + + double t_init = 0.0; + double t_final = 1.0; + + // setup simulation + idas->configureSimulation(); + idas->getDefaultInitialCondition(); + idas->initializeSimulation(t_init); + + idas->runSimulation(t_final); + + std::vector& yfinial = sysmodel->y(); + + std::cout << "Final Vector y\n"; + for (size_t i = 0; i < yfinial.size(); i++) + { + printf("%lu: % 2.16e\n", i, yfinial[i]); + } + + //if proper MATLAB results are avalible and model is using origional parameters + std::vector compDataSizes = {2,4,8}; + //All data generated with abstol=1e-12 and reltol=1e-12 with ode23tb + if (orgparams && compDataSizes.end() != std::find(compDataSizes.begin(), compDataSizes.end(), Nsize)) + { + //get the cmake source dir from the cmake configuration + std::string base_path = XSTRING(SOURCE_ROOT); + + base_path += "/Examples/Scale_Microgrid/microgrid_N"; + base_path += std::to_string(Nsize); + base_path += ".txt"; + std::cout << base_path << std::endl; + + //load vector from data file + std::vector true_vec(vec_size_total, 0.0); + double val_cur = 0.0; + std::ifstream data_file(base_path); + size_t i = 0; + while (data_file >> val_cur && i < true_vec.size()) + { + true_vec[i++] = val_cur; + } + data_file.close(); + + //check relative error + std::cout << "Test the Relative Error\n"; + for (size_t i = 0; i < true_vec.size(); i++) + { + printf("%lu: % 2.16e\n", i, abs(true_vec[i] - yfinial[i]) / abs(true_vec[i])); + } + } + + + return 0; +} diff --git a/Examples/Scale_Microgrid/microgrid_N2.txt b/Examples/Scale_Microgrid/microgrid_N2.txt new file mode 100644 index 000000000..d0edf2a51 --- /dev/null +++ b/Examples/Scale_Microgrid/microgrid_N2.txt @@ -0,0 +1,70 @@ +22975.4182636905 +12753.1173017451 +0.0376305671131306 +-0.0209815421114537 +0.0184828563235406 +-0.00015632917065729 +63.2193617412383 +-29.4226556659582 +363.420924977355 +-3.01001804456668e-06 +63.2193618667302 +-35.0920143829141 +-0.00755583999797958 +22975.8457840701 +8742.0172166684 +0.0371009878165673 +-0.0142112776774797 +0.0187407972932474 +-9.8913852531819e-05 +62.3296548917654 +-17.9650261562766 +368.635407345931 +3.79041261513032e-05 +62.3296560841534 +-23.7157298601546 +-0.0827401584095097 +17277.712521392 +16493.7578328327 +0.0311645357391787 +-0.0298601153771274 +0.0225001003469904 +-0.000264388302121386 +48.6166482764357 +-40.8862612232969 +355.25957014696 +-0.000167008045114112 +48.6166481095298 +-46.4283022775928 +-0.0844566209033113 +17277.2493364959 +9182.29479881977 +0.0302503981389185 +-0.0161722538457184 +0.023180586071601 +-0.000129590157483103 +47.1906392248137 +-19.3574255862892 +366.226354188735 +0.000121054462396047 +47.19063792117 +-25.0705499054599 +-18.8125403122072 +21.1471334522508 +43.2997340692497 +-3.03798323340816 +-44.8715356440453 +28.9585224749495 +81.99613295014 +-56.2385627562355 +132.749774614687 +-82.280664729262 +311.999576042192 +357.692287974629 +-5.85078929333349 +364.119335219897 +-8.84631033126304 +347.214535767435 +-32.7241067379802 +360.411028950125 +-34.9283280833745 diff --git a/Examples/Scale_Microgrid/microgrid_N4.txt b/Examples/Scale_Microgrid/microgrid_N4.txt new file mode 100644 index 000000000..29a0b71b8 --- /dev/null +++ b/Examples/Scale_Microgrid/microgrid_N4.txt @@ -0,0 +1,142 @@ +27828.3291148094 +10602.3611530864 +0.0452452394028709 +-0.0173410584955486 +0.018686818367312 +-0.000129595027000909 +76.0120809944985 +-23.2367034227098 +366.216582730654 +-0.000167782960864797 +76.0120710728117 +-28.9413214479885 +-0.0154989336357971 +27832.0772154743 +7838.80352597054 +0.0448129806183038 +-0.0127296381144373 +0.0188642014642206 +-9.04502393904097e-05 +75.2859236720964 +-15.4316980534341 +369.809174828127 +-5.17440472732025e-05 +75.285919083362 +-21.1922719962368 +-0.142596248886844 +20950.1519748442 +16334.3924580166 +0.0377787488551238 +-0.0295717781600636 +0.0225780601074885 +-0.000265567743682681 +58.9348270364006 +-40.4081583028089 +355.498460539903 +-8.66167274613643e-05 +58.9348242715342 +-45.9457664944992 +-0.164628885385433 +20956.2846481359 +12345.7855779785 +0.0371673110634281 +-0.0220171188824754 +0.0229486760225139 +-0.000191111142238558 +57.9810673844105 +-28.5265491599081 +361.481100853144 +8.24481547667206e-05 +57.9810719040216 +-34.1573355283559 +-0.245126576498858 +20978.9206932923 +17875.6825958711 +0.0380785081131898 +-0.0325621468970297 +0.0224354615928625 +-0.000295085318936756 +59.4025243779293 +-45.1101946009202 +353.186117339098 +5.52721744209165e-05 +59.4025238741703 +-50.6117204294148 +-0.253672269778405 +20990.6142554844 +11779.5685373245 +0.0371243965775962 +-0.0209716906203726 +0.0230016494389548 +-0.000180846578022512 +57.9140614794815 +-26.8817831662193 +362.331254349606 +0.000209247259473183 +57.9140782926947 +-32.5257339504705 +-0.288747285297145 +21004.5418902462 +16686.981801999 +0.0379131316203435 +-0.0302602142538338 +0.0225460339603269 +-0.000272422675391038 +59.1444740212228 +-41.4902940591195 +354.969993387113 +8.14114753778542e-05 +59.1444846638236 +-47.0195494892644 +-0.285876486857154 +21005.895228757 +8274.13913126834 +0.0366267978764156 +-0.0145584209340773 +0.0233276948336748 +-0.000117627382397687 +57.1378568500881 +-16.7923279871216 +367.58883605301 +0.000263351556352378 +57.1378679159653 +-22.518140603782 +-6.57009481597077 +28.1053117219546 +68.341829672125 +5.75010361666728 +-7.27398138223966 +42.3413009908014 +44.2901915856089 +-0.850144510998897 +-26.9214526328474 +37.7939474726438 +20.9421230166698 +-8.2155394685309 +-48.4341275019927 +37.706248875936 +82.5460878639016 +-57.0458911301263 +127.388509162578 +-90.4406093871607 +116.522583626035 +-102.149734009655 +112.650118587972 +-107.825883544914 +311.543402422187 +360.780248808368 +-7.42039816792328 +365.078323407317 +-13.2331839185884 +344.46378568747 +-54.5546252592288 +350.335287885457 +-63.572021962256 +334.342198258035 +-88.749585714325 +344.281369936645 +-94.7726681838823 +332.2248206198 +-103.942854393111 +347.103721199815 +-107.812479611979 diff --git a/Examples/Scale_Microgrid/microgrid_N8.txt b/Examples/Scale_Microgrid/microgrid_N8.txt new file mode 100644 index 000000000..3e1ba779b --- /dev/null +++ b/Examples/Scale_Microgrid/microgrid_N8.txt @@ -0,0 +1,286 @@ +29266.6517718661 +9842.93617289812 +0.0475360674334622 +-0.0160323945316821 +0.0187557247105805 +-0.000119821248231538 +79.8612117213119 +-21.0144010498971 +367.201497494684 +-0.00135963018489767 +79.8611351716573 +-26.7318789917162 +-0.018074876389402 +29296.9645459408 +7415.51099954903 +0.0471789367393934 +-0.0120180219897291 +0.0189117902285582 +-8.57914733703415e-05 +79.2614266664798 +-14.2194852461262 +370.357116139458 +-0.00065261697325357 +79.261388452934 +-19.9860446882469 +-0.161178046356866 +22178.7337755581 +15750.48869542 +0.0399575496599213 +-0.028431003000158 +0.0226540351215628 +-0.000255811047442045 +62.3338080750298 +-38.6061338491152 +356.372404460464 +-0.000888421043595241 +62.3337589017493 +-44.1546192236143 +-0.191206982234175 +22245.3587939821 +12476.0312983393 +0.0395296431152022 +-0.0222832972915751 +0.0229591349358969 +-0.000195357283522886 +61.6667253463805 +-28.9363062720176 +361.284131747149 +0.000606091049765824 +61.6667589580497 +-34.5611135316627 +-0.300475535038271 +22471.354929649 +17410.9400696732 +0.0407475331761201 +-0.0316496339533813 +0.0225047347006168 +-0.000287941144857336 +63.5662158978541 +-43.6654709736205 +353.882194971394 +-0.00050508442766251 +63.5661867600733 +-49.1745383652835 +-0.321406735230742 +22562.1063953332 +12532.040739496 +0.0400730650460856 +-0.0224103188019356 +0.0229590093469276 +-0.000197040279593967 +62.5145400797163 +-29.1337602252211 +361.200953962968 +0.00123813270414561 +62.5146115608051 +-34.7565572443792 +-0.398765881347133 +22822.9625175864 +17526.9123376124 +0.0413769691613727 +-0.0318846988884131 +0.0224996948233429 +-0.000290724959665147 +64.5480523645119 +-44.0326735095454 +353.709220392926 +-0.000255137918253834 +64.548036917491 +-49.5382706457328 +-0.409294621792759 +22917.4640781459 +11700.1980576741 +0.0405370737861658 +-0.0208717910251266 +0.0230419643488667 +-0.000182321342412399 +63.2383663569188 +-26.7111380754575 +362.449323338104 +0.00143605100750772 +63.2384503029344 +-32.3525635247183 +-0.460038982115987 +23175.0870418607 +17429.0372806116 +0.0419717095772374 +-0.0317010913432995 +0.0225145433123769 +-0.000289381352876061 +65.4757968347883 +-43.7415548084125 +353.856643943042 +-0.000116590766441278 +65.4757901489451 +-49.2486679790579 +-0.461848591689221 +23264.6732405303 +10919.0360806903 +0.0409947737541995 +-0.0194331296392293 +0.0231200668519233 +-0.000168575863901554 +63.9522672718067 +-24.4455560147541 +363.621937642842 +0.00154556746783549 +63.9523565934322 +-30.1044436917781 +-0.491529580804623 +23488.6137650364 +17313.8654584652 +0.0424952351974662 +-0.0314883547842804 +0.0225303364455447 +-0.000287714847080755 +66.2924442955506 +-43.4048501801219 +354.030311475628 +0.000169934086992562 +66.2924545883603 +-48.9139721676174 +-0.486548093474613 +23557.6136117665 +10241.0790360359 +0.0413774884672506 +-0.0181860120867723 +0.0231877453638413 +-0.000156639599075328 +64.5492156984859 +-22.4816084883194 +364.639179755733 +0.00142420279185394 +64.5492984953198 +-28.1556597465189 +-0.499726325044563 +23722.4168131373 +16958.7765974266 +0.0428487548646152 +-0.0308090857078185 +0.0225672437721518 +-0.000281355782039133 +66.8440182379463 +-42.3350991467661 +354.562942832682 +0.000573219240561573 +66.844044569212 +-47.8519918014414 +-0.490219448053285 +23769.8747006891 +9267.5206785042 +0.0415639300026818 +-0.0164109903099032 +0.0232814268213158 +-0.000139385907988285 +64.8399200066663 +-19.6874999818575 +366.100410278813 +0.00128332197988872 +64.8400012051758 +-25.3838027935624 +-0.491586583798841 +23854.0240861864 +15160.7060140903 +0.0427385845553072 +-0.0273659210853948 +0.0227360281885303 +-0.00024756822257102 +66.6722121992594 +-36.9193366680176 +357.260483774461 +0.000734666517031364 +66.6722602990682 +-42.4779079553274 +-0.482907936930927 +23870.5548740189 +6166.60742794455 +0.0412253604361869 +-0.0108406830677542 +0.0235710268609798 +-8.45378382385454e-05 +64.3117067426907 +-10.9219886629635 +370.751596332923 +0.00130490570318174 +64.3117765573399 +-16.6904284244068 +-2.9267653635869 +30.5878043390112 +75.9238910016987 +9.17392754248112 +4.3701560041079 +48.7765765968327 +58.3101300775815 +3.13323809951331 +-6.37573932293514 +46.1701408549949 +41.9244199648313 +-6.5432868117422 +-17.3691293511209 +41.8611610718482 +27.7383173553277 +-12.9709065074016 +-27.5322418670623 +38.9032728624808 +16.2733736528389 +-16.5280348065045 +-36.4800564569504 +37.0627808819117 +7.38198504755967 +-17.9899033675727 +-44.0731708800056 +36.9539474625741 +1.14781892918688 +-15.9507601441003 +-49.1751072411967 +44.6278268007059 +82.7517114852138 +-57.3188928805757 +125.959171148664 +-93.1822145893453 +110.816672146529 +-108.811406393296 +99.5107131550674 +-119.104827911048 +92.0427992280762 +-125.056967118294 +88.0811872722293 +-127.985464658329 +87.1649116220972 +-128.957730829954 +89.0189233593932 +-129.480383815729 +311.408200092424 +361.890500304156 +-7.90450151715305 +365.594288034004 +-14.6504114199963 +344.278948204657 +-61.517809887448 +348.104769580715 +-73.1715704285651 +329.472137794467 +-107.797643650827 +335.509251816504 +-117.787067889008 +317.044841017058 +-139.602945170765 +325.182412285621 +-147.51178633583 +307.989533967543 +-158.91998673915 +318.171184823086 +-165.141414351062 +302.951769665185 +-168.712626964975 +315.009688292198 +-173.624287308414 +302.070219389208 +-171.572667424371 +315.86470341008 +-175.706947618597 +306.288884765777 +-170.785573848562 +322.018589824395 +-176.179397251772 From 76d4e2cfffe2f5f0e553db6e3dd292fad39c96c3 Mon Sep 17 00:00:00 2001 From: Reid Date: Fri, 24 May 2024 14:55:38 -0400 Subject: [PATCH 2/7] Update Examples/Scale_Microgrid/CMakeLists.txt Co-authored-by: pelesh --- Examples/Scale_Microgrid/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/Scale_Microgrid/CMakeLists.txt b/Examples/Scale_Microgrid/CMakeLists.txt index 8ffc91d81..139eec959 100644 --- a/Examples/Scale_Microgrid/CMakeLists.txt +++ b/Examples/Scale_Microgrid/CMakeLists.txt @@ -4,10 +4,10 @@ add_executable(scalemicrogrid Scale_Microgrid.cpp) target_link_libraries(scalemicrogrid GRIDKIT::powerelec_disgen - GRIDKIT::powerelec_mircoline - GRIDKIT::powerelec_microload - GRIDKIT::solvers_dyn - GRIDKIT::powerelec_mircobusdq) + GRIDKIT::powerelec_mircoline + GRIDKIT::powerelec_microload + GRIDKIT::solvers_dyn + GRIDKIT::powerelec_mircobusdq) add_test(NAME ScaleMicrogrid COMMAND $) install(TARGETS scalemicrogrid RUNTIME DESTINATION bin) From c37ca338c6ad6b5684b6fd0d8f1a810229310e6c Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 31 May 2024 18:15:59 -0400 Subject: [PATCH 3/7] Fix ScaleMicrogrid example: - Remove dependence on data files. - Check whether tests pass. - Fix code style. --- CMakeLists.txt | 8 +- Examples/Scale_Microgrid/Scale_Microgrid.cpp | 152 +++--- Examples/Scale_Microgrid/SolutionKeys.hpp | 507 +++++++++++++++++++ Examples/Scale_Microgrid/microgrid_N2.txt | 70 --- Examples/Scale_Microgrid/microgrid_N4.txt | 142 ------ Examples/Scale_Microgrid/microgrid_N8.txt | 286 ----------- 6 files changed, 597 insertions(+), 568 deletions(-) create mode 100644 Examples/Scale_Microgrid/SolutionKeys.hpp delete mode 100644 Examples/Scale_Microgrid/microgrid_N2.txt delete mode 100644 Examples/Scale_Microgrid/microgrid_N4.txt delete mode 100644 Examples/Scale_Microgrid/microgrid_N8.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1659d61d1..fb52b0820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,11 +54,12 @@ # Security, LLC, and shall not be used for advertising or product # endorsement purposes. # - +# # [[ # Author(s): # - Cameron Rutherford -#]] +# - Slaven Peles +# ]] cmake_minimum_required(VERSION 3.12) @@ -88,9 +89,6 @@ set(CMAKE_MACOSX_RPATH 1) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake) -# Add source directory to macros for file access -add_compile_definitions("SOURCE_ROOT=${CMAKE_SOURCE_DIR}") - # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath # use, i.e. don't skip the full RPATH for the build tree set(CMAKE_SKIP_BUILD_RPATH FALSE) diff --git a/Examples/Scale_Microgrid/Scale_Microgrid.cpp b/Examples/Scale_Microgrid/Scale_Microgrid.cpp index 70d4148c9..a4099c689 100644 --- a/Examples/Scale_Microgrid/Scale_Microgrid.cpp +++ b/Examples/Scale_Microgrid/Scale_Microgrid.cpp @@ -6,6 +6,8 @@ #include #include +#include +#include "SolutionKeys.hpp" #include #include @@ -16,11 +18,33 @@ #include #include -//macro to get macro -#define STRING(x) #x -#define XSTRING(x) STRING(x) + +static int test(size_t Nsize); int main(int argc, char const *argv[]) +{ + int retval = 0; + retval += test(2); + retval += test(4); + retval += test(8); + if (retval > 0) + { + std::cout << "Some tests fail!!\n"; + } + else + { + std::cout << "All tests pass!!\n"; + } + return retval; +} + +/** + * @brief Tests network of distributed generators. + * + * @param Nsize - The number of DG line load cobinations to generate for scale + * @return int returns 0 if successful, >0 otherwise + */ +int test(size_t Nsize) { double abstol = 1.0e-8; double reltol = 1.0e-8; @@ -31,19 +55,31 @@ int main(int argc, char const *argv[]) //Create circuit model ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_amount); - - //The amount of DG line load cobinations to generate for scale - size_t Nsize = 8; + const std::vector* true_vec = &answer_key_N8; - //Set to false if the parameters choosen are not used to generate data files - bool orgparams = true; + switch (Nsize) + { + case 2: + true_vec = &answer_key_N2; + break; + case 4: + true_vec = &answer_key_N4; + break; + case 8: + // true_vec = &answer_key_N8; + break; + default: + std::cout << "No reference solution for Nsize = " << Nsize << ".\n"; + std::cout << "Using default Nsize = 8.\n"; + } - //Modeled after the problem in the paper + + // Modeled after the problem in the paper // Every Bus has the same virtual resistance. This is due to the numerical stability as mentioned in the paper. double RN = 1.0e4; - //DG Params Vector - //All DGs have the same set of parameters except for the first two. + // DG Params Vector + // All DGs have the same set of parameters except for the first two. ModelLib::DistributedGeneratorParameters DG_parms1; DG_parms1.wb_ = 2.0*M_PI*50.0; DG_parms1.wc_ = 31.41; @@ -127,19 +163,18 @@ int main(int argc, char const *argv[]) //Create the reference DG - ModelLib::DistributedGenerator *dg_ref = new ModelLib::DistributedGenerator(0, DGParams_list[0], true); + ModelLib::DistributedGenerator* dg_ref = new ModelLib::DistributedGenerator(0, DGParams_list[0], true); //ref motor - dg_ref->setExternalConnectionNodes(0,vec_size_internals); + dg_ref->setExternalConnectionNodes(0, vec_size_internals); //outputs - dg_ref->setExternalConnectionNodes(1,vdqbus_index[0]); - dg_ref->setExternalConnectionNodes(2,vdqbus_index[0] + 1); + dg_ref->setExternalConnectionNodes(1, vdqbus_index[0]); + dg_ref->setExternalConnectionNodes(2, vdqbus_index[0] + 1); //"grounding" of the difference - dg_ref->setExternalConnectionNodes(3,-1); + dg_ref->setExternalConnectionNodes(3, -1); //internal connections for (size_t i = 0; i < 12; i++) { - - dg_ref->setExternalConnectionNodes(4 + i,i); + dg_ref->setExternalConnectionNodes(4 + i, i); } sysmodel->addComponent(dg_ref); @@ -149,9 +184,8 @@ int main(int argc, char const *argv[]) //Add all other DGs for (size_t i = 1; i < 2*Nsize; i++) { - //current DG to add - ModelLib::DistributedGenerator *dg = new ModelLib::DistributedGenerator(model_id++, DGParams_list[i], false); + ModelLib::DistributedGenerator* dg = new ModelLib::DistributedGenerator(model_id++, DGParams_list[i], false); //ref motor dg->setExternalConnectionNodes(0,vec_size_internals); //outputs @@ -160,7 +194,6 @@ int main(int argc, char const *argv[]) //internal connections for (size_t j = 0; j < 13; j++) { - dg->setExternalConnectionNodes(3 + j,indexv + j); } indexv += 13; @@ -171,19 +204,19 @@ int main(int argc, char const *argv[]) for (size_t i = 0; i < 2*Nsize - 1; i++) { //line - ModelLib::MicrogridLine *line_model = new ModelLib::MicrogridLine(model_id++, rline_list[i], Lline_list[i]); + ModelLib::MicrogridLine* line_model = new ModelLib::MicrogridLine(model_id++, rline_list[i], Lline_list[i]); //ref motor - line_model->setExternalConnectionNodes(0,vec_size_internals); + line_model->setExternalConnectionNodes(0, vec_size_internals); //input connections - line_model->setExternalConnectionNodes(1,vdqbus_index[i]); - line_model->setExternalConnectionNodes(2,vdqbus_index[i] + 1); + line_model->setExternalConnectionNodes(1, vdqbus_index[i]); + line_model->setExternalConnectionNodes(2, vdqbus_index[i] + 1); //output connections - line_model->setExternalConnectionNodes(3,vdqbus_index[i+1]); - line_model->setExternalConnectionNodes(4,vdqbus_index[i+1] + 1); + line_model->setExternalConnectionNodes(3, vdqbus_index[i+1]); + line_model->setExternalConnectionNodes(4, vdqbus_index[i+1] + 1); //internal connections for (size_t j = 0; j < 2; j++) { - line_model->setExternalConnectionNodes(5 + j,indexv + j); + line_model->setExternalConnectionNodes(5 + j, indexv + j); } indexv += 2; sysmodel->addComponent(line_model); @@ -192,17 +225,16 @@ int main(int argc, char const *argv[]) // Load all the Load components for (size_t i = 0; i < Nsize; i++) { - ModelLib::MicrogridLoad *load_model = new ModelLib::MicrogridLoad(model_id++, rload_list[i], Lload_list[i]); + ModelLib::MicrogridLoad* load_model = new ModelLib::MicrogridLoad(model_id++, rload_list[i], Lload_list[i]); //ref motor - load_model->setExternalConnectionNodes(0,vec_size_internals); + load_model->setExternalConnectionNodes(0, vec_size_internals); //input connections - load_model->setExternalConnectionNodes(1,vdqbus_index[2*i]); - load_model->setExternalConnectionNodes(2,vdqbus_index[2*i] + 1); + load_model->setExternalConnectionNodes(1, vdqbus_index[2*i]); + load_model->setExternalConnectionNodes(2, vdqbus_index[2*i] + 1); //internal connections for (size_t j = 0; j < 2; j++) { - - load_model->setExternalConnectionNodes(3 + j,indexv + j); + load_model->setExternalConnectionNodes(3 + j, indexv + j); } indexv += 2; sysmodel->addComponent(load_model); @@ -211,7 +243,7 @@ int main(int argc, char const *argv[]) //Add all the microgrid Virtual DQ Buses for (size_t i = 0; i < 2*Nsize; i++) { - ModelLib::MicrogridBusDQ *virDQbus_model = new ModelLib::MicrogridBusDQ( + ModelLib::MicrogridBusDQ* virDQbus_model = new ModelLib::MicrogridBusDQ( model_id++, RN); virDQbus_model->setExternalConnectionNodes(0, vdqbus_index[i]); @@ -280,38 +312,28 @@ int main(int argc, char const *argv[]) printf("%lu: % 2.16e\n", i, yfinial[i]); } - //if proper MATLAB results are avalible and model is using origional parameters - std::vector compDataSizes = {2,4,8}; - //All data generated with abstol=1e-12 and reltol=1e-12 with ode23tb - if (orgparams && compDataSizes.end() != std::find(compDataSizes.begin(), compDataSizes.end(), Nsize)) - { - //get the cmake source dir from the cmake configuration - std::string base_path = XSTRING(SOURCE_ROOT); - - base_path += "/Examples/Scale_Microgrid/microgrid_N"; - base_path += std::to_string(Nsize); - base_path += ".txt"; - std::cout << base_path << std::endl; - - //load vector from data file - std::vector true_vec(vec_size_total, 0.0); - double val_cur = 0.0; - std::ifstream data_file(base_path); - size_t i = 0; - while (data_file >> val_cur && i < true_vec.size()) - { - true_vec[i++] = val_cur; - } - data_file.close(); + bool test_pass = true; + double tol = 3e-3; - //check relative error - std::cout << "Test the Relative Error\n"; - for (size_t i = 0; i < true_vec.size(); i++) - { - printf("%lu: % 2.16e\n", i, abs(true_vec[i] - yfinial[i]) / abs(true_vec[i])); - } + // check relative error + std::cout << "Test the Relative Error\n"; + for (size_t i = 0; i < true_vec->size(); i++) + { + test_pass *= GridKit::Testing::isEqual(yfinial[i], true_vec->at(i), tol); + printf("%lu: % 2.16e\n", i, abs(true_vec->at(i) - yfinial[i]) / abs(true_vec->at(i))); } + delete idas; + delete sysmodel; - return 0; + if(test_pass) + { + std::cout << "Test with Nsize = " << Nsize << " passes!\n"; + return 0; + } + else + { + std::cout << "Test with Nsize = " << Nsize << " fails!\n"; + return 1; + } } diff --git a/Examples/Scale_Microgrid/SolutionKeys.hpp b/Examples/Scale_Microgrid/SolutionKeys.hpp new file mode 100644 index 000000000..b43a42304 --- /dev/null +++ b/Examples/Scale_Microgrid/SolutionKeys.hpp @@ -0,0 +1,507 @@ +// All data generated with abstol=1e-12 and reltol=1e-12 with ode23tb Matlab solver + + +#include + +const std::vector answer_key_N2 = {22975.4182636905, + 12753.1173017451, + 0.0376305671131306, + -0.0209815421114537, + 0.0184828563235406, + -0.00015632917065729, + 63.2193617412383, + -29.4226556659582, + 363.420924977355, + -3.01001804456668e-06, + 63.2193618667302, + -35.0920143829141, + -0.00755583999797958, + 22975.8457840701, + 8742.0172166684, + 0.0371009878165673, + -0.0142112776774797, + 0.0187407972932474, + -9.8913852531819e-05, + 62.3296548917654, + -17.9650261562766, + 368.635407345931, + 3.79041261513032e-05, + 62.3296560841534, + -23.7157298601546, + -0.0827401584095097, + 17277.712521392, + 16493.7578328327, + 0.0311645357391787, + -0.0298601153771274, + 0.0225001003469904, + -0.000264388302121386, + 48.6166482764357, + -40.8862612232969, + 355.25957014696, + -0.000167008045114112, + 48.6166481095298, + -46.4283022775928, + -0.0844566209033113, + 17277.2493364959, + 9182.29479881977, + 0.0302503981389185, + -0.0161722538457184, + 0.023180586071601, + -0.000129590157483103, + 47.1906392248137, + -19.3574255862892, + 366.226354188735, + 0.000121054462396047, + 47.19063792117, + -25.0705499054599, + -18.8125403122072, + 21.1471334522508, + 43.2997340692497, + -3.03798323340816, + -44.8715356440453, + 28.9585224749495, + 81.99613295014, + -56.2385627562355, + 132.749774614687, + -82.280664729262, + 311.999576042192, + 357.692287974629, + -5.85078929333349, + 364.119335219897, + -8.84631033126304, + 347.214535767435, + -32.7241067379802, + 360.411028950125, + -34.9283280833745}; + +const std::vector answer_key_N4 = {27828.3291148094, + 10602.3611530864, + 0.0452452394028709, + -0.0173410584955486, + 0.018686818367312, + -0.000129595027000909, + 76.0120809944985, + -23.2367034227098, + 366.216582730654, + -0.000167782960864797, + 76.0120710728117, + -28.9413214479885, + -0.0154989336357971, + 27832.0772154743, + 7838.80352597054, + 0.0448129806183038, + -0.0127296381144373, + 0.0188642014642206, + -9.04502393904097e-05, + 75.2859236720964, + -15.4316980534341, + 369.809174828127, + -5.17440472732025e-05, + 75.285919083362, + -21.1922719962368, + -0.142596248886844, + 20950.1519748442, + 16334.3924580166, + 0.0377787488551238, + -0.0295717781600636, + 0.0225780601074885, + -0.000265567743682681, + 58.9348270364006, + -40.4081583028089, + 355.498460539903, + -8.66167274613643e-05, + 58.9348242715342, + -45.9457664944992, + -0.164628885385433, + 20956.2846481359, + 12345.7855779785, + 0.0371673110634281, + -0.0220171188824754, + 0.0229486760225139, + -0.000191111142238558, + 57.9810673844105, + -28.5265491599081, + 361.481100853144, + 8.24481547667206e-05, + 57.9810719040216, + -34.1573355283559, + -0.245126576498858, + 20978.9206932923, + 17875.6825958711, + 0.0380785081131898, + -0.0325621468970297, + 0.0224354615928625, + -0.000295085318936756, + 59.4025243779293, + -45.1101946009202, + 353.186117339098, + 5.52721744209165e-05, + 59.4025238741703, + -50.6117204294148, + -0.253672269778405, + 20990.6142554844, + 11779.5685373245, + 0.0371243965775962, + -0.0209716906203726, + 0.0230016494389548, + -0.000180846578022512, + 57.9140614794815, + -26.8817831662193, + 362.331254349606, + 0.000209247259473183, + 57.9140782926947, + -32.5257339504705, + -0.288747285297145, + 21004.5418902462, + 16686.981801999, + 0.0379131316203435, + -0.0302602142538338, + 0.0225460339603269, + -0.000272422675391038, + 59.1444740212228, + -41.4902940591195, + 354.969993387113, + 8.14114753778542e-05, + 59.1444846638236, + -47.0195494892644, + -0.285876486857154, + 21005.895228757, + 8274.13913126834, + 0.0366267978764156, + -0.0145584209340773, + 0.0233276948336748, + -0.000117627382397687, + 57.1378568500881, + -16.7923279871216, + 367.58883605301, + 0.000263351556352378, + 57.1378679159653, + -22.518140603782, + -6.57009481597077, + 28.1053117219546, + 68.341829672125, + 5.75010361666728, + -7.27398138223966, + 42.3413009908014, + 44.2901915856089, + -0.850144510998897, + -26.9214526328474, + 37.7939474726438, + 20.9421230166698, + -8.2155394685309, + -48.4341275019927, + 37.706248875936, + 82.5460878639016, + -57.0458911301263, + 127.388509162578, + -90.4406093871607, + 116.522583626035, + -102.149734009655, + 112.650118587972, + -107.825883544914, + 311.543402422187, + 360.780248808368, + -7.42039816792328, + 365.078323407317, + -13.2331839185884, + 344.46378568747, + -54.5546252592288, + 350.335287885457, + -63.572021962256, + 334.342198258035, + -88.749585714325, + 344.281369936645, + -94.7726681838823, + 332.2248206198, + -103.942854393111, + 347.103721199815, + -107.812479611979 + }; + +const std::vector answer_key_N8 = {29266.6517718661, + 9842.93617289812, + 0.0475360674334622, + -0.0160323945316821, + 0.0187557247105805, + -0.000119821248231538, + 79.8612117213119, + -21.0144010498971, + 367.201497494684, + -0.00135963018489767, + 79.8611351716573, + -26.7318789917162, + -0.018074876389402, + 29296.9645459408, + 7415.51099954903, + 0.0471789367393934, + -0.0120180219897291, + 0.0189117902285582, + -8.57914733703415e-05, + 79.2614266664798, + -14.2194852461262, + 370.357116139458, + -0.00065261697325357, + 79.261388452934, + -19.9860446882469, + -0.161178046356866, + 22178.7337755581, + 15750.48869542, + 0.0399575496599213, + -0.028431003000158, + 0.0226540351215628, + -0.000255811047442045, + 62.3338080750298, + -38.6061338491152, + 356.372404460464, + -0.000888421043595241, + 62.3337589017493, + -44.1546192236143, + -0.191206982234175, + 22245.3587939821, + 12476.0312983393, + 0.0395296431152022, + -0.0222832972915751, + 0.0229591349358969, + -0.000195357283522886, + 61.6667253463805, + -28.9363062720176, + 361.284131747149, + 0.000606091049765824, + 61.6667589580497, + -34.5611135316627, + -0.300475535038271, + 22471.354929649, + 17410.9400696732, + 0.0407475331761201, + -0.0316496339533813, + 0.0225047347006168, + -0.000287941144857336, + 63.5662158978541, + -43.6654709736205, + 353.882194971394, + -0.00050508442766251, + 63.5661867600733, + -49.1745383652835, + -0.321406735230742, + 22562.1063953332, + 12532.040739496, + 0.0400730650460856, + -0.0224103188019356, + 0.0229590093469276, + -0.000197040279593967, + 62.5145400797163, + -29.1337602252211, + 361.200953962968, + 0.00123813270414561, + 62.5146115608051, + -34.7565572443792, + -0.398765881347133, + 22822.9625175864, + 17526.9123376124, + 0.0413769691613727, + -0.0318846988884131, + 0.0224996948233429, + -0.000290724959665147, + 64.5480523645119, + -44.0326735095454, + 353.709220392926, + -0.000255137918253834, + 64.548036917491, + -49.5382706457328, + -0.409294621792759, + 22917.4640781459, + 11700.1980576741, + 0.0405370737861658, + -0.0208717910251266, + 0.0230419643488667, + -0.000182321342412399, + 63.2383663569188, + -26.7111380754575, + 362.449323338104, + 0.00143605100750772, + 63.2384503029344, + -32.3525635247183, + -0.460038982115987, + 23175.0870418607, + 17429.0372806116, + 0.0419717095772374, + -0.0317010913432995, + 0.0225145433123769, + -0.000289381352876061, + 65.4757968347883, + -43.7415548084125, + 353.856643943042, + -0.000116590766441278, + 65.4757901489451, + -49.2486679790579, + -0.461848591689221, + 23264.6732405303, + 10919.0360806903, + 0.0409947737541995, + -0.0194331296392293, + 0.0231200668519233, + -0.000168575863901554, + 63.9522672718067, + -24.4455560147541, + 363.621937642842, + 0.00154556746783549, + 63.9523565934322, + -30.1044436917781, + -0.491529580804623, + 23488.6137650364, + 17313.8654584652, + 0.0424952351974662, + -0.0314883547842804, + 0.0225303364455447, + -0.000287714847080755, + 66.2924442955506, + -43.4048501801219, + 354.030311475628, + 0.000169934086992562, + 66.2924545883603, + -48.9139721676174, + -0.486548093474613, + 23557.6136117665, + 10241.0790360359, + 0.0413774884672506, + -0.0181860120867723, + 0.0231877453638413, + -0.000156639599075328, + 64.5492156984859, + -22.4816084883194, + 364.639179755733, + 0.00142420279185394, + 64.5492984953198, + -28.1556597465189, + -0.499726325044563, + 23722.4168131373, + 16958.7765974266, + 0.0428487548646152, + -0.0308090857078185, + 0.0225672437721518, + -0.000281355782039133, + 66.8440182379463, + -42.3350991467661, + 354.562942832682, + 0.000573219240561573, + 66.844044569212, + -47.8519918014414, + -0.490219448053285, + 23769.8747006891, + 9267.5206785042, + 0.0415639300026818, + -0.0164109903099032, + 0.0232814268213158, + -0.000139385907988285, + 64.8399200066663, + -19.6874999818575, + 366.100410278813, + 0.00128332197988872, + 64.8400012051758, + -25.3838027935624, + -0.491586583798841, + 23854.0240861864, + 15160.7060140903, + 0.0427385845553072, + -0.0273659210853948, + 0.0227360281885303, + -0.00024756822257102, + 66.6722121992594, + -36.9193366680176, + 357.260483774461, + 0.000734666517031364, + 66.6722602990682, + -42.4779079553274, + -0.482907936930927, + 23870.5548740189, + 6166.60742794455, + 0.0412253604361869, + -0.0108406830677542, + 0.0235710268609798, + -8.45378382385454e-05, + 64.3117067426907, + -10.9219886629635, + 370.751596332923, + 0.00130490570318174, + 64.3117765573399, + -16.6904284244068, + -2.9267653635869, + 30.5878043390112, + 75.9238910016987, + 9.17392754248112, + 4.3701560041079, + 48.7765765968327, + 58.3101300775815, + 3.13323809951331, + -6.37573932293514, + 46.1701408549949, + 41.9244199648313, + -6.5432868117422, + -17.3691293511209, + 41.8611610718482, + 27.7383173553277, + -12.9709065074016, + -27.5322418670623, + 38.9032728624808, + 16.2733736528389, + -16.5280348065045, + -36.4800564569504, + 37.0627808819117, + 7.38198504755967, + -17.9899033675727, + -44.0731708800056, + 36.9539474625741, + 1.14781892918688, + -15.9507601441003, + -49.1751072411967, + 44.6278268007059, + 82.7517114852138, + -57.3188928805757, + 125.959171148664, + -93.1822145893453, + 110.816672146529, + -108.811406393296, + 99.5107131550674, + -119.104827911048, + 92.0427992280762, + -125.056967118294, + 88.0811872722293, + -127.985464658329, + 87.1649116220972, + -128.957730829954, + 89.0189233593932, + -129.480383815729, + 311.408200092424, + 361.890500304156, + -7.90450151715305, + 365.594288034004, + -14.6504114199963, + 344.278948204657, + -61.517809887448, + 348.104769580715, + -73.1715704285651, + 329.472137794467, + -107.797643650827, + 335.509251816504, + -117.787067889008, + 317.044841017058, + -139.602945170765, + 325.182412285621, + -147.51178633583, + 307.989533967543, + -158.91998673915, + 318.171184823086, + -165.141414351062, + 302.951769665185, + -168.712626964975, + 315.009688292198, + -173.624287308414, + 302.070219389208, + -171.572667424371, + 315.86470341008, + -175.706947618597, + 306.288884765777, + -170.785573848562, + 322.018589824395, + -176.179397251772 + }; \ No newline at end of file diff --git a/Examples/Scale_Microgrid/microgrid_N2.txt b/Examples/Scale_Microgrid/microgrid_N2.txt deleted file mode 100644 index d0edf2a51..000000000 --- a/Examples/Scale_Microgrid/microgrid_N2.txt +++ /dev/null @@ -1,70 +0,0 @@ -22975.4182636905 -12753.1173017451 -0.0376305671131306 --0.0209815421114537 -0.0184828563235406 --0.00015632917065729 -63.2193617412383 --29.4226556659582 -363.420924977355 --3.01001804456668e-06 -63.2193618667302 --35.0920143829141 --0.00755583999797958 -22975.8457840701 -8742.0172166684 -0.0371009878165673 --0.0142112776774797 -0.0187407972932474 --9.8913852531819e-05 -62.3296548917654 --17.9650261562766 -368.635407345931 -3.79041261513032e-05 -62.3296560841534 --23.7157298601546 --0.0827401584095097 -17277.712521392 -16493.7578328327 -0.0311645357391787 --0.0298601153771274 -0.0225001003469904 --0.000264388302121386 -48.6166482764357 --40.8862612232969 -355.25957014696 --0.000167008045114112 -48.6166481095298 --46.4283022775928 --0.0844566209033113 -17277.2493364959 -9182.29479881977 -0.0302503981389185 --0.0161722538457184 -0.023180586071601 --0.000129590157483103 -47.1906392248137 --19.3574255862892 -366.226354188735 -0.000121054462396047 -47.19063792117 --25.0705499054599 --18.8125403122072 -21.1471334522508 -43.2997340692497 --3.03798323340816 --44.8715356440453 -28.9585224749495 -81.99613295014 --56.2385627562355 -132.749774614687 --82.280664729262 -311.999576042192 -357.692287974629 --5.85078929333349 -364.119335219897 --8.84631033126304 -347.214535767435 --32.7241067379802 -360.411028950125 --34.9283280833745 diff --git a/Examples/Scale_Microgrid/microgrid_N4.txt b/Examples/Scale_Microgrid/microgrid_N4.txt deleted file mode 100644 index 29a0b71b8..000000000 --- a/Examples/Scale_Microgrid/microgrid_N4.txt +++ /dev/null @@ -1,142 +0,0 @@ -27828.3291148094 -10602.3611530864 -0.0452452394028709 --0.0173410584955486 -0.018686818367312 --0.000129595027000909 -76.0120809944985 --23.2367034227098 -366.216582730654 --0.000167782960864797 -76.0120710728117 --28.9413214479885 --0.0154989336357971 -27832.0772154743 -7838.80352597054 -0.0448129806183038 --0.0127296381144373 -0.0188642014642206 --9.04502393904097e-05 -75.2859236720964 --15.4316980534341 -369.809174828127 --5.17440472732025e-05 -75.285919083362 --21.1922719962368 --0.142596248886844 -20950.1519748442 -16334.3924580166 -0.0377787488551238 --0.0295717781600636 -0.0225780601074885 --0.000265567743682681 -58.9348270364006 --40.4081583028089 -355.498460539903 --8.66167274613643e-05 -58.9348242715342 --45.9457664944992 --0.164628885385433 -20956.2846481359 -12345.7855779785 -0.0371673110634281 --0.0220171188824754 -0.0229486760225139 --0.000191111142238558 -57.9810673844105 --28.5265491599081 -361.481100853144 -8.24481547667206e-05 -57.9810719040216 --34.1573355283559 --0.245126576498858 -20978.9206932923 -17875.6825958711 -0.0380785081131898 --0.0325621468970297 -0.0224354615928625 --0.000295085318936756 -59.4025243779293 --45.1101946009202 -353.186117339098 -5.52721744209165e-05 -59.4025238741703 --50.6117204294148 --0.253672269778405 -20990.6142554844 -11779.5685373245 -0.0371243965775962 --0.0209716906203726 -0.0230016494389548 --0.000180846578022512 -57.9140614794815 --26.8817831662193 -362.331254349606 -0.000209247259473183 -57.9140782926947 --32.5257339504705 --0.288747285297145 -21004.5418902462 -16686.981801999 -0.0379131316203435 --0.0302602142538338 -0.0225460339603269 --0.000272422675391038 -59.1444740212228 --41.4902940591195 -354.969993387113 -8.14114753778542e-05 -59.1444846638236 --47.0195494892644 --0.285876486857154 -21005.895228757 -8274.13913126834 -0.0366267978764156 --0.0145584209340773 -0.0233276948336748 --0.000117627382397687 -57.1378568500881 --16.7923279871216 -367.58883605301 -0.000263351556352378 -57.1378679159653 --22.518140603782 --6.57009481597077 -28.1053117219546 -68.341829672125 -5.75010361666728 --7.27398138223966 -42.3413009908014 -44.2901915856089 --0.850144510998897 --26.9214526328474 -37.7939474726438 -20.9421230166698 --8.2155394685309 --48.4341275019927 -37.706248875936 -82.5460878639016 --57.0458911301263 -127.388509162578 --90.4406093871607 -116.522583626035 --102.149734009655 -112.650118587972 --107.825883544914 -311.543402422187 -360.780248808368 --7.42039816792328 -365.078323407317 --13.2331839185884 -344.46378568747 --54.5546252592288 -350.335287885457 --63.572021962256 -334.342198258035 --88.749585714325 -344.281369936645 --94.7726681838823 -332.2248206198 --103.942854393111 -347.103721199815 --107.812479611979 diff --git a/Examples/Scale_Microgrid/microgrid_N8.txt b/Examples/Scale_Microgrid/microgrid_N8.txt deleted file mode 100644 index 3e1ba779b..000000000 --- a/Examples/Scale_Microgrid/microgrid_N8.txt +++ /dev/null @@ -1,286 +0,0 @@ -29266.6517718661 -9842.93617289812 -0.0475360674334622 --0.0160323945316821 -0.0187557247105805 --0.000119821248231538 -79.8612117213119 --21.0144010498971 -367.201497494684 --0.00135963018489767 -79.8611351716573 --26.7318789917162 --0.018074876389402 -29296.9645459408 -7415.51099954903 -0.0471789367393934 --0.0120180219897291 -0.0189117902285582 --8.57914733703415e-05 -79.2614266664798 --14.2194852461262 -370.357116139458 --0.00065261697325357 -79.261388452934 --19.9860446882469 --0.161178046356866 -22178.7337755581 -15750.48869542 -0.0399575496599213 --0.028431003000158 -0.0226540351215628 --0.000255811047442045 -62.3338080750298 --38.6061338491152 -356.372404460464 --0.000888421043595241 -62.3337589017493 --44.1546192236143 --0.191206982234175 -22245.3587939821 -12476.0312983393 -0.0395296431152022 --0.0222832972915751 -0.0229591349358969 --0.000195357283522886 -61.6667253463805 --28.9363062720176 -361.284131747149 -0.000606091049765824 -61.6667589580497 --34.5611135316627 --0.300475535038271 -22471.354929649 -17410.9400696732 -0.0407475331761201 --0.0316496339533813 -0.0225047347006168 --0.000287941144857336 -63.5662158978541 --43.6654709736205 -353.882194971394 --0.00050508442766251 -63.5661867600733 --49.1745383652835 --0.321406735230742 -22562.1063953332 -12532.040739496 -0.0400730650460856 --0.0224103188019356 -0.0229590093469276 --0.000197040279593967 -62.5145400797163 --29.1337602252211 -361.200953962968 -0.00123813270414561 -62.5146115608051 --34.7565572443792 --0.398765881347133 -22822.9625175864 -17526.9123376124 -0.0413769691613727 --0.0318846988884131 -0.0224996948233429 --0.000290724959665147 -64.5480523645119 --44.0326735095454 -353.709220392926 --0.000255137918253834 -64.548036917491 --49.5382706457328 --0.409294621792759 -22917.4640781459 -11700.1980576741 -0.0405370737861658 --0.0208717910251266 -0.0230419643488667 --0.000182321342412399 -63.2383663569188 --26.7111380754575 -362.449323338104 -0.00143605100750772 -63.2384503029344 --32.3525635247183 --0.460038982115987 -23175.0870418607 -17429.0372806116 -0.0419717095772374 --0.0317010913432995 -0.0225145433123769 --0.000289381352876061 -65.4757968347883 --43.7415548084125 -353.856643943042 --0.000116590766441278 -65.4757901489451 --49.2486679790579 --0.461848591689221 -23264.6732405303 -10919.0360806903 -0.0409947737541995 --0.0194331296392293 -0.0231200668519233 --0.000168575863901554 -63.9522672718067 --24.4455560147541 -363.621937642842 -0.00154556746783549 -63.9523565934322 --30.1044436917781 --0.491529580804623 -23488.6137650364 -17313.8654584652 -0.0424952351974662 --0.0314883547842804 -0.0225303364455447 --0.000287714847080755 -66.2924442955506 --43.4048501801219 -354.030311475628 -0.000169934086992562 -66.2924545883603 --48.9139721676174 --0.486548093474613 -23557.6136117665 -10241.0790360359 -0.0413774884672506 --0.0181860120867723 -0.0231877453638413 --0.000156639599075328 -64.5492156984859 --22.4816084883194 -364.639179755733 -0.00142420279185394 -64.5492984953198 --28.1556597465189 --0.499726325044563 -23722.4168131373 -16958.7765974266 -0.0428487548646152 --0.0308090857078185 -0.0225672437721518 --0.000281355782039133 -66.8440182379463 --42.3350991467661 -354.562942832682 -0.000573219240561573 -66.844044569212 --47.8519918014414 --0.490219448053285 -23769.8747006891 -9267.5206785042 -0.0415639300026818 --0.0164109903099032 -0.0232814268213158 --0.000139385907988285 -64.8399200066663 --19.6874999818575 -366.100410278813 -0.00128332197988872 -64.8400012051758 --25.3838027935624 --0.491586583798841 -23854.0240861864 -15160.7060140903 -0.0427385845553072 --0.0273659210853948 -0.0227360281885303 --0.00024756822257102 -66.6722121992594 --36.9193366680176 -357.260483774461 -0.000734666517031364 -66.6722602990682 --42.4779079553274 --0.482907936930927 -23870.5548740189 -6166.60742794455 -0.0412253604361869 --0.0108406830677542 -0.0235710268609798 --8.45378382385454e-05 -64.3117067426907 --10.9219886629635 -370.751596332923 -0.00130490570318174 -64.3117765573399 --16.6904284244068 --2.9267653635869 -30.5878043390112 -75.9238910016987 -9.17392754248112 -4.3701560041079 -48.7765765968327 -58.3101300775815 -3.13323809951331 --6.37573932293514 -46.1701408549949 -41.9244199648313 --6.5432868117422 --17.3691293511209 -41.8611610718482 -27.7383173553277 --12.9709065074016 --27.5322418670623 -38.9032728624808 -16.2733736528389 --16.5280348065045 --36.4800564569504 -37.0627808819117 -7.38198504755967 --17.9899033675727 --44.0731708800056 -36.9539474625741 -1.14781892918688 --15.9507601441003 --49.1751072411967 -44.6278268007059 -82.7517114852138 --57.3188928805757 -125.959171148664 --93.1822145893453 -110.816672146529 --108.811406393296 -99.5107131550674 --119.104827911048 -92.0427992280762 --125.056967118294 -88.0811872722293 --127.985464658329 -87.1649116220972 --128.957730829954 -89.0189233593932 --129.480383815729 -311.408200092424 -361.890500304156 --7.90450151715305 -365.594288034004 --14.6504114199963 -344.278948204657 --61.517809887448 -348.104769580715 --73.1715704285651 -329.472137794467 --107.797643650827 -335.509251816504 --117.787067889008 -317.044841017058 --139.602945170765 -325.182412285621 --147.51178633583 -307.989533967543 --158.91998673915 -318.171184823086 --165.141414351062 -302.951769665185 --168.712626964975 -315.009688292198 --173.624287308414 -302.070219389208 --171.572667424371 -315.86470341008 --175.706947618597 -306.288884765777 --170.785573848562 -322.018589824395 --176.179397251772 From 7190499f82d5392448c707df4b5104cac681827b Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 31 May 2024 18:36:11 -0400 Subject: [PATCH 4/7] Fix naming convention and build rules. --- Examples/CMakeLists.txt | 6 +++--- Examples/{Scale_Microgrid => ScaleMicrogrid}/CMakeLists.txt | 2 +- .../ScaleMicrogrid.cpp} | 0 .../{Scale_Microgrid => ScaleMicrogrid}/SolutionKeys.hpp | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename Examples/{Scale_Microgrid => ScaleMicrogrid}/CMakeLists.txt (90%) rename Examples/{Scale_Microgrid/Scale_Microgrid.cpp => ScaleMicrogrid/ScaleMicrogrid.cpp} (100%) rename Examples/{Scale_Microgrid => ScaleMicrogrid}/SolutionKeys.hpp (100%) diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index f23dfdc1b..67e0da154 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -56,9 +56,6 @@ # add_subdirectory(MatPowerTesting) -add_subdirectory(RLCircuit) -add_subdirectory(Microgrid) -add_subdirectory(Scale_Microgrid) add_subdirectory(SparseTest) add_subdirectory(DistributedGeneratorTest) @@ -68,6 +65,9 @@ endif() if(TARGET SUNDIALS::idas) add_subdirectory(AdjointSensitivity) + add_subdirectory(RLCircuit) + add_subdirectory(Microgrid) + add_subdirectory(ScaleMicrogrid) if(GRIDKIT_ENABLE_IPOPT) add_subdirectory(DynamicConstrainedOpt) add_subdirectory(GenConstLoad) diff --git a/Examples/Scale_Microgrid/CMakeLists.txt b/Examples/ScaleMicrogrid/CMakeLists.txt similarity index 90% rename from Examples/Scale_Microgrid/CMakeLists.txt rename to Examples/ScaleMicrogrid/CMakeLists.txt index 139eec959..d1822c587 100644 --- a/Examples/Scale_Microgrid/CMakeLists.txt +++ b/Examples/ScaleMicrogrid/CMakeLists.txt @@ -2,7 +2,7 @@ -add_executable(scalemicrogrid Scale_Microgrid.cpp) +add_executable(scalemicrogrid ScaleMicrogrid.cpp) target_link_libraries(scalemicrogrid GRIDKIT::powerelec_disgen GRIDKIT::powerelec_mircoline GRIDKIT::powerelec_microload diff --git a/Examples/Scale_Microgrid/Scale_Microgrid.cpp b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp similarity index 100% rename from Examples/Scale_Microgrid/Scale_Microgrid.cpp rename to Examples/ScaleMicrogrid/ScaleMicrogrid.cpp diff --git a/Examples/Scale_Microgrid/SolutionKeys.hpp b/Examples/ScaleMicrogrid/SolutionKeys.hpp similarity index 100% rename from Examples/Scale_Microgrid/SolutionKeys.hpp rename to Examples/ScaleMicrogrid/SolutionKeys.hpp From 5068086d17bbfd4496d22a674006fc070d07260b Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 31 May 2024 19:02:26 -0400 Subject: [PATCH 5/7] Surpress unnecessary output. --- Examples/ScaleMicrogrid/ScaleMicrogrid.cpp | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp index a4099c689..a70ebe9a1 100644 --- a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp +++ b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp @@ -19,7 +19,7 @@ #include -static int test(size_t Nsize); +static int test(size_t Nsize, bool debug_output = false); int main(int argc, char const *argv[]) { @@ -44,16 +44,16 @@ int main(int argc, char const *argv[]) * @param Nsize - The number of DG line load cobinations to generate for scale * @return int returns 0 if successful, >0 otherwise */ -int test(size_t Nsize) +int test(size_t Nsize, bool debug_output) { double abstol = 1.0e-8; double reltol = 1.0e-8; - size_t max_step_amount = 3000; + size_t max_step_number = 3000; bool usejac = true; //TODO:setup as named parameters //Create circuit model - ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_amount); + ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_number); const std::vector* true_vec = &answer_key_N8; @@ -243,8 +243,7 @@ int test(size_t Nsize) //Add all the microgrid Virtual DQ Buses for (size_t i = 0; i < 2*Nsize; i++) { - ModelLib::MicrogridBusDQ* virDQbus_model = new ModelLib::MicrogridBusDQ( - model_id++, RN); + ModelLib::MicrogridBusDQ* virDQbus_model = new ModelLib::MicrogridBusDQ(model_id++, RN); virDQbus_model->setExternalConnectionNodes(0, vdqbus_index[i]); virDQbus_model->setExternalConnectionNodes(1, vdqbus_index[i] + 1); @@ -254,8 +253,11 @@ int test(size_t Nsize) //allocate all the intial conditions sysmodel->allocate(vec_size_total); - std::cout << sysmodel->y().size() << std::endl; - std::cout << vec_size_internals << ", " << vec_size_externals << "\n"; + if (debug_output) + { + std::cout << sysmodel->y().size() << std::endl; + std::cout << vec_size_internals << ", " << vec_size_externals << "\n"; + } //Create Intial points for states. Every state is to specified to the zero intially for (size_t i = 0; i < vec_size_total; i++) @@ -278,17 +280,21 @@ int test(size_t Nsize) sysmodel->initialize(); sysmodel->evaluateResidual(); - std::vector& fres = sysmodel->getResidual(); - std::cout << "Verify Intial Resisdual is Zero: {\n"; - for (size_t i = 0; i < fres.size(); i++) + std::vector& fres = sysmodel->getResidual(); + if (debug_output) { - printf("%lu : %.16e \n", i, fres[i]); + std::cout << "Verify Intial Resisdual is Zero: {\n"; + for (size_t i = 0; i < fres.size(); i++) + { + std::cout << i << " : " << fres[i] << "\n"; + } + std::cout << "}\n"; } - std::cout << "}\n"; sysmodel->updateTime(0.0, 1.0e-8); sysmodel->evaluateJacobian(); - std::cout << "Intial Jacobian with alpha:\n"; + if (debug_output) + std::cout << "Intial Jacobian with alpha:\n"; //Create numerical integrator and configure it for the generator model @@ -304,12 +310,15 @@ int test(size_t Nsize) idas->runSimulation(t_final); - std::vector& yfinial = sysmodel->y(); + std::vector& yfinal = sysmodel->y(); - std::cout << "Final Vector y\n"; - for (size_t i = 0; i < yfinial.size(); i++) + if (debug_output) { - printf("%lu: % 2.16e\n", i, yfinial[i]); + std::cout << "Final Vector y\n"; + for (size_t i = 0; i < yfinal.size(); i++) + { + std::cout << i << " : " << yfinal[i] << "\n"; + } } bool test_pass = true; @@ -319,8 +328,9 @@ int test(size_t Nsize) std::cout << "Test the Relative Error\n"; for (size_t i = 0; i < true_vec->size(); i++) { - test_pass *= GridKit::Testing::isEqual(yfinial[i], true_vec->at(i), tol); - printf("%lu: % 2.16e\n", i, abs(true_vec->at(i) - yfinial[i]) / abs(true_vec->at(i))); + test_pass *= GridKit::Testing::isEqual(yfinal[i], true_vec->at(i), tol); + if (debug_output) + std::cout << i << " : " << abs(true_vec->at(i) - yfinal[i]) / abs(true_vec->at(i)) << "\n"; } delete idas; From b91faf91f42100c568d0ab8d23e6244ab2a48a48 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 31 May 2024 19:09:04 -0400 Subject: [PATCH 6/7] Use aliases for index and real types. --- Examples/ScaleMicrogrid/ScaleMicrogrid.cpp | 112 +++++++++++---------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp index a70ebe9a1..550291ba2 100644 --- a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp +++ b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp @@ -18,8 +18,10 @@ #include #include +using index_type = size_t; +using real_type = double; -static int test(size_t Nsize, bool debug_output = false); +static int test(index_type Nsize, bool debug_output = false); int main(int argc, char const *argv[]) { @@ -44,18 +46,18 @@ int main(int argc, char const *argv[]) * @param Nsize - The number of DG line load cobinations to generate for scale * @return int returns 0 if successful, >0 otherwise */ -int test(size_t Nsize, bool debug_output) +int test(index_type Nsize, bool debug_output) { - double abstol = 1.0e-8; - double reltol = 1.0e-8; - size_t max_step_number = 3000; + real_type abstol = 1.0e-8; + real_type reltol = 1.0e-8; + index_type max_step_number = 3000; bool usejac = true; //TODO:setup as named parameters //Create circuit model - ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_number); + ModelLib::PowerElectronicsModel* sysmodel = new ModelLib::PowerElectronicsModel(reltol, abstol, usejac, max_step_number); - const std::vector* true_vec = &answer_key_N8; + const std::vector* true_vec = &answer_key_N8; switch (Nsize) { @@ -76,11 +78,11 @@ int test(size_t Nsize, bool debug_output) // Modeled after the problem in the paper // Every Bus has the same virtual resistance. This is due to the numerical stability as mentioned in the paper. - double RN = 1.0e4; + real_type RN = 1.0e4; // DG Params Vector // All DGs have the same set of parameters except for the first two. - ModelLib::DistributedGeneratorParameters DG_parms1; + ModelLib::DistributedGeneratorParameters DG_parms1; DG_parms1.wb_ = 2.0*M_PI*50.0; DG_parms1.wc_ = 31.41; DG_parms1.mp_ = 9.4e-5; @@ -97,7 +99,7 @@ int test(size_t Nsize, bool debug_output) DG_parms1.rLc_ = 0.03; DG_parms1.Lc_ = 0.35e-3; - ModelLib::DistributedGeneratorParameters DG_parms2; + ModelLib::DistributedGeneratorParameters DG_parms2; DG_parms2.wb_ = 2.0*M_PI*50.0; DG_parms2.wc_ = 31.41; DG_parms2.mp_ = 12.5e-5; @@ -114,20 +116,20 @@ int test(size_t Nsize, bool debug_output) DG_parms2.rLc_ = 0.03; DG_parms2.Lc_ = 0.35e-3; - std::vector> DGParams_list(2*Nsize, DG_parms2); + std::vector> DGParams_list(2*Nsize, DG_parms2); DGParams_list[0] = DG_parms1; DGParams_list[1] = DG_parms1; //line vector params //Every odd line has the same parameters and every even line has the same parameters - double rline1 = 0.23; - double Lline1 = 0.1 / (2.0 * M_PI * 50.0); - double rline2 = 0.35; - double Lline2 = 0.58 / (2.0 * M_PI * 50.0); - std::vector rline_list(2*Nsize-1, 0.0); - std::vector Lline_list(2*Nsize-1, 0.0); - for (size_t i = 0; i < rline_list.size(); i++) + real_type rline1 = 0.23; + real_type Lline1 = 0.1 / (2.0 * M_PI * 50.0); + real_type rline2 = 0.35; + real_type Lline2 = 0.58 / (2.0 * M_PI * 50.0); + std::vector rline_list(2*Nsize-1, 0.0); + std::vector Lline_list(2*Nsize-1, 0.0); + for (index_type i = 0; i < rline_list.size(); i++) { rline_list[i] = (i % 2) ? rline2 : rline1; Lline_list[i] = (i % 2) ? Lline2 : Lline1; @@ -136,34 +138,34 @@ int test(size_t Nsize, bool debug_output) //load parms //Only the first load has the same paramaters. - double rload1 = 3.0; - double Lload1 = 2.0 / (2.0 * M_PI * 50.0); - double rload2 = 2.0; - double Lload2 = 1.0 / (2.0 * M_PI * 50.0); + real_type rload1 = 3.0; + real_type Lload1 = 2.0 / (2.0 * M_PI * 50.0); + real_type rload2 = 2.0; + real_type Lload2 = 1.0 / (2.0 * M_PI * 50.0); - std::vector rload_list(Nsize, rload2); - std::vector Lload_list(Nsize, Lload2); + std::vector rload_list(Nsize, rload2); + std::vector Lload_list(Nsize, Lload2); rload_list[0] = rload1; Lload_list[0] = Lload1; // DGs + - refframe Lines + Loads - size_t vec_size_internals = 13*(2*Nsize) - 1 + (2 + 4*(Nsize - 1)) + 2*Nsize; + index_type vec_size_internals = 13*(2*Nsize) - 1 + (2 + 4*(Nsize - 1)) + 2*Nsize; // \omegaref + BusDQ - size_t vec_size_externals = 1 + 2*(2*Nsize); + index_type vec_size_externals = 1 + 2*(2*Nsize); - std::vector vdqbus_index(2*Nsize,0); + std::vector vdqbus_index(2*Nsize,0); vdqbus_index[0] = vec_size_internals + 1; - for (size_t i = 1; i < vdqbus_index.size(); i++) + for (index_type i = 1; i < vdqbus_index.size(); i++) { vdqbus_index[i] = vdqbus_index[i-1] + 2; } //Total size of the vector setup - size_t vec_size_total = vec_size_internals + vec_size_externals; + index_type vec_size_total = vec_size_internals + vec_size_externals; //Create the reference DG - ModelLib::DistributedGenerator* dg_ref = new ModelLib::DistributedGenerator(0, DGParams_list[0], true); + ModelLib::DistributedGenerator* dg_ref = new ModelLib::DistributedGenerator(0, DGParams_list[0], true); //ref motor dg_ref->setExternalConnectionNodes(0, vec_size_internals); //outputs @@ -172,27 +174,27 @@ int test(size_t Nsize, bool debug_output) //"grounding" of the difference dg_ref->setExternalConnectionNodes(3, -1); //internal connections - for (size_t i = 0; i < 12; i++) + for (index_type i = 0; i < 12; i++) { dg_ref->setExternalConnectionNodes(4 + i, i); } sysmodel->addComponent(dg_ref); //Keep track of models and index location - size_t indexv = 12; - size_t model_id = 1; + index_type indexv = 12; + index_type model_id = 1; //Add all other DGs - for (size_t i = 1; i < 2*Nsize; i++) + for (index_type i = 1; i < 2*Nsize; i++) { //current DG to add - ModelLib::DistributedGenerator* dg = new ModelLib::DistributedGenerator(model_id++, DGParams_list[i], false); + ModelLib::DistributedGenerator* dg = new ModelLib::DistributedGenerator(model_id++, DGParams_list[i], false); //ref motor dg->setExternalConnectionNodes(0,vec_size_internals); //outputs dg->setExternalConnectionNodes(1,vdqbus_index[i]); dg->setExternalConnectionNodes(2,vdqbus_index[i] + 1); //internal connections - for (size_t j = 0; j < 13; j++) + for (index_type j = 0; j < 13; j++) { dg->setExternalConnectionNodes(3 + j,indexv + j); } @@ -201,10 +203,10 @@ int test(size_t Nsize, bool debug_output) } // Load all the Line compoenents - for (size_t i = 0; i < 2*Nsize - 1; i++) + for (index_type i = 0; i < 2*Nsize - 1; i++) { //line - ModelLib::MicrogridLine* line_model = new ModelLib::MicrogridLine(model_id++, rline_list[i], Lline_list[i]); + ModelLib::MicrogridLine* line_model = new ModelLib::MicrogridLine(model_id++, rline_list[i], Lline_list[i]); //ref motor line_model->setExternalConnectionNodes(0, vec_size_internals); //input connections @@ -214,7 +216,7 @@ int test(size_t Nsize, bool debug_output) line_model->setExternalConnectionNodes(3, vdqbus_index[i+1]); line_model->setExternalConnectionNodes(4, vdqbus_index[i+1] + 1); //internal connections - for (size_t j = 0; j < 2; j++) + for (index_type j = 0; j < 2; j++) { line_model->setExternalConnectionNodes(5 + j, indexv + j); } @@ -223,16 +225,16 @@ int test(size_t Nsize, bool debug_output) } // Load all the Load components - for (size_t i = 0; i < Nsize; i++) + for (index_type i = 0; i < Nsize; i++) { - ModelLib::MicrogridLoad* load_model = new ModelLib::MicrogridLoad(model_id++, rload_list[i], Lload_list[i]); + ModelLib::MicrogridLoad* load_model = new ModelLib::MicrogridLoad(model_id++, rload_list[i], Lload_list[i]); //ref motor load_model->setExternalConnectionNodes(0, vec_size_internals); //input connections load_model->setExternalConnectionNodes(1, vdqbus_index[2*i]); load_model->setExternalConnectionNodes(2, vdqbus_index[2*i] + 1); //internal connections - for (size_t j = 0; j < 2; j++) + for (index_type j = 0; j < 2; j++) { load_model->setExternalConnectionNodes(3 + j, indexv + j); } @@ -241,9 +243,9 @@ int test(size_t Nsize, bool debug_output) } //Add all the microgrid Virtual DQ Buses - for (size_t i = 0; i < 2*Nsize; i++) + for (index_type i = 0; i < 2*Nsize; i++) { - ModelLib::MicrogridBusDQ* virDQbus_model = new ModelLib::MicrogridBusDQ(model_id++, RN); + ModelLib::MicrogridBusDQ* virDQbus_model = new ModelLib::MicrogridBusDQ(model_id++, RN); virDQbus_model->setExternalConnectionNodes(0, vdqbus_index[i]); virDQbus_model->setExternalConnectionNodes(1, vdqbus_index[i] + 1); @@ -260,14 +262,14 @@ int test(size_t Nsize, bool debug_output) } //Create Intial points for states. Every state is to specified to the zero intially - for (size_t i = 0; i < vec_size_total; i++) + for (index_type i = 0; i < vec_size_total; i++) { sysmodel->y()[i] = 0.0; sysmodel->yp()[i] = 0.0; } // Create Intial derivatives specifics generated in MATLAB - for (size_t i = 0; i < 2*Nsize; i++) + for (index_type i = 0; i < 2*Nsize; i++) { sysmodel->yp()[13*i - 1 + 3] = DGParams_list[i].Vn_; sysmodel->yp()[13*i - 1 + 5] = DGParams_list[i].Kpv_ * DGParams_list[i].Vn_; @@ -280,11 +282,11 @@ int test(size_t Nsize, bool debug_output) sysmodel->initialize(); sysmodel->evaluateResidual(); - std::vector& fres = sysmodel->getResidual(); + std::vector& fres = sysmodel->getResidual(); if (debug_output) { std::cout << "Verify Intial Resisdual is Zero: {\n"; - for (size_t i = 0; i < fres.size(); i++) + for (index_type i = 0; i < fres.size(); i++) { std::cout << i << " : " << fres[i] << "\n"; } @@ -298,10 +300,10 @@ int test(size_t Nsize, bool debug_output) //Create numerical integrator and configure it for the generator model - AnalysisManager::Sundials::Ida* idas = new AnalysisManager::Sundials::Ida(sysmodel); + AnalysisManager::Sundials::Ida* idas = new AnalysisManager::Sundials::Ida(sysmodel); - double t_init = 0.0; - double t_final = 1.0; + real_type t_init = 0.0; + real_type t_final = 1.0; // setup simulation idas->configureSimulation(); @@ -310,23 +312,23 @@ int test(size_t Nsize, bool debug_output) idas->runSimulation(t_final); - std::vector& yfinal = sysmodel->y(); + std::vector& yfinal = sysmodel->y(); if (debug_output) { std::cout << "Final Vector y\n"; - for (size_t i = 0; i < yfinal.size(); i++) + for (index_type i = 0; i < yfinal.size(); i++) { std::cout << i << " : " << yfinal[i] << "\n"; } } bool test_pass = true; - double tol = 3e-3; + real_type tol = 3e-3; // check relative error std::cout << "Test the Relative Error\n"; - for (size_t i = 0; i < true_vec->size(); i++) + for (index_type i = 0; i < true_vec->size(); i++) { test_pass *= GridKit::Testing::isEqual(yfinal[i], true_vec->at(i), tol); if (debug_output) From f29d73be0b0439916187565e69fe5af1729bed4f Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Tue, 4 Jun 2024 10:53:38 -0400 Subject: [PATCH 7/7] Minor code comment improvements. --- .../DistributedGenerator.cpp | 2 +- .../MicrogridBusDQ/MicrogridBusDQ.cpp | 7 +- .../MicrogridLine/MicrogridLine.cpp | 10 +- Examples/ScaleMicrogrid/ScaleMicrogrid.cpp | 5 +- Examples/ScaleMicrogrid/SolutionKeys.hpp | 1012 +++++++++-------- 5 files changed, 523 insertions(+), 513 deletions(-) diff --git a/ComponentLib/PowerElectronicsComponents/DistributedGenerator/DistributedGenerator.cpp b/ComponentLib/PowerElectronicsComponents/DistributedGenerator/DistributedGenerator.cpp index 21b91d751..00d174ae4 100644 --- a/ComponentLib/PowerElectronicsComponents/DistributedGenerator/DistributedGenerator.cpp +++ b/ComponentLib/PowerElectronicsComponents/DistributedGenerator/DistributedGenerator.cpp @@ -10,7 +10,7 @@ namespace ModelLib { /*! - * @brief Constructor for a Discrete Generator + * @brief Constructor for a Distributed Generator * @todo Maybe have parameters be templated in. Variables cannot be changed and are unlikely to. Allows for compile time optimizations * * Calls default ModelEvaluatorImpl constructor. diff --git a/ComponentLib/PowerElectronicsComponents/MicrogridBusDQ/MicrogridBusDQ.cpp b/ComponentLib/PowerElectronicsComponents/MicrogridBusDQ/MicrogridBusDQ.cpp index 0355e44d0..f486e1720 100644 --- a/ComponentLib/PowerElectronicsComponents/MicrogridBusDQ/MicrogridBusDQ.cpp +++ b/ComponentLib/PowerElectronicsComponents/MicrogridBusDQ/MicrogridBusDQ.cpp @@ -13,11 +13,10 @@ namespace ModelLib { * * In DQ space * Each microgrid line has a virtual resistance RN - * Model is from paper: " - "Modeling, Analysis and Testing of Autonomous Operation of an Inverter-Based Microgrid" Nagaraju Pogaku, Milan Prodanovic, and Timothy C. Green" - * Section E + * Model is from paper: "Modeling, Analysis and Testing of Autonomous Operation + * of an Inverter-Based Microgrid", Nagaraju Pogaku, Milan Prodanovic, and + * Timothy C. Green, Section E */ - template MicrogridBusDQ::MicrogridBusDQ(IdxT id, ScalarT RN) : RN_(RN) diff --git a/ComponentLib/PowerElectronicsComponents/MicrogridLine/MicrogridLine.cpp b/ComponentLib/PowerElectronicsComponents/MicrogridLine/MicrogridLine.cpp index 46c97fa29..3198af2e5 100644 --- a/ComponentLib/PowerElectronicsComponents/MicrogridLine/MicrogridLine.cpp +++ b/ComponentLib/PowerElectronicsComponents/MicrogridLine/MicrogridLine.cpp @@ -12,9 +12,9 @@ namespace ModelLib { * Calls default ModelEvaluatorImpl constructor. * * - * Model is from paper: " - "Modeling, Analysis and Testing of Autonomous Operation of an Inverter-Based Microgrid" Nagaraju Pogaku, Milan Prodanovic, and Timothy C. Green" - * Section C + * Model is from paper: "Modeling, Analysis and Testing of Autonomous Operation + * of an Inverter-Based Microgrid", Nagaraju Pogaku, Milan Prodanovic, and + * Timothy C. Green, Section C * * @todo Consider having \omegaref as a global constant, not a node variable. */ @@ -88,7 +88,7 @@ int MicrogridLine::evaluateResidual() f_[4] = y_[6] ; //Internal variables - f_[5] = -yp_[5] - (R_ / L_) * y_[5] + y_[0]*y_[6] + (y_[1] - y_[3])/L_; + f_[5] = -yp_[5] - (R_ / L_) * y_[5] + y_[0]*y_[6] + (y_[1] - y_[3])/L_; f_[6] = -yp_[6] - (R_ / L_) * y_[6] - y_[0]*y_[5] + (y_[2] - y_[4])/L_; @@ -166,8 +166,6 @@ int MicrogridLine::evaluateAdjointIntegrand() - - // Available template instantiations template class MicrogridLine; template class MicrogridLine; diff --git a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp index 550291ba2..7a4b997ef 100644 --- a/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp +++ b/Examples/ScaleMicrogrid/ScaleMicrogrid.cpp @@ -7,7 +7,6 @@ #include #include -#include "SolutionKeys.hpp" #include #include @@ -21,6 +20,10 @@ using index_type = size_t; using real_type = double; +// Include solution keys for the three test cases here: +#include "SolutionKeys.hpp" + + static int test(index_type Nsize, bool debug_output = false); int main(int argc, char const *argv[]) diff --git a/Examples/ScaleMicrogrid/SolutionKeys.hpp b/Examples/ScaleMicrogrid/SolutionKeys.hpp index b43a42304..3bfb6f449 100644 --- a/Examples/ScaleMicrogrid/SolutionKeys.hpp +++ b/Examples/ScaleMicrogrid/SolutionKeys.hpp @@ -1,507 +1,517 @@ -// All data generated with abstol=1e-12 and reltol=1e-12 with ode23tb Matlab solver +/** + * @file SolutionKeys.hpp + * @author Reid Gomillion (rjg18@vt.edu) + * @author Slaven Peles (peless@ornl.gov) + * @brief Answer keys for Scaled Microgrid test with Nsize = 2, 4, 8 + * + * All data generated with Matlab ode23tb solver with tolerances set to + * abstol=1e-12 and reltol=1e-12. + * + * @note This file is only to be included in ScaleMicrogrid.cpp. It has no + * use anywhere else. + */ + #include -const std::vector answer_key_N2 = {22975.4182636905, - 12753.1173017451, - 0.0376305671131306, - -0.0209815421114537, - 0.0184828563235406, - -0.00015632917065729, - 63.2193617412383, - -29.4226556659582, - 363.420924977355, - -3.01001804456668e-06, - 63.2193618667302, - -35.0920143829141, - -0.00755583999797958, - 22975.8457840701, - 8742.0172166684, - 0.0371009878165673, - -0.0142112776774797, - 0.0187407972932474, - -9.8913852531819e-05, - 62.3296548917654, - -17.9650261562766, - 368.635407345931, - 3.79041261513032e-05, - 62.3296560841534, - -23.7157298601546, - -0.0827401584095097, - 17277.712521392, - 16493.7578328327, - 0.0311645357391787, - -0.0298601153771274, - 0.0225001003469904, - -0.000264388302121386, - 48.6166482764357, - -40.8862612232969, - 355.25957014696, - -0.000167008045114112, - 48.6166481095298, - -46.4283022775928, - -0.0844566209033113, - 17277.2493364959, - 9182.29479881977, - 0.0302503981389185, - -0.0161722538457184, - 0.023180586071601, - -0.000129590157483103, - 47.1906392248137, - -19.3574255862892, - 366.226354188735, - 0.000121054462396047, - 47.19063792117, - -25.0705499054599, - -18.8125403122072, - 21.1471334522508, - 43.2997340692497, - -3.03798323340816, - -44.8715356440453, - 28.9585224749495, - 81.99613295014, - -56.2385627562355, - 132.749774614687, - -82.280664729262, - 311.999576042192, - 357.692287974629, - -5.85078929333349, - 364.119335219897, - -8.84631033126304, - 347.214535767435, - -32.7241067379802, - 360.411028950125, - -34.9283280833745}; +const std::vector answer_key_N2 = {22975.4182636905, + 12753.1173017451, + 0.0376305671131306, + -0.0209815421114537, + 0.0184828563235406, + -0.00015632917065729, + 63.2193617412383, + -29.4226556659582, + 363.420924977355, + -3.01001804456668e-06, + 63.2193618667302, + -35.0920143829141, + -0.00755583999797958, + 22975.8457840701, + 8742.0172166684, + 0.0371009878165673, + -0.0142112776774797, + 0.0187407972932474, + -9.8913852531819e-05, + 62.3296548917654, + -17.9650261562766, + 368.635407345931, + 3.79041261513032e-05, + 62.3296560841534, + -23.7157298601546, + -0.0827401584095097, + 17277.712521392, + 16493.7578328327, + 0.0311645357391787, + -0.0298601153771274, + 0.0225001003469904, + -0.000264388302121386, + 48.6166482764357, + -40.8862612232969, + 355.25957014696, + -0.000167008045114112, + 48.6166481095298, + -46.4283022775928, + -0.0844566209033113, + 17277.2493364959, + 9182.29479881977, + 0.0302503981389185, + -0.0161722538457184, + 0.023180586071601, + -0.000129590157483103, + 47.1906392248137, + -19.3574255862892, + 366.226354188735, + 0.000121054462396047, + 47.19063792117, + -25.0705499054599, + -18.8125403122072, + 21.1471334522508, + 43.2997340692497, + -3.03798323340816, + -44.8715356440453, + 28.9585224749495, + 81.99613295014, + -56.2385627562355, + 132.749774614687, + -82.280664729262, + 311.999576042192, + 357.692287974629, + -5.85078929333349, + 364.119335219897, + -8.84631033126304, + 347.214535767435, + -32.7241067379802, + 360.411028950125, + -34.9283280833745}; -const std::vector answer_key_N4 = {27828.3291148094, - 10602.3611530864, - 0.0452452394028709, - -0.0173410584955486, - 0.018686818367312, - -0.000129595027000909, - 76.0120809944985, - -23.2367034227098, - 366.216582730654, - -0.000167782960864797, - 76.0120710728117, - -28.9413214479885, - -0.0154989336357971, - 27832.0772154743, - 7838.80352597054, - 0.0448129806183038, - -0.0127296381144373, - 0.0188642014642206, - -9.04502393904097e-05, - 75.2859236720964, - -15.4316980534341, - 369.809174828127, - -5.17440472732025e-05, - 75.285919083362, - -21.1922719962368, - -0.142596248886844, - 20950.1519748442, - 16334.3924580166, - 0.0377787488551238, - -0.0295717781600636, - 0.0225780601074885, - -0.000265567743682681, - 58.9348270364006, - -40.4081583028089, - 355.498460539903, - -8.66167274613643e-05, - 58.9348242715342, - -45.9457664944992, - -0.164628885385433, - 20956.2846481359, - 12345.7855779785, - 0.0371673110634281, - -0.0220171188824754, - 0.0229486760225139, - -0.000191111142238558, - 57.9810673844105, - -28.5265491599081, - 361.481100853144, - 8.24481547667206e-05, - 57.9810719040216, - -34.1573355283559, - -0.245126576498858, - 20978.9206932923, - 17875.6825958711, - 0.0380785081131898, - -0.0325621468970297, - 0.0224354615928625, - -0.000295085318936756, - 59.4025243779293, - -45.1101946009202, - 353.186117339098, - 5.52721744209165e-05, - 59.4025238741703, - -50.6117204294148, - -0.253672269778405, - 20990.6142554844, - 11779.5685373245, - 0.0371243965775962, - -0.0209716906203726, - 0.0230016494389548, - -0.000180846578022512, - 57.9140614794815, - -26.8817831662193, - 362.331254349606, - 0.000209247259473183, - 57.9140782926947, - -32.5257339504705, - -0.288747285297145, - 21004.5418902462, - 16686.981801999, - 0.0379131316203435, - -0.0302602142538338, - 0.0225460339603269, - -0.000272422675391038, - 59.1444740212228, - -41.4902940591195, - 354.969993387113, - 8.14114753778542e-05, - 59.1444846638236, - -47.0195494892644, - -0.285876486857154, - 21005.895228757, - 8274.13913126834, - 0.0366267978764156, - -0.0145584209340773, - 0.0233276948336748, - -0.000117627382397687, - 57.1378568500881, - -16.7923279871216, - 367.58883605301, - 0.000263351556352378, - 57.1378679159653, - -22.518140603782, - -6.57009481597077, - 28.1053117219546, - 68.341829672125, - 5.75010361666728, - -7.27398138223966, - 42.3413009908014, - 44.2901915856089, - -0.850144510998897, - -26.9214526328474, - 37.7939474726438, - 20.9421230166698, - -8.2155394685309, - -48.4341275019927, - 37.706248875936, - 82.5460878639016, - -57.0458911301263, - 127.388509162578, - -90.4406093871607, - 116.522583626035, - -102.149734009655, - 112.650118587972, - -107.825883544914, - 311.543402422187, - 360.780248808368, - -7.42039816792328, - 365.078323407317, - -13.2331839185884, - 344.46378568747, - -54.5546252592288, - 350.335287885457, - -63.572021962256, - 334.342198258035, - -88.749585714325, - 344.281369936645, - -94.7726681838823, - 332.2248206198, - -103.942854393111, - 347.103721199815, - -107.812479611979 - }; +const std::vector answer_key_N4 = {27828.3291148094, + 10602.3611530864, + 0.0452452394028709, + -0.0173410584955486, + 0.018686818367312, + -0.000129595027000909, + 76.0120809944985, + -23.2367034227098, + 366.216582730654, + -0.000167782960864797, + 76.0120710728117, + -28.9413214479885, + -0.0154989336357971, + 27832.0772154743, + 7838.80352597054, + 0.0448129806183038, + -0.0127296381144373, + 0.0188642014642206, + -9.04502393904097e-05, + 75.2859236720964, + -15.4316980534341, + 369.809174828127, + -5.17440472732025e-05, + 75.285919083362, + -21.1922719962368, + -0.142596248886844, + 20950.1519748442, + 16334.3924580166, + 0.0377787488551238, + -0.0295717781600636, + 0.0225780601074885, + -0.000265567743682681, + 58.9348270364006, + -40.4081583028089, + 355.498460539903, + -8.66167274613643e-05, + 58.9348242715342, + -45.9457664944992, + -0.164628885385433, + 20956.2846481359, + 12345.7855779785, + 0.0371673110634281, + -0.0220171188824754, + 0.0229486760225139, + -0.000191111142238558, + 57.9810673844105, + -28.5265491599081, + 361.481100853144, + 8.24481547667206e-05, + 57.9810719040216, + -34.1573355283559, + -0.245126576498858, + 20978.9206932923, + 17875.6825958711, + 0.0380785081131898, + -0.0325621468970297, + 0.0224354615928625, + -0.000295085318936756, + 59.4025243779293, + -45.1101946009202, + 353.186117339098, + 5.52721744209165e-05, + 59.4025238741703, + -50.6117204294148, + -0.253672269778405, + 20990.6142554844, + 11779.5685373245, + 0.0371243965775962, + -0.0209716906203726, + 0.0230016494389548, + -0.000180846578022512, + 57.9140614794815, + -26.8817831662193, + 362.331254349606, + 0.000209247259473183, + 57.9140782926947, + -32.5257339504705, + -0.288747285297145, + 21004.5418902462, + 16686.981801999, + 0.0379131316203435, + -0.0302602142538338, + 0.0225460339603269, + -0.000272422675391038, + 59.1444740212228, + -41.4902940591195, + 354.969993387113, + 8.14114753778542e-05, + 59.1444846638236, + -47.0195494892644, + -0.285876486857154, + 21005.895228757, + 8274.13913126834, + 0.0366267978764156, + -0.0145584209340773, + 0.0233276948336748, + -0.000117627382397687, + 57.1378568500881, + -16.7923279871216, + 367.58883605301, + 0.000263351556352378, + 57.1378679159653, + -22.518140603782, + -6.57009481597077, + 28.1053117219546, + 68.341829672125, + 5.75010361666728, + -7.27398138223966, + 42.3413009908014, + 44.2901915856089, + -0.850144510998897, + -26.9214526328474, + 37.7939474726438, + 20.9421230166698, + -8.2155394685309, + -48.4341275019927, + 37.706248875936, + 82.5460878639016, + -57.0458911301263, + 127.388509162578, + -90.4406093871607, + 116.522583626035, + -102.149734009655, + 112.650118587972, + -107.825883544914, + 311.543402422187, + 360.780248808368, + -7.42039816792328, + 365.078323407317, + -13.2331839185884, + 344.46378568747, + -54.5546252592288, + 350.335287885457, + -63.572021962256, + 334.342198258035, + -88.749585714325, + 344.281369936645, + -94.7726681838823, + 332.2248206198, + -103.942854393111, + 347.103721199815, + -107.812479611979}; -const std::vector answer_key_N8 = {29266.6517718661, - 9842.93617289812, - 0.0475360674334622, - -0.0160323945316821, - 0.0187557247105805, - -0.000119821248231538, - 79.8612117213119, - -21.0144010498971, - 367.201497494684, - -0.00135963018489767, - 79.8611351716573, - -26.7318789917162, - -0.018074876389402, - 29296.9645459408, - 7415.51099954903, - 0.0471789367393934, - -0.0120180219897291, - 0.0189117902285582, - -8.57914733703415e-05, - 79.2614266664798, - -14.2194852461262, - 370.357116139458, - -0.00065261697325357, - 79.261388452934, - -19.9860446882469, - -0.161178046356866, - 22178.7337755581, - 15750.48869542, - 0.0399575496599213, - -0.028431003000158, - 0.0226540351215628, - -0.000255811047442045, - 62.3338080750298, - -38.6061338491152, - 356.372404460464, - -0.000888421043595241, - 62.3337589017493, - -44.1546192236143, - -0.191206982234175, - 22245.3587939821, - 12476.0312983393, - 0.0395296431152022, - -0.0222832972915751, - 0.0229591349358969, - -0.000195357283522886, - 61.6667253463805, - -28.9363062720176, - 361.284131747149, - 0.000606091049765824, - 61.6667589580497, - -34.5611135316627, - -0.300475535038271, - 22471.354929649, - 17410.9400696732, - 0.0407475331761201, - -0.0316496339533813, - 0.0225047347006168, - -0.000287941144857336, - 63.5662158978541, - -43.6654709736205, - 353.882194971394, - -0.00050508442766251, - 63.5661867600733, - -49.1745383652835, - -0.321406735230742, - 22562.1063953332, - 12532.040739496, - 0.0400730650460856, - -0.0224103188019356, - 0.0229590093469276, - -0.000197040279593967, - 62.5145400797163, - -29.1337602252211, - 361.200953962968, - 0.00123813270414561, - 62.5146115608051, - -34.7565572443792, - -0.398765881347133, - 22822.9625175864, - 17526.9123376124, - 0.0413769691613727, - -0.0318846988884131, - 0.0224996948233429, - -0.000290724959665147, - 64.5480523645119, - -44.0326735095454, - 353.709220392926, - -0.000255137918253834, - 64.548036917491, - -49.5382706457328, - -0.409294621792759, - 22917.4640781459, - 11700.1980576741, - 0.0405370737861658, - -0.0208717910251266, - 0.0230419643488667, - -0.000182321342412399, - 63.2383663569188, - -26.7111380754575, - 362.449323338104, - 0.00143605100750772, - 63.2384503029344, - -32.3525635247183, - -0.460038982115987, - 23175.0870418607, - 17429.0372806116, - 0.0419717095772374, - -0.0317010913432995, - 0.0225145433123769, - -0.000289381352876061, - 65.4757968347883, - -43.7415548084125, - 353.856643943042, - -0.000116590766441278, - 65.4757901489451, - -49.2486679790579, - -0.461848591689221, - 23264.6732405303, - 10919.0360806903, - 0.0409947737541995, - -0.0194331296392293, - 0.0231200668519233, - -0.000168575863901554, - 63.9522672718067, - -24.4455560147541, - 363.621937642842, - 0.00154556746783549, - 63.9523565934322, - -30.1044436917781, - -0.491529580804623, - 23488.6137650364, - 17313.8654584652, - 0.0424952351974662, - -0.0314883547842804, - 0.0225303364455447, - -0.000287714847080755, - 66.2924442955506, - -43.4048501801219, - 354.030311475628, - 0.000169934086992562, - 66.2924545883603, - -48.9139721676174, - -0.486548093474613, - 23557.6136117665, - 10241.0790360359, - 0.0413774884672506, - -0.0181860120867723, - 0.0231877453638413, - -0.000156639599075328, - 64.5492156984859, - -22.4816084883194, - 364.639179755733, - 0.00142420279185394, - 64.5492984953198, - -28.1556597465189, - -0.499726325044563, - 23722.4168131373, - 16958.7765974266, - 0.0428487548646152, - -0.0308090857078185, - 0.0225672437721518, - -0.000281355782039133, - 66.8440182379463, - -42.3350991467661, - 354.562942832682, - 0.000573219240561573, - 66.844044569212, - -47.8519918014414, - -0.490219448053285, - 23769.8747006891, - 9267.5206785042, - 0.0415639300026818, - -0.0164109903099032, - 0.0232814268213158, - -0.000139385907988285, - 64.8399200066663, - -19.6874999818575, - 366.100410278813, - 0.00128332197988872, - 64.8400012051758, - -25.3838027935624, - -0.491586583798841, - 23854.0240861864, - 15160.7060140903, - 0.0427385845553072, - -0.0273659210853948, - 0.0227360281885303, - -0.00024756822257102, - 66.6722121992594, - -36.9193366680176, - 357.260483774461, - 0.000734666517031364, - 66.6722602990682, - -42.4779079553274, - -0.482907936930927, - 23870.5548740189, - 6166.60742794455, - 0.0412253604361869, - -0.0108406830677542, - 0.0235710268609798, - -8.45378382385454e-05, - 64.3117067426907, - -10.9219886629635, - 370.751596332923, - 0.00130490570318174, - 64.3117765573399, - -16.6904284244068, - -2.9267653635869, - 30.5878043390112, - 75.9238910016987, - 9.17392754248112, - 4.3701560041079, - 48.7765765968327, - 58.3101300775815, - 3.13323809951331, - -6.37573932293514, - 46.1701408549949, - 41.9244199648313, - -6.5432868117422, - -17.3691293511209, - 41.8611610718482, - 27.7383173553277, - -12.9709065074016, - -27.5322418670623, - 38.9032728624808, - 16.2733736528389, - -16.5280348065045, - -36.4800564569504, - 37.0627808819117, - 7.38198504755967, - -17.9899033675727, - -44.0731708800056, - 36.9539474625741, - 1.14781892918688, - -15.9507601441003, - -49.1751072411967, - 44.6278268007059, - 82.7517114852138, - -57.3188928805757, - 125.959171148664, - -93.1822145893453, - 110.816672146529, - -108.811406393296, - 99.5107131550674, - -119.104827911048, - 92.0427992280762, - -125.056967118294, - 88.0811872722293, - -127.985464658329, - 87.1649116220972, - -128.957730829954, - 89.0189233593932, - -129.480383815729, - 311.408200092424, - 361.890500304156, - -7.90450151715305, - 365.594288034004, - -14.6504114199963, - 344.278948204657, - -61.517809887448, - 348.104769580715, - -73.1715704285651, - 329.472137794467, - -107.797643650827, - 335.509251816504, - -117.787067889008, - 317.044841017058, - -139.602945170765, - 325.182412285621, - -147.51178633583, - 307.989533967543, - -158.91998673915, - 318.171184823086, - -165.141414351062, - 302.951769665185, - -168.712626964975, - 315.009688292198, - -173.624287308414, - 302.070219389208, - -171.572667424371, - 315.86470341008, - -175.706947618597, - 306.288884765777, - -170.785573848562, - 322.018589824395, - -176.179397251772 - }; \ No newline at end of file +const std::vector answer_key_N8 = {29266.6517718661, + 9842.93617289812, + 0.0475360674334622, + -0.0160323945316821, + 0.0187557247105805, + -0.000119821248231538, + 79.8612117213119, + -21.0144010498971, + 367.201497494684, + -0.00135963018489767, + 79.8611351716573, + -26.7318789917162, + -0.018074876389402, + 29296.9645459408, + 7415.51099954903, + 0.0471789367393934, + -0.0120180219897291, + 0.0189117902285582, + -8.57914733703415e-05, + 79.2614266664798, + -14.2194852461262, + 370.357116139458, + -0.00065261697325357, + 79.261388452934, + -19.9860446882469, + -0.161178046356866, + 22178.7337755581, + 15750.48869542, + 0.0399575496599213, + -0.028431003000158, + 0.0226540351215628, + -0.000255811047442045, + 62.3338080750298, + -38.6061338491152, + 356.372404460464, + -0.000888421043595241, + 62.3337589017493, + -44.1546192236143, + -0.191206982234175, + 22245.3587939821, + 12476.0312983393, + 0.0395296431152022, + -0.0222832972915751, + 0.0229591349358969, + -0.000195357283522886, + 61.6667253463805, + -28.9363062720176, + 361.284131747149, + 0.000606091049765824, + 61.6667589580497, + -34.5611135316627, + -0.300475535038271, + 22471.354929649, + 17410.9400696732, + 0.0407475331761201, + -0.0316496339533813, + 0.0225047347006168, + -0.000287941144857336, + 63.5662158978541, + -43.6654709736205, + 353.882194971394, + -0.00050508442766251, + 63.5661867600733, + -49.1745383652835, + -0.321406735230742, + 22562.1063953332, + 12532.040739496, + 0.0400730650460856, + -0.0224103188019356, + 0.0229590093469276, + -0.000197040279593967, + 62.5145400797163, + -29.1337602252211, + 361.200953962968, + 0.00123813270414561, + 62.5146115608051, + -34.7565572443792, + -0.398765881347133, + 22822.9625175864, + 17526.9123376124, + 0.0413769691613727, + -0.0318846988884131, + 0.0224996948233429, + -0.000290724959665147, + 64.5480523645119, + -44.0326735095454, + 353.709220392926, + -0.000255137918253834, + 64.548036917491, + -49.5382706457328, + -0.409294621792759, + 22917.4640781459, + 11700.1980576741, + 0.0405370737861658, + -0.0208717910251266, + 0.0230419643488667, + -0.000182321342412399, + 63.2383663569188, + -26.7111380754575, + 362.449323338104, + 0.00143605100750772, + 63.2384503029344, + -32.3525635247183, + -0.460038982115987, + 23175.0870418607, + 17429.0372806116, + 0.0419717095772374, + -0.0317010913432995, + 0.0225145433123769, + -0.000289381352876061, + 65.4757968347883, + -43.7415548084125, + 353.856643943042, + -0.000116590766441278, + 65.4757901489451, + -49.2486679790579, + -0.461848591689221, + 23264.6732405303, + 10919.0360806903, + 0.0409947737541995, + -0.0194331296392293, + 0.0231200668519233, + -0.000168575863901554, + 63.9522672718067, + -24.4455560147541, + 363.621937642842, + 0.00154556746783549, + 63.9523565934322, + -30.1044436917781, + -0.491529580804623, + 23488.6137650364, + 17313.8654584652, + 0.0424952351974662, + -0.0314883547842804, + 0.0225303364455447, + -0.000287714847080755, + 66.2924442955506, + -43.4048501801219, + 354.030311475628, + 0.000169934086992562, + 66.2924545883603, + -48.9139721676174, + -0.486548093474613, + 23557.6136117665, + 10241.0790360359, + 0.0413774884672506, + -0.0181860120867723, + 0.0231877453638413, + -0.000156639599075328, + 64.5492156984859, + -22.4816084883194, + 364.639179755733, + 0.00142420279185394, + 64.5492984953198, + -28.1556597465189, + -0.499726325044563, + 23722.4168131373, + 16958.7765974266, + 0.0428487548646152, + -0.0308090857078185, + 0.0225672437721518, + -0.000281355782039133, + 66.8440182379463, + -42.3350991467661, + 354.562942832682, + 0.000573219240561573, + 66.844044569212, + -47.8519918014414, + -0.490219448053285, + 23769.8747006891, + 9267.5206785042, + 0.0415639300026818, + -0.0164109903099032, + 0.0232814268213158, + -0.000139385907988285, + 64.8399200066663, + -19.6874999818575, + 366.100410278813, + 0.00128332197988872, + 64.8400012051758, + -25.3838027935624, + -0.491586583798841, + 23854.0240861864, + 15160.7060140903, + 0.0427385845553072, + -0.0273659210853948, + 0.0227360281885303, + -0.00024756822257102, + 66.6722121992594, + -36.9193366680176, + 357.260483774461, + 0.000734666517031364, + 66.6722602990682, + -42.4779079553274, + -0.482907936930927, + 23870.5548740189, + 6166.60742794455, + 0.0412253604361869, + -0.0108406830677542, + 0.0235710268609798, + -8.45378382385454e-05, + 64.3117067426907, + -10.9219886629635, + 370.751596332923, + 0.00130490570318174, + 64.3117765573399, + -16.6904284244068, + -2.9267653635869, + 30.5878043390112, + 75.9238910016987, + 9.17392754248112, + 4.3701560041079, + 48.7765765968327, + 58.3101300775815, + 3.13323809951331, + -6.37573932293514, + 46.1701408549949, + 41.9244199648313, + -6.5432868117422, + -17.3691293511209, + 41.8611610718482, + 27.7383173553277, + -12.9709065074016, + -27.5322418670623, + 38.9032728624808, + 16.2733736528389, + -16.5280348065045, + -36.4800564569504, + 37.0627808819117, + 7.38198504755967, + -17.9899033675727, + -44.0731708800056, + 36.9539474625741, + 1.14781892918688, + -15.9507601441003, + -49.1751072411967, + 44.6278268007059, + 82.7517114852138, + -57.3188928805757, + 125.959171148664, + -93.1822145893453, + 110.816672146529, + -108.811406393296, + 99.5107131550674, + -119.104827911048, + 92.0427992280762, + -125.056967118294, + 88.0811872722293, + -127.985464658329, + 87.1649116220972, + -128.957730829954, + 89.0189233593932, + -129.480383815729, + 311.408200092424, + 361.890500304156, + -7.90450151715305, + 365.594288034004, + -14.6504114199963, + 344.278948204657, + -61.517809887448, + 348.104769580715, + -73.1715704285651, + 329.472137794467, + -107.797643650827, + 335.509251816504, + -117.787067889008, + 317.044841017058, + -139.602945170765, + 325.182412285621, + -147.51178633583, + 307.989533967543, + -158.91998673915, + 318.171184823086, + -165.141414351062, + 302.951769665185, + -168.712626964975, + 315.009688292198, + -173.624287308414, + 302.070219389208, + -171.572667424371, + 315.86470341008, + -175.706947618597, + 306.288884765777, + -170.785573848562, + 322.018589824395, + -176.179397251772};