How to Parameterstudy

This notebook shows you a way to set up a bunch, here for, simulations where we vary two parameters.

The simulations shall stem from

In [1]:
root_dir = '../sample_simulations/2d_streaming_instability/'

and shall be stored in

In [2]:
project_folder = '../tmp/5001'

We use pencilnew internal routines to create this folder later.

Import needed packages

In [3]:
%matplotlib inline
import numpy as np
import pencilnew as pcn
import matplotlib.pyplot as plt
Warning: no h5py library found.
!! ERR in diag/fixed_points.py: Dependency of h5py not fullfilled.
Warning: no h5py library found.

Get our setup done

First, lets get the simulation out of root_dir as simulation object.

In [4]:
SIM_root = pcn.get_sim(root_dir)
print('~ Name of the root simulation: '+SIM_root.name)
~ Name of the root simulation: 2d_streaming_instability

Second we need to specify the names of our new simulations and their parameter sets, we do this in a nested dictionary:

In [5]:
new_sims = {
    'AA': {'eps_dtog': 1,
           'tausp': 0.1},
    
    'AB': {'eps_dtog': 1,
           'tausp': 0.01},
    
    'BA': {'eps_dtog': 3,
           'tausp': 0.1},
    
    'BB': {'eps_dtog': 3,
           'tausp': 0.01}    
}

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!

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!

Create new simulations

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!

In [6]:
for sim_name in new_sims.keys():            # get simulation name
    SIM = SIM_root.copy(path_root = project_folder,
                        name = sim_name)
! ERROR: Folder to copy simulation to already exists!
! -> /home/user/pencil-code/python/tutorials/tmp/5001/AA
! ERROR: Folder to copy simulation to already exists!
! -> /home/user/pencil-code/python/tutorials/tmp/5001/AB
! ERROR: Folder to copy simulation to already exists!
! -> /home/user/pencil-code/python/tutorials/tmp/5001/BA
! ERROR: Folder to copy simulation to already exists!
! -> /home/user/pencil-code/python/tutorials/tmp/5001/BB

Now go and check out pencil-code/python/tutorials/tmp/5001/

Change parameters

Again we do loop over our new_sims dictionary but this time we change parameters.

In [9]:
SIMs = pcn.get_sims(project_folder, quiet=True)
for SIM in SIMs:                          # now we iterate over simulations
    parameter_set = new_sims[SIM.name]    # get new simulation parameters
    
In [10]:
SIM.name
Out[10]:
'BA'
In [11]:
parameter_set
Out[11]:
{'eps_dtog': 3, 'tausp': 0.1}
In [12]:
SIM.change_value_in_file?
In [ ]: