This topic describes how to add and edit optical material properties in CHARGE/HEAT/DGTD/FEEM using only script commands. Handling materials using script commands can be useful to completely regenerate a project from script, either for version control or to increase workflow automation. For details about optical material models see Optical Material Models
Adding a new optical material from material database
The following commands will add a new material to the objects tree in CHARGE/HEAT/DGTD/FEEM, name it, and assign optical properties to it using a material model in the optical material database.
addmaterialproperties("EM","Ag (Silver) - CRC");
Adding a new optical material property to a model material
The following commands will add a new material to the objects tree in CHARGE/HEAT/DGTD/FEEM, assign a Debye optical material model to it and set the permittivity of the model to 1.5.
Creating sampled data materials using script
Reading data from file
1. Save the experimental data as columns in a text file, as shown below and name the file usr_sampled_data.txt. The first column should contain the wavelength or frequency, and the second and third columns the corresponding real and imaginary parts of the refractive index.
400 5.57 0.387
420 5.08894 0.237724
440 4.78731 0.169323
460 4.57592 0.130235
480 4.4202 0.0933521
500 4.29748 0.0728287
520 4.19996 0.0568346
540 4.11973 0.0472312
560 4.05256 0.0362285
580 3.99543 0.027335
600 3.94724 0.0256523
620 3.90579 0.022
640 3.86838 0.0178648
660 3.83622 0.0159291
680 3.80661 0.013161
700 3.78304 0.0125603
2. Import data as a matrix, using readdata,
usrData = readdata("usr_sampled_data.txt");
3. Convert to a matrix where the first column is frequency (in Hz), and the second column is permittivity. For example, if the experimental data is given by wavelength (in nm):
freqPermData = [c/(usrData(:,1)*1e-9), mult(usrData(:,2:3), [1.0; 1.0i])^2];
Or, if the experimental data is given by frequency (in Hz),
freqPermData = [usrData(:,1), mult(usrData(:,2:3), [1.0; 1.0i])^2]
In both cases the permittivity is the refractive index squared.
Creating the optical material property
1. Create a new model material using addmodelmaterial, or select a model material in the object tree that does not have optical properties
2. Add optical properties of desired type using addemmaterialproperty
addemmaterialproperty("Sampled Data 3D");
3. Configure the new object using the frequency/permittivity data read in the previous step
set("sampled data", freqPermData);
set("frequency min", min(freqPermData(:,1))); #fitting configuration
set("frequency max", max(freqPermData(:,1)));
The last two lines are not necessary if the simulation already includes an optical source. Other fitting options, such as imaginary weight and frequency fitting range, are available.
Checking the material fit
Data imported from file should be visible in the material editor as shown below:
For automated workflows, the quality of fit in terms of RMS error can be retrieved immediately from script,
?get("standard rms error");
?get("weighted rms error");
For visual inspection of the fit, a plot of refractive index vs wavelength can be produced using getdgtdindex,
lambda = linspace(400e-9, 1000e-9, 60);
index = getdgtdindex("New Material", c/lambda, c/max(lambda), c/min(lambda));
plot(lambda*1e9, real(index), "lambda(nm)", "Re(index)");
plot(lambda*1e9, imag(index), "lambda(nm)", "Im(index)");
Similar plots and the RMS errors may also be found in the material editor, by choosing 'Go to Material Explorer', then 'Fit and plot'.
Updating the optical material property
Property sampled data of an optical material may be changed at any time while in Layout Mode, either by selecting the optical material in the Object Tree and using set, or using setnamed.
Optical material properties that are created from the optical material database may be modified at any time while in Layout Mode, the same as if the optical material were created with addemmaterialproperty. The optical material database is not affected.