Hello,
Some years ago I got great help from someone here who was a racer in LUA scripts. But those scripts I saved in my old computer, which is pretty much out of service now.
I need help to make a script that measure torque of a group made in FEMM 4.2. I have read the FEMM 4.2 manual, but I cannot understand what script to use, or where to put them in right order.
I want to keep the original file, so the script must save the results as another file.
For group 1 with center X0 - Y0, I need 0.8 degree steps starting at 0 degrees, ends at 71.2 degrees (At 72 degrees the result will be the same as 0 degrees)
For group 2 with center X0 - Y1, I need 1 degree steps starting at 0 degrees, ends at 89 degrees (At 90 degrees the result will be the same as 0 degrees)[/size]
Can someone please help? Any help is very much appreciated :-)
Vidar
I used a script that I've used myself a while ago and modified it for your needs, please be aware it's not tested but I think it should give you a decent start :) .
Besides generating data it also generates an image of every simulated step which can later be converted to an animated gif file if you want.
showconsole()
--Defining the variables
dAngle=0.8 -- Increase of angle ( Degrees of rotor rotation by step )
totalDegrees= 72 -- amount of total degrees to roate
X0 = 0
Y0 = 0
open("myfile.fem")
mi_saveas("temp.fem") -- Temp file for save the original
mi_seteditmode("group")
data = {};
for n=0,((totalDegrees/dAngle)-1) do
alfa=dAngle*n
print(alfa) -- print to console for debugging and showing the progress
--analyze the current rotation and take image
mi_analyse(1)
mi_loadsolution()
mo_showdensityplot(0,0,0.5,0,"mag") -- Obtain Image
mo_savebitmap(format("acgen_%1$d.bmp",alfa)) -- Save Image
--Calculate the torque
mi_analyse(1)
mi_loadsolution()
mo_groupselectblock(1)
torque = mo_blockintegral(22)
--gather all data
data[n] = {}
data[n][1] = alfa
data[n][2] = torque
mo_close()
-- write results to disk for further analysis, make sure the file already exist to write the results to
fp=openfile("results.txt","a")
write(fp,data[n][1],"\t" .. data[n][2],"\n")
closefile(fp);
mi_selectgroup(1) -- Select Rotor group
mi_move_rotate(X0,Y0,dAngle) -- Rotate the rotor
end
WOW! I can't thank you enough :) This is awesome!
Thank you broli!
Vidar
I tried it, and I think it need some minor modifications. I got an error message. Please see attached picture :-)
showconsole()
--Defining the variables
dAngle=0.8 -- Increase of angle ( Degrees of rotor rotation by step )
totalDegrees= 72 -- amount of total degrees to roate
X0 = 0
Y0 = 0
open("GE.FEM")
mi_saveas("GEtemp.FEM") -- Temp file for save the original
mi_seteditmode("1")
data = {};
for n=0,((totalDegrees/dAngle)-1) do
alfa=dAngle*n
print(alfa) -- print to console for debugging and showing the progress
--analyze the current rotation and take image
mi_analyse(1)
mi_loadsolution()
mo_showdensityplot(0,0,0.5,0,"mag") -- Obtain Image
mo_savebitmap(format("acgen_%1$d.bmp",alfa)) -- Save Image
--Calculate the torque
mi_analyse(1)
mi_loadsolution()
mo_groupselectblock(1)
torque = mo_blockintegral(22)
--gather all data
data[n] = {}
data[n][1] = alfa
data[n][2] = torque
mo_close()
-- write results to disk for further analysis, make sure the file already exist to write the results to
fp=openfile("results.txt","a")
write(fp,data[n][1],"\t" .. data[n][2],"\n")
closefile(fp);
mi_selectgroup(1) -- Select Rotor group
mi_move_rotate(X0,Y0,dAngle) -- Rotate the rotor
end
I made a mistake in "group"...at the beginning. It works now - just have to add script for group 2 because these two groups are colliding :D
Can I just copy the script twice in the same LUA?
I want both groups to rotate in the same script. I have tried just to add the script once more, under the first one, and changed group number, XY points etc, but got errors...
Vidar
Since it's the same amount of steps just different increments you can keep it in the same for loop and try something like this (I highlighted the changes):
showconsole()
--Defining the variables
dAngle1=0.8 -- Increase of angle for group 1 ( Degrees of rotor rotation by step )
dAngle2=1.0 -- Increase of angle for group 2 ( Degrees of rotor rotation by step )
totalDegrees= 72 -- amount of total degrees to roate
X0 = 0
Y0 = 0
open("GE.FEM")
mi_saveas("GEtemp.FEM") -- Temp file for save the original
mi_seteditmode("group")
data = {};
for n=0,((totalDegrees/dAngle1)-1) do
alfa=dAngle1*n
print(alfa) -- print to console for debugging and showing the progress
--analyze the current rotation and take image
mi_analyse(1)
mi_loadsolution()
mo_showdensityplot(0,0,0.5,0,"mag") -- Obtain Image
mo_savebitmap(format("acgen_%1$d.bmp",alfa)) -- Save Image
--Calculate the torque
mi_analyse(1)
mi_loadsolution()
mo_groupselectblock(1)
torque = mo_blockintegral(22)
--gather all data
data[n] = {}
data[n][1] = alfa
data[n][2] = torque
mo_close()
-- write results to disk for further analysis, make sure the file already exist to write the results to
fp=openfile("results.txt","a")
write(fp,data[n][1],"\t" .. data[n][2],"\n")
closefile(fp);
-- rotate group 1
mi_selectgroup(1) -- Select Rotor group 1
mi_move_rotate(X0,Y0,dAngle1) -- Rotate the rotor
-- rotate group 2
mi_selectgroup(2) -- Select Rotor group 2
mi_move_rotate(X0,Y0,dAngle2) -- Rotate the rotor
end
Thanks again broli! This is really helpful :D
Can I put in additional line:
X1 = 0
Y1 = -1
and change:
mi_move_rotate(X0,Y0,dAngle2) to mi_move_rotate(X1,Y1,dAngle2)?
If I want to rotate group 2 90 degrees instead, can I add:
dAngle1=0.8 -- Increase of angle for group 1 ( Degrees of rotor rotation by step )
dAngle2=1.0 -- Increase of angle for group 2 ( Degrees of rotor rotation by step )
totalDegrees= 72 -- amount of total degrees to roate
totalDegrees= 90 -- amount of total degrees to roate???[/size]
Vidar
Ofcourse - when outer rotor turns 72 degrees the inner rotor turns 90 by itself. Didn't think of that.
Now it all works as I want it to. Thank you!!!!!
Vidar
I know this is an old topic, but I don't know where else to ask really. I searched around google to find this script, I'm using femm 4.2 and am also trying to get femm to rotate a couple groups of objects and output the torque values, or at least output the .ans files so I can just go look at the torque myself. Rotating everything the few degrees I need and analyzing each individually until I get to 360 takes forever.
I tried the script above but keep getting
"error: No current magnetics input in focus"
stack traceback:
1: function 'mi_saveas' [C]
2: main of string "'showconsole()..." at line 10
Yes I also made a boundary around everything and I can analyze it normally with no problems.
Yes I also gave a group value to the group I want to rotate that is the same as the group value specified in the script.
Also, in the file names, where are the files supposed to be placed? Where does FEMM end up looking for them? What folder? The installed folder? what if I installed it in a different location should I specify the entire path?
Hi there.
The lua script might refer to groups. If your model consist of different parts, say the rotor have more than one part, you must mark every line, arch, points, material, press Space and then name them all as group 1.
If the script, which you can edit in notepad, refer to grpup 2 or other than 1, you will get an error.
If the rotors symmetry consists of several equal magnets, for example 6 of them in a circle, you need to simulate only 60 degrees rotation, because the next 60 degrees will give you the same output. No need for 360 degrees samples.
Vidar
Quote from: Apoc4lypse on April 20, 2018, 01:11:21 PM
I know this is an old topic, but I don't know where else to ask really. I searched around google to find this script, I'm using femm 4.2 and am also trying to get femm to rotate a couple groups of objects and output the torque values, or at least output the .ans files so I can just go look at the torque myself. Rotating everything the few degrees I need and analyzing each individually until I get to 360 takes forever.
I tried the script above but keep getting
"error: No current magnetics input in focus"
stack traceback:
1: function 'mi_saveas' [C]
2: main of string "'showconsole()..." at line 10
Yes I also made a boundary around everything and I can analyze it normally with no problems.
Yes I also gave a group value to the group I want to rotate that is the same as the group value specified in the script.
Also, in the file names, where are the files supposed to be placed? Where does FEMM end up looking for them? What folder? The installed folder? what if I installed it in a different location should I specify the entire path?