Kicad -> pcbmodelgen -> OpenEMS - electromagnetic field modelling

I have a 2012 rMBP. But for this sort of thing I’ve used Linode instances in the past. They just give you a shell in the cloud - I’ve had them running some optical simulation stuff before FDTD and ray tracing.

I bought this primarily as a processing/modelling machine, be it in VMs, native etc - I tend to use linux in a VM because home-brew starts infesting your machine with lots of junk that suddenly becomes incompatible with each other. So now they sit neatly in their own VMs.
It has been used for R, Quantum hackathons, Octave, optical and audio processing, LTSpice, Kicad, Xcode, ... the list goes on. Big CPU + Big memory in a small box (the SSD is not massive but I use a USB 1TB drive for the VMs).
 
  • Like
Reactions: exlabs
I left this running overnight. The mini's exhaust was like a jet engine 🙂

Warning: Unused primitive (type: Polygon) detected in property: metal_top!
Warning: No primitives found in property: metal_bot!
Running FDTD engine... this may take a while... grab a cup of coffee?!?
[@ 58m12s] Timestep: 40000 || Speed: 53.3 MC/s (8.732e-02 s/TS) || Energy: ~0.00e+00 (- 0.00dB)
RunFDTD: Warning: Max. number of timesteps was reached before the end-criteria of -50dB was reached...
You may want to choose a higher number of max. timesteps...
Time for 40000 iterations with 4650800.00 cells : 3493.04 sec
Speed: 53.26 MCells/s
error: t(2): out of bound 1 (dimensions are 1x1)
error: called from
DFT_time2freq at line 39 column 6
ReadUI at line 98 column 26
simulation_script at line 130 column 3
octave:1>

Hmm - that may need some more memory for one of the tasks. I've also checked the files - no data stored. Grrr. I'm wondering if the converter assumes all models start from 0,0 and go positive. Looks to be about an hour per tilmestep.

Ok I think this is because I was using a gaussian excite - with a centre freq of 24MHz and too small a spread. Instead I'll switch to a custom excite but with the function creating a centre 24.576MHz fundamental and then ill spoof and additional 20 odd harmonics to approximate a square wave. I may later use a square wave with octave FFT and do a peak find to the harmonics.
 
Last edited:
  • Like
Reactions: exlabs
I've noted that you can add things like LumpedElements, for example capacitors or resistors.

% function CSX = AddLumpedElement(CSX, name, direction, varargin)
%
% Add a lumped element property to CSX with the given name.
% Remember to add at least one or more box primitive to any
% property.
%
% arguments:
% direction: 0,1,2 or 'x','y','z' for the orientation of the lumped element
%
% optional arguments:
% 'R', 'C', 'L': definition of the lumped element properties
% 'Caps': 0 or 1 to (de)activate lumped element caps (1=default)
% If Caps are enable, a small PEC plate is added to each
% end of the lumped element to ensure contact to e.g
% a microstrip line
%
% examples:
% lumped element capacitor in y-direction with 1pF
% CSX = AddLumpedElement( CSX, 'Capacitor', 1, 'Caps', 1, 'C', 1e-12 );
% CSX = AddBox( CSX, 'Capacitor', 0, [0 0 0], [10 10 10] );
%
% See also AddMaterial, AddMetal, AddExcitation, AddProbe, AddDump, AddBox

I had a look at the pcb model converter and it doesn't add anything - it just uses the mesh.
The kicad pub file defines caps etc in it - including the footprint and the pins. So it could be possible to map the pin out locations to a lumped element with the capacitance (well the LCR) of the component between the pads.

Currently it's taking about an hour to run the model, however at the moment I'm not seeing any visible data (even when data is present in the output file).

Also with the open ems it has somethings that the CSXCAD doesn't have - such as AddStriplinePort which basically creates a port to fit on the end of a stripline (and basically all tracks attached are stripline). This may be a better port primitive.

The current pcb converter simply runs through the list of elements and picks out the PCB tracks to create the sim file. What an updated pub converter should do is look for footprints for components, search to see if it's an output pin, then create a stripline on the end of the pin. If it's an input then it should put an AddLumpedElement to ground to simulate the load pin. If the component sees a resistor, cap or inductor it should simply use AddLumpedElement to add the relevant characteristics between the two pads.
Things like transistors, fets, or triodes etc should be easy enough to map into a set of LumpedElements between the pins. It's at this point that being able to parse the LTSpice models would be useful to pull out the modelled capacitance etc.
 
  • Like
Reactions: exlabs
NIck, very nice. I am still trying to figure out the full pipeline. So you output a Kicad board file to pcb-modelgen that produced an XML representation for use by CSXCAD as input geometry to openEMS. Any other comment on the overall process? Did you get the Sm to run finally? I was looking to use this approach and wondering what the pitfalls were.
 
Hi, yes life got in the way on this unfortunately. I got to the point above but switched jobs and everything took a backseat.

Key thing is getting the port aligned with the right part of the PCB meshes. The pit fall is the slow rate of computation given the mesh but if that can be simplified then naturally it'll speed up.
 
  • Like
Reactions: exlabs