CoolProp
HelmholtzEOSBackend.h
1 /*
2  * AbstractBackend.h
3  *
4  * Created on: 20 Dec 2013
5  * Author: jowr
6  */
7 
8 #ifndef HELMHOLTZEOSBACKEND_H_
9 #define HELMHOLTZEOSBACKEND_H_
10 
11 #include <vector>
12 #include "HelmholtzEOSMixtureBackend.h"
13 #include "Fluids/FluidLibrary.h"
14 #include "MixtureParameters.h"
15 #include "DataStructures.h"
16 
17 namespace CoolProp {
18 
20 inline std::string vecstring_to_string(const std::vector<std::string> &a) {
21  std::stringstream out;
22  out << "[ " << format("%s", a[0].c_str());
23  for (size_t j = 1; j < a.size(); j++) {
24  out << ", " << format("%s", a[j].c_str());
25  }
26  out << " ]";
27  return out.str();
28 };
29 
31 public:
33  HelmholtzEOSBackend(CoolPropFluid Fluid){set_components(std::vector<CoolPropFluid>(1,Fluid));};
34  HelmholtzEOSBackend(const std::string &name) : HelmholtzEOSMixtureBackend() {
35  Dictionary dict;
36  std::vector<double> mole_fractions;
37  std::vector<CoolPropFluid> components;
39  if (is_predefined_mixture(name, dict)){
40  std::vector<std::string> fluids = dict.get_string_vector("fluids");
41  mole_fractions = dict.get_double_vector("mole_fractions");
42  if (get_debug_level() > 0){
43  std::cout << "Got the fluids" << vecstring_to_string(fluids) << std::endl;
44  std::cout << "Got the fractions" << vec_to_string(mole_fractions, "%g") << std::endl;
45  }
46  for (unsigned int i = 0; i < fluids.size(); ++i){
47  components.push_back(library.get(fluids[i]));
48  }
49  }
50  else{
51  components.push_back(library.get(name)); // Until now it's empty
52  mole_fractions.push_back(1.);
53  }
54  // Set the components
55  set_components(components);
56  // Set the mole fractions
57  set_mole_fractions(std::vector<CoolPropDbl>(mole_fractions.begin(), mole_fractions.end()));
58  if (get_debug_level() > 0){ std::cout << "successfully set up state" << std::endl; }
59  };
60  virtual ~HelmholtzEOSBackend(){};
61  std::string backend_name(void) { return get_backend_string(HEOS_BACKEND_PURE); }
62 };
63 
64 } /* namespace CoolProp */
65 #endif /* HELMHOLTZEOSBACKEND_H_ */
std::vector< CoolPropDbl > mole_fractions
The bulk mole fractions of the mixture.
Definition: HelmholtzEOSMixtureBackend.h:49
std::string name()
Return the name - backend dependent.
Definition: AbstractState.h:679
std::string vecstring_to_string(const std::vector< std::string > &a)
Templates for turning vectors (1D-matrices) into strings.
Definition: HelmholtzEOSBackend.h:20
JSONFluidLibrary & get_library(void)
Get a reference to the library instance.
Definition: FluidLibrary.cpp:316
int get_debug_level()
Get the debug level.
Definition: CoolProp.cpp:63
void set_mole_fractions(const std::vector< CoolPropDbl > &mole_fractions)
Set the mole fractions.
Definition: HelmholtzEOSMixtureBackend.cpp:123
Definition: HelmholtzEOSBackend.h:30
A thermophysical property provider for critical and reducing values as well as derivatives of Helmhol...
Definition: CoolPropFluid.h:476
Definition: CoolPropTools.h:63
bool is_predefined_mixture(const std::string &name, Dictionary &dict)
Get the parameters for a predefined mixture - R410A, R404A, etc.
Definition: MixtureParameters.cpp:53
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: HelmholtzEOSBackend.h:61
virtual void set_components(const std::vector< CoolPropFluid > &components, bool generate_SatL_and_SatV=true)
Set the components of the mixture.
Definition: HelmholtzEOSMixtureBackend.cpp:92
Definition: HelmholtzEOSMixtureBackend.h:22
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
CoolPropFluid get(const std::string &key)
Get a CoolPropFluid instance stored in this library.
Definition: FluidLibrary.h:1216
std::vector< CoolPropFluid > components
The components that are in use.
Definition: HelmholtzEOSMixtureBackend.h:45
A container for the fluid parameters for the CoolProp fluids.
Definition: FluidLibrary.h:27
std::string vec_to_string(const std::vector< T > &a, const char *fmt)
Templates for turning vectors (1D-matrices) into strings.
Definition: MatrixMath.h:299