pencil.sim.simulation ===================== .. py:module:: pencil.sim.simulation .. autoapi-nested-parse:: Contains the simulation class which can be used to directly create, access and manipulate simulations. Exceptions ---------- .. autoapisummary:: pencil.sim.simulation.CommandFailedError Classes ------- .. autoapisummary:: pencil.sim.simulation.Simulation Functions --------- .. autoapisummary:: pencil.sim.simulation.simulation Module Contents --------------- .. py:exception:: CommandFailedError Bases: :py:obj:`RuntimeError` Unspecified run-time error. Initialize self. See help(type(self)) for accurate signature. .. py:class:: 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. :param path: Path to simulation, default = '.'. :type path: string :param hidden: Set True to set hidden flag, default is False. :type hidden: bool :param quiet: Suppress irrelevant output, default is False. :type quiet: bool :param hard: Force update, default is False :type hard: bool :param Properties: :param ----------: :param self.name: :type self.name: name of :param self.path: :type self.path: path to simulation :param self.datadir: :type self.datadir: path to simulation data-dir (./data/) :param self.pc_dir: :type self.pc_dir: path to simulation pc-dir (./pc/) :param self.pc_datadir: :type self.pc_datadir: path to simulation pendir in datadir (data/pc/) :param self.components: the simulation :type self.components: list of files which are necessary components of :param self.optionals: the simulation :type self.optionals: list of files which are optional components of :param self.start_components: :type self.start_components: list of files provided at the simulation start :param self.start_optionals: :type self.start_optionals: list of optional files after the simulation start :param self.hidden: be ignored by pencil :type self.hidden: Default is False, if True this simulation will :param self.param: :type self.param: list of param file :param self.grid: :type self.grid: grid object :param self.index index object: :param self.dim: :type self.dim: dim object :param self.tmp_dict: :type self.tmp_dict: temporal dictionary of stuff, will not be saved .. py:attribute:: path .. py:attribute:: name :value: '' .. py:attribute:: datadir .. py:attribute:: pc_dir .. py:attribute:: pc_datadir .. py:attribute:: components :value: ['src/cparam.local', 'src/Makefile.local', 'start.in', 'run.in', 'print.in'] .. py:attribute:: quantity_searchables :value: ['src/cparam.local', 'start.in', 'run.in'] .. py:attribute:: optionals :value: ['*.in', '*.py', 'submit*'] .. py:attribute:: start_components :value: ['index.pro', 'param.nml', 'pencils.list'] .. py:attribute:: start_optionals :value: ['time_series.dat', '*.pro', '*.h5'] .. py:attribute:: hidden :value: False .. py:attribute:: param :value: False .. py:attribute:: grid :value: False .. py:attribute:: index :value: False .. py:attribute:: dim :value: False .. py:attribute:: ghost_grid :value: False .. py:attribute:: tmp_dict .. py:method:: 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! :param path_root: 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 :type path_root: string :param name: 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! :type name: string :param optionals: Add list of further files to be copied. Wildcasts allowed according to glob module! Set True to use self.optionals. :type optionals: bool :param start optionals: Add list of further files to be copied. Wildcasts allowed according to glob module! Set True to use self.optionals. :param quiet: Set True to suppress output. :type quiet: bool :param rename_submit_script: Set False if no renames shall be performed in submit* files :type rename_submit_script: bool :param OVERWRITE: Set True to overwrite no matter what happens! :type OVERWRITE: bool .. py:method:: 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. :param sim_source: Simulation from where to copy all the files. :type sim_source: string :param varno: var-file number # from which to copy (VAR#). :type varno: int .. py:method:: 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. .. py:method:: hide() Set hide flag True for this simulation. .. py:method:: unhide() Set hide flag False for this simulation. .. py:method:: export() Export simulation object to its root/.pc-dir .. py:method:: started() Returns whether simulation has already started. This is indicated by existing time_series.dat in data directory. .. py:method:: 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. :param cleanall: Before calling pc_build, pc_build --cleanall is called. :type cleanall: bool :param verbose: Activate for verbosity. :type verbose: bool :param fast: Set True for fast compilation. :type fast: bool :param autoclean: If compilation fails, automatically set cleanall=True and retry. :type autoclean: bool :param previous_flags: If True, use the same flags as the last time pc_build was called. :type previous_flags: bool :param additional_options: Addition options to be passed to pc_build. :type additional_options: str :param Accepts all other keywords accepted by self.bash: .. py:method:: build(**kwargs) Same as compile() .. py:method:: 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 :param command: Command to be executed, can be a list of commands. :type command: string :param verbose: lastN = show last N lines of output afterwards False = no output True = all output :type verbose: bool :param bashrc: 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. :type bashrc: bool :param raise_errors: If True, a nonzero return code for command will be raised as a Python error. :type raise_errors: bool .. py:method:: cleanall(verbose=False, hostfile=None, **kwargs) Runs `pc_build --cleanall` in the simulation directory :param verbose: Activate for verbosity. :type verbose: bool :param Accepts all other keywords accepted by self.bash: .. py:method:: 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! :param to activate pass True: :param True: .. py:method:: clear_data(do_it=False, do_it_really=False) This method clears the data directory of the simulation! All files in data get deleted! :param to activate pass True: :param True: .. py:method:: 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. :param to activate pass True: :param True: :param remove_data: also clear data directory .. py:method:: get_T_last() Returns ts.t[-1] WITHOUTH reading the whole time series! .. py:method:: get_extent(dimensions='xy') Returns extent as [xmin, xmax, ymin, ymax], as needed by e.g. imshow. :param dimensions: specify here if you want x, y or z dimensions. .. py:method:: 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 .. py:method:: get_var_time(var_file) Read varN.list to find the time corresponding to a varfile :param var_file: string or list of strings :returns: float or list of floats depending on the type of var_file .. py:method:: get_pvarlist(pos=False) Same as get_varfiles(pos, particles=True). .. py:method:: get_lastvarfilename(particle=False, id=False) Returns las varfile name as string. .. py:method:: 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. .. py:method:: get_ts(**kwargs) Returns time series object. All kwargs are passed to `pencil.read.ts`. .. py:method:: change_value_in_file(*args, **kwargs) Same as pencil.io.change_value_in_file. .. py:method:: run(verbose=False, hostfile=None, cleardata=False, **kwargs) Runs the simulation. :param verbose: Whether to print progress and detailed output :type verbose: bool :param hostfile: Pencil config file to use :type hostfile: string :param cleardata: Whether to clear existing data :type cleardata: bool :param Accepts all other keywords accepted by self.bash: .. py:function:: simulation(*args, **kwargs) Wrapper for :py:class:`Simulation`