Reference Guide  2.5.0
meta_ref_element_metadata.py
1 # -----------------------------------------------------------------------------
2 # BSD 3-Clause License
3 #
4 # Copyright (c) 2022-2024, Science and Technology Facilities Council
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
12 #
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 #
17 # * Neither the name of the copyright holder nor the names of its
18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 # -----------------------------------------------------------------------------
34 # Author R. W. Ford, STFC Daresbury Lab
35 
36 '''Module containing the MetaRefElementMetadata class which captures
37 the values for the LFRic kernel meta_ref_element metadata.
38 
39 '''
41  CommonDeclarationMetadata
43  MetaRefElementArgMetadata
44 
45 
47  '''Class to capture the values of the LFRic kernel
48  meta_ref_element metadata. This class supports the creation,
49  modification and Fortran output of this metadata.
50 
51  meta_ref_element metadata specifies properties of the reference
52  element.
53 
54  :param meta_ref_element_args: a list of meta_ref_element arguments.
55  :type meta_ref_element_args: List[:py:class:`psyclone.domain.lfric.kernel.\
56  MetaRefElementArgMetadata`]
57 
58  '''
59  def __init__(self, meta_ref_element_args):
60  super().__init__()
61  self.meta_ref_element_argsmeta_ref_element_argsmeta_ref_element_argsmeta_ref_element_args = meta_ref_element_args
62 
63  def fortran_string(self):
64  '''
65  :returns: the meta_ref_element metadata as Fortran.
66  :rtype: str
67  '''
68  return self.type_declaration_stringtype_declaration_string(
69  "REFERENCE_ELEMENT_DATA_TYPE", "META_REFERENCE_ELEMENT",
70  self._meta_ref_element_args_meta_ref_element_args)
71 
72  @staticmethod
73  def create_from_fparser2(fparser2_tree):
74  '''Create an instance of MetaRefElementMetadata from an fparser2
75  tree.
76 
77  :param fparser2_tree: fparser2 tree capturing the meta \
78  reference element metadata.
79  :type fparser2_tree: :py:class:`fparser.two.Fortran2003.\
80  Data_Component_Def_Stmt`
81 
82  :returns: an instance of MetaRefElementMetadata.
83  :rtype: :py:class:`psyclone.domain.lfric.kernel.\
84  MetaRefElementMetadata`
85 
86  '''
87  values_list = MetaRefElementMetadata.\
89  fparser2_tree, "REFERENCE_ELEMENT_DATA_TYPE",
90  "META_REFERENCE_ELEMENT")
91  meta_obj_list = []
92  for value in values_list:
93  meta_obj_list.append(
94  MetaRefElementArgMetadata.create_from_fortran_string(value))
95  return MetaRefElementMetadata(meta_obj_list)
96 
97  @property
98  def meta_ref_element_args(self):
99  '''
100  :returns: a list of meta reference element argument objects.
101  :rtype: List[:py:class:`psyclone.domain.lfric.kernel.\
102  MetaRefElementArgMetadata`]
103  '''
104  return self._meta_ref_element_args_meta_ref_element_args[:]
105 
106  @meta_ref_element_args.setter
107  def meta_ref_element_args(self, values):
108  '''
109  :param values: set the meta_ref_element metadata to the \
110  supplied list of values.
111  :type values: List[:py:class:`psyclone.domain.lfric.kernel.\
112  MetaRefElementArgMetadata`]
113 
114  '''
115  self.validate_listvalidate_list(values, MetaRefElementArgMetadata)
116  # Take a copy of the list so that it can't be modified
117  # externally.
118  self._meta_ref_element_args_meta_ref_element_args = values[:]
119 
120 
121 __all__ = ["MetaRefElementMetadata"]