38 '''This module implements a class that creates the argument list
39 for a kernel subroutine.
49 '''Creates the argument list required to create and declare the
50 required arguments for a kernel subroutine. The ordering and type
51 of the arguments is captured by the base class.
53 :param kern: Kernel for which to create argument list.
54 :type kern: :py:class:`psyclone.domain.lfric.LFRicKern`
56 :raises NotImplementedError: if the kernel is inter-grid.
57 :raises NotImplementedError: if the kernel requires properties of the \
60 def __init__(self, kern):
61 ArgOrdering.__init__(self, kern)
68 '''Adds a cell argument to the argument list and if supplied stores
69 this access in var_accesses.
71 :param var_accesses: optional VariablesAccessInfo instance to store \
72 the information about variable accesses.
74 :py:class:`psyclone.core.VariablesAccessInfo`
77 self.
appendappend(
"cell", var_accesses)
80 '''Add mesh height (nlayers) to the argument list and if supplied
81 stores this access in var_accesses.
83 :param var_accesses: optional VariablesAccessInfo instance to store \
84 the information about variable accesses.
86 :py:class:`psyclone.core.VariablesAccessInfo`
89 self.
appendappend(
"nlayers", var_accesses)
91 def _mesh_ncell2d(self, var_accesses=None):
92 '''Add the number of columns in the mesh to the argument list and if
93 supplied stores this access in var_accesses.
95 :param var_accesses: optional VariablesAccessInfo instance to store \
96 the information about variable accesses.
98 :py:class:`psyclone.core.VariablesAccessInfo`
101 self.
appendappend(
"ncell_2d", var_accesses)
104 '''Add the CMA operator and associated scalars to the argument
105 list and optionally add them to the variable access
108 :param arg: the CMA operator argument.
109 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
110 :param var_accesses: optional VariablesAccessInfo instance to store \
111 the information about variable accesses.
112 :type var_accesses: \
113 :py:class:`psyclone.core.VariablesAccessInfo`
117 self.
appendappend(arg.name, var_accesses)
119 nrow = arg.name +
"_nrow"
121 if arg.function_space_to.orig_name != \
122 arg.function_space_from.orig_name:
126 ncol = arg.name +
"_ncol"
127 _local_args.append(ncol)
128 bandwidth = arg.name +
"_bandwidth"
129 alpha = arg.name +
"_alpha"
130 beta = arg.name +
"_beta"
131 gamma_m = arg.name +
"_gamma_m"
132 gamma_p = arg.name +
"_gamma_p"
133 _local_args += [bandwidth, alpha, beta, gamma_m, gamma_p]
134 self.
extendextend(_local_args, var_accesses)
137 '''Add the field vector associated with the argument 'argvect' to the
138 argument list. If supplied it also stores these accesses to the
141 :param argvect: the field vector to add.
142 :type argvect: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
143 :param var_accesses: optional VariablesAccessInfo instance to store \
144 the information about variable accesses.
145 :type var_accesses: \
146 :py:class:`psyclone.core.VariablesAccessInfo`
152 for idx
in range(1, argvect.vector_size+1):
153 text = (argvect.name +
"_" +
154 argvect.function_space.mangled_name +
156 self.
appendappend(text, var_accesses)
158 def field(self, arg, var_accesses=None):
159 '''Add the field array associated with the argument 'arg' to the
160 argument list. If supplied it also stores this access in var_accesses.
162 :param arg: the field to be added.
163 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
164 :param var_accesses: optional VariablesAccessInfo instance to store \
165 the information about variable accesses.
166 :type var_accesses: \
167 :py:class:`psyclone.core.VariablesAccessInfo`
170 text = arg.name +
"_" + arg.function_space.mangled_name
171 self.
appendappend(text, var_accesses, mode=arg.access)
174 '''Add stencil information to the argument list associated with the
175 argument 'arg' if the extent is unknown. If supplied it also stores
176 this access in var_accesses.
178 :param arg: the kernel argument with which the stencil is associated.
179 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
180 :param var_accesses: optional VariablesAccessInfo instance to store \
181 the information about variable accesses.
182 :type var_accesses: \
183 :py:class:`psyclone.core.VariablesAccessInfo`
189 name = LFRicStencils.dofmap_size_symbol(self.
_stub_symtab_stub_symtab, arg).name
190 self.
appendappend(name, var_accesses)
193 '''Add stencil information to the argument list associated with the
194 argument 'arg' if the direction is unknown. If supplied it also stores
195 this access in var_accesses.
197 :param arg: the kernel argument with which the stencil is associated.
198 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
199 :param var_accesses: optional VariablesAccessInfo instance to store \
200 the information about variable accesses.
201 :type var_accesses: \
202 :py:class:`psyclone.core.VariablesAccessInfo`
208 name = LFRicStencils.direction_name(self.
_stub_symtab_stub_symtab, arg)
209 self.
appendappend(name, var_accesses)
212 '''Add general stencil information associated with the argument 'arg'
213 to the argument list. If supplied it also stores this access in
216 :param arg: the meta-data description of the kernel \
217 argument with which the stencil is associated.
218 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
219 :param var_accesses: optional VariablesAccessInfo instance to store \
220 the information about variable accesses.
221 :type var_accesses: \
222 :py:class:`psyclone.core.VariablesAccessInfo`
228 var_name = LFRicStencils.dofmap_symbol(self.
_stub_symtab_stub_symtab, arg).name
229 self.
appendappend(var_name, var_accesses)
232 '''Add the maximum branch extent for a 2D stencil associated with the
233 argument 'arg' to the argument list. If supplied it also stores this
236 :param arg: the kernel argument with which the stencil is associated.
237 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
238 :param var_accesses: optional `SingleVariableAccessInfo` \
239 instance to store the information about variable accesses.
240 :type var_accesses: \
241 :py:class:`psyclone.core.SingleVariableAccessInfo`
249 name = LFRicStencils.max_branch_length_name(self.
_stub_symtab_stub_symtab, arg)
250 self.
appendappend(name, var_accesses)
253 '''Add 2D stencil information to the argument list associated with the
254 argument 'arg' if the extent is unknown. If supplied it also stores
255 this access in var_accesses.
257 :param arg: the kernel argument with which the stencil is associated.
258 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
259 :param var_accesses: optional `VariablesAccessInfo` instance to store \
260 the information about variable accesses.
261 :type var_accesses: \
262 :py:class:`psyclone.core.VariablesAccessInfo`
268 name = LFRicStencils.dofmap_size_symbol(self.
_stub_symtab_stub_symtab, arg).name
269 self.
appendappend(name, var_accesses)
272 '''Add general 2D stencil information associated with the argument
273 'arg' to the argument list. If supplied it also stores this access in
276 :param arg: the meta-data description of the kernel \
277 argument with which the stencil is associated.
278 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
279 :param var_accesses: optional `VariablesAccessInfo` instance to store \
280 the information about variable accesses.
281 :type var_accesses: \
282 :py:class:`psyclone.core.VariablesAccessInfo`
295 var_name = LFRicStencils.dofmap_symbol(self.
_stub_symtab_stub_symtab, arg).name
296 self.
appendappend(var_name, var_accesses)
299 '''Add the operator arguments to the argument list. If supplied it
300 also stores this access in var_accesses.
302 :param arg: the meta-data description of the operator.
303 :type arg: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
304 :param var_accesses: optional VariablesAccessInfo instance to store \
305 the information about variable accesses.
306 :type var_accesses: \
307 :py:class:`psyclone.core.VariablesAccessInfo`
310 size = arg.name +
"_ncell_3d"
311 self.
appendappend(size, var_accesses)
312 self.
appendappend(arg.name, var_accesses)
315 ''' Provide compulsory arguments if there is a field on this
316 function space. If supplied it also stores this access in
319 :param function_space: the function space for which the compulsory \
321 :type function_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
322 :param var_accesses: optional VariablesAccessInfo instance to store \
323 the information about variable accesses.
324 :type var_accesses: \
325 :py:class:`psyclone.core.VariablesAccessInfo`
328 self.
appendappend(function_space.undf_name, var_accesses)
329 self.
appendappend(function_space.map_name, var_accesses)
331 def basis(self, function_space, var_accesses=None):
332 '''Add basis function information for this function space to the
333 argument list and optionally to the variable access information.
334 There can be more than one if this is an evaluator and/or multiple
335 'gh_shape's have been requested in the kernel metadata. If supplied
336 it also stores these accesses in var_accesses.
338 :param function_space: the function space for which to provide \
340 :type function_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
341 :param var_accesses: optional VariablesAccessInfo instance to store \
342 the information about variable accesses.
343 :type var_accesses: \
344 :py:class:`psyclone.core.VariablesAccessInfo`
346 :raises InternalError: if the evaluator shape is not recognised.
350 for shape
in self.
_kern_kern.eval_shapes:
351 if shape
in const.VALID_QUADRATURE_SHAPES:
355 basis_name = function_space.get_basis_name(
356 qr_var=
"qr_"+shape.split(
"_")[-1])
357 self.
appendappend(basis_name, var_accesses)
359 elif shape
in const.VALID_EVALUATOR_SHAPES:
363 for _, target
in self.
_kern_kern.eval_targets.items():
365 function_space.get_basis_name(on_space=target[0])
366 self.
appendappend(basis_name, var_accesses)
369 f
"Unrecognised evaluator shape ('{shape}'). Expected one "
370 f
"of: {const.VALID_EVALUATOR_SHAPES}")
373 '''Add differential basis information for the function space to the
374 argument list. If supplied it also stores this access in
377 :param function_space: the function space for which the differential \
378 basis functions are required.
379 :type function_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
380 :param var_accesses: optional VariablesAccessInfo instance to store \
381 the information about variable accesses.
382 :type var_accesses: \
383 :py:class:`psyclone.core.VariablesAccessInfo`
385 :raises InternalError: if the evaluator shape is not recognised.
389 for shape
in self.
_kern_kern.eval_shapes:
390 if shape
in const.VALID_QUADRATURE_SHAPES:
395 diff_basis_name = function_space.get_diff_basis_name(
396 qr_var=
"qr_"+shape.split(
"_")[-1])
397 self.
appendappend(diff_basis_name, var_accesses)
399 elif shape
in const.VALID_EVALUATOR_SHAPES:
404 for _, target
in self.
_kern_kern.eval_targets.items():
405 diff_basis_name = function_space.get_diff_basis_name(
407 self.
appendappend(diff_basis_name, var_accesses)
410 f
"('{shape}'). Expected one of: "
411 f
"{const.VALID_EVALUATOR_SHAPES}")
414 '''Implement the boundary_dofs array fix for a field. If supplied it
415 also stores this access in var_accesses.
417 :param function_space: the function space for which boundary dofs \
419 :type function_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
420 :param var_accesses: optional VariablesAccessInfo instance to store \
421 the information about variable accesses.
422 :type var_accesses: \
423 :py:class:`psyclone.core.VariablesAccessInfo`
426 arg = self.
_kern_kern.arguments.get_arg_on_space(function_space)
427 name =
"boundary_dofs_"+arg.name
428 self.
appendappend(name, var_accesses)
431 '''Supply necessary additional arguments for the kernel that
432 applies boundary conditions to a LMA operator. If supplied it
433 also stores this access in var_accesses.
435 :param function_space: the 'to' function space of the operator.
436 :type function_space: :py:class:`psyclone.dynamo3.FunctionSpace`
437 :param var_accesses: optional VariablesAccessInfo instance to store \
438 the information about variable accesses.
439 :type var_accesses: \
440 :py:class:`psyclone.core.VariablesAccessInfo`
446 '''Provide the kernel arguments required for the mesh properties
447 specified in the kernel metadata. If supplied it also stores this
448 access in var_accesses.
450 :param var_accesses: optional VariablesAccessInfo instance to store \
451 the information about variable accesses.
452 :type var_accesses: \
453 :py:class:`psyclone.core.VariablesAccessInfo`
456 if self.
_kern_kern.mesh.properties:
460 self.
extendextend(LFRicMeshProperties(self.
_kern_kern).
461 kern_args(stub=
True, var_accesses=var_accesses))
464 '''Add quadrature-related information to the kernel argument list.
465 Adds the necessary arguments to the argument list, and optionally
466 adds variable access information to the var_accesses object.
468 :param var_accesses: optional VariablesAccessInfo instance to store \
469 the information about variable accesses.
470 :type var_accesses: \
471 :py:class:`psyclone.core.VariablesAccessInfo`
474 for rule
in self.
_kern_kern.qr_rules.values():
475 self.
extendextend(rule.kernel_args, var_accesses)
479 '''Add indirection dofmap required when applying a CMA operator. If
480 supplied it also stores this access in var_accesses.
482 :param function_space: the function space for which the indirect \
484 :type function_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
485 :param operator: the CMA operator.
486 :type operator: :py:class:`psyclone.dynamo0p3.DynKernelArgument`
487 :param var_accesses: optional VariablesAccessInfo instance to store \
488 the information about variable accesses.
489 :type var_accesses: \
490 :py:class:`psyclone.core.VariablesAccessInfo`
492 :raises InternalError: if no kernel argument is supplied.
493 :raises InternalError: if the supplied kernel argument is not a \
499 if operator.argument_type !=
"gh_columnwise_operator":
501 f
"A CMA operator (gh_columnwise_operator) must "
502 f
"be supplied but got '{operator.argument_type}'.")
508 __all__ = [
"KernStubArgList"]
def field_bcs_kernel(self, function_space, var_accesses=None)
def append(self, var_name, var_accesses=None, var_access_name=None, mode=AccessType.READ, metadata_posn=None)
def extend(self, list_var_name, var_accesses=None, mode=AccessType.READ, list_metadata_posn=None)
def quad_rule(self, var_accesses=None)
def mesh_properties(self, var_accesses=None)
def diff_basis(self, function_space, var_accesses=None)
def cell_position(self, var_accesses=None)
def stencil_2d_unknown_extent(self, arg, var_accesses=None)
def fs_compulsory_field(self, function_space, var_accesses=None)
def indirection_dofmap(self, function_space, operator=None, var_accesses=None)
def field_vector(self, argvect, var_accesses=None)
def stencil_unknown_direction(self, arg, var_accesses=None)
def operator(self, arg, var_accesses=None)
def cma_operator(self, arg, var_accesses=None)
def basis(self, function_space, var_accesses=None)
def mesh_height(self, var_accesses=None)
def field_bcs_kernel(self, function_space, var_accesses=None)
def stencil_unknown_extent(self, arg, var_accesses=None)
def operator_bcs_kernel(self, function_space, var_accesses=None)
def field(self, arg, var_accesses=None)
def stencil_2d_max_extent(self, arg, var_accesses=None)
def stencil(self, arg, var_accesses=None)
def stencil_2d(self, arg, var_accesses=None)