コード例 #1
0
    IncompPropertiesSinglePhase::IncompPropertiesSinglePhase(Opm::DeckConstPtr deck,
                                                             Opm::EclipseStateConstPtr eclState,
                                                             const UnstructuredGrid& grid)
    {
        rock_.init(eclState, grid.number_of_cells, grid.global_cell, grid.cartdims);

        if (deck->hasKeyword("DENSITY")) {
            Opm::DeckRecordConstPtr densityRecord = deck->getKeyword("DENSITY")->getRecord(0);
            surface_density_ = densityRecord->getItem("OIL")->getSIDouble(0);
        } else {
            surface_density_ = 1000.0;
            OPM_MESSAGE("Input is missing DENSITY -- using a standard density of "
                        << surface_density_ << ".\n");
        }

        // This will be modified if we have a PVCDO specification.
        reservoir_density_ = surface_density_;

        if (deck->hasKeyword("PVCDO")) {
            Opm::DeckRecordConstPtr pvcdoRecord = deck->getKeyword("PVCDO")->getRecord(0);
            if (pvcdoRecord->getItem("OIL_COMPRESSIBILITY")->getSIDouble(0) != 0.0 ||
                pvcdoRecord->getItem("OIL_VISCOSIBILITY")->getSIDouble(0) != 0.0) {
                OPM_MESSAGE("Compressibility effects in PVCDO are ignored.");
            }
            reservoir_density_ /= pvcdoRecord->getItem("OIL_VOL_FACTOR")->getSIDouble(0);
            viscosity_ = pvcdoRecord->getItem("OIL_VISCOSITY")->getSIDouble(0);
        } else {
            viscosity_ = 1.0 * prefix::centi*unit::Poise;
            OPM_MESSAGE("Input is missing PVCDO -- using a standard viscosity of "
                        << viscosity_ << " and reservoir density equal to surface density.\n");
        }
    }
コード例 #2
0
ファイル: phaseUsageFromDeck.hpp プロジェクト: chflo/opm-core
    /// Looks at presence of WATER, OIL and GAS keywords in deck
    /// to determine active phases.
    inline PhaseUsage phaseUsageFromDeck(Opm::DeckConstPtr deck)
    {
        PhaseUsage pu;
        std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases, 0);

        // Discover phase usage.
        if (deck->hasKeyword("WATER")) {
            pu.phase_used[BlackoilPhases::Aqua] = 1;
        }
        if (deck->hasKeyword("OIL")) {
            pu.phase_used[BlackoilPhases::Liquid] = 1;
        }
        if (deck->hasKeyword("GAS")) {
            pu.phase_used[BlackoilPhases::Vapour] = 1;
        }
        pu.num_phases = 0;
        for (int i = 0; i < BlackoilPhases::MaxNumPhases; ++i) {
            pu.phase_pos[i] = pu.num_phases;
            pu.num_phases += pu.phase_used[i];
        }

        // Only 2 or 3 phase systems handled.
        if (pu.num_phases < 2 || pu.num_phases > 3) {
            OPM_THROW(std::runtime_error, "Cannot handle cases with " << pu.num_phases << " phases.");
        }

        // We need oil systems, since we do not support the keywords needed for
        // water-gas systems.
        if (!pu.phase_used[BlackoilPhases::Liquid]) {
            OPM_THROW(std::runtime_error, "Cannot handle cases with no OIL, i.e. water-gas systems.");
        }

        return pu;
    }
コード例 #3
0
        /// set the tables which specify the temperature dependence of the water viscosity
        void initFromDeck(std::shared_ptr<const PvtInterface> isothermalPvt,
                          Opm::DeckConstPtr deck,
                          Opm::EclipseStateConstPtr eclipseState)
        {
            isothermalPvt_ = isothermalPvt;
            watvisctTables_ = 0;

            // stuff which we need to get from the PVTW keyword
            const auto& pvtwKeyword = deck->getKeyword("PVTW");
            int numRegions = pvtwKeyword.size();
            pvtwRefPress_.resize(numRegions);
            pvtwRefB_.resize(numRegions);
            pvtwCompressibility_.resize(numRegions);
            pvtwViscosity_.resize(numRegions);
            pvtwViscosibility_.resize(numRegions);
            for (int regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
                const auto& pvtwRecord = pvtwKeyword.getRecord(regionIdx);
                pvtwRefPress_[regionIdx] = pvtwRecord.getItem("P_REF").getSIDouble(0);
                pvtwRefB_[regionIdx] = pvtwRecord.getItem("WATER_VOL_FACTOR").getSIDouble(0);
                pvtwViscosity_[regionIdx] = pvtwRecord.getItem("WATER_VISCOSITY").getSIDouble(0);
                pvtwViscosibility_[regionIdx] = pvtwRecord.getItem("WATER_VISCOSIBILITY").getSIDouble(0);
            }

            // quantities required for the temperature dependence of the viscosity
            // (basically we expect well-behaved VISCREF and WATVISCT keywords.)
            if (deck->hasKeyword("VISCREF")) {
                auto tables = eclipseState->getTableManager();
                watvisctTables_ = &tables->getWatvisctTables();
                const auto& viscrefKeyword = deck->getKeyword("VISCREF");

                assert(int(watvisctTables_->size()) == numRegions);
                assert(int(viscrefKeyword.size()) == numRegions);

                viscrefPress_.resize(numRegions);
                for (int regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
                    const auto& viscrefRecord = viscrefKeyword.getRecord(regionIdx);

                    viscrefPress_[regionIdx] = viscrefRecord.getItem("REFERENCE_PRESSURE").getSIDouble(0);
                }
            }

            // quantities required for the temperature dependence of the density
            if (deck->hasKeyword("WATDENT")) {
                const auto& watdentKeyword = deck->getKeyword("WATDENT");

                assert(int(watdentKeyword.size()) == numRegions);

                watdentRefTemp_.resize(numRegions);
                watdentCT1_.resize(numRegions);
                watdentCT2_.resize(numRegions);
                for (int regionIdx = 0; regionIdx < numRegions; ++regionIdx) {
                    const auto& watdentRecord = watdentKeyword.getRecord(regionIdx);

                    watdentRefTemp_[regionIdx] = watdentRecord.getItem("REFERENCE_TEMPERATURE").getSIDouble(0);
                    watdentCT1_[regionIdx] = watdentRecord.getItem("EXPANSION_COEFF_LINEAR").getSIDouble(0);
                    watdentCT2_[regionIdx] = watdentRecord.getItem("EXPANSION_COEFF_QUADRATIC").getSIDouble(0);
                }
            }
        }
コード例 #4
0
ファイル: BlackoilPVT.cpp プロジェクト: jokva/opm-porsol
    void BlackoilPVT::init(Opm::DeckConstPtr deck)
    {
        Opm::ParseMode parseMode;
        const auto eclipseState = std::make_shared<EclipseState>(deck , parseMode);
	region_number_ = 0;

	// Surface densities. Accounting for different orders in eclipse and our code.
	if (deck->hasKeyword("DENSITY")) {
        Opm::DeckRecordConstPtr densityRecord =
            deck->getKeyword("DENSITY")->getRecord(/*regionIdx=*/0);
	    densities_[Aqua]   = densityRecord->getItem("WATER")->getSIDouble(0);
	    densities_[Vapour] = densityRecord->getItem("GAS")->getSIDouble(0);
	    densities_[Liquid] = densityRecord->getItem("OIL")->getSIDouble(0);
	} else {
	    OPM_THROW(std::runtime_error, "Input is missing DENSITY\n");
	}

        // Water PVT
        if (deck->hasKeyword("PVTW")) {
            water_props_.reset(new MiscibilityWater(deck->getKeyword("PVTW")));
        } else {
            water_props_.reset(new MiscibilityWater(0.5*Opm::prefix::centi*Opm::unit::Poise)); // Eclipse 100 default 
        }

        // Oil PVT
        const auto& tables     = eclipseState->getTableManager();
        const auto& pvdoTables = tables->getPvdoTables();
        const auto& pvtoTables = tables->getPvtoTables();
        if (!pvdoTables.empty()) {
            const auto& pvdoTable = pvdoTables.getTable<PvdoTable>(0);
            oil_props_.reset(new MiscibilityDead(pvdoTable));
        } else if (pvtoTables.empty()) {
            // PVTOTables is a std::vector<>
            const auto& pvtoTable = pvtoTables[0];
            oil_props_.reset(new MiscibilityLiveOil(pvtoTable));
        } else if (deck->hasKeyword("PVCDO")) {
            auto *misc_water = new MiscibilityWater(0);
            misc_water->initFromPvcdo(deck->getKeyword("PVCDO"));
            oil_props_.reset(misc_water);
        } else {
            OPM_THROW(std::runtime_error, "Input is missing PVDO and PVTO\n");
        }

	// Gas PVT
        const auto& pvdgTables = tables->getPvdgTables();
        const auto& pvtgTables = tables->getPvtgTables();
        if (!pvdgTables.empty()) {
            const auto& pvdgTable = pvdgTables.getTable<PvdgTable>(0);
            gas_props_.reset(new MiscibilityDead(pvdgTable));
        } else if (pvtgTables.empty()) {
            gas_props_.reset(new MiscibilityLiveGas(pvtgTables[0]));
        } else {
	    OPM_THROW(std::runtime_error, "Input is missing PVDG and PVTG\n");
        }
    }
コード例 #5
0
    void PvtPropertiesIncompFromDeck::init(Opm::DeckConstPtr deck)
    {
        // So far, this class only supports a single PVT region. TODO?
        int region_number = 0;

        PhaseUsage phase_usage = phaseUsageFromDeck(deck);
        if (phase_usage.phase_used[PhaseUsage::Vapour] ||
            !phase_usage.phase_used[PhaseUsage::Aqua] ||
            !phase_usage.phase_used[PhaseUsage::Liquid]) {
            OPM_THROW(std::runtime_error, "PvtPropertiesIncompFromDeck::init() -- must have gas and oil phases (only) in deck input.\n");
        }

        // Surface densities. Accounting for different orders in eclipse and our code.
        if (deck->hasKeyword("DENSITY")) {
            const auto& densityRecord = deck->getKeyword("DENSITY").getRecord(region_number);
            surface_density_[phase_usage.phase_pos[PhaseUsage::Aqua]]   = densityRecord.getItem("OIL").getSIDouble(0);
            surface_density_[phase_usage.phase_pos[PhaseUsage::Liquid]] = densityRecord.getItem("WATER").getSIDouble(0);
        } else {
            OPM_THROW(std::runtime_error, "Input is missing DENSITY\n");
        }

        // Make reservoir densities the same as surface densities initially.
        // We will modify them with formation volume factors if found.
        reservoir_density_ = surface_density_;

        // Water viscosity.
        if (deck->hasKeyword("PVTW")) {
            const auto& pvtwRecord = deck->getKeyword("PVTW").getRecord(region_number);
            if (pvtwRecord.getItem("WATER_COMPRESSIBILITY").getSIDouble(0) != 0.0 ||
                pvtwRecord.getItem("WATER_VISCOSIBILITY").getSIDouble(0) != 0.0) {
                OPM_MESSAGE("Compressibility effects in PVTW are ignored.");
            }
            reservoir_density_[phase_usage.phase_pos[PhaseUsage::Aqua]] /= pvtwRecord.getItem("WATER_VOL_FACTOR").getSIDouble(0);
            viscosity_[phase_usage.phase_pos[PhaseUsage::Aqua]] = pvtwRecord.getItem("WATER_VISCOSITY").getSIDouble(0);
        } else {
            // Eclipse 100 default.
            // viscosity_[phase_usage.phase_pos[PhaseUsage::Aqua]] = 0.5*Opm::prefix::centi*Opm::unit::Poise;
            OPM_THROW(std::runtime_error, "Input is missing PVTW\n");
        }

        // Oil viscosity.
        if (deck->hasKeyword("PVCDO")) {
            const auto& pvcdoRecord = deck->getKeyword("PVCDO").getRecord(region_number);

            if (pvcdoRecord.getItem("OIL_COMPRESSIBILITY").getSIDouble(0) != 0.0 ||
                pvcdoRecord.getItem("OIL_VISCOSIBILITY").getSIDouble(0) != 0.0) {
                OPM_MESSAGE("Compressibility effects in PVCDO are ignored.");
            }
            reservoir_density_[phase_usage.phase_pos[PhaseUsage::Liquid]] /= pvcdoRecord.getItem("OIL_VOL_FACTOR").getSIDouble(0);
            viscosity_[phase_usage.phase_pos[PhaseUsage::Liquid]] = pvcdoRecord.getItem("OIL_VISCOSITY").getSIDouble(0);
        } else {
            OPM_THROW(std::runtime_error, "Input is missing PVCDO\n");
        }
    }
コード例 #6
0
    /*!
     * \brief Reads all relevant material parameters form a cell of a parsed ECL deck.
     *
     * This requires that the opm-parser module is available.
     */
    void initFromDeck(Opm::DeckConstPtr deck)
    {
        enableHysteresis_ = false;

        if (!deck->hasKeyword("SATOPTS"))
            return;

        Opm::DeckItemConstPtr satoptsItem = deck->getKeyword("SATOPTS")->getRecord(0)->getItem(0);
        for (unsigned i = 0; i < satoptsItem->size(); ++i) {
            std::string satoptsValue = satoptsItem->getString(0);
            std::transform(satoptsValue.begin(),
                           satoptsValue.end(),
                           satoptsValue.begin(),
                           ::toupper);

            if (satoptsValue == "HYSTER")
                enableHysteresis_ = true;
        }

        // check for the (deprecated) HYST keyword
        if (deck->hasKeyword("HYST"))
            enableHysteresis_ = true;

        if (!enableHysteresis_)
            return;

        if (!deck->hasKeyword("EHYSTR"))
            OPM_THROW(std::runtime_error,
                      "Enabling hysteresis via the HYST parameter for SATOPTS requires the "
                      "presence of the EHYSTR keyword");

        Opm::DeckKeywordConstPtr ehystrKeyword = deck->getKeyword("EHYSTR");
        if (deck->hasKeyword("NOHYKR"))
            krHysteresisModel_ = -1;
        else {
            krHysteresisModel_ = ehystrKeyword->getRecord(0)->getItem("relative_perm_hyst")->getInt(0);
            if (krHysteresisModel_ != 0)
                OPM_THROW(std::runtime_error,
                          "Only the Carlson kr hystersis model (indicated by a 0 on the second item"
                          " of the 'EHYSTR' keyword) is supported");
        }

        if (deck->hasKeyword("NOHYPC"))
            pcHysteresisModel_ = -1;
        else {
            // if capillary pressure hysteresis is enabled, Eclipse always uses the
            // Killough model
            pcHysteresisModel_ = 0;
        }
    }
コード例 #7
0
ファイル: GridManager.cpp プロジェクト: chflo/opm-core
    void GridManager::createGrdecl(Opm::DeckConstPtr deck, struct grdecl &grdecl)
    {
        // Extract data from deck.
        const std::vector<double>& zcorn = deck->getKeyword("ZCORN").getSIDoubleData();
        const std::vector<double>& coord = deck->getKeyword("COORD").getSIDoubleData();
        const int* actnum = NULL;
        if (deck->hasKeyword("ACTNUM")) {
            actnum = &(deck->getKeyword("ACTNUM").getIntData()[0]);
        }

        std::array<int, 3> dims;
        if (deck->hasKeyword("DIMENS")) {
            const auto& dimensKeyword = deck->getKeyword("DIMENS");
            dims[0] = dimensKeyword.getRecord(0).getItem(0).get< int >(0);
            dims[1] = dimensKeyword.getRecord(0).getItem(1).get< int >(0);
            dims[2] = dimensKeyword.getRecord(0).getItem(2).get< int >(0);
        } else if (deck->hasKeyword("SPECGRID")) {
            const auto& specgridKeyword = deck->getKeyword("SPECGRID");
            dims[0] = specgridKeyword.getRecord(0).getItem(0).get< int >(0);
            dims[1] = specgridKeyword.getRecord(0).getItem(1).get< int >(0);
            dims[2] = specgridKeyword.getRecord(0).getItem(2).get< int >(0);
        } else {
            OPM_THROW(std::runtime_error, "Deck must have either DIMENS or SPECGRID.");
        }

        // Collect in input struct for preprocessing.

        grdecl.zcorn = &zcorn[0];
        grdecl.coord = &coord[0];
        grdecl.actnum = actnum;
        grdecl.dims[0] = dims[0];
        grdecl.dims[1] = dims[1];
        grdecl.dims[2] = dims[2];

        if (deck->hasKeyword("MAPAXES")) {
            const auto& mapaxesKeyword = deck->getKeyword("MAPAXES");
            const auto& mapaxesRecord = mapaxesKeyword.getRecord(0);

            // memleak alert: here we need to make sure that C code
            // can properly take ownership of the grdecl.mapaxes
            // object. if it is not freed, it will result in a
            // memleak...
            double *cWtfMapaxes = static_cast<double*>(malloc(sizeof(double)*mapaxesRecord.size()));
            for (unsigned i = 0; i < mapaxesRecord.size(); ++i)
                cWtfMapaxes[i] = mapaxesRecord.getItem(i).getSIDouble(0);
            grdecl.mapaxes = cWtfMapaxes;
        } else
            grdecl.mapaxes = NULL;

    }
コード例 #8
0
 void filterIntegerField(const std::string& keyword, std::vector<int>& output_field)
 {
     if (deck_->hasKeyword(keyword)) {
         const std::vector<int>& field = deck_->getKeyword(keyword)->getIntData();
         filterField(field, output_field);
     }
 }
コード例 #9
0
 void filterDoubleField(const std::string& keyword, std::vector<double>& output_field)
 {
     if (deck_->hasKeyword(keyword)) {
         const std::vector<double>& field = deck_->getKeyword(keyword)->getRawDoubleData();
         filterField(field, output_field);
     }
 }
コード例 #10
0
RockCompressibility::RockCompressibility(Opm::DeckConstPtr deck,
        Opm::EclipseStateConstPtr eclipseState)
    : pref_(0.0),
      rock_comp_(0.0)
{
    const auto tables = eclipseState->getTableManager();
    const auto& rocktabTables = tables->getRocktabTables();
    if (rocktabTables.size() > 0) {
        const auto& rocktabTable = rocktabTables.getTable<RocktabTable>(0);
        if (rocktabTables.size() != 1)
            OPM_THROW(std::runtime_error, "Can only handle a single region in ROCKTAB.");

        p_ = rocktabTable.getColumn("PO").vectorCopy( );
        poromult_ = rocktabTable.getColumn("PV_MULT").vectorCopy();
        if (rocktabTable.hasColumn("PV_MULT_TRAN")) {
            transmult_ =  rocktabTable.getColumn("PV_MULT_TRAN").vectorCopy();
        } else {
            transmult_ =  rocktabTable.getColumn("PV_MULT_TRANX").vectorCopy();
        }
    } else if (deck->hasKeyword("ROCK")) {
        Opm::DeckKeywordConstPtr rockKeyword = deck->getKeyword("ROCK");
        if (rockKeyword->size() != 1) {
            // here it would be better not to use std::cout directly but to add the
            // warning to some "warning list"...
            std::cout << "Can only handle a single region in ROCK ("<<rockKeyword->size()<<" regions specified)."
                      << " Ignoring all except for the first.\n";
        }

        pref_ = rockKeyword->getRecord(0)->getItem("PREF")->getSIDouble(0);
        rock_comp_ = rockKeyword->getRecord(0)->getItem("COMPRESSIBILITY")->getSIDouble(0);
    } else {
        std::cout << "**** warning: no rock compressibility data found in deck (ROCK or ROCKTAB)." << std::endl;
    }
}
コード例 #11
0
ファイル: Rock_impl.hpp プロジェクト: qilicun/opm-upscaling
void Rock<dim>::assignPorosity(Opm::DeckConstPtr deck,
                               const std::vector<int>& global_cell)
{
    porosity_.assign(global_cell.size(), 1.0);

    if (deck->hasKeyword("PORO")) {
        const std::vector<double>& poro = deck->getKeyword("PORO").getSIDoubleData();

        for (int c = 0; c < int(porosity_.size()); ++c) {
            porosity_[c] = poro[global_cell[c]];
        }
    }
}
コード例 #12
0
/// Mirror keyword MAPAXES in deck
void mirror_mapaxes(Opm::DeckConstPtr deck, std::string direction, std::ofstream& out) {
    // Assumes axis aligned with x/y-direction
    std::cout << "Warning: Keyword MAPAXES not fully understood. Result should be verified manually." << std::endl;
    if (deck->hasKeyword("MAPAXES")) {
        std::vector<double> mapaxes = getMapaxesValues(deck);
        std::vector<double> mapaxes_mirrored = mapaxes;
        // Double the length of the coordinate axis
        if (direction == "x") {
            mapaxes_mirrored[4] = (mapaxes[4]-mapaxes[2])*2 + mapaxes[2];
        }
        else if (direction == "y") {
            mapaxes_mirrored[1] = (mapaxes[1]-mapaxes[3])*2 + mapaxes[3];
        }
        printKeywordValues(out, "MAPAXES", mapaxes_mirrored, 2);
    }
}
コード例 #13
0
ファイル: PolymerInflow.cpp プロジェクト: edbru/opm-polymer
    /// Constructor.
    /// @param[in]  deck     Input deck expected to contain WPOLYMER.
    PolymerInflowFromDeck::PolymerInflowFromDeck(Opm::DeckConstPtr deck,
                                                 const Wells& wells,
                                                 const int num_cells)
        : sparse_inflow_(num_cells)
    {
        if (!deck->hasKeyword("WPOLYMER")) {
            OPM_MESSAGE("PolymerInflowFromDeck initialized without WPOLYMER in current epoch.");
            return;
        }

        // Extract concentrations and put into cell->concentration map.
        Opm::DeckKeywordConstPtr wpolymerKeyword = deck->getKeyword("WPOLYMER");
        const int num_wpl = wpolymerKeyword->size();
        std::map<int, double> perfcell_conc;
        for (int i = 0; i < num_wpl; ++i) {
            // Only use well name and polymer concentration.
            // That is, we ignore salt concentration and group
            // names.
            int wix = 0;
            for (; wix < wells.number_of_wells; ++wix) {
                if (wpolymerKeyword->getRecord(i)->getItem("WELL")->getString(0) == wells.name[wix]) {
                    break;
                }
            }
            if (wix == wells.number_of_wells) {
                OPM_THROW(std::runtime_error, "Could not find a match for well "
                          << wpolymerKeyword->getRecord(i)->getItem("WELL")->getString(0)
                          << " from WPOLYMER.");
            }
            for (int j = wells.well_connpos[wix]; j < wells.well_connpos[wix+1]; ++j) {
                const int perf_cell = wells.well_cells[j];
                perfcell_conc[perf_cell] =
                    wpolymerKeyword->getRecord(i)->getItem("POLYMER_CONCENTRATION")->getSIDouble(0);
            }
        }

        // Build sparse vector from map.
        std::map<int, double>::const_iterator it = perfcell_conc.begin();
        for (; it != perfcell_conc.end(); ++it) {
            sparse_inflow_.addElement(it->second, it->first);
        }
    }
コード例 #14
0
ファイル: PolymerInflow.cpp プロジェクト: edbru/opm-polymer
    /// Constructor.
    /// @param[in]  deck     Input deck expected to contain WPOLYMER.
    PolymerInflowFromDeck::PolymerInflowFromDeck(Opm::DeckConstPtr deck,
                                                 Opm::EclipseStateConstPtr eclipseState,
                                                 const Wells& wells,
                                                 const int num_cells,
                                                 size_t currentStep)
        : sparse_inflow_(num_cells)
    {
        if (!deck->hasKeyword("WPOLYMER")) {
            OPM_MESSAGE("PolymerInflowFromDeck initialized without WPOLYMER in current epoch.");
            return;
        }
        setInflowValues(deck, eclipseState, currentStep);
        
        std::unordered_map<std::string, double>::const_iterator map_it;
        // Extract concentrations and put into cell->concentration map.
        std::map<int, double> perfcell_conc;
        for (size_t i = 0; i < wellPolymerRate_.size(); ++i) {
            // Only use well name and polymer concentration.
            // That is, we ignore salt concentration and group
            // names.
            int wix = 0;
            for (; wix < wells.number_of_wells; ++wix) {
                map_it = wellPolymerRate_.find(wells.name[wix]);
                if (map_it == wellPolymerRate_.end()) {
                    OPM_THROW(std::runtime_error, "Could not find a match for well from WPOLYMER.");
                } else {
                    break;
                }
            }
            for (int j = wells.well_connpos[wix]; j < wells.well_connpos[wix+1]; ++j) {
                const int perf_cell = wells.well_cells[j];
                perfcell_conc[perf_cell] = map_it->second;
            }
        }

        // Build sparse vector from map.
        std::map<int, double>::const_iterator it = perfcell_conc.begin();
        for (; it != perfcell_conc.end(); ++it) {
            sparse_inflow_.addElement(it->second, it->first);
        }
    }
コード例 #15
0
    inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck,
                                                 Opm::EclipseStateConstPtr eclState,
                                                 std::shared_ptr<MaterialLawManager> materialLawManager,
                                                 int number_of_cells,
                                                 const int* global_cell,
                                                 const int* cart_dims,
                                                 const parameter::ParameterGroup& param,
                                                 bool init_rock)
    {
        // retrieve the cell specific PVT table index from the deck
        // and using the grid...
        extractPvtTableIndex(cellPvtRegionIdx_, eclState, number_of_cells, global_cell);

        if(init_rock){
            rock_.init(eclState, number_of_cells, global_cell, cart_dims);
        }

        const int pvt_samples = param.getDefault("pvt_tab_size", -1);
        pvt_.init(deck, eclState, pvt_samples);

        // Unfortunate lack of pointer smartness here...
        std::string threephase_model = param.getDefault<std::string>("threephase_model", "gwseg");
        if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") {
            OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only.");
        }

        SaturationPropsFromDeck* ptr
            = new SaturationPropsFromDeck();
        ptr->init(phaseUsageFromDeck(deck), materialLawManager);
        satprops_.reset(ptr);

        if (pvt_.numPhases() != satprops_->numPhases()) {
            OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data ("
                  << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ").");
        }
    }
コード例 #16
0
ファイル: TimeMap.cpp プロジェクト: flikka/opm-parser
    TimeMap::TimeMap(Opm::DeckConstPtr deck) {
        // The default start date is not specified in the Eclipse
        // reference manual. We hence just assume it is same as for
        // the START keyword for Eclipse R100, i.e., January 1st,
        // 1983...
        boost::posix_time::ptime startTime(boost::gregorian::date(1983, 1, 1));

        // use the 'START' keyword to find out the start date (if the
        // keyword was specified)
        if (deck->hasKeyword("START")) {
            Opm::DeckKeywordConstPtr keyword = deck->getKeyword("START");
            startTime = timeFromEclipse(keyword->getRecord(/*index=*/0));
        }

        m_timeList.push_back( startTime );

        // find all "TSTEP" and "DATES" keywords in the deck and deal
        // with them one after another
        size_t numKeywords = deck->size();
        for (size_t keywordIdx = 0; keywordIdx < numKeywords; ++keywordIdx) {
            Opm::DeckKeywordConstPtr keyword = deck->getKeyword(keywordIdx);

            // We're only interested in "TSTEP" and "DATES" keywords,
            // so we ignore everything else here...
            if (keyword->name() != "TSTEP" &&
                keyword->name() != "DATES")
            {
                continue;
            }

            if (keyword->name() == "TSTEP")
                addFromTSTEPKeyword(keyword);
            else if (keyword->name() == "DATES")
                addFromDATESKeyword(keyword);
        }
    }
コード例 #17
0
    /*!
     * \brief Reads all relevant material parameters form a cell of a parsed ECL deck.
     *
     * This requires that the opm-parser module is available.
     */
    void initFromDeck(Opm::DeckConstPtr deck,
                      Opm::EclipseStateConstPtr eclState,
                      Opm::EclTwoPhaseSystemType twoPhaseSystemType)
    {
        // find out if endpoint scaling is used in the first place
        if (!deck->hasKeyword("ENDSCALE")) {
            // it is not used, i.e., just set all enable$Foo attributes to 0 and be done
            // with it.
            enableSatScaling_ = false;
            enableThreePointKrSatScaling_ = false;
            enablePcScaling_ = false;
            enableKrwScaling_ = false;
            enableKrnScaling_ = false;
            return;
        }

        // endpoint scaling is used, i.e., at least saturation scaling needs to be enabled
        enableSatScaling_ = true;

        // check if three-point scaling is to be used for the saturations of the relative
        // permeabilities
        if (deck->hasKeyword("SCALECRS")) {
            // if the deck features the SCALECRS keyword, it must be set to 'YES'
            Opm::DeckKeywordConstPtr scalecrsKeyword = deck->getKeyword("SCALECRS");
            std::string scalecrsValue =
                scalecrsKeyword->getRecord(0)->getItem("VALUE")->getString(0);
            // convert the value of the SCALECRS keyword to upper case, just to be sure
            std::transform(scalecrsValue.begin(),
                           scalecrsValue.end(),
                           scalecrsValue.begin(),
                           ::toupper);

            if (scalecrsValue == "YES" || scalecrsValue == "Y")
                enableThreePointKrSatScaling_ = true;
            else
                enableThreePointKrSatScaling_ = false;
        }
        else
            enableThreePointKrSatScaling_ = false;

        // check if we are supposed to scale the Y axis of the capillary pressure
        if (twoPhaseSystemType == EclOilWaterSystem)
            enablePcScaling_ =
                eclState->hasDoubleGridProperty("PCW")
                || eclState->hasDoubleGridProperty("SWATINIT");

        else {
            assert(twoPhaseSystemType == EclGasOilSystem);
            enablePcScaling_ = eclState->hasDoubleGridProperty("PCG");
        }

        // check if we are supposed to scale the Y axis of the wetting phase relperm
        if (twoPhaseSystemType == EclOilWaterSystem)
            enableKrwScaling_ = eclState->hasDoubleGridProperty("KRW");
        else {
            assert(twoPhaseSystemType == EclGasOilSystem);
            enableKrwScaling_ = eclState->hasDoubleGridProperty("KRO");
        }

        // check if we are supposed to scale the Y axis of the non-wetting phase relperm
        if (twoPhaseSystemType == EclOilWaterSystem)
            enableKrnScaling_ = eclState->hasDoubleGridProperty("KRO");
        else {
            assert(twoPhaseSystemType == EclGasOilSystem);
            enableKrnScaling_ = eclState->hasDoubleGridProperty("KRG");
        }
    }
コード例 #18
0
void mirror_celldata(std::string keyword, Opm::DeckConstPtr deck, std::string direction, std::ofstream& out) {
    if ( ! deck->hasKeyword(keyword)) {
        std::cout << "Ignoring keyword " << keyword << " as it was not found." << std::endl;
        return;
    }
    // Get data from eclipse deck
    Opm::DeckRecordConstPtr specgridRecord = deck->getKeyword("SPECGRID")->getRecord(0);
    std::vector<int> dimensions(3);
    dimensions[0] = specgridRecord->getItem("NX")->getInt(0);
    dimensions[1] = specgridRecord->getItem("NY")->getInt(0);
    dimensions[2] = specgridRecord->getItem("NZ")->getInt(0);
    std::vector<T> values = getKeywordValues(keyword, deck, T(0.0));
    std::vector<T> values_mirrored(2*dimensions[0]*dimensions[1]*dimensions[2], 0.0);
    // Handle the two directions differently due to ordering of the pillars.
    if (direction == "x") {
        typename std::vector<T>::iterator it_orig = values.begin();
        typename std::vector<T>::iterator it_new = values_mirrored.begin();
        // Loop through each line and copy old cell data and add new (which are the old reversed)
        for ( ; it_orig != values.end(); it_orig += dimensions[0]) {
            // Copy old cell data
            copy(it_orig, it_orig + dimensions[0], it_new);
            it_new += dimensions[0];
            // Add new cell data
            std::vector<double> next_vec(it_orig, it_orig + dimensions[0]);
            std::vector<double> next_reversed = next_vec;
            reverse(next_reversed.begin(), next_reversed.end());
            copy(next_reversed.begin(), next_reversed.end(), it_new);
            it_new += dimensions[0];
        }
    }
    else if (direction =="y") {
        typename std::vector<T>::iterator it_orig = values.begin();
        typename std::vector<T>::iterator it_new = values_mirrored.begin();
        // Entries per layer
        const int entries_per_layer = dimensions[0]*dimensions[1];
        // Loop through each layer and copy old cell data and add new (which are the old reordered) 
        for ( ; it_orig != values.end(); it_orig += entries_per_layer) {
            // Copy old cell data
            copy(it_orig, it_orig + entries_per_layer, it_new);
            it_new += entries_per_layer;
            // Add new cell data
            std::vector<T> next_vec(it_orig, it_orig + entries_per_layer);
            std::vector<T> next_reordered(entries_per_layer, 0.0);
            typename std::vector<T>::iterator it_next = next_vec.end();
            typename std::vector<T>::iterator it_reordered = next_reordered.begin();
            // Reorder next entries
            for ( ; it_reordered != next_reordered.end(); it_reordered += dimensions[0]) {
                copy(it_next - dimensions[0], it_next, it_reordered);
                it_next -= dimensions[0];
            }
            copy(next_reordered.begin(), next_reordered.end(), it_new);
            it_new += entries_per_layer;
        }
    }
    else {
        std::cerr << "Direction should be either x or y" << std::endl;
        exit(1);
    }
    // Write new keyword values to output file
    printKeywordValues(out, keyword, values_mirrored, 8);
}
コード例 #19
0
    inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck,
                                                 Opm::EclipseStateConstPtr eclState,
                                                 int number_of_cells,
                                                 const int* global_cell,
                                                 const int* cart_dims,
                                                 const CentroidIterator& begin_cell_centroids,
                                                 int dimension,
                                                 const parameter::ParameterGroup& param,
                                                 bool init_rock)
    {
        // retrieve the cell specific PVT table index from the deck
        // and using the grid...
        extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell);

        if(init_rock){
            rock_.init(eclState, number_of_cells, global_cell, cart_dims);
        }

        const int pvt_samples = param.getDefault("pvt_tab_size", 200);
        pvt_.init(deck, pvt_samples);

        // Unfortunate lack of pointer smartness here...
        const int sat_samples = param.getDefault("sat_tab_size", 200);
        std::string threephase_model = param.getDefault<std::string>("threephase_model", "simple");
        if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") {
            OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only.");
        }
        if (sat_samples > 1) {
            if (threephase_model == "stone2") {
                SaturationPropsFromDeck<SatFuncStone2Uniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncStone2Uniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else if (threephase_model == "simple") {
                SaturationPropsFromDeck<SatFuncSimpleUniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncSimpleUniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else if (threephase_model == "gwseg") {
                SaturationPropsFromDeck<SatFuncGwsegUniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncGwsegUniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else {
                OPM_THROW(std::runtime_error, "Unknown threephase_model: " << threephase_model);
            }
        } else {
            if (threephase_model == "stone2") {
                SaturationPropsFromDeck<SatFuncStone2Nonuniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncStone2Nonuniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else if (threephase_model == "simple") {
                SaturationPropsFromDeck<SatFuncSimpleNonuniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncSimpleNonuniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else if (threephase_model == "gwseg") {
                SaturationPropsFromDeck<SatFuncGwsegNonuniform>* ptr
                    = new SaturationPropsFromDeck<SatFuncGwsegNonuniform>();
                satprops_.reset(ptr);
                ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids,
                          dimension, sat_samples);
            } else {
                OPM_THROW(std::runtime_error, "Unknown threephase_model: " << threephase_model);
            }
        }

        if (pvt_.numPhases() != satprops_->numPhases()) {
            OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data ("
                  << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ").");
        }
    }
コード例 #20
0
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    std::cout << "\n================    Test program for fully implicit three-phase black-oil flow     ===============\n\n";
    parameter::ParameterGroup param(argc, argv, false);
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;

    // If we have a "deck_filename", grid and props will be read from that.
    bool use_deck = param.has("deck_filename");
    if (!use_deck) {
        OPM_THROW(std::runtime_error, "This program must be run with an input deck. "
                  "Specify the deck with deck_filename=deckname.data (for example).");
    }
    std::shared_ptr<GridManager> grid;
    std::shared_ptr<BlackoilPropertiesInterface> props;
    std::shared_ptr<BlackoilPropsAdInterface> new_props;
    std::shared_ptr<RockCompressibility> rock_comp;
    PolymerBlackoilState state;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    std::string deck_filename = param.get<std::string>("deck_filename");

    Opm::ParserPtr newParser(new Opm::Parser());
    Opm::DeckConstPtr deck = newParser->parseFile(deck_filename);
    std::shared_ptr<EclipseState> eclipseState(new EclipseState(deck));
    // Grid init
    std::vector<double> porv;
    if (eclipseState->hasDoubleGridProperty("PORV")) {
        porv = eclipseState->getDoubleGridProperty("PORV")->getData();
    }
    grid.reset(new GridManager(eclipseState->getEclipseGrid(), porv));
    auto &cGrid = *grid->c_grid();
    const PhaseUsage pu = Opm::phaseUsageFromDeck(deck);
    Opm::EclipseWriter outputWriter(param,
                                    eclipseState,
                                    pu,
                                    cGrid.number_of_cells,
                                    cGrid.global_cell);
    // Rock and fluid init
    props.reset(new BlackoilPropertiesFromDeck(deck, eclipseState, *grid->c_grid(), param));
    new_props.reset(new BlackoilPropsAdFromDeck(deck, eclipseState, *grid->c_grid()));
    PolymerProperties polymer_props(deck, eclipseState);
    PolymerPropsAd polymer_props_ad(polymer_props);
    // Rock compressibility.
    rock_comp.reset(new RockCompressibility(deck, eclipseState));
    // Gravity.
    gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
    // Init state variables (saturation and pressure).
    if (param.has("init_saturation")) {
        initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
        initBlackoilSurfvol(*grid->c_grid(), *props, state);
    } else {
        initStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], state);
    }

    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    const double *grav = use_gravity ? &gravity[0] : 0;
    // Solver for Newton iterations.
    std::unique_ptr<NewtonIterationBlackoilInterface> fis_solver;
    if (param.getDefault("use_cpr", true)) {
        fis_solver.reset(new NewtonIterationBlackoilCPR(param));
    } else {
        fis_solver.reset(new NewtonIterationBlackoilSimple(param));
    }

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    std::string output_dir;
    if (output) {
        output_dir =
            param.getDefault("output_dir", std::string("output"));
        boost::filesystem::path fpath(output_dir);
        try {
            create_directories(fpath);
        }
        catch (...) {
            OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
        }
        param.writeParam(output_dir + "/simulation.param");
    }

    Opm::TimeMapConstPtr timeMap(eclipseState->getSchedule()->getTimeMap());
    SimulatorTimer simtimer;
    simtimer.init(timeMap);


    SimulatorReport rep;
    // With a deck, we may have more epochs etc.
    WellState well_state;
    // Check for WPOLYMER presence in last epoch to decide
    // polymer injection control type.
    const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
    if (use_wpolymer) {
        if (param.has("poly_start_days")) {
            OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. "
                        "You seem to be trying to control it via parameter poly_start_days (etc.) as well.");
        }
    }
    std::cout << "\n\n================    Starting main simulation loop     ===============\n"
              << std::flush;
    SimulatorReport fullReport;
    // Create and run simulator.
    Opm::DerivedGeology geology(*grid->c_grid(), *new_props, eclipseState, grav);
    SimulatorFullyImplicitCompressiblePolymer simulator(param,
            *grid->c_grid(),
            geology,
            *new_props,
            polymer_props_ad,
            rock_comp->isActive() ? rock_comp.get() : 0,
            eclipseState,
            outputWriter,
            deck,
            *fis_solver,
            grav);
    fullReport= simulator.run(simtimer, state);

    std::cout << "\n\n================    End of simulation     ===============\n\n";
    fullReport.report(std::cout);

    if (output) {
        std::string filename = output_dir + "/walltime.param";
        std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
        fullReport.reportParam(tot_os);
        warnIfUnusedParams(param);
    }

}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}
コード例 #21
0
    void BlackoilPvtProperties::init(Opm::DeckConstPtr deck,
                                     Opm::EclipseStateConstPtr eclipseState,
                                     int numSamples)
    {
        phase_usage_ = phaseUsageFromDeck(deck);

        // Surface densities. Accounting for different orders in eclipse and our code.
        Opm::DeckKeywordConstPtr densityKeyword = deck->getKeyword("DENSITY");
        int numRegions = densityKeyword->size();

        densities_.resize(numRegions);
        for (int regionIdx = 0; regionIdx < numRegions; ++regionIdx) {
            if (phase_usage_.phase_used[Liquid]) {
                densities_[regionIdx][phase_usage_.phase_pos[Liquid]]
                    = densityKeyword->getRecord(regionIdx)->getItem("OIL")->getSIDouble(0);
            }
            if (phase_usage_.phase_used[Aqua]) {
                densities_[regionIdx][phase_usage_.phase_pos[Aqua]]
                    = densityKeyword->getRecord(regionIdx)->getItem("WATER")->getSIDouble(0);
            }
            if (phase_usage_.phase_used[Vapour]) {
                densities_[regionIdx][phase_usage_.phase_pos[Vapour]]
                    = densityKeyword->getRecord(regionIdx)->getItem("GAS")->getSIDouble(0);
            }
        }

        // Resize the property objects container
        props_.resize(phase_usage_.num_phases);

        // Water PVT
        if (phase_usage_.phase_used[Aqua]) {
            // if water is used, we require the presence of the "PVTW"
            // keyword for now...
            std::shared_ptr<PvtConstCompr> pvtw(new PvtConstCompr);
            pvtw->initFromWater(deck->getKeyword("PVTW"));

            props_[phase_usage_.phase_pos[Aqua]] = pvtw;
        }

        {
            auto tables = eclipseState->getTableManager();
            // Oil PVT
            if (phase_usage_.phase_used[Liquid]) {
                // for oil, we support the "PVDO", "PVTO" and "PVCDO"
                // keywords...
                const auto &pvdoTables = tables->getPvdoTables();
                const auto &pvtoTables = tables->getPvtoTables();
                if (pvdoTables.size() > 0) {
                    if (numSamples > 0) {
                        auto splinePvt = std::shared_ptr<PvtDeadSpline>(new PvtDeadSpline);
                        splinePvt->initFromOil(pvdoTables, numSamples);
                        props_[phase_usage_.phase_pos[Liquid]] = splinePvt;
                    } else {
                        auto deadPvt = std::shared_ptr<PvtDead>(new PvtDead);
                        deadPvt->initFromOil(pvdoTables);
                        props_[phase_usage_.phase_pos[Liquid]] = deadPvt;
                    }
                } else if (pvtoTables.size() > 0) {
                    props_[phase_usage_.phase_pos[Liquid]].reset(new PvtLiveOil(pvtoTables));
                } else if (deck->hasKeyword("PVCDO")) {
                    std::shared_ptr<PvtConstCompr> pvcdo(new PvtConstCompr);
                    pvcdo->initFromOil(deck->getKeyword("PVCDO"));

                    props_[phase_usage_.phase_pos[Liquid]] = pvcdo;
                } else {
                    OPM_THROW(std::runtime_error, "Input is missing PVDO, PVCDO or PVTO\n");
                }
            }
            // Gas PVT
            if (phase_usage_.phase_used[Vapour]) {
                // gas can be specified using the "PVDG" or "PVTG" keywords...
                const auto &pvdgTables = tables->getPvdgTables();
                const auto &pvtgTables = tables->getPvtgTables();
                if (pvdgTables.size() > 0) {
                    if (numSamples > 0) {
                        std::shared_ptr<PvtDeadSpline> splinePvt(new PvtDeadSpline);
                        splinePvt->initFromGas(pvdgTables, numSamples);

                        props_[phase_usage_.phase_pos[Vapour]] = splinePvt;
                    } else {
                        std::shared_ptr<PvtDead> deadPvt(new PvtDead);
                        deadPvt->initFromGas(pvdgTables);

                        props_[phase_usage_.phase_pos[Vapour]] = deadPvt;
                    }
                } else if (pvtgTables.size() > 0) {
                    props_[phase_usage_.phase_pos[Vapour]].reset(new PvtLiveGas(pvtgTables));
                } else {
                    OPM_THROW(std::runtime_error, "Input is missing PVDG or PVTG\n");
                }
            }
        }
    }
コード例 #22
0
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    std::cout << "\n================    Test program for fully implicit three-phase black-oil flow     ===============\n\n";
    parameter::ParameterGroup param(argc, argv, false);
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;

    // If we have a "deck_filename", grid and props will be read from that.
    bool use_deck = param.has("deck_filename");
    if (!use_deck) {
        OPM_THROW(std::runtime_error, "This program must be run with an input deck. "
                  "Specify the deck with deck_filename=deckname.data (for example).");
    }
    std::shared_ptr<GridManager> grid;
    std::shared_ptr<BlackoilPropertiesInterface> props;
    std::shared_ptr<BlackoilPropsAdInterface> new_props;
    std::shared_ptr<RockCompressibility> rock_comp;
    std::unique_ptr<PolymerBlackoilState> state;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    std::string deck_filename = param.get<std::string>("deck_filename");

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    std::string output_dir;
    if (output) {
        // Create output directory if needed.
        output_dir =
            param.getDefault("output_dir", std::string("output"));
        boost::filesystem::path fpath(output_dir);
        try {
            create_directories(fpath);
        }
        catch (...) {
            std::cerr << "Creating directories failed: " << fpath << std::endl;
            return EXIT_FAILURE;
        }
        // Write simulation parameters.
        param.writeParam(output_dir + "/simulation.param");
    }

    std::string logFile = output_dir + "/LOGFILE.txt";
    Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
    Opm::ParserPtr parser(new Opm::Parser());
    {
        std::shared_ptr<Opm::StreamLog> streamLog = std::make_shared<Opm::StreamLog>(logFile , Opm::Log::DefaultMessageTypes);
        std::shared_ptr<Opm::CounterLog> counterLog = std::make_shared<Opm::CounterLog>(Opm::Log::DefaultMessageTypes);

        Opm::OpmLog::addBackend( "STREAM" , streamLog );
        Opm::OpmLog::addBackend( "COUNTER" , counterLog );
    }

    Opm::DeckConstPtr deck;
    std::shared_ptr<EclipseState> eclipseState;
    try {
        deck = parser->parseFile(deck_filename , parseContext);
        Opm::checkDeck(deck, parser);
        eclipseState.reset(new Opm::EclipseState(deck , parseContext));
    }
    catch (const std::invalid_argument& e) {
        std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
        std::cerr << "Exception caught: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    // Grid init

    if (eclipseState->get3DProperties().hasDeckDoubleGridProperty("PORV")) {
        const auto& porv = eclipseState->get3DProperties().getDoubleGridProperty("PORV").getData();
        grid.reset(new GridManager(eclipseState->getInputGrid(), porv));
    } else {
        grid.reset(new GridManager(eclipseState->getInputGrid()));
    }
    auto &cGrid = *grid->c_grid();
    const PhaseUsage pu = Opm::phaseUsageFromDeck(deck);

    // Rock and fluid init

    std::vector<int> compressedToCartesianIdx;
    Opm::createGlobalCellArray(*grid->c_grid(), compressedToCartesianIdx);

    typedef BlackoilPropsAdFromDeck::MaterialLawManager MaterialLawManager;
    auto materialLawManager = std::make_shared<MaterialLawManager>();
    materialLawManager->initFromDeck(deck, eclipseState, compressedToCartesianIdx);

    props.reset(new BlackoilPropertiesFromDeck( deck, eclipseState, materialLawManager,
                                                Opm::UgGridHelpers::numCells(cGrid),
                                                Opm::UgGridHelpers::globalCell(cGrid),
                                                Opm::UgGridHelpers::cartDims(cGrid),
                                                param));

    state.reset( new PolymerBlackoilState( Opm::UgGridHelpers::numCells(cGrid), Opm::UgGridHelpers::numFaces(cGrid), 2));
    new_props.reset(new BlackoilPropsAdFromDeck(deck, eclipseState, materialLawManager, cGrid));
    PolymerProperties polymer_props(deck, eclipseState);
    PolymerPropsAd polymer_props_ad(polymer_props);

    // Rock compressibility.
    rock_comp.reset(new RockCompressibility(deck, eclipseState));

    // Gravity.
    gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;

    // Init state variables (saturation and pressure).
    if (param.has("init_saturation")) {
        initStateBasic(*grid->c_grid(), *props, param, gravity[2], *state);
        initBlackoilSurfvol(*grid->c_grid(), *props, *state);
    } else {
        initStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], *state);
    }

    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    const double *grav = use_gravity ? &gravity[0] : 0;
    // Solver for Newton iterations.
    std::unique_ptr<NewtonIterationBlackoilInterface> fis_solver;
    if (param.getDefault("use_cpr", true)) {
        fis_solver.reset(new NewtonIterationBlackoilCPR(param));
    } else {
        fis_solver.reset(new NewtonIterationBlackoilSimple(param));
    }

    Opm::TimeMapConstPtr timeMap(eclipseState->getSchedule()->getTimeMap());
    SimulatorTimer simtimer;
    simtimer.init(timeMap);


    SimulatorReport rep;
    // With a deck, we may have more epochs etc.
    WellState well_state;
    // Check for WPOLYMER presence in last epoch to decide
    // polymer injection control type.
    const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
    if (use_wpolymer) {
        if (param.has("poly_start_days")) {
            OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. "
                        "You seem to be trying to control it via parameter poly_start_days (etc.) as well.");
        }
    }
    std::cout << "\n\n================    Starting main simulation loop     ===============\n"
              << std::flush;

    Opm::BlackoilOutputWriter
        outputWriter(cGrid, param, eclipseState, Opm::NNC(), pu,
                     new_props->permeability() );

    SimulatorReport fullReport;
    // Create and run simulator.
    Opm::DerivedGeology geology(*grid->c_grid(), *new_props, eclipseState, grav);
    SimulatorFullyImplicitCompressiblePolymer<UnstructuredGrid>
        simulator(param,
                  *grid->c_grid(),
                  geology,
                  *new_props,
                  polymer_props_ad,
                  rock_comp->isActive() ? rock_comp.get() : 0,
                  eclipseState,
                  outputWriter,
                  deck,
                  *fis_solver,
                  grav);
    fullReport= simulator.run(simtimer, *state);

    std::cout << "\n\n================    End of simulation     ===============\n\n";
    fullReport.report(std::cout);

    if (output) {
        std::string filename = output_dir + "/walltime.param";
        std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
        fullReport.reportParam(tot_os);
        warnIfUnusedParams(param);
    }

}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}
コード例 #23
0
ファイル: flow_polymer.cpp プロジェクト: atgeirr/opm-polymer
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    {
        std::string version = moduleVersionName();
        std::cout << "**********************************************************************\n";
        std::cout << "*                                                                    *\n";
        std::cout << "*                   This is Flow-Polymer (version " << version << ")"
                  << std::string(18 - version.size(), ' ') << "*\n";
        std::cout << "*                                                                    *\n";
        std::cout << "*     Flow-Polymer is a simulator for fully implicit three-phase,    *\n";
        std::cout << "*    four-component (black-oil + polymer) flow, and is part of OPM.  *\n";
        std::cout << "*           For more information see http://opm-project.org          *\n";
        std::cout << "*                                                                    *\n";
        std::cout << "**********************************************************************\n\n";
    }

    // Read parameters, see if a deck was specified on the command line.
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;
    parameter::ParameterGroup param(argc, argv, false);
    if (!param.unhandledArguments().empty()) {
        if (param.unhandledArguments().size() != 1) {
            OPM_THROW(std::runtime_error, "You can only specify a single input deck on the command line.");
        } else {
            param.insertParameter("deck_filename", param.unhandledArguments()[0]);
        }
    }

    // We must have an input deck. Grid and props will be read from that.
    if (!param.has("deck_filename")) {
        std::cerr << "This program must be run with an input deck.\n"
            "Specify the deck filename either\n"
            "    a) as a command line argument by itself\n"
            "    b) as a command line parameter with the syntax deck_filename=<path to your deck>, or\n"
            "    c) as a parameter in a parameter file (.param or .xml) passed to the program.\n";
        OPM_THROW(std::runtime_error, "Input deck required.");
    }

    std::shared_ptr<GridManager> grid;
    std::shared_ptr<BlackoilPropertiesFromDeck> props;
    std::shared_ptr<BlackoilPropsAdFromDeck> new_props;
    std::shared_ptr<RockCompressibility> rock_comp;
    PolymerBlackoilState state;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    std::string deck_filename = param.get<std::string>("deck_filename");

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    std::string output_dir;
    if (output) {
        // Create output directory if needed.
        output_dir =
            param.getDefault("output_dir", std::string("output"));
        boost::filesystem::path fpath(output_dir);
        try {
            create_directories(fpath);
        }
        catch (...) {
            OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
        }
        // Write simulation parameters.
        param.writeParam(output_dir + "/simulation.param");
    }

    std::string logFile = output_dir + "/LOGFILE.txt";
    Opm::ParserPtr parser(new Opm::Parser());
    {
        std::shared_ptr<Opm::StreamLog> streamLog = std::make_shared<Opm::StreamLog>(logFile , Opm::Log::DefaultMessageTypes);
        std::shared_ptr<Opm::CounterLog> counterLog = std::make_shared<Opm::CounterLog>(Opm::Log::DefaultMessageTypes);

        Opm::OpmLog::addBackend( "STREAM" , streamLog );
        Opm::OpmLog::addBackend( "COUNTER" , counterLog );
    }


    Opm::DeckConstPtr deck;
    std::shared_ptr<EclipseState> eclipseState;
    Opm::ParseMode parseMode;
    try {
        deck = parser->parseFile(deck_filename , parseMode);
        Opm::checkDeck(deck);
        eclipseState.reset(new Opm::EclipseState(deck , parseMode));
    }
    catch (const std::invalid_argument& e) {
        std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
        std::cerr << "Exception caught: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    // Grid init
    std::vector<double> porv = eclipseState->getDoubleGridProperty("PORV")->getData();
    grid.reset(new GridManager(eclipseState->getEclipseGrid(), porv));
    auto &cGrid = *grid->c_grid();
    const PhaseUsage pu = Opm::phaseUsageFromDeck(deck);

    // Rock and fluid init

    std::vector<int> compressedToCartesianIdx;
    Opm::createGlobalCellArray(*grid->c_grid(), compressedToCartesianIdx);

    typedef BlackoilPropsAdFromDeck::MaterialLawManager MaterialLawManager;
    auto materialLawManager = std::make_shared<MaterialLawManager>();
    materialLawManager->initFromDeck(deck, eclipseState, compressedToCartesianIdx);

    props.reset(new BlackoilPropertiesFromDeck( deck, eclipseState, materialLawManager,
                                                Opm::UgGridHelpers::numCells(cGrid),
                                                Opm::UgGridHelpers::globalCell(cGrid),
                                                Opm::UgGridHelpers::cartDims(cGrid),
                                                param));
    new_props.reset(new BlackoilPropsAdFromDeck(deck, eclipseState, materialLawManager, cGrid));
    const bool polymer = deck->hasKeyword("POLYMER");
    const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
    PolymerProperties polymer_props(deck, eclipseState);
    PolymerPropsAd polymer_props_ad(polymer_props);
    // check_well_controls = param.getDefault("check_well_controls", false);
    // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
    // Rock compressibility.
    rock_comp.reset(new RockCompressibility(deck, eclipseState));

    // Gravity.
    gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;

    // Init state variables (saturation and pressure).
    if (param.has("init_saturation")) {
        initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
        initBlackoilSurfvol(*grid->c_grid(), *props, state);
        enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour };
        if (pu.phase_used[Oil] && pu.phase_used[Gas]) {
            const int np = props->numPhases();
            const int nc = grid->c_grid()->number_of_cells;
            for (int c = 0; c < nc; ++c) {
                state.gasoilratio()[c] = state.surfacevol()[c*np + pu.phase_pos[Gas]]
                    / state.surfacevol()[c*np + pu.phase_pos[Oil]];
            }
        }
    } else if (deck->hasKeyword("EQUIL") && props->numPhases() == 3) {
        state.init(*grid->c_grid(), props->numPhases());
        const double grav = param.getDefault("gravity", unit::gravity);
        initStateEquil(*grid->c_grid(), *props, deck, eclipseState, grav, state);
        state.faceflux().resize(grid->c_grid()->number_of_faces, 0.0);
    } else {
        initBlackoilStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], state);
    }

    // The capillary pressure is scaled in new_props to match the scaled capillary pressure in props.
    if (deck->hasKeyword("SWATINIT")) {
        const int nc = grid->c_grid()->number_of_cells;
        std::vector<int> cells(nc);
        for (int c = 0; c < nc; ++c) { cells[c] = c; }
        std::vector<double> pc = state.saturation();
        props->capPress(nc, state.saturation().data(), cells.data(), pc.data(),NULL);
        new_props->setSwatInitScaling(state.saturation(),pc);
    }

    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    const double *grav = use_gravity ? &gravity[0] : 0;

    // Solver for Newton iterations.
    std::unique_ptr<NewtonIterationBlackoilInterface> fis_solver;
    if (param.getDefault("use_cpr", true)) {
        fis_solver.reset(new NewtonIterationBlackoilCPR(param));
    } else {
        fis_solver.reset(new NewtonIterationBlackoilSimple(param));
    }

    Opm::ScheduleConstPtr schedule = eclipseState->getSchedule();
    Opm::TimeMapConstPtr timeMap(schedule->getTimeMap());
    SimulatorTimer simtimer;

    // initialize variables
    simtimer.init(timeMap);
    if (polymer){
        if (!use_wpolymer) {
            OPM_MESSAGE("Warning: simulate polymer injection without WPOLYMER.");
        } else {
            if (param.has("polymer_start_days")) {
                OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck."
                            "You seem to be trying to control it via parameter poly_start_days (etc.) as well.");
            }
        }
    } else {
        if (use_wpolymer) {
            OPM_MESSAGE("Warning: use WPOLYMER in a non-polymer scenario.");
        }
    }

    bool use_local_perm = param.getDefault("use_local_perm", true);
    Opm::DerivedGeology geology(*grid->c_grid(), *new_props, eclipseState, use_local_perm, grav);

    std::map<std::pair<int, int>, double> maxDp;
    computeMaxDp(maxDp, deck, eclipseState, *grid->c_grid(), state, *props, gravity[2]);
    std::vector<double> threshold_pressures = thresholdPressures(deck, eclipseState, *grid->c_grid(), maxDp);

    Opm::BlackoilOutputWriter
        outputWriter(cGrid, param, eclipseState, pu,
                     new_props->permeability());

    SimulatorFullyImplicitBlackoilPolymer<UnstructuredGrid>
        simulator(param,
                  *grid->c_grid(),
                  geology,
                  *new_props,
                  polymer_props_ad,
                  rock_comp->isActive() ? rock_comp.get() : 0,
                  *fis_solver,
                  grav,
                  deck->hasKeyword("DISGAS"),
                  deck->hasKeyword("VAPOIL"),
                  polymer,
                  deck->hasKeyword("PLYSHLOG"),
                  deck->hasKeyword("SHRATE"),
                  eclipseState,
                  outputWriter,
                  deck,
                  threshold_pressures);

    if (!schedule->initOnly()){
        std::cout << "\n\n================ Starting main simulation loop ===============\n"
                  << std::flush;

        SimulatorReport fullReport = simulator.run(simtimer, state);

        std::cout << "\n\n================    End of simulation     ===============\n\n";
        fullReport.report(std::cout);

        if (output) {
            std::string filename = output_dir + "/walltime.txt";
            std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
            fullReport.reportParam(tot_os);
            warnIfUnusedParams(param);
        }
    } else {
        outputWriter.writeInit( simtimer );
        std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
    }
}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}
コード例 #24
0
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    std::cout << "\n================    Test program for weakly compressible two-phase flow with polymer    ===============\n\n";
    parameter::ParameterGroup param(argc, argv, false);
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;

    // If we have a "deck_filename", grid and props will be read from that.
    bool use_deck = param.has("deck_filename");
    boost::scoped_ptr<GridManager> grid;
    boost::scoped_ptr<BlackoilPropertiesInterface> props;
    boost::scoped_ptr<RockCompressibility> rock_comp;
    Opm::DeckConstPtr deck;
    EclipseStateConstPtr eclipseState;
    std::unique_ptr<PolymerBlackoilState> state;
    Opm::PolymerProperties poly_props;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    if (use_deck) {
        std::string deck_filename = param.get<std::string>("deck_filename");
        ParserPtr parser(new Opm::Parser());
        Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
        deck = parser->parseFile(deck_filename , parseContext);
        eclipseState.reset(new Opm::EclipseState(deck , parseContext));

        // Grid init
        grid.reset(new GridManager(deck));
        {
            const UnstructuredGrid& ug_grid = *(grid->c_grid());

            // Rock and fluid init
            props.reset(new BlackoilPropertiesFromDeck(deck, eclipseState, ug_grid));
            // check_well_controls = param.getDefault("check_well_controls", false);
            // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);

            state.reset( new PolymerBlackoilState(  UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 2));
            // Rock compressibility.
            rock_comp.reset(new RockCompressibility(deck, eclipseState));
            // Gravity.
            gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
            // Init state variables (saturation and pressure).
            if (param.has("init_saturation")) {
                initStateBasic(ug_grid, *props, param, gravity[2], *state);
            } else {
                initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
            }
            initBlackoilSurfvol(ug_grid, *props, *state);
            // Init polymer properties.
            poly_props.readFromDeck(deck, eclipseState);
        }
    } else {
        // Grid init.
        const int nx = param.getDefault("nx", 100);
        const int ny = param.getDefault("ny", 100);
        const int nz = param.getDefault("nz", 1);
        const double dx = param.getDefault("dx", 1.0);
        const double dy = param.getDefault("dy", 1.0);
        const double dz = param.getDefault("dz", 1.0);
        grid.reset(new GridManager(nx, ny, nz, dx, dy, dz));
        {
            const UnstructuredGrid& ug_grid = *(grid->c_grid());

            // Rock and fluid init.
            props.reset(new BlackoilPropertiesBasic(param, ug_grid.dimensions, UgGridHelpers::numCells( ug_grid )));
            state.reset( new PolymerBlackoilState(  UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ) , 2));
            // Rock compressibility.
            rock_comp.reset(new RockCompressibility(param));
            // Gravity.
            gravity[2] = param.getDefault("gravity", 0.0);
            // Init state variables (saturation and pressure).
            initStateBasic(ug_grid, *props, param, gravity[2], *state);
            initBlackoilSurfvol(ug_grid, *props, *state);
            // Init Polymer state

            if (param.has("poly_init")) {
                double poly_init = param.getDefault("poly_init", 0.0);
                for (int cell = 0; cell < UgGridHelpers::numCells( ug_grid ); ++cell) {
                    double smin[2], smax[2];

                    auto& saturation = state->saturation();
                    auto& concentration = state->getCellData( state->CONCENTRATION );
                    auto& max_concentration = state->getCellData( state->CMAX );

                    props->satRange(1, &cell, smin, smax);
                    if (saturation[2*cell] > 0.5*(smin[0] + smax[0])) {
                        concentration[cell] = poly_init;
                        max_concentration[cell] = poly_init;
                    } else {
                        saturation[2*cell + 0] = 0.;
                        saturation[2*cell + 1] = 1.;
                        concentration[cell] = 0.;
                        max_concentration[cell] = 0.;
                    }
                }
            }

        }
        // Init polymer properties.
        // Setting defaults to provide a simple example case.
        double c_max = param.getDefault("c_max_limit", 5.0);
        double mix_param = param.getDefault("mix_param", 1.0);
        double rock_density = param.getDefault("rock_density", 1000.0);
        double dead_pore_vol = param.getDefault("dead_pore_vol", 0.15);
        double res_factor = param.getDefault("res_factor", 1.) ; // res_factor = 1 gives no change in permeability
        double c_max_ads = param.getDefault("c_max_ads", 1.);
        int ads_index = param.getDefault<int>("ads_index", Opm::PolymerProperties::NoDesorption);
        std::vector<double> c_vals_visc(2, -1e100);
        c_vals_visc[0] = 0.0;
        c_vals_visc[1] = 7.0;
        std::vector<double> visc_mult_vals(2, -1e100);
        visc_mult_vals[0] = 1.0;
        // poly_props.visc_mult_vals[1] = param.getDefault("c_max_viscmult", 30.0);
        visc_mult_vals[1] = 20.0;
        std::vector<double> c_vals_ads(3, -1e100);
        c_vals_ads[0] = 0.0;
        c_vals_ads[1] = 2.0;
        c_vals_ads[2] = 8.0;
        std::vector<double> ads_vals(3, -1e100);
        ads_vals[0] = 0.0;
        ads_vals[1] = 0.0015;
        ads_vals[2] = 0.0025;
        // ads_vals[1] = 0.0;
        // ads_vals[2] = 0.0;
        std::vector<double> water_vel_vals(2, -1e100);
        water_vel_vals[0] = 0.0;
        water_vel_vals[1] = 10.0;
        std::vector<double> shear_vrf_vals(2, -1e100);
        shear_vrf_vals[0] = 1.0;
        shear_vrf_vals[1] = 1.0;
        poly_props.set(c_max, mix_param, rock_density, dead_pore_vol, res_factor, c_max_ads,
                       static_cast<Opm::PolymerProperties::AdsorptionBehaviour>(ads_index),
                       c_vals_visc,  visc_mult_vals, c_vals_ads, ads_vals, water_vel_vals, shear_vrf_vals);
    }

    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    const double *grav = use_gravity ? &gravity[0] : 0;

    // Linear solver.
    LinearSolverFactory linsolver(param);

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    if (output) {
      std::string output_dir =
        param.getDefault("output_dir", std::string("output"));
      boost::filesystem::path fpath(output_dir);
      try {
        create_directories(fpath);
      }
      catch (...) {
        OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
      }
      param.writeParam(output_dir + "/simulation.param");
    }


    std::cout << "\n\n================    Starting main simulation loop     ===============\n"
              << std::flush;

    SimulatorReport rep;
    if (!use_deck) {
        // Simple simulation without a deck.
        PolymerInflowBasic polymer_inflow(param.getDefault("poly_start_days", 300.0)*Opm::unit::day,
                                          param.getDefault("poly_end_days", 800.0)*Opm::unit::day,
                                          param.getDefault("poly_amount", poly_props.cMax()));
        WellsManager wells;
        SimulatorCompressiblePolymer simulator(param,
                                               *grid->c_grid(),
                                               *props,
                                               poly_props,
                                               rock_comp->isActive() ? rock_comp.get() : 0,
                                               wells,
                                               polymer_inflow,
                                               linsolver,
                                               grav);
        SimulatorTimer simtimer;
        simtimer.init(param);
        warnIfUnusedParams(param);
        WellState well_state;
        well_state.init(0, *state);
        rep = simulator.run(simtimer, *state, well_state);
    } else {
        // With a deck, we may have more epochs etc.
        WellState well_state;
        int step = 0;
        Opm::TimeMapPtr timeMap(new Opm::TimeMap(deck));
        SimulatorTimer simtimer;
        simtimer.init(timeMap);
        // Check for WPOLYMER presence in last report step to decide
        // polymer injection control type.
        const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
        if (use_wpolymer) {
            if (param.has("poly_start_days")) {
                OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. "
                        "You seem to be trying to control it via parameter poly_start_days (etc.) as well.");
            }
        }
        for (size_t reportStepIdx = 0; reportStepIdx < timeMap->numTimesteps(); ++reportStepIdx) {
            simtimer.setCurrentStepNum(reportStepIdx);

            // Report on start of report step.
            std::cout << "\n\n--------------    Starting report step " << reportStepIdx << "    --------------"
                      << "\n                  (number of remaining steps: "
                      << simtimer.numSteps() - step << ")\n\n" << std::flush;

            // Create new wells, polymer inflow controls.
            WellsManager wells(eclipseState , reportStepIdx , *grid->c_grid(), props->permeability());
            boost::scoped_ptr<PolymerInflowInterface> polymer_inflow;
            if (use_wpolymer) {
                if (wells.c_wells() == 0) {
                    OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells.");
                }
                polymer_inflow.reset(new PolymerInflowFromDeck(eclipseState, *wells.c_wells(), props->numCells(), simtimer.currentStepNum()));
            } else {
                polymer_inflow.reset(new PolymerInflowBasic(param.getDefault("poly_start_days", 300.0)*Opm::unit::day,
                                                            param.getDefault("poly_end_days", 800.0)*Opm::unit::day,
                                                            param.getDefault("poly_amount", poly_props.cMax())));
            }

            // @@@ HACK: we should really make a new well state and
            // properly transfer old well state to it every report step,
            // since number of wells may change etc.
            if (reportStepIdx == 0) {
                well_state.init(wells.c_wells(), *state);
            }

            // Create and run simulator.
            SimulatorCompressiblePolymer simulator(param,
                                                   *grid->c_grid(),
                                                   *props,
                                                   poly_props,
                                                   rock_comp->isActive() ? rock_comp.get() : 0,
                                                   wells,
                                                   *polymer_inflow,
                                                   linsolver,
                                                   grav);
            if (reportStepIdx == 0) {
                warnIfUnusedParams(param);
            }
            SimulatorReport epoch_rep = simulator.run(simtimer, *state, well_state);

            // Update total timing report and remember step number.
            rep += epoch_rep;
            step = simtimer.currentStepNum();
        }
    }

    std::cout << "\n\n================    End of simulation     ===============\n\n";
    rep.report(std::cout);
}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}
コード例 #25
0
ファイル: compute_tof.cpp プロジェクト: PETECLAM/opm-core
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    std::cout << "\n================    Test program for incompressible tof computations     ===============\n\n";
    parameter::ParameterGroup param(argc, argv, false);
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;

    // If we have a "deck_filename", grid and props will be read from that.
    bool use_deck = param.has("deck_filename");
    Opm::DeckConstPtr deck;
    std::unique_ptr<GridManager> grid;
    std::unique_ptr<IncompPropertiesInterface> props;
    std::unique_ptr<Opm::WellsManager> wells;
    TwophaseState state;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    if (use_deck) {
        std::string deck_filename = param.get<std::string>("deck_filename");
        Opm::ParserPtr parser(new Opm::Parser());
        deck = parser->parseFile(deck_filename);
        Opm::EclipseStateConstPtr eclipseState(new Opm::EclipseState(deck));

        // Grid init
        grid.reset(new GridManager(deck));
        // Rock and fluid init
        props.reset(new IncompPropertiesFromDeck(deck, eclipseState, *grid->c_grid()));
        // Wells init.
        wells.reset(new Opm::WellsManager(eclipseState , 0 , *grid->c_grid(), props->permeability()));
        // Gravity.
        gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
        // Init state variables (saturation and pressure).
        if (param.has("init_saturation")) {
            initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
        } else {
            initStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], state);
        }
    } else {
        // Grid init.
        const int nx = param.getDefault("nx", 100);
        const int ny = param.getDefault("ny", 100);
        const int nz = param.getDefault("nz", 1);
        const double dx = param.getDefault("dx", 1.0);
        const double dy = param.getDefault("dy", 1.0);
        const double dz = param.getDefault("dz", 1.0);
        grid.reset(new GridManager(nx, ny, nz, dx, dy, dz));
        // Rock and fluid init.
        props.reset(new IncompPropertiesBasic(param, grid->c_grid()->dimensions, grid->c_grid()->number_of_cells));
        // Wells init.
        wells.reset(new Opm::WellsManager());
        // Gravity.
        gravity[2] = param.getDefault("gravity", 0.0);
        // Init state variables (saturation and pressure).
        initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
    }

    // Warn if gravity but no density difference.
    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    if (use_gravity) {
        if (props->density()[0] == props->density()[1]) {
            std::cout << "**** Warning: nonzero gravity, but zero density difference." << std::endl;
        }
    }
    const double *grav = use_gravity ? &gravity[0] : 0;

    // Initialising src
    std::vector<double> porevol;
    computePorevolume(*grid->c_grid(), props->porosity(), porevol);
    int num_cells = grid->c_grid()->number_of_cells;
    std::vector<double> src(num_cells, 0.0);
    if (use_deck) {
        // Do nothing, wells will be the driving force, not source terms.
    } else {
        const double tot_porevol_init = std::accumulate(porevol.begin(), porevol.end(), 0.0);
        const double default_injection = use_gravity ? 0.0 : 0.1;
        const double flow_per_sec = param.getDefault<double>("injected_porevolumes_per_day", default_injection)
            *tot_porevol_init/unit::day;
        src[0] = flow_per_sec;
        src[num_cells - 1] = -flow_per_sec;
    }

    // Boundary conditions.
    FlowBCManager bcs;
    if (param.getDefault("use_pside", false)) {
        int pside = param.get<int>("pside");
        double pside_pressure = param.get<double>("pside_pressure");
        bcs.pressureSide(*grid->c_grid(), FlowBCManager::Side(pside), pside_pressure);
    }

    // Linear solver.
    LinearSolverFactory linsolver(param);

    // Pressure solver.
    Opm::IncompTpfa psolver(*grid->c_grid(), *props, 0, linsolver,
                            0.0, 0.0, 0,
                            grav, wells->c_wells(), src, bcs.c_bcs());

    // Choice of tof solver.
    bool use_dg = param.getDefault("use_dg", false);
    bool use_multidim_upwind = false;
    // Need to initialize dg solver here, since it uses parameters now.
    std::unique_ptr<Opm::TofDiscGalReorder> dg_solver;
    if (use_dg) {
        dg_solver.reset(new Opm::TofDiscGalReorder(*grid->c_grid(), param));
    } else {
        use_multidim_upwind = param.getDefault("use_multidim_upwind", false);
    }
    bool compute_tracer = param.getDefault("compute_tracer", false);

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    std::ofstream epoch_os;
    std::string output_dir;
    if (output) {
        output_dir =
            param.getDefault("output_dir", std::string("output"));
        boost::filesystem::path fpath(output_dir);
        try {
            create_directories(fpath);
        }
        catch (...) {
            OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
        }
        std::string filename = output_dir + "/epoch_timing.param";
        epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out);
        // open file to clean it. The file is appended to in SimulatorTwophase
        filename = output_dir + "/step_timing.param";
        std::fstream step_os(filename.c_str(), std::fstream::trunc | std::fstream::out);
        step_os.close();
        param.writeParam(output_dir + "/simulation.param");
    }

    // Init wells.
    Opm::WellState well_state;
    well_state.init(wells->c_wells(), state);

    // Check if we have misspelled anything
    warnIfUnusedParams(param);

    // Main solvers.
    Opm::time::StopWatch pressure_timer;
    double ptime = 0.0;
    Opm::time::StopWatch transport_timer;
    double ttime = 0.0;
    Opm::time::StopWatch total_timer;
    total_timer.start();
    std::cout << "\n\n================    Starting main solvers     ===============" << std::endl;

    // Solve pressure.
    pressure_timer.start();
    psolver.solve(1.0, state, well_state);
    pressure_timer.stop();
    double pt = pressure_timer.secsSinceStart();
    std::cout << "Pressure solver took:  " << pt << " seconds." << std::endl;
    ptime += pt;

    // Process transport sources (to include bdy terms and well flows).
    std::vector<double> transport_src;
    Opm::computeTransportSource(*grid->c_grid(), src, state.faceflux(), 1.0,
                                wells->c_wells(), well_state.perfRates(), transport_src);

    // Solve time-of-flight.
    transport_timer.start();
    std::vector<double> tof;
    std::vector<double> tracer;
    Opm::SparseTable<int> tracerheads;
    if (compute_tracer) {
        buildTracerheadsFromWells(wells->c_wells(), tracerheads);
    }
    if (use_dg) {
        if (compute_tracer) {
            dg_solver->solveTofTracer(&state.faceflux()[0], &porevol[0], &transport_src[0], tracerheads, tof, tracer);
        } else {
            dg_solver->solveTof(&state.faceflux()[0], &porevol[0], &transport_src[0], tof);
        }
    } else {
        Opm::TofReorder tofsolver(*grid->c_grid(), use_multidim_upwind);
        if (compute_tracer) {
            tofsolver.solveTofTracer(&state.faceflux()[0], &porevol[0], &transport_src[0], tracerheads, tof, tracer);
        } else {
            tofsolver.solveTof(&state.faceflux()[0], &porevol[0], &transport_src[0], tof);
        }
    }
    transport_timer.stop();
    double tt = transport_timer.secsSinceStart();
    std::cout << "Transport solver took: " << tt << " seconds." << std::endl;
    ttime += tt;
    total_timer.stop();

    // Output.
    if (output) {
        std::string tof_filename = output_dir + "/tof.txt";
        std::ofstream tof_stream(tof_filename.c_str());
        tof_stream.precision(16);
        std::copy(tof.begin(), tof.end(), std::ostream_iterator<double>(tof_stream, "\n"));
        if (compute_tracer) {
            std::string tracer_filename = output_dir + "/tracer.txt";
            std::ofstream tracer_stream(tracer_filename.c_str());
            tracer_stream.precision(16);
            const int nt = tracer.size()/num_cells;
            for (int i = 0; i < nt*num_cells; ++i) {
                tracer_stream << tracer[i] << (((i + 1) % nt == 0) ? '\n' : ' ');
            }
        }
    }

    std::cout << "\n\n================    End of simulation     ===============\n"
              << "Total time taken: " << total_timer.secsSinceStart()
              << "\n  Pressure time:  " << ptime
              << "\n  Transport time: " << ttime << std::endl;
}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}
コード例 #26
0
std::vector<std::shared_ptr<PvtInterface> > getProps(Opm::DeckConstPtr deck, PhaseUsage phase_usage_){
    Opm::GridManager grid(deck);

    enum PhaseIndex { Aqua = 0, Liquid = 1, Vapour = 2 };
    int samples = 0;

    std::vector<std::shared_ptr<PvtInterface> > props_;
    // Set the properties.
    props_.resize(phase_usage_.num_phases);

    // Water PVT
    if (phase_usage_.phase_used[Aqua]) {
        if (deck->hasKeyword("PVTW")) {
            std::shared_ptr<PvtConstCompr> pvtw(new PvtConstCompr);
            pvtw->initFromWater(deck->getKeyword("PVTW"));

            props_[phase_usage_.phase_pos[Aqua]] = pvtw;
        } else {
            // Eclipse 100 default.
            props_[phase_usage_.phase_pos[Aqua]].reset(new PvtConstCompr(0.5*Opm::prefix::centi*Opm::unit::Poise));
        }
    }

    // Oil PVT
    if (phase_usage_.phase_used[Liquid]) {
        if (deck->hasKeyword("PVDO")) {
            Opm::DeckKeywordConstPtr pvdoKeyword(deck->getKeyword("PVDO"));
            if (samples > 0) {
                std::shared_ptr<PvtDeadSpline> splinePvt(new PvtDeadSpline);
                splinePvt->initFromOil(pvdoKeyword, samples);
                props_[phase_usage_.phase_pos[Liquid]] = splinePvt;
            } else {
                std::shared_ptr<PvtDead> deadPvt(new PvtDead);
                deadPvt->initFromOil(pvdoKeyword);
                props_[phase_usage_.phase_pos[Liquid]] = deadPvt;
            }
        } else if (deck->hasKeyword("PVTO")) {
            props_[phase_usage_.phase_pos[Liquid]].reset(new PvtLiveOil(deck->getKeyword("PVTO")));
        } else if (deck->hasKeyword("PVCDO")) {
            std::shared_ptr<PvtConstCompr> pvcdo(new PvtConstCompr);
            pvcdo->initFromOil(deck->getKeyword("PVCDO"));

            props_[phase_usage_.phase_pos[Liquid]] = pvcdo;
        } else {
            OPM_THROW(std::runtime_error, "Input is missing PVDO, PVCDO or PVTO\n");
        }
    }
    // Gas PVT
    if (phase_usage_.phase_used[Vapour]) {
        if (deck->hasKeyword("PVDG")) {
            Opm::DeckKeywordConstPtr pvdgKeyword(deck->getKeyword("PVDG"));
            if (samples > 0) {
                std::shared_ptr<PvtDeadSpline> splinePvt(new PvtDeadSpline);
                splinePvt->initFromGas(pvdgKeyword, samples);
                props_[phase_usage_.phase_pos[Vapour]] = splinePvt;
            } else {
                std::shared_ptr<PvtDead> deadPvt(new PvtDead);
                deadPvt->initFromGas(pvdgKeyword);
                props_[phase_usage_.phase_pos[Vapour]] = deadPvt;
            }
        } else if (deck->hasKeyword("PVTG")) {
            props_[phase_usage_.phase_pos[Vapour]].reset(new PvtLiveGas(deck->getKeyword("PVTG")));
        } else {
            OPM_THROW(std::runtime_error, "Input is missing PVDG or PVTG\n");
        }
    }

    return props_;
}
コード例 #27
0
// ----------------- Main program -----------------
int
main(int argc, char** argv)
try
{
    using namespace Opm;

    std::cout << "\n================    Test program for weakly compressible two-phase flow     ===============\n\n";
    parameter::ParameterGroup param(argc, argv, false);
    std::cout << "---------------    Reading parameters     ---------------" << std::endl;

    // If we have a "deck_filename", grid and props will be read from that.
    bool use_deck = param.has("deck_filename");
    EclipseStateConstPtr eclipseState;
    std::unique_ptr<GridManager> grid;
    std::unique_ptr<BlackoilPropertiesInterface> props;
    std::unique_ptr<RockCompressibility> rock_comp;

    ParserPtr parser(new Opm::Parser());
    Opm::DeckConstPtr deck;

    BlackoilState state;
    // bool check_well_controls = false;
    // int max_well_control_iterations = 0;
    double gravity[3] = { 0.0 };
    if (use_deck) {
        ParseMode parseMode;
        std::string deck_filename = param.get<std::string>("deck_filename");
        deck = parser->parseFile(deck_filename , parseMode);
        eclipseState.reset(new EclipseState(deck, parseMode));

        // Grid init
        grid.reset(new GridManager(deck));
        // Rock and fluid init
        props.reset(new BlackoilPropertiesFromDeck(deck, eclipseState, *grid->c_grid(), param));
        // check_well_controls = param.getDefault("check_well_controls", false);
        // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
        // Rock compressibility.
        rock_comp.reset(new RockCompressibility(deck, eclipseState));
        // Gravity.
        gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
        // Init state variables (saturation and pressure).
        if (param.has("init_saturation")) {
            initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
        } else {
            initStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], state);
        }
        initBlackoilSurfvol(*grid->c_grid(), *props, state);
    } else {
        // Grid init.
        const int nx = param.getDefault("nx", 100);
        const int ny = param.getDefault("ny", 100);
        const int nz = param.getDefault("nz", 1);
        const double dx = param.getDefault("dx", 1.0);
        const double dy = param.getDefault("dy", 1.0);
        const double dz = param.getDefault("dz", 1.0);
        grid.reset(new GridManager(nx, ny, nz, dx, dy, dz));
        // Rock and fluid init.
        props.reset(new BlackoilPropertiesBasic(param, grid->c_grid()->dimensions, grid->c_grid()->number_of_cells));
        // Rock compressibility.
        rock_comp.reset(new RockCompressibility(param));
        // Gravity.
        gravity[2] = param.getDefault("gravity", 0.0);
        // Init state variables (saturation and pressure).
        initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
        initBlackoilSurfvol(*grid->c_grid(), *props, state);
    }

    bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
    const double *grav = use_gravity ? &gravity[0] : 0;

    // Initialising src
    int num_cells = grid->c_grid()->number_of_cells;
    std::vector<double> src(num_cells, 0.0);
    if (use_deck) {
        // Do nothing, wells will be the driving force, not source terms.
    } else {
        // Compute pore volumes, in order to enable specifying injection rate
        // terms of total pore volume.
        std::vector<double> porevol;
        if (rock_comp->isActive()) {
            computePorevolume(*grid->c_grid(), props->porosity(), *rock_comp, state.pressure(), porevol);
        } else {
            computePorevolume(*grid->c_grid(), props->porosity(), porevol);
        }
        const double tot_porevol_init = std::accumulate(porevol.begin(), porevol.end(), 0.0);
        const double default_injection = use_gravity ? 0.0 : 0.1;
        const double flow_per_sec = param.getDefault<double>("injected_porevolumes_per_day", default_injection)
            *tot_porevol_init/unit::day;
        src[0] = flow_per_sec;
        src[num_cells - 1] = -flow_per_sec;
    }

    // Boundary conditions.
    FlowBCManager bcs;
    if (param.getDefault("use_pside", false)) {
        int pside = param.get<int>("pside");
        double pside_pressure = param.get<double>("pside_pressure");
        bcs.pressureSide(*grid->c_grid(), FlowBCManager::Side(pside), pside_pressure);
    }

    // Linear solver.
    LinearSolverFactory linsolver(param);

    // Write parameters used for later reference.
    bool output = param.getDefault("output", true);
    std::ofstream epoch_os;
    std::string output_dir;
    if (output) {
        output_dir =
            param.getDefault("output_dir", std::string("output"));
        boost::filesystem::path fpath(output_dir);
        try {
            create_directories(fpath);
        }
        catch (...) {
            OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
        }
        std::string filename = output_dir + "/epoch_timing.param";
        epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out);
        // open file to clean it. The file is appended to in SimulatorTwophase
        filename = output_dir + "/step_timing.param";
        std::fstream step_os(filename.c_str(), std::fstream::trunc | std::fstream::out);
        step_os.close();
        param.writeParam(output_dir + "/simulation.param");
    }


    std::cout << "\n\n================    Starting main simulation loop     ===============\n";

    SimulatorReport rep;
    if (!use_deck) {
        // Simple simulation without a deck.
        WellsManager wells; // no wells.
        SimulatorCompressibleTwophase simulator(param,
                                                *grid->c_grid(),
                                                *props,
                                                rock_comp->isActive() ? rock_comp.get() : 0,
                                                wells,
                                                src,
                                                bcs.c_bcs(),
                                                linsolver,
                                                grav);
        SimulatorTimer simtimer;
        simtimer.init(param);
        warnIfUnusedParams(param);
        WellState well_state;
        well_state.init(0, state);
        rep = simulator.run(simtimer, state, well_state);
    } else {
        // With a deck, we may have more epochs etc.
        WellState well_state;
        int step = 0;
        SimulatorTimer simtimer;
        // Use timer for last epoch to obtain total time.
        Opm::TimeMapPtr timeMap(new Opm::TimeMap(deck));
        simtimer.init(timeMap);
        const double total_time = simtimer.totalTime();
        for (size_t reportStepIdx = 0; reportStepIdx < timeMap->numTimesteps(); ++reportStepIdx) {
            simtimer.setCurrentStepNum(step);
            simtimer.setTotalTime(total_time);

            // Report on start of report step.
            std::cout << "\n\n--------------    Starting report step " << reportStepIdx << "    --------------"
                      << "\n                  (number of steps: "
                      << simtimer.numSteps() - step << ")\n\n" << std::flush;

            // Create new wells, well_state
            WellsManager wells(eclipseState , reportStepIdx , *grid->c_grid(), props->permeability());
            // @@@ HACK: we should really make a new well state and
            // properly transfer old well state to it every report step,
            // since number of wells may change etc.
            if (reportStepIdx == 0) {
                well_state.init(wells.c_wells(), state);
            }

            // Create and run simulator.
            SimulatorCompressibleTwophase simulator(param,
                                                    *grid->c_grid(),
                                                    *props,
                                                    rock_comp->isActive() ? rock_comp.get() : 0,
                                                    wells,
                                                    src,
                                                    bcs.c_bcs(),
                                                    linsolver,
                                                    grav);
            if (reportStepIdx == 0) {
                warnIfUnusedParams(param);
            }
            SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state);
            if (output) {
                epoch_rep.reportParam(epoch_os);
            }
            // Update total timing report and remember step number.
            rep += epoch_rep;
            step = simtimer.currentStepNum();
        }
    }

    std::cout << "\n\n================    End of simulation     ===============\n\n";
    rep.report(std::cout);

    if (output) {
        std::string filename = output_dir + "/walltime.param";
        std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
        rep.reportParam(tot_os);
    }

}
catch (const std::exception &e) {
    std::cerr << "Program threw an exception: " << e.what() << "\n";
    throw;
}