• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-Sn / opensn / 18928565313

22 Oct 2025 07:55PM UTC coverage: 74.771%. Remained the same
18928565313

push

github

web-flow
Merge pull request #807 from wdhawkins/clang-tidy-init-variables

Fixing clang-tidy init-variables warnings

132 of 179 new or added lines in 52 files covered. (73.74%)

184 existing lines in 3 files now uncovered.

18203 of 24345 relevant lines covered (74.77%)

53868061.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.57
/modules/linear_boltzmann_solvers/lbs_problem/lbs_vecops.cc
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "modules/linear_boltzmann_solvers/lbs_problem/lbs_vecops.h"
5
#include "modules/linear_boltzmann_solvers/lbs_problem/lbs_problem.h"
6

7
namespace opensn
8
{
9

10
template <typename Functor>
11
int64_t
12
LBSVecOps::GroupsetScopedCopy(LBSProblem& lbs_problem, uint64_t gsi, uint64_t gss, Functor func)
66,431✔
13
{
14
  CALI_CXX_MARK_SCOPE("LBSVecOps::GroupsetScopedCopy");
66,431✔
15

16
  const auto& grid = lbs_problem.GetGrid();
66,431✔
17
  const auto& cell_transport_views = lbs_problem.GetCellTransportViews();
66,431✔
18
  auto num_moments = lbs_problem.GetNumMoments();
66,431✔
19

20
  int64_t idx = -1;
66,431✔
21
  for (const auto& cell : grid->local_cells)
20,828,561✔
22
  {
23
    const auto& transport_view = cell_transport_views[cell.local_id];
20,762,130✔
24
    for (std::size_t i = 0; i < cell.vertex_ids.size(); ++i)
135,355,564✔
25
    {
26
      for (size_t m = 0; m < num_moments; ++m)
433,211,192✔
27
      {
28
        auto mapped_idx = transport_view.MapDOF(i, m, gsi);
318,617,758✔
29
        for (std::size_t g = 0; g < gss; ++g)
2,147,483,647✔
30
        {
31
          ++idx;
2,147,483,647✔
32
          func(idx, mapped_idx + g);
2,147,483,647✔
33
        }
34
      }
35
    }
36
  }
37
  return idx;
132,862✔
38
}
66,431✔
39

40
void
41
LBSVecOps::SetPhiVectorScalarValues(LBSProblem& lbs_problem, PhiSTLOption phi_opt, double value)
59✔
42
{
43
  CALI_CXX_MARK_SCOPE("LBSVecOps::SetPhiVectorScalarValues");
59✔
44

45
  auto& phi = (phi_opt == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
59✔
46
                                                 : lbs_problem.GetPhiOldLocal();
59✔
47
  const auto& grid = lbs_problem.GetGrid();
59✔
48
  const auto& groups = lbs_problem.GetGroups();
59✔
49
  const auto& sdm = lbs_problem.GetSpatialDiscretization();
59✔
50
  const auto& unknown_manager = lbs_problem.GetUnknownManager();
59✔
51

52
  const long first_grp = groups.front().id;
59✔
53
  const long final_grp = groups.back().id;
59✔
54

55
  for (const auto& cell : grid->local_cells)
10,439✔
56
  {
57
    const auto& cell_mapping = sdm.GetCellMapping(cell);
10,380✔
58
    const size_t num_nodes = cell_mapping.GetNumNodes();
10,380✔
59

60
    for (size_t i = 0; i < num_nodes; ++i)
53,772✔
61
    {
62
      const auto dof_map = static_cast<long>(sdm.MapDOFLocal(cell, i, unknown_manager, 0, 0));
43,392✔
63
      std::fill(phi.begin() + dof_map + first_grp, phi.begin() + dof_map + final_grp + 1, value);
86,784✔
64
    }
65
  }
66
}
59✔
67

68
void
69
LBSVecOps::ScalePhiVector(LBSProblem& lbs_problem, PhiSTLOption phi_opt, double value)
8✔
70
{
71
  CALI_CXX_MARK_SCOPE("LBSVecOps::ScalePhiVector");
8✔
72

73
  auto& phi = (phi_opt == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
8✔
74
                                                 : lbs_problem.GetPhiOldLocal();
×
75
  auto& groupsets = lbs_problem.GetGroupsets();
8✔
76

77
  Scale(phi, value);
8✔
78
  for (auto& groupset : groupsets)
16✔
79
  {
80
    if (groupset.angle_agg)
8✔
81
    {
82
      if (phi_opt == PhiSTLOption::PHI_NEW)
8✔
83
      {
84
        auto psi = groupset.angle_agg->GetNewDelayedAngularDOFsAsSTLVector();
8✔
85
        Scale(psi, value);
8✔
86
        groupset.angle_agg->SetNewDelayedAngularDOFsFromSTLVector(psi);
8✔
87
      }
8✔
88
      else if (phi_opt == PhiSTLOption::PHI_OLD)
×
89
      {
90
        auto psi = groupset.angle_agg->GetOldDelayedAngularDOFsAsSTLVector();
×
91
        Scale(psi, value);
×
92
        groupset.angle_agg->SetOldDelayedAngularDOFsFromSTLVector(psi);
×
93
      }
×
94
    }
95
  }
96
}
8✔
97

98
void
99
LBSVecOps::SetGSPETScVecFromPrimarySTLvector(LBSProblem& lbs_problem,
26,239✔
100
                                             const LBSGroupset& groupset,
101
                                             Vec dest,
102
                                             PhiSTLOption src)
103
{
104
  const auto& src_phi =
26,239✔
105
    (src == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
26,239✔
106
  double* petsc_dest = nullptr;
26,239✔
107
  VecGetArray(dest, &petsc_dest);
26,239✔
108
  int64_t index = GroupsetScopedCopy(lbs_problem,
26,239✔
109
                                     groupset.groups.front().id,
26,239✔
110
                                     groupset.groups.size(),
111
                                     [&](int64_t idx, size_t mapped_idx)
2,147,483,647✔
112
                                     { petsc_dest[idx] = src_phi[mapped_idx]; });
2,147,483,647✔
113
  if (groupset.angle_agg)
26,239✔
114
  {
115
    if (src == PhiSTLOption::PHI_NEW)
26,239✔
116
      groupset.angle_agg->AppendNewDelayedAngularDOFsToArray(index, petsc_dest);
25,087✔
117
    else if (src == PhiSTLOption::PHI_OLD)
1,152✔
118
      groupset.angle_agg->AppendOldDelayedAngularDOFsToArray(index, petsc_dest);
1,152✔
119
  }
120
  VecRestoreArray(dest, &petsc_dest);
26,239✔
121
}
26,239✔
122

123
void
124
LBSVecOps::SetPrimarySTLvectorFromGSPETScVec(LBSProblem& lbs_problem,
26,239✔
125
                                             const LBSGroupset& groupset,
126
                                             Vec src,
127
                                             PhiSTLOption dest)
128
{
129
  auto& dest_phi =
26,239✔
130
    (dest == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
26,239✔
131
  const double* petsc_src = nullptr;
26,239✔
132
  VecGetArrayRead(src, &petsc_src);
26,239✔
133
  int64_t index = GroupsetScopedCopy(lbs_problem,
26,239✔
134
                                     groupset.groups.front().id,
26,239✔
135
                                     groupset.groups.size(),
136
                                     [&](int64_t idx, size_t mapped_idx)
2,147,483,647✔
137
                                     { dest_phi[mapped_idx] = petsc_src[idx]; });
2,147,483,647✔
138
  if (groupset.angle_agg)
26,239✔
139
  {
140
    if (dest == PhiSTLOption::PHI_NEW)
26,239✔
141
      groupset.angle_agg->SetNewDelayedAngularDOFsFromArray(index, petsc_src);
8,824✔
142
    else if (dest == PhiSTLOption::PHI_OLD)
17,415✔
143
      groupset.angle_agg->SetOldDelayedAngularDOFsFromArray(index, petsc_src);
17,415✔
144
  }
145
  VecRestoreArrayRead(src, &petsc_src);
26,239✔
146
}
26,239✔
147

148
void
149
LBSVecOps::SetGroupScopedPETScVecFromPrimarySTLvector(LBSProblem& lbs_problem,
×
150
                                                      int first_group_id,
151
                                                      int last_group_id,
152
                                                      Vec dest,
153
                                                      const std::vector<double>& src)
154
{
NEW
155
  double* petsc_dest = nullptr;
×
156
  VecGetArray(dest, &petsc_dest);
×
157
  GroupsetScopedCopy(lbs_problem,
×
158
                     first_group_id,
159
                     last_group_id - first_group_id + 1,
×
160
                     [&](int64_t idx, size_t mapped_idx) { petsc_dest[idx] = src[mapped_idx]; });
×
161
  VecRestoreArray(dest, &petsc_dest);
×
162
}
×
163

164
void
165
LBSVecOps::SetPrimarySTLvectorFromGroupScopedPETScVec(
28✔
166
  LBSProblem& lbs_problem, int first_group_id, int last_group_id, Vec src, PhiSTLOption dest)
167
{
168
  auto& dest_phi =
28✔
169
    (dest == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
28✔
170
  const double* petsc_src = nullptr;
28✔
171
  VecGetArrayRead(src, &petsc_src);
28✔
172
  GroupsetScopedCopy(lbs_problem,
28✔
173
                     first_group_id,
174
                     last_group_id - first_group_id + 1,
28✔
175
                     [&](int64_t idx, size_t mapped_idx)
2,217,800✔
176
                     { dest_phi[mapped_idx] = petsc_src[idx]; });
2,217,800✔
177
  VecRestoreArrayRead(src, &petsc_src);
28✔
178
}
28✔
179

180
void
181
LBSVecOps::GSScopedCopyPrimarySTLvectors(LBSProblem& lbs_problem,
47✔
182
                                         const LBSGroupset& groupset,
183
                                         const std::vector<double>& src,
184
                                         std::vector<double>& dest)
185
{
186
  GroupsetScopedCopy(lbs_problem,
47✔
187
                     groupset.groups.front().id,
47✔
188
                     groupset.groups.size(),
189
                     [&](int64_t idx, size_t mapped_idx) { dest[mapped_idx] = src[mapped_idx]; });
759,888✔
190
}
47✔
191

192
void
193
LBSVecOps::GSScopedCopyPrimarySTLvectors(LBSProblem& lbs_problem,
6,194✔
194
                                         const LBSGroupset& groupset,
195
                                         PhiSTLOption src,
196
                                         PhiSTLOption dest)
197
{
198
  const auto& src_phi =
6,194✔
199
    (src == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
6,194✔
200
  auto& dest_phi =
6,194✔
201
    (dest == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
6,194✔
202
  GroupsetScopedCopy(lbs_problem,
6,194✔
203
                     groupset.groups.front().id,
6,194✔
204
                     groupset.groups.size(),
205
                     [&](int64_t idx, size_t mapped_idx)
1,399,210,718✔
206
                     { dest_phi[mapped_idx] = src_phi[mapped_idx]; });
1,399,210,718✔
207
  if (groupset.angle_agg)
6,194✔
208
  {
209
    if (src == PhiSTLOption::PHI_NEW and dest == PhiSTLOption::PHI_OLD)
6,194✔
210
      groupset.angle_agg->SetDelayedPsiOld2New();
6,194✔
211
    else if (src == PhiSTLOption::PHI_OLD and dest == PhiSTLOption::PHI_NEW)
×
212
      groupset.angle_agg->SetDelayedPsiNew2Old();
×
213
  }
214
}
6,194✔
215

216
void
217
LBSVecOps::SetMultiGSPETScVecFromPrimarySTLvector(LBSProblem& lbs_problem,
3,856✔
218
                                                  const std::vector<int>& groupset_ids,
219
                                                  Vec x,
220
                                                  PhiSTLOption which_phi)
221
{
222
  auto& y = (which_phi == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
3,856✔
223
                                                 : lbs_problem.GetPhiOldLocal();
28✔
224
  auto& groupsets = lbs_problem.GetGroupsets();
3,856✔
225
  double* x_ref = nullptr;
3,856✔
226
  VecGetArray(x, &x_ref);
3,856✔
227

228
  for (int gs_id : groupset_ids)
7,712✔
229
  {
230
    const auto& groupset = groupsets.at(gs_id);
3,856✔
231
    int gsi = groupset.groups.front().id;
3,856✔
232
    int gsf = groupset.groups.back().id;
3,856✔
233
    int gss = gsf - gsi + 1;
3,856✔
234

235
    int64_t index = GroupsetScopedCopy(
3,856✔
236
      lbs_problem, gsi, gss, [&](int64_t idx, size_t mapped_idx) { x_ref[idx] = y[mapped_idx]; });
371,615,200✔
237
    if (groupset.angle_agg)
3,856✔
238
    {
239
      if (which_phi == PhiSTLOption::PHI_NEW)
3,856✔
240
        groupset.angle_agg->AppendNewDelayedAngularDOFsToArray(index, x_ref);
3,828✔
241
      else if (which_phi == PhiSTLOption::PHI_OLD)
28✔
242
        groupset.angle_agg->AppendOldDelayedAngularDOFsToArray(index, x_ref);
28✔
243
    }
244
  }
245

246
  VecRestoreArray(x, &x_ref);
3,856✔
247
}
3,856✔
248

249
void
250
LBSVecOps::SetPrimarySTLvectorFromMultiGSPETScVec(LBSProblem& lbs_problem,
3,828✔
251
                                                  const std::vector<int>& groupset_ids,
252
                                                  Vec x,
253
                                                  PhiSTLOption which_phi)
254
{
255
  auto& y = (which_phi == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
3,828✔
256
                                                 : lbs_problem.GetPhiOldLocal();
3,828✔
257
  auto& groupsets = lbs_problem.GetGroupsets();
3,828✔
258
  const double* x_ref = nullptr;
3,828✔
259
  VecGetArrayRead(x, &x_ref);
3,828✔
260

261
  for (int gs_id : groupset_ids)
7,656✔
262
  {
263
    const auto& groupset = groupsets.at(gs_id);
3,828✔
264
    int gsi = groupset.groups.front().id;
3,828✔
265
    int gsf = groupset.groups.back().id;
3,828✔
266
    int gss = gsf - gsi + 1;
3,828✔
267

268
    int64_t index = GroupsetScopedCopy(
3,828✔
269
      lbs_problem, gsi, gss, [&](int64_t idx, size_t mapped_idx) { y[mapped_idx] = x_ref[idx]; });
369,397,400✔
270
    if (groupset.angle_agg)
3,828✔
271
    {
272
      if (which_phi == PhiSTLOption::PHI_NEW)
3,828✔
273
        groupset.angle_agg->SetNewDelayedAngularDOFsFromArray(index, x_ref);
×
274
      else if (which_phi == PhiSTLOption::PHI_OLD)
3,828✔
275
        groupset.angle_agg->SetOldDelayedAngularDOFsFromArray(index, x_ref);
3,828✔
276
    }
277
  }
278

279
  VecRestoreArrayRead(x, &x_ref);
3,828✔
280
}
3,828✔
281

282
} // namespace opensn
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc