diff --git a/lectures/02_NA_MNA/VS_CS_R4_hard-coded.ipynb b/lectures/02_NA_MNA/VS_CS_R4_hard-coded.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..a152001e303cdee8c35cfbc81e8fa748ae04b06f --- /dev/null +++ b/lectures/02_NA_MNA/VS_CS_R4_hard-coded.ipynb @@ -0,0 +1,182 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MSP Simulation Example - Modified Nodal Analysis - without the DPsim solver" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Sample Circuit" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<img src=\"VS_CS_R4_HC.png\" width=\"500\" align=\"left\">" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$R_1$: $1 \\Omega$, $R_2$: $1 \\Omega$, $R_3$: $10 \\Omega$, $R_4$: $5 \\Omega$ \n", + "$I_1$: $1 A$, $V_{in}$: $10 V$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Circuit and Simulation Setup" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "np.set_printoptions(sign=' ')\n", + "\n", + "#Components\n", + "R1= 1.0\n", + "R2= 1.0\n", + "R3= 10.0\n", + "R4= 5.0\n", + "I_src= 1.0\n", + "V_src= 10.0\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Derive the admittance matrix G and the source vector A applied in nodal analysis using the matrix stamp approach. Note here that there are two approaches to stamp the voltage source:\n", + "1. **NA**: Stamp the voltage source as **real** voltage source with internal resistance R1 and transform it into a current source using Norton transformation --> 2 nodes + 1 reference node\n", + "2. **MNA**: Stamp the voltage source as **ideal** voltage source. --> 3 nodes + 1 reference node" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Modified Nodal Analysis" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Admitance matrix: \n", + "[[ 1. -1. 0. 1. ]\n", + " [-1. 2.1 -0.1 0. ]\n", + " [ 0. -0.1 0.3 0. ]\n", + " [ 1. 0. 0. 0. ]]\n", + "\n", + "Problem size: 4x4\n", + "\n", + "Node Voltages: \n", + "[[ 10.]\n", + " [ 5.]\n", + " [ 5.]]\n", + "\n", + "Current i_10 through the voltage source: \n", + "[-5.]\n" + ] + } + ], + "source": [ + "#Building source vector\n", + "A_src = np.array([[0] ,\n", + " [0] ,\n", + " [I_src] ,\n", + " [V_src]])\n", + "\n", + "#Building admitance matrix\n", + "G = np.array([[1/R1, -1/R1 , 0 , 1],\n", + " [-1/R1, (1/R1 + 1/R2 + 1/R3) , -1/R3 , 0],\n", + " [0 , -1/R3, (1/R3 + 1/R4), 0],\n", + " [1, 0, 0, 0]])\n", + " \n", + "#System solution\n", + "e_nodes = np.matmul(np.linalg.inv(G),A_src)\n", + "\n", + "print('Admitance matrix: \\n' + str(G))\n", + "print('\\nProblem size: 4x4')\n", + "print('\\nNode Voltages: \\n' + str(e_nodes[0:3 , :]))\n", + "print('\\nCurrent i_10 through the voltage source: \\n'+ str(-e_nodes[1 , :]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "toc-hr-collapsed": false + }, + "source": [ + "## LU decomposition of final system matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'scipy'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m<ipython-input-1-3dc02d571707>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mscipy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mipywidgets\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mwidgets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'scipy'" + ] + } + ], + "source": [ + "import scipy as sc\n", + "import ipywidgets as widgets" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}