aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Argao <mcargao@email.wm.edu>2012-10-25 17:04:38 -0400
committerMatt Argao <mcargao@email.wm.edu>2012-10-25 17:04:38 -0400
commit1b47451605901d0bb19a566ff55b8ac29651ba23 (patch)
treeef7ecb82a3f1ec80269faf68989b8023e038cbcf
parentf4f7ddf366273449e662fbf5d8cbb08c472f33d3 (diff)
downloadmode_match-1b47451605901d0bb19a566ff55b8ac29651ba23.tar.gz
mode_match-1b47451605901d0bb19a566ff55b8ac29651ba23.zip
Made code parallel friendly
-rw-r--r--fitter_check.m100
1 files changed, 43 insertions, 57 deletions
diff --git a/fitter_check.m b/fitter_check.m
index d28b7f3..37ff237 100644
--- a/fitter_check.m
+++ b/fitter_check.m
@@ -1,8 +1,8 @@
lens_set = [.075, .203, .05, .03];
-lens_set = [.075, .203];
+lens_set = [.075,.203];
lens_permutations = pick(lens_set,3,'or');
n_perms = size(lens_permutations,1);
-n_shuffles=10; %number of random placements of lenses
+n_shuffles=20; %number of random placements of lenses
% ##########################################
@@ -39,76 +39,62 @@ xf=Ltot;
%Initialize sample arrays
-sample_energy = [];
-sample_x = [];
-possible_soln = [];
-possible_lens_pos = [];
-possible_sample_energy = [];
-lens_size = .03;
-
-
-for i = 1:n_perms
-
-
- lenses_choice=lens_permutations(i,:)
+
+N = n_perms * n_shuffles;
+possible_lens_placement = zeros(N,3);
+possible_lens_set = zeros(N,3);
+possible_sample_energy = zeros(N,1);
+initial_rand_lens_placement=zeros(N,3);
+
+lens_size = .03; % physical size of the lens
+
+for ip = 1:n_perms
+ f3=lens_permutations(ip,3);
+ x3=xf-f3; % last lense transfer collimated region to focused spot
+ for is = 1:n_shuffles
+ possible_lens_set((ip-1)*n_shuffles + is,:) = lens_permutations(ip,:);
+
+ initial_rand_lens_placement_tmp = sort(lens_size+(x3-2*lens_size)*rand(1,2));
+ initial_rand_lens_placement((ip-1)*n_shuffles + is,:) = [initial_rand_lens_placement_tmp, x3];
+ end
+end
+
+parfor i = 1:N
- for iteration = 1:n_shuffles
- f3=lenses_choice(3);
- x3=xf-f3; % last lense transfer collimated region to focused spot
- optics_x_rand = sort(lens_size+(x3-2*lens_size)*rand(1,2));
- optics_x_rand = [optics_x_rand, x3];
-
- fitness_simplified=@(x) fitness(q0, qf, Ltot, x, lenses_choice, lambda );
- [x_sol, energy]=fminsearch(fitness_simplified, optics_x_rand, optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200));
-
- sample_energy = [sample_energy; energy];
- sample_x = [sample_x; x_sol];
-
- %Return final Waist of trial
- q_f_trial = gbeam_propagation(Ltot,q0,x0,optics_placer(x_sol, lenses_choice));
- [waist, Radius] = q2wr(q_f_trial, lambda);
-
- %If it is a good solution, add to list of possible solutions
- waist_desired = wf;
- compare_waist = abs(waist - waist_desired);
- tolerance = 1E-6;
-
- if compare_waist < tolerance
- possible_soln = [possible_soln; x_sol];
- possible_lens_pos = [possible_lens_pos; lenses_choice];
- possible_sample_energy = [possible_sample_energy; energy];
- end
+ fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda );
+ [x_sol, energy]=fminsearch(fitness_simplified, initial_rand_lens_placement(i,:), optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200));
+ possible_lens_placement(i,:) =x_sol;
+ possible_sample_energy(i) = energy;
+
%Visualize solution
- figure(2)
- solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lenses_choice), lambda);
- title('Testing Points');
- drawnow;
-
- end
-
+% figure(2)
+% solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lens_permutations(ip,:)), lambda);
+% title('Testing Points');
+% drawnow;
+
end
%Sorting possible solution according to energy
[possible_sample_energy, index] = sort(possible_sample_energy);
-possible_soln = possible_soln(index,:);
-possible_lens_pos = possible_lens_pos(index,:);
+possible_lens_placement = possible_lens_placement(index,:);
+possible_lens_set = possible_lens_set(index,:);
%Truncate other possible solutions to an accuracy of n decimal places
n=4;
-possible_soln_trunc = round(possible_soln*10^n)./10^n;
-[possible_soln_uniq, index] = unique(possible_soln_trunc,'rows','stable'); %Unique solutions only
+possible_lens_placement_trunc = round(possible_lens_placement*10^n)./10^n;
+[possible_lens_placement_uniq, index] = unique(possible_lens_placement_trunc,'rows','stable'); %Unique solutions only
%Visualize five best solutions
-n_possible_soln = min(5,size(possible_soln_uniq,1));
-for n_graph = 1:n_possible_soln
+n_possible_lens_placement = min(5,size(possible_lens_placement_uniq,1));
+for n_graph = 1:n_possible_lens_placement
figure(n_graph+1)
- w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(possible_soln(index(n_graph),:), possible_lens_pos(index(n_graph),:)), lambda);
+ w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(possible_lens_placement(index(n_graph),:), possible_lens_set(index(n_graph),:)), lambda);
title('Other Solutions');
end
-possible_soln(index(1:n_graph),:)
-possible_lens_pos(index(1:n_graph),:)
-possible_sample_energy(index(1:n_graph),:) \ No newline at end of file
+possible_lens_placement(index(1:n_graph),:)
+possible_lens_set(index(1:n_graph),:)
+possible_sample_energy(index(1:n_graph),:)