Here we are again, trying to build a bridge to one of the sole open-source Electromagnetic (EM) solvers out there. I’m going to put a spoiler here. There is a reason these things cost money. A lot of money. The reason is that in order to build a reliable, efficient and user-friendly platform, you need to put in a lot of time and other resources, all of which cost money.
That being said, trying to build something abstract as a bridge that will take a layout, place some ports in it and actually produce usable results, is bound for trouble. I presented one such trouble in the previous post, in the form of problems importing a structure from KiCAD into a different CAD environment. I’ll present a few more problems I’ve gone through here, just so you will see the issues that come up while building even roughly made pieces of software.
The first issue is simplification of the model. This is one of these “tricks of the trade” you learn over time. Let’s explain the problem, shall we?
Model Simplification
It is well known that (most) EM solvers discretize the problem, namely, dividing it into little bits. Time Domain (TD) solvers, be it Finite Integration Technique (FIT, used in CST, for example) or Finite Difference Time Domain (FDTD) method, divide the problem into boxes, as can be seen here:

This type of subdivision is usually referred to as meshing and the set of divisions is referred to as mesh. These rectangular boxes are a type of structured mesh. Meaning the sub-division can’t snap to any type of structure, but can only accurately depict, well, rectangular structures. This, of course, is one of the flaws of TD solvers. A common approach to handle this flaw, is the Perfect Boundary Approximation (PBA), or it’s younger sister, Fast PBA (FPBA).
So naturally, complex structures, e.g. rounded corners, result in an excess of mesh cells that can either slow down your solver significantly, or kill it altogether. It also requires more memory and other computational resources.

So it may come in handy to have an interface that can take out these KiCAD “corner smoothing” results

and straighten them up. For that extent and purpose, I wrote an interface, demonstrated in this video here:
Ok, so I have simple enough structure. Now I need to connect the ports to it.
Port Placement
I’m a CST disciple, myself. So for me, simple port placement is a must. I’m not saying that what I did is even close to adequate, but everything beats writing it by code, individually.
This took quite a while to program, but was very straight forward. The following and hopefully final issue, is the meshing.
Mesh Generation
So the OpenEMS developers were kind enough to supply some basic meshing functions. The first would be DetectEdges. Simple enough, every polygon in the structure has corners. Put them in a list and let’s go, right?

The next function supplied is SmoothMesh, that (hopefully) generates a nice enough mesh. Running it for the first time all but rendered my computer useless. It ran for half an hour before I crashed the program. So a more careful approach is required. Digging a bit into the SDK revealed that there is a function available called AutoSmoothMeshLines, which does the same operation, but per-axis. Still no luck. So what I discovered is that I need to take only small parts of the mesh existing crude, with wide enough gaps between them and run AutoSmoothMeshLines there.

I’m neglecting here, of course, a lot of the problems I found along the way, but this is a post. Not a recap of the last week.
So theoretically, we are ready to simulate, right?
Running The First Simulation
After some setting up and additional trouble meshing the added air box, we are ready to go!

Well, here is a problem. See these small mesh lines?

They force the solver to choose really small time steps. In the order of . This can take a long time to run and needs a solution.
There are two ways to approach this now:
- Modifying your model to fit the mesh.
- Modifying the meshing scheme.
Option #1 is a bad idea and generally not what we convened here for. Option #2 requires us to pray that the developer implemented some sort of PBA into this solver. I don’t pray a lot, but let’s go with #2.
Before proceeding, I checked that I can simulate a simpler structure, with only one layer and no vias:

And what do you know, it works and I got the following return loss graph:

It also took only about a minute and a half to run! Darn impressive for an imported design.
So in order to accomodate for this issue of the small steps, I am suggesting to force the mesh cells around a given small mesh cell to withstand a given threshold, and viola.

Running this took 6.5 minutes. Hoozah!

Well, it seems I need to make this antenna a bit longer.
Current Impressions
Well, this is definitely not going to win a beauty contest any time soon, for starters. Is this a good solver? Well, it produces pretty results, pending verification. More than anything I every did, that’s for sure. Is it fast? More than I expected. Accuracy? I sure hope so, Boss!
Well, the first step I need to take is to try and compare these results to a known simulation software. This is critical for me to move forward. Given that this requires me to own said software, let’s set my goals a little lower, shall we?
The important question here is robustness. I want to know that I can run a structure here that I designed in KiCAD or found on the web, without 2 hours of pre and post-processing. For this extent and purpose, I am actually doing pretty well. The run time numbers are definitely not in the scale of multiple hours, which is great.
So what did I earn from this? It was a nice learning experience. It was also a nice recollection of what it means to program hours a day, even if it’s m-scripts and not a real language. Everybody knows real men use Fortran.
What’s Next?
Well, the meshing still needs a lot of work. The result is still not nearly as smooth as it should be. This can impede the simulation results, significantly. I also need to somehow include “interesting regions”. For example, around the ports the mesh should be tight.
I have some work incorporating additional features, such as thick conducting metals and some sort of scheme dealing with thin materials. I also want to add a feature that defines a material name per layer, to make the pictures a little more pretty. Maybe even per-polygon, even though that’s a bit of a reach…
I’ll be uploading my codes to my GitHub. I think I’m only going to add to this according to necessity. After verifying my designs by simulating them in more official simulation software, I’ll move on to manufacturing my and measuring. It’s time to build a portfolio in my actual area of expertise. Don’t you think?