How to Modify FEMM files on the fly

Kingfish

100 MW
Joined
Feb 3, 2010
Messages
4,064
Location
Redmond, WA-USA, Earth, Sol, Orion–Cygnus Arm, Mil
Greetings.

I have created roughly 200 models using FEMM Version 4.2 in the past two years; anyone following the Doing the Math thread will readily see that I’ve been a busy boy. It is a useful tool, however it lacks a few nice features, such as a way to measure between points or segments, or a method to rapidly substitute materials, or to edit the number of turns of conductors en masse as would a high-level mature product could.

I would like to show you how to make these changes quickly. For this example I used Microsoft Visual Studio 2010, however any decent text editor will do because the files are in simple ASCII. The only caveat to using text editors is to not allow them to apply text formatting. We need only to search and replace, and cut & paste. :)

File Format Review
The source files are in ASCII. If you are familiar with DXF format, the FEM format is very similar. For the neophyte: Each line represents a property or piece of data. The file is organized with a header section and then followed by data sections.

  • The undefined Header section contains Problem properties as single line statements. This is followed with Group statements, with each Group providing the Name of the group, and the Count of components. These are internally indexed (1-based) by the application and used as a reference for the Data sections. It’s pretty easy to read and figure out which component is referenced.
  • Material Block properties (called BlockProps) follow, and are presented in XML format with terminator.
  • Circuit properties (CircuitProps) follow, and are presented in XML format with terminator.
  • Data: Numerical Points (NumPoints) represents each single node, and are listed as a single entity formatted X, Y, 0, 0.
  • Data: Numerical Segments (NumSegments) are straight-lined segments described in a similar manner as the point data, and connect between points.
  • Data: Numerical Arc Segments (NumArcSegments) are curved lines between points.
  • Data: Numeric Holes (NumHoles): I don’t know what these are and I don’t use them. The count is Zero in my models.
  • Data: Numeric Block Labels (NumBlockLabels): Simply – they are object block definitions, the meat and potatoes that describe the materials within the bounding segments. The format is: X, Y, Block ID, Auto Mesh?, Circuit ID, Magnetization Direction, Group ID, Number of Turns (& direction), Mesh Size?
Replacing Materials
Wholesale replacement in one edit to the file can be made in the following manner:

  1. Open a new file and add the replacement material to the Materials Library.
  2. Save the file to a known location, for the moment let’s presume it’s the same folder as the file to update.
  3. Important! Make a backup of the file you wish to update.
  4. Close FEMM and Open the Editor, then open both the new file and the one we want to update; read them in as ASCII Text.
  5. With the new file, find the section [BlockProps] and locate the new material; select the entire block including <BeginBlock> and <EndBlock> and copy it to the Clipboard.
  6. With the file to update, find and select the <BeginBlock> and <EndBlock> of the material we want to replace, and paste over it with the new definition.
  7. Save the updated file. Note: Some editors like to keep the handle open on the file which can prevent another program from having Read-Access. Visual Studio and Notepad do not keep file locks, however Word and Excel will, so chose a good editor that behaves nicely to eliminate this issue. :wink:
  8. Open the updated file in FEMM and check to see if the edit took: Review the Materials Library, and inspect the object definitions closely.
All good? :)

Editing the Number of Turns en masse
This edit can be quite a bit trickier and may not work for every case, therefore I encourage to make a backup of the original file before proceeding. My AF models have three circuits and conductors with windings in two directions. However the number of turns is easy to spot in the file format, and we can replace them by using associative editing of the pattern. Let’s review the example below:

Code:
17.100000000000001	12.800000000000001	4	-1	1	90	1	6	0
32.899999999999999	35.356999999999999	4	-1	1	90	1	-6	0
The number of turns is equal to 6, and I have two entries for Left and Right turns. We can’t just edit 6 by itself; we have to look for a good pattern. From experience, this will take no less than two replacements. I would build two replacement patterns on these two cases.
Code:
“	90	1	6	0” 
“	90	1	-6	0”
If I wanted 8 turns, the replacement would be:
Code:
“	90	1	8	0” 
“	90	1	-8	0”
As it turns out, I required two more:
Code:
“	0	1	6	0” 
“	0	1	-6	0”
Replaced with:
Code:
“	0	1	8	0” 
“	0	1	-8	0”
Save the file and compare with the original. Normally I’d use WinDiff but the FEM file format throw it for a loop, so I turned instead to… <hesitation> Microsoft Word. Yes – MS Word can do file comparisons very nicely: Just don’t save the file!!! You have been warned. :)

I am sure other mass edits are possible, but for me – these are the only ones worth bothering with. Perhaps one day someone will integrate these features into FEMM Version 4.3, and if they do – would you please add a method for measuring between points? 8)

Enjoy, KF
 
Is there anything extra that can be done with this method compared to lua scripting?
 
bearing said:
Is there anything extra that can be done with this method compared to lua scripting?
Is your question suggesting this can be done in script? Brilliant: Go for it. I support automata whenever possible.

~KF
 
I haven't read in detail what you did above, but since lua scripting is built into FEMM, you can do a lot of stuff with it. It's all in the manual. I just assumed that you were familiar with lua scripting, since you seem to have spent a few hours with FEMM.

It was a while since I made any script, but I remember that I could change the resistivity of a conductor with the script, so I assume it was also possible to change the actual material. What I mostly did, was to try different dimension of things. I would make a loop in the script that, for instance, modified the airgap, ran the analysis, looked at the results, saved the resulting torque, and then tried again with the next value. That way it was possible to sort of "optimize" the design. I never made any nestled loops, since one loop took minutes to finish. But if you really want to optimize a design, you could have like 5 nestled loops which changes 5 parameters. Then you could let the simulation run, it would probably take days, but in the end you would have a pretty optimized result.
 
Back
Top