Skip to content

Commit 0780266

Browse files
committed
Update code style for GENROU model and example.
1 parent 2fc06cd commit 0780266

File tree

3 files changed

+454
-374
lines changed

3 files changed

+454
-374
lines changed
Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,85 @@
1-
#include "example1.hpp"
1+
#include <stdio.h>
2+
#define _USE_MATH_DEFINES
3+
#include <math.h>
4+
#include <time.h>
5+
6+
// #include <sundials_core.h>
7+
#include <idas/idas.h>
8+
#include <nvector/nvector_serial.h>
9+
#include <sunlinsol/sunlinsol_dense.h>
10+
#include <sunlinsol/sunlinsol_klu.h>
11+
#include <sunmatrix/sunmatrix_sparse.h>
12+
13+
#include "Model/PhasorDynamics/Branch/Branch.cpp"
14+
#include "Model/PhasorDynamics/Branch/Branch.hpp"
15+
#include "Model/PhasorDynamics/Bus/Bus.cpp"
16+
#include "Model/PhasorDynamics/Bus/Bus.hpp"
17+
#include "Model/PhasorDynamics/Bus/BusInfinite.cpp"
18+
#include "Model/PhasorDynamics/Bus/BusInfinite.hpp"
19+
#include "Model/PhasorDynamics/BusFault/BusFault.hpp"
20+
#include "Model/PhasorDynamics/SynchronousMachine/GENROUwS/GENROU.hpp"
21+
#include "Model/PhasorDynamics/SystemModel.hpp"
22+
#include "Solver/Dynamic/Ida.cpp"
23+
#include "Solver/Dynamic/Ida.hpp"
224

325
#define _CRT_SECURE_NO_WARNINGS
426

5-
using namespace GridKit::PhasorDynamics;
6-
using namespace AnalysisManager::Sundials;
727

828
int main()
929
{
10-
printf("Example 1 version 2\n");
11-
12-
/* Create model parts */
13-
SystemModel<double, size_t> sys;
14-
Bus<double, size_t> bus1(0.9949877346411762, 0.09999703952427966);
15-
BusInfinite<double, size_t> bus2(1.0, 0.0);
16-
Branch<double, size_t> branch(&bus1, &bus2, 0, 0.1, 0, 0);
17-
BusFault fault(&bus1, 0, 1e-3, 0);
18-
GENROU gen(&bus1, 1, 1, 0.05013, 3, 0, 0, 7, .04, .05, .75, 2.1, 0.2, 0.18,
19-
0.5, 0.5, 0.18, 0.15, 0, 0);
20-
21-
/* Connect everything together */
22-
sys.addBus(&bus1);
23-
sys.addBus(&bus2);
24-
sys.addComponent(&branch);
25-
sys.addComponent(&fault);
26-
sys.addComponent(&gen);
27-
sys.allocate();
28-
29-
double dt = 1.0/4.0/60.0;
30-
31-
/* Output file header */
32-
FILE *f = fopen("example1_v2_results.csv", "w");
33-
if (!f) printf("ERROR writing to output file!\n");
34-
fprintf(f, "%s,%s", "t", "IDA Return Value");
35-
for (int i = 0; i < sys.size(); ++i) fprintf(f, ",Y[%d]", i);
36-
for (int i = 0; i < sys.size(); ++i) fprintf(f, ",Yp[%d]", i);
37-
fprintf(f, "\n");
38-
39-
/* Set up simulation */
40-
Ida<double, size_t> ida(&sys);
41-
ida.configureSimulation();
42-
43-
/* Run simulation */
44-
double start = (double) clock();
45-
ida.printOutputF(0, 0, f);
46-
ida.initializeSimulation(0, false);
47-
ida.runSimulationFixed(0, dt, 1, f);
48-
fault.setStatus(1);
49-
ida.initializeSimulation(1, false);
50-
ida.runSimulationFixed(1, dt, 1.1, f);
51-
fault.setStatus(0);
52-
ida.initializeSimulation(1.1, false);
53-
ida.runSimulationFixed(1.1, dt, 30, f);
54-
55-
printf("Complete in %.4g seconds\n", (clock() - start) / CLOCKS_PER_SEC);
56-
fclose(f);
57-
58-
return 0;
30+
using namespace GridKit::PhasorDynamics;
31+
using namespace AnalysisManager::Sundials;
32+
33+
printf("Example 1 version 2\n");
34+
35+
/* Create model parts */
36+
SystemModel<double, size_t> sys;
37+
Bus<double, size_t> bus1(0.9949877346411762, 0.09999703952427966);
38+
BusInfinite<double, size_t> bus2(1.0, 0.0);
39+
Branch<double, size_t> branch(&bus1, &bus2, 0, 0.1, 0, 0);
40+
BusFault fault(&bus1, 0, 1e-3, 0);
41+
42+
GENROU gen(&bus1, 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);
43+
44+
/* Connect everything together */
45+
sys.addBus(&bus1);
46+
sys.addBus(&bus2);
47+
sys.addComponent(&branch);
48+
sys.addComponent(&fault);
49+
sys.addComponent(&gen);
50+
sys.allocate();
51+
52+
double dt = 1.0 / 4.0 / 60.0;
53+
54+
/* Output file header */
55+
FILE* f = fopen("example1_v2_results.csv", "w");
56+
if (!f)
57+
printf("ERROR writing to output file!\n");
58+
fprintf(f, "%s,%s", "t", "IDA Return Value");
59+
for (int i = 0; i < sys.size(); ++i)
60+
fprintf(f, ",Y[%d]", i);
61+
for (int i = 0; i < sys.size(); ++i)
62+
fprintf(f, ",Yp[%d]", i);
63+
fprintf(f, "\n");
64+
65+
/* Set up simulation */
66+
Ida<double, size_t> ida(&sys);
67+
ida.configureSimulation();
68+
69+
/* Run simulation */
70+
double start = (double) clock();
71+
ida.printOutputF(0, 0, f);
72+
ida.initializeSimulation(0.0, false);
73+
ida.runSimulationFixed(0.0, dt, 1.0, f);
74+
fault.setStatus(1);
75+
ida.initializeSimulation(1.0, false);
76+
ida.runSimulationFixed(1.0, dt, 1.1, f);
77+
fault.setStatus(0);
78+
ida.initializeSimulation(1.1, false);
79+
ida.runSimulationFixed(1.1, dt, 10.0, f);
80+
81+
printf("Complete in %.4g seconds\n", (clock() - start) / CLOCKS_PER_SEC);
82+
fclose(f);
5983

84+
return 0;
6085
}

examples/PhasorDynamics/Example1/example1.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)