mctools / ncrystal

NCrystal : a library for thermal neutron transport in crystals and other materials
https://mctools.github.io/ncrystal/
Other
41 stars 18 forks source link

Density bug in multiphase-materials with both density and scatter keywords #182

Closed tkittel closed 3 months ago

tkittel commented 5 months ago

Somehow, the density keyword inside a phase in connection with scatter-cfg hints affect the reported material density!:

$> nctool -d 'phases<0.25*Ge_sg227.ncmat;density=1gcm3&0.75*Al_sg225.ncmat>'|grep Density
Density : 2.27398 g/cm3, 0.0472471 atoms/Aa^3
$> nctool -d 'phases<0.25*Ge_sg227.ncmat;density=1gcm3&0.75*Al_sg225.ncmat>;vdoslux=0'|grep Density
Density : 1 g/cm3, 0.0207772 atoms/Aa^3

This is a clear bug!! Without the density keyword, this is not seen:

$> nctool -d 'phases<0.25*Ge_sg227.ncmat&0.75*Al_sg225.ncmat>;vdoslux=0'|grep Density
Density : 3.35618 g/cm3, 0.0562199 atoms/Aa^3
$> nctool -d 'phases<0.25*Ge_sg227.ncmat&0.75*Al_sg225.ncmat>'|grep Density
Density : 3.35618 g/cm3, 0.0562199 atoms/Aa^3
tkittel commented 5 months ago

This seems to be a bug in the MatCfg class, as the normalised version is clearly wrong:

$> nctool --cfg 'phases<0.25*Ge_sg227.ncmat;density=1gcm3&0.75*Al_sg225.ncmat>;vdoslux=0'
==> Debugging cfg-string: "phases<0.25*Ge_sg227.ncmat;density=1gcm3&0.75*Al_sg225.ncmat>;vdoslux=0"
==> Normalised cfg-string : "phases<0.25*Ge_sg227.ncmat;density=1gcm3&0.75*Al_sg225.ncmat>;vdoslux=0;density=1gcm3"
tkittel commented 5 months ago

The bug is in MatCfg::toStrCfg, since createInfo(..) with the original cfg string gives the correct density. However, nctool passes the normalised (i.e. processed by MatCfg::toStrCfg) to createInfo(), thus triggering the bug.

tkittel commented 5 months ago

Same issue for phasechoice params:

$> sb_ncperfval_normcfg 'phases<0.25*NCTestData/Al_Sapphire_mix_test.ncmat;phasechoice=0&0.75*Al_sg225.ncmat>;vdoslux=0'
cfgstring in:         >>phases<0.25*NCTestData/Al_Sapphire_mix_test.ncmat;phasechoice=0&0.75*Al_sg225.ncmat>;vdoslux=0<<
cfgstring normalised: >>phases<0.25*NCTestData/Al_Sapphire_mix_test.ncmat;phasechoice=0&0.75*Al_sg225.ncmat>;vdoslux=0;phasechoice=0<<
tkittel commented 5 months ago

Bug found and understood, testing a fix.

tkittel commented 5 months ago

Should add unit tests for this of course.

tkittel commented 5 months ago

Fixed for next release (v3.8.3 or 3.9.0).

tkittel commented 3 months ago

Fixed in v3.9.0.