CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tests.cpp
Go to the documentation of this file.
1 
2 
3 
4 #include "CoolPropDLL.h"
5 #include "CoolProp.h"
6 
7 #ifndef DISABLE_CATCH
8  #include "Tests.h"
9  #define CATCH_CONFIG_RUNNER
10  #include "Catch/catch.hpp"
11  TEST_CASE( "Check reference state", "[reference_state]" )
12  {
13  SECTION( "IIR")
14  {
15  set_reference_stateS("Propane","IIR");
16  double h_EOS = PropsSI("H","T",273.15,"Q",0,"Propane");
17  double s_EOS = PropsSI("S","T",273.15,"Q",0,"Propane");
18  double h_target = 200000;
19  double s_target = 1000;
20 
21  REQUIRE(abs(h_target-h_EOS) < 1e-6);
22  REQUIRE(abs(s_target-s_EOS) < 1e-6);
23  }
24  SECTION( "NBP")
25  {
26  set_reference_stateS( "Propane", "NBP");
27  double h_EOS = PropsSI("H","P",101325,"Q",0,"Propane");
28  double s_EOS = PropsSI("S","P",101325,"Q",0,"Propane");
29  double h_target = 0;
30  double s_target = 0;
31 
32  REQUIRE(abs(h_target-h_EOS) < 1e-6);
33  REQUIRE(abs(s_target-s_EOS) < 1e-6);
34  }
35  SECTION("ASHRAE")
36  {
37  set_reference_stateS( "Propane", "ASHRAE");
38  double h_EOS = PropsSI( "H", "T",233.15, "Q",0, "Propane");
39  double s_EOS = PropsSI( "S", "T",233.15, "Q",0, "Propane");
40  double h_target = 0;
41  double s_target = 0;
42 
43  REQUIRE(abs(h_target-h_EOS) < 1e-6);
44  REQUIRE(abs(s_target-s_EOS) < 1e-6);
45  }
46  }
47 
48  TEST_CASE("Check units of fluid constants", "[fast]" )
49  {
50  SECTION( "kSI")
51  {
53 
54  SECTION( "pcrit")
55  {
56  double p_Props1SI = Props1SI( "R134a", "pcrit");
57  double p_Props1 = Props1( "R134a", "pcrit")*1000;
58  double p_Props = Props( "pcrit",'T',300,'Q',0, "R134a")*1000;
59  double p_PropsSI = PropsSI( "pcrit", "T",300, "Q",0, "R134a");
60  double p_IProps = IProps(iPcrit,iT,0,iP,0,get_Fluid_index("R134a"))*1000;
61  double p_IPropsSI = IPropsSI(iPcrit,iT,0,iP,0,get_Fluid_index("R134a"));
62  REQUIRE(fabs(p_Props1/p_Props-1) < 1e-6);
63  REQUIRE(fabs(p_PropsSI/p_Props-1) < 1e-6);
64  REQUIRE(fabs(p_PropsSI/p_Props1SI-1) < 1e-6);
65  REQUIRE(fabs(p_IProps/p_Props1SI-1) < 1e-6);
66  REQUIRE(fabs(p_IPropsSI/p_Props1SI-1) < 1e-6);
67  }
68  }
69  SECTION( "SI")
70  {
72 
73  SECTION( "pcrit")
74  {
75  double p_Props1SI = Props1( "R134a", "pcrit");
76  double p_Props1 = Props1( "R134a", "pcrit");
77  double p_Props = Props( "pcrit",'T',300,'Q',0, "R134a");
78  double p_PropsSI = PropsSI( "pcrit", "T",300, "Q",0, "R134a");
79  double p_IProps = IProps(iPcrit,iT,0,iP,0,get_Fluid_index("R134a"));
80  //double p_IPropsSI = IPropsSI(iPcrit,iT,0,iP,0,get_Fluid_index("R134a"));
81  REQUIRE(fabs(p_Props1/p_Props-1) < 1e-6);
82  REQUIRE(fabs(p_PropsSI/p_Props-1) < 1e-6);
83  REQUIRE(fabs(p_PropsSI/p_Props1SI-1) < 1e-6);
84  REQUIRE(fabs(p_IProps/p_Props1SI-1) < 1e-6);
85  REQUIRE(fabs(p_IProps/p_Props1SI-1) < 1e-6);
86  }
88  }
89  }
90 
91  TEST_CASE("Normal boiling point of water", "[fast]" )
92  {
93  SECTION( "kSI")
94  {
95  int us = get_standard_unit_system();
97  SECTION( "pcrit")
98  {
99  double T_Props = Props("T","P",101.325,"Q",0,"Water");
100  double T_PropsSI = PropsSI("T","P",101325,"Q",0,"Water");
101  double T_IProps = IProps(iT,iP,101.325,iQ,0,get_Fluid_index("Water"));
102  double T_IPropsSI = IPropsSI(iT,iP,101325,iQ,0,get_Fluid_index("Water"));
103  double T_nbp = 99.98+273.15;
104  REQUIRE(fabs(T_Props-T_nbp) < 0.01);
105  REQUIRE(fabs(T_PropsSI-T_Props) < 0.01);
106  REQUIRE(fabs(T_IProps-T_PropsSI) < 0.01);
107  REQUIRE(fabs(T_IPropsSI-T_IProps) < 0.01);
108  }
110  }
111  SECTION( "SI")
112  {
113  int us = get_standard_unit_system();
115  SECTION( "pcrit")
116  {
117  double T_Props = Props("T","P",101325,"Q",0,"Water");
118  double T_PropsSI = PropsSI("T","P",101325,"Q",0,"Water");
119  double T_IProps = IProps(iT,iP,101325,iQ,0,get_Fluid_index("Water"));
120  double T_IPropsSI = IPropsSI(iT,iP,101325,iQ,0,get_Fluid_index("Water"));
121  double T_nbp = 99.98+273.15;
122  REQUIRE(fabs(T_Props-T_nbp) < 0.01);
123  REQUIRE(fabs(T_PropsSI-T_Props) < 0.01);
124  REQUIRE(fabs(T_IProps-T_PropsSI) < 0.01);
125  REQUIRE(fabs(T_IPropsSI-T_IProps) < 0.01);
126  }
128  }
129  }
130 
131  static Catch::Session session; // There must be exactly once instance
132 
134  {
135  Catch::ConfigData &config = session.configData();
136  config.testsOrTags.clear();
137  config.testsOrTags.push_back("[fast]");
138  session.useConfigData(config);
139  return session.run();
140  }
141 
143  {
144  Catch::ConfigData &config = session.configData();
145  config.testsOrTags.clear();
146  config.testsOrTags.push_back("~[slow]");
147  session.useConfigData(config);
148 
149  time_t t1, t2;
150  t1 = clock();
151  session.run();
152  t2 = clock();
153  printf("Elapsed time for not slow tests: %g s",(double)(t2-t1)/CLOCKS_PER_SEC);
154 
155  return 1;
156  }
157 
158  int run_user_defined_tests(const std::vector<std::string> & tests_or_tags)
159  {
160  Catch::ConfigData &config = session.configData();
161  config.testsOrTags.clear();
162  for (unsigned int i = 0; i < tests_or_tags.size(); i++)
163  {
164  config.testsOrTags.push_back(tests_or_tags[i]);
165  }
166  session.useConfigData(config);
167 
168  time_t t1, t2;
169  t1 = clock();
170  session.run();
171  t2 = clock();
172  printf("Elapsed time for user defined tests: %g s",(double)(t2-t1)/CLOCKS_PER_SEC);
173 
174  return 1;
175  }
176 
177  void run_tests()
178  {
179  Catch::ConfigData &config = session.configData();
180  config.testsOrTags.clear();
181  session.useConfigData(config);
182  session.run();
183  }
184 
185 
186 #endif
EXPORT_CODE double CONVENTION IProps(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
Definition: CoolProp.cpp:758
long get_Fluid_index(std::string FluidName)
Definition: CoolProp.cpp:239
EXPORT_CODE void CONVENTION set_standard_unit_system(int val)
int run_not_slow_tests()
Definition: Tests.cpp:142
double Props(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:902
double Props1(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:586
EXPORT_CODE int CONVENTION get_standard_unit_system(void)
double PropsSI(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:886
int run_fast_tests()
Definition: Tests.cpp:133
void run_tests()
Definition: Tests.cpp:177
REQUIRE(fabs(CPWater.p()-RPWater.p())< 1e-4)
TEST_CASE("Check reference state","[reference_state]")
Definition: Tests.cpp:11
#define SECTION(name, description)
Definition: catch.hpp:8088
int set_reference_stateS(std::string Ref, std::string reference_state)
Definition: CoolProp.cpp:1037
int run_user_defined_tests(const std::vector< std::string > &tests_or_tags)
Definition: Tests.cpp:158
EXPORT_CODE double CONVENTION IPropsSI(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
Definition: CoolProp.cpp:861
double Props1SI(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:570