GCC Code Coverage Report


Directory: ./
File: Geometry/listEdges.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 68 100 68.0%
Branches: 37 75 49.3%

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: J.Castelneau & J.Foulon
13 //
14
15 // System includes
16
17 // External includes
18
19 // Project includes
20 #include "Geometry/geometricEdges.hpp"
21 #include "Geometry/listEdges.hpp"
22 #include "Geometry/neighFacesOfEdges.hpp"
23 #include "Geometry/neighVolumesOfEdges.hpp"
24
25 namespace felisce
26 {
27 const felInt ListEdges::m_null_int = -1;
28
29 //////////////////////
30 // LIST EDGES CLASS //
31 //////////////////////
32
33 //----------------
34 1277 ListEdges::~ListEdges() {
35
2/2
✓ Branch 1 taken 187184 times.
✓ Branch 2 taken 1277 times.
188461 for (unsigned int iedge = 0; iedge < m_listEdges.size(); iedge++) {
36
1/2
✓ Branch 1 taken 187184 times.
✗ Branch 2 not taken.
187184 delete m_listEdges[iedge];
37 }
38 1277 m_listEdges.clear();
39 1277 m_listBeginEdge.clear();
40 1277 }
41
42 //----------------
43 93 void ListEdges::clearAndInit(felInt numPts) {
44 93 m_listBeginEdge.clear();
45 93 m_listEdges.clear();
46 93 m_numEdges = 0;
47 93 m_numGivenEdges = 0;
48
49
1/2
✓ Branch 1 taken 93 times.
✗ Branch 2 not taken.
93 m_listBeginEdge.resize( numPts, nullptr );
50 93 }
51
52 //----------------
53 561748 void ListEdges::searchAddEdge(felInt pt_edge_beg, felInt pt_edge_end,
54 shar_ptrFace the_face_neighbour,
55 shar_ptrVol the_vol_neighbour) {
56 Edge* begin_edge;
57 561748 begin_edge = m_listBeginEdge[ pt_edge_beg ];
58
2/2
✓ Branch 0 taken 52601 times.
✓ Branch 1 taken 509147 times.
561748 if ( begin_edge == nullptr ) {
59 //! this vertex has never been the beginning of an edge: add the edge
60
2/4
✓ Branch 1 taken 52601 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 52601 times.
✗ Branch 5 not taken.
52601 Edge* the_edge = new Edge(pt_edge_beg, pt_edge_end, m_numEdges);
61
1/2
✓ Branch 3 taken 52601 times.
✗ Branch 4 not taken.
52601 m_insertNeighbors(the_edge, the_face_neighbour, the_vol_neighbour);
62
63
1/2
✓ Branch 1 taken 52601 times.
✗ Branch 2 not taken.
52601 m_listEdges.push_back( the_edge );
64 52601 m_listBeginEdge[ pt_edge_beg ] = the_edge;
65 52601 m_numEdges ++;
66 52601 return;
67 }
68
69 //! otherwise: there already exists (at least) one edge starting with this vertex:
70 Edge* current_edge;
71 Edge* previous_edge;
72 509147 current_edge = begin_edge;
73 //! search all edges starting from pt_edge_beg
74 do {
75 1629268 previous_edge = current_edge;
76
2/2
✓ Branch 1 taken 1254704 times.
✓ Branch 2 taken 374564 times.
1629268 if ( previous_edge->idEnd() != pt_edge_end ) { //! edge not found
77 1254704 current_edge = previous_edge->ptrNext(); //! go to next edge
78 } else { //! this edge exists already
79
1/2
✓ Branch 3 taken 374564 times.
✗ Branch 4 not taken.
374564 m_insertNeighbors(current_edge, the_face_neighbour, the_vol_neighbour);
80 374564 return; //! we do not insert this existing edge.
81 }
82
83
2/2
✓ Branch 0 taken 1120121 times.
✓ Branch 1 taken 134583 times.
1254704 } while ( current_edge != nullptr );
84
85 //! If we did not exit so far, this is a new edge: we add it
86
2/4
✓ Branch 1 taken 134583 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 134583 times.
✗ Branch 5 not taken.
134583 Edge* the_edge = new Edge(pt_edge_beg, pt_edge_end, m_numEdges);
87
1/2
✓ Branch 3 taken 134583 times.
✗ Branch 4 not taken.
134583 m_insertNeighbors(the_edge, the_face_neighbour, the_vol_neighbour);
88
89
1/2
✓ Branch 1 taken 134583 times.
✗ Branch 2 not taken.
134583 m_listEdges.push_back( the_edge );
90 //! link between previous edge and current:
91 134583 previous_edge->ptrNext() = m_listEdges[m_numEdges];
92 134583 m_numEdges ++;
93 }
94
95 //----------------
96 561748 void ListEdges::m_insertNeighbors(Edge* the_edge,
97 shar_ptrFace the_face_neighbour,
98 shar_ptrVol the_vol_neighbour) const {
99
2/2
✓ Branch 1 taken 281720 times.
✓ Branch 2 taken 280028 times.
561748 if (the_face_neighbour)// != NULL)
100 281720 the_edge->listNeighFacesOfEdges().push_back(the_face_neighbour);
101
2/2
✓ Branch 1 taken 273600 times.
✓ Branch 2 taken 288148 times.
561748 if (the_vol_neighbour)// != NULL)
102 273600 the_edge->listNeighVolumesOfEdges().push_back(the_vol_neighbour);
103 561748 }
104
105 2446 void ListEdges::searchEdge(const std::vector<felInt>& edgePts, Edge& resultEdge) const {
106 felInt iD;
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2446 times.
2446 FEL_ASSERT(edgePts.size()==2)
108
2/2
✓ Branch 2 taken 293 times.
✓ Branch 3 taken 2153 times.
2446 if ( edgePts[0] < edgePts[1] )
109 293 iD=findEdge(edgePts[0],edgePts[1]);
110 else
111 2153 iD=findEdge(edgePts[1],edgePts[0]);
112 2446 resultEdge = *m_listEdges[iD]; // now it is safe with shared_ptr
113 2446 }
114
115 //----------------
116 7734669 felInt ListEdges::findEdge(felInt pt_edge_beg, felInt pt_edge_end) const {
117
118
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7734669 times.
7734669 FEL_ASSERT(static_cast<int>(m_listBeginEdge.size()) > pt_edge_beg)
119
120 7734669 const felInt resultEdgeNotFound = -1;
121
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7734669 times.
7734669 if ( pt_edge_beg >= pt_edge_end ) {
123 FEL_ERROR("The starting point should be < the ending point in findEdge!\n");
124 }
125
126 7734669 Edge* current_edge = m_listBeginEdge[ pt_edge_beg ];
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7734669 times.
7734669 if ( current_edge == nullptr ) {
128 FEL_WARNING("You are searching a edge with an unknow first point!!!!\n");
129 return resultEdgeNotFound;
130 }
131
132 do {
133
2/2
✓ Branch 1 taken 7734669 times.
✓ Branch 2 taken 14605627 times.
22340296 if ( current_edge->idEnd() == pt_edge_end ) {
134 7734669 return current_edge->id();
135 } else {
136 14605627 current_edge = current_edge->ptrNext();
137 }
138
1/2
✓ Branch 0 taken 14605627 times.
✗ Branch 1 not taken.
14605627 } while ( current_edge != nullptr );
139
140 FEL_WARNING("The sought edge was not found.");
141 return resultEdgeNotFound;
142 }
143
144 //----------------
145 void ListEdges::print( std::ostream& outstr, int verbose, int orderFormat ) const {
146 switch ( orderFormat ) {
147 case 0: { // print by increasing edge ID
148 outstr << "Print the list of edges: " << m_numEdges
149 << " edges (ordered by edge ID) (" << m_numGivenEdges
150 << " first edges were provided.)\n";
151 bool print_next_edge = false;
152 for(auto it_edg = m_listEdges.begin();
153 it_edg != m_listEdges.end(); it_edg++) {
154 (*it_edg)->print( outstr, verbose, print_next_edge );
155 }
156 }
157 break;
158 case 1: { // print by increasing BeginPoint
159 felInt begPt = 0;
160 outstr << "Print the list of edges: " << m_numEdges
161 << " edges (ordered by increasing BeginPoint) (" << m_numGivenEdges
162 << " edges were provided.)\n";
163 bool print_next_edge = true;
164 for(auto it_beg = m_listBeginEdge.begin();
165 it_beg != m_listBeginEdge.end(); it_beg++) {
166 if ( (*it_beg) == NULL ) {
167 if ( verbose > 30 ) outstr << begPt << " ------> NULL "<< std::endl;
168 } else {
169 (*it_beg)->print( outstr, verbose, print_next_edge );
170 }
171 begPt++;
172 }
173 }
174 break;
175 default:
176 FEL_ERROR("Problem: choose the order for edge printing");
177 }
178 }
179
180 108 double ListEdges::countAndComputeIdEdgesSupportingDofs(const RefElement& refEle) {
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if ( m_numOfEdgesSupportingADof > 0) {
182 // It has been computed before, it is returned.
183 return m_numOfEdgesSupportingADof;
184 } else {
185 // In this function we want to count the edges that are actually supporting a dof!
186 // While we count them we assign them an id. This id starts at 0 (idSupporting);
187 108 double idSupporting(0);
188 // Number of dof supported by the current edge.
189 108 felInt numExtraDof(0);
190 // Loop over all the edges of the list
191
2/2
✓ Branch 1 taken 5544 times.
✓ Branch 2 taken 108 times.
5652 for (std::size_t i(0); i < m_listEdges.size(); ++i) {
192 // We get the number of dof supported by the current edge.
193 // Of course for doing this we need to know which kind of reference element we are using.
194 5544 numExtraDof = m_listEdges[i]->numOfDofSupported(refEle);
195 // If the edge is indeed supporting sum dofs
196 // we count it and we assign an id to him
197
2/2
✓ Branch 0 taken 872 times.
✓ Branch 1 taken 4672 times.
5544 if ( numExtraDof > 0 ) {
198 872 m_numOfEdgesSupportingADof += numExtraDof;
199 872 m_listEdges[i]->idOnlySupporting() = idSupporting;
200 872 idSupporting++;
201 }
202 }
203 108 return m_numOfEdgesSupportingADof;
204 }
205 }
206 }
207