Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
29 changes: 20 additions & 9 deletions tests/material_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/material_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "test_agents/test_facility.h"
#include "recorder.h"
#include "timer.h"
#include "test_context.h"


namespace cyclus {
Expand Down