CoolProp
8.0.0
An open-source fluid property and humid air property database
src
Backends
Helmholtz
Fluids
FluidLibraryFactories.h
Go to the documentation of this file.
1
#ifndef FLUIDLIBRARYFACTORIES_H
2
#define FLUIDLIBRARYFACTORIES_H
3
4
// NON-INSTALLED factory helpers that build fluid-model objects from
5
// nlohmann::json. These live under src/ (not include/) so that the
6
// nlohmann::json type never appears in a public/installed header.
7
// Neither factory requires friendship: make_surface_tension_correlation uses
8
// only public members, and make_saturation_ancillary builds a plain-typed
9
// SaturationAncillaryFunction::Values bundle and constructs from it.
10
//
11
// Convention: every value type constructed from JSON exposes a nested public
12
// `struct Values` (plain/POD fields) plus a single `explicit T(const Values&)`
13
// ctor; these factories own all nlohmann parsing and hand a Values across, so
14
// no JSON type appears in any installed header. (This is distinct from the
15
// link-time export control via cmake/CoolPropJSONVisibility.cmake that hides
16
// nlohmann/valijson symbols per shared product at link time.)
17
18
#include "
CoolProp/detail/json.h
"
19
#include "
CoolProp/fluids/Ancillaries.h
"
20
21
namespace
cpjson
{
22
26
inline
CoolProp::SurfaceTensionCorrelation
make_surface_tension_correlation
(
const
nlohmann::json& j) {
27
CoolProp::SurfaceTensionCorrelation::Values
vals;
28
vals.
a
=
cpjson::get_long_double_array
(j.at(
"a"
));
29
vals.
n
=
cpjson::get_long_double_array
(j.at(
"n"
));
30
if
(vals.
a
.size() != vals.
n
.size()) {
31
throw
CoolProp::ValueError
(
"Surface tension 'a' and 'n' arrays must have equal length"
);
32
}
33
vals.
Tc
=
cpjson::get_double
(j,
"Tc"
);
34
vals.
BibTeX
=
cpjson::get_string
(j,
"BibTeX"
);
35
return
CoolProp::SurfaceTensionCorrelation
(vals);
36
}
37
41
inline
CoolProp::SaturationAncillaryFunction
make_saturation_ancillary
(
const
nlohmann::json& j) {
42
CoolProp::SaturationAncillaryFunction::Values
vals;
43
std::string type =
cpjson::get_string
(j,
"type"
);
44
if
(!type.compare(
"rational_polynomial"
)) {
45
vals.
type
=
CoolProp::SaturationAncillaryFunction::TYPE_RATIONAL_POLYNOMIAL
;
46
vals.
num_coeffs
=
CoolProp::vec_to_eigen
(
cpjson::get_double_array
(j.at(
"A"
)));
47
vals.
den_coeffs
=
CoolProp::vec_to_eigen
(
cpjson::get_double_array
(j.at(
"B"
)));
48
vals.
max_abs_error
=
cpjson::get_double
(j,
"max_abs_error"
);
49
try
{
50
vals.
Tmin
=
cpjson::get_double
(j,
"Tmin"
);
51
vals.
Tmax
=
cpjson::get_double
(j,
"Tmax"
);
52
}
catch
(...) {
53
vals.
Tmin
= _HUGE;
54
vals.
Tmax
= _HUGE;
55
}
56
}
else
{
57
if
(!type.compare(
"rhoLnoexp"
))
58
vals.
type
=
CoolProp::SaturationAncillaryFunction::TYPE_NOT_EXPONENTIAL
;
59
else
60
vals.
type
=
CoolProp::SaturationAncillaryFunction::TYPE_EXPONENTIAL
;
61
vals.
n
=
cpjson::get_double_array
(j.at(
"n"
));
62
vals.
t
=
cpjson::get_double_array
(j.at(
"t"
));
63
if
(vals.
n
.size() != vals.
t
.size()) {
64
throw
CoolProp::ValueError
(
"Ancillary 'n' and 't' arrays must have equal length"
);
65
}
66
vals.
Tmin
=
cpjson::get_double
(j,
"Tmin"
);
67
vals.
Tmax
=
cpjson::get_double
(j,
"Tmax"
);
68
vals.
reducing_value
=
cpjson::get_double
(j,
"reducing_value"
);
69
vals.
using_tau_r
=
cpjson::get_bool
(j,
"using_tau_r"
);
70
vals.
T_r
=
cpjson::get_double
(j,
"T_r"
);
71
}
72
return
CoolProp::SaturationAncillaryFunction
(vals);
73
}
74
75
}
// namespace cpjson
76
77
#endif
// FLUIDLIBRARYFACTORIES_H
Generated by
1.9.4