User-defined Kernels#

parcels.kernel module#

class parcels.kernel.BaseKernel(fieldset, ptype, pyfunc=None, funcname=None, funccode=None, py_ast=None, funcvars=None, c_include='', delete_cfiles=True)[source]#

Superclass for ‘normal’ and Interactive Kernels

Attributes
c_include
fieldset
ptype
pyfunc

Methods

fix_indentation(string)

Fix indentation to allow in-lined kernel definitions.

remove_deleted(pset)

Utility to remove all particles that signalled deletion.

property c_include[source]#
property fieldset[source]#
static fix_indentation(string)[source]#

Fix indentation to allow in-lined kernel definitions.

property ptype[source]#
property pyfunc[source]#
remove_deleted(pset)[source]#

Utility to remove all particles that signalled deletion.

class parcels.kernel.Kernel(fieldset, ptype, pyfunc=None, funcname=None, funccode=None, py_ast=None, funcvars=None, c_include='', delete_cfiles=True)[source]#

Kernel object that encapsulates auto-generated code.

Parameters
  • fieldset (parcels.Fieldset) – FieldSet object providing the field information (possibly None)

  • ptype – PType object for the kernel particle

  • pyfunc – (aggregated) Kernel function

  • funcname (str) – function name

  • delete_cfiles (bool) – Whether to delete the C-files after compilation in JIT mode (default is True)

Notes

A Kernel is either created from a compiled <function …> object or the necessary information (funcname, funccode, funcvars) is provided. The py_ast argument may be derived from the code string, but for concatenation, the merged AST plus the new header definition is required.

Attributes
c_include
fieldset
ptype
pyfunc

Methods

check_fieldsets_in_kernels(pyfunc)

Checks the integrity of the fieldset with the kernels.

compile(compiler)

Writes kernel code to file and compiles it.

evaluate_particle(p, endtime)

Execute the kernel evaluation of for an individual particle.

execute(pset, endtime, dt)

Execute this Kernel over a ParticleSet for several timesteps.

execute_jit(pset, endtime, dt)

Invokes JIT engine to perform the core update loop.

execute_python(pset, endtime, dt)

Performs the core update loop via Python.

fix_indentation(string)

Fix indentation to allow in-lined kernel definitions.

from_list(fieldset, ptype, pyfunc_list, ...)

Create a combined kernel from a list of functions.

get_kernel_compile_files()

Returns the correct src_file, lib_file, log_file for this kernel.

load_fieldset_jit(pset)

Updates the loaded fields of pset's fieldset according to the chunk information within their grids.

remove_deleted(pset)

Utility to remove all particles that signalled deletion.

add_scipy_positionupdate_kernels

check_kernel_signature_on_version

cleanup_remove_files

cleanup_unload_lib

load_lib

merge

remove_lib

add_scipy_positionupdate_kernels()[source]#
property c_include[source]#
check_fieldsets_in_kernels(pyfunc)[source]#

Checks the integrity of the fieldset with the kernels.

This function is to be called from the derived class when setting up the ‘pyfunc’.

check_kernel_signature_on_version()[source]#
static cleanup_remove_files(lib_file, all_files_array, delete_cfiles)[source]#
static cleanup_unload_lib(lib)[source]#
compile(compiler)[source]#

Writes kernel code to file and compiles it.

evaluate_particle(p, endtime)[source]#

Execute the kernel evaluation of for an individual particle.

Parameters
  • p – object of (sub-)type (ScipyParticle, JITParticle)

  • endtime – endtime of this overall kernel evaluation step

  • dt – computational integration timestep

execute(pset, endtime, dt)[source]#

Execute this Kernel over a ParticleSet for several timesteps.

execute_jit(pset, endtime, dt)[source]#

Invokes JIT engine to perform the core update loop.

execute_python(pset, endtime, dt)[source]#

Performs the core update loop via Python.

property fieldset[source]#
classmethod from_list(fieldset, ptype, pyfunc_list, *args, **kwargs)[source]#

Create a combined kernel from a list of functions.

Takes a list of functions, converts them to kernels, and joins them together.

Parameters
  • fieldset (parcels.Fieldset) – FieldSet object providing the field information (possibly None)

  • ptype – PType object for the kernel particle

  • pyfunc_list (list of functions) – List of functions to be combined into a single kernel.

  • *args – Additional arguments passed to first kernel during construction.

  • **kwargs – Additional keyword arguments passed to first kernel during construction.

get_kernel_compile_files()[source]#

Returns the correct src_file, lib_file, log_file for this kernel.

load_fieldset_jit(pset)[source]#

Updates the loaded fields of pset’s fieldset according to the chunk information within their grids.

load_lib()[source]#
merge(kernel, kclass)[source]#
property ptype[source]#
property pyfunc[source]#
remove_lib()[source]#