forked from SCRobarts/OptiFax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptic.m
231 lines (204 loc) · 5.28 KB
/
Optic.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
classdef Optic < matlab.mixin.Copyable
%OPTIC: An optical component in a cavity
% Combines up to two optical surfaces and a dielectric into a single
% optical component, with associated transmission and dispersion.
%
% Sebastian C. Robarts 2023 - sebrobarts@gmail.com
properties
Name string = "Optic";
Regime string
S1 OpticalSurface
Bulk Dielectric
S2 OpticalSurface
Parent % Cavity
end
properties (Transient)
SimWin SimWindow
Transmission
Reflection
Absorption
Dispersion
end
properties (Dependent)
IncidentAngle % Degrees
Length
OpticalPath
GroupDelay
RelativeGD
GDD
Material
end
methods(Access = protected)
% Override copyElement method:
function cpObj = copyElement(obj)
% Make a shallow copy of all properties
cpObj = copyElement@matlab.mixin.Copyable(obj);
% Make a deep copy of the Deep object
cpObj.S1 = copy(obj.S1);
cpObj.Bulk = copy(obj.Bulk);
cpObj.S2 = copy(obj.S2);
cpObj.adopt;
end
end
methods
function obj = Optic(regimeStr,s1,material,length_m,theta,s2,celsius,parent)
%OPTIC Construct an instance of this class
% Detailed explanation goes here
arguments
regimeStr string = "T";
s1 = 'None';
material = "FS";
length_m = 0.001;
theta = 0;
s2 = s1;
celsius = 20;
% parent handle = Cavity.empty;
parent handle = [];
end
if nargin > 0
obj.Parent = parent;
obj.SimWin = SimWindow.empty;
if class(s1) ~= "OpticalSurface"
s1 = OpticalSurface(s1,material,theta,1,obj);
else
% s1 = OpticalSurface(s1.Coating,material,theta,1,obj,s1.GDD);
end
obj.Regime = regimeStr;
obj.S1 = s1;
if class(material) ~= "Dielectric"
material = Dielectric(material,length_m,celsius,obj);
end
if class(s2) ~= "OpticalSurface"
s2 = OpticalSurface(s2,material,theta,2,obj);
else
s2 = OpticalSurface(s2.Coating,material,theta,2,obj,s2.GDD);
end
obj.Bulk = material;
obj.S2 = s2;
end
end
function simulate(obj,simWin)
obj.SimWin = simWin;
obj.adopt;
obj.Bulk.simulate;
obj.Transmission = obj.S1.Transmission;
obj.Reflection = obj.S1.Reflection; % Counting only the first surface reflection as other reflections form separate "pulses"
obj.Absorption = obj.Bulk.Absorption;
obj.Dispersion = obj.S1.Dispersion;
obj.Transmission = obj.Transmission...
.* obj.Bulk.Transmission...
.* obj.S2.Transmission;
if obj.Regime == "T"
obj.Dispersion = obj.Dispersion...
+ obj.Bulk.Dispersion...
+ obj.S2.Dispersion;
else
% obj.Transmission = 1 - obj.Transmission;
end
end
function adopt(obj)
obj.S1.Parent = obj;
obj.Bulk.Parent = obj;
obj.S2.Parent = obj;
end
function scaleT(obj,lamOCnm,target,lamLimsnm)
arguments
obj Optic
lamOCnm
target
lamLimsnm = [350 2000];
end
limIDs = and(obj.SimWin.Lambdanm>lamLimsnm(1),obj.SimWin.Lambdanm<lamLimsnm(2));
nuOC = c ./ (lamOCnm .* 1e-9);
lamID = find(abs(obj.SimWin.Frequencies - nuOC) < obj.SimWin.DeltaNu./2);
prevOC = obj.Transmission(lamID);
newOC = target;
powOC = log2(newOC)./log2(prevOC);
obj.Transmission(limIDs) = obj.Transmission(limIDs) .^ powOC;
obj.Reflection(limIDs) = 1 - obj.Transmission(limIDs);
end
function GD = get.GroupDelay(obj)
% GD = phi2GD(obj.Dispersion,obj.SimWin.DeltaOmega);
GD = phi2GD(obj.Bulk.Phi,obj.SimWin.DeltaOmega);
end
function GD_rel = get.RelativeGD(obj)
GD_rel = phi2GD(obj.Dispersion,obj.SimWin.DeltaOmega);
end
function GDD = get.GDD(obj)
[~,GDD] = phi2GD(obj.Dispersion,obj.SimWin.DeltaOmega);
end
function theta = get.IncidentAngle(obj)
theta = obj.S1.IncidentAngle;
end
function set.IncidentAngle(obj,theta)
obj.S1.IncidentAngle = theta;
end
function l = get.Length(obj)
if strcmp(obj.Regime,"T")
l = obj.Bulk.PathLength;
else
l = 0;
end
end
function set.Length(obj,l)
obj.Bulk.Length = l;
end
function opl = get.OpticalPath(obj)
if strcmp(obj.Regime,"T")
nr = obj.Bulk.RefractiveIndex;
else
nr = 0;
end
opl = obj.Length .* nr;
end
function bulkMat = get.Material(obj)
bulkMat = obj.Bulk.Material;
end
function plot(obj,lims)
arguments
obj
lims = [350 5500]
end
fh = figure;
tl = tiledlayout(fh,2,2);
title(tl,obj.Name,"Interpreter","none");
nexttile
if strcmp(obj.Regime,"T")
wavplot(obj.SimWin.Lambdanm,obj.Transmission)
ylabel('Power Transmission')
else
wavplot(obj.SimWin.Lambdanm,obj.Reflection)
ylabel('Power Reflection')
end
xlim(lims)
ylim([0 1])
nexttile
wavplot(obj.SimWin.Lambdanm,obj.Dispersion)
xlim(lims)
ylabel('Dispersion, \Phi (rad)')
nexttile
wavplot(obj.SimWin.Lambdanm,obj.RelativeGD*1e15)
% wavplot(obj.SimWin.Lambdanm,obj.GroupDelay*1e15)
xlim(lims)
ylabel('Relative GD (fs)')
% ylabel('Group Delay (fs)')
nexttile
wavplot(obj.SimWin.Lambdanm,obj.GDD*1e30)
xlim(lims)
ylabel('GDD (fs^2)')
end
function store(obj,name,devFlag)
arguments
obj
name
devFlag = 0;
end
obj.Name = name;
currentfolder = pwd;
cd(OptiFaxRoot(devFlag));
cd("objects" + filesep + "optics");
save(name + ".mat","obj","-mat");
cd(currentfolder);
end
end
end