@@ -387,6 +387,9 @@ def map_int_g(self, expr):
387387 target_discr = self .places .get_discretization (
388388 expr .target .geometry , expr .target .discr_stage )
389389
390+ actx = self .array_context
391+ assert abs (expr .qbx_forced_limit ) > 0
392+
390393 result = 0
391394 for kernel , density in zip (expr .source_kernels , expr .densities ):
392395 rec_density = self .rec (density )
@@ -397,18 +400,8 @@ def map_int_g(self, expr):
397400 if not self .is_kind_matrix (rec_density ):
398401 raise NotImplementedError ("layer potentials on non-variables" )
399402
400- actx = self .array_context
401- kernel_args = _get_layer_potential_args (
402- actx , self .places , expr , context = self .context )
403- local_expn = lpot_source .get_expansion_for_qbx_direct_eval (
404- kernel .get_base_kernel (), (expr .target_kernel ,))
405-
406- from sumpy .qbx import LayerPotentialMatrixGenerator
407- mat_gen = LayerPotentialMatrixGenerator (actx .context ,
408- expansion = local_expn , source_kernels = (kernel ,),
409- target_kernels = (expr .target_kernel ,))
403+ # {{{ geometry
410404
411- assert abs (expr .qbx_forced_limit ) > 0
412405 from pytential import bind , sym
413406 radii = bind (self .places , sym .expansion_radii (
414407 source_discr .ambient_dim ,
@@ -418,6 +411,25 @@ def map_int_g(self, expr):
418411 expr .qbx_forced_limit ,
419412 dofdesc = expr .target ))(actx )
420413
414+ # }}}
415+
416+ # {{{ expansion
417+
418+ local_expn = lpot_source .get_expansion_for_qbx_direct_eval (
419+ kernel .get_base_kernel (), (expr .target_kernel ,))
420+
421+ from sumpy .qbx import LayerPotentialMatrixGenerator
422+ mat_gen = LayerPotentialMatrixGenerator (actx .context ,
423+ expansion = local_expn , source_kernels = (kernel ,),
424+ target_kernels = (expr .target_kernel ,))
425+
426+ # }}}
427+
428+ # {{{ evaluate
429+
430+ kernel_args = _get_layer_potential_args (
431+ actx , self .places , expr , context = self .context )
432+
421433 _ , (mat ,) = mat_gen (actx .queue ,
422434 targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
423435 sources = flatten (source_discr .nodes (), actx , leaf_class = DOFArray ),
@@ -432,6 +444,8 @@ def map_int_g(self, expr):
432444 dofdesc = expr .source ))(actx )
433445 mat [:, :] *= actx .to_numpy (flatten (waa , actx ))
434446
447+ # }}}
448+
435449 result += mat @ rec_density
436450
437451 return result
@@ -458,6 +472,9 @@ def map_int_g(self, expr):
458472 target_discr = self .places .get_discretization (
459473 expr .target .geometry , expr .target .discr_stage )
460474
475+ actx = self .array_context
476+ target_base_kernel = expr .target_kernel .get_base_kernel ()
477+
461478 result = 0
462479 for density , kernel in zip (expr .densities , expr .source_kernels ):
463480 rec_density = self .rec (density )
@@ -468,41 +485,53 @@ def map_int_g(self, expr):
468485 if not self .is_kind_matrix (rec_density ):
469486 raise NotImplementedError ("layer potentials on non-variables" )
470487
471- # NOTE: copied from pytential.symbolic.primitives.IntG
488+ # {{{ generator
489+
472490 base_kernel = kernel .get_base_kernel ()
491+
492+ from sumpy .p2p import P2PMatrixGenerator
493+ mat_gen = P2PMatrixGenerator (actx .context ,
494+ source_kernels = (base_kernel ,),
495+ target_kernels = (target_base_kernel ,),
496+ exclude_self = self .exclude_self )
497+
498+ # }}}
499+
500+ # {{{ evaluation
501+
502+ # {{{ kernel args
503+
504+ # NOTE: copied from pytential.symbolic.primitives.IntG
473505 kernel_args = base_kernel .get_args () + base_kernel .get_source_args ()
474506 kernel_args = {arg .loopy_arg .name for arg in kernel_args }
475507
476- actx = self .array_context
477508 kernel_args = _get_layer_potential_args (
478509 actx , self .places , expr , context = self .context ,
479510 include_args = kernel_args )
511+
480512 if self .exclude_self :
481513 kernel_args ["target_to_source" ] = actx .from_numpy (
482514 np .arange (0 , target_discr .ndofs , dtype = np .int64 )
483515 )
484516
485- from sumpy .p2p import P2PMatrixGenerator
486- mat_gen = P2PMatrixGenerator (actx .context ,
487- source_kernels = (base_kernel ,),
488- target_kernels = (expr .target_kernel .get_base_kernel (),),
489- exclude_self = self .exclude_self )
517+ # }}}
490518
491519 _ , (mat ,) = mat_gen (actx .queue ,
492520 targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
493521 sources = flatten (source_discr .nodes (), actx , leaf_class = DOFArray ),
494522 ** kernel_args )
495523 mat = actx .to_numpy (mat )
496524
497- from meshmode .discretization import Discretization
498- if self .weighted and isinstance (source_discr , Discretization ):
525+ if self .weighted :
499526 from pytential import bind , sym
500527 waa = bind (self .places , sym .weights_and_area_elements (
501528 source_discr .ambient_dim ,
502529 dofdesc = expr .source ))(actx )
503530
504531 mat [:, :] *= actx .to_numpy (flatten (waa , actx ))
505532
533+ # }}}
534+
506535 result += mat @ rec_density
507536
508537 return result
@@ -514,7 +543,8 @@ def map_int_g(self, expr):
514543
515544class QBXClusterMatrixBuilder (ClusterMatrixBuilderBase ):
516545 def __init__ (self , queue , dep_expr , other_dep_exprs , dep_source , dep_discr ,
517- places , tgt_src_index , context , _weighted = True , ** kwargs ):
546+ places , tgt_src_index , context ,
547+ exclude_self = False , _weighted = True ):
518548 super ().__init__ (queue ,
519549 dep_expr , other_dep_exprs , dep_source , dep_discr ,
520550 places , tgt_src_index , context )
@@ -531,52 +561,49 @@ def map_int_g(self, expr):
531561 if self .weighted and source_discr is not target_discr :
532562 raise NotImplementedError
533563
564+ actx = self .array_context
565+
534566 result = 0
567+ assert abs (expr .qbx_forced_limit ) > 0
568+
535569 for kernel , density in zip (expr .source_kernels , expr .densities ):
536570 rec_density = self ._inner_mapper .rec (density )
537571 if is_zero (rec_density ):
538572 continue
539573
540574 if not np .isscalar (rec_density ):
541- raise NotImplementedError
575+ raise NotImplementedError ( "layer potentials on non-variables" )
542576
543- actx = self .array_context
544- local_expn = lpot_source .get_expansion_for_qbx_direct_eval (
545- kernel .get_base_kernel (), (expr .target_kernel ,))
577+ # {{{ geometry
546578
547579 from pytential .linalg import make_index_cluster_cartesian_product
548580 tgtindices , srcindices = make_index_cluster_cartesian_product (
549581 actx , self .tgt_src_index )
550582
551- from meshmode .discretization import Discretization
552- if isinstance (target_discr , Discretization ):
553- assert abs (expr .qbx_forced_limit ) > 0
583+ from pytential import bind , sym
584+ radii = bind (self .places , sym .expansion_radii (
585+ source_discr .ambient_dim ,
586+ dofdesc = expr .target ))(actx )
587+ centers = bind (self .places , sym .expansion_centers (
588+ source_discr .ambient_dim ,
589+ expr .qbx_forced_limit ,
590+ dofdesc = expr .target ))(actx )
554591
555- from pytential import bind , sym
556- radii = bind (self .places , sym .expansion_radii (
557- source_discr .ambient_dim ,
558- dofdesc = expr .target ))(actx )
559- centers = bind (self .places , sym .expansion_centers (
560- source_discr .ambient_dim ,
561- expr .qbx_forced_limit ,
562- dofdesc = expr .target ))(actx )
592+ # }}}
563593
564- radii = flatten (radii , actx )
565- centers = flatten (centers , actx , leaf_class = DOFArray )
566- else :
567- raise TypeError ("unsupported target type: "
568- f"'{ type (target_discr ).__name__ } '" )
594+ # {{{ generator
569595
570- if not isinstance (source_discr , Discretization ):
571- expr = expr .copy (kernel_arguments = {
572- k : (sym .var (k ) if k in self .context else v )
573- for k , v in expr .kernel_arguments .items ()
574- })
596+ local_expn = lpot_source .get_expansion_for_qbx_direct_eval (
597+ kernel .get_base_kernel (), (expr .target_kernel ,))
575598
576599 from sumpy .qbx import LayerPotentialMatrixSubsetGenerator
577600 mat_gen = LayerPotentialMatrixSubsetGenerator (actx .context , local_expn ,
578601 source_kernels = (kernel ,), target_kernels = (expr .target_kernel ,))
579602
603+ # }}}
604+
605+ # {{{ evaluate
606+
580607 kernel_args = _get_layer_potential_args (
581608 actx , self .places , expr , context = self .context )
582609
@@ -598,6 +625,8 @@ def map_int_g(self, expr):
598625 actx )
599626 mat *= waa [srcindices ]
600627
628+ # }}}
629+
601630 result += actx .to_numpy (mat ) * rec_density
602631
603632 return result
@@ -606,7 +635,7 @@ def map_int_g(self, expr):
606635class P2PClusterMatrixBuilder (ClusterMatrixBuilderBase ):
607636 def __init__ (self , queue , dep_expr , other_dep_exprs , dep_source , dep_discr ,
608637 places , tgt_src_index , context ,
609- exclude_self = False , _weighted = False , ** kwargs ):
638+ exclude_self = False , _weighted = False ):
610639 super ().__init__ (queue ,
611640 dep_expr , other_dep_exprs , dep_source , dep_discr ,
612641 places , tgt_src_index , context )
@@ -620,6 +649,9 @@ def map_int_g(self, expr):
620649 target_discr = self .places .get_discretization (
621650 expr .target .geometry , expr .target .discr_stage )
622651
652+ actx = self .array_context
653+ target_base_kernel = expr .target_kernel .get_base_kernel ()
654+
623655 result = 0
624656 for kernel , density in zip (expr .source_kernels , expr .densities ):
625657 rec_density = self ._inner_mapper .rec (density )
@@ -629,29 +661,44 @@ def map_int_g(self, expr):
629661 if not np .isscalar (rec_density ):
630662 raise NotImplementedError
631663
632- # NOTE: copied from pytential.symbolic.primitives.IntG
664+ # {{{ geometry
665+
666+ from pytential .linalg import make_index_cluster_cartesian_product
667+ tgtindices , srcindices = make_index_cluster_cartesian_product (
668+ actx , self .tgt_src_index )
669+
670+ # }}}
671+
672+ # {{{ generator
673+
633674 base_kernel = kernel .get_base_kernel ()
675+
676+ from sumpy .p2p import P2PMatrixSubsetGenerator
677+ mat_gen = P2PMatrixSubsetGenerator (actx .context ,
678+ source_kernels = (base_kernel ,),
679+ target_kernels = (target_base_kernel ,),
680+ exclude_self = self .exclude_self )
681+
682+ # }}}
683+
684+ # {{{ evaluation
685+
686+ # {{{ kernel args
687+
688+ # NOTE: copied from pytential.symbolic.primitives.IntG
634689 kernel_args = base_kernel .get_args () + base_kernel .get_source_args ()
635690 kernel_args = {arg .loopy_arg .name for arg in kernel_args }
636691
637- actx = self .array_context
638692 kernel_args = _get_layer_potential_args (
639693 actx , self .places , expr , context = self .context ,
640694 include_args = kernel_args )
695+
641696 if self .exclude_self :
642697 kernel_args ["target_to_source" ] = actx .from_numpy (
643698 np .arange (0 , target_discr .ndofs , dtype = np .int64 )
644699 )
645700
646- from pytential .linalg import make_index_cluster_cartesian_product
647- tgtindices , srcindices = make_index_cluster_cartesian_product (
648- actx , self .tgt_src_index )
649-
650- from sumpy .p2p import P2PMatrixSubsetGenerator
651- mat_gen = P2PMatrixSubsetGenerator (actx .context ,
652- source_kernels = (base_kernel ,),
653- target_kernels = (expr .target_kernel .get_base_kernel (),),
654- exclude_self = self .exclude_self )
701+ # }}}
655702
656703 _ , (mat ,) = mat_gen (actx .queue ,
657704 targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
0 commit comments