1#ifndef COMMA_PROJECT_SEEDS_POOL_H
2#define COMMA_PROJECT_SEEDS_POOL_H
42 typename CoMMAIndexType,
43 typename CoMMAWeightType,
44 typename CoMMAIntType>
52 std::set<CoMMAPairType, CustomPairGreaterFunctor<CoMMAPairType>>;
70 const std::vector<CoMMAWeightType> &priority_weights,
71 const std::vector<CoMMAIntType> &n_bnd_faces,
72 const CoMMAIntType max_bnd,
84 typename CoMMAIndexType,
85 typename CoMMAWeightType,
86 typename CoMMAIntType>
114 const std::vector<CoMMAWeightType> &priority_weights,
115 const std::vector<CoMMAIntType> &n_bnd_faces,
116 const CoMMAIntType max_bnd,
122 for (
auto i_fc =
decltype(n_bnd_faces.size()){0}; i_fc < n_bnd_faces.size();
124 if (n_bnd_faces[i_fc] >= max_bnd)
125 tmp_set.emplace(i_fc, priority_weights[i_fc]);
127 for (
const auto &idx : tmp_set)
128 queue.push_back(idx.first);
139 typename CoMMAIndexType,
140 typename CoMMAWeightType,
141 typename CoMMAIntType>
143 public SPInitializator<CoMMAIndexType, CoMMAWeightType, CoMMAIntType> {
169 const std::vector<CoMMAWeightType> &priority_weights,
170 const std::vector<CoMMAIntType> &n_bnd_faces,
171 const CoMMAIntType max_bnd,
175 std::numeric_limits<CoMMAIndexType>::max(),
176 std::numeric_limits<CoMMAWeightType>::min()
179 for (
auto i_fc =
decltype(n_bnd_faces.size()){0}; i_fc < n_bnd_faces.size();
182 if (n_bnd_faces[i_fc] >= max_bnd && comp_op(cur_pair, cur_max))
183 cur_max = std::move(cur_pair);
185 queue.push_back(cur_max.first);
197 typename CoMMAIndexType,
198 typename CoMMAWeightType,
199 typename CoMMAIntType>
209 using CoMMAContainerPairType = std::deque<CoMMAPairType>;
215 CoMMAContainerPairType,
222 std::set<CoMMAPairType, CustomPairGreaterFunctor<CoMMAPairType>>;
257 const std::vector<CoMMAIntType> &n_bnd_faces,
258 const std::vector<CoMMAWeightType> &priority_weights,
259 const bool one_point_init
287 const std::vector<bool> &is_fc_agglomerated,
CoMMAQueueType &queue
291 for (; !queue.empty() && is_fc_agglomerated[queue.front()];
292 queue.pop_front()) {}
293 if (!queue.empty()) {
294 const auto seed = queue.front();
307 const std::vector<bool> &is_agglomerated
316 virtual void update(
const std::deque<CoMMAIndexType> &new_seeds) = 0;
324 const std::unordered_set<CoMMAIndexType> &new_seeds
336 const std::vector<bool> &is_fc_agglomerated,
const CoMMAIntType target
343 if (!is_fc_agglomerated[i_fc] &&
_n_bnd_faces[i_fc] == target)
346 for (
const auto &idx : tmp_set)
360 const std::vector<bool> &is_fc_agglomerated,
363 std::optional<CoMMAIntType> max_bnd = std::nullopt;
367 if (!is_fc_agglomerated[i_fc]) {
369 if (!max_bnd.has_value()) max_bnd = i_fc_bnd;
370 if (i_fc_bnd >= expected_max) {
373 if (i_fc_bnd > max_bnd) {
424 this->_priority_weights,
426 this->_cur_top_queue.value(),
427 this->_l_of_seeds[this->_cur_top_queue.value()]
435 this->_cur_top_queue = q_lvl;
448 typename CoMMAIndexType,
449 typename CoMMAWeightType,
450 typename CoMMAIntType>
452 public Seeds_Pool<CoMMAIndexType, CoMMAWeightType, CoMMAIntType> {
471 const std::vector<CoMMAIntType> &n_bnd_faces,
472 const std::vector<CoMMAWeightType> &priority_weights,
473 const bool one_point_init
475 Seeds_Pool<CoMMAIndexType, CoMMAWeightType, CoMMAIntType>(
476 n_bnd_faces, priority_weights, one_point_init
488 const std::vector<bool> &is_agglomerated
501 if (opt_seed.has_value())
return opt_seed.value();
505 if (opt_top.has_value()) {
506 const auto cur_queue = opt_top.value();
511 if (opt_seed.has_value())
return opt_seed.value();
517 const auto seed = this->
_l_of_seeds[cur_queue].front();
533 inline void update(
const std::deque<CoMMAIndexType> &new_seeds)
override {
534 if (!new_seeds.empty()) {
535 CoMMAIntType max_bnd{0};
536 for (
const auto &seed : new_seeds) {
538 if (n_bnd > max_bnd) max_bnd = n_bnd;
544 || max_bnd > this->_cur_top_queue.value())
555 const std::unordered_set<CoMMAIndexType> &new_seeds
557 std::map<CoMMAIntType, CoMMASetOfPairType, std::greater<>> new_seeds_by_bnd;
558 if (!new_seeds.empty()) {
559 for (
const auto seed : new_seeds) {
564 const auto max_bnd = new_seeds_by_bnd.begin()->first;
566 || max_bnd > this->_cur_top_queue.value())
568 for (
const auto &[n_bnd, seeds] : new_seeds_by_bnd) {
574 std::back_inserter(this->_l_of_seeds[n_bnd]),
575 [](
const auto &pr) { return pr.first; }
591 if (max_bnd.has_value() && max_bnd.value() > this->_cur_top_queue.value()) {
608 typename CoMMAIndexType,
609 typename CoMMAWeightType,
610 typename CoMMAIntType>
612 public Seeds_Pool<CoMMAIndexType, CoMMAWeightType, CoMMAIntType> {
631 const std::vector<CoMMAIntType> &n_bnd_faces,
632 const std::vector<CoMMAWeightType> &priority_weights,
633 const bool one_point_init
635 Seeds_Pool<CoMMAIndexType, CoMMAWeightType, CoMMAIntType>(
636 n_bnd_faces, priority_weights, one_point_init
648 const std::vector<bool> &is_agglomerated
659 + (this->_l_of_seeds.size() - (this->_cur_top_queue.value() + 1));
660 queue != this->_l_of_seeds.rend();
662 const auto opt_seed = this->
spoil_queue(is_agglomerated, *queue);
663 if (opt_seed.has_value()) {
665 return opt_seed.value();
673 if (opt_top.has_value()) {
674 const auto cur_queue = opt_top.value();
677 const auto opt_seed =
679 if (opt_seed.has_value())
return opt_seed.value();
685 const auto seed = this->
_l_of_seeds[cur_queue].front();
701 inline void update(
const std::deque<CoMMAIndexType> &new_seeds)
override {
702 for (
const auto &seed : new_seeds) {
720 const std::unordered_set<CoMMAIndexType> &new_seeds
722 std::map<CoMMAIntType, CoMMASetOfPairType, std::greater<>> new_seeds_by_bnd;
723 for (
const auto &seed : new_seeds) {
728 for (
auto &[n_bnd, seeds] : new_seeds_by_bnd) {
739 std::back_inserter(this->_l_of_seeds[q_lvl]),
740 [](
const auto &pr) { return pr.first; }
#define CoMMAUnused(var)
Convenient function to avoid unused warnings.
Definition: Util.h:38
Class representing the pool of all the seeds for creating a coarse cell. This derived class gives hig...
Definition: Seeds_Pool.h:452
void order_new_seeds_and_update(const std::unordered_set< CoMMAIndexType > &new_seeds) override
Add the provided seeds to a seeds pool queue according to the number of boundary faces....
Definition: Seeds_Pool.h:554
bool need_initialization(const std::vector< bool > &is_agglomerated) override
Whether the seeds pool need to be initialized. It updates the top queue if necessary.
Definition: Seeds_Pool.h:587
Seeds_Pool_Boundary_Priority(const std::vector< CoMMAIntType > &n_bnd_faces, const std::vector< CoMMAWeightType > &priority_weights, const bool one_point_init)
Constructor.
Definition: Seeds_Pool.h:470
~Seeds_Pool_Boundary_Priority() override=default
Destructor.
void update(const std::deque< CoMMAIndexType > &new_seeds) override
Add the provided seeds to a seeds pool queue according to the number of boundary faces....
Definition: Seeds_Pool.h:533
std::optional< CoMMAIndexType > choose_new_seed(const std::vector< bool > &is_agglomerated) override
Choose a new seed in the pool.
Definition: Seeds_Pool.h:487
Class representing the pool of all the seeds for creating a coarse cell. This derived class gives hig...
Definition: Seeds_Pool.h:612
std::optional< CoMMAIndexType > choose_new_seed(const std::vector< bool > &is_agglomerated) override
Choose a new seed in the pool.
Definition: Seeds_Pool.h:647
bool need_initialization(const std::vector< bool > &is_agglomerated) override
Whether the seeds pool need to be initialized.
Definition: Seeds_Pool.h:749
Seeds_Pool_Neighbourhood_Priority(const std::vector< CoMMAIntType > &n_bnd_faces, const std::vector< CoMMAWeightType > &priority_weights, const bool one_point_init)
Constructor.
Definition: Seeds_Pool.h:630
~Seeds_Pool_Neighbourhood_Priority() override=default
Destructor.
void order_new_seeds_and_update(const std::unordered_set< CoMMAIndexType > &new_seeds) override
Add the provided seeds to a seeds pool queue according to the number of boundary faces....
Definition: Seeds_Pool.h:719
void update(const std::deque< CoMMAIndexType > &new_seeds) override
Add the provided seeds to a seeds pool queue according to the number of boundary faces.
Definition: Seeds_Pool.h:701
Class representing the pool of all the seeds for creating a coarse cell.
Definition: Seeds_Pool.h:200
virtual bool need_initialization(const std::vector< bool > &is_agglomerated)=0
Whether the seeds pool need to be initialized.
std::vector< CoMMAQueueType > _l_of_seeds
List of deque of seeds. For each identifier we have the available seeds. We want the seed to be chose...
Definition: Seeds_Pool.h:229
std::optional< CoMMAIntType > get_highest_n_bnd_yet_to_agglomerate(const std::vector< bool > &is_fc_agglomerated, const CoMMAIntType expected_max=CoMMACellT::CORNER) const
Compute the highest number of boundary faces of cells which are not agglomerated yet.
Definition: Seeds_Pool.h:359
const std::vector< CoMMAWeightType > & _priority_weights
Weights used to set the order of the seed to choose.
Definition: Seeds_Pool.h:232
Seeds_Pool(const std::vector< CoMMAIntType > &n_bnd_faces, const std::vector< CoMMAWeightType > &priority_weights, const bool one_point_init)
Constructor.
Definition: Seeds_Pool.h:256
virtual std::optional< CoMMAIndexType > choose_new_seed(const std::vector< bool > &is_agglomerated)=0
Choose a new seed in the pool.
bool is_empty(CoMMAIntType i_level=CoMMACellT::N_CELL_TYPES) const
Given the default levels we define if the list of the targeted level is empty.
Definition: Seeds_Pool.h:385
std::pair< CoMMAIndexType, CoMMAWeightType > CoMMAPairType
Type of pair.
Definition: Seeds_Pool.h:203
virtual ~Seeds_Pool()=default
Destructor.
void initialize()
Initialize the seeds pool via a call to its initializator.
Definition: Seeds_Pool.h:418
virtual void update(const std::deque< CoMMAIndexType > &new_seeds)=0
Add the provided seeds to a seeds pool queue according to the number of boundary faces.
std::set< CoMMAPairType, CustomPairGreaterFunctor< CoMMAPairType > > CoMMASetOfPairType
Type of set of pairs.
Definition: Seeds_Pool.h:222
std::optional< CoMMAIntType > _cur_top_queue
Optional possibly containing the level (0,1,2,3, see Seeds_Pool::_l_of_seeds) of the queue currently ...
Definition: Seeds_Pool.h:237
std::optional< CoMMAIndexType > spoil_queue(const std::vector< bool > &is_fc_agglomerated, CoMMAQueueType &queue)
Spoil a queue looking for an not-yet-agglomerated seed.
Definition: Seeds_Pool.h:286
void set_top_queue(const CoMMAIntType q_lvl)
Setter for the top queue member.
Definition: Seeds_Pool.h:434
std::deque< CoMMAIndexType > CoMMAQueueType
Type of queue which holds seeds.
Definition: Seeds_Pool.h:219
std::shared_ptr< SPInitializator< CoMMAIndexType, CoMMAWeightType, CoMMAIntType > > _initializator
Pointer to a SPInitializator.
Definition: Seeds_Pool.h:242
virtual void order_new_seeds_and_update(const std::unordered_set< CoMMAIndexType > &new_seeds)=0
Add the provided seeds to a seeds pool queue according to the number of boundary faces....
void build_queue(const std::vector< bool > &is_fc_agglomerated, const CoMMAIntType target)
Build the weight-ordered queue of seed for a given target level. A set of (index, weight) pair with s...
Definition: Seeds_Pool.h:335
const std::vector< CoMMAIntType > & _n_bnd_faces
Vector of number of faces on boundary per cell.
Definition: Seeds_Pool.h:246
Definition: Agglomerator.h:37
@ N_CELL_TYPES
Total number of values.
Definition: CoMMADefs.h:31
@ CORNER
Corners, three boundary faces.
Definition: CoMMADefs.h:28
@ VALLEY
Valley, one boundary face.
Definition: CoMMADefs.h:26
@ RIDGE
Ridge, two boundary faces.
Definition: CoMMADefs.h:27
@ INTERIOR
Interior cell, no boundary faces.
Definition: CoMMADefs.h:25
Functor for pairs implementing a custom 'greater than'. It relies on the 'greater than' operator for ...
Definition: Util.h:201
Functor for pairs implementing a custom 'less than'. It relies on the 'less than' operator for the se...
Definition: Util.h:178
Functor performing the full initialization of a seeds pool.
Definition: Seeds_Pool.h:88
SPFullInitializator()
Constructor.
Definition: Seeds_Pool.h:98
~SPFullInitializator() override=default
Destructor.
void operator()(const std::vector< CoMMAWeightType > &priority_weights, const std::vector< CoMMAIntType > &n_bnd_faces, const CoMMAIntType max_bnd, CoMMAQueueType &queue) override
Initialize a queue of a seeds pool.
Definition: Seeds_Pool.h:113
std::set< CoMMAPairType, CustomPairGreaterFunctor< CoMMAPairType > > CoMMASetOfPairType
Type of set of pairs.
Definition: Seeds_Pool.h:52
std::deque< CoMMAIndexType > CoMMAQueueType
Type of queue which holds seeds.
Definition: Seeds_Pool.h:49
Functor performing the initialization of a seeds pool.
Definition: Seeds_Pool.h:45
std::pair< CoMMAIndexType, CoMMAWeightType > CoMMAPairType
Type of pair.
Definition: Seeds_Pool.h:47
virtual ~SPInitializator()=default
Destructor.
SPInitializator()=default
Constructor.
virtual void operator()(const std::vector< CoMMAWeightType > &priority_weights, const std::vector< CoMMAIntType > &n_bnd_faces, const CoMMAIntType max_bnd, CoMMAQueueType &queue)=0
Initialize a queue of a seeds pool.
std::set< CoMMAPairType, CustomPairGreaterFunctor< CoMMAPairType > > CoMMASetOfPairType
Type of set of pairs.
Definition: Seeds_Pool.h:52
std::deque< CoMMAIndexType > CoMMAQueueType
Type of queue which holds seeds.
Definition: Seeds_Pool.h:49
Functor performing the one-point initialization of a seeds pool.
Definition: Seeds_Pool.h:143
std::pair< CoMMAIndexType, CoMMAWeightType > CoMMAPairType
Type of pair.
Definition: Seeds_Pool.h:47
void operator()(const std::vector< CoMMAWeightType > &priority_weights, const std::vector< CoMMAIntType > &n_bnd_faces, const CoMMAIntType max_bnd, CoMMAQueueType &queue) override
Initialize a queue of a seeds pool.
Definition: Seeds_Pool.h:168
~SPOnePointInitializator() override=default
Destructor.
SPOnePointInitializator()
Constructor.
Definition: Seeds_Pool.h:153
std::deque< CoMMAIndexType > CoMMAQueueType
Type of queue which holds seeds.
Definition: Seeds_Pool.h:49