Skip to content

Commit b6a759c

Browse files
committed
remove operator and use getData
1 parent 18b6541 commit b6a759c

96 files changed

Lines changed: 1821 additions & 1193 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GridKit/LinearAlgebra/Vector/Vector.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <cassert>
32
#include <cstddef>
43
#include <string>
54

@@ -64,18 +63,6 @@ namespace GridKit
6463
return static_cast<std::size_t>(getSize());
6564
}
6665

67-
ScalarT& operator[](std::size_t i)
68-
{
69-
assert(i < size());
70-
return getData(memory::HOST)[i];
71-
}
72-
73-
const ScalarT& operator[](std::size_t i) const
74-
{
75-
assert(i < size());
76-
return getData(memory::HOST)[i];
77-
}
78-
7966
IdxT getCapacity() const;
8067
IdxT getSize() const;
8168
IdxT getNumVectors() const;

GridKit/Model/Evaluator.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,19 @@ namespace GridKit
233233
assert(offset + n <= abs_tol.getSize());
234234

235235
y_.resize(n);
236-
y_.setData(y.getData(memory::HOST) + offset);
236+
y_.setData(y.getData() + offset);
237237

238238
yp_.resize(n);
239-
yp_.setData(yp.getData(memory::HOST) + offset);
239+
yp_.setData(yp.getData() + offset);
240240

241241
f_.resize(n);
242-
f_.setData(f.getData(memory::HOST) + offset);
242+
f_.setData(f.getData() + offset);
243243

244244
tag_.resize(n);
245-
tag_.setData(tag.getData(memory::HOST) + offset);
245+
tag_.setData(tag.getData() + offset);
246246

247247
abs_tol_.resize(n);
248-
abs_tol_.setData(abs_tol.getData(memory::HOST) + offset);
248+
abs_tol_.setData(abs_tol.getData() + offset);
249249

250250
offset_ = offset;
251251
allocated_ = true;

GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ namespace GridKit
4545
static_cast<size_t>((bus1_->y()).size()),
4646
(bus1_->getResidualIndices()).data(),
4747
(bus1_->getVariableIndices()).data(),
48-
y_.getData(memory::HOST),
49-
yp_.getData(memory::HOST),
50-
(bus1_->y()).getData(memory::HOST),
48+
y_.getData(),
49+
yp_.getData(),
50+
bus1_->y().getData(),
5151
J_rows_buffer_,
5252
J_cols_buffer_,
5353
J_vals_buffer_,
@@ -60,9 +60,9 @@ namespace GridKit
6060
static_cast<size_t>((bus2_->y()).size()),
6161
(bus2_->getResidualIndices()).data(),
6262
(bus2_->getVariableIndices()).data(),
63-
y_.getData(memory::HOST),
64-
yp_.getData(memory::HOST),
65-
(bus2_->y()).getData(memory::HOST),
63+
y_.getData(),
64+
yp_.getData(),
65+
bus2_->y().getData(),
6666
J_rows_buffer_,
6767
J_cols_buffer_,
6868
J_vals_buffer_,
@@ -75,9 +75,9 @@ namespace GridKit
7575
static_cast<size_t>((bus2_->y()).size()),
7676
(bus1_->getResidualIndices()).data(),
7777
(bus2_->getVariableIndices()).data(),
78-
y_.getData(memory::HOST),
79-
yp_.getData(memory::HOST),
80-
(bus2_->y()).getData(memory::HOST),
78+
y_.getData(),
79+
yp_.getData(),
80+
bus2_->y().getData(),
8181
J_rows_buffer_,
8282
J_cols_buffer_,
8383
J_vals_buffer_,
@@ -90,9 +90,9 @@ namespace GridKit
9090
static_cast<size_t>((bus1_->y()).size()),
9191
(bus2_->getResidualIndices()).data(),
9292
(bus1_->getVariableIndices()).data(),
93-
y_.getData(memory::HOST),
94-
yp_.getData(memory::HOST),
95-
(bus1_->y()).getData(memory::HOST),
93+
y_.getData(),
94+
yp_.getData(),
95+
bus1_->y().getData(),
9696
J_rows_buffer_,
9797
J_cols_buffer_,
9898
J_vals_buffer_,

GridKit/Model/PhasorDynamics/Bus/Bus.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,42 +60,42 @@ namespace GridKit
6060

6161
virtual ScalarT& Vr() override final
6262
{
63-
return y_[0];
63+
return y_.getData()[0];
6464
}
6565

6666
virtual const ScalarT& Vr() const override final
6767
{
68-
return y_[0];
68+
return y_.getData()[0];
6969
}
7070

7171
virtual ScalarT& Vi() override final
7272
{
73-
return y_[1];
73+
return y_.getData()[1];
7474
}
7575

7676
virtual const ScalarT& Vi() const override final
7777
{
78-
return y_[1];
78+
return y_.getData()[1];
7979
}
8080

8181
virtual ScalarT& Ir() override final
8282
{
83-
return f_[0];
83+
return f_.getData()[0];
8484
}
8585

8686
virtual const ScalarT& Ir() const override final
8787
{
88-
return f_[0];
88+
return f_.getData()[0];
8989
}
9090

9191
virtual ScalarT& Ii() override final
9292
{
93-
return f_[1];
93+
return f_.getData()[1];
9494
}
9595

9696
virtual const ScalarT& Ii() const override final
9797
{
98-
return f_[1];
98+
return f_.getData()[1];
9999
}
100100

101101
protected:

GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ namespace GridKit
145145
template <typename scalar_type, typename index_type>
146146
int Bus<scalar_type, index_type>::tagDifferentiable()
147147
{
148-
tag_[0] = false;
149-
tag_[1] = false;
148+
auto* tag = tag_.getData();
149+
150+
tag[0] = false;
151+
tag[1] = false;
150152
return 0;
151153
}
152154

@@ -165,7 +167,7 @@ namespace GridKit
165167
template <typename scalar_type, typename index_type>
166168
int Bus<scalar_type, index_type>::setAbsoluteTolerance(RealT rel_tol)
167169
{
168-
std::fill(abs_tol_.getData(memory::HOST), abs_tol_.getData(memory::HOST) + abs_tol_.size(), rel_tol);
170+
std::fill(abs_tol_.getData(), abs_tol_.getData() + abs_tol_.size(), rel_tol);
169171
return 0;
170172
}
171173

@@ -176,10 +178,13 @@ namespace GridKit
176178
int Bus<scalar_type, index_type>::initialize()
177179
{
178180
// std::cout << "Initialize Bus..." << std::endl;
179-
y_[0] = Vr0_;
180-
y_[1] = Vi0_;
181-
yp_[0] = 0.0;
182-
yp_[1] = 0.0;
181+
auto* y = y_.getData();
182+
auto* yp = yp_.getData();
183+
184+
y[0] = Vr0_;
185+
y[1] = Vi0_;
186+
yp[0] = 0.0;
187+
yp[1] = 0.0;
183188

184189
return 0;
185190
}
@@ -195,8 +200,10 @@ namespace GridKit
195200
int Bus<scalar_type, index_type>::evaluateResidual()
196201
{
197202
// std::cout << "Evaluating residual of a PQ bus ...\n";
198-
f_[0] = 0.0;
199-
f_[1] = 0.0;
203+
auto* f = f_.getData();
204+
205+
f[0] = 0.0;
206+
f[1] = 0.0;
200207
return 0;
201208
}
202209
} // namespace PhasorDynamics

GridKit/Model/PhasorDynamics/BusFault/BusFaultEnzyme.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace GridKit
4444
y_.size(),
4545
(this->getResidualIndices()).data(),
4646
(this->getVariableIndices()).data(),
47-
y_.getData(memory::HOST),
48-
yp_.getData(memory::HOST),
47+
y_.getData(),
48+
yp_.getData(),
4949
wb_.data(),
5050
J_rows_buffer_,
5151
J_cols_buffer_,
@@ -59,9 +59,9 @@ namespace GridKit
5959
static_cast<size_t>(bus_->size()),
6060
(this->getResidualIndices()).data(),
6161
(bus_->getVariableIndices()).data(),
62-
y_.getData(memory::HOST),
63-
yp_.getData(memory::HOST),
64-
(bus_->y()).getData(memory::HOST),
62+
y_.getData(),
63+
yp_.getData(),
64+
bus_->y().getData(),
6565
J_rows_buffer_,
6666
J_cols_buffer_,
6767
J_vals_buffer_,
@@ -80,8 +80,8 @@ namespace GridKit
8080
y_.size(),
8181
(bus_->getResidualIndices()).data(),
8282
(this->getVariableIndices()).data(),
83-
y_.getData(memory::HOST),
84-
yp_.getData(memory::HOST),
83+
y_.getData(),
84+
yp_.getData(),
8585
wb_.data(),
8686
J_rows_buffer_,
8787
J_cols_buffer_,

GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ namespace GridKit
8484
monitor_->set(Variable::state, [this]
8585
{ return status_; });
8686
monitor_->set(Variable::ir, [this]
87-
{ return y_[0]; });
87+
{
88+
auto* y = y_.getData();
89+
return y[0]; });
8890
monitor_->set(Variable::ii, [this]
89-
{ return y_[1]; });
91+
{
92+
auto* y = y_.getData();
93+
return y[1]; });
9094

9195
size_ = 2;
9296
setDerivedParams();
@@ -150,23 +154,26 @@ namespace GridKit
150154
template <typename scalar_type, typename index_type>
151155
int BusFault<scalar_type, index_type>::initialize()
152156
{
157+
auto* y = y_.getData();
158+
auto* yp = yp_.getData();
159+
153160
if (status_)
154161
{
155162
ScalarT vr = Vr();
156163
ScalarT vi = Vi();
157164
ScalarT ir = -(vr * G_ - vi * B_);
158165
ScalarT ii = -(vr * B_ + vi * G_);
159-
y_[0] = ir;
160-
y_[1] = ii;
166+
y[0] = ir;
167+
y[1] = ii;
161168
}
162169
else
163170
{
164-
y_[0] = 0.0;
165-
y_[1] = 0.0;
171+
y[0] = 0.0;
172+
y[1] = 0.0;
166173
}
167174

168-
yp_[0] = 0.0;
169-
yp_[1] = 0.0;
175+
yp[0] = 0.0;
176+
yp[1] = 0.0;
170177

171178
return 0;
172179
}
@@ -177,8 +184,10 @@ namespace GridKit
177184
template <typename scalar_type, typename index_type>
178185
int BusFault<scalar_type, index_type>::tagDifferentiable()
179186
{
180-
tag_[0] = false;
181-
tag_[1] = false;
187+
auto* tag = tag_.getData();
188+
189+
tag[0] = false;
190+
tag[1] = false;
182191

183192
return 0;
184193
}
@@ -198,7 +207,7 @@ namespace GridKit
198207
template <class scalar_type, typename index_type>
199208
int BusFault<scalar_type, index_type>::setAbsoluteTolerance(RealT rel_tol)
200209
{
201-
std::fill(abs_tol_.getData(memory::HOST), abs_tol_.getData(memory::HOST) + abs_tol_.size(), rel_tol);
210+
std::fill(abs_tol_.getData(), abs_tol_.getData() + abs_tol_.size(), rel_tol);
202211
return 0;
203212
}
204213

@@ -252,18 +261,24 @@ namespace GridKit
252261
{
253262
if (status_)
254263
{
255-
wb_[0] = Vr();
256-
wb_[1] = Vi();
257-
evaluateInternalResidual(y_.getData(memory::HOST), yp_.getData(memory::HOST), wb_.data(), f_.getData(memory::HOST));
258-
evaluateBusResidual(y_.getData(memory::HOST), yp_.getData(memory::HOST), wb_.data(), h_.data());
264+
wb_[0] = Vr();
265+
wb_[1] = Vi();
266+
auto* y = y_.getData();
267+
auto* yp = yp_.getData();
268+
auto* f = f_.getData();
269+
evaluateInternalResidual(y, yp, wb_.data(), f);
270+
evaluateBusResidual(y, yp, wb_.data(), h_.data());
259271
Ir() += h_[0];
260272
Ii() += h_[1];
261273
}
262274
else
263275
{
264-
wb_[0] = 0.0;
265-
wb_[1] = 0.0;
266-
evaluateInternalResidual(y_.getData(memory::HOST), yp_.getData(memory::HOST), wb_.data(), f_.getData(memory::HOST));
276+
wb_[0] = 0.0;
277+
wb_[1] = 0.0;
278+
auto* y = y_.getData();
279+
auto* yp = yp_.getData();
280+
auto* f = f_.getData();
281+
evaluateInternalResidual(y, yp, wb_.data(), f);
267282
}
268283

269284
return 0;

0 commit comments

Comments
 (0)