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

Open-Sn / opensn / 16766938693

05 Aug 2025 03:26PM UTC coverage: 73.386% (+0.1%) from 73.282%
16766938693

push

github

web-flow
Merge pull request #693 from andrsd/move-bnds

Moving sweep boundaries into `DiscreteOrdinatesProblem`

247 of 311 new or added lines in 19 files covered. (79.42%)

625 existing lines in 49 files now uncovered.

18320 of 24964 relevant lines covered (73.39%)

43106214.05 hits per line

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

84.15
/framework/post_processors/cell_volume_integral_post_processor.cc
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "framework/post_processors/cell_volume_integral_post_processor.h"
5
#include "framework/event_system/event.h"
6
#include "framework/runtime.h"
7
#include "framework/field_functions/field_function_grid_based.h"
8
#include "framework/math/spatial_discretization/spatial_discretization.h"
9
#include "framework/math/spatial_discretization/finite_element/finite_element_data.h"
10
#include "framework/mesh/mesh_continuum/mesh_continuum.h"
11
#include "framework/mesh/logical_volume/logical_volume.h"
12
#include "framework/object_factory.h"
13

14
namespace opensn
15
{
16

17
OpenSnRegisterObjectInNamespace(post, CellVolumeIntegralPostProcessor);
18

19
InputParameters
20
CellVolumeIntegralPostProcessor::GetInputParameters()
32✔
21
{
22
  InputParameters params = PostProcessor::GetInputParameters();
32✔
23
  params += GridBasedFieldFunctionInterface::GetInputParameters();
32✔
24
  params += LogicalVolumeInterface::GetInputParameters();
32✔
25

26
  params.SetGeneralDescription("Computes the volumetric integral of a field-function as a scalar.");
64✔
27
  params.SetDocGroup("doc_PostProcessors");
64✔
28

29
  params.AddOptionalParameter(
64✔
30
    "compute_volume_average",
31
    false,
32
    "Flag, when true will compute the volume average of the post-processor.");
33

34
  return params;
32✔
UNCOV
35
}
×
36

37
std::shared_ptr<CellVolumeIntegralPostProcessor>
38
CellVolumeIntegralPostProcessor::Create(const ParameterBlock& params)
32✔
39
{
40
  auto& factory = opensn::ObjectFactory::GetInstance();
32✔
41
  auto pps = factory.Create<CellVolumeIntegralPostProcessor>(
32✔
42
    "post::CellVolumeIntegralPostProcessor", params);
32✔
43
  postprocessor_stack.push_back(pps);
64✔
44
  return pps;
32✔
UNCOV
45
}
×
46

47
CellVolumeIntegralPostProcessor::CellVolumeIntegralPostProcessor(const InputParameters& params)
32✔
48
  : PostProcessor(params, PPType::SCALAR),
49
    GridBasedFieldFunctionInterface(params),
50
    LogicalVolumeInterface(params),
51
    compute_volume_average_(params.GetParamValue<bool>("compute_volume_average"))
32✔
52
{
53
  value_ = ParameterBlock("", 0.0);
32✔
54
}
32✔
55

56
void
57
CellVolumeIntegralPostProcessor::Initialize()
32✔
58
{
59
  const auto grid_field_function = GetGridBasedFieldFunction();
32✔
60

61
  OpenSnLogicalErrorIf(not grid_field_function,
32✔
62
                       "Attempted to access invalid field"
63
                       "function");
64

65
  const auto& grid = grid_field_function->GetSpatialDiscretization().GetGrid();
32✔
66

67
  const auto logical_volume_ptr_ = GetLogicalVolume();
32✔
68
  if (logical_volume_ptr_ == nullptr)
32✔
69
  {
70
    cell_local_ids_.reserve(grid->local_cells.size());
32✔
71
    for (const auto& cell : grid->local_cells)
65,568✔
72
      cell_local_ids_.push_back(cell.local_id);
65,536✔
73
  }
74
  else
75
  {
UNCOV
76
    for (const auto& cell : grid->local_cells)
×
UNCOV
77
      if (logical_volume_ptr_->Inside(cell.centroid))
×
UNCOV
78
        cell_local_ids_.push_back(cell.local_id);
×
79
  }
80

81
  initialized_ = true;
32✔
82
}
96✔
83

84
void
85
CellVolumeIntegralPostProcessor::Execute(const Event& event_context)
32✔
86
{
87
  if (not initialized_)
32✔
88
    Initialize();
32✔
89

90
  const auto grid_field_function = GetGridBasedFieldFunction();
32✔
91

92
  OpenSnLogicalErrorIf(not grid_field_function,
32✔
93
                       "Attempted to access invalid field"
94
                       "function");
95

96
  const auto& ref_ff = *grid_field_function;
32✔
97
  const auto& sdm = ref_ff.GetSpatialDiscretization();
32✔
98
  const auto& grid = sdm.GetGrid();
32✔
99

100
  const auto& uk_man = ref_ff.GetUnknownManager();
32✔
101
  const auto uid = 0;
32✔
102
  const auto cid = 0;
32✔
103

104
  const auto field_data = ref_ff.GetGhostedFieldVector();
32✔
105

106
  auto coord = sdm.GetSpatialWeightingFunction();
32✔
107

108
  double local_integral = 0.0;
32✔
109
  double local_volume = 0.0;
32✔
110
  for (const uint64_t cell_local_id : cell_local_ids_)
65,568✔
111
  {
112
    const auto& cell = grid->local_cells[cell_local_id];
65,536✔
113
    const auto& cell_mapping = sdm.GetCellMapping(cell);
65,536✔
114
    const size_t num_nodes = cell_mapping.GetNumNodes();
65,536✔
115
    const auto fe_vol_data = cell_mapping.MakeVolumetricFiniteElementData();
65,536✔
116

117
    std::vector<double> node_dof_values(num_nodes, 0.0);
65,536✔
118
    for (size_t i = 0; i < num_nodes; ++i)
589,824✔
119
    {
120
      const int64_t imap = sdm.MapDOFLocal(cell, i, uk_man, uid, cid);
524,288✔
121
      node_dof_values[i] = field_data[imap];
524,288✔
122
    } // for i
123

124
    for (const size_t qp : fe_vol_data.GetQuadraturePointIndices())
6,356,992✔
125
    {
126
      // phi_h = sum_j b_j phi_j
127
      double ff_value = 0.0;
6,291,456✔
128
      for (size_t j = 0; j < num_nodes; ++j)
56,623,104✔
129
        ff_value += fe_vol_data.ShapeValue(j, qp) * node_dof_values[j];
50,331,648✔
130

131
      local_integral += ff_value * coord(fe_vol_data.QPointXYZ(qp)) * fe_vol_data.JxW(qp);
6,291,456✔
132
      local_volume += coord(fe_vol_data.QPointXYZ(qp)) * fe_vol_data.JxW(qp);
6,291,456✔
133
    } // for qp
134
  } // for cell-id
65,536✔
135

136
  double global_integral;
32✔
137
  mpi_comm.all_reduce(local_integral, global_integral, mpi::op::sum<double>());
32✔
138
  if (not compute_volume_average_)
32✔
UNCOV
139
    value_ = ParameterBlock("", global_integral);
×
140
  else
141
  {
142
    double global_volume;
32✔
143
    mpi_comm.all_reduce(local_volume, global_volume, mpi::op::sum<double>());
32✔
144

145
    value_ = ParameterBlock("", global_integral / global_volume);
32✔
146
  }
147

148
  const int event_code = event_context.GetCode();
32✔
149
  if (event_code == Event::SolverInitialized or event_code == Event::SolverAdvanced)
32✔
150
  {
UNCOV
151
    const auto& event_params = event_context.Parameters();
×
152

153
    if (event_params.Has("timestep_index") and event_params.Has("time"))
×
154
    {
155
      const size_t index = event_params.GetParamValue<size_t>("timestep_index");
×
156
      const double time = event_params.GetParamValue<double>("time");
×
UNCOV
157
      TimeHistoryEntry entry{index, time, value_};
×
UNCOV
158
      time_history_.push_back(std::move(entry));
×
UNCOV
159
    }
×
160
  }
161
}
96✔
162

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