diff --git a/include/AbstractState.h b/include/AbstractState.h index 7519c4ae..8fcf7b9d 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -416,6 +416,10 @@ public: void set_mass_fractions(const std::vector &mass_fractions){ set_mass_fractions(std::vector(mass_fractions.begin(), mass_fractions.end())); }; void set_volu_fractions(const std::vector &volu_fractions){ set_volu_fractions(std::vector(volu_fractions.begin(), volu_fractions.end())); }; + #ifdef EMSCRIPTEN + void set_mole_fractions_double(const std::vector &mole_fractions){ set_mole_fractions(std::vector(mole_fractions.begin(), mole_fractions.end())); }; + #endif + /// Get the mole fractions of the equilibrium liquid phase std::vector mole_fractions_liquid(void){ return calc_mole_fractions_liquid(); }; /// Get the mole fractions of the equilibrium liquid phase (but as a double for use in SWIG wrapper) diff --git a/src/AbstractState.cpp b/src/AbstractState.cpp index 18479a63..1f1030d7 100644 --- a/src/AbstractState.cpp +++ b/src/AbstractState.cpp @@ -767,3 +767,47 @@ TEST_CASE("Check AbstractState","[AbstractState]") } #endif + + +/// ********************************************************************************* +/// ********************************************************************************* +/// EMSCRIPTEN (for javascript) +/// ********************************************************************************* +/// ********************************************************************************* + +#ifdef EMSCRIPTEN + +#include +using namespace emscripten; + +CoolProp::AbstractState * factory(const std::string &backend, const std::string &fluid_names) +{ + return CoolProp::AbstractState::factory(backend, strsplit(fluid_names, '&')); +} + +// Binding code +EMSCRIPTEN_BINDINGS(abstract_state_bindings) { + + register_vector("VectorDouble"); + register_vector("VectorString"); + + //value_object("CoolProp::PhaseEnvelopeData") + // // Use X macros to auto-generate the variables; + // // each will look something like: .field("T", &CoolProp::PhaseEnvelopeData::T); + // #define X(name) .field("name", &CoolProp::PhaseEnvelopeData::name) + // PHASE_ENVELOPE_VECTORS + // #undef X + // ; + + function("factory", &factory, allow_raw_pointers()); + + class_("AbstractState") + .function("gas_constant", &CoolProp::AbstractState::gas_constant) + .function("update", &CoolProp::AbstractState::update) + .function("set_mole_fractions", &CoolProp::AbstractState::set_mole_fractions_double) + .function("build_phase_envelope", &CoolProp::AbstractState::build_phase_envelope) + .function("get_phase_envelope_data", &CoolProp::AbstractState::get_phase_envelope_data); + +} + +#endif \ No newline at end of file