File indexing completed on 2025-12-16 09:24:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Material/AccumulatedVolumeMaterial.hpp"
0012 #include "Acts/Material/Material.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0015
0016 #include <cmath>
0017
0018 using namespace Acts;
0019
0020 namespace ActsTests {
0021
0022 BOOST_AUTO_TEST_SUITE(MaterialSuite)
0023
0024 BOOST_AUTO_TEST_CASE(vacuum) {
0025 AccumulatedVolumeMaterial avm;
0026
0027
0028 BOOST_CHECK(avm.average().isVacuum());
0029
0030
0031 avm.accumulate(MaterialSlab::Vacuum(1));
0032 BOOST_CHECK(avm.average().isVacuum());
0033 }
0034
0035 BOOST_AUTO_TEST_CASE(single_material) {
0036 Material mat = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0037 MaterialSlab matprop(mat, 1);
0038 AccumulatedVolumeMaterial avm;
0039
0040
0041 avm.accumulate(matprop);
0042 {
0043 auto result = avm.average();
0044 CHECK_CLOSE_REL(result.parameters(), mat.parameters(), 1e-4);
0045 CHECK_CLOSE_REL(result.L0(), mat.L0(), 1e-4);
0046 CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
0047 CHECK_CLOSE_REL(result.Z(), mat.Z(), 1e-4);
0048 CHECK_CLOSE_REL(result.molarDensity(), mat.molarDensity(), 1e-4);
0049 CHECK_CLOSE_REL(result.massDensity(), mat.massDensity(), 1e-4);
0050 }
0051
0052 avm.accumulate(MaterialSlab::Vacuum(1));
0053 {
0054 auto result = avm.average();
0055
0056 CHECK_CLOSE_REL(result.X0(), 2 * mat.X0(), 1e-4);
0057 CHECK_CLOSE_REL(result.L0(), 2 * mat.L0(), 1e-4);
0058
0059 CHECK_CLOSE_REL(result.molarDensity(), 0.5 * mat.molarDensity(), 1e-4);
0060 CHECK_CLOSE_REL(result.massDensity(), 0.5 * mat.massDensity(), 1e-4);
0061
0062 CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
0063 CHECK_CLOSE_REL(result.Z(), 0.5 * mat.Z(), 1e-4);
0064 }
0065 }
0066
0067 BOOST_AUTO_TEST_CASE(two_materials) {
0068 Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0069 Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
0070
0071 MaterialSlab matprop1(mat1, 1);
0072 MaterialSlab matprop2(mat2, 1);
0073
0074 AccumulatedVolumeMaterial avm;
0075 avm.accumulate(matprop1);
0076 avm.accumulate(matprop2);
0077 auto result = avm.average();
0078 CHECK_CLOSE_REL(result.X0(), 2. / (1. / 1. + 1. / 6.), 1e-4);
0079 CHECK_CLOSE_REL(result.L0(), 2. / (1. / 2. + 1. / 7.), 1e-4);
0080 CHECK_CLOSE_REL(result.Ar(), (5 * 3. + 10 * 8.) / (5 + 10), 1e-4);
0081 CHECK_CLOSE_REL(result.Z(),
0082 std::exp((1. / 2.) * std::log(4.) + (1. / 2.) * std::log(9.)),
0083 1e-4);
0084 CHECK_CLOSE_REL(result.molarDensity(), 0.5 * (5. + 10.), 1e-4);
0085 }
0086
0087 BOOST_AUTO_TEST_CASE(two_materials_different_lengh) {
0088 Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0089 Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
0090
0091 MaterialSlab matprop1(mat1, 0.5);
0092 MaterialSlab matprop2(mat2, 2);
0093
0094 AccumulatedVolumeMaterial avm;
0095 avm.accumulate(matprop1);
0096 avm.accumulate(matprop2);
0097 auto result = avm.average();
0098 CHECK_CLOSE_REL(result.X0(), 2.5 / (0.5 / 1. + 2. / 6.), 1e-4);
0099 CHECK_CLOSE_REL(result.L0(), 2.5 / (0.5 / 2. + 2. / 7.), 1e-4);
0100 CHECK_CLOSE_REL(result.Ar(),
0101 (0.5 * 5 * 3. + 2 * 10 * 8.) / (0.5 * 5 + 2 * 10), 1e-4);
0102 CHECK_CLOSE_REL(result.Z(),
0103 std::exp((0.5 / (0.5 + 2.)) * std::log(4.) +
0104 (2. / (0.5 + 2.)) * std::log(9.)),
0105 1e-4);
0106 CHECK_CLOSE_REL(result.molarDensity(), (0.5 * 5. + 2 * 10.) / (0.5 + 2),
0107 1e-4);
0108 }
0109
0110 BOOST_AUTO_TEST_SUITE_END()
0111
0112 }