summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abcd.m80
-rw-r--r--gbeam_propagation.m41
-rw-r--r--gbeam_propagation_froward_only.m40
-rw-r--r--propagation.m6
4 files changed, 84 insertions, 83 deletions
diff --git a/abcd.m b/abcd.m
index ac9b1db..814615c 100644
--- a/abcd.m
+++ b/abcd.m
@@ -29,87 +29,7 @@ function optics = arrange_optics_along_x(optics_unsorted)
end
end
-function q = prop_forward(x_pos, q_in, x_in, optics_elements)
-% calculate the 'q' parameter of the Gaussian beam propagating through optical
-% 'optics_elements' only in the positive direction along 'x' axis at points 'x_pos'
-% takes the gaussian beam with initial q_in parameter at x_in
-%
-% all x_pos must be to the right of x_in
-% x_pos must be monotonic!
- if (any(x_pos < x_in))
- error('all beam positions must be to the right of the x_in');
- end
-
- optics_elements=arrange_optics_along_x(optics_elements);
-
- % Forward propagation to the right of x_in
- Np=length(x_pos); % number of 'x' points
- Nel=length(optics_elements) ;
- q=0*x_pos; % q vector initialization
- q_last_calc=q_in;
- x_last_calc=x_in; % the furthest calculated point
- for i=1:Np
- x_pos_i=x_pos(i);
- for k=1:length(optics_elements)
- % iterates through optics_elements to make sure
- % we take them in account for the beam propagation
- el=optics_elements{k};
- if ( (x_last_calc < el.x) && (el.x <= x_pos_i) )
- abcd=abcd_free_space(el.x-x_last_calc);
- q_last_calc=q_afteer_element(q_last_calc,abcd);
- q_last_calc=q_afteer_element(q_last_calc,el.abcd);
- x_last_calc=el.x;
- endif
- endfor
- if (x_pos_i > x_last_calc);
- abcd=abcd_free_space(x_pos_i-x_last_calc);
- q_last_calc=q_afteer_element(q_last_calc,abcd);
- x_last_calc=x_pos_i;
- endif
- q(i)=q_last_calc;
- endfor
-end
-
-function q = prop(x_pos, q_in, x_in, optics_elements)
-% calculate the 'q' parameter of the Gaussian beam propagating through optical
-% 'optics_elements' array along 'x' axis at points 'x_pos'
-% takes the gaussian beam with initial q_in parameter at x_in
-% x_pos must be monotonic!
-
- q=0*x_pos; % q vector initialization
- if any(x_pos >= x_in)
- % Forward propagation to the right of x_in
- q(x_pos >= x_in) = prop_forward(x_pos(x_pos>=x_in), q_in, x_in, optics_elements);
- end
-
- if any(x_pos < x_in)
- % Backward propagation part the left of x_in
- % do it as forward propagation of the reverse beam
- x_backw=x_pos(x_pos<x_in);
- % now let's reflect the beam with respect to x_in
- % and solve the problem as forward propagating.
- x_backw=x_in-x_backw;
- % now we need to flip x positions
- x_backw=fliplr(x_backw);
- % reflected beam means inverted radius of curvature or real part of q parameter
- q_in_backw = -real(q_in) + 1i*imag(q_in);
- optics_elements_backw=optics_elements;
- % we need to flip all optics elements around x_in as well
- for i=1:length(optics_elements_backw)
- optics_elements_backw{i}.x=x_in-optics_elements_backw{i}.x;
- end
-
- q_backw = prop_forward(x_backw, q_in_backw, 0, optics_elements_backw);
- % now we need to flip the radius of curvature again
- q_backw = -real(q_backw) + 1i*imag(q_backw);
-
- % final assignment of the backwards propagating beam
- % which we need to flip back
- q(x_pos<x_in) = fliplr(q_backw);
- end
-
-endfunction
function waste =q2waste(q, lambda)
for i=1:size(q,2)
diff --git a/gbeam_propagation.m b/gbeam_propagation.m
new file mode 100644
index 0000000..524d4ae
--- /dev/null
+++ b/gbeam_propagation.m
@@ -0,0 +1,41 @@
+function q = gbeam_propagation(x_pos, q_in, x_in, optics_elements)
+% calculate the 'q' parameter of the Gaussian beam propagating through optical
+% 'optics_elements' array along 'x' axis at points 'x_pos'
+% takes the gaussian beam with initial q_in parameter at x_in
+% x_pos must be monotonic!
+
+ q=0*x_pos; % q vector initialization
+
+ if any(x_pos >= x_in)
+ % Forward propagation to the right of x_in
+ q(x_pos >= x_in) = gbeam_propagation_froward_only(x_pos(x_pos>=x_in), q_in, x_in, optics_elements);
+ end
+
+ if any(x_pos < x_in)
+ % Backward propagation part the left of x_in
+ % do it as forward propagation of the reverse beam
+ x_backw=x_pos(x_pos<x_in);
+ % now let's reflect the beam with respect to x_in
+ % and solve the problem as forward propagating.
+ x_backw=x_in-x_backw;
+ % now we need to flip x positions
+ x_backw=fliplr(x_backw);
+ % reflected beam means inverted radius of curvature or real part of q parameter
+ q_in_backw = -real(q_in) + 1i*imag(q_in);
+ optics_elements_backw=optics_elements;
+ % we need to flip all optics elements around x_in as well
+ for i=1:length(optics_elements_backw)
+ optics_elements_backw{i}.x=x_in-optics_elements_backw{i}.x;
+ end
+
+ q_backw = gbeam_propagation_froward_only(x_backw, q_in_backw, 0, optics_elements_backw);
+ % now we need to flip the radius of curvature again
+ q_backw = -real(q_backw) + 1i*imag(q_backw);
+
+ % final assignment of the backwards propagating beam
+ % which we need to flip back
+ q(x_pos<x_in) = fliplr(q_backw);
+ end
+
+endfunction
+
diff --git a/gbeam_propagation_froward_only.m b/gbeam_propagation_froward_only.m
new file mode 100644
index 0000000..ba8c1cf
--- /dev/null
+++ b/gbeam_propagation_froward_only.m
@@ -0,0 +1,40 @@
+function q = gbeam_propagation_froward_only(x_pos, q_in, x_in, optics_elements)
+% calculate the 'q' parameter of the Gaussian beam propagating through optical
+% 'optics_elements' only in the positive direction along 'x' axis at points 'x_pos'
+% takes the gaussian beam with initial q_in parameter at x_in
+%
+% all x_pos must be to the right of x_in
+% x_pos must be monotonic!
+ if (any(x_pos < x_in))
+ error('all beam positions must be to the right of the x_in');
+ end
+
+ optics_elements=arrange_optics_along_x(optics_elements);
+
+ % Forward propagation to the right of x_in
+ Np=length(x_pos); % number of 'x' points
+ Nel=length(optics_elements) ;
+ q=0*x_pos; % q vector initialization
+ q_last_calc=q_in;
+ x_last_calc=x_in; % the furthest calculated point
+ for i=1:Np
+ x_pos_i=x_pos(i);
+ for k=1:length(optics_elements)
+ % iterates through optics_elements to make sure
+ % we take them in account for the beam propagation
+ el=optics_elements{k};
+ if ( (x_last_calc < el.x) && (el.x <= x_pos_i) )
+ abcd=abcd_free_space(el.x-x_last_calc);
+ q_last_calc=q_afteer_element(q_last_calc,abcd);
+ q_last_calc=q_afteer_element(q_last_calc,el.abcd);
+ x_last_calc=el.x;
+ endif
+ endfor
+ if (x_pos_i > x_last_calc);
+ abcd=abcd_free_space(x_pos_i-x_last_calc);
+ q_last_calc=q_afteer_element(q_last_calc,abcd);
+ x_last_calc=x_pos_i;
+ endif
+ q(i)=q_last_calc;
+ endfor
+end
diff --git a/propagation.m b/propagation.m
index 35547f5..15d52c2 100644
--- a/propagation.m
+++ b/propagation.m
@@ -23,7 +23,7 @@ optics={lns1,lns2,lns3};
x=0:.001:Ltot;
printf('======== Forward propagation ======\n')
-q1=prop(x,q0,0,optics);
+q1=gbeam_propagation(x,q0,0,optics);
w1=q2waste(q1, lambda);
r1=q2radius(q1,lambda);
@@ -32,7 +32,7 @@ printf('======== Backward propagation ===\n')
rf=-rf;
q1b=waste_r2q(wf,rf,lambda);
-q2b=prop(x,q1b,Ltot,optics);
+q2b=gbeam_propagation(x,q1b,Ltot,optics);
printf('=================================\n')
wb=q2waste(q2b, lambda);
rb=q2radius(q2b,lambda);
@@ -48,7 +48,7 @@ r0
wf
rf
q0=waste_r2q(w0,r0,lambda);
-qtf=prop(Ltot, q0,0, optics);
+qtf=gbeam_propagation(Ltot, q0,0, optics);
printf('values below should match wf and rf: \n')
waste = q2waste(qtf, lambda)
radius = q2radius(qtf,lambda)