--INTERACTIVE COIL CALCULATION -- LUA SCRIPT FOR CALCULATION OF INDUCTANCE (AIR COILS ONLY) ---------------------------------------------------------------------- -- INPUT COIL PARAMETERS length=tonumber(prompt("Coil length/mm")) InnerDiameter=tonumber(prompt("Inner coil diameter/mm")) th=tonumber(prompt("Thickness of winding/mm")) turns=tonumber(prompt("Number of turns")) wiredia=tonumber(prompt("Wire diameter")) I=tonumber(prompt("Current intensity I/A")) -- calculate geometric variables radius=InnerDiameter/2 h=length/2 x1=radius x2=x1+th ---------------------------------------------------------------------- -- ANALYSIS PARAMETERS -- BOUNDARY OF CALCULATION -- boundary radius is k times length or outer radius k=2 R=k*length --for flat coil 2x outer radius if x2>length then R = k*x2 end P=prompt("Mesh division factor, the bigger the more precise, default=100:") if P == "" then Precision = 100 else Precision=tonumber(P) end Copperautomesh=0 --Coppermeshsize=1 Coppermeshsize=R/Precision Airautomesh=0 --Airmeshsize=tonumber(prompt("Air mesh size [e.g. 5]:")) Airmeshsize=R/Precision maxsegdeg=2.5 -- boundary meshed with elements that span max. maxsegdeg per element --************************************************************* showconsole() clearconsole() --New magnetic problem create(0) mi_probdef(0,"millimeters","axi",1E-8) ---------------------------------------------------------- -- SYMMETRY LINE AND SPHERE mi_addnode(0,-R) mi_addnode(0,R) mi_addsegment(0,-R,0,R) mi_addarc(0,-R,0,R,180,2.5) mi_zoomnatural() ----------------------------------------------------------- -- COIL mi_addnode(x1,-h) mi_addnode(x1,h) mi_addnode(x2,-h) mi_addnode(x2,h) mi_addsegment(x1,-h,x1,h) mi_addsegment(x1,h,x2,h) mi_addsegment(x2,h,x2,-h) mi_addsegment(x1,-h,x2,-h) ----------------------------------------------------------- -- MATERIALS mi_addmaterial ("Air",1,1) mu_x=1 -- rel. permeability mu_y=1 HC=0 -- permanent coercitivity [A/m] Jr=0 -- current density (real) [A/mm2] Ji=0 -- current density (real) [A/mm2] Conductivity=58 -- [MS/m] Lam_d=0 -- laminar thickness [mm] Phi_hmax=0 -- hysteresis lag angle Lam_fill=1 -- 100% Lam_type=3 -- magnet wire Phi_x =0 --Hysteresis lag x Phi_y =0 --Hysteresis lag y Nstrands=1 mi_addmaterial ("Copper",mu_x,mu_y,HC,Jr,Ji,Conductivity,Lam_d,Phi_hmax,Lam_fill,Lam_type,Phi_x,Phi_y,Nstrands,wiredia) ----------------------------------------------------------- -- CIRCUIT --var: I mi_addcircprop("Coil",I,0,1) ----------------------------------------------------------- -- BLOCK LABELS TO DEFINE REGIONS -- COPPER -- var: turns mi_addblocklabel(radius+th/2,0) mi_selectlabel(radius+th/2,0) mi_setblockprop("Copper",Copperautomesh,Coppermeshsize,"Coil",0,0,turns) mi_clearselected() -- AIR mi_addblocklabel(radius/2,0) mi_selectlabel(radius/2,0) mi_setblockprop("Air",Airautomesh,Airmeshsize,"air",0,0,0) -------------------------------------------------------------------------------- -- BOUNDARY CONDITIONS -- asymptotic boundary conditions BdryFormat=2 --Mixed ur=1 --relative permeability c0=1/(ur*1.256E-6 *R*1e-3) -- R = radius of considered domain (boundary) IN MM! c1=0 mi_addboundprop("ABC",A0,A1,A2,Phi,Mu,Sig,c0,c1,BdryFormat) mi_selectarcsegment (0,R) -- meshed with elements that span max. maxsegdeg per element mi_setarcsegmentprop(maxsegdeg,"ABC",0,0) ---------------------------------------------------------------------------------- -- ANALYZE --****************************************************************************** mi_saveas("tmp.fem") print("Saving to temporary file") -- GENERATE MESH print("Creating mesh") mi_createmesh() mi_showmesh() print("Analyzing...") mi_analyze(0) mi_loadsolution() print("Ready!") ----------------------------------------------------------------- -- INDUCTANCE via energy mo_selectblock((InnerDiameter+th)/2,0) L=mo_blockintegral(0)/I^2 -- AJ print("L = ",L*1000,"mH") -- RESISTANCE R = mo_blockintegral(4)/I^2 print("R = ",R,"Ohm")