FEMM/examples/IntegralExample/simpleintegral.lua

42 lines
1.3 KiB
Lua

open("LinearNew.fem");
mi_analyze();
mi_loadsolution();
-- Turn off smoothing so that mo_getpointvalues will return the
-- "raw" piece-wise constant values for flux density and field intensity
mo_smooth("off");
-- Grab the total number of elements in the problem;
numelm = mo_numelements();
-- Call mo_getprobleminfo to grab the depth of the problem in th
-- into-the-page direction, which we need for computing volume integrals.
-- Note that the problem depth is always returned in units of meters.
problemtype,freq,depth=mo_getprobleminfo()
-- Loop through all elements to evaluate the stored energy in all regions
-- denoted as being part of Group 1.
nrg = 0;
for k=1,numelm do
p1,p2,p3,x,y,a,g=mo_getelement(k);
if (g == 1) then
-- Compute element volume.
dv = depth*a*mm^2;
-- Evaluate properties at element centroid
a,bx,by,Sig,E,hx,hy = mo_getpointvalues(x,y);
-- Compute the contribution of this element to the integral
nrg = nrg + (1/2)*(bx*hx+by*hy)*dv;
end
end
-- For comparison, directly select Group 1 and perform the integral using
-- the built-in function
mo_groupselectblock(1);
altnrg = mo_blockintegral(2);
-- Print out results
print("Energy in group 1 computed by manual integral ",nrg);
print("Energy in group 1 computed by canned integral ",altnrg);