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

Open-Sn / opensn / 20201962283

12 Dec 2025 06:55PM UTC coverage: 74.333%. Remained the same
20201962283

push

github

web-flow
Merge pull request #859 from wdhawkins/td_source_driver

Adding time-dependent solver and time-dependent sources

367 of 398 new or added lines in 23 files covered. (92.21%)

359 existing lines in 17 files now uncovered.

18610 of 25036 relevant lines covered (74.33%)

68925445.1 hits per line

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

91.18
/modules/linear_boltzmann_solvers/lbs_problem/point_source/point_source.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/point_source/point_source.h"
5
#include "modules/linear_boltzmann_solvers/lbs_problem/lbs_problem.h"
6
#include "framework/mesh/mesh_continuum/mesh_continuum.h"
7
#include "framework/object_factory.h"
8
#include "framework/logging/log.h"
9
#include "framework/runtime.h"
10
#include <numeric>
11
#include <limits>
12

13
namespace opensn
14
{
15

16
OpenSnRegisterObjectInNamespace(lbs, PointSource);
17

18
InputParameters
19
PointSource::GetInputParameters()
9✔
20
{
21
  InputParameters params;
9✔
22

23
  params.SetGeneralDescription("A multi-group isotropic point source.");
18✔
24
  params.SetClassName("Point Source");
18✔
25

26
  params.AddRequiredParameterArray("location", "The (x, y, z) coordinate of the point source.");
18✔
27
  params.AddRequiredParameterArray("strength", "The group-wise point source strength");
18✔
28
  params.AddOptionalParameter("start_time",
18✔
29
                              -std::numeric_limits<double>::infinity(),
30
                              "Time at which the source becomes active.");
31
  params.AddOptionalParameter("end_time",
18✔
32
                              std::numeric_limits<double>::infinity(),
33
                              "Time at which the source becomes inactive.");
34

35
  return params;
9✔
UNCOV
36
}
×
37

38
std::shared_ptr<PointSource>
39
PointSource::Create(const ParameterBlock& params)
9✔
40
{
41
  auto& factory = opensn::ObjectFactory::GetInstance();
9✔
42
  return factory.Create<PointSource>("lbs::PointSource", params);
18✔
43
}
44

45
PointSource::PointSource(const InputParameters& params)
9✔
46
  : location_(params.GetParamVectorValue<double>("location")),
9✔
47
    strength_(params.GetParamVectorValue<double>("strength")),
9✔
48
    start_time_(params.GetParamValue<double>("start_time")),
9✔
49
    end_time_(params.GetParamValue<double>("end_time"))
9✔
50
{
51
  if (std::all_of(strength_.begin(), strength_.end(), [](double x) { return x == 0.0; }))
9✔
UNCOV
52
    log.Log0Warning() << "Point source at " << location_.PrintStr() << " "
×
UNCOV
53
                      << "does not have a non-zero source strength.";
×
54
}
9✔
55

56
void
57
PointSource::Initialize(const LBSProblem& lbs_problem)
17✔
58
{
59
  OpenSnLogicalErrorIf(strength_.size() != lbs_problem.GetNumGroups(),
17✔
60
                       "Incompatible point source strength vector at location " +
61
                         location_.PrintStr() + ". " + "There are " +
62
                         std::to_string(lbs_problem.GetNumGroups()) + " simulation groups, but " +
63
                         std::to_string(strength_.size()) + " source strength values.");
64

65
  // Get info from solver
66
  const auto& grid = lbs_problem.GetGrid();
17✔
67
  const auto& discretization = lbs_problem.GetSpatialDiscretization();
17✔
68
  const auto& unit_cell_matrices = lbs_problem.GetUnitCellMatrices();
17✔
69
  const auto& ghost_unit_cell_matrices = lbs_problem.GetUnitGhostCellMatrices();
17✔
70

71
  // Find local subscribers
72
  double total_volume = 0.0;
17✔
73
  std::vector<Subscriber> subscribers;
17✔
74
  for (const auto& cell : grid->local_cells)
14,538✔
75
  {
76
    if (grid->CheckPointInsideCell(cell, location_))
14,521✔
77
    {
78
      const auto& cell_mapping = discretization.GetCellMapping(cell);
5✔
79
      const auto& fe_values = unit_cell_matrices[cell.local_id];
5✔
80

81
      // Map the point source to the finite element space
82
      Vector<double> shape_vals;
5✔
83
      cell_mapping.ShapeValues(location_, shape_vals);
5✔
84
      const auto M_inv = Inverse(fe_values.intV_shapeI_shapeJ);
5✔
85
      const auto node_wgts = Mult(M_inv, shape_vals);
5✔
86

87
      // Increment the total volume
88
      total_volume += cell.volume;
5✔
89

90
      // Add to subscribers
91
      subscribers.push_back(Subscriber{cell.volume, cell.local_id, shape_vals, node_wgts});
5✔
92
    }
15✔
93
  }
94

95
  // If the point source lies on a partition boundary, ghost cells must be
96
  // added to the total volume.
97
  auto ghost_global_ids = grid->cells.GetGhostGlobalIDs();
17✔
98
  for (uint64_t global_id : ghost_global_ids)
1,025✔
99
  {
100
    const auto& nbr_cell = grid->cells[global_id];
1,008✔
101
    if (grid->CheckPointInsideCell(nbr_cell, location_))
1,008✔
102
    {
UNCOV
103
      const auto& fe_values = ghost_unit_cell_matrices.at(nbr_cell.global_id);
×
UNCOV
104
      total_volume +=
×
UNCOV
105
        std::accumulate(fe_values.intV_shapeI.begin(), fe_values.intV_shapeI.end(), 0.0);
×
106
    }
107
  }
108

109
  // Create the actual subscriber list
110
  subscribers_.clear();
17✔
111
  for (const auto& sub : subscribers)
22✔
112
  {
113
    subscribers_.push_back(
5✔
114
      {sub.volume_weight / total_volume, sub.cell_local_id, sub.shape_values, sub.node_weights});
10✔
115

116
    std::stringstream ss;
5✔
117
    ss << "Point source at " << location_.PrintStr() << " assigned to cell "
10✔
118
       << grid->local_cells[sub.cell_local_id].global_id << " with shape values [ ";
5✔
119
    for (const auto& value : sub.shape_values)
25✔
120
      ss << value << " ";
20✔
121
    ss << "] and volume weight " << sub.volume_weight / total_volume;
5✔
122
    log.LogAll() << ss.str();
10✔
123
  }
5✔
124

125
  size_t num_local_subs = subscribers_.size();
17✔
126
  mpi_comm.all_reduce(num_local_subs, num_global_subscribers_, mpi::op::sum<size_t>());
17✔
127

128
  log.LogAll() << "Point source has " << num_local_subs << " subscribing cells on processor "
17✔
129
               << mpi_comm.rank();
34✔
130
  log.Log() << "Point source has " << num_global_subscribers_ << " global subscribing cells.";
51✔
131
}
39✔
132

133
bool
134
PointSource::IsActive(double time) const
17✔
135
{
136
  return time >= start_time_ && time <= end_time_;
17✔
137
}
138

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