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

Open-Sn / opensn / 20388244010

20 Dec 2025 12:27AM UTC coverage: 74.437% (+0.02%) from 74.415%
20388244010

push

github

web-flow
Merge pull request #882 from andrsd/issue/90-local-cell-idxs

Unifying integer types for local cell face/side indices

13 of 15 new or added lines in 2 files covered. (86.67%)

43 existing lines in 8 files now uncovered.

18677 of 25091 relevant lines covered (74.44%)

66914505.04 hits per line

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

77.14
/python/lib/response.cc
1
// SPDX-FileCopyrightText: 2025 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "python/lib/py_wrappers.h"
5
#include "modules/linear_boltzmann_solvers/response_evaluator/response_evaluator.h"
6
#include <memory>
7

8
namespace opensn
9
{
10

11
// Wrap response evaluator
12
void
13
WrapResEval(py::module& response)
483✔
14
{
15
  // clang-format off
16
  // response evaluator
17
  auto res_eval = py::class_<ResponseEvaluator, std::shared_ptr<ResponseEvaluator>>(
483✔
18
    response,
19
    "ResponseEvaluator",
20
    R"(
21
    Response evaluator by folding sources against adjoint solutions.
22

23
    Wrapper of :cpp:class:`opensn::ResponseEvaluator`.
24

25
    The workflow for this utility is constructed to minimize the file reading necessary for
26
    evaluations. To begin, one should add all adjoint solutions that are desired for response
27
    computations into the buffer. Then, one should define the different forward source
28
    configurations of interest. With this, the user can now iterate over the source
29
    configurations and convolve them against all available adjoint solutions in the buffer.
30
    )"
31
  );
483✔
32
  res_eval.def(
966✔
33
    py::init(
483✔
34
      [](py::kwargs& params)
32✔
35
      {
36
        return ResponseEvaluator::Create(kwargs_to_param_block(params));
32✔
37
      }
38
    ),
39
    R"(
40
    Construct a response evaluator object.
41

42
    Parameters
43
    ----------
44
    lbs_problem: pyopensn.solver.Solver
45
        A handle to an existing LBS problem.
46
    options: Dict
47
        The specification of adjoint buffers and forward sources to use. Supported keys:
48
          - buffers: List[Dict], default=[]
49
              Each dictionary supports:
50
                - name: str (required)
51
                    Buffer name used for response queries.
52
                - file_prefixes: Dict (required)
53
                    Prefix map with optional keys:
54
                      - flux_moments: str
55
                          Prefix for flux moments files.
56
                      - angular_fluxes: str
57
                          Prefix for angular flux files.
58
          - clear_sources: bool, default=False
59
              If true, clears any existing forward sources.
60
          - sources: Dict, default={}
61
              Dictionary describing forward sources. Supported keys:
62
                - material: List[Dict], default=[]
63
                    Each dictionary supports:
64
                      - block_id: int (required)
65
                          Block id for the material source.
66
                      - strength: List[float] (required)
67
                          Group-wise source strength (length must match number of groups).
68
                - point: List[pyopensn.source.PointSource], default=[]
69
                    Point source handles.
70
                - volumetric: List[pyopensn.source.VolumetricSource], default=[]
71
                    Volumetric source handles.
72
                - boundary: List[Dict], default=[]
73
                    Boundary source dictionaries. Each dictionary supports:
74
                      - name: str (required)
75
                          Boundary name that identifies the specific boundary.
76
                      - type: {'vacuum', 'isotropic', 'reflecting'} (required)
77
                          Boundary type specification. Only ``isotropic`` is used for responses.
78
                      - group_strength: List[float], optional
79
                          Required when ``type='isotropic'``. Isotropic strength per group.
80
                      - function_name: str, optional, default=''
81
                          Name of a registered function to evaluate on the boundary.
82
    )"
83
  );
84
  res_eval.def(
483✔
85
    "EvaluateResponse",
86
    &ResponseEvaluator::EvaluateResponse,
966✔
87
    R"(
88
    Evaluate a response using the specified adjoint buffer with the currently defined sources in
89
    the solver.
90

91
    Parameters
92
    ----------
93
    buffer_name: str
94
        Adjoint buffer name
95
    )",
96
    py::arg("buffer_name")
483✔
97
  );
98
  res_eval.def(
483✔
99
    "SetOptions",
100
    [](ResponseEvaluator& self, py::kwargs& params)
515✔
101
    {
102
      InputParameters input = ResponseEvaluator::GetOptionsBlock();
32✔
103
      input.AssignParameters(kwargs_to_param_block(params));
32✔
104
      self.SetOptions(input);
32✔
105
    },
32✔
106
    R"(
107
    Set options for the response evaluator for adding adjoint buffers and defining forward sources.
108

109
    Parameters
110
    ----------
111
    buffers: List[Dict], default=[]
112
        A list of dictionaries containing adjoint buffer specifications. Each dictionary supports:
113
          - name: str (required)
114
              Buffer name used for response queries.
115
          - file_prefixes: Dict (required)
116
              Prefix map with optional keys:
117
                - flux_moments: str
118
                    Prefix for flux moments files.
119
                - angular_fluxes: str
120
                    Prefix for angular flux files.
121
    clear_sources: bool, default=False
122
        A flag to clear existing sources.
123
    sources: Dict, default={}
124
        Dictionary describing forward sources. Supported keys:
125
          - material: List[Dict], default=[]
126
              Each dictionary supports:
127
                - block_id: int (required)
128
                    Block id for the material source.
129
                - strength: List[float] (required)
130
                    Group-wise source strength (length must match number of groups).
131
          - point: List[pyopensn.source.PointSource], default=[]
132
              Point source handles.
133
          - volumetric: List[pyopensn.source.VolumetricSource], default=[]
134
              Volumetric source handles.
135
          - boundary: List[Dict], default=[]
136
              Boundary source dictionaries. Each dictionary supports:
137
                - name: str (required)
138
                    Boundary name that identifies the specific boundary.
139
                - type: {'vacuum', 'isotropic', 'reflecting'} (required)
140
                    Boundary type specification. Only ``isotropic`` is used for responses.
141
                - group_strength: List[float], optional
142
                    Required when ``type='isotropic'``. Isotropic strength per group.
143
                - function_name: str, optional, default=''
144
                    Name of a registered function to evaluate on the boundary.
145
    )"
146
    );
147
  res_eval.def(
483✔
148
    "ClearForwardSources",
149
    &ResponseEvaluator::ClearForwardSources,
483✔
150
    "Clear the existing forward sources from the response evaluator."
151
  );
152
  res_eval.def(
483✔
153
    "SetBufferOptions",
154
    [](ResponseEvaluator& self, py::kwargs& params)
483✔
155
    {
UNCOV
156
      InputParameters input = ResponseEvaluator::GetBufferOptionsBlock();
×
UNCOV
157
      input.AssignParameters(kwargs_to_param_block(params));
×
UNCOV
158
      self.SetBufferOptions(input);
×
UNCOV
159
    },
×
160
    R"(
161
    Add adjoint buffers from the options block to the response evaluator.
162

163
    Parameters
164
    ----------
165
    name: str (required)
166
        Buffer name used for response queries.
167
    file_prefixes: Dict (required)
168
        Prefix map with optional keys:
169
          - flux_moments: str
170
              Prefix for flux moments files.
171
          - angular_fluxes: str
172
              Prefix for angular flux files.
173
    )"
174
  );
175
  res_eval.def(
483✔
176
    "SetSourceOptions",
177
    [](ResponseEvaluator& self, py::kwargs& params)
483✔
178
    {
UNCOV
179
      InputParameters input = ResponseEvaluator::GetSourceOptionsBlock();
×
UNCOV
180
      input.AssignParameters(kwargs_to_param_block(params));
×
UNCOV
181
      self.SetSourceOptions(input);
×
UNCOV
182
    },
×
183
    R"(
184
    Add forward sources from the options block to the response evaluator.
185

186
    Parameters
187
    ----------
188
    material: List[Dict], default=[]
189
        Each dictionary supports:
190
          - block_id: int (required)
191
              Block id for the material source.
192
          - strength: List[float] (required)
193
              Group-wise source strength (length must match number of groups).
194
    point: List[pyopensn.source.PointSource], default=[]
195
        Point source handles.
196
    volumetric: List[pyopensn.source.VolumetricSource], default=[]
197
        Volumetric source handles.
198
    boundary: List[Dict], default=[]
199
        Boundary source dictionaries. Each dictionary supports:
200
          - name: str (required)
201
              Boundary name that identifies the specific boundary.
202
          - type: {'vacuum', 'isotropic', 'reflecting'} (required)
203
              Boundary type specification. Only ``isotropic`` is used for responses.
204
          - group_strength: List[float], optional
205
              Required when ``type='isotropic'``. Isotropic strength per group.
206
          - function_name: str, optional, default=''
207
              Name of a registered function to evaluate on the boundary.
208
    )"
209
  );
210
  // clang-format on
211
}
483✔
212

213
// Wrap the response components of OpenSn
214
void
215
py_response(py::module& pyopensn)
62✔
216
{
217
  py::module response = pyopensn.def_submodule("response", "Response module.");
62✔
218
  WrapResEval(response);
62✔
219
}
62✔
220

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