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
remove_deleted(pset)Utility to remove all particles that signalled deletion.
get_kernel_compile_files
remove_lib
- 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.
Returns number of arguments in a Python function.
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.
from_list(fieldset, ptype, pyfunc_list, ...)Create a combined kernel from a list of functions.
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
cleanup_remove_files
cleanup_unload_lib
load_lib
merge
remove_lib
- 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’.
- static cleanup_remove_files(lib_file: str | None, all_files: list[str], delete_cfiles: bool) None[source]#
- 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
- 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.