Reference Guide  2.5.0
gocean_constants.py
1 # -----------------------------------------------------------------------------
2 # BSD 3-Clause License
3 #
4 # Copyright (c) 2021-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: J. Henrichs, Bureau of Meteorology
35 # Modified: R. W. Ford, STFC Daresbury Lab
36 
37 '''
38 This module provides a class with all GOcean related constants.
39 '''
40 
41 # Imports
42 from psyclone.configuration import Config
43 
44 
45 # pylint: disable=too-few-public-methods
47  '''This class stores all GOcean constants. It stores all values in
48  class variables (to avoid re-evaluating them).
49 
50  '''
51  HAS_BEEN_INITIALISED = False
52 
53  @staticmethod
55  '''Return the valid access types for the GOcean API. Reads the values
56  from the config file the first time the method is called.
57 
58  :returns: valid access types for the GOcean API.
59  :rtype: list[str]
60 
61  '''
62  if not GOceanConstants._VALID_ACCESS_TYPES:
63  conf = Config.get().api_conf("gocean1.0")
64  GOceanConstants._VALID_ACCESS_TYPES = \
65  list(conf.get_access_mapping().keys())
66  return GOceanConstants._VALID_ACCESS_TYPES
67 
68  def __init__(self):
69  if GOceanConstants.HAS_BEEN_INITIALISED:
70  return
71 
72  GOceanConstants.HAS_BEEN_INITIALISED = True
73 
74  # Valid intrinsic types of kernel argument metadata.
75  GOceanConstants.VALID_INTRINSIC_TYPES = []
76 
77  # Valid access types (GO_READ etc). These are accessed via the
78  # get_valid_access_types() method as they are read from the
79  # config file rather than being fixed constant values.
80  GOceanConstants._VALID_ACCESS_TYPES = []
81 
82  # psyGen argument types.
83  GOceanConstants.VALID_ARG_TYPE_NAMES = []
84 
85  # psyGen names of internal scalar argument types.
86  GOceanConstants.VALID_SCALAR_NAMES = ["rscalar", "iscalar"]
87 
88  # The different grid-point types that a field can live on.
89  GOceanConstants.VALID_FIELD_GRID_TYPES = ["go_cu", "go_cv", "go_ct",
90  "go_cf", "go_every"]
91 
92  # The two scalar types we support in the kernel argument
93  # metadata.
94  GOceanConstants.VALID_SCALAR_TYPES = ["go_i_scalar", "go_r_scalar"]
95 
96  # Index-offset schemes (for the Arakawa C-grid)
97  GOceanConstants.VALID_OFFSET_NAMES = ["go_offset_se", "go_offset_sw",
98  "go_offset_ne", "go_offset_nw",
99  "go_offset_any"]
100 
101  # The offset schemes for which we can currently generate constant
102  # loop bounds in the PSy layer.
103  GOceanConstants.SUPPORTED_OFFSETS = ["go_offset_ne", "go_offset_sw",
104  "go_offset_any"]
105 
106  # The sets of grid points that a kernel may operate on.
107  GOceanConstants.VALID_ITERATES_OVER = ["go_all_pts", "go_internal_pts",
108  "go_external_pts"]
109 
110  # The list of valid stencil properties. We currently only support
111  # pointwise. This property could probably be removed from the
112  # GOcean API altogether.
113  GOceanConstants.VALID_STENCIL_NAMES = ["go_pointwise"]
114 
115  # The name used to indicate there is a stencil. This will
116  # contain 3 arguments specifying the type of stencil being
117  # used.
118  GOceanConstants.VALID_STENCIL_NAME = "go_stencil"
119 
120  # The valid types of loop. In this API we expect only doubly-nested
121  # loops.
122  GOceanConstants.VALID_LOOP_TYPES = ["inner", "outer"]
123 
124 
125 # =============================================================================
126 # Documentation utils: The list of module members that we wish AutoAPI to
127 # generate documentation for (see https://psyclone-ref.readthedocs.io).
128 __all__ = ['GOceanConstants']