Minor mods

This commit is contained in:
Karthik 2025-04-25 16:00:27 +02:00
parent eabf2c1a75
commit f42c5ab0de
7 changed files with 228 additions and 120 deletions

View File

@ -1,80 +1,138 @@
function makeMovie(run_index)
function makeMovie(folder_path, run_index)
set(0,'defaulttextInterpreter','latex')
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
folder_path = './Data';
format long
persistent yMaxNormFixed
persistent yMaxEnergyFixed
% Load data
FileDir = dir(sprintf(horzcat(folder_path, '/Run_%03i/*.mat'),run_index));
NumFiles = numel(FileDir);
Data = load(sprintf(horzcat(folder_path, '/Run_%03i/psi_%i.mat'),run_index,1),'Params','Transf');
Data = load(sprintf(horzcat(folder_path, '/Run_%03i/psi_%i.mat'),run_index,2),'Params','Transf');
Params = Data.Params;
Transf = Data.Transf;
w0 = Params.w0;
x = Transf.x; y = Transf.y; z = Transf.z;
dx = x(2)-x(1); dy = y(2)-y(1); dz = z(2)-z(1);
mkdir(sprintf(horzcat(folder_path, '/Run_%03i/Figures'),run_index))
outputVideo = VideoWriter(fullfile(horzcat(folder_path, '/Movie.avi')));
outputVideo = VideoWriter(fullfile(horzcat(folder_path, '/Movie')), 'MPEG-4');
outputVideo.Quality = 100; % Set quality to maximum (0100)
outputVideo.FrameRate = 10;
open(outputVideo)
figure(1);
x0 = 800;
y0 = 200;
width = 800;
height = 600;
set(gcf,'position',[x0,y0,width,height])
clf
set(gcf,'Position', [100, 100, 1600, 900])
t = tiledlayout(2, 3, 'TileSpacing', 'compact', 'Padding', 'compact'); % 2x3 grid
for ii = 1:(NumFiles-1)
Data = load(sprintf(horzcat(folder_path, '/Run_%03i/psi_%i.mat'),run_index,ii),'psi','muchem','T','Observ');
for ii = 2:(NumFiles-1)
% Load data
Data = load(sprintf('./Results/Data_3D/RealTimeDynamics/Run_%03i/psi_%i.mat',run_index,ii),'psi','muchem','Observ','t_idx');
if isgpuarray(Data.psi), psi = gather(Data.psi); end
if isgpuarray(Data.Observ.tVecPlot)
Observ.tVecPlot = gather(Data.Observ.tVecPlot);
else
Observ.tVecPlot = Data.Observ.tVecPlot;
end
if isgpuarray(Data.Observ.NormVec)
Observ.NormVec = gather(Data.Observ.NormVec);
else
Observ.NormVec = Data.Observ.NormVec;
end
if isgpuarray(Data.Observ.PCVec)
Observ.PCVec = gather(Data.Observ.PCVec);
else
Observ.PCVec = Data.Observ.PCVec;
end
if isgpuarray(Data.Observ.EVec)
Observ.EVec = gather(Data.Observ.EVec);
else
Observ.EVec = Data.Observ.EVec;
end
psi = Data.psi;
muchem = Data.muchem;
T = Data.T;
Observ = Data.Observ;
if isempty(yMaxNormFixed)
yMaxNormFixed = 1.05 * Observ.NormVec; % Set once in the first iteration
end
if isempty(yMaxEnergyFixed)
yMaxEnergyFixed = 1.05 * Observ.EVec; % Set once in the first iteration
end
% Compute probability density |psi|^2
n = abs(psi).^2;
%Plotting
subplot(2,3,1)
n = abs(psi).^2;
nexttile;
nxz = squeeze(trapz(n*dy,2));
nyz = squeeze(trapz(n*dx,1));
nxy = squeeze(trapz(n*dz,3));
plotxz = pcolor(x,z,nxz'); shading interp
plotxz = pcolor(x,z,nxz');
set(plotxz, 'EdgeColor', 'none');
xlabel('$x$ [$\mu$m]'); ylabel('$z$ [$\mu$m]');
cbar1 = colorbar;
cbar1.Label.Interpreter = 'latex';
% cbar1.Ticks = []; % Disable the ticks
colormap(gca, Helper.Colormaps.plasma())
xlabel('$x$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
ylabel('$z$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
title('$|\Psi(x,z)|^2$', 'Interpreter', 'latex', 'FontSize', 14)
subplot(2,3,2)
plotyz = pcolor(y,z,nyz'); shading interp
nexttile;
plotyz = pcolor(y,z,nyz');
set(plotyz, 'EdgeColor', 'none');
xlabel('$y$ [$\mu$m]'); ylabel('$z$ [$\mu$m]');
cbar1 = colorbar;
cbar1.Label.Interpreter = 'latex';
% cbar1.Ticks = []; % Disable the ticks
colormap(gca, Helper.Colormaps.plasma())
xlabel('$y$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
ylabel('$z$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
title('$|\Psi(y,z)|^2$', 'Interpreter', 'latex', 'FontSize', 14)
subplot(2,3,3)
plotxy = pcolor(x,y,nxy'); shading interp
nexttile;
plotxy = pcolor(x,y,nxy');
set(plotxy, 'EdgeColor', 'none');
xlabel('$x$ [$\mu$m]'); ylabel('$y$ [$\mu$m]');
cbar1 = colorbar;
cbar1.Label.Interpreter = 'latex';
% cbar1.Ticks = []; % Disable the ticks
colormap(gca, Helper.Colormaps.plasma())
xlabel('$x$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
ylabel('$y$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
title('$|\Psi(x,y)|^2$', 'Interpreter', 'latex', 'FontSize', 14)
subplot(2,3,4)
plot(Observ.tVecPlot*1000/Params.w0,Observ.NormVec,'-b')
ylabel('Normalization'); xlabel('$t$ [$m$s]');
nexttile;
plot(Observ.tVecPlot*1000/w0,Observ.NormVec,'-b')
ylim([0, yMaxNormFixed]);
ylabel('$N$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Normalization', 'FontSize', 14);
grid on
subplot(2,3,5)
plot(Observ.tVecPlot*1000/Params.w0,1-2*Observ.PCVec/pi,'-b')
ylabel('Coherence'); xlabel('$t$ [$m$s]');
nexttile;
plot(Observ.tVecPlot*1000/w0,1-2*Observ.PCVec/pi,'-b')
ylim([0,1])
ylabel('$C$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Coherence', 'FontSize', 14);
grid on
subplot(2,3,6)
plot(Observ.tVecPlot*1000/Params.w0,Observ.EVec,'-b')
ylabel('E'); xlabel('$t$ [$m$s]');
tVal = Observ.tVecPlot(end)*1000/Params.w0;
sgtitle(sprintf('$\\mu =%.3f \\hbar\\omega_0$, $T=%.1f$nK, $t=%.1f$ms',muchem,T,tVal))
nexttile;
plot(Observ.tVecPlot*1000/w0,Observ.EVec,'-b')
ylim([0, yMaxEnergyFixed]);
ylabel('$E_{tot}$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Energy', 'FontSize', 14);
grid on
tVal = Observ.tVecPlot(end)*1000/w0;
sgtitle(sprintf('$\\mu =%.3f \\hbar\\omega_0$, $t=%.1f$ms',muchem,tVal),'Interpreter', 'latex','FontSize', 14)
drawnow
saveas(gcf,sprintf(horzcat(folder_path, '/Run_%03i/Figures/Image_%i.jpg'),run_index,ii))
img = imread(sprintf(horzcat(folder_path, '/Run_%03i/Figures/Image_%i.jpg'),run_index,ii));
saveas(gcf,sprintf('./Results/Data_3D/RealTimeDynamics/Run_%03i/Figures/Image_%i.jpg',run_index,ii))
img = imread(sprintf('./Results/Data_3D/RealTimeDynamics/Run_%03i/Figures/Image_%i.jpg',run_index,ii));
writeVideo(outputVideo,img)
clf
end

View File

@ -124,19 +124,19 @@ function plotLive(psi,Params,Transf,Observ,SimulationMode)
nexttile;
plot(Observ.tVecPlot,Observ.NormVec,'-b')
ylabel('$N$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14);
ylabel('$N$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Normalization', 'FontSize', 14);
grid on
nexttile;
plot(Observ.tVecPlot,1-2*Observ.PCVec/pi,'-b')
ylabel('$C$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14);
ylabel('$C$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Coherence', 'FontSize', 14);
grid on
nexttile;
plot(Observ.tVecPlot,Observ.EVec,'-b')
ylabel('$E_{tot}$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14);
ylabel('$E_{tot}$', 'FontSize', 14); xlabel('$t$ [$m$s]', 'FontSize', 14);
title('Energy', 'FontSize', 14);
grid on
end

View File

@ -50,19 +50,18 @@ sim.Potential = pot.trap(); % + pot.repulsive_chopstick(
Plotter.visualizeTrapPotential(sim.Potential,Params,Transf)
%% - Plot initial wavefunction
Plotter.visualizeWavefunction(psi,Params,Transf)
%% Imaginary-Time followed by Real-time
%% Imaginary-Time followed by Real-time
% - Imaginary-Time
OptionsStruct = struct;
OptionsStruct.NumberOfAtoms = 80000;
OptionsStruct.NumberOfAtoms = 1E5;
OptionsStruct.DipolarPolarAngle = deg2rad(0);
OptionsStruct.DipolarAzimuthAngle = deg2rad(0);
OptionsStruct.ScatteringLength = 110;
OptionsStruct.TrapFrequencies = [50, 20, 250];
OptionsStruct.TrapFrequencies = [50, 20, 150];
OptionsStruct.TrapPotentialType = 'Harmonic';
OptionsStruct.NumberOfGridPoints = [64, 128, 32];
@ -102,10 +101,10 @@ OptionsStruct.SimulationMode = 'RealTimeEvolution'; % 'ImaginaryT
OptionsStruct.EquilibrationTime = 10E-3;
OptionsStruct.QuenchTime = 10E-3;
OptionsStruct.HoldTime = 10E-3;
OptionsStruct.QuenchScatteringLength = true;
OptionsStruct.RotateDipoles = false;
OptionsStruct.FinalScatteringLength = 75;
OptionsStruct.FinalDipolarPolarAngle = deg2rad(90);
OptionsStruct.QuenchScatteringLength = false;
OptionsStruct.RotateDipoles = true;
OptionsStruct.FinalScatteringLength = 88;
OptionsStruct.FinalDipolarPolarAngle = deg2rad(35);
OptionsStruct.FinalDipolarAzimuthAngle = deg2rad(0);
OptionsStruct.TimeStepSize = 1E-3; % in s
OptionsStruct.NoiseScaleFactor = 0.010;
@ -120,6 +119,7 @@ clear OptionsStruct
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
@ -522,3 +522,27 @@ Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
SaveDirectory = './Results/Data_3D/TiltedDipoles45';
JobNumber = 2;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/RealTimeDynamics';
JobNumber = 0;
Plotter.makeMovie(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles15';
JobNumber = 0;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles30';
JobNumber = 0;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles35';
JobNumber = 0;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles40';
JobNumber = 0;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
%%
SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles45';
JobNumber = 0;
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)

View File

@ -1,77 +1,24 @@
%{
theta = 0;
phi = 0;
% - SSD: N = 1E5, as = 86ao
theta = 15;
OptionsStruct = struct;
OptionsStruct.NumberOfAtoms = 1E5;
OptionsStruct.DipolarPolarAngle = deg2rad(theta);
OptionsStruct.DipolarAzimuthAngle = deg2rad(phi);
OptionsStruct.ScatteringLength = 86;
OptionsStruct.DipolarAzimuthAngle = deg2rad(0);
OptionsStruct.ScatteringLength = 88;
% AspectRatio = 2.0;
% HorizontalTrapFrequency = 125;
% VerticalTrapFrequency = AspectRatio * HorizontalTrapFrequency;
% OptionsStruct.TrapFrequencies = [HorizontalTrapFrequency, HorizontalTrapFrequency, VerticalTrapFrequency];
OptionsStruct.TrapFrequencies = [150, 150, 300];
OptionsStruct.TrapFrequencies = [50, 20, 150];
OptionsStruct.TrapPotentialType = 'Harmonic';
OptionsStruct.NumberOfGridPoints = [128, 128, 64];
OptionsStruct.Dimensions = [18, 18, 18];
OptionsStruct.UseApproximationForLHY = true;
OptionsStruct.IncludeDDICutOff = true;
OptionsStruct.CutoffType = 'Cylindrical';
OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution'
OptionsStruct.TimeStepSize = 1E-3; % in s
OptionsStruct.MinimumTimeStepSize = 2E-6; % in s
OptionsStruct.TimeCutOff = 2E6; % in s
OptionsStruct.EnergyTolerance = 5E-10;
OptionsStruct.ResidualTolerance = 1E-08;
OptionsStruct.NoiseScaleFactor = 0.01;
OptionsStruct.NumberOfGridPoints = [128, 256, 64];
OptionsStruct.Dimensions = [50, 50, 10];
OptionsStruct.PlotLive = true;
OptionsStruct.JobNumber = 0;
OptionsStruct.RunOnGPU = false;
OptionsStruct.SaveData = true;
OptionsStruct.SaveDirectory = './Results/Data_3D/TiltedDipoles0';
options = Helper.convertstruct2cell(OptionsStruct);
clear OptionsStruct
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
%}
%% - Aspect Ratio: 2.5
theta = 45;
OptionsStruct = struct;
OptionsStruct.NumberOfAtoms = 1E5;
OptionsStruct.DipolarPolarAngle = deg2rad(theta);
OptionsStruct.DipolarAzimuthAngle = 0;
OptionsStruct.ScatteringLength = 85;
AspectRatio = 2.5;
HorizontalTrapFrequency = 125;
VerticalTrapFrequency = AspectRatio * HorizontalTrapFrequency;
OptionsStruct.TrapFrequencies = [HorizontalTrapFrequency, HorizontalTrapFrequency, VerticalTrapFrequency];
OptionsStruct.TrapPotentialType = 'Harmonic';
OptionsStruct.NumberOfGridPoints = [128, 128, 64];
OptionsStruct.Dimensions = [12, 12, 12];
OptionsStruct.UseApproximationForLHY = true;
OptionsStruct.IncludeDDICutOff = true;
OptionsStruct.CutoffType = 'CustomCylindrical';
OptionsStruct.CustomCylindricalCutOffRadius = 4.5;
OptionsStruct.CustomCylindricalCutOffHeight = 4.5;
OptionsStruct.CustomCylindricalCutOffRadius = 20.0;
OptionsStruct.CustomCylindricalCutOffHeight = 4.0;
OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution'
OptionsStruct.TimeStepSize = 1E-3; % in s
OptionsStruct.MinimumTimeStepSize = 2E-6; % in s
@ -81,7 +28,7 @@ OptionsStruct.ResidualTolerance = 1E-05;
OptionsStruct.NoiseScaleFactor = 0.01;
OptionsStruct.PlotLive = false;
OptionsStruct.JobNumber = 2;
OptionsStruct.JobNumber = 0;
OptionsStruct.RunOnGPU = true;
OptionsStruct.SaveData = true;
OptionsStruct.SaveDirectory = sprintf('./Results/Data_3D/TiltedDipoles%s', strrep(num2str(round(rad2deg(OptionsStruct.DipolarPolarAngle),2)), '.', '_'));
@ -94,3 +41,78 @@ sim.Potential = pot.trap();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
%{
%% Imaginary-Time followed by Real-time
% - Imaginary-Time
OptionsStruct = struct;
OptionsStruct.NumberOfAtoms = 1E5;
OptionsStruct.DipolarPolarAngle = deg2rad(0);
OptionsStruct.DipolarAzimuthAngle = deg2rad(0);
OptionsStruct.ScatteringLength = 88;
OptionsStruct.TrapFrequencies = [50, 20, 150];
OptionsStruct.TrapPotentialType = 'Harmonic';
OptionsStruct.NumberOfGridPoints = [128, 256, 64];
OptionsStruct.Dimensions = [50, 50, 10];
OptionsStruct.UseApproximationForLHY = true;
OptionsStruct.IncludeDDICutOff = true;
OptionsStruct.CutoffType = 'CustomCylindrical';
OptionsStruct.CustomCylindricalCutOffRadius = 20.0;
OptionsStruct.CustomCylindricalCutOffHeight = 4.0;
OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' | 'EnergyMinimization'
OptionsStruct.TimeStepSize = 5E-3; % in s
OptionsStruct.MinimumTimeStepSize = 1E-6; % in s
OptionsStruct.TimeCutOff = 1E2; % in s
OptionsStruct.EnergyTolerance = 5E-10;
OptionsStruct.ResidualTolerance = 1E-08;
OptionsStruct.NoiseScaleFactor = 0.05;
OptionsStruct.PlotLive = false;
OptionsStruct.JobNumber = 0;
OptionsStruct.RunOnGPU = true;
OptionsStruct.SaveData = false;
OptionsStruct.SaveDirectory = './Results/Data_3D/RealTimeDynamics';
options = Helper.convertstruct2cell(OptionsStruct);
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
% Save only final state as initial wavefunction for real-time propagation
mkdir(sprintf(OptionsStruct.SaveDirectory))
save(sprintf(strcat(OptionsStruct.SaveDirectory, '/psi_init.mat'),Params.njob),'psi','Transf','Params','VDk','V');
OptionsStruct.SimulationMode = 'RealTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' | 'EnergyMinimization'
OptionsStruct.EquilibrationTime = 10E-3;
OptionsStruct.QuenchTime = 30E-3;
OptionsStruct.HoldTime = 50E-3;
OptionsStruct.QuenchScatteringLength = false;
OptionsStruct.RotateDipoles = true;
OptionsStruct.FinalScatteringLength = 88;
OptionsStruct.FinalDipolarPolarAngle = deg2rad(40);
OptionsStruct.FinalDipolarAzimuthAngle = deg2rad(0);
OptionsStruct.TimeStepSize = 1E-3; % in s
OptionsStruct.NoiseScaleFactor = 0.010;
OptionsStruct.PlotLive = false;
OptionsStruct.JobNumber = 1;
OptionsStruct.RunOnGPU = true;
OptionsStruct.SaveData = true;
options = Helper.convertstruct2cell(OptionsStruct);
clear OptionsStruct
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
%}

View File

@ -50,6 +50,10 @@ function [psi,V,VDk] = initialize(this,Params,Transf,TransfRad)
else
psi = loadedData.psi;
end
if ~isequal(size(psi), size(VDk))
psi = this.setupWavefunction(Params,Transf);
disp('Computing new initial wavefunction was necessary due to incompatible array sizes.');
end
else
psi = this.setupWavefunction(Params,Transf);
end

View File

@ -1,4 +1,4 @@
function [psi] = propagateWavefunction(this,psi,Params,Transf,VDk,V,t_idx,Observ)
function [psi] = propagateWavefunction(this,psi,Params,Transf,TransfRad,VDk,V,t_idx,Observ)
switch this.SimulationMode
case 'ImaginaryTimeEvolution'

View File

@ -25,6 +25,6 @@ function [Params, Transf, psi,V,VDk] = run(this)
if strcmp(this.SimulationMode, 'RealTimeEvolution')
this.QuenchSettings = this.setupQuenchSettings(Params);
end
[psi] = this.propagateWavefunction(psi,Params,Transf,VDk,V,t_idx,Observ);
[psi] = this.propagateWavefunction(psi,Params,Transf,TransfRad,VDk,V,t_idx,Observ);
end
end