Garchupiter / Kraken-Optical-Simulator

Python - Exact ray tracing library
GNU General Public License v3.0
53 stars 9 forks source link

extra_data Add precise Fresnel data? #12

Open xacGOOD opened 1 month ago

xacGOOD commented 1 month ago

I'm trying to do a ray simulation of a Fresnel lens using KeakenOS, using the EXTRA_DATA feature, but the ray tracing results don't meet expectations. Here's the code:

`#!/usr/bin/env python3

-- coding: utf-8 --

"""Examp Extra Shape Radial Sine""" import math

import matplotlib import pkg_resources required = {'KrakenOS'} installed = {pkg.key for pkg in pkg_resources.working_set} missing = required - installed

if missing: print("No instalado") import sys sys.path.append("../..")

import KrakenOS as Kos import numpy as np import matplotlib.pyplot as plt matplotlib.use('TkAgg')

__

P_Obj = Kos.surf() P_Obj.Rc = 0.0 P_Obj.Thickness = 10 P_Obj.Glass = "AIR" P_Obj.Diameter = 30.0 P_Obj.Drawing = 0

__

data = [] # just use to export Kraken surf data def fresnel(x,y,data): dis = np.sqrt(x2+y2) z = np.interp(x=dis,xp=data[...,0],fp=data[...,1]) global data data += np.array((dis,z)).T.tolist() # append to data return z

fresnel_data= np.loadtxt('R1064_F1800_超大菲涅尔.txt',delimiter=',') # fresnel profile data L1a = Kos.surf() L1a.Rc = 0.0 L1a.Thickness = 5.0 L1a.Glass = "PMMA" L1a.Diameter = 2128 fresnel_ES = [fresnel,fresnel_data] L1a.ExtraData = fresnel_ES

__

L1c = Kos.surf() L1c.Rc = 0.0 L1c.Thickness = 1800 # 本片的厚度,也是后面一片的起点距离 L1c.Glass = "AIR" L1c.Diameter = 2128

__

P_Ima = Kos.surf() P_Ima.Rc = 0.0 P_Ima.Thickness = 0.0 P_Ima.Glass = "AIR" P_Ima.Diameter = 200.0 P_Ima.Name = "Image plane"

__

A = [P_Obj, L1a, L1c,P_Ima] Config_1 = Kos.Setup()

__

Lens = Kos.system(A, Config_1) Rays = Kos.raykeeper(Lens)

__

Wav = 0.45 # 波长??? y = fresnel_data[...,0] y_diff = np.diff(y)/2 y[:-1] += y_diff

index = np.arange(0,y.shape[0],100) y = y[index] print(y)

for i in y: p_s = [0.0,i,0.0] d_cos = [0.0,0.0,1.0] Lens.Trace(p_s,d_cos,0.55) Rays.push()

__

data = np.unique(np.array(data),axis=0) # unique and sort np.savetxt('rz.txt',data_,fmt='%.8f',delimiter=',') # save for verify

Kos.display3d(Lens, Rays, 2) Kos.display2d(Lens, Rays, 0)

`The 2D display results are as follows:

image

The original design of the lens is as follows: image

The results of using Lighttools simulation are as follows: image

How can I use KrakenOS to accurately ray trace Extra_data custom outlines?

xacGOOD commented 1 month ago

R1064_F1800_超大菲涅尔.zip fresnel profile data is here, type is rar

xacGOOD commented 1 month ago

image

By comparing the extracted ray and the exported profile, the refractive index of the material at the inverted incidence is 1.55, which does not conform to the design. The refractive index of the material at the exit is 1.4936, which is in line with the design value, so what went wrong?

xacGOOD commented 1 month ago

Here's the latest test code: `

!/usr/bin/env python3

-- coding: utf-8 --

"""Examp Extra Shape Radial Sine""" import math

import matplotlib import pkg_resources required = {'KrakenOS'} installed = {pkg.key for pkg in pkg_resources.working_set} missing = required - installed

if missing: print("No instalado") import sys sys.path.append("../..")

import KrakenOS as Kos import numpy as np import matplotlib.pyplot as plt matplotlib.use('TkAgg')

__

P_Obj = Kos.surf() P_Obj.Rc = 0.0 P_Obj.Thickness = 10.0 P_Obj.Glass = "AIR" P_Obj.Diameter = 2128.0 P_Obj.Drawing = 0

__

data = [] # just use to export Kraken surf data def fresnel(x,y,data): dis = np.sqrt(x2+y2) z = np.interp(x=dis,xp=data[...,0],fp=data[...,1]) global data data += np.array((dis,z)).T.tolist() # append to data return z

fresnel_data= np.loadtxt('R1064_F1800_超大菲涅尔.txt',delimiter=',') # fresnel profile data L1a = Kos.surf() L1a.Rc = 0.0 L1a.Thickness = 5.0 L1a.Glass = "PMMA" L1a.Diameter = 2128.0 fresnel_ES = [fresnel,fresnel_data] L1a.ExtraData = fresnel_ES L1a.Name = 'zone side'

__

L1c = Kos.surf() L1c.Rc = 0.0 L1c.Thickness = 1800 # 本片的厚度,也是后面一片的起点距离 L1c.Glass = "AIR" L1c.Diameter = 2128.0 L1c.Name = 'plan side'

__

P_Ima = Kos.surf() P_Ima.Rc = 0.0 P_Ima.Thickness = 0.0 P_Ima.Glass = "AIR" P_Ima.Diameter = 200.0 P_Ima.Name = "Image plane"

__

A = [P_Obj, L1a, L1c,P_Ima] Config_1 = Kos.Setup()

__

Lens = Kos.system(A, Config_1) Rays = Kos.raykeeper(Lens)

Wav = 0.55 # 波长??? y = np.arange(1063,1064,0.002) np.savetxt('y.txt',y,delimiter=',')

__

for i in y: p_s = [0.0,i,0.0] d_cos = [0.0,0.0,1.0] Lens.Trace(p_s,d_cos,0.55) Rays.push()

__

print(Rays.XYZ[100]) # here is verify ray , ri shoot in material is 1.550, out from material to air is 1.4936, why?

data = np.unique(np.array(data),axis=0) # unique and sort np.savetxt('rz.txt',data_,fmt='%.8f',delimiter=',') # save for verify

Kos.display3d(Lens, Rays, 2) Kos.display2d(Lens, Rays, 0)

`

How can I customize the refractive index of a material?

xacGOOD commented 1 month ago

Here's the latest test code: `

!/usr/bin/env python3

-- coding: utf-8 --

"""Examp Extra Shape Radial Sine""" import math

import matplotlib import pkg_resources required = {'KrakenOS'} installed = {pkg.key for pkg in pkg_resources.working_set} missing = required - installed

if missing: print("No instalado") import sys sys.path.append("../..")

import KrakenOS as Kos import numpy as np import matplotlib.pyplot as plt matplotlib.use('TkAgg')

__

P_Obj = Kos.surf() P_Obj.Rc = 0.0 P_Obj.Thickness = 10.0 P_Obj.Glass = "AIR" P_Obj.Diameter = 2128.0 P_Obj.Drawing = 0

__

data = [] # just use to export Kraken surf data def fresnel(x,y,data): dis = np.sqrt(x2+y2) z = np.interp(x=dis,xp=data[...,0],fp=data[...,1]) global data data += np.array((dis,z)).T.tolist() # append to data return z

fresnel_data= np.loadtxt('R1064_F1800_超大菲涅尔.txt',delimiter=',') # fresnel profile data L1a = Kos.surf() L1a.Rc = 0.0 L1a.Thickness = 5.0 L1a.Glass = "PMMA" L1a.Diameter = 2128.0 fresnel_ES = [fresnel,fresnel_data] L1a.ExtraData = fresnel_ES L1a.Name = 'zone side'

__

L1c = Kos.surf() L1c.Rc = 0.0 L1c.Thickness = 1800 # 本片的厚度,也是后面一片的起点距离 L1c.Glass = "AIR" L1c.Diameter = 2128.0 L1c.Name = 'plan side'

__

P_Ima = Kos.surf() P_Ima.Rc = 0.0 P_Ima.Thickness = 0.0 P_Ima.Glass = "AIR" P_Ima.Diameter = 200.0 P_Ima.Name = "Image plane"

__

A = [P_Obj, L1a, L1c,P_Ima] Config_1 = Kos.Setup()

__

Lens = Kos.system(A, Config_1) Rays = Kos.raykeeper(Lens)

Wav = 0.55 # 波长??? y = np.arange(1063,1064,0.002) np.savetxt('y.txt',y,delimiter=',')

__

for i in y: p_s = [0.0,i,0.0] d_cos = [0.0,0.0,1.0] Lens.Trace(p_s,d_cos,0.55) Rays.push()

__

print(Rays.XYZ[100]) # here is verify ray , ri shoot in material is 1.550, out from material to air is 1.4936, why?

data = np.unique(np.array(data),axis=0) # unique and sort np.savetxt('rz.txt',data_,fmt='%.8f',delimiter=',') # save for verify

Kos.display3d(Lens, Rays, 2) Kos.display2d(Lens, Rays, 0)

`

How can I customize the refractive index of a material?

Garchupiter commented 2 weeks ago

Hi,

I got a bit confused with the series of questions. I understand that in the end, your only question is how to add the refractive index. I am not familiar with the glass catalog you are using for MMA, but you can add the refractive index directly. For example, L1a.Glass = "PMMA”.

For some reason, I can't run your code because my Python kernel crashes.

Best regards,
Joel H. V.

El 2 jun 2024, a las 7:06 a.m., xacGOOD @.***> escribió:

Here's the latest test code: `

!/usr/bin/env python3

-- coding: utf-8 --

"""Examp Extra Shape Radial Sine""" import math

import matplotlib import pkg_resources required = {'KrakenOS'} installed = {pkg.key for pkg in pkg_resources.working_set} missing = required - installed

if missing: print("No instalado") import sys sys.path.append("../..")

import KrakenOS as Kos import numpy as np import matplotlib.pyplot as plt matplotlib.use('TkAgg')

__#

P_Obj = Kos.surf() P_Obj.Rc = 0.0 P_Obj.Thickness = 10.0 P_Obj.Glass = "AIR" P_Obj.Diameter = 2128.0 P_Obj.Drawing = 0

__#

data = [] # just use to export Kraken surf data def fresnel(x,y,data): dis = np.sqrt(x2+y2) z = np.interp(x=dis,xp=data[...,0],fp=data[...,1]) global data data += np.array((dis,z)).T.tolist() # append to data return z

fresnel_data= np.loadtxt('R1064_F1800_超大菲涅尔.txt',delimiter=',') # fresnel profile data L1a = Kos.surf() L1a.Rc = 0.0 L1a.Thickness = 5.0 L1a.Glass = "PMMA" L1a.Diameter = 2128.0 fresnel_ES = [fresnel,fresnel_data] L1a.ExtraData = fresnel_ES L1a.Name = 'zone side'

__#

L1c = Kos.surf() L1c.Rc = 0.0 L1c.Thickness = 1800 # 本片的厚度,也是后面一片的起点距离 L1c.Glass = "AIR" L1c.Diameter = 2128.0 L1c.Name = 'plan side'

__#

P_Ima = Kos.surf() P_Ima.Rc = 0.0 P_Ima.Thickness = 0.0 P_Ima.Glass = "AIR" P_Ima.Diameter = 200.0 P_Ima.Name = "Image plane"

__#

A = [P_Obj, L1a, L1c,P_Ima] Config_1 = Kos.Setup()

__#

Lens = Kos.system(A, Config_1) Rays = Kos.raykeeper(Lens)

Wav = 0.55 # 波长??? y = np.arange(1063,1064,0.002) np.savetxt('y.txt',y,delimiter=',')

__#

for i in y: p_s = [0.0,i,0.0] d_cos = [0.0,0.0,1.0] Lens.Trace(p_s,d_cos,0.55) Rays.push()

__#

print(Rays.XYZ[100]) # here is verify ray , ri shoot in material is 1.550, out from material to air is 1.4936, why?

data = np.unique(np.array(data),axis=0) # unique and sort np.savetxt('rz.txt',data_,fmt='%.8f',delimiter=',') # save for verify

Kos.display3d(Lens, Rays, 2) Kos.display2d(Lens, Rays, 0)

`

How can I customize the refractive index of a material?

— Reply to this email directly, view it on GitHub https://github.com/Garchupiter/Kraken-Optical-Simulator/issues/12#issuecomment-2143867705, or unsubscribe https://github.com/notifications/unsubscribe-auth/AED73RS4HQWG3LBUXOQRFSDZFMRHDAVCNFSM6AAAAABIVAWNG2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTHA3DONZQGU. You are receiving this because you are subscribed to this thread.

Dr. Joel Herrera Vázquez Observatorio Astronómico Nacional Instituto de Astronomía de la UNAM (Sede Ensenada B.C.)

Tel. (646) 1 74 45 80 Ext.426