Added script to visualize the 2D grid for the 2D solver and made other appropriate changes.

This commit is contained in:
Karthik 2024-11-14 12:16:37 +01:00
parent 53894fb77b
commit 96f33d3634
5 changed files with 115 additions and 34 deletions

View File

@ -0,0 +1,83 @@
function visualizeSpace2D(Transf)
% Ensure that x and y are vectors (1D) and create a 2D mesh grid from them
[X, Y] = meshgrid(Transf.x, Transf.y); % Create 2D mesh grid from x and y vectors
height = 20;
width = 45;
figure(1)
clf
set(gcf, 'Units', 'centimeters')
set(gcf, 'Position', [2 4 width height])
set(gcf, 'PaperPositionMode', 'auto')
% Plot real space grid
subplot(1,2,1)
hold on
% Plot the grid lines
for i = 1:size(X, 1)
plot(X(i,:), Y(i,:), 'k'); % Plot horizontal grid lines in black
end
for j = 1:size(X, 2)
plot(X(:,j), Y(:,j), 'k'); % Plot vertical grid lines in black
end
axis equal % Ensures equal scaling for both axes
% Set axes labels
xlabel(gca, {'$x / l_o ~ (m)$'}, ...
'Interpreter', 'latex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
ylabel(gca, {'$y / l_o ~ (m)$'}, ...
'Interpreter', 'latex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
title(gca, 'Real Space', ...
'Interpreter', 'tex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
% Plot Fourier space grid in a similar style
[KX, KY] = meshgrid(Transf.kx, Transf.ky); % Create 2D mesh grid from kx and ky
subplot(1,2,2)
hold on
% Plot the grid lines
for i = 1:size(KX, 1)
plot(KX(i,:), KY(i,:), 'k'); % Plot horizontal grid lines
end
for j = 1:size(KX, 2)
plot(KX(:,j), KY(:,j), 'k'); % Plot vertical grid lines
end
axis equal % Ensure equal scaling for both axes
% Set axes labels
xlabel(gca, {'$k_x / l_o ~ (m^{-1})$'}, ...
'Interpreter', 'latex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
ylabel(gca, {'$k_y / l_o ~ (m^{-1})$'}, ...
'Interpreter', 'latex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
title(gca, 'Fourier Space', ...
'Interpreter', 'tex', ...
'FontName', 'Times New Roman', ...
'FontSize', 14, ...
'FontWeight', 'normal', ...
'FontAngle', 'normal')
end

View File

@ -32,12 +32,12 @@ OptionsStruct.SaveDirectory = './Data';
options = Helper.convertstruct2cell(OptionsStruct);
clear OptionsStruct
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap(); % + pot.repulsive_chopstick();
sim = Simulator.DipolarGas(options{:});
pot = Simulator.Potentials(options{:});
sim.Potential = pot.trap(); % + pot.repulsive_chopstick();
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.run();
[Params, Transf, psi, V, VDk] = sim.run();
%% - Plot numerical grid
Plotter.visualizeSpace(Transf)
@ -59,12 +59,12 @@ OptionsStruct.ScatteringLength = 90;
OptionsStruct.TrapFrequencies = [44.97, 10.4, 126.3];
OptionsStruct.NumberOfGridPoints = [128, 256, 128];
OptionsStruct.Dimensions = [50, 120, 150];
OptionsStruct.TimeStepSize = 500E-6; % in s
OptionsStruct.NumberOfTimeSteps = 100; % in s
OptionsStruct.NumberOfGridPoints = [50, 50];
OptionsStruct.Dimensions = [100, 100];
OptionsStruct.TimeStepSize = 1E-3; % in s
OptionsStruct.TimeCutOff = 2E6; % in s
OptionsStruct.EnergyTolerance = 5E-10;
OptionsStruct.ResidualTolerance = 1E-05;
OptionsStruct.ResidualTolerance = 1E-04;
OptionsStruct.JobNumber = 1;
OptionsStruct.RunOnGPU = false;
@ -73,16 +73,15 @@ OptionsStruct.SaveDirectory = './Data';
options = Helper.convertstruct2cell(OptionsStruct);
clear OptionsStruct
solver = Variational2D.DipolarGas(options{:});
solver = Variational2D.DipolarGas(options{:});
%-% Run Solver %-%
[Params, Transf, psi, V, VDk] = solver.run();
%% - Plot numerical grid
Plotter.visualizeSpace(Transf)
%% - Plot trap potential
Plotter.visualizeTrapPotential(sim.Potential,Params,Transf)
Plotter.visualizeSpace2D(Transf)
%% - Plot initial wavefunction
Plotter.visualizeWavefunction(psi,Params,Transf)
Plotter.visualizeWavefunction2D(psi,Params,Transf)
%% - Plot GS wavefunction
Plotter.visualizeGSWavefunction(Params.njob)
Plotter.visualizeGSWavefunction2D(Params.njob)

View File

@ -11,11 +11,11 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
SimulationMode;
TimeStepSize;
NumberOfTimeSteps;
MinimumTimeStepSize;
TimeCutOff;
EnergyTolerance;
ResidualTolerance;
MinimumTimeStepSize;
Calculator;
SimulationParameters;
@ -51,14 +51,14 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
addParameter(p, 'TimeStepSize', 5E-4,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'NumberOfTimeSteps', 2e6,...
addParameter(p, 'MinimumTimeStepSize', 1e-6,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'TimeCutOff', 2e6,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'EnergyTolerance', 1e-10,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'ResidualTolerance', 1e-10,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'MinimumTimeStepSize', 1e-6,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'JobNumber', 1,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'RunOnGPU', false,...
@ -80,11 +80,10 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
this.NumberOfGridPoints = p.Results.NumberOfGridPoints;
this.Dimensions = p.Results.Dimensions;
this.TimeStepSize = p.Results.TimeStepSize;
this.NumberOfTimeSteps = p.Results.NumberOfTimeSteps;
this.MinimumTimeStepSize = p.Results.MinimumTimeStepSize;
this.TimeCutOff = p.Results.TimeCutOff;
this.EnergyTolerance = p.Results.EnergyTolerance;
this.ResidualTolerance = p.Results.ResidualTolerance;
this.MinimumTimeStepSize = p.Results.MinimumTimeStepSize;
this.JobNumber = p.Results.JobNumber;
this.RunOnGPU = p.Results.RunOnGPU;
this.DebugMode = p.Results.DebugMode;
@ -106,12 +105,12 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
function ret = get.TimeStepSize(this)
ret = this.TimeStepSize;
end
function set.NumberOfTimeSteps(this, val)
assert(val <= 2E6, 'Not time efficient to compute for time spans longer than 2E6 seconds!');
this.NumberOfTimeSteps = val;
function set.TimeCutOff(this, val)
assert(val <= 2E6, 'Not efficient to compute for time spans longer than 2E6 seconds!');
this.TimeCutOff = val;
end
function ret = get.NumberOfTimeSteps(this)
ret = this.NumberOfTimeSteps;
function ret = get.TimeCutOff(this)
ret = this.TimeCutOff;
end
function set.NumberOfAtoms(this, val)
assert(val <= 1E6, '!!Not time efficient to compute for atom numbers larger than 1,000,000!!');

View File

@ -27,7 +27,7 @@ function [Params, Transf, psi, V, VDk] = run(this)
E_vs_iter(1) = E_Var([ells(1) nus(1)]);
t_idx = 1; % Start at t = 0;
for nn = 1:Params.SelfConIter
Observ.EVec = []; Observ.NormVec = []; Observ.PCVec = []; Observ.tVecPlot = []; Observ.mucVec = [];
Observ.res_idx = 1;

View File

@ -42,11 +42,11 @@ function [Params] = setupParameters(this)
% Tolerances
Params.Etol = this.EnergyTolerance;
Params.rtol = this.ResidualTolerance;
Params.sim_time_cut_off = this.NumberOfTimeSteps; % sometimes the imaginary time gets a little stuck
% even though the solution is good, this just stops it going on forever
Params.mindt = this.MinimumTimeStepSize; % Minimum size for a time step using adaptive dt
Params.sim_time_cut_off = this.TimeCutOff; % sometimes the imaginary time gets a little stuck
% even though the solution is good, this just stops it going on forever
Params.mindt = this.MinimumTimeStepSize; % Minimum size for a time step using adaptive dt
Params.njob = this.JobNumber;
Params.njob = this.JobNumber;
% ================ Variational method parameters ================ %