38 '''This module contains the FunctionSpace object and related constants.
41 from psyclone.errors import InternalError, FieldNotFoundError, GenerationError
47 Manages the name of a function space. If it is an any_space or
48 any_discontinuous_space then its name is mangled such that it is unique
49 within the scope of an Invoke.
51 :param str name: original name of function space to create a \
53 :param kernel_args: object encapsulating all arguments to the kernel, \
54 one or more of which are on this function space.
55 :type kernel_args: :py:class:`psyclone.dynamo0p3.DynKernelArguments`
57 :raises InternalError: if an unrecognised function space is encountered.
61 def __init__(self, name, kernel_args):
69 if self.
_orig_name_orig_name
not in const.VALID_FUNCTION_SPACE_NAMES:
71 f
"Unrecognised function space '{self._orig_name}'. The "
72 f
"supported spaces are {const.VALID_FUNCTION_SPACE_NAMES}.")
74 if self.
_orig_name_orig_name
not in const.VALID_ANY_SPACE_NAMES + \
75 const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES:
90 Returns the name of this function space as declared in the
93 :returns: original name of this function space.
102 Returns the short name of this function space (original name for a
103 valid LFRic function space and condensed name for any_*_spaces).
105 :returns: short name of this function space.
114 Returns the mangled name of this function space such that it is
115 unique within the scope of an invoke. If the mangled name has not
116 been generated then we do that the first time we are called.
118 :returns: mangled name of this function space.
130 def _mangle_fs_name(self):
132 Constructs the mangled version of a function-space name given a list
133 of kernel arguments if the argument's function space is any_*_space
134 (if the argument's function space is one of the valid LFRic function
135 spaces then the mangled name is the original name, set in the class
136 initialisation). The mangled name is the short name of the function
137 space combined with the argument's name.
139 :returns: mangled name of this function space.
142 :raises InternalError: if a function space to create the mangled \
143 name for is not one of 'any_space' or \
144 'any_discontinuous_space' spaces.
145 :raises FieldNotFoundError: if no kernel argument was found on \
146 the specified function space.
152 if self.
_orig_name_orig_name
not in const.VALID_ANY_SPACE_NAMES + \
153 const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES:
155 f
"_mangle_fs_name: function space '{self._orig_name}' is not "
156 f
"one of {const.VALID_ANY_SPACE_NAMES} or "
157 f
"{const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES} spaces.")
163 for fspace
in arg.function_spaces:
164 if (fspace
and fspace.orig_name.lower() ==
166 mngl_name = self.
_short_name_short_name +
"_" + arg.name
171 f
"space '{self._orig_name}'")
173 def _shorten_fs_name(self):
175 Creates short names for any_*_spaces to be used for mangled names
176 from the condensed keywords and function space IDs.
178 :returns: short name of this function space.
181 :raises InternalError: if a function space to create the short \
182 name for is not one of 'any_space' or \
183 'any_discontinuous_space' spaces.
189 if self.
_orig_name_orig_name
in const.VALID_ANY_SPACE_NAMES:
191 elif self.
_orig_name_orig_name
in const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES:
195 f
"_shorten_fs_name: function space '{self._orig_name}' is not "
196 f
"one of {const.VALID_ANY_SPACE_NAMES} or "
197 f
"{const.VALID_ANY_DISCONTINUOUS_SPACE_NAMES} spaces.")
202 self.
_short_name_short_name = start +
"spc" + fslist[-1]
207 ''':returns: a dofmap name for the supplied FunctionSpace.
214 ''':returns: the name of a column-banded dofmap for this FunctionSpace.
221 ''':returns: the name of a CMA indirection dofmap for the supplied \
225 return "cma_indirection_map_" + self.
mangled_namemangled_name
229 ''':returns: a ndf name for this FunctionSpace object.
236 ''':returns: a undf name for this FunctionSpace object.
243 Returns a name for the basis function on this FunctionSpace. If
244 the name of an associated quadrature object is supplied then this
245 is appended to the returned name. Similarly, if the function space
246 at which the basis is to be evaluated is supplied then this is
247 also appended to the name.
249 :param string qr_var: the name of the Quadrature Object for which the \
250 basis functions are required
251 :param on_space: the function space at which the basis functions \
253 :type on_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
254 :returns: name for the Fortran array holding the basis function
258 name =
"_".join([
"basis", self.
mangled_namemangled_name])
262 name +=
"_on_" + on_space.mangled_name
267 Returns a name for the differential basis function on this
268 FunctionSpace. If the name of an associated quadrature object is
269 supplied then this is appended to the returned name. Similarly, if the
270 function space at which the basis is to be evaluated is supplied then
271 this is also appended to the name.
273 :param str qr_var: the name of the Quadrature Object for which the \
274 differential basis functions are required.
275 :param on_space: the function space at which the differential basis \
276 functions will be evaluated
277 :type on_space: :py:class:`psyclone.dynamo0p3.domain.lfric.\
279 :returns: name for the Fortran array holding the differential basis \
288 name +=
"_on_" + on_space.mangled_name
293 Returns the name of the specified operator (basis or differential
294 basis) for this FunctionSpace.
296 :param str operator_name: name (type) of the operator.
297 :param str qr_var: the name of the Quadrature Object for which the \
298 operator is required.
299 :param on_space: the function space at which the operator is required.
300 :type on_space: :py:class:`psyclone.domain.lfric.FunctionSpace`
302 :returns: name for the Fortran arry holding the named operator \
303 for the specified function space.
307 if operator_name ==
"gh_basis":
308 return self.
get_basis_nameget_basis_name(qr_var=qr_var, on_space=on_space)
309 if operator_name ==
"gh_diff_basis":
314 f
"Unsupported name '{operator_name}' found. Expected one of "
315 f
"{const.VALID_METAFUNC_NAMES}")
318 '''Returns the corresponding argument if the supplied list of
319 arguments contains a field that exists on this space. Otherwise this
320 function returns None.
322 :param arguments: list of arguments to be tested.
323 :type arguments: :py:class:`psyclone.dynamo0p3.DynKernelArguments`
325 :returns: the argument from the supplied list of arguments that \
326 contains a field that exists on this space or None.
327 :rtype: :py:class:`psyclone.dynamo0p3.DynKernelArgument` or None
330 if self.
mangled_namemangled_name
in arguments.unique_fs_names:
331 for arg
in arguments.args:
334 if arg.is_field
and \
335 arg.function_space.orig_name == self.
orig_nameorig_name:
340 '''Returns the corresponding argument if the supplied list of
341 arguments contains a cma operator that maps to/from this FunctionSpace.
342 Otherwise this function returns None.
344 :param arguments: list of arguments to be tested.
345 :type arguments: :py:class:`psyclone.dynamo0p3.DynKernelArguments`
347 :returns: the argument from the supplied list of arguments that \
348 contains a field that exists on this space or None.
349 :rtype: :py:class:`psyclone.dynamo0p3.DynKernelArgument` or None
352 if self.
mangled_namemangled_name
in arguments.unique_fs_names:
353 for arg
in arguments.args:
356 if arg.argument_type ==
"gh_columnwise_operator" and \
357 self.
orig_nameorig_name
in [arg.function_space_to.orig_name,
358 arg.function_space_from.orig_name]:
364 ''':returns: True if this function space has scalar basis functions.
368 return self.
orig_nameorig_name.lower()
in const.SCALAR_BASIS_SPACE_NAMES
372 ''':returns: True if this function space has vector basis functions.
376 return self.
orig_nameorig_name.lower()
in const.VECTOR_BASIS_SPACE_NAMES
380 ''':returns: True if this function space has scalar differential
385 return self.
orig_nameorig_name.lower()
in const.SCALAR_DIFF_BASIS_SPACE_NAMES
389 ''':returns: True if this function space has vector differential
394 return self.
orig_nameorig_name.lower()
in const.VECTOR_DIFF_BASIS_SPACE_NAMES
def has_vector_diff_basis(self)
def has_scalar_diff_basis(self)
def cbanded_map_name(self)
def _shorten_fs_name(self)
def get_operator_name(self, operator_name, qr_var=None, on_space=None)
def field_on_space(self, arguments)
def cma_indirection_map_name(self)
def has_scalar_basis(self)
def get_basis_name(self, qr_var=None, on_space=None)
def has_vector_basis(self)
def cma_on_space(self, arguments)
def _mangle_fs_name(self)
def get_diff_basis_name(self, qr_var=None, on_space=None)