Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
esm-course
esm-tutorials
Commits
4a0e0cb9
Commit
4a0e0cb9
authored
Jul 11, 2018
by
sp2668
Browse files
minor
parent
77db2b01
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
tutorial-1/solution01-1.ipynb
View file @
4a0e0cb9
This diff is collapsed.
Click to expand it.
tutorial-1/solution01-2.ipynb
View file @
4a0e0cb9
...
...
@@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count":
30
,
"execution_count":
2
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -80,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
3
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
4
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -108,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
5
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count":
14
,
"execution_count":
6
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -136,7 +136,7 @@
},
{
"cell_type": "code",
"execution_count":
31
,
"execution_count":
7
,
"metadata": {
"slideshow": {
"slide_type": "subslide"
...
...
@@ -150,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count":
16
,
"execution_count":
8
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -164,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count":
34
,
"execution_count":
9
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -178,7 +178,7 @@
},
{
"cell_type": "code",
"execution_count": 1
8
,
"execution_count": 1
0
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -203,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": 1
2
,
"execution_count": 1
1
,
"metadata": {
"slideshow": {
"slide_type": "skip"
...
...
@@ -227,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": 1
3
,
"execution_count": 1
2
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -266,7 +266,7 @@
},
{
"cell_type": "code",
"execution_count":
25
,
"execution_count":
13
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -318,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 1
9
,
"execution_count": 1
4
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -338,10 +338,10 @@
{
"data": {
"text/plain": [
"0.73913043212890
7
"
"0.73913043212890
694
"
]
},
"execution_count": 1
9
,
"execution_count": 1
4
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -365,7 +365,7 @@
},
{
"cell_type": "code",
"execution_count":
20
,
"execution_count":
15
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -378,7 +378,7 @@
},
{
"cell_type": "code",
"execution_count":
2
1,
"execution_count": 1
6
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -398,10 +398,10 @@
{
"data": {
"text/plain": [
"0.565217391967773
9
"
"0.565217391967773
87
"
]
},
"execution_count":
2
1,
"execution_count": 1
6
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -413,7 +413,7 @@
},
{
"cell_type": "code",
"execution_count":
22
,
"execution_count":
17
,
"metadata": {
"slideshow": {
"slide_type": "fragment"
...
...
@@ -440,7 +440,7 @@
},
{
"cell_type": "code",
"execution_count":
44
,
"execution_count":
18
,
"metadata": {
"slideshow": {
"slide_type": "subslide"
...
...
@@ -450,10 +450,10 @@
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f
6a03f0f5c0
>]"
"[<matplotlib.lines.Line2D at 0x7f
2c3ef2d3c8
>]"
]
},
"execution_count":
44
,
"execution_count":
18
,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -496,7 +496,7 @@
},
{
"cell_type": "code",
"execution_count":
48
,
"execution_count":
19
,
"metadata": {
"slideshow": {
"slide_type": "subslide"
...
...
@@ -506,10 +506,10 @@
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f
6a03f4d63
0>]"
"[<matplotlib.lines.Line2D at 0x7f
2c3ee857f
0>]"
]
},
"execution_count":
48
,
"execution_count":
19
,
"metadata": {},
"output_type": "execute_result"
},
...
...
@@ -538,9 +538,8 @@
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python
[default]
",
"display_name": "Python
3
",
"language": "python",
"name": "python3"
},
...
...
@@ -554,7 +553,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
5
"
"version": "3.6.
4
"
},
"varInspector": {
"cols": {
...
...
%% Cell type:markdown id: tags:
# Energy System Modelling - Solutions to Tutorial II.1
%% Cell type:markdown id: tags:
## Imports
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
scipy.integrate
as
integrate
from
scipy.optimize
import
minimize
%
matplotlib
inline
```
%% Cell type:markdown id: tags:
## Parameters
%% Cell type:code id: tags:
```
python
A_w
=
0.4
A_s
=
0.75
A_l
=
0.1
T
=
1
phi
=
0
```
%% Cell type:markdown id: tags:
## Functions
%% Cell type:code id: tags:
```
python
def
w
(
t
,
phi
=
0
):
return
1
+
A_w
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
-
phi
)
```
%% Cell type:code id: tags:
```
python
def
s
(
t
):
return
1
-
A_s
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
)
```
%% Cell type:code id: tags:
```
python
def
l
(
t
):
return
1
+
A_l
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
)
```
%% Cell type:code id: tags:
```
python
def
c
(
gamma
):
return
1
-
gamma
```
%% Cell type:code id: tags:
```
python
def
mismatch_a
(
alpha
,
t
,
phi
=
phi
):
return
alpha
*
w
(
t
,
phi
)
+
(
1
-
alpha
)
*
s
(
t
)
-
l
(
t
)
```
%% Cell type:code id: tags:
```
python
def
mismatch_c
(
alpha
,
gamma
,
t
):
return
gamma
*
(
alpha
*
w
(
t
)
+
(
1
-
alpha
)
*
s
(
t
))
+
c
(
t
)
-
l
(
t
)
```
%% Cell type:code id: tags:
```
python
def
objective_a
(
alpha
):
return
1
/
T
*
integrate
.
quad
(
lambda
t
:
mismatch_a
(
alpha
,
t
,
phi
=
phi
)
**
2
,
0
,
T
)[
0
]
```
%% Cell type:code id: tags:
```
python
def
objective_c
(
alpha
):
return
1
/
T
*
integrate
.
quad
(
lambda
t
:
mismatch_c
(
alpha
,
gamma
,
t
)
**
2
,
0
,
T
)[
0
]
```
%% Cell type:markdown id: tags:
## Plots
%% Cell type:code id: tags:
```
python
x
=
np
.
arange
(
0
,
1
,
0.01
)
```
%% Cell type:markdown id: tags:
Availability time series
%% Cell type:code id: tags:
```
python
wind
=
plt
.
plot
(
x
,
w
(
x
),
label
=
'wind'
)
solar
=
plt
.
plot
(
x
,
s
(
x
),
label
=
'solar'
)
load
=
plt
.
plot
(
x
,
l
(
x
),
label
=
'load'
)
plt
.
legend
()
plt
.
show
()
```
%% Output
%% Cell type:markdown id: tags:
Mismatch
%% Cell type:code id: tags:
```
python
alphas
=
[
0
,
0.25
,
0.5
,
0.75
,
1
]
for
a
in
alphas
:
plt
.
plot
(
x
,
mismatch_a
(
a
,
x
),
label
=
'wind share = '
+
str
(
a
))
plt
.
legend
()
plt
.
show
()
```
%% Output
%% Cell type:markdown id: tags:
## Solution
%% Cell type:markdown id: tags:
***
**(a) What is the seasonal optimal mix $\alpha$, which minimizes**
$$
\l
angle
\l
eft[
\a
lpha W(
\c
dot) + (1-
\a
lpha) S(
\c
dot) - L(
\c
dot)
\r
ight]^2
\r
angle =
\f
rac1T
\i
nt_0^T
\l
eft[
\a
lpha W(t) + (1-
\a
lpha) S(t) - L(t)
\r
ight]^2
\,\m
athrm d t$$
%% Cell type:code id: tags:
```
python
alpha
=
minimize
(
objective_a
,
x0
=
0
,
method
=
'nelder-mead'
,
options
=
{
'xtol'
:
1e-8
,
'disp'
:
True
}).
x
[
0
]
alpha
```
%% Output
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 37
Function evaluations: 74
0.73913043212890
7
0.73913043212890
694
%% Cell type:markdown id: tags:
***
**(b) How does the optimal mix change if we replace $A_L \to -A_L$?**
%% Cell type:code id: tags:
```
python
A_l
*=
(
-
1
)
```
%% Cell type:code id: tags:
```
python
alpha
=
minimize
(
objective_a
,
x0
=
0
,
method
=
'nelder-mead'
,
options
=
{
'xtol'
:
1e-8
,
'disp'
:
True
}).
x
[
0
]
alpha
```
%% Output
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 36
Function evaluations: 72
0.565217391967773
9
0.565217391967773
87
%% Cell type:code id: tags:
```
python
A_l
*=
(
-
1
)
```
%% Cell type:markdown id: tags:
***
**
(c) Now assume that there is a seasonal shift in the wind signal
$$ W(t) = 1 + A_W
\c
os
\l
eft(
\o
mega t -
\p
hi
\r
ight).$$
Express the optimal mix $
\a
lpha$ as a function of $
\p
hi$.
**
%% Cell type:code id: tags:
```
python
phis
=
np
.
arange
(
0
,
2
*
np
.
pi
,
np
.
pi
/
100
)
alphas
=
[]
for
p
in
phis
:
phi
=
p
bnds
=
[(
0
,
1
)]
alpha
=
minimize
(
objective_a
,
x0
=
0
,
method
=
'TNC'
,
bounds
=
bnds
,
options
=
{
'xtol'
:
1e-8
}).
x
[
0
]
alphas
.
append
(
alpha
)
plt
.
plot
(
phis
,
alphas
)
```
%% Output
[<matplotlib.lines.Line2D at 0x7f
6a03f0f5c0
>]
[<matplotlib.lines.Line2D at 0x7f
2c3ef2d3c8
>]
%% Cell type:markdown id: tags:
***
**
(d) A constant conventional power source $C(t) = 1 -
\g
amma$ is now introduced. The mismatch then becomes
$$
\D
elta(t) =
\g
amma
\l
eft[
\a
lpha W(t) + (1-
\a
lpha) S(t)
\r
ight] + C(t) - L(t)$$
Analogously to (a), find the optimal mix $
\a
lpha$ as a function of $0
\l
eq
\g
amma
\l
eq 1$, which minimizes $
\l
angle{
\D
elta^2}
\r
angle$.
**
%% Cell type:code id: tags:
```
python
gammas
=
np
.
arange
(
0
,
1
,
0.01
)
alphas
=
[]
for
g
in
gammas
:
gamma
=
g
bnds
=
[(
0
,
1
)]
alpha
=
minimize
(
objective_c
,
x0
=
0
,
method
=
'TNC'
,
bounds
=
bnds
,
options
=
{
'xtol'
:
1e-8
}).
x
[
0
]
alphas
.
append
(
alpha
)
plt
.
plot
(
gammas
,
alphas
)
```
%% Output
[<matplotlib.lines.Line2D at 0x7f
6a03f4d63
0>]
[<matplotlib.lines.Line2D at 0x7f
2c3ee857f
0>]
...
...
tutorial-1/tutorial01-2.ipynb
View file @
4a0e0cb9
...
...
@@ -183,7 +183,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem I
I.1
"
"## Problem I
.2
"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Energy System Modelling - Tutorial II.1
%% Cell type:markdown id: tags:
We use approximations to seasonal variations of wind and solar power generation $W(t)$
and $S(t)$ and load $L(t)$:
$$W(t) = 1 + A_W
\c
os
\o
mega t$$
$$S(t) = 1 - A_S
\c
os
\o
mega t$$
$$L(t) = 1 + A_L
\c
os
\o
mega t$$
The time series are normalized to $
\l
angle{W}
\r
angle =
\l
angle{S}
\r
angle =
\l
angle{L}
\r
angle :=
\f
rac{1}{T}
\i
nt_0^T L(t)
d t = 1$, and the constants have the values
$$
\o
mega =
\f
rac{2
\p
i}{T} $$
$$T = 1
\t
ext{ year}$$
$$ A_W = 0.4 $$ $$ A_S = 0.75 $$ $$ A_L = 0.1 $$
%% Cell type:markdown id: tags:
## Parameters
%% Cell type:code id: tags:
```
python
A_w
=
0.4
A_s
=
0.75
A_l
=
0.1
T
=
1
phi
=
0
```
%% Cell type:markdown id: tags:
## Imports
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
scipy.integrate
as
integrate
from
scipy.optimize
import
minimize
%
matplotlib
inline
```
%% Cell type:markdown id: tags:
## Functions
%% Cell type:code id: tags:
```
python
def
w
(
t
,
phi
=
0
):
return
1
+
A_w
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
-
phi
)
```
%% Cell type:code id: tags:
```
python
def
s
(
t
):
return
1
-
A_s
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
)
```
%% Cell type:code id: tags:
```
python
def
l
(
t
):
return
1
+
A_l
*
np
.
cos
(
2
*
t
*
np
.
pi
/
T
)
```
%% Cell type:code id: tags:
```
python
def
c
(
gamma
):
return
1
-
gamma
```
%% Cell type:code id: tags:
```
python
def
mismatch
(
???
):
return
???
```
%% Cell type:code id: tags:
```
python
def
objective
(
alpha
):
return
1
/
T
*
integrate
.
quad
(
lambda
t
:
mismatch
(
???
)
**
2
,
0
,
T
)[
0
]
```
%% Cell type:markdown id: tags:
## Plots
%% Cell type:code id: tags:
```
python
x
=
np
.
arange
(
0
,
1
,
0.01
)
```
%% Cell type:markdown id: tags:
Availability time series as shown on the worksheet.
%% Cell type:code id: tags:
```
python
wind
=
plt
.
plot
(
x
,
w
(
x
),
label
=
'wind'
)
solar
=
plt
.
plot
(
x
,
s
(
x
),
label
=
'solar'
)
load
=
plt
.
plot
(
x
,
l
(
x
),
label
=
'load'
)
plt
.
legend
()
plt
.
show
()
```
%% Output
%% Cell type:markdown id: tags:
## Problem I
I.1
## Problem I
.2
%% Cell type:markdown id: tags:
***
**(a) What is the seasonal optimal mix $\alpha$, which minimizes**
$$
\l
angle
\l
eft[
\a
lpha W(
\c
dot) + (1-
\a
lpha) S(
\c
dot) - L(
\c
dot)
\r
ight]^2
\r
angle =
\f
rac1T
\i
nt_0^T
\l
eft[
\a
lpha W(t) + (1-
\a
lpha) S(t) - L(t)
\r
ight]^2
\,\m
athrm d t$$
%% Cell type:code id: tags:
```
python
``
`
%%
Cell
type
:
markdown
id
:
tags
:
***
**
(
b
)
How
does
the
optimal
mix
change
if
we
replace
$
A_L
\
to
-
A_L
$?
**
%%
Cell
type
:
code
id
:
tags
:
```
python
```
%% Cell type:markdown id: tags:
***
**(c) Now assume that there is a seasonal shift in the wind signal
$$ W(t) = 1 + A_W \cos \left( \omega t - \phi \right).$$
Express the optimal mix $\alpha$ as a function of $\phi$.**
%% Cell type:code id: tags:
```
python
```
%% Cell type:markdown id: tags:
***
**(d) A constant conventional power source $C(t) = 1 - \gamma$ is now introduced. The mismatch then becomes
$$\Delta(t) = \gamma \left[ \alpha W(t) + (1-\alpha) S(t) \right] + C(t) - L(t)$$
Analogously to (a), find the optimal mix $\alpha$ as a function of $0 \leq \gamma \leq 1$, which minimizes $\langle{\Delta^2}\rangle$.**
%% Cell type:code id: tags:
```
python
```
...
...
tutorial-6/solution06.ipynb
View file @
4a0e0cb9
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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