PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
mls_interface.cpp
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#include "interface.hpp"
7
8#include <ArborX_Point.hpp>
9#include <Kokkos_Core.hpp>
10#include <Kokkos_Profiling_ScopedRegion.hpp>
11#include <stdexcept>
12#include <string>
13
14#include "common/concepts.hpp"
15#include "common/transfer.hxx"
16// Extern-template declarations in interpolator.hxx suppress re-instantiation
17// in this TU. ETI is provided by MLS_interface_eti_*.cpp.
18#include "mls/interpolator.hxx"
19
20// ---------------------------------------------------------------------------
21// Internal helpers (anonymous namespace)
22// ---------------------------------------------------------------------------
23
24namespace {
25
26using namespace PACMAN;
27
28template <typename ExecSpace, PACMAN::int_t Dim>
36 pSourcePoints, pSourceValues, nullptr, nullptr,
37 nullptr, pTargetPoints);
38
39 PACMAN::MLS::MLSInterpolator<ExecSpace, Dim> interpolator(transfer);
40
42 result.targetValues.resize(nTargetPoints);
43
45 Kokkos::View<PACMAN::fp_t *,
46 Kokkos::DefaultHostExecutionSpace::memory_space,
47 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
48 result.targetValues.data(), nTargetPoints);
49 Kokkos::deep_copy(unmanaged_host_tv, transfer.targetValues);
50 return result;
51}
52
53template <PACMAN::int_t Dim>
55DispatchMLS(unsigned char execSpace,
59 return std::visit(
60 [&](auto execSpaceObj) {
64 },
66}
67
68} // anonymous namespace
69
70// ---------------------------------------------------------------------------
71// Public API implementation
72// ---------------------------------------------------------------------------
73
74namespace PACMAN {
75
79 fp_t *sourceValues, coordinates_t *targetPoints,
81 const std::string _region_name = "PACMAN::MLS_interpolate";
82 const Kokkos::Profiling::ScopedRegion region(_region_name);
83
84 if (sourcePoints == nullptr && nSourcePoints > 0)
85 throw std::invalid_argument("sourcePoints is null but nSourcePoints > 0");
86 if (targetPoints == nullptr && nTargetPoints > 0)
87 throw std::invalid_argument("targetPoints is null but nTargetPoints > 0");
88 if (sourceValues == nullptr && nSourcePoints > 0)
89 throw std::invalid_argument("sourceValues is null but nSourcePoints > 0");
90
91 switch (spaceDimension) {
92 case 1:
95 case 2:
98 case 3:
101 default:
102 throw std::runtime_error(
103 "The dimension of the points can only be: 1, 2 or 3.\n");
104 }
105}
106
107} // namespace PACMAN
double fp_t
Definition types.hpp:15
double coordinates_t
Definition types.hpp:16
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
MLSInterpolateResult MLS_interpolate(int_t spaceDimension, unsigned char execSpace, coordinates_t *sourcePoints, int_t nSourcePoints, fp_t *sourceValues, coordinates_t *targetPoints, int_t nTargetPoints)
C++ interface for Moving Least Squares (MLS) interpolation.
int32_t int_t
Definition types.hpp:18
Result of a Moving Least Squares interpolation call.