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

Open-Sn / opensn / 21892714514

10 Feb 2026 11:58PM UTC coverage: 74.806% (-0.02%) from 74.828%
21892714514

push

github

web-flow
Merge pull request #929 from wdhawkins/iteration_log

Fixing iteration status messages

4 of 4 new or added lines in 1 file covered. (100.0%)

211 existing lines in 16 files now uncovered.

19638 of 26252 relevant lines covered (74.81%)

69654996.54 hits per line

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

89.51
/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,
167,404✔
13
                              unsigned int gsi,
14
                              unsigned int gss,
15
                              Functor func)
16
{
17
  CALI_CXX_MARK_SCOPE("LBSVecOps::GroupsetScopedCopy");
167,404✔
18

19
  const auto& grid = lbs_problem.GetGrid();
167,404✔
20
  const auto& cell_transport_views = lbs_problem.GetCellTransportViews();
167,404✔
21
  auto num_moments = lbs_problem.GetNumMoments();
167,404✔
22

23
  int64_t idx = -1;
167,404✔
24
  for (const auto& cell : grid->local_cells)
136,089,820✔
25
  {
26
    const auto& transport_view = cell_transport_views[cell.local_id];
135,922,416✔
27
    for (std::size_t i = 0; i < cell.vertex_ids.size(); ++i)
709,751,492✔
28
    {
29
      for (size_t m = 0; m < num_moments; ++m)
1,357,496,844✔
30
      {
31
        auto mapped_idx = transport_view.MapDOF(i, m, gsi);
783,667,768✔
32
        for (unsigned int g = 0; g < gss; ++g)
2,147,483,647✔
33
        {
34
          ++idx;
2,147,483,647✔
35
          func(idx, mapped_idx + g);
2,147,483,647✔
36
        }
37
      }
38
    }
39
  }
40
  return idx;
334,808✔
41
}
167,404✔
42

43
void
44
LBSVecOps::SetPhiVectorScalarValues(LBSProblem& lbs_problem, PhiSTLOption phi_opt, double value)
171✔
45
{
46
  CALI_CXX_MARK_SCOPE("LBSVecOps::SetPhiVectorScalarValues");
171✔
47

48
  auto& phi = (phi_opt == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
171✔
49
                                                 : lbs_problem.GetPhiOldLocal();
171✔
50
  const auto& grid = lbs_problem.GetGrid();
171✔
51
  const auto& sdm = lbs_problem.GetSpatialDiscretization();
171✔
52
  const auto& unknown_manager = lbs_problem.GetUnknownManager();
171✔
53

54
  const auto first_grp = 0;
171✔
55
  const long final_grp = static_cast<long>(lbs_problem.GetNumGroups() - 1);
171✔
56

57
  for (const auto& cell : grid->local_cells)
19,275✔
58
  {
59
    const auto& cell_mapping = sdm.GetCellMapping(cell);
19,104✔
60
    const size_t num_nodes = cell_mapping.GetNumNodes();
19,104✔
61

62
    for (size_t i = 0; i < num_nodes; ++i)
98,480✔
63
    {
64
      const auto dof_map = static_cast<long>(sdm.MapDOFLocal(cell, i, unknown_manager, 0, 0));
79,376✔
65
      std::fill(phi.begin() + dof_map + first_grp, phi.begin() + dof_map + final_grp + 1, value);
158,752✔
66
    }
67
  }
68
}
171✔
69

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

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

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

100
void
101
LBSVecOps::SetGSPETScVecFromPrimarySTLvector(LBSProblem& lbs_problem,
72,516✔
102
                                             const LBSGroupset& groupset,
103
                                             Vec dest,
104
                                             PhiSTLOption src)
105
{
106
  const auto& src_phi =
72,516✔
107
    (src == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
72,516✔
108
  double* petsc_dest = nullptr;
72,516✔
109
  VecGetArray(dest, &petsc_dest);
72,516✔
110
  int64_t index = GroupsetScopedCopy(lbs_problem,
72,516✔
111
                                     groupset.first_group,
72,516✔
112
                                     groupset.GetNumGroups(),
113
                                     [&](int64_t idx, size_t mapped_idx)
2,147,483,647✔
114
                                     { petsc_dest[idx] = src_phi[mapped_idx]; });
2,147,483,647✔
115
  if (groupset.angle_agg)
72,516✔
116
  {
117
    if (src == PhiSTLOption::PHI_NEW)
72,516✔
118
      groupset.angle_agg->AppendNewDelayedAngularDOFsToArray(index, petsc_dest);
68,389✔
119
    else if (src == PhiSTLOption::PHI_OLD)
4,127✔
120
      groupset.angle_agg->AppendOldDelayedAngularDOFsToArray(index, petsc_dest);
4,127✔
121
  }
122
  VecRestoreArray(dest, &petsc_dest);
72,516✔
123
}
72,516✔
124

125
void
126
LBSVecOps::SetPrimarySTLvectorFromGSPETScVec(LBSProblem& lbs_problem,
72,516✔
127
                                             const LBSGroupset& groupset,
128
                                             Vec src,
129
                                             PhiSTLOption dest)
130
{
131
  auto& dest_phi =
72,516✔
132
    (dest == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
72,516✔
133
  const double* petsc_src = nullptr;
72,516✔
134
  VecGetArrayRead(src, &petsc_src);
72,516✔
135
  int64_t index = GroupsetScopedCopy(lbs_problem,
72,516✔
136
                                     groupset.first_group,
72,516✔
137
                                     groupset.GetNumGroups(),
138
                                     [&](int64_t idx, size_t mapped_idx)
2,147,483,647✔
139
                                     { dest_phi[mapped_idx] = petsc_src[idx]; });
2,147,483,647✔
140
  if (groupset.angle_agg)
72,516✔
141
  {
142
    if (dest == PhiSTLOption::PHI_NEW)
72,516✔
143
      groupset.angle_agg->SetNewDelayedAngularDOFsFromArray(index, petsc_src);
11,787✔
144
    else if (dest == PhiSTLOption::PHI_OLD)
60,729✔
145
      groupset.angle_agg->SetOldDelayedAngularDOFsFromArray(index, petsc_src);
60,729✔
146
  }
147
  VecRestoreArrayRead(src, &petsc_src);
72,516✔
148
}
72,516✔
149

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

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

185
void
186
LBSVecOps::GSScopedCopyPrimarySTLvectors(LBSProblem& lbs_problem,
43✔
187
                                         const LBSGroupset& groupset,
188
                                         const std::vector<double>& src,
189
                                         std::vector<double>& dest)
190
{
191
  GroupsetScopedCopy(lbs_problem,
43✔
192
                     groupset.first_group,
43✔
193
                     groupset.GetNumGroups(),
194
                     [&](int64_t idx, size_t mapped_idx) { dest[mapped_idx] = src[mapped_idx]; });
633,440✔
195
}
43✔
196

197
void
198
LBSVecOps::GSScopedCopyPrimarySTLvectors(LBSProblem& lbs_problem,
14,585✔
199
                                         const LBSGroupset& groupset,
200
                                         PhiSTLOption src,
201
                                         PhiSTLOption dest)
202
{
203
  const auto& src_phi =
14,585✔
204
    (src == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
14,585✔
205
  auto& dest_phi =
14,585✔
206
    (dest == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal() : lbs_problem.GetPhiOldLocal();
14,585✔
207
  GroupsetScopedCopy(lbs_problem,
14,585✔
208
                     groupset.first_group,
14,585✔
209
                     groupset.GetNumGroups(),
210
                     [&](int64_t idx, size_t mapped_idx)
1,216,041,206✔
211
                     { dest_phi[mapped_idx] = src_phi[mapped_idx]; });
1,216,041,206✔
212
  if (groupset.angle_agg)
14,585✔
213
  {
214
    if (src == PhiSTLOption::PHI_NEW and dest == PhiSTLOption::PHI_OLD)
14,585✔
215
      groupset.angle_agg->SetDelayedPsiOld2New();
14,585✔
UNCOV
216
    else if (src == PhiSTLOption::PHI_OLD and dest == PhiSTLOption::PHI_NEW)
×
UNCOV
217
      groupset.angle_agg->SetDelayedPsiNew2Old();
×
218
  }
219
}
14,585✔
220

221
void
222
LBSVecOps::SetMultiGSPETScVecFromPrimarySTLvector(LBSProblem& lbs_problem,
3,872✔
223
                                                  const std::vector<unsigned int>& groupset_ids,
224
                                                  Vec x,
225
                                                  PhiSTLOption which_phi)
226
{
227
  auto& y = (which_phi == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
3,872✔
228
                                                 : lbs_problem.GetPhiOldLocal();
28✔
229
  auto& groupsets = lbs_problem.GetGroupsets();
3,872✔
230
  double* x_ref = nullptr;
3,872✔
231
  VecGetArray(x, &x_ref);
3,872✔
232

233
  for (auto gs_id : groupset_ids)
7,744✔
234
  {
235
    const auto& groupset = groupsets.at(gs_id);
3,872✔
236
    auto gsi = groupset.first_group;
3,872✔
237
    auto gsf = groupset.last_group;
3,872✔
238
    auto gss = gsf - gsi + 1;
3,872✔
239

240
    int64_t index = GroupsetScopedCopy(
3,872✔
241
      lbs_problem, gsi, gss, [&](int64_t idx, size_t mapped_idx) { x_ref[idx] = y[mapped_idx]; });
371,922,400✔
242
    if (groupset.angle_agg)
3,872✔
243
    {
244
      if (which_phi == PhiSTLOption::PHI_NEW)
3,872✔
245
        groupset.angle_agg->AppendNewDelayedAngularDOFsToArray(index, x_ref);
3,844✔
246
      else if (which_phi == PhiSTLOption::PHI_OLD)
28✔
247
        groupset.angle_agg->AppendOldDelayedAngularDOFsToArray(index, x_ref);
28✔
248
    }
249
  }
250

251
  VecRestoreArray(x, &x_ref);
3,872✔
252
}
3,872✔
253

254
void
255
LBSVecOps::SetPrimarySTLvectorFromMultiGSPETScVec(LBSProblem& lbs_problem,
3,844✔
256
                                                  const std::vector<unsigned int>& groupset_ids,
257
                                                  Vec x,
258
                                                  PhiSTLOption which_phi)
259
{
260
  auto& y = (which_phi == PhiSTLOption::PHI_NEW) ? lbs_problem.GetPhiNewLocal()
3,844✔
261
                                                 : lbs_problem.GetPhiOldLocal();
3,844✔
262
  auto& groupsets = lbs_problem.GetGroupsets();
3,844✔
263
  const double* x_ref = nullptr;
3,844✔
264
  VecGetArrayRead(x, &x_ref);
3,844✔
265

266
  for (auto gs_id : groupset_ids)
7,688✔
267
  {
268
    const auto& groupset = groupsets.at(gs_id);
3,844✔
269
    auto gsi = groupset.first_group;
3,844✔
270
    auto gsf = groupset.last_group;
3,844✔
271
    auto gss = gsf - gsi + 1;
3,844✔
272

273
    int64_t index = GroupsetScopedCopy(
3,844✔
274
      lbs_problem, gsi, gss, [&](int64_t idx, size_t mapped_idx) { y[mapped_idx] = x_ref[idx]; });
369,704,600✔
275
    if (groupset.angle_agg)
3,844✔
276
    {
277
      if (which_phi == PhiSTLOption::PHI_NEW)
3,844✔
UNCOV
278
        groupset.angle_agg->SetNewDelayedAngularDOFsFromArray(index, x_ref);
×
279
      else if (which_phi == PhiSTLOption::PHI_OLD)
3,844✔
280
        groupset.angle_agg->SetOldDelayedAngularDOFsFromArray(index, x_ref);
3,844✔
281
    }
282
  }
283

284
  VecRestoreArrayRead(x, &x_ref);
3,844✔
285
}
3,844✔
286

287
} // 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