36 '''Module containing the InterGridArgMetadata class which captures the metadata
37 associated with an intergrid argument. Supports the creation, modification
38 and Fortran output of an intergrid argument.
41 from fparser.two
import Fortran2003
48 '''Class to capture LFRic kernel metadata information for an intergrid
51 :param str datatype: the datatype of this InterGrid argument \
53 :param str access: the way the kernel accesses this intergrid \
54 argument (GH_WRITE, ...).
55 :param str function_space: the function space that this \
56 InterGrid is on (W0, ...).
57 :param str mesh_arg: the type of mesh that this InterGrid arg \
58 is on (coarse or fine).
59 :param Optional[str] stencil: the type of stencil used by the \
60 kernel when accessing this InterGrid arg.
74 check_name =
"inter-grid"
80 fparser2_class = Fortran2003.Structure_Constructor
82 def __init__(self, datatype, access, function_space, mesh_arg,
84 super().__init__(datatype, access, function_space, stencil=stencil)
88 def _get_metadata(cls, fparser2_tree):
89 '''Extract the required metadata from the fparser2 tree and return it
90 as strings. Also check that the metadata is in the expected
91 form (but do not check the metadata values as that is done
94 :param fparser2_tree: fparser2 tree containing the metadata \
96 :type fparser2_tree: \
97 :py:class:`fparser.two.Fortran2003.Structure_Constructor`
99 :returns: a tuple containing the datatype, access, function \
100 space, mesh and stencil metadata.
101 :rtype: Tuple[str, str, str, str, Optional[str]]
105 function_space = cls.
get_argget_arg(
108 stencil = cls.
get_stencilget_stencil(fparser2_tree)
109 mesh_arg = cls.
get_mesh_argget_mesh_arg(fparser2_tree, 5)
112 mesh_arg = cls.
get_mesh_argget_mesh_arg(fparser2_tree, 4)
114 return (datatype, access, function_space, mesh_arg, stencil)
118 '''Retrieves the mesh_arg metadata value from the supplied fparser2
121 :param fparser2_tree: fparser2 tree capturing the metadata for \
122 an InterGrid argument.
123 :type fparser2_tree: \
124 :py:class:`fparser.two.Fortran2003.Structure_Constructor`
125 :param int mesh_arg_index: the index at which to find the metadata.
127 :returns: the metadata mesh value extracted from the fparser2 tree.
130 raises ValueError: if the metadata is not in the form \
131 'mesh_arg = <value>'.
135 mesh_arg_lhs = fparser2_tree.children[1].\
136 children[mesh_arg_index].children[0].tostr()
137 except IndexError
as info:
139 f
"At argument index {mesh_arg_index} for metadata "
140 f
"'{fparser2_tree}' expected the metadata to be in the form "
141 f
"'mesh_arg=value' but found "
142 f
"'{fparser2_tree.children[1].children[mesh_arg_index]}'.") \
145 if not mesh_arg_lhs.lower() ==
"mesh_arg":
147 f
"At argument index {mesh_arg_index} for metadata "
148 f
"'{fparser2_tree}' expected the left hand side "
149 f
"to be 'mesh_arg' but found '{mesh_arg_lhs}'.")
150 mesh_arg = fparser2_tree.children[1].\
151 children[mesh_arg_index].children[1].tostr()
156 :returns: the metadata represented by this class as Fortran.
160 return (f
"arg_type({self.form}, {self.datatype}, {self.access}, "
161 f
"{self.function_space}, stencil({self.stencil}), "
162 f
"mesh_arg={self.mesh_arg})")
163 return (f
"arg_type({self.form}, {self.datatype}, {self.access}, "
164 f
"{self.function_space}, mesh_arg={self.mesh_arg})")
169 :returns: the mesh type for this intergrid argument.
175 def mesh_arg(self, value):
177 :param str value: set the mesh type to the \
181 InterGridArgMetadata.validate_scalar_value(
182 value, const.VALID_MESH_TYPES,
"mesh_arg")
186 __all__ = [
"InterGridArgMetadata"]
def get_arg(fparser2_tree, index)
int function_space_arg_index
int function_space_arg_index
def get_stencil(cls, fparser2_tree)
def mesh_arg(self, value)
def get_mesh_arg(fparser2_tree, mesh_arg_index)
def _get_datatype_access_metadata(cls, fparser2_tree)