pencil.ism_dyn ============== .. py:module:: pencil.ism_dyn .. autoapi-nested-parse:: Diagnostics for interstellar-medium dynamo simulations. Submodules ---------- .. toctree:: :maxdepth: 1 /code/sourcePython/pencil/ism_dyn/derived_h5/index /code/sourcePython/pencil/ism_dyn/get_masks/index /code/sourcePython/pencil/ism_dyn/get_stats/index /code/sourcePython/pencil/ism_dyn/ism_cooling/index /code/sourcePython/pencil/ism_dyn/ism_sedov_taylor/index /code/sourcePython/pencil/ism_dyn/rhs_terms/index Attributes ---------- .. autoapisummary:: pencil.ism_dyn.wsw_cooling Classes ------- .. autoapisummary:: pencil.ism_dyn.SedovTaylor Functions --------- .. autoapisummary:: pencil.ism_dyn.derive_data pencil.ism_dyn.calc_derived_data pencil.ism_dyn.is_vector pencil.ism_dyn.der_limits pencil.ism_dyn.under_limits pencil.ism_dyn.cpu_optimal pencil.ism_dyn.open_h5 pencil.ism_dyn.group_h5 pencil.ism_dyn.dataset_h5 pencil.ism_dyn.thermal_decomposition pencil.ism_dyn.derive_masks pencil.ism_dyn.dot pencil.ism_dyn.dot2 pencil.ism_dyn.natural_sort pencil.ism_dyn.helmholtz_fft pencil.ism_dyn.cpu_optimal pencil.ism_dyn.curl pencil.ism_dyn.div pencil.ism_dyn.curl2 pencil.ism_dyn.grad pencil.ism_dyn.fluid_reynolds pencil.ism_dyn.magnetic_reynolds pencil.ism_dyn.open_h5 pencil.ism_dyn.group_h5 pencil.ism_dyn.dataset_h5 pencil.ism_dyn.derive_stats pencil.ism_dyn.plot_hist2d pencil.ism_dyn.sedov_taylor Package Contents ---------------- .. py:function:: derive_data(sim_path, src, dst, magic=['pp', 'tt'], par=[], comm=None, gd=[], grp_overwrite=False, overwrite=False, rank=0, size=1, nghost=3, status='a', chunksize=1000.0, dtype=np.float64, quiet=True, nmin=32, Reynolds_shock=False, lmix=False) .. py:function:: calc_derived_data(src, dst, key, par, gd, l1=3, l2=-3, m1=3, m2=-3, n1=3, n2=-3, nghost=3, Reynolds_shock=False, lmix=False) compute from src data and existing dst data derived data .. py:function:: is_vector(key) Check if the variable denoted by the label key is a vector. .. py:function:: der_limits(n1, n2, m1, m2, l1, l2, nghost) .. py:function:: under_limits(n1, m1, l1, n1shift, m1shift, l1shift, nghost) .. py:function:: cpu_optimal(nx, ny, nz, mvar=8, maux=0, par=dict(), nmin=32, MBmin=5.0, minghosts=7, quiet=True, size=1, remesh=False, nsize=None) .. py:function:: open_h5(filename, status, driver=None, comm=None, overwrite=False, size=1, rank=0, lfs=False, MB=1, count=1) This function opens hdf5 file in serial or parallel. :keyword filename: relative or absolute path string for name of hdf5 file. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword driver: 'mpio' required for parallel: version but absent for serial. :keyword comm: only present for parallel version of h5py. :keyword overwrite: flag to replace existing file. :keyword rank: processor rank with root = 0. .. py:function:: group_h5(h5obj, groupname, status='r', delete=False, overwrite=False, rank=0, size=1, comm=None) This function adds/removes hdf5 group objects. :keyword h5obj: h5 object, may be the file or a sub group within the file :keyword groupname: string for name of the group. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword delete: flag to remove existing group from h5 object. :keyword overwrite: flag to replace existing group from h5 object. :keyword rank: processor rank with root = 0. :keyword comm: only present for parallel version of h5py. .. py:function:: dataset_h5(h5obj, dataname, status='r', data=None, shape=None, dtype=None, overwrite=False, delete=False, rank=0, size=1, comm=None) This function adds/removes hdf5 dataset objects. :keyword h5obj: h5 object, may be the file or a sub group within the file :keyword dataname: string for name of the dataset. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword data: h5 compatible data object; float, integer, string, array :keyword shape: data shape tuple of length > 0 :keyword dtype: h5 compatible data type, eg. np.float64 :keyword delete: flag to remove existing group from h5 object. :keyword overwrite: flag to replace existing group from h5 object. :keyword rank: processor rank with root = 0. :keyword comm: only present for parallel version of h5py. .. py:function:: thermal_decomposition(ss, pars, unit_key='unit_entropy', ent_cut=[2320000000.0]) call signature: thermal_decomposition(ss, pars, unit='unit_entropy', ent_cut=[2.32e9,]) :keyword ss: dataset used for masks, default 'ss', alternate e.g.'tt' :keyword pars: Param() object required for units rescaling :keyword unit_key: label of physical units in pars to apply to code values :keyword ent_cut: list of boundary mask values, default see thesis http://hdl.handle.net/10443/1755 Figure 5.10 may have multiple boundaries .. py:function:: derive_masks(sim_path, src, dst, data_key='data/ss', par=[], comm=None, overwrite=False, rank=0, size=1, nghost=3, status='a', chunksize=1000.0, quiet=True, nmin=32, ent_cuts=[2320000000.0], mask_keys=['hot'], unit_key='unit_entropy') .. py:function:: dot(a, b) dot(a, b) Take dot product of two pencil-code vectors a and b. :param a: Pencil-code vectors with shape [3, mz, my, mx]. :type a: ndarrays :param b: Pencil-code vectors with shape [3, mz, my, mx]. :type b: ndarrays .. py:function:: dot2(a) dot2(a) Take dot product of a pencil-code vector with itself. :param a: Pencil-code vector with shape [3, mz, my, mx]. :type a: ndarray .. py:function:: natural_sort(string_list, reverse=False) natural_sort(string_list, reverse=False) Sort a list of float numbers in strings in a natural way. :param string_list: Will be converted to float, then sorted. :type string_list: list of strings :param reverse: If true, list in reverse order. :type reverse: bool .. py:function:: helmholtz_fft(tot_field, grid, params, nghost=3, pot=True, rot=True, lno_mean=False, nonperi_bc=None, field_scalar=[], s=None, quiet=True) helmholz_fft(field, grid, params) Creates the decomposition vector pair for the supplied vector field. :param tot_field: Vector field of dimension [3, mz, my, mx], which is decomposed. :type tot_field: ndarray :param grid: Grid object with grid spacing dx, dy, dz. :type grid: obj :param params: Simulation Params object with domain dimensions Lx, Ly and Lz. :type params: obj :param nghost: Number of ghost zones to exclude from the fft. :type nghost: int :param lno_mean: Exclude any mean flow from the decomposition - should drop anyway. :type lno_mean: float :param nonperi_bc: String if not None with boundary condition label. How to apply the bc needs to be implemented as required. :type nonperi_bc: string :param field_scalar: Scalar field (density) as debug tool for energy comparison. :type field_scalar: ndarray :param s: List of three integers if not None for fft dimension. If none the dimension of the field [nz,ny,nx] is used. :type s: list of int :rtype: ndarray with decomposed field. .. py:function:: cpu_optimal(nx, ny, nz, mvar=8, maux=0, par=dict(), nmin=32, MBmin=5.0, minghosts=7, quiet=True, size=1, remesh=False, nsize=None) .. py:function:: curl(f, dx=None, dy=None, dz=None, x=None, y=None, run2D=False, coordinate_system='cartesian', grid=None) curl(f, dx=None, dy=None, dz=None, x=None, y=None, run2D=False, coordinate_system="cartesian", grid=None) Take the curl of a pencil code vector array f in various coordinate systems. :param f: Pencil code scalar array f. :type f: ndarray :param grid: Pencil grid object. See pc.read.grid(). :type grid: pencil.read.grids.Grid :param run2D: Deals with pure 2-D snapshots. !Only for Cartesian grids at the moment! Requires grid!=None. :type run2D: bool :param coordinate_system: Coordinate system under which to take the divergence. Takes 'cartesian', 'cylindrical' and 'spherical'. !Does not work for 2d runs yet! :type coordinate_system: string :param Deprecated parameters (only for backwards compatibility): :param --------------------------------------------------------: :param dx: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dx: floats :param dy: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dy: floats :param dz: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dz: floats :param x: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type x: ndarrays :param y: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type y: ndarrays .. py:function:: div(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system='cartesian', grid=None) div(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system="cartesian", grid=None) Take divergence of pencil code vector array f in various coordinate systems. :param f: Pencil code vector array f. :type f: ndarray :param grid: Pencil grid object. See pc.read.grid(). :type grid: pencil.read.grids.Grid :param coordinate_system: Coordinate system under which to take the divergence. Takes 'cartesian', 'cylindrical' and 'spherical'. :type coordinate_system: string :param Deprecated parameters (only for backwards compatibility): :param --------------------------------------------------------: :param dx: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dx: floats :param dy: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dy: floats :param dz: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dz: floats :param x: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type x: ndarrays :param y: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type y: ndarrays .. py:function:: curl2(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system='cartesian', grid=None) curl2(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system="cartesian", grid=None) Take the double curl of a pencil code vector array f. :param f: Pencil code vector array f. :type f: ndarray :param grid: Pencil grid object. See pc.read.grid(). :type grid: pencil.read.grids.Grid :param coordinate_system: Coordinate system under which to take the divergence. Takes 'cartesian', 'cylindrical' and 'spherical'. :type coordinate_system: string :param Deprecated parameters (only for backwards compatibility): :param --------------------------------------------------------: :param dx: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dx: floats :param dy: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dy: floats :param dz: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dz: floats :param x: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type x: ndarrays :param y: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type y: ndarrays .. py:function:: grad(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system='cartesian', grid=None) grad(f, dx=None, dy=None, dz=None, x=None, y=None, coordinate_system="cartesian", grid=None) Take the gradient of a pencil code scalar array f in various coordinate systems. :param f: Pencil code scalar array f. :type f: ndarray :param grid: Pencil grid object. See pc.read.grid(). :type grid: pencil.read.grids.Grid :param coordinate_system: Coordinate system under which to take the divergence. Takes 'cartesian', 'cylindrical' and 'spherical'. :type coordinate_system: string :param Deprecated parameters (only for backwards compatibility): :param --------------------------------------------------------: :param dx: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dx: floats :param dy: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dy: floats :param dz: Grid spacing in the three dimensions. These will not have any effect if grid!=None :type dz: floats :param x: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type x: ndarrays :param y: Radial (x) and polar (y) coordinates, 1d arrays. These will not have any effect if grid!=None :type y: ndarrays .. py:function:: fluid_reynolds(uu, param, grid, lnrho=list(), shock=list(), nghost=3, lmix=True, quiet=True) Computes the fluid Reynolds number from the advective and effective viscous expressions in the momentum equation. call signature: fluid_reynolds(uu, ivisc, grid, rho=None, shock=None, nghost=3) :keyword \*uu*: The velocity field [3,mz,my,mx] from the simulation data :keyword \*param*: The Param simulation object with viscosity data information :keyword \*grid*: The Grid simulation object :keyword \*lnrho*: The log density field if it is non-uniform :keyword \*shock*: The shock variable if shock viscosity is applied :keyword \*nghost*: The number of ghost zones appropriate to the order of accuracy :keyword \*lmix*: Option not to include hyper values when Laplacian values present .. py:function:: magnetic_reynolds(uu, param, grid, aa=list(), bb=list(), jj=list(), nghost=3, lmix=True, quiet=True) Computes the magnetic Reynolds number from the advective and effective resistive expressions in the induction equation. call signature: magnetic_reynolds(uu, param, grid, aa=None, bb=None, jj=None, nghost=3): :keyword \*uu*: The velocity field [3,mz,my,mx] from the simulation data :keyword \*param*: The Param simulation object with resistivity data information :keyword \*grid*: The Grid simulation object :keyword \*aa*: The vector potential if bb is not present or hyper diffusion :keyword \*bb*: The magnetic field :keyword \*jj*: The current density field :keyword \*nghost*: The number of ghost zones appropriate to the order of accuracy :keyword \*lmix*: Option not to include hyper values when Laplacian values present .. py:function:: open_h5(filename, status, driver=None, comm=None, overwrite=False, size=1, rank=0, lfs=False, MB=1, count=1) This function opens hdf5 file in serial or parallel. :keyword filename: relative or absolute path string for name of hdf5 file. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword driver: 'mpio' required for parallel: version but absent for serial. :keyword comm: only present for parallel version of h5py. :keyword overwrite: flag to replace existing file. :keyword rank: processor rank with root = 0. .. py:function:: group_h5(h5obj, groupname, status='r', delete=False, overwrite=False, rank=0, size=1, comm=None) This function adds/removes hdf5 group objects. :keyword h5obj: h5 object, may be the file or a sub group within the file :keyword groupname: string for name of the group. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword delete: flag to remove existing group from h5 object. :keyword overwrite: flag to replace existing group from h5 object. :keyword rank: processor rank with root = 0. :keyword comm: only present for parallel version of h5py. .. py:function:: dataset_h5(h5obj, dataname, status='r', data=None, shape=None, dtype=None, overwrite=False, delete=False, rank=0, size=1, comm=None) This function adds/removes hdf5 dataset objects. :keyword h5obj: h5 object, may be the file or a sub group within the file :keyword dataname: string for name of the dataset. :keyword status: open state of file 'w': write, 'r': read or 'a'/'r+': append. :keyword data: h5 compatible data object; float, integer, string, array :keyword shape: data shape tuple of length > 0 :keyword dtype: h5 compatible data type, eg. np.float64 :keyword delete: flag to remove existing group from h5 object. :keyword overwrite: flag to replace existing group from h5 object. :keyword rank: processor rank with root = 0. :keyword comm: only present for parallel version of h5py. .. py:function:: derive_stats(sim_path, src, dst, stat_keys=['Rm', 'uu', 'Ms'], par=[], comm=None, overwrite=False, rank=0, size=1, nghost=3, status='a', chunksize=1000.0, quiet=True, nmin=32, lmask=False, mask_key='hot') .. py:function:: plot_hist2d(xvar, yvar, par=[], xlim=None, ylim=None, xbins=100, ybins=100, figsize=[3.5 * 1.61803, 3.5], xlabel='$x$', ylabel='$y$', clabel='${\\cal P}\\,(\\log\\,x,\\log\\,y)$', norm=None, cmap=None, density=True, pad=0.02, fontsize=14) xvar: array 1D.ravel() format of variable yvar: array length and format matching xvar of complementary variable par: Param object containing simulation parameters xlim: tuple with min & max bin values for xvar ylim: tuple with min & max bin values for yvar xbins: number of bins for xvar histogram ybins: number of bins for yvar histogram figsize: list of length 2 floats with width and height of figure ylabel: plot y-axis label string xlabel: plot x-axis label string clabel: plot colorbar label string norm: color table normalization from colors cmap: color table density: normalize histogram integral to 1 for PDF fontsize: size of plot fonts .. py:data:: wsw_cooling .. py:function:: sedov_taylor(*args, **kwargs) Compute analytic radial time evolution of SN blast waves for comparison with numerical results *t_sedov*: Time_series object read from the simulation sn_series.dat *par*: Param object containing the simulation parameters *time*: list of time in code units *nt*: Integer size of analytic arrays *endt* Real end time in code units for the time series *dims*: Dimension of the simulation default 3D *rho0*: Ambient ISM density .. py:class:: SedovTaylor Bases: :py:obj:`object` SedovTaylor -- holds blast wave parameters and radial profiles. Fill members with default values. .. py:attribute:: t :value: [] .. py:attribute:: keys :value: [] .. py:method:: get_st(t_sedov=None, par=list(), time=list(), nt=5000, startt=0.0, endt=0.005, dims=3, quiet=True, rho0=None, M0=10, lsnowplough=True, lcioffi=True) Compute analytic radial time evolution of SN blast waves for comparison with numerical results *t_sedov*: Time_series object read from the simulation sn_series.dat *par*: Param object containing the simulation parameters *time*: list of time in code units *nt*: Integer size of analytic arrays *endt* Real end time in code units for the time series *dims*: Dimension of the simulation default 3D *rho0*: Ambient ISM density *lsnowplough: Include original snowplough profile *lcioffi: Include Cioffi et al profile