pencil.diag

Diagnostic scripts and functions

Submodules

Classes

Tracers

Tracers -- Holds the traced tracer object with the field line integrated

TracersParameterClass

__TracersParameterClass -- Holds the simulation and tracing parameters.

FixedPoint

FixedPoint -- Holds the fixed points and additional integrated quantities.

DiffusionData

DiffusionData -- holds diffusion data for particles.

Functions

diffusion([directions, trange, sim, OVERWRITE, quiet, ...])

Calculate particle diffusion via stalked particles: PSTALK

dispersion_and_drift([sim, OVERWRITE, GLOBAL, LOCAL, ...])

This calculates the dispersion (sigma) and drift (zeta) locally and globally

gas_velo_at_particle_pos([varfiles, sim, scheme, ...])

This script calulates the gas velocity at the particle position and stores this together

gas_alpha([sim, t_range, OVERWRITE])

This calculates the global alpha-value from ts object via

Package Contents

class pencil.diag.Tracers

Bases: object

Tracers – Holds the traced tracer object with the field line integrated quantities and the mapping.

Fill members with default values.

params
x0 = None
y0 = None
x1 = None
y1 = None
z1 = None
l = None
tracers = None
mapping = None
t = None
aa = None
ee = None
curly_A = None
splines = None
find_tracers(var_file='VAR0', datadir='data', trace_field='bb', ti=-1, tf=-1)

Trace streamlines of the vectofield ‘field’ from z = z0 to z = z1 and integrate quantities ‘int_q’ along the lines. Creates a 2d mapping as in ‘streamlines.f90’.

call signature:

find_tracers(var_file=’VAR0’, datadir=’data’, trace_field=’bb’,

ti=-1, tf=-1)

Keyword arguments:

var_file:

Varfile to be read.

datadir:

Directory where the data is stored.

trace_field:

Vector field used for the streamline tracing.

ti:

Initial VAR file index for tracer time sequences. Overrides ‘var_file’.

tf:

Final VAR file index for tracer time sequences. Overrides ‘var_file’.

write(datadir='data', destination='tracers.hdf5')

Write the tracers into a file.

call signature:

write(self, datadir=’data’, destination=’tracers.hdf5’)

Keyword arguments:

datadir:

Directory where the data is stored.

destination:

Destination file.

read(datadir='data', file_name='tracers.hdf5')

Read the tracers from a file.

call signature:

read(self, datadir=’data’, file_name=’tracers.hdf5’)

Keyword arguments:

datadir:

Directory where the data is stored.

file_name:

File with the tracer data.

class pencil.diag.TracersParameterClass

Bases: object

__TracersParameterClass – Holds the simulation and tracing parameters.

Initialize the parameters.

dx = 0
dy = 0
dz = 0
Ox = 0
Oy = 0
Oz = 0
Lx = 0
Ly = 0
Lz = 0
nx = 0
ny = 0
nz = 0
trace_field = ''
rtol = 1e-08
atol = 1e-08
periodic_x = False
periodic_y = False
periodic_z = False
interpolation = 'trilinear'
method = 'RK45'
trace_sub = 1
int_q = ''
var_file = 'VAR0'
ti = -1
tf = -1
datadir = 'data'
destination = 'tracers.hdf5'
n_proc = 1
class pencil.diag.FixedPoint

Bases: object

FixedPoint – Holds the fixed points and additional integrated quantities.

Fill members with default values.

params
t = None
fixed_index = None
fixed_points = None
fixed_tracers = None
fixed_sign = None
poincare = None
tracers = None
find_fixed(datadir='data', var_file='VAR0', trace_field='bb', ti=-1, tf=-1, tracer_file_name=None)

Find the fixed points to a snapshot or existing tracer file.

call signature:

find_fixed(datadir='data', var_file='VAR0', trace_field='bb',
           ti=-1, tf=-1, tracer_file_name=None):
Keyword Arguments:

*datadir*

Data directory.

var_file:

Varfile to be read.

trace_field:

Vector field used for the streamline tracing.

ti:

Initial VAR file index for tracer time sequences. Overrides ‘var_file’.

tf:

Final VAR file index for tracer time sequences. Overrides ‘var_file’.

tracer_file_name

Name of the tracer file to be read. If ‘None’ compute the tracers.

write(datadir='data', destination='fixed_points.hdf5')

Write the fixed points into a file.

call signature:

write(self, datadir=’data’, destination=’fixed_points.hdf5’)

Keyword arguments:

datadir:

Directory where the data is stored.

destination:

Destination file.

read(datadir='data', file_name='fixed_points.hdf5', quiet=True)

Read the fixed points from a file.

call signature:

read(self, datadir=’data’, file_name=’fixed_points.hdf5’)

Keyword arguments:

datadir:

Directory where the data is stored.

file_name:

File with the tracer data.

quiet:

Suppress warnings.

pencil.diag.diffusion(directions=['x'], trange=[0, -1], sim='.', OVERWRITE=False, quiet=True, jump_distance=0.5, use_existing_pstalk_sav=False)

Calculate particle diffusion via stalked particles: PSTALK Therefore, it read PSTALK files from Pencil Code using IDL by using the IDL<->Python Bridge. It may be activated manually!

Generated DiffusionData object will be stored in:

sim.pc_datadir/particle/diffusion/<direction>_<t_start>:<t_end>

and be reloaded and returned if already existing and OVERWRITE=False!

Parameters:
  • sim (-) –

    simulation object, but also simulations object or list of simulations or path of simulation,

    default =’.’

  • for (- directions list or directions to calculate diffusion) – default =[‘x’]

  • ['x' (e.g.) – default =[‘x’]

  • 'y' – default =[‘x’]

  • 'z'] – default =[‘x’]

:param : default =[‘x’] :param - trange range in code time for which diffusion shall be calc.: default =[0, -1] :param - jump_distance expressed in L_: half the domain size :type - jump_distance expressed in L_: x,y,z :param - OVERWRITE previously calculated diffusions shall be overwritten: default =False :param - quiet verbosity: :param default =False: :param - use_existing_pstalk_sav: use existing <sim.datadir>/data/pc/tmp/pstalk.sav for speed up

Returns:

diffusion object for simulation, if function is called for a set of simulations, a dictionary with all diffusion objects and simulation-name as key is returned

class pencil.diag.DiffusionData(direction='x', trange=[0, -1], sim='.', OVERWRITE=False, quiet=True, jump_distance=0.5, use_existing_pstalk_sav=False)

Bases: object

DiffusionData – holds diffusion data for particles.

pencil.diag.dispersion_and_drift(sim=False, OVERWRITE=False, GLOBAL=True, LOCAL=True, use_IDL=False, recalculate_gas_velo_at_particle_pos=False)

This calculates the dispersion (sigma) and drift (zeta) locally and globally by using the gas_velo_at_particle_pos script and dataset for all particles.

With sigma = sqrt( 1/N_par * sum_i^N_par( (v_par(i) - <v_par>)^2 ) ) and zeta = sqrt( 1/N_par * sum_i^N_par( (v_par(i) - u(xp_i))^2 ) )

Arg:

OVERWRITE: set to True to overwrite already calculated results

GLOBAL: Calculate drift and dispersion globally, i.e. whole simulation domain LOCAL: Calculate drift and dispersion locally, i.e. grid cell wise recalculate_gas_velo_at_particle_pos:

if the dataset shall be recalcualted

use_IDL: use backup solution of IDL script and sav files

returns True if successfull

pencil.diag.gas_velo_at_particle_pos(varfiles='last4', sim=False, scheme='tsc', use_IDL=False, OVERWRITE=False)

This script calulates the gas velocity at the particle position and stores this together with particle position, containing grid cell idicies, particle velocities, and particle index in a gas_velo_at_particle_pos file.

Parameters:
  • varfiles – specifiy varfiles for calculation, e.g. ‘last’, ‘first’, ‘all’, ‘VAR###’, ‘last4’, ‘first3’

  • scheme – possible are: - ngp: nearest grid point - cic: cloud in cell - tsc: triangular shaped cloud

  • OVERWRITE – set to True to overwrite already calculated results

pencil.diag.gas_alpha(sim=False, t_range=[0, -1], OVERWRITE=False)
This calculates the global alpha-value from ts object via

alphah=(2./3.)*(ts3.uxuym)/(ts3.rhom*ts3.csm**2)

for the lastNentries of the time series. Input:

t_range use this time range of the timeseries OVERWRITE overwrite alpha file in sim.pc_datadir/alpha_<lastNentries>

Returns:

alpha dictionary