Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Power System Simulation and Optimization
DPsim
DPsim
Commits
01faf730
Commit
01faf730
authored
May 26, 2017
by
Georg Martin Reinke
Browse files
add basic testing/result verification
parent
c8d536e3
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Source/Makefile
View file @
01faf730
...
...
@@ -6,13 +6,19 @@ LD_FLAGS = -lvillas-ext
# File names
EXEC
=
DPSolver
SOURCES
=
$(
wildcard
*
.cpp
)
$(
wildcard
Components/
*
.cpp
)
$(
wildcard
Examples/
*
.cpp
)
OBJECTS
=
$(SOURCES:.cpp=.o)
OBJECTS
=
$(
filter-out
DPsimMain.o,
$(SOURCES:.cpp=.o)
)
TEST_SOURCES
=
$(
wildcard
Tests/Test
*
.cpp
)
TEST_OBJS
=
$(TEST_SOURCES:.cpp=.o)
TEST_BINS
=
$(TEST_SOURCES:.cpp=)
INCLUDES
=
-I
/usr/include/eigen3
.PHONY
:
tests clean
# Main target
$(EXEC)
:
$(OBJECTS)
$(CC)
$
(OBJECTS)
$(LD_FLAGS)
-o
$(EXEC)
$(EXEC)
:
$(OBJECTS)
DPsimMain.o
$(CC)
$
^
$(LD_FLAGS)
-o
$(EXEC)
# To obtain object files
%.o
:
%.cpp
...
...
@@ -20,4 +26,9 @@ $(EXEC): $(OBJECTS)
# To remove generated files
clean
:
rm
-f
$(EXEC)
$(OBJECTS)
rm
-f
$(EXEC)
$(OBJECTS)
$(TEST_BINS)
Tests/Test%
:
$(OBJECTS) Tests/Test%.o
$(CC)
$^
$(LD_FLAGS)
-o
$@
tests
:
$(TEST_BINS)
Source/Tests/TestSimple.cpp
0 → 100644
View file @
01faf730
#include
"../Simulation.h"
using
namespace
DPsim
;
int
main
(
int
argc
,
char
*
argv
[])
{
Logger
logNone
(
LogLevel
::
NONE
),
llog
;
std
::
vector
<
BaseComponent
*>
comps
;
comps
.
push_back
(
new
VoltSourceRes
(
"v_s"
,
1
,
0
,
10000
,
0
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_line"
,
1
,
2
,
1
));
comps
.
push_back
(
new
Inductor
(
"l_line"
,
2
,
3
,
1
));
comps
.
push_back
(
new
LinearResistor
(
"r_load"
,
3
,
0
,
1000
));
Real
timeStemp
=
0.001
;
Simulation
sim
(
comps
,
2
*
M_PI
*
50
,
timeStemp
,
0.3
,
logNone
);
while
(
sim
.
step
(
logNone
,
llog
,
logNone
))
{
sim
.
increaseByTimeStep
();
}
llog
.
WriteLogToFile
(
"TestSimple.csv"
);
}
Source/Tests/TestSimple.expected.csv
0 → 100644
View file @
01faf730
This diff is collapsed.
Click to expand it.
Source/Tests/run_tests.py
0 → 100755
View file @
01faf730
#!/usr/bin/python
#
# Script for automatically running the tests and comparing the results against
# given CSV files (from some other simulator).
# TODO: supporting different timesteps (interpolating), phasor/EMT conversion,
# more advanced error criterions...
import
glob
import
numpy
as
np
import
pandas
import
subprocess
import
sys
EPSILON
=
1e-6
def
run_test
(
binary
,
dpCsv
,
expectedCsv
):
ret
=
subprocess
.
call
(
"./"
+
binary
)
if
ret
:
print
(
binary
+
" binary returned code "
+
ret
,
file
=
sys
.
stderr
)
return
ret
dpData
=
pandas
.
read_csv
(
dpCsv
,
header
=
None
)
expectedData
=
pandas
.
read_csv
(
expectedCsv
,
header
=
None
)
if
dpData
.
shape
[
1
]
!=
expectedData
.
shape
[
1
]:
print
(
"{}: result vector dimension mismatch (DP: {}, expected: {}"
.
format
(
binary
,
dpData
.
shape
[
1
],
expectedData
.
shape
[
1
]),
file
=
sys
.
stderr
)
return
1
dpTime
=
np
.
array
(
dpData
.
ix
[:,
0
])
expectedTime
=
np
.
array
(
expectedData
.
ix
[:,
0
])
diffTime
=
dpTime
-
expectedTime
if
np
.
any
(
diffTime
):
print
(
binary
+
": time mismatch (wrong timestep?)"
)
return
1
ret
=
0
for
i
in
range
(
1
,
int
((
dpData
.
shape
[
1
]
-
1
)
/
2
)):
realIdx
=
i
imagIdx
=
i
+
int
((
dpData
.
shape
[
1
]
-
1
)
/
2
)
dpReal
=
np
.
array
(
dpData
.
ix
[:,
realIdx
])
dpImag
=
np
.
array
(
dpData
.
ix
[:,
imagIdx
])
expectedReal
=
np
.
array
(
expectedData
.
ix
[:,
realIdx
])
expectedImag
=
np
.
array
(
expectedData
.
ix
[:,
imagIdx
])
diff
=
np
.
sqrt
((
dpReal
-
expectedReal
)
**
2
+
(
dpImag
-
expectedImag
)
**
2
)
diffIdx
=
np
.
nonzero
(
diff
>
EPSILON
)
if
len
(
diffIdx
[
0
])
!=
0
:
print
(
"{}: node {} has {} values above diff threshold"
.
format
(
binary
,
i
,
len
(
diffIdx
[
0
])),
file
=
sys
.
stderr
)
print
(
"(first at {} with diff of {})"
.
format
(
diffIdx
[
0
][
0
],
diff
[
diffIdx
[
0
][
0
]]),
file
=
sys
.
stderr
)
ret
=
1
return
ret
if
__name__
==
"__main__"
:
sources
=
glob
.
glob
(
"Test*.cpp"
)
bins
=
[
s
.
replace
(
".cpp"
,
""
)
for
s
in
sources
]
dpCsvs
=
[
s
.
replace
(
".cpp"
,
".csv"
)
for
s
in
sources
]
expectedCsvs
=
[
s
.
replace
(
".cpp"
,
".expected.csv"
)
for
s
in
sources
]
ret
=
0
for
i
in
range
(
0
,
len
(
sources
)):
if
run_test
(
bins
[
i
],
dpCsvs
[
i
],
expectedCsvs
[
i
]):
print
(
bins
[
i
]
+
" failed!"
,
file
=
sys
.
stderr
)
ret
=
1
else
:
print
(
bins
[
i
]
+
" successfull."
)
if
not
ret
:
print
(
"All tests successfull."
)
sys
.
exit
(
ret
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment