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 {
32  public:
35  set_components(std::vector<CoolPropFluid>(1, Fluid));
36  };
37  HelmholtzEOSBackend(const std::string& name) : HelmholtzEOSMixtureBackend() {
38  Dictionary dict;
39  std::vector<double> mole_fractions;
40  std::vector<CoolPropFluid> components;
42  if (is_predefined_mixture(name, dict)) {
43  std::vector<std::string> fluids = dict.get_string_vector("fluids");
44  mole_fractions = dict.get_double_vector("mole_fractions");
45  if (get_debug_level() > 0) {
46  std::cout << "Got the fluids" << vecstring_to_string(fluids) << std::endl;
47  std::cout << "Got the fractions" << vec_to_string(mole_fractions, "%g") << std::endl;
48  }
49  for (unsigned int i = 0; i < fluids.size(); ++i) {
50  components.push_back(library.get(fluids[i]));
51  }
52  } else {
53  components.push_back(library.get(name)); // Until now it's empty
54  mole_fractions.push_back(1.);
55  }
56  // Set the components
57  set_components(components);
58  // Set the mole fractions
59  set_mole_fractions(std::vector<CoolPropDbl>(mole_fractions.begin(), mole_fractions.end()));
60  if (get_debug_level() > 0) {
61  std::cout << "successfully set up state" << std::endl;
62  }
63  };
64  virtual ~HelmholtzEOSBackend(){};
65  std::string backend_name(void) {
66  return get_backend_string(HEOS_BACKEND_PURE);
67  }
68 };
69 
70 } /* namespace CoolProp */
71 #endif /* HELMHOLTZEOSBACKEND_H_ */
void set_mole_fractions(const std::vector< CoolPropDbl > &mf)
Set the mole fractions.
Definition: HelmholtzEOSMixtureBackend.cpp:121
std::string name()
Return the name - backend dependent.
Definition: AbstractState.h:1017
MoleFractions mole_fractions
The bulk mole fractions of the mixture.
Definition: HelmholtzEOSMixtureBackend.h:96
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:327
int get_debug_level()
Get the debug level.
Definition: CoolProp.cpp:64
Definition: HelmholtzEOSBackend.h:30
A thermophysical property provider for critical and reducing values as well as derivatives of Helmhol...
Definition: CoolPropFluid.h:521
Definition: CoolPropTools.h:61
bool is_predefined_mixture(const std::string &name, Dictionary &dict)
Get the parameters for a predefined mixture - R410A, R404A, etc.
Definition: MixtureParameters.cpp:64
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: HelmholtzEOSBackend.h:65
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:58
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:1213
std::vector< CoolPropFluid > components
The components that are in use.
Definition: HelmholtzEOSMixtureBackend.h:92
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:319