Topics related to Lumerical and more

issues with array splicing and power calculation in MODE

    • Nirvan Gajadharsingh

      I have calculated the poynting vector for my simulation and stored its magnitude in an array called S.

      S has dimensions (2081,361) and my simulation domain extends from -26um to 26um in the horizontal and 5um to -4um in the vertical. 

      I use the following script to get the normalized power in the region bounded from 5um to 0um and -26 to 26um:






      setanalysis("integration shape","rectangular");



      area=getanalysis("fraction integrated");


      BUT, if I were to splice the array 'S' as x = S(:,1:201) where 1 is the row index corresponding to 5um and 201 is the index corresponding 0um in my simulation domain and then I perform a sum(x)/sum(S) I get an incorrect answer to what is given in the script above.

      However if I splice the array 'S' as x = S(:,161:361) and then take the sum(x)/sum(S), I get the correct value given by the script above. I do not understand why this gives the correct result because this captures the array values which are beneath the region I specified in the script, why in a manual calculation using array splicing I need to specify indices which do not belong to the region 5um to 0um vertical, but instead specify 0 to -4um vertical. A pic of S is shown below.


      Also, if I use GUI power integration, it gives correct answer as script:

      what am I not understanding about splicing in lumerical, or what am I not understanding about the built in 'fraction integrated' function? 


    • Guilin Sun
      Ansys Employee

      I guess it is not because of the splicing.Instead, it is due to the mesh which might not be uniform. The internal calculation has considered the non-uniform mesh. But your script does not since you simply sum them up. I would suggest to use integrate:

    • Nirvan Gajadharsingh



      thanks for that quick response. To be honest I did not think that would have been an issue because I thought that if the mesh is non uniform the arrays captured as ExEyEzHxHyHz would be interpolated, so that the data set captured from lumerical varies across the simulation domain in a linear uniform manner so that I could correlate index position of the array to spatial position within my simulation domain.

      How can I relate the index positions in the array to the spatial positions of sim domain? Is there any way to do this in lumerical mode? 


    • Guilin Sun
      Ansys Employee

      Please note that the result is not interpolated into uniform mesh by the product.

      you can use "find". For example, you want to find a slice z=z0, you can use


      where Ex is a 4D matrix in xyz and f. Some of them are singleton. the above method uses the single frequency result.

      you can also specify a small length, eg


      It would be much simpler to specify the region in the GUI using script as you did.


    • Nirvan Gajadharsingh

      Thanks for your reply,

      I can see how using the find command you specified above links the  index position of a value in the matrix to the value at that position. But I can't see how that will be useful if I have a non linear mesh. I have an array Ex, Ex is in x-z plane of size (2081,361) , I want to be able to take all the elements of Ex and generate 2 new arrays called X and Z which gives the cartesian cordinate(Xum,Zum) of every value in Ex. Assuming a linear, uniform mapping, I can just generate arrays X and Z of size linspace(26,-26,2081) and linspace(5,-4,361) respectively.

      This is inaccurate because of the non-uniform meshing, how can I build those X and Z arrays containing the x and z position of the values of the Ex array which considers that the meshing is non uniform. Basically I want to get the mesh points overlayed over the simulation domain


    • Guilin Sun
      Ansys Employee

      As I suggested, the raw data is from the non-iniform mesh. In order to build a linear mesh, you will need to interpolate the date:

      I would suggest to first resolve the issues that the result is different from the GUI and script. Once it works, please write a new post for any other questions, as the forum is to have one question one solution.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.