How to add my own model to openems

How to use openEMS. Discussion on examples, tutorials etc

Moderator: thorsten

Post Reply
Katrina
Posts: 12
Joined: Tue 25 May 2021, 03:38

How to add my own model to openems

Post by Katrina » Tue 25 May 2021, 03:44

Hello, guys. I'm a student of high speed railway electromagnetic calculation. First of all, please allow me to say that open EMS is a very good software. But I can't use it skillfully through the study on the website. So I have a few questions for you.

First of all, does open EMS support direct import of my own model, such as a high-speed rail model with ". IGS" format. If you can, can you teach me how to import it? If not, how will this problem be solved?

The second question is whether you have a source code package that can be compiled under windows. Because I am a beginner of FDTD, I want to learn relevant theoretical knowledge through the process of compilation.

If you can reply me in your busy schedule, I will thank you very much

HexAndFlex
Posts: 14
Joined: Sat 06 Oct 2018, 09:11

Re: How to add my own model to openems

Post by HexAndFlex » Tue 25 May 2021, 05:08

The software can import STL files. Most 3D software can export to that format.

The source code is on the openEMS GitHub.

Katrina
Posts: 12
Joined: Tue 25 May 2021, 03:38

Re: How to add my own model to openems

Post by Katrina » Wed 26 May 2021, 04:43

First of all, thank you for your reply, but I still don't understand. Could you explain the process of importing software into STL model in more detail. Another problem is, after STL model is imported into software, I set up an excitation in it. Can the software calculate the distribution of electric field and magnetic field in the model?

sjgallagher2
Posts: 4
Joined: Tue 22 Jun 2021, 15:36

Re: How to add my own model to openems

Post by sjgallagher2 » Fri 25 Jun 2021, 20:24

You can import .stl files to OpenEMS using the ImportSTL function. (You need to use the absolute path of the .stl file as one of the arguments, otherwise it will throw an error.) In my limited experience, you can only import one object at a time for .stl files, so export each body in your assembly as an individual .stl file and import them together.

Here's some example code:

Code: Select all

# Clean up
close all
clear
clc 

# Initialize FDTD environment
unit = 1e-3; # Use this to convert to mm
FDTD = InitFDTD('NrTS',2000);

# Sinusoidal excitation
f0 = (2450e6/1)*unit; # Scaled to mm by decreasing frequency
lambda = 3e8/f0
FDTD = SetSinusExcite(FDTD,f0);

# Boundary conditions are absorptive surface
FDTD = SetBoundaryCond(FDTD,{'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'});

# Initialize geometry
CSX = InitCSX();

# Define simple grid 
step=lambda/20;
mesh.x = -lambda:step:lambda;
mesh.y = -lambda:step:lambda;
mesh.z = -lambda:step:lambda;

CSX = DefineRectGrid(CSX, 1, mesh);

# Add cad geometry 
CSX = AddMetal(CSX, 'ground_RX'); # Declare PEC
CSX = ImportSTL(CSX, 'ground_RX',1,'C:/Users/[...]/MyModel.stl'); # Import geometry; make sure you use the absolute path!

# Add source
start = [-step 0 0]; # Note: these must make contact at either end with metal! And keep it fixed to grid points!
stop = [step 0 0];  #
R = 50; # Resistance
[CSX  port] = AddLumpedPort(CSX,1,1,R,start,stop,[1 0 0],true);

# Define plane for observing the E field
CSX = AddDump(CSX, 'Et');
CSX = AddBox(CSX,'Et',0,[-200 -200 50],[200 200 50]);

# Write FDTD and CSX structure to xml file 
mkdir('tmp');
WriteOpenEMS('tmp/tmp.xml',FDTD,CSX);

# View the geometry generated
CSXGeomPlot('tmp/tmp.xml');

# Run the simulation
RunOpenEMS('tmp','tmp.xml','');

Be careful with units. The .stl format doesn't define units, so find the default system for your CAD software, and use it to make sure everything scales. OpenEMS uses meters, so make sure your simulation is scaled for meters. In the above, I assumed millimeter .stl file and altered the simulation frequency.

sjgallagher2
Posts: 4
Joined: Tue 22 Jun 2021, 15:36

Re: How to add my own model to openems

Post by sjgallagher2 » Fri 25 Jun 2021, 20:33

Also, see this forum post for some more information about lumped ports, how they're modeled, what the requirements are, etc.

Some other thoughts. Probably the most important aspect to keep in mind when importing geometries (or for FDTD in general) is your meshing (see this page on the wiki). Most of the time, you'll be creating a mesh manually. You can export the parts of your mesh that are e.g. specified as PEC (perfect electrical conductor) by running:

Code: Select all

RunOpenEMS('tmp','tmp.xml','--debug-PEC --no-simulation');
Instead of simply using RunOpenEMS('tmp','tmp.xml'). This will create a .vtk file that can be opened in ParaView. It should resemble your geometry - this is the part that's going to actually be used as a conductor during calculations. See also this page on the wiki.

Note also that you can import .stl files to ParaView and compare them to the mesh geometry (or radiation patterns etc) for better visualization.

Katrina
Posts: 12
Joined: Tue 25 May 2021, 03:38

Re: How to add my own model to openems

Post by Katrina » Fri 02 Jul 2021, 08:24

OK, your suggestion is very useful. Thank you very much!

Post Reply