fast-nuclear-sim/src/reactor/rod.cpp

60 lines
930 B
C++
Raw Normal View History

2024-01-14 16:57:13 +11:00
#include "rod.hpp"
#include "reactor.hpp"
2024-01-14 16:57:13 +11:00
2024-01-15 12:45:22 +11:00
#include <cmath>
2024-01-14 17:07:45 +11:00
using namespace sim::reactor;
2024-01-14 16:57:13 +11:00
double rod::get(val_t type) const
{
return vals[type];
}
void rod::add(val_t type, double v)
{
2024-01-18 18:00:39 +11:00
vals[type] += v;
2024-01-14 16:57:13 +11:00
}
2024-01-15 16:30:54 +11:00
double rod::extract(val_t type, double s, double k, double o)
2024-01-14 16:57:13 +11:00
{
2024-01-15 17:15:08 +11:00
k *= get_k(type);
double m = 1;
2024-01-18 18:00:39 +11:00
k = 1 - k * get_k(type);
if(k > 0)
2024-01-15 17:15:08 +11:00
{
2024-01-18 18:00:39 +11:00
m = 1 - std::pow(0.5, s * -std::log2(k));
2024-01-15 17:15:08 +11:00
}
2024-01-18 18:00:39 +11:00
2024-01-15 17:15:08 +11:00
double v = m * 0.5 * (get(type) - o);
2024-01-18 18:00:39 +11:00
vals[type] -= v;
2024-01-14 16:57:13 +11:00
return v;
}
2024-01-14 17:50:43 +11:00
void rod::interact(rod* o, double secs)
2024-01-14 16:57:13 +11:00
{
for(int i = 0; i < rod::VAL_N; i++)
{
val_t v = (val_t)i;
2024-01-15 16:30:54 +11:00
add(v, o->extract(v, secs, get_k(v), get(v)));
2024-01-14 16:57:13 +11:00
}
}
double rod::get_volume() const
{
auto r = (sim::reactor::reactor*)reactor;
return r->cell_width * r->cell_width * r->cell_height;
}
2024-01-18 18:00:39 +11:00
void rod::update_rod(double secs)
{
2024-01-15 16:30:54 +11:00
// decay the free neutrons
double m = std::pow(0.5, secs / 879.4);
vals[val_t::N_FAST] *= m;
vals[val_t::N_SLOW] *= m;
2024-01-14 16:57:13 +11:00
}