diff --git a/src/material.cc b/src/material.cc index 74405274da..68be084017 100644 --- a/src/material.cc +++ b/src/material.cc @@ -128,7 +128,11 @@ void Material::Absorb(Material::Ptr mat) { comp_ = Composition::CreateFromMass(compmath::Add(v, otherv)); } - qty_ += mat->qty_; + double tot_mass = qty_ + mat->quantity(); + double avg_unit_value = + (qty_ * UnitValue() + mat->quantity() * mat->UnitValue()) / tot_mass; + SetUnitValue(avg_unit_value); + qty_ = tot_mass; mat->qty_ = 0; tracker_.Absorb(&mat->tracker_); } diff --git a/tests/material_tests.cc b/tests/material_tests.cc index a0566102f8..89b05c5141 100644 --- a/tests/material_tests.cc +++ b/tests/material_tests.cc @@ -408,23 +408,34 @@ TEST_F(MaterialTest, TransmutePrevDecay) { // as coded. We may decide to change the behavior in the future breaking // this test; the test will need to be modified accordingly. // -// This test checks to see that, when materials are absorbed together, the -// previous decay time for the larger quantity material is used as the value -// for the new, combined material. +// This test checks to see that, when materials are absorbed together, both +// materials are decayed prior to the absorption. + TEST_F(MaterialTest, AbsorbPrevDecay) { - Material::Ptr m1 = Material::Create(fac, 1, diff_comp_); - Material::Ptr m2 = Material::Create(fac, 1, diff_comp_); - Material::Ptr m3 = Material::Create(fac, 1000, diff_comp_); - m3->Decay(10); + FakeContext* fake_ctx = new FakeContext(&ti, &rec); + TestFacility* fake_fac = new TestFacility(fake_ctx); + + Material::Ptr m1 = Material::Create(fake_fac, 1, diff_comp_); + Material::Ptr m2 = Material::Create(fake_fac, 1, diff_comp_); + Material::Ptr m3 = Material::Create(fake_fac, 1000, diff_comp_); + + // Set context time to 10 to match the decay time + fake_ctx->time(10); + m3->Decay(); // decay m3 to time 10 EXPECT_EQ(0, m1->prev_decay_time()); EXPECT_EQ(0, m2->prev_decay_time()); EXPECT_EQ(10, m3->prev_decay_time()); + fake_ctx->time(11); + m1->Absorb(m3); - EXPECT_EQ(10, m1->prev_decay_time()); + EXPECT_EQ(11, m1->prev_decay_time()); m1->Absorb(m2); - EXPECT_EQ(10, m1->prev_decay_time()); + EXPECT_EQ(11, m1->prev_decay_time()); + + delete fake_fac; + delete fake_ctx; } TEST_F(MaterialTest, DecayHeatTest) { diff --git a/tests/material_tests.h b/tests/material_tests.h index a562f21b3d..e49b4c35f5 100644 --- a/tests/material_tests.h +++ b/tests/material_tests.h @@ -11,6 +11,7 @@ #include "test_agents/test_facility.h" #include "recorder.h" #include "timer.h" +#include "test_context.h" namespace cyclus {