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

179 lines
7.0 KiB
Mathematica
Raw Normal View History

2024-06-12 20:05:27 +02:00
classdef DipolarGas < handle & matlab.mixin.Copyable
properties (Access = public)
2024-06-13 02:02:44 +02:00
NumberOfAtoms;
2024-06-13 11:30:12 +02:00
DipolarPolarAngle;
DipolarAzimuthAngle
2024-06-13 02:02:44 +02:00
ScatteringLength;
TrapFrequencies;
2024-06-13 11:30:12 +02:00
NumberOfGridPoints;
2024-06-13 02:02:44 +02:00
Dimensions;
2024-06-17 20:24:00 +02:00
Potential;
2024-06-12 20:05:27 +02:00
SimulationMode;
2024-06-17 20:24:00 +02:00
TimeStepSize;
NumberOfTimeSteps;
2024-06-13 18:27:02 +02:00
EnergyTolerance;
2024-06-17 20:24:00 +02:00
MinimumTimeStepSize;
2024-06-12 20:05:27 +02:00
2024-06-17 12:14:15 +02:00
Calculator;
2024-06-17 20:24:00 +02:00
SimulationParameters;
2024-06-17 12:14:15 +02:00
2024-06-12 20:05:27 +02:00
%Flags
JobNumber;
2024-06-12 20:05:27 +02:00
DebugMode;
DoSave;
SaveDirectory;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%- Methods
methods
function this = DipolarGas(varargin)
p = inputParser;
p.KeepUnmatched = true;
2024-06-13 02:02:44 +02:00
addParameter(p, 'NumberOfAtoms', 1E6,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
2024-06-13 11:30:12 +02:00
addParameter(p, 'DipolarPolarAngle', pi/2,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > -2*pi) && (x < 2*pi)));
addParameter(p, 'DipolarAzimuthAngle', pi/2,...
2024-06-13 02:02:44 +02:00
@(x) assert(isnumeric(x) && isscalar(x) && (x > -2*pi) && (x < 2*pi)));
addParameter(p, 'ScatteringLength', 120,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > -150) && (x < 150)));
addParameter(p, 'TrapFrequencies', 100 * ones(1,3),...
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
2024-06-13 11:30:12 +02:00
addParameter(p, 'NumberOfGridPoints', 128 * ones(1,3),...
2024-06-13 02:02:44 +02:00
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
addParameter(p, 'Dimensions', 10 * ones(1,3),...
@(x) assert(isnumeric(x) && isvector(x) && all(x > 0)));
2024-06-12 20:05:27 +02:00
addParameter(p, 'SimulationMode', 'ImaginaryTimeEvolution',...
2024-06-17 20:24:00 +02:00
@(x) assert(any(strcmpi(x,{'ImaginaryTimeEvolution','RealTimeEvolution'}))));
2024-06-17 12:14:15 +02:00
addParameter(p, 'CutoffType', 'Cylindrical',...
2024-06-17 20:24:00 +02:00
@(x) assert(any(strcmpi(x,{'Cylindrical','CylindricalInfiniteZ', 'Spherical'}))));
addParameter(p, 'TimeStepSize', 5E-4,...
2024-06-12 20:05:27 +02:00
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
2024-06-17 20:24:00 +02:00
addParameter(p, 'NumberOfTimeSteps', 2e6,...
2024-06-13 18:27:02 +02:00
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'EnergyTolerance', 1e-10,...
2024-06-12 20:05:27 +02:00
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
2024-06-17 20:24:00 +02:00
addParameter(p, 'MinimumTimeStepSize', 1e-6,...
2024-06-13 18:27:02 +02:00
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
addParameter(p, 'JobNumber', 1,...
@(x) assert(isnumeric(x) && isscalar(x) && (x > 0)));
2024-06-13 02:02:44 +02:00
addParameter(p, 'DebugMode', false,...
2024-06-12 20:05:27 +02:00
@islogical);
2024-06-13 02:02:44 +02:00
addParameter(p, 'SaveData', false,...
2024-06-12 20:05:27 +02:00
@islogical);
2024-06-13 02:02:44 +02:00
addParameter(p, 'SaveDirectory', './Data',...
2024-06-12 20:05:27 +02:00
@ischar);
p.parse(varargin{:});
this.NumberOfAtoms = p.Results.NumberOfAtoms;
2024-06-13 11:30:12 +02:00
this.DipolarPolarAngle = p.Results.DipolarPolarAngle;
this.DipolarAzimuthAngle = p.Results.DipolarAzimuthAngle;
2024-06-13 02:02:44 +02:00
this.ScatteringLength = p.Results.ScatteringLength;
this.TrapFrequencies = p.Results.TrapFrequencies;
2024-06-13 11:30:12 +02:00
this.NumberOfGridPoints = p.Results.NumberOfGridPoints;
2024-06-13 02:02:44 +02:00
this.Dimensions = p.Results.Dimensions;
2024-06-17 20:24:00 +02:00
this.Potential = NaN;
2024-06-13 02:02:44 +02:00
this.SimulationMode = p.Results.SimulationMode;
2024-06-17 20:24:00 +02:00
this.TimeStepSize = p.Results.TimeStepSize;
this.NumberOfTimeSteps = p.Results.NumberOfTimeSteps;
2024-06-13 18:27:02 +02:00
this.EnergyTolerance = p.Results.EnergyTolerance;
2024-06-17 20:24:00 +02:00
this.MinimumTimeStepSize = p.Results.MinimumTimeStepSize;
2024-06-12 20:05:27 +02:00
this.JobNumber = p.Results.JobNumber;
2024-06-12 20:05:27 +02:00
this.DebugMode = p.Results.DebugMode;
this.DoSave = p.Results.SaveData;
this.SaveDirectory = p.Results.SaveDirectory;
2024-06-17 12:14:15 +02:00
this.Calculator = Simulator.Calculator('CutoffType', p.Results.CutoffType);
2024-06-17 20:24:00 +02:00
this.SimulationParameters = this.setupParameters();
2024-06-12 20:05:27 +02:00
end
end
methods
2024-06-17 20:24:00 +02:00
function set.TimeStepSize(this, val)
2024-06-12 20:05:27 +02:00
assert(val > 1e-06, 'Not time efficient to compute for time steps smaller than 1 microsecond!');
2024-06-17 20:24:00 +02:00
this.TimeStepSize = val;
2024-06-12 20:05:27 +02:00
end
2024-06-17 20:24:00 +02:00
function ret = get.TimeStepSize(this)
ret = this.TimeStepSize;
2024-06-12 20:05:27 +02:00
end
2024-06-17 20:24:00 +02:00
function set.NumberOfTimeSteps(this, val)
assert(val <= 2E6, 'Not time efficient to compute for time spans longer than 2E6 seconds!');
this.NumberOfTimeSteps = val;
2024-06-12 20:05:27 +02:00
end
2024-06-17 20:24:00 +02:00
function ret = get.NumberOfTimeSteps(this)
ret = this.NumberOfTimeSteps;
2024-06-12 20:05:27 +02:00
end
function set.NumberOfAtoms(this, val)
2024-06-13 02:02:44 +02:00
assert(val <= 1E6, '!!Not time efficient to compute for atom numbers larger than 1,000,000!!');
2024-06-12 20:05:27 +02:00
this.NumberOfAtoms = val;
end
function ret = get.NumberOfAtoms(this)
ret = this.NumberOfAtoms;
end
function set.DebugMode(this, val)
this.DebugMode = val;
end
function ret = get.DebugMode(this)
ret = this.DebugMode;
end
function set.DoSave(this, val)
this.DoSave = val;
end
function ret = get.DoSave(this)
ret = this.DoSave;
end
function set.SaveDirectory(this, val)
this.SaveDirectory = val;
end
function ret = get.SaveDirectory(this)
ret = this.SaveDirectory;
end
end % - setters and getters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%- Methods
methods(Access = protected)
function cp = copyElement(this)
% Shallow copy object
cp = copyElement@matlab.mixin.Copyable(this);
% Forces the setter to redefine the function handles to the new copied object
pl = properties(this);
for k = 1:length(pl)
sc = superclasses(this.(pl{k}));
if any(contains(sc,{'matlab.mixin.Copyable'}))
cp.(pl{k}) = this.(pl{k}).copy();
end
end
end
end
methods (Static)
% Creates an Instance of Class, ensures singleton behaviour (that there
% can only be one Instance of this class
function singleObj = getInstance(varargin)
% Creates an Instance of Class, ensures singleton behaviour
persistent localObj;
if isempty(localObj) || ~isvalid(localObj)
localObj = Simulator.DipolarGas(varargin{:});
end
singleObj = localObj;
end
end
end