Commit 723f0069 by sp2668

### add more explanations and remarks

parent d09d7f7b
This diff is collapsed.
 %% Cell type:markdown id: tags: # Energy System Modelling - Solutions to Tutorial I.2 %% 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 \cos \omega t$$ $$S(t) = 1 - A_S \cos \omega t$$ $$L(t) = 1 + A_L \cos \omega t$$ The time series are normalized to $\langle{W}\rangle = \langle{S}\rangle = \langle{L}\rangle := \frac{1}{T} \int_0^T L(t) d t = 1$, and the constants have the values $$\omega = \frac{2\pi}{T}$$ $$T = 1 \text{ year}$$ $$A_W = 0.4$$ $$A_S = 0.75$$ $$A_L = 0.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:markdown id: tags: > **Remark:** The lambda operator is a way to create small anonymous functions, i.e. functions without a name, in Python. %% 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** $$\langle\left[ \alpha W(\cdot) + (1-\alpha) S(\cdot) - L(\cdot) \right]^2 \rangle = \frac1T \int_0^T \left[ \alpha W(t) + (1-\alpha) S(t) - L(t) \right]^2 \,\mathrm d t$$ > **Hint:** You can use the function [scipy.optimize.minimize](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [method='nelder-mead'](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method). %% 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.73913043212890694 %% 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.56521739196777387 %% 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 \cos \left( \omega t - \phi \right).$$ Express the optimal mix $\alpha$ as a function of $\phi$.** > **Remark:** Note, that $\alpha\in [0,1]$ and you need to add this as bounds. > **Hint:** If you encounter problems (why?), try another optimisation algorithm [method='TNC'](https://en.wikipedia.org/wiki/Truncated_Newton_method) %% 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 [] %% 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 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 [] ... ...
 %% Cell type:markdown id: tags: # Energy System Modelling - Tutorial I.2 %% 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 \cos \omega t$$ $$S(t) = 1 - A_S \cos \omega t$$ $$L(t) = 1 + A_L \cos \omega t$$ The time series are normalized to $\langle{W}\rangle = \langle{S}\rangle = \langle{L}\rangle := \frac{1}{T} \int_0^T L(t) d t = 1$, and the constants have the values $$\omega = \frac{2\pi}{T}$$ $$T = 1 \text{ year}$$ $$A_W = 0.4$$ $$A_S = 0.75$$ $$A_L = 0.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:markdown id: tags: > **Remark:** The lambda operator is a way to create small anonymous functions, i.e. functions without a name, in Python. %% 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.2 %% Cell type:markdown id: tags: *** **(a) What is the seasonal optimal mix $\alpha$, which minimizes** $$\langle\left[ \alpha W(\cdot) + (1-\alpha) S(\cdot) - L(\cdot) \right]^2 \rangle = \frac1T \int_0^T \left[ \alpha W(t) + (1-\alpha) S(t) - L(t) \right]^2 \,\mathrm d t$$ > **Hint:** You can use the function [scipy.optimize.minimize](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [method='nelder-mead'](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method). %% 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$.** > **Remark:** Note, that $\alpha\in [0,1]$ and you need to add this as bounds. > **Hint:** If you encounter problems (why?), try another optimisation algorithm [method='TNC'](https://en.wikipedia.org/wiki/Truncated_Newton_method) %% 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  ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!