-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBus.cpp
More file actions
222 lines (194 loc) · 5.66 KB
/
Bus.cpp
File metadata and controls
222 lines (194 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "Bus.hpp"
#include <cmath>
#include <iostream>
#include <PowerSystemData.hpp>
namespace GridKit
{
namespace PhasorDynamics
{
/*!
* @brief Constructor for a phasor dynamics bus.
*
* The model is using current balance in Cartesian coordinates.
*
* @todo Arguments that should be passed to ModelEvaluatorImpl constructor:
* - Number of equations = 2 (size_)
* - Number of variables = 2 (size_)
* - Number of quadratures = 0
* - Number of optimization parameters = 0
*/
template <class ScalarT, typename IdxT>
Bus<ScalarT, IdxT>::Bus()
: Vr0_(0.0), Vi0_(0.0)
{
// std::cout << "Create Bus..." << std::endl;
// std::cout << "Number of equations is " << size_ << std::endl;
size_ = 2;
}
/*!
* @brief Bus constructor.
*
* This constructor sets initial values for active and reactive voltage.
*
* @todo Arguments that should be passed to ModelEvaluatorImpl constructor:
* - Number of equations = 2 (size_)
* - Number of variables = 2 (size_)
* - Number of quadratures = 0
* - Number of optimization parameters = 0
*/
template <class ScalarT, typename IdxT>
Bus<ScalarT, IdxT>::Bus(ScalarT Vr, ScalarT Vi)
: Vr0_(Vr), Vi0_(Vi)
{
// std::cout << "Create Bus..." << std::endl;
// std::cout << "Number of equations is " << size_ << std::endl;
size_ = 2;
}
/**
* @brief Construct a new Bus
*
* @tparam ScalarT - type of scalar variables
* @tparam IdxT - type for vector/matrix indices
* @param[in] data - structure with bus data
*/
template <class ScalarT, typename IdxT>
Bus<ScalarT, IdxT>::Bus(BusData& data)
: BusBase<ScalarT, IdxT>(data.bus_i),
Vr0_(data.Vm * cos(data.Va)),
Vi0_(data.Vm * sin(data.Va))
{
// std::cout << "Create Bus..." << std::endl;
// std::cout << "Number of equations is " << size_ << std::endl;
size_ = 2;
}
template <class ScalarT, typename IdxT>
Bus<ScalarT, IdxT>::~Bus()
{
// std::cout << "Destroy PQ bus ..." << std::endl;
}
/*!
* @brief allocate method resizes local solution and residual vectors.
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::allocate()
{
// Temporary while we use std::vector in the code
size_t size = static_cast<size_t>(size_);
// Resize component model data
f_.resize(size);
y_.resize(size);
yp_.resize(size);
tag_.resize(size);
fB_.resize(size);
yB_.resize(size);
ypB_.resize(size);
return 0;
}
/*!
* @brief Bus variables are algebraic.
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::tagDifferentiable()
{
tag_[0] = false;
tag_[1] = false;
return 0;
}
/*!
* @brief initialize method sets bus variables to stored initial values.
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::initialize()
{
// std::cout << "Initialize Bus..." << std::endl;
y_[0] = Vr0_;
y_[1] = Vi0_;
yp_[0] = 0.0;
yp_[1] = 0.0;
return 0;
}
/*!
* @brief PQ bus does not compute residuals, so here we just reset residual values.
*
* @warning This implementation assumes bus residuals are always evaluated
* _before_ component model residuals.
*
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::evaluateResidual()
{
// std::cout << "Evaluating residual of a PQ bus ...\n";
f_[0] = 0.0;
f_[1] = 0.0;
return 0;
}
/**
* @brief Jacobian evaluation not implemented
*
* @tparam ScalarT - data type for Jacobian elements
* @tparam IdxT - data type for matrix indices
* @return int - error code
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::evaluateJacobian()
{
return 0;
}
/*!
* @brief initialize method sets bus variables to stored initial values.
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::initializeAdjoint()
{
// std::cout << "Initialize Bus..." << std::endl;
yB_[0] = 0.0;
yB_[1] = 0.0;
ypB_[0] = 0.0;
ypB_[1] = 0.0;
return 0;
}
/**
* @brief Bus only initializes adjoint residual elements to zero.
*
* @tparam ScalarT - data type for the integrand
* @tparam IdxT - data type for matrix/vector indices
* @return int - error code
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::evaluateAdjointResidual()
{
fB_[0] = 0.0;
fB_[1] = 0.0;
return 0;
}
/**
* @brief Quadrature evaluation not implemented
*
* @tparam ScalarT - data type for the integrand
* @tparam IdxT - data type for matrix/vector indices
* @return int - error code
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::evaluateIntegrand()
{
return 0;
}
/**
* @brief Adjoint quadrature evaluation not implemented
*
* @tparam ScalarT - data type for the integrand
* @tparam IdxT - data type for matrix/vector indices
* @return int - error code
*/
template <class ScalarT, typename IdxT>
int Bus<ScalarT, IdxT>::evaluateAdjointIntegrand()
{
return 0;
}
// Available template instantiations
template class Bus<double, long int>;
template class Bus<double, size_t>;
template class Bus<Sparse::Variable, long int>;
template class Bus<Sparse::Variable, size_t>;
} // namespace PhasorDynamics
} // namespace GridKit