Reference Guide  2.5.0
meta_mesh_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 MetaMeshMetadata class which captures
37 the values for the LFRic kernel meta_mesh metadata.
38 
39 '''
41  CommonDeclarationMetadata
43  MetaMeshArgMetadata
44 
45 
47  '''Class to capture the values of the LFRic kernel
48  meta_mesh metadata. This class supports the creation,
49  modification and Fortran output of this metadata.
50 
51  meta_mesh metadata specifies properties of the LFRic mesh object
52  that are required by a kernel.
53 
54  :param meta_mesh_args: a list of meta_mesh arguments.
55  :type meta_mesh_args: List[:py:class:`psyclone.domain.lfric.kernel.\
56  MetaMeshArgMetadata`]
57 
58  '''
59  def __init__(self, meta_mesh_args):
60  super().__init__()
61  self.meta_mesh_argsmeta_mesh_argsmeta_mesh_argsmeta_mesh_args = meta_mesh_args
62 
63  def fortran_string(self):
64  '''
65  :returns: the meta_mesh metadata as Fortran.
66  :rtype: str
67  '''
68  return self.type_declaration_stringtype_declaration_string(
69  "MESH_DATA_TYPE", "META_MESH", self._meta_mesh_args_meta_mesh_args)
70 
71  @staticmethod
72  def create_from_fparser2(fparser2_tree):
73  '''Create an instance of MetaMeshMetadata from an fparser2
74  tree.
75 
76  LFRic meta mesh metadata is in array form. Two
77  versions of the array form are supported:
78 
79  type(mesh_data_type) :: meta_mesh(1) = (/ ... /)
80  type(mesh_data_type), dimension(1) :: meta_mesh = (/ ... /)
81 
82  :param fparser2_tree: fparser2 tree capturing the meta \
83  mesh metadata.
84 
85  :type fparser2_tree: :py:class:`fparser.two.Fortran2003.\
86  Data_Component_Def_Stmt`
87 
88  :returns: an instance of MetaMeshMetadata.
89  :rtype: :py:class:`psyclone.domain.lfric.kernel.\
90  MetaMeshMetadata`
91 
92  '''
93  values_list = MetaMeshMetadata.get_derived_array_declaration(
94  fparser2_tree, "MESH_DATA_TYPE", "META_MESH")
95  meta_obj_list = []
96  for value in values_list:
97  meta_obj_list.append(
98  MetaMeshArgMetadata.create_from_fortran_string(value))
99  return MetaMeshMetadata(meta_obj_list)
100 
101  @property
102  def meta_mesh_args(self):
103  '''
104  :returns: a list of meta mesh argument objects.
105  :rtype: List[:py:class:`psyclone.domain.lfric.kernel.\
106  MetaMeshArgMetadata`]
107  '''
108  return self._meta_mesh_args_meta_mesh_args[:]
109 
110  @meta_mesh_args.setter
111  def meta_mesh_args(self, values):
112  '''
113  :param values: set the meta_mesh metadata to the \
114  supplied list of values.
115  :type values: List[:py:class:`psyclone.domain.lfric.kernel.\
116  MetaMeshArgMetadata`]
117 
118  '''
119  self.validate_listvalidate_list(values, MetaMeshArgMetadata)
120  # Take a copy of the list so that it can't be modified
121  # externally.
122  self._meta_mesh_args_meta_mesh_args = values[:]
123 
124 
125 __all__ = ["MetaMeshMetadata"]