Commit cfcb0945 authored by Quentin Khan's avatar Quentin Khan

Update testChebOperators to new kernel interface

parent 1e279641
......@@ -3,7 +3,6 @@
#include <algorithm>
#include "Containers/FOctree.hpp"
#include "Components/FSimpleLeaf.hpp"
#include "Core/FFmmAlgorithm.hpp"
#include "Kernels/Chebyshev/FChebCell.hpp"
......@@ -22,10 +21,8 @@ const int NVals = 1;
const unsigned int ORDER = 3;
using FReal = double;
using container_t = FP2PParticleContainerIndexed<FReal,1,1,NVals>;
using leaf_t = FSimpleLeaf<FReal, container_t>;
using matrix_kernel_t = FInterpMatrixKernelR<FReal>;
using cell_t = FChebCell<FReal,ORDER, 1, 1, NVals>;
using octree_t = FOctree<FReal, cell_t,container_t,leaf_t>;
using kernel_t = FChebKernel<FReal,cell_t,container_t,matrix_kernel_t,ORDER, NVals>;
......@@ -42,22 +39,9 @@ std::ostream& print_array(std::ostream& os, const T(&arr)[N]) {
return os;
}
template<class... Args, class T = typename std::common_type<Args...>::type,
class = inria::require<inria::conjunction<std::is_arithmetic<Args>...>>
>
T sum(Args&&... args) {
T res = 0;
auto l = {((res += std::forward<Args>(args)),0)...,0};
(void)l;
return res;
}
template<class T, std::size_t N>
T sum(const T (&arr)[N]) {
T res = 0;
for(std::size_t i = 0; i < N; ++i)
res += arr[i];
return res;
return std::accumulate(arr, arr + N, 0);
}
......@@ -88,10 +72,10 @@ int main() {
leaf.setCoordinate(0,0,0);
// Call P2M on the cell, using the particle container
print_array(std::cout, leaf.multipole_exp) << '\n';
kernel.P2M(&leaf, &container);
print_array(std::cout, leaf.multipole_exp) << '\n';
std::cout << sum(leaf.multipole_exp) << "\n\n";
print_array(std::cout, leaf.m_data.exp) << '\n';
kernel.P2M(&leaf.m_data, &leaf, &container);
print_array(std::cout, leaf.m_data.exp) << '\n';
std::cout << sum(leaf.m_data.exp) << "\n\n";
// Build a parent to run an M2M operation
cell_t node {};
......@@ -100,12 +84,14 @@ int main() {
node.setCoordinate(0,0,0);
std::array<cell_t*,8> leaf_ptrs = {{&leaf}};
std::array<typename cell_t::multipole_t*, 8> leaf_multipoles = {{&leaf.m_data}};
std::array<typename cell_t::local_expansion_t*, 8> leaf_local_exps = {{&leaf.l_data}};
// Call M2M on the parent
print_array(std::cout, node.multipole_exp) << '\n';
kernel.M2M(&node, leaf_ptrs.data(), static_cast<int>(node.getLevel()));
print_array(std::cout, node.multipole_exp) << '\n';
std::cout << sum(node.multipole_exp) << "\n\n";
print_array(std::cout, node.m_data.exp) << '\n';
kernel.M2M(&node.m_data, &node, leaf_multipoles.data(), leaf_ptrs.data());
print_array(std::cout, node.m_data.exp) << '\n';
std::cout << sum(node.m_data.exp) << "\n\n";
// Duplicate the parent to create an M2L operation
cell_t v_item = node;
......@@ -115,21 +101,25 @@ int main() {
auto coord_diff = v_item.getCoordinate() - node.getCoordinate();
int v_idx = ((coord_diff.getX() + 3) * 7 + (coord_diff.getY() + 3)) * 7 + coord_diff.getZ() + 3;
const cell_t* v_item_ptr = &v_item;
const cell_t::multipole_t* v_item_multipole_ptr = &v_item.m_data;
const cell_t* v_item_symbolic_ptr = &v_item;
print_array(std::cout, node.local_exp) << '\n';
kernel.M2L(&node, &v_item_ptr, &v_idx, 1, static_cast<int>(node.getLevel()));
print_array(std::cout, node.local_exp) << '\n';
std::cout << sum(node.local_exp) << "\n\n";
// Call M2L
print_array(std::cout, node.l_data.exp) << '\n';
kernel.M2L(&node.l_data, &node,
&v_item_multipole_ptr, &v_item_symbolic_ptr,
&v_idx, 1);
print_array(std::cout, node.l_data.exp) << '\n';
std::cout << sum(node.l_data.exp) << "\n\n";
// Call L2L
print_array(std::cout, leaf.local_exp) << '\n';
kernel.L2L(&node, leaf_ptrs.data(), static_cast<int>(node.getLevel()));
print_array(std::cout, leaf.local_exp) << '\n';
std::cout << sum(leaf.local_exp) << "\n\n";
print_array(std::cout, leaf.l_data.exp) << '\n';
kernel.L2L(&node.l_data, &node, leaf_local_exps.data(), leaf_ptrs.data());
print_array(std::cout, leaf.l_data.exp) << '\n';
std::cout << sum(leaf.l_data.exp) << "\n\n";
// Call L2P
kernel.L2P(&leaf, &container);
kernel.L2P(&leaf.l_data, &leaf, &container);
// Print particles
auto positions = container.getPositions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment