Commit 2f6cbb5f authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

rewrite trace function to get info on the tree. Add tikz output for the 2d case

parent fa88e2f4
......@@ -98,7 +98,8 @@ void change_format(const std::string& input_file, bool& use_old_format, const st
if(!visu_file.empty())
{
std::string visufile(visu_file);
scalfmm::tools::exportVTKxml(visufile, particles, Dimension, loader.get_number_of_input_per_record(), NbPoints);
scalfmm::tools::io::exportVTKxml(visufile, particles, Dimension, loader.get_number_of_input_per_record(),
NbPoints);
}
}
......
......@@ -542,7 +542,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
if(dimension < 4)
{
std::string visufile(parser.get<paramGenerate::visu_file>());
scalfmm::tools::exportVTKxml(visufile, data, dimension, number_input_values, nb_particles);
scalfmm::tools::io::exportVTKxml(visufile, data, dimension, number_input_values, nb_particles);
}
else
{
......
......@@ -13,6 +13,8 @@
#include "scalfmm/utils/sort.hpp"
#include "scalfmm/utils/timer.hpp"
#include "scalfmm/interpolation/grid_storage.hpp"
#include "scalfmm/tools/tikz_writer.hpp"
#include <array>
#include <bits/c++config.h>
......@@ -70,7 +72,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
std::cout << scalfmm::colors::blue << "Entering tree test...\n" << scalfmm::colors::reset;
static constexpr std::size_t dimension = 3;
static constexpr std::size_t dimension = 2;
static constexpr std::size_t inputs = 2;
static constexpr std::size_t outputs = 2;
const auto order{parser.get<args::order>()};
......@@ -137,5 +139,10 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
int log_level = 5;
gtree.trace(log_level);
if (dimension == 2) {
std::string tikzName("leaf_" + std::to_string(tree_height-1) + ".tex");
scalfmm::tools::io::exportTIKZ(tikzName, gtree);
}
return 0;
}
// --------------------------------
// See LICENCE file at project root
// File : tools/vtk_writer.hpp
// --------------------------------
#ifndef SCALFMM_TOOLS_TIKZ_WRITER_HPP
#define SCALFMM_TOOLS_TIKZ_WRITER_HPP
#include <fstream>
#include <iostream>
#include <string>
#include "scalfmm/tree/box.hpp"
#include "scalfmm/tree/for_each.hpp"
namespace scalfmm::tools::io {
template <class TREE>
void exportTIKZ(std::string& filename, const TREE& tree) {
std::ofstream out(filename);
out << "\\begin{tikzpicture}[help lines/.style={blue!50,very thin}] "
<< std::endl;
{
auto center = tree.box_center();
auto corner_l = center - tree.box_width()*0.5;
auto corner_u = center + tree.box_width()*0.5;
out << "\\draw[very thin, gray] ( (" << corner_l[0] << ","
<< corner_l[1] << ") rectangle (" << corner_u[0] << "," << corner_u[1]
<< " );" << std::endl;
}
auto half_width = tree.leaf_width()/2.0;
component::for_each(
std::get<0>(tree.begin()), std::get<0>(tree.end()),
[&half_width, &out](auto& group) {
// std::size_t index_in_group{0};
component::for_each(
std::begin(*group), std::end(*group), [&half_width, &out](auto& leaf) {
auto& leaf_symbolics = leaf.symbolics();
auto center = leaf.center();
auto corner_l = center - half_width;
auto corner_u = center + half_width;
out << "\\filldraw[fill=black!40!white] (" << corner_l[0]
<< "," << corner_l[1] << ") rectangle (" << corner_u[0] << ","
<< corner_u[1] << " );" << std::endl;
out << "\\node[scale=0.8] at (" << center[0] << "," << center[1]
<< ") {\\textbf{" << leaf.index() << "}};" << std::endl;
});
});
out << "\\end{tikzpicture}";
out.close();
}
}
#endif
......@@ -9,7 +9,7 @@
#include <iostream>
#include <string>
namespace scalfmm::tools
namespace scalfmm::tools::io
{
std::string writeHeader(const int nb_val, const std::string& name)
{
......@@ -156,5 +156,5 @@ namespace scalfmm::tools
<< "</PolyData>" << std::endl
<< "</VTKFile>" << std::endl;
};
} // namespace scalfmm::tools
} // namespace scalfmm::tools::io
#endif
......@@ -933,11 +933,70 @@ namespace scalfmm::tree
dst.erase(last, dst.end());
return dst;
}
///
/// \brief find the processor owning the index
/// \param[in] index
/// \param[in] distrib the index distribution
/// \param[in] start [optional]position to strat in the distrbution
/// vector \return the process number
///
template<typename MortonIdx, typename MortonDistribution>
inline int find_proc_for_index(const MortonIdx& index, const MortonDistribution& distrib, std::size_t start = 0)
{
for(std::size_t i = start; i < distrib.size(); ++i)
{
if(between(index, distrib[i][0], distrib[i][1]))
{
return i;
}
}
}
template<typename VectorMortonIdx, typename MortonDistribution>
void check_if_morton_index_exist(parallel_manager& para, VectorMortonIdx& needed_idx,
MortonDistribution distrib)
const MortonDistribution distrib, const VectorMortonIdx& local_morton_idx)
{
auto nb_proc = para.get_num_processes();
auto rank = para.get_process_id();
std::cout << "check_if_morton_index_exist in progress \n";
std::vector<int> nb_messages_to_send(nb_proc, 0);
std::vector<int> nb_messages_to_receive(nb_proc, 0);
// beging index to send to process k
std::vector<int> start(nb_proc + 1, 0);
//
// Check the number of messages to send to the processes
int k = 0;
start[nb_proc] = needed_idx.size();
for(std::size_t i = 0; i < needed_idx.size(); ++i)
{
if(needed_idx[i] <= distrib[k][1])
{
nb_messages_to_send[k]++;
}
else
{
k = find_proc_for_index(needed_idx[i], distrib, k);
start[k] = i;
nb_messages_to_send[k]++;
}
}
out::print("rank(" + std::to_string(rank) + ") Nb msg send : ", nb_messages_to_send);
out::print("rank(" + std::to_string(rank) + ") start : ", start);
// exchange the vector all to all to know which process send us a
// message
auto comm = para.get_communicator();
auto mpi_type = inria::mpi::get_datatype<int>();
comm.barrier();
std::cout << "================================================\n";
comm.alltoall(nb_messages_to_send.data(), 1, mpi_type, nb_messages_to_receive.data(), 1, mpi_type);
out::print("rank(" + std::to_string(rank) + ") Nb msg receiv : ", nb_messages_to_receive);
// _to_send
// check if the morton index exist locally
//
// send the existing index
}
} // namespace distrib
......@@ -1013,7 +1072,7 @@ namespace scalfmm::tree
}
std::cout << std::endl;
/// Look if the morton index really exists in the distributed tree
distrib::check_if_morton_index_exist(para, needed_idx);
distrib::check_if_morton_index_exist(para, needed_idx, cells_distrib, local_morton_idx);
///
tree.insert_component_at_level(level, needed_idx);
}
......
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