36 '''Module containing the FieldVector Arg class which captures the metadata
37 associated with a field vector argument. Supports the creation, modification
38 and Fortran output of a Field Vector argument.
45 '''Class to capture LFRic kernel metadata information for a field
48 :param str datatype: the datatype of this field (GH_INTEGER, ...).
49 :param str access: the way the kernel accesses this field (GH_WRITE, ...).
50 :param str function_space: the function space that this field is on \
52 :param str vector_length: the size of the vector.
53 :param Optional[str] stencil: the type of stencil used by the \
54 kernel when accessing this field.
64 vector_length_arg_index = 0
66 check_name =
"field-vector"
70 def __init__(self, datatype, access, function_space, vector_length,
72 super().__init__(datatype, access, function_space, stencil=stencil)
76 def _get_metadata(cls, fparser2_tree):
77 '''Extract the required metadata from the fparser2 tree and return it
78 as strings. Also check that the metadata is in the expected
79 form (but do not check the metadata values as that is done
82 :param fparser2_tree: fparser2 tree containing the metadata \
84 :type fparser2_tree: :py:class:`fparser.two.Fortran2003.Part_Ref`
86 :returns: a tuple containing the datatype, access, function \
87 space, vector-length and stencil metadata.
88 :rtype: Tuple[str, str, str, str, Optional[str]]
91 datatype, access, function_space, stencil = super()._get_metadata(
94 return (datatype, access, function_space, vector_length, stencil)
98 :returns: the metadata represented by this class as Fortran.
102 return (f
"arg_type({self.form}*{self.vector_length}, "
103 f
"{self.datatype}, {self.access}, {self.function_space}, "
104 f
"stencil({self.stencil}))")
105 return (f
"arg_type({self.form}*{self.vector_length}, {self.datatype}, "
106 f
"{self.access}, {self.function_space})")
109 def vector_length(self):
111 :returns: the vector length of this field vector \
117 @vector_length.setter
118 def vector_length(self, value):
119 ''':param str value: set the field vector length to the specified \
122 :raises TypeError: if the provided value is not of type str.
123 :raises ValueError: if the provided value is not a string \
124 containing an integer.
125 :raises ValueError: if the provided value is not greater than 1.
128 if not isinstance(value, str):
129 raise TypeError(f
"The vector size should be a string but found "
130 f
"{type(value).__name__}.")
132 int_value = int(value)
133 except ValueError
as info:
135 f
"The vector size should be a string containing an integer, "
136 f
"but found '{value}'.")
from info
139 raise ValueError(f
"The vector size should be an integer greater "
140 f
"than 1 but found {value}.")
144 __all__ = [
"FieldVectorArgMetadata"]
def get_vector_length(cls, fparser2_tree)
def vector_length(self, value)