Amrita Pati
Ansys Employee

Hello Peng,

A few things to note here:

1. The mode expansion monitor provides a number of expansion results including T_backward. T_backward is the backward (the direction of the negative coordinate axis) transmission into the selected modal field(s). As it is in the negative direction, there is a negative sign by default. If you just want the portion of power and are not concerned about the direction then you can use – sign at the front of the T_backward result and it will give you the corresponding positive values as has been done in the original script. In the code I sent it can be done by modifying the last line as follows:

sweep_result = struct;
sweep_result.Name = “fom”;
sweep_result.Result = “::model::fom_exp::expansion for fom”;
addsweepresult(“sweep source position”,sweep_result);
runsweep(“sweep source position”);
result = getsweepresult(“sweep source position”,”fom”);
T = -result.T_backward;

The code above will give the same result as the code in the original file on the website.

For more information on Mode Expansion Monitors and the various results it calculates, please refer to the following links:

Monitors – Mode Expansion – Results & Applications
Monitors – Mode Expansion – Setup & Tips
Mode expansion monitor – Simulation object
Using and understanding Mode Expansion Monitors 

2. You can not use the following code:
i. result_1 = struct;
ii. result_1.Name = “T”;
iii. temp = “::model::fom_exp::expansion for fom”;
iv. result_1.Result = -temp_backward;
v. addsweepresult(“sweep source position”, result_1);

I assume you wanted Line iv. to be iv. result_1.Result = -temp.T_backward;  As temp_backward variable is never used before in your code and as a result you get the error. However, even making the above code change would result in an error. Since in addsweepresult you can only add the monitor results that are available, which include the following:

For including any other result you have to output this result from the model (or Structure/Analysis group) like it was done in the original file in the Analysis-Variables Tab of model:

If you want to do it in .lsf file and not use the model, I would suggest you to record the complete set of results from “expansion for fom” and access the T_backward result with the negative sign using the code I have provided. Hope that helps.