64 lines
2.5 KiB
Matlab
64 lines
2.5 KiB
Matlab
function [psi,V,VDk] = initialize(this,Params,Transf,TransfRad)
|
|
|
|
% == User-defined potential == %
|
|
V = this.Potential;
|
|
assert(~anynan(V), 'Potential not defined! Specify as <SimulatorObject>.Potential = <PotentialsObject>.trap() + <AdditionalTerms>.');
|
|
|
|
VDkFile = fullfile(this.SaveDirectory, 'VDk_M.mat');
|
|
VDk = [];
|
|
DDICutOffIncluded = false;
|
|
CutOffType = 'None';
|
|
|
|
% == Calculating the DDIs == %
|
|
if isfile(VDkFile)
|
|
loadedData = load(VDkFile);
|
|
[VDk, DDICutOffIncluded, CutOffType] = deal(loadedData.VDk, loadedData.DDICutOffIncluded, loadedData.CutOffType);
|
|
end
|
|
|
|
if isempty(VDk) || ~isequal(size(VDk), this.NumberOfGridPoints) || this.IncludeDDICutOff ~= DDICutOffIncluded || strcmp(this.Calculator.CutOffType, 'CustomCylindrical')
|
|
% Calculate VDk if necessary
|
|
VDk = this.Calculator.calculateVDk(Params, Transf, TransfRad, this.IncludeDDICutOff);
|
|
DDICutOffIncluded = this.IncludeDDICutOff;
|
|
% Set CutOffType based on DDICutOffIncluded
|
|
if DDICutOffIncluded
|
|
CutOffType = this.Calculator.CutOffType;
|
|
fprintf('Computed and saved DDI potential in Fourier space with a %s cutoff.\n', CutOffType);
|
|
else
|
|
CutOffType = 'None';
|
|
fprintf('Computed and saved DDI potential in Fourier space with no cutoff.\n');
|
|
end
|
|
% Save the calculated VDk
|
|
save(VDkFile,'VDk', 'DDICutOffIncluded', 'CutOffType');
|
|
|
|
else
|
|
if DDICutOffIncluded
|
|
% Print load message
|
|
fprintf('Loaded pre-saved DDI potential in Fourier space with a %s cutoff.\n', CutOffType);
|
|
else
|
|
% Print load message
|
|
fprintf('Loaded pre-saved DDI potential in Fourier space with no cutoff.\n');
|
|
end
|
|
end
|
|
|
|
% == Setting up the initial wavefunction == %
|
|
WavefunctionFile = fullfile(this.SaveDirectory, 'psi_init.mat');
|
|
|
|
if isfile(WavefunctionFile)
|
|
loadedData = load(WavefunctionFile);
|
|
if isgpuarray(loadedData.psi)
|
|
psi = gather(loadedData.psi);
|
|
else
|
|
psi = loadedData.psi;
|
|
end
|
|
if ~isequal(size(psi), size(VDk))
|
|
psi = this.setupWavefunction(Params,Transf);
|
|
disp('Computing new initial wavefunction was necessary due to incompatible array sizes.');
|
|
end
|
|
else
|
|
psi = this.setupWavefunction(Params,Transf);
|
|
end
|
|
|
|
if this.RunOnGPU
|
|
psi = gpuArray(psi);
|
|
end
|
|
end |