1#ifndef IPPL_FEMINTERPOLATE_H
2#define IPPL_FEMINTERPOLATE_H
14 template <
typename T,
unsigned Dim>
15 KOKKOS_INLINE_FUNCTION
void
22 for (
unsigned d = 0; d <
Dim; ++d) {
23 const T s = (x[d] - origin[d]) / hr[d];
24 const size_t e =
static_cast<size_t>(Kokkos::floor(s));
26 xi[d] = s -
static_cast<T>(e);
31 template<
class View,
class IVec, std::size_t... Is>
32 KOKKOS_INLINE_FUNCTION
34 ->
decltype(&v(I[Is]...)) {
38 template<
int D,
class View,
class IVec>
39 KOKKOS_INLINE_FUNCTION
41 ->
decltype(
view_ptr_impl(v, I, std::make_index_sequence<D>{})) {
58 template <
typename AttribIn,
typename Field,
typename PosAttrib,
typename Space,
59 typename policy_type = Kokkos::RangePolicy<typename Field::execution_space>>
61 const PosAttrib& pp,
const Space& space,
62 policy_type iteration_policy)
76 const mesh_type& mesh = f.
get_mesh();
86 auto d_attr = attrib.getView();
87 auto d_pos = pp.getView();
90 auto device_space = space.getDeviceMirror();
92 Kokkos::parallel_for(
"assemble_rhs_from_particles_P1", iteration_policy,
93 KOKKOS_LAMBDA(
const size_t p) {
95 const T val = d_attr(p);
103 const auto dofs = device_space.getGlobalDOFIndices(e_nd);
106 for (
size_t a = 0; a < dofs.dim; ++a) {
107 const size_t local = device_space.getLocalDOFIndex(e_nd, dofs[a]);
108 const T w = device_space.evaluateRefElementShapeFunction(local, xi);
111 const auto v_nd = device_space.getMeshVertexNDIndex(dofs[a]);
114 for (
unsigned d = 0; d <
Dim; ++d) {
115 I[d] =
static_cast<size_t>(v_nd[d] - lDom.
first()[d] + nghost);
129 template<
class View,
class IVec, std::size_t... Is>
130 KOKKOS_INLINE_FUNCTION
131 decltype(
auto)
view_ref_impl(View& v,
const IVec& I, std::index_sequence<Is...>) {
135 template<
int D,
class View,
class IVec>
136 KOKKOS_INLINE_FUNCTION
154 template <
typename AttribOut,
typename Field,
typename PosAttrib,
typename Space,
155 typename policy_type = Kokkos::RangePolicy<typename Field::execution_space>>
160 policy_type iteration_policy)
163 using T =
typename AttribOut::value_type;
173 const mesh_type& mesh = coeffs.
get_mesh();
183 auto d_pos = pp.getView();
184 auto d_out = attrib_out.getView();
187 auto device_space = space.getDeviceMirror();
188 Kokkos::parallel_for(
"interpolate_to_diracs_P1", iteration_policy,
189 KOKKOS_LAMBDA(
const size_t p) {
197 const auto dofs = device_space.getGlobalDOFIndices(e_nd);
199 field_value_type up = field_value_type(0);
201 for (
size_t a = 0; a < dofs.dim; ++a) {
202 const size_t local = device_space.getLocalDOFIndex(e_nd, dofs[a]);
203 const field_value_type w = device_space.evaluateRefElementShapeFunction(local, xi);
205 const auto v_nd = device_space.getMeshVertexNDIndex(dofs[a]);
207 for (
unsigned d = 0; d <
Dim; ++d) {
208 I[d] =
static_cast<size_t>(v_nd[d] - lDom.
first()[d] + nghost);
213 d_out(p) =
static_cast<T>(up);
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
ippl::Field< T, Dim, Mesh_t< Dim >, Centering_t< Dim >, ViewArgs... > Field
KOKKOS_INLINE_FUNCTION decltype(auto) view_ref(View &v, const IVec &I)
KOKKOS_INLINE_FUNCTION auto view_ptr_impl(View &v, const IVec &I, std::index_sequence< Is... >) -> decltype(&v(I[Is]...))
KOKKOS_INLINE_FUNCTION auto view_ptr(View &v, const IVec &I) -> decltype(view_ptr_impl(v, I, std::make_index_sequence< D >{}))
void assemble_rhs_from_particles(const AttribIn &attrib, Field &f, const PosAttrib &pp, const Space &space, policy_type iteration_policy)
Assemble a P1 FEM load vector (RHS) from particle attributes.
void interpolate_to_diracs(AttribOut &attrib_out, const Field &coeffs, const PosAttrib &pp, const Space &space, policy_type iteration_policy)
Interpolate a P1 FEM field to particle positions.
KOKKOS_INLINE_FUNCTION void locate_element_nd_and_xi(const Vector< T, Dim > &hr, const Vector< T, Dim > &origin, const Vector< T, Dim > &x, Vector< size_t, Dim > &e_nd, Vector< T, Dim > &xi)
Mapping from global position to element ND index and reference coordinates (xi ∈ [0,...
KOKKOS_INLINE_FUNCTION decltype(auto) view_ref_impl(View &v, const IVec &I, std::index_sequence< Is... >)
Layout_t & getLayout() const
static constexpr unsigned dim
KOKKOS_INLINE_FUNCTION Mesh_t & get_mesh() const
typename BareField_t::view_type view_type
const NDIndex_t & getLocalNDIndex() const
KOKKOS_INLINE_FUNCTION Vector< int, Dim > first() const
KOKKOS_INLINE_FUNCTION vector_type getOrigin() const
virtual KOKKOS_INLINE_FUNCTION const vector_type & getMeshSpacing() const =0
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)