CoolProp
8.0.0
An open-source fluid property and humid air property database
include
CoolProp
sbtl
SurfaceSpec.h
Go to the documentation of this file.
1
#ifndef COOLPROP_SBTL_SURFACE_SPEC_H
2
#define COOLPROP_SBTL_SURFACE_SPEC_H
3
4
#include <cstddef>
5
#include <cstdint>
6
#include <functional>
7
#include <memory>
8
#include <string>
9
#include <utility>
10
#include <vector>
11
12
#include "
CoolProp/AbstractState.h
"
13
#include "
CoolProp/region/AxisTransform.h
"
14
#include "
CoolProp/region/BoundaryCurve.h
"
15
#include "
CoolProp/svd/SVDDecomposition.h
"
16
#include "
CoolProp/DataStructures.h
"
17
18
namespace
CoolProp
{
19
namespace
sbtl {
20
21
// Per-region geometry: primary axis + two boundary curves on the
22
// secondary axis. Identical to what `region::Region` takes, but
23
// staged in a value-type aggregate so SurfaceSpec can be assembled
24
// incrementally before any Region exists.
25
struct
RegionSpec
26
{
27
// Default-state primary is filled in by builder code before any
28
// build_surface() call reads it; the aggregate default is a
29
// never-contains AxisTransform that fails AxisTransform::make's
30
// invariants if accidentally used.
31
region::AxisTransform
primary
{
region::AxisScale::LINEAR
, 0.0, 1.0, 0.0, 1.0, 1.0};
32
std::unique_ptr<region::BoundaryCurve>
b_lo
;
33
std::unique_ptr<region::BoundaryCurve>
b_hi
;
34
// Secondary-axis (eta) normalisation scale. LINEAR by default; set
35
// LOG for wide-dynamic-range secondary axes (see region::Region).
36
region::AxisScale
secondary
{
region::AxisScale::LINEAR
};
37
38
RegionSpec
() =
default
;
39
RegionSpec
(
region::AxisTransform
p, std::unique_ptr<region::BoundaryCurve> lo, std::unique_ptr<region::BoundaryCurve> hi,
40
region::AxisScale
sec =
region::AxisScale::LINEAR
)
41
:
primary
(p),
b_lo
(std::move(lo)),
b_hi
(std::move(hi)),
secondary
(sec) {}
42
RegionSpec
(
const
RegionSpec
&) =
delete
;
43
RegionSpec
&
operator=
(
const
RegionSpec
&) =
delete
;
44
RegionSpec
(
RegionSpec
&&) =
default
;
45
RegionSpec
&
operator=
(
RegionSpec
&&) =
default
;
46
~RegionSpec
() =
default
;
47
};
48
49
// One output property to tabulate on the surface, plus the transform
50
// the SVD evaluator should apply at lookup time.
51
//
52
// IDENTITY : value = Σ_k σ_k u_k v_k (default)
53
// EXP : value = exp(Σ_k σ_k u_k v_k) (log-fit)
54
//
55
// EXP is the right choice for strictly-positive properties with wide
56
// dynamic range (density, pressure). IDENTITY for properties that
57
// can change sign or that vary by orders of magnitude only locally
58
// (enthalpy near reference state, entropy, internal energy).
59
struct
PropertySpec
60
{
61
::CoolProp::parameters
key
=
::CoolProp::iDmass
;
62
svd::OutputTransform
transform
=
svd::OutputTransform::IDENTITY
;
63
};
64
65
// Complete recipe for one SVDSurface. Captures both the geometry
66
// (how regions are bounded) and the thermodynamics (how to sample
67
// HEOS at any (a, b) and which properties to read out).
68
//
69
// The two callbacks `update_state` and `read_property` are the
70
// thermodynamics-aware glue that keeps the rest of the library
71
// input-pair-agnostic:
72
//
73
// update_state(heos, a, b)
74
// ↑ takes the surface's (a, b) inputs and puts the HEOS state
75
// into the matching configuration via the right
76
// AbstractState::update() input-pair call.
77
//
78
// read_property(heos, key)
79
// ↑ reads `key` off the already-updated HEOS state.
80
//
81
// PH preset uses `heos.update(HmassP_INPUTS, h, p)` then
82
// `heos.rhomass()` / `heos.T()` / `heos.smass()` / `heos.umass()`.
83
// PT preset uses `heos.update(PT_INPUTS, p, T)` then
84
// `heos.rhomass()` / `heos.hmass()` / `heos.smass()` / `heos.umass()`.
85
// DU / HS / PS presets plug in by writing their own pair of lambdas;
86
// no other files in this library need to change.
87
struct
SurfaceSpec
88
{
89
std::string
fluid_name
;
90
// Source-backend name ("HEOS" / "REFPROP" / "IF97") — used by
91
// sample_grid to spawn per-thread AbstractState instances when
92
// the PARALLEL_SVDSBTL_SAMPLING config flag is set. Empty value
93
// forces serial sampling regardless of the config (no factory
94
// metadata to clone from).
95
std::string
source_backend
;
96
// The unscoped CoolProp::input_pairs enum lacks a portable
97
// "sentinel" value — initialise to PT_INPUTS which is always a
98
// valid enumerator, then expect builders to overwrite.
99
::CoolProp::input_pairs
input_pair
=
::CoolProp::PT_INPUTS
;
100
std::vector<RegionSpec>
regions
;
101
std::vector<PropertySpec>
properties
;
102
103
// Thermodynamics-aware glue. See SurfaceSpec docstring above.
104
// update_state should throw on two-phase / HEOS failure; the
105
// factory's per-cell loop catches and treats that cell as NaN.
106
std::function<void(
::CoolProp::AbstractState
&,
double
a,
double
b)>
update_state
;
107
std::function<double(
::CoolProp::AbstractState
&,
::CoolProp::parameters
)>
read_property
;
108
109
// SVD grid sizing. The defaults match Phase 2a's production
110
// resolution (Water max ≈ 7e-5 fractional with CubicSpline sat
111
// boundaries). Override per-fluid when needed.
112
std::size_t
NT
= 200;
113
std::size_t
NR
= 800;
114
std::int32_t
rank
= 20;
115
116
SurfaceSpec
() =
default
;
117
SurfaceSpec
(
const
SurfaceSpec
&) =
delete
;
118
SurfaceSpec
&
operator=
(
const
SurfaceSpec
&) =
delete
;
119
SurfaceSpec
(
SurfaceSpec
&&) =
default
;
120
SurfaceSpec
&
operator=
(
SurfaceSpec
&&) =
default
;
121
~SurfaceSpec
() =
default
;
122
};
123
124
}
// namespace sbtl
125
}
// namespace CoolProp
126
127
#endif
// COOLPROP_SBTL_SURFACE_SPEC_H
Generated by
1.9.4