Hi
I’m using DEVICE to calculate and visualize the electric field of the structures I’m interested in. Is there a way to calculate/plot the gradient of the electric field in Lumerical?
Hi
I’m using DEVICE to calculate and visualize the electric field of the structures I’m interested in. Is there a way to calculate/plot the gradient of the electric field in Lumerical?
Hi. There is no built-in option in DEVICE that will allow the calculation of the gradient of electric field. However, once you have the simulation results, you can do post processing to calculate any secondary quantity you want using the script. Since the DEVICE results are saved on a finite element grid, you will first have to interpolate this data (electric field) onto a rectilinear grid. See this KX post for more information on that: Interpolate finite element data onto a rectilinear grid. Once you have the data on rectilinear grid, you can easily calculate the derivative.
*Note that since the electric field data has three components Ex, Ey, Ez, you will have to interpolate them separately.
I’m trying to follow your advice on interpolating the data from the electric field. I don’t have much experience with the scripting and I am not really sure what I’m doing. Could you please have a look at this script and point out my mistakes?
electrostatics = getresult(‘CHARGE’,‘electrostatics’);
Ex = pinch(electrostatics.Ex);
Ey = pinch(electrostatics.Ey);
Ez = pinch(electrostatics.Ez);
x = pinch(electrostatics.x); # x coordinates
y = pinch(electrostatics.y); # y coordinates
z = pinch(electrostatics.z); # z coordinates
vtx = [x,y,z];
elements = electrostatics.elements; # connectivity matrix
kern = size(Ex);
Ne = kern(1); # Number of elements
Nv = kern(2); # Number of bias points
xmin = -1.3e-6;
xmax = 1.3e-6;
xstep = .001e-6;
xrect = xmin:xstep:xmax;
ymin = -.3e-6;
ymax = .3e-6;
ystep = .001e-6;
yrect = ymin:ystep:ymax;
zmin = -0.1e-6;
zmax = 0.9e-6;
zstep = .001e-6;
zrect = zmin:zstep:zmax;
Ex = Ex(1:Ne,Nv);
Ey = Ey(1:Ne,Nv);
Ez = Ez(1:Ne,Nv);
Ex_rect = interptet(elements,vtx,Ex,xrect,yrect,zrect); # interpolating Ex
Ey_rect = interptet(elements,vtx,Ey,xrect,yrect,zrect); # interpolating Ey
Ez_rect = interptet(elements,vtx,Ez,xrect,yrect,zrect); # interpolating Ez
You’ve done a great job with the script. There are no issues with the commands. There are however two suggestions that I would like to share to help make it run more easily,
The resolution in your rectangular grid is very small (0.001 micron). You will end up with a very large 3D matrix with this setting and that will require a huge memory and very long time to calculate the whole interpolation. Use a step size of 0.01 micron instead and it would work much better.
In the “interptet” command, I always recommend using a zero in the last optional entry. This will set a value of zero to any data point that falls out of the span of the original data. Otherwise the solver assign an INF value by default. So the last three lines would be
Ex_rect = interptet(elements,vtx,Ex,xrect,yrect,zrect,0); # interpolating Ex
Ey_rect = interptet(elements,vtx,Ey,xrect,yrect,zrect,0); # interpolating Ey
Ez_rect = interptet(elements,vtx,Ez,xrect,yrect,zrect,0); # interpolating Ez
These two modifications should be enough to get the code working!!
Thanks for the feedback! The code is working, but now I’m struggling to calculate and plot the gradient of the electric field, and not mess up any of the underlying physics while doing this.
Should I export the data to Matlab or can I do this in Lumerical?
Which commands should I use to get the derivative? Should I calculate the derivative for each component of the electric field first and add the components afterwards? And how would I plot the obtained gradient?
I can’t find much help on the Knowledge Base/Exchange so any help would be much appreciated.
I am guessing that you will define the gradient of electric field in the following way,
If this is what you are looking for and you already have Ex, Ey, Ez from interpolation then all you need to calculate is the derivative of Ex, Ey, and Ez w.r.t. x, y, and z, respectively. You can definitely do this from Lumerical’s scripting environment. Unfortunately there is no equivalent command to Matlab’s “diff” in Lumerical so you will have to calculate the derivatives manually.
I’m trying to make sure that the interpolated data I get from Lumerical give me the exact same results in Matlab. At the moment they don’t quite look the same.
I’ve included the script I’m using in Lumerical and the one I’m using in Matlab. I use the x,y,z components of the electric field to calculate the norm E = sqrt(Ex^2 + Ey^2 + Ez^2). Then I use a slice of the matrix to get the y-view I’ve included here. Am I making any mistakes?
Interpolate.lsf (1.2 KB)
gradientscript3.m (771 Bytes)
To give some more information: depending on the step size I use in Lumerical, the images I get in Matlab change. This is a 5nm step size and for some reason it seems like a lot of regions get assigned 0 (which according to your previous post means that the data points fell out of the original span)
Hi. My guess is that this is probably due to the resolution in your interpolation. If your mesh in DEVICE is too small in certain regions, it gets very hard to interpolate the data properly in those regions since the rectilinear data will have the same resolution everywhere.
Your script to interpolate Ex, Ey, Ez and then getting E looks fine. However, you do not need to do a loop to calculate E from Ex, Ey, Ez. You can do that directly in Lumerical’s script using a single line of command. I have shown this in the following script file (Interpolate_mod.lsf (1.3 KB)) which is a modified version of you one (line 43). Once change I made to the script is that instead of reading Ex, Ey, Ez from the “electrostatics” data directly, I read E from the “electrostatics” data and then got Ex, Ey, Ez from it (lines 3-6). I am not sure if your approach (electrostatics.Ex) is compatible with all versions of DEVICE. You can use this script along with this DEVICE project file (test_interp.ldev (1.7 MB)) to reproduce the following plot. Note I have used the visualizer options to get a slice of the electric field data as discussed in this KB page (https://kb.lumerical.com/en/index.html?layout_analysis_visualizer_figures_settings.html).
Thank you again! These alterations seem to do the trick.