40 This module provides a class with all LFRic related constants.
43 from collections
import OrderedDict
51 '''This class stores all LFRic constants. Note that some constants
52 depend on values in the config file, so this class can only be
53 used after the config file has been read.
54 It stores all values in class variables (to avoid re-evaluating them).
57 HAS_BEEN_INITIALISED =
False
61 if LFRicConstants.HAS_BEEN_INITIALISED:
64 if not Config.has_config_been_initialised():
65 raise InternalError(
"LFRicConstants is being created before the "
66 "config file is loaded")
68 LFRicConstants.HAS_BEEN_INITIALISED =
True
69 api_config = Config.get().api_conf(
"dynamo0.3")
72 LFRicConstants.VALID_QUADRATURE_SHAPES = \
73 [
"gh_quadrature_xyoz",
"gh_quadrature_face",
"gh_quadrature_edge"]
74 LFRicConstants.VALID_EVALUATOR_SHAPES = \
75 LFRicConstants.VALID_QUADRATURE_SHAPES + [
"gh_evaluator"]
80 LFRicConstants.VALID_SCALAR_NAMES = [
"gh_scalar"]
81 LFRicConstants.VALID_FIELD_NAMES = [
"gh_field"]
82 LFRicConstants.VALID_OPERATOR_NAMES = [
"gh_operator",
83 "gh_columnwise_operator"]
84 LFRicConstants.VALID_ARG_TYPE_NAMES = \
85 LFRicConstants.VALID_FIELD_NAMES + \
86 LFRicConstants.VALID_OPERATOR_NAMES + \
87 LFRicConstants.VALID_SCALAR_NAMES
91 LFRicConstants.ARG_TYPE_SUFFIX_MAPPING = {
93 "gh_operator":
"local_stencil",
94 "gh_columnwise_operator":
"cma_matrix"
99 LFRicConstants.VALID_ARG_DATA_TYPES = \
100 [
"gh_real",
"gh_integer",
"gh_logical"]
101 LFRicConstants.VALID_SCALAR_DATA_TYPES = \
102 LFRicConstants.VALID_ARG_DATA_TYPES
103 LFRicConstants.VALID_FIELD_DATA_TYPES = [
"gh_real",
"gh_integer"]
104 LFRicConstants.VALID_OPERATOR_DATA_TYPES = [
"gh_real"]
110 LFRicConstants.VALID_SCALAR_ACCESS_TYPES = [
"gh_read",
"gh_sum"]
111 LFRicConstants.VALID_FIELD_ACCESS_TYPES = [
112 "gh_read",
"gh_write",
"gh_readwrite",
"gh_inc",
"gh_readinc"]
113 LFRicConstants.VALID_OPERATOR_ACCESS_TYPES = [
114 "gh_read",
"gh_write",
"gh_readwrite"]
115 LFRicConstants.VALID_ACCESS_TYPES = [
116 "gh_read",
"gh_write",
"gh_readwrite",
"gh_inc",
"gh_readinc"]
118 LFRicConstants.WRITE_ACCESSES = [
119 "gh_write",
"gh_readwrite",
"gh_inc",
"gh_readinc",
"gh_sum"]
122 LFRicConstants.VALID_STENCIL_TYPES = [
"x1d",
"y1d",
"xory1d",
"cross",
127 LFRicConstants.VALID_STENCIL_DIRECTIONS = [
"x_direction",
132 LFRicConstants.STENCIL_MAPPING = \
133 {
"x1d":
"STENCIL_1DX",
"y1d":
"STENCIL_1DY",
134 "cross":
"STENCIL_CROSS",
"cross2d":
"STENCIL_2D_CROSS",
135 "region":
"STENCIL_REGION"}
140 LFRicConstants.VALID_MESH_TYPES = [
"gh_coarse",
"gh_fine"]
144 supported_fortran_datatypes = api_config.supported_fortran_datatypes
149 LFRicConstants.VALID_INTRINSIC_TYPES = supported_fortran_datatypes
153 LFRicConstants.VALID_FIELD_INTRINSIC_TYPES = [
"real",
"integer",
157 LFRicConstants.MAPPING_DATA_TYPES = \
158 OrderedDict(zip(LFRicConstants.VALID_ARG_DATA_TYPES,
159 LFRicConstants.VALID_INTRINSIC_TYPES))
162 LFRicConstants.MAPPING_INTRINSIC_TYPES = \
163 OrderedDict(zip(LFRicConstants.VALID_INTRINSIC_TYPES,
164 LFRicConstants.VALID_ARG_DATA_TYPES))
171 LFRicConstants.HALO_ACCESS_LOOP_BOUNDS = [
"cell_halo",
"dof_halo",
174 LFRicConstants.VALID_LOOP_BOUNDS_NAMES = \
201 + LFRicConstants.HALO_ACCESS_LOOP_BOUNDS)
206 LFRicConstants.VALID_LOOP_TYPES = [
"dof",
"colours",
"colour",
"",
210 LFRicConstants.BUILTIN_ITERATION_SPACES = [
"dof"]
214 LFRicConstants.VALID_BUILTIN_ARG_TYPES = \
215 LFRicConstants.VALID_FIELD_NAMES + \
216 LFRicConstants.VALID_SCALAR_NAMES
220 LFRicConstants.VALID_BUILTIN_DATA_TYPES = [
"gh_real",
"gh_integer"]
224 LFRicConstants.USER_KERNEL_ITERATION_SPACES = [
"cell_column",
"domain"]
225 LFRicConstants.VALID_ITERATION_SPACES = \
226 LFRicConstants.USER_KERNEL_ITERATION_SPACES + \
227 LFRicConstants.BUILTIN_ITERATION_SPACES
231 LFRicConstants.DISCONTINUOUS_FUNCTION_SPACES = \
232 [
"w3",
"wtheta",
"w2v",
"w2vtrace",
"w2broken"]
242 LFRicConstants.ANY_W2_FUNCTION_SPACES = \
243 [
"w2",
"w2h",
"w2v",
"w2broken"]
245 LFRicConstants.CONTINUOUS_FUNCTION_SPACES = \
246 [
"w0",
"w1",
"w2",
"w2trace",
"w2h",
"w2htrace",
"any_w2"]
249 LFRicConstants.READ_ONLY_FUNCTION_SPACES = [
"wchi"]
252 LFRicConstants.VALID_FUNCTION_SPACES = \
253 LFRicConstants.DISCONTINUOUS_FUNCTION_SPACES + \
254 LFRicConstants.CONTINUOUS_FUNCTION_SPACES + \
255 LFRicConstants.READ_ONLY_FUNCTION_SPACES
260 LFRicConstants.VALID_ANY_SPACE_NAMES = [
261 f
"any_space_{x+1}" for x
in
262 range(api_config.num_any_space)]
267 LFRicConstants.VALID_ANY_DISCONTINUOUS_SPACE_NAMES = [
268 f
"any_discontinuous_space_{x+1}" for x
in
269 range(api_config.num_any_discontinuous_space)]
272 LFRicConstants.VALID_DISCONTINUOUS_NAMES = \
273 LFRicConstants.DISCONTINUOUS_FUNCTION_SPACES +\
274 LFRicConstants.VALID_ANY_DISCONTINUOUS_SPACE_NAMES
277 LFRicConstants.VALID_FUNCTION_SPACE_NAMES = \
278 LFRicConstants.VALID_FUNCTION_SPACES + \
279 LFRicConstants.VALID_ANY_SPACE_NAMES + \
280 LFRicConstants.VALID_ANY_DISCONTINUOUS_SPACE_NAMES
284 LFRicConstants.SCALAR_BASIS_SPACE_NAMES = \
285 [
"w0",
"w2trace",
"w2htrace",
"w2vtrace",
"w3",
"wtheta",
"wchi"]
287 LFRicConstants.VECTOR_BASIS_SPACE_NAMES = [
"w1",
"w2",
"w2h",
"w2v",
288 "w2broken",
"any_w2"]
290 LFRicConstants.SCALAR_DIFF_BASIS_SPACE_NAMES = [
"w2",
"w2h",
"w2v",
291 "w2broken",
"any_w2"]
293 LFRicConstants.VECTOR_DIFF_BASIS_SPACE_NAMES = \
294 [
"w0",
"w1",
"w2trace",
"w2htrace",
"w2vtrace",
"w3",
"wtheta",
298 LFRicConstants.VALID_EVALUATOR_NAMES = [
"gh_basis",
"gh_diff_basis"]
301 LFRicConstants.VALID_METAFUNC_NAMES = \
302 LFRicConstants.VALID_EVALUATOR_NAMES
305 LFRicConstants.VALID_REF_ELEMENT_NAMES = [
306 "normals_to_horizontal_faces",
"normals_to_vertical_faces",
307 "normals_to_faces",
"outward_normals_to_horizontal_faces",
308 "outward_normals_to_vertical_faces",
"outward_normals_to_faces"]
311 LFRicConstants.VALID_MESH_NAMES = [
"adjacent_face"]
314 LFRicConstants.SCALAR_PRECISION_MAP = \
315 OrderedDict(zip(LFRicConstants.VALID_INTRINSIC_TYPES,
316 [
"r_def",
"i_def",
"l_def"]))
324 LFRicConstants.DATA_TYPE_MAP = {
327 "reduction": {
"module":
"scalar_mod",
328 "type":
"scalar_type",
333 "field": {
"module":
"field_mod",
334 "type":
"field_type",
335 "proxy_type":
"field_proxy_type",
339 "r_solver_field": {
"module":
"r_solver_field_mod",
340 "type":
"r_solver_field_type",
341 "proxy_type":
"r_solver_field_proxy_type",
345 "r_tran_field": {
"module":
"r_tran_field_mod",
346 "type":
"r_tran_field_type",
347 "proxy_type":
"r_tran_field_proxy_type",
351 "r_bl_field": {
"module":
"r_bl_field_mod",
352 "type":
"r_bl_field_type",
353 "proxy_type":
"r_bl_field_proxy_type",
357 "r_phys_field": {
"module":
"r_phys_field_mod",
358 "type":
"r_phys_field_type",
359 "proxy_type":
"r_phys_field_proxy_type",
363 "integer_field": {
"module":
"integer_field_mod",
364 "type":
"integer_field_type",
365 "proxy_type":
"integer_field_proxy_type",
366 "intrinsic":
"integer",
369 "operator": {
"module":
"operator_mod",
370 "type":
"operator_type",
371 "proxy_type":
"operator_proxy_type",
375 "r_solver_operator": {
376 "module":
"r_solver_operator_mod",
377 "type":
"r_solver_operator_type",
378 "proxy_type":
"r_solver_operator_proxy_type",
383 "module":
"r_tran_operator_mod",
384 "type":
"r_tran_operator_type",
385 "proxy_type":
"r_tran_operator_proxy_type",
389 "columnwise_operator": {
390 "module":
"columnwise_operator_mod",
391 "type":
"columnwise_operator_type",
392 "proxy_type":
"columnwise_operator_proxy_type",
398 LFRicConstants.FIELD_VECTOR_TO_FIELD_MAP = {
399 "field_vector_type":
"field_type",
400 "r_solver_field_vector_type":
"r_solver_field_type",
401 "r_tran_field_vector_type":
"r_tran_field_type",
402 "r_bl_field_vector_type":
"r_bl_field_type",
403 "r_phys_field_vector_type":
"r_phys_field_type"}
407 LFRicConstants.STENCIL_TYPE_MAP = {
408 "stencil_dofmap": {
"module":
"stencil_dofmap_mod",
409 "type":
"stencil_dofmap_type"},
410 "stencil_2D_dofmap": {
"module":
"stencil_2D_dofmap_mod",
411 "type":
"stencil_2D_dofmap_type"},
412 "direction": {
"module":
"flux_direction_mod"}}
416 LFRicConstants.QUADRATURE_TYPE_MAP = {
417 "gh_quadrature_xyoz": {
"module":
"quadrature_xyoz_mod",
418 "type":
"quadrature_xyoz_type",
419 "proxy_type":
"quadrature_xyoz_proxy_type",
422 "gh_quadrature_face": {
"module":
"quadrature_face_mod",
423 "type":
"quadrature_face_type",
424 "proxy_type":
"quadrature_face_proxy_type",
427 "gh_quadrature_edge": {
"module":
"quadrature_edge_mod",
428 "type":
"quadrature_edge_type",
429 "proxy_type":
"quadrature_edge_proxy_type",
435 LFRicConstants.MESH_TYPE_MAP = {
436 "mesh": {
"module":
"mesh_mod",
437 "type":
"mesh_type"},
438 "mesh_map": {
"module":
"mesh_map_mod",
439 "type":
"mesh_map_type"}}
443 LFRicConstants.REFELEMENT_TYPE_MAP = {
444 "refelement": {
"module":
"reference_element_mod",
445 "type":
"reference_element_type"}}
449 LFRicConstants.FUNCTION_SPACE_TYPE_MAP = {
451 "function_space": {
"module":
"function_space_mod",
452 "type":
"function_space_type"},
454 "fs_continuity": {
"module":
"fs_continuity_mod"}}
458 LFRicConstants.UTILITIES_MOD_MAP = {
460 "constants": {
"module":
"constants_mod"},
462 "logging": {
"module":
"log_mod"}}
467 Maps from a valid kernel metadata function-space name to one
468 that exists within the LFRic infrastructure. This is necessary
469 because meta-data can contain 'generic' names such as 'any_w2' but,
470 when generating code, we need the name of a specific function space
471 that is recognised by the LFRic infrastructure.
473 :param str name: the name of the function space in metadata.
475 :returns: the name of a specific function space.
478 :raises ValueError: if the supplied name is not a valid LFRic \
480 :raises InternalError: if an unrecognised wildcard function-space \
484 if space
not in LFRicConstants.VALID_FUNCTION_SPACE_NAMES:
486 f
"'{space}' is not a recognised LFRic function space (one of "
487 f
"{LFRicConstants.VALID_FUNCTION_SPACE_NAMES}).")
491 if not space.startswith(
"any_"):
493 if space ==
"any_w2":
495 if space.startswith(
"any_space_"):
496 return LFRicConstants.CONTINUOUS_FUNCTION_SPACES[0]
497 if space.startswith(
"any_discontinuous_space_"):
498 return LFRicConstants.DISCONTINUOUS_FUNCTION_SPACES[0]
500 raise InternalError(f
"Error mapping from meta-data function space "
501 f
"to actual space: cannot handle '{space}'")
504 '''This function returns the precision required for the various
507 :param str data_type: the name of the data type.
509 :returns: the precision as defined in domain.lfric.lfric_types
510 (one of R_SOLVER, R_TRAN, R_DEF).
511 :rtype: :py:class:`psyclone.psyir.symbols.DataSymbol`
513 :raises InternalError: if an unknown data_type is specified.
516 for module_info
in self.DATA_TYPE_MAP.values():
517 if module_info[
"type"] == data_type:
520 return LFRicTypes(module_info[
"kind"].upper())
522 valid = [module_info[
"type"]
523 for module_info
in self.DATA_TYPE_MAP.values()]
524 raise InternalError(f
"Unknown data type '{data_type}', expected one "
531 __all__ = [
'LFRicConstants']
def specific_function_space(name)
def precision_for_type(self, data_type)