Extracting fields as 2d arrays on rectangular grid #133
Replies: 2 comments 8 replies
-
Yay, thanks! grid_data = mode.basis.interpolator(mode.E)(array_with_coordinates) or if used more often interpolator = mode.basis.interpolator(mode.E)
grid_data_1 = interpolator(array_with_coordinates)
grid_data_2 = interpolator(array_with_other_coordinates) That should do the job :) But be aware that you take a slight hit in precision if you do this. It depends a lot on the exact problem if it's problematic. What do you plan to do with the interpolated data? Maybe there's a way how we could get it done without a rectangular grid? :) |
Beta Was this translation helpful? Give feedback.
-
Hi @HelgeGehring, thank you for the quick response! The example use case for me is performing mode decomposition for a field I got after simulating complex structures in FDTD. So, I need to re-mesh eigenmode fields to overlap with the resulting field from FDTD (or vice-versa, which is probably more complicated). It will decrease precision indeed, however we can make a denser mesh in the mode-solver. Besides this use case, I've encountered issues accessing field components (Ex/Ey/Ez) and plotting them using non-built-in functions. For instance: I do not fully comprehend those splits and re-basing in overlap calculation, but I would like to take the longitudinal component into account, as I experienced it to be crucial in some problems: basis_j_fix = basis_j.with_element(ElementVector(ElementTriP1()))
(et, et_basis), (ez, ez_basis) = basis_j.split(E_j)
E_j = basis_j_fix.project(et_basis.interpolate(et), dtype=np.cfloat)
(et_x, et_x_basis), (et_y, et_y_basis) = basis_j_fix.split(E_j)
(et, et_basis), (ez, ez_basis) = basis_j.split(H_j)
H_j = basis_j_fix.project(et_basis.interpolate(et), dtype=np.cfloat)
(ht_x, ht_x_basis), (ht_y, ht_y_basis) = basis_j_fix.split(H_j)
def overlap(w):
return cross(
np.conj(w["E_i"][0]),
np.array((ht_x_basis.interpolator(ht_x)(w.x), ht_y_basis.interpolator(ht_y)(w.x))),
) + cross(
np.array((et_x_basis.interpolator(et_x)(w.x), et_y_basis.interpolator(et_y)(w.x))),
np.conj(w["H_i"][0]),
) |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I've been playing with this nice package and need some assistance. My goal is to extract calculated modal field values and represent them as 2D arrays on a rectangular grid. This format is essential for the manipulation and analysis I need to do for my research.
I've delved into the package's source code and the scikit-fem documentation, but I'm still struggling to make it work. I grasp the concept of interpolating and re-mapping values from a triangular FEM mesh. However, the limited documentation makes it challenging to fully understand the interplay between methods related to the different bases, mesh, etc.
If anyone could offer some guidance with code snippets (which, I think, should be relatively simple for those familiar with skfem), I'd be incredibly thankful!
Beta Was this translation helpful? Give feedback.
All reactions