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
8f4b41e7
Commit
8f4b41e7
authored
Jul 18, 2019
by
Markus Mirz
Browse files
Merge branch 'fix-multi-freq' into 'master'
Fix multi freq See merge request acs/public/simulation/dpsim!85
parents
8fddab10
cbd2c837
Changes
5
Hide whitespace changes
Inline
Side-by-side
libcps
@
c8daca4e
Compare
2f2f246a
...
c8daca4e
Subproject commit
2f2f246aee96a2f213a1ccceec3d392a3f0a06a0
Subproject commit
c8daca4e5f2fbcbe4ca49c0917e975deacf7a43e
Examples/Cxx/Inverter/DP_Inverter_Grid_Test.cpp
View file @
8f4b41e7
...
...
@@ -46,7 +46,7 @@ int main(int argc, char* argv[]) {
auto
n4
=
Node
::
make
(
"n4"
);
auto
n5
=
Node
::
make
(
"n5"
);
Logger
::
Level
level
=
Logger
::
Level
::
NONE
;
Logger
::
Level
level
=
Logger
::
Level
::
INFO
;
// Components
auto
inv
=
Inverter
::
make
(
"inv"
,
level
);
...
...
@@ -86,14 +86,15 @@ int main(int argc, char* argv[]) {
SystemNodeList
{
n1
,
n2
,
n3
,
n4
,
n5
},
SystemComponentList
{
inv
,
r1
,
l1
,
r2
,
l2
,
c1
,
rc
,
grid
});
//Simulation sim(simName, sys, timeStep, finalTime, Domain::DP, Solver::Type::MNA, Logger::Level::INFO);
Simulation
sim
(
simName
,
level
);
sim
.
setSystem
(
sys
);
sim
.
setTimeStep
(
timeStep
);
sim
.
setFinalTime
(
finalTime
);
sim
.
doHarmonicParallelization
(
false
);
sim
.
initialize
();
// Logging
auto
logger
=
DataLogger
::
make
(
simName
);
logger
->
addAttribute
(
"v1"
,
n1
->
attributeMatrixComp
(
"v"
),
1
,
5
);
...
...
@@ -108,6 +109,7 @@ int main(int argc, char* argv[]) {
sim
.
run
();
auto
spdStepTimeLog
=
Logger
::
get
(
"step_times"
,
Logger
::
Level
::
INFO
);
Logger
::
setLogPattern
(
spdStepTimeLog
,
"%v"
);
spdStepTimeLog
->
info
(
"steptime_inv"
);
Real
tot
=
0
;
...
...
Examples/Notebooks/Components/Inverter_Grid_Test.ipynb
View file @
8f4b41e7
...
...
@@ -9,17 +9,14 @@
},
{
"cell_type": "code",
"execution_count":
30
,
"execution_count":
1
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scheduling tasks.\n",
"Start simulation.\n",
"Simulation finished.\n",
"0.000300565\n"
"0.000395416\n"
]
}
],
...
...
@@ -33,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count":
11
,
"execution_count":
2
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -45,7 +42,7 @@
},
{
"cell_type": "code",
"execution_count":
12
,
"execution_count":
3
,
"metadata": {},
"outputs": [
{
...
...
@@ -71,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count":
4
4,
"execution_count": 4,
"metadata": {},
"outputs": [
{
...
...
@@ -81,7 +78,7 @@
" -0.14131796, -0.07476615])"
]
},
"execution_count":
4
4,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -114,7 +111,7 @@
},
{
"cell_type": "code",
"execution_count":
4
5,
"execution_count": 5,
"metadata": {},
"outputs": [
{
...
...
@@ -123,7 +120,7 @@
"(0, 0.05)"
]
},
"execution_count":
4
5,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -148,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count":
4
6,
"execution_count": 6,
"metadata": {},
"outputs": [
{
...
...
@@ -157,7 +154,7 @@
"(0, 0.05)"
]
},
"execution_count":
4
6,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -182,7 +179,7 @@
},
{
"cell_type": "code",
"execution_count":
4
7,
"execution_count": 7,
"metadata": {},
"outputs": [
{
...
...
@@ -191,7 +188,7 @@
"(0, 0.05)"
]
},
"execution_count":
4
7,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -220,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count":
4
8,
"execution_count": 8,
"metadata": {},
"outputs": [
{
...
...
@@ -229,7 +226,7 @@
"(0, 0.05)"
]
},
"execution_count":
4
8,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -261,7 +258,7 @@
},
{
"cell_type": "code",
"execution_count":
4
9,
"execution_count": 9,
"metadata": {},
"outputs": [
{
...
...
@@ -292,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count":
5
0,
"execution_count":
1
0,
"metadata": {},
"outputs": [
{
...
...
@@ -314,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count":
5
1,
"execution_count":
1
1,
"metadata": {},
"outputs": [
{
...
...
@@ -323,7 +320,7 @@
"(300, 320)"
]
},
"execution_count":
5
1,
"execution_count":
1
1,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -350,17 +347,18 @@
},
{
"cell_type": "code",
"execution_count":
52
,
"execution_count":
13
,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"diff = ts_ml_inverter['v_c'].values[:5000] - np.interp(ts_ml_inverter['v_c'].time[:5000], ts_dpsim_emt_v3.time, ts_dpsim_emt_v3.values)\n",
"assert np.all(diff) < 10"
]
},
{
"cell_type": "code",
"execution_count":
53
,
"execution_count":
14
,
"metadata": {},
"outputs": [
{
...
...
@@ -391,7 +389,7 @@
},
{
"cell_type": "code",
"execution_count": 5
4
,
"execution_count":
1
5,
"metadata": {},
"outputs": [
{
...
...
@@ -413,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count":
55
,
"execution_count":
16
,
"metadata": {},
"outputs": [
{
...
...
@@ -422,7 +420,7 @@
"(300, 320)"
]
},
"execution_count":
55
,
"execution_count":
16
,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -450,7 +448,7 @@
},
{
"cell_type": "code",
"execution_count":
56
,
"execution_count":
17
,
"metadata": {},
"outputs": [
{
...
...
%% Cell type:markdown id: tags:
# Inverter Grid Test
%% Cell type:code id: tags:
```
python
%%
bash
TOP
=
$
{
TOP
:
-
$
(
git
rev
-
parse
--
show
-
toplevel
)}
PATH
=
$
{
TOP
}
/
build
/
Examples
/
Cxx
DP_Inverter_Grid_Test
```
%% Output
Scheduling tasks.
Start simulation.
Simulation finished.
0.000300565
0.000395416
%% Cell type:code id: tags:
```
python
import
villas.dataprocessing.readtools
as
rt
import
villas.dataprocessing.plottools
as
pt
from
villas.dataprocessing.timeseries
import
TimeSeries
import
matplotlib.pyplot
as
plt
```
%% Cell type:code id: tags:
```
python
# read results
work_dir
=
'logs/DP_Inverter_Grid_Test/'
log_name
=
'DP_Inverter_Grid_Test'
print
(
work_dir
+
log_name
+
'.csv'
)
ts_dpsim
=
rt
.
read_timeseries_dpsim
(
work_dir
+
log_name
+
'.csv'
)
```
%% Output
logs/DP_Inverter_Grid_Test/DP_Inverter_Grid_Test.csv
column number: 15
results length: 50000
real column names: []
complex column names: ['i12_0_0', 'i34_0_0', 'v1_0_0', 'v1_0_1', 'v1_0_2', 'v1_0_3', 'v1_0_4', 'v2_0_0', 'v3_0_0', 'v3_0_1', 'v3_0_2', 'v3_0_3', 'v3_0_4', 'v4_0_0', 'v5_0_0']
%% Cell type:code id: tags:
```
python
ts_list_v1
=
[
ts_dpsim
[
'v1_0_0'
],
ts_dpsim
[
'v1_0_1'
],
ts_dpsim
[
'v1_0_2'
],
ts_dpsim
[
'v1_0_3'
],
ts_dpsim
[
'v1_0_4'
]]
ts_list_v3
=
[
ts_dpsim
[
'v3_0_0'
],
ts_dpsim
[
'v3_0_1'
],
ts_dpsim
[
'v3_0_2'
],
ts_dpsim
[
'v3_0_3'
],
ts_dpsim
[
'v3_0_4'
]]
freq_list
=
[
50
,
19850
,
19950
,
20050
,
20150
]
ts_dpsim_emt_v1
=
TimeSeries
.
create_emt_from_dp
(
ts_list_v1
,
freq_list
)
ts_dpsim_emt_v1
.
values
```
%% Output
array([ 0. , -0.07476615, -0.14131796, ..., -0.19165711,
-0.14131796, -0.07476615])
%% Cell type:code id: tags:
```
python
#%matplotlib qt
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v1
)
plt
.
xlim
(
0
,
0.05
)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
```
python
ts_dpsim_emt_v3
=
TimeSeries
.
create_emt_from_dp
(
ts_list_v3
,
freq_list
)
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v3
)
plt
.
xlim
(
0
,
0.05
)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
```
python
ts_dpsim_emt_v5
=
ts_dpsim
[
'v5_0_0'
].
frequency_shift
(
50
)
#%matplotlib qt
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v1
)
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v3
)
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v5
)
plt
.
xlim
(
0
,
0.05
)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
```
python
ts_dpsim_emt_v1
=
ts_dpsim
[
'v1_0_0'
].
frequency_shift
(
50
)
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v1
)
plt
.
xlim
(
0
,
0.05
)
```
%% Output
(0, 0.05)
%% Cell type:markdown id: tags:
## Validation
%% Cell type:code id: tags:
```
python
# read Simulink log file
import
os
import
urllib.request
if
not
os
.
path
.
exists
(
'reference-results'
):
os
.
mkdir
(
'reference-results'
)
url
=
'https://git.rwth-aachen.de/acs/public/simulation/reference-results/raw/master/Simulink/Inverter/ML_SP_Inverter_OL_v_i.csv'
local_file
=
'reference-results/ML_SP_Inverter_OL_v_i.csv'
urllib
.
request
.
urlretrieve
(
url
,
local_file
)
ts_ml_inverter
=
rt
.
read_timeseries_simulink
(
local_file
)
```
%% Output
column number: 4
results length: 100001
real column names: ['v_inv', 'v_c', 'i1', 'i2']
complex column names: []
%% Cell type:code id: tags:
```
python
pt
.
plot_timeseries
(
1
,
ts_ml_inverter
[
'v_inv'
])
```
%% Output
%% Cell type:code id: tags:
```
python
#plt.figure(figsize=(20,10))
pt
.
plot_timeseries
(
1
,
ts_ml_inverter
[
'v_c'
])
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v3
)
plt
.
xlim
(
0.024
,
0.026
)
plt
.
ylim
(
300
,
320
)
```
%% Output
(300, 320)
%% Cell type:code id: tags:
```
python
import
numpy
as
np
diff
=
ts_ml_inverter
[
'v_c'
].
values
[:
5000
]
-
np
.
interp
(
ts_ml_inverter
[
'v_c'
].
time
[:
5000
],
ts_dpsim_emt_v3
.
time
,
ts_dpsim_emt_v3
.
values
)
assert
np
.
all
(
diff
)
<
10
```
%% Cell type:code id: tags:
```
python
# read Simulink log file
import
os
import
urllib.request
if
not
os
.
path
.
exists
(
'reference-results'
):
os
.
mkdir
(
'reference-results'
)
url
=
'https://git.rwth-aachen.de/acs/public/simulation/reference-results/raw/master/Simulink/Inverter/SL_SP_Inverter_OL_v_i.csv'
local_file
=
'reference-results/SL_SP_Inverter_OL_v_i.csv'
urllib
.
request
.
urlretrieve
(
url
,
local_file
)
ts_sl_inverter
=
rt
.
read_timeseries_simulink
(
local_file
)
```
%% Output
column number: 4
results length: 712639
real column names: ['v_inv', 'v_c', 'i1', 'i2']
complex column names: []
%% Cell type:code id: tags:
```
python
pt
.
plot_timeseries
(
1
,
ts_sl_inverter
[
'v_inv'
])
```
%% Output
%% Cell type:code id: tags:
```
python
#plt.figure(figsize=(20,10))
pt
.
plot_timeseries
(
1
,
ts_ml_inverter
[
'v_c'
])
pt
.
plot_timeseries
(
1
,
ts_sl_inverter
[
'v_c'
])
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v3
)
plt
.
xlim
(
0.024
,
0.026
)
plt
.
ylim
(
300
,
320
)
```
%% Output
(300, 320)
%% Cell type:code id: tags:
```
python
import
numpy
as
np
ts_sl_inverter
[
'v_c'
].
label
=
'vc_sl'
ts_dpsim_emt_v3
.
label
=
'vc_dpsim'
pt
.
plot_timeseries
(
1
,
ts_sl_inverter
[
'v_c'
])
pt
.
plot_timeseries
(
1
,
ts_dpsim_emt_v3
)
plt
.
xlim
(
0.0245
,
0.0255
)
plt
.
ylim
(
306
,
315
)
plt
.
xlabel
(
'time (s)'
)
plt
.
ylabel
(
'voltage (V)'
)
ax
=
plt
.
gca
()
ax
.
xaxis
.
set_major_locator
(
plt
.
MaxNLocator
(
5
))
```
%% Output
%% Cell type:code id: tags:
```
python
```
...
...
Source/MNASolver.cpp
View file @
8f4b41e7
...
...
@@ -110,19 +110,17 @@ void MnaSolver<VarType>::initialize(CPS::SystemTopology system) {
template
<
>
void
MnaSolver
<
Real
>::
initializeComponents
()
{
// TODO: Move to base solver class?
// This intialization according to power flow information is not MNA specific.
mSLog
->
info
(
"-- Initialize components from power flow"
);
for
(
auto
comp
:
mPowerComponents
)
{
auto
pComp
=
std
::
dynamic_pointer_cast
<
PowerComponent
<
Complex
>>
(
comp
);
if
(
!
pComp
)
continue
;
pComp
->
initialize
(
mSystem
.
mFrequencies
);
auto
pComp
=
std
::
dynamic_pointer_cast
<
PowerComponent
<
Real
>>
(
comp
);
if
(
!
pComp
)
continue
;
pComp
->
initializeFromPowerflow
(
mSystem
.
mSystemFrequency
);
}
// Initialize signal components.
for
(
auto
comp
:
mSignalComponents
)
comp
->
initialize
(
mSystem
.
mSystemOmega
,
mTimeStep
);
// Initialize MNA specific parts of components.
for
(
auto
comp
:
mPowerComponents
)
{
comp
->
mnaInitialize
(
mSystem
.
mSystemOmega
,
mTimeStep
,
attribute
<
Matrix
>
(
"left_vector"
));
...
...
@@ -137,19 +135,12 @@ void MnaSolver<Real>::initializeComponents() {
template
<
>
void
MnaSolver
<
Complex
>::
initializeComponents
()
{
// TODO: Move to base solver class?
// This intialization according to power flow information is not MNA specific.
mSLog
->
info
(
"-- Initialize components from power flow"
);
// Initialize nodes
for
(
UInt
nodeIdx
=
0
;
nodeIdx
<
mNodes
.
size
();
nodeIdx
++
)
mNodes
[
nodeIdx
]
->
initialize
(
mSystem
.
mFrequencies
);
// Initialize power components with frequencies and from powerflow results
for
(
auto
comp
:
mPowerComponents
)
{
auto
pComp
=
std
::
dynamic_pointer_cast
<
PowerComponent
<
Complex
>>
(
comp
);
if
(
!
pComp
)
continue
;
pComp
->
initialize
(
mSystem
.
mFrequencies
);
pComp
->
initializeFromPowerflow
(
mSystem
.
mSystemFrequency
);
}
...
...
Source/Simulation.cpp
View file @
8f4b41e7
...
...
@@ -56,6 +56,8 @@ Simulation::Simulation(String name, Logger::Level logLevel) :
mSLog
=
Logger
::
get
(
name
);
mSLog
->
set_pattern
(
"[%L] %v"
);
mSLog
->
set_level
(
Logger
::
cpsLogLevelToSpd
(
logLevel
));
mInitialized
=
false
;
}
Simulation
::
Simulation
(
String
name
,
SystemTopology
system
,
...
...
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