-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuildSolverMatrix.cpp
More file actions
559 lines (459 loc) · 23.8 KB
/
buildSolverMatrix.cpp
File metadata and controls
559 lines (459 loc) · 23.8 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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#include "../../../include/DirectSolver/DirectSolver-COO-MUMPS-Take/directSolverTake.h"
#ifdef GMGPOLAR_USE_MUMPS
static inline void updateMatrixElement(SparseMatrixCOO<double>& matrix, int ptr, int offset, int row, int col,
double val)
{
matrix.row_index(ptr + offset) = row;
matrix.col_index(ptr + offset) = col;
matrix.value(ptr + offset) = val;
}
void DirectSolver_COO_MUMPS_Take::nodeBuildSolverMatrixTake(int i_r, int i_theta, const PolarGrid& grid,
bool DirBC_Interior, SparseMatrixCOO<double>& solver_matrix,
ConstVector<double>& arr, ConstVector<double>& att,
ConstVector<double>& art, ConstVector<double>& detDF,
ConstVector<double>& coeff_beta)
{
int ptr, offset;
int row, col;
double val;
/* -------------------- */
/* Node in the interior */
/* -------------------- */
if (i_r > 1 && i_r < grid.nr() - 2) {
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta_M1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
int left_index = grid.index(i_r - 1, i_theta);
int right_index = grid.index(i_r + 1, i_theta);
int bottom_index = grid.index(i_r, i_theta_M1);
int top_index = grid.index(i_r, i_theta_P1);
int bottom_left_index = grid.index(i_r - 1, i_theta_M1);
int bottom_right_index = grid.index(i_r + 1, i_theta_M1);
int top_left_index = grid.index(i_r - 1, i_theta_P1);
int top_right_index = grid.index(i_r + 1, i_theta_P1);
double left_value = -coeff1 * (arr(center_index) + arr(left_index)); /* Left */
double right_value = -coeff2 * (arr(center_index) + arr(right_index)); /* Right */
double bottom_value = -coeff3 * (att(center_index) + att(bottom_index)); /* Bottom */
double top_value = -coeff4 * (att(center_index) + att(top_index)); /* Top */
double center_value =
(+0.25 * (h1 + h2) * (k1 + k2) * coeff_beta[center_index] * fabs(detDF(center_index)) /* beta_{i,j} */
- left_value /* Center: (Left) */
- right_value /* Center: (Right) */
- bottom_value /* Center: (Bottom) */
- top_value /* Center: (Top) */
);
double bottom_left_value = -0.25 * (art(left_index) + art(bottom_index)); /* Bottom Left */
double bottom_right_value = +0.25 * (art(right_index) + art(bottom_index)); /* Bottom Right */
double top_left_value = +0.25 * (art(left_index) + art(top_index)); /* Top Left */
double top_right_value = -0.25 * (art(right_index) + art(top_index)); /* Top Right */
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = center_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Left];
col = left_index;
val = left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Right];
col = right_index;
val = right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Bottom];
col = bottom_index;
val = bottom_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Top];
col = top_index;
val = top_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::BottomLeft];
col = bottom_left_index;
val = bottom_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::BottomRight];
col = bottom_right_index;
val = bottom_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::TopLeft];
col = top_left_index;
val = top_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::TopRight];
col = top_right_index;
val = top_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
/* -------------------------- */
/* Node on the inner boundary */
/* -------------------------- */
else if (i_r == 0) {
/* ------------------------------------------------ */
/* Case 1: Dirichlet boundary on the inner boundary */
/* ------------------------------------------------ */
if (DirBC_Interior) {
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = 1.0;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
else {
/* ------------------------------------------------------------- */
/* Case 2: Across origin discretization on the interior boundary */
/* ------------------------------------------------------------- */
// h1 gets replaced with 2 * R0.
// (i_r-1,i_theta) gets replaced with (i_r, i_theta + grid.ntheta()/2).
// Some more adjustments from the changing the 9-point stencil to the artifical 7-point stencil.
const int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
const int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
assert(grid_.ntheta() % 2 == 0);
const int i_theta_AcrossOrigin = grid.wrapThetaIndex(i_theta + grid.ntheta() / 2);
double h1 = 2.0 * grid.radius(0);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta_M1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
int left_index = grid.index(i_r, i_theta_AcrossOrigin);
int right_index = grid.index(i_r + 1, i_theta);
int bottom_index = grid.index(i_r, i_theta_M1);
int top_index = grid.index(i_r, i_theta_P1);
int bottom_right_index = grid.index(i_r + 1, i_theta_M1);
int top_right_index = grid.index(i_r + 1, i_theta_P1);
double left_value = -coeff1 * (arr(center_index) + arr(left_index)); /* Left */
double right_value = -coeff2 * (arr(center_index) + arr(right_index)); /* Right */
double bottom_value = -coeff3 * (att(center_index) + att(bottom_index)); /* Bottom */
double top_value = -coeff4 * (att(center_index) + att(top_index)); /* Top */
double center_value =
(+0.25 * (h1 + h2) * (k1 + k2) * coeff_beta[center_index] * fabs(detDF(center_index)) /* beta_{i,j} */
- left_value /* Center: (Left) */
- right_value /* Center: (Right) */
- bottom_value /* Center: (Bottom) */
- top_value /* Center: (Top) */
);
double bottom_right_value = +0.25 * (art(right_index) + art(bottom_index)); /* Bottom Right */
double top_right_value = -0.25 * (art(right_index) + art(top_index)); /* Top Right */
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = center_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Left];
col = left_index;
val = left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Right];
col = right_index;
val = right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Bottom];
col = bottom_index;
val = bottom_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Top];
col = top_index;
val = top_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* BottomLeft: REMOVED DUE TO ARTIFICAL 7 POINT STENCIL */
offset = CenterStencil[StencilPosition::BottomRight];
col = bottom_right_index;
val = bottom_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* TopLeft: REMOVED DUE TO ARTIFICAL 7 POINT STENCIL */
offset = CenterStencil[StencilPosition::TopRight];
col = top_right_index;
val = top_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
}
/* ------------------------------- */
/* Node next to the inner boundary */
/* ------------------------------- */
else if (i_r == 1) {
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta_M1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
int left_index = grid.index(i_r - 1, i_theta);
int right_index = grid.index(i_r + 1, i_theta);
int bottom_index = grid.index(i_r, i_theta_M1);
int top_index = grid.index(i_r, i_theta_P1);
int bottom_left_index = grid.index(i_r - 1, i_theta_M1);
const int bottom_right_index = grid.index(i_r + 1, i_theta_M1);
int top_left_index = grid.index(i_r - 1, i_theta_P1);
int top_right_index = grid.index(i_r + 1, i_theta_P1);
double left_value = -coeff1 * (arr(center_index) + arr(left_index)); /* Left */
double right_value = -coeff2 * (arr(center_index) + arr(right_index)); /* Right */
double bottom_value = -coeff3 * (att(center_index) + att(bottom_index)); /* Bottom */
double top_value = -coeff4 * (att(center_index) + att(top_index)); /* Top */
double center_value =
(+0.25 * (h1 + h2) * (k1 + k2) * coeff_beta[center_index] * fabs(detDF(center_index)) /* beta_{i,j} */
- left_value /* Center: (Left) */
- right_value /* Center: (Right) */
- bottom_value /* Center: (Bottom) */
- top_value /* Center: (Top) */
);
double bottom_left_value = -0.25 * (art(left_index) + art(bottom_index)); /* Bottom Left */
double bottom_right_value = +0.25 * (art(right_index) + art(bottom_index)); /* Bottom Right */
double top_left_value = +0.25 * (art(left_index) + art(top_index)); /* Top Left */
double top_right_value = -0.25 * (art(right_index) + art(top_index)); /* Top Right */
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = center_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* REMOVED: Moved to the right hand side to make the matrix symmetric */
if (!DirBC_Interior) {
offset = CenterStencil[StencilPosition::Left];
col = left_index;
val = left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
offset = CenterStencil[StencilPosition::Right];
col = right_index;
val = right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Bottom];
col = bottom_index;
val = bottom_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Top];
col = top_index;
val = top_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* REMOVED: Moved to the right hand side to make the matrix symmetric */
if (!DirBC_Interior) {
offset = CenterStencil[StencilPosition::BottomLeft];
col = bottom_left_index;
val = bottom_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
offset = CenterStencil[StencilPosition::BottomRight];
col = bottom_right_index;
val = bottom_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* REMOVED: Moved to the right hand side to make the matrix symmetric */
if (!DirBC_Interior) {
offset = CenterStencil[StencilPosition::TopLeft];
col = top_left_index;
val = top_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
offset = CenterStencil[StencilPosition::TopRight];
col = top_right_index;
val = top_right_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
/* ------------------------------- */
/* Node next to the outer boundary */
/* ------------------------------- */
else if (i_r == grid.nr() - 2) {
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta_M1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
int left_index = grid.index(i_r - 1, i_theta);
int right_index = grid.index(i_r + 1, i_theta);
int bottom_index = grid.index(i_r, i_theta_M1);
int top_index = grid.index(i_r, i_theta_P1);
int bottom_left_index = grid.index(i_r - 1, i_theta_M1);
int bottom_right_index = grid.index(i_r + 1, i_theta_M1);
int top_left_index = grid.index(i_r - 1, i_theta_P1);
int top_right_index = grid.index(i_r + 1, i_theta_P1);
double left_value = -coeff1 * (arr(center_index) + arr(left_index)); /* Left */
double right_value = -coeff2 * (arr(center_index) + arr(right_index)); /* Right */
double bottom_value = -coeff3 * (att(center_index) + att(bottom_index)); /* Bottom */
double top_value = -coeff4 * (att(center_index) + att(top_index)); /* Top */
double center_value =
(+0.25 * (h1 + h2) * (k1 + k2) * coeff_beta[center_index] * fabs(detDF(center_index)) /* beta_{i,j} */
- left_value /* Center: (Left) */
- right_value /* Center: (Right) */
- bottom_value /* Center: (Bottom) */
- top_value /* Center: (Top) */
);
double bottom_left_value = -0.25 * (art(left_index) + art(bottom_index)); /* Bottom Left */
double bottom_right_value = +0.25 * (art(right_index) + art(bottom_index)); /* Bottom Right */
double top_left_value = +0.25 * (art(left_index) + art(top_index)); /* Top Left */
double top_right_value = -0.25 * (art(right_index) + art(top_index)); /* Top Right */
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = center_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Left];
col = left_index;
val = left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* Right REMOVED: Moved to the right hand side to make the matrix symmetric */
offset = CenterStencil[StencilPosition::Bottom];
col = bottom_index;
val = bottom_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::Top];
col = top_index;
val = top_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
offset = CenterStencil[StencilPosition::BottomLeft];
col = bottom_left_index;
val = bottom_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* BottomRight REMOVED: Moved to the right hand side to make the matrix symmetric */
offset = CenterStencil[StencilPosition::TopLeft];
col = top_left_index;
val = top_left_value;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
/* TopRight REMOVED: Moved to the right hand side to make the matrix symmetric */
}
/* ------------------------------------ */
/* Node on the outer dirichlet boundary */
/* ------------------------------------ */
else if (i_r == grid.nr() - 1) {
int center_nz_index = getSolverMatrixIndex(i_r, i_theta);
int center_index = grid.index(i_r, i_theta);
/* Fill matrix row of (i,j) */
row = center_index;
ptr = center_nz_index;
const Stencil& CenterStencil = getStencil(i_r);
offset = CenterStencil[StencilPosition::Center];
col = center_index;
val = 1.0;
updateMatrixElement(solver_matrix, ptr, offset, row, col, val);
}
}
void DirectSolver_COO_MUMPS_Take::buildSolverMatrixCircleSection(const int i_r, SparseMatrixCOO<double>& solver_matrix)
{
assert(level_cache_.cacheDensityProfileCoefficients());
assert(level_cache_.cacheDomainGeometry());
ConstVector<double> arr = level_cache_.arr();
ConstVector<double> att = level_cache_.att();
ConstVector<double> art = level_cache_.art();
ConstVector<double> detDF = level_cache_.detDF();
ConstVector<double> coeff_beta = level_cache_.coeff_beta();
for (int i_theta = 0; i_theta < grid_.ntheta(); i_theta++) {
// Build solver matrix at the current node
nodeBuildSolverMatrixTake(i_r, i_theta, grid_, DirBC_Interior_, solver_matrix, arr, att, art, detDF,
coeff_beta);
}
}
void DirectSolver_COO_MUMPS_Take::buildSolverMatrixRadialSection(const int i_theta,
SparseMatrixCOO<double>& solver_matrix)
{
assert(level_cache_.cacheDensityProfileCoefficients());
assert(level_cache_.cacheDomainGeometry());
ConstVector<double> arr = level_cache_.arr();
ConstVector<double> att = level_cache_.att();
ConstVector<double> art = level_cache_.art();
ConstVector<double> detDF = level_cache_.detDF();
ConstVector<double> coeff_beta = level_cache_.coeff_beta();
for (int i_r = grid_.numberSmootherCircles(); i_r < grid_.nr(); i_r++) {
// Build solver matrix at the current node
nodeBuildSolverMatrixTake(i_r, i_theta, grid_, DirBC_Interior_, solver_matrix, arr, att, art, detDF,
coeff_beta);
}
}
// clang-format off
/* ------------------------------------------------------------------------ */
/* If the indexing is not smoother-based, please adjust the access patterns */
SparseMatrixCOO<double> DirectSolver_COO_MUMPS_Take::buildSolverMatrix()
{
const int n = grid_.numberOfNodes();
const int nnz = getNonZeroCountSolverMatrix();
// Although the matrix is symmetric, we need to store all its entries, so we disable the symmetry.
SparseMatrixCOO<double> solver_matrix(n, n, nnz);
solver_matrix.is_symmetric(false);
if (num_omp_threads_ == 1) {
/* Single-threaded execution */
for (int i_r = 0; i_r < grid_.numberSmootherCircles(); i_r++) {
buildSolverMatrixCircleSection(i_r, solver_matrix);
}
for (int i_theta = 0; i_theta < grid_.ntheta(); i_theta++) {
buildSolverMatrixRadialSection(i_theta, solver_matrix);
}
}
else {
/* Multi-threaded execution */
#pragma omp parallel num_threads(num_omp_threads_)
{
/* Circle Section */
#pragma omp for nowait
for (int i_r = 0; i_r < grid_.numberSmootherCircles(); i_r++) {
buildSolverMatrixCircleSection(i_r, solver_matrix);
}
/* Radial Section */
#pragma omp for nowait
for (int i_theta = 0; i_theta < grid_.ntheta(); i_theta++) {
buildSolverMatrixRadialSection(i_theta, solver_matrix);
}
}
}
/* Mumps: In the case of symmetric matrices, only half of the matrix should be provided. */
const bool construct_symmetric = true;
if (!construct_symmetric) {
return solver_matrix;
}
/* Only store the upper tridiagonal entries of the symmetric solver_matrix */
const int symmetric_nnz = nnz - (nnz - n) / 2;
SparseMatrixCOO<double> symmetric_solver_matrix(n, n, symmetric_nnz);
symmetric_solver_matrix.is_symmetric(true);
int current_nz = 0;
for (int nz_index = 0; nz_index < nnz; nz_index++) {
const int row = solver_matrix.row_index(nz_index);
const int col = solver_matrix.col_index(nz_index);
if (row <= col) {
symmetric_solver_matrix.row_index(current_nz) = row;
symmetric_solver_matrix.col_index(current_nz) = col;
symmetric_solver_matrix.value(current_nz) = std::move(solver_matrix.value(nz_index));
current_nz++;
}
}
return symmetric_solver_matrix;
}
// clang-format on
#endif