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

openmc-dev / openmc / 13114782272

03 Feb 2025 01:38PM UTC coverage: 82.603% (-2.3%) from 84.867%
13114782272

Pull #3087

github

web-flow
Merge 258841139 into 59c398be8
Pull Request #3087: wheel building with scikit build core

107121 of 129682 relevant lines covered (82.6%)

12608592.69 hits per line

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

50.98
/src/tallies/filter_mesh.cpp
1
#include "openmc/tallies/filter_mesh.h"
2

3
#include <fmt/core.h>
4
#include <gsl/gsl-lite.hpp>
5

6
#include "openmc/capi.h"
7
#include "openmc/constants.h"
8
#include "openmc/error.h"
9
#include "openmc/mesh.h"
10
#include "openmc/xml_interface.h"
11

12
namespace openmc {
13

14
void MeshFilter::from_xml(pugi::xml_node node)
1,710✔
15
{
16
  auto bins_ = get_node_array<int32_t>(node, "bins");
1,710✔
17
  if (bins_.size() != 1) {
1,710✔
18
    fatal_error(
×
19
      "Only one mesh can be specified per " + type_str() + " mesh filter.");
×
20
  }
21

22
  auto id = bins_[0];
1,710✔
23
  auto search = model::mesh_map.find(id);
1,710✔
24
  if (search != model::mesh_map.end()) {
1,710✔
25
    set_mesh(search->second);
1,710✔
26
  } else {
27
    fatal_error(
×
28
      fmt::format("Could not find mesh {} specified on tally filter.", id));
×
29
  }
30

31
  if (check_for_node(node, "translation")) {
1,710✔
32
    set_translation(get_node_array<double>(node, "translation"));
34✔
33
  }
34
}
1,710✔
35

36
void MeshFilter::get_all_bins(
285,398,431✔
37
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
38
{
39

40
  Position last_r = p.r_last();
285,398,431✔
41
  Position r = p.r();
285,398,431✔
42
  Position u = p.u();
285,398,431✔
43

44
  // apply translation if present
45
  if (translated_) {
285,398,431✔
46
    last_r -= translation();
826,296✔
47
    r -= translation();
826,296✔
48
  }
49

50
  if (estimator != TallyEstimator::TRACKLENGTH) {
285,398,431✔
51
    auto bin = model::meshes[mesh_]->get_bin(r);
44,575,440✔
52
    if (bin >= 0) {
44,575,440✔
53
      match.bins_.push_back(bin);
21,037,737✔
54
      match.weights_.push_back(1.0);
21,037,737✔
55
    }
56
  } else {
57
    model::meshes[mesh_]->bins_crossed(
240,822,991✔
58
      last_r, r, u, match.bins_, match.weights_);
240,822,991✔
59
  }
60
}
285,398,431✔
61

62
void MeshFilter::to_statepoint(hid_t filter_group) const
1,572✔
63
{
64
  Filter::to_statepoint(filter_group);
1,572✔
65
  write_dataset(filter_group, "bins", model::meshes[mesh_]->id_);
1,572✔
66
  if (translated_) {
1,572✔
67
    write_dataset(filter_group, "translation", translation_);
24✔
68
  }
69
}
1,572✔
70

71
std::string MeshFilter::text_label(int bin) const
2,901,140✔
72
{
73
  auto& mesh = *model::meshes.at(mesh_);
2,901,140✔
74
  std::string label = mesh.bin_label(bin);
2,901,140✔
75
  return label;
2,901,140✔
76
}
77

78
void MeshFilter::set_mesh(int32_t mesh)
1,582✔
79
{
80
  // perform any additional perparation for mesh tallies here
81
  mesh_ = mesh;
1,582✔
82
  n_bins_ = model::meshes[mesh_]->n_bins();
1,582✔
83
  model::meshes[mesh_]->prepare_for_point_location();
1,582✔
84
}
1,582✔
85

86
void MeshFilter::set_translation(const Position& translation)
34✔
87
{
88
  translated_ = true;
34✔
89
  translation_ = translation;
34✔
90
}
34✔
91

92
void MeshFilter::set_translation(const double translation[3])
×
93
{
94
  this->set_translation({translation[0], translation[1], translation[2]});
×
95
}
96

97
//==============================================================================
98
// C-API functions
99
//==============================================================================
100

101
extern "C" int openmc_mesh_filter_get_mesh(int32_t index, int32_t* index_mesh)
×
102
{
103
  if (!index_mesh) {
×
104
    set_errmsg("Mesh index argument is a null pointer.");
×
105
    return OPENMC_E_INVALID_ARGUMENT;
×
106
  }
107

108
  // Make sure this is a valid index to an allocated filter.
109
  if (int err = verify_filter(index))
×
110
    return err;
×
111

112
  // Get a pointer to the filter and downcast.
113
  const auto& filt_base = model::tally_filters[index].get();
×
114
  auto* filt = dynamic_cast<MeshFilter*>(filt_base);
×
115

116
  // Check the filter type.
117
  if (!filt) {
×
118
    set_errmsg("Tried to get mesh on a non-mesh filter.");
×
119
    return OPENMC_E_INVALID_TYPE;
×
120
  }
121

122
  // Output the mesh.
123
  *index_mesh = filt->mesh();
×
124
  return 0;
×
125
}
126

127
extern "C" int openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh)
41✔
128
{
129
  // Make sure this is a valid index to an allocated filter.
130
  if (int err = verify_filter(index))
41✔
131
    return err;
×
132

133
  // Get a pointer to the filter and downcast.
134
  const auto& filt_base = model::tally_filters[index].get();
41✔
135
  auto* filt = dynamic_cast<MeshFilter*>(filt_base);
41✔
136

137
  // Check the filter type.
138
  if (!filt) {
41✔
139
    set_errmsg("Tried to set mesh on a non-mesh filter.");
×
140
    return OPENMC_E_INVALID_TYPE;
×
141
  }
142

143
  // Check the mesh index.
144
  if (index_mesh < 0 || index_mesh >= model::meshes.size()) {
41✔
145
    set_errmsg("Index in 'meshes' array is out of bounds.");
×
146
    return OPENMC_E_OUT_OF_BOUNDS;
×
147
  }
148

149
  // Update the filter.
150
  filt->set_mesh(index_mesh);
41✔
151
  return 0;
41✔
152
}
153

154
extern "C" int openmc_mesh_filter_get_translation(
×
155
  int32_t index, double translation[3])
156
{
157
  // Make sure this is a valid index to an allocated filter
158
  if (int err = verify_filter(index))
×
159
    return err;
×
160

161
  // Check the filter type
162
  const auto& filter = model::tally_filters[index];
×
163
  if (filter->type() != FilterType::MESH &&
×
164
      filter->type() != FilterType::MESHBORN &&
×
165
      filter->type() != FilterType::MESH_SURFACE) {
×
166
    set_errmsg("Tried to get a translation from a non-mesh-based filter.");
×
167
    return OPENMC_E_INVALID_TYPE;
×
168
  }
169

170
  // Get translation from the mesh filter and set value
171
  auto mesh_filter = dynamic_cast<MeshFilter*>(filter.get());
×
172
  const auto& t = mesh_filter->translation();
×
173
  for (int i = 0; i < 3; i++) {
×
174
    translation[i] = t[i];
×
175
  }
176

177
  return 0;
×
178
}
179

180
extern "C" int openmc_mesh_filter_set_translation(
×
181
  int32_t index, double translation[3])
182
{
183
  // Make sure this is a valid index to an allocated filter
184
  if (int err = verify_filter(index))
×
185
    return err;
×
186

187
  const auto& filter = model::tally_filters[index];
×
188
  // Check the filter type
189
  if (filter->type() != FilterType::MESH &&
×
190
      filter->type() != FilterType::MESHBORN &&
×
191
      filter->type() != FilterType::MESH_SURFACE) {
×
192
    set_errmsg("Tried to set mesh on a non-mesh-based filter.");
×
193
    return OPENMC_E_INVALID_TYPE;
×
194
  }
195

196
  // Get a pointer to the filter and downcast
197
  auto mesh_filter = dynamic_cast<MeshFilter*>(filter.get());
×
198

199
  // Set the translation
200
  mesh_filter->set_translation(translation);
×
201

202
  return 0;
×
203
}
204

205
} // namespace openmc
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