mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
remove files
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/flowdiagnostics/AnisotropicEikonal.hpp>
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/grid/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Warning: unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "-------------------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
ParameterGroup param(argc, argv);
|
||||
|
||||
// Read grid.
|
||||
GridManager grid_manager(param.get<std::string>("grid_filename"));
|
||||
const UnstructuredGrid& grid = *grid_manager.c_grid();
|
||||
|
||||
// Read metric tensor.
|
||||
std::vector<double> metric;
|
||||
{
|
||||
std::ifstream metric_stream(param.get<std::string>("metric_filename").c_str());
|
||||
std::istream_iterator<double> beg(metric_stream);
|
||||
std::istream_iterator<double> end;
|
||||
metric.assign(beg, end);
|
||||
if (int(metric.size()) != grid.number_of_cells*grid.dimensions*grid.dimensions) {
|
||||
OPM_THROW(std::runtime_error, "Size of metric field differs from (dim^2 * number of cells).");
|
||||
}
|
||||
}
|
||||
|
||||
// Read starting cells.
|
||||
std::vector<int> startcells;
|
||||
{
|
||||
std::ifstream start_stream(param.get<std::string>("startcells_filename").c_str());
|
||||
std::istream_iterator<int> beg(start_stream);
|
||||
std::istream_iterator<int> end;
|
||||
startcells.assign(beg, end);
|
||||
}
|
||||
|
||||
// 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 + "/eikonal.param");
|
||||
}
|
||||
|
||||
// Issue a warning if any parameters were unused.
|
||||
warnIfUnusedParams(param);
|
||||
|
||||
// Solve eikonal equation.
|
||||
Opm::time::StopWatch timer;
|
||||
timer.start();
|
||||
std::vector<double> solution;
|
||||
AnisotropicEikonal2d ae(grid);
|
||||
ae.solve(metric.data(), startcells, solution);
|
||||
timer.stop();
|
||||
double tt = timer.secsSinceStart();
|
||||
std::cout << "Eikonal solver took: " << tt << " seconds." << std::endl;
|
||||
|
||||
// Output.
|
||||
if (output) {
|
||||
std::string filename = output_dir + "/solution.txt";
|
||||
std::ofstream stream(filename.c_str());
|
||||
stream.precision(16);
|
||||
std::copy(solution.begin(), solution.end(), std::ostream_iterator<double>(stream, "\n"));
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2017 IRIS
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initStateEquil.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
#include <opm/core/props/BlackoilPhases.hpp>
|
||||
#include <opm/core/props/phaseUsageFromDeck.hpp>
|
||||
#include <opm/core/simulator/BlackoilState.hpp>
|
||||
#include <opm/grid/utility/compressedToCartesian.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void outputData(const std::string& output_dir,
|
||||
const std::string& name,
|
||||
const std::vector<double>& data)
|
||||
{
|
||||
std::ostringstream fname;
|
||||
fname << output_dir << "/" << name;
|
||||
boost::filesystem::path fpath = fname.str();
|
||||
try {
|
||||
create_directories(fpath);
|
||||
}
|
||||
catch (...) {
|
||||
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
|
||||
}
|
||||
fname << "/" << "initial.txt";
|
||||
std::ofstream file(fname.str().c_str());
|
||||
if (!file) {
|
||||
OPM_THROW(std::runtime_error, "Failed to open " << fname.str());
|
||||
}
|
||||
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(file, "\n"));
|
||||
}
|
||||
|
||||
/// Convert saturations from a vector of individual phase saturation vectors
|
||||
/// to an interleaved format where all values for a given cell come before all
|
||||
/// values for the next cell, all in a single vector.
|
||||
template <class FluidSystem>
|
||||
void convertSats(std::vector<double>& sat_interleaved, const std::vector< std::vector<double> >& sat, const Opm::PhaseUsage& pu)
|
||||
{
|
||||
assert(sat.size() == 3);
|
||||
const auto nc = sat[0].size();
|
||||
const auto np = sat_interleaved.size() / nc;
|
||||
for (size_t c = 0; c < nc; ++c) {
|
||||
if ( FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
||||
const int opos = pu.phase_pos[Opm::BlackoilPhases::Liquid];
|
||||
const std::vector<double>& sat_p = sat[ FluidSystem::oilPhaseIdx];
|
||||
sat_interleaved[np*c + opos] = sat_p[c];
|
||||
}
|
||||
if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
||||
const int wpos = pu.phase_pos[Opm::BlackoilPhases::Aqua];
|
||||
const std::vector<double>& sat_p = sat[ FluidSystem::waterPhaseIdx];
|
||||
sat_interleaved[np*c + wpos] = sat_p[c];
|
||||
}
|
||||
if ( FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
||||
const int gpos = pu.phase_pos[Opm::BlackoilPhases::Vapour];
|
||||
const std::vector<double>& sat_p = sat[ FluidSystem::gasPhaseIdx];
|
||||
sat_interleaved[np*c + gpos] = sat_p[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
// Setup.
|
||||
ParameterGroup param(argc, argv);
|
||||
std::cout << "--------------- Reading parameters ---------------" << std::endl;
|
||||
const std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
Opm::ParseContext parseContext;
|
||||
Opm::Parser parser;
|
||||
const Opm::Deck& deck = parser.parseFile(deck_filename , parseContext);
|
||||
const Opm::EclipseState eclipseState(deck, parseContext);
|
||||
const double grav = param.getDefault("gravity", unit::gravity);
|
||||
GridManager gm(eclipseState.getInputGrid());
|
||||
const UnstructuredGrid& grid = *gm.c_grid();
|
||||
warnIfUnusedParams(param);
|
||||
|
||||
// Create material law manager.
|
||||
std::vector<int> compressedToCartesianIdx
|
||||
= Opm::compressedToCartesian(grid.number_of_cells, grid.global_cell);
|
||||
|
||||
typedef BlackOilFluidSystem<double> FluidSystem;
|
||||
|
||||
// Forward declaring the MaterialLawManager template.
|
||||
typedef Opm::ThreePhaseMaterialTraits<double,
|
||||
/*wettingPhaseIdx=*/FluidSystem::waterPhaseIdx,
|
||||
/*nonWettingPhaseIdx=*/FluidSystem::oilPhaseIdx,
|
||||
/*gasPhaseIdx=*/FluidSystem::gasPhaseIdx> MaterialTraits;
|
||||
typedef Opm::EclMaterialLawManager<MaterialTraits> MaterialLawManager;
|
||||
|
||||
MaterialLawManager materialLawManager = MaterialLawManager();
|
||||
materialLawManager.initFromDeck(deck, eclipseState, compressedToCartesianIdx);
|
||||
|
||||
// Initialisation.
|
||||
//initBlackoilSurfvolUsingRSorRV(UgGridHelpers::numCells(grid), props, state);
|
||||
BlackoilState state( UgGridHelpers::numCells(grid) , UgGridHelpers::numFaces(grid), 3);
|
||||
FluidSystem::initFromDeck(deck, eclipseState);
|
||||
PhaseUsage pu = phaseUsageFromDeck(deck);
|
||||
|
||||
typedef EQUIL::DeckDependent::InitialStateComputer<FluidSystem> ISC;
|
||||
|
||||
ISC isc(materialLawManager, eclipseState, grid, grav);
|
||||
|
||||
const bool oil = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
|
||||
const int oilpos = FluidSystem::oilPhaseIdx;
|
||||
const int waterpos = FluidSystem::waterPhaseIdx;
|
||||
const int ref_phase = oil ? oilpos : waterpos;
|
||||
|
||||
state.pressure() = isc.press()[ref_phase];
|
||||
convertSats<FluidSystem>(state.saturation(), isc.saturation(), pu);
|
||||
state.gasoilratio() = isc.rs();
|
||||
state.rv() = isc.rv();
|
||||
|
||||
// Output.
|
||||
const std::string output_dir = param.getDefault<std::string>("output_dir", "output");
|
||||
outputData(output_dir, "pressure", state.pressure());
|
||||
outputData(output_dir, "saturation", state.saturation());
|
||||
outputData(output_dir, "rs", state.gasoilratio());
|
||||
outputData(output_dir, "rv", state.rv());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/grid/utility/SparseTable.hpp>
|
||||
#include <opm/grid/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/props/IncompPropertiesBasic.hpp>
|
||||
#include <opm/core/props/IncompPropertiesFromDeck.hpp>
|
||||
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
|
||||
#include <opm/core/simulator/TwophaseState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/flowdiagnostics/TofReorder.hpp>
|
||||
#include <opm/core/flowdiagnostics/TofDiscGalReorder.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <iterator>
|
||||
#include <fstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Warning: unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "-------------------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
ParameterGroup param(argc, argv);
|
||||
|
||||
// Read grid.
|
||||
GridManager grid_manager(param.get<std::string>("grid_filename"));
|
||||
const UnstructuredGrid& grid = *grid_manager.c_grid();
|
||||
|
||||
// Read porosity, compute pore volume.
|
||||
std::vector<double> porevol;
|
||||
{
|
||||
std::ifstream poro_stream(param.get<std::string>("poro_filename").c_str());
|
||||
std::istream_iterator<double> beg(poro_stream);
|
||||
std::istream_iterator<double> end;
|
||||
porevol.assign(beg, end); // Now contains poro.
|
||||
if (int(porevol.size()) != grid.number_of_cells) {
|
||||
OPM_THROW(std::runtime_error, "Size of porosity field differs from number of cells.");
|
||||
}
|
||||
for (int i = 0; i < grid.number_of_cells; ++i) {
|
||||
porevol[i] *= grid.cell_volumes[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Read flux.
|
||||
std::vector<double> flux;
|
||||
{
|
||||
std::ifstream flux_stream(param.get<std::string>("flux_filename").c_str());
|
||||
std::istream_iterator<double> beg(flux_stream);
|
||||
std::istream_iterator<double> end;
|
||||
flux.assign(beg, end);
|
||||
if (int(flux.size()) != grid.number_of_faces) {
|
||||
OPM_THROW(std::runtime_error, "Size of flux field differs from number of faces.");
|
||||
}
|
||||
}
|
||||
|
||||
// Read source terms.
|
||||
std::vector<double> src;
|
||||
{
|
||||
std::ifstream src_stream(param.get<std::string>("src_filename").c_str());
|
||||
std::istream_iterator<double> beg(src_stream);
|
||||
std::istream_iterator<double> end;
|
||||
src.assign(beg, end);
|
||||
if (int(src.size()) != grid.number_of_cells) {
|
||||
OPM_THROW(std::runtime_error, "Size of source term field differs from number of cells.");
|
||||
}
|
||||
}
|
||||
|
||||
const bool compute_tracer = param.getDefault("compute_tracer", false);
|
||||
Opm::SparseTable<int> tracerheads;
|
||||
if (compute_tracer) {
|
||||
std::ifstream tr_stream(param.get<std::string>("tracerheads_filename").c_str());
|
||||
int num_rows;
|
||||
tr_stream >> num_rows;
|
||||
for (int row = 0; row < num_rows; ++row) {
|
||||
int row_size;
|
||||
tr_stream >> row_size;
|
||||
std::vector<int> rowdata(row_size);
|
||||
for (int elem = 0; elem < row_size; ++elem) {
|
||||
tr_stream >> rowdata[elem];
|
||||
}
|
||||
tracerheads.appendRow(rowdata.begin(), rowdata.end());
|
||||
}
|
||||
}
|
||||
|
||||
// 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, param));
|
||||
} else {
|
||||
use_multidim_upwind = param.getDefault("use_multidim_upwind", 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);
|
||||
}
|
||||
param.writeParam(output_dir + "/simulation.param");
|
||||
}
|
||||
|
||||
// Issue a warning if any parameters were unused.
|
||||
warnIfUnusedParams(param);
|
||||
|
||||
// Solve time-of-flight.
|
||||
Opm::time::StopWatch transport_timer;
|
||||
transport_timer.start();
|
||||
std::vector<double> tof;
|
||||
std::vector<double> tracer;
|
||||
if (use_dg) {
|
||||
if (compute_tracer) {
|
||||
dg_solver->solveTofTracer(&flux[0], &porevol[0], &src[0], tracerheads, tof, tracer);
|
||||
} else {
|
||||
dg_solver->solveTof(&flux[0], &porevol[0], &src[0], tof);
|
||||
}
|
||||
} else {
|
||||
Opm::TofReorder tofsolver(grid, use_multidim_upwind);
|
||||
if (compute_tracer) {
|
||||
tofsolver.solveTofTracer(&flux[0], &porevol[0], &src[0], tracerheads, tof, tracer);
|
||||
} else {
|
||||
tofsolver.solveTof(&flux[0], &porevol[0], &src[0], tof);
|
||||
}
|
||||
}
|
||||
transport_timer.stop();
|
||||
double tt = transport_timer.secsSinceStart();
|
||||
std::cout << "Transport solver took: " << tt << " seconds." << std::endl;
|
||||
|
||||
// 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()/grid.number_of_cells;
|
||||
for (int i = 0; i < nt*grid.number_of_cells; ++i) {
|
||||
tracer_stream << tracer[i] << (((i + 1) % nt == 0) ? '\n' : ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
|
||||
#include <opm/core/props/satfunc/RelpermDiagnostics_impl.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/grid/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/common/OpmLog/OpmLog.hpp>
|
||||
#include <opm/common/OpmLog/EclipsePRTLog.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
void usage() {
|
||||
std::cout << std::endl <<
|
||||
"Usage: diagnose_relperm <eclipseFile>" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
if (argc <= 1) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
const char* eclipseFilename = argv[1];
|
||||
Parser parser;
|
||||
Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE },
|
||||
{ ParseContext::PARSE_UNKNOWN_KEYWORD, InputError::IGNORE},
|
||||
{ ParseContext::PARSE_RANDOM_TEXT, InputError::IGNORE},
|
||||
{ ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER, InputError::IGNORE},
|
||||
{ ParseContext::UNSUPPORTED_COMPORD_TYPE, InputError::IGNORE},
|
||||
{ ParseContext::UNSUPPORTED_INITIAL_THPRES, InputError::IGNORE},
|
||||
{ ParseContext::INTERNAL_ERROR_UNINITIALIZED_THPRES, InputError::IGNORE}
|
||||
});
|
||||
Opm::Deck deck = parser.parseFile(eclipseFilename, parseContext);
|
||||
Opm::EclipseState eclState( deck, parseContext );
|
||||
|
||||
GridManager gm(eclState.getInputGrid());
|
||||
const UnstructuredGrid& grid = *gm.c_grid();
|
||||
using boost::filesystem::path;
|
||||
path fpath(eclipseFilename);
|
||||
std::string baseName;
|
||||
if (boost::to_upper_copy(path(fpath.extension()).string())== ".DATA") {
|
||||
baseName = path(fpath.stem()).string();
|
||||
} else {
|
||||
baseName = path(fpath.filename()).string();
|
||||
}
|
||||
|
||||
std::string logFile = baseName + ".SATFUNCLOG";
|
||||
std::shared_ptr<EclipsePRTLog> prtLog = std::make_shared<EclipsePRTLog>(logFile, Log::DefaultMessageTypes);
|
||||
OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog );
|
||||
prtLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true, false));
|
||||
std::shared_ptr<StreamLog> streamLog = std::make_shared<EclipsePRTLog>(std::cout, Log::DefaultMessageTypes);
|
||||
OpmLog::addBackend( "STREAMLOG" , streamLog );
|
||||
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(10));
|
||||
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true, true));
|
||||
RelpermDiagnostics diagnostic;
|
||||
diagnostic.diagnosis(eclState, deck, grid);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*===========================================================================
|
||||
//
|
||||
// File: find_zero.cpp
|
||||
//
|
||||
// Created: 2013-04-29 11:58:29+0200
|
||||
//
|
||||
// Authors: Knut-Andreas Lie <Knut-Andreas.Lie@sintef.no>
|
||||
// Halvor M. Nilsen <HalvorMoll.Nilsen@sintef.no>
|
||||
// Atgeirr F. Rasmussen <atgeirr@sintef.no>
|
||||
// Xavier Raynaud <Xavier.Raynaud@sintef.no>
|
||||
// Bård Skaflestad <Bard.Skaflestad@sintef.no>
|
||||
//
|
||||
//==========================================================================*/
|
||||
|
||||
|
||||
/*
|
||||
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media Project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <opm/autodiff/AutoDiff.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
struct Func
|
||||
{
|
||||
template <typename T>
|
||||
T operator()(T x) const
|
||||
{
|
||||
#if 1
|
||||
T r = std::sqrt(std::cos(x * x) + x) - 1.2;
|
||||
return r;
|
||||
#else
|
||||
return x;
|
||||
// const int n = 6;
|
||||
// double xv[6] = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 };
|
||||
// double yv[6] = { -0.5, -0.3, -0.1, 0.1, 0.3, 0.5 };
|
||||
// int interv = -1;
|
||||
// for (int i = 0; i < n; ++i) {
|
||||
// if (x < xv[i]) {
|
||||
// interv = i - 1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// T t = (x - xv[interv])/(xv[interv+1] - xv[interv]);
|
||||
// return (1.0 - t)*yv[interv] + t*yv[interv+1];
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
// template <class ErrorPolicy = ThrowOnError>
|
||||
class Newton
|
||||
{
|
||||
public:
|
||||
/// Implements a scalar Newton solve.
|
||||
template <class Functor>
|
||||
inline static double solve(const Functor& f,
|
||||
const double initial_guess,
|
||||
const int max_iter,
|
||||
const double tolerance,
|
||||
int& iterations_used)
|
||||
{
|
||||
double x = initial_guess;
|
||||
iterations_used = 0;
|
||||
typedef Opm::AutoDiff<double> AD;
|
||||
while (std::abs(f(x)) > tolerance && ++iterations_used < max_iter) {
|
||||
AD xfad = AD::variable(x);
|
||||
AD rfad = f(xfad);
|
||||
x = x - rfad.val()/rfad.der();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
try
|
||||
{
|
||||
int iter = 0;
|
||||
const double atol = 1.0e-13;
|
||||
const double soln = Newton::solve(Func(), 0.1, 30, atol, iter);
|
||||
|
||||
std::cout.precision(16);
|
||||
std::cout << "Solution is: " << soln
|
||||
<< " using " << iter << " iterations." << '\n';
|
||||
std::cout << " f(x) = " << Func()(soln) << '\n';
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
||||
Copyright 2015 IRIS AS
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
// Define making clear that the simulator supports AMG
|
||||
#define FLOW_SUPPORT_AMG !defined(HAVE_UMFPACK)
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/autodiff/SimulatorFullyImplicitBlackoil.hpp>
|
||||
#include <opm/autodiff/FlowMain.hpp>
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
typedef UnstructuredGrid Grid;
|
||||
typedef Opm::SimulatorFullyImplicitBlackoil<Grid> Simulator;
|
||||
|
||||
Opm::FlowMain<Grid, Simulator> mainfunc;
|
||||
return mainfunc.execute(argc, argv);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/autodiff/SimulatorSequentialBlackoil.hpp>
|
||||
#include <opm/autodiff/FlowMainSequential.hpp>
|
||||
#include <opm/autodiff/BlackoilPressureModel.hpp>
|
||||
#include <opm/autodiff/BlackoilReorderingTransportModel.hpp>
|
||||
#include <opm/autodiff/StandardWells.hpp>
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
typedef UnstructuredGrid Grid;
|
||||
typedef Opm::StandardWells WellModel;
|
||||
typedef Opm::SimulatorSequentialBlackoil<Grid, WellModel, Opm::BlackoilPressureModel, Opm::BlackoilReorderingTransportModel> Simulator;
|
||||
|
||||
Opm::FlowMainSequential<Grid, Simulator> mainfunc;
|
||||
return mainfunc.execute(argc, argv);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/autodiff/SimulatorSequentialBlackoil.hpp>
|
||||
#include <opm/autodiff/FlowMainSequential.hpp>
|
||||
#include <opm/autodiff/BlackoilPressureModel.hpp>
|
||||
#include <opm/autodiff/BlackoilTransportModel.hpp>
|
||||
#include <opm/autodiff/StandardWells.hpp>
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
typedef UnstructuredGrid Grid;
|
||||
typedef Opm::StandardWells WellModel;
|
||||
typedef Opm::SimulatorSequentialBlackoil<Grid, WellModel, Opm::BlackoilPressureModel, Opm::BlackoilTransportModel> Simulator;
|
||||
|
||||
Opm::FlowMainSequential<Grid, Simulator> mainfunc;
|
||||
return mainfunc.execute(argc, argv);
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/grid/GridHelpers.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/props/BlackoilPropertiesBasic.hpp>
|
||||
#include <opm/core/props/BlackoilPropertiesFromDeck.hpp>
|
||||
#include <opm/core/props/rock/RockCompressibility.hpp>
|
||||
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
|
||||
#include <opm/core/simulator/BlackoilState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/simulators/SimulatorCompressibleTwophase.hpp>
|
||||
#include <opm/simulators/ensureDirectoryExists.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <fstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
OpmLog::setupSimpleDefaultLogging(false, true, 10);
|
||||
std::cout << "\n================ Test program for weakly compressible two-phase flow ===============\n\n";
|
||||
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");
|
||||
std::shared_ptr< EclipseState > eclipseState;
|
||||
std::shared_ptr< Schedule > schedule;
|
||||
std::unique_ptr<GridManager> grid;
|
||||
std::unique_ptr<BlackoilPropertiesInterface> props;
|
||||
std::unique_ptr<RockCompressibility> rock_comp;
|
||||
std::unique_ptr<BlackoilState> state;
|
||||
|
||||
|
||||
Parser parser;
|
||||
|
||||
// bool check_well_controls = false;
|
||||
// int max_well_control_iterations = 0;
|
||||
double gravity[3] = { 0.0 };
|
||||
if (use_deck) {
|
||||
ParseContext parseContext;
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
auto deck = parser.parseFile(deck_filename , parseContext);
|
||||
eclipseState.reset(new EclipseState(deck, parseContext));
|
||||
schedule.reset( new Schedule(deck,
|
||||
eclipseState->getInputGrid(),
|
||||
eclipseState->get3DProperties(),
|
||||
eclipseState->runspec(),
|
||||
parseContext));
|
||||
|
||||
|
||||
// Grid init
|
||||
grid.reset(new GridManager(eclipseState->getInputGrid()));
|
||||
{
|
||||
const UnstructuredGrid& ug_grid = *(grid->c_grid());
|
||||
state.reset( new BlackoilState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ) ,2));
|
||||
// Rock and fluid init
|
||||
props.reset(new BlackoilPropertiesFromDeck(deck, *eclipseState, ug_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(*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);
|
||||
}
|
||||
} 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 init
|
||||
state.reset( new BlackoilState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 3));
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
ensureDirectoryExists(output_dir);
|
||||
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.
|
||||
const auto& timeMap = schedule->getTimeMap();
|
||||
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 , *schedule, reportStepIdx , *grid->c_grid());
|
||||
// @@@ 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;
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/props/IncompPropertiesBasic.hpp>
|
||||
#include <opm/core/props/IncompPropertiesFromDeck.hpp>
|
||||
#include <opm/core/props/rock/RockCompressibility.hpp>
|
||||
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
|
||||
#include <opm/core/simulator/TwophaseState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/autodiff/SimulatorIncompTwophaseAd.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/simulators/ensureDirectoryExists.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <fstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
OpmLog::setupSimpleDefaultLogging(false, true, 10);
|
||||
std::cout << "\n================ Test program for incompressible two-phase flow ===============\n\n";
|
||||
ParameterGroup param(argc, argv, false);
|
||||
std::cout << "--------------- Reading parameters ---------------" << std::endl;
|
||||
|
||||
#if ! HAVE_SUITESPARSE_UMFPACK_H
|
||||
// This is an extra check to intercept a potentially invalid request for the
|
||||
// implicit transport solver as early as possible for the user.
|
||||
{
|
||||
const std::string transport_solver_type
|
||||
= param.getDefault<std::string>("transport_solver_type", "ad");
|
||||
if (transport_solver_type == "implicit") {
|
||||
OPM_THROW(std::runtime_error, "Cannot use implicit transport solver without UMFPACK. "
|
||||
"Either reconfigure opm-core with SuiteSparse/UMFPACK support and recompile, "
|
||||
"or use the reordering solver (transport_solver_type=reorder).");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// If we have a "deck_filename", grid and props will be read from that.
|
||||
bool use_deck = param.has("deck_filename");
|
||||
std::shared_ptr< EclipseState > eclipseState;
|
||||
std::shared_ptr< Schedule > schedule;
|
||||
std::unique_ptr<GridManager> grid;
|
||||
std::unique_ptr<IncompPropertiesInterface> props;
|
||||
std::unique_ptr<RockCompressibility> rock_comp;
|
||||
std::unique_ptr<TwophaseState> state;
|
||||
double gravity[3] = { 0.0 };
|
||||
if (use_deck) {
|
||||
Parser parser;
|
||||
ParseContext parseContext;
|
||||
parseContext.update(ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN);
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
auto deck = parser.parseFile(deck_filename, parseContext);
|
||||
eclipseState.reset(new EclipseState(deck, parseContext));
|
||||
schedule.reset( new Schedule(deck,
|
||||
eclipseState->getInputGrid(),
|
||||
eclipseState->get3DProperties(),
|
||||
eclipseState->runspec(),
|
||||
parseContext));
|
||||
|
||||
// Grid init
|
||||
grid.reset(new GridManager(eclipseState->getInputGrid()));
|
||||
{
|
||||
const UnstructuredGrid& ug_grid = *(grid->c_grid());
|
||||
|
||||
// Rock and fluid init
|
||||
props.reset(new IncompPropertiesFromDeck(deck, *eclipseState, ug_grid));
|
||||
|
||||
state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid )));
|
||||
// Rock compressibility.
|
||||
rock_comp.reset(new RockCompressibility(*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);
|
||||
}
|
||||
}
|
||||
} 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 IncompPropertiesBasic(param, ug_grid.dimensions, UgGridHelpers::numCells( ug_grid )));
|
||||
|
||||
state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid )));
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
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"));
|
||||
ensureDirectoryExists(output_dir);
|
||||
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.
|
||||
SimulatorIncompTwophaseAd 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 report steps etc.
|
||||
WellState well_state;
|
||||
const auto& timeMap = schedule->getTimeMap();
|
||||
SimulatorTimer simtimer;
|
||||
for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) {
|
||||
// Report on start of report step.
|
||||
std::cout << "\n\n-------------- Starting report step " << reportStepIdx << " --------------"
|
||||
<< "\n (number of steps left: "
|
||||
<< timeMap.numTimesteps() - reportStepIdx << ")\n\n" << std::flush;
|
||||
|
||||
// Create new wells, well_state
|
||||
WellsManager wells(*eclipseState , *schedule, reportStepIdx , *grid->c_grid());
|
||||
// @@@ 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);
|
||||
}
|
||||
|
||||
simtimer.setCurrentStepNum(reportStepIdx);
|
||||
|
||||
// Create and run simulator.
|
||||
SimulatorIncompTwophaseAd 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,335 +0,0 @@
|
||||
/*
|
||||
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/props/BlackoilPropertiesBasic.hpp>
|
||||
#include <opm/core/props/BlackoilPropertiesFromDeck.hpp>
|
||||
#include <opm/core/props/rock/RockCompressibility.hpp>
|
||||
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
|
||||
#include <opm/polymer/PolymerBlackoilState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/polymer/SimulatorCompressiblePolymer.hpp>
|
||||
#include <opm/polymer/PolymerInflow.hpp>
|
||||
#include <opm/polymer/PolymerProperties.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
|
||||
#include <opm/simulators/ensureDirectoryExists.hpp>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
OpmLog::setupSimpleDefaultLogging(false, true, 10);
|
||||
std::cout << "\n================ Test program for weakly compressible two-phase flow with polymer ===============\n\n";
|
||||
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;
|
||||
std::unique_ptr<PolymerBlackoilState> state;
|
||||
Opm::PolymerProperties poly_props;
|
||||
std::unique_ptr<Opm::Deck> deck;
|
||||
std::unique_ptr< EclipseState > eclipseState;
|
||||
std::unique_ptr< Schedule> schedule;
|
||||
// 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");
|
||||
Parser parser;
|
||||
Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
|
||||
deck.reset(new Deck(parser.parseFile(deck_filename , parseContext)));
|
||||
eclipseState.reset( new EclipseState(*deck , parseContext) );
|
||||
schedule.reset( new Schedule(*deck, eclipseState->getInputGrid(), eclipseState->get3DProperties(), eclipseState->runspec(), parseContext ));
|
||||
// Grid init
|
||||
grid.reset(new GridManager(eclipseState->getInputGrid()));
|
||||
{
|
||||
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(*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"));
|
||||
ensureDirectoryExists(output_dir);
|
||||
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::TimeMap 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.
|
||||
eclipseState.reset( new EclipseState( *deck ) );
|
||||
WellsManager wells(*eclipseState , *schedule, reportStepIdx , *grid->c_grid());
|
||||
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( *schedule, *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;
|
||||
}
|
||||
|
||||
@@ -1,370 +0,0 @@
|
||||
/*
|
||||
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/props/IncompPropertiesBasic.hpp>
|
||||
#include <opm/core/props/IncompPropertiesFromDeck.hpp>
|
||||
#include <opm/core/props/rock/RockCompressibility.hpp>
|
||||
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
|
||||
#include <opm/polymer/PolymerState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/polymer/SimulatorPolymer.hpp>
|
||||
#include <opm/polymer/PolymerInflow.hpp>
|
||||
#include <opm/polymer/PolymerProperties.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
|
||||
#include <opm/simulators/ensureDirectoryExists.hpp>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void warnIfUnusedParams(const Opm::ParameterGroup& param)
|
||||
{
|
||||
if (param.anyUnused()) {
|
||||
std::cout << "-------------------- Unused parameters: --------------------\n";
|
||||
param.displayUsage();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
|
||||
OpmLog::setupSimpleDefaultLogging(false, true, 10);
|
||||
std::cout << "\n================ Test program for incompressible two-phase flow with polymer ===============\n\n";
|
||||
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");
|
||||
std::unique_ptr<Deck> deck;
|
||||
boost::scoped_ptr<GridManager> grid;
|
||||
boost::scoped_ptr<IncompPropertiesInterface> props;
|
||||
boost::scoped_ptr<RockCompressibility> rock_comp;
|
||||
std::shared_ptr< EclipseState > eclipseState;
|
||||
std::shared_ptr<Schedule> schedule;
|
||||
std::unique_ptr<PolymerState> 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");
|
||||
Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
|
||||
Parser parser;
|
||||
deck.reset(new Deck(parser.parseFile(deck_filename , parseContext)));
|
||||
|
||||
eclipseState.reset(new Opm::EclipseState(*deck , parseContext));
|
||||
schedule.reset( new Opm::Schedule(*deck, eclipseState->getInputGrid(), eclipseState->get3DProperties(), eclipseState->runspec(), parseContext));
|
||||
// Grid init
|
||||
grid.reset(new GridManager(eclipseState->getInputGrid()));
|
||||
{
|
||||
const UnstructuredGrid& ug_grid = *(grid->c_grid());
|
||||
// Rock and fluid init
|
||||
props.reset(new IncompPropertiesFromDeck(*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 PolymerState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 2));
|
||||
|
||||
// Rock compressibility.
|
||||
rock_comp.reset(new RockCompressibility(*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);
|
||||
}
|
||||
// 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 IncompPropertiesBasic(param, ug_grid.dimensions, UgGridHelpers::numCells( ug_grid )));;
|
||||
state.reset( new PolymerState( 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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
|
||||
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);
|
||||
if (output) {
|
||||
std::string output_dir =
|
||||
param.getDefault("output_dir", std::string("output"));
|
||||
ensureDirectoryExists(output_dir);
|
||||
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;
|
||||
SimulatorPolymer simulator(param,
|
||||
*grid->c_grid(),
|
||||
*props,
|
||||
poly_props,
|
||||
rock_comp->isActive() ? rock_comp.get() : 0,
|
||||
wells,
|
||||
polymer_inflow,
|
||||
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;
|
||||
const auto& timeMap = schedule->getTimeMap();
|
||||
SimulatorTimer simtimer;
|
||||
simtimer.init(timeMap);
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
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 , *schedule, reportStepIdx , *grid->c_grid());
|
||||
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(*schedule, *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.
|
||||
SimulatorPolymer simulator(param,
|
||||
*grid->c_grid(),
|
||||
*props,
|
||||
poly_props,
|
||||
rock_comp->isActive() ? rock_comp.get() : 0,
|
||||
wells,
|
||||
*polymer_inflow,
|
||||
src,
|
||||
bcs.c_bcs(),
|
||||
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;
|
||||
}
|
||||
@@ -1,311 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <opm/autodiff/AutoDiffBlock.hpp>
|
||||
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/props/IncompPropertiesBasic.hpp>
|
||||
#include <opm/parser/eclipse/Units/Units.hpp>
|
||||
#include <opm/grid/utility/StopWatch.hpp>
|
||||
#include <opm/grid/transmissibility/trans_tpfa.h>
|
||||
|
||||
#include <opm/common/utility/platform_dependent/disable_warnings.h>
|
||||
#if HAVE_SUITESPARSE_UMFPACK_H
|
||||
#include <Eigen/UmfPackSupport>
|
||||
#else
|
||||
#include <Eigen/IterativeLinearSolvers>
|
||||
#endif
|
||||
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
/*
|
||||
Equations for incompressible two-phase flow.
|
||||
|
||||
Using s and p as variables:
|
||||
|
||||
PV (s_i - s0_i) / dt + sum_{j \in U(i)} f(s_j) v_{ij} + sum_{j in D(i) f(s_i) v_{ij} = qw_i
|
||||
|
||||
where
|
||||
|
||||
v_{ij} = totmob_ij T_ij (p_i - p_j)
|
||||
|
||||
|
||||
Pressure equation:
|
||||
|
||||
sum_{j \in N(i)} totmob_ij T_ij (p_i - p_j) = q_i
|
||||
|
||||
*/
|
||||
|
||||
|
||||
template <class ADB>
|
||||
std::vector<ADB>
|
||||
phaseMobility(const Opm::IncompPropertiesInterface& props,
|
||||
const std::vector<int>& cells,
|
||||
const typename ADB::V& sw)
|
||||
{
|
||||
typedef Eigen::Array<double, Eigen::Dynamic, 2, Eigen::RowMajor> TwoCol;
|
||||
typedef Eigen::Array<double, Eigen::Dynamic, 4, Eigen::RowMajor> FourCol;
|
||||
typedef Eigen::SparseMatrix<double> S;
|
||||
typedef typename ADB::V V;
|
||||
typedef typename ADB::M M;
|
||||
const int nc = props.numCells();
|
||||
TwoCol s(nc, 2);
|
||||
s.leftCols<1>() = sw;
|
||||
s.rightCols<1>() = 1.0 - s.leftCols<1>();
|
||||
TwoCol kr(nc, 2);
|
||||
FourCol dkr(nc, 4);
|
||||
props.relperm(nc, s.data(), cells.data(), kr.data(), dkr.data());
|
||||
V krw = kr.leftCols<1>();
|
||||
V kro = kr.rightCols<1>();
|
||||
V dkrw = dkr.leftCols<1>(); // Left column is top-left of dkr/ds 2x2 matrix.
|
||||
V dkro = -dkr.rightCols<1>(); // Right column is bottom-right of dkr/ds 2x2 matrix.
|
||||
S krwjac(nc,nc);
|
||||
S krojac(nc,nc);
|
||||
auto sizes = Eigen::ArrayXi::Ones(nc);
|
||||
krwjac.reserve(sizes);
|
||||
krojac.reserve(sizes);
|
||||
for (int c = 0; c < nc; ++c) {
|
||||
krwjac.insert(c,c) = dkrw(c);
|
||||
krojac.insert(c,c) = dkro(c);
|
||||
}
|
||||
const double* mu = props.viscosity();
|
||||
std::vector<M> dmw = { M(krwjac)/mu[0] };
|
||||
std::vector<M> dmo = { M(krojac)/mu[1] };
|
||||
|
||||
std::vector<ADB> pmobc = { ADB::function(krw / mu[0], std::move(dmw)) ,
|
||||
ADB::function(kro / mu[1], std::move(dmo)) };
|
||||
return pmobc;
|
||||
}
|
||||
|
||||
/// Returns fw(sw).
|
||||
template <class ADB>
|
||||
ADB
|
||||
fluxFunc(const std::vector<ADB>& m)
|
||||
{
|
||||
assert (m.size() == 2);
|
||||
|
||||
ADB f = m[0] / (m[0] + m[1]);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
try
|
||||
{
|
||||
typedef Opm::AutoDiffBlock<double> ADB;
|
||||
typedef ADB::V V;
|
||||
typedef Eigen::SparseMatrix<double> S;
|
||||
|
||||
Opm::time::StopWatch clock;
|
||||
clock.start();
|
||||
const Opm::GridManager gm(3,3);//(50, 50, 10);
|
||||
const UnstructuredGrid& grid = *gm.c_grid();
|
||||
using namespace Opm::unit;
|
||||
using namespace Opm::prefix;
|
||||
// const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
|
||||
// { 1000.0, 800.0 },
|
||||
// { 1.0*centi*Poise, 5.0*centi*Poise },
|
||||
// 0.2, 100*milli*darcy,
|
||||
// grid.dimensions, grid.number_of_cells);
|
||||
// const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
|
||||
// { 1000.0, 1000.0 },
|
||||
// { 1.0, 1.0 },
|
||||
// 1.0, 1.0,
|
||||
// grid.dimensions, grid.number_of_cells);
|
||||
const Opm::IncompPropertiesBasic props(2, Opm::SaturationPropsBasic::Linear,
|
||||
{ 1000.0, 1000.0 },
|
||||
{ 1.0, 30.0 },
|
||||
1.0, 1.0,
|
||||
grid.dimensions, grid.number_of_cells);
|
||||
V htrans(grid.cell_facepos[grid.number_of_cells]);
|
||||
tpfa_htrans_compute(const_cast<UnstructuredGrid*>(&grid), props.permeability(), htrans.data());
|
||||
V trans_all(grid.number_of_faces);
|
||||
// tpfa_trans_compute(const_cast<UnstructuredGrid*>(&grid), htrans.data(), trans_all.data());
|
||||
const int nc = grid.number_of_cells;
|
||||
std::vector<int> allcells(nc);
|
||||
for (int i = 0; i < nc; ++i) {
|
||||
allcells[i] = i;
|
||||
}
|
||||
std::cerr << "Opm core " << clock.secsSinceLast() << std::endl;
|
||||
|
||||
// Define neighbourhood-derived operator matrices.
|
||||
const Opm::HelperOps ops(grid);
|
||||
const int num_internal = ops.internal_faces.size();
|
||||
std::cerr << "Topology matrices " << clock.secsSinceLast() << std::endl;
|
||||
|
||||
typedef Opm::AutoDiffBlock<double> ADB;
|
||||
typedef ADB::V V;
|
||||
|
||||
// q
|
||||
V q(nc);
|
||||
q.setZero();
|
||||
q[0] = 1.0;
|
||||
q[nc-1] = -1.0;
|
||||
|
||||
// s0 - this is explicit now
|
||||
typedef Eigen::Array<double, Eigen::Dynamic, 2, Eigen::RowMajor> TwoCol;
|
||||
TwoCol s0(nc, 2);
|
||||
s0.leftCols<1>().setZero();
|
||||
s0.rightCols<1>().setOnes();
|
||||
|
||||
// totmob - explicit as well
|
||||
TwoCol kr(nc, 2);
|
||||
props.relperm(nc, s0.data(), allcells.data(), kr.data(), 0);
|
||||
const V krw = kr.leftCols<1>();
|
||||
const V kro = kr.rightCols<1>();
|
||||
const double* mu = props.viscosity();
|
||||
const V totmob = krw/mu[0] + kro/mu[1];
|
||||
|
||||
// Moved down here because we need total mobility.
|
||||
tpfa_eff_trans_compute(const_cast<UnstructuredGrid*>(&grid), totmob.data(),
|
||||
htrans.data(), trans_all.data());
|
||||
// Still explicit, and no upwinding!
|
||||
V mobtransf(num_internal);
|
||||
for (int fi = 0; fi < num_internal; ++fi) {
|
||||
mobtransf[fi] = trans_all[ops.internal_faces[fi]];
|
||||
}
|
||||
std::cerr << "Property arrays " << clock.secsSinceLast() << std::endl;
|
||||
|
||||
// Initial pressure.
|
||||
V p0(nc,1);
|
||||
p0.fill(200*Opm::unit::barsa);
|
||||
|
||||
// First actual AD usage: defining pressure variable.
|
||||
const std::vector<int> bpat = { nc };
|
||||
// Could actually write { nc } instead of bpat below,
|
||||
// but we prefer a named variable since we will repeat it.
|
||||
const ADB p = ADB::variable(0, p0, bpat);
|
||||
const ADB ngradp = ops.ngrad*p;
|
||||
// We want flux = totmob*trans*(p_i - p_j) for the ij-face.
|
||||
const ADB flux = mobtransf*ngradp;
|
||||
const ADB residual = ops.div*flux - q;
|
||||
std::cerr << "Construct AD residual " << clock.secsSinceLast() << std::endl;
|
||||
|
||||
// It's the residual we want to be zero. We know it's linear in p,
|
||||
// so we just need a single linear solve. Since we have formulated
|
||||
// ourselves with a residual and jacobian we do this with a single
|
||||
// Newton step (hopefully easy to extend later):
|
||||
// p = p0 - J(p0) \ R(p0)
|
||||
// Where R(p0) and J(p0) are contained in residual.value() and
|
||||
// residual.derived()[0].
|
||||
|
||||
#if HAVE_SUITESPARSE_UMFPACK_H
|
||||
typedef Eigen::UmfPackLU<S> LinSolver;
|
||||
#else
|
||||
typedef Eigen::BiCGSTAB<S> LinSolver;
|
||||
#endif // HAVE_SUITESPARSE_UMFPACK_H
|
||||
|
||||
LinSolver solver;
|
||||
S pmatr;
|
||||
residual.derivative()[0].toSparse(pmatr);
|
||||
pmatr.coeffRef(0,0) *= 2.0;
|
||||
pmatr.makeCompressed();
|
||||
solver.compute(pmatr);
|
||||
if (solver.info() != Eigen::Success) {
|
||||
std::cerr << "Pressure/flow Jacobian decomposition error\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// const Eigen::VectorXd dp = solver.solve(residual.value().matrix());
|
||||
ADB::V residual_v = residual.value();
|
||||
const V dp = solver.solve(residual_v.matrix()).array();
|
||||
if (solver.info() != Eigen::Success) {
|
||||
std::cerr << "Pressure/flow solve failure\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const V p1 = p0 - dp;
|
||||
std::cerr << "Solve " << clock.secsSinceLast() << std::endl;
|
||||
// std::cout << p1 << std::endl;
|
||||
|
||||
// ------ Transport solve ------
|
||||
|
||||
// Now we'll try to do a transport step as well.
|
||||
// Residual formula is
|
||||
// R_w = s_w - s_w^0 + dt/pv * (div v_w)
|
||||
// where
|
||||
// v_w = f_w v
|
||||
// and f_w is (for now) based on averaged mobilities, not upwind.
|
||||
|
||||
double res_norm = 1e100;
|
||||
const V sw0 = s0.leftCols<1>();
|
||||
// V sw1 = sw0;
|
||||
V sw1 = 0.5*V::Ones(nc,1);
|
||||
const V ndp = (ops.ngrad * p1.matrix()).array();
|
||||
const V dflux = mobtransf * ndp;
|
||||
const Opm::UpwindSelector<double> upwind(grid, ops, dflux);
|
||||
const V pv = Eigen::Map<const V>(props.porosity(), nc, 1)
|
||||
* Eigen::Map<const V>(grid.cell_volumes, nc, 1);
|
||||
const double dt = 0.0005;
|
||||
const V dtpv = dt/pv;
|
||||
const V qneg = q.min(V::Zero(nc,1));
|
||||
const V qpos = q.max(V::Zero(nc,1));
|
||||
|
||||
std::cout.setf(std::ios::scientific);
|
||||
std::cout.precision(16);
|
||||
|
||||
int it = 0;
|
||||
do {
|
||||
const ADB sw = ADB::variable(0, sw1, bpat);
|
||||
const std::vector<ADB> pmobc = phaseMobility<ADB>(props, allcells, sw.value());
|
||||
const std::vector<ADB> pmobf = upwind.select(pmobc);
|
||||
const ADB fw_cell = fluxFunc(pmobc);
|
||||
const ADB fw_face = fluxFunc(pmobf);
|
||||
const ADB flux1 = fw_face * dflux;
|
||||
const ADB qtr_ad = qpos + fw_cell*qneg;
|
||||
const ADB transport_residual = sw - sw0 + dtpv*(ops.div*flux1 - qtr_ad);
|
||||
res_norm = transport_residual.value().matrix().norm();
|
||||
std::cout << "res_norm[" << it << "] = "
|
||||
<< res_norm << std::endl;
|
||||
|
||||
S smatr;
|
||||
transport_residual.derivative()[0].toSparse(smatr);
|
||||
smatr.makeCompressed();
|
||||
solver.compute(smatr);
|
||||
if (solver.info() != Eigen::Success) {
|
||||
std::cerr << "Transport Jacobian decomposition error\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ADB::V transport_residual_v = transport_residual.value();
|
||||
const V ds = solver.solve(transport_residual_v.matrix()).array();
|
||||
if (solver.info() != Eigen::Success) {
|
||||
std::cerr << "Transport solve failure\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
sw1 = sw.value() - ds;
|
||||
std::cerr << "Solve for s[" << it << "]: "
|
||||
<< clock.secsSinceLast() << '\n';
|
||||
sw1 = sw1.min(V::Ones(nc,1)).max(V::Zero(nc,1));
|
||||
|
||||
it += 1;
|
||||
} while (res_norm > 1e-7);
|
||||
|
||||
std::cout << "Saturation solution:\n"
|
||||
<< "function s1 = solution\n"
|
||||
<< "s1 = [\n" << sw1 << "\n];\n";
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/grid/GridManager.hpp>
|
||||
#include <opm/core/pressure/IncompTpfa.hpp>
|
||||
#include <opm/core/props/IncompPropertiesFromDeck.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/grid/UnstructuredGrid.h>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/core/simulator/TwophaseState.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
||||
#include <opm/core/props/rock/RockCompressibility.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
try
|
||||
{
|
||||
using namespace Opm;
|
||||
ParameterGroup parameters(argc, argv, false);
|
||||
std::string file_name = parameters.getDefault<std::string > ("inputdeck", "data.data");
|
||||
|
||||
SimulatorTimer simtimer;
|
||||
simtimer.init(parameters);
|
||||
|
||||
// Read input file
|
||||
ParseContext parseContext;
|
||||
Opm::Parser parser;
|
||||
Opm::Deck deck = parser.parseFile(file_name , parseContext);
|
||||
Opm::EclipseState eclipseState(deck , parseContext);
|
||||
Opm::Schedule schedule(deck, eclipseState.getInputGrid(), eclipseState.get3DProperties(), eclipseState.runspec(), parseContext);
|
||||
std::cout << "Done!" << std::endl;
|
||||
|
||||
// Setup grid
|
||||
GridManager grid(eclipseState.getInputGrid());
|
||||
|
||||
// Define rock and fluid properties
|
||||
IncompPropertiesFromDeck incomp_properties(deck, eclipseState, *grid.c_grid());
|
||||
RockCompressibility rock_comp(eclipseState);
|
||||
|
||||
// Finally handle the wells
|
||||
WellsManager wells(eclipseState , schedule, 0 , *grid.c_grid());
|
||||
|
||||
double gravity[3] = {0.0, 0.0, parameters.getDefault<double>("gravity", 0.0)};
|
||||
Opm::LinearSolverFactory linsolver(parameters);
|
||||
double nl_pressure_residual_tolerance = 1e-8;
|
||||
double nl_pressure_change_tolerance = 0.0;
|
||||
int nl_pressure_maxiter = 100;
|
||||
if (rock_comp.isActive()) {
|
||||
nl_pressure_residual_tolerance = parameters.getDefault("nl_pressure_residual_tolerance", 1e-8);
|
||||
nl_pressure_change_tolerance = parameters.getDefault("nl_pressure_change_tolerance", 1.0); // in Pascal
|
||||
nl_pressure_maxiter = parameters.getDefault("nl_pressure_maxiter", 10);
|
||||
}
|
||||
|
||||
std::vector<double> src;
|
||||
Opm::FlowBCManager bcs;
|
||||
|
||||
// EXPERIMENT_ISTL
|
||||
IncompTpfa pressure_solver(*grid.c_grid(), incomp_properties, &rock_comp, linsolver,
|
||||
nl_pressure_residual_tolerance, nl_pressure_change_tolerance, nl_pressure_maxiter,
|
||||
gravity, wells.c_wells(), src, bcs.c_bcs());
|
||||
|
||||
|
||||
std::vector<int> all_cells;
|
||||
for (int i = 0; i < grid.c_grid()->number_of_cells; i++) {
|
||||
all_cells.push_back(i);
|
||||
}
|
||||
|
||||
Opm::TwophaseState state( grid.c_grid()->number_of_cells , grid.c_grid()->number_of_faces );
|
||||
|
||||
initStateFromDeck(*grid.c_grid(), incomp_properties, deck, gravity[2], state);
|
||||
|
||||
Opm::WellState well_state;
|
||||
well_state.init(wells.c_wells(), state);
|
||||
|
||||
pressure_solver.solve(simtimer.currentStepLength(), state, well_state);
|
||||
|
||||
const int np = incomp_properties.numPhases();
|
||||
std::vector<double> fractional_flows(grid.c_grid()->number_of_cells*np, 0.0);
|
||||
computeFractionalFlow(incomp_properties, all_cells, state.saturation(), fractional_flows);
|
||||
|
||||
// This will be refactored into a separate function once done
|
||||
std::vector<double> well_resflows(wells.c_wells()->number_of_wells*np, 0.0);
|
||||
computePhaseFlowRatesPerWell(*wells.c_wells(), well_state.perfRates(), fractional_flows, well_resflows);
|
||||
// We approximate (for _testing_ that resflows = surfaceflows)
|
||||
for (int wc_iter = 0; wc_iter < 10 && !wells.conditionsMet(well_state.bhp(), well_resflows, well_resflows); ++wc_iter) {
|
||||
std::cout << "Conditions not met for well, trying again" << std::endl;
|
||||
pressure_solver.solve(simtimer.currentStepLength(), state, well_state);
|
||||
std::cout << "Solved" << std::endl;
|
||||
|
||||
computePhaseFlowRatesPerWell(*wells.c_wells(), well_state.perfRates(), fractional_flows, well_resflows);
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::vector<double> porevol;
|
||||
computePorevolume(*grid->c_grid(), incomp_properties, porevol);
|
||||
|
||||
|
||||
|
||||
TwophaseFluid fluid(incomp_properties);
|
||||
TransportContextl model(fluid, *grid->c_grid(), porevol, gravity[2], true);
|
||||
|
||||
TransportSolver tsolver(model);
|
||||
|
||||
TransportSource* tsrc = create_transport_source(2, 2);
|
||||
double ssrc[] = {1.0, 0.0};
|
||||
double ssink[] = {0.0, 1.0};
|
||||
double zdummy[] = {0.0, 0.0};
|
||||
|
||||
{
|
||||
int well_cell_index = 0;
|
||||
for (int well = 0; well < wells.c_wells()->number_of_wells; ++well) {
|
||||
for (int cell = wells.c_wells()->well_connpos[well]; cell < wells.c_wells()->well_connpos[well + 1]; ++cell) {
|
||||
if (well_rate_per_cell[well_cell_index] > 0.0) {
|
||||
append_transport_source(well_cell_index, 2, 0,
|
||||
well_rate_per_cell[well_cell_index], ssrc, zdummy, tsrc);
|
||||
} else if (well_rate_per_cell[well_cell_index] < 0.0) {
|
||||
append_transport_source(well_cell_index, 2, 0,
|
||||
well_rate_per_cell[well_cell_index], ssink, zdummy, tsrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tsolver.solve(*grid->c_grid(), tsrc, stepsize, ctrl, state, linsolve, rpt);
|
||||
|
||||
Opm::computeInjectedProduced(*props, state.saturation(), src, stepsize, injected, produced);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
throw;
|
||||
}
|
||||
Reference in New Issue
Block a user