@@ -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
@@ -801,19 +833,38 @@ def _get_qbx_discretization(self, geometry, discr_stage):
801833 # }}}
802834
803835 def get_connection (self , from_dd , to_dd ):
836+ """Construct a connection from *from_dd* to *to_dd* geometries.
837+
838+ :param from_dd: a :class:`~pytential.symbolic.primitives.DOFDescriptor`
839+ or a value that can be converted to one using
840+ :func:`~pytential.symbolic.primitives.as_dofdesc`.
841+ :param to_dd: as *from_dd*.
842+
843+ :returns: an object compatible with the
844+ :class:`~meshmode.discretization.connection.DiscretizationConnection`
845+ interface.
846+ """
847+
804848 from pytential .symbolic .dof_connection import connection_from_dds
805849 return connection_from_dds (self , from_dd , to_dd )
806850
807851 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.
852+ """Get the geometry or discretization in the collection.
853+
854+ If a specific QBX stage discretization is requested, refinement is
855+ performed on demand and cached for subsequent calls.
856+
857+ :param geometry: the identifier of the geometry in the collection.
858+ :param discr_stage: if the geometry is a
859+ :class:`~pytential.source.LayerPotentialSourceBase`, this denotes
860+ the QBX stage of the returned discretization. Can be one of
861+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_STAGE1` (default),
862+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_STAGE2` or
863+ :class:`~pytential.symbolic.primitives.QBX_SOURCE_QUAD_STAGE2`.
864+
865+ :returns: a geometry object in the collection or a
866+ :class:`~meshmode.discretization.Discretization` corresponding to
867+ *discr_stage*.
817868 """
818869 if discr_stage is None :
819870 discr_stage = sym .QBX_SOURCE_STAGE1
@@ -830,13 +881,19 @@ def get_discretization(self, geometry, discr_stage=None):
830881 return discr
831882
832883 def get_geometry (self , geometry ):
884+ """
885+ :param geometry: the identifier of the geometry in the collection.
886+ """
887+
833888 try :
834889 return self .places [geometry ]
835890 except KeyError :
836891 raise KeyError ("geometry not in the collection: '{}'" .format (
837892 geometry ))
838893
839894 def copy (self , places = None , auto_where = None ):
895+ """Get a shallow copy of the geometry collection."""
896+
840897 places = self .places if places is None else places
841898 return type (self )(
842899 places = places .copy (),
@@ -845,7 +902,7 @@ def copy(self, places=None, auto_where=None):
845902 def merge (self , places ):
846903 """Merges two geometry collections and returns the new collection.
847904
848- :arg places: A :class:`dict` or :class:`GeometryCollection` to
905+ :param places: a :class:`dict` or :class:`GeometryCollection` to
849906 merge with the current collection. If it is empty, a copy of the
850907 current collection is returned.
851908 """
0 commit comments