PACMAN
0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Toggle main menu visibility
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
24
namespace
{
25
26
using namespace
PACMAN
;
27
28
template
<
typename
ExecSpace, PACMAN::
int
_t Dim>
29
void
30
RunMLSInterpolate(
PACMAN::coordinates_t
*pSourcePoints,
31
PACMAN::int_t
nSourcePoints,
PACMAN::fp_t
*pSourceValues,
32
PACMAN::coordinates_t
*pTargetPoints,
33
PACMAN::int_t
nTargetPoints,
34
PACMAN::int_t
nComponents,
35
PACMAN::fp_t
*pTargetValues) {
36
PACMAN::Transfer<ExecSpace, Dim> transfer(
PACMAN::TransferMethods::MLS
);
37
PACMAN::SetupTransferClass(transfer, nSourcePoints, 0, 0, nTargetPoints,
38
nComponents,
39
pSourcePoints, pSourceValues,
nullptr
,
nullptr
,
40
nullptr
, pTargetPoints);
41
42
PACMAN::MLS::MLSInterpolator<ExecSpace, Dim> interpolator(transfer);
43
44
PACMAN::CopyToRowMajorHost(transfer.targetValues, pTargetValues);
45
}
46
47
template
<PACMAN::
int
_t Dim>
48
requires
PACMAN::IsValidDim<Dim>
void
49
DispatchMLS(
unsigned
char
execSpace,
50
PACMAN::coordinates_t
*pSourcePoints,
PACMAN::int_t
nSourcePoints,
51
PACMAN::fp_t
*pSourceValues,
PACMAN::coordinates_t
*pTargetPoints,
52
PACMAN::int_t
nTargetPoints,
PACMAN::int_t
nComponents,
53
PACMAN::fp_t
*pTargetValues) {
54
std::visit(
55
[&](
auto
execSpaceObj) {
56
RunMLSInterpolate<decltype(execSpaceObj), Dim>(
57
pSourcePoints, nSourcePoints, pSourceValues, pTargetPoints,
58
nTargetPoints, nComponents, pTargetValues);
59
},
60
PACMAN::MakeExecSpace
(execSpace));
61
}
62
63
}
// anonymous namespace
64
65
// ---------------------------------------------------------------------------
66
// Public API implementation
67
// ---------------------------------------------------------------------------
68
69
namespace
PACMAN
{
70
71
void
72
MLS_interpolate
(
int_t
spaceDimension,
unsigned
char
execSpace,
73
coordinates_t
*sourcePoints,
int_t
nSourcePoints,
74
fp_t
*sourceValues,
coordinates_t
*targetPoints,
75
int_t
nTargetPoints,
fp_t
*targetValues,
int_t
nComponents) {
76
const
std::string _region_name =
"PACMAN::MLS_interpolate"
;
77
const
Kokkos::Profiling::ScopedRegion region(_region_name);
78
79
// LCOV_EXCL_START
80
if
(sourcePoints ==
nullptr
&& nSourcePoints > 0)
81
throw
std::invalid_argument(
"sourcePoints is null but nSourcePoints > 0"
);
82
if
(targetPoints ==
nullptr
&& nTargetPoints > 0)
83
throw
std::invalid_argument(
"targetPoints is null but nTargetPoints > 0"
);
84
if
(sourceValues ==
nullptr
&& nSourcePoints > 0)
85
throw
std::invalid_argument(
"sourceValues is null but nSourcePoints > 0"
);
86
if
(targetValues ==
nullptr
&& nTargetPoints > 0)
87
throw
std::invalid_argument(
"targetValues is null but nTargetPoints > 0"
);
88
if
(nComponents < 1)
89
throw
std::invalid_argument(
"nComponents must be greater than zero"
);
90
// LCOV_EXCL_STOP
91
92
switch
(spaceDimension) {
93
case
1:
94
return
DispatchMLS<1>(execSpace, sourcePoints, nSourcePoints, sourceValues,
95
targetPoints, nTargetPoints, nComponents, targetValues);
96
case
2:
97
return
DispatchMLS<2>(execSpace, sourcePoints, nSourcePoints, sourceValues,
98
targetPoints, nTargetPoints, nComponents, targetValues);
99
case
3:
100
return
DispatchMLS<3>(execSpace, sourcePoints, nSourcePoints, sourceValues,
101
targetPoints, nTargetPoints, nComponents, targetValues);
102
// LCOV_EXCL_START
103
default
:
104
throw
std::runtime_error(
105
"The dimension of the points can only be: 1, 2 or 3.\n"
);
106
// LCOV_EXCL_STOP
107
}
108
}
109
110
}
// namespace PACMAN
PACMAN::IsValidDim
Definition
concepts.hpp:44
concepts.hpp
interface.hpp
PACMAN
Definition
concepts.hpp:14
PACMAN::fp_t
double fp_t
Definition
types.hpp:15
PACMAN::coordinates_t
double coordinates_t
Definition
types.hpp:16
PACMAN::MakeExecSpace
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
Definition
execspaces.hpp:80
PACMAN::TransferMethods::MLS
@ MLS
Definition
types.hpp:36
PACMAN::int_t
int32_t int_t
Definition
types.hpp:18
PACMAN::MLS_interpolate
void MLS_interpolate(int_t spaceDimension, unsigned char execSpace, coordinates_t *sourcePoints, int_t nSourcePoints, fp_t *sourceValues, coordinates_t *targetPoints, int_t nTargetPoints, fp_t *targetValues, int_t nComponents=1)
C++ interface for Moving Least Squares (MLS) interpolation.
Definition
mls_interface.cpp:72
src
mls_interface.cpp
Generated on
for PACMAN by
1.17.0