Skip to content

Commit 19ee3cc

Browse files
peleshactions-user
authored andcommitted
Apply pre-commmit fixes
1 parent 0780266 commit 19ee3cc

File tree

9 files changed

+157
-123
lines changed

9 files changed

+157
-123
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ if(GRIDKIT_ENABLE_ENZYME)
8080
add_subdirectory(Enzyme)
8181
endif()
8282

83-
add_subdirectory(PhasorDynamics)
83+
add_subdirectory(PhasorDynamics)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_subdirectory(Example1)
1+
add_subdirectory(Example1)

examples/PhasorDynamics/Example1/example1.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#define _CRT_SECURE_NO_WARNINGS
2626

27-
2827
int main()
2928
{
3029
using namespace GridKit::PhasorDynamics;
@@ -82,4 +81,4 @@ int main()
8281
fclose(f);
8382

8483
return 0;
85-
}
84+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "BusFault.hpp"
1+
#include "BusFault.hpp"
Lines changed: 125 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,150 @@
11
/* Bus Fault Component - Adam Birchfield */
22
#pragma once
33

4-
#include <Model/PhasorDynamics/Component.hpp>
54
#include <Model/PhasorDynamics/BusBase.hpp>
5+
#include <Model/PhasorDynamics/Component.hpp>
66

77
namespace GridKit
88
{
9-
namespace PhasorDynamics
10-
{
9+
namespace PhasorDynamics
10+
{
1111
using ComponentT = Component<double, size_t>;
12-
using BaseBusT = BusBase<double, size_t>;
12+
using BaseBusT = BusBase<double, size_t>;
1313

1414
class BusFault : public ComponentT
1515
{
16-
using ComponentT::size_;
17-
using ComponentT::nnz_;
18-
using ComponentT::time_;
19-
using ComponentT::alpha_;
20-
using ComponentT::y_;
21-
using ComponentT::yp_;
22-
using ComponentT::tag_;
23-
using ComponentT::f_;
24-
using ComponentT::g_;
25-
using ComponentT::yB_;
26-
using ComponentT::ypB_;
27-
using ComponentT::fB_;
28-
using ComponentT::gB_;
29-
using ComponentT::param_;
30-
16+
using ComponentT::alpha_;
17+
using ComponentT::f_;
18+
using ComponentT::fB_;
19+
using ComponentT::g_;
20+
using ComponentT::gB_;
21+
using ComponentT::nnz_;
22+
using ComponentT::param_;
23+
using ComponentT::size_;
24+
using ComponentT::tag_;
25+
using ComponentT::time_;
26+
using ComponentT::y_;
27+
using ComponentT::yB_;
28+
using ComponentT::yp_;
29+
using ComponentT::ypB_;
3130

3231
public:
33-
BusFault(BaseBusT* bus) : bus_(bus), R_(0), X_(0.01),
34-
status_(0), busID_(0)
32+
BusFault(BaseBusT* bus)
33+
: bus_(bus), R_(0), X_(0.01), status_(0), busID_(0)
34+
{
35+
size_ = 0;
36+
}
37+
38+
BusFault(BaseBusT* bus, double R, double X, int status)
39+
: bus_(bus), R_(R), X_(X), status_(status), busID_(0)
40+
{
41+
size_ = 0;
42+
}
43+
44+
~BusFault()
45+
{
46+
}
47+
48+
int allocate() override
49+
{
50+
return 0;
51+
}
52+
53+
int initialize() override
54+
{
55+
return 0;
56+
}
57+
58+
int tagDifferentiable() override
59+
{
60+
return 0;
61+
}
62+
63+
int evaluateResidual() override
64+
{
65+
if (status_)
3566
{
36-
size_ = 0;
67+
double B = -X_ / (X_ * X_ + R_ * R_);
68+
double G = R_ / (X_ * X_ + R_ * R_);
69+
Ir() += -Vr() * G + Vi() * B;
70+
Ii() += -Vr() * B - Vi() * G;
3771
}
38-
39-
BusFault(BaseBusT* bus, double R, double X, int status) :
40-
bus_(bus), R_(R), X_(X), status_(status), busID_(0)
41-
{
42-
size_ = 0;
43-
}
44-
45-
~BusFault() { }
46-
47-
int allocate() override { return 0; }
48-
49-
int initialize() override { return 0; }
50-
51-
int tagDifferentiable() override { return 0; }
52-
53-
int evaluateResidual() override
54-
{
55-
if (status_)
56-
{
57-
double B = -X_ / (X_*X_ + R_*R_);
58-
double G = R_ / (X_*X_ + R_*R_);
59-
Ir() += -Vr()*G + Vi()*B;
60-
Ii() += -Vr()*B - Vi()*G;
61-
}
62-
return 0;
63-
}
64-
65-
int evaluateJacobian() override { return 0; }
66-
67-
68-
int evaluateIntegrand() override { return 0; }
69-
int initializeAdjoint() override { return 0; }
70-
int evaluateAdjointResidual() override { return 0; }
71-
int evaluateAdjointIntegrand() override { return 0; }
72-
73-
void updateTime(double t, double a) override { }
72+
return 0;
73+
}
74+
75+
int evaluateJacobian() override
76+
{
77+
return 0;
78+
}
79+
80+
int evaluateIntegrand() override
81+
{
82+
return 0;
83+
}
84+
85+
int initializeAdjoint() override
86+
{
87+
return 0;
88+
}
89+
90+
int evaluateAdjointResidual() override
91+
{
92+
return 0;
93+
}
94+
95+
int evaluateAdjointIntegrand() override
96+
{
97+
return 0;
98+
}
99+
100+
void updateTime(double t, double a) override
101+
{
102+
}
74103

75104
public:
76-
void setR(double R) { R_ = R; }
105+
void setR(double R)
106+
{
107+
R_ = R;
108+
}
77109

78-
void setX(double X) { X_ = X; }
79-
80-
void setStatus(int status) { status_ = status; }
110+
void setX(double X)
111+
{
112+
X_ = X;
113+
}
81114

115+
void setStatus(int status)
116+
{
117+
status_ = status;
118+
}
82119

83120
private:
84-
double& Vr()
85-
{
86-
return bus_->Vr();
87-
}
88-
89-
double& Vi()
90-
{
91-
return bus_->Vi();
92-
}
93-
94-
double& Ir()
95-
{
96-
return bus_->Ir();
97-
}
98-
99-
double& Ii()
100-
{
101-
return bus_->Ii();
102-
}
121+
double& Vr()
122+
{
123+
return bus_->Vr();
124+
}
125+
126+
double& Vi()
127+
{
128+
return bus_->Vi();
129+
}
130+
131+
double& Ir()
132+
{
133+
return bus_->Ir();
134+
}
135+
136+
double& Ii()
137+
{
138+
return bus_->Ii();
139+
}
103140

104141
private:
105-
BaseBusT* bus_;
106-
double R_;
107-
double X_;
108-
int status_;
109-
const int busID_;
142+
BaseBusT* bus_;
143+
double R_;
144+
double X_;
145+
int status_;
146+
const int busID_;
110147
};
111148

112-
}
113-
}
149+
} // namespace PhasorDynamics
150+
} // namespace GridKit

src/Model/PhasorDynamics/BusFault/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ gridkit_add_library(phasor_dynamics_BusFault
22
SOURCES
33
BusFault.cpp
44
OUTPUT_NAME
5-
gridkit_phasor_dynamics_BusFault)
5+
gridkit_phasor_dynamics_BusFault)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "GENROU.hpp"
1+
#include "GENROU.hpp"

src/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GENROU.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ namespace GridKit
170170
double psidpp = vq / (1 + omega);
171171
double Te = (psidpp - id * Xdpp_) * iq - (psiqpp - iq * Xdpp_) * id;
172172
double psiqp = -(-(Xqp_ - Xl_) * iq + psiqpp * (Xqp_ - Xl_) / (Xqpp_ - Xl_))
173-
/ (1 + (Xqp_ - Xqpp_) / (Xqpp_ - Xl_));
173+
/ (1 + (Xqp_ - Xqpp_) / (Xqpp_ - Xl_));
174174
double Edp = psiqp - (Xqp_ - Xl_) * iq;
175175
double psidp = -((Xdp_ - Xl_) * id - psidpp * (Xdp_ - Xl_) / (Xdpp_ - Xl_))
176-
/ (1 + (Xdp_ - Xdpp_) / (Xdpp_ - Xl_));
176+
/ (1 + (Xdp_ - Xdpp_) / (Xdpp_ - Xl_));
177177
double Eqp = psidp + (Xdp_ - Xl_) * id;
178178

179179
/* Now we have the state variables, solve for alg. variables */

src/Solver/Dynamic/Ida.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -264,35 +264,33 @@ namespace AnalysisManager
264264
}
265265

266266
template <class ScalarT, typename IdxT>
267-
int Ida<ScalarT, IdxT>::runSimulationFixed(real_type t0, real_type dt,
268-
real_type tmax, FILE *f)
269-
{
270-
int retval = 0;
271-
int iout = 0;
272-
real_type t, tret;
273-
274-
//printOutputF(t0, 0, f);
275-
for (t = t0+dt; t < tmax; t += dt)
267+
int Ida<ScalarT, IdxT>::runSimulationFixed(real_type t0, real_type dt, real_type tmax, FILE* f)
268+
{
269+
int retval = 0;
270+
int iout = 0;
271+
real_type t, tret;
272+
273+
// printOutputF(t0, 0, f);
274+
for (t = t0 + dt; t < tmax; t += dt)
275+
{
276+
retval = IDASolve(solver_, t, &tret, yy_, yp_, IDA_NORMAL);
277+
checkOutput(retval, "IDASolve");
278+
printOutputF(t, retval, f);
279+
280+
if (retval != IDA_SUCCESS)
276281
{
277-
retval = IDASolve(solver_, t, &tret, yy_, yp_, IDA_NORMAL);
278-
checkOutput(retval, "IDASolve");
279-
printOutputF(t, retval, f);
280-
281-
if (retval != IDA_SUCCESS)
282-
{
283-
printf("IDA Failure! %dn", retval);
284-
break;
285-
}
282+
printf("IDA Failure! %dn", retval);
283+
break;
286284
}
285+
}
287286

288-
model_->updateTime(t, 0.0);
289-
copyVec(yy_, model_->y());
290-
copyVec(yp_, model_->yp());
287+
model_->updateTime(t, 0.0);
288+
copyVec(yy_, model_->y());
289+
copyVec(yp_, model_->yp());
291290

292-
return retval;
291+
return retval;
293292
}
294293

295-
296294
template <class ScalarT, typename IdxT>
297295
int Ida<ScalarT, IdxT>::runSimulation(real_type tf, int nout)
298296
{
@@ -740,10 +738,10 @@ namespace AnalysisManager
740738
}
741739

742740
template <class ScalarT, typename IdxT>
743-
void Ida<ScalarT, IdxT>::printOutputF(sunrealtype t, int res, FILE *f)
741+
void Ida<ScalarT, IdxT>::printOutputF(sunrealtype t, int res, FILE* f)
744742
{
745-
sunrealtype *yval = N_VGetArrayPointer_Serial(yy_);
746-
sunrealtype *ypval = N_VGetArrayPointer_Serial(yp_);
743+
sunrealtype* yval = N_VGetArrayPointer_Serial(yy_);
744+
sunrealtype* ypval = N_VGetArrayPointer_Serial(yp_);
747745

748746
fprintf(f, "%g,%d", t, res);
749747
for (IdxT i = 0; i < model_->size(); ++i)

0 commit comments

Comments
 (0)