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

openmc-dev / openmc / 21043587909

15 Jan 2026 07:25PM UTC coverage: 81.332% (-0.7%) from 82.044%
21043587909

Pull #3734

github

web-flow
Merge 0c6701672 into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16365 of 22657 branches covered (72.23%)

Branch coverage included in aggregate %.

157 of 180 new or added lines in 12 files covered. (87.22%)

681 existing lines in 43 files now uncovered.

54412 of 64365 relevant lines covered (84.54%)

23556062.71 hits per line

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

67.86
/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/vector.h"
6

7
namespace openmc {
8

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

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

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

27
  for (double v : values) {
54✔
28
    this->values_.push_back(v);
48✔
29
  }
30
}
6✔
31

32
double ScalarField::distance_to_next_boundary(
496,028✔
33
  const Position& r, const Direction& u)
34
{
35
  return this->mesh_ptr()->distance_to_next_boundary(r, u);
496,028✔
36
}
37

38
double TemperatureField::get_temperature(const Position& r)
241,088✔
39
{
40
  // Get bin from position
41
  int i = this->mesh_ptr()->get_bin(r);
241,088✔
42

43
  // If we have a bin, we use it to locate the value
44
  if (i >= 0 && i < this->values().size()) {
241,088!
45
    return this->value(i);
241,088✔
46
  }
47

48
  // No values were found (outside the mesh)
NEW
49
  return -1.0;
×
50
}
51

52
double TemperatureField::get_sqrtkT(const Position& r)
241,088✔
53
{
54
  double temperature = this->get_temperature(r);
241,088✔
55
  if (temperature >= 0) {
241,088!
56
    return sqrt(temperature * K_BOLTZMANN);
241,088✔
57
  }
NEW
58
  return -1.0;
×
59
}
60

61
void TemperatureField::update_particle_temperature(Particle& p)
241,088✔
62
{
63
  // Save current temperature
64
  p.sqrtkT_last() = p.sqrtkT();
241,088✔
65

66
  // Determine the temperature based on the temperature field
67
  double field_sqrtkT = this->get_sqrtkT(p.r() + p.u() * TINY_BIT);
241,088✔
68

69
  // If particle inside the mesh, we use the temperature field
70
  if (field_sqrtkT >= 0.) {
241,088!
71
    p.sqrtkT() = field_sqrtkT;
241,088✔
72

73
    // If particle outside the mesh, go back to the cell instance temperature
74
  } else {
NEW
75
    Cell& c {*model::cells[p.lowest_coord().cell()]};
×
NEW
76
    p.sqrtkT() = c.sqrtkT(p.cell_instance());
×
77
  }
78
}
241,088✔
79

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