Reference Guide  2.5.0
psyclone.domain.lfric.lfric_constants.LFRicConstants Class Reference

Public Member Functions

def __init__ (self)
 
def precision_for_type (self, data_type)
 

Static Public Member Functions

def specific_function_space (name)
 

Static Public Attributes

bool HAS_BEEN_INITIALISED = False
 

Detailed Description

This class stores all LFRic constants. Note that some constants
depend on values in the config file, so this class can only be
used after the config file has been read.
It stores all values in class variables (to avoid re-evaluating them).

Definition at line 50 of file lfric_constants.py.

Member Function Documentation

◆ precision_for_type()

def psyclone.domain.lfric.lfric_constants.LFRicConstants.precision_for_type (   self,
  data_type 
)
This function returns the precision required for the various
LFRic types.

:param str data_type: the name of the data type.

:returns: the precision as defined in domain.lfric.lfric_types
    (one of R_SOLVER, R_TRAN, R_DEF).
:rtype: :py:class:`psyclone.psyir.symbols.DataSymbol`

:raises InternalError: if an unknown data_type is specified.

Definition at line 503 of file lfric_constants.py.

503  def precision_for_type(self, data_type):
504  '''This function returns the precision required for the various
505  LFRic types.
506 
507  :param str data_type: the name of the data type.
508 
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`
512 
513  :raises InternalError: if an unknown data_type is specified.
514 
515  '''
516  for module_info in self.DATA_TYPE_MAP.values():
517  if module_info["type"] == data_type:
518  # pylint: disable=import-outside-toplevel
519  from psyclone.domain.lfric.lfric_types import LFRicTypes
520  return LFRicTypes(module_info["kind"].upper())
521 
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 "
525  f"of {valid}.")
526 
527 
528 # =============================================================================
529 # Documentation utils: The list of module members that we wish AutoAPI to
530 # generate documentation for (see https://psyclone-ref.readthedocs.io).

◆ specific_function_space()

def psyclone.domain.lfric.lfric_constants.LFRicConstants.specific_function_space (   name)
static
Maps from a valid kernel metadata function-space name to one
that exists within the LFRic infrastructure. This is necessary
because meta-data can contain 'generic' names such as 'any_w2' but,
when generating code, we need the name of a specific function space
that is recognised by the LFRic infrastructure.

:param str name: the name of the function space in metadata.

:returns: the name of a specific function space.
:rtype: str

:raises ValueError: if the supplied name is not a valid LFRic \
                    function-space name.
:raises InternalError: if an unrecognised wildcard function-space \
                       name is supplied.

Definition at line 465 of file lfric_constants.py.

465  def specific_function_space(name):
466  '''
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.
472 
473  :param str name: the name of the function space in metadata.
474 
475  :returns: the name of a specific function space.
476  :rtype: str
477 
478  :raises ValueError: if the supplied name is not a valid LFRic \
479  function-space name.
480  :raises InternalError: if an unrecognised wildcard function-space \
481  name is supplied.
482  '''
483  space = name.lower()
484  if space not in LFRicConstants.VALID_FUNCTION_SPACE_NAMES:
485  raise ValueError(
486  f"'{space}' is not a recognised LFRic function space (one of "
487  f"{LFRicConstants.VALID_FUNCTION_SPACE_NAMES}).")
488 
489  # TODO #1709 - make this mapping configurable rather than
490  # hardwiring it here.
491  if not space.startswith("any_"):
492  return space
493  if space == "any_w2":
494  return "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]
499 
500  raise InternalError(f"Error mapping from meta-data function space "
501  f"to actual space: cannot handle '{space}'")
502 

The documentation for this class was generated from the following file: