CoolProp 8.0.0
An open-source fluid property and humid air property database
ConstantCurve.h
Go to the documentation of this file.
1#ifndef COOLPROP_REGION_CONSTANT_CURVE_H
2#define COOLPROP_REGION_CONSTANT_CURVE_H
3
4#include <stdexcept>
5
7
8namespace CoolProp {
9namespace region {
10
11// Trivial BoundaryCurve b(a) = c, used for fixed ceilings/floors such as
12// a T_max or p_max plane. All three queries are O(1).
13class ConstantCurve final : public BoundaryCurve
14{
15 public:
16 ConstantCurve(double a_lo, double a_hi, double b_value) : a_lo_(a_lo), a_hi_(a_hi), b_(b_value) {
17 if (!(a_hi_ > a_lo_)) {
18 throw std::invalid_argument("ConstantCurve: a_hi must exceed a_lo");
19 }
20 }
21
22 // Plain-data snapshot for serialization. Safe to expose because
23 // the only invariant ConstantCurve enforces (a_hi > a_lo) is
24 // re-checked by the constructor.
25 struct State
26 {
27 double a_lo;
28 double a_hi;
29 double b;
30 };
31 [[nodiscard]] State state() const noexcept {
32 return State{a_lo_, a_hi_, b_};
33 }
34
35 [[nodiscard]] double eval(double /*a*/) const noexcept override {
36 return b_;
37 }
38
39 // db/da is exactly zero — analytic derivative of the constant function.
40 [[nodiscard]] double eval_da(double /*a*/) const noexcept override {
41 return 0.0;
42 }
43
44 [[nodiscard]] std::pair<double, double> bounds() const noexcept override {
45 return {b_, b_};
46 }
47
48 [[nodiscard]] std::pair<double, double> a_range() const noexcept override {
49 return {a_lo_, a_hi_};
50 }
51
52 private:
53 double a_lo_;
54 double a_hi_;
55 double b_;
56};
57
58} // namespace region
59} // namespace CoolProp
60
61#endif // COOLPROP_REGION_CONSTANT_CURVE_H