Reference Guide  2.5.0
evaluator_targets_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 EvaluatorTargetsMetadata class which captures
37 the values for the LFRic kernel GH_EVALUATOR_TARGETS 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  GH_EVALUATOR_TARGETS metadata. This class supports the creation,
48  modification and Fortran output of this metadata.
49 
50  if an evaluator is required for multiple function spaces then
51  this is specified using the gh_evaluator_targets
52  metadata.
53 
54  :param evaluator_targets: a list of function-space names.
55  :type evaluator_targets: List[str]
56 
57  '''
58  def __init__(self, evaluator_targets):
59  super().__init__()
60  self.evaluator_targetsevaluator_targetsevaluator_targetsevaluator_targets = evaluator_targets
61 
62  def fortran_string(self):
63  '''
64  :returns: the evaluator_targets metadata as Fortran.
65  :rtype: str
66  '''
67  return EvaluatorTargetsMetadata.array_declaration_string(
68  "INTEGER", "GH_EVALUATOR_TARGETS", self._evaluator_targets_evaluator_targets)
69 
70  @staticmethod
71  def create_from_fparser2(fparser2_tree):
72  '''Create an instance of EvaluatorTargetsMetadata from an fparser2
73  tree.
74 
75  LFRic evaluator targets metadata is in array form. Two
76  versions of the array form are supported:
77 
78  integer :: gh_evaluator_targets(2) = (/ w0, w1 /)
79  integer, dimension(2) :: gh_shape = (/ w0, w1 /)
80 
81  :param fparser2_tree: fparser2 tree capturing the evaluator \
82  targets metadata.
83  :type fparser2_tree: :py:class:`fparser.two.Fortran2003.\
84  Data_Component_Def_Stmt`
85 
86  :returns: an instance of EvaluatorTargetsMetadata.
87  :rtype: :py:class:`psyclone.domain.lfric.kernel.\
88  EvaluatorTargetsMetadata`
89 
90  '''
91  const = LFRicConstants()
92  valid_values = const.VALID_FUNCTION_SPACES
93  values_list = EvaluatorTargetsMetadata.\
95  fparser2_tree, "INTEGER", "GH_EVALUATOR_TARGETS", valid_values)
96  return EvaluatorTargetsMetadata(values_list)
97 
98  @property
99  def evaluator_targets(self):
100  '''
101  :returns: a list of evaluator targets values (names of \
102  function spaces).
103  :rtype: List[str]
104  '''
105  return self._evaluator_targets_evaluator_targets[:]
106 
107  @evaluator_targets.setter
108  def evaluator_targets(self, values):
109  '''
110  :param values: set the evaluator_targets metadata to the \
111  supplied list of values.
112  :type values: List[str]
113  '''
114  const = LFRicConstants()
115  EvaluatorTargetsMetadata.validate_list(values, str)
116  for value in values:
117  EvaluatorTargetsMetadata.validate_scalar_value(
118  value, const.VALID_FUNCTION_SPACES, "evaluator_targets")
119  # Take a copy of the list so that it can't be modified
120  # externally. Also make all values lower case.
121  self._evaluator_targets_evaluator_targets = [value.lower() for value in values]
122 
123 
124 __all__ = ["EvaluatorTargetsMetadata"]