## Photonics

#### Can anyone explain this matrix components for current density?

• Mariah Ha
Subscriber

Hello,

Can anyone please help me explain these components of Jn current density data? I am running a transient 2D simulation in (xy) plane. The anode is positioned along z axis. What is the meaning of 7836 and 3 and 61 ? in which direction are they ?

• Khashayar Ghaffari
Ansys Employee
Hello,

In general when working with variables saved from the visualizer, it is helpful to use the “.” operator to find all the related parameters and attributes; when writing “variable+’.’” in the script prompt, the autocomplete feature will show these quantities in bold.

For example here you have probably used a command like:
```charge = getresult("CHARGE","charge");
Jn = charge.Jn;
```
To define the current density matrix.

Now by starting to write “charge.” in the script prompt you will see that t (time), and x,y,z (coordinates) are other related attributes. For example try:
```T = charge.t;
X = charge.x;
```
Using the size of these new matrices you can tell what each dimension of your original Jn matrix corresponds to.

In the case of a 2D transient simulation the three dimensions correspond to coordinates (XY), the time steps (t), and the component of the current density (x, y, or z).

Best regards
• Mariah Ha
Subscriber
Thank you for the reply. The matrix I got for Jn is [7836 , 3 , 61] so if I follow your description, the "3" should be the time steps? an "61" are all the current density values ?
• Khashayar Ghaffari
Ansys Employee
Hi Please check the number of your time steps by referring to the newly created T matrix (according to my previous response). I can't check your project but I suspect 7836 corresponds to current density values, 61 to time steps, and 3 to density component (direction).
• mmarch
Subscriber
Hi,

I had a similar question and have extracted charge.x and charge.z (I have a 2D Y-normal simulation region). Both of these have the dimensions as shown below

So for Jn I think it's like this: 133261 is the amount of nodes, 31 is the amount of voltage steps, 1 is because I only have them at one moment in time(?) and 3 because I have an x, y and z. Is this correct?
If so, how are the nodes/values structured in my X, Y or Z variable?
Best regards
• Khashayar Ghaffari
Ansys Employee
Hi,
As you suggested, the X, Y, Z matrices indicate the coordinate of the mesh points (nodes). A row number corresponds to the same point for each of them so they can determine the coordinates of a reported result, here current density.
Best regards
• mmarch
Subscriber
Hi,

Thanks for quick response. So how do I know where the origin is?
And since I have just column vectors with size 133261, how do I know how many nodes there are every direction in my structure? For example say the x direction is horizontal here. If the most left node at a fixed z and y coordinate is x=0 then what is the x coordinate of the most right node?

• Khashayar Ghaffari
Ansys Employee
Hi,
You would have the same number of nodes in all directions. So here you have 133261 nodes, meaning there will be 133261 coordinates for x, y, and z.
If the left most node is x = 0, the most right one will be equal to width of the simulation region in x direction. You can also use the min and max commands (and apply them to x,y, and z) to find how much your nodes span in each direction.
Best
• Mariah Ha
Subscriber
Hello,
The answers are still not clear . I am trying to plot J vs x , because having a vector J [133261,3,1] is not meaningful and we can not extract useful knowledge from such vector in the way it looks .
Please help me plot J vs x , what lines should I write exactly because what I wrote did not give me the wanted curve.
• mmarch
Subscriber
Hi mariah
I had the same question/problem. I think that it is probably easier if your try to process the data and make your plots in Matlab or Python. I use Matlab to interpolate the data, creating a grid with in each node the interpolated value of J. Once you have this you can simply plot J versus x or z. Here's a snippet of the code I use to do this:
[xq,yq] is the grid I want to have my interpolated J values in
x and z are the vectors I obtained from Lumerical
each column of Jn_ contains the values of Jn in each node for one voltage step,
and here is the explanation of the griddata function: https://www.mathworks.com/help/matlab/ref/griddata.html

• Mariah Ha
Subscriber
Hi mmarch ,
Thank you very much .This is what I am looking for. However, just one more thing, this gives me the current density in a 3d plot although I am looking for a 2D plot where J is in the vertica laxis and x is in the horizontal axis . I tried with "plot" in MATLAB but did not work. Can you help ?
Regards.
• Mariah Ha
Subscriber
Hi mmarch,
Can you please explain why you multiply by e-5 in the meshgrid ? If the structure is for example from "-2.5 microns " to "2.5 microns " in Lumercical, then may be we should multiply by e-6 to get meter right ? Please correct me if I am wrong.
• mmarch
Subscriber
So the result of the interpolation gives you a matrix with the value of Jn in each point of the grid. If you now only want to get the current density as a function of x you just need to take only a single column/row (whichever represents the change of x values) and plot this vector against the x coordinate of your mesh grid.

And yes, you are correct, you should use 1e-6 to have the coordinates in m
• Khashayar Ghaffari
Ansys Employee
Thank you for commenting this. Please let me know if you have further questions.
Best regards
• Mariah Ha
Subscriber
Thank you all for your assistance and answers. So the only way to plot Jn vs x is by postrocessing it with meshgrid in Matlab? Can Lumerical provide a monitor for J similar to the electric field monitor for more simplicity, in the future ? I am now able to plot Jn vs x in matlab but the meshing step is tricky because you can end up taking more mesh nodes than the initial vector coming from lumerical , you can also end up using a finer mesh on y and wider on x , and this affects the accuracy of the graph .