示例#1
0
文件: rkcell.cpp 项目: Abbath/lbsim
void RKCell::preUpdate(double epsilon[], BaseCell* neighbors[], Grid *grid, Vector3i position) {
    int model = Shared::instance()->getGridConfig()->getModel();
    MyVector3D colorGradient = MyVector3D();
    for (int a = 0; a < model; a++) {
        Vector3i neighbor = position + LBUtil::C[model][a];
        RKCell *cell = dynamic_cast<RKCell*>(grid->getGrid(neighbor.getY(), neighbor.getX(), neighbor.getZ()));
        if (cell != 0) {
            colorGradient = colorGradient + (LBUtil::C[model][a] ^ cell->getColor());
        }
    }
    for (int i = 0; i < model; i++) {
        double fi = red[i] + blue[i];
        double p = redP + blueP;
        double nextF = fi + 1.0 / epsilon[0] * (LBUtil::f_eq(u, p, model, i) - fi);
        double cos = (LBUtil::C[model][i] * colorGradient);
        if (colorGradient.norm() > 1e-10 && LBUtil::C[model][i].norm() > 1e-10) {
            cos = cos / (LBUtil::C[model][i].norm() * colorGradient.norm());
        } else {
            //cos = std::sqrt(2.0) / 2;
            //cos = 1;
            cos = 0;
        }
        GridConfig *config = Shared::instance()->getGridConfig();
        nextF += config->getRkA() * colorGradient.norm() * (2 * cos * cos - 1);
        double diff = config->getRkBeta() * redP * blueP / (p * p) * LBUtil::W[model][i] * p * cos;
        //double diff = 0;
        double newNextRed = redP / p * nextF + diff;
        double newNextBlue = blueP / p * nextF - diff;
        if (neighbors[i] != 0) {
            neighbors[i]->setNextF(i, newNextRed, 0);
            neighbors[i]->setNextF(i, newNextBlue, 1);
        }
    }
}
示例#2
0
void DepositionCell::postUpdate(Grid *grid, Vector3i position) {
    for (int i = 0; i < 9; i++) {
        Vector3i neighbor = position + LBUtil::C[9][i];
        nextG[i] = g[i] + deposited * (grid->getGrid(neighbor.getY(), neighbor.getX(), neighbor.getZ())->getF(LBUtil::OPPOSITE[9][i], 1) - g[i]);
    }
    for (int i = 0; i < 9; i++) {
        g[i] = nextG[i];
    }
}