Calculations/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/initialize.m

49 lines
1.9 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
% 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 == %
psi = this.setupWavefunction(Params,Transf);
if this.RunOnGPU
psi = gpuArray(psi);
end
end