diff --git a/Dipolar Gas Simulator/+Helper/ProgressBar.m b/Dipolar Gas Simulator/+Helper/ProgressBar.m new file mode 100644 index 0000000..e30a4e0 --- /dev/null +++ b/Dipolar Gas Simulator/+Helper/ProgressBar.m @@ -0,0 +1,68 @@ +classdef ProgressBar < handle +% class for command-line progress-bar notification. + properties + strPercentageLength; + strDotsMaximum; + end + methods + %--- constructor + function this = ProgressBar() + %% Initialization + % Vizualization parameters + this.strPercentageLength = 10; % Length of percentage string (must be >5) + this.strDotsMaximum = 10; % The total number of dots in a progress bar + end + %--- print method + function run(this, msg) + % This function creates a text progress bar. It should be called with a + % STRING argument to initialize and terminate. Otherwise the number corresponding + % to progress in % should be supplied. + % INPUTS: C Either: Text string to initialize or terminate + % Percentage number to show progress + % OUTPUTS: N/A + % Example: Please refer to demo_textprogressbar.m + % Author: Paul Proteus (e-mail: proteus.paul (at) yahoo (dot) com) + % Version: 1.0 + % Changes tracker: 29.06.2010 - First version + % Inspired by: http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/ + %% Main + persistent strCR; % Carriage return pesistent variable + if isempty(strCR) && ~ischar(msg) + % Progress bar must be initialized with a string + error('The text progress must be initialized with a string!'); + elseif isempty(strCR) && ischar(msg) + % Progress bar - initialization + fprintf('%s',msg); + strCR = -1; + elseif ~isempty(strCR) && ischar(msg) + % Progress bar - termination + strCR = []; + fprintf([msg '\n']); + elseif isnumeric(msg) + % Progress bar - normal progress + msg = floor(msg); + percentageOut = [num2str(msg) '%%']; + percentageOut = [percentageOut repmat(' ',1,this.strPercentageLength-length(percentageOut)-1)]; + nDots = floor(msg/100*this.strDotsMaximum); + dotOut = ['[' repmat('.',1,nDots) repmat(' ',1,this.strDotsMaximum-nDots) ']']; + strOut = [percentageOut dotOut]; + + % Print it on the screen + if strCR == -1 + % Don't do carriage return during first run + fprintf(strOut); + else + % Do it during all the other runs + fprintf([strCR strOut]); + end + + % Update carriage return + strCR = repmat('\b',1,length(strOut)-1); + + else + % Any other unexpected input + error('Unsupported argument type'); + end + end + end +end \ No newline at end of file diff --git a/Dipolar Gas Simulator/+Helper/parforNotifications.m b/Dipolar Gas Simulator/+Helper/parforNotifications.m deleted file mode 100644 index 4ad3af4..0000000 --- a/Dipolar Gas Simulator/+Helper/parforNotifications.m +++ /dev/null @@ -1,148 +0,0 @@ -% Copyright (c) 2019 Andrea Alberti -% -% All rights reserved. -classdef parforNotifications < handle - properties - N; % number of iterations - text = 'Please wait ...'; % text to show - width = 50; - showWarning = true; - end - properties (GetAccess = public, SetAccess = private) - n; - end - properties (Access = private) - inProgress = false; - percent; - DataQueue; - usePercent; - Nstr; - NstrL; - lastComment; - end - methods - function this = parforNotifications() - this.DataQueue = parallel.pool.DataQueue; - afterEach(this.DataQueue, @this.updateStatus); - end - % Start progress bar - function PB_start(this,N,varargin) - assert(isscalar(N) && isnumeric(N) && N == floor(N) && N>0, 'Error: ''N'' must be a scalar positive integer.'); - - this.N = N; - - p = inputParser; - addParameter(p,'message','Please wait: '); - addParameter(p,'usePercentage',true); - - parse(p,varargin{:}); - - this.text = p.Results.message; - assert(ischar(this.text), 'Error: ''Message'' must be a string.'); - - this.usePercent = p.Results.usePercentage; - assert(isscalar(this.usePercent) && islogical(this.usePercent), 'Error: ''usePercentage'' must be a logical scalar.'); - - this.percent = 0; - this.n = 0; - this.lastComment = ''; - if this.usePercent - fprintf('%s [%s]: %3d%%\n',this.text, char(32*ones(1,this.width)),0); - else - this.Nstr = sprintf('%d',this.N); - this.NstrL = numel(this.Nstr); - fprintf('%s [%s]: %s/%s\n',this.text, char(32*ones(1,this.width)),[char(32*ones(1,this.NstrL-1)),'0'],this.Nstr); - end - - this.inProgress = true; - end - % Iterate progress bar - function PB_iterate(this,str) - if nargin == 1 - send(this.DataQueue,''); - else - send(this.DataQueue,str); - end - end - function warning(this,warn_id,msg) - if this.showWarning - msg = struct('Action','Warning','Id',warn_id,'Message',msg); - send(this.DataQueue,msg); - end - end - function PB_reprint(this) - p = round(100*this.n/this.N); - - this.percent = p; - - cursor_pos=1+round((this.width-1)*p/100); - - if p < 100 - sep_char = '|'; - else - sep_char = '.'; - end - - if this.usePercent - fprintf('%s [%s%s%s]: %3d%%\n', this.text, char(46*ones(1,cursor_pos-1)), sep_char, char(32*ones(1,this.width-cursor_pos)),p); - else - nstr=sprintf('%d',this.n); - fprintf('%s [%s%s%s]: %s/%s\n', this.text, char(46*ones(1,cursor_pos-1)), sep_char, char(32*ones(1,this.width-cursor_pos)),[char(32*ones(1,this.NstrL-numel(nstr))),nstr],this.Nstr); - end - end - function updateStatus(this,data) - - if ischar(data) - - this.n = this.n + 1; - - p = round(100*this.n/this.N); - - if p >= this.percent+1 || this.n == this.N - this.percent = p; - - cursor_pos=1+round((this.width-1)*p/100); - - if p < 100 - sep_char = '|'; - else - sep_char = '.'; - end - - if ~isempty(data) - comment = [' (',data,')']; - else - comment = ''; - end - - if this.usePercent - fprintf('%s%s%s%s]: %3d%%%s\n',char(8*ones(1,58+numel(this.lastComment))), char(46*ones(1,cursor_pos-1)), sep_char, char(32*ones(1,this.width-cursor_pos)),p,comment); - else - nstr=sprintf('%d',this.n); - fprintf('%s%s%s%s]: %s/%s%s\n',char(8*ones(1,55+2*numel(this.Nstr)+numel(this.lastComment))), char(46*ones(1,cursor_pos-1)), sep_char, char(32*ones(1,this.width-cursor_pos)),[char(32*ones(1,this.NstrL-numel(nstr))),nstr],this.Nstr,comment) - end - - this.lastComment = comment; - - - if p == 100 - this.inProgress = false; - end - end - - else - switch data.Action - case 'Warning' - warning(data.Id,[data.Message,newline]); - if this.inProgress - this.PB_reprint(); - end - end - - end - - end - end -end - - diff --git a/Dipolar Gas Simulator/+Scripts/test.m b/Dipolar Gas Simulator/+Scripts/test.m index 835e7a9..a828fe5 100644 --- a/Dipolar Gas Simulator/+Scripts/test.m +++ b/Dipolar Gas Simulator/+Scripts/test.m @@ -21,7 +21,7 @@ OptionsStruct.Dimensions = [40, 40, 20]; OptionsStruct.CutoffType = 'Cylindrical'; OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' OptionsStruct.TimeStepSize = 50E-6; % in s -OptionsStruct.NumberOfTimeSteps = 2E6; % in s +OptionsStruct.NumberOfTimeSteps = 10; % in s OptionsStruct.EnergyTolerance = 5E-10; OptionsStruct.SaveData = true; diff --git a/Dipolar Gas Simulator/+Simulator/@Calculator/Calculator.m b/Dipolar Gas Simulator/+Simulator/@Calculator/Calculator.m index aae055e..a80c05c 100644 --- a/Dipolar Gas Simulator/+Simulator/@Calculator/Calculator.m +++ b/Dipolar Gas Simulator/+Simulator/@Calculator/Calculator.m @@ -43,7 +43,7 @@ classdef Calculator < handle & matlab.mixin.Copyable this.TotalEnergy = this.CalculatorDefaults.TotalEnergy; this.CutoffType = p.Results.CutoffType; end - + function restoreDefaults(this) this.ChemicalPotential = this.CalculatorDefaults.ChemicalPotential; this.EnergyComponents = this.CalculatorDefaults.EnergyComponents; diff --git a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateChemicalPotential.m b/Dipolar Gas Simulator/+Simulator/@Calculator/calculateChemicalPotential.m deleted file mode 100644 index 96a6a84..0000000 --- a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateChemicalPotential.m +++ /dev/null @@ -1,29 +0,0 @@ -function muchem = calculateChemicalPotential(~,psi,Params,Transf,VDk,V) - - %Parameters - normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi); - KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); - - % DDIs - frho=fftn(abs(psi).^2); - Phi=real(ifftn(frho.*VDk)); - - Eddi = (Params.gdd*Phi.*abs(psi).^2); - - %Kinetic energy - Ekin = KEop.*abs(fftn(psi)*normfac).^2; - Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3; - - %Potential energy - Epot = V.*abs(psi).^2; - - %Contact interactions - Eint = Params.gs*abs(psi).^4; - - %Quantum fluctuations - 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 \ No newline at end of file diff --git a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateEnergyComponents.m b/Dipolar Gas Simulator/+Simulator/@Calculator/calculateEnergyComponents.m deleted file mode 100644 index 92dd32c..0000000 --- a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateEnergyComponents.m +++ /dev/null @@ -1,35 +0,0 @@ -function E = calculateEnergyComponents(~,psi,Params,Transf,VDk,V) - - %Parameters - - KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); - normfac = Params.Lx*Params.Ly*Params.Lz/numel(psi); - - % DDIs - frho = fftn(abs(psi).^2); - Phi = real(ifftn(frho.*VDk)); - - Eddi = 0.5*Params.gdd*Phi.*abs(psi).^2; - E.Eddi = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz; - - % EddiTot = trapz(Eddi(:))*Transf.dx*Transf.dy*Transf.dz; - - %Kinetic energy - % psik = ifftshift(fftn(fftshift(psi)))*normfac; - - Ekin = KEop.*abs(fftn(psi)*normfac).^2; - E.Ekin = trapz(Ekin(:))*Transf.dkx*Transf.dky*Transf.dkz/(2*pi)^3; - - % Potential energy - Epot = V.*abs(psi).^2; - E.Epot = trapz(Epot(:))*Transf.dx*Transf.dy*Transf.dz; - - %Contact interactions - Eint = 0.5*Params.gs*abs(psi).^4; - E.Eint = trapz(Eint(:))*Transf.dx*Transf.dy*Transf.dz; - - %Quantum fluctuations - Eqf = 0.4*Params.gammaQF*abs(psi).^5; - E.Eqf = trapz(Eqf(:))*Transf.dx*Transf.dy*Transf.dz; - -end diff --git a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNormalizedResiduals.m b/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNormalizedResiduals.m deleted file mode 100644 index 134e426..0000000 --- a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNormalizedResiduals.m +++ /dev/null @@ -1,25 +0,0 @@ -function res = calculateNormalizedResiduals(~,psi,Params,Transf,VDk,V,muchem) - - KEop= 0.5*(Transf.KX.^2+Transf.KY.^2+Transf.KZ.^2); - - % DDIs - frho=fftn(abs(psi).^2); - Phi=real(ifftn(frho.*VDk)); - - Eddi = Params.gdd*Phi.*psi; - - %Kinetic energy - Ekin = ifftn(KEop.*fftn(psi)); - - %Potential energy - Epot = V.*psi; - - %Contact interactions - Eint = Params.gs*abs(psi).^2.*psi; - - %Quantum fluctuations - 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 \ No newline at end of file diff --git a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNumericalHankelTransform.m b/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNumericalHankelTransform.m deleted file mode 100644 index b3d96c6..0000000 --- a/Dipolar Gas Simulator/+Simulator/@Calculator/calculateNumericalHankelTransform.m +++ /dev/null @@ -1,39 +0,0 @@ -function VDkSemi = calculateNumericalHankelTransform(~,kr,kz,Rmax,Zmax,Nr) - - % accuracy inputs for numerical integration - if(nargin==5) - Nr = 5e4; - end - - Nz = 64; - farRmultiple = 2000; - - % midpoint grids for the integration over 0