Latest working version.
This commit is contained in:
parent
570995f3f5
commit
6bb354de7a
@ -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)
|
||||||
|
@ -27,13 +27,23 @@ classdef Calculator < handle & matlab.mixin.Copyable
|
|||||||
|
|
||||||
methods
|
methods
|
||||||
function this = Calculator(varargin)
|
function this = Calculator(varargin)
|
||||||
|
|
||||||
|
p = inputParser;
|
||||||
|
p.KeepUnmatched = true;
|
||||||
|
addParameter(p, 'CutoffType', this.CalculatorDefaults.CutoffType,...
|
||||||
|
@(x) any(strcmpi(x,{'Cylindrical','CylindricalInfiniteZ', 'Spherical'})));
|
||||||
|
|
||||||
|
p.parse(varargin{:});
|
||||||
|
|
||||||
this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential;
|
this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential;
|
||||||
this.EnergyComponents = this.CalculatorDefaults.EnergyComponents;
|
this.EnergyComponents = this.CalculatorDefaults.EnergyComponents;
|
||||||
this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals;
|
this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals;
|
||||||
this.OrderParameter = this.CalculatorDefaults.OrderParameter;
|
this.OrderParameter = this.CalculatorDefaults.OrderParameter;
|
||||||
this.PhaseCoherence = this.CalculatorDefaults.PhaseCoherence;
|
this.PhaseCoherence = this.CalculatorDefaults.PhaseCoherence;
|
||||||
this.TotalEnergy = this.CalculatorDefaults.TotalEnergy;
|
this.TotalEnergy = this.CalculatorDefaults.TotalEnergy;
|
||||||
this.CutoffType = this.CalculatorDefaults.CutoffType;
|
this.CutoffType = p.Results.CutoffType;
|
||||||
|
this.CalculatorDefaults.CutoffType = this.CutoffType;
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function restoreDefaults(this)
|
function restoreDefaults(this)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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);
|
||||||
@ -26,3 +26,4 @@ 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
|
@ -1,4 +1,4 @@
|
|||||||
function E = calculateEnergyComponents(psi,Params,Transf,VDk,V)
|
function E = calculateEnergyComponents(~,psi,Params,Transf,VDk,V)
|
||||||
|
|
||||||
%Parameters
|
%Parameters
|
||||||
|
|
||||||
@ -32,4 +32,4 @@ E.Eint = trapz(Eint(:))*Transf.dx*Transf.dy*Transf.dz;
|
|||||||
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
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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);
|
||||||
|
|
||||||
@ -22,3 +22,4 @@ 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
|
@ -1,4 +1,4 @@
|
|||||||
function VDkSemi = calculateNumericalHankelTransform(this,kr,kz,Rmax,Zmax,Nr)
|
function VDkSemi = calculateNumericalHankelTransform(~,kr,kz,Rmax,Zmax,Nr)
|
||||||
|
|
||||||
% accuracy inputs for numerical integration
|
% accuracy inputs for numerical integration
|
||||||
if(nargin==5)
|
if(nargin==5)
|
||||||
@ -35,5 +35,5 @@ for krn = 1:Nkr
|
|||||||
igrand = igrandbasez.*besselr{krn};
|
igrand = igrandbasez.*besselr{krn};
|
||||||
VDkSemi(krn,kzn) = VDkSemi(krn,kzn) - sum(igrand(:))*dz*dr;
|
VDkSemi(krn,kzn) = VDkSemi(krn,kzn) - sum(igrand(:))*dz*dr;
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
@ -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;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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);
|
||||||
@ -16,3 +16,4 @@ phi = angle(psi);
|
|||||||
|
|
||||||
avgphi = sum(sum(sum(phi.*abs(psi).^2,1),2),3)*Transf.dx*Transf.dy*Transf.dz;
|
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;
|
PhaseC = sum(sum(sum(abs(angle(psi)-avgphi).*abs(psi).^2)))*Transf.dx*Transf.dy*Transf.dz;
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
function E = calculateTotalEnergy(psi,Params,Transf,VDk,V)
|
function E = calculateTotalEnergy(~,psi,Params,Transf,VDk,V)
|
||||||
|
|
||||||
%Parameters
|
%Parameters
|
||||||
|
|
||||||
@ -29,3 +29,4 @@ Eint = 0.5*Params.gs*abs(psi).^4;
|
|||||||
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
|
@ -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
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
function [psi,V,VDk] = initialize(this,calcObj,Params,Transf,TransfRad)
|
function [psi,V,VDk] = initialize(this,Params,Transf,TransfRad)
|
||||||
|
|
||||||
format long
|
format long
|
||||||
X = Transf.X; Y = Transf.Y; Z = Transf.Z;
|
X = Transf.X; Y = Transf.Y; Z = Transf.Z;
|
||||||
|
|
||||||
@ -11,12 +10,11 @@ if isfile(strcat(this.SaveDirectory, '/VDk_M.mat'))
|
|||||||
VDk = load(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')));
|
VDk = load(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')));
|
||||||
VDk = VDk.VDk;
|
VDk = VDk.VDk;
|
||||||
else
|
else
|
||||||
VDk = calcObj.calculateVDCutoff(Params,Transf,TransfRad);
|
VDk = this.Calculator.calculateVDCutoff(Params,Transf,TransfRad);
|
||||||
save(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')),'VDk');
|
save(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')),'VDk');
|
||||||
end
|
end
|
||||||
fprintf('Computed and saved DDI potential in Fourier space with %s cutoff.', calcObj.CutoffType)
|
fprintf('Computed and saved DDI potential in Fourier space with %s cutoff.', this.Calculator.CutoffType)
|
||||||
|
|
||||||
% == Setting up the initial wavefunction == %
|
% == Setting up the initial wavefunction == %
|
||||||
psi = this.setupWavefunction(Params,Transf);
|
psi = this.setupWavefunction(Params,Transf);
|
||||||
|
|
||||||
end
|
end
|
@ -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);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
function [Params] = setupParameters(this)
|
function [Params] = setupParameters(this)
|
||||||
|
|
||||||
CONSTANTS = Helper.PhysicsConstants;
|
CONSTANTS = Helper.PhysicsConstants;
|
||||||
hbar = CONSTANTS.PlanckConstantReduced; % [J.s]
|
hbar = CONSTANTS.PlanckConstantReduced; % [J.s]
|
||||||
kbol = CONSTANTS.BoltzmannConstant; % [J/K]
|
kbol = CONSTANTS.BoltzmannConstant; % [J/K]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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);
|
||||||
@ -44,7 +44,6 @@ 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
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
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(0,'defaulttextInterpreter','latex')
|
||||||
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
|
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
|
||||||
|
|
||||||
@ -8,7 +7,7 @@ dt=-1j*abs(this.TimeStep);
|
|||||||
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
|
KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2);
|
||||||
Observ.residual = 1; Observ.res = 1;
|
Observ.residual = 1; Observ.res = 1;
|
||||||
|
|
||||||
muchem = Simulator.ChemicalPotential(psi,Params,Transf,VDk,V);
|
muchem = this.Calculator.ChemicalPotential(psi,Params,Transf,VDk,V);
|
||||||
AdaptIdx = 0;
|
AdaptIdx = 0;
|
||||||
|
|
||||||
while t_idx < Params.cut_off
|
while t_idx < Params.cut_off
|
||||||
@ -22,7 +21,7 @@ while t_idx < Params.cut_off
|
|||||||
Phi = real(ifftn(frho.*VDk));
|
Phi = real(ifftn(frho.*VDk));
|
||||||
|
|
||||||
%Real-space
|
%Real-space
|
||||||
psi = psi.*exp(-1i*dt*(V + Params.gs*abs(psi).^2 + Params.gammaQF*abs(psi).^3 + Params.gdd*Phi - muchem));
|
psi = psi.*exp(-1i*dt*(V + Params.gs*abs(psi).^2 + Params.gdd*Phi + Params.gammaQF*abs(psi).^3 - muchem));
|
||||||
|
|
||||||
%kin
|
%kin
|
||||||
psi = fftn(psi);
|
psi = fftn(psi);
|
||||||
@ -33,12 +32,12 @@ while t_idx < Params.cut_off
|
|||||||
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);
|
||||||
|
|
||||||
muchem = Simulator.ChemicalPotential(psi,Params,Transf,VDk,V);
|
muchem = this.Calculator.ChemicalPotential(psi,Params,Transf,VDk,V);
|
||||||
|
|
||||||
if mod(t_idx,1000) == 0
|
if mod(t_idx,1000) == 0
|
||||||
|
|
||||||
%Change in Energy
|
%Change in Energy
|
||||||
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V);
|
E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
|
||||||
E = E/Norm;
|
E = E/Norm;
|
||||||
Observ.EVec = [Observ.EVec E];
|
Observ.EVec = [Observ.EVec E];
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ while t_idx < Params.cut_off
|
|||||||
Observ.mucVec = [Observ.mucVec muchem];
|
Observ.mucVec = [Observ.mucVec muchem];
|
||||||
|
|
||||||
%Normalized residuals
|
%Normalized residuals
|
||||||
res = Simulator.NormalizedResiduals(psi,Params,Transf,VDk,V,muchem);
|
res = this.Calculator.NormalizedResiduals(psi,Params,Transf,VDk,V,muchem);
|
||||||
Observ.residual = [Observ.residual res];
|
Observ.residual = [Observ.residual res];
|
||||||
|
|
||||||
Observ.res_idx = Observ.res_idx + 1;
|
Observ.res_idx = Observ.res_idx + 1;
|
||||||
@ -77,12 +76,12 @@ while t_idx < Params.cut_off
|
|||||||
end
|
end
|
||||||
|
|
||||||
%Change in Energy
|
%Change in Energy
|
||||||
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V);
|
E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
|
||||||
E = E/Norm;
|
E = E/Norm;
|
||||||
Observ.EVec = [Observ.EVec E];
|
Observ.EVec = [Observ.EVec E];
|
||||||
|
|
||||||
% Phase coherence
|
% Phase coherence
|
||||||
[PhaseC] = Simulator.PhaseCoherence(psi,Transf,Params);
|
[PhaseC] = this.Calculator.PhaseCoherence(psi,Transf,Params);
|
||||||
Observ.PCVec = [Observ.PCVec PhaseC];
|
Observ.PCVec = [Observ.PCVec PhaseC];
|
||||||
|
|
||||||
Observ.res_idx = Observ.res_idx + 1;
|
Observ.res_idx = Observ.res_idx + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user