AGA8 WebAssembly  1.0
bindings for AGA8 gas properties calculations
Loading...
Searching...
No Matches
bindings.cpp File Reference

Emscripten bindings for the AGA8 gas calculation library. More...

#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "Detail.h"
#include "GERG2008.h"
#include "Gross.h"
Include dependency graph for bindings.cpp:

Go to the source code of this file.

Data Structures

struct  gasMixture
 
struct  PressureResult
 
struct  DensityResult
 Structure to hold the results of density calculations. More...
 
struct  PropertiesDetailResult
 
struct  PropertiesGERGResult
 Structure containing thermodynamic properties for GERG-2008 calculations. More...
 
struct  xGrs
 
struct  PressureGrossResult
 
struct  GrossHvResult
 
struct  GrossInputsResult
 
struct  BmixResult
 
struct  GrossMethod1Result
 
struct  GrossMethod2Result
 

Functions

std::vector< double > gasMixture_to_vector (gasMixture js_object)
 Converts a JavaScript gasMixture Object to a C++ struct.
 
std::vector< double > xGrs_to_vector (xGrs js_object)
 Converts a JavaScript xGrs Object to a C++ struct.
 
xGrs vector_to_xGrs (const std::vector< double > &vec)
 Converts a C++ vector to a JavaScript xGrs object.
 
std::vector< double > array_to_vector (const val &js_array)
 Converts a JavaScript array to a C++ vector of doubles.
 
val vector_to_array (const std::vector< double > &vec)
 Converts a C++ vector of doubles to a JavaScript array.
 
double MolarMassDetail_wrapper (gasMixture x_array)
 Calculates the molar mass of a gas mixture given mole percentages.
 
PressureResult PressureDetail_wrapper (double T, double D, gasMixture x_array)
 Wraps the PressureDetail function to calculate pressure and compressibility factor.
 
DensityResult DensityDetail_wrapper (double T, double P, gasMixture x_array)
 Calculates the density of a gas mixture given temperature, pressure and composition.
 
PropertiesDetailResult PropertiesDetail_wrapper (double T, double D, gasMixture x_array)
 Wrapper function to calculate detailed thermodynamic properties of a gas mixture.
 
double MolarMassGERG_wrapper (gasMixture x_array)
 Calculates the molar mass of a gas mixture using GERG-2008 equation of state.
 
PressureResult PressureGERG_wrapper (double T, double D, gasMixture x_array)
 Calculates pressure and compressibility factor using GERG-2008 equation of state.
 
DensityResult DensityGERG_wrapper (int iflag, double T, double P, gasMixture x_array)
 Wrapper function to calculate density using GERG-2008 equation of state.
 
PropertiesGERGResult PropertiesGERG_wrapper (double T, double D, gasMixture x_array)
 Calculates thermodynamic properties using GERG-2008 equation of state.
 
double MolarMassGross_wrapper (gasMixture x_array)
 Calculates the gross molar mass of a gas mixture.
 
PressureGrossResult PressureGross_wrapper (double T, double D, xGrs xGrs_object, double HCH)
 Wrapper function for PressureGross calculation.
 
DensityResult DensityGross_wrapper (double T, double P, xGrs xGrs_object, double HCH)
 Wrapper function for DensityGross calculation.
 
GrossHvResult GrossHv_wrapper (gasMixture x_array)
 Wrapper function to calculate gross heating values for a gas mixture.
 
GrossInputsResult GrossInputs_wrapper (double T, double P, gasMixture x_array)
 Wrapper function for GrossInputs calculation.
 
BmixResult Bmix_wrapper (double T, xGrs xGrs_object, double HCH)
 Calculates mixture second and third virial coefficients using the GERG-2008 equation of state.
 
GrossMethod1Result GrossMethod1_wrapper (double Th, double Td, double Pd, xGrs xGrs_object, double Gr, double Hv)
 Wrapper function for GrossMethod1 calculation method.
 
GrossMethod2Result GrossMethod2_wrapper (double Th, double Td, double Pd, xGrs xGrs_object, double Gr)
 Wrapper function for the GrossMethod2 calculation method.
 
 EMSCRIPTEN_BINDINGS (AGA8_module)
 Emscripten bindings for the AGA8 gas calculation module.
 

Detailed Description

Emscripten bindings for the AGA8 gas calculation library.

This file provides WebAssembly bindings for the AGA8 gas calculation library, enabling its use in JavaScript environments. It implements three main calculation methods:

  • Detail method (high accuracy)
  • GERG-2008 method (reference equations)
  • Gross method (simplified calculations)

The gas composition is represented using a 21-component system where:

  • Index 1: Methane
  • Index 2: Nitrogen
  • Index 3: Carbon dioxide
  • Index 4-14: Various hydrocarbons (Ethane through n-Decane)
  • Index 15-21: Other components (Hydrogen, Oxygen, CO, Water, H2S, Helium, Argon)
Note
All compositions must be provided as mole fractions (not percentages)
Temperature inputs are in Kelvin
Pressure inputs are in kPa
Density inputs are in mol/l (mol/dm³)

Example mixture (94% methane, 5% CO2, 1% helium): gasMixtureInMolePercent(1) = 0.94 // Methane gasMixtureInMolePercent(3) = 0.05 // CO2 gasMixtureInMolePercent(20) = 0.01 // Helium

Definition in file bindings.cpp.

Function Documentation

◆ array_to_vector()

std::vector< double > array_to_vector ( const val & js_array)

Converts a JavaScript array to a C++ vector of doubles.

Parameters
js_arrayJavaScript array object passed as an emscripten::val
Returns
std::vector<double> C++ vector containing the converted values

This function takes a JavaScript array passed through emscripten's val interface and converts it to a C++ std::vector<double>. Each element in the JavaScript array is converted to a double value.

Definition at line 379 of file bindings.cpp.

380{
381 auto length = js_array["length"].as<unsigned>();
382 std::vector<double> result(length);
383 for (unsigned i = 0; i < length; ++i)
384 {
385 result[i] = js_array[i].as<double>();
386 }
387 return result;
388}

◆ Bmix_wrapper()

BmixResult Bmix_wrapper ( double T,
xGrs xGrs_object,
double HCH )

Calculates mixture second and third virial coefficients using the GERG-2008 equation of state.

Parameters
TTemperature [K]
xGrs_objectArray of mole fractions for each component in the mixture
HCHParameter for handling hydrocarbon mixtures
Returns
BmixResult Structure containing:
  • B: Second virial coefficient [cm³/mol]
  • C: Third virial coefficient [(cm³/mol)²]
  • ierr: Error code (0 = successful)
  • herr: Error message string

This function serves as a wrapper for the Bmix calculation, converting array inputs to the required vector format and returning results in a structured format.

See also
Bmix For the underlying calculation implementation

Definition at line 790 of file bindings.cpp.

791{
792 std::vector<double> xGrs = xGrs_to_vector(xGrs_object);
793 double B = 0, C = 0;
794 int ierr = 0;
795 std::string herr;
796
797 Bmix(T, xGrs, HCH, B, C, ierr, herr);
798
799 BmixResult result = {B, C, ierr, herr};
800 return result;
801}
void Bmix(const double T, const std::vector< double > &xGrs, const double HCH, double &B, double &C, int &ierr, std::string &herr)
Calculate 2nd and 3rd virial coefficients for the mixture at T.
Definition Gross.cpp:412
std::vector< double > xGrs_to_vector(xGrs js_object)
Converts a JavaScript xGrs Object to a C++ struct.
Definition bindings.cpp:344

References Bmix(), and xGrs_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ DensityDetail_wrapper()

DensityResult DensityDetail_wrapper ( double T,
double P,
gasMixture x_array )

Calculates the density of a gas mixture given temperature, pressure and composition.

This function wraps the DensityDetail calculation for easier interface handling.

Parameters
TTemperature in K
PPressure in kPa
x_arrayGas mixture composition in mole percent
Returns
DensityResult struct containing:
  • D: Density in kg/m³
  • ierr: Error code (0 = successful)
  • herr: Error message
See also
DensityDetail For the underlying calculation implementation

Definition at line 468 of file bindings.cpp.

469{
470 std::vector<double> x = gasMixture_to_vector(x_array);
471 double D = 0;
472 int ierr = 0;
473 std::string herr;
474
475 DensityDetail(T, P, x, D, ierr, herr);
476
477 DensityResult result = {D, ierr, herr};
478 return result;
479}
void DensityDetail(const double T, const double P, const std::vector< double > &x, double &D, int &ierr, std::string &herr)
Calculates density as a function of temperature and pressure using an iterative method.
Definition Detail.cpp:246
std::vector< double > gasMixture_to_vector(gasMixture js_object)
Converts a JavaScript gasMixture Object to a C++ struct.
Definition bindings.cpp:311
Structure to hold the results of density calculations.
Definition bindings.cpp:129

References DensityDetail(), and gasMixture_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ DensityGERG_wrapper()

DensityResult DensityGERG_wrapper ( int iflag,
double T,
double P,
gasMixture x_array )

Wrapper function to calculate density using GERG-2008 equation of state.

Parameters
iflagFlag to specify calculation path (1: density from pressure/temperature, 2: pressure from density/temperature)
TTemperature [K]
PPressure [kPa]
x_arrayArray containing mole fractions of components in percent
Returns
DensityResult Struct containing:
  • D: Density [kg/m³]
  • ierr: Error flag (0: successful, non-zero: error occurred)
  • herr: Error message string
See also
DensityGERG For the underlying calculation implementation

Definition at line 580 of file bindings.cpp.

581{
582 std::vector<double> x = gasMixture_to_vector(x_array);
583 double D = 0;
584 int ierr = 0;
585 std::string herr;
586
587 DensityGERG(iflag, T, P, x, D, ierr, herr);
588
589 DensityResult result = {D, ierr, herr};
590 return result;
591}
void DensityGERG(const int iFlag, const double T, const double P, const std::vector< double > &x, double &D, int &ierr, std::string &herr)
Calculate density from temperature and pressure.
Definition GERG2008.cpp:247

References DensityGERG(), and gasMixture_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ DensityGross_wrapper()

DensityResult DensityGross_wrapper ( double T,
double P,
xGrs xGrs_object,
double HCH )

Wrapper function for DensityGross calculation.

This function calculates the density of a natural gas mixture using the GERG-2008 equation of state

Parameters
TTemperature [K]
PPressure [kPa]
xGrs_objectArray containing mole fractions of the mixture components
HCHHeating value [MJ/m³]
Returns
DensityResult struct containing:
  • D: Density [kg/m³]
  • ierr: Error code (0 = successful)
  • herr: Error message string
See also
DensityGross For the underlying calculation implementation
Note
This is a wrapper function that converts the input array to a vector before calling the main DensityGross function

Definition at line 703 of file bindings.cpp.

704{
705 std::vector<double> xGrs = xGrs_to_vector(xGrs_object);
706 double D = 0;
707 int ierr = 0;
708 std::string herr;
709
710 DensityGross(T, P, xGrs, HCH, D, ierr, herr);
711
712 DensityResult result = {D, ierr, herr};
713 return result;
714}
void DensityGross(const double T, const double P, const std::vector< double > &xGrs, const double HCH, double &D, int &ierr, std::string &herr)
Calculate density as a function of temperature and pressure.
Definition Gross.cpp:236

References DensityGross(), and xGrs_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ EMSCRIPTEN_BINDINGS()

EMSCRIPTEN_BINDINGS ( AGA8_module )

Emscripten bindings for the AGA8 gas calculation module.

These bindings expose the AGA8 gas calculation functionality to JavaScript/WebAssembly. It includes:

Enums:

  • GasComponent: Enumeration of different gas components (methane, nitrogen, etc.)

Types:

  • gasMixtureInMolePercent: Gas mixture composition in mole percent
  • xGrsArray: Array for gross method calculations
  • VectorDouble: Vector of double precision numbers

Value Objects:

Functions: Detail Methods:

  • SetupDetail: Initialize detail calculation method
  • MolarMassDetail: Calculate molar mass using detail method
  • PressureDetail: Calculate pressure using detail method
  • DensityDetail: Calculate density using detail method
  • PropertiesDetail: Calculate detailed properties

GERG Methods:

  • SetupGERG: Initialize GERG-2008 calculation method
  • MolarMassGERG: Calculate molar mass using GERG-2008
  • PressureGERG: Calculate pressure using GERG-2008
  • DensityGERG: Calculate density using GERG-2008
  • PropertiesGERG: Calculate properties using GERG-2008

Gross Methods:

  • SetupGross: Initialize gross calculation method
  • MolarMassGross: Calculate molar mass using gross method
  • PressureGross: Calculate pressure using gross method
  • DensityGross: Calculate density using gross method
  • GrossHv: Calculate heating value
  • GrossInputs: Process inputs for gross calculations
  • Bmix: Calculate binary mixture properties
  • GrossMethod1: Perform gross characterization method 1
  • GrossMethod2: Perform gross characterization method 2

Definition at line 921 of file bindings.cpp.

922{
923 register_vector<double>("VectorDouble");
924
925 value_object<gasMixture>("GasMixture")
926 .field("methane", &gasMixture::methane)
927 .field("nitrogen", &gasMixture::nitrogen)
928 .field("carbon_dioxide", &gasMixture::carbon_dioxide)
929 .field("ethane", &gasMixture::ethane)
930 .field("propane", &gasMixture::propane)
931 .field("isobutane", &gasMixture::isobutane)
932 .field("n_butane", &gasMixture::n_butane)
933 .field("isopentane", &gasMixture::isopentane)
934 .field("n_pentane", &gasMixture::n_pentane)
935 .field("n_hexane", &gasMixture::n_hexane)
936 .field("n_heptane", &gasMixture::n_heptane)
937 .field("n_octane", &gasMixture::n_octane)
938 .field("n_nonane", &gasMixture::n_nonane)
939 .field("n_decane", &gasMixture::n_decane)
940 .field("hydrogen", &gasMixture::hydrogen)
941 .field("oxygen", &gasMixture::oxygen)
942 .field("carbon_monoxide", &gasMixture::carbon_monoxide)
943 .field("water", &gasMixture::water)
944 .field("hydrogen_sulfide", &gasMixture::hydrogen_sulfide)
945 .field("helium", &gasMixture::helium)
946 .field("argon", &gasMixture::argon);
947
948 value_object<xGrs>("xGrs")
949 .field("hydrocarbon", &xGrs::hydrocarbon)
950 .field("nitrogen", &xGrs::nitrogen)
951 .field("carbon_dioxide", &xGrs::carbon_dioxide);
952
953 value_object<PressureResult>("PressureResult")
954 .field("P", &PressureResult::P)
955 .field("Z", &PressureResult::Z);
956
957 value_object<DensityResult>("DensityResult")
958 .field("D", &DensityResult::D)
959 .field("ierr", &DensityResult::ierr)
960 .field("herr", &DensityResult::herr);
961
962 value_object<PropertiesDetailResult>("PropertiesDetailResult")
963 .field("P", &PropertiesDetailResult::P)
964 .field("Z", &PropertiesDetailResult::Z)
965 .field("dPdD", &PropertiesDetailResult::dPdD)
966 .field("d2PdD2", &PropertiesDetailResult::d2PdD2)
967 .field("d2PdTD", &PropertiesDetailResult::d2PdTD)
968 .field("dPdT", &PropertiesDetailResult::dPdT)
969 .field("U", &PropertiesDetailResult::U)
970 .field("H", &PropertiesDetailResult::H)
971 .field("S", &PropertiesDetailResult::S)
972 .field("Cv", &PropertiesDetailResult::Cv)
973 .field("Cp", &PropertiesDetailResult::Cp)
974 .field("W", &PropertiesDetailResult::W)
975 .field("G", &PropertiesDetailResult::G)
976 .field("JT", &PropertiesDetailResult::JT)
977 .field("Kappa", &PropertiesDetailResult::Kappa)
978 .field("Cf", &PropertiesDetailResult::Cf);
979
980 value_object<PropertiesGERGResult>("PropertiesGERGResult")
981 .field("P", &PropertiesGERGResult::P)
982 .field("Z", &PropertiesGERGResult::Z)
983 .field("dPdD", &PropertiesGERGResult::dPdD)
984 .field("d2PdD2", &PropertiesGERGResult::d2PdD2)
985 .field("d2PdTD", &PropertiesGERGResult::d2PdTD)
986 .field("dPdT", &PropertiesGERGResult::dPdT)
987 .field("U", &PropertiesGERGResult::U)
988 .field("H", &PropertiesGERGResult::H)
989 .field("S", &PropertiesGERGResult::S)
990 .field("Cv", &PropertiesGERGResult::Cv)
991 .field("Cp", &PropertiesGERGResult::Cp)
992 .field("W", &PropertiesGERGResult::W)
993 .field("G", &PropertiesGERGResult::G)
994 .field("JT", &PropertiesGERGResult::JT)
995 .field("Kappa", &PropertiesGERGResult::Kappa)
996 .field("A", &PropertiesGERGResult::A)
997 .field("Cf", &PropertiesGERGResult::Cf);
998
999 value_object<PressureGrossResult>("PressureGrossResult")
1000 .field("P", &PressureGrossResult::P)
1001 .field("Z", &PressureGrossResult::Z)
1002 .field("ierr", &PressureGrossResult::ierr)
1003 .field("herr", &PressureGrossResult::herr);
1004
1005 value_object<GrossHvResult>("GrossHvResult")
1006 .field("xGrs", &GrossHvResult::xGrs)
1007 .field("HN", &GrossHvResult::HN)
1008 .field("HCH", &GrossHvResult::HCH);
1009
1010 value_object<GrossInputsResult>("GrossInputsResult")
1011 .field("xGrs", &GrossInputsResult::xGrs)
1012 .field("Gr", &GrossInputsResult::Gr)
1013 .field("HN", &GrossInputsResult::HN)
1014 .field("HCH", &GrossInputsResult::HCH)
1015 .field("ierr", &GrossInputsResult::ierr)
1016 .field("herr", &GrossInputsResult::herr);
1017
1018 value_object<BmixResult>("BmixResult")
1019 .field("B", &BmixResult::B)
1020 .field("C", &BmixResult::C)
1021 .field("ierr", &BmixResult::ierr)
1022 .field("herr", &BmixResult::herr);
1023
1024 value_object<GrossMethod1Result>("GrossMethod1Result")
1025 .field("xGrs", &GrossMethod1Result::xGrs)
1026 .field("Mm", &GrossMethod1Result::Mm)
1027 .field("HCH", &GrossMethod1Result::HCH)
1028 .field("HN", &GrossMethod1Result::HN)
1029 .field("ierr", &GrossMethod1Result::ierr)
1030 .field("herr", &GrossMethod1Result::herr);
1031
1032 value_object<GrossMethod2Result>("GrossMethod2Result")
1033 .field("xGrs", &GrossMethod2Result::xGrs)
1034 .field("Hv", &GrossMethod2Result::Hv)
1035 .field("Mm", &GrossMethod2Result::Mm)
1036 .field("HCH", &GrossMethod2Result::HCH)
1037 .field("HN", &GrossMethod2Result::HN)
1038 .field("ierr", &GrossMethod2Result::ierr)
1039 .field("herr", &GrossMethod2Result::herr);
1040
1041 // Detail bindings
1042 function("SetupDetail", &SetupDetail);
1043 function("MolarMassDetail", &MolarMassDetail_wrapper);
1044 function("PressureDetail", &PressureDetail_wrapper);
1045 function("DensityDetail", &DensityDetail_wrapper);
1046 function("PropertiesDetail", &PropertiesDetail_wrapper);
1047
1048 // GERG bindings
1049 function("SetupGERG", &SetupGERG);
1050 function("MolarMassGERG", &MolarMassGERG_wrapper);
1051 function("PressureGERG", &PressureGERG_wrapper);
1052 function("DensityGERG", &DensityGERG_wrapper);
1053 function("PropertiesGERG", &PropertiesGERG_wrapper);
1054
1055 // Gross bindings
1056 function("SetupGross", &SetupGross);
1057 function("MolarMassGross", &MolarMassGross_wrapper);
1058 function("PressureGross", &PressureGross_wrapper);
1059 function("DensityGross", &DensityGross_wrapper);
1060 function("GrossHv", &GrossHv_wrapper);
1061 function("GrossInputs", &GrossInputs_wrapper);
1062 function("Bmix", &Bmix_wrapper);
1063 function("GrossMethod1", &GrossMethod1_wrapper);
1064 function("GrossMethod2", &GrossMethod2_wrapper);
1065}
void SetupDetail()
The following routine must be called once before any other routine.
Definition Detail.cpp:806
void SetupGERG()
Initializes all the constants and parameters in the GERG-2008 model.
Definition GERG2008.cpp:775
void SetupGross()
Initialize all the constants and parameters in the GROSS model.
Definition Gross.cpp:651
BmixResult Bmix_wrapper(double T, xGrs xGrs_object, double HCH)
Calculates mixture second and third virial coefficients using the GERG-2008 equation of state.
Definition bindings.cpp:790
GrossMethod2Result GrossMethod2_wrapper(double Th, double Td, double Pd, xGrs xGrs_object, double Gr)
Wrapper function for the GrossMethod2 calculation method.
Definition bindings.cpp:856
GrossHvResult GrossHv_wrapper(gasMixture x_array)
Wrapper function to calculate gross heating values for a gas mixture.
Definition bindings.cpp:731
PressureResult PressureDetail_wrapper(double T, double D, gasMixture x_array)
Wraps the PressureDetail function to calculate pressure and compressibility factor.
Definition bindings.cpp:445
double MolarMassGERG_wrapper(gasMixture x_array)
Calculates the molar mass of a gas mixture using GERG-2008 equation of state.
Definition bindings.cpp:533
PropertiesDetailResult PropertiesDetail_wrapper(double T, double D, gasMixture x_array)
Wrapper function to calculate detailed thermodynamic properties of a gas mixture.
Definition bindings.cpp:507
double MolarMassGross_wrapper(gasMixture x_array)
Calculates the gross molar mass of a gas mixture.
Definition bindings.cpp:646
PressureResult PressureGERG_wrapper(double T, double D, gasMixture x_array)
Calculates pressure and compressibility factor using GERG-2008 equation of state.
Definition bindings.cpp:556
PressureGrossResult PressureGross_wrapper(double T, double D, xGrs xGrs_object, double HCH)
Wrapper function for PressureGross calculation.
Definition bindings.cpp:673
DensityResult DensityGross_wrapper(double T, double P, xGrs xGrs_object, double HCH)
Wrapper function for DensityGross calculation.
Definition bindings.cpp:703
GrossInputsResult GrossInputs_wrapper(double T, double P, gasMixture x_array)
Wrapper function for GrossInputs calculation.
Definition bindings.cpp:759
GrossMethod1Result GrossMethod1_wrapper(double Th, double Td, double Pd, xGrs xGrs_object, double Gr, double Hv)
Wrapper function for GrossMethod1 calculation method.
Definition bindings.cpp:823
double MolarMassDetail_wrapper(gasMixture x_array)
Calculates the molar mass of a gas mixture given mole percentages.
Definition bindings.cpp:423
DensityResult DensityGERG_wrapper(int iflag, double T, double P, gasMixture x_array)
Wrapper function to calculate density using GERG-2008 equation of state.
Definition bindings.cpp:580
PropertiesGERGResult PropertiesGERG_wrapper(double T, double D, gasMixture x_array)
Calculates thermodynamic properties using GERG-2008 equation of state.
Definition bindings.cpp:621
DensityResult DensityDetail_wrapper(double T, double P, gasMixture x_array)
Calculates the density of a gas mixture given temperature, pressure and composition.
Definition bindings.cpp:468
std::string herr
Definition bindings.cpp:282
std::string herr
Definition bindings.cpp:132
std::string herr
Definition bindings.cpp:274
std::string herr
Definition bindings.cpp:292
std::string herr
Definition bindings.cpp:303
double n_pentane
Definition bindings.cpp:93
double n_nonane
Definition bindings.cpp:97
double carbon_dioxide
Definition bindings.cpp:87
double oxygen
Definition bindings.cpp:100
double water
Definition bindings.cpp:102
double methane
Definition bindings.cpp:85
double hydrogen
Definition bindings.cpp:99
double isobutane
Definition bindings.cpp:90
double argon
Definition bindings.cpp:105
double nitrogen
Definition bindings.cpp:86
double n_octane
Definition bindings.cpp:96
double n_hexane
Definition bindings.cpp:94
double carbon_monoxide
Definition bindings.cpp:101
double hydrogen_sulfide
Definition bindings.cpp:103
double helium
Definition bindings.cpp:104
double isopentane
Definition bindings.cpp:92
double n_decane
Definition bindings.cpp:98
double n_heptane
Definition bindings.cpp:95
double ethane
Definition bindings.cpp:88
double propane
Definition bindings.cpp:89
double n_butane
Definition bindings.cpp:91
double hydrocarbon
Definition bindings.cpp:230
double nitrogen
Definition bindings.cpp:231
double carbon_dioxide
Definition bindings.cpp:232

References PropertiesGERGResult::A, gasMixture::argon, BmixResult::B, Bmix_wrapper(), BmixResult::C, gasMixture::carbon_dioxide, xGrs::carbon_dioxide, gasMixture::carbon_monoxide, PropertiesDetailResult::Cf, PropertiesGERGResult::Cf, PropertiesDetailResult::Cp, PropertiesGERGResult::Cp, PropertiesDetailResult::Cv, PropertiesGERGResult::Cv, DensityResult::D, PropertiesDetailResult::d2PdD2, PropertiesGERGResult::d2PdD2, PropertiesDetailResult::d2PdTD, PropertiesGERGResult::d2PdTD, DensityDetail_wrapper(), DensityGERG_wrapper(), DensityGross_wrapper(), PropertiesDetailResult::dPdD, PropertiesGERGResult::dPdD, PropertiesDetailResult::dPdT, PropertiesGERGResult::dPdT, gasMixture::ethane, PropertiesDetailResult::G, PropertiesGERGResult::G, GrossInputsResult::Gr, GrossHv_wrapper(), GrossInputs_wrapper(), GrossMethod1_wrapper(), GrossMethod2_wrapper(), PropertiesDetailResult::H, PropertiesGERGResult::H, GrossHvResult::HCH, GrossInputsResult::HCH, GrossMethod1Result::HCH, GrossMethod2Result::HCH, gasMixture::helium, BmixResult::herr, DensityResult::herr, GrossInputsResult::herr, GrossMethod1Result::herr, GrossMethod2Result::herr, PressureGrossResult::herr, GrossHvResult::HN, GrossInputsResult::HN, GrossMethod1Result::HN, GrossMethod2Result::HN, GrossMethod2Result::Hv, xGrs::hydrocarbon, gasMixture::hydrogen, gasMixture::hydrogen_sulfide, BmixResult::ierr, DensityResult::ierr, GrossInputsResult::ierr, GrossMethod1Result::ierr, GrossMethod2Result::ierr, PressureGrossResult::ierr, gasMixture::isobutane, gasMixture::isopentane, PropertiesDetailResult::JT, PropertiesGERGResult::JT, PropertiesDetailResult::Kappa, PropertiesGERGResult::Kappa, gasMixture::methane, GrossMethod1Result::Mm, GrossMethod2Result::Mm, MolarMassDetail_wrapper(), MolarMassGERG_wrapper(), MolarMassGross_wrapper(), gasMixture::n_butane, gasMixture::n_decane, gasMixture::n_heptane, gasMixture::n_hexane, gasMixture::n_nonane, gasMixture::n_octane, gasMixture::n_pentane, gasMixture::nitrogen, xGrs::nitrogen, gasMixture::oxygen, PressureGrossResult::P, PressureResult::P, PropertiesDetailResult::P, PropertiesGERGResult::P, PressureDetail_wrapper(), PressureGERG_wrapper(), PressureGross_wrapper(), gasMixture::propane, PropertiesDetail_wrapper(), PropertiesGERG_wrapper(), PropertiesDetailResult::S, PropertiesGERGResult::S, SetupDetail(), SetupGERG(), SetupGross(), PropertiesDetailResult::U, PropertiesGERGResult::U, PropertiesDetailResult::W, PropertiesGERGResult::W, gasMixture::water, GrossHvResult::xGrs, GrossInputsResult::xGrs, GrossMethod1Result::xGrs, GrossMethod2Result::xGrs, PressureGrossResult::Z, PressureResult::Z, PropertiesDetailResult::Z, and PropertiesGERGResult::Z.

◆ gasMixture_to_vector()

std::vector< double > gasMixture_to_vector ( gasMixture js_object)

Converts a JavaScript gasMixture Object to a C++ struct.

Parameters
js_objectJavaScript gasMixture object

Definition at line 311 of file bindings.cpp.

312{
313 std::vector<double> result(22);
314 result[0] = 0;
315 result[1] = js_object.methane;
316 result[2] = js_object.nitrogen;
317 result[3] = js_object.carbon_dioxide;
318 result[4] = js_object.ethane;
319 result[5] = js_object.propane;
320 result[6] = js_object.isobutane;
321 result[7] = js_object.n_butane;
322 result[8] = js_object.isopentane;
323 result[9] = js_object.n_pentane;
324 result[10] = js_object.n_hexane;
325 result[11] = js_object.n_heptane;
326 result[12] = js_object.n_octane;
327 result[13] = js_object.n_nonane;
328 result[14] = js_object.n_decane;
329 result[15] = js_object.hydrogen;
330 result[16] = js_object.oxygen;
331 result[17] = js_object.carbon_monoxide;
332 result[18] = js_object.water;
333 result[19] = js_object.hydrogen_sulfide;
334 result[20] = js_object.helium;
335 result[21] = js_object.argon;
336 return result;
337}

References gasMixture::argon, gasMixture::carbon_dioxide, gasMixture::carbon_monoxide, gasMixture::ethane, gasMixture::helium, gasMixture::hydrogen, gasMixture::hydrogen_sulfide, gasMixture::isobutane, gasMixture::isopentane, gasMixture::methane, gasMixture::n_butane, gasMixture::n_decane, gasMixture::n_heptane, gasMixture::n_hexane, gasMixture::n_nonane, gasMixture::n_octane, gasMixture::n_pentane, gasMixture::nitrogen, gasMixture::oxygen, gasMixture::propane, and gasMixture::water.

Referenced by DensityDetail_wrapper(), DensityGERG_wrapper(), GrossHv_wrapper(), GrossInputs_wrapper(), MolarMassDetail_wrapper(), MolarMassGERG_wrapper(), MolarMassGross_wrapper(), PressureDetail_wrapper(), PressureGERG_wrapper(), PropertiesDetail_wrapper(), and PropertiesGERG_wrapper().

◆ GrossHv_wrapper()

GrossHvResult GrossHv_wrapper ( gasMixture x_array)

Wrapper function to calculate gross heating values for a gas mixture.

Parameters
x_arrayGas mixture composition in mole fraction
Returns
GrossHvResult Structure containing:
  • xGrs: Vector of calculated gross heating values for each component
  • HN: Normal gross heating value of the mixture
  • HCH: Chinese gross heating value of the mixture

This function serves as a wrapper around the GrossHv calculation, converting between array and vector data structures while maintaining the computational logic of the original GERG-2008 implementation.

See also
GrossHv For the underlying calculation implementation

Definition at line 731 of file bindings.cpp.

732{
733 std::vector<double> x = gasMixture_to_vector(x_array);
734 std::vector<double> xGrs(x.size());
735 double HN = 0, HCH = 0;
736
737 GrossHv(x, xGrs, HN, HCH);
738 GrossHvResult result = {vector_to_xGrs(xGrs), HN, HCH};
739 return result;
740}
void GrossHv(const std::vector< double > &x, std::vector< double > &xGrs, double &HN, double &HCH)
Calculate ideal heating values based on composition.
Definition Gross.cpp:317
xGrs vector_to_xGrs(const std::vector< double > &vec)
Converts a C++ vector to a JavaScript xGrs object.
Definition bindings.cpp:359

References gasMixture_to_vector(), GrossHv(), and vector_to_xGrs().

Referenced by EMSCRIPTEN_BINDINGS().

◆ GrossInputs_wrapper()

GrossInputsResult GrossInputs_wrapper ( double T,
double P,
gasMixture x_array )

Wrapper function for GrossInputs calculation.

This function wraps the GrossInputs calculation to handle array conversions and provide a structured result

Parameters
TTemperature value
PPressure value
x_arrayGas mixture composition in mole percent
Returns
GrossInputsResult Structure containing:
  • xGrs: Vector of gross mole fractions
  • Gr: Relative density
  • HN: Heating value (normal conditions) [MJ/m³]
  • HCH: Heating value (combustion conditions) [MJ/m³]
  • ierr: Error code (0 = success)
  • herr: Error message
See also
GrossInputs For the underlying calculation implementation

Definition at line 759 of file bindings.cpp.

760{
761 std::vector<double> x = gasMixture_to_vector(x_array);
762 std::vector<double> xGrs(x.size());
763 double Gr = 0, HN = 0, HCH = 0;
764 int ierr = 0;
765 std::string herr;
766
767 GrossInputs(T, P, x, xGrs, Gr, HN, HCH, ierr, herr);
768
769 GrossInputsResult result = {vector_to_xGrs(xGrs), Gr, HN, HCH, ierr, herr};
770 return result;
771}
void GrossInputs(const double T, const double P, const std::vector< double > &x, std::vector< double > &xGrs, double &Gr, double &HN, double &HCH, int &ierr, std::string &herr)
Calculate relative density and heating values based on composition.
Definition Gross.cpp:364

References gasMixture_to_vector(), GrossInputs(), and vector_to_xGrs().

Referenced by EMSCRIPTEN_BINDINGS().

◆ GrossMethod1_wrapper()

GrossMethod1Result GrossMethod1_wrapper ( double Th,
double Td,
double Pd,
xGrs xGrs_object,
double Gr,
double Hv )

Wrapper function for GrossMethod1 calculation method.

Parameters
ThTemperature high (T1) [K]
TdTemperature difference (T1-T2) [K]
PdPressure drop (P1-P2) [Pa]
xGrs_objectArray of mole fractions for the mixture components
GrMass flow rate [kg/s]
HvHeating value [J/kg]
Returns
GrossMethod1Result Structure containing:
  • Updated mole fractions array
  • Mm (Molar mass) [kg/kmol]
  • HCH (Heat capacity [J/(kg·K)])
  • HN (Heat value normalized)
  • ierr (Error code, 0 = success)
  • herr (Error message string)
See also
GrossMethod1 For the underlying calculation implementation

Definition at line 823 of file bindings.cpp.

824{
825 std::vector<double> xGrs = xGrs_to_vector(xGrs_object);
826 double Mm = 0, HCH = 0, HN = 0;
827 int ierr = 0;
828 std::string herr;
829
830 GrossMethod1(Th, Td, Pd, xGrs, Gr, Hv, Mm, HCH, HN, ierr, herr);
831
832 GrossMethod1Result result = {vector_to_xGrs(xGrs), Mm, HCH, HN, ierr, herr};
833 return result;
834}
void GrossMethod1(const double Th, const double Td, const double Pd, std::vector< double > &xGrs, const double Gr, const double Hv, double &Mm, double &HCH, double &HN, int &ierr, std::string &herr)
Initialize variables required in the GROSS equation with Method 1 of the AGA 8 Part 1 publication.
Definition Gross.cpp:517

References GrossMethod1(), vector_to_xGrs(), and xGrs_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ GrossMethod2_wrapper()

GrossMethod2Result GrossMethod2_wrapper ( double Th,
double Td,
double Pd,
xGrs xGrs_object,
double Gr )

Wrapper function for the GrossMethod2 calculation method.

Parameters
ThTemperature at higher pressure (K)
TdTemperature at lower pressure (K)
PdPressure at lower temperature (kPa)
xGrs_objectArray containing molar composition of the gas mixture
GrRelative density of the gas mixture
Returns
GrossMethod2Result struct containing:
  • Updated molar composition array
  • Hv: Heating value
  • Mm: Molar mass
  • HCH: Hydrocarbon content
  • HN: Number related to heating value
  • ierr: Error code (0 = success)
  • herr: Error message string
See also
GrossMethod2 For the underlying calculation implementation

Definition at line 856 of file bindings.cpp.

857{
858 std::vector<double> xGrs = xGrs_to_vector(xGrs_object);
859 double Hv = 0, Mm = 0, HCH = 0, HN = 0;
860 int ierr = 0;
861 std::string herr;
862
863 GrossMethod2(Th, Td, Pd, xGrs, Gr, Hv, Mm, HCH, HN, ierr, herr);
864
865 GrossMethod2Result result = {vector_to_xGrs(xGrs), Hv, Mm, HCH, HN, ierr, herr};
866 return result;
867}
void GrossMethod2(const double Th, const double Td, const double Pd, std::vector< double > &xGrs, const double Gr, double &Hv, double &Mm, double &HCH, double &HN, int &ierr, std::string &herr)
Initialize variables required in the GROSS equation with Method 2 of the AGA 8 Part 1 publication.
Definition Gross.cpp:594

References GrossMethod2(), vector_to_xGrs(), and xGrs_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ MolarMassDetail_wrapper()

double MolarMassDetail_wrapper ( gasMixture x_array)

Calculates the molar mass of a gas mixture given mole percentages.

This function wraps the MolarMassDetail calculation for use with external bindings. It converts the input array to a vector before calculating the molar mass.

Parameters
x_arrayGas mixture composition in mole percentages
Returns
double Molar mass of the gas mixture in kg/mol
See also
MolarMassDetail For the underlying calculation implementation

Definition at line 423 of file bindings.cpp.

424{
425 std::vector<double> x = gasMixture_to_vector(x_array);
426 double Mm = 0;
427 MolarMassDetail(x, Mm);
428 return Mm;
429}
void MolarMassDetail(const std::vector< double > &x, double &Mm)
Calculate molar mass of a mixture based on composition.
Definition Detail.cpp:158

References gasMixture_to_vector(), and MolarMassDetail().

Referenced by EMSCRIPTEN_BINDINGS().

◆ MolarMassGERG_wrapper()

double MolarMassGERG_wrapper ( gasMixture x_array)

Calculates the molar mass of a gas mixture using GERG-2008 equation of state.

Parameters
x_arrayGas mixture composition in mole percent
Returns
double Molar mass of the mixture in kg/mol

This function serves as a wrapper for the MolarMassGERG calculation. It converts the input array to a vector format before performing the calculation.

See also
MolarMassGERG For the underlying calculation implementation

Definition at line 533 of file bindings.cpp.

534{
535 std::vector<double> x = gasMixture_to_vector(x_array);
536 double Mm = 0;
537 MolarMassGERG(x, Mm);
538 return Mm;
539}
void MolarMassGERG(const std::vector< double > &x, double &Mm)
Calculate molar mass of a gas mixture.
Definition GERG2008.cpp:191

References gasMixture_to_vector(), and MolarMassGERG().

Referenced by EMSCRIPTEN_BINDINGS().

◆ MolarMassGross_wrapper()

double MolarMassGross_wrapper ( gasMixture x_array)

Calculates the gross molar mass of a gas mixture.

This function is a wrapper to MolarMassGross that converts a gas mixture composition from array to vector and calculates its gross molar mass.

Parameters
x_arrayGas mixture composition in mole percent
Returns
double Gross molar mass of the mixture in g/mol
See also
MolarMassGross For the underlying calculation implementation

Definition at line 646 of file bindings.cpp.

647{
648 std::vector<double> x = gasMixture_to_vector(x_array);
649 double Mm = 0;
650 MolarMassGross(x, Mm);
651 return Mm;
652}
void MolarMassGross(const std::vector< double > &x, double &Mm)
Calculate molar mass of the mixture with the compositions contained in the x() input array.
Definition Gross.cpp:143

References gasMixture_to_vector(), and MolarMassGross().

Referenced by EMSCRIPTEN_BINDINGS().

◆ PressureDetail_wrapper()

PressureResult PressureDetail_wrapper ( double T,
double D,
gasMixture x_array )

Wraps the PressureDetail function to calculate pressure and compressibility factor.

Parameters
TTemperature in Kelvin
DDensity in mol/l
x_arrayGas mixture composition in mole percent
Returns
PressureResult Struct containing:
  • P: Pressure in kPa
  • Z: Compressibility factor (dimensionless)

This wrapper function converts the input array to a vector and handles the pressure calculation using PressureDetail, returning the results in a convenient struct.

See also
PressureDetail For the underlying calculation implementation

Definition at line 445 of file bindings.cpp.

446{
447 std::vector<double> x = gasMixture_to_vector(x_array);
448 double P = 0, Z = 0;
449 PressureDetail(T, D, x, P, Z);
450 PressureResult result = {P, Z};
451 return result;
452}
void PressureDetail(const double T, const double D, const std::vector< double > &x, double &P, double &Z)
Calculates pressure and compressibility factor as a function of temperature and density.
Definition Detail.cpp:196

References gasMixture_to_vector(), and PressureDetail().

Referenced by EMSCRIPTEN_BINDINGS().

◆ PressureGERG_wrapper()

PressureResult PressureGERG_wrapper ( double T,
double D,
gasMixture x_array )

Calculates pressure and compressibility factor using GERG-2008 equation of state.

Parameters
TTemperature in K
DDensity in mol/l (or mol/dm³)
x_arrayGas mixture composition in mole percent
Returns
PressureResult Struct containing:
  • P: Pressure in kPa
  • Z: Compressibility factor (dimensionless)

This function is a wrapper around the PressureGERG function that handles the conversion between array and vector representations of the gas mixture composition.

See also
PressureGERG For the underlying calculation implementation

Definition at line 556 of file bindings.cpp.

557{
558 std::vector<double> x = gasMixture_to_vector(x_array);
559 double P = 0, Z = 0;
560 PressureGERG(T, D, x, P, Z);
561
562 PressureResult result = {P, Z};
563 return result;
564}
void PressureGERG(const double T, const double D, const std::vector< double > &x, double &P, double &Z)
Calculate pressure and compressibility factor.
Definition GERG2008.cpp:216

References gasMixture_to_vector(), and PressureGERG().

Referenced by EMSCRIPTEN_BINDINGS().

◆ PressureGross_wrapper()

PressureGrossResult PressureGross_wrapper ( double T,
double D,
xGrs xGrs_object,
double HCH )

Wrapper function for PressureGross calculation.

This function wraps the PressureGross calculation to provide a simplified interface for computing pressure and compressibility factor for natural gas mixtures.

Parameters
TTemperature in K
DDensity in mol/l
xGrs_objectArray containing mole fractions of components
HCHGross heating value in MJ/m³
Returns
PressureGrossResult struct containing:
  • P: Pressure in kPa
  • Z: Compressibility factor
  • ierr: Error code (0 = success)
  • herr: Error message
See also
PressureGross For the underlying calculation implementation

Definition at line 673 of file bindings.cpp.

674{
675 std::vector<double> xGrs = xGrs_to_vector(xGrs_object);
676 double P = 0, Z = 0;
677 int ierr = 0;
678 std::string herr;
679
680 PressureGross(T, D, xGrs, HCH, P, Z, ierr, herr);
681
682 PressureGrossResult result = {P, Z, ierr, herr};
683 return result;
684}
void PressureGross(const double T, const double D, const std::vector< double > &xGrs, const double HCH, double &P, double &Z, int &ierr, std::string &herr)
Calculate pressure as a function of temperature and density.
Definition Gross.cpp:183

References PressureGross(), and xGrs_to_vector().

Referenced by EMSCRIPTEN_BINDINGS().

◆ PropertiesDetail_wrapper()

PropertiesDetailResult PropertiesDetail_wrapper ( double T,
double D,
gasMixture x_array )

Wrapper function to calculate detailed thermodynamic properties of a gas mixture.

Parameters
TTemperature [K]
DDensity [mol/l]
x_arrayGas mixture composition in mole percent
Returns
PropertiesDetailResult struct containing:
  • P: Pressure [kPa]
  • Z: Compressibility factor [-]
  • dPdD: Pressure derivative with respect to density [(kPa·l)/mol]
  • d2PdD2: Second pressure derivative with respect to density [(kPa·l²)/mol²]
  • d2PdTD: Mixed pressure derivative with respect to temperature and density [(kPa·l)/(mol·K)]
  • dPdT: Pressure derivative with respect to temperature [kPa/K]
  • U: Internal energy [J/mol]
  • H: Enthalpy [J/mol]
  • S: Entropy [J/(mol·K)]
  • Cv: Isochoric heat capacity [J/(mol·K)]
  • Cp: Isobaric heat capacity [J/(mol·K)]
  • W: Speed of sound [m/s]
  • G: Gibbs energy [J/mol]
  • JT: Joule-Thomson coefficient [K/kPa]
  • Kappa: Isentropic exponent [-]
  • Cf: Critical flow factor [-]
See also
PropertiesDetail For the underlying calculation implementation

Definition at line 507 of file bindings.cpp.

508{
509 std::vector<double> x = gasMixture_to_vector(x_array);
510 double P = 0, Z = 0, dPdD = 0, d2PdD2 = 0, d2PdTD = 0, dPdT = 0;
511 double U = 0, H = 0, S = 0, Cv = 0, Cp = 0, W = 0, G = 0, JT = 0, Kappa = 0, Cf = 0;
512
513 PropertiesDetail(T, D, x, P, Z, dPdD, d2PdD2, d2PdTD, dPdT,
514 U, H, S, Cv, Cp, W, G, JT, Kappa, Cf);
515
516 PropertiesDetailResult result = {P, Z, dPdD, d2PdD2, d2PdTD, dPdT, U, H, S, Cv, Cp, W, G, JT, Kappa, Cf};
517
518 return result;
519}
void PropertiesDetail(const double T, const double D, const std::vector< double > &x, double &P, double &Z, double &dPdD, double &d2PdD2, double &d2PdTD, double &dPdT, double &U, double &H, double &S, double &Cv, double &Cp, double &W, double &G, double &JT, double &Kappa, double &Cf)
Calculates thermodynamic properties as a function of temperature and density.
Definition Detail.cpp:350

References gasMixture_to_vector(), and PropertiesDetail().

Referenced by EMSCRIPTEN_BINDINGS().

◆ PropertiesGERG_wrapper()

PropertiesGERGResult PropertiesGERG_wrapper ( double T,
double D,
gasMixture x_array )

Calculates thermodynamic properties using GERG-2008 equation of state.

Parameters
TTemperature [K]
DDensity [kg/m³]
x_arrayArray of mole fractions [%] of the mixture components
Returns
PropertiesGERGResult struct containing:
  • P: Pressure [kPa]
  • Z: Compressibility factor [-]
  • dPdD: Partial derivative of pressure with respect to density [(kPa)/(kg/m³)]
  • d2PdD2: Second partial derivative of pressure with respect to density [(kPa)/(kg/m³)²]
  • d2PdTD: Mixed partial derivative of pressure with respect to temperature and density [(kPa)/(K·kg/m³)]
  • dPdT: Partial derivative of pressure with respect to temperature [kPa/K]
  • U: Internal energy [J/kg]
  • H: Enthalpy [J/kg]
  • S: Entropy [J/(kg·K)]
  • Cv: Isochoric heat capacity [J/(kg·K)]
  • Cp: Isobaric heat capacity [J/(kg·K)]
  • W: Speed of sound [m/s]
  • G: Gibbs energy [J/kg]
  • JT: Joule-Thomson coefficient [K/kPa]
  • Kappa: Isentropic exponent [-]
  • A: Helmholtz energy [J/kg]
  • Cf: Critical flow factor [-]
See also
PropertiesGERG For the underlying calculation implementation

Definition at line 621 of file bindings.cpp.

622{
623 std::vector<double> x = gasMixture_to_vector(x_array);
624 double P = 0, Z = 0, dPdD = 0, d2PdD2 = 0, d2PdTD = 0, dPdT = 0;
625 double U = 0, H = 0, S = 0, Cv = 0, Cp = 0, W = 0, G = 0, JT = 0, Kappa = 0, A = 0, Cf = 0;
626
627 PropertiesGERG(T, D, x, P, Z, dPdD, d2PdD2, d2PdTD, dPdT,
628 U, H, S, Cv, Cp, W, G, JT, Kappa, A, Cf);
629
630 PropertiesGERGResult result = {P, Z, dPdD, d2PdD2, d2PdTD, dPdT, U, H, S, Cv, Cp, W, G, JT, Kappa, A, Cf};
631 return result;
632}
void PropertiesGERG(const double T, const double D, const std::vector< double > &x, double &P, double &Z, double &dPdD, double &d2PdD2, double &d2PdTD, double &dPdT, double &U, double &H, double &S, double &Cv, double &Cp, double &W, double &G, double &JT, double &Kappa, double &A, double &Cf)
Calculate thermodynamic properties as a function of temperature and density.
Definition GERG2008.cpp:371
Structure containing thermodynamic properties for GERG-2008 calculations.
Definition bindings.cpp:201

References gasMixture_to_vector(), and PropertiesGERG().

Referenced by EMSCRIPTEN_BINDINGS().

◆ vector_to_array()

val vector_to_array ( const std::vector< double > & vec)

Converts a C++ vector of doubles to a JavaScript array.

Parameters
vecThe input vector containing double values to convert
Returns
val A JavaScript array containing the values from the input vector

This function takes a C++ vector of doubles and creates a new JavaScript array, copying each element from the vector to the corresponding index in the JavaScript array. The function is typically used for interoperability between C++ and JavaScript/WebAssembly.

Definition at line 401 of file bindings.cpp.

402{
403 val result = val::array();
404 for (size_t i = 0; i < vec.size(); ++i)
405 {
406 result.set(i, vec[i]);
407 }
408 return result;
409}

◆ vector_to_xGrs()

xGrs vector_to_xGrs ( const std::vector< double > & vec)

Converts a C++ vector to a JavaScript xGrs object.

Parameters
vecC++ vector containing the xGrs values

Definition at line 359 of file bindings.cpp.

360{
361 xGrs result;
362 result.hydrocarbon = vec[1];
363 result.nitrogen = vec[2];
364 result.carbon_dioxide = vec[3];
365 return result;
366}

References xGrs::carbon_dioxide, xGrs::hydrocarbon, and xGrs::nitrogen.

Referenced by GrossHv_wrapper(), GrossInputs_wrapper(), GrossMethod1_wrapper(), and GrossMethod2_wrapper().

◆ xGrs_to_vector()

std::vector< double > xGrs_to_vector ( xGrs js_object)

Converts a JavaScript xGrs Object to a C++ struct.

Parameters
js_objectJavaScript xGrs object

Definition at line 344 of file bindings.cpp.

345{
346 std::vector<double> result(3);
347 result[0] = 0;
348 result[1] = js_object.hydrocarbon;
349 result[2] = js_object.nitrogen;
350 result[3] = js_object.carbon_dioxide;
351 return result;
352}

References xGrs::carbon_dioxide, xGrs::hydrocarbon, and xGrs::nitrogen.

Referenced by Bmix_wrapper(), DensityGross_wrapper(), GrossMethod1_wrapper(), GrossMethod2_wrapper(), and PressureGross_wrapper().