// Radiator Heat Emission

function RadiatorHeat(p, p50, ti, tr, ta, n){
	this.p = p; // actual heat emission - Watts
	this.p50 = p50; // standard heat emission - Watts
	this.ti = ti; // water temperature inn - gradC
	this.tr = tr; // water temperature out - gradC
	this.ta = ta; // surrounding room air temperature - gradC
	this.n = n; // radiator constant - 1.33 radiator - 1.6 convector
}

RadiatorHeat.prototype.heatEmission = function(){
	if (this.ta > this.tr || this.tr > this.ti) {
		h = -1;
	} else {
		h = this.p50 * Math.pow((((this.ti - this.tr)/Math.log((this.ti - this.ta)/(this.tr - this.ta)) )/49.32),this.n);
	}
	return h;
}

RadiatorHeat.prototype.returnTemperature = function(){
	var pc = this.p; // calculated heatemission from radiator
	if (this.ta > this.ti) {
		this.tr = -1;
	} else {
		this.tr = this.ti;
		while(pc >= this.p) {
			this.tr = this.tr - 0.5;
			pc = this.heatEmission();
		}
	}
	if (this.tr > this.ti - 3) this.tr = -1;
	return this.tr;
}

RadiatorHeat.prototype.inputString = function(){
	return this.p + " " + this.p50 + " " + this.ti + " " + this.tr + " " + this.ta + " " + this.n;
}

// Copyright engineeringtoolbox.com