matthuszagh / pyems

High-level python interface to OpenEMS with automatic mesh generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fully manual meshing & pyems equivalent to AddLumpedPort

0xCoto opened this issue · comments

Currently playing around with pyems now that things are running smoothly. The first thing I'm trying to do is migrate my Octave openEMS script (which works well and can be used as reference) to pyems.

I'm facing two main issues that I've been trying to resolve:

  1. While openEMS does not support automatic meshing at all, pyems' automatic mesh isn't ideal either (although it looks somewhat more promising). Does pyems allow you to manually feed in the mesh line positions like Octave? I.e. provide three 1D arrays (or one 3D array) to construct the mesh like that. That'd really help me experiment with some custom meshing libraries! Am I supposed to iterate the input arrays over the add_line_manual() function? I couldn't find a pyems example that relies solely on manual meshing.
  2. Regarding the port, I've been using AddLumpedPort in Octave, which works great as a simple discrete 50 Ω port. Which type of port serves as its equivalent in pyems? I played around with a couple of classes found in port.py, with little luck.

You don't need to use any of the meshing functionality provided by pyems. The csx attribute of the Simulation object is a ContinuousStructure object, which is part of the CSXCAD python API. You can use that to set whatever mesh you'd like.

There's currently no lumped port in pyems, nor is there in the openems python api. I may add this in the future, but it's not a high priority item for me at the moment. Ports are a higher-level object and you can always create them yourself from the underlying primitives.

@matthuszagh Thanks! For now, I've managed to deal with the pre-processing separately. What I'm now curious about is post-processing. Given I've run a simulation without pyems (e.g. generated the XML with Octave and got some results), is it possible to process and view the results (S11, farfield and E-field) with pyems?

My understanding is that the postprocessing utilities (print_table and Simulation.view_field) depend on the Simulation class, but is it possible for pyems to output results without it (e.g. using the generated XML file), or must everything have been generated through pyems?

The original Octave functions that take care of postprocessing is CalcNF2FF.m and ReadUI.m, so I'd be curious to know if pyems already includes some kind of implementation so I don't have to rewrite them in python.

The original Octave functions that take care of postprocessing is CalcNF2FF.m and ReadUI.m, so I'd be curious to know if pyems already includes some kind of implementation so I don't have to rewrite them in python.

Take a look at the interface provided by openems. For example, nf2ff.py and ports.py. FYI it seems I was wrong about openems not implementing lumped ports. It's in that same ports.py file.

As for print_table etc it doesn't really make sense to use pyems just for this - a lot of those data display and viewing functions are really simple and just provided as a convenience.

I would spend some time looking at the python interface provided by openems. The main benefit of pyems is meshing and higher-level objects (classes for creating pcbs, vias, etc). If all you want is lower-level access to things already in the openems api just use that. The python api gives you most (but not all) of what the matlab interface gives you. There are a few differences. IIRC Lorentz models are exposed by the matlab api but not the python api. If you find something that's missing in the python api it's probably better to just make a PR in openems adding it. Using that example, if I wanted Lorentz models I would first add support in the python openems api before integrating that capability into pyems ports, etc.