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
sim = Simulator.DipolarGas(options{:});
calc = Simulator.Calculator(options{:});
pot = Simulator.Potentials(options{:});
%-% Run Simulation %-%
[Params, Transf, psi, V, VDk] = sim.runSimulation(calc);
[Params, Transf, psi, V, VDk] = sim.runSimulation();
%% - Plot numerical grid
Plotter.visualizeSpace(Transf)

View File

@ -27,13 +27,23 @@ classdef Calculator < handle & matlab.mixin.Copyable
methods
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.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 = this.CalculatorDefaults.CutoffType;
this.CutoffType = p.Results.CutoffType;
this.CalculatorDefaults.CutoffType = this.CutoffType;
end
function restoreDefaults(this)

View File

@ -1,4 +1,4 @@
function muchem = calculateChemicalPotential(psi,Params,Transf,VDk,V)
function muchem = calculateChemicalPotential(~,psi,Params,Transf,VDk,V)
%Parameters
normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi);
@ -26,3 +26,4 @@ Eqf = Params.gammaQF*abs(psi).^5;
%Total energy
muchem = Ekin + trapz(Epot(:) + Eint(:) + Eddi(:) + Eqf(:))*Transf.dx*Transf.dy*Transf.dz; %
muchem = muchem / Params.N;
end

View File

@ -1,4 +1,4 @@
function E = calculateEnergyComponents(psi,Params,Transf,VDk,V)
function E = calculateEnergyComponents(~,psi,Params,Transf,VDk,V)
%Parameters
@ -32,4 +32,4 @@ E.Eint = trapz(Eint(:))*Transf.dx*Transf.dy*Transf.dz;
Eqf = 0.4*Params.gammaQF*abs(psi).^5;
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,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);
@ -22,3 +22,4 @@ Eqf = Params.gammaQF*abs(psi).^3.*psi;
%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);
end

View File

@ -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
if(nargin==5)
@ -35,5 +35,5 @@ for krn = 1:Nkr
igrand = igrandbasez.*besselr{krn};
VDkSemi(krn,kzn) = VDkSemi(krn,kzn) - sum(igrand(:))*dz*dr;
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;

View File

@ -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;
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;
PhaseC = sum(sum(sum(abs(angle(psi)-avgphi).*abs(psi).^2)))*Transf.dx*Transf.dy*Transf.dz;
end

View File

@ -1,4 +1,4 @@
function E = calculateTotalEnergy(psi,Params,Transf,VDk,V)
function E = calculateTotalEnergy(~,psi,Params,Transf,VDk,V)
%Parameters
@ -29,3 +29,4 @@ Eint = 0.5*Params.gs*abs(psi).^4;
Eqf = 0.4*Params.gammaQF*abs(psi).^5;
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;
MinimumTimeStep;
Calculator;
%Flags
DebugMode;
@ -46,6 +48,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
addParameter(p, 'SimulationMode', 'ImaginaryTimeEvolution',...
@(x) any(strcmpi(x,{'ImaginaryTimeEvolution','RealTimeEvolution'})));
addParameter(p, 'CutoffType', 'Cylindrical',...
@(x) any(strcmpi(x,{'Cylindrical','CylindricalInfiniteZ', 'Spherical'})));
addParameter(p, 'TimeStep', 5E-4,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'SimulationTime', 2e6,...
@ -81,6 +85,8 @@ classdef DipolarGas < handle & matlab.mixin.Copyable
this.DoSave = p.Results.SaveData;
this.SaveDirectory = p.Results.SaveDirectory;
this.Calculator = Simulator.Calculator('CutoffType', p.Results.CutoffType);
switch this.SimulationMode
case "ImaginaryTimeEvolution"
% Development In progress

View File

@ -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
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 = VDk.VDk;
else
VDk = calcObj.calculateVDCutoff(Params,Transf,TransfRad);
VDk = this.Calculator.calculateVDCutoff(Params,Transf,TransfRad);
save(sprintf(strcat(this.SaveDirectory, '/VDk_M.mat')),'VDk');
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 == %
psi = this.setupWavefunction(Params,Transf);
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 ---
[Params] = this.setupParameters();
@ -9,15 +9,15 @@ function [Params, Transf, psi,V,VDk] = runSimulation(this,calcObj)
% --- Initialize ---
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 = [];
t_idx = 1; %Start at t = 0;
Observ.res_idx = 1;
% --- Job Settings ---
% njob = 6;
% mkdir(sprintf('./Data/Run_%03i',njob))
njob = 6;
mkdir(sprintf('./Data/Run_%03i',njob))
% --- Run Simulation ---
% [psi] = this.solver(psi,Params,Transf,VDk,V,njob,t_idx,Observ);

View File

@ -1,5 +1,4 @@
function [Params] = setupParameters(this)
CONSTANTS = Helper.PhysicsConstants;
hbar = CONSTANTS.PlanckConstantReduced; % [J.s]
kbol = CONSTANTS.BoltzmannConstant; % [J/K]

View File

@ -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.Nr = max(Params.Nx,Params.Ny);
@ -44,7 +44,6 @@ Transf.Rmax=Rmax;
Transf.Zmax=Zmax;
Transf.dz=z(2)-z(1);
Transf.dkz=kz(2)-kz(1);
%b1=Transf;
function s_HT = hankelmatrix(order,rmax,Nr,eps_roots)
%HANKEL_MATRIX: Generates data to use for Hankel Transforms

View File

@ -1,4 +1,4 @@
function [psi] = setupWavefunction(this,Params,Transf)
function [psi] = setupWavefunction(~,Params,Transf)
X = Transf.X; Y = Transf.Y; Z = Transf.Z;

View File

@ -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(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);
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;
while t_idx < Params.cut_off
@ -22,7 +21,7 @@ while t_idx < Params.cut_off
Phi = real(ifftn(frho.*VDk));
%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
psi = fftn(psi);
@ -33,12 +32,12 @@ while t_idx < Params.cut_off
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);
muchem = this.Calculator.ChemicalPotential(psi,Params,Transf,VDk,V);
if mod(t_idx,1000) == 0
%Change in Energy
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V);
E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
E = E/Norm;
Observ.EVec = [Observ.EVec E];
@ -46,7 +45,7 @@ while t_idx < Params.cut_off
Observ.mucVec = [Observ.mucVec muchem];
%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.res_idx = Observ.res_idx + 1;
@ -77,12 +76,12 @@ while t_idx < Params.cut_off
end
%Change in Energy
E = Simulator.TotalEnergy(psi,Params,Transf,VDk,V);
E = this.Calculator.TotalEnergy(psi,Params,Transf,VDk,V);
E = E/Norm;
Observ.EVec = [Observ.EVec E];
% Phase coherence
[PhaseC] = Simulator.PhaseCoherence(psi,Transf,Params);
[PhaseC] = this.Calculator.PhaseCoherence(psi,Transf,Params);
Observ.PCVec = [Observ.PCVec PhaseC];
Observ.res_idx = Observ.res_idx + 1;