@@ -634,39 +634,61 @@ class _GeometryCollectionConnectionCacheKey:
634634class GeometryCollection :
635635 """A mapping from symbolic identifiers ("place IDs", typically strings)
636636 to 'geometries', where a geometry can be a
637- :class:`pytential.source.PotentialSource`
638- or a :class:`pytential.target.TargetBase`.
637+ :class:`~pytential.source.PotentialSource`, a
638+ :class:`~pytential.target.TargetBase` or a
639+ :class:`~meshmode.discretization.Discretization`.
640+
639641 This class is meant to hold a specific combination of sources and targets
640642 serve to host caches of information derived from them, e.g. FMM trees
641643 of subsets of them, as well as related common subexpressions such as
642644 metric terms.
643645
646+ Refinement of :class:`pytential.qbx.QBXLayerPotentialSource` entries is
647+ performed on demand, i.e. on calls to :meth:`get_discretization` with
648+ a specific *discr_stage*. To perform refinement explicitly, call
649+ :func:`pytential.qbx.refinement.refine_geometry_collection`,
650+ which allows more customization of the refinement process through
651+ parameters.
652+
653+ .. automethod:: __init__
654+
655+ .. attribute:: auto_source
656+
657+ Default :class:`~pytential.symbolic.primitives.DOFDescriptor` for the
658+ source geometry.
659+
660+ .. attribute:: auto_target
661+
662+ Default :class:`~pytential.symbolic.primitives.DOFDescriptor` for the
663+ target geometry.
664+
644665 .. automethod:: get_geometry
645- .. automethod:: get_connection
646666 .. automethod:: get_discretization
667+ .. automethod:: get_connection
647668
648669 .. automethod:: copy
649670 .. automethod:: merge
650671
651- Refinement of :class:`pytential.qbx.QBXLayerPotentialSource` entries is
652- performed on demand, or it may be performed by explcitly calling
653- :func:`pytential.qbx.refinement.refine_geometry_collection`,
654- which allows more customization of the refinement process through
655- parameters.
656672 """
657673
658674 def __init__ (self , places , auto_where = None ):
659- """
675+ r """
660676 :arg places: a scalar, tuple of or mapping of symbolic names to
661677 geometry objects. Supported objects are
662678 :class:`~pytential.source.PotentialSource`,
663679 :class:`~pytential.target.TargetBase` and
664680 :class:`~meshmode.discretization.Discretization`. If this is
665681 a mapping, the keys that are strings must be valid Python identifiers.
666- :arg auto_where: location identifier for each geometry object, used
667- to denote specific discretizations, e.g. in the case where
668- *places* is a :class:`~pytential.source.LayerPotentialSourceBase`.
669- By default, we assume
682+ The tuple should contain only two entries, denoting the source and
683+ target geometries for layer potential evaluation.
684+
685+ :arg auto_where: a single or a tuple of two
686+ :class:`~pytential.symbolic.primitives.DOFDescriptor`\ s, or values
687+ that can be converted to one using
688+ :func:`~pytential.symbolic.primitives.as_dofdesc`. The two
689+ descriptors are used to define the default source and target
690+ geometries for layer potential evaluations.
691+ By default, they are set to
670692 :class:`~pytential.symbolic.primitives.DEFAULT_SOURCE` and
671693 :class:`~pytential.symbolic.primitives.DEFAULT_TARGET` for
672694 sources and targets, respectively.
@@ -705,6 +727,15 @@ def __init__(self, places, auto_where=None):
705727
706728 # {{{ validate
707729
730+ # check auto_where
731+ if auto_source .geometry not in self .places :
732+ raise ValueError ("'auto_where' source geometry is not in the "
733+ f"collection: '{ auto_source .geometry } '" )
734+
735+ if auto_target .geometry not in self .places :
736+ raise ValueError ("'auto_where' target geometry is not in the "
737+ f"collection: '{ auto_target .geometry } '" )
738+
708739 # check allowed identifiers
709740 for name in self .places :
710741 if not isinstance (name , str ):
@@ -715,8 +746,9 @@ def __init__(self, places, auto_where=None):
715746 # check allowed types
716747 for p in self .places .values ():
717748 if not isinstance (p , (PotentialSource , TargetBase , Discretization )):
718- raise TypeError ("Values in 'places' must be discretization, targets "
719- "or layer potential sources." )
749+ raise TypeError (
750+ "Values in 'places' must be discretization, targets "
751+ f"or layer potential sources, got '{ type (p ).__name__ } '" )
720752
721753 # check ambient_dim
722754 from pytools import is_single_valued
@@ -746,8 +778,9 @@ def _get_discr_from_cache(self, geometry, discr_stage):
746778 key = (geometry , discr_stage )
747779
748780 if key not in cache :
749- raise KeyError ("cached discretization does not exist on '{}'"
750- "for stage '{}'" .format (geometry , discr_stage ))
781+ raise KeyError (
782+ "cached discretization does not exist on '{geometry}'"
783+ "for stage '{discr_stage}'" )
751784
752785 return cache [key ]
753786
@@ -756,7 +789,8 @@ def _add_discr_to_cache(self, discr, geometry, discr_stage):
756789 key = (geometry , discr_stage )
757790
758791 if key in cache :
759- raise RuntimeError ("trying to overwrite the cache" )
792+ raise RuntimeError ("trying to overwrite the discretization cache of "
793+ f"'{ geometry } ' for stage '{ discr_stage } '" )
760794
761795 cache [key ] = discr
762796
@@ -765,8 +799,8 @@ def _get_conn_from_cache(self, geometry, from_stage, to_stage):
765799 key = (geometry , from_stage , to_stage )
766800
767801 if key not in cache :
768- raise KeyError ("cached connection does not exist on '{}' "
769- " from '{ }' to '{}'". format ( geometry , from_stage , to_stage ) )
802+ raise KeyError ("cached connection does not exist on "
803+ f"' { geometry } ' from stage ' { from_stage } ' to '{ to_stage } '" )
770804
771805 return cache [key ]
772806
@@ -775,7 +809,8 @@ def _add_conn_to_cache(self, conn, geometry, from_stage, to_stage):
775809 key = (geometry , from_stage , to_stage )
776810
777811 if key in cache :
778- raise RuntimeError ("trying to overwrite the cache" )
812+ raise RuntimeError ("trying to overwrite the connection cache of "
813+ f"'{ geometry } ' from stage '{ from_stage } ' to '{ to_stage } '" )
779814
780815 cache [key ] = conn
781816
@@ -801,19 +836,38 @@ def _get_qbx_discretization(self, geometry, discr_stage):
801836 # }}}
802837
803838 def get_connection (self , from_dd , to_dd ):
839+ """Construct a connection from *from_dd* to *to_dd* geometries.
840+
841+ :param from_dd: a :class:`~pytential.symbolic.primitives.DOFDescriptor`
842+ or a value that can be converted to one using
843+ :func:`~pytential.symbolic.primitives.as_dofdesc`.
844+ :param to_dd: as *from_dd*.
845+
846+ :returns: an object compatible with the
847+ :class:`~meshmode.discretization.connection.DiscretizationConnection`
848+ interface.
849+ """
850+
804851 from pytential .symbolic .dof_connection import connection_from_dds
805852 return connection_from_dds (self , from_dd , to_dd )
806853
807854 def get_discretization (self , geometry , discr_stage = None ):
808- """
809- :arg dofdesc: a :class:`~pytential.symbolic.primitives.DOFDescriptor`
810- specifying the desired discretization.
811-
812- :return: a geometry object in the collection corresponding to the
813- key *dofdesc*. If it is a
814- :class:`~pytential.source.LayerPotentialSourceBase`, we look for
815- the corresponding :class:`~meshmode.discretization.Discretization`
816- in its attributes instead.
855+ """Get the geometry or discretization in the collection.
856+
857+ If a specific QBX stage discretization is requested, refinement is
858+ performed on demand and cached for subsequent calls.
859+
860+ :param geometry: the identifier of the geometry in the collection.
861+ :param discr_stage: if the geometry is a
862+ :class:`~pytential.source.LayerPotentialSourceBase`, this denotes
863+ the QBX stage of the returned discretization. Can be one of
864+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_STAGE1` (default),
865+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_STAGE2` or
866+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_QUAD_STAGE2`.
867+
868+ :returns: a geometry object in the collection or a
869+ :class:`~meshmode.discretization.Discretization` corresponding to
870+ *discr_stage*.
817871 """
818872 if discr_stage is None :
819873 discr_stage = sym .QBX_SOURCE_STAGE1
@@ -830,13 +884,18 @@ def get_discretization(self, geometry, discr_stage=None):
830884 return discr
831885
832886 def get_geometry (self , geometry ):
887+ """
888+ :param geometry: the identifier of the geometry in the collection.
889+ """
890+
833891 try :
834892 return self .places [geometry ]
835893 except KeyError :
836- raise KeyError ("geometry not in the collection: '{}'" .format (
837- geometry ))
894+ raise KeyError (f"geometry not in the collection: '{ geometry } '" )
838895
839896 def copy (self , places = None , auto_where = None ):
897+ """Get a shallow copy of the geometry collection."""
898+
840899 places = self .places if places is None else places
841900 return type (self )(
842901 places = places .copy (),
@@ -845,7 +904,7 @@ def copy(self, places=None, auto_where=None):
845904 def merge (self , places ):
846905 """Merges two geometry collections and returns the new collection.
847906
848- :arg places: A :class:`dict` or :class:`GeometryCollection` to
907+ :param places: a :class:`dict` or :class:`GeometryCollection` to
849908 merge with the current collection. If it is empty, a copy of the
850909 current collection is returned.
851910 """
@@ -859,10 +918,10 @@ def merge(self, places):
859918 return self .copy (places = new_places )
860919
861920 def __repr__ (self ):
862- return "{}({})" . format ( type (self ).__name__ , repr (self .places ))
921+ return "{type(self).__name__}({ repr(self.places)})"
863922
864923 def __str__ (self ):
865- return "{}({})" . format ( type (self ).__name__ , str ( self .places ))
924+ return "{type(self).__name__}({repr( self.places)})"
866925
867926# }}}
868927
0 commit comments