CoMMA 1.3.2
A geometric agglomerator for unstructured meshes
Loading...
Searching...
No Matches
Coarse_Cell.h
Go to the documentation of this file.
1#ifndef COMMA_PROJECT_COARSE_CELL_H
2#define COMMA_PROJECT_COARSE_CELL_H
3
4/*
5 * CoMMA
6 *
7 * Copyright © 2024 ONERA
8 *
9 * Authors: Nicolas Lantos, Alberto Remigi, and Riccardo Milani
10 * Contributors: Karim Anemiche
11 *
12 * This Source Code Form is subject to the terms of the Mozilla Public
13 * License, v. 2.0. If a copy of the MPL was not distributed with this
14 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
15 */
16
17#include <memory>
18#include <optional>
19#include <unordered_set>
20#include <utility>
21#include <vector>
22
23#include "CoMMA/Dual_Graph.h"
24
25namespace comma {
26
33template<
34 typename CoMMAIndexType,
35 typename CoMMAWeightType,
36 typename CoMMAIntType>
38public:
41 std::shared_ptr<Dual_Graph<CoMMAIndexType, CoMMAWeightType, CoMMAIntType>>;
42
54 DualGraphPtr fc_graph,
55 CoMMAIndexType i_cc,
56 const std::unordered_set<CoMMAIndexType> &s_fc,
57 CoMMAIntType compactness,
58 bool is_isotropic = true
59 ) :
60 _idx(i_cc),
61 _fc_graph(fc_graph),
62 _compactness(compactness),
63 _cardinality(static_cast<CoMMAIntType>(s_fc.size())),
64 _is_isotropic(is_isotropic),
65 _s_fc(s_fc) {}
66
68 virtual ~Coarse_Cell() = default;
69
72 CoMMAIndexType _idx;
73
76
78 CoMMAIntType _compactness;
79
81 CoMMAIntType _cardinality;
82
85
87 std::unordered_set<CoMMAIndexType> _s_fc;
88
94 inline bool is_connected() { return _compactness > 0; }
95
101 virtual void insert_cell(
102 const CoMMAIndexType i_fc, const std::optional<CoMMAIntType> new_compactness
103 ) {
104 _s_fc.insert(i_fc);
105 ++_cardinality;
106 _compactness = new_compactness.has_value()
107 ? new_compactness.value()
108 : _fc_graph->compute_min_fc_compactness_inside_a_cc(_s_fc);
109 }
110
116 virtual void insert_cells(
117 const std::unordered_set<CoMMAIndexType> &fcs,
118 const std::optional<CoMMAIntType> new_compactness
119 ) {
120 _s_fc.insert(fcs.begin(), fcs.end());
121 _cardinality += fcs.size();
122 _compactness = new_compactness.has_value()
123 ? new_compactness.value()
124 : _fc_graph->compute_min_fc_compactness_inside_a_cc(_s_fc);
125 }
126};
127
136template<
137 typename CoMMAIndexType,
138 typename CoMMAWeightType,
139 typename CoMMAIntType>
141 Coarse_Cell<CoMMAIndexType, CoMMAWeightType, CoMMAIntType> {
142public:
145
147 using typename BaseClass::DualGraphPtr;
148
151
153 using SubGraphPtr = std::shared_ptr<SubGraphType>;
154
166 DualGraphPtr fc_graph,
167 CoMMAIndexType i_cc,
168 const std::unordered_set<CoMMAIndexType> &s_fc,
169 CoMMAIntType compactness,
170 bool is_isotropic = true
171 ) :
172 BaseClass(fc_graph, i_cc, s_fc, compactness, is_isotropic),
173 _is_connected(compactness > 0),
175 // initialization vectors
176 CoMMAIndexType position = 0;
177 std::vector<CoMMAWeightType> volumes;
178 std::vector<CoMMAWeightType> CSR_vals{};
179 std::vector<CoMMAIndexType> CSR_row = {0};
180 std::vector<CoMMAIndexType> CSR_col{};
181 std::vector<CoMMAIndexType> col_ind{};
182 std::vector<CoMMAIndexType> mapping{};
183 for (const CoMMAIndexType &i_fc : this->_s_fc) {
184 // we add to the mapping the i_fc
185 mapping.push_back(i_fc);
186 auto n_it = this->_fc_graph->neighbours_cbegin(i_fc);
187 auto w_it = this->_fc_graph->weights_cbegin(i_fc);
188 for (; n_it != this->_fc_graph->neighbours_cend(i_fc)
189 && w_it != this->_fc_graph->weights_cend(i_fc);
190 ++n_it, ++w_it) {
191 if (std::find(this->_s_fc.begin(), this->_s_fc.end(), *n_it)
192 != this->_s_fc.end()) {
193 ++position;
194 col_ind.push_back(*n_it);
195 CSR_vals.push_back(*w_it);
196 }
197 }
198 CSR_row.push_back(position);
199 volumes.push_back(this->_fc_graph->_volumes[i_fc]);
200 }
201
202 // Map in the local subgraph
203 for (auto it = col_ind.begin(); it != col_ind.end(); ++it) {
204 auto indx = std::find(mapping.begin(), mapping.end(), *it);
205 CSR_col.push_back(indx - mapping.begin());
206 }
207
208 _cc_graph = std::make_shared<SubGraphType>(
209 s_fc.size(), CSR_row, CSR_col, CSR_vals, volumes, mapping, is_isotropic
210 );
211 }
212
219 const CoMMAIndexType i_fc, const std::optional<CoMMAIntType> new_compactness
220 ) override {
221 // As base class...
222 this->_s_fc.insert(i_fc);
223 ++this->_cardinality;
224 this->_compactness = new_compactness.has_value()
225 ? new_compactness.value()
226 : this->_fc_graph->compute_min_fc_compactness_inside_a_cc(this->_s_fc);
227 // ...but now add to the subgraph
228 _cc_graph->insert_node(
229 this->_fc_graph->get_neighbours(i_fc),
230 i_fc,
231 this->_fc_graph->_volumes[i_fc],
232 this->_fc_graph->get_weights(i_fc)
233 );
234 }
235
242 const std::unordered_set<CoMMAIndexType> &fcs,
243 const std::optional<CoMMAIntType> new_compactness
244 ) override {
245 // As base class...
246 this->_s_fc.insert(fcs.begin(), fcs.end());
247 this->_cardinality += fcs.size();
248 this->_compactness = new_compactness.has_value()
249 ? new_compactness.value()
250 : this->_fc_graph->compute_min_fc_compactness_inside_a_cc(this->_s_fc);
251 // ...but now add to the subgraph
252 for (const auto &i_fc : fcs) {
253 _cc_graph->insert_node(
254 this->_fc_graph->get_neighbours(i_fc),
255 i_fc,
256 this->_fc_graph->_volumes[i_fc],
257 this->_fc_graph->get_weights(i_fc)
258 );
259 }
260 }
261
263 inline void update_connectivity() {
264 _is_connected = _cc_graph->check_connectivity();
266 }
267
270
273
276};
277
278} // end namespace comma
279
280#endif // COMMA_PROJECT_COARSE_CELL_H
Class describing a coarse cell with a full description, that is, it also holds a subgraph describing ...
Definition: Coarse_Cell.h:141
SubGraphPtr _cc_graph
Shared pointer of the subgraph structure (CSR representation)
Definition: Coarse_Cell.h:269
void insert_cell(const CoMMAIndexType i_fc, const std::optional< CoMMAIntType > new_compactness) override
Insert a FC in the CC (and update sub-graph if necessary)
Definition: Coarse_Cell.h:218
void update_connectivity()
Analyse subgraph and update the connectivity.
Definition: Coarse_Cell.h:263
std::shared_ptr< Dual_Graph< CoMMAIndexType, CoMMAWeightType, CoMMAIntType > > DualGraphPtr
Type for a shared pointer to a Dual_Graph object.
Definition: Coarse_Cell.h:41
bool _is_connectivity_up_to_date
Whether the connectivity has been checked.
Definition: Coarse_Cell.h:275
void insert_cells(const std::unordered_set< CoMMAIndexType > &fcs, const std::optional< CoMMAIntType > new_compactness) override
Insert several FC in the CC (and update sub-graph if necessary)
Definition: Coarse_Cell.h:241
bool _is_connected
Whether the cell connected.
Definition: Coarse_Cell.h:272
std::shared_ptr< SubGraphType > SubGraphPtr
Type for a shared pointer to a Subgraph object.
Definition: Coarse_Cell.h:153
Coarse_Cell_Subgraph(DualGraphPtr fc_graph, CoMMAIndexType i_cc, const std::unordered_set< CoMMAIndexType > &s_fc, CoMMAIntType compactness, bool is_isotropic=true)
Constructor of the class.
Definition: Coarse_Cell.h:165
Class describing a coarse cell.
Definition: Coarse_Cell.h:37
CoMMAIndexType _idx
Index of the coarse cell (It seems to be unused, but useful to have)
Definition: Coarse_Cell.h:72
CoMMAIntType _cardinality
Number of FC in the CC.
Definition: Coarse_Cell.h:81
std::shared_ptr< Dual_Graph< CoMMAIndexType, CoMMAWeightType, CoMMAIntType > > DualGraphPtr
Type for a shared pointer to a Dual_Graph object.
Definition: Coarse_Cell.h:41
bool _is_isotropic
Whether the cell isotropic or anisotropic.
Definition: Coarse_Cell.h:84
Coarse_Cell(DualGraphPtr fc_graph, CoMMAIndexType i_cc, const std::unordered_set< CoMMAIndexType > &s_fc, CoMMAIntType compactness, bool is_isotropic=true)
Constructor of the class.
Definition: Coarse_Cell.h:53
virtual void insert_cell(const CoMMAIndexType i_fc, const std::optional< CoMMAIntType > new_compactness)
Insert a FC in the CC (and update sub-graph if necessary)
Definition: Coarse_Cell.h:101
std::unordered_set< CoMMAIndexType > _s_fc
Set of fine cells composing the Coarse cell.
Definition: Coarse_Cell.h:87
DualGraphPtr _fc_graph
The global dual graph.
Definition: Coarse_Cell.h:75
CoMMAIntType _compactness
Compactness degree of the CC.
Definition: Coarse_Cell.h:78
bool is_connected()
Method that return a boolean determining if the coarse cell is defined by a connected sub-graph or no...
Definition: Coarse_Cell.h:94
virtual ~Coarse_Cell()=default
Destructor of the class.
virtual void insert_cells(const std::unordered_set< CoMMAIndexType > &fcs, const std::optional< CoMMAIntType > new_compactness)
Insert several FC in the CC (and update sub-graph if necessary)
Definition: Coarse_Cell.h:116
A class implementing the CRS subgraph representation. It is used in the framework of CoMMA for the im...
Definition: Dual_Graph.h:320
Definition: Agglomerator.h:37