/*
 Authors......: Rodrigo Hjort (rodrigo_hjort@yahoo.com) 
                Felix Sharipov (sharipov@fisica.ufpr.br)
 Created......: 28 Mar 2003
 Last modified: 29 Apr 2003
*/

var GASNAMEs = new Array ("Helium", "Neon", "Argon", "Kripton", "Xenon");
var MASSAs = new Array (4.0026, 20.1790, 39.9480, 83.8000, 131.2900);
var EPSILONs = new Array (10.40, 42., 141.5, 197.8, 274.);
var C6s = new Array (3.090, 2.594, 2.210, 2.164, 2.162)
var VROs = new Array (0.0797, 0.0784, 0.0836, 0.0831, 0.0854);
var V0s = new Array (8.5, 11.09, 5.117, 4.491, 3.898);
var SIGMAs = new Array (0.2610, 0.2755, 0.3350, 0.3571, 0.3885);

var MASSA = 4.0026, C6 = 3.09, VRO = 0.0797, V0 = 8.5E-5, SIGMA = 0.261;

function CalcVisc(gasindex, temp)
{
	C6 = C6s[gasindex];
	VRO = VROs[gasindex];
	V0 = V0s[gasindex] * 1.e5;
	SIGMA = SIGMAs[gasindex];
	MASSA = MASSAs[gasindex];

	var t = temp / EPSILONs[gasindex];
	var visc = 0.5 / 16.0 * F(t) * 
		Math.sqrt(MASSA * 1.6605655 * 1.380662 * temp / Math.PI) /
		(Math.pow(SIGMA, 2) * OM22(t));	
	return(visc);
}

function OM22(t)
{
	if (t <= 1.2)
	{
		var A1 = 0.18;
		var A2 = 0.0;
		var A3 = -1.20407 - 0.195866 * Math.pow(C6, -1.0 / 3.0);
		var A4 = -9.86374 + 20.2221 * Math.pow(C6, -1.0 / 3.0);
		var A5 = 16.6295 - 31.3613 * Math.pow(C6, -1.0 / 3.0);
		var A6 = -6.73805 + 12.6611 * Math.pow(C6, -1.0 / 3.0);
		return(
		  1.1943 * Math.pow(C6 / t, 1.0 / 3.0) * 
			(
				1.0 + 
				A1 * Math.pow(t, 1.0 / 3.0) + 
				A2 * Math.pow(t, 2.0 / 3.0) + 
				A3 * t + 
				A4 * Math.pow(t, 4.0 / 3.0) +
				A5 * Math.pow(t, 5.0 / 3.0) +
				A6 * Math.pow(t, 2)
			)
		);
	}
	else if (t > 1.2 && t < 10.0)
	{
		return(Math.exp(
			0.46641 - 
			0.56991 * Math.log(t) + 
			0.19591 * Math.pow(Math.log(t), 2) -
			0.03879 * Math.pow(Math.log(t), 3) + 
			0.00259 * Math.pow(Math.log(t), 4)
		));
	}	
	var alpha10 = Math.log(V0 / 10.0);
	var alpha = Math.log(V0 / t);
	var cc = 1.0 / Math.pow(alpha10 * VRO, 2); 
	var a2 = -33.0838 + cc * (20.0862 + 72.1059 / alpha10 + Math.pow(8.27648 / alpha10,  2));
	var a3 = 101.571 - cc * (56.4472 + 286.393 / alpha10 + Math.pow(17.7610 / alpha10, 2));  
	var a4 = -87.7036 + cc * (46.3130 + 277.146 / alpha10 + Math.pow(19.0573 / alpha10, 2));
	return(
		Math.pow(VRO, 2) * Math.pow(alpha, 2) * (
			1.04 + 
			a2 / Math.pow(Math.log(t), 2) + 
			a3 / Math.pow(Math.log(t), 3) +
			a4 / Math.pow(Math.log(t), 4)
		)
	);
}

function F(t)
{
	var dt = 0.001;
	var domdt = (OM22(t + dt) - OM22(t - dt)) / (2.0 * dt);
  var ee = 1.0 + t / 4.0 * domdt;
	return(1.0 + 3.0 / 196.0 * Math.pow(8.0 * ee - 7.0, 2));
}

