{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# RadialGridGenerator Examples\n", "\n", "The `RadialGridGenerator` class in the `power_grid_model_ds` library is designed to generate radial grid structures with nodes, sources, lines, and optionally transformers. This documentation covers the usage of the `RadialGridGenerator` class, including grid generation, node, source, and line generation, and various grid configuration functions.\n", "\n", "## Grid Generation\n", "\n", "### Generating a Random Grid\n", "\n", "The `RadialGridGenerator` class can be used to generate a random grid with a specified structure. The `run` method initializes the grid generation process.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from power_grid_model_ds import Grid\n", "from power_grid_model_ds.generators import RadialGridGenerator\n", "\n", "# Generate a random grid\n", "grid_generator = RadialGridGenerator(grid_class=Grid)\n", "grid = grid_generator.run(seed=0)\n", "\n", "# Verify the structure of the generated grid\n", "print(f\"Number of nodes: {len(grid.node)}\")\n", "print(f\"Number of sources: {len(grid.source)}\")\n", "print(f\"Number of loads: {len(grid.sym_load)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generating a Random Grid with Transformers\n", "\n", "The RadialGridGenerator can also generate a grid that includes transformers.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from power_grid_model_ds import Grid\n", "from power_grid_model_ds.generators import RadialGridGenerator\n", "\n", "# Generate a random grid with transformers\n", "grid_generator = RadialGridGenerator(grid_class=Grid)\n", "grid = grid_generator.run(seed=0, create_10_3_kv_net=True)\n", "\n", "# Verify the transformers in the generated grid\n", "print(f\"Number of transformers: {len(grid.transformer)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Node Generation\n", "\n", "The NodeGenerator class is used to generate random nodes within the grid.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from power_grid_model_ds import Grid\n", "from power_grid_model_ds.arrays import NodeArray\n", "from power_grid_model_ds.generators import NodeGenerator\n", "\n", "# Generate random nodes\n", "grid = Grid.empty()\n", "node_generator = NodeGenerator(grid, seed=0)\n", "nodes, loads_low, loads_high = node_generator.run(amount=2)\n", "\n", "# Verify the generated nodes and loads\n", "print(f\"Generated nodes: \\n{nodes}\")\n", "print(f\"Low load scenarios: \\n{loads_low}\")\n", "print(f\"High load scenarios: \\n{loads_high}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Source Generation\n", "\n", "The SourceGenerator class is used to generate random sources within the grid.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from power_grid_model_ds import Grid\n", "from power_grid_model_ds.arrays import SourceArray\n", "from power_grid_model_ds.generators import SourceGenerator\n", "\n", "# Generate random sources\n", "grid = Grid.empty()\n", "source_generator = SourceGenerator(grid=grid, seed=0)\n", "nodes, sources = source_generator.run(amount=1)\n", "\n", "# Verify the generated nodes and sources\n", "print(f\"Generated nodes: \\n{nodes}\")\n", "print(f\"Generated sources: \\n{sources}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Line Generation\n", "\n", "The LineGenerator class is used to generate random lines within the grid.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from power_grid_model_ds import Grid\n", "from power_grid_model_ds.generators import LineGenerator\n", "\n", "# Setup initial nodes and sources\n", "grid = Grid.empty()\n", "nodes = NodeArray.zeros(4)\n", "nodes.id = [0, 1, 2, 3]\n", "nodes.u_rated = [10_500] * 4\n", "\n", "sources = SourceArray.zeros(1)\n", "sources.id = [4]\n", "sources.node = [0]\n", "sources.status = [1]\n", "sources.u_ref = [1]\n", "\n", "grid.append(nodes)\n", "grid.append(sources)\n", "\n", "# Generate random lines\n", "line_generator = LineGenerator(grid=grid, seed=0)\n", "lines = line_generator.run(amount=2)\n", "\n", "# Verify the generated lines\n", "print(f\"Generated lines: \\n{lines}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Grid Configuration Functions\n", "\n", "### Creating Routes\n", "\n", "The create_routes method in the LineGenerator class generates routes between nodes.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create routes\n", "line_generator.create_routes(2)\n", "\n", "# Verify the generated routes\n", "print(f\"Generated routes: \\n{line_generator.line_array}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Connecting Nodes\n", "\n", "The connect_nodes method connects unconnected nodes in the grid.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Connect unconnected nodes\n", "line_generator.set_unconnected_nodes()\n", "line_generator.connect_nodes()\n", "\n", "# Verify the connected nodes\n", "print(f\"Connected nodes: {line_generator.connected_nodes}\")\n", "print(f\"Unconnected nodes: {line_generator.unconnected_nodes}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating Normally Open Points\n", "\n", "The create_nop_lines method generates normally open points in the grid.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create normally open points\n", "line_generator.create_nop_lines(1)\n", "\n", "# Verify the generated normally open points\n", "print(f\"Generated NOP lines: \\n{line_generator.line_array}\")" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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" } }, "nbformat": 4, "nbformat_minor": 2 }