Commit 7b9b7677 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

test_l2p can use either uniform or Chebychev interpolators (--cheb parameters)

parent 57601dcd
#include "parameters.hpp"
#include <iostream>
#include <string>
#include "parameters.hpp"
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/container/point.hpp"
......@@ -12,27 +16,15 @@
#include "scalfmm/tree/cell.hpp"
#include "scalfmm/tree/group_tree.hpp"
#include "scalfmm/tree/leaf.hpp"
#include "scalfmm/meta/is_valid.hpp"
#include "scalfmm/meta/type_pack.hpp"
#include "scalfmm/meta/utils.hpp"
#include "scalfmm/tools/fma_loader.hpp"
#include "scalfmm/utils/timer.hpp"
#include <array>
#include <bits/c++config.h>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <thread>
#include <tuple>
#include <unistd.h>
#include <utility>
#include <vector>
// /examples/RelWithDebInfo/test_l2p --input-file ../data/datal2p_10.fma --order 4
/// For uniform
/// examples/RelWithDebInfo/test_l2p --input-file ../data/datal2p_10.fma --order 4
///
/// For cheb
/// examples/RelWithDebInfo/test_l2p --input-file ../data/datal2p_10.fma --order 4
using value_type = double;
namespace functions {
......@@ -66,55 +58,26 @@ auto dery_poly = [](const value_type& x, const value_type& y, const value_type&
auto derz_poly = [](const value_type& x, const value_type& y, const value_type& z) -> value_type
{ return value_type(4.0)*std::pow(z+1,3); };
}
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
template <typename far_field_type>
auto run(const std::string& title, const std::string& input_file, const int &tree_height, const int & group_size, const int & order) -> int
{
// Parameter handling
args::cli.parse(argc, argv);
command_line_parameters params(args::cli);
std::cout << scalfmm::colors::blue << "Entering tree test...\n" << scalfmm::colors::reset;
// Getting command line parameters
const auto tree_height{params.tree_height};
std::cout << scalfmm::colors::blue << "<params> Tree height : " << tree_height << scalfmm::colors::reset << '\n';
const auto group_size{params.block_size};
std::cout << scalfmm::colors::blue << "<params> Group Size : " << group_size << scalfmm::colors::reset << '\n';
const auto input_file{params.input_file};
if(!input_file.empty())
{
std::cout << scalfmm::colors::blue << "<params> Input file : " << input_file << scalfmm::colors::reset << '\n';
}
const auto output_file{params.output_file};
if(!output_file.empty())
{
std::cout << scalfmm::colors::blue << "<params> Output file : " << output_file << scalfmm::colors::reset
<< '\n';
}
std::cout << "run: " << title << std::endl;
static constexpr std::size_t dimension = 3;
const auto order{params.order};
std::cout << scalfmm::colors::blue << "<params> Runtime order : " << order << scalfmm::colors::reset << '\n';
// Open particle file
std::size_t number_of_particles{};
scalfmm::utils::timer time{};
// ---------------------------------------
// scalfmm 3.0 tree tests and benchmarks.
// ---------------------------------------
using matrix_kernel_type = scalfmm::matrix_kernels::laplace::one_over_r;
using matrix_kernel_type =
typename far_field_type::approximation_type::matrix_kernel_type;
using interpolator_type = typename far_field_type::approximation_type;
static constexpr std::size_t nb_inputs{matrix_kernel_type::km};
static constexpr std::size_t nb_outputs{matrix_kernel_type::kn};
// Number of output p + force
static constexpr std::size_t nb_outputs_leaf{nb_outputs+dimension };
using interpolator_type = scalfmm::interpolation::uniform_interpolator<value_type, dimension, matrix_kernel_type>;
using interpolator_type2 = scalfmm::interpolation::chebyshev_interpolator<value_type, dimension, matrix_kernel_type>;
using far_field_type = scalfmm::operators::far_field_operator<interpolator_type, true>;
using far_field_type2 = scalfmm::operators::far_field_operator<interpolator_type2, true>;
// pos, charge, pot + forces no variables
using particle_type =
......@@ -143,7 +106,6 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
number_of_particles = loader.getNumberOfParticles();
box_width = loader.getBoxWidth();
std::cout << scalfmm::colors::green << "Box center = " << box3_center << scalfmm::colors::reset << '\n';
time.tic();
// point3_type cornerMin{100.0, 100.0,100.0},cornerMax{};
container_type container(number_of_particles);
......@@ -172,54 +134,33 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
}
loader.close();
// }
time.tac();
std::cout << scalfmm::colors::green << "... Done.\n" << scalfmm::colors::reset;
std::cout << scalfmm::colors::yellow << "Container loaded in " << time.elapsed() << "s\n"
std::cout << scalfmm::colors::yellow << "Container loaded \n"
<< scalfmm::colors::reset;
time.tic();
box_type box(box_width, box3_center);
group_tree_type gtree(static_cast<std::size_t>(tree_height), order, box, static_cast<std::size_t>(group_size),
container);
time.tac();
std::cout << scalfmm::colors::yellow << "Group tree created in " << time.elapsed() << "s\n"
<< scalfmm::colors::reset;
// gtree3.trace();
time.tic();
/////////////////////////////////////////////////////////////////////////////////////////////////
//// construct the interpolateor and the far-field
///
interpolator_type uniform(matrix_kernel_type{}, order,
interpolator_type interpolator(matrix_kernel_type{}, order,
static_cast<std::size_t>(tree_height),
box.width(0));
far_field_type far_uniform(uniform);
std::cout << " Start Cheb " << std::endl;
interpolator_type2 cheb(matrix_kernel_type{}, order,
static_cast<std::size_t>(tree_height),
box.width(0));
far_field_type far_field(interpolator);
auto roots2_1d = cheb.roots(static_cast<std::size_t>(order));
std::cout << "roots: " << roots2_1d << std::endl;
interpolator_type2 chebychev(matrix_kernel_type{}, order,
static_cast<std::size_t>(tree_height),
box.width(0));
far_field_type2 far_cheb(chebychev);
///
/////////////////////////////////////////////////////////////////////////////
time.tac();
std::cout << scalfmm::colors::yellow << "Kernel and Interp created in " << time.elapsed() << "s\n"
<< scalfmm::colors::reset;
{
std::cout << std::endl << " &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& " << std::endl;
std::cout << std::scientific;
std::cout.precision(15);
//
auto roots_1d = uniform.roots(static_cast<std::size_t>(order));
auto roots_1d = interpolator.roots(static_cast<std::size_t>(order));
std::cout << "roots: " << roots_1d <<std::endl;
......@@ -234,7 +175,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
scalfmm::component::for_each_cell_leaf(
std::begin(gtree), std::end(gtree), static_cast<std::size_t>(tree_height),
[&pos, &order, &roots_x, &roots_y, &roots_z, &global_idx, &far_uniform](auto& cell, auto& leaf) {
[&pos, &order, &roots_x, &roots_y, &roots_z, &global_idx, &far_field](auto& cell, auto& leaf) {
auto func = functions::poly;
auto derx_func = functions::derx_poly;
......@@ -270,7 +211,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
// Apply the l2p operator
/// farfield operator
///
scalfmm::operators::apply_l2p_der<far_field_type::compute_gradient>(far_uniform, cell.clocals(), leaf, order);
scalfmm::operators::apply_l2p_der<far_field_type::compute_gradient>(far_field, cell.clocals(), leaf, order);
// for the next call nb_outputs_leaf = nb_outputs + dimension;
//scalfmm::operators::apply_l2p(far_uniform, cell.clocals(), leaf, order);
//
......@@ -318,3 +259,77 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
}
return 0;
}
struct chebInterp {
/// Unused type, mandatory per interface specification
using type = bool;
/// The parameter is a flag, it doesn't expect a following value
enum { flagged };
inria::tcli::str_vec flags = {
"--cheb",
};
std::string description = "Use Chebychev interpolator raher than uniform one";
};
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
// Parameter handling
auto parser = inria::tcli::make_parser(args::tree_height{}, args::order{},
args::input_file{}, chebInterp{},
inria::tcli::help{});
parser.parse(argc, argv);
std::cout << scalfmm::colors::blue << "Entering tree test...\n"
<< scalfmm::colors::reset;
const int tree_height{parser.get<args::tree_height>()};
std::cout << scalfmm::colors::blue << "<params> Tree height : " << tree_height
<< scalfmm::colors::reset << '\n';
const int group_size{1};
std::cout << scalfmm::colors::blue << "<params> Group Size : " << group_size
<< scalfmm::colors::reset << '\n';
const std::string input_file{parser.get<args::input_file>()};
if (!input_file.empty()) {
std::cout << scalfmm::colors::blue << "<params> Input file : " << input_file
<< scalfmm::colors::reset << '\n';
}
const bool useCheb(parser.exists<chebInterp>());
static constexpr std::size_t dimension = 3;
const auto order{parser.get<args::order>()};
std::cout << scalfmm::colors::blue << "<params> Runtime order : " << order
<< scalfmm::colors::reset << '\n';
using matrix_kernel_type = scalfmm::matrix_kernels::laplace::one_over_r;
std::string title;
int val{};
if (useCheb) {
title = " Chebychev interpolator ";
using interpolator_type =
scalfmm::interpolation::chebyshev_interpolator<value_type, dimension,
matrix_kernel_type>;
using far_field_type =
scalfmm::operators::far_field_operator<interpolator_type, true>;
val =
run<far_field_type>(title, input_file, tree_height, group_size, order);
} else {
title = " Equispaced interpolator ";
using interpolator_type =
scalfmm::interpolation::uniform_interpolator<value_type, dimension,
matrix_kernel_type>;
using far_field_type =
scalfmm::operators::far_field_operator<interpolator_type, true>;
val =
run<far_field_type>(title, input_file, tree_height, group_size, order);
}
return val;
}
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