Commit c9c0457e authored by DUFOYER Benjamin's avatar DUFOYER Benjamin

Adding information in BlockedLinearInformation

parent b562c0b3
......@@ -5,13 +5,18 @@
#include "../../Utils/FLog.hpp"
#include "FDistributedGroupTreeBuilder.hpp"
using FReal = double;
template<class node_t>
class FBlockedLinearTree {
protected:
const int block_size;
int nb_leaf;
const FPoint<FReal> box_center;
const FReal box_width;
int nb_block;
std::vector<node_t>* linear_tree;
......@@ -30,18 +35,33 @@ public:
* @param in_linear_tree current linear_tree
* @param in_block_size block_size needed
*/
FBlockedLinearTree(const int in_block_size ,std::vector<node_t>* in_linear_tree):
FBlockedLinearTree(const int in_block_size ,std::vector<node_t>* in_linear_tree
, FPoint<FReal> in_box_center, FReal in_box_width):
block_size(in_block_size),
nb_leaf((int)in_linear_tree->size())
nb_leaf((int)in_linear_tree->size()),
box_center(in_box_center),
box_width(in_box_width)
{
if(nb_leaf%block_size == 0)
this->nb_block = nb_leaf/block_size;
else
this->nb_block = nb_leaf/block_size+1;
init_blocked_linear_tree(in_linear_tree);
}
std::swap(in_linear_tree,linear_tree);
template<class Box>
FBlockedLinearTree(const int in_block_size, std::vector<node_t>* in_linear_tree,const Box box,int dim = 3):
block_size(in_block_size),
nb_leaf((int)in_linear_tree->size()),
box_center(box.center()),
box_width(box.width(dim))
{
init_blocked_linear_tree(in_linear_tree);
}
void init_blocked_linear_tree(std::vector<node_t>* in_linear_tree){
if(this->nb_leaf%this->block_size == 0)
this->nb_block = this->nb_leaf/this->block_size;
else
this->nb_block = this->nb_leaf/this->block_size+1;
std::swap(in_linear_tree,this->linear_tree);
}
////////////////////////////////////////////////
// destructor
////////////////////////////////////////////////
......@@ -97,21 +117,33 @@ public:
* @param num_block number of the block
* @return size of the block
*/
int get_block_size_at(int num_block) {
int get_block_size_at(int num_block) const{
FAssertLF(num_block < this->nb_block);
int size;
if(num_block < this->nb_block){
if(num_block == this->nb_block-1){
size = this->nb_leaf - ((this->nb_block-1)*this->block_size);
} else {
size = this->block_size;
}
if(num_block == this->nb_block-1){
size = this->nb_leaf - ((this->nb_block-1)*this->block_size);
} else {
FLOG(FLog::Controller << "[ERROR][FBlockedLinearTree] Trying to access to undefined block, returning block_size " << "\n");
size = this->block_size;
}
return size;
}
int get_idx_first_cell_for_block(int num_block){
FAssertLF(num_block < this->nb_block);
return this->block_size * num_block;
}
int get_idx_last_cell_for_block(int num_block){
FAssertLF(num_block < this->nb_block);
int last;
//if it's the last block
if(num_block == (this->nb_block-1))
last = nb_leaf-1;
else
last = (this->block_size * (num_block+1))-1;
return last;
}
/**
* get_leaf_at return the leaf at the position placed in parameter
* @author benjamin.dufoyer@inria.fr
......@@ -119,20 +151,18 @@ public:
* @return the leaf
*/
node_t get_leaf_at(int position){
node_t leaf;
if(position < this->nb_leaf && position >= 0) {
leaf = this->linear_tree->at(position);
} else {
FLOG(FLog::Controller << "[ERROR][FBlockedLinearTree] Trying to access to undefined leaf " << "\n");
leaf = this->linear_tree->front();
}
return leaf;
FAssertLF(position < this->nb_leaf && position >=0);
return this->linear_tree->at(position);
}
size_t get_leaf_level(){
size_t get_leaf_level() const{
return this->linear_tree->front().level;
}
size_t get_tree_height() const{
return this->get_leaf_level();
}
size_t get_first_morton_index(){
return this->linear_tree->front().morton_index;
}
......@@ -150,6 +180,14 @@ public:
}
}
FPoint<FReal> get_box_center() const{
return this->box_center;
}
FReal get_box_width() const {
return this->box_width;
}
};
#endif //_FBLOCKED_LINEAR_TREE_HPP_
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