General > General Technical Chat
[WIP] 2D MoM field solver (TNT-MMTL) in the Web browser with WebAssembly
niconiconi:
Note to mods: Do not move this thread. This project is an unreleased, work-in-progress project in the extremely early stage with nothing to show so far, its completion is not even guaranteed. So it's only a "Technical Chat", not a "Project".
Currently, most free and open source PCB transmission line impedance calculators are based on hardcoded, closed-form formulas. The most popular calculator is TransCalc [1]. It's currently included in both KiCad and Qucs, but began as a standalone project. This has the advantage of simplicity and accuracy - you can't be wrong with test-and-proven formulas that give you the standard result. But with some important limitations, such as the inability to solve transmission lines with multiple different dielectric layers.
Fortunately, we do have something more powerful, such as ATLC [2] and TNT-MMTL [3]. The subject of this post is TNT-MMTL. It's a 2D electromagnetic field solver that solves transmission lines with an arbitrary circuit board layer stackup using the Boundary Element Method (a.k.a. Method of Moments) according to the laws of electrostatics. It was developed by Mayo Clinic's Special Purpose Processor Development Group (SPPDG) from the 1980s to the 1990s. In the early 2000s, it was released as free software under the GPLv2+ license. Development was then discontinued, and the project fell into obscurity and is mostly forgotten.
Today, the upstream code doesn't even compile anymore, unless you're a Unixhead who knows where to look (NetBSD's software repository has some patches). The engine is also far from perfect [4]. But in spite of these flaws, it's still a powerful tool in the free and open source world. At least for the simple cases I've tried - microstrip with solder mask coating - the results are comparable to Si9000.
Recently, I was thinking about things I can do to revive its ancient but still useful code. And I realized the answer is obvious: WebAssembly. WebAssembly is a technology that allows one to execute portable binary code in a Web browser via a virtual machine sandbox with a hypothetical CPU and its own instruction set. For old-timers, it's basically a Pascal p-code machine.
Moreover, recent versions of LLVM compiler allows one to cross-compile code directly to WebAssembly, as if it's just another CPU. Furthermore, the project emscripten provides a "mockup" C standard library that allows many C/C++ programs to run directly without modifications. It has already been well-demonstrated that programs as complex as the original Doom game, 3D CAD, or x86 emulator with pre-installed Linux or Windows 95, or an entire FPGA place-and-route engine [5] can be ported to the Web browser in WebAssembly. In many cases, there's "only" a 2x performance hit compared to native code - which is often good enough.
This technology is not without its critics - if JavaScript spyware is not good enough for you, now you can even make them in WebAssembly! It also allows proprietary software vendors to strengthen their "everything is a cloud Web app" strategy to increase their monopolistic power and control over the users. Others may say it encourages developers to put more inefficient bloatware in the Web browser.
I'm sympathetic with these views. However, I also believe the technology itself can be used for good.
A PCB impedance calculator that runs directly in a Web page without the need to download install anything sounds like a perfect candidate. Right now I'm working on project to port the TNT-MMTL to the Web browser with the power of WebAssembly. Now I've managed to reimplement its graphical user interface, "TNT", in JavaScript. The underlying MMTL-BEM engine is also running flawlessly.
To me, it's a technical marvell - the MMTL-BEM code is written in C++, but the linear algebra kernel was written in FORTRAN, some code was copied directly from the original LINPACK from 1978 written by Jack Dongarra himself! But I was able to compile the FORTRAN code directly to WebAssembly as well, without any modification!
The next step of the project is:
1. Keep reimplementing the TNT GUI in JavaScript.
2. Add parametric sweep.
3. TNT-MMTL requires users to model each layer of the PCB manually. The next step is writing a GUI that works at a level higher than TNT, instead of modeling each layer of the board, it would generate the stackup automatically based on the type of transmission lines and its parameters, in Si8000/Si9000 style. My hope is to create the ultimate PCB impedance calculator on the Web.
[1] https://transcalc.sourceforge.net/
[2] https://atlc.sourceforge.net/
[3] https://mmtl.sourceforge.net/
[4] Lossy line is not supported, and occasionally, some inputs can generate ill-formed matrices that can't be solved.
[5] https://github.com/YoWASP/nextpnr
WatchfulEye:
What a great project. I'd heard of web assembly, but never really explored it as I don't really know anything about modern web development.
As it is, I've just developed my own 2D field solver, including coding a special linear algebra solver for the specific matrix structure. I've no experience with numerical methods, so I just coded some algorithms from wikipedia, but the resulting code does seem to work faster than atlc. My C# development code takes around 6 seconds to solve a 1280x720 mesh, although a C++ version will do it in about 3.
I have no engineering background, so I developed the solution method from basic principles. The code solves the boundary integral form of Gauss's law on a discrete mesh (I'm guessing that this is what is called the boundary element method).
The code is a total mess at the moment, as it is really just a proof of concept - but I'd been meaning to clean it up and opensource it as a cross-platform C++ command line program. I've also been wasting time with exploring the visualisation aspects.
If you are interested in an alternative solver engine, then I might just have a viable one.
niconiconi:
--- Quote from: WatchfulEye on March 10, 2023, 06:54:09 pm ---What a great project. I'd heard of web assembly, but never really explored it as I don't really know anything about modern web development.
--- End quote ---
I, too, is not a Web developer, since I'm not really interested in Web development (I have a blog in HTML5 but that's all). The power of WebAssembly is impressive enough to motivate me to take a serious look at it. I have exactly one week of experience with JavaScript, learned during the development of this project... Guided by my rough impression of what you can do on the modern Web - I follow the news occasionally - combined it with my per-existing specialty of tinkering with Unix/Linux systems to cross-compile the code to WebAssembly - It turned out to be sufficient to get a working prototype.
My current code quality is poor, but it's just a prototype and can be progressively rewritten if I found the project is worth perusing.
--- Quote from: WatchfulEye on March 10, 2023, 06:54:09 pm ---As it is, I've just developed my own 2D field solver, including coding a special linear algebra solver for the specific matrix structure. I've no experience with numerical methods, so I just coded some algorithms from wikipedia, but the resulting code does seem to work faster than atlc. My C# development code takes around 6 seconds to solve a 1280x720 mesh, although a C++ version will do it in about 3.
--- End quote ---
Interesting. I also know that there's another project called "ATLC2". It's an independent rewrite of ATLC with improvements. Although it's planned, but so far the code is still not released under a open source license, unlike the original ATLC.
Is it your project?
niconiconi:
Here's the latest demo:
WatchfulEye:
No ATLC2 isn't mine. Mine is a lot simpler, and it's a static solver, so doesn't take into account skin effect, mainly because I couldn't think of a sensible way to solve for this without some questionable assumptions, and for what I wanted, I wasn't convinced it was going to be significant.
The demo looked impressive and nice to use. I'm really impressed.
Navigation
[0] Message Index
[#] Next page
Go to full version