/// @brief Computes phase mobilities for a set of saturation values.
    /// @param[in]  props     rock and fluid properties
    /// @param[in]  cells     cells with which the saturation values are associated
    /// @param[in]  p         pressure (one value per cell)
    /// @param[in]  z         surface-volume values (for all P phases)
    /// @param[in]  s         saturation values (for all phases)
    /// @param[out] pmobc     phase mobilities (for all phases).
    void computePhaseMobilities(const Opm::BlackoilPropertiesInterface& props,
                                const std::vector<int>&                 cells,
                                const std::vector<double>&              p,
                                const std::vector<double>&              z,
                                const std::vector<double>&              s,
                                std::vector<double>&                    pmobc)
    {
        const int nc = props.numCells();
        const int np = props.numPhases();

        assert(int(s.size()) == nc * np);

        std::vector<double> mu(nc*np);
        props.viscosity(nc, &p[0], &z[0], &cells[0], &mu[0], 0);

        pmobc.clear();
        pmobc.resize(nc*np, 0.0);
        double* dpmobc = 0;
        props.relperm(nc, &s[0], &cells[0],
                      &pmobc[0], dpmobc);

        std::transform(pmobc.begin(), pmobc.end(),
                       mu.begin(),
                       pmobc.begin(),
                       std::divides<double>());
    }
TransportSolverCompressibleTwophaseReorder::TransportSolverCompressibleTwophaseReorder(
    const UnstructuredGrid& grid,
    const Opm::BlackoilPropertiesInterface& props,
    const double tol,
    const int maxit)
    : grid_(grid),
      props_(props),
      tol_(tol),
      maxit_(maxit),
      darcyflux_(0),
      source_(0),
      dt_(0.0),
      saturation_(grid.number_of_cells, -1.0),
      fractionalflow_(grid.number_of_cells, -1.0),
      gravity_(0),
      mob_(2*grid.number_of_cells, -1.0),
      ia_upw_(grid.number_of_cells + 1, -1),
      ja_upw_(grid.number_of_faces, -1),
      ia_downw_(grid.number_of_cells + 1, -1),
      ja_downw_(grid.number_of_faces, -1)
{
    if (props.numPhases() != 2) {
        OPM_THROW(std::runtime_error, "Property object must have 2 phases");
    }
    int np = props.numPhases();
    int num_cells = props.numCells();
    visc_.resize(np*num_cells);
    A_.resize(np*np*num_cells);
    smin_.resize(np*num_cells);
    smax_.resize(np*num_cells);
    allcells_.resize(num_cells);
    for (int i = 0; i < num_cells; ++i) {
        allcells_[i] = i;
    }
    props.satRange(props.numCells(), &allcells_[0], &smin_[0], &smax_[0]);
}