19#ifndef CORE_EXTERNAL_FIELD_FIELDS_INTERPOLATED_HPP
20#define CORE_EXTERNAL_FIELD_FIELDS_INTERPOLATED_HPP
30#if defined(NDEBUG) && !defined(BOOST_DISABLE_ASSERTS)
31#define BOOST_DISABLE_ASSERTS
33#include <boost/multi_array.hpp>
43void deep_copy(boost::multi_array<T, 3> &dst,
44 const boost::multi_array<T, 3> &src) {
45 auto *s = src.shape();
46 dst.resize(boost::extents[s[0]][s[1]][s[2]]);
49 auto *b = src.index_bases();
50 dst.reindex(std::array<
typename boost::multi_array<T, 3>::index, 3>{
81 Interpolated(
const boost::const_multi_array_ref<value_type, 3> &global_field,
84 : m_global_field(global_field), m_grid_spacing(
grid_spacing),
89 detail::deep_copy(m_global_field, rhs.m_global_field);
91 m_grid_spacing = rhs.m_grid_spacing;
92 m_origin = rhs.m_origin;
106 return {m_global_field.shape(), m_global_field.shape() + 3};
111 auto const *data =
reinterpret_cast<T
const *
>(m_global_field.data());
112 return std::vector<T>(data, data + codim * m_global_field.num_elements());
120 return bspline_3d_accumulate<2>(
122 [
this](
const std::array<int, 3> &ind) {
return m_global_field(ind); },
131 return bspline_3d_gradient_accumulate<2>(
133 [
this](
const std::array<int, 3> &ind) {
return m_global_field(ind); },
138 auto const box_shape =
shape();
141 ((m_origin + grid_size) >= box);
Vector implementation and trait types for boost qvm interoperability.
A vector or scalar field interpolated from a regular grid.
Utils::Vector3i shape() const
Utils::Vector3d origin() const
typename Utils::decay_to_scalar< Utils::Vector< T, codim > >::type value_type
Type of the values, usually Utils::Vector<T, 3> for vector fields and T for scalar fields.
bool fits_in_box(const Utils::Vector3d &box) const
Interpolated & operator=(const Interpolated &rhs)
value_type operator()(const Utils::Vector3d &pos, double={}) const
Interpolated(const Interpolated &rhs)
std::vector< T > field_data_flat() const
Serialize field.
Interpolated(const boost::const_multi_array_ref< value_type, 3 > &global_field, const Utils::Vector3d &grid_spacing, const Utils::Vector3d &origin)
storage_type const & field_data() const
jacobian_type jacobian(const Utils::Vector3d &pos, double={}) const
detail::jacobian_type< T, codim > jacobian_type
boost::multi_array< value_type, 3 > storage_type
Utils::Vector3d grid_spacing() const
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value)
Create a vector that has all entries set to the same value.
T bspline_3d_accumulate(Vector3d const &pos, Kernel const &kernel, Vector3d const &grid_spacing, Vector3d const &offset, T const &init)
cardinal B-spline weighted sum.
T bspline_3d_gradient_accumulate(Vector3d const &pos, Kernel const &kernel, Vector3d const &grid_spacing, Vector3d const &offset, T const &init)
cardinal B-spline weighted sum.
auto hadamard_product(Vector< T, N > const &a, Vector< U, N > const &b)
Meta function to turns a Vector<1, T> into T.