Skip to content

Commit 8fa5689

Browse files
Tentative IDA Test (does not work)
1 parent 520a0ba commit 8fa5689

File tree

5 files changed

+326
-0
lines changed

5 files changed

+326
-0
lines changed

tests/UnitTests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#
22
add_subdirectory(PhasorDynamics)
33
add_subdirectory(SparsityPattern)
4+
add_subdirectory(Solver)

tests/UnitTests/Solver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#
2+
add_subdirectory(Dynamic)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
3+
add_executable(test_ida runIdaTests.cpp)
4+
target_link_libraries(test_ida GRIDKIT::solvers_dyn)
5+
6+
7+
add_test(NAME IDATest COMMAND $<TARGET_FILE:test_ida>)
8+
9+
install(TARGETS test_ida
10+
RUNTIME DESTINATION bin)
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
#include "Model/Evaluator.hpp"
2+
#include "Solver/Dynamic/Ida.hpp"
3+
#include "Utilities/TestHelpers.hpp"
4+
#include "Utilities/Testing.hpp"
5+
6+
using AnalysisManager::Sundials::Ida;
7+
8+
namespace GridKit
9+
{
10+
namespace Model
11+
{
12+
template <class ScalarT, typename IdxT>
13+
class NullEvaluator : public Model::Evaluator<ScalarT, IdxT>
14+
{
15+
public:
16+
typedef typename Model::Evaluator<ScalarT, IdxT>::real_type real_type;
17+
18+
NullEvaluator()
19+
{
20+
}
21+
22+
int allocate() override
23+
{
24+
return 0;
25+
}
26+
27+
int initialize() override
28+
{
29+
y_ = {0};
30+
yp_ = {0};
31+
32+
tag_ = {false};
33+
34+
f_ = {0};
35+
g_ = {0};
36+
return 0;
37+
}
38+
39+
IdxT size() override
40+
{
41+
return 1;
42+
}
43+
44+
IdxT nnz() override
45+
{
46+
return 0;
47+
}
48+
49+
bool hasJacobian() override
50+
{
51+
return false;
52+
}
53+
54+
IdxT sizeQuadrature() override
55+
{
56+
return 0;
57+
}
58+
59+
IdxT sizeParams() override
60+
{
61+
return 0;
62+
}
63+
64+
void setTolerances(real_type& rel_tol, real_type& abs_tol) const override
65+
{
66+
}
67+
68+
void setMaxSteps(IdxT& msa) const override
69+
{
70+
msa = 2000;
71+
}
72+
73+
int tagDifferentiable() override
74+
{
75+
return 0;
76+
}
77+
78+
int evaluateResidual() override
79+
{
80+
// f_ = yp_;
81+
return 0;
82+
}
83+
84+
int evaluateJacobian() override
85+
{
86+
return 0;
87+
}
88+
89+
int evaluateIntegrand() override
90+
{
91+
return 0;
92+
}
93+
94+
int initializeAdjoint() override
95+
{
96+
return 0;
97+
}
98+
99+
int evaluateAdjointResidual() override
100+
{
101+
return 0;
102+
}
103+
104+
int evaluateAdjointIntegrand() override
105+
{
106+
return 0;
107+
}
108+
109+
void updateTime(real_type t, real_type a) override
110+
{
111+
}
112+
113+
std::vector<ScalarT>& y()
114+
{
115+
return y_;
116+
}
117+
118+
const std::vector<ScalarT>& y() const
119+
{
120+
return y_;
121+
}
122+
123+
std::vector<ScalarT>& yp()
124+
{
125+
return yp_;
126+
}
127+
128+
const std::vector<ScalarT>& yp() const
129+
{
130+
return yp_;
131+
}
132+
133+
std::vector<bool>& tag()
134+
{
135+
return tag_;
136+
}
137+
138+
const std::vector<bool>& tag() const
139+
{
140+
return tag_;
141+
}
142+
143+
std::vector<ScalarT>& yB()
144+
{
145+
return yB_;
146+
}
147+
148+
const std::vector<ScalarT>& yB() const
149+
{
150+
return yB_;
151+
}
152+
153+
std::vector<ScalarT>& ypB()
154+
{
155+
return ypB_;
156+
}
157+
158+
const std::vector<ScalarT>& ypB() const
159+
{
160+
return ypB_;
161+
}
162+
163+
std::vector<ScalarT>& param()
164+
{
165+
return param_;
166+
}
167+
168+
const std::vector<ScalarT>& param() const
169+
{
170+
return param_;
171+
}
172+
173+
std::vector<ScalarT>& param_up()
174+
{
175+
return param_up_;
176+
}
177+
178+
const std::vector<ScalarT>& param_up() const
179+
{
180+
return param_up_;
181+
}
182+
183+
std::vector<ScalarT>& param_lo()
184+
{
185+
return param_lo_;
186+
}
187+
188+
const std::vector<ScalarT>& param_lo() const
189+
{
190+
return param_lo_;
191+
}
192+
193+
std::vector<ScalarT>& getResidual()
194+
{
195+
return f_;
196+
}
197+
198+
const std::vector<ScalarT>& getResidual() const
199+
{
200+
return f_;
201+
}
202+
203+
COO_Matrix<ScalarT, IdxT>& getJacobian()
204+
{
205+
return jac_;
206+
}
207+
208+
const COO_Matrix<ScalarT, IdxT>& getJacobian() const
209+
{
210+
return jac_;
211+
}
212+
213+
std::vector<ScalarT>& getIntegrand()
214+
{
215+
return g_;
216+
}
217+
218+
const std::vector<ScalarT>& getIntegrand() const
219+
{
220+
return g_;
221+
}
222+
223+
std::vector<ScalarT>& getAdjointResidual()
224+
{
225+
return fB_;
226+
}
227+
228+
const std::vector<ScalarT>& getAdjointResidual() const
229+
{
230+
return fB_;
231+
}
232+
233+
std::vector<ScalarT>& getAdjointIntegrand()
234+
{
235+
return gB_;
236+
}
237+
238+
const std::vector<ScalarT>& getAdjointIntegrand() const
239+
{
240+
return gB_;
241+
}
242+
243+
IdxT getIDcomponent()
244+
{
245+
return 0;
246+
}
247+
248+
protected:
249+
std::vector<ScalarT> y_;
250+
std::vector<ScalarT> yp_;
251+
std::vector<bool> tag_;
252+
std::vector<ScalarT> f_;
253+
std::vector<ScalarT> g_;
254+
255+
std::vector<ScalarT> yB_;
256+
std::vector<ScalarT> ypB_;
257+
std::vector<ScalarT> fB_;
258+
std::vector<ScalarT> gB_;
259+
260+
COO_Matrix<ScalarT, IdxT> jac_;
261+
262+
std::vector<ScalarT> param_;
263+
std::vector<ScalarT> param_up_;
264+
std::vector<ScalarT> param_lo_;
265+
};
266+
} // namespace Model
267+
268+
namespace Testing
269+
{
270+
template <class ScalarT, typename IdxT>
271+
class IdaTests
272+
{
273+
public:
274+
TestOutcome test()
275+
{
276+
const unsigned n_steps = 100;
277+
TestStatus success = true;
278+
279+
Model::NullEvaluator<ScalarT, IdxT> model;
280+
281+
Ida<double, size_t> ida(&model);
282+
ida.configureSimulation();
283+
284+
unsigned observed_steps = 0;
285+
auto output_cb = [&](double t)
286+
{
287+
observed_steps++;
288+
};
289+
290+
ida.initializeSimulation(0.0, false);
291+
ida.runSimulation(1.0, n_steps, output_cb);
292+
293+
success *= (observed_steps == n_steps);
294+
295+
return success.report(__func__);
296+
}
297+
};
298+
} // namespace Testing
299+
} // namespace GridKit
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "IdaTests.hpp"
2+
3+
int main()
4+
{
5+
using namespace GridKit;
6+
using namespace GridKit::Testing;
7+
8+
GridKit::Testing::TestingResults result;
9+
GridKit::Testing::IdaTests<double, size_t> test;
10+
11+
result += test.test();
12+
13+
return result.summary();
14+
}

0 commit comments

Comments
 (0)