pencil.sim.simulation

Contains the simulation class which can be used to directly create, access and manipulate simulations.

Exceptions

CommandFailedError

Unspecified run-time error.

Classes

Simulation

Simulation objects are containers for simulations. Pencil can work with

Functions

simulation(*args, **kwargs)

Wrapper for Simulation

Module Contents

exception pencil.sim.simulation.CommandFailedError

Bases: RuntimeError

Unspecified run-time error.

Initialize self. See help(type(self)) for accurate signature.

class pencil.sim.simulation.Simulation(path='.', hidden=False, hard=False, quiet=False)

Simulation objects are containers for simulations. Pencil can work with several of them at once if stored in a simulations object.

Parameters:
  • path (string) – Path to simulation, default = ‘.’.

  • hidden (bool) – Set True to set hidden flag, default is False.

  • quiet (bool) – Suppress irrelevant output, default is False.

  • hard (bool) – Force update, default is False

  • Properties

  • ----------

  • self.name (name of)

  • self.path (path to simulation)

  • self.datadir (path to simulation data-dir (./data/))

  • self.pc_dir (path to simulation pc-dir (./pc/))

  • self.pc_datadir (path to simulation pendir in datadir (data/pc/))

  • self.components (list of files which are necessary components of) – the simulation

  • self.optionals (list of files which are optional components of) – the simulation

  • self.start_components (list of files provided at the simulation start)

  • self.start_optionals (list of optional files after the simulation start)

  • self.hidden (Default is False, if True this simulation will) – be ignored by pencil

  • self.param (list of param file)

  • self.grid (grid object)

  • object (self.index index)

  • self.dim (dim object)

  • self.tmp_dict (temporal dictionary of stuff, will not be saved)

path
name = ''
datadir
pc_dir
pc_datadir
components = ['src/cparam.local', 'src/Makefile.local', 'start.in', 'run.in', 'print.in']
quantity_searchables = ['src/cparam.local', 'start.in', 'run.in']
optionals = ['*.in', '*.py', 'submit*']
start_components = ['index.pro', 'param.nml', 'pencils.list']
start_optionals = ['time_series.dat', '*.pro', '*.h5']
hidden = False
param = False
grid = False
index = False
dim = False
ghost_grid = False
tmp_dict
copy(path_root='.', name=False, start_optionals=True, optionals=True, quiet=True, rename_submit_script=False, OVERWRITE=False, lfs=False, MB=1, count=1)

This method does a copy of the simulation object by creating a new directory ‘name’ in ‘path_root’ and copy all simulation components and optiona)

ls to its directory.

This method neither links/compiles the simulation. If start_optionals it creates data dir. It does not overwrite anything, unless OVERWRITE is True.

Submit Script Rename:

Name in submit scripts will be renamed if possible! Submit scripts will be identified by submit* plus appearenace of old simulation name inside, latter will be renamed!

Parameters:
  • path_root (string) – Path to new sim.-folder(sim.-name). This folder will be created if not existing! Relative paths are thought to be relative to the python current workdir

  • name (string) – Name of new simulation, will be used as folder name. Rename will also happen in submit script if found. Simulation folders is not allowed to preexist!

  • optionals (start) – Add list of further files to be copied. Wildcasts allowed according to glob module! Set True to use self.optionals.

  • optionals – Add list of further files to be copied. Wildcasts allowed according to glob module! Set True to use self.optionals.

  • quiet (bool) – Set True to suppress output.

  • rename_submit_script (bool) – Set False if no renames shall be performed in submit* files

  • OVERWRITE (bool) – Set True to overwrite no matter what happens!

resume_from_var(sim_source, varno, DEBUG=False)

Copies everything to resume a run from an older state.

It uses VAR-file number >varno< as new VAR0 and var.dat. Does copy PVAR as well if available.

Parameters:
  • sim_source (string) – Simulation from where to copy all the files.

  • varno (int) – var-file number # from which to copy (VAR#).

update(hard=False, quiet=True)

Update simulation object: if not read in:

  • read param.nml

  • read grid and ghost grid

Set hard=True to force update.

hide()

Set hide flag True for this simulation.

unhide()

Set hide flag False for this simulation.

export()

Export simulation object to its root/.pc-dir

started()

Returns whether simulation has already started. This is indicated by existing time_series.dat in data directory.

compile(cleanall=False, fast=False, verbose=False, hostfile=None, autoclean=True, previous_flags=False, additional_options='', **kwargs)

Compiles the simulation. Per default the linking is done before the compiling process is called. This method will use your settings as defined in your .bashrc-file.

Parameters:
  • cleanall (bool) – Before calling pc_build, pc_build –cleanall is called.

  • verbose (bool) – Activate for verbosity.

  • fast (bool) – Set True for fast compilation.

  • autoclean (bool) – If compilation fails, automatically set cleanall=True and retry.

  • previous_flags (bool) – If True, use the same flags as the last time pc_build was called.

  • additional_options (str) – Addition options to be passed to pc_build.

  • self.bash (Accepts all other keywords accepted by)

build(**kwargs)

Same as compile()

bash(command, verbose='last100', logfile=False, bashrc=True, raise_errors=False)

Executes command in simulation directory. This method will use your settings as defined in your .bashrc-file. A log file will be produced within ‘self.path/pc’-folder

Parameters:
  • command (string) – Command to be executed, can be a list of commands.

  • verbose (bool) –

    lastN = show last N lines of output afterwards

    False = no output True = all output

  • bashrc (bool) – True: source bashrc in the subprocess False: don’t source bashrc in the subprocess. Instead, only pass along the environment variables from the current session.

  • raise_errors (bool) – If True, a nonzero return code for command will be raised as a Python error.

cleanall(verbose=False, hostfile=None, **kwargs)

Runs pc_build –cleanall in the simulation directory

Parameters:
  • verbose (bool) – Activate for verbosity.

  • self.bash (Accepts all other keywords accepted by)

clear_src(do_it=False, do_it_really=False)

This method clears the src directory of the simulation! All files in src get deleted, except of whats in components and optionals! By default, everything except Makefile.local and cparam.local gets erased!

Parameters:
  • True (to activate pass)

  • True

clear_data(do_it=False, do_it_really=False)

This method clears the data directory of the simulation! All files in data get deleted!

Parameters:
  • True (to activate pass)

  • True

remove(do_it=False, do_it_really=False, remove_data=False)

This method removes the WHOLE simulation, but NOT the DATA directory per default. Do remove_data=True to delete data dir as well.

Parameters:
  • True (to activate pass)

  • True

  • remove_data – also clear data directory

get_T_last()

Returns ts.t[-1] WITHOUTH reading the whole time series!

get_extent(dimensions='xy')

Returns extent as [xmin, xmax, ymin, ymax], as needed by e.g. imshow.

Parameters:

dimensions – specify here if you want x, y or z dimensions.

get_varlist(pos=False, particle=False, down=False)

Get a list of all existing VAR# file names.

pos = False: give full list pos = ‘last’/’first’: give latest/first var file pos = ‘lastXXX’ / ‘firstXXX’ give last/first XXX varfiles pos = list of numbers: give varfiles at this positions particle = True: return PVAR- instead of VAR-list down = True: return list of downsampled snapshots

get_var_time(var_file)

Read varN.list to find the time corresponding to a varfile

Parameters:

var_file – string or list of strings

Returns:

float or list of floats depending on the type of var_file

get_pvarlist(pos=False)

Same as get_varfiles(pos, particles=True).

get_lastvarfilename(particle=False, id=False)

Returns las varfile name as string.

get_value(quantity, DEBUG=False)

Optimized version of get_value_from_file. Just state quantity for simulation and param-list together with searchable components will be searched.

get_ts(**kwargs)

Returns time series object. All kwargs are passed to pencil.read.ts.

change_value_in_file(*args, **kwargs)

Same as pencil.io.change_value_in_file.

run(verbose=False, hostfile=None, cleardata=False, **kwargs)

Runs the simulation.

Parameters:
  • verbose (bool) – Whether to print progress and detailed output

  • hostfile (string) – Pencil config file to use

  • cleardata (bool) – Whether to clear existing data

  • self.bash (Accepts all other keywords accepted by)

pencil.sim.simulation.simulation(*args, **kwargs)

Wrapper for Simulation