lbolla / EMpy

Electromagnetic Python
MIT License
194 stars 83 forks source link

ex_modesolver_2: coordinates rotated? #25

Closed demisjohn closed 6 years ago

demisjohn commented 6 years ago

I'm trying to use your modesolver example #2 with the "CrossSection" & "Slices" method that I like very much (ex_modesolver_2.py). Your example only plots the mode versus grid/mesh points - the spatial dimension is missing.

If I insert the variables X & Y into the contourf function, the solver.modes[0].Ex array then doesn't match the X & Y arrays, I have to use numpy.rot90() to get it to plot, indicating that the X & Y axes are flipped for some reason (and the mode shows up sideways). (Also I have to strip one point off from each X/Y array, as CrossSection.grid() is one value larger in each direction than the solver.modes[0].Ex array.)

I am thus unable to figure out which way is the expected "up/down/left/right" in this example, it doesn't seem to match the passed X & Y arrays.

Is VFDModeSolver.solve() returning the modes sideways, and missing one point in each dimension? Is it also solving them sideways?

lbolla commented 6 years ago

The mode solver uses finite-differences on a staggered grid, so E and H fields are located on different points on the grid: nodes, vertical/horizontal edges, center. That is the reason why they don't have the same dimensions. You can of course interpolate the values on any (x,y) point you need using one of the scipy's interp functions.

demisjohn commented 6 years ago

I see, that makes sense about the extra data point. Since there's no way for a user to know which coordinates to discard to match the grid to their desired coordinate space, we could have the solver interpolate to return field values at the same X/Y coordinates the user provided.

Also, what's going on with the 90° rotation?

Can you post the code you used to make the spatial field plots shown on the web page, here? I believe the code there also only plots versus grid number, not spatial dimension like the plots shown. That would probably clarify things.

Thanks!

lbolla commented 6 years ago

You can use FDMode.get_field to interpolate a mode where needed. I had to fix a bug in that function, though. Also, I've updated the example in http://lbolla.github.io/EMpy/#example_modesolver