-
-
May 1, 2023 at 7:57 pm
Nirvan Gajadharsingh
SubscriberI 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:
x1=26e06;
x2=-26e-06;
z1=5e-6;
z2=0e-6;
selectmode(1);
setanalysis("integration shape","rectangular");
setanalysis("z1",z1);setanalysis("z2",z2);
setanalysis("x1",x1);setanalysis("x2",x2);
area=getanalysis("fraction integrated");
?area;
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?
Thanks
-
May 2, 2023 at 8:52 pm
Guilin Sun
Ansys EmployeeI 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:
https://optics.ansys.com/hc/en-us/articles/360034405814-integrate-Script-command
-
May 3, 2023 at 1:16 am
Nirvan Gajadharsingh
SubscriberHello,
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?
-
May 3, 2023 at 3:43 pm
Guilin Sun
Ansys EmployeePlease 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
Ex0=Ex(:,:,find(z,z0),1)
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
Ex0=Ex(:,:,find(z,z0):find(z,z0+1e-6),1)
It would be much simpler to specify the region in the GUI using script as you did.
-
May 3, 2023 at 7:18 pm
Nirvan Gajadharsingh
SubscriberThanks 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
-
May 3, 2023 at 9:12 pm
Guilin Sun
Ansys EmployeeAs 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: https://optics.ansys.com/hc/en-us/articles/360034925893-interp-Script-command
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.
-
- You must be logged in to reply to this topic.

Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Why am I getting “process exited without calling finalize”, and how do I fix it?
- “Import optical generation” or “delta generation rate”?
- Error: addfdtd is not a valid function or a variable name
- Error on Lumerical device
- Using a license file on a new license server
- Ansys Insight: Transmission results greater than one
- Ansys Insight: Diverging Simulations
- Finding your Ansys (or Lumerical) account number
- Ansys Insight: Why my simulation result is different from published paper or experiment?
- Is there a Lumerical script command to output the Simulation and Memory requirements?
-
5402
-
3377
-
2471
-
1310
-
1022
© 2023 Copyright ANSYS, Inc. All rights reserved.