{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to Parameterstudy\n", "This notebook shows you a way to set up a bunch, here for, simulations where we vary two parameters. \n", "\n", "The simulations shall stem from" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "root_dir = '../sample_simulations/2d_streaming_instability/'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and shall be stored in" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "project_folder = '../tmp/5001'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use pencilnew internal routines to create this folder later." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import needed packages" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import pencilnew as pcn\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get our setup done\n", "First, lets get the simulation out of root_dir as simulation object." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "~ Name of the root simulation: 2d_streaming_instability\n" ] } ], "source": [ "SIM_root = pcn.get_sim(root_dir)\n", "print('~ Name of the root simulation: '+SIM_root.name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Second we need to specify the names of our new simulations and their parameter sets, we do this in a nested dictionary:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "new_sims = {\n", " 'AA': {'eps_dtog': 1,\n", " 'tausp': 0.1},\n", " \n", " 'AB': {'eps_dtog': 1,\n", " 'tausp': 0.01},\n", " \n", " 'BA': {'eps_dtog': 3,\n", " 'tausp': 0.1},\n", " \n", " 'BB': {'eps_dtog': 3,\n", " 'tausp': 0.01} \n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The parameters we want to vary are Stokes number (in pencil code named tausp) of the particles and dust-to-gas ratio (named eps_dtog). Both parameters are found to be in the start.in file. Luckly pencilnew does not need to know where to search but looks up pencil code simulation in and local files automatically!\n", "\n", "But beware, if both run.in and start.in contain a certain parameter you may need to specify in which file exactly you want to modify this parameter!\n", "\n", "## Create new simulations\n", "Now lets create these four new simulations in our new project dir and change parameters accordingly. We do that by producing copies of SIM_root, so check out SIM_root.copy help at this point!" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for sim_name in new_sims.keys(): # get simulation name\n", " SIM = SIM_root.copy(path_root = project_folder,\n", " name = sim_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now go and check out pencil-code/python/tutorials/tmp/5001/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Change parameters\n", "Again we do loop over our new_sims dictionary but this time we change parameters." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [], "source": [ "SIMs = pcn.get_sims(project_folder, quiet=True)\n", "for SIM in SIMs: # now we iterate over simulations\n", " parameter_set = new_sims[SIM.name] # get new simulation parameters\n", " " ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'BA'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SIM.name" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{'eps_dtog': 3, 'tausp': 0.1}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "parameter_set" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "SIM.change_value_in_file?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.5" } }, "nbformat": 4, "nbformat_minor": 1 }