Calling user defined Matlab function from Lumerical File Editor

Hello,
I have a user-defined Matlab function which I want to call from Lumerical Script Editor and return its arguments to the Lumerical Script Workspace (for the future use).
Attached is the simple example function.
addsub.m (72 Bytes)

If i call that function by matlab(“addsub(20,15)”); command, i see following result in Script Prompt:
ans =

struct with fields:

sum: 35
sub: 5

But I do not know how to access these results.

On the other hand, the following code (copied) works well (what I want in my user-defined Matlab function).
matlab("

% create a logspaced vector

x_min = 1

x_max = 10

output.x = logspace(x_min,x_max,10)

");

matlabget(output);

Any help/lead would be highly appreciated.

Regards,

Hello @twayana,

I am not sure exactly what you are hoping to do, but it seems that you have your MATLAB integration status active if the later code block runs succesfully. The following syntax should work for you please give it a try.

> matlab("ouput = addsub(20,15)");
> matlabget(output);
>?output.sum;
> 35
>?output.sub;
> 5

Here is some further information on struct datatypes. It might be easier to write user defined functions in the Lumerical scripting language?

> function sum(a,b){
>     tmp = a+b;
>     return tmp;
> }
> 
> function sub(a,b){
>     tmp = a-b;
>     return tmp;
> }

Let me know if you have any other questions.

Regards,
Taylor

Dear @trobertson,
Great!!! That was what i wanted to do for now.
Thank you for supplement information.
In the end, i want complex refractive index calculation from ellipsometer parameters at desire wavelength (for that I have a code in Matlab: “epsilon contribution from a pole and Gaussian oscillator”) and define it in “Material Database List” for my structure from “Script File Editor”.
i would be grateful if you post links or some information regarding how to define complex refractive index
in “Material Database List” from “Script File Editor”.

Best Regards,

Hey @twayana,

Extracting n, and k information from ellipsometry measurements is not trivial and requires some assumptions. I believe the MATLAB code that you referenced performs this analysis? I will just post this in case you want some further information.

Once you have the material data it is very straightforward to define a custom material in Lumerical using sampled data points.

Dear @trobertson,
we model the dielectric function as a summation of Gaussian oscillator functions from the modeling parameter that we have received from J.A: Woollam Co. for our SiN recipe.
I was wondering if there is a way to define custom material from “Script File Editor”. I am asking this because I want to calculate optical properties at the exact wavelengths where I have dielectric constant from the Gaussian model.
If I can define custom material from “Script File Editor”, I can explicitly force to calculate optical properties at the desired wavelength at dielectric constant calculated from the Gaussian model.

Simply, I want to calculate optical properties at the wavelength (wavelength might be different at a different simulation run.) at which dielectric constant is calculated from the Gaussian model every time that I run the simulation.

Best Regards,
Krishna

Hello @twayana,

There is certainly a way of changing the material properties using the script editor. You should save your calculated material data as a .txt, .ldf or .mat file. This can imported into the script workspace . From there you could use the data to force the source center frequency, and material parameters to align with your measurements. For example, if you had a text file with three columns separated by spaces [ wavelength n k] your code might look like.

> # Read data
> Mat_Data=readdata('mat_data.txt');
> 
> # Update source
> select('source');
> set('center wavelength',Mat_Data(1,1));
> 
> #Update film
> select('film');
> n =M(1,2)+ i*M(1,3);
> set('index', n);

In this way you could loop through the rows of your data and simulate for each wavelength. However, I would recommend leveraging the fact the FDTD is naturally a broadband technique and run a single simulation. To do this simply define a custom material model using your data. Then adjust the material fit parameters to get a fit with small RMS, and run the simulation. Even if you are only interested in the results at a few discrete wavelengths this technique will be much more efficient.

-Regards

Dear @trobertson,
Thank you very much.
It was nice talking to you.
Best Regards,
Krishna

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.