GCC Code Coverage Report


Directory: ./
File: Tools/petsc_utilities.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 22 33 66.7%
Branches: 22 42 52.4%

Line Branch Exec Source
1 // ______ ______ _ _ _____ ______
2 // | ____| ____| | (_)/ ____| | ____|
3 // | |__ | |__ | | _| (___ ___| |__
4 // | __| | __| | | | |\___ \ / __| __|
5 // | | | |____| |____| |____) | (__| |____
6 // |_| |______|______|_|_____/ \___|______|
7 // Finite Elements for Life Sciences and Engineering
8 //
9 // License: LGL2.1 License
10 // FELiScE default license: LICENSE in root folder
11 //
12 // Main authors: Vicente Mataix Ferrandiz
13 //
14
15 #if FULL_PETSC_CODE
16
17 // System includes
18 #include <cmath>
19 #include <limits>
20
21 // External includes
22 #include <bitmap_image.hpp>
23 #include <src/mat/impls/aij/seq/aij.h>
24
25 // Project includes
26 #include "Tools/petsc_utilities.hpp"
27 #include "Core/filesystemUtil.hpp"
28
29 namespace felisce
30 {
31
32 namespace PETScUtilities
33 {
34
35 4 void SparsePlot(
36 const PetscMatrix& rA,
37 const std::string& rFilename,
38 const bool structure
39 )
40 {
41 // Work directly with PETSc matrix
42
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 const Mat& A = rA.toPetsc();
43
44 // Get size matric
45 PetscInt m, n;
46
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 MatGetSize(A, &m, &n);
47
48 // Initialize image
49
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 bitmap_image spy(m,n);
50
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 spy.clear();
51
52 PetscInt i,j,cols;
53 // Filll white by default
54
2/2
✓ Branch 0 taken 16900 times.
✓ Branch 1 taken 4 times.
16904 for (i = 0; i < m; i++) {
55
2/2
✓ Branch 0 taken 71402500 times.
✓ Branch 1 taken 16900 times.
71419400 for (j = 0; j < n; j++) {
56 71402500 spy.set_pixel(i, j, 255, 255, 255);
57 }
58 }
59
60 // Getting sparse matrix data
61 4 Mat_SeqAIJ* a = (Mat_SeqAIJ*)A->data;
62 4 cols = A->rmap->n;
63
64 // Getting max
65
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 felisce::PetscVector max_vector;
66
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 max_vector.createMPIInstance(m);
67
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 MatGetRowMaxAbs(A, max_vector.toPetsc(), NULL);
68
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 const PetscScalar max = max_vector.max();
69
70 // Fill bitmap
71
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (structure) {
72
2/2
✓ Branch 0 taken 16900 times.
✓ Branch 1 taken 4 times.
16904 for (i = 0; i < cols; i++) {
73
2/2
✓ Branch 0 taken 116228 times.
✓ Branch 1 taken 16900 times.
133128 for (j = a->i[i]; j < a->i[i+1]; j++) {
74
2/2
✓ Branch 0 taken 49156 times.
✓ Branch 1 taken 67072 times.
116228 if (a->a[j] > 0.0) {
75 49156 spy.set_pixel(i, a->j[j], 0, 0, 204);
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67072 times.
67072 } else if (a->a[j] > 0.0) {
77 spy.set_pixel(i, a->j[j], 204, 0, 0);
78 }
79 }
80 }
81 } else {
82 PetscScalar s;
83 for (i = 0; i < cols; i++) {
84 for (j = a->i[i]; j < a->i[i+1]; j++) {
85 if (a->a[j] > 0.0) {
86 s = std::abs(a->a[j]) / max;
87 const std::size_t aux = (1.0 - s) * 499;
88 spy.set_pixel(i, a->j[j], hot_colormap[aux]);
89 } else if (a->a[j] > 0.0) {
90 s = std::abs(a->a[j]) / max;
91 const std::size_t aux = s * 500 + 499;
92 spy.set_pixel(i, a->j[j], hot_colormap[aux]);
93 }
94 }
95 }
96 }
97
98
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 spy.save_image(rFilename);
99 4 }
100
101 /***********************************************************************************/
102 /***********************************************************************************/
103
104 } // namespace PETScUtilities
105
106 } // namespace felisce
107
108 #endif
109