Reference Guide  2.5.0
psyclone.dynamo0p3.LFRicMeshProperties Class Reference
Inheritance diagram for psyclone.dynamo0p3.LFRicMeshProperties:
Collaboration diagram for psyclone.dynamo0p3.LFRicMeshProperties:

Public Member Functions

def __init__ (self, node)
 
def kern_args (self, stub=False, var_accesses=None, kern_call_arg_list=None)
 
def initialise (self, parent)
 
- Public Member Functions inherited from psyclone.domain.lfric.lfric_collection.LFRicCollection
def declarations (self, parent)
 

Detailed Description

Holds all information on the the mesh properties required by either an
invoke or a kernel stub. Note that the creation of a suitable mesh
object is handled in the `DynMeshes` class. This class merely deals with
extracting the necessary properties from that object and providing them to
kernels.

:param node: kernel or invoke for which to manage mesh properties.
:type node: :py:class:`psyclone.domain.lfric.LFRicKern` or \
            :py:class:`psyclone.dynamo0p3.LFRicInvoke`

Definition at line 496 of file dynamo0p3.py.

Member Function Documentation

◆ initialise()

def psyclone.dynamo0p3.LFRicMeshProperties.initialise (   self,
  parent 
)
Creates the f2pygen nodes for the initialisation of properties of
the mesh.

:param parent: node in the f2pygen tree to which to add statements.
:type parent: :py:class:`psyclone.f2pygen.SubroutineGen`

:raises InternalError: if an unsupported mesh property is encountered.

Reimplemented from psyclone.domain.lfric.lfric_collection.LFRicCollection.

Definition at line 749 of file dynamo0p3.py.

749  def initialise(self, parent):
750  '''
751  Creates the f2pygen nodes for the initialisation of properties of
752  the mesh.
753 
754  :param parent: node in the f2pygen tree to which to add statements.
755  :type parent: :py:class:`psyclone.f2pygen.SubroutineGen`
756 
757  :raises InternalError: if an unsupported mesh property is encountered.
758 
759  '''
760  const = LFRicConstants()
761  # Since colouring is applied via transformations, we have to check for
762  # it now, rather than when this class was first constructed.
763  need_colour_limits = False
764  need_colour_halo_limits = False
765  for call in self._calls:
766  if call.is_coloured() and not call.is_intergrid:
767  loop = call.parent.parent
768  # Record whether or not this coloured loop accesses the halo.
769  if loop.upper_bound_name in const.HALO_ACCESS_LOOP_BOUNDS:
770  need_colour_halo_limits = True
771  else:
772  need_colour_limits = True
773 
774  if not self._properties and not (need_colour_limits or
775  need_colour_halo_limits):
776  # If no mesh properties are required and there's no colouring
777  # (which requires a mesh object to lookup loop bounds) then we
778  # need do nothing.
779  return
780 
781  parent.add(CommentGen(parent, ""))
782  parent.add(CommentGen(parent, " Initialise mesh properties"))
783  parent.add(CommentGen(parent, ""))
784 
785  mesh = self._symbol_table.find_or_create_tag("mesh").name
786 
787  for prop in self._properties:
788  if prop == MeshProperty.ADJACENT_FACE:
789  adj_face = self._symbol_table.find_or_create_tag(
790  "adjacent_face").name
791  parent.add(AssignGen(parent, pointer=True, lhs=adj_face,
792  rhs=mesh+"%get_adjacent_face()"))
793 
794  elif prop == MeshProperty.NCELL_2D_NO_HALOS:
795  name = self._symbol_table.find_or_create_integer_symbol(
796  "ncell_2d_no_halos", tag="ncell_2d_no_halos").name
797  parent.add(AssignGen(parent, lhs=name,
798  rhs=mesh+"%get_last_edge_cell()"))
799 
800  elif prop == MeshProperty.NCELL_2D:
801  name = self._symbol_table.find_or_create_integer_symbol(
802  "ncell_2d", tag="ncell_2d").name
803  parent.add(AssignGen(parent, lhs=name,
804  rhs=mesh+"%get_ncells_2d()"))
805  else:
806  raise InternalError(
807  f"Found unsupported mesh property '{str(prop)}' when "
808  f"generating initialisation code. Only members of the "
809  f"MeshProperty Enum are permitted ({list(MeshProperty)})")
810 
811  if need_colour_halo_limits:
812  lhs = self._symbol_table.find_or_create_tag(
813  "last_halo_cell_all_colours").name
814  rhs = f"{mesh}%get_last_halo_cell_all_colours()"
815  parent.add(AssignGen(parent, lhs=lhs, rhs=rhs))
816  if need_colour_limits:
817  lhs = self._symbol_table.find_or_create_tag(
818  "last_edge_cell_all_colours").name
819  rhs = f"{mesh}%get_last_edge_cell_all_colours()"
820  parent.add(AssignGen(parent, lhs=lhs, rhs=rhs))
821 
822 

References psyclone.domain.lfric.lfric_collection.LFRicCollection._calls, psyclone.parse.algorithm.FileInfo._calls, psyclone.dynamo0p3.LFRicMeshProperties._properties, psyclone.dynamo0p3.DynReferenceElement._properties, psyclone.domain.lfric.lfric_collection.LFRicCollection._symbol_table, psyclone.dynamo0p3.DynMeshes._symbol_table, psyclone.dynamo0p3.HaloDepth._symbol_table, psyclone.psyGen.HaloExchange._symbol_table, psyclone.psyir.backend.sympy_writer.SymPyWriter._symbol_table, and psyclone.psyir.nodes.scoping_node.ScopingNode._symbol_table.

◆ kern_args()

def psyclone.dynamo0p3.LFRicMeshProperties.kern_args (   self,
  stub = False,
  var_accesses = None,
  kern_call_arg_list = None 
)
Provides the list of kernel arguments associated with the mesh
properties that the kernel requires. Optionally adds variable
access information if var_accesses is given.

:param bool stub: whether or not we are generating code for a \
                  kernel stub.
:param var_accesses: optional VariablesAccessInfo instance to store \
    the information about variable accesses.
:type var_accesses: \
    :py:class:`psyclone.core.VariablesAccessInfo`
:param kern_call_arg_list: an optional KernCallArgList instance \
    used to store PSyIR representation of the arguments.
:type kern_call_arg_list: \
    Optional[:py:class:`psyclone.domain.lfric.KernCallArgList`]

:returns: the kernel arguments associated with the mesh properties.
:rtype: list of str

:raises InternalError: if the class has been constructed for an \
                       invoke rather than a single kernel call.
:raises InternalError: if an unsupported mesh property is encountered.

Definition at line 544 of file dynamo0p3.py.

545  kern_call_arg_list=None):
546  # pylint: disable=too-many-locals, too-many-branches
547  '''
548  Provides the list of kernel arguments associated with the mesh
549  properties that the kernel requires. Optionally adds variable
550  access information if var_accesses is given.
551 
552  :param bool stub: whether or not we are generating code for a \
553  kernel stub.
554  :param var_accesses: optional VariablesAccessInfo instance to store \
555  the information about variable accesses.
556  :type var_accesses: \
557  :py:class:`psyclone.core.VariablesAccessInfo`
558  :param kern_call_arg_list: an optional KernCallArgList instance \
559  used to store PSyIR representation of the arguments.
560  :type kern_call_arg_list: \
561  Optional[:py:class:`psyclone.domain.lfric.KernCallArgList`]
562 
563  :returns: the kernel arguments associated with the mesh properties.
564  :rtype: list of str
565 
566  :raises InternalError: if the class has been constructed for an \
567  invoke rather than a single kernel call.
568  :raises InternalError: if an unsupported mesh property is encountered.
569 
570  '''
571  if not self._kernel:
572  raise InternalError(
573  "LFRicMeshProperties.kern_args() can only be called when "
574  "LFRicMeshProperties has been instantiated for a kernel "
575  "rather than an invoke.")
576 
577  arg_list = []
578 
579  for prop in self._properties:
580  if prop == MeshProperty.ADJACENT_FACE:
581  # Is this kernel already being passed the number of horizontal
582  # faces of the reference element?
583  has_nfaces = (
584  RefElementMetaData.Property.NORMALS_TO_HORIZONTAL_FACES
585  in self._kernel.reference_element.properties or
586  RefElementMetaData.Property.
587  OUTWARD_NORMALS_TO_HORIZONTAL_FACES
588  in self._kernel.reference_element.properties)
589  if not has_nfaces:
590  if kern_call_arg_list:
591  sym = kern_call_arg_list.\
592  append_integer_reference("nfaces_re_h")
593  name = sym.name
594  else:
595  name = self._symbol_table.\
596  find_or_create_integer_symbol(
597  "nfaces_re_h", tag="nfaces_re_h").name
598  arg_list.append(name)
599  if var_accesses is not None:
600  var_accesses.add_access(Signature(name),
601  AccessType.READ, self._kernel)
602 
603  adj_face = "adjacent_face"
604  if not stub and kern_call_arg_list:
605  # Use the functionality in kern_call_arg_list to properly
606  # declare the symbol and to create a PSyIR reference for it
607  _, cell_ref = \
608  kern_call_arg_list.cell_ref_name(var_accesses)
609  adj_face_sym = kern_call_arg_list. \
610  append_array_reference(adj_face,
611  [":", cell_ref],
612  ScalarType.Intrinsic.INTEGER)
613  # Update the name in case there was a clash
614  adj_face = adj_face_sym.name
615  if var_accesses:
616  var_accesses.add_access(Signature(adj_face),
617  AccessType.READ, self._kernel,
618  [":", cell_ref])
619 
620  if not stub:
621  adj_face = self._symbol_table.find_or_create_tag(
622  "adjacent_face").name
623  cell_name = "cell"
624  if self._kernel.is_coloured():
625  colour_name = "colour"
626  cmap_name = self._symbol_table.find_or_create_tag(
627  "cmap", root_name="cmap").name
628  adj_face += (f"(:,{cmap_name}({colour_name},"
629  f"{cell_name}))")
630  else:
631  adj_face += f"(:,{cell_name})"
632  arg_list.append(adj_face)
633 
634  if var_accesses and not kern_call_arg_list:
635  # TODO #1320 Replace [1]
636  # The [1] just indicates that this variable is accessed
637  # as a rank 1 array. #1320 will improve this.
638  var_accesses.add_access(Signature(adj_face),
639  AccessType.READ, self._kernel,
640  [1])
641  else:
642  raise InternalError(
643  f"kern_args: found unsupported mesh property '{prop}' "
644  f"when generating arguments for kernel "
645  f"'{self._kernel.name}'. Only members of the MeshProperty "
646  f"Enum are permitted ({list(MeshProperty)}).")
647 
648  return arg_list
649 

References psyclone.domain.lfric.lfric_collection.LFRicCollection._invoke, psyclone.nemo.NemoInvokeSchedule._invoke, psyclone.psyGen.InvokeSchedule._invoke, psyclone.domain.lfric.lfric_collection.LFRicCollection._kernel, psyclone.dynamo0p3.LFRicMeshProperties._properties, psyclone.dynamo0p3.DynReferenceElement._properties, psyclone.domain.lfric.lfric_collection.LFRicCollection._symbol_table, psyclone.dynamo0p3.DynMeshes._symbol_table, psyclone.dynamo0p3.HaloDepth._symbol_table, psyclone.psyGen.HaloExchange._symbol_table, psyclone.psyir.backend.sympy_writer.SymPyWriter._symbol_table, and psyclone.psyir.nodes.scoping_node.ScopingNode._symbol_table.


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