Skip to content

Commit baeac11

Browse files
authored
49 Fixed small error where iterator could go out of bounds and improve loop structure. (#50)
List of coarser nodes in r and theta direction now have correct size and entries.
1 parent 2f0f749 commit baeac11

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

src/define_coarse_nodes.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,46 +95,34 @@ void level::define_coarse_nodes_onelevel(level* coarser)
9595
std::set<int> indices_r;
9696
std::set<int> indices_theta;
9797
coarse_nodes = (nr_int + 1) * ntheta_int;
98-
coarse_nodes_list_r = std::vector<int>(coarse_nodes);
99-
coarse_nodes_list_theta = std::vector<int>(coarse_nodes);
98+
coarse_nodes_list_r = std::vector<int>(coarse_nodes, -1);
99+
coarse_nodes_list_theta = std::vector<int>(coarse_nodes, -1);
100100
for (int j = 0; j < nr_int + 1; j += 2) {
101101
for (int i = 0; i < ntheta_int; i += 2) {
102+
102103
coarse_nodes_list_r[j * ntheta_int + i] = j;
103104
coarse_nodes_list_theta[j * ntheta_int + i] = i;
104105

105106
indices_r.insert(j);
106107
indices_theta.insert(i);
107108
}
108109
}
109-
for (int j = 0; j < nr_int + 1; j++) {
110-
for (int i = 0; i < ntheta_int; i++) {
111-
if (j % 2 == 0) {
112-
if (i % 2 == 1) {
113-
coarse_nodes_list_r[j * ntheta_int + i] = -1;
114-
coarse_nodes_list_theta[j * ntheta_int + i] = -1;
115-
}
116-
}
117-
else {
118-
coarse_nodes_list_r[j * ntheta_int + i] = -1;
119-
coarse_nodes_list_theta[j * ntheta_int + i] = -1;
120-
}
121-
}
122-
}
123110

124111
std::set<int, std::greater<int>>::iterator itr_r, itr_theta;
125112

126113
coarser->nr = (int)indices_r.size();
127-
coarser->r = std::vector<double>(nr);
114+
coarser->r = std::vector<double>(coarser->nr);
128115
coarser->ntheta = (int)indices_theta.size();
129-
coarser->theta = std::vector<double>(ntheta);
116+
coarser->theta = std::vector<double>(coarser->ntheta);
130117

131118
itr_r = indices_r.begin();
132-
for (int i = 0; i < nr; i++) {
119+
for (int i = 0; i < coarser->nr; i++) {
133120
coarser->r[i] = r[*itr_r];
134121
itr_r++;
135122
}
123+
136124
itr_theta = indices_theta.begin();
137-
for (int i = 0; i < ntheta; i++) {
125+
for (int i = 0; i < coarser->ntheta; i++) {
138126
coarser->theta[i] = theta[*itr_theta];
139127
itr_theta++;
140128
}

0 commit comments

Comments
 (0)