Demo entry 3497959

Refrigerant Charge

   

Submitted by anonymous on Jan 05, 2016 at 00:06
Language: JavaScript. Code size: 2.1 kB.

/*
Calculations for Refrigerant Charge
*/
(function () {

var cont = document.querySelector('.container');

var hprVessel = function (level, temp) {
	/**
	* @params {Number} level - Percentage load for HPR 
	*/
	var liquidCoefficients = [
		83.4485407734612,
		-0.111449280945489,
		0.000100022560084721,
		-0.00000206240663899928
	];
	
	var vaporCoefficients = [
		0.895329190066827, 
		0.016635773286873, 
		-0.0000894924196507015, 
		0.00000206296636296276
	];

	var vessel = {
		// Vessel-specific Params
		diameter: 1.9583 * level,
		height: 0.2937 * level,
		length: 15.9583 * level,
		
		// Calculations
		getLiquidVol: function () {		
			var r = this.diameter/2;
			var sectionArea = Math.pow(r, 2) * Math.acos((r - this.height) / r);
			var triangleArea = Math.sqrt(Math.pow(r, 2) - Math.pow((r-this.height), 2))*(r-this.height);

			return (this.length * sectionArea * triangleArea);
		},
		getVesselVol: function () {
			return (Math.PI * Math.pow(this.diameter, 2) * this.length);
		},
		getVaporVol: function () {
			return (vessel.getVesselVol() - vessel.getLiquidVol());
		},
		getLiquidCharge: function (temp) {
			return (vessel.getLiquidVol() * vessel.calcDensity(liquidCoefficients, temp));
		},
		getVaporCharge: function (temp) {
			return (vessel.getVaporVol() * vessel.calcDensity(vaporCoefficients, temp));
		},
		chargeHPR: function (temp) {
			return (1000 + vessel.getLiquidCharge(temp) + vessel.getVaporCharge(temp));
		},
		
		// Helper functions
		calcDensity: function (regressionCoefs, temp) {
			var liqDensityArray = regressionCoefs.map(function (coef) {
				return coef * Math.pow(temp, regressionCoefs.indexOf(coef));
			});

			return vessel.sum(liqDensityArray);
		},
		sum: function (arr) {
			return arr.reduce( (prev, current) => prev + current );
		}
	};
	
	return {
		getCharge: function() {
			return vessel.chargeHPR(temp);
		}
	};
}

var vessel = hprVessel(1, -30);
var result = vessel.getCharge();

cont.innerHTML = result.toString();

} )();

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).