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

openmc-dev / openmc / 13461947318

21 Feb 2025 05:24PM UTC coverage: 85.019% (+0.05%) from 84.969%
13461947318

Pull #3140

github

web-flow
Merge ece247ada into 2b788ea6e
Pull Request #3140: Add Versioning Support from `version.txt`

8 of 8 new or added lines in 2 files covered. (100.0%)

1293 existing lines in 43 files now uncovered.

50627 of 59548 relevant lines covered (85.02%)

35584918.67 hits per line

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

93.75
/include/openmc/interpolate.h
1
#ifndef OPENMC_INTERPOLATE_H
2
#define OPENMC_INTERPOLATE_H
3

4
#include <cmath>
5
#include <vector>
6

7
#include "openmc/error.h"
8
#include "openmc/search.h"
9
#include "openmc/span.h"
10

11
namespace openmc {
12

13
inline double interpolate_lin_lin(
2,095,248✔
14
  double x0, double x1, double y0, double y1, double x)
15
{
16
  return y0 + (x - x0) / (x1 - x0) * (y1 - y0);
2,095,248✔
17
}
18

19
inline double interpolate_lin_log(
382,656✔
20
  double x0, double x1, double y0, double y1, double x)
21
{
22
  return y0 + std::log(x / x0) / std::log(x1 / x0) * (y1 - y0);
382,656✔
23
}
24

25
inline double interpolate_log_lin(
382,656✔
26
  double x0, double x1, double y0, double y1, double x)
27
{
28
  return y0 * std::exp((x - x0) / (x1 - x0) * std::log(y1 / y0));
382,656✔
29
}
30

31
inline double interpolate_log_log(
382,656✔
32
  double x0, double x1, double y0, double y1, double x)
33
{
34
  double f = std::log(x / x0) / std::log(x1 / x0);
382,656✔
35
  return y0 * std::exp(f * std::log(y1 / y0));
382,656✔
36
}
37

38
inline double interpolate_lagrangian(
765,312✔
39
  span<const double> xs, span<const double> ys, int idx, double x, int order)
40
{
41
  double output {0.0};
765,312✔
42

43
  for (int i = 0; i < order + 1; i++) {
3,443,904✔
44
    double numerator {1.0};
2,678,592✔
45
    double denominator {1.0};
2,678,592✔
46
    for (int j = 0; j < order + 1; j++) {
12,244,992✔
47
      if (i == j)
9,566,400✔
48
        continue;
2,678,592✔
49
      numerator *= (x - xs[idx + j]);
6,887,808✔
50
      denominator *= (xs[idx + i] - xs[idx + j]);
6,887,808✔
51
    }
52
    output += (numerator / denominator) * ys[idx + i];
2,678,592✔
53
  }
54

55
  return output;
765,312✔
56
}
57

58
inline double interpolate(span<const double> xs, span<const double> ys,
4,391,184✔
59
  double x, Interpolation i = Interpolation::lin_lin)
60
{
61
  int idx = lower_bound_index(xs.begin(), xs.end(), x);
4,391,184✔
62

63
  if (idx == xs.size())
4,391,184✔
UNCOV
64
    idx--;
×
65

66
  switch (i) {
4,391,184✔
67
  case Interpolation::histogram:
382,656✔
68
    return ys[idx];
382,656✔
69
  case Interpolation::lin_lin:
2,095,248✔
70
    return interpolate_lin_lin(xs[idx], xs[idx + 1], ys[idx], ys[idx + 1], x);
2,095,248✔
71
  case Interpolation::log_log:
382,656✔
72
    return interpolate_log_log(xs[idx], xs[idx + 1], ys[idx], ys[idx + 1], x);
382,656✔
73
  case Interpolation::lin_log:
382,656✔
74
    return interpolate_lin_log(xs[idx], xs[idx + 1], ys[idx], ys[idx + 1], x);
382,656✔
75
  case Interpolation::log_lin:
382,656✔
76
    return interpolate_log_lin(xs[idx], xs[idx + 1], ys[idx], ys[idx + 1], x);
382,656✔
77
  case Interpolation::quadratic:
382,656✔
78
    // move back one point if x is in the last interval of the x-grid
79
    if (idx == xs.size() - 2 && idx > 0)
382,656✔
80
      idx--;
216✔
81
    return interpolate_lagrangian(xs, ys, idx, x, 2);
382,656✔
82
  case Interpolation::cubic:
382,656✔
83
    // if x is not in the first interval of the x-grid, move back one
84
    if (idx > 0)
382,656✔
85
      idx--;
10,788✔
86
    // if the index was the last interval of the x-grid, move it back one more
87
    if (idx == xs.size() - 3)
382,656✔
88
      idx--;
216✔
89
    return interpolate_lagrangian(xs, ys, idx, x, 3);
382,656✔
UNCOV
90
  default:
×
UNCOV
91
    fatal_error("Unsupported interpolation");
×
92
  }
93
}
94

95
} // namespace openmc
96

97
#endif
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