Moved calculations of capture velocity, cut-off, reduced Clausing factor and reduced flux to here, changed the condition for the velocity sampling to correctly sample from the normalized probability distributions.

This commit is contained in:
Karthik 2021-07-11 06:40:19 +02:00
parent 47a93001c8
commit e16ac42415

View File

@ -1,47 +1,67 @@
function ret = initialVelocitySampling(this) function ret = initialVelocitySampling(this)
n = this.NumberOfAtoms; switch this.SimulationMode
case "2D"
n = this.NumberOfAtoms;
ret = zeros(n,3); % Calculate Calculate Capture velocity --> Introduce velocity cutoff
SampledVelocityMagnitude = zeros(n,1);
SampledPolarAngle = zeros(n,1);
SampledAzimuthalAngle = zeros(n,1);
MostProbableVelocity = sqrt((3 * Helper.PhysicsConstants.BoltzmannConstant * this.OvenTemperature) / Helper.PhysicsConstants.Dy164Mass); % For v * f(v) distribution this.CaptureVelocity = 1.05 * this.calculateCaptureVelocity([-this.OvenDistance,0,0], [1,0,0]);
this.VelocityCutoff = this.CaptureVelocity(1); % Should be the magnitude of the 3-D velocity vector but since here the obtained capture
% velocity is only along the x-axis, we take the first term which is the x-component of the velocity.
if MostProbableVelocity > this.VelocityCutoff [ReducedClausingFactor, NormalizationConstantForAngularDistribution] = this.calculateReducedClausingFactor();
MaximumVelocityAllowed = this.VelocityCutoff; this.ReducedClausingFactor = ReducedClausingFactor;
else
MaximumVelocityAllowed = MostProbableVelocity;
end
ProbabilityOfMaximumVelocityAllowed = this.velocityDistributionFunction(MaximumVelocityAllowed);
ProbabilityOfMaximumDivergenceAngleAllowed = 0.98 * this.NormalizationConstantForAngularDistribution * max(this.AngularDistribution .* sin(this.ThetaArray));
parfor i = 1:n VelocityDistribution = @(velocity) sqrt(2 / pi) * sqrt(Helper.PhysicsConstants.Dy164Mass/(Helper.PhysicsConstants.BoltzmannConstant * this.OvenTemperatureinKelvin))^3 ...
% Rejection Sampling of speed * velocity.^3 .* exp(-velocity.^2 .* (Helper.PhysicsConstants.Dy164Mass / (2 * Helper.PhysicsConstants.BoltzmannConstant ...
y = ProbabilityOfMaximumVelocityAllowed * rand(1); * this.OvenTemperatureinKelvin)));
x = this.VelocityCutoff * rand(1);
while y > this.velocityDistributionFunction(x) %As long as this loop condition is satisfied, reject the corresponding x value c = integral(VelocityDistribution, 0, this.VelocityCutoff)/integral(VelocityDistribution,0,Inf);
y = ProbabilityOfMaximumVelocityAllowed * rand(1);
x = this.VelocityCutoff * rand(1);
end
SampledVelocityMagnitude(i) = x; % When loop condition is not satisfied, accept x value and store as sample
% Rejection Sampling of polar angle this.ReducedFlux = c * this.ReducedClausingFactor * this.calculateFreeMolecularRegimeFlux();
z = this.MOTExitDivergence * rand(1);
w = ProbabilityOfMaximumDivergenceAngleAllowed * rand(1);
while w > (this.NormalizationConstantForAngularDistribution * this.angularDistributionFunction(z) * sin(z)) %As long as this loop condition is satisfied, reject the corresponding x value ret = zeros(n,3);
z = this.MOTExitDivergence * rand(1); SampledVelocityMagnitude = zeros(n,1);
w = ProbabilityOfMaximumDivergenceAngleAllowed * rand(1); SampledPolarAngle = zeros(n,1);
end SampledAzimuthalAngle = zeros(n,1);
SampledPolarAngle(i) = z; %When loop condition is not satisfied, accept x value and store as sample
% Sampling of azimuthal angle MostProbableVelocity = sqrt((3 * Helper.PhysicsConstants.BoltzmannConstant * this.OvenTemperature) / Helper.PhysicsConstants.Dy164Mass); % For v * f(v) distribution
SampledAzimuthalAngle(i)= 2 * pi * rand(1);
ret(i,:)=[SampledVelocityMagnitude(i)*cos(SampledPolarAngle(i)), SampledVelocityMagnitude(i)*sin(SampledPolarAngle(i))*cos(SampledAzimuthalAngle(i)), ... if MostProbableVelocity > this.VelocityCutoff
SampledVelocityMagnitude(i)*sin(SampledPolarAngle(i))*sin(SampledAzimuthalAngle(i))]; MaximumVelocityAllowed = this.VelocityCutoff;
else
MaximumVelocityAllowed = MostProbableVelocity;
end
NormalizationConstantForVelocityDistribution = this.velocityDistributionFunction(MaximumVelocityAllowed);
parfor i = 1:n
% Rejection Sampling of speed
y = rand(1);
x = this.VelocityCutoff * rand(1);
while y > ((NormalizationConstantForVelocityDistribution)^-1 * this.velocityDistributionFunction(x)) %As long as this loop condition is satisfied, reject the corresponding x value
y = rand(1);
x = this.VelocityCutoff * rand(1);
end
SampledVelocityMagnitude(i) = x; % When loop condition is not satisfied, accept x value and store as sample
% Rejection Sampling of polar angle
w = rand(1);
z = this.NozzleExitDivergence * rand(1);
while w > ((NormalizationConstantForAngularDistribution)^-1 * 2 * pi * this.angularDistributionFunction(z) * sin(z)) %As long as this loop condition is satisfied, reject the corresponding x value
w = rand(1);
z = this.NozzleExitDivergence * rand(1);
end
SampledPolarAngle(i) = z; %When loop condition is not satisfied, accept x value and store as sample
% Sampling of azimuthal angle
SampledAzimuthalAngle(i)= 2 * pi * rand(1);
ret(i,:)=[SampledVelocityMagnitude(i)*cos(SampledPolarAngle(i)), SampledVelocityMagnitude(i)*sin(SampledPolarAngle(i))*cos(SampledAzimuthalAngle(i)), ...
SampledVelocityMagnitude(i)*sin(SampledPolarAngle(i))*sin(SampledAzimuthalAngle(i))];
end
case "3D"
% Development In progress
end end
end end