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

openmc-dev / openmc / 23916574395

02 Apr 2026 06:50PM UTC coverage: 81.336% (+0.01%) from 81.324%
23916574395

Pull #3734

github

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

17720 of 25601 branches covered (69.22%)

Branch coverage included in aggregate %.

183 of 204 new or added lines in 15 files covered. (89.71%)

69 existing lines in 3 files now uncovered.

58284 of 67843 relevant lines covered (85.91%)

44753955.49 hits per line

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

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

15
  if (mesh_ptr != nullptr) {
26!
16
    this->mesh_ptr_ = mesh_ptr;
26✔
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()) {
26!
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) {
234✔
29
    this->values_.push_back(v);
208✔
30
  }
31
}
26✔
32

33
double ScalarField::distance_to_next_boundary(
1,364,077✔
34
  const Position& r, const Direction& u)
35
{
36
  return this->mesh_ptr()->distance_to_next_boundary(r, u);
1,364,077✔
37
}
38

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

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

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

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

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

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

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

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

81
//==============================================================================
82
// C API
83
//==============================================================================
84

NEW
85
extern "C" int openmc_temperature_field_set_temperature(
×
86
  int32_t index, double temperature)
87
{
NEW
88
  if (index < 0 || index >= simulation::temperature_field.values().size()) {
×
NEW
89
    set_errmsg("Index in temperature field is out of bounds.");
×
NEW
90
    return OPENMC_E_OUT_OF_BOUNDS;
×
91
  }
92

NEW
93
  simulation::temperature_field.value(index) = temperature;
×
NEW
94
  return 0;
×
95
}
96

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