PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
FTInterpNearest.hpp
Go to the documentation of this file.
1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
6#pragma once
7
8#include "common/transfer.hxx"
11
12namespace PACMAN {
13namespace FiniteElements {
14
27template <typename ExecSpace, int_t Dim>
28void FTInterpNearest(Transfer<ExecSpace, Dim> &transfer) {
29 Kokkos::Profiling::pushRegion("FTInterpNearest");
30
31 using MemorySpace = typename ExecSpace::memory_space;
32 using Box = ::ArborX::Box<Dim, coordinates_t>;
33
34 ExecSpace execSpace{};
35
36 auto sourcePointsPtr = transfer.sourcePoints;
37 auto sourceValuesPtr = transfer.sourceValues;
38
39 auto targetPointsPtr = transfer.targetPoints;
40 auto targetValuesPtr = transfer.targetValues;
41 auto targetStatusPtr = transfer.targetStatus;
42 auto nbtargetPoints = targetPointsPtr.extent(0);
43
44 ::ArborX::BoundingVolumeHierarchy bvhPoints(
45 execSpace, ::ArborX::Experimental::attach_indices(sourcePointsPtr));
46 Kokkos::Profiling::pushRegion("Compute nearest points");
47 auto nearestPointValues = Kokkos::View<int_t *, MemorySpace>(
48 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
49 "nearestPointValues"),
50 0);
51 auto nearestPointOffsets = Kokkos::View<int_t *, MemorySpace>(
52 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
53 "nearestPointOffsets"),
54 0);
55 PointCloudNearest<MemorySpace, Dim> pcn{targetPointsPtr};
56 bvhPoints.query(execSpace, pcn, ExtractIndex{}, nearestPointValues,
57 nearestPointOffsets);
58 Kokkos::Profiling::popRegion();
59
60 Kokkos::Profiling::pushRegion("Compute target point FE intersection");
62 Kokkos::Profiling::popRegion();
63
64 // Assign nearest node source value for target points outside the mesh
65 Kokkos::Profiling::pushRegion("Get Nearest");
66 Kokkos::parallel_for(
67 "Get Nearest functor",
68 Kokkos::RangePolicy<ExecSpace>(execSpace, 0, nbtargetPoints),
69 KOKKOS_LAMBDA(const int_t &i) {
70 if (targetStatusPtr(i) != TransferStatus::INTER) {
71 auto nearest_idx = nearestPointValues(i);
72 for (index_t component = 0;
73 component < sourceValuesPtr.extent(1); ++component) {
74 targetValuesPtr(i, component) =
75 sourceValuesPtr(nearest_idx, component);
76 }
77 targetStatusPtr(i) = TransferStatus::NEAREST;
78 }
79 });
80 Kokkos::Profiling::popRegion();
81
82 Kokkos::Profiling::popRegion();
83 return;
84}
85} // namespace FiniteElements
86} // namespace PACMAN
ArborX predicate/callback helpers for PACMAN finite-elements kernels.
void FTInterpNearest(Transfer< ExecSpace, Dim > &transfer)
Interpolate target points from FE cells and fallback to nearest source-node value outside the source ...
void ComputeBoxTargetPointIntersection(Transfer< ExecSpace, Dim > &transfer)
Intersect target points with source-element bounding boxes, then evaluate FE interpolation for inters...
Definition FTUtils.hpp:33
uint32_t index_t
Definition types.hpp:20
int32_t int_t
Definition types.hpp:18
Generic callback extracting index from ArborX query values.
Predicate wrapper for nearest-neighbor queries over point clouds.