From 37de6a6353ffba9a046f395021adfde10d77dcd9 Mon Sep 17 00:00:00 2001 From: Karthik Chandrashekara Date: Tue, 19 Nov 2024 18:46:47 +0100 Subject: [PATCH] Cosmetic changes/additions, analysis script for variational solver, added save feature for all ells and E_vs_iter. --- Dipolar-Gas-Simulator/+Scripts/analyze.m | 50 ------------- Dipolar-Gas-Simulator/+Scripts/analyzeRun2D.m | 72 +++++++++++++++++++ Dipolar-Gas-Simulator/+Scripts/run_locally.m | 5 +- .../+Scripts/run_on_cluster.m | 5 +- .../+VariationalSolver2D/@DipolarGas/run.m | 6 +- 5 files changed, 81 insertions(+), 57 deletions(-) delete mode 100644 Dipolar-Gas-Simulator/+Scripts/analyze.m create mode 100644 Dipolar-Gas-Simulator/+Scripts/analyzeRun2D.m diff --git a/Dipolar-Gas-Simulator/+Scripts/analyze.m b/Dipolar-Gas-Simulator/+Scripts/analyze.m deleted file mode 100644 index df85ab4..0000000 --- a/Dipolar-Gas-Simulator/+Scripts/analyze.m +++ /dev/null @@ -1,50 +0,0 @@ - set(0,'defaulttextInterpreter','latex') - set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex'); - format long - - runIdx = 6; - - load(sprintf('./Data/Run_%03i/psi_gs.mat',runIdx),'psi','muchem','Observ','t_idx','Transf','Params','VDk','V'); - - x = Transf.x*Params.l0*1e6; - y = Transf.y*Params.l0*1e6; - z = Transf.z*Params.l0*1e6; - %percentcomplete = linspace(0,1,Params.cut_off/200); - - dx = x(2)-x(1); dy = y(2)-y(1); dz = z(2)-z(1); - %Plotting - subplot(2,3,1) - n = abs(psi).^2; - nxz = squeeze(trapz(n*dy,2)); - nyz = squeeze(trapz(n*dx,1)); - nxy = squeeze(trapz(n*dz,3)); - - plotxz = pcolor(x,z,nxz'); - set(plotxz, 'EdgeColor', 'none'); - xlabel('$x$ [$\mu$m]'); ylabel('$z$ [$\mu$m]'); - - subplot(2,3,2) - plotyz = pcolor(y,z,nyz'); - set(plotyz, 'EdgeColor', 'none'); - xlabel('$y$ [$\mu$m]'); ylabel('$z$ [$\mu$m]'); - - subplot(2,3,3) - plotxy = pcolor(x,y,nxy'); - set(plotxy, 'EdgeColor', 'none'); - xlabel('$x$ [$\mu$m]'); ylabel('$y$ [$\mu$m]'); - - subplot(2,3,4) - plot(-log10(Observ.residual),'-b') - ylabel('$-\mathrm{log}_{10}(r)$'); xlabel('steps'); - - subplot(2,3,5) - plot(Observ.EVec,'-b') - ylabel('$E$'); xlabel('steps'); - - subplot(2,3,6) - plot(Observ.mucVec,'-b') - ylabel('$\mu$'); xlabel('steps'); -% xlim([0,1]); ylim([0,8]); -% xlim([0,1]); ylim([0,8]); - - Ecomp = energy_components(psi,Params,Transf,VDk,V); diff --git a/Dipolar-Gas-Simulator/+Scripts/analyzeRun2D.m b/Dipolar-Gas-Simulator/+Scripts/analyzeRun2D.m new file mode 100644 index 0000000..e94cf27 --- /dev/null +++ b/Dipolar-Gas-Simulator/+Scripts/analyzeRun2D.m @@ -0,0 +1,72 @@ +function analyzeRun2D(run_index) + set(0,'defaulttextInterpreter','latex') + set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex'); + + folder_path = './Data'; + + % Load data + Data = load(sprintf(horzcat(folder_path, '/Run_%03i/psi_gs.mat'),run_index),'psi','Observ','Transf','Params','VParams'); + + Params = Data.Params; + Transf = Data.Transf; + Observ = Data.Observ; + + if isgpuarray(Data.psi) + psi = gather(Data.psi); + else + psi = Data.psi; + end + + if isgpuarray(Data.Observ.residual) + Observ.residual = gather(Data.Observ.residual); + else + Observ.residual = Data.Observ.residual; + end + + % Set long format for output + format long + + % Coordinates in micrometers + x = Transf.x * Params.l0 * 1e6; + y = Transf.y * Params.l0 * 1e6; + + % Plotting + figure('Position', [100, 100, 1600, 900]); + clf + + % Compute probability density |psi|^2 + n = abs(psi).^2; + + % Plot |psi(x,y)|^2 (density in x and y plane) + subplot('Position', [0.05, 0.55, 0.28, 0.4]) + pcolor(x, y, n'); + shading interp; + colorbar; + xlabel('$x$ [$\mu$m]', 'FontSize', 14); ylabel('$y$ [$\mu$m]', 'FontSize', 14); + title('$|\Psi_{xy}|^2$', 'FontSize', 14); + + % Plot residual (time steps vs -log10(residual)) + subplot('Position', [0.36, 0.55, 0.28, 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.67, 0.55, 0.28, 0.4]) + plot(Observ.EVec, '-b') + ylabel('$E$', 'FontSize', 14); xlabel('Time steps', 'FontSize', 14); + title('Total Energy', 'FontSize', 14); + + % Plot chemical potential over time + subplot('Position', [0.05, 0.05, 0.26, 0.4]); + 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); + + subplot('Position', [0.36, 0.05, 0.26, 0.4]); + plot(VParams.ells,VParams.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); +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 8beb925..bc48203 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_locally.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_locally.m @@ -51,16 +51,15 @@ Plotter.visualizeGSWavefunction(Params.njob) %% % To reproduce results from the Blair Blakie paper: - +% (n*add^2, as/add) % Critical point: (0.0978, 0.784); Triangular phase: (0.0959, 0.750); Stripe phase: (0.144, 0.765); Honeycomb phase: (0.192, 0.780) -% N = ((nadd^2)/Params.add^2) * (Params.Lx *1E-6)^2 +% N = ((n*add^2)/Params.add^2) * (Params.Lx *1E-6)^2 % Critical point: N = 2.0427e+07; Triangular phase: N = 2.0030e+07; Stripe phase: N = 3.0077e+07; Honeycomb phase: N = 4.0102e+07 for dimensions fixed to 100 % as = ((as/add)*Params.add)/Params.a0 % Critical point: 102.5133; Triangular phase: 98.0676; Stripe phase: 100.0289; Honeycomb phase: 101.9903 - %% - Create Variational2D and Calculator object with specified options OptionsStruct = struct; diff --git a/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m b/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m index 6bf5d97..d5905a9 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m @@ -1,16 +1,15 @@ %% % To reproduce results from the Blair Blakie paper: - +% (n*add^2, as/add) % Critical point: (0.0978, 0.784); Triangular phase: (0.0959, 0.750); Stripe phase: (0.144, 0.765); Honeycomb phase: (0.192, 0.780) -% N = ((nadd^2)/Params.add^2) * (Params.Lx *1E-6)^2 +% N = ((n*add^2)/Params.add^2) * (Params.Lx *1E-6)^2 % Critical point: N = 2.0427e+07; Triangular phase: N = 2.0030e+07; Stripe phase: N = 3.0077e+07; Honeycomb phase: N = 4.0102e+07 for dimensions fixed to 100 % as = ((as/add)*Params.add)/Params.a0 % Critical point: 102.5133; Triangular phase: 98.0676; Stripe phase: 100.0289; Honeycomb phase: 101.9903 - %% - Create Variational2D and Calculator object with specified options OptionsStruct = struct; diff --git a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m index 643201f..c8ff597 100644 --- a/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m +++ b/Dipolar-Gas-Simulator/+VariationalSolver2D/@DipolarGas/run.m @@ -59,7 +59,7 @@ function [Params, Transf, psi, V, VDk] = run(this) ells = [ells VParams.ell]; relelldiff = abs(ells(nn+1)-ells(nn))/ells(nn); E_vs_iter = [E_vs_iter E_Var(VParams.ell)]; - + save(sprintf(strcat(this.SaveDirectory, '/Run_%03i/psi_gs_%i.mat'),Params.njob),'psi','Observ','Transf','Params','VDk','V','VParams'); %Plotting @@ -76,6 +76,10 @@ function [Params, Transf, psi, V, VDk] = run(this) break end end + + VParams.ells = ells; + VParams.E_vs_iter = E_vs_iter; + fprintf('\n') disp('Saving data...'); save(sprintf(strcat(this.SaveDirectory, '/Run_%03i/psi_gs.mat'),Params.njob),'psi','Observ','Transf','Params','VDk','V','VParams');