From 4d08c162d5ce4ac8b7eaeb9d985bfef62c886e99 Mon Sep 17 00:00:00 2001 From: Matt Argao Date: Sun, 31 Mar 2013 22:35:49 -0400 Subject: Added descriptions to each function. --- energy_vs_stability.m | 25 +++++--- find_min.m | 4 +- fitness.m | 125 +++++++++++++++++++++++++-------------- fitter_check.m | 54 ++++++++--------- gaussian_focus.m | 17 ++++-- gbeam_propagation.m | 8 ++- gbeam_propagation_froward_only.m | 9 ++- mode_match.m | 29 ++++++--- optics_placer.m | 1 + pick_visualization.m | 10 ++-- remove_similar_soln.m | 4 +- self_gbeam_propagation.m | 38 ++---------- solution_stability.m | 9 +-- solution_visualization.m | 64 +++++++++++++++++--- stability_visualization.m | 7 +-- 15 files changed, 246 insertions(+), 158 deletions(-) diff --git a/energy_vs_stability.m b/energy_vs_stability.m index 796c631..1915449 100644 --- a/energy_vs_stability.m +++ b/energy_vs_stability.m @@ -1,10 +1,22 @@ function [] = energy_vs_stability( possible_energy, stability, index, stability_max ) -%ENERGY_VS_STABILITY Summary of this function goes here -% Detailed explanation goes here +%Plots energy vs. stability +% Using data sent from mode_match, this function plots energy vs. +% stability of each solution for eyed comparisons. n = size(stability,2); - c = 1:n; + %Color code data points + if n == 3 + c = [1, 0, 0; 0, 1, 0; 0, 0, 1]; + elseif n == 2 + c = [1, 0, 0; 0, 1, 0]; + elseif n == 1 + c = [1, 0, 0]; + else + c = 1:n; + end + + %Reorganize stability to coincide with energies for i=1:n fixed_stability(i,1) = stability(i); end @@ -13,6 +25,7 @@ function [] = energy_vs_stability( possible_energy, stability, index, stability_ energy(i,1) = possible_energy(index(i)); end + %Graph scatter plot figure(n+1) textCell = arrayfun(@(x,y) sprintf('(%3.2f, %3.2f)',x,y),energy,fixed_stability,'un',0); scatter(energy,fixed_stability,25,c,'filled') @@ -23,13 +36,11 @@ function [] = energy_vs_stability( possible_energy, stability, index, stability_ dx =0.0000000005; dy =0.0000000005; + %Label data points relative to solution number for i = 1:n n_solution = num2str(i); text(energy(i)+dx, fixed_stability(i)+dy, n_solution, 'FontSize',10); end -% for i = 1:n -% text(energy(i), fixed_stability(i), textCell{i}, 'FontSize',8) -% end - + end diff --git a/find_min.m b/find_min.m index 2c3ae7d..a6962d2 100644 --- a/find_min.m +++ b/find_min.m @@ -1,7 +1,5 @@ function [ x_sol, energy ] = find_min( index, lens_placement, fitness_simplified, MaxFunEvals, MaxIter ) -%FIND_MIN Summary of this function goes here -% Detailed explanation goes here - +%Minimizes energy for given solution [x_sol, energy] = fminsearch(fitness_simplified, lens_placement(index,:), optimset('TolFun',1e-5,'MaxFunEvals',MaxFunEvals,'MaxIter', MaxIter)); end diff --git a/fitness.m b/fitness.m index 403d8d7..697d5fd 100644 --- a/fitness.m +++ b/fitness.m @@ -1,45 +1,16 @@ -function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_positions, optics_focal_length, lambda ) +function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_positions, optics_focal_length, lambda, self_flag ) %Outputs fitness of suggested solution - x0 = 0; - Energy = 0; - - x1=optics_positions(1); - x2=optics_positions(2); - x3=optics_positions(3); - - % penalty calculation - % do not put lenses too close to each other and end positions - lens_size=0.03; - - d(1)=abs(x1-x2); - d(2)=abs(x2-x3); - d(3)=abs(x1-x3); - - d_from_start=abs(x0-optics_positions); - d_from_end=abs(x_final-optics_positions); - - - d=cat(2, d, d_from_start, d_from_end); - - coef = 1; - - penalty_lenses_too_closely_spaced =coef*sum( exp(-(d/(lens_size)).^12) ); - - Energy = Energy + penalty_lenses_too_closely_spaced; - - % make sure that lenses are between ends - d_from_start=(x0-optics_positions); - d_from_end=(optics_positions-x_final); - - d = cat(2, d_from_start, d_from_end); - - coef = 1; - distance_scaling=100; - penalty_lenses_outside_optical_path = coef * sum(1 + tanh(distance_scaling*d)); - - Energy = Energy + penalty_lenses_outside_optical_path; - - % make collimated region between 2nd and 3rd lens +x0 = 0; +Np=20; % # of pts between start position and second lens +N_collimated = 10; % # of pts between second lens and third lens to be collimated region +Energy = 0; + +x1=optics_positions(1); +x2=optics_positions(2); +x3=optics_positions(3); + +if self_flag == 1 + % make collimated region between 2nd and 3rd lens [w0, r0] = q2wr(q_0, lambda); [ w, w_pos ] = self_gbeam_propagation( w0, optics_positions, optics_focal_length, x0, lambda ); @@ -51,20 +22,84 @@ function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_posit Energy = Energy + penalty_not_collimated_beam; -% % waist at end matches desired waist + % waist at end matches desired waist coef = 10; [waist_desired, r_desired] = q2wr(q_final, lambda); penalty_waist = coef *((( waist_desired-w(end) )/waist_desired)^2); Energy = Energy + penalty_waist; - + coef=10; dist_between_desired_and_final_waist_location =w_pos(end) - x_final; penalty_final_waist_position = coef*dist_between_desired_and_final_waist_location^2; - + Energy = Energy + penalty_final_waist_position; + +else + % check if waists match in forward and backward propagation + x_array1=linspace(x0,x2,Np); + x_array2=linspace(x2, x3, N_collimated); + x = cat(2,x_array1,x_array2); + + q_f_trial_forward = gbeam_propagation(x,q_0,x0,optics_placer(optics_positions, optics_focal_length)); + [Waist_trial_forward, Radius_trial_forward] = q2wr(q_f_trial_forward, lambda); + q_f_trial_backward = gbeam_propagation(x,q_final,x_final,optics_placer(optics_positions, optics_focal_length)); + [Waist_trial_backward, Radius_trial_backward] = q2wr(q_f_trial_backward, lambda); + + Penalty_waist_mismatch = sum(abs((Waist_trial_forward-Waist_trial_backward)./min(Waist_trial_forward, Waist_trial_backward)))/Np; + + Energy = 1e-2*Penalty_waist_mismatch; + + %intialize intermediate points between lenses + q_intermediate = q_f_trial_forward((x20 before lens) +% f = focal length of lens (f>0 for converging lens) +% Output: w = new waist; +% s = position of waist from lens -zR = pi*w0^2/lambda; -s = f*(1+(s0/f-1)/((s0/f-1)^2+(zR/f)^2)); +zR = pi*w0^2/lambda; %Rayleigh Range +s = f*(1+(s0/f-1)/((s0/f-1)^2+(zR/f)^2)); %Eq. (9b) w = w0/sqrt((1-s0/f)^2+(zR/f)^2); -end - +end \ No newline at end of file diff --git a/gbeam_propagation.m b/gbeam_propagation.m index d81f70e..585048d 100644 --- a/gbeam_propagation.m +++ b/gbeam_propagation.m @@ -1,4 +1,4 @@ -function q = gbeam_propagation(x_pos, q_in, x_in, optics_elements) +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 @@ -8,7 +8,7 @@ function q = gbeam_propagation(x_pos, q_in, x_in, optics_elements) 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); + [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) @@ -45,8 +45,10 @@ function q = gbeam_propagation(x_pos, q_in, x_in, optics_elements) % final assignment of the backwards propagating beam % which we need to flip back q(x_pos