Skip to content

Commit fd3de52

Browse files
committed
Merge remote-tracking branch 'gonuke/decay_absorb' into decay_absorb
2 parents 934d546 + c21f51f commit fd3de52

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Since last release
4242

4343

4444
**Changed:**
45+
* Absorb back to respect manual decay mode and the logic of the decay conditional (#1918)
4546
* Modified cycpp.py to fix a few whitespace-related bugs, and allow cyclus vars to be initialized (#1954)
4647
* Changed the epsilon (eps) in Material::Decay to 1e-4 allowing 1 day decay of tritium (#1946)
4748
* Changed the schema for recipes to require oneOrMore instead of zeroOrMore (#1940)

src/material.cc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,34 @@ Material::Ptr Material::ExtractComp(double qty, Composition::Ptr c,
103103
}
104104

105105
void Material::Absorb(Material::Ptr mat) {
106+
107+
bool tracked = HasContext();
108+
bool mat_tracked = mat->HasContext();
106109

107-
// Handle absorb-specific decay rules
108-
int common_decay_time;
109-
if (HasContext() != mat->HasContext()) {
110+
if (tracked != mat_tracked) {
110111
throw cyclus::Error("Cannot combine a tracked and untracked material!");
111-
} else if (!HasContext()) {
112-
// both materials are untracked
112+
}
113+
114+
if (!tracked) {
113115
if (mat->prev_decay_time_ > prev_decay_time_) {
114-
throw ValueError("Cannot absorb a material that is more decayed than this one");
115-
} else {
116-
common_decay_time = prev_decay_time_;
116+
throw ValueError(
117+
"Cannot absorb a material that is more decayed than this one");
117118
}
118-
} else {
119-
// both materials are tracked
120-
common_decay_time = ctx_->time();
121-
}
122119

123-
mat->Decay(common_decay_time);
124-
this->Decay(common_decay_time);
120+
// Synchronize the incoming material with this material.
121+
mat->Decay(prev_decay_time_);
122+
} else if (ctx_->sim_info().decay == "lazy") {
123+
// NOTE: Absorb will only Decay materials like this if the decay mode is
124+
// set to lazy. If more decay modes are introduced in the future which
125+
// want Absorb to decay, this will need to be changed
126+
int common_decay_time = ctx_->time();
127+
128+
mat->Decay(common_decay_time);
129+
Decay(common_decay_time);
125130

126-
// manually update decay time in case the change was so small
127-
// that no decay was invoked
128-
this->prev_decay_time_ = common_decay_time;
131+
// Decay may return early when the change is below its threshold.
132+
prev_decay_time_ = common_decay_time;
133+
}
129134

130135
// these calls force lazy evaluation if in lazy decay mode
131136
Composition::Ptr c0 = comp();

tests/material_tests.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ TEST_F(MaterialTest, TransmutePrevDecay) {
454454

455455
TEST_F(MaterialTest, AbsorbPrevDecay) {
456456
FakeContext* fake_ctx = new FakeContext(&ti, &rec);
457+
458+
// FakeContexts get generated with "manual" decay by default,
459+
// so we need to set it to lazy to get Absorb to decay.
460+
SimInfo lazy_si(100, 2015, 1, "", "lazy");
461+
fake_ctx->InitSim(lazy_si);
462+
457463
TestFacility* fake_fac = new TestFacility(fake_ctx);
458464

459465
double untracked_qty = 1.0;

0 commit comments

Comments
 (0)