-
Notifications
You must be signed in to change notification settings - Fork 5
Unit test and example for Genrou
class.
#85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
15064d0
Needed to compile for me
abirchfield d120d24
Unit test for gen residual
abirchfield c0b3886
Unit test for genrou residual
abirchfield 9256328
Working 3-bus example, bug in Load
abirchfield 47d4b83
Apply pre-commmit fixes
pelesh c67d2c2
Minor improvements to Genrou example 2 and unit test.
pelesh fa42468
Apply pre-commmit fixes
pelesh 84ad0da
Fix linking of Genrou examples.
pelesh e76100b
Apply pre-commmit fixes
pelesh 6c120f2
Accounted for load bug in docs and test
abirchfield c924d5a
Apply pre-commmit fixes
abirchfield 828e780
Align with GridKit style guidelines.
pelesh 1b88ca5
Apply pre-commmit fixes
pelesh 091bc86
Clean up example 1.
pelesh 7e1a96e
Minimal documentation for tests and examples.
pelesh f9a4f79
Apply pre-commmit fixes
pelesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
|
||
#define _USE_MATH_DEFINES | ||
#include <cmath> | ||
#include <filesystem> | ||
#include <fstream> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* | ||
*/ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include <cmath> | ||
#include <filesystem> | ||
#include <fstream> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
|
||
#define _USE_MATH_DEFINES | ||
#include <cmath> | ||
#include <filesystem> | ||
#include <fstream> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(Example1) | ||
add_subdirectory(Example2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
add_executable(phasordynamics_example2 example2.cpp) | ||
target_link_libraries(phasordynamics_example2 | ||
GRIDKIT::phasor_dynamics_bus | ||
GRIDKIT::phasor_dynamics_bus_fault | ||
GRIDKIT::phasor_dynamics_branch | ||
GRIDKIT::phasor_dynamics_genrou | ||
GRIDKIT::phasor_dynamics_load | ||
SUNDIALS::sunlinsolklu | ||
SUNDIALS::core | ||
SUNDIALS::ida | ||
SUNDIALS::idas | ||
SUNDIALS::sunmatrixdense) | ||
install(TARGETS phasordynamics_example2 RUNTIME DESTINATION bin) | ||
|
||
add_test(NAME GenrouTest COMMAND $<TARGET_FILE:phasordynamics_example2>) |
2,406 changes: 2,406 additions & 0 deletions
2,406
examples/PhasorDynamics/Example2/Example2_Powerworld_Reference.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include <stdio.h> | ||
#define _USE_MATH_DEFINES | ||
#include <math.h> | ||
#include <time.h> | ||
|
||
// #include <sundials_core.h> | ||
#include <idas/idas.h> | ||
#include <nvector/nvector_serial.h> | ||
#include <sunlinsol/sunlinsol_dense.h> | ||
#include <sunlinsol/sunlinsol_klu.h> | ||
#include <sunmatrix/sunmatrix_sparse.h> | ||
|
||
#include "Example2_Powerworld_Reference.hpp" | ||
#include "Model/PhasorDynamics/Branch/Branch.cpp" | ||
#include "Model/PhasorDynamics/Branch/Branch.hpp" | ||
#include "Model/PhasorDynamics/Bus/Bus.cpp" | ||
#include "Model/PhasorDynamics/Bus/Bus.hpp" | ||
#include "Model/PhasorDynamics/Bus/BusInfinite.cpp" | ||
#include "Model/PhasorDynamics/Bus/BusInfinite.hpp" | ||
#include "Model/PhasorDynamics/BusFault/BusFault.hpp" | ||
#include "Model/PhasorDynamics/Load/Load.hpp" | ||
#include "Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.hpp" | ||
#include "Model/PhasorDynamics/SystemModel.hpp" | ||
#include "Solver/Dynamic/Ida.cpp" | ||
#include "Solver/Dynamic/Ida.hpp" | ||
#include <Utilities/Testing.hpp> | ||
|
||
#define _CRT_SECURE_NO_WARNINGS | ||
|
||
int main() | ||
{ | ||
using namespace GridKit::PhasorDynamics; | ||
using namespace AnalysisManager::Sundials; | ||
|
||
printf("Example 2 version 1\n"); | ||
|
||
/* Create model parts */ | ||
SystemModel<double, size_t> sys; | ||
BusInfinite<double, size_t> bus1(1.06, 0.0); | ||
Bus<double, size_t> bus2(1.0599558398065716, -0.009675621941024773); | ||
Bus<double, size_t> bus3(0.9610827543495831, -0.13122476630506485); | ||
Branch<double, size_t> branch12(&bus1, &bus2, 0.05, 0.21, 0, 0.1); | ||
Branch<double, size_t> branch13(&bus1, &bus3, 0.06, 0.15, 0, 0.12); | ||
Branch<double, size_t> branch23(&bus2, &bus3, 0.08, 0.27, 0, 0.45); | ||
Genrou<double, size_t> gen2(&bus2, 1, 0.5, -0.07588, 2.7, 0., 0., 7., .04, .05, .75, 1.9, 0.17, 0.15, 0.4, 0.35, 0.15, 0.14999, 0., 0.); | ||
Genrou<double, size_t> gen3(&bus3, 1, 0.25, 0.26587, 1.6, 0., 0., 7.5, .04, .05, .75, 2.3, 0.2, 0.18, 0.5, 0.5, 0.18, 0.15, 0., 0.); | ||
// Genrou<double, size_t> gen3(&bus3, 1, 0.25, 0.26587, 1.6, 0, 0, 7.5, .04, | ||
// .05, .75, 2.3, 0.2, 0.18, 0.5, 0.5, 0.18, 0.15, 0, 0); | ||
// Genrou<double, size_t> gen3(&bus3, 1, 1., 0.05013, 3., 0., 0., 7., .04, | ||
// .05, .75, 2.1, 0.2, 0.18, 0.5, 0.5, 0.18, 0.15, 0., 0.); | ||
Load<double, size_t> load3(&bus3, 0.4447197839297772, 0.20330047265361242); | ||
BusFault<double, size_t> fault(&bus3, 0, 1e-5, 0); | ||
|
||
/* Connect everything together */ | ||
sys.addBus(&bus1); | ||
sys.addBus(&bus2); | ||
sys.addBus(&bus3); | ||
sys.addComponent(&branch12); | ||
sys.addComponent(&branch13); | ||
sys.addComponent(&branch23); | ||
sys.addComponent(&fault); | ||
sys.addComponent(&load3); | ||
sys.addComponent(&gen2); | ||
sys.addComponent(&gen3); | ||
sys.allocate(); | ||
/*sys.initialize(); | ||
sys.tagDifferentiable(); | ||
sys.evaluateResidual(); | ||
for (int i = 0; i< 46; ++i) | ||
{ | ||
printf("%d %g %g %g\n", i, sys.y()[i], sys.yp()[i], sys.getResidual()[i]); | ||
}*/ | ||
|
||
double dt = 1.0 / 4.0 / 60.0; | ||
|
||
std::stringstream buffer; | ||
|
||
/* Set up simulation */ | ||
Ida<double, size_t> ida(&sys); | ||
ida.configureSimulation(); | ||
|
||
/* Run simulation */ | ||
double start = static_cast<double>(clock()); | ||
// ida.printOutputF(0, 0, buffer); | ||
ida.initializeSimulation(0.0, false); | ||
ida.runSimulationFixed(0.0, dt, 1.0, buffer); | ||
fault.setStatus(1); | ||
ida.initializeSimulation(1.0, false); | ||
ida.runSimulationFixed(1.0, dt, 1.1, buffer); | ||
fault.setStatus(0); | ||
ida.initializeSimulation(1.1, false); | ||
ida.runSimulationFixed(1.1, dt, 10.0, buffer); | ||
double stop = static_cast<double>(clock()); | ||
|
||
/* Check worst-case error */ | ||
double worst_error = 0; | ||
double worst_error_time = 0; | ||
|
||
int i, j; | ||
const int stride = 94; | ||
const int nt = 2401; | ||
double results[stride]; | ||
buffer.seekg(0, std::ios::beg); | ||
FILE* f = fopen("example2_results.csv", "w"); | ||
fprintf(f, "Time,gen2speed,gen3speed,v2mag,v3mag\n"); | ||
fprintf(f, "0,1,1,1,1\n"); | ||
alexander-novo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (i = 0; i < nt - 1; ++i) | ||
{ | ||
for (j = 0; j < stride; ++j) | ||
buffer >> results[j]; | ||
alexander-novo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// for (j = 0; j < stride; ++j) printf("%d %d %g\n", i, j, results[j]); | ||
double t = results[0]; | ||
double tref = reference_solution[i + 1][0]; | ||
// printf("Time GridKit %g PowerWorld %g\n", t, tref); | ||
double gen2speed = 1 + results[7]; | ||
double gen2speed_ref = reference_solution[i + 1][1]; | ||
double gen3speed = 1 + results[28]; | ||
double gen3speed_ref = reference_solution[i + 1][2]; | ||
double v2mag = sqrt(results[2] * results[2] + results[3] * results[3]); | ||
double v2mag_ref = reference_solution[i + 1][4]; | ||
double v3mag = sqrt(results[4] * results[4] + results[5] * results[5]); | ||
double v3mag_ref = reference_solution[i + 1][5]; | ||
fprintf(f, "%g,%g,%g,%g,%g\n", t, gen2speed, gen3speed, v2mag, v3mag); | ||
double err = fmax(fmax(fabs(gen2speed - gen2speed_ref), | ||
fabs(gen3speed - gen3speed_ref)), | ||
fmax(fabs(v2mag - v2mag_ref), | ||
fabs(v3mag - v3mag_ref))); | ||
if (err > worst_error) | ||
{ | ||
worst_error = err; | ||
worst_error_time = t; | ||
} | ||
// printf("%g %g %g %g\n", gen2speed, gen3speed, v2mag, v3mag); | ||
// printf("%g %g %g %g\n", gen2speed_ref, gen3speed_ref, v2mag_ref, v3mag_ref); | ||
} | ||
fclose(f); | ||
|
||
printf("Worst error %g at time t=%g\n", worst_error, worst_error_time); | ||
|
||
std::cout << "\n\nComplete in " << (stop - start) / CLOCKS_PER_SEC << " seconds\n"; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
|
||
#define _USE_MATH_DEFINES | ||
#include <cmath> | ||
#include <filesystem> | ||
#include <fstream> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* | ||
*/ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "Genrou.hpp" | ||
|
||
#include <cmath> | ||
|
2 changes: 2 additions & 0 deletions
2
src/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "SynchronousMachine.hpp" | ||
|
||
#include <cmath> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "Generator2.hpp" | ||
|
||
#include <cmath> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "Generator4.hpp" | ||
|
||
#include <cmath> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
* | ||
*/ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "Generator4Governor.hpp" | ||
|
||
#include <cmath> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
#define _USE_MATH_DEFINES | ||
#include "Generator4Param.hpp" | ||
|
||
#include <cmath> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.