psyclone.domain.lfric#
Module for the LFRic domain.
Submodules#
psyclone.domain.lfric.algorithm- Submodules
- Classes
psyclone.domain.lfric.arg_index_to_metadata_indexpsyclone.domain.lfric.arg_ordering- Classes
ArgOrderingArgOrdering.append()ArgOrdering.append_array_reference()ArgOrdering.append_integer_reference()ArgOrdering.arglistArgOrdering.banded_dofmap()ArgOrdering.basis()ArgOrdering.cell_map()ArgOrdering.cell_position()ArgOrdering.cma_operator()ArgOrdering.diff_basis()ArgOrdering.extend()ArgOrdering.field()ArgOrdering.field_bcs_kernel()ArgOrdering.field_vector()ArgOrdering.fs_common()ArgOrdering.fs_compulsory_field()ArgOrdering.fs_intergrid()ArgOrdering.generate()ArgOrdering.get_array_reference()ArgOrdering.halo_depth()ArgOrdering.indirection_dofmap()ArgOrdering.mesh_height()ArgOrdering.mesh_properties()ArgOrdering.metadata_index_from_actual_index()ArgOrdering.num_argsArgOrdering.operator()ArgOrdering.operator_bcs_kernel()ArgOrdering.psyir_append()ArgOrdering.psyir_arglistArgOrdering.quad_rule()ArgOrdering.ref_element_properties()ArgOrdering.scalar()ArgOrdering.stencil()ArgOrdering.stencil_2d()ArgOrdering.stencil_2d_max_extent()ArgOrdering.stencil_2d_unknown_extent()ArgOrdering.stencil_unknown_direction()ArgOrdering.stencil_unknown_extent()
- Classes
psyclone.domain.lfric.function_spacepsyclone.domain.lfric.kern_call_acc_arg_list- Classes
KernCallAccArgListKernCallAccArgList.cell_map()KernCallAccArgList.cell_position()KernCallAccArgList.field()KernCallAccArgList.fs_compulsory_field()KernCallAccArgList.fs_intergrid()KernCallAccArgList.operator()KernCallAccArgList.scalar()KernCallAccArgList.stencil()KernCallAccArgList.stencil_2d()KernCallAccArgList.stencil_2d_unknown_extent()KernCallAccArgList.stencil_unknown_extent()
- Classes
psyclone.domain.lfric.kern_call_arg_list- Classes
KernCallArgListKernCallArgList.NdfInfoKernCallArgList.append_structure_reference()KernCallArgList.basis()KernCallArgList.cell_map()KernCallArgList.cell_position()KernCallArgList.cell_ref_name()KernCallArgList.cma_operator()KernCallArgList.diff_basis()KernCallArgList.field()KernCallArgList.field_bcs_kernel()KernCallArgList.field_vector()KernCallArgList.fs_common()KernCallArgList.fs_compulsory_field()KernCallArgList.fs_intergrid()KernCallArgList.get_user_type()KernCallArgList.mesh_height()KernCallArgList.mesh_properties()KernCallArgList.ndf_positionsKernCallArgList.nlayers_positionsKernCallArgList.nqp_positionsKernCallArgList.operator()KernCallArgList.operator_bcs_kernel()KernCallArgList.quad_rule()KernCallArgList.scalar()KernCallArgList.stencil()KernCallArgList.stencil_2d()KernCallArgList.stencil_2d_max_extent()KernCallArgList.stencil_2d_unknown_extent()KernCallArgList.stencil_unknown_direction()KernCallArgList.stencil_unknown_extent()
- Classes
psyclone.domain.lfric.kern_call_invoke_arg_list- Classes
KernCallInvokeArgListKernCallInvokeArgList.field()KernCallInvokeArgList.field_vector()KernCallInvokeArgList.fieldsKernCallInvokeArgList.fs_common()KernCallInvokeArgList.generate()KernCallInvokeArgList.halo_depth()KernCallInvokeArgList.operator()KernCallInvokeArgList.operatorsKernCallInvokeArgList.quad_rule()KernCallInvokeArgList.quadrature_objectsKernCallInvokeArgList.scalar()KernCallInvokeArgList.scalarsKernCallInvokeArgList.stencil()KernCallInvokeArgList.stencil_2d()KernCallInvokeArgList.stencil_2d_unknown_extent()KernCallInvokeArgList.stencil_unknown_extent()
- Classes
psyclone.domain.lfric.kern_stub_arg_list- Classes
KernStubArgListKernStubArgList.basis()KernStubArgList.cell_position()KernStubArgList.cma_operator()KernStubArgList.diff_basis()KernStubArgList.field()KernStubArgList.field_bcs_kernel()KernStubArgList.field_vector()KernStubArgList.fs_compulsory_field()KernStubArgList.indirection_dofmap()KernStubArgList.mesh_height()KernStubArgList.mesh_properties()KernStubArgList.operator()KernStubArgList.operator_bcs_kernel()KernStubArgList.quad_rule()KernStubArgList.stencil()KernStubArgList.stencil_2d()KernStubArgList.stencil_2d_max_extent()KernStubArgList.stencil_2d_unknown_extent()KernStubArgList.stencil_unknown_direction()KernStubArgList.stencil_unknown_extent()
- Classes
psyclone.domain.lfric.kernel- Submodules
psyclone.domain.lfric.kernel.columnwise_operator_arg_metadatapsyclone.domain.lfric.kernel.common_arg_metadatapsyclone.domain.lfric.kernel.common_declaration_metadata- Classes
CommonDeclarationMetadataCommonDeclarationMetadata.array_declaration_string()CommonDeclarationMetadata.fparser2_classCommonDeclarationMetadata.get_derived_array_declaration()CommonDeclarationMetadata.get_intrinsic_array_declaration()CommonDeclarationMetadata.get_intrinsic_scalar_declaration()CommonDeclarationMetadata.scalar_declaration_string()CommonDeclarationMetadata.type_declaration_string()CommonDeclarationMetadata.validate_list()CommonDeclarationMetadata.validate_name_value()CommonDeclarationMetadata.validate_node()
- Classes
psyclone.domain.lfric.kernel.common_meta_arg_metadata- Classes
CommonMetaArgMetadataCommonMetaArgMetadata.accessCommonMetaArgMetadata.check_access()CommonMetaArgMetadata.check_datatype()CommonMetaArgMetadata.check_first_arg()CommonMetaArgMetadata.check_nargs()CommonMetaArgMetadata.check_remaining_args()CommonMetaArgMetadata.create_from_fparser2()CommonMetaArgMetadata.datatypeCommonMetaArgMetadata.get_vector_length()
- Classes
psyclone.domain.lfric.kernel.common_metadatapsyclone.domain.lfric.kernel.evaluator_targets_metadatapsyclone.domain.lfric.kernel.field_arg_metadatapsyclone.domain.lfric.kernel.field_vector_arg_metadatapsyclone.domain.lfric.kernel.inter_grid_arg_metadatapsyclone.domain.lfric.kernel.inter_grid_vector_arg_metadatapsyclone.domain.lfric.kernel.lfric_kernel_metadata- Classes
LFRicKernelMetadataLFRicKernelMetadata.create_from_fparser2()LFRicKernelMetadata.create_from_psyir()LFRicKernelMetadata.evaluator_targetsLFRicKernelMetadata.field_meta_args_on_fs()LFRicKernelMetadata.fortran_string()LFRicKernelMetadata.fparser2_classLFRicKernelMetadata.kernel_typeLFRicKernelMetadata.lower_to_psyir()LFRicKernelMetadata.meta_argsLFRicKernelMetadata.meta_args_get()LFRicKernelMetadata.meta_funcsLFRicKernelMetadata.meta_meshLFRicKernelMetadata.meta_ref_elementLFRicKernelMetadata.nameLFRicKernelMetadata.operates_onLFRicKernelMetadata.operator_meta_args_on_fs()LFRicKernelMetadata.procedure_nameLFRicKernelMetadata.shapesLFRicKernelMetadata.validate()
- Classes
psyclone.domain.lfric.kernel.meta_args_metadatapsyclone.domain.lfric.kernel.meta_funcs_arg_metadatapsyclone.domain.lfric.kernel.meta_funcs_metadatapsyclone.domain.lfric.kernel.meta_mesh_arg_metadatapsyclone.domain.lfric.kernel.meta_mesh_metadatapsyclone.domain.lfric.kernel.meta_ref_element_arg_metadatapsyclone.domain.lfric.kernel.meta_ref_element_metadatapsyclone.domain.lfric.kernel.operates_on_metadatapsyclone.domain.lfric.kernel.operator_arg_metadatapsyclone.domain.lfric.kernel.psyirpsyclone.domain.lfric.kernel.scalar_arg_metadatapsyclone.domain.lfric.kernel.scalar_array_arg_metadatapsyclone.domain.lfric.kernel.shapes_metadata
- Submodules
psyclone.domain.lfric.kernel_interfacepsyclone.domain.lfric.lfric_arg_descriptorpsyclone.domain.lfric.lfric_builtins- Classes
LFRicBuiltInCallFactoryLFRicBuiltInLFRicBuiltIn.cma_operationLFRicBuiltIn.fs_descriptorsLFRicBuiltIn.get_dof_loop_index_symbol()LFRicBuiltIn.get_indexed_field_argument_references()LFRicBuiltIn.get_scalar_argument_references()LFRicBuiltIn.halo_depthLFRicBuiltIn.is_intergridLFRicBuiltIn.load()LFRicBuiltIn.metadata()LFRicBuiltIn.qr_requiredLFRicBuiltIn.reference_accesses()LFRicBuiltIn.reference_elementLFRicBuiltIn.undf_name
LFRicXPlusYKernLFRicIncXPlusYKernLFRicAPlusXKernLFRicIncAPlusXKernLFRicAXPlusYKernLFRicIncAXPlusYKernLFRicIncXPlusBYKernLFRicAXPlusBYKernLFRicIncAXPlusBYKernLFRicAXPlusAYKernLFRicXMinusYKernLFRicIncXMinusYKernLFRicAMinusXKernLFRicIncAMinusXKernLFRicXMinusAKernLFRicIncXMinusAKernLFRicAXMinusYKernLFRicXMinusBYKernLFRicIncXMinusBYKernLFRicAXMinusBYKernLFRicXTimesYKernLFRicIncXTimesYKernLFRicIncAXTimesYKernLFRicATimesXKernLFRicIncATimesXKernLFRicXDividebyYKernLFRicIncXDividebyYKernLFRicXDividebyAKernLFRicIncXDividebyAKernLFRicADividebyXKernLFRicIncADividebyXKernLFRicIncXPowrealAKernLFRicIncXPowintNKernLFRicSetvalCKernLFRicSetvalXKernLFRicSetvalRandomKernLFRicXInnerproductYKernLFRicXInnerproductXKernLFRicSumXKernLFRicSignXKernLFRicMaxAXKernLFRicIncMaxAXKernLFRicMinAXKernLFRicIncMinAXKernLFRicRealToIntXKernLFRicRealToRealXKernLFRicIntXPlusYKernLFRicIntIncXPlusYKernLFRicIntAPlusXKernLFRicIntIncAPlusXKernLFRicIntXMinusYKernLFRicIntIncXMinusYKernLFRicIntAMinusXKernLFRicIntIncAMinusXKernLFRicIntXMinusAKernLFRicIntIncXMinusAKernLFRicIntXTimesYKernLFRicIntIncXTimesYKernLFRicIntATimesXKernLFRicIntIncATimesXKernLFRicIntSetvalCKernLFRicIntSetvalXKernLFRicIntSignXKernLFRicIntMaxAXKernLFRicIntIncMaxAXKernLFRicIntMinAXKernLFRicIntIncMinAXKernLFRicIntToRealXKern
- Classes
psyclone.domain.lfric.lfric_cell_iteratorspsyclone.domain.lfric.lfric_collectionpsyclone.domain.lfric.lfric_constantspsyclone.domain.lfric.lfric_dofmapspsyclone.domain.lfric.lfric_driver_creatorpsyclone.domain.lfric.lfric_fieldspsyclone.domain.lfric.lfric_halo_depthspsyclone.domain.lfric.lfric_invokepsyclone.domain.lfric.lfric_invoke_schedulepsyclone.domain.lfric.lfric_invokespsyclone.domain.lfric.lfric_kern- Classes
LFRicKernLFRicKern.QRRuleLFRicKern.all_updates_are_writesLFRicKern.argument_kindsLFRicKern.base_nameLFRicKern.cma_operationLFRicKern.colourmapLFRicKern.eval_shapesLFRicKern.eval_targetsLFRicKern.fs_descriptorsLFRicKern.gen_stubLFRicKern.get_callees()LFRicKern.get_interface_symbol()LFRicKern.halo_depthLFRicKern.is_intergridLFRicKern.last_cell_all_colours_symbolLFRicKern.load()LFRicKern.load_meta()LFRicKern.meshLFRicKern.ncolours_varLFRicKern.ntilecolours_varLFRicKern.qr_requiredLFRicKern.qr_rulesLFRicKern.reference_accesses()LFRicKern.reference_elementLFRicKern.tilecolourmapLFRicKern.undf_nameLFRicKern.validate_global_constraints()LFRicKern.validate_kernel_code_args()
- Classes
psyclone.domain.lfric.lfric_kern_call_factorypsyclone.domain.lfric.lfric_kern_metadatapsyclone.domain.lfric.lfric_loop- Classes
LFRicLoopLFRicLoop.create_halo_exchanges()LFRicLoop.gen_mark_halos_clean_dirty()LFRicLoop.independent_iterations()LFRicLoop.load()LFRicLoop.lower_bound_psyir()LFRicLoop.lower_to_language_level()LFRicLoop.node_str()LFRicLoop.set_lower_bound()LFRicLoop.set_upper_bound()LFRicLoop.update_halo_exchanges()LFRicLoop.upper_bound_halo_depthLFRicLoop.upper_bound_nameLFRicLoop.upper_bound_psyir()
- Classes
psyclone.domain.lfric.lfric_loop_boundspsyclone.domain.lfric.lfric_psypsyclone.domain.lfric.lfric_run_time_checkspsyclone.domain.lfric.lfric_scalar_argspsyclone.domain.lfric.lfric_stencils- Classes
LFRicStencilsLFRicStencils.direction_name()LFRicStencils.dofmap_size_symbol()LFRicStencils.dofmap_symbol()LFRicStencils.extent_value()LFRicStencils.initialise()LFRicStencils.invoke_declarations()LFRicStencils.map_name()LFRicStencils.max_branch_length()LFRicStencils.stencil_unique_str()LFRicStencils.stub_declarations()LFRicStencils.unique_alg_vars
- Classes
psyclone.domain.lfric.lfric_symbol_tablepsyclone.domain.lfric.lfric_typespsyclone.domain.lfric.metadata_to_arguments_rulespsyclone.domain.lfric.transformations- Submodules
psyclone.domain.lfric.transformations.lfric_alg_invoke_2_psy_call_transpsyclone.domain.lfric.transformations.lfric_alg_transpsyclone.domain.lfric.transformations.lfric_extract_transpsyclone.domain.lfric.transformations.lfric_loop_fuse_transpsyclone.domain.lfric.transformations.raise_psyir_2_lfric_alg_transpsyclone.domain.lfric.transformations.raise_psyir_2_lfric_kern_trans
- Submodules
psyclone.domain.lfric.utils
Classes#
ArgOrdering: Base class capturing the arguments, type and ordering of data inFunctionSpace: Manages the name of a function space. If it is an any_space orKernCallAccArgList: Kernel call arguments that need to be declared by OpenACCKernCallArgList: Creates the argument list required to call kernel “kern” from theKernelInterface: Create the kernel arguments for the supplied kernel as specified byKernStubArgList: Creates the argument list required to create and declare theLFRicArgDescriptor: This class captures the information specified in one of LFRic API argumentLFRicCellIterators: Handles all entities required by kernels that operate on cell-columns.LFRicCollection: Base class for managing the declaration and initialisation of aLFRicConstants: This class stores all LFRic constants. Note that some constantsLFRicDofmaps: Holds all information on the dofmaps (including column-banded andLFRicDriverCreator: This class provides the functionality to create a driver thatLFRicFields: Manages the declarations for all field arguments required by an InvokeLFRicHaloDepths: Manages the declarations for all halo-depth arguments (as needed byLFRicInvoke: The LFRic-specific Invoke class. This passes the LFRic-specificLFRicInvokes: The LFRic-specific invokes class. This passes the LFRic-specificLFRicInvokeSchedule: The LFRic-specific InvokeSchedule sub-class. This passes the LFRic-LFRicKern: Stores information about LFRic Kernels as specified by theLFRicKernCallFactory: Create the necessary framework for an LFRic kernel call.LFRicKernMetadata: Captures the Kernel subroutine code and metadata describingLFRicLoop: The LFRic-specific PSyLoop class. This passes the LFRic-specificLFRicLoopBounds: Handles all variables required for specifying loop limits withinLFRicPSy: The LFRic-specific PSy class. This creates an LFRic-specificLFRicRunTimeChecks: Handle declarations and code generation for run-time checks. ThisLFRicScalarArgs: Handles the declarations of scalar kernel arguments appearing in eitherLFRicStencils: Stencil information and code generation associated with a PSy-layerLFRicSymbolTable: Sub-classes SymbolTable to provide an LFRic-specific implementation.
- class psyclone.domain.lfric.ArgOrdering(kern)[source]#
Base class capturing the arguments, type and ordering of data in a Kernel call. This base class implements some functionality of a list (extend and append functions), but not using list as a base class. Reason is that many typical functions of a list make only sense to be used after
generateis called, which would then require a large number of functions to be re-implemented. So instead the propertyarglistchecks thatgeneratehas been called and then provides a list.- Parameters:
kern (
psyclone.domain.lfric.LFRicKern) – the kernel call object to use.
Inheritance

- append(var_name, var_accesses=None, var_access_name=None, mode=AccessType.READ, metadata_posn=None)[source]#
Appends the specified variable name to the list of all arguments and stores the mapping between the position of this actual argument and the corresponding metadata entry. If var_accesses is given, it will also record the access to the variable. The name of the variable accessed can be overwritten by specifying var_access_name. By default it is assumed that access mode is READ (which can be set with
mode).- Parameters:
var_name (str) – the name of the variable.
var_accesses (
psyclone.core.VariablesAccessMap) – optional class to store variable access information.var_access_name (str) – optional name of the variable for which access information is stored (used e.g. when the actual argument is field_proxy, but the access is to be recorded for field).
mode (
psyclone.core.access_type.AccessType) – optional access mode (defaults to READ).metadata_posn (int) – the location of the corresponding entry in the list of arguments in the kernel metadata (if any).
- append_array_reference(array_name, indices, intrinsic_type=None, tag=None, symbol=None)[source]#
This function adds an array reference. If there is no symbol with the given tag, a new array symbol will be defined using the given intrinsic_type. If a symbol already exists but has no type, it will be replaced. The created reference is added to the list of PSyIR expressions, and the symbol is returned to the user.
- Parameters:
array_name (str) – the name and tag of the array.
indices (List[Union[str, py:class:psyclone.psyir.nodes.Node]]) – the indices to be used in the PSyIR reference. It must either be “:”, or a PSyIR node.
intrinsic_type (Optional[
psyclone.psyir.symbols.datatypes.ScalarType]) – the intrinsic type of the array.tag (Optional[str]) – optional tag for the symbol.
symbol (Optional[
psyclone.psyir.symbols.Symbol]) – optional the symbol to use.
- Returns:
the symbol used in the added reference.
- Return type:
- append_integer_reference(name, tag=None)[source]#
This function adds a reference to an integer variable to the list of PSyIR nodes. If the symbol does not exist, it will be added to the symbol table. If no tag is specified, is uses the name as tag. It also returns the symbol.
- Parameters:
name (str) – name of the integer variable to declare.
tag (Optional[str]) – optional tag of the integer variable to declare.
- Returns:
the symbol to which a reference was added.
- Return type:
- property arglist#
- Returns:
the kernel argument list. The generate method must be called first.
- Return type:
List[str]
- Raises:
InternalError – if the generate() method has not been called.
- banded_dofmap(function_space, var_accesses=None)[source]#
Add banded dofmap (required for CMA operator assembly).
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which banded dofmap is added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod basis(function_space, var_accesses=None)[source]#
Add basis function information for this function space to the argument list and optionally to the variable access information.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the basis function is required.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_map(var_accesses=None)[source]#
Add cell-map and related cell counts (for inter-grid kernels) to the argument list. If supplied it also stores these accesses to the var_access object.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_position(var_accesses=None)[source]#
Add cell position information.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod cma_operator(arg, var_accesses=None)[source]#
Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the CMA operator argument.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod diff_basis(function_space, var_accesses=None)[source]#
Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the differential basis functions are required.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- extend(list_var_name, var_accesses=None, mode=AccessType.READ, list_metadata_posn=None)[source]#
Appends all variable names in the argument list to the list of all arguments. If var_accesses is given, it will also record the access to the variables. By default any access will be recorded as a read-only access, but this can be changed (for all variables included) using mode.
- Parameters:
list_var_name (list of str.) – the list with name of the variables to append.
var_accesses (
psyclone.core.VariablesAccessMap) – optional class to store variable access information.mode (Optional[
psyclone.core.access_type.AccessType]) – optional access mode (defaults to READ).list_metadata_posn (Optional[List[int]]) – list of metadata argument positions.
- abstractmethod field(arg, var_accesses=None)[source]#
Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the field to be added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod field_bcs_kernel(function_space, var_accesses=None)[source]#
Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.
- Parameters:
function_space – the function space for which boundary dofs are required.
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod field_vector(argvect, var_accesses=None)[source]#
Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.
- Parameters:
argvect (
psyclone.lfric.LFRicKernelArgument) – the field vector to add.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_common(function_space, var_accesses=None)[source]#
Add function-space related arguments common to LMA operators and fields. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the related arguments common to LMA operators and fields are added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_compulsory_field(function_space, var_accesses=None)[source]#
Add compulsory arguments associated with this function space to the list. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the compulsory arguments are added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod fs_intergrid(function_space, var_accesses=None)[source]#
Add function-space related arguments for an intergrid kernel. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which to add argumentsvar_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- generate(var_accesses=None)[source]#
Specifies which arguments appear in an argument list, their type and their ordering. Calls methods for each type of argument that can be specialised by a child class for its particular need. If the optional argument var_accesses is supplied, this function will also add variable access information for each implicit argument (i.e. that is not explicitly listed in kernel metadata) that is added. These accesses will be marked as read.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance that stores the information about variable accesses.- Raises:
GenerationError – if the kernel arguments break the rules for the LFRic API.
- get_array_reference(array_name, indices, intrinsic_type=None, tag=None, symbol=None)[source]#
This function creates an array reference. If there is no symbol with the given tag, a new array symbol will be defined using the given intrinsic_type. If a symbol already exists but has no type, it will be replaced.
- Parameters:
array_name (str) – the name and tag of the array.
indices (List[Union[str, py:class:psyclone.psyir.nodes.Node]]) – the indices to be used in the PSyIR reference. It must either be “:”, or a PSyIR node.
intrinsic_type (Optional[
psyclone.psyir.symbols.datatypes.ScalarType]) – the intrinsic type of the array. Defaults to LFRicIntegerScalarDataType.tag (Optional[str]) – optional tag for the symbol.
symbol – optional the symbol to use.
- Type:
Optional[
psyclone.psyir.symbols.Symbol]- Returns:
a reference to the symbol used.
- Return type:
- halo_depth(var_accesses=None)[source]#
Add a halo-depth argument to the Kernel argument list. This default implementation does nothing as halo depths are not passed to kernel subroutines (but they are passed down from the Algorithm layer to the PSy layer).
- Parameters:
var_accesses (Optional[
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store information about variable accesses.
- indirection_dofmap(function_space, operator=None, var_accesses=None)[source]#
Add indirection dofmap required when applying a CMA operator. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the indirect dofmap is required.operator (
psyclone.lfric.LFRicKernelArgument) – the CMA operator (not used at the moment).var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- mesh_height(var_accesses=None)[source]#
Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod mesh_properties(var_accesses=None)[source]#
Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- metadata_index_from_actual_index(idx)[source]#
Returns the index of the entry in the meta_args list from which the actual subroutine argument at idx originated.
- Parameters:
idx (int) – the index of an actual argument to the kernel subroutine.
- Returns:
the 0-indexed position of the corresponding metadata entry or None if there isn’t one.
- Return type:
Optional[int]
- property num_args#
- Returns:
the current number of arguments stored in _arglist.
- Return type:
int
- abstractmethod operator(arg, var_accesses=None)[source]#
Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the operator.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod operator_bcs_kernel(function_space, var_accesses=None)[source]#
Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space of the operator.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- psyir_append(node)[source]#
Appends a PSyIR node to the PSyIR argument list.
- Parameters:
node (
psyclone.psyir.nodes.Node) – the node to append.
- property psyir_arglist#
- Returns:
the kernel argument list as PSyIR expressions. The generate method must be called first.
- Return type:
- Raises:
InternalError – if the generate() method has not been called.
- abstractmethod quad_rule(var_accesses=None)[source]#
Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- ref_element_properties(var_accesses=None)[source]#
Add kernel arguments relating to properties of the reference element. If supplied it also stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- scalar(scalar_arg, var_accesses=None)[source]#
Add the name associated with the scalar argument to the argument list and optionally add this scalar to the variable access information.
- Parameters:
scalar_arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance that stores information about variable accesses.
- Raises:
InternalError – if the argument is not a recognised scalar type.
- abstractmethod stencil(arg, var_accesses=None)[source]#
Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod stencil_2d(arg, var_accesses=None)[source]#
Add 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod stencil_2d_max_extent(arg, var_accesses=None)[source]#
Add 2D stencil information to the argument list associated with the argument ‘arg’ if the stencil extent (from which it is calculated) is passed from the Algorithm layer rather than being specified in kernel metadata. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod stencil_2d_unknown_extent(arg, var_accesses=None)[source]#
Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod stencil_unknown_direction(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown (i.e. it’s being supplied in a variable). If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- abstractmethod stencil_unknown_extent(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- class psyclone.domain.lfric.FunctionSpace(name, kernel_args)[source]#
Manages the name of a function space. If it is an any_space or any_discontinuous_space then its name is mangled such that it is unique within the scope of an Invoke.
- Parameters:
name (str) – original name of function space to create a mangled name for.
kernel_args (
psyclone.lfric.LFRicKernelArguments) – object encapsulating all arguments to the kernel, one or more of which are on this function space.
- Raises:
InternalError – if an unrecognised function space is encountered.
Inheritance

- property cbanded_map_name#
- Returns:
the name of a column-banded dofmap for this FunctionSpace.
- Return type:
str
- property cma_indirection_map_name#
- Returns:
the name of a CMA indirection dofmap for the supplied FunctionSpace.
- Return type:
str
- cma_on_space(arguments)[source]#
Returns the corresponding argument if the supplied list of arguments contains a cma operator that maps to/from this FunctionSpace. Otherwise this function returns None.
- Parameters:
arguments (
psyclone.lfric.LFRicKernelArguments) – list of arguments to be tested.- Returns:
the argument from the supplied list of arguments that contains a field that exists on this space or None.
- Return type:
- field_on_space(arguments)[source]#
Returns the corresponding argument if the supplied list of arguments contains a field that exists on this space. Otherwise this function returns None.
- Parameters:
arguments (
psyclone.lfric.LFRicKernelArguments) – list of arguments to be tested.- Returns:
the argument from the supplied list of arguments that contains a field that exists on this space or None.
- Return type:
- get_basis_name(qr_var=None, on_space=None)[source]#
Returns a name for the basis function on this FunctionSpace. If the name of an associated quadrature object is supplied then this is appended to the returned name. Similarly, if the function space at which the basis is to be evaluated is supplied then this is also appended to the name.
- Parameters:
qr_var (string) – the name of the Quadrature Object for which the basis functions are required
on_space (
psyclone.domain.lfric.FunctionSpace) – the function space at which the basis functions will be evaluated
- Returns:
name for the Fortran array holding the basis function
- Return type:
str
- get_diff_basis_name(qr_var=None, on_space=None)[source]#
Returns a name for the differential basis function on this FunctionSpace. If the name of an associated quadrature object is supplied then this is appended to the returned name. Similarly, if the function space at which the basis is to be evaluated is supplied then this is also appended to the name.
- Parameters:
qr_var (str) – the name of the Quadrature Object for which the differential basis functions are required.
on_space (
psyclone.domain.lfric.FunctionSpace) – the function space at which the differential basis functions will be evaluated
- Return type:
str- Returns:
name for the Fortran array holding the differential basis function
- get_operator_name(operator_name, qr_var=None, on_space=None)[source]#
Returns the name of the specified operator (basis or differential basis) for this FunctionSpace.
- Parameters:
operator_name (str) – name (type) of the operator.
qr_var (str) – the name of the Quadrature Object for which the operator is required.
on_space (
psyclone.domain.lfric.FunctionSpace) – the function space at which the operator is required.
- Returns:
name for the Fortran arry holding the named operator for the specified function space.
- Return type:
str
- property has_scalar_basis#
- Returns:
True if this function space has scalar basis functions.
- Return type:
bool
- property has_scalar_diff_basis#
- Returns:
True if this function space has scalar differential basis functions.
- Return type:
bool
- property has_vector_basis#
- Returns:
True if this function space has vector basis functions.
- Return type:
bool
- property has_vector_diff_basis#
- Returns:
True if this function space has vector differential basis functions.
- Return type:
bool
- property mangled_name#
Returns the mangled name of this function space such that it is unique within the scope of an invoke. If the mangled name has not been generated then we do that the first time we are called.
- Returns:
mangled name of this function space.
- Return type:
str
- property map_name#
- Returns:
a dofmap name for the supplied FunctionSpace.
- Return type:
str
- property ndf_name#
- Returns:
a ndf name for this FunctionSpace object.
- Return type:
str
- property orig_name#
Returns the name of this function space as declared in the kernel meta-data.
- Returns:
original name of this function space.
- Return type:
str
- property short_name#
Returns the short name of this function space (original name for a valid LFRic function space and condensed name for any_*_spaces).
- Returns:
short name of this function space.
- Return type:
str
- property undf_name#
- Returns:
a undf name for this FunctionSpace object.
- Return type:
str
- class psyclone.domain.lfric.KernCallAccArgList(kern)[source]#
Kernel call arguments that need to be declared by OpenACC directives. KernCallArgList only needs to be specialised where modified, or additional, arguments are required. Scalars are apparently not required but it is valid in OpenACC to include them and requires less specialisation to keep them in.
Inheritance

- cell_map(var_accesses=None)[source]#
Add cell-map to the list of required arrays.
- Parameters:
var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_position(var_accesses=None)[source]#
Adds a cell argument to the argument list and if supplied stores this access in var_accesses. Although normally just a scalar, the cell argument may actually require a lookup from a colour map array. Either way, this method adds the name of the variable to the argument list.
- Parameters:
var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- field(arg, var_accesses=None)[source]#
Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the field to be added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_compulsory_field(function_space, var_accesses=None)[source]#
Add compulsory arguments associated with this function space to the list. OpenACC requires the full function-space map to be specified. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the compulsory arguments are added.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_intergrid(function_space, var_accesses=None)[source]#
Add arrays that need to be uploaded for inter-grid kernels. These arrays contain the mapping between fine and coarse meshes.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space associated with the mesh.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- operator(arg, var_accesses=None)[source]#
Add the operator arguments if they have not already been added. OpenACC requires the derived type and the dereferenced data to be specified. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the operator.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- scalar(scalar_arg, var_accesses=None)[source]#
Override the default implementation as there’s no need to specify scalars for an OpenACC data region.
- Parameters:
scalar_arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance that stores information about variable accesses.
- stencil(arg, var_accesses=None)[source]#
Add general stencil information associated with the argument ‘arg’ to the argument list. OpenACC requires the full dofmap to be specified. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d(arg, var_accesses=None)[source]#
Add general 2D stencil information associated with the argument ‘arg’ to the argument list. OpenACC requires the full dofmap to be specified. If supplied it also stores this access in var_accesses.This method passes through to the stencil method.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d_unknown_extent(arg, var_accesses=None)[source]#
Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses. This method passes through to the stencil_unknown_extent method.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_unknown_extent(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (Optional[
psyclone.core.VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- class psyclone.domain.lfric.KernCallArgList(kern)[source]#
Creates the argument list required to call kernel “kern” from the PSy-layer and captures the positions of the following arguments in the argument list: nlayers, number of quadrature points and number of degrees of freedom. The ordering and type of arguments is captured by the base class.
- Parameters:
kern (
psyclone.domain.lfric.LFRicKern) – The kernel that is being called.
Inheritance

- class NdfInfo(position=None, function_space=None)[source]#
Holds information relating to the number-of-dofs kernel argument.
- Parameters:
position (
int) – the position of this argument in the argument list.function_space (
str) – the function space that this argument is for.
- append_structure_reference(module_name, user_type, member_list, name, tag=None, overwrite_datatype=None)[source]#
Creates a reference to a variable of a user-defined type. If required, the required import statements will all be generated.
- Parameters:
module_name (str) – the name of the module from which the user-defined type must be imported.
user_type (str) – the name of the user-defined type.
member_list (List[str]) – the members used hierarchically.
name (str) – the name of the variable to be used in the Reference.
tag (Optional[str]) – tag to use for the variable, defaults to the name
overwrite_datatype (Optional[
psyclone.psyir.symbols.DataType]) – the datatype for the reference, which will overwrite the value determined by analysing the corresponding user defined type. This is useful when e.g. the module that declares the structure cannot be accessed.
- Returns:
the symbol that is used in the reference
- Return type:
- basis(function_space, var_accesses=None)[source]#
Add basis function information for this function space to the argument list and optionally to the variable access information.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the basis function is required.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_map(var_accesses=None)[source]#
Add cell-map and related cell counts (for inter-grid kernels) to the argument list. If supplied it also stores these accesses to the var_access object.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_position(var_accesses=None)[source]#
Adds a cell argument to the argument list and if supplied stores this access in var_accesses.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- cell_ref_name(var_accesses=None)[source]#
Utility routine which determines whether to return the cell reference or the colourmap/tilemap lookup array references. If supplied with a “var_accesses” it also stores the Variables Access information.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.- Return type:
Tuple[str,Reference]- Returns:
the variable name and a reference to access the cell index.
TODO #2874: The name, argument, and first tuple component of this and similar methods should be refactored.
- cma_operator(arg, var_accesses=None)[source]#
Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the CMA operator argument.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- diff_basis(function_space, var_accesses=None)[source]#
Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the differential basis functions are required.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- field(arg, var_accesses=None)[source]#
Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the field to be added.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- field_bcs_kernel(function_space, var_accesses=None)[source]#
Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which boundary dofs are required.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- Raises:
GenerationError – if the bcs kernel does not contain a field as argument (but e.g. an operator).
- field_vector(argvect, var_accesses=None)[source]#
Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.
- Parameters:
argvect (
psyclone.lfric.LFRicKernelArgument) – the field vector to add.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_common(function_space, var_accesses=None)[source]#
Add function-space related arguments common to LMA operators and fields. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the related arguments common to LMA operators and fields are added.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_compulsory_field(function_space, var_accesses=None)[source]#
Add compulsory arguments associated with this function space to the list. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the compulsory arguments are added.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_intergrid(function_space, var_accesses=None)[source]#
Add function-space related arguments for an intergrid kernel. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which to add argumentsvar_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- get_user_type(module_name, user_type, name, tag=None)[source]#
Returns the symbol for a user-defined type. If required, the required import statements will all be generated.
- Parameters:
module_name (str) – the name of the module from which the user-defined type must be imported.
user_type (str) – the name of the user-defined type.
name (str) – the name of the variable to be used in the Reference.
tag (Optional[str]) – tag to use for the variable, defaults to the name
- Returns:
the symbol that is used in the reference
- Return type:
- mesh_height(var_accesses=None)[source]#
Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- mesh_properties(var_accesses=None)[source]#
Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- property ndf_positions#
- Returns:
the position(s) in the argument list and the function space(s) associated with the variable(s) that pass(es) the number of degrees of freedom for the function space. The generate method must be called first.
- Return type:
list of namedtuple (position=int, function_space=str).
- Raises:
InternalError – if the generate() method has not been called.
- property nlayers_positions#
- Returns:
the position(s) in the argument list of the variable(s) that passes the number of layers. The generate method must be called first.
- Return type:
list of int.
- Raises:
InternalError – if the generate() method has not been called.
- property nqp_positions#
- Returns:
the positions in the argument list of the variables that pass the number of quadrature points. The number and type of these will change depending on the type of quadrature. A list of dictionaries is returned with the quadrature types being the keys to the dictionaries and their position in the argument list being the values. At the moment only XYoZ is supported (which has horizontal and vertical quadrature points). The generate method must be called first.
- Return type:
[{str: int, …}]
- Raises:
InternalError – if the generate() method has not been called.
- operator(arg, var_accesses=None)[source]#
Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the operator.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- operator_bcs_kernel(function_space, var_accesses=None)[source]#
Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.lfric.FunctionSpace) – unused, only for consistency with base class.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- quad_rule(var_accesses=None)[source]#
Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.
- Parameters:
var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- scalar(scalar_arg, var_accesses=None)[source]#
Add the necessary argument for a scalar quantity as well as an appropriate Symbol to the SymbolTable.
- Parameters:
scalar_arg (
psyclone.lfric.LFRicKernelArgument) – the scalar kernel argument.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance that stores information about variable accesses.
- stencil(arg, var_accesses=None)[source]#
Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d(arg, var_accesses=None)[source]#
Add general 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d_max_extent(arg, var_accesses=None)[source]#
Add the maximum branch extent for a 2D stencil associated with the argument ‘arg’ to the argument list. If supplied it also stores this in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariableAccessMap instance to store the information about variable accesses.
- stencil_2d_unknown_extent(arg, var_accesses=None)[source]#
Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_unknown_direction(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown (i.e. it’s being supplied in a variable). If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_unknown_extent(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- class psyclone.domain.lfric.KernelInterface(kern)[source]#
Create the kernel arguments for the supplied kernel as specified by the associated kernel metadata and the kernel ordering rules encoded in the ArgOrdering base class as method callbacks.
A PSyIR symbol table is created containing appropriate LFRic PSyIR symbols to specify the arguments. If an argument is an array with one or more dimension sizes specified by another argument, then the associated array symbol is created so that it references the appropriate symbol.
Related arguments - e.g. a field has an associated dofmap - are not directly connected, they must be inferred from the function space names. It is not yet clear whether this would be useful or not.
TODO #928: This class should replace the current kernel stub generation code when all of its methods are implemented.
- Parameters:
kern (
psyclone.domain.lfric.LFRicKern) – the kernel for which to create arguments.
Inheritance

- banded_dofmap(function_space, var_accesses=None)[source]#
Not implemented.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this dofmap.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- basis(function_space, var_accesses=None)[source]#
Create an LFRic basis function argument and add it to the symbol table and argument list.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this basis function.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- basis_mapping = {'gh_quadrature_edge': 'BasisFunctionQrEdgeDataSymbol', 'gh_quadrature_face': 'BasisFunctionQrFaceDataSymbol', 'gh_quadrature_xyoz': 'BasisFunctionQrXyozDataSymbol'}#
Mapping from the LFRic metadata description of quadrature to the associated LFRic-specific basis function datasymbol.
- cell_map(var_accesses=None)[source]#
Not implemented.
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- cell_position(var_accesses=None)[source]#
Create an LFRic cell-position object and add it to the symbol table and argument list.
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- cma_operator(arg, var_accesses=None)[source]#
Not implemented.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the CMA operator argument.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- diff_basis(function_space, var_accesses=None)[source]#
Create an LFRic differential basis function argument and add it to the symbol table and argument list.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this differential basis function.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- diff_basis_mapping = {'gh_quadrature_edge': 'DiffBasisFunctionQrEdgeDataSymbol', 'gh_quadrature_face': 'DiffBasisFunctionQrFaceDataSymbol', 'gh_quadrature_xyoz': 'DiffBasisFunctionQrXyozDataSymbol'}#
Mapping from the LFRic metadata description of quadrature to the associated LFRic-specific differential basis function datasymbol.
- field(arg, var_accesses=None)[source]#
Create an LFRic field argument and add it to the symbol table and argument list. Also declare the associated “undf” symbol if it has not already been declared so that it can be used to dimension the field argument.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the field to add.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – if the datatype of the field is not supported.
- field_bcs_kernel(function_space, var_accesses=None)[source]#
Create the boundary-dofs mask argument required for the enforce_bc_code kernel. Adds it to the symbol table and the argument list.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this boundary condition.var_accesses (
psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
InternalError – if the kernel does not have a single field as argument.
InternalError – if the field argument is not on the ‘ANY_SPACE_1’ function space.
- field_mapping = {'integer': 'IntegerFieldDataSymbol', 'logical': 'LogicalFieldDataSymbol', 'real': 'RealFieldDataSymbol'}#
Mapping from a generic PSyIR datatype to the equivalent LFRic-specific field datasymbol.
- field_vector(argvect, var_accesses=None)[source]#
Create LFRic field vector arguments and add them to the symbol table and argument list. Also declare the associated “undf” symbol if it has not already been declared so that it can be used to dimension the field vector arguments.
- Parameters:
argvect (
psyclone.lfric.LFRicKernelArgument) – the field vector to add.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – if the datatype of the vector field is not supported.
- fs_common(function_space, var_accesses=None)[source]#
Create any arguments that are common to a particular function space. At this time the only common argument is the number of degrees of freedom. Create the associated LFRic symbol, and add it to the symbol table and argument list.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for any common arguments.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- fs_compulsory_field(function_space, var_accesses=None)[source]#
Create any arguments that are compulsory for a field on a particular function space. At this time the compulsory arguments are the unique number of degrees of freedom and the dofmap. Create the associated LFRic symbol, and add it to the symbol table and argument list. Also declare the number of degrees of freedom and add to the symbol table if one has not yet been added.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for any compulsory arguments.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- fs_intergrid(function_space, var_accesses=None)[source]#
Not implemented.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the CMA operator argument.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- generate(var_accesses=None)[source]#
Call the generate base class then add the argument list as it can’t be appended as we go along.
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- indirection_dofmap(function_space, operator=None, var_accesses=None)[source]#
Not implemented.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this dofmap.operator (
psyclone.lfric.LFRicKernelArgument) – the CMA operator.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- mesh_height(var_accesses=None)[source]#
Create an LFRic mesh height object and add it to the symbol table and argument list.
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- mesh_properties(var_accesses=None)[source]#
Properties associated with the mesh
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- operator(arg, var_accesses=None)[source]#
Create an LFRic operator argument and an ncells argument and add them to the symbol table and argument list. Also declare the associated ‘fs_from’, ‘fs_to’ symbols if they have not already been declared so that they can be used to dimension the operator symbol (as well as ncells).
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the operator to add.var_accesses (
psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – if the datatype of the field is not supported.
- operator_bcs_kernel(function_space, var_accesses=None)[source]#
Not implemented.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for this bcs kernelvar_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- quad_rule(var_accesses=None)[source]#
Create LFRic arguments associated with the required quadrature, if they do not already exist, and add them to the symbol table and argument list. The arguments depend on the type of quadrature requested.
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
InternalError – if an unsupported quadrature shape is found.
- ref_element_properties(var_accesses=None)[source]#
Properties associated with the reference element
- Parameters:
var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- scalar(scalar_arg, var_accesses=None)[source]#
Create an LFRic scalar argument and add it to the symbol table and argument list.
- Parameters:
scalar_arg (
psyclone.lfric.LFRicKernelArgument) – the scalar to add.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – if the datatype of the scalar is not supported.
- stencil(arg, var_accesses=None)[source]#
Not implemented.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- stencil_unknown_direction(arg, var_accesses=None)[source]#
Not implemented.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- stencil_unknown_extent(arg, var_accesses=None)[source]#
Not implemented.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (: py:class:psyclone.core.VariablesAccessMap) – an unused optional argument that stores information about variable accesses.
- Raises:
NotImplementedError – as this method is not implemented.
- vector_field_mapping = {'integer': 'IntegerVectorFieldDataSymbol', 'logical': 'LogicalVectorFieldDataSymbol', 'real': 'RealVectorFieldDataSymbol'}#
Mapping from a generic PSyIR datatype to the equivalent LFRic-specific vector field datasymbol.
- class psyclone.domain.lfric.KernStubArgList(kern)[source]#
Creates the argument list required to create and declare the required arguments for a kernel subroutine. The ordering and type of the arguments is captured by the base class.
- Parameters:
kern (
psyclone.domain.lfric.LFRicKern) – Kernel for which to create argument list.- Raises:
NotImplementedError – if the kernel is inter-grid.
NotImplementedError – if the kernel requires properties of the reference element.
Inheritance

- basis(function_space, var_accesses=None)[source]#
Add basis function information for this function space to the argument list and optionally to the variable access information. There can be more than one if this is an evaluator and/or multiple ‘gh_shape’s have been requested in the kernel metadata. If supplied it also stores these accesses in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which to provide the basis functionsvar_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- Raises:
InternalError – if the evaluator shape is not recognised.
- cell_position(var_accesses=None)[source]#
Adds a cell argument to the argument list and if supplied stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- cma_operator(arg, var_accesses=None)[source]#
Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the CMA operator argument.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- diff_basis(function_space, var_accesses=None)[source]#
Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the differential basis functions are required.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- Raises:
InternalError – if the evaluator shape is not recognised.
- field(arg, var_accesses=None)[source]#
Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the field to be added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- field_bcs_kernel(function_space, var_accesses=None)[source]#
Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which boundary dofs are required.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- field_vector(argvect, var_accesses=None)[source]#
Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.
- Parameters:
argvect (
psyclone.lfric.LFRicKernelArgument) – the field vector to add.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- fs_compulsory_field(function_space, var_accesses=None)[source]#
Provide compulsory arguments if there is a field on this function space. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the compulsory arguments are added.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- indirection_dofmap(function_space, operator=None, var_accesses=None)[source]#
Add indirection dofmap required when applying a CMA operator. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which the indirect dofmap is required.operator (
psyclone.lfric.LFRicKernelArgument) – the CMA operator.var_accesses (
Optional[VariablesAccessMap]) – optional VariablesAccessMap instance to store the information about variable accesses.
- Raises:
InternalError – if no kernel argument is supplied.
InternalError – if the supplied kernel argument is not a CMA operator.
- mesh_height(var_accesses=None)[source]#
Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- mesh_properties(var_accesses=None)[source]#
Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- operator(arg, var_accesses=None)[source]#
Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the operator.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- operator_bcs_kernel(function_space, var_accesses=None)[source]#
Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.
- Parameters:
function_space (
psyclone.lfric.FunctionSpace) – the ‘to’ function space of the operator.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- quad_rule(var_accesses=None)[source]#
Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.
- Parameters:
var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil(arg, var_accesses=None)[source]#
Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d(arg, var_accesses=None)[source]#
Add general 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the meta-data description of the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_2d_max_extent(arg, var_accesses=None)[source]#
Add the maximum branch extent for a 2D stencil associated with the argument ‘arg’ to the argument list. If supplied it also stores this in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.AccessSequence) – optional AccessSequence instance to store the information about variable accesses.
- stencil_2d_unknown_extent(arg, var_accesses=None)[source]#
Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_unknown_direction(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- stencil_unknown_extent(arg, var_accesses=None)[source]#
Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.var_accesses (
psyclone.core.VariablesAccessMap) – optional VariablesAccessMap instance to store the information about variable accesses.
- class psyclone.domain.lfric.LFRicArgDescriptor(arg_type, operates_on, metadata_index)[source]#
This class captures the information specified in one of LFRic API argument descriptors (scalars, fields and operators).
- Parameters:
arg_type (
psyclone.expression.FunctionVarorpsyclone.expression.BinaryOperator) – LFRic API valid argument type (scalar, field or operator).operates_on (str) – value of operates_on from the parsed kernel metadata (used for validation).
metadata_index (int) – position of this argument in the list of arguments specified in the metadata.
- Raises:
ParseError – if a ‘meta_arg’ entry is not of ‘arg_type’ type.
ParseError – if the first argument of a ‘meta_arg’ entry is not one of LFRic API valid argument types.
ParseError – if the second argument of a ‘meta_arg’ entry is not one of LFRic API valid data types.
ParseError – if a ‘meta_arg’ entry has fewer than 3 args.
ParseError – if the third ‘meta_arg’ entry is not a valid access descriptor.
InternalError – if the operates_on from the parsed kernel metadata is not ‘cell_column’ or ‘dof’.
InternalError – if all the metadata checks fail to catch an invalid argument type.
Inheritance

- property array_ndims#
Returns the array rank of the argument. This will be 1 if
*nhas not been specified for all argument types except scalars (their array rank is set to 0).- Returns:
array rank of the argument.
- Return type:
int
- property data_type#
- Returns:
intrinsic Fortran (primitive) type of the argument data.
- Return type:
str
- property function_space#
Returns the function space name related to this kernel argument depending on the argument type: a single function space for a field, function_space_from for an operator and nothing for a scalar.
- Returns:
function space relating to this kernel argument or None (for a scalar or ScalarArray).
- Return type:
str or NoneType
- Raises:
InternalError – if an invalid argument type is passed in.
- property function_space_from#
Returns the “from” function space for an operator. This is the second function space specified in the metadata.
- Returns:
“from” function space for an operator.
- Return type:
str
- Raises:
InternalError – if this is not an operator.
- property function_space_to#
Returns the “to” function space for an operator. This is the first function space specified in the metadata.
- Returns:
“to” function space for an operator.
- Return type:
str
- Raises:
InternalError – if this is not an operator.
- property function_spaces#
Returns the function space names related to this kernel argument as a list depending on the argument type: one function space for a field, both function spaces (“to”- and then “from”-) for an operator and an empty list for a scalar.
- Returns:
function space names related to this kernel argument.
- Return type:
list of str
- Raises:
InternalError – if an invalid argument type is passed in.
- property vector_size#
Returns the vector size of the argument. This will be 1 if
*nhas not been specified for all argument types except scalars (their vector size is set to 0).- Returns:
vector size of the argument.
- Return type:
int
- class psyclone.domain.lfric.LFRicCellIterators(kern_or_invoke)[source]#
Handles all entities required by kernels that operate on cell-columns.
- Parameters:
kern_or_invoke (
psyclone.domain.lfric.LFRicKern|psyclone.lfric.LFRicInvoke) – the Kernel or Invoke for which to manage cell iterators.- Raises:
GenerationError – if an Invoke has no field or operator arguments.
Inheritance

- class psyclone.domain.lfric.LFRicCollection(node)[source]#
Base class for managing the declaration and initialisation of a group of related entities within an Invoke or Kernel stub
- Parameters:
node (
psyclone.domain.lfric.LFRicInvokeorpsyclone.domain.lfric.LFRicKern) – the Kernel or Invoke for which to manage variable declarations and initialisation.- Raises:
InternalError – if the supplied node is not an LFRicInvoke or an LFRicKern.
Inheritance

- abstractmethod initialise(cursor)[source]#
Add code to initialise the entities being managed by this class. We do nothing by default - it is up to the sub-class to override this method if initialisation is required.
- Parameters:
cursor (
int) – position where to add the next initialisation statements.- Return type:
int- Returns:
Updated cursor value.
- invoke_declarations()[source]#
Add necessary Invoke declarations for this Collection.
By default we just sanity check that the class is appropriately initialised - it is up to the sub-class to add required declarations.
- Raises:
InternalError – if the class has been instantiated for a kernel and not an invoke.
- stub_declarations()[source]#
Add necessary Kernel Stub declarations for this Collection.
By default we just sanity check that the class is appropriately initialised - it is up to the sub-class to add required declarations.
- Raises:
InternalError – if the class has been instantiated for an invoke and not a kernel.
- property symtab#
- Returns:
associated symbol table.
- Return type:
- class psyclone.domain.lfric.LFRicConstants[source]#
This class stores all LFRic constants. Note that some constants depend on values in the config file, so this class can only be used after the config file has been read. It stores all values in class variables (to avoid re-evaluating them).
Inheritance

-
UTILITIES_MOD_MAP:
dict[str,dict[str,str]]# Dictionary allowing us to look-up the name of the Fortran modules that store various utilities in LFRic.
- precision_for_type(data_type)[source]#
This function returns the precision required for the various LFRic types.
- Parameters:
data_type (str) – the name of the data type.
- Returns:
the precision as defined in domain.lfric.lfric_types (one of R_SOLVER, R_TRAN, R_DEF).
- Return type:
- Raises:
InternalError – if an unknown data_type is specified.
- static specific_function_space(name)[source]#
Maps from a valid kernel metadata function-space name to one that exists within the LFRic infrastructure. This is necessary because meta-data can contain ‘generic’ names such as ‘any_w2’ but, when generating code, we need the name of a specific function space that is recognised by the LFRic infrastructure.
- Parameters:
name (str) – the name of the function space in metadata.
- Returns:
the name of a specific function space.
- Return type:
str
- Raises:
ValueError – if the supplied name is not a valid LFRic function-space name.
InternalError – if an unrecognised wildcard function-space name is supplied.
-
UTILITIES_MOD_MAP:
- class psyclone.domain.lfric.LFRicDofmaps(node)[source]#
Holds all information on the dofmaps (including column-banded and indirection) required by an invoke.
- Parameters:
node (
psyclone.domain.lfric.LFRicKernorpsyclone.domain.lfric.LFRicInvoke) – Kernel or Invoke for which to manage dofmaps.
Inheritance

- initialise(cursor)[source]#
Add code to initialise the entities being managed by this class.
- Parameters:
cursor (
int) – position where to add the next initialisation statements.- Return type:
int- Returns:
Updated cursor value.
- class psyclone.domain.lfric.LFRicDriverCreator(region_name=None)[source]#
This class provides the functionality to create a driver that reads in extracted data produced by using the PSyData kernel-extraction functionality.
- Parameters:
region_name (
Optional[tuple[str,str]]) – the suggested region_name.
Inheritance

- handle_precision_symbols(symbol_table)[source]#
This function adds an import of the various precision symbols used by LFRic from the constants_mod module.
- Parameters:
symbol_table (
SymbolTable) – the symbol table to which the precision symbols must be added.- Return type:
None
- verify_and_cleanup_psyir(extract_region)[source]#
This implementation removes MPI related calls in LFRic (set_dirty and set_clean. Note that any LFRic-specific StructureReferences should have been replaced as part of the lowering process.
- Parameters:
extract_region (
Node) – the node with the extracted region.- Raises:
ValueError – if structure references are found (raised in the base class)
- Return type:
None
- class psyclone.domain.lfric.LFRicFields(node)[source]#
Manages the declarations for all field arguments required by an Invoke or Kernel stub.
Inheritance

- invoke_declarations()[source]#
Add field-related declarations to the PSy-layer routine. Note: PSy layer in LFRic does not modify the field objects. Hence, their Fortran intents are always in (the data updated in the kernels is only pointed to from the field object and is thus not a part of the object).
- Raises:
InternalError – for unsupported intrinsic types of field argument data.
- stub_declarations()[source]#
Add field-related declarations to a Kernel stub.
- Raises:
InternalError – for an unsupported data type of field argument data.
- class psyclone.domain.lfric.LFRicHaloDepths(node)[source]#
Manages the declarations for all halo-depth arguments (as needed by kernels that have operates_on == HALO_CELL_COLUMNS or OWNED_AND_HALO_CELL_COLUMNS) required by an Invoke.
- Parameters:
node (py:class:psyclone.domain.lfric.lfric_invoke.LFRicInvoke) – the LFRic Invoke for which to manage halo-depth arguments.
- Raises:
NotImplementedError – if the halo-depth passed to a Kernel from the Algorithm layer is not a literal or a scalar reference.
Inheritance

- class psyclone.domain.lfric.LFRicInvoke(alg_invocation, idx, invokes)[source]#
The LFRic-specific Invoke class. This passes the LFRic-specific InvokeSchedule class to the base class so it creates the one we require.
- Parameters:
alg_invocation (
psyclone.parse.algorithm.InvokeCall) – object containing the invoke call information.idx (int) – the position of the invoke in the list of invokes contained in the Algorithm.
invokes (
psyclone.domain.lfric.LFRicInvokes) – the Invokes object containing this LFRicInvoke object.
- Raises:
GenerationError – if integer reductions are required in the PSy-layer.
Inheritance

- arg_for_funcspace(fspace)[source]#
Returns an argument object which is on the requested function space. Searches through all Kernel calls in this Invoke. Currently the first argument object that is found is used. Throws an exception if no argument exists.
- Parameters:
fspace (
psyclone.domain.lfric.FunctionSpace) – function space of the argument.- Returns:
an argument object which is on the requested function space.
- Return type:
- Raises:
GenerationError – if the argument object does not exist.
- field_on_space(func_space)[source]#
If a field exists on this space for any kernel in this Invoke then return that field. Otherwise return ‘None’.
- Parameters:
func_space (
psyclone.domain.lfric.FunctionSpace) – the function space for which to find an argument.
- property operates_on_dofs_only#
- Returns:
whether or not this Invoke consists only of kernels that operate on DoFs.
- Return type:
bool
- setup_psy_layer_symbols()[source]#
Declare, initialise and deallocate all symbols required by the PSy-layer Invoke subroutine.
- class psyclone.domain.lfric.LFRicInvokes(alg_calls, psy)[source]#
The LFRic-specific invokes class. This passes the LFRic-specific LFRicInvoke class to the base class so it creates the one we require.
- Parameters:
alg_calls (List[
psyclone.parse.algorithm.InvokeCall]) – A list of objects containing the parsed invoke information.psy (
psyclone.domain.lfric.LFRicPSy) – The PSy object containing this LFRicInvokes object.
Inheritance

- class psyclone.domain.lfric.LFRicInvokeSchedule(symbol, alg_calls=None, parent=None, **kwargs)[source]#
The LFRic-specific InvokeSchedule sub-class. This passes the LFRic- specific factories for creating kernel and infrastructure calls to the base class so it creates the ones we require.
- Parameters:
symbol (
psyclone.psyir.symbols.RoutineSymbol) – symbol representing the Invoke.alg_calls (Optional[list of
psyclone.parse.algorithm.KernelCall]) – optional list of KernelCalls parsed from the algorithm layer.parent (
psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR.
Inheritance

- class psyclone.domain.lfric.LFRicKern[source]#
Stores information about LFRic Kernels as specified by the Kernel metadata and associated algorithm call. Uses this information to generate appropriate PSy layer code for the Kernel instance or to generate a Kernel stub.
Inheritance

- class QRRule(alg_name, psy_name, kernel_args)[source]#
Used to store information on a quadrature rule required by a kernel.
- Parameters:
alg_name (
str) – The actual argument text specifying the QR object in the Alg. layer.psy_name (
str) – The PSy-layer variable name for the QR object.kernel_args (
List[str]) – Kernel arguments associated with this QR rule.
- property all_updates_are_writes: bool#
- Returns:
True if all arguments updated by this kernel have ‘GH_WRITE’ access, False otherwise.
- property argument_kinds#
- Returns:
kinds (precisions) for all arguments in a kernel.
- Return type:
set of str
- property base_name#
- Returns:
a base name for this kernel.
- Return type:
str
- property cma_operation#
- Returns:
the type of CMA operation performed by this kernel (one of ‘assembly’, ‘apply’ or ‘matrix-matrix’) or None if the kernel does not involve CMA operators.
- Return type:
str
- property colourmap: DataSymbol#
- Returns:
the symbol representing the colourmap for this kernel call.
- Raises:
InternalError – if this kernel is not coloured or the dictionary of inter-grid kernels and colourmaps has not been constructed.
- property eval_shapes#
- Returns:
the value(s) of GH_SHAPE for this kernel or an empty list if none are specified.
- Return type:
list
- property eval_targets#
- Returns:
the function spaces upon which basis/diff-basis functions are to be evaluated for this kernel.
- Return type:
dict of (
psyclone.domain.lfric.FunctionSpace, :py:class`psyclone.lfric.LFRicKernelArgument`), indexed by the names of the target function spaces.
- property fs_descriptors#
- Returns:
a list of function space descriptor objects of type FSDescriptors which contain information about the function spaces.
- Return type:
List[
psyclone.FSDescriptors].
- property gen_stub: Container#
Create the PSyIR for a kernel stub.
- Returns:
the kernel stub root Container.
- Raises:
GenerationError – if the supplied kernel stub does not operate on a supported subset of the domain (currently only those that end with “cell_column”).
- get_callees()[source]#
Returns the PSyIR Schedule(s) representing the kernel code. The base class creates the PSyIR schedule(s) on first invocation which is then checked for consistency with the kernel metadata here. The Schedule is just generated on first invocation, this allows us to retain transformations that may subsequently be applied to the Schedule(s).
Once issue #935 is implemented, this routine will return the PSyIR Schedule using LFRic-specific PSyIR where possible.
- Return type:
List[KernelSchedule]- Returns:
the Schedule(s) representing the kernel implementation.
- Raises:
InternalError – if no subroutines matching this kernel can be found in the parse tree of the associated source code.
- get_interface_symbol()[source]#
- Return type:
Optional[GenericInterfaceSymbol]- Returns:
the interface symbol for this kernel if it is polymorphic, None otherwise.
- property halo_depth#
If this is a kernel that has metadata specifying that it operates on halo cells then this property gives the depth of halo that is written.
- Returns:
the PSyIR of the depth of halo that is modified.
- Return type:
psyclone.psyir.nodes.Literal|psyclone.psyir.nodes.Reference
- property is_intergrid#
- Returns:
True if it is an inter-grid kernel, False otherwise
- Return type:
bool
- property last_cell_all_colours_symbol#
Getter for the symbol of the array holding the index of the last cell of each colour.
- Returns:
name of the array.
- Return type:
str
- Raises:
InternalError – if this kernel is not coloured.
- load(call, parent=None)[source]#
Sets up kernel information with the call object which is created by the parser. This object includes information about the invoke call and the associated kernel.
- Parameters:
call (
psyclone.parse.algorithm.KernelCall) – The KernelCall object from which to extract information about this kernelparent (
psyclone.domain.lfric.LFRicLoop) – The parent node of the kernel call in the AST we are constructing. This will be a loop.
- load_meta(ktype)[source]#
Sets up kernel information with the kernel type object which is created by the parser. The object includes the metadata describing the kernel code.
- Parameters:
ktype (
psyclone.domain.lfric.LFRicKernMetadata) – the kernel metadata object produced by the parser- Raises:
InternalError – for an invalid data type of a scalar argument.
GenerationError – if an invalid argument type is found in the kernel.
- property mesh#
- Returns:
the mesh properties required by this kernel.
- Return type:
:py:class`psyclone.lfric.MeshPropertiesMetaData`
- property ncolours_var#
Getter for the name of the variable holding the number of colours associated with this kernel call.
- Returns:
name of the variable holding the number of colours
- Return type:
Optional[str]
- Raises:
InternalError – if this kernel is not coloured.
- property ntilecolours_var: str | None#
Getter for the name of the variable holding the number of colours (over tiled cells) associated with this kernel call.
- Returns:
name of the variable holding the number of colours
- Raises:
InternalError – if this kernel is not coloured or the colour-map information has not been initialised.
- property qr_required#
- Returns:
True if this kernel requires quadrature, else returns False.
- Return type:
bool
- property qr_rules#
- Returns:
details of each of the quadrature rules required by this kernel.
- Return type:
OrderedDict containing
psyclone.domain.lfric.LFRicKern.QRRuleindexed by quadrature shape.
- reference_accesses()[source]#
- Return type:
- Returns:
a map of all the symbol accessed inside this node, the keys are Signatures (unique identifiers to a symbol and its structure acccessors) and the values are AccessSequence (a sequence of AccessTypes).
- property reference_element#
- Returns:
the reference-element properties required by this kernel.
- Return type:
psyclone.lfric.RefElementMetaData
- property tilecolourmap: DataSymbol#
Getter for the name of the tilecolourmap associated with this kernel call.
- Returns:
the symbol representing the tilecolourmap.
- Raises:
InternalError – if this kernel is not coloured or the dictionary of inter-grid kernels and colourmaps has not been constructed.
- property undf_name#
Dynamically looks up the name of the ‘undf’ variable for the space that this kernel updates.
- Returns:
the name of the undf variable.
- Return type:
str
- validate_global_constraints()[source]#
Perform validation checks for any global constraints (that require the tree to be complete).
- Raises:
GenerationError – if this kernel does not have a supported operates-on.
GenerationError – if the loop goes beyond the level 1 halo and an operator is accessed.
GenerationError – if a kernel in the loop has an inc access and the loop is not coloured but is within an OpenMP parallel region.
- validate_kernel_code_args(table)[source]#
Check that the arguments in the kernel code match the expected arguments as defined by the kernel metadata and the LFRic API.
- Parameters:
table (
psyclone.psyir.symbols.SymbolTable) – the symbol table to validate against the metadata.- Raises:
GenerationError – if the number of arguments indicated by the kernel metadata doesn’t match the actual number of arguments in the symbol table.
- class psyclone.domain.lfric.LFRicKernCallFactory[source]#
Create the necessary framework for an LFRic kernel call. This consists of a Loop over cells containing a call to the user-supplied kernel routine.
Inheritance

- static create(call, parent=None)[source]#
Create the objects needed for a call to the kernel described in the call object.
- Parameters:
call (
psyclone.parse.algorithm.KernelCall) – information on the kernel call as obtained from the Algorithm layer.parent (
psyclone.psyir.nodes.Schedule) – the parent of this kernel call in the PSyIR.
- class psyclone.domain.lfric.LFRicKernMetadata(ast, name=None)[source]#
Captures the Kernel subroutine code and metadata describing the subroutine for the LFRic API.
- Parameters:
ast (
fparser.block_statements.BeginSource) – fparser1 AST for the kernel.name (str) – the name of this kernel.
- Raises:
ParseError – if the metadata does not conform to the rules for the LFRic API.
Inheritance

- property cma_operation#
Returns the type of CMA operation identified from the kernel metadata (one of ‘assembly’, ‘apply’ or ‘matrix-matrix’) or None if the kernel does not involve CMA operators
- property eval_shapes#
Returns the shape(s) of evaluator required by this kernel or an empty string if none.
- Returns:
the shape(s) of the evaluator (one of VALID_EVALUATOR_SHAPES) or an empty list if the kernel does not require one.
- Return type:
list
- property eval_targets#
Returns the list of function spaces upon which any evaluator must be provided. This list is obtained from the GH_EVALUATOR_TARGETS metadata entry (if present). If this is not specified in the metadata then we default to providing evaluators on all of the function spaces associated with the arguments which this kernel updates.
- Returns:
list of the names of the function spaces (as they appear in kernel metadata) upon which any evaluator must be provided.
- Return type:
list of str
- property func_descriptors#
Returns metadata about the function spaces within a Kernel. This metadata is provided within Kernel code via the meta_funcs variable. Information is returned as a list of LFRicFuncDescriptor objects, one for each function space.
- property is_intergrid#
Returns whether or not this is an inter-grid kernel.
- Returns:
True if kernel is an inter-grid kernel, False otherwise
- Return type:
bool
- class psyclone.domain.lfric.LFRicLoop(loop_type='', **kwargs)[source]#
The LFRic-specific PSyLoop class. This passes the LFRic-specific loop information to the base class so it creates the one we require. Creates LFRic-specific loop bounds when the code is being generated.
- Parameters:
loop_type (str) – the type (iteration space) of this loop.
kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.
- Raises:
InternalError – if an unrecognised loop_type is specified.
InternalError – if a parent that is descendant from an InvokeSchedule is not provided.
Inheritance

- create_halo_exchanges()[source]#
Add halo exchanges before this loop as required by fields within this loop. To keep the logic simple we assume that any field that accesses the halo will require a halo exchange and then remove the halo exchange if this is not the case (when previous writers perform sufficient redundant computation). It is implemented this way as the halo exchange class determines whether it is required or not so a halo exchange needs to exist in order to find out. The appropriate logic is coded in the _add_halo_exchange helper method. In some cases a new halo exchange will replace an existing one. In this situation that routine also removes the old one.
- gen_mark_halos_clean_dirty()[source]#
Generates the necessary code to mark halo regions for all modified fields as clean or dirty following execution of this loop.
- independent_iterations(test_all_variables=False, signatures_to_ignore=None, dep_tools=None)[source]#
This function is an LFRic-specific override of the default method in the Loop class. It allows domain-specific rules to be applied when determining whether or not loop iterations are independent.
- Parameters:
test_all_variables (bool) – if True, it will test if all variable accesses are independent, otherwise it will stop after the first variable access is found that isn’t.
signatures_to_ignore (Optional[ List[
psyclone.core.Signature]]) – list of signatures for which to skip the access checks.dep_tools (Optional[
psyclone.psyir.tools.DependencyTools]) – an optional instance of DependencyTools so that the caller can access any diagnostic messages detailing why the loop iterations are not independent.
- Returns:
True if the loop iterations are independent, False otherwise.
- Return type:
bool
- load(kern)[source]#
Load the state of this Loop using the supplied Kernel object. This method is provided so that we can individually construct Loop objects for a given kernel call.
- Parameters:
kern (
psyclone.domain.lfric.LFRicKern) – Kernel object to use to populate state of Loop- Raises:
GenerationError – if the field updated by the kernel has an unexpected function space or if the kernel’s ‘operates-on’ is not consistent with the loop type.
- lower_bound_psyir()[source]#
- Return type:
- Returns:
the PSyIR for this loop lower bound.
- Raises:
GenerationError – if self._lower_bound_name is not “start” for sequential code.
GenerationError – if self._lower_bound_name is unrecognised.
- lower_to_language_level()[source]#
In-place replacement of DSL or high-level concepts into generic PSyIR constructs. This function replaces an LFRicLoop with a PSyLoop and inserts the loop boundaries into the new PSyLoop, or removes the loop node in case of a domain kernel. Once TODO #1731 is done (which should fix the loop boundaries, which atm rely on index of the loop in the schedule, i.e. can change when transformations are applied), this function can likely be removed.
- Returns:
the lowered version of this node.
- Return type:
psyclone.psyir.node.Node
- node_str(colour=True)[source]#
Creates a text summary of this loop node. We override this method from the Loop class because, in LFRic, the function space is now an object and we need to call orig_name on it. We also include the upper loop bound as this can now be modified.
- Parameters:
colour (bool) – whether or not to include control codes for colour.
- Returns:
text summary of this node, optionally with control codes for colour highlighting.
- Return type:
str
- set_upper_bound(name, halo_depth=None)[source]#
Set the upper bound of this loop.
- Parameters:
name (str) – Loop upper-bound name. Must be a supported name.
halo_depth (Optional[
psyclone.psyir.nodes.DataNode| int]) – An optional argument indicating the depth of halo that this loop accesses.
- Raises:
GenerationError – if supplied with an invalid upper-bound name.
GenerationError – if supplied with a halo depth < 1.
TypeError – if the supplied halo_depth value is neither an int or DataNode.
- update_halo_exchanges()[source]#
add and/or remove halo exchanges due to changes in the loops bounds
- property upper_bound_halo_depth#
Returns the index of the upper loop bound. This is None if the upper bound name is not in HALO_ACCESS_LOOP_BOUNDS.
- Returns:
the depth of the halo for a loops upper bound. If it is None then a depth has not been provided. The depth value is only valid when the upper-bound name is associated with a halo e.g. ‘cell_halo’.
- Return type:
int
- property upper_bound_name#
Returns the name of the upper loop bound
- class psyclone.domain.lfric.LFRicLoopBounds(node)[source]#
Handles all variables required for specifying loop limits within an LFRic PSy-layer routine.
Inheritance

- class psyclone.domain.lfric.LFRicPSy(invoke_info)[source]#
The LFRic-specific PSy class. This creates an LFRic-specific Invokes object (which controls all the required invocation calls). It also overrides the PSy gen method so that we generate LFRic-specific PSy module code.
- Parameters:
invoke_info (
psyclone.parse.algorithm.FileInfo) – object containing the required invocation information for code optimisation and generation.
Inheritance

- property name#
- Returns:
a name for the PSy layer. This is used as the PSy module name. We override the default value as the Met Office prefer “_psy” to be appended, rather than prepended.
- Return type:
str
- property orig_name#
- Returns:
the unmodified PSy-layer name.
- Return type:
str
- class psyclone.domain.lfric.LFRicRunTimeChecks(node)[source]#
Handle declarations and code generation for run-time checks. This is not used in the stub generator.
Inheritance

- initialise(cursor)[source]#
Add runtime checks to make sure that the arguments being passed from the algorithm layer are consistent with the metadata specified in the associated kernels. Currently checks are limited to ensuring that field function spaces are consistent with the associated kernel function-space metadata.
- Parameters:
cursor (
int) – position where to add the next initialisation statements.- Return type:
int- Returns:
Updated cursor value.
- class psyclone.domain.lfric.LFRicScalarArgs(node)[source]#
Handles the declarations of scalar kernel arguments appearing in either an Invoke or a Kernel stub.
- Parameters:
node (
psyclone.domain.lfric.LFRicKernorpsyclone.domain.lfric.LFRicInvoke) – the Invoke or Kernel stub for which to manage the scalar arguments.
Inheritance

- invoke_declarations()[source]#
Create argument lists and declarations for all scalar arguments in an Invoke.
- Raises:
InternalError – for unsupported argument intrinsic types.
GenerationError – if the same scalar argument has different data types in different Kernel calls within the same Invoke.
- stub_declarations()[source]#
Create and add declarations for all scalar arguments in a Kernel stub.
- Raises:
InternalError – for an unsupported argument data type.
- class psyclone.domain.lfric.LFRicStencils(node)[source]#
Stencil information and code generation associated with a PSy-layer routine or Kernel stub.
- Parameters:
node (
psyclone.lfric.LFRicInvokeorpsyclone.domain.lfric.LFRicKern) – the Invoke or Kernel stub for which to provide stencil info.- Raises:
GenerationError – if a literal has been supplied for a stencil direction.
Inheritance

- static direction_name(symtab, arg)[source]#
Creates a Fortran variable name to hold the direction of the stencil associated with the supplied kernel argument.
- Parameters:
symtab (
psyclone.psyir.symbols.SymbolTable) – symbol table that will contain (or already contains) the symbol with this name.arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.
- Returns:
a Fortran variable name for the stencil direction.
- Return type:
str
- static dofmap_size_symbol(symtab, arg)[source]#
Create a valid symbol for the size (in cells) of a stencil dofmap in the PSy layer.
- Parameters:
symtab (
psyclone.psyir.symbols.SymbolTable) – symbol table that will contain (or already contains) the symbol with this name.arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.
- Returns:
a symbol for the stencil size.
- Return type:
- static dofmap_symbol(symtab, arg)[source]#
Creates and registers a symbol for the stencil dofmap associated with the supplied kernel argument.
- Parameters:
symtab (
psyclone.psyir.symbols.SymbolTable) – symbol table that will contain (or already contains) the symbol with this name.arg (
psyclone.lfric.LFRicKernelArgument) – kernel argument with which the stencil is associated.
- Returns:
a dofmap symbol for a stencil in the PSy layer.
- Return type:
- extent_value(arg)[source]#
Returns the content of the stencil extent which may be a literal value (a number) or a variable name. This function simplifies this problem by returning a string in either case.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – the argument with which the stencil is associated.- Return type:
- Returns:
the content of the stencil extent.
- initialise(cursor)[source]#
Adds in the code to initialise stencil dofmaps to the PSy layer.
- Parameters:
cursor (
int) – position where to add the next initialisation statements.- Return type:
int- Returns:
Updated cursor value.
- Raises:
GenerationError – if an unsupported stencil type is encountered.
- invoke_declarations()[source]#
Declares all stencil maps, extent and direction arguments passed into the PSy layer.
- map_name(arg)[source]#
Creates and registers a name for the stencil map associated with the supplied kernel argument.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – kernel argument with which the stencil is associated.- Returns:
a valid unique map name for a stencil in the PSy layer.
- Return type:
str
- static max_branch_length(symtab, arg)[source]#
Create a valid unique name for the maximum length of a stencil branch (in cells) of a 2D stencil dofmap in the PSy layer. This is required in the kernels for defining the maximum possible length of one of the dofmap array dimensions.
- Parameters:
symtab (
psyclone.psyir.symbols.SymbolTable) – symbol table that will contain (or already contains) the symbol with this name.arg (
psyclone.lfric.LFRicKernelArgument) – the kernel argument with which the stencil is associated.
- Return type:
- Returns:
the symbol representing the max stencil branch length.
- static stencil_unique_str(arg, context)[source]#
Creates a unique identifier for a stencil. As a stencil differs due to the function space it operates on, type of stencil and extent of stencil, we concatenate these things together to create a unique string.
- Parameters:
arg (
psyclone.lfric.LFRicKernelArgument) – kernel argument with which stencil is associated.context (str) – a context for this stencil (e.g. “size” or “direction”).
- Returns:
unique string identifying the stencil for this argument.
- Return type:
str
- Raises:
GenerationError – if an explicit stencil extent is found in the metadata for the kernel argument.
- property unique_alg_vars#
- Returns:
list of the names of the extent and direction arguments supplied to the PSy routine from the Algorithm layer.
- Return type:
list of str
- class psyclone.domain.lfric.LFRicSymbolTable(node=None, default_visibility=Visibility.PUBLIC)[source]#
Sub-classes SymbolTable to provide an LFRic-specific implementation.
- Parameters:
node (
psyclone.psyir.nodes.Schedule,psyclone.psyir.nodes.Containeror NoneType) – reference to the Schedule or Container to which this symbol table belongs.default_visibility – optional default visibility value for this symbol table, if not provided it defaults to PUBLIC visibility.
Inheritance

- add_lfric_precision_symbol(name)[source]#
If the named LFRic precision symbol is not already in the table then add it. Also ensure that the Container symbol from which it is imported is in the table.
- Parameters:
name (str) – name of the LFRic precision symbol to add to table.
- Returns:
the specified LFRic precision symbol.
- Return type:
- Raises:
ValueError – if the supplied name is not a recognised LFRic precision variable.
ValueError – if a symbol with the same name is already in the table but is not imported from the correct container.
- find_or_create_array(array_name, num_dimensions, intrinsic_type, tag=None)[source]#
This function returns a symbol for an ArrayReference. If the symbol does not exist, it is created. If a new array symbol is created, it gets the DEFERRED attribute, which in Fortran means it will be declared as an allocatable array.
- Parameters:
array_name (str) – the name and tag of the array.
num_dimensions (int) – the number of dimensions of this array.
intrinsic_type (
psyclone.psyir.symbols.datatypes.ScalarType.Intrinsic) – the intrinsic type of the array.tag (Optional[str]) – optional tag to be used in searching and defining.
- Returns:
the requested symbol
- Return type:
- Raises:
TypeError – if the symbol exists, but is not a DataSymbol, or not an Array, or has different number of dimensions.
- find_or_create_integer_symbol(name, tag=None)[source]#
This function returns a symbol for an integer reference. If a tag is specified, it will be used to search for an existing symbol, otherwise the name will be used. If the symbol should not already exist in the symbol table, it will be returned, otherwise a new symbol will be created.
- Parameters:
name (str) – name of the integer variable to declare.
tag (Optional[str]) – optional tag of the integer variable to declare.
- Returns:
the symbol for the variable.
- Return type:
- Raises:
TypeError – TypeError if the symbol exists but is not a DataSymbol.
TypeError – TypeError if the symbol exists and is a DataSymbol, but not an Integer.