PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
fortran_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
14
15#include "fortran_interface.h"
16#include "interface.hpp"
17
18#include <Kokkos_Core.hpp>
19#include <iostream>
20#include <stdexcept>
21
22extern "C" {
23
24// ---------------------------------------------------------------------------
25// Kokkos lifecycle
26// ---------------------------------------------------------------------------
27
29 if (!Kokkos::is_initialized()) {
30 Kokkos::initialize();
31 }
32}
33
35 if (Kokkos::is_initialized()) {
36 Kokkos::finalize();
37 }
38}
39
41#if defined(KOKKOS_ENABLE_HIP)
42 return static_cast<int>(PACMAN::ExecSpaces::HIP);
43#elif defined(KOKKOS_ENABLE_CUDA)
44 return static_cast<int>(PACMAN::ExecSpaces::CUDA);
45#elif defined(KOKKOS_ENABLE_SYCL)
46 return static_cast<int>(PACMAN::ExecSpaces::SYCL);
47#elif defined(KOKKOS_ENABLE_OPENMP)
48 return static_cast<int>(PACMAN::ExecSpaces::OPENMP);
49#elif defined(KOKKOS_ENABLE_THREADS)
50 return static_cast<int>(PACMAN::ExecSpaces::THREADS);
51#elif defined(KOKKOS_ENABLE_SERIAL)
52 return static_cast<int>(PACMAN::ExecSpaces::SERIAL);
53#else
54 return -1;
55#endif
56}
57
58// ---------------------------------------------------------------------------
59// RBF-PUM interpolation
60// ---------------------------------------------------------------------------
61
62int pacman_rbf_interpolate_c(int spaceDimension, int execSpace, int rbfFunction,
63 const double *sourcePoints, int nSourcePoints,
64 const double *sourceValues,
65 const double *targetPoints, int nTargetPoints,
66 double *targetValues) {
67 try {
69 static_cast<PACMAN::int_t>(spaceDimension),
70 static_cast<unsigned char>(execSpace),
71 static_cast<unsigned char>(rbfFunction),
72 // The C++ API takes non-const pointers but does not modify the data.
73 const_cast<PACMAN::coordinates_t *>(sourcePoints),
74 static_cast<PACMAN::int_t>(nSourcePoints),
75 const_cast<PACMAN::fp_t *>(sourceValues),
76 const_cast<PACMAN::coordinates_t *>(targetPoints),
77 static_cast<PACMAN::int_t>(nTargetPoints), targetValues);
78
79 return 0;
80 }
81 // LCOV_EXCL_START
82 catch (const std::exception &e) {
83 std::cerr << "pacman_rbf_interpolate_c: " << e.what() << "\n";
84 return -1;
85 } catch (...) {
86 std::cerr << "pacman_rbf_interpolate_c: unknown exception\n";
87 return -2;
88 }
89 // LCOV_EXCL_STOP
90}
91
92// ---------------------------------------------------------------------------
93// FE interpolation
94// ---------------------------------------------------------------------------
95
96int pacman_fe_interpolate_c(int spaceDimension, int execSpace, int method,
97 const double *sourcePoints, int nSourcePoints,
98 const double *sourceValues, const int *connVal,
99 int connValSize, const int *connOff,
100 int connOffSize, const int *cellTypes,
101 const double *targetPoints, int nTargetPoints,
102 double *targetValues, int *targetStatus) {
103 try {
105 static_cast<PACMAN::int_t>(spaceDimension),
106 static_cast<unsigned char>(execSpace),
107 static_cast<PACMAN::method_t>(method),
108 const_cast<PACMAN::coordinates_t *>(sourcePoints),
109 static_cast<PACMAN::int_t>(nSourcePoints),
110 const_cast<PACMAN::fp_t *>(sourceValues),
111 const_cast<PACMAN::int_t *>(connVal),
112 static_cast<PACMAN::int_t>(connValSize),
113 const_cast<PACMAN::offset_t *>(connOff),
114 static_cast<PACMAN::int_t>(connOffSize),
115 const_cast<PACMAN::cell_t *>(cellTypes),
116 const_cast<PACMAN::coordinates_t *>(targetPoints),
117 static_cast<PACMAN::int_t>(nTargetPoints), targetValues, targetStatus,
118 true);
119 return 0;
120 }
121 // LCOV_EXCL_START
122 catch (const std::exception &e) {
123 std::cerr << "pacman_fe_interpolate_c: " << e.what() << "\n";
124 return -1;
125 }
126 catch (...) {
127 std::cerr << "pacman_fe_interpolate_c: unknown exception\n";
128 return -2;
129 }
130 // LCOV_EXCL_STOP
131}
132
133// ---------------------------------------------------------------------------
134// MLS interpolation
135// ---------------------------------------------------------------------------
136
137int pacman_mls_interpolate_c(int spaceDimension, int execSpace,
138 const double *sourcePoints, int nSourcePoints,
139 const double *sourceValues,
140 const double *targetPoints, int nTargetPoints,
141 double *targetValues) {
142
143 try {
145 static_cast<PACMAN::int_t>(spaceDimension),
146 static_cast<unsigned char>(execSpace),
147 const_cast<PACMAN::coordinates_t *>(sourcePoints),
148 static_cast<PACMAN::int_t>(nSourcePoints),
149 const_cast<PACMAN::fp_t *>(sourceValues),
150 const_cast<PACMAN::coordinates_t *>(targetPoints),
151 static_cast<PACMAN::int_t>(nTargetPoints), targetValues);
152
153 return 0;
154 }
155 // LCOV_EXCL_START
156 catch (const std::exception &e) {
157 std::cerr << "pacman_mls_interpolate_c: " << e.what() << "\n";
158 return -1;
159 }
160 catch (...) {
161 std::cerr << "pacman_mls_interpolate_c: unknown exception\n";
162 return -2;
163 }
164 // LCOV_EXCL_STOP
165}
166
167// ---------------------------------------------------------------------------
168// Cell-type helpers
169// ---------------------------------------------------------------------------
170
171int pacman_vtk_to_pacman_cell_type_c(const int *vtkTypes, int *pacmanTypes,
172 int n) {
173 try {
175 reinterpret_cast<const PACMAN::int_t *>(vtkTypes),
176 reinterpret_cast<PACMAN::cell_t *>(pacmanTypes),
177 static_cast<PACMAN::int_t>(n));
178 return 0;
179 }
180 // LCOV_EXCL_START
181 catch (const std::exception &e) {
182 std::cerr << "pacman_vtk_to_pacman_cell_type_c: " << e.what() << "\n";
183 return -1;
184 }
185 catch (...) {
186 std::cerr << "pacman_vtk_to_pacman_cell_type_c: unknown exception\n";
187 return -2;
188 }
189 // LCOV_EXCL_STOP
190}
191
192} // extern "C"
void pacman_kokkos_initialize_c(void)
Initialize Kokkos with default settings.
int pacman_rbf_interpolate_c(int spaceDimension, int execSpace, int rbfFunction, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const double *targetPoints, int nTargetPoints, double *targetValues)
C shim for PACMAN::rbf_interpolate.
int pacman_mls_interpolate_c(int spaceDimension, int execSpace, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const double *targetPoints, int nTargetPoints, double *targetValues)
C shim for PACMAN::mls_interpolate.
int pacman_best_execspace_c(void)
Return the best execution space available in the current build.
int pacman_fe_interpolate_c(int spaceDimension, int execSpace, int method, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const int *connVal, int connValSize, const int *connOff, int connOffSize, const int *cellTypes, const double *targetPoints, int nTargetPoints, double *targetValues, int *targetStatus)
C shim for PACMAN::fe_interpolate.
void pacman_kokkos_finalize_c(void)
Finalize Kokkos.
int pacman_vtk_to_pacman_cell_type_c(const int *vtkTypes, int *pacmanTypes, int n)
Convert an array of VTK cell-type IDs to PACMAN CellType values.
Plain-C shim declarations for the Fortran ISO C bindings interface.
double fp_t
Definition types.hpp:15
double coordinates_t
Definition types.hpp:16
void rbf_interpolate(int_t spaceDimension, unsigned char execSpace, unsigned char rbfFunction, 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 RBF-PUM interpolation.
int32_t cell_t
Definition types.hpp:25
void vtk_to_pacman_cell_type(const int_t *vtkTypes, cell_t *pacmanTypes, int_t n)
Convert an array of VTK cell type IDs to PACMAN CellType enum values.
int32_t offset_t
Definition types.hpp:21
void fe_interpolate(int_t spaceDimension, unsigned char execSpace, method_t method, coordinates_t *sourcePoints, int_t nSourcePoints, fp_t *sourceValues, int_t *connVal, int_t connValSize, offset_t *connOff, int_t connOffSize, cell_t *cellTypes, coordinates_t *targetPoints, int_t nTargetPoints, fp_t *targetValues, int_t *targetStatus, bool fortranIndexing, int_t nComponents)
C++ interface for finite-elements interpolation.
Definition interface.cpp:84
int32_t method_t
Definition types.hpp:24
int32_t int_t
Definition types.hpp:18
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.
static constexpr const unsigned char OPENMP
static constexpr const unsigned char SERIAL
static constexpr const unsigned char SYCL
static constexpr const unsigned char THREADS
static constexpr const unsigned char HIP
static constexpr const unsigned char CUDA