-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_structure.cpp
More file actions
507 lines (494 loc) · 19.4 KB
/
Copy pathtest_structure.cpp
File metadata and controls
507 lines (494 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
* CoMMA
*
* Copyright © 2024 ONERA
*
* Authors: Nicolas Lantos, Alberto Remigi, and Riccardo Milani
* Contributors: Karim Anemiche
*
* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
#define CATCH_CONFIG_MAIN
#include <catch2/catch_test_macros.hpp>
#include <optional>
#include <vector>
#include "CoMMA/Args.h"
#include "CoMMA/CoMMA.h"
#include "CoMMA/CoMMADefs.h"
#include "DualGraphExamples.h"
#include "test_defs.h"
using namespace comma; // NOLINT
using namespace std; // NOLINT
SCENARIO("Test of a structure", "[structure]") {
GIVEN("A simple graph, and we build the Dual Graph") {
const DualGEx Data = DualGEx();
// Construction of the Dual Graph element
shared_ptr<SeedsPoolT> seeds_pool =
make_shared<SeedsPoolT>(Data.n_bnd_faces, Data.weights, false);
shared_ptr<DualGraphT> fc_graph = make_shared<DualGraphT>(
Data.nb_fc,
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.n_bnd_faces,
Data.dim,
Data.anisoCompliantCells
);
shared_ptr<CCContainerT> cc_graph =
make_shared<CCContainerT>(fc_graph, SING_CARD_THRESH);
// Check the effective length
WHEN("We try to access to the member variables") {
class test :
public Agglomerator_Biconnected<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> {
public:
test(
shared_ptr<DualGraphT> &graph,
shared_ptr<CCContainerT> &cc_graph,
shared_ptr<SeedsPoolT> &seeds_pool,
CoMMAIntT dimension
) :
Agglomerator_Biconnected<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
graph,
cc_graph,
seeds_pool,
dimension,
DEFAULT_AR,
CoMMANeighbourhoodT::EXTENDED,
FC_ITER
){};
CoMMAIntT test_variable() { return (this->_threshold_card); }
};
THEN("We see that the agglomeration is not set, hence set to 0") {
test agg = test(fc_graph, cc_graph, seeds_pool, 2);
const CoMMAIntT testing = agg.test_variable();
REQUIRE(testing == 0);
}
}
WHEN("We try to access to Define the cardinality") {
class test :
public Agglomerator_Biconnected<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> {
public:
test(
shared_ptr<DualGraphT> &graph,
shared_ptr<CCContainerT> &cc_graph,
shared_ptr<SeedsPoolT> &seeds_pool,
CoMMAIntT dimension
) :
Agglomerator_Biconnected<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
graph,
cc_graph,
seeds_pool,
dimension,
DEFAULT_AR,
CoMMANeighbourhoodT::EXTENDED,
FC_ITER
){};
CoMMAIntT thres() { return (_threshold_card); }
CoMMAIntT max() { return (_max_card); }
CoMMAIntT min() { return (_min_card); }
};
THEN("We see that the cardinality passes from 0 to 2") {
test agg = test(fc_graph, cc_graph, seeds_pool, 2);
REQUIRE(agg.thres() == 0);
REQUIRE(agg.max() == 0);
REQUIRE(agg.min() == 0);
agg.set_agglomeration_parameter(2, 2, 2);
REQUIRE(agg.thres() == 2);
REQUIRE(agg.max() == 2);
REQUIRE(agg.min() == 2);
}
}
}
}
SCENARIO("Test of main function", "[structure]") {
// The following tests are basically a copy of test_isoagglo but with the
// main function
GIVEN("A simple 4x4 Cartesian mesh") {
const DualGEx_quad_4 Data = DualGEx_quad_4();
const vector<CoMMAIndexT> ref_results(
{0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3}
);
WHEN("We agglomerate with neighbourhood priority") {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = false, build_lines = true,
odd_length = true, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = -4.;
constexpr auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY;
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.anisoCompliantCells,
Data.n_bnd_faces,
build_lines,
is_anisotropic,
odd_length,
aniso_thr,
seed,
fc2cc,
alines_idx,
alines,
correction,
Data.dim,
goal_card,
min_card,
max_card
);
THEN("We obtain the 16 fine cells divided in 4 coarse cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
// It is the same test as above but we use the API with parameter classes
WHEN("We agglomerate with neighbourhood priority and the parameter API") {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = false, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY;
const GraphArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> graph_args(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.n_bnd_faces,
Data.dim
);
const AgglomerationArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> agglo_args(
goal_card, min_card, max_card, correction, seed
);
const AnisotropicArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> aniso_args(
is_anisotropic, Data.anisoCompliantCells
);
// Agglomerate
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
graph_args, agglo_args, aniso_args, fc2cc, alines_idx, alines
);
THEN("We obtain the 16 fine cells divided in 4 coarse cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
WHEN("We agglomerate with boundary priority") {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = false, build_lines = true,
odd_length = true, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = -4.;
constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY;
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.anisoCompliantCells,
Data.n_bnd_faces,
build_lines,
is_anisotropic,
odd_length,
aniso_thr,
seed,
fc2cc,
alines_idx,
alines,
correction,
Data.dim,
goal_card,
min_card,
max_card
);
THEN("We obtain the 16 fine cells divided in 4 coarse cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
WHEN("We agglomerate with neighbourhood priority one point initialization"
) {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = false, build_lines = true,
odd_length = true, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = -4.;
constexpr auto seed =
CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY_ONE_POINT_INIT;
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.anisoCompliantCells,
Data.n_bnd_faces,
build_lines,
is_anisotropic,
odd_length,
aniso_thr,
seed,
fc2cc,
alines_idx,
alines,
correction,
Data.dim,
goal_card,
min_card,
max_card
);
THEN("We obtain the 16 fine cells divided in 4 coarse cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
WHEN("We agglomerate with boundary priority one point initialization") {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = false, build_lines = true,
odd_length = true, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = -4.;
constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY_ONE_POINT_INIT;
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.anisoCompliantCells,
Data.n_bnd_faces,
build_lines,
is_anisotropic,
odd_length,
aniso_thr,
seed,
fc2cc,
alines_idx,
alines,
correction,
Data.dim,
goal_card,
min_card,
max_card
);
THEN("We obtain the 16 fine cells divided in 4 coarse cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
}
GIVEN("a 4by7 quad 2D mesh which has 4 anisotropic lines") {
const DualGEx_aniso_3cell Data = DualGEx_aniso_3cell();
const vector<CoMMAIndexT> ref_results({0, 0, 1, 1, 1, 8, 8, 3, 3, 3,
2, 2, 5, 5, 4, 5, 4, 9, 9, 7,
6, 7, 6, 7, 8, 8, 9, 9});
// The following tests are basically a copy of test_isoagglo but with the
// main function
WHEN(
"We agglomerate with anisotropy activated, boundary priority and, full initialization"
) {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = true, build_lines = true,
odd_length = ODD_LINE_LENGTH, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = 4.;
constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY;
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.anisoCompliantCells,
Data.n_bnd_faces,
build_lines,
is_anisotropic,
odd_length,
aniso_thr,
seed,
fc2cc,
alines_idx,
alines,
correction,
Data.dim,
goal_card,
min_card,
max_card
);
THEN("The result is 4 anisotropic lines and 2 isotropic cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
WHEN(
"We agglomerate with anisotropy activated, boundary priority and, full initialization using the parameter classes"
) {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = true, build_lines = true,
odd_length = ODD_LINE_LENGTH, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = 4.;
constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY;
const GraphArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> graph_args(
Data.adjMatrix_row_ptr,
Data.adjMatrix_col_ind,
Data.adjMatrix_areaValues,
Data.volumes,
Data.centers,
Data.weights,
Data.n_bnd_faces,
Data.dim
);
const AgglomerationArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> agglo_args(
goal_card, min_card, max_card, correction, seed
);
const AnisotropicArgs<CoMMAIndexT, CoMMAWeightT, CoMMAIntT> aniso_args(
is_anisotropic,
Data.anisoCompliantCells,
build_lines,
odd_length,
aniso_thr
);
// Agglomerate
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
graph_args, agglo_args, aniso_args, fc2cc, alines_idx, alines
);
THEN("The result is 4 anisotropic lines and 2 isotropic cells") {
for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i)
REQUIRE(fc2cc[i] == ref_results[i]);
}
}
WHEN("We agglomerate with bad argument") {
vector<CoMMAIndexT> fc2cc(Data.nb_fc), alines_idx{}, alines{};
constexpr bool is_anisotropic = true, build_lines = true,
odd_length = true, correction = true;
constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4;
constexpr CoMMAWeightT aniso_thr = 4.;
const auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY;
// clang-format off
// Off to highlight which parameter should be responsible for the throw
THEN("CoMMA throws if invalid arguments") {
// Bad dimension: only 2 or 3
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
5,
goal_card, min_card, max_card)
);
vector<CoMMAIndexT> tmp = {};
// Bad graph definition: indirection
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
tmp,
Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim, goal_card, min_card, max_card)
);
tmp.push_back(2);
// Bad graph definition: indirection
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
tmp,
Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers,
Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, build_lines,
is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim,
goal_card, min_card, max_card)
);
// Bad graph definition: values do not correspond to indirection
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr,
tmp,
Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights,
Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, is_anisotropic,
odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card,
min_card, max_card)
);
// Bad graph definition: values do not correspond to indirection
const vector<CoMMAWeightT> tmp_w = {};
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind,
tmp_w,
Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells,
Data.n_bnd_faces, build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx,
alines, correction, Data.dim, goal_card, min_card, max_card)
);
// Bad cardinality: min higher than goal
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim, goal_card,
goal_card + 1,
max_card)
);
// Bad cardinality: goal cardinality is 0
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim,
0,
min_card, max_card)
);
// Bad anisotropic line definition
vector<CoMMAIndexT> tmp_idx = {0, 0};
vector<CoMMAIndexT> tmp_lines = {4};
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
false,
is_anisotropic, odd_length, aniso_thr, seed, fc2cc,
tmp_idx, tmp_lines,
correction, Data.dim, goal_card, min_card, max_card)
);
// Bad cardinality: singular cardinality is 0
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim, goal_card, min_card, max_card, DEFAULT_AR,
0)
);
// Bad iteration number: is 0
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim, goal_card, min_card, max_card, DEFAULT_AR, SING_CARD_THRESH, MAX_CELLS_IN_LINE,
CELL_COUPLING_MAX, FORCE_DIRECTION,
0)
);
// Bad iteration number: greater than threshold
REQUIRE_THROWS(
agglomerate_one_level<CoMMAIndexT, CoMMAWeightT, CoMMAIntT>(
Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes,
Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces,
build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction,
Data.dim, goal_card, min_card, max_card, DEFAULT_AR, SING_CARD_THRESH, MAX_CELLS_IN_LINE,
CELL_COUPLING_MAX, FORCE_DIRECTION,
comma::iter_agglo_max_iter + 1)
);
}
// clang-format on
}
}
}