Reference Guide  2.5.0
operates_on_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 OperatesOnMetadata class which captures
37 the values for the LFRic kernel OPERATES_ON metadata.
38 
39 '''
40 from psyclone.domain.lfric import LFRicConstants
42  CommonDeclarationMetadata
43 
44 
46  '''Class to capture the values of the LFRic kernel
47  OPERATES_ON metadata. This class supports the creation,
48  modification and Fortran output of this metadata.
49 
50  OPERATES_ON metadata specifies that the Kernel has been written to
51  expect data in the specified form, i.e. 'cell_column' means a column
52  of cells and 'domain' means all cells.
53 
54  :param str operates_on: the value of operates_on.
55 
56  '''
57  def __init__(self, operates_on):
58  super().__init__()
59  self.operates_onoperates_onoperates_onoperates_on = operates_on
60 
61  def fortran_string(self):
62  '''
63  :returns: the operates_on metadata as Fortran.
64  :rtype: str
65  '''
66  return OperatesOnMetadata.scalar_declaration_string(
67  "INTEGER", "OPERATES_ON", self._operates_on_operates_on)
68 
69  @staticmethod
70  def create_from_fparser2(fparser2_tree):
71  '''Create an instance of OperatesOnMetadata from an fparser2
72  tree.
73 
74  :param fparser2_tree: fparser2 tree capturing the operates_on \
75  metadata.
76  :type fparser2_tree: :py:class:`fparser.two.Fortran2003.\
77  Data_Component_Def_Stmt`
78 
79  LFRic operates_on metadata is in scalar form:
80 
81  integer :: operates_on = cell_column
82 
83  :returns: an instance of OperatesOnMetadata.
84  :rtype: :py:class:`psyclone.domain.lfric.kernel.\
85  OperatesOnMetadata`
86 
87  '''
88  const = LFRicConstants()
89  valid_values = const.USER_KERNEL_ITERATION_SPACES
90  value = OperatesOnMetadata.get_intrinsic_scalar_declaration(
91  fparser2_tree, "INTEGER", "OPERATES_ON", valid_values)
92  return OperatesOnMetadata(value)
93 
94  @property
95  def operates_on(self):
96  '''
97  :returns: the operates_on value.
98  :rtype: str
99  '''
100  return self._operates_on_operates_on
101 
102  @operates_on.setter
103  def operates_on(self, value):
104  '''
105  :param str value: sets the operates_on metadata to the \
106  supplied value.
107  '''
108  const = LFRicConstants()
109  OperatesOnMetadata.validate_scalar_value(
110  value, const.VALID_ITERATION_SPACES, "OPERATES_ON")
111  self._operates_on_operates_on = value.lower()
112 
113 
114 __all__ = ["OperatesOnMetadata"]