public PreprocessedDatabase([NotNull] IDatabase db, [NotNull] IEnumerable<Element> target, Region region_eV, int n) { if (db == null) throw new ArgumentNullException("db"); if (target == null) throw new ArgumentNullException("target"); var elements = target as Element[] ?? target.ToArray(); var zs = elements.Select(e => e.AtomicNumber).ToArray(); var lineGroups = db.LineGroups.Where(lg => zs.Contains(lg.AtomicNumber)); LineGroups = new ReadOnlyCollection<LineGroup>(lineGroups.ToList()); TotalMassAtten = new ElementCoefficientCollection(); foreach (var e in elements) { var tma = db.TotalMassAtten[e.AtomicNumber]; var compiled = new PreprocessedCoefficients(e, tma.GetValue, region_eV, n); TotalMassAtten.Add(compiled); } PhotoElectricAbs = new ElementCoefficientCollection(); foreach (var e in elements) { var pea = db.PhotoElectricAbs[e.AtomicNumber]; var compiled = new PreprocessedCoefficients(e, pea.GetValue, region_eV, n); PhotoElectricAbs.Add(compiled); } }
public void CompiledTest() { var db = new Database {DirectoryPath = @"C:\Users\X-BrIdge Tech\Desktop\data"}; db.Load(); const int z = 22; var compiled = new PreprocessedCoefficients( Elements.Get(z), db.TotalMassAtten[z].GetValue, new Region(0, 11000), 11000); // normal // AtomicNumber=22, Energy=1k, // lambda = 12.4A, ln_lambda = 2.5177 // coherent_index = 8.677, coherent = 5868.2 // incoherent = 6.6265e-29 var expected = 5868.2; var actual = compiled.GetValue(1000); var delta = 5.0; Assert.AreEqual(expected, actual, delta); // normal // AtomicNumber=22, Energy=10k, // lambda = 1.24A, ln_lambda = 0.215... // coherent_index = 4.7071, coherent = 110.73 // incoherent = 6.6047E-29 expected = 110.7; actual = compiled.GetValue(10000); delta = 5; Assert.AreEqual(expected, actual, delta); }