Description
Currently the code at src/input.rs scales direction cosines by length_unit for the UNIFORM/NORMAL distribution cases.
Because the unit direction is normalized afterwards it affects only cases where a user mixes uniform/normal distributions on some cosine directions and fixed values for the other components.
Location
|
ux: match cosx { |
|
Distributions::NORMAL{mean, std} => {let normal = Normal::new(mean, std).unwrap(); normal.sample(&mut rng)*length_unit}, |
|
Distributions::UNIFORM{min, max} => {let uniform = Uniform::new(min, max).unwrap(); uniform.sample(&mut rng)*length_unit}, |
|
Distributions::POINT(ux) => ux |
|
}, |
|
uy: match cosy { |
|
Distributions::NORMAL{mean, std} => {let normal = Normal::new(mean, std).unwrap(); normal.sample(&mut rng)*length_unit}, |
|
Distributions::UNIFORM{min, max} => {let uniform = Uniform::new(min, max).unwrap(); uniform.sample(&mut rng)*length_unit}, |
|
Distributions::POINT(uy) => uy, |
|
}, |
|
uz: match cosz { |
|
Distributions::NORMAL{mean, std} => {let normal = Normal::new(mean, std).unwrap(); normal.sample(&mut rng)*length_unit}, |
|
Distributions::UNIFORM{min, max} => {let uniform = Uniform::new(min, max).unwrap(); uniform.sample(&mut rng)*length_unit}, |
|
Distributions::POINT(uz) => uz, |
|
}, |
Reproduction
Input with meter units for the particle position:
[options]
name = "meter_"
track_trajectories = true
track_recoils = false
[particle_parameters]
length_unit = "M"
energy_unit = "EV"
mass_unit = "AMU"
N = [ 3 ]
m = [ 4.0026 ]
Z = [ 2 ]
E = [ 1000.0 ]
Ec = [ 1.0 ]
Es = [ 0.0 ]
pos = [ [ 1.0e-7, 0.0, 0.0 ] ]
dir = [ [ {min = 0.5, max = 0.6}, 0.8, 0.0 ] ]
[geometry_input]
length_unit = "ANGSTROM"
densities = [ 0.059 ]
electronic_stopping_correction_factor = 1.0
[material_parameters]
energy_unit = "EV"
mass_unit = "AMU"
Eb = [ 0.0 ]
Es = [ 0.0 ]
Ec = [ 1.0 ]
Z = [ 79 ]
m = [ 196.967 ]
Input with angstrom units for the particle position:
[options]
name = "angstrom_"
track_trajectories = true
track_recoils = false
[particle_parameters]
length_unit = "ANGSTROM"
energy_unit = "EV"
mass_unit = "AMU"
N = [ 3 ]
m = [ 4.0026 ]
Z = [ 2 ]
E = [ 1000.0 ]
Ec = [ 1.0 ]
Es = [ 0.0 ]
pos = [ [ 1000.0, 0.0, 0.0 ] ]
dir = [ [ {min = 0.5, max = 0.6}, 0.8, 0.0 ] ]
[geometry_input]
length_unit = "ANGSTROM"
densities = [ 0.059 ]
electronic_stopping_correction_factor = 1.0
[material_parameters]
energy_unit = "EV"
mass_unit = "AMU"
Eb = [ 0.0 ]
Es = [ 0.0 ]
Ec = [ 1.0 ]
Z = [ 79 ]
m = [ 196.967 ]
Current behavior
❯ RustBCA 0D mwe_angstrom.toml
❯ head -3 angstrom_trajectories.output
4.0026,2,1000,1000,0,0
4.0026,2,999.9111591680867,1000,0,0
4.0026,2,995.9127187898878,1000.0000000001257,1.7620556276702002,0
❯ awk -F, 'NR==1{x=$4;y=$5;z=$6} NR==3{dx=$4-x;dy=$5-y;dz=$6-z;n=sqrt(dx*dx+dy*dy+dz*dz);printf "%.4f %.4f %.4f\n",dx/n,dy/n,dz/n; exit}' angstrom_trajectories.output
0.0000 1.0000 0.0000
❯ RustBCA 0D mwe_meter.toml
❯ head -3 meter_trajectories.output
4.0026,2,1000,0.0000001,0,0
4.0026,2,999.9111591680867,0.0000001,0,0
4.0026,2,995.9127187898878,0.00000010010235553881618,0.0000000001434285328088165,0
❯ awk -F, 'NR==1{x=$4;y=$5;z=$6} NR==3{dx=$4-x;dy=$5-y;dz=$6-z;n=sqrt(dx*dx+dy*dy+dz*dz);printf "%.4f %.4f %.4f\n",dx/n,dy/n,dz/n; exit}' meter_trajectories.output
0.5809 0.8140 0.0000
The initial direction is different even though the inputs are equivalent.
Expected behavior
A unit-less quantity should not be scaled by length units.
The initial direction should be the same in both runs.
Generative AI Use
This problem was found with the help of Claude Opus 5.5.
The inputs and the short awk command were also generated with its help.
Description
Currently the code at src/input.rs scales direction cosines by length_unit for the UNIFORM/NORMAL distribution cases.
Because the unit direction is normalized afterwards it affects only cases where a user mixes uniform/normal distributions on some cosine directions and fixed values for the other components.
Location
RustBCA/src/input.rs
Lines 593 to 607 in 328f468
Reproduction
Input with meter units for the particle position:
Input with angstrom units for the particle position:
Current behavior
The initial direction is different even though the inputs are equivalent.
Expected behavior
A unit-less quantity should not be scaled by length units.
The initial direction should be the same in both runs.
Generative AI Use
This problem was found with the help of Claude Opus 5.5.
The inputs and the short awk command were also generated with its help.