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

openmc-dev / openmc / 26125164380

19 May 2026 09:02PM UTC coverage: 81.414% (+0.09%) from 81.324%
26125164380

Pull #3734

github

web-flow
Merge c2bb44df6 into beed56e6e
Pull Request #3734: Specify temperature from a field (structured mesh only)

17929 of 25865 branches covered (69.32%)

Branch coverage included in aggregate %.

278 of 308 new or added lines in 18 files covered. (90.26%)

1332 existing lines in 29 files now uncovered.

58995 of 68620 relevant lines covered (85.97%)

47961357.16 hits per line

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

61.29
/src/field.cpp
1
#include "openmc/field.h"
2
#include "openmc/cell.h"
3
#include "openmc/constants.h"
4
#include "openmc/mesh.h"
5
#include "openmc/simulation.h"
6
#include "openmc/vector.h"
7

8
namespace openmc {
9

10
ScalarField::ScalarField(
199✔
11
  Mesh* mesh_ptr, vector<double> values, const std::string& field_type)
199✔
12
{
13
  this->field_type_ = field_type;
199✔
14

15
  if (mesh_ptr != nullptr) {
199!
16
    this->mesh_ptr_ = mesh_ptr;
199✔
17
  } else {
NEW
18
    fatal_error(fmt::format("No mesh found for {}!", field_type));
×
19
  }
20

21
  if (this->mesh_ptr_->n_bins() != values.size()) {
199!
NEW
22
    fatal_error(
×
NEW
23
      fmt::format("The number of bins in the mesh is not consistent with the "
×
24
                  "number of values declared in {}!",
25
        field_type));
26
  }
27

28
  for (double v : values) {
1,791✔
29
    this->values_.push_back(v);
1,592✔
30
  }
31
}
199✔
32

33
double ScalarField::distance_to_next_boundary(
11,669,832✔
34
  int current_bin, const Position& r, const Direction& u, int& bin_next)
35
{
36
  return this->mesh_ptr()->distance_to_next_boundary(
11,669,832✔
37
    current_bin, r, u, bin_next);
11,669,832✔
38
}
39

40
double TemperatureField::get_temperature(int bin)
2,992,308✔
41
{
42
  if (bin >= 0 && bin < values().size()) {
2,992,308!
43
    return this->value(bin);
2,992,297✔
44
  }
45
  return -1.0;
46
}
47

48
double TemperatureField::get_sqrtkT(int bin)
2,992,242✔
49
{
50
  double temperature = get_temperature(bin);
2,992,242✔
51
  if (temperature >= 0) {
2,992,242!
52
    return sqrt(temperature * K_BOLTZMANN);
2,992,242✔
53
  }
54
  return -1.0;
55
}
56

57
int TemperatureField::get_bin(const Position& r)
1,366,145✔
58
{
59
  int bin = mesh_ptr()->get_bin(r);
1,366,145✔
60
  if (bin >= 0 && bin < values().size()) {
1,366,145!
61
    return bin;
62
  } else {
63
    return C_NONE;
468,413✔
64
  }
65
}
66

67
//==============================================================================
68
// C API
69
//==============================================================================
70

NEW
71
extern "C" int openmc_temperature_field_set_temperature(
×
72
  int32_t index, double temperature)
73
{
NEW
74
  if (index < 0 || index >= simulation::temperature_field.values().size()) {
×
NEW
75
    set_errmsg("Index in temperature field is out of bounds.");
×
NEW
76
    return OPENMC_E_OUT_OF_BOUNDS;
×
77
  }
78

NEW
79
  simulation::temperature_field.value(index) = temperature;
×
NEW
80
  return 0;
×
81
}
82

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