Getting into OpenEMS - Page 1
Forum section: electronics / rf-microwave

author: PerArdua
author_rank: Regular Contributor
timestamp: November 25, 2024, 10:09:21 pm
content: I'm trying to get into OpenEMS as a tool for analysing the behaviour of microwave components. I think I understand the general workflow (setup in octave, view structures in AppCSXCAD, send data to OpenEMS, and process results in octave), as well as some of the general principles around FDTD, but only at a surface level.I'm trying to simulate the following structure - a bad interdigital filter with no GND connections. My code seems to produce the correct structure, but when OpenEMS starts I get a message saying that all of the primitives are unused (except for the substrate).Code:close allclearclcCSX = InitCSX();% Define materialsCSX = AddMaterial(CSX, 'substrate');% Substrate materialCSX = SetMaterialProperty(CSX, 'substrate', 'Epsilon', 4.2);CSX = AddMetal(CSX, 'feed1');CSX = AddMetal(CSX, 'res1');CSX = AddMetal(CSX, 'res2');CSX = AddMetal(CSX, 'res3');CSX = AddMetal(CSX, 'res4');CSX = AddMetal(CSX, 'res5');CSX = AddMetal(CSX, 'feed2');CSX = AddMetal(CSX, 'gnd');%Define geometryCSX = AddBox(CSX, 'substrate', 0, [0 0 0], [67.62 49.4 -1.5]);CSX = AddBox(CSX, 'feed1', 0, [0 11.125 0], [6.75 14.075 0]);CSX = AddBox(CSX, 'res1', 0, [6.75 10 0], [9.7 39.4 0]);CSX = AddBox(CSX, 'res2', 0, [18.2 10 0], [21.15 39.3 0]);CSX = AddBox(CSX, 'res3', 0, [32.75 10 0], [35.7 39.3 0]);CSX = AddBox(CSX, 'res4', 0, [47.3 10 0], [50.25 39.3 0]);CSX = AddBox(CSX, 'res5', 0, [58.75 10 0], [61.7 39.4 0]);CSX = AddBox(CSX, 'feed2', 0, [61.7 11.125 0], [67.62 14.075 0]);CSX = AddBox(CSX, 'gnd', 0, [0 0 -1.5], [67.62 49.4 -1.5]);% Add ports[CSX port{1}] = AddLumpedPort(CSX, 1, 1, 50, [0 11.125 0], [0 14.075 -1.5], [0 0 1], true);[CSX port{2}] = AddLumpedPort(CSX, 1, 2, 50, [67.62 11.125 0], [67.62 14.075 -1.5], [0 0 1], false);% Slicemesh = DetectEdges(CSX);% Extend meshmesh.x = [mesh.x -30 97.62];% Two YZ planes at X = -25 and X = 25mesh.y = [mesh.y -30 79.4];% Two XZ planes at Y = -25 and Y = 25mesh.z = [mesh.z -30 30];% Two XY planes at Z = -15 and X = 15% Smooth meshmesh = SmoothMesh(mesh, 0.5, 1.25);% (mesh, max_res, ratio)% Set FDTD parameters:F0 = 1.4*10^9;% Centre frequencyFC = 300*10^9;% Corner frequencyFDTD = InitFDTD('EndCriteria', 10^-3);FDTD = SetGaussExcite(FDTD, F0, FC);FDTD = SetBoundaryCond(FDTD, {'MUR','MUR','MUR','MUR','MUR','MUR'});CSX = DefineRectGrid(CSX, 1/1000, mesh);% Save data file that can be used by OpenEMS and AppCSXCADmkdir('temp');WriteOpenEMS('temp/test.xml', FDTD, CSX);% Display 3D modelCSXGeomPlot('temp/test.xml');% Run OpenEMSRunOpenEMS('temp', 'test.xml');I have tried to follow this tutorial (youtube.com/watch?v=SPlrcp-gCKk), as well as any documentation I can find online - but the OpenEMS documentation seems a bit sparse, and without a background in the underlying theory I am a bit lost.I did read the FAQs (https://wiki.openems.de/index.php/Frequently_Asked_Questions.html), but as far as I can see none of the reasons it suggests unused primatives are met here - the structure is within the meshed area, the primatives are all of the same priority, and I assigned a primative to each property.Any ideas as to where I am going wrong?Additionally, if anyone is aware of any useful resources to try and learn more about the various options available in OpenEMS, I'd be grateful.

author: szoftveres
author_rank: Regular Contributor
timestamp: November 26, 2024, 03:05:46 am
content: I started out from a working official example (https://github.com/thliebig/openEMS/blob/master/matlab/Tutorials/Simple_Patch_Antenna.m) and modified it incrementally until I got what I wanted to simulate - writing one from scratch would have given me no way to detect any mistake I made along the way.Also, one metal is sufficient for all features, eg:Code:CSX = AddMetal(CSX, 'copper');

author: selcuk
author_rank: Frequent Contributor
timestamp: November 26, 2024, 12:38:41 pm
content: All of them are vanishing into the substrate since they have the same priority value. When two objects intersect, the one with the higher priority exists in that intersection and the other one is assumed to be not there.https://wiki.openems.de/index.php/File:Priorities2.png.htmlYou may use like this:Code:CSX = AddBox(CSX, 'substrate', 0, [0 0 0], [67.62 49.4 -1.5]);CSX = AddBox(CSX, 'feed1', 9, [0 11.125 0], [6.75 14.075 0]);CSX = AddBox(CSX, 'res1', 10, [6.75 10 0], [9.7 39.4 0]);CSX = AddBox(CSX, 'res2', 10, [18.2 10 0], [21.15 39.3 0]);CSX = AddBox(CSX, 'res3', 10, [32.75 10 0], [35.7 39.3 0]);CSX = AddBox(CSX, 'res4', 10, [47.3 10 0], [50.25 39.3 0]);CSX = AddBox(CSX, 'res5', 10, [58.75 10 0], [61.7 39.4 0]);CSX = AddBox(CSX, 'feed2', 9, [61.7 11.125 0], [67.62 14.075 0]);CSX = AddBox(CSX, 'gnd', 5, [0 0 -1.5], [67.62 49.4 -1.5]);

author: PerArdua
author_rank: Regular Contributor
timestamp: November 29, 2024, 05:58:18 pm
content: Thank you both - I got the simulation to work - only took 9 hours...And I did spot that I was trying a 600 GHz bandwidth instead of 600 MHzIf I might ask, why is it that the geometry in the YouTube tutorial doesn't throw up this error, when all of his boxes are the same priority and his 'signal' and 'ground' sit on the same plane as his 'substrate' boundaries?If you go to 26 mins in exactly, you can see the three boxes, each with 0th priority.

author: selcuk
author_rank: Frequent Contributor
timestamp: December 01, 2024, 01:09:45 pm
content: I guess there is a difference between software versions in handling equal priorities. This is not clearly defined so I usually try to assign a different priority to each element to make sure the simulation runs as intended.An example block:Code:% object prioritiesant_prio = 20 ; % antennatr_prio = 19 ; % transmission linevia_prio = 18 ; % viagnd_prio = 17 ; % ground coppersh_prio = 16 ; % shieldport_prio = 15 ; % portmask_prio = 10 ; % solder masksub_prio = 9 ; % substrateair_prio = 8 ; % airenc_prio = 7 ; % enclosure

author: electron_plumber
author_rank: Regular Contributor
timestamp: January 05, 2025, 09:07:24 pm
content: Piggybacking on this thread.I'm trying to simulate something in openEMS for the first time. I chose S11 of a microstrip with and without a ground cutout underneath but my simulation seems to hang -- I kill it after about 10 minutes, since all the example scripts run in <30 seconds. The geometries seem fine, to my eye, in the CSXCAD viewer (attached). Anyone with experience have any debug tips? Documentation is a bit sparse.Initial setupHere I define the microstrip length/width, substrate, and ground geometries.Code:### Import Librariesimport os, tempfilefrom pylab import *import timefrom CSXCAD import ContinuousStructurefrom openEMS import openEMSfrom openEMS.physical_constants import *### Setup the simulationt = time.time()Sim_Path = os.path.join(tempfile.gettempdir(), 'Test_{}'.format(t))post_proc_only = Falseunit = 1e-6 # specify everything in umMSL_length = 12243MSL_width = 240substrate_thickness = 76.4substrate_epr = 3.9ground_thickness = 15.2f_max = 2e9### Setup FDTD parameters & excitation functionFDTD = openEMS()FDTD.SetGaussExcite( f_max/2, f_max/2 )FDTD.SetBoundaryCond( ['PML_8', 'PML_8', 'MUR', 'MUR', 'PEC', 'MUR'] )MeshHere I'm using essentially the same meshing strategy as the notch filter example. Not particularly optimized.Code:### Setup Geometry & MeshCSX = ContinuousStructure()FDTD.SetCSX(CSX)mesh = CSX.GetGrid()mesh.SetDeltaUnit(unit)resolution = C0/(f_max*sqrt(substrate_epr))/unit/50 # resolution of lambda/50third_mesh = array([2*resolution/3, -resolution/3])/4## Do manual meshingmesh.AddLine('x', 0)mesh.AddLine('x', MSL_width/2+third_mesh)mesh.AddLine('x', -MSL_width/2-third_mesh)mesh.SmoothMeshLines('x', resolution/4)mesh.AddLine('x', [-MSL_length, MSL_length])mesh.SmoothMeshLines('x', resolution)mesh.AddLine('y', 0)mesh.AddLine('y', MSL_width/2+third_mesh)mesh.AddLine('y', -MSL_width/2-third_mesh)mesh.SmoothMeshLines('y', resolution/4)mesh.AddLine('y', [-15*MSL_width, 15*MSL_width])mesh.AddLine('y', (MSL_width/2)+third_mesh)mesh.SmoothMeshLines('y', resolution)mesh.AddLine('z', linspace(-500,500,10))mesh.SmoothMeshLines('z', resolution)Copper, substrate, reference plane, and airgap geometriesHere I set generate the substrate material (it says RO4350B, but i've changed the epr) and I instantiate a single 50ohm port for S11.Code:## Add the substratesubstrate = CSX.AddMaterial( 'RO4350B', epsilon=substrate_epr)start = [-MSL_length, -15*MSL_width, 0]stop = [+MSL_length, +15*MSL_width, substrate_thickness]substrate.AddBox(start, stop )# Port Setupfeed_pos = -MSL_length+100;# %feeding position in x-directionfeed_R = 50; # %feed resistancestart = [feed_pos,0,0]stop = [feed_pos, 0, substrate_thickness];port = FDTD.AddLumpedPort(1 ,feed_R, start, stop, 'z', 1.0);## Trace Coppertrace = CSX.AddMetal('PEC')trace_start = [ -MSL_length, -MSL_width/2, substrate_thickness]trace_stop = [ MSL_length, MSL_width/2, substrate_thickness]trace.AddBox(trace_start, trace_stop,priority=0)## Ground planeground_plane = CSX.AddMetal('PEC')start = [-MSL_length, -15*MSL_width, 0]stop = [+MSL_length, +15*MSL_width, -ground_thickness]ground_plane.AddBox(start, stop,priority=0)# Define the void (air or vacuum)void_material = CSX.AddMaterial('Air')void_start = [-MSL_length+1000, -MSL_width, 0]void_stop = [ MSL_length-1000, MSL_width, -ground_thickness]void_material.AddBox(void_start, void_stop,priority=1)visualize/runCode:if 1: # debugging onlyCSX_file = os.path.join(Sim_Path, 'test.xml')if not os.path.exists(Sim_Path):os.mkdir(Sim_Path)CSX.Write2XML(CSX_file)from CSXCAD import AppCSXCAD_BINos.system(AppCSXCAD_BIN + ' "{}"'.format(CSX_file))# ### Run the simulationFDTD.Run(Sim_Path, cleanup=True)(Complete file also attached)

author: Miek
author_rank: Regular Contributor
timestamp: January 05, 2025, 11:35:28 pm
content: Quote from: electron_plumber on January 05, 2025, 09:07:24 pmOne thing to watch is the energy value in the log. It should increase initially as energy is introduced to the system from the excitation, then gradually decrease as energy leaves to terminations/boundaries.Running your example, I notice two things: there's a warning about the port 1 excitation being unused, and the energy value is stuck at 0. I think there's something wrong about the way your port is defined and the excitation doesn't seem to work. I don't know enough about OpenEMS myself yet to say exactly what is wrong, but I'd suggest starting by making it more like the notch example and using AddMSLPort.

author: electron_plumber
author_rank: Regular Contributor
timestamp: January 06, 2025, 02:55:30 am
content: Quote from: Miek on January 05, 2025, 11:35:28 pmThanks for the tip! If I use the MSLPort, the model runs and I get a plot. But the s-params are identical with the airgap code commented out, so the airgap either isn't being rendered properly (i've given it higher priority than the copper?) or the ports aren't properly referencing my ground plane? Hrm.