//============================================================+
// Inductance Calculator       || Author:                     |
// A JavaScript Program        ||-----------------------------|
//                             || Nicola Asuni                |
//                             || Via Della Pace n.11         |
// ----------------------------|| 09045 Quartucciu (CA)       |
// start          : 2001-01-23 || info@technick.net           |
// last update    : 2008-05-08 || www.technick.net            |
//============================================================+
// (c) Copyright 1999-2008 Nicola Asuni - Tecnick.com s.r.l.

//variables and arrays
PI=Math.PI;
u=PI*0.0000004; // Absolute permeability [H/m].

// ArcSinh(x) ----------------------------------------------------------
function ArcSinh(x) {
 return( Math.log(x+Math.sqrt((x*x)+1)) );
}

// ArcCosh(x) ----------------------------------------------------------
function ArcCosh(x) {
 return( Math.log(x+(Math.sqrt(x-1)*Math.sqrt(x+1))) );
}

// Error message  ----------------------------------------------------------
function InputError() {
	alert("INPUT ERROR: Please check values");
}

// Check input values
// --------------------------------------------------------------------------
function Check_A(){if(isNaN(document.inductanceform.A.value)) return(0); return(1);}
function Check_B(){if(isNaN(document.inductanceform.B.value)) return(0); return(1);}
function Check_C(){if(isNaN(document.inductanceform.C.value)) return(0); return(1);}
function Check_D(){if(isNaN(document.inductanceform.D.value)) return(0); return(1);}
function Check_E(){if(isNaN(document.inductanceform.E.value)) return(0); return(1);}


// Inductance for Circular wire loop -----------------------------------------
function LCircularLoop() {
	var N = 1.0*document.inductanceform.A.value;
	var R = 1.0*document.inductanceform.B.value;
	var a = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( (a>0) && (R>(2*a)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=N*N*R*u*p*(Math.log(8*R/a)-2);}
	else InputError();
 return;
}

// Inductance for Circular wire loop -----------------------------------------
function LRectangularLoop() {
	var N = 1.0*document.inductanceform.A.value;
	var w = 1.0*document.inductanceform.B.value;
	var h = 1.0*document.inductanceform.C.value;
	var a = 1.0*document.inductanceform.D.value;
	var p = 1.0*document.inductanceform.E.value;
	
	var tmp1 = Math.sqrt((h*h)+(w*w));
	var tmp2 = (2*(w+h));
	var tmp3 = (2*tmp1);
	var tmp4 = (h*Math.log((h+tmp1)/w));
	var tmp5 = (w*Math.log((w+tmp1)/h));
	var tmp6 = (h*Math.log(2*w/a));
	var tmp7 = (w*Math.log(2*h/a));
	var tmp8 = ((N*N*u*p)/PI)*(tmp3-tmp2-tmp4-tmp5+tmp6+tmp7);

	if( (a>0) && (h>(2*a)) && (Check_A() && Check_B() && Check_C() && Check_D() && Check_E()) )
		{document.inductanceform.L.value=tmp8;}
	else InputError();
 return;
}

// Inductance for Square wire loop -----------------------------------------
function LSquareLoop() {
	var N = 1.0*document.inductanceform.A.value;
	var w = 1.0*document.inductanceform.B.value;
	var a = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( (a>0) && (w>(2*a)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=N*N*((2*w*u*p)/PI)*(Math.log(w/a)-0.77401);}
	else InputError();
 return;
}


// Inductance for Equilateral Triangle wire loop -----------------------------------------
function LTriangleEqLoop() {
	var N = 1.0*document.inductanceform.A.value;
	var s = 1.0*document.inductanceform.B.value;
	var a = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( (a>0) && (s>(2*a)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=N*N*((3*s*p*u)/(2*PI))*(Math.log(s/a)-1.40546);}
	else InputError();
 return;
}

// Inductance for Isosceles Triangle wire loop -----------------------------------------
function LTriangleIsLoop() {
	var N = 1.0*document.inductanceform.A.value;
	var b = 1.0*document.inductanceform.B.value;
	var c = 1.0*document.inductanceform.C.value;
	var a = 1.0*document.inductanceform.D.value;
	var p = 1.0*document.inductanceform.E.value;
	
	var tmp1 = Math.sqrt((4*b*b*c*c)-(b*b*b*b));
	var tmp2 = 2*c*Math.log(2*c/a);
	var tmp3 = b*Math.log(2*c/a);
	var tmp4 = 2*(b+c)*ArcSinh((b*b)/tmp1);
	var tmp5 = 2*c*ArcSinh(((2*c*c)-(b*b))/tmp1);
	var tmp6 = (2*c+b);
	var tmp7 = ((N*N*u*p)/(2*PI))*(tmp2+tmp3-tmp4-tmp5-tmp6);
	
	if( (b<2*c) && (c>(2*a)) && (Check_A() && Check_B() && Check_C() && Check_D() && Check_E()) )
		{document.inductanceform.L.value=tmp7;}
	else InputError();
 return;
}

//  -----------------------------------------

// Inductance for Twin Lead -----------------------------------------
function LTwinLead() {
	var d = 1.0*document.inductanceform.A.value;
	var a = 1.0*document.inductanceform.B.value;
	var p = 1.0*document.inductanceform.C.value;
	
	if( (d >(2*a)) && (Check_A() && Check_B() && Check_C()) )
		{document.inductanceform.L.value=((u*p)/PI)*ArcCosh(d/(2*a));}
	else InputError();
 return;
}

// Inductance for Round Wire over a Ground Plane ----------------------
function LWireG() {
	var h = 1.0*document.inductanceform.A.value;
	var a = 1.0*document.inductanceform.B.value;
	var p = 1.0*document.inductanceform.C.value;
	
	if( (h>=a) && (Check_A() && Check_B() && Check_C()) )
		{document.inductanceform.L.value=((u*p)/(2*PI))*ArcCosh(h/a);}
	else InputError();
 return;
}

// Inductance for Vertically Spaced Traces ----------------------
function LTraceV() {
	var w = 1.0*document.inductanceform.A.value;
	var h = 1.0*document.inductanceform.B.value;
	var t = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( (w>0) && ((w>h) && (h>(2*t)) && (w>t)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=((u*p*h)/w);}
	else InputError();
 return;
}

// Inductance for Wide Trace over a Ground Plane ----------------------
function LTraceG() {
	var w = 1.0*document.inductanceform.A.value;
	var h = 1.0*document.inductanceform.B.value;
	var t = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( (w>0) && ((w>h) && (h>t) && (w>t)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=(u*p*h)/w;}
	else InputError();
 return;
}

// Inductance for Coplanar Traces ----------------------
function LTraceH() {
	var w = 1.0*document.inductanceform.A.value;
	var d = 1.0*document.inductanceform.B.value;
	var t = 1.0*document.inductanceform.C.value;
	var p = 1.0*document.inductanceform.D.value;
	
	if( ((d>w) && (d>t) && (w>t)) && (Check_A() && Check_B() && Check_C() && Check_D()) )
		{document.inductanceform.L.value=((u*p)/PI)*ArcCosh(d/w);}
	else InputError();
 return;
}

// -------------------------------------------------------------------------
// END OF SCRIPT
// -------------------------------------------------------------------------



