Latest working version.

This commit is contained in:
Karthik 2024-06-17 12:14:15 +02:00
parent 570995f3f5
commit 6bb354de7a
17 changed files with 605 additions and 591 deletions

View File

@ -28,11 +28,10 @@ options = Helper.convertstruct2cell(OptionsStruct)
clear OptionsStruct clear OptionsStruct
sim = Simulator.DipolarGas(options{:}); sim = Simulator.DipolarGas(options{:});
calc = Simulator.Calculator(options{:});
pot = Simulator.Potentials(options{:}); pot = Simulator.Potentials(options{:});
%-% Run Simulation %-% %-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.runSimulation(calc); [Params, Transf, psi, V, VDk] = sim.runSimulation();
%% - Plot numerical grid %% - Plot numerical grid
Plotter.visualizeSpace(Transf) Plotter.visualizeSpace(Transf)

View File

@ -27,13 +27,23 @@ classdef Calculator < handle & matlab.mixin.Copyable
methods methods
function this = Calculator(varargin) function this = Calculator(varargin)
this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential;
this.EnergyComponents = this.CalculatorDefaults.EnergyComponents; p = inputParser;
this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals; p.KeepUnmatched = true;
this.OrderParameter = this.CalculatorDefaults.OrderParameter; addParameter(p, 'CutoffType', this.CalculatorDefaults.CutoffType,...
this.PhaseCoherence = this.CalculatorDefaults.PhaseCoherence; @(x) any(strcmpi(x,{'Cylindrical','CylindricalInfiniteZ', 'Spherical'})));
this.TotalEnergy = this.CalculatorDefaults.TotalEnergy;
this.CutoffType = this.CalculatorDefaults.CutoffType; p.parse(varargin{:});
this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential;
this.EnergyComponents = this.CalculatorDefaults.EnergyComponents;
this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals;
this.OrderParameter = this.CalculatorDefaults.OrderParameter;
this.PhaseCoherence = this.CalculatorDefaults.PhaseCoherence;
this.TotalEnergy = this.CalculatorDefaults.TotalEnergy;
this.CutoffType = p.Results.CutoffType;
this.CalculatorDefaults.CutoffType = this.CutoffType;
end end
function restoreDefaults(this) function restoreDefaults(this)

View File

@ -1,28 +1,29 @@
function muchem = calculateChemicalPotential(psi,Params,Transf,VDk,V) function muchem = calculateChemicalPotential(~,psi,Params,Transf,VDk,V)
%Parameters %Parameters
normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi); normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi);
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
% DDIs % DDIs
frho=fftn(abs(psi).^2); frho=fftn(abs(psi).^2);
Phi=real(ifftn(frho.*VDk)); Phi=real(ifftn(frho.*VDk));
Eddi = (Params.gdd*Phi.*abs(psi).^2); Eddi = (Params.gdd*Phi.*abs(psi).^2);
%Kinetic energy %Kinetic energy
Ekin = KEop.*abs(fftn(psi)*normfac).^2; Ekin = KEop.*abs(fftn(psi)*normfac).^2;
Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3; Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3;
%Potential energy %Potential energy
Epot = V.*abs(psi).^2; Epot = V.*abs(psi).^2;
%Contact interactions %Contact interactions
Eint = Params.gs*abs(psi).^4; Eint = Params.gs*abs(psi).^4;
%Quantum fluctuations %Quantum fluctuations
Eqf = Params.gammaQF*abs(psi).^5; Eqf = Params.gammaQF*abs(psi).^5;
%Total energy %Total energy
muchem = Ekin + trapz(Epot(:) + Eint(:) + Eddi(:) + Eqf(:))*Transf.dx*Transf.dy*Transf.dz; % muchem = Ekin + trapz(Epot(:) + Eint(:) + Eddi(:) + Eqf(:))*Transf.dx*Transf.dy*Transf.dz; %
muchem = muchem / Params.N; muchem = muchem / Params.N;
end

View File

@ -1,35 +1,35 @@
function E = calculateEnergyComponents(psi,Params,Transf,VDk,V) function E = calculateEnergyComponents(~,psi,Params,Transf,VDk,V)
%Parameters %Parameters
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi); normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi);
% DDIs % DDIs
frho = fftn(abs(psi).^2); frho = fftn(abs(psi).^2);
Phi = real(ifftn(frho.*VDk)); Phi = real(ifftn(frho.*VDk));
Eddi = 0.5*Params.gdd*Phi.*abs(psi).^2; Eddi = 0.5*Params.gdd*Phi.*abs(psi).^2;
E.Eddi = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz; E.Eddi = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz;
% EddiTot = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz; % EddiTot = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz;
%Kinetic energy %Kinetic energy
% psik = ifftshift(fftn(fftshift(psi)))*normfac; % psik = ifftshift(fftn(fftshift(psi)))*normfac;
Ekin = KEop.*abs(fftn(psi)*normfac).^2; Ekin = KEop.*abs(fftn(psi)*normfac).^2;
E.Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3; E.Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3;
% Potential energy % Potential energy
Epot = V.*abs(psi).^2; Epot = V.*abs(psi).^2;
E.Epot = trapz(Epot(:))*Transf.dx*Transf.dy*Transf.dz; E.Epot = trapz(Epot(:))*Transf.dx*Transf.dy*Transf.dz;
%Contact interactions %Contact interactions
Eint = 0.5*Params.gs*abs(psi).^4; Eint = 0.5*Params.gs*abs(psi).^4;
E.Eint = trapz(Eint(:))*Transf.dx*Transf.dy*Transf.dz; E.Eint = trapz(Eint(:))*Transf.dx*Transf.dy*Transf.dz;
%Quantum fluctuations %Quantum fluctuations
Eqf = 0.4*Params.gammaQF*abs(psi).^5; Eqf = 0.4*Params.gammaQF*abs(psi).^5;
E.Eqf = trapz(Eqf(:))*Transf.dx*Transf.dy*Transf.dz; E.Eqf = trapz(Eqf(:))*Transf.dx*Transf.dy*Transf.dz;
% plot(Transf.x,abs(psi(:,end/2,end/2+1)).^2) end

View File

@ -1,24 +1,25 @@
function res = calculateNormalizedResiduals(psi,Params,Transf,VDk,V,muchem) function res = calculateNormalizedResiduals(~,psi,Params,Transf,VDk,V,muchem)
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
% DDIs % DDIs
frho=fftn(abs(psi).^2); frho=fftn(abs(psi).^2);
Phi=real(ifftn(frho.*VDk)); Phi=real(ifftn(frho.*VDk));
Eddi = Params.gdd*Phi.*psi; Eddi = Params.gdd*Phi.*psi;
%Kinetic energy %Kinetic energy
Ekin = ifftn(KEop.*fftn(psi)); Ekin = ifftn(KEop.*fftn(psi));
%Potential energy %Potential energy
Epot = V.*psi; Epot = V.*psi;
%Contact interactions %Contact interactions
Eint = Params.gs*abs(psi).^2.*psi; Eint = Params.gs*abs(psi).^2.*psi;
%Quantum fluctuations %Quantum fluctuations
Eqf = Params.gammaQF*abs(psi).^3.*psi; Eqf = Params.gammaQF*abs(psi).^3.*psi;
%Total energy %Total energy
res = trapz(abs(Ekin(:) + Epot(:) + Eint(:) + Eddi(:) + Eqf(:) - muchem*psi(:))*Transf.dx*Transf.dy*Transf.dz)/trapz(abs(muchem*psi(:))*Transf.dx*Transf.dy*Transf.dz); res = trapz(abs(Ekin(:) + Epot(:) + Eint(:) + Eddi(:) + Eqf(:) - muchem*psi(:))*Transf.dx*Transf.dy*Transf.dz)/trapz(abs(muchem*psi(:))*Transf.dx*Transf.dy*Transf.dz);
end

View File

@ -1,39 +1,39 @@
function VDkSemi = calculateNumericalHankelTransform(this,kr,kz,Rmax,Zmax,Nr) function VDkSemi = calculateNumericalHankelTransform(~,kr,kz,Rmax,Zmax,Nr)
% accuracy inputs for numerical integration
if(nargin==5)
Nr = 5e4;
end
Nz = 64;
farRmultiple = 2000;
% midpoint grids for the integration over 0<z<Zmax, Rmax<r<farRmultiple*Rmax (i.e. starts at Rmax)
dr=(farRmultiple-1)*Rmax/Nr;
r = ((1:Nr)'-0.5)*dr+Rmax;
dz=Zmax/Nz;
z = ((1:Nz)-0.5)*dz;
[R, Z] = ndgrid(r,z);
Rsq = R.^2 + Z.^2;
% real space interaction to be transformed
igrandbase = (1 - 3*Z.^2./Rsq)./Rsq.^(3/2);
% do the Hankel/Fourier-Bessel transform numerically
% prestore to ensure each besselj is only calculated once
% cell is faster than (:,:,krn) slicing
Nkr = numel(kr);
besselr = cell(Nkr,1);
for krn = 1:Nkr
besselr{krn} = repmat(r.*besselj(0,kr(krn)*r),1,Nz);
end
VDkSemi = zeros([Nkr,numel(kz)]);
for kzn = 1:numel(kz)
igrandbasez = repmat(cos(kz(kzn)*z),Nr,1) .* igrandbase;
for krn = 1:Nkr
igrand = igrandbasez.*besselr{krn};
VDkSemi(krn,kzn) = VDkSemi(krn,kzn) - sum(igrand(:))*dz*dr;
end
% accuracy inputs for numerical integration
if(nargin==5)
Nr = 5e4;
end
Nz = 64;
farRmultiple = 2000;
% midpoint grids for the integration over 0<z<Zmax, Rmax<r<farRmultiple*Rmax (i.e. starts at Rmax)
dr=(farRmultiple-1)*Rmax/Nr;
r = ((1:Nr)'-0.5)*dr+Rmax;
dz=Zmax/Nz;
z = ((1:Nz)-0.5)*dz;
[R, Z] = ndgrid(r,z);
Rsq = R.^2 + Z.^2;
% real space interaction to be transformed
igrandbase = (1 - 3*Z.^2./Rsq)./Rsq.^(3/2);
% do the Hankel/Fourier-Bessel transform numerically
% prestore to ensure each besselj is only calculated once
% cell is faster than (:,:,krn) slicing
Nkr = numel(kr);
besselr = cell(Nkr,1);
for krn = 1:Nkr
besselr{krn} = repmat(r.*besselj(0,kr(krn)*r),1,Nz);
end
VDkSemi = zeros([Nkr,numel(kz)]);
for kzn = 1:numel(kz)
igrandbasez = repmat(cos(kz(kzn)*z),Nr,1) .* igrandbase;
for krn = 1:Nkr
igrand = igrandbasez.*besselr{krn};
VDkSemi(krn,kzn) = VDkSemi(krn,kzn) - sum(igrand(:))*dz*dr;
end
end
end end

View File

@ -1,4 +1,4 @@
function [m_Order] = calculateOrderParameter(psi,Transf,Params,VDk,V,T,muchem) function [m_Order] = calculateOrderParameter(~,psi,Transf,Params,VDk,V,T,muchem)
NumRealiz = 100; NumRealiz = 100;

View File

@ -1,18 +1,19 @@
function [PhaseC] = calculatePhaseCoherence(psi,Transf,Params) function [PhaseC] = calculatePhaseCoherence(~,psi,Transf,Params)
norm = sum(sum(sum(abs(psi).^2,1),2),3)*Transf.dx*Transf.dy*Transf.dz; norm = sum(sum(sum(abs(psi).^2,1),2),3)*Transf.dx*Transf.dy*Transf.dz;
psi = psi/sqrt(norm); psi = psi/sqrt(norm);
NumGlobalShifts = 800; NumGlobalShifts = 800;
betas = []; phishift = []; betas = []; phishift = [];
for jj = 1:NumGlobalShifts for jj = 1:NumGlobalShifts
phishift(jj) = -pi + 2*pi*(jj-1)/NumGlobalShifts; phishift(jj) = -pi + 2*pi*(jj-1)/NumGlobalShifts;
betas(jj) = sum(sum(sum(abs(angle(psi*exp(-1i*phishift(jj)))).*abs(psi).^2))); betas(jj) = sum(sum(sum(abs(angle(psi*exp(-1i*phishift(jj)))).*abs(psi).^2)));
end
[minbeta,minidx] = min(betas);
psi = psi*exp(-1i*phishift(minidx));
phi = angle(psi);
avgphi = sum(sum(sum(phi.*abs(psi).^2,1),2),3)*Transf.dx*Transf.dy*Transf.dz;
PhaseC = sum(sum(sum(abs(angle(psi)-avgphi).*abs(psi).^2)))*Transf.dx*Transf.dy*Transf.dz;
end end
[minbeta,minidx] = min(betas);
psi = psi*exp(-1i*phishift(minidx));
phi = angle(psi);
avgphi = sum(sum(sum(phi.*abs(psi).^2,1),2),3)*Transf.dx*Transf.dy*Transf.dz;
PhaseC = sum(sum(sum(abs(angle(psi)-avgphi).*abs(psi).^2)))*Transf.dx*Transf.dy*Transf.dz;

View File

@ -1,31 +1,32 @@
function E = calculateTotalEnergy(psi,Params,Transf,VDk,V) function E = calculateTotalEnergy(~,psi,Params,Transf,VDk,V)
%Parameters %Parameters
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi); normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi);
% DDIs % DDIs
frho = fftn(abs(psi).^2); frho = fftn(abs(psi).^2);
Phi = real(ifftn(frho.*VDk)); Phi = real(ifftn(frho.*VDk));
Eddi = 0.5*Params.gdd*Phi.*abs(psi).^2; Eddi = 0.5*Params.gdd*Phi.*abs(psi).^2;
% EddiTot = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz; % EddiTot = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz;
%Kinetic energy %Kinetic energy
% psik = ifftshift(fftn(fftshift(psi)))*normfac; % psik = ifftshift(fftn(fftshift(psi)))*normfac;
Ekin = KEop.*abs(fftn(psi)*normfac).^2; Ekin = KEop.*abs(fftn(psi)*normfac).^2;
Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3; Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3;
% Potential energy % Potential energy
Epot = V.*abs(psi).^2; Epot = V.*abs(psi).^2;
%Contact interactions %Contact interactions
Eint = 0.5*Params.gs*abs(psi).^4; Eint = 0.5*Params.gs*abs(psi).^4;
%Quantum fluctuations %Quantum fluctuations
Eqf = 0.4*Params.gammaQF*abs(psi).^5; Eqf = 0.4*Params.gammaQF*abs(psi).^5;
E = Ekin + trapz(Epot(:) + Eint(:) + Eddi(:) + Eqf(:))*Transf.dx*Transf.dy*Transf.dz; E = Ekin + trapz(Epot(:) + Eint(:) + Eddi(:) + Eqf(:))*Transf.dx*Transf.dy*Transf.dz;
end

View File

@ -15,6 +15,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
EnergyTolerance; EnergyTolerance;
MinimumTimeStep; MinimumTimeStep;
Calculator;
%Flags %Flags
DebugMode; DebugMode;
@ -46,6 +48,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0))); @(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
addParameter(p, 'SimulationMode', 'ImaginaryTimeEvolution',... addParameter(p, 'SimulationMode', 'ImaginaryTimeEvolution',...
@(x) any(strcmpi(x,{'ImaginaryTimeEvolution','RealTimeEvolution'}))); @(x) any(strcmpi(x,{'ImaginaryTimeEvolution','RealTimeEvolution'})));
addParameter(p, 'CutoffType', 'Cylindrical',...
@(x) any(strcmpi(x,{'Cylindrical','CylindricalInfiniteZ', 'Spherical'})));
addParameter(p, 'TimeStep', 5E-4,... addParameter(p, 'TimeStep', 5E-4,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0))); @(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'SimulationTime', 2e6,... addParameter(p, 'SimulationTime', 2e6,...
@ -81,6 +85,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
this.DoSave = p.Results.SaveData; this.DoSave = p.Results.SaveData;
this.SaveDirectory = p.Results.SaveDirectory; this.SaveDirectory = p.Results.SaveDirectory;
this.Calculator = Simulator.Calculator('CutoffType', p.Results.CutoffType);
switch this.SimulationMode switch this.SimulationMode
case "ImaginaryTimeEvolution" case "ImaginaryTimeEvolution"
% Development In progress % Development In progress

View File

@ -1,22 +1,20 @@
function [psi,V,VDk] = initialize(this,calcObj,Params,Transf,TransfRad) function [psi,V,VDk] = initialize(this,Params,Transf,TransfRad)
format long
X = Transf.X; Y = Transf.Y; Z = Transf.Z;
format long % == Trap potential == %
X = Transf.X; Y = Transf.Y; Z = Transf.Z; V = 0.5*(Params.gx.*X.^2+Params.gy.*Y.^2+Params.gz*Z.^2);
% == Trap potential == % % == Calculating the DDIs == %
V = 0.5*(Params.gx.*X.^2+Params.gy.*Y.^2+Params.gz*Z.^2); if isfile(strcat(this.SaveDirectory, '/VDk_M.mat'))
VDk = load(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')));
% == Calculating the DDIs == % VDk = VDk.VDk;
if isfile(strcat(this.SaveDirectory, '/VDk_M.mat')) else
VDk = load(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat'))); VDk = this.Calculator.calculateVDCutoff(Params,Transf,TransfRad);
VDk = VDk.VDk; save(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')),'VDk');
else end
VDk = calcObj.calculateVDCutoff(Params,Transf,TransfRad); fprintf('Computed and saved DDI potential in Fourier space with %s cutoff.', this.Calculator.CutoffType)
save(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')),'VDk');
end
fprintf('Computed and saved DDI potential in Fourier space with %s cutoff.', calcObj.CutoffType)
% == Setting up the initial wavefunction == %
psi = this.setupWavefunction(Params,Transf);
% == Setting up the initial wavefunction == %
psi = this.setupWavefunction(Params,Transf);
end end

View File

@ -1,4 +1,4 @@
function [Params, Transf, psi,V,VDk] = runSimulation(this,calcObj) function [Params, Transf, psi,V,VDk] = runSimulation(this)
% --- Obtain simulation parameters --- % --- Obtain simulation parameters ---
[Params] = this.setupParameters(); [Params] = this.setupParameters();
@ -9,15 +9,15 @@ function [Params, Transf, psi,V,VDk] = runSimulation(this,calcObj)
% --- Initialize --- % --- Initialize ---
mkdir(sprintf(this.SaveDirectory)) mkdir(sprintf(this.SaveDirectory))
[psi,V,VDk] = this.initialize(calcObj,Params,Transf,TransfRad); [psi,V,VDk] = this.initialize(Params,Transf,TransfRad);
Observ.EVec = []; Observ.NormVec = []; Observ.PCVec = []; Observ.tVecPlot = []; Observ.mucVec = []; Observ.EVec = []; Observ.NormVec = []; Observ.PCVec = []; Observ.tVecPlot = []; Observ.mucVec = [];
t_idx = 1; %Start at t = 0; t_idx = 1; %Start at t = 0;
Observ.res_idx = 1; Observ.res_idx = 1;
% --- Job Settings --- % --- Job Settings ---
% njob = 6; njob = 6;
% mkdir(sprintf('./Data/Run_%03i',njob)) mkdir(sprintf('./Data/Run_%03i',njob))
% --- Run Simulation --- % --- Run Simulation ---
% [psi] = this.solver(psi,Params,Transf,VDk,V,njob,t_idx,Observ); % [psi] = this.solver(psi,Params,Transf,VDk,V,njob,t_idx,Observ);

View File

@ -1,92 +1,91 @@
function [Params] = setupParameters(this) function [Params] = setupParameters(this)
CONSTANTS = Helper.PhysicsConstants;
hbar = CONSTANTS.PlanckConstantReduced; % [J.s]
kbol = CONSTANTS.BoltzmannConstant; % [J/K]
mu0 = CONSTANTS.VacuumPermeability; % [N/A^2]
muB = CONSTANTS.BohrMagneton; % [J/T]
a0 = CONSTANTS.BohrRadius; % [m]
m0 = CONSTANTS.AtomicMassUnit; % [kg]
w0 = 2*pi*100; % Angular frequency unit [s^-1]
mu0factor = 0.3049584233607396; % =(m0/me)*pi*alpha^2 -- me=mass of electron, alpha=fine struct. const.
% mu0=mu0factor *hbar^2*a0/(m0*muB^2)
% Number of points in each direction
Params.Nx = this.NumberOfGridPoints(1);
Params.Ny = this.NumberOfGridPoints(2);
Params.Nz = this.NumberOfGridPoints(3);
CONSTANTS = Helper.PhysicsConstants; % Dimensions (in units of l0)
hbar = CONSTANTS.PlanckConstantReduced; % [J.s] Params.Lx = this.Dimensions(1);
kbol = CONSTANTS.BoltzmannConstant; % [J/K] Params.Ly = this.Dimensions(2);
mu0 = CONSTANTS.VacuumPermeability; % [N/A^2] Params.Lz = this.Dimensions(3);
muB = CONSTANTS.BohrMagneton; % [J/T]
a0 = CONSTANTS.BohrRadius; % [m]
m0 = CONSTANTS.AtomicMassUnit; % [kg]
w0 = 2*pi*100; % Angular frequency unit [s^-1]
mu0factor = 0.3049584233607396; % =(m0/me)*pi*alpha^2 -- me=mass of electron, alpha=fine struct. const.
% mu0=mu0factor *hbar^2*a0/(m0*muB^2)
% Number of points in each direction
Params.Nx = this.NumberOfGridPoints(1);
Params.Ny = this.NumberOfGridPoints(2);
Params.Nz = this.NumberOfGridPoints(3);
% Dimensions (in units of l0) % Masses
Params.Lx = this.Dimensions(1); Params.m = CONSTANTS.Dy164Mass;
Params.Ly = this.Dimensions(2); l0 = sqrt(hbar/(Params.m*w0)); % Defining a harmonic oscillator length
Params.Lz = this.Dimensions(3);
% Masses % Atom numbers
Params.m = CONSTANTS.Dy164Mass; Params.N = this.NumberOfAtoms;
l0 = sqrt(hbar/(Params.m*w0)); % Defining a harmonic oscillator length
% Atom numbers % Dipole angle
Params.N = this.NumberOfAtoms; Params.theta = this.DipolarPolarAngle; % pi/2 dipoles along x, theta=0 dipoles along z
Params.phi = this.DipolarAzimuthAngle;
% Dipole angle % Dipole lengths (units of muB)
Params.theta = this.DipolarPolarAngle; % pi/2 dipoles along x, theta=0 dipoles along z Params.mu = CONSTANTS.DyMagneticMoment;
Params.phi = this.DipolarAzimuthAngle;
% Dipole lengths (units of muB) % Scattering lengths
Params.mu = CONSTANTS.DyMagneticMoment; Params.as = this.ScatteringLength*a0;
% Scattering lengths % Trapping frequencies
Params.as = this.ScatteringLength*a0; Params.wx = 2*pi*this.TrapFrequencies(1);
Params.wy = 2*pi*this.TrapFrequencies(2);
Params.wz = 2*pi*this.TrapFrequencies(3);
% Trapping frequencies % Stochastic GPE
Params.wx = 2*pi*this.TrapFrequencies(1); Params.gamma_S = 7.5*10^(-3); % gamma for the stochastic GPE
Params.wy = 2*pi*this.TrapFrequencies(2); Params.muchem = 12.64*Params.wz/w0; % fixing the chemical potential for the stochastic GPE
Params.wz = 2*pi*this.TrapFrequencies(3);
% Stochastic GPE Params.Etol = this.EnergyTolerance; % Tolerances
Params.gamma_S = 7.5*10^(-3); % gamma for the stochastic GPE Params.cut_off = this.SimulationTime; % sometimes the imaginary time gets a little stuck
Params.muchem = 12.64*Params.wz/w0; % fixing the chemical potential for the stochastic GPE % even though the solution is good, this just stops it going on forever
Params.mindt = this.MinimumTimeStep; % Minimum size for a time step using adaptive dt
Params.Etol = this.EnergyTolerance; % Tolerances % ================ Parameters defined by those above ================ %
Params.cut_off = this.SimulationTime; % sometimes the imaginary time gets a little stuck
% even though the solution is good, this just stops it going on forever
Params.mindt = this.MinimumTimeStep; % Minimum size for a time step using adaptive dt
% ================ Parameters defined by those above ================ % % Contact interaction strength (units of l0/m)
Params.gs = 4*pi*Params.as/l0;
% Contact interaction strength (units of l0/m) % Dipole lengths
Params.gs = 4*pi*Params.as/l0; Params.add = mu0*Params.mu^2*Params.m/(12*pi*hbar^2);
% Dipole lengths % DDI strength
Params.add = mu0*Params.mu^2*Params.m/(12*pi*hbar^2); Params.gdd = 12*pi*Params.add/l0; %sometimes the 12 is a 4 --> depends on how Vdk (DDI) is defined
% DDI strength % Trap gamma
Params.gdd = 12*pi*Params.add/l0; %sometimes the 12 is a 4 --> depends on how Vdk (DDI) is defined Params.gx = (Params.wx/w0)^2;
Params.gy = (Params.wy/w0)^2;
Params.gz = (Params.wz/w0)^2;
% Trap gamma % == Calculate LHY correction == %
Params.gx = (Params.wx/w0)^2; eps_dd = Params.add/Params.as;
Params.gy = (Params.wy/w0)^2; if eps_dd == 0
Params.gz = (Params.wz/w0)^2; Q5 = 1;
elseif eps_dd == 1
Q5 = 3*sqrt(3)/2;
else
yeps = (1-eps_dd)/(3*eps_dd);
Q5 = (3*eps_dd)^(5/2)*( (8+26*yeps+33*yeps^2)*sqrt(1+yeps) + 15*yeps^3*log((1+sqrt(1+yeps))/sqrt(yeps)) )/48;
Q5 = real(Q5);
end
% == Calculate LHY correction == % Params.gammaQF = 128/3*sqrt(pi*(Params.as/l0)^5)*Q5;
eps_dd = Params.add/Params.as;
if eps_dd == 0 % Loading the rest into Params
Q5 = 1; Params.hbar = hbar;
elseif eps_dd == 1 Params.kbol = kbol;
Q5 = 3*sqrt(3)/2; Params.mu0 = mu0;
else Params.muB = muB;
yeps = (1-eps_dd)/(3*eps_dd); Params.a0 = a0;
Q5 = (3*eps_dd)^(5/2)*( (8+26*yeps+33*yeps^2)*sqrt(1+yeps) + 15*yeps^3*log((1+sqrt(1+yeps))/sqrt(yeps)) )/48; Params.w0 = w0;
Q5 = real(Q5); Params.l0 = l0;
end
Params.gammaQF = 128/3*sqrt(pi*(Params.as/l0)^5)*Q5;
% Loading the rest into Params
Params.hbar = hbar;
Params.kbol = kbol;
Params.mu0 = mu0;
Params.muB = muB;
Params.a0 = a0;
Params.w0 = w0;
Params.l0 = l0;
end end

View File

@ -1,33 +1,33 @@
function [Transf] = setupSpace(this,Params) function [Transf] = setupSpace(this,Params)
Transf.Xmax = 0.5*Params.Lx; Transf.Xmax = 0.5*Params.Lx;
Transf.Ymax = 0.5*Params.Ly; Transf.Ymax = 0.5*Params.Ly;
Transf.Zmax = 0.5*Params.Lz; Transf.Zmax = 0.5*Params.Lz;
Nz = Params.Nz; Nx = Params.Nx; Ny = Params.Ny; Nz = Params.Nz; Nx = Params.Nx; Ny = Params.Ny;
% Fourier grids % Fourier grids
x = linspace(-0.5*Params.Lx,0.5*Params.Lx-Params.Lx/Params.Nx,Params.Nx); x = linspace(-0.5*Params.Lx,0.5*Params.Lx-Params.Lx/Params.Nx,Params.Nx);
Kmax = pi*Params.Nx/Params.Lx; Kmax = pi*Params.Nx/Params.Lx;
kx = linspace(-Kmax,Kmax,Nx+1); kx = linspace(-Kmax,Kmax,Nx+1);
kx = kx(1:end-1); dkx = kx(2)-kx(1); kx = kx(1:end-1); dkx = kx(2)-kx(1);
kx = fftshift(kx); kx = fftshift(kx);
y = linspace(-0.5*Params.Ly,0.5*Params.Ly-Params.Ly/Params.Ny,Params.Ny); y = linspace(-0.5*Params.Ly,0.5*Params.Ly-Params.Ly/Params.Ny,Params.Ny);
Kmax = pi*Params.Ny/Params.Ly; Kmax = pi*Params.Ny/Params.Ly;
ky = linspace(-Kmax,Kmax,Ny+1); ky = linspace(-Kmax,Kmax,Ny+1);
ky = ky(1:end-1); dky = ky(2)-ky(1); ky = ky(1:end-1); dky = ky(2)-ky(1);
ky = fftshift(ky); ky = fftshift(ky);
z = linspace(-0.5*Params.Lz,0.5*Params.Lz-Params.Lz/Params.Nz,Params.Nz); z = linspace(-0.5*Params.Lz,0.5*Params.Lz-Params.Lz/Params.Nz,Params.Nz);
Kmax = pi*Params.Nz/Params.Lz; Kmax = pi*Params.Nz/Params.Lz;
kz = linspace(-Kmax,Kmax,Nz+1); kz = linspace(-Kmax,Kmax,Nz+1);
kz = kz(1:end-1); dkz = kz(2)-kz(1); kz = kz(1:end-1); dkz = kz(2)-kz(1);
kz = fftshift(kz); kz = fftshift(kz);
[Transf.X,Transf.Y,Transf.Z]=ndgrid(x,y,z); [Transf.X,Transf.Y,Transf.Z]=ndgrid(x,y,z);
[Transf.KX,Transf.KY,Transf.KZ]=ndgrid(kx,ky,kz); [Transf.KX,Transf.KY,Transf.KZ]=ndgrid(kx,ky,kz);
Transf.x = x; Transf.y = y; Transf.z = z; Transf.x = x; Transf.y = y; Transf.z = z;
Transf.kx = kx; Transf.ky = ky; Transf.kz = kz; Transf.kx = kx; Transf.ky = ky; Transf.kz = kz;
Transf.dx = x(2)-x(1); Transf.dy = y(2)-y(1); Transf.dz = z(2)-z(1); Transf.dx = x(2)-x(1); Transf.dy = y(2)-y(1); Transf.dz = z(2)-z(1);
Transf.dkx = dkx; Transf.dky = dky; Transf.dkz = dkz; Transf.dkx = dkx; Transf.dky = dky; Transf.dkz = dkz;
end end

View File

@ -1,50 +1,49 @@
function [Transf] = setupSpaceRadial(this,Params,morder) function [Transf] = setupSpaceRadial(~,Params,morder)
Params.Lr = 0.5*min(Params.Lx,Params.Ly); Params.Lr = 0.5*min(Params.Lx,Params.Ly);
Params.Nr = max(Params.Nx,Params.Ny); Params.Nr = max(Params.Nx,Params.Ny);
Zmax = 0.5*Params.Lz; Zmax = 0.5*Params.Lz;
Rmax = Params.Lr; Rmax = Params.Lr;
Nz = Params.Nz; Nz = Params.Nz;
Nr = Params.Nr; Nr = Params.Nr;
if(nargin==2) if(nargin==2)
morder=0; %only do Bessel J0 morder=0; %only do Bessel J0
end end
% Fourier grids % Fourier grids
z=linspace(-Zmax,Zmax,Nz+1); z=linspace(-Zmax,Zmax,Nz+1);
z=z(1:end-1); z=z(1:end-1);
dz=z(2)-z(1); dz=z(2)-z(1);
Kmax=Nz*2*pi/(4*Zmax); Kmax=Nz*2*pi/(4*Zmax);
kz=linspace(-Kmax,Kmax,Nz+1); kz=linspace(-Kmax,Kmax,Nz+1);
kz=kz(1:end-1); kz=kz(1:end-1);
% Hankel grids and transform % Hankel grids and transform
H = hankelmatrix(morder,Rmax,Nr); H = hankelmatrix(morder,Rmax,Nr);
r=H.r(:); r=H.r(:);
kr=H.kr(:); kr=H.kr(:);
T = diag(H.J/H.kmax)*H.T*diag(Rmax./H.J)*dz*(2*pi); T = diag(H.J/H.kmax)*H.T*diag(Rmax./H.J)*dz*(2*pi);
Tinv = diag(H.J./Rmax)*H.T'*diag(H.kmax./H.J)/dz/(2*pi); Tinv = diag(H.J./Rmax)*H.T'*diag(H.kmax./H.J)/dz/(2*pi);
wr=H.wr; wr=H.wr;
wk=H.wk; wk=H.wk;
% H.T'*diag(H.J/H.vmax)*H.T*diag(Rmax./H.J) % H.T'*diag(H.J/H.vmax)*H.T*diag(Rmax./H.J)
[Transf.R,Transf.Z]=ndgrid(r,z); [Transf.R,Transf.Z]=ndgrid(r,z);
[Transf.KR,Transf.KZ]=ndgrid(kr,kz); [Transf.KR,Transf.KZ]=ndgrid(kr,kz);
Transf.T=T; Transf.T=T;
Transf.Tinv=Tinv; Transf.Tinv=Tinv;
Transf.r=r; Transf.r=r;
Transf.kr=kr; Transf.kr=kr;
Transf.z=z; Transf.z=z;
Transf.kz=kz; Transf.kz=kz;
Transf.wr=wr; Transf.wr=wr;
Transf.wk=wk; Transf.wk=wk;
Transf.Rmax=Rmax; Transf.Rmax=Rmax;
Transf.Zmax=Zmax; Transf.Zmax=Zmax;
Transf.dz=z(2)-z(1); Transf.dz=z(2)-z(1);
Transf.dkz=kz(2)-kz(1); Transf.dkz=kz(2)-kz(1);
%b1=Transf;
function s_HT = hankelmatrix(order,rmax,Nr,eps_roots) function s_HT = hankelmatrix(order,rmax,Nr,eps_roots)
%HANKEL_MATRIX: Generates data to use for Hankel Transforms %HANKEL_MATRIX: Generates data to use for Hankel Transforms
@ -103,9 +102,9 @@ function s_HT = hankelmatrix(order,rmax,Nr,eps_roots)
% See also bessel_zeros, besselj % See also bessel_zeros, besselj
if (~exist('eps_roots', 'var')||isemtpy(eps_roots)) if (~exist('eps_roots', 'var')||isemtpy(eps_roots))
s_HT.eps_roots = 1e-6; s_HT.eps_roots = 1e-6;
else else
s_HT.eps_roots = eps_roots; s_HT.eps_roots = eps_roots;
end end
s_HT.order = order; s_HT.order = order;
@ -166,146 +165,146 @@ mu3 = mu^3;
mu4 = mu^4; mu4 = mu^4;
if (d<3) if (d<3)
p = 7*mu - 31; p = 7*mu - 31;
p0 = mu - 1; p0 = mu - 1;
if ((1+p)==p) if ((1+p)==p)
p1 = 0; p1 = 0;
q1 = 0; q1 = 0;
else else
p1 = 4*(253*mu2 - 3722*mu+17869)*p0/(15*p); p1 = 4*(253*mu2 - 3722*mu+17869)*p0/(15*p);
q1 = 1.6*(83*mu2 - 982*mu + 3779)/p; q1 = 1.6*(83*mu2 - 982*mu + 3779)/p;
end end
else else
p = 7*mu2 + 82*mu - 9; p = 7*mu2 + 82*mu - 9;
p0 = mu + 3; p0 = mu + 3;
if ((p+1)==1) if ((p+1)==1)
p1 = 0; p1 = 0;
q1 = 0; q1 = 0;
else else
p1 = (4048*mu4 + 131264*mu3 - 221984*mu2 - 417600*mu + 1012176)/(60*p); p1 = (4048*mu4 + 131264*mu3 - 221984*mu2 - 417600*mu + 1012176)/(60*p);
q1 = 1.6*(83*mu3 + 2075*mu2 - 3039*mu + 3537)/p; q1 = 1.6*(83*mu3 + 2075*mu2 - 3039*mu + 3537)/p;
end end
end end
if (d==1)|(d==4) if (d==1)|(d==4)
t = .25; t = .25;
else else
t = .75; t = .75;
end end
tt = 4*t; tt = 4*t;
if (d<3) if (d<3)
pp1 = 5/48; pp1 = 5/48;
qq1 = -5/36; qq1 = -5/36;
else else
pp1 = -7/48; pp1 = -7/48;
qq1 = 35/288; qq1 = 35/288;
end end
y = .375*pi; y = .375*pi;
if (a>=3) if (a>=3)
bb = a^(-2/3); bb = a^(-2/3);
else else
bb = 1; bb = 1;
end end
a1 = 3*a - 8; a1 = 3*a - 8;
% psi = (.5*a + .25)*pi; % psi = (.5*a + .25)*pi;
for s=1:n for s=1:n
if ((a==0)&(s==1)&(d==3)) if ((a==0)&(s==1)&(d==3))
x = 0; x = 0;
j = 0; j = 0;
else else
if (s>=a1) if (s>=a1)
b = (s + .5*a - t)*pi; b = (s + .5*a - t)*pi;
c = .015625/(b^2); c = .015625/(b^2);
x = b - .125*(p0 - p1*c)/(b*(1 - q1*c)); x = b - .125*(p0 - p1*c)/(b*(1 - q1*c));
else else
if (s==1) if (s==1)
switch (d) switch (d)
case (1) case (1)
x = -2.33811; x = -2.33811;
case (2) case (2)
x = -1.17371; x = -1.17371;
case (3) case (3)
x = -1.01879; x = -1.01879;
otherwise otherwise
x = -2.29444; x = -2.29444;
end end
else else
x = y*(4*s - tt); x = y*(4*s - tt);
v = x^(-2); v = x^(-2);
x = -x^(2/3) * (1 + v*(pp1 + qq1*v)); x = -x^(2/3) * (1 + v*(pp1 + qq1*v));
end end
u = x*bb; u = x*bb;
v = fi(2/3 * (-u)^1.5); v = fi(2/3 * (-u)^1.5);
w = 1/cos(v); w = 1/cos(v);
xx = 1 - w^2; xx = 1 - w^2;
c = sqrt(u/xx); c = sqrt(u/xx);
if (d<3) if (d<3)
x = w*(a + c*(-5/u - c*(6 - 10/xx))/(48*a*u)); x = w*(a + c*(-5/u - c*(6 - 10/xx))/(48*a*u));
else else
x = w*(a + c*(7/u + c*(18 - 14/xx))/(48*a*u)); x = w*(a + c*(7/u + c*(18 - 14/xx))/(48*a*u));
end end
end end
j = 0; j = 0;
while ((j==0)|((j<5)&(abs(w/x)>e))) while ((j==0)|((j<5)&(abs(w/x)>e)))
xx = x^2; xx = x^2;
x4 = x^4; x4 = x^4;
a2 = aa - xx; a2 = aa - xx;
r0 = bessr(d, a, x); r0 = bessr(d, a, x);
j = j+1; j = j+1;
if (d<3) if (d<3)
u = r0; u = r0;
w = 6*x*(2*a + 1); w = 6*x*(2*a + 1);
p = (1 - 4*a2)/w; p = (1 - 4*a2)/w;
q = (4*(xx-mu) - 2 - 12*a)/w; q = (4*(xx-mu) - 2 - 12*a)/w;
else else
u = -xx*r0/a2; u = -xx*r0/a2;
v = 2*x*a2/(3*(aa+xx)); v = 2*x*a2/(3*(aa+xx));
w = 64*a2^3; w = 64*a2^3;
q = 2*v*(1 + mu2 + 32*mu*xx + 48*x4)/w; q = 2*v*(1 + mu2 + 32*mu*xx + 48*x4)/w;
p = v*(1 + (40*mu*xx + 48*x4 - mu2)/w); p = v*(1 + (40*mu*xx + 48*x4 - mu2)/w);
end end
w = u*(1 + p*r0)/(1 + q*r0); w = u*(1 + p*r0)/(1 + q*r0);
x = x+w; x = x+w;
end end
z(s) = x; z(s) = x;
end end
end end
function FI = fi(y) function FI = fi(y)
c1 = 1.570796; c1 = 1.570796;
if (~y) if (~y)
FI = 0; FI = 0;
elseif (y>1e5) elseif (y>1e5)
FI = c1; FI = c1;
else else
if (y<1) if (y<1)
p = (3*y)^(1/3); p = (3*y)^(1/3);
pp = p^2; pp = p^2;
p = p*(1 + pp*(pp*(27 - 2*pp) - 210)/1575); p = p*(1 + pp*(pp*(27 - 2*pp) - 210)/1575);
else else
p = 1/(y + c1); p = 1/(y + c1);
pp = p^2; pp = p^2;
p = c1 - p*(1 + pp*(2310 + pp*(3003 + pp*(4818 + pp*(8591 + pp*16328))))/3465); p = c1 - p*(1 + pp*(2310 + pp*(3003 + pp*(4818 + pp*(8591 + pp*16328))))/3465);
end end
pp = (y+p)^2; pp = (y+p)^2;
r = (p - atan(p+y))/pp; r = (p - atan(p+y))/pp;
FI = p - (1+pp)*r*(1 + r/(p+y)); FI = p - (1+pp)*r*(1 + r/(p+y));
end end
return return
function Jr = bessr(d,a,x) function Jr = bessr(d,a,x)
switch (d) switch (d)
case (1) case (1)
Jr = besselj(a, x)./besselj(a+1, x); Jr = besselj(a, x)./besselj(a+1, x);
case (2) case (2)
Jr = bessely(a, x)./bessely(a+1, x); Jr = bessely(a, x)./bessely(a+1, x);
case (3) case (3)
Jr = a./x - besselj(a+1, x)./besselj(a, x); Jr = a./x - besselj(a+1, x)./besselj(a, x);
otherwise otherwise
Jr = a./x - bessely(a+1, x)./bessely(a, x); Jr = a./x - bessely(a+1, x)./bessely(a, x);
end end
return return

View File

@ -1,25 +1,25 @@
function [psi] = setupWavefunction(this,Params,Transf) function [psi] = setupWavefunction(~,Params,Transf)
X = Transf.X; Y = Transf.Y; Z = Transf.Z; X = Transf.X; Y = Transf.Y; Z = Transf.Z;
ellx = sqrt(Params.hbar/(Params.m*Params.wx))/Params.l0; ellx = sqrt(Params.hbar/(Params.m*Params.wx))/Params.l0;
elly = sqrt(Params.hbar/(Params.m*Params.wy))/Params.l0; elly = sqrt(Params.hbar/(Params.m*Params.wy))/Params.l0;
ellz = sqrt(Params.hbar/(Params.m*Params.wz))/Params.l0; ellz = sqrt(Params.hbar/(Params.m*Params.wz))/Params.l0;
Rx = 8*ellx; Ry = 8*elly; Rz = 8*ellz; Rx = 8*ellx; Ry = 8*elly; Rz = 8*ellz;
X0 = 0.0*Transf.Xmax; Y0 = 0.0*Transf.Ymax; Z0 = 0*Transf.Zmax; X0 = 0.0*Transf.Xmax; Y0 = 0.0*Transf.Ymax; Z0 = 0*Transf.Zmax;
psi = exp(-(X-X0).^2/Rx^2-(Y-Y0).^2/Ry^2-(Z-Z0).^2/Rz^2); psi = exp(-(X-X0).^2/Rx^2-(Y-Y0).^2/Ry^2-(Z-Z0).^2/Rz^2);
cur_norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz; cur_norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz;
psi = psi/sqrt(cur_norm); psi = psi/sqrt(cur_norm);
% add some noise % add some noise
r = normrnd(0,1,size(X)); r = normrnd(0,1,size(X));
theta = rand(size(X)); theta = rand(size(X));
noise = r.*exp(2*pi*1i*theta); noise = r.*exp(2*pi*1i*theta);
psi = psi + 0.01*noise; psi = psi + 0.01*noise;
Norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz; Norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz;
psi = sqrt(Params.N)*psi/sqrt(Norm); psi = sqrt(Params.N)*psi/sqrt(Norm);
end end

View File

@ -1,90 +1,89 @@
function [psi] = solver(this,psi,Params,Transf,VDk,V,njob,t_idx,Observ) function [psi] = propagate(this,psi,Params,Transf,VDk,V,njob,t_idx,Observ)
set(0,'defaulttextInterpreter','latex')
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
set(0,'defaulttextInterpreter','latex') dt=-1j*abs(this.TimeStep);
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
dt=-1j*abs(this.TimeStep); KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
Observ.residual = 1; Observ.res = 1;
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); muchem = this.Calculator.ChemicalPotential(psi,Params,Transf,VDk,V);
Observ.residual = 1; Observ.res = 1; AdaptIdx = 0;
muchem = Simulator.ChemicalPotential(psi,Params,Transf,VDk,V); while t_idx < Params.cut_off
AdaptIdx = 0; %kin
psi = fftn(psi);
psi = psi.*exp(-0.5*1i*dt*KEop);
psi = ifftn(psi);
while t_idx < Params.cut_off %DDI
%kin frho = fftn(abs(psi).^2);
psi = fftn(psi); Phi = real(ifftn(frho.*VDk));
psi = psi.*exp(-0.5*1i*dt*KEop);
psi = ifftn(psi);
%DDI %Real-space
frho = fftn(abs(psi).^2); psi = psi.*exp(-1i*dt*(V + Params.gs*abs(psi).^2 + Params.gdd*Phi + Params.gammaQF*abs(psi).^3 - muchem));
Phi = real(ifftn(frho.*VDk));
%Real-space %kin
psi = psi.*exp(-1i*dt*(V + Params.gs*abs(psi).^2 + Params.gammaQF*abs(psi).^3 + Params.gdd*Phi - muchem)); psi = fftn(psi);
psi = psi.*exp(-0.5*1i*dt*KEop);
psi = ifftn(psi);
%kin %Renorm
psi = fftn(psi); Norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz;
psi = psi.*exp(-0.5*1i*dt*KEop); psi = sqrt(Params.N)*psi/sqrt(Norm);
psi = ifftn(psi);
%Renorm muchem = this.Calculator.ChemicalPotential(psi,Params,Transf,VDk,V);
Norm = trapz(abs(psi(:)).^2)*Transf.dx*Transf.dy*Transf.dz;
psi = sqrt(Params.N)*psi/sqrt(Norm);
muchem = Simulator.ChemicalPotential(psi,Params,Transf,VDk,V); if mod(t_idx,1000) == 0
if mod(t_idx,1000) == 0 %Change in Energy
E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
E = E/Norm;
Observ.EVec = [Observ.EVec E];
%Change in Energy %Chemical potential
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V); Observ.mucVec = [Observ.mucVec muchem];
E = E/Norm;
Observ.EVec = [Observ.EVec E];
%Chemical potential %Normalized residuals
Observ.mucVec = [Observ.mucVec muchem]; res = this.Calculator.NormalizedResiduals(psi,Params,Transf,VDk,V,muchem);
Observ.residual = [Observ.residual res];
%Normalized residuals Observ.res_idx = Observ.res_idx + 1;
res = Simulator.NormalizedResiduals(psi,Params,Transf,VDk,V,muchem);
Observ.residual = [Observ.residual res];
Observ.res_idx = Observ.res_idx + 1; save(sprintf('./Data/Run_%03i/psi_gs.mat',njob),'psi','muchem','Observ','t_idx','Transf','Params','VDk','V');
save(sprintf('./Data/Run_%03i/psi_gs.mat',njob),'psi','muchem','Observ','t_idx','Transf','Params','VDk','V'); %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);
%Adaptive time step -- Careful, this can quickly get out of control if relres <1e-5
relres = abs(Observ.residual(Observ.res_idx)-Observ.residual(Observ.res_idx-1))/Observ.residual(Observ.res_idx); if AdaptIdx > 4 && abs(dt) > Params.mindt
if relres <1e-5 dt = dt / 2;
if AdaptIdx > 4 && abs(dt) > Params.mindt fprintf('Time step changed to '); disp(dt);
dt = dt / 2; AdaptIdx = 0;
fprintf('Time step changed to '); disp(dt); elseif AdaptIdx > 4 && abs(dt) < Params.mindt
AdaptIdx = 0; break
elseif AdaptIdx > 4 && abs(dt) < Params.mindt else
break AdaptIdx = AdaptIdx + 1;
end
else else
AdaptIdx = AdaptIdx + 1; AdaptIdx = 0;
end end
else
AdaptIdx = 0;
end end
if any(isnan(psi(:)))
disp('NaNs encountered!')
break
end
t_idx=t_idx+1;
end end
if any(isnan(psi(:)))
disp('NaNs encountered!') %Change in Energy
break E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
end E = E/Norm;
t_idx=t_idx+1; Observ.EVec = [Observ.EVec E];
end
% Phase coherence
%Change in Energy [PhaseC] = this.Calculator.PhaseCoherence(psi,Transf,Params);
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V); Observ.PCVec = [Observ.PCVec PhaseC];
E = E/Norm;
Observ.EVec = [Observ.EVec E]; Observ.res_idx = Observ.res_idx + 1;
save(sprintf('./Data/Run_%03i/psi_gs.mat',njob),'psi','muchem','Observ','t_idx','Transf','Params','VDk','V');
% Phase coherence
[PhaseC] = Simulator.PhaseCoherence(psi,Transf,Params);
Observ.PCVec = [Observ.PCVec PhaseC];
Observ.res_idx = Observ.res_idx + 1;
save(sprintf('./Data/Run_%03i/psi_gs.mat',njob),'psi','muchem','Observ','t_idx','Transf','Params','VDk','V');
end end