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"
17 template <
unsigned int dim>
38 template <
unsigned int dim,
typename Graph>
55 for (
size_t j = 0 ; j < dim ; j++)
57 v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template
get<
wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
58 v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template
get<
wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
79 for (
size_t k = 0 ; k < q_comb.size() ; k++)
81 for (
size_t j = 0 ; j < dim ; j++)
83 if (w_comb[d].c[j] != 0)
91 for (
size_t j = 0 ; j < q_comb.size() ; j++)
93 size_t id = hyp.
LinId(q_comb[j]);
100 for (
size_t s = 0 ; s < dim ; s++)
103 {v_w.template get<wavefront<dim>::stop>(id)[s] = v_w.template
get<
wavefront<dim>::stop>(
id)[s] + w_comb[d].c[s];}
105 {v_w.template get<wavefront<dim>::start>(id)[s] = v_w.template
get<
wavefront<dim>::start>(
id)[s] + w_comb[d].c[s];}
122 fill_domain<prp>(graph,
gh.
getBox(),0);
126 for (
int i = 0 ; i < v_w.size() ; i++)
130 fill_domain<prp>(graph,box,1);
151 while (g_sub.isNext())
158 graph.vertex(
gh.
LinId(gk)).
template get<p_sub>() = ids;
185 for (
size_t j = 0 ; j < domains.
size() ; j++)
187 long int gs = graph.vertex(domains.get(j)).
template get<p_sub>();
192 domains_new.add(domains.get(j));
199 for (
size_t d = 0 ; d < v_w.size() ; d++)
207 for (
size_t d = 0 ; d < v_w.size() ; d++)
220 long int pid = graph.vertex(
gh.
LinId(gk)).
template get<p_sub>();
223 long int pp_id = graph.vertex(
gh.
LinId(gk)).
template get<p_id>();
245 domains.swap(domains_new);
269 size_t n_wf = w_comb.size();
276 size_t domain_id = graph.vertex(start_p).template get<p_id>();
277 bool can_expand =
true;
288 for (
size_t d = 0 ; d < n_wf ; d++)
291 size_t n_proc_sub = 0;
294 bool w_can_expand =
true;
309 size_t exp_p = graph.vertex(sub_w_e).template get<p_id>();
312 long int ass = graph.vertex(sub_w_e).template get<p_sub>();
315 w_can_expand &= ((exp_p == domain_id) & (ass < 0));
325 w_can_expand &= (n_proc_sub != 0);
328 can_expand |= w_can_expand;
331 if (w_can_expand ==
true)
334 for (
size_t j = 0 ; j < dim ; j++)
336 v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template
get<
wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
337 v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template
get<
wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
348 for (
size_t k = 0 ; k < q_comb.size() ; k++)
350 for (
size_t j = 0 ; j < dim ; j++)
352 if (w_comb[d].c[j] != 0)
360 for (
size_t j = 0 ; j < q_comb.size() ; j++)
362 size_t id = hyp.
LinId(q_comb[j]);
370 for (
size_t s = 0 ; s < dim ; s++)
373 {v_w.template get<wavefront<dim>::stop>(id)[s] = v_w.template
get<
wavefront<dim>::stop>(
id)[s] + w_comb[d].c[s];}
375 {v_w.template get<wavefront<dim>::start>(id)[s] = v_w.template
get<
wavefront<dim>::start>(
id)[s] + w_comb[d].c[s];}
385 for (
size_t i = 0 ; i < dim ; i++)
407 for (
size_t i = 0 ; i < v_w.size() ; i++)
409 for (
size_t j = 0 ; j < dim ; j++)
411 v_w.template get<wavefront<dim>::start>(i)[j] = start_p.
get(j);
412 v_w.template get<wavefront<dim>::stop>(i)[j] = start_p.
get(j);
453 if ((
long int)graph.vertex(
gh.
LinId(gk)).
template get<p_id>() ==
id && graph.vertex(
gh.
LinId(gk)).
template get<p_sub>() == -1)
492 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)
511 if (init_sub_id ==
true)
512 fill_domain<p_sub>(graph,
gh.
getBox(),-1);
517 while (v_q.
size() != 0)
529 expand_from_point<p_sub,p_id>(v_q.get(0),graph,box,v_w,w_comb);
535 fill_domain<p_sub>(graph,box,sub_id);
538 add_to_queue<p_sub,p_id>(v_q,v_w,graph,w_comb,pr_id,bc);
563 std::unordered_map<size_t,size_t> map;
565 for (
size_t i = 0 ; i < subs.size() ; i++)
575 auto key = gsi.get();
577 size_t pp_id = graph.vertex(
gh.
LinId(
key)).
template get<p_id>();
578 if (pr_id != (
long int)pp_id)
586 box_nn_processor.add();
587 for (
auto it = map.begin(); it != map.end(); ++it )
589 box_nn_processor.last().add(it->first);
634 optimize<p_sub,p_id>(start_p,graph,-1,tmp, box_nn_processor,ghe,bc);
661 optimize<p_sub,p_id>(key_seed,graph,pr_id,lb,box_nn_processor,ghe,bc);
664 construct_box_nn_processor<p_id>(graph,box_nn_processor,lb,ghe,bc,pr_id);
672 fill_domain<p_sub>(graph,
gh.
getBox(),-1);
674 key_seed = search_seed<p_id,p_sub>(graph,pr_id);
676 while (key_seed.isValid())
679 sub_id = optimize<p_sub,p_id>(key_seed,graph,pr_id,lb,box_nn_processor,ghe,bc,
false,sub_id);
682 key_seed = search_seed<p_id,p_sub>(graph,pr_id);
686 construct_box_nn_processor<p_id>(graph,box_nn_processor,lb,ghe,bc,pr_id);
grid_key_dx< dim > search_seed(Graph &graph, long int id)
Get the first seed.
void optimize(grid_key_dx< dim > &start_p, Graph &graph, const Ghost< dim, long int > &ghe, const size_t(&bc)[dim])
optimize the graph
dec_optimizer(Graph &g, const size_t(&sz)[dim])
Constructor.
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.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
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.
static std::vector< comb< dim > > getCombinations_R(size_t d)
grid_key_dx is the key to access any element in the grid
Position of the element of dimension d in the hyper-cube of dimension dim.
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
void invalid()
Set to invalid the key.
const Box< N, size_t > & getBox() const
Return the box enclosing the grid.
static int positiveFace(int d)
return the combination of the positive face on direction d
void setHigh(int i, T val)
set the high interval of the box
grid_sm< dim, void > gh
Contain information about the grid size.
bool isNext()
Check if there is the next element.
grid_key_dx< N > InvLinId(mem_id id) const
Construct.
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
static bool isPositive(size_t d)
isPositive return if the combination d is a positive or a negative
static size_t LinId(comb< dim > &c)
Linearize the combination.
mem_id get(size_t i) const
Get the i index.
void expand_one_wf(openfpm::vector< wavefront< dim >> &v_w, std::vector< comb< dim >> &w_comb, size_t d)
Expand one wavefront.
static const int start
start point is the property with id 0 (first property)
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
The same as grid_key_dx_iterator_sub_p but with periodic boundary.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
void zero()
Set to zero the key.
const grid_key_dx< dim > & get() const
Get the actual key.
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.
void fill_domain(Graph &graph, const Box< dim, size_t > &box, long int ids)
Fill the domain.
void setLow(int i, T val)
set the low interval of the box
bool isNext()
Check if there is the next element.
void write_wavefront(Graph &graph, openfpm::vector< wavefront< dim >> &v_w)
Fill the wavefront position.
This class represent an N-dimensional box.
Box< dim, size_t > & getBox()
Get the box enclosing this Box.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
This class is a trick to indicate the compiler a specific specialization pattern. ...
static const int stop
stop point is the property with id 1 (second property)
This class take a graph representing the space decomposition and produce a simplified version...
Declaration grid_key_dx_iterator_sub.
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.
static std::vector< comb< dim > > getCombinations_R(comb< dim > c, int d)
static int negativeFace(int d)
Return the combination of the negative face on direction d.
This class calculate elements of the hyper-cube.
const grid_key_dx< dim > get() const
Return the actual grid key iterator.
void InitializeWavefront(grid_key_dx< dim > &start_p, openfpm::vector< wavefront< dim >> &v_w)
Initialize the wavefronts.
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
Implementation of 1-D std::vector like structure.
bool isNext()
Check if there is the next element.
this class represent a wavefront of dimension dim