TAGGED: lumerical, material, python, python-scripting
-
-
August 9, 2021 at 6:09 pm
geopsar
SubscriberI'm trying to add a new material to Lumerical using Python but I'm not sure how to do this. The txt file that I have contains a 3D sampled material, so it has the wavelength and the Re and Im permittivities in x, y, z. This is what I tried to do but it doesn't work.
newmaterial = fdtd.readdata("WS2 Bulk Dielectric Constant.txt")
mymaterial = fdtd.addmaterial("3D Material data")
  fdtd.setmaterial(mymaterial,"name","WS2 (tungsten disulfide")
  fdtd.setmaterial("WS2 (tungsten disulfide)","Import data",newmaterial)
Any help would be appreciated.
August 13, 2021 at 1:06 amTaylor Robertson
Ansys Employee
Could you share the traceback from this? The error message will be helpful for debugging. I suspect that the sampled data matrix may not in the correct form.
Probably this line.
mymaterial = fdtd.addmaterial("3D Material data")

It may be better pass a python dictionary = struct with the values defined in Python rather than reading into Lumerical -> Passing to Python -> and then Passing it back to Lumerical.
sampledData = [f,eps]; # collect f and eps in one matrix
# create a material
setmaterial(addmaterial("Sampled 3D data"), "name", "mymaterial");
setmaterial("mymaterial","sampled data",sampledData); # load the sampled data matrix
You could try debugging in Lumerical script workspace. If nothing else works I would suggest using fdtd.eval(" ... ") on the lsf code that works.
August 14, 2021 at 3:06 pmgeopsar
SubscriberThank you for your reply. I've tried to change my code according to your answer and it looks something like this now
fdtd.addcircle fdtd.set("name","Nanoantenna")
fdtd.set("x",0.0)
fdtd.set("y",0.0)
fdtd.set("z",0.0)
fdtd.set("radius",R)
fdtd.set("z span",100e-9)
data = np.loadtxt('WS2 Bulk Dielectric Constant(1).txt')
lam = data[:,0]
repsx = data[:,1]
iepsx = data[:,2]
repsy = data[:,3]
iepsy = data[:,4]
repsz = data[:,5]
iepsz = data[:,6]
epsx = repsx + 1j*iepsx
epsy = repsy + 1j*iepsy
epsz = repsz + 1j*iepsz
eps = epsx + epsy + epsz
sampledData = [lam,eps]
fdtd.setmaterial(fdtd.addmaterial("Sampled 3D data"),"name","WS2 (tungsten disulfide)")
fdtd.setmaterial("WS2 (tungsten disulfide)","Sampled 3D data",sampledData)
but I still get the following error in Python
LumApiError: "argument list for setmaterial command is incorrect - setmaterial arguments were converted to ('str, 'str, cell array)"
which corresponds to this warning on Lumerical
Warning: prompt line 3: The material type 'sampled 3d data' is now called 'Sampled 3D data'.
I'm not sure why I'm getting such an error since I am using 'Sampled 3D data.'
August 20, 2021 at 9:34 pmKyle
Ansys Employee
As indicated by the LumApiError message, your sampledData Python list is being converted to a cell array. However, the Lumerical command requires a matrix, not a cell array. Numpy arrays are converted to Lumerical matrices, so the sampledData list needs to be converted to a Numpy array before it is used in the setmaterial method.
The Python data types and their Lumerical equivalents are given on this page:
October 13, 2022 at 11:35 amSaeid AsgarnezhadZorgabad
SubscriberSorry but I don't understand what you are saying Kyle.
Let me show you my code. First I have made a matrix:
M_data=np.array([f,eps])
Then I set the name as:
Mat_Name='Quantum dot'
Then I have added these lines:
temp=fdtd.addmaterial('Sampled data')Â Â Â Â
fdtd.setmaterial(temp,'name',Mat_Name)
fdtd.setmaterial(Mat_Name,'max coefficients',2)
fdtd.setmaterial(Mat_Name,'sampled data',M_data)and I get this error: "the number of columns for the data in 'sampled 3d data' should be either 2 or 4"
Indeed the shape of M_data is (2,3000) and has 2 columns. So I am not sure what the error is. Can you be more specific and kindly correct my code instead of "explaining"?
Â
Â
Â
May 29, 2023 at 9:01 pmmustafa
SubscriberOn a related note, would anyone know why changing the material color cannot be done from the python API? I'm getting an error for the following command:
fdtd.setmaterial(matname, "color",[0.5, 0.5, 0.5, 1])
Viewing 5 reply threads- The topic ‘Adding new material to lumerical via Python’ is closed to new replies.
Innovation SpaceTrending discussionsTop Contributors-
5834
-
1906
-
1420
-
1305
-
1021
Top Rated Tags© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-