@@ -387,6 +387,9 @@ def map_int_g(self, expr):
387
387
target_discr = self .places .get_discretization (
388
388
expr .target .geometry , expr .target .discr_stage )
389
389
390
+ actx = self .array_context
391
+ assert abs (expr .qbx_forced_limit ) > 0
392
+
390
393
result = 0
391
394
for kernel , density in zip (expr .source_kernels , expr .densities ):
392
395
rec_density = self .rec (density )
@@ -397,18 +400,8 @@ def map_int_g(self, expr):
397
400
if not self .is_kind_matrix (rec_density ):
398
401
raise NotImplementedError ("layer potentials on non-variables" )
399
402
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
410
404
411
- assert abs (expr .qbx_forced_limit ) > 0
412
405
from pytential import bind , sym
413
406
radii = bind (self .places , sym .expansion_radii (
414
407
source_discr .ambient_dim ,
@@ -418,6 +411,25 @@ def map_int_g(self, expr):
418
411
expr .qbx_forced_limit ,
419
412
dofdesc = expr .target ))(actx )
420
413
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
+
421
433
_ , (mat ,) = mat_gen (actx .queue ,
422
434
targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
423
435
sources = flatten (source_discr .nodes (), actx , leaf_class = DOFArray ),
@@ -432,6 +444,8 @@ def map_int_g(self, expr):
432
444
dofdesc = expr .source ))(actx )
433
445
mat [:, :] *= actx .to_numpy (flatten (waa , actx ))
434
446
447
+ # }}}
448
+
435
449
result += mat @ rec_density
436
450
437
451
return result
@@ -458,6 +472,9 @@ def map_int_g(self, expr):
458
472
target_discr = self .places .get_discretization (
459
473
expr .target .geometry , expr .target .discr_stage )
460
474
475
+ actx = self .array_context
476
+ target_base_kernel = expr .target_kernel .get_base_kernel ()
477
+
461
478
result = 0
462
479
for density , kernel in zip (expr .densities , expr .source_kernels ):
463
480
rec_density = self .rec (density )
@@ -468,41 +485,53 @@ def map_int_g(self, expr):
468
485
if not self .is_kind_matrix (rec_density ):
469
486
raise NotImplementedError ("layer potentials on non-variables" )
470
487
471
- # NOTE: copied from pytential.symbolic.primitives.IntG
488
+ # {{{ generator
489
+
472
490
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
473
505
kernel_args = base_kernel .get_args () + base_kernel .get_source_args ()
474
506
kernel_args = {arg .loopy_arg .name for arg in kernel_args }
475
507
476
- actx = self .array_context
477
508
kernel_args = _get_layer_potential_args (
478
509
actx , self .places , expr , context = self .context ,
479
510
include_args = kernel_args )
511
+
480
512
if self .exclude_self :
481
513
kernel_args ["target_to_source" ] = actx .from_numpy (
482
514
np .arange (0 , target_discr .ndofs , dtype = np .int64 )
483
515
)
484
516
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
+ # }}}
490
518
491
519
_ , (mat ,) = mat_gen (actx .queue ,
492
520
targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
493
521
sources = flatten (source_discr .nodes (), actx , leaf_class = DOFArray ),
494
522
** kernel_args )
495
523
mat = actx .to_numpy (mat )
496
524
497
- from meshmode .discretization import Discretization
498
- if self .weighted and isinstance (source_discr , Discretization ):
525
+ if self .weighted :
499
526
from pytential import bind , sym
500
527
waa = bind (self .places , sym .weights_and_area_elements (
501
528
source_discr .ambient_dim ,
502
529
dofdesc = expr .source ))(actx )
503
530
504
531
mat [:, :] *= actx .to_numpy (flatten (waa , actx ))
505
532
533
+ # }}}
534
+
506
535
result += mat @ rec_density
507
536
508
537
return result
@@ -514,7 +543,8 @@ def map_int_g(self, expr):
514
543
515
544
class QBXClusterMatrixBuilder (ClusterMatrixBuilderBase ):
516
545
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 ):
518
548
super ().__init__ (queue ,
519
549
dep_expr , other_dep_exprs , dep_source , dep_discr ,
520
550
places , tgt_src_index , context )
@@ -531,52 +561,49 @@ def map_int_g(self, expr):
531
561
if self .weighted and source_discr is not target_discr :
532
562
raise NotImplementedError
533
563
564
+ actx = self .array_context
565
+
534
566
result = 0
567
+ assert abs (expr .qbx_forced_limit ) > 0
568
+
535
569
for kernel , density in zip (expr .source_kernels , expr .densities ):
536
570
rec_density = self ._inner_mapper .rec (density )
537
571
if is_zero (rec_density ):
538
572
continue
539
573
540
574
if not np .isscalar (rec_density ):
541
- raise NotImplementedError
575
+ raise NotImplementedError ( "layer potentials on non-variables" )
542
576
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
546
578
547
579
from pytential .linalg import make_index_cluster_cartesian_product
548
580
tgtindices , srcindices = make_index_cluster_cartesian_product (
549
581
actx , self .tgt_src_index )
550
582
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 )
554
591
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
+ # }}}
563
593
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
569
595
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 ,))
575
598
576
599
from sumpy .qbx import LayerPotentialMatrixSubsetGenerator
577
600
mat_gen = LayerPotentialMatrixSubsetGenerator (actx .context , local_expn ,
578
601
source_kernels = (kernel ,), target_kernels = (expr .target_kernel ,))
579
602
603
+ # }}}
604
+
605
+ # {{{ evaluate
606
+
580
607
kernel_args = _get_layer_potential_args (
581
608
actx , self .places , expr , context = self .context )
582
609
@@ -598,6 +625,8 @@ def map_int_g(self, expr):
598
625
actx )
599
626
mat *= waa [srcindices ]
600
627
628
+ # }}}
629
+
601
630
result += actx .to_numpy (mat ) * rec_density
602
631
603
632
return result
@@ -606,7 +635,7 @@ def map_int_g(self, expr):
606
635
class P2PClusterMatrixBuilder (ClusterMatrixBuilderBase ):
607
636
def __init__ (self , queue , dep_expr , other_dep_exprs , dep_source , dep_discr ,
608
637
places , tgt_src_index , context ,
609
- exclude_self = False , _weighted = False , ** kwargs ):
638
+ exclude_self = False , _weighted = False ):
610
639
super ().__init__ (queue ,
611
640
dep_expr , other_dep_exprs , dep_source , dep_discr ,
612
641
places , tgt_src_index , context )
@@ -620,6 +649,9 @@ def map_int_g(self, expr):
620
649
target_discr = self .places .get_discretization (
621
650
expr .target .geometry , expr .target .discr_stage )
622
651
652
+ actx = self .array_context
653
+ target_base_kernel = expr .target_kernel .get_base_kernel ()
654
+
623
655
result = 0
624
656
for kernel , density in zip (expr .source_kernels , expr .densities ):
625
657
rec_density = self ._inner_mapper .rec (density )
@@ -629,29 +661,44 @@ def map_int_g(self, expr):
629
661
if not np .isscalar (rec_density ):
630
662
raise NotImplementedError
631
663
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
+
633
674
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
634
689
kernel_args = base_kernel .get_args () + base_kernel .get_source_args ()
635
690
kernel_args = {arg .loopy_arg .name for arg in kernel_args }
636
691
637
- actx = self .array_context
638
692
kernel_args = _get_layer_potential_args (
639
693
actx , self .places , expr , context = self .context ,
640
694
include_args = kernel_args )
695
+
641
696
if self .exclude_self :
642
697
kernel_args ["target_to_source" ] = actx .from_numpy (
643
698
np .arange (0 , target_discr .ndofs , dtype = np .int64 )
644
699
)
645
700
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
+ # }}}
655
702
656
703
_ , (mat ,) = mat_gen (actx .queue ,
657
704
targets = flatten (target_discr .nodes (), actx , leaf_class = DOFArray ),
0 commit comments