halfway merged and pulled?!
This commit is contained in:
135
Classes/02_optical/dp_fiber_lib/CNLSE.m
Normal file
135
Classes/02_optical/dp_fiber_lib/CNLSE.m
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
function [opt_out_struct,state] = CNLSE(opt_in_struct,state)
|
||||
|
||||
% init transfer functions h.X and h.Y
|
||||
h = struct('X',0,'Y',0);
|
||||
state.common_beta=struct('X',0,'Y',0);
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% pre calculations
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% calculate transfer function and rotate coordines for both
|
||||
% polarizations
|
||||
|
||||
for n=1:2
|
||||
% get current polarization name and contrary one
|
||||
curPol = state.polNames{n};
|
||||
|
||||
% extend linear transfer function depending on beta values for the
|
||||
% current polarization
|
||||
for n_beta = 1:length(state.beta.(curPol))
|
||||
% h.(curPol) = h.(curPol) - 1j*state.beta.(curPol)(n_beta)*(state.omega).^(n_beta-1)/factorial(n_beta-1);
|
||||
% if n_beta ~= 2
|
||||
state.common_beta.(curPol) = state.common_beta.(curPol) + state.beta.(curPol)(n_beta) * (state.omega).^(n_beta-1) / factorial(n_beta-1);
|
||||
% end
|
||||
end
|
||||
|
||||
opt_out_struct.(curPol)=opt_in_struct.(curPol).envelope;
|
||||
end
|
||||
|
||||
state.h=h;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Splitstep method
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
% state.SS_dzs = zeros(1,state.max_nonlin_its);
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Split Step Method
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% get nonlinear step size
|
||||
[state.dz] = getNLstepsize(state,opt_out_struct);
|
||||
|
||||
state.n_step = 0;
|
||||
state.z_prop = 0;
|
||||
state.test_dz = [];
|
||||
state.powers = [];
|
||||
|
||||
while state.z_prop < state.L
|
||||
|
||||
|
||||
|
||||
|
||||
if state.z_prop + state.dz > state.L
|
||||
state.dz = state.L - state.z_prop;
|
||||
end
|
||||
|
||||
|
||||
% lin conv
|
||||
% opt_out_struct = [ opt_out_struct 0 0 0 0 0 ];
|
||||
% opt_out_struct
|
||||
%%%%%%%%%%%%%
|
||||
% STEP
|
||||
% update step number
|
||||
|
||||
state.n_step=state.n_step+1;
|
||||
state.dzs(state.n_step)=state.dz;
|
||||
|
||||
% half linear step
|
||||
[opt_out_struct,state] = lin_step(state,opt_out_struct,state.dz/2);
|
||||
|
||||
|
||||
% complete nonlinear step
|
||||
[opt_out_struct,state] = nl_step(state,opt_out_struct,state.dz);
|
||||
|
||||
% half linear step
|
||||
[opt_out_struct,state] = lin_step(state,opt_out_struct,state.dz/2);
|
||||
|
||||
%%%%%%%%%%%%%
|
||||
% prepare next STEP
|
||||
|
||||
% overlap(n_step+1,:) = opt_out_struct(M+1:end);
|
||||
% opt_out_struct = opt_out_struct(1:M);
|
||||
|
||||
|
||||
% get nonlinear step size
|
||||
[state.dz] = getNLstepsize(state,opt_out_struct);
|
||||
|
||||
end
|
||||
|
||||
|
||||
% figure(88);clf;subplot(2,1,1);stem(state.test_plates);subplot(2,1,1); hold all;stem(-1000*state.test_plate_numbers);subplot(2,1,2);stem(state.dzs)
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Post Calculations
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% opt_out_struct.X.envelope = ( cos(state.psi)*cos(state.chi) + 1j*sin(state.psi)*sin(state.chi))*opt_out_struct.X + ...
|
||||
% (-sin(state.psi)*cos(state.chi) - 1j*cos(state.psi)*sin(state.chi))*opt_out_struct.Y;
|
||||
%
|
||||
buffer.X.envelope = opt_out_struct.X;
|
||||
buffer.X.type = opt_in_struct.X.type;
|
||||
buffer.X.wavelength = opt_in_struct.X.wavelength;
|
||||
if isfield(buffer.X,'Nase')
|
||||
buffer.X.Nase = opt_in_struct.X.Nase;
|
||||
else
|
||||
buffer.X.Nase = 0;
|
||||
end
|
||||
|
||||
opt_out_struct.X =[];
|
||||
opt_out_struct.X.envelope = buffer.X.envelope;
|
||||
opt_out_struct.X.type = buffer.X.type;
|
||||
opt_out_struct.X.wavelength = buffer.X.wavelength;
|
||||
opt_out_struct.X.Nase = buffer.X.Nase;
|
||||
|
||||
%
|
||||
% opt_out_struct.Y.envelope = ( sin(state.psi)*cos(state.chi) - 1j*cos(state.psi)*sin(state.chi))*opt_out_struct.X.envelope + ...
|
||||
% ( cos(state.psi)*cos(state.chi) - 1j*sin(state.psi)*sin(state.chi))*opt_out_struct.Y;
|
||||
%
|
||||
buffer.Y.envelope = opt_out_struct.Y;
|
||||
buffer.Y.type = opt_in_struct.Y.type;
|
||||
buffer.Y.wavelength = opt_in_struct.Y.wavelength;
|
||||
if isfield(buffer.Y,'Nase')
|
||||
buffer.Y.Nase = opt_in_struct.Y.Nase;
|
||||
else
|
||||
buffer.Y.Nase = 0;
|
||||
end
|
||||
|
||||
opt_out_struct.Y =[];
|
||||
opt_out_struct.Y.envelope = buffer.Y.envelope;
|
||||
opt_out_struct.Y.type = buffer.Y.type;
|
||||
opt_out_struct.Y.wavelength = buffer.Y.wavelength;
|
||||
opt_out_struct.Y.Nase = buffer.Y.Nase;
|
||||
|
||||
% figure(100+loop);plot([real(opt_out_struct.X.envelope);real(opt_out_struct.Y.envelope)].');
|
||||
end
|
||||
Reference in New Issue
Block a user