diff --git a/Dipolar-Gas-Simulator/+Plotter/plotLive2D.m b/Dipolar-Gas-Simulator/+Plotter/plotLive2D.m new file mode 100644 index 0000000..1e339f4 --- /dev/null +++ b/Dipolar-Gas-Simulator/+Plotter/plotLive2D.m @@ -0,0 +1,67 @@ +function plotLive2D(psi, Params, Transf, Observ) + set(0,'defaulttextInterpreter','latex') + set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex'); + + format long + + % Axes scaling and coordinates in micrometers + x = Transf.x * Params.l0 * 1e6; + y = Transf.y * Params.l0 * 1e6; + + % Compute probability density |psi|^2 + nxy = abs(psi).^2; + nxyScaled = nxy*(Params.add*10^6)^2; + + % Plotting + figure(1); + set(gcf,'Position', [100, 100, 1600, 900]) + clf + + % Plot |psi(x,y)|^2 (density in x and y plane) + ax1 = subplot('Position', [0.05, 0.55, 0.28, 0.4]); + plotxy = pcolor(x,y,nxyScaled'); + set(plotxy, 'EdgeColor', 'none'); + % shading interp; % Smooth shading + clim(ax1); + cbar1 = colorbar; + cbar1.Label.Interpreter = 'latex'; + ylabel(cbar1,'$na_{dd}^2$','FontSize',16,'Rotation',270) + 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) + + % Plot real part of psi in the x-y plane + subplot('Position', [0.36, 0.55, 0.28, 0.4]) + pcolor(x, y, real(psi)'); + shading interp; + colorbar; + xlabel('$x$ [$\mu$m]', 'FontSize', 14); ylabel('$y$ [$\mu$m]', 'FontSize', 14); + title('Re$\{\Psi_{xy}\}$', 'FontSize', 14); + + % Plot imaginary part of psi in the x-y plane + subplot('Position', [0.67, 0.55, 0.28, 0.4]) + pcolor(x, y, imag(psi)'); + shading interp; + colorbar; + xlabel('$x$ [$\mu$m]', 'FontSize', 14); ylabel('$y$ [$\mu$m]', 'FontSize', 14); + title('Im$\{\Psi_{xy}\}$', 'FontSize', 14); + + + % Plot residual (time steps vs -log10(residual)) + subplot('Position', [0.05, 0.05, 0.26, 0.4]); + plot(-log10(Observ.residual), '-b') + ylabel('$-\mathrm{log}_{10}(r)$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14); + title('Residual', 'FontSize', 14); + + % Plot total energy over time + subplot('Position', [0.36, 0.05, 0.26, 0.4]); + plot(Observ.EVec, '-b') + ylabel('$E_{tot}$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14); + title('Total Energy', 'FontSize', 14); + + % Plot chemical potential over time + subplot('Position', [0.67, 0.05, 0.26, 0.4]); + plot(Observ.mucVec, '-b') + ylabel('$\mu$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14); + title('Chemical Potential', 'FontSize', 14); +end \ No newline at end of file diff --git a/Dipolar-Gas-Simulator/+Scripts/run_locally.m b/Dipolar-Gas-Simulator/+Scripts/run_locally.m index f01fb52..5b818c8 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_locally.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_locally.m @@ -73,6 +73,7 @@ OptionsStruct.WidthLowerBound = 5; OptionsStruct.WidthUpperBound = 8; OptionsStruct.WidthCutoff = 1e-3; +OptionsStruct.PlotLive = true; OptionsStruct.JobNumber = 1; OptionsStruct.RunOnGPU = false; OptionsStruct.SaveData = true; diff --git a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/propagateWavefunction.m b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/propagateWavefunction.m index 760957a..7bad664 100644 --- a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/propagateWavefunction.m +++ b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/propagateWavefunction.m @@ -175,7 +175,7 @@ function [psi] = propagateWavefunction(this,psi,Params,Transf,VDk,V,t_idx,Observ Observ.tVecPlot = [Observ.tVecPlot tVal]; Observ.res_idx = Observ.res_idx + 1; - pb.run(' - Job Completed!'); + pb.run(' - Run Completed!'); disp('Saving data...'); save(sprintf('./Data/Run_%03i/TimeEvolution/psi_%i.mat',Params.njob,Observ.res_idx),'psi','muchem','Observ','t_idx'); disp('Save complete!'); diff --git a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/DipolarGas.m b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/DipolarGas.m index 54c5ff8..777e078 100644 --- a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/DipolarGas.m +++ b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/DipolarGas.m @@ -26,7 +26,7 @@ classdef DipolarGas < handle & matlab.mixin.Copyable Calculator; SimulationParameters; - + PlotLive; JobNumber; RunOnGPU; DebugMode; @@ -78,6 +78,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable @(x) assert(isnumeric(x) && isscalar(x) && (x > 0))); addParameter(p, 'JobNumber', 1,... @(x) assert(isnumeric(x) && isscalar(x) && (x > 0))); + addParameter(p, 'PlotLive', false,... + @islogical); addParameter(p, 'RunOnGPU', false,... @islogical); addParameter(p, 'DebugMode', false,... @@ -108,7 +110,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable this.WidthLowerBound = p.Results.WidthUpperBound; this.WidthUpperBound = p.Results.WidthUpperBound; this.WidthCutoff = p.Results.WidthCutoff; - + + this.PlotLive = p.Results.PlotLive; this.JobNumber = p.Results.JobNumber; this.RunOnGPU = p.Results.RunOnGPU; this.DebugMode = p.Results.DebugMode; diff --git a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/propagateWavefunction.m b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/propagateWavefunction.m index dcb0d86..10ad1f9 100644 --- a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/propagateWavefunction.m +++ b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/propagateWavefunction.m @@ -21,6 +21,11 @@ function [psi, Observ] = propagateWavefunction(this, psi, Params, VParams, Trans % Normalized residuals res = this.Calculator.calculateNormalizedResiduals(psi,Params,VParams,Transf,VDk,V,muchem); Observ.residual = [Observ.residual res]; + + if this.PlotLive + Plotter.plotLive2D(psi,Params,Transf,Observ) + drawnow + end g_eff = Params.gs * (1/(sqrt(2*pi)*VParams.ell)); gamma_eff = Params.gammaQF * (sqrt(2/5)/(pi^(3/4)*VParams.ell^(3/2))); @@ -55,7 +60,8 @@ function [psi, Observ] = propagateWavefunction(this, psi, Params, VParams, Trans muchem = this.Calculator.calculateChemicalPotential(psi,Params,VParams,Transf,VDk,V); - if mod(t_idx,1000) == 0 + %Plotting loop + if mod(t_idx,500) == 0 % Change in Energy E = this.Calculator.calculateTotalEnergy(psi,Params,VParams,Transf,VDk,V); @@ -69,6 +75,13 @@ function [psi, Observ] = propagateWavefunction(this, psi, Params, VParams, Trans res = this.Calculator.calculateNormalizedResiduals(psi,Params,VParams,Transf,VDk,V,muchem); Observ.residual = [Observ.residual res]; Observ.res_idx = Observ.res_idx + 1; + + % Plotting + if this.PlotLive + Plotter.plotLive2D(psi,Params,Transf,Observ) + drawnow + end + % %Adaptive time step -- Careful, this can quickly get out of control relres = abs(Observ.residual(Observ.res_idx)-Observ.residual(Observ.res_idx-1))/Observ.residual(Observ.res_idx); @@ -109,6 +122,6 @@ function [psi, Observ] = propagateWavefunction(this, psi, Params, VParams, Trans % Chemical potential Observ.mucVec = [Observ.mucVec muchem]; - pb.run(' - Job Completed!'); + pb.run(' - Run Completed!'); clear pb.run end \ No newline at end of file diff --git a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m index 253203f..0e64e1a 100644 --- a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m +++ b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m @@ -62,6 +62,16 @@ function [Params, Transf, psi, V, VDk] = run(this) save(sprintf('./Data/Run_%03i/psi_gs_%i.mat',Params.njob),'psi','Observ','Transf','Params','VDk','V','VParams'); + %Plotting + if this.PlotLive + figure(2); + plot(ells,E_vs_iter,'LineStyle','none','Marker','o','MarkerSize',3,'Color','b','MarkerFaceColor','b') + xlabel('$\ell$', 'FontSize', 14) + ylabel('$E_{var}$', 'FontSize', 14) + title('Variational Energy', 'FontSize', 14); + drawnow + end + if relelldiff < Params.ellcutoff break end