{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pencil as pc\n", "import os" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Changing Simulation Parameters\n", "So far, we havnt implemented a way to modify simulation modules directly from python! But, you can modify 'src/cparam.local' and 'start.in' and 'run.in'. You see, ways to modify 'print.in', 'video.in', etc. are missing. Feel free to add them!\n", "\n", "The reason they are missing is, that valid input parameters depend on modules and its sometimes unclear where and how to add parameters correcly. But, changing them is rather easy and anyway what we do most of the time!\n", "\n", "So, for starting runs with modifyied parameters our workflow should be:\n", "1. Find a suiting master simulation or set up one on your own.\n", "2. From this master produce your simulation copies. \n", "3. Change parameters of the simulations. \n", "\n", "You already know how to do the first two things. Lets explore how we can do the last step from python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Start by doing a copy of a sample simulation" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "~ Reading param.nml.. \n", "~ Reading grid.. \n", "~ Reading ghost_grid.. \n", "~ Reading dim.. \n", "? Warning: No name specified and simulation with that name already found! New simulation name now 2d_streaming_instability_copy1\n", "~ Reading param.nml.. \n", "~ Reading grid.. \n", "File /home/iomsn/pencil-code/python/tutorials/tmp/0004/2d_streaming_instability_copy1/data/dim.dat could not be opened.\n", "? WARNING: Couldnt load grid for /home/iomsn/pencil-code/python/tutorials/tmp/0004/2d_streaming_instability_copy1\n", "/home/iomsn/pencil-code/python/tutorials/tmp/0004/2d_streaming_instability_copy1\n" ] } ], "source": [ "SIM_MASTER = pc.sim.simulation('../sample_simulations/2d_streaming_instability', quiet=True)\n", "SIM = SIM_MASTER.copy('../tmp/0004/')\n", "print(SIM.path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We do changes to cparam.local and in files, by specifing:\n", "- filename\n", "- quantity\n", "- newValue\n", "- and maybe filepath=False\n", "\n", "## a) Do changes in cparam.local" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SIM.change_value_in_file('start.in', 'qshear', 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Compile and run simulations" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SIM.compile()" ] }, { "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.6.9" } }, "nbformat": 4, "nbformat_minor": 1 }