75 void step(
const std::vector<double>& c, std::vector<double>& cOut,
double dt,
double D,
78 cOut.assign(
static_cast<std::size_t
>(n), 0.0);
79 for (Index i = 0; i < n; ++i) {
80 const double ci = c[
static_cast<std::size_t
>(i)];
82 forEachFace(i, [&](Index j,
int axis,
int oSign, Real area,
const Vec<Dim>& fc, Real dist) {
83 const double cj = c[
static_cast<std::size_t
>(j)];
84 const double unOut = oSign *
static_cast<double>(vel(fc, axis));
85 const double cUp = (unOut > 0.0) ? ci : cj;
86 flux += area * unOut * cUp;
87 flux += -D * area * (cj - ci) / dist;
89 cOut[
static_cast<std::size_t
>(i)] = ci - dt * flux /
cellVolume(i);
97 auto b = t_->bounds(i);
98 const auto& lo = b[0];
99 const unsigned Li = t_->level(i);
101 for (
int axis = 0; axis < Dim; ++axis)
102 for (
int dir = -1; dir <= 1; dir += 2) {
103 const long pc = (dir > 0) ?
static_cast<long>(lo[axis]) +
static_cast<long>(si)
104 :
static_cast<long>(lo[axis]) - 1;
105 const long facePlane = (dir > 0) ?
static_cast<long>(lo[axis]) +
static_cast<long>(si)
106 :
static_cast<long>(lo[axis]);
107 std::array<Coord, Dim> p = lo;
108 p[axis] = wrap(pc, axis);
109 Index j0 = t_->find(M::encode(p).code());
110 const unsigned Lj = t_->level(j0);
112 fn(j0, axis, dir, faceArea(si, axis),
113 faceCentre(lo, axis, facePlane, std::array<Coord, Dim>{}, si),
114 0.5 * (
static_cast<Real
>(si) +
static_cast<Real
>(
Coord(
Coord(1) << Lj))) *
118 const int nsub = 1 << (Dim - 1);
119 for (
int k = 0; k < nsub; ++k) {
120 std::array<Coord, Dim> q = lo;
121 q[axis] = wrap(pc, axis);
122 std::array<Coord, Dim> off{};
124 for (
int t = 0; t < Dim; ++t) {
127 off[t] = ((k >> bit) & 1) ? sj :
Coord(0);
128 q[t] = wrap(
static_cast<long>(lo[t]) +
static_cast<long>(off[t]), t);
131 Index jj = t_->find(M::encode(q).code());
132 fn(jj, axis, dir, faceArea(sj, axis), faceCentre(lo, axis, facePlane, off, sj),
133 0.5 * (
static_cast<Real
>(si) +
static_cast<Real
>(sj)) * geo_.h0[axis]);