@@ -515,7 +515,7 @@ function connectivity(msh::SubMesh, E::DataType)
515
515
end
516
516
517
517
"""
518
- near_interaction_list (X,Y::AbstractMesh; tol)
518
+ elements_to_near_targets (X,Y::AbstractMesh; tol)
519
519
520
520
For each element `el` of type `E` in `Y`, return the indices of the points in
521
521
`X` which are closer than `tol` to the `center` of `el`.
@@ -526,7 +526,7 @@ fifth element of type `E`.
526
526
527
527
If `tol` is a `Dict`, then `tol[E]` is the tolerance for elements of type `E`.
528
528
"""
529
- function near_interaction_list (
529
+ function elements_to_near_targets (
530
530
X:: AbstractVector{<:SVector{N}} ,
531
531
Y:: AbstractMesh{N} ;
532
532
tol,
@@ -538,17 +538,47 @@ function near_interaction_list(
538
538
for E in element_types (Y)
539
539
els = elements (Y, E)
540
540
tol_ = isa (tol, Number) ? tol : tol[E]
541
- idxs = _near_interaction_list (balltree, els, tol_)
541
+ idxs = _elements_to_near_targets (balltree, els, tol_)
542
542
dict[E] = idxs
543
543
end
544
544
return dict
545
545
end
546
546
547
- @noinline function _near_interaction_list (balltree, els, tol)
547
+ @noinline function _elements_to_near_targets (balltree, els, tol)
548
548
centers = map (center, els)
549
549
return inrange (balltree, centers, tol)
550
550
end
551
551
552
+ """
553
+ target_to_near_elements(X::AbstractVector{<:SVector{N}}, Y::AbstractMesh{N};
554
+ tol)
555
+
556
+ For each target `x` in `X`, return a vector of tuples `(E, i)` where `E` is the
557
+ type of the element in `Y` and `i` is the index of the element in `Y` such that
558
+ `x` is closer than `tol` to the center of the element.
559
+ """
560
+ function target_to_near_elements (
561
+ X:: AbstractVector{<:SVector{N}} ,
562
+ Y:: AbstractMesh{N} ;
563
+ tol,
564
+ ) where {N}
565
+ @assert isa (tol, Number) || isa (tol, Dict) " tol must be a number or a dictionary mapping element types to numbers"
566
+ dict = Dict {Int,Vector{Tuple{DataType,Int}}} ()
567
+ balltree = BallTree (X)
568
+ for E in element_types (Y)
569
+ els = elements (Y, E)
570
+ tol_ = isa (tol, Number) ? tol : tol[E]
571
+ idxs = _target_to_near_elements (balltree, els, tol_)
572
+ for (i, idx) in enumerate (idxs)
573
+ dict[i] = get! (dict, i, Vector {Tuple{DataType,Int}} ())
574
+ for j in idx
575
+ push! (dict[i], (E, j))
576
+ end
577
+ end
578
+ end
579
+ return dict
580
+ end
581
+
552
582
"""
553
583
topological_neighbors(msh::LagrangeMesh, k=1)
554
584
@@ -586,68 +616,3 @@ function topological_neighbors(msh::LagrangeMesh, k = 1)
586
616
# TODO : for k > 1, recursively compute the neighbors from the one-neighbors
587
617
return one_neighbors
588
618
end
589
-
590
- """
591
- element_to_near_targets(X,Y::AbstractMesh; tol)
592
-
593
- For each element `el` of type `E` in `Y`, return the indices of the points in
594
- `X` which are closer than `tol` to the `center` of `el`.
595
-
596
- This function returns a dictionary where e.g. `dict[E][5] --> Vector{Int}` gives
597
- the indices of points in `X` which are closer than `tol` to the center of the
598
- fifth element of type `E`.
599
-
600
- If `tol` is a `Dict`, then `tol[E]` is the tolerance for elements of type `E`.
601
- """
602
- function element_to_near_targets (
603
- X:: AbstractVector{<:SVector{N}} ,
604
- Y:: AbstractMesh{N} ;
605
- tol,
606
- ) where {N}
607
- @assert isa (tol, Number) || isa (tol, Dict) " tol must be a number or a dictionary mapping element types to numbers"
608
- # for each element type, build the list of targets close to a given element
609
- dict = Dict {DataType,Vector{Vector{Int}}} ()
610
- balltree = BallTree (X)
611
- for E in element_types (Y)
612
- els = elements (Y, E)
613
- tol_ = isa (tol, Number) ? tol : tol[E]
614
- idxs = _element_to_near_targets (balltree, els, tol_)
615
- dict[E] = idxs
616
- end
617
- return dict
618
- end
619
-
620
- @noinline function _element_to_near_targets (balltree, els, tol)
621
- centers = map (center, els)
622
- return inrange (balltree, centers, tol)
623
- end
624
-
625
- """
626
- target_to_near_elements(X::AbstractVector{<:SVector{N}}, Y::AbstractMesh{N};
627
- tol)
628
-
629
- For each target `x` in `X`, return a vector of tuples `(E, i)` where `E` is the
630
- type of the element in `Y` and `i` is the index of the element in `Y` such that
631
- `x` is closer than `tol` to the center of the element.
632
- """
633
- function target_to_near_elements (
634
- X:: AbstractVector{<:SVector{N}} ,
635
- Y:: AbstractMesh{N} ;
636
- tol,
637
- ) where {N}
638
- @assert isa (tol, Number) || isa (tol, Dict) " tol must be a number or a dictionary mapping element types to numbers"
639
- dict = Dict {Int,Vector{Tuple{DataType,Int}}} ()
640
- balltree = BallTree (X)
641
- for E in element_types (Y)
642
- els = elements (Y, E)
643
- tol_ = isa (tol, Number) ? tol : tol[E]
644
- idxs = _target_to_near_elements (balltree, els, tol_)
645
- for (i, idx) in enumerate (idxs)
646
- dict[i] = get! (dict, i, Vector {Tuple{DataType,Int}} ())
647
- for j in idx
648
- push! (dict[i], (E, j))
649
- end
650
- end
651
- end
652
- return dict
653
- end
0 commit comments