Hi brains trust,
I'm hoping someone can simplify the code inside the file TtoVaporABV.h to the original formula used for each section?
I know it's all based on the Clausius–Clapeyron relation, however there's so many different formula referenced in the development of that I don't know where to start.
I want to have this all working in Excel and ultimately in a PLC rather than in Arduino.
While I can use the following code (in Excel) to achieve results that make sense I don't understand the origin of the following numbers in this section of code shown below:
I've played with the gas constant "R" of 8.3145 and the Heat of Vaporization for EtOH and H2O but I'm just not getting it.
float h2oBoilingPoint(float p) {
// calculate the the boiling temperature of water for the measured pressure in Celsius
float H2OInKelvin=-20330000*373.15/(4157* log(p/1013.25)*373.15-20330000);
return H2OInKelvin-273.15;
}
float azeotrope(float p) {
// Calculate the the azeotrope for the measured pressure in Celsius
float AzeotropeInKelvin=-19280000*351.324/(4157*log(p/1013.25)*351.324-19280000);
return AzeotropeInKelvin-273.15;
Next, the code goes on to solve for the
TtoLiquidABV and
TtoVapourABV solutions via inbuilt arrays and the help of a formula.
I'm lost at this point as I don't understand the array or how to use it in reference to the formula:
// Calculate the index for the table (1251 is the the azeotrope at 1013.25 hPa and the
// starting point of the table) in °DC
int16_t IndexABV = int16_t((T + 0.03125 + 100 - h2oBoilingPoint(P)) / 0.0625 ) - 1251;
if (IndexABV < 0) return float(IndexABV) * 0.0625; // Below azeotrope
if (IndexABV >= int16_t(sizeof ABV / sizeof *ABV)) return 0; // Above 100 °C
if (IndexABV < 29) return float(pgm_read_byte(&ABV[IndexABV]) + 768) / 10;
if (IndexABV < 74) return float(pgm_read_byte(&ABV[IndexABV]) + 512) / 10;
if (IndexABV < 138) return float(pgm_read_byte(&ABV[IndexABV]) + 256) / 10;
return float(pgm_read_byte(&ABV[IndexABV])) / 10;
};
// Calculate the index for the table (1251 is the the azeotrope at 1013.25 hPa and the
// starting point of the table) in °DC
int16_t IndexABV = int16_t((T + 0.03125 + 78.174 - azeotrope(P)) / 0.0625 ) - 1251;
if (IndexABV < 0) return float(IndexABV) * 0.0625; // Below azeotrope
if (IndexABV >= int16_t(sizeof ABV / sizeof *ABV)) return 0; // Above 100 °C
if (IndexABV < 114) return float(pgm_read_byte(&ABV[IndexABV]) + 768) / 10;
if (IndexABV < 256) return float(pgm_read_byte(&ABV[IndexABV]) + 512) / 10;
if (IndexABV < 314) return float(pgm_read_byte(&ABV[IndexABV]) + 256) / 10;
return float(pgm_read_byte(&ABV[IndexABV])) / 10;
};
Hoping someone can point me in the right direction.
PS, happy New Year to all!!
Mech.