1#ifndef DEC_OPTIMIZER_HPP
2#define DEC_OPTIMIZER_HPP
4#include "Grid/iterators/grid_key_dx_iterator_sub.hpp"
5#include "Grid/iterators/grid_skin_iterator.hpp"
17template <
unsigned int dim>
31template<
unsigned int dim>
49template <
unsigned int dim,
typename Graph>
66 for (
size_t j = 0 ; j < dim ; j++)
68 v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template get<
wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
69 v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template get<
wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
90 for (
size_t k = 0 ; k < q_comb.size() ; k++)
92 for (
size_t j = 0 ; j < dim ; j++)
94 if (w_comb[d].c[j] != 0)
102 for (
size_t j = 0 ; j < q_comb.size() ; j++)
104 size_t id = hyp.
LinId(q_comb[j]);
111 for (
size_t s = 0 ; s < dim ; s++)
114 {v_w.template get<wavefront<dim>::stop>(id)[s] = v_w.template get<
wavefront<dim>::stop>(
id)[s] + w_comb[d].c[s];}
116 {v_w.template get<wavefront<dim>::start>(id)[s] = v_w.template get<
wavefront<dim>::start>(
id)[s] + w_comb[d].c[s];}
133 fill_domain<prp>(graph,
gh.
getBox(),0);
137 for (
int i = 0 ; i < v_w.size() ; i++)
141 fill_domain<prp>(graph,box,1);
169 graph.vertex(
gh.
LinId(gk)).template get<p_sub>() = ids;
196 for (
size_t j = 0 ; j < domains.
size() ; j++)
198 long int gs = graph.vertex(domains.get(j)).template get<p_sub>();
203 domains_new.add(domains.get(j));
210 for (
size_t d = 0 ; d < v_w.size() ; d++)
218 for (
size_t d = 0 ; d < v_w.size() ; d++)
231 long int pid = graph.vertex(
gh.
LinId(gk)).template get<p_sub>();
234 long int pp_id = graph.vertex(
gh.
LinId(gk)).template get<p_id>();
256 domains.swap(domains_new);
280 size_t n_wf = w_comb.size();
287 size_t domain_id = graph.vertex(start_p).template get<p_id>();
288 bool can_expand =
true;
299 for (
size_t d = 0 ; d < n_wf ; d++)
302 size_t n_proc_sub = 0;
305 bool w_can_expand =
true;
320 size_t exp_p = graph.vertex(sub_w_e).template get<p_id>();
323 long int ass = graph.vertex(sub_w_e).template get<p_sub>();
326 w_can_expand &= ((exp_p == domain_id) & (ass < 0));
336 w_can_expand &= (n_proc_sub != 0);
339 can_expand |= w_can_expand;
342 if (w_can_expand ==
true)
345 for (
size_t j = 0 ; j < dim ; j++)
347 v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template get<
wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
348 v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template get<
wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
359 for (
size_t k = 0 ; k < q_comb.size() ; k++)
361 for (
size_t j = 0 ; j < dim ; j++)
363 if (w_comb[d].c[j] != 0)
371 for (
size_t j = 0 ; j < q_comb.size() ; j++)
373 size_t id = hyp.
LinId(q_comb[j]);
381 for (
size_t s = 0 ; s < dim ; s++)
384 {v_w.template get<wavefront<dim>::stop>(id)[s] = v_w.template get<
wavefront<dim>::stop>(
id)[s] + w_comb[d].c[s];}
386 {v_w.template get<wavefront<dim>::start>(id)[s] = v_w.template get<
wavefront<dim>::start>(
id)[s] + w_comb[d].c[s];}
396 for (
size_t i = 0 ; i < dim ; i++)
418 for (
size_t i = 0 ; i < v_w.size() ; i++)
420 for (
size_t j = 0 ; j < dim ; j++)
422 v_w.template get<wavefront<dim>::start>(i)[j] = start_p.
get(j);
423 v_w.template get<wavefront<dim>::stop>(i)[j] = start_p.
get(j);
464 if ((
long int)graph.vertex(
gh.
LinId(gk)).template get<p_id>() ==
id && graph.vertex(
gh.
LinId(gk)).template get<p_sub>() == -1)
503 template <
unsigned int p_sub,
unsigned int p_
id>
size_t optimize(
grid_key_dx<dim> & start_p, Graph & graph,
long int pr_id,
openfpm::vector<
Box<dim,size_t>> & lb,
openfpm::vector<
openfpm::vector<size_t> > & box_nn_processor ,
const Ghost<dim,long int> & ghe ,
const size_t (& bc)[dim],
bool init_sub_id =
true,
size_t sub_id = 0)
522 if (init_sub_id ==
true)
523 fill_domain<p_sub>(graph,
gh.
getBox(),-1);
528 while (v_q.
size() != 0)
540 expand_from_point<p_sub,p_id>(v_q.get(0),graph,box,v_w,w_comb);
546 fill_domain<p_sub>(graph,box,sub_id);
549 add_to_queue<p_sub,p_id>(v_q,v_w,graph,w_comb,pr_id,bc);
574 std::unordered_map<size_t,size_t> map;
576 for (
size_t i = 0 ; i < subs.size() ; i++)
586 auto key = gsi.
get();
588 size_t pp_id = graph.vertex(
gh.
LinId(key)).template get<p_id>();
589 if (pr_id != (
long int)pp_id)
597 box_nn_processor.add();
598 for (
auto it = map.begin(); it != map.end(); ++it )
600 box_nn_processor.last().add(it->first);
645 optimize<p_sub,p_id>(start_p,graph,-1,tmp, box_nn_processor,ghe,bc);
672 optimize<p_sub,p_id>(key_seed,graph,pr_id,lb,box_nn_processor,ghe,bc);
675 construct_box_nn_processor<p_id>(graph,box_nn_processor,lb,ghe,bc,pr_id);
683 fill_domain<p_sub>(graph,
gh.
getBox(),-1);
685 key_seed = search_seed<p_id,p_sub>(graph,pr_id);
690 sub_id = optimize<p_sub,p_id>(key_seed,graph,pr_id,lb,box_nn_processor,ghe,bc,
false,sub_id);
693 key_seed = search_seed<p_id,p_sub>(graph,pr_id);
697 construct_box_nn_processor<p_id>(graph,box_nn_processor,lb,ghe,bc,pr_id);
This class represent an N-dimensional box.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
Box< dim, size_t > & getBox()
Get the box enclosing this Box.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
This class calculate elements of the hyper-cube.
static std::vector< comb< dim > > getCombinations_R(size_t d)
static int negativeFace(int d)
Return the combination of the negative face on direction d.
static size_t LinId(comb< dim > &c)
Linearize the combination.
static int positiveFace(int d)
return the combination of the positive face on direction d
static bool isPositive(size_t d)
isPositive return if the combination d is a positive or a negative
static std::vector< comb< dim > > getCombinations_R(comb< dim > c, int d)
This class take a graph representing the space decomposition and produce a simplified version.
void construct_box_nn_processor(Graph &graph, openfpm::vector< openfpm::vector< size_t > > &box_nn_processor, const openfpm::vector< Box< dim, size_t > > &subs, const Ghost< dim, long int > &ghe, const size_t(&bc)[dim], long int pr_id)
Construct the sub-domain processor list.
void optimize(Graph &graph, long int pr_id, openfpm::vector< Box< dim, size_t > > &lb, openfpm::vector< openfpm::vector< size_t > > &box_nn_processor, const Ghost< dim, long int > &ghe, const size_t(&bc)[dim])
optimize the graph
grid_sm< dim, void > gh
Contain information about the grid size.
void optimize(grid_key_dx< dim > &start_p, Graph &graph, const Ghost< dim, long int > &ghe, const size_t(&bc)[dim])
optimize the graph
void expand_from_point(size_t start_p, Graph &graph, Box< dim, size_t > &box, openfpm::vector< wavefront< dim > > &v_w, std::vector< comb< dim > > &w_comb)
Find the biggest hyper-cube.
dec_optimizer(Graph &g, const size_t(&sz)[dim])
Constructor.
void add_to_queue(openfpm::vector< size_t > &domains, openfpm::vector< wavefront< dim > > &v_w, Graph &graph, std::vector< comb< dim > > &w_comb, long int pr_id, const size_t(&bc)[dim])
Add the boundary domain of id p_id to the queue.
void write_wavefront(Graph &graph, openfpm::vector< wavefront< dim > > &v_w)
Fill the wavefront position.
void expand_one_wf(openfpm::vector< wavefront< dim > > &v_w, std::vector< comb< dim > > &w_comb, size_t d)
Expand one wavefront.
void adjust_others_wf(openfpm::vector< wavefront< dim > > &v_w, HyperCube< dim > &hyp, std::vector< comb< dim > > &w_comb, size_t d)
Adjust the other wavefronts.
size_t optimize(grid_key_dx< dim > &start_p, Graph &graph, long int pr_id, openfpm::vector< Box< dim, size_t > > &lb, openfpm::vector< openfpm::vector< size_t > > &box_nn_processor, const Ghost< dim, long int > &ghe, const size_t(&bc)[dim], bool init_sub_id=true, size_t sub_id=0)
optimize the graph
void InitializeWavefront(grid_key_dx< dim > &start_p, openfpm::vector< wavefront< dim > > &v_w)
Initialize the wavefronts.
grid_key_dx< dim > search_seed(Graph &graph, long int id)
Get the first seed.
void fill_domain(Graph &graph, const Box< dim, size_t > &box, long int ids)
Fill the domain.
The same as grid_key_dx_iterator_sub_p but with periodic boundary.
const grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
Declaration grid_key_dx_iterator_sub.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
const grid_key_dx< dim > & get() const
Get the actual key.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
void zero()
Set to zero the key.
bool isValid()
Check if the key is invalid (all components set to -1)
void invalid()
Set to invalid the key.
__device__ __host__ index_type get(index_type i) const
Get the i index.
bool isNext()
Check if there is the next element.
grid_key_dx< dim > get() const
Get the actual key.
__device__ __host__ grid_key_dx< N > InvLinId(mem_id id) const
Construct.
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Box< N, size_t > getBox() const
Return the box enclosing the grid.
Implementation of 1-D std::vector like structure.
this class represent a wavefront of dimension dim
static const int stop
stop point is the property with id 1 (second property)
static const int start
start point is the property with id 0 (first property)
Position of the element of dimension d in the hyper-cube of dimension dim.
check if T::type and T.data has the same type