Example #1
0
void compare_pressure(const GI& g, const std::vector<double>& p)
{
    typedef typename GI::CellIterator CI;
    int count = 0;
    double l1err = 0.0;
    double l2err = 0.0;
    double linferr = 0.0;
    double totv = 0.0;
    for (CI c = g.cellbegin(); c != g.cellend(); ++c, ++count) {
        Vec cen = c->centroid();
        double uval = u(cen);
        double diff = uval - p[count];
        double v = c->volume();
        l1err += std::fabs(diff*v);
        l2err += diff*diff*v;
        linferr = std::max(std::fabs(diff), linferr);
        totv += v;
        // std::cout << cen[0] << ' ' << uval << ' ' << p[count] << std::endl;
    }
    l2err = std::sqrt(l2err);
    std::cout << "\n\n"
              << "\n     L1 error density: " << l1err/totv
              << "\n     L2 error density: " << l2err/totv
              << "\n     Linf error:       " << linferr << "\n\n\n";
}
Example #2
0
void assign_src(const GI& g, std::vector<double>& src)
{
    typedef typename GI::CellIterator CI;
    int count = 0;
    for (CI c = g.cellbegin(); c != g.cellend(); ++c) {
        src[count++] = -Lu(c->centroid())*c->volume();
    }
}
 double setSourceBlock(const Vector& low, const Vector& high, double density, bool is_injection)
 {
     typedef typename GI::CellIterator CI;
     // Iterate over all cells, if the centroid of a cell is in the
     // domain given, set a source term. Accumulate total source terms.
     double total_rate = 0.0;
     for (CI c = this->ginterf_.cellbegin(); c != this->ginterf_.cellend(); ++c) {
         if (isInside(low, high, c->centroid())) {
             int index = c->index();
             double rate = density*c->volume();
             if (!is_injection) {
                 rate = -rate;
             }
             total_rate += rate;
             this->injection_rates_.addElement(rate, index);
             this->injection_rates_psolver_[index] = rate;
         }
     }
     return total_rate;
 }