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

98 lines
4.0 KiB
Mathematica
Raw Normal View History

2024-06-12 20:05:27 +02:00
classdef Calculator < handle & matlab.mixin.Copyable
2024-06-12 20:45:08 +02:00
properties (Access = private)
2024-06-12 20:05:27 +02:00
2024-06-13 11:30:12 +02:00
CalculatorDefaults = struct('ChemicalPotential', 1, ...
'EnergyComponents', 1, ...
'NormalizedResiduals', 1, ...
'OrderParameter', 1, ...
2024-06-12 20:45:08 +02:00
'PhaseCoherence', 1, ...
2024-06-13 11:30:12 +02:00
'TotalEnergy', 1, ...
2024-06-12 20:45:08 +02:00
'CutoffType', 'Cylindrical');
end
properties (Access = public)
2024-06-13 11:30:12 +02:00
ChemicalPotential;
EnergyComponents;
NormalizedResiduals;
2024-06-12 20:45:08 +02:00
OrderParameter;
PhaseCoherence;
2024-06-13 11:30:12 +02:00
TotalEnergy;
2024-06-12 20:45:08 +02:00
CutoffType;
2024-06-12 20:05:27 +02:00
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%- Methods
methods
function this = Calculator(varargin)
2024-06-17 12:14:15 +02:00
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 = p.Results.CutoffType;
2024-06-12 20:05:27 +02:00
end
2024-06-12 20:45:08 +02:00
function restoreDefaults(this)
2024-06-13 11:30:12 +02:00
this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential;
this.EnergyComponents = this.CalculatorDefaults.EnergyComponents;
this.NormalizedResiduals = this.CalculatorDefaults.NormalizedResiduals;
this.OrderParameter = this.CalculatorDefaults.OrderParameter;
2024-06-12 20:45:08 +02:00
this.PhaseCoherence = this.CalculatorDefaults.PhaseCoherence;
2024-06-13 11:30:12 +02:00
this.TotalEnergy = this.CalculatorDefaults.TotalEnergy;
2024-06-12 20:45:08 +02:00
this.CutoffType = this.CalculatorDefaults.CutoffType;
end
2024-06-17 20:24:00 +02:00
end %
2024-06-12 20:05:27 +02:00
2024-06-12 20:45:08 +02:00
% methods
2024-06-12 20:05:27 +02:00
2024-06-12 20:45:08 +02:00
% end % - setters and getters
2024-06-12 20:05:27 +02:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%- 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.Calculator(varargin{:});
end
singleObj = localObj;
end
end
end