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

openmc-dev / openmc / 21043561037

15 Jan 2026 07:23PM UTC coverage: 81.388% (-0.7%) from 82.044%
21043561037

Pull #3734

github

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

16703 of 22995 branches covered (72.64%)

Branch coverage included in aggregate %.

156 of 179 new or added lines in 12 files covered. (87.15%)

843 existing lines in 36 files now uncovered.

54487 of 64475 relevant lines covered (84.51%)

27592585.27 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(
7✔
10
  Mesh* mesh_ptr, vector<double> values, const std::string& field_type)
7✔
11
{
12
  this->field_type_ = field_type;
7✔
13

14
  if (mesh_ptr != nullptr) {
7!
15
    this->mesh_ptr_ = mesh_ptr;
7✔
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()) {
7!
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) {
63✔
28
    this->values_.push_back(v);
56✔
29
  }
30
}
7✔
31

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

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

43
  // If we have a bin, we use it to locate the value
44
  if (i >= 0 && i < this->values().size()) {
301,360!
45
    return this->value(i);
301,360✔
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)
301,360✔
53
{
54
  double temperature = this->get_temperature(r);
301,360✔
55
  if (temperature >= 0) {
301,360!
56
    return sqrt(temperature * K_BOLTZMANN);
301,360✔
57
  }
NEW
58
  return -1.0;
×
59
}
60

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

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

69
  // If particle inside the mesh, we use the temperature field
70
  if (field_sqrtkT >= 0.) {
301,360!
71
    p.sqrtkT() = field_sqrtkT;
301,360✔
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
}
301,360✔
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