Photonics

Photonics

Topics related to Lumerical and more.

Import material .txt file with script

    • tim.fuhrmann
      Subscriber

      Hello,

      I want to modify my measured material parameters in order to study the effect of perturbations of my measurements on my simulation.
      To manipulate the data, I use MATLAB and save it as a .txt file. Then I want to import my data via a script from this .txt file. The .txt file is a three-column table with the first column being the wavelength, the second one is the real index, and the third one is the imaginary index. The material is not anisotropic. There is no problem at all with this type of file if I import it manually.

      If I use the following script, I only use the wavelength and Re{index} column, to import my .txt file:
      filename = "test.txt";
      sampledData = readdata(filename);
      rows = size(sampledData, 1);
      sampledData_modi = zeros(rows,2);
      sampledData_modi(:,1) = sampledData(:,1);
      sampledData_modi(:,2) = sampledData(:,2);
      test_material = addmaterial("Sampled 3D data");
      setmaterial(test_material, "name", "4 Test");
      setmaterial("4 Test", "sampled data", sampledData_modi);
      setmaterial("4 Test", "Anisotropy", 0);
      I get the correct wavelength imported as well as the correct real part of the refractive index.

      If I now add one column and populate it with the imaginary part from the .txt file:
      filename = "test.txt";
      sampledData = readdata(filename);
      rows = size(sampledData, 1);
      sampledData_modi = zeros(rows,3);
      sampledData_modi(:,1) = sampledData(:,1);
      sampledData_modi(:,2) = sampledData(:,2); 
      sampledData_modi(:,3) = sampledData(:,3);
      test_material = addmaterial("Sampled 3D data");
      setmaterial(test_material, "name", "4 Test");
      setmaterial("4 Test", "sampled data", sampledData_modi);
      setmaterial("4 Test", "Anisotropy", 0);
      I get the error: the number of columns for the data in 'sampled 3d data' should be either 2 or 4

      If I just add one column of zeros:
      filename = "test.txt";
      sampledData = readdata(filename);
      rows = size(sampledData, 1);
      sampledData_modi = zeros(rows,4);
      sampledData_modi(:,1) = sampledData(:,1);
      sampledData_modi(:,2) = sampledData(:,2);
      sampledData_modi(:,3) = sampledData(:,3);
      test_material = addmaterial("Sampled 3D data");
      setmaterial(test_material, "name", "4 Test");
      setmaterial("4 Test", "sampled data", sampledData_modi);
      setmaterial("4 Test", "Anisotropy", 0);
      The table is not properly imported.

      Is there a way so solve this issue or work around it? 

      Best regards, 
      Tim

    • Guilin Sun
      Ansys Employee

      Sorry to reply you late as something happend.

      When the material has complex refractive index or permittivity, please directly use the complex data.

      Please refer to this example: https://optics.ansys.com/hc/en-us/articles/360034409654-setmaterial-Script-command

    • tim.fuhrmann
      Subscriber

      Hello,
      Thank you for your reply. 
      I am using the complex data. However, I have the following problem, when using the setmaterial function:

      • My data has three columns: wavelength, real part of the index, and imaginary part of the index
      • setmaterial with the property name "sampled data" only takes 2 or 4 inputs.
      • If I use only two,I don't get the imaginary part, if I take 4, even though I have only 3 in my data set (I set the last column to zero), I get wrong material parameters

      Thank you for your help and best regrds,
      Tim 

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