Commit c16a282e authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

Now l2p oprators only use far-field oprator

parent 989faad7
......@@ -226,79 +226,10 @@ auto run(const int& tree_height, const int& group_size, const bool readFile, std
group_tree_type gtree(static_cast<std::size_t>(tree_height), runtime_order, box3,
static_cast<std::size_t>(group_size), *container);
// if(interaction)
// {
// using fmm_operator_type = count_kernels::interactions::count_fmm_operator;
// fmm_operator_type fmm_operator{};
// scalfmm::algorithms::sequential(gtree, std::move(fmm_operator));
// }
// else
{
using fmm_operator_type = count_kernels::particles::count_fmm_operator;
fmm_operator_type fmm_operator{};
auto operator_to_proceed = scalfmm::algorithms::all;
scalfmm::algorithms::sequential(gtree, std::move(fmm_operator), operator_to_proceed);
}
// if(interaction)
// {
// std::cout << scalfmm::colors::on_blue << "bottom pass" << scalfmm::colors::reset << '\n';
// std::cout << scalfmm::colors::on_blue << "-----------" << scalfmm::colors::reset << '\n';
// typename cell_type::multipoles_container accumulate(get_accumulate_shape<Dimension>(), 0.);
// // typename cell_type::multipoles_container accumulate({1, 1, 1}, 0.);
// std::cout << scalfmm::colors::on_blue << "first cell level multipoles :\n" << scalfmm::colors::reset;
// scalfmm::component::for_each_cell(
// std::begin(gtree), std::end(gtree), std::size_t(tree_height) - 1, [&accumulate](auto const& cell) {
// accumulate += std::get<0>(cell.cmultipoles());
// std::cout << scalfmm::colors::blue << std::get<0>(cell.cmultipoles()) << " " <<
// scalfmm::colors::reset;
// });
// std::cout << '\n'
// << scalfmm::colors::on_blue << " accumulate = " << accumulate << scalfmm::colors::reset <<
// '\n';
// std::cout << scalfmm::colors::on_yellow << "upward pass" << scalfmm::colors::reset << '\n';
// std::cout << scalfmm::colors::on_yellow << "-----------" << scalfmm::colors::reset << '\n';
// for(std::size_t level = static_cast<std::size_t>(tree_height) - 2; level > 1; --level)
// {
// std::cout << scalfmm::colors::on_yellow << "cell level multipoles " << level << " :\n"
// << scalfmm::colors::reset;
// accumulate = xt::zeros<double>({1, 1, 1});
// scalfmm::component::for_each_cell(
// std::begin(gtree), std::end(gtree), level, [&accumulate](auto const& cell) {
// accumulate += std::get<0>(cell.cmultipoles());
// std::cout << scalfmm::colors::yellow << std::get<0>(cell.cmultipoles()) << " "
// << scalfmm::colors::reset;
// });
// std::cout << '\n'
// << scalfmm::colors::on_yellow << " accumulate = " << accumulate << scalfmm::colors::reset
// << '\n';
// }
// std::cout << scalfmm::colors::on_green << "transfert & downward pass" << scalfmm::colors::reset << '\n';
// std::cout << scalfmm::colors::on_green << "-------------------------" << scalfmm::colors::reset << '\n';
// for(std::size_t level = static_cast<std::size_t>(tree_height) - 1; level > 1; --level)
// {
// std::cout << scalfmm::colors::on_green << "cell level multipoles " << level << " :\n"
// << scalfmm::colors::reset;
// accumulate = xt::zeros<double>({1, 1, 1});
// scalfmm::component::for_each_cell(
// std::begin(gtree), std::end(gtree), level, [&accumulate](auto const& cell) {
// accumulate += std::get<0>(cell.clocals());
// std::cout << scalfmm::colors::green << std::get<0>(cell.clocals()) << " " <<
// scalfmm::colors::reset;
// });
// std::cout << '\n'
// << scalfmm::colors::on_green << " accumulate = " << accumulate << scalfmm::colors::reset
// << '\n';
// }
// std::cout << scalfmm::colors::on_red << "direct pass" << scalfmm::colors::reset << '\n';
// std::cout << scalfmm::colors::on_red << "-----------" << scalfmm::colors::reset << '\n';
// }
using fmm_operator_type = count_kernels::particles::count_fmm_operator;
fmm_operator_type fmm_operator{};
auto operator_to_proceed = scalfmm::algorithms::all;
scalfmm::algorithms::sequential(gtree, std::move(fmm_operator), operator_to_proceed);
std::size_t nb_particles_min = 2 * number_of_particles, nb_particles_max = 0;
bool right_number_of_particles = true;
......
......@@ -11,7 +11,6 @@
#include "scalfmm/matrix_kernels/laplace.hpp"
#include "scalfmm/operators/laplace_operators.hpp"
#include "scalfmm/algorithms/sequential/sequential.hpp"
#include "scalfmm/tools/colorized.hpp"
......@@ -227,7 +226,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
using near_field_type = scalfmm::operators::near_field_operator<near_matrix_kernel_type>;
using interpolation_type =
scalfmm::interpolation::uniform_interpolator<double, dimension, far_matrix_kernel_type>;
// true beacause we compute the gradient of the interpolator
using far_field_type = scalfmm::operators::far_field_operator<interpolation_type, true>;
run<scalfmm::operators::fmm_operators<near_field_type, far_field_type>>(
......@@ -242,6 +241,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
using near_field_type = scalfmm::operators::near_field_operator<near_matrix_kernel_type>;
using interpolation_type =
scalfmm::interpolation::uniform_interpolator<double, dimension, far_matrix_kernel_type>;
// true beacause we compute the gradient of the interpolator
using far_field_type = scalfmm::operators::far_field_operator<interpolation_type, true>;
run<scalfmm::operators::fmm_operators<near_field_type, far_field_type>>(
......@@ -250,8 +250,9 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
break;
default:
std::cout << "Kernel not implemented. value is 0 1/r, 1 grad(1/r), 2 p "
"& grad(1/r) 3 shift grad 4) p and grad with shift operator. "
<< std::endl;
std::cout << "Kernel not implemented. value is 0) 1/r, 1) grad(1/r), "
"2) p & grad(1/r) "
<< std::endl
<< "3) optimized grad(1/r) 4) optimized p & grad(1/r) . " << std::endl;
}
}
......@@ -37,6 +37,8 @@ namespace scalfmm::algorithms::pass
auto group_of_cell_begin = std::begin(cells_at_leaf_level);
auto group_of_cell_end = std::end(cells_at_leaf_level);
auto const& far_field = fmm_operator.far_field();
while(group_of_leaf_begin != group_of_leaf_end && group_of_cell_begin != group_of_cell_end)
{
{ // Can be a task(in:iterCells, inout:iterParticles)
......@@ -44,8 +46,7 @@ namespace scalfmm::algorithms::pass
{
auto const& source_cell = (*group_of_cell_begin)->ccomponent(leaf_index);
auto& target_leaf = (*group_of_leaf_begin)->component(leaf_index);
l2p(fmm_operator, source_cell, target_leaf, source_cell.order());
l2p(far_field /*fmm_operator*/, source_cell, target_leaf, source_cell.order());
}
}
......
......@@ -91,8 +91,8 @@ namespace count_kernels
}
template<typename Cell>
inline void l2l(count_approximation const& interp, Cell const& parent_cell, std::size_t child_index,
Cell& child_cell, std::size_t order, std::size_t tree_level = 2)
inline void l2l(count_approximation const& /*interp*/, Cell const& parent_cell, std::size_t /*child_index*/,
Cell& child_cell, std::size_t /*order*/)
{
auto const& target_symb = child_cell.csymbolics();
auto& child_locals = std::get<0>(child_cell.locals());
......@@ -101,8 +101,8 @@ namespace count_kernels
}
template<typename Cell>
inline void m2m(count_approximation const& interp, Cell const& child_cell, std::size_t child_index,
Cell& parent_cell, std::size_t order, std::size_t tree_level = 2)
inline void m2m(count_approximation const& /*interp*/, Cell const& child_cell, std::size_t /*child_index*/,
Cell& parent_cell, std::size_t /*order*/)
{
auto const& target_symb = parent_cell.csymbolics();
auto& parent_multipoles = std::get<0>(parent_cell.multipoles());
......@@ -120,11 +120,11 @@ namespace count_kernels
auto& target_locals = std::get<0>(target_cell.locals());
target_locals += source_multipoles;
}
template<typename Cell, typename Leaf, bool ComputeForces = false>
inline void l2p(count_fmm_operator const& fmm_operator, Cell const& source_cell, Leaf& target_leaf,
template<typename Cell, typename Leaf>
inline void l2p(count_far_field const& /*fmm_operator*/, Cell const& source_cell, Leaf& target_leaf,
std::size_t /*order*/)
{
auto interp = fmm_operator.far_field();
// auto interp = fmm_operator.far_field();
std::get<0>(*scalfmm::container::outputs_begin(target_leaf.particles())) =
*std::begin(std::get<0>(source_cell.clocals()));
}
......@@ -156,266 +156,6 @@ namespace count_kernels
{
}
} // namespace particles
namespace interactions
{
struct execution_infos
{
const std::string operator_name{};
std::size_t particles{0};
std::size_t number_of_component{0};
std::size_t call_count{0};
std::array<std::size_t, 10> multipoles_count{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::array<std::size_t, 10> locals_count{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
friend inline auto operator<<(std::ostream& os, const execution_infos& infos) -> std::ostream&;
};
inline auto operator<<(std::ostream& os, const execution_infos& infos) -> std::ostream&
{
os << "[\n operator : " << infos.operator_name << "\n particles : " << infos.particles
<< "\n call_count : " << infos.call_count << '\n';
std::size_t level{0};
for(auto l: infos.multipoles_count)
{
std::cout << " multipoles_count[" << level++ << "] : " << l << '\n';
}
level = 0;
for(auto l: infos.locals_count)
{
std::cout << " locals_count[" << level++ << "] : " << l << '\n';
}
std::cout << " ]";
return os;
}
///
/// \brief The count_matrix_kernel struct
///
struct count_matrix_kernel
{
using map_type = std::unordered_map<std::string, execution_infos>;
using mapped_type = execution_infos;
// static constexpr auto homogeneity_tag{scalfmm::matrix_kernels::homogeneity::homogenous};
// static constexpr int km{1};
// static constexpr int kn{1};
// inline auto separation_criterion() const -> std::size_t { return 1; }
inline auto get(std::string const& key) -> mapped_type& { return m_map.at(key); }
inline auto get(std::string const& key) const -> mapped_type const& { return m_map.at(key); }
inline auto print() -> void
{
for(auto const& pair: m_map)
{
std::cout << pair.second << '\n';
}
}
private:
map_type m_map{{
{"p2p_full_mutual", {"p2p_full_mutual"}},
{"p2p_inner", {"p2p_inner"}},
{"p2p_remote", {"p2p_remote"}},
}};
};
///
/// \brief The count_near_field struct
///
/// An implementation of the near field for the counter kernel
struct count_near_field
{
count_matrix_kernel mat;
inline auto separation_criterion() const -> std::size_t { return 1; }
inline count_matrix_kernel matrix_kernel() { return mat; };
inline auto print() -> void { mat.print(); }
};
struct count_approximation
{
struct empty
{
};
using buffer_type = empty;
using map_type = std::unordered_map<std::string, execution_infos>;
using map_value_type = typename map_type::value_type;
using mapped_type = execution_infos;
template<typename Cell>
void apply_multipoles_preprocessing(Cell& /*current_cell*/, std::size_t /*order*/)
{
}
template<typename Cell>
void apply_multipoles_postprocessing(Cell& /*current_cell*/, buffer_type)
{
}
inline auto buffer_initialization() const -> buffer_type { return empty{}; }
// template<typename Cell>
// auto apply_m2l(Cell const& /*source_cell*/, Cell& /*target_cell*/, std::size_t
// /*neighbor_idx*/,
// std::size_t /*order*/, std::size_t /*tree_level*/,
// [[maybe_unused]] buffer_type& products) const -> void
// {
// }
inline auto get(std::string const& key) -> mapped_type& { return m_map.at(key); }
inline auto get(std::string const& key) const -> mapped_type const& { return m_map.at(key); }
inline auto print() -> void
{
for(auto const& pair: m_map)
{
std::cout << pair.second << '\n';
}
}
private:
map_type m_map{{
{"p2m", {"p2m"}},
{"m2m", {"m2m"}},
{"m2l", {"m2l"}},
{"l2l", {"l2l"}},
{"l2p", {"l2p"}},
// {"p2p_full_mutual", {"p2p_full_mutual"}},
// {"p2p_inner", {"p2p_inner"}},
// {"p2p_remote", {"p2p_remote"}},
}};
};
///
/// \brief The count_interpolator struct
///
/// An implementation of the far field for the counter kernel
// struct count_interpolator
struct count_far_field
{
private:
count_approximation m_count_approximation;
public:
using approximation_type = count_approximation;
static constexpr bool compute_gradient = false;
auto approximation() const -> approximation_type const& { return m_count_approximation; }
// static constexpr std::size_t dimension{3};
// static constexpr std::size_t kn = count_matrix_kernel::kn;
// static constexpr std::size_t km = count_matrix_kernel::km;
// inline auto separation_criterion() const -> std::size_t { return 1; }
// template<typename Cell>
// void apply_multipoles_preprocessing(Cell& current_cell, std::size_t order)
// {
// }
// template<typename Cell>
// void apply_multipoles_postprocessing(Cell& current_cell, std::size_t order)
// {
// }
};
struct count_fmm_operator
{
count_far_field m_far_field;
count_near_field m_near_field;
inline count_far_field far_field() { return m_far_field; };
inline count_near_field near_field() const { return m_near_field; };
// inline auto separation_criterion() const -> std::size_t { return interp.separation_criterion(); }
inline auto print() -> void
{
// far_field.print();
// near_field.print();
}
};
template<typename Leaf, typename Cell>
inline void p2m(count_approximation& interp, Leaf const& source_leaf, Cell& target_cell, std::size_t /*order*/)
{
auto& infos = interp.get("p2m");
auto const& target_symb = target_cell.csymbolics();
auto& multipoles = std::get<0>(target_cell.multipoles());
multipoles += source_leaf.size();
infos.call_count++;
infos.multipoles_count[target_symb.level]++;
infos.particles += source_leaf.size();
}
template<typename Cell>
inline void l2l(count_approximation& interp, Cell const& parent_cell, std::size_t child_index, Cell& child_cell,
std::size_t order, std::size_t tree_level = 2)
{
auto& infos = interp.get("l2l");
auto const& target_symb = child_cell.csymbolics();
auto& child_locals = std::get<0>(child_cell.locals());
auto const& current_locals = std::get<0>(parent_cell.clocals());
child_locals += current_locals;
infos.call_count++;
infos.locals_count[target_symb.level]++;
}
template<typename Cell>
inline void m2m(count_approximation& interp, Cell const& child_cell, std::size_t child_index, Cell& parent_cell,
std::size_t order, std::size_t tree_level = 2)
{
auto& infos = interp.get("m2m");
auto const& target_symb = parent_cell.csymbolics();
auto& parent_multipoles = std::get<0>(parent_cell.multipoles());
auto const& child_multipoles = std::get<0>(child_cell.cmultipoles());
parent_multipoles += child_multipoles;
infos.call_count++;
infos.multipoles_count[target_symb.level]++;
}
template<typename Cell>
inline void m2l(count_approximation const& interp, Cell const& source_cell, std::size_t /*neighbor_idx*/,
Cell& target_cell, std::size_t /*order*/, std::size_t /*tree_level*/,
typename count_approximation::buffer_type& /*buffer*/)
{
auto& infos = interp.get("m2l");
auto const& target_symb = target_cell.csymbolics();
auto const& source_multipoles = std::get<0>(source_cell.cmultipoles());
auto& target_locals = std::get<0>(target_cell.locals());
target_locals += source_multipoles;
infos.locals_count[target_symb.level]++;
}
template<typename Cell, typename Leaf, bool ComputeForces = false>
inline void l2p(count_fmm_operator& fmm_operator, Cell const& source_cell, Leaf& target_leaf,
std::size_t /*order*/)
{
auto interp = fmm_operator.far_field().approximation();
auto& infos = interp.get("l2p");
std::get<0>(*scalfmm::container::outputs_begin(target_leaf.particles())) =
*std::begin(std::get<0>(source_cell.clocals()));
infos.call_count++;
}
template<typename Leaf, typename ContainerOfLeafIterator>
inline void p2p_full_mutual(count_matrix_kernel const& mat, Leaf& target_leaf,
ContainerOfLeafIterator const& neighbor)
{
using value_type = typename Leaf::value_type;
// auto& infos = mat.get("p2p_full_mutual");
value_type nb_val{0};
std::for_each(std::begin(neighbor), std::end(neighbor), [&target_leaf, &nb_val](auto const& n) {
auto neighbor_leaf_output = scalfmm::container::outputs_begin(n->particles());
std::get<0>(*neighbor_leaf_output) += static_cast<value_type>(target_leaf.size());
nb_val += static_cast<value_type>(n->size());
});
std::get<0>(*scalfmm::container::outputs_begin(target_leaf.particles())) += nb_val;
// infos.call_count++;
}
template<typename Leaf>
inline void p2p_inner(count_matrix_kernel const& mat, Leaf& target_leaf)
{
using value_type = typename Leaf::value_type;
// auto& infos = mat.get("p2p_inner");
std::get<0>(*scalfmm::container::outputs_begin(target_leaf.particles())) +=
static_cast<value_type>(target_leaf.size());
// infos.call_count++;
}
template<typename Leaf, typename ContainerOfLeafIterator>
inline void p2p_remote(count_matrix_kernel const&, Leaf&, ContainerOfLeafIterator const&)
{
}
} // namespace interactions
} // namespace count_kernels
#endif // SCALFMM_CORE_COUNT_KERNEL_HPP
......@@ -270,8 +270,7 @@ namespace scalfmm::operators
// Resulting S, also in simd
using vector_type = std::vector<value_type, XSIMD_DEFAULT_ALLOCATOR(value_type)>;
vector_type S(nnodes * inc);
std::conditional_t<ComputeGradien, container::get_variadic_adaptor_t<vector_type, dimension>, empty>
S_der;
std::conditional_t<ComputeGradien, container::get_variadic_adaptor_t<vector_type, dimension>, empty> S_der;
std::conditional_t<ComputeGradien, typename container::get_variadic_adaptor_t<vector_type, dimension>::iterator,
empty>
S_der_it;
......@@ -499,10 +498,11 @@ namespace scalfmm::operators
}
}
template<typename FmmOperator, typename Cell, typename Leaf, bool ComputeForces = false>
inline void l2p(FmmOperator const& fmm_operator, Cell const& source_cell, Leaf& target_leaf, std::size_t order)
template<typename FmmFarField, typename Cell, typename Leaf, bool ComputeForces = false>
inline void l2p(FmmFarField const& far_field /*fmm_operator*/, Cell const& source_cell, Leaf& target_leaf,
std::size_t order)
{
auto const& far_field = fmm_operator.far_field();
// auto const& far_field = fmm_operator.far_field();
apply_l2p(far_field, source_cell.clocals(), target_leaf, order);
}
} // namespace scalfmm::operators
......
......@@ -11,25 +11,38 @@
namespace scalfmm::operators
{
// namespace laplace
// {
// template<typename Approximation>
// using fullLaplace = scalfmm::operators::fmm_operators<
// scalfmm::operators::near_field_operator<scalfmm::matrix_kernels::laplace::val_grad_one_over_r>,
// scalfmm::operators::far_field_operator<Approximation, true>>;
// } // namespace laplace
// template<typename Cell, typename Leaf, typename Approximation>
// inline void l2p(scalfmm::operators::fmm_operators<
// scalfmm::operators::near_field_operator<scalfmm::matrix_kernels::laplace::val_grad_one_over_r>,
// scalfmm::operators::far_field_operator<Approximation, true>> const& fmmOperator,
// Cell const& source_cell, Leaf& target_leaf, std::size_t order)
// template<typename Cell, typename Leaf, typename Approximation>
template<typename Cell, typename Leaf, typename Approximation>
inline void l2p(scalfmm::operators::fmm_operators<
scalfmm::operators::near_field_operator<scalfmm::matrix_kernels::laplace::val_grad_one_over_r>,
scalfmm::operators::far_field_operator<Approximation, true>> const& fmmOperator,
inline void l2p(scalfmm::operators::far_field_operator<Approximation, true> const& far_field,
Cell const& source_cell, Leaf& target_leaf, std::size_t order)
{
const auto& far_field = fmmOperator.far_field();
// const auto& far_field = fmmOperator.far_field();
apply_l2p_der<true>(far_field, source_cell.clocals(), target_leaf, order);
}
template<typename Cell, typename Leaf, typename Approximation, std::size_t Dimension>
inline void
l2p(scalfmm::operators::fmm_operators<
scalfmm::operators::near_field_operator<scalfmm::matrix_kernels::laplace::grad_one_over_r<Dimension>>,
scalfmm::operators::far_field_operator<Approximation, true>> const& fmmOperator,
Cell const& source_cell, Leaf& target_leaf, std::size_t order)
// l2p(scalfmm::operators::fmm_operators<
// scalfmm::operators::near_field_operator<scalfmm::matrix_kernels::laplace::grad_one_over_r<Dimension>>,
// scalfmm::operators::far_field_operator<Approximation, true>> const& fmmOperator,
// Cell const& source_cell, Leaf& target_leaf, std::size_t order)
l2p(scalfmm::operators::far_field_operator<Approximation, true> const& far_field, Cell const& source_cell,
Leaf& target_leaf, std::size_t order)
{
const auto& far_field = fmmOperator.far_field();
// const auto& far_field = fmmOperator.far_field();
apply_l2p_der<true>(far_field, source_cell.clocals(), target_leaf, order);
}
} // namespace scalfmm::operators::laplace
} // namespace scalfmm::operators
#endif
......@@ -61,8 +61,7 @@ void test_l2p(std::size_t order)
// specific laplace kernels combination.
interpolator_type interpolator(far_matrix_kernel_type{}, order, tree_height, box_width);
far_field_type far_field(interpolator);
near_field_type near_field(near_matrix_kernel_type{});
fmm_operator_type fmm_operator(near_field, far_field);
//
container::point<value_type, dimension> center{utils::get_center<value_type, dimension>()};
......@@ -120,7 +119,7 @@ void test_l2p(std::size_t order)
});
// we call the operator
operators::l2p(fmm_operator, cell, leaf, order);
operators::l2p(far_field, cell, leaf, order);
auto const& particles = leaf.cparticles();
auto particle_begin = particles.begin();
......
Supports Markdown
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