mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-25 10:40:21 -06:00
Merge pull request #91 from OPM/opm-parser-integrate
Opm parser integrate
This commit is contained in:
commit
c7efc85568
@ -25,6 +25,8 @@ find_path (OPM_MACROS_ROOT cmake/Modules/OpmInit.cmake
|
||||
)
|
||||
list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules")
|
||||
|
||||
option( INCLUDE_NON_PUBLIC_TESTS "Include the tests which need non-public data" OFF)
|
||||
|
||||
# not the same location as most of the other projects? this hook overrides
|
||||
macro (dir_hook)
|
||||
endmacro (dir_hook)
|
||||
|
@ -49,10 +49,27 @@ list (APPEND TEST_SOURCE_FILES
|
||||
tests/test_welldensitysegmented.cpp
|
||||
)
|
||||
|
||||
if (INCLUDE_NON_PUBLIC_TESTS)
|
||||
list (APPEND TEST_SOURCE_FILES
|
||||
tests/integration_tests/sim_fibo_ad_test.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
list (APPEND TEST_DATA_FILES
|
||||
tests/fluid.data
|
||||
)
|
||||
|
||||
# Note, these two files are not included in the repo.
|
||||
# If enabling INCLUDE_NON_PUBLIC_TESTS, please add add symlink to the folder
|
||||
# "non_public" containing these two files.
|
||||
if (INCLUDE_NON_PUBLIC_TESTS)
|
||||
list (APPEND TEST_DATA_FILES
|
||||
tests/non_public/SPE1_opm.DATA
|
||||
tests/non_public/spe1.xml
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
# originally generated with the command:
|
||||
# find tutorials examples -name '*.c*' -printf '\t%p\n' | sort
|
||||
list (APPEND EXAMPLE_SOURCE_FILES
|
||||
|
@ -5,9 +5,9 @@
|
||||
#
|
||||
# If found, it sets these variables:
|
||||
#
|
||||
# HAVE_OPM_PARSER Defined if a test program compiled
|
||||
# OPM_PARSER_INCLUDE_DIRS Header file directories
|
||||
# OPM_PARSER_LIBRARIES Archives and shared objects
|
||||
# HAVE_OPM_PARSER Defined if a test program compiled
|
||||
# OPM_PARSER_INCLUDE_DIRS Header file directories
|
||||
# OPM_PARSER_LIBRARIES Archives and shared objects
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
@ -61,18 +61,18 @@ find_path (OPM_PARSER_INCLUDE_DIR
|
||||
# then it is probably a build directory; read the CMake cache of
|
||||
# opm-parser to figure out where the source directory is
|
||||
if ((NOT OPM_PARSER_INCLUDE_DIR) AND
|
||||
(OPM_PARSER_ROOT AND (EXISTS "${OPM_PARSER_ROOT}/CMakeCache.txt")))
|
||||
(OPM_PARSER_ROOT AND (EXISTS "${OPM_PARSER_ROOT}/CMakeCache.txt")))
|
||||
set (_regex "^OPMParser_SOURCE_DIR:STATIC=\(.*\)$")
|
||||
file (STRINGS
|
||||
"${OPM_PARSER_ROOT}/CMakeCache.txt"
|
||||
_cache_entry
|
||||
REGEX "${_regex}")
|
||||
"${OPM_PARSER_ROOT}/CMakeCache.txt"
|
||||
_cache_entry
|
||||
REGEX "${_regex}")
|
||||
string(REGEX REPLACE "${_regex}" "\\1"
|
||||
OPM_PARSER_INCLUDE_DIR
|
||||
"${_cache_entry}")
|
||||
OPM_PARSER_INCLUDE_DIR
|
||||
"${_cache_entry}")
|
||||
if (OPM_PARSER_INCLUDE_DIR)
|
||||
set (OPM_PARSER_INCLUDE_DIR "${OPM_PARSER_INCLUDE_DIR}"
|
||||
CACHE PATH "Path to OPM parser header files" FORCE)
|
||||
set (OPM_PARSER_INCLUDE_DIR "${OPM_PARSER_INCLUDE_DIR}"
|
||||
CACHE PATH "Path to OPM parser header files" FORCE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
@ -109,14 +109,16 @@ endif ()
|
||||
# get the prerequisite Boost libraries
|
||||
if (NOT Boost_FOUND)
|
||||
find_package(Boost 1.44.0
|
||||
COMPONENTS filesystem date_time system unit_test_framework REQUIRED ${OPM_PARSER_QUIET})
|
||||
COMPONENTS filesystem date_time system unit_test_framework REQUIRED ${OPM_PARSER_QUIET})
|
||||
endif ()
|
||||
|
||||
# setup list of all required libraries to link with opm-parser. notice that
|
||||
# we use the plural form to get *all* the libraries needed by cjson
|
||||
set (OPM_PARSER_INCLUDE_DIRS
|
||||
${OPM_PARSER_INCLUDE_DIR}
|
||||
${CJSON_INCLUDE_DIRS}
|
||||
${Boost_INCLUDE_DIRS})
|
||||
|
||||
set (OPM_PARSER_LIBRARIES
|
||||
${OPM_PARSER_LIBRARY}
|
||||
${OPM_JSON_LIBRARY}
|
||||
@ -126,7 +128,7 @@ set (OPM_PARSER_LIBRARIES
|
||||
# see if we can compile a minimum example
|
||||
# CMake logical test doesn't handle lists (sic)
|
||||
if (NOT (OPM_PARSER_INCLUDE_DIR MATCHES "-NOTFOUND"
|
||||
OR OPM_PARSER_LIBRARIES MATCHES "-NOTFOUND"))
|
||||
OR OPM_PARSER_LIBRARIES MATCHES "-NOTFOUND"))
|
||||
include (CMakePushCheckState)
|
||||
include (CheckCSourceCompiles)
|
||||
cmake_push_check_state ()
|
||||
|
@ -3,21 +3,21 @@
|
||||
|
||||
# defines that must be present in config.h for our headers
|
||||
set (opm-autodiff_CONFIG_VAR
|
||||
)
|
||||
)
|
||||
|
||||
# dependencies
|
||||
set (opm-autodiff_DEPS
|
||||
# Compile with C99 support if available
|
||||
"C99"
|
||||
# Compile with C++0x/11 support if available
|
||||
"CXX11Features"
|
||||
# Various runtime library enhancements
|
||||
"Boost 1.39.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
# DUNE prerequisites
|
||||
"dune-common REQUIRED;
|
||||
dune-istl REQUIRED;
|
||||
opm-core REQUIRED"
|
||||
# Eigen
|
||||
"Eigen3 3.1.2 "
|
||||
)
|
||||
# Compile with C99 support if available
|
||||
"C99"
|
||||
# Compile with C++0x/11 support if available
|
||||
"CXX11Features"
|
||||
# Various runtime library enhancements
|
||||
"Boost 1.44.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
# DUNE prerequisites
|
||||
"dune-common REQUIRED;
|
||||
dune-istl REQUIRED;
|
||||
opm-core REQUIRED"
|
||||
# Eigen
|
||||
"Eigen3 3.1.2 REQUIRED"
|
||||
)
|
||||
|
@ -3,31 +3,33 @@
|
||||
|
||||
# defines that must be present in config.h for our headers
|
||||
set (opm-core_CONFIG_VAR
|
||||
HAVE_ERT
|
||||
HAVE_SUITESPARSE_UMFPACK_H
|
||||
)
|
||||
HAVE_ERT
|
||||
HAVE_SUITESPARSE_UMFPACK_H
|
||||
)
|
||||
|
||||
# dependencies
|
||||
set (opm-core_DEPS
|
||||
# compile with C99 support if available
|
||||
"C99"
|
||||
# compile with C++0x/11 support if available
|
||||
"CXX11Features REQUIRED"
|
||||
# various runtime library enhancements
|
||||
"Boost 1.39.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
# matrix library
|
||||
"BLAS REQUIRED"
|
||||
"LAPACK REQUIRED"
|
||||
# Tim Davis' SuiteSparse archive
|
||||
"SuiteSparse COMPONENTS umfpack"
|
||||
# solver
|
||||
"SuperLU"
|
||||
# xml processing (for config parsing)
|
||||
"TinyXML"
|
||||
# Ensembles-based Reservoir Tools (ERT)
|
||||
"ERT"
|
||||
# DUNE dependency
|
||||
"dune-common"
|
||||
"dune-istl"
|
||||
)
|
||||
# compile with C99 support if available
|
||||
"C99"
|
||||
# compile with C++0x/11 support if available
|
||||
"CXX11Features REQUIRED"
|
||||
# various runtime library enhancements
|
||||
"Boost 1.44.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
# matrix library
|
||||
"BLAS REQUIRED"
|
||||
"LAPACK REQUIRED"
|
||||
# Tim Davis' SuiteSparse archive
|
||||
"SuiteSparse COMPONENTS umfpack"
|
||||
# solver
|
||||
"SuperLU"
|
||||
# xml processing (for config parsing)
|
||||
"TinyXML"
|
||||
#Parser library
|
||||
"opm-parser REQUIRED"
|
||||
# Ensembles-based Reservoir Tools (ERT)
|
||||
"ERT"
|
||||
# DUNE dependency
|
||||
"dune-common"
|
||||
"dune-istl"
|
||||
)
|
||||
|
@ -13,6 +13,6 @@ set (opm-parser_DEPS
|
||||
# compile with C++0x/11 support if available
|
||||
"CXX11Features REQUIRED"
|
||||
# various runtime library enhancements
|
||||
"Boost 1.39.0
|
||||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
"Boost 1.44.0 COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
|
||||
"cJSON"
|
||||
)
|
||||
|
@ -46,6 +46,9 @@
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/autodiff/SimulatorCompressibleAd.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@ -98,14 +101,17 @@ try
|
||||
if (use_deck) {
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
deck.reset(new EclipseGridParser(deck_filename));
|
||||
Opm::ParserPtr newParser(new Opm::Parser() );
|
||||
Opm::DeckConstPtr newParserDeck = newParser->parseFile( deck_filename );
|
||||
|
||||
// Grid init
|
||||
grid.reset(new GridManager(*deck));
|
||||
grid.reset(new GridManager(newParserDeck));
|
||||
// Rock and fluid init
|
||||
props.reset(new BlackoilPropertiesFromDeck(*deck, *grid->c_grid(), param));
|
||||
props.reset(new BlackoilPropertiesFromDeck(newParserDeck, *grid->c_grid(), param));
|
||||
// check_well_controls = param.getDefault("check_well_controls", false);
|
||||
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
|
||||
// Rock compressibility.
|
||||
rock_comp.reset(new RockCompressibility(*deck));
|
||||
rock_comp.reset(new RockCompressibility(newParserDeck));
|
||||
// Gravity.
|
||||
gravity[2] = deck->hasField("NOGRAV") ? 0.0 : unit::gravity;
|
||||
// Init state variables (saturation and pressure).
|
||||
|
@ -16,11 +16,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <opm/core/pressure/FlowBCManager.hpp>
|
||||
|
||||
@ -49,10 +45,13 @@
|
||||
#include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
|
||||
#include <opm/core/utility/share_obj.hpp>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
@ -90,30 +89,66 @@ try
|
||||
OPM_THROW(std::runtime_error, "This program must be run with an input deck. "
|
||||
"Specify the deck with deck_filename=deckname.data (for example).");
|
||||
}
|
||||
boost::scoped_ptr<EclipseGridParser> deck;
|
||||
boost::scoped_ptr<GridManager> grid;
|
||||
boost::scoped_ptr<BlackoilPropertiesInterface> props;
|
||||
boost::scoped_ptr<BlackoilPropsAdInterface> new_props;
|
||||
boost::scoped_ptr<RockCompressibility> rock_comp;
|
||||
std::shared_ptr<GridManager> grid;
|
||||
std::shared_ptr<BlackoilPropertiesInterface> props;
|
||||
std::shared_ptr<BlackoilPropsAdInterface> new_props;
|
||||
std::shared_ptr<RockCompressibility> rock_comp;
|
||||
BlackoilState state;
|
||||
// bool check_well_controls = false;
|
||||
// int max_well_control_iterations = 0;
|
||||
double gravity[3] = { 0.0 };
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
deck.reset(new EclipseGridParser(deck_filename));
|
||||
// Grid init
|
||||
grid.reset(new GridManager(*deck));
|
||||
|
||||
Opm::EclipseWriter outputWriter(param, share_obj(*deck), share_obj(*grid->c_grid()));
|
||||
#define USE_NEW_PARSER 1
|
||||
#if USE_NEW_PARSER
|
||||
Opm::ParserPtr newParser(new Opm::Parser() );
|
||||
Opm::DeckConstPtr newParserDeck = newParser->parseFile( deck_filename );
|
||||
|
||||
#warning "HACK: required until the WellsManager and the EclipseWriter don't require the old parser anymore"
|
||||
std::shared_ptr<EclipseGridParser> deck;
|
||||
deck.reset(new EclipseGridParser(deck_filename));
|
||||
#else
|
||||
std::shared_ptr<EclipseGridParser> deck;
|
||||
deck.reset(new EclipseGridParser(deck_filename));
|
||||
#endif
|
||||
|
||||
// Grid init
|
||||
#if USE_NEW_PARSER
|
||||
grid.reset(new GridManager(newParserDeck));
|
||||
#else
|
||||
grid.reset(new GridManager(*deck));
|
||||
#endif
|
||||
|
||||
#warning "HACK: required until the WellsManager and the EclipseWriter don't require the old parser anymore"
|
||||
#if 0 // USE_NEW_PARSER
|
||||
Opm::EclipseWriter outputWriter(param, newParserDeck, share_obj(*grid->c_grid()));
|
||||
#else
|
||||
Opm::EclipseWriter outputWriter(param, deck, share_obj(*grid->c_grid()));
|
||||
#endif
|
||||
|
||||
// Rock and fluid init
|
||||
#if USE_NEW_PARSER
|
||||
props.reset(new BlackoilPropertiesFromDeck(newParserDeck, *grid->c_grid(), param));
|
||||
new_props.reset(new BlackoilPropsAdFromDeck(newParserDeck, *grid->c_grid()));
|
||||
#else
|
||||
props.reset(new BlackoilPropertiesFromDeck(*deck, *grid->c_grid(), param));
|
||||
new_props.reset(new BlackoilPropsAdFromDeck(*deck, *grid->c_grid()));
|
||||
#endif
|
||||
|
||||
// check_well_controls = param.getDefault("check_well_controls", false);
|
||||
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
|
||||
// Rock compressibility.
|
||||
#if USE_NEW_PARSER
|
||||
rock_comp.reset(new RockCompressibility(newParserDeck));
|
||||
#else
|
||||
rock_comp.reset(new RockCompressibility(*deck));
|
||||
#endif
|
||||
// Gravity.
|
||||
#if USE_NEW_PARSER
|
||||
gravity[2] = newParserDeck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
|
||||
#else
|
||||
gravity[2] = deck->hasField("NOGRAV") ? 0.0 : unit::gravity;
|
||||
#endif
|
||||
// Init state variables (saturation and pressure).
|
||||
if (param.has("init_saturation")) {
|
||||
initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
|
||||
@ -129,7 +164,11 @@ try
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#if USE_NEW_PARSER
|
||||
initBlackoilStateFromDeck(*grid->c_grid(), *props, newParserDeck, gravity[2], state);
|
||||
#else
|
||||
initBlackoilStateFromDeck(*grid->c_grid(), *props, *deck, gravity[2], state);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
|
||||
@ -140,7 +179,7 @@ try
|
||||
|
||||
// Write parameters used for later reference.
|
||||
bool output = param.getDefault("output", true);
|
||||
std::ofstream epoch_os;
|
||||
std::ofstream outStream;
|
||||
std::string output_dir;
|
||||
if (output) {
|
||||
output_dir =
|
||||
@ -152,8 +191,8 @@ try
|
||||
catch (...) {
|
||||
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
|
||||
}
|
||||
std::string filename = output_dir + "/epoch_timing.param";
|
||||
epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out);
|
||||
std::string filename = output_dir + "/timing.param";
|
||||
outStream.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);
|
||||
@ -161,7 +200,48 @@ try
|
||||
param.writeParam(output_dir + "/simulation.param");
|
||||
}
|
||||
|
||||
#warning "TODO: convert the well handling code to the new parser"
|
||||
#if USE_NEW_PARSER
|
||||
std::cout << "\n\n================ Starting main simulation loop ===============\n"
|
||||
<< std::flush;
|
||||
|
||||
WellState well_state;
|
||||
Opm::TimeMapPtr timeMap(new Opm::TimeMap(newParserDeck));
|
||||
SimulatorTimer simtimer;
|
||||
|
||||
// Create new wells, well_state
|
||||
WellsManager wells(*deck, *grid->c_grid(), props->permeability());
|
||||
// @@@ HACK: we should really make a new well state and
|
||||
// properly transfer old well state to it every epoch,
|
||||
// since number of wells may change etc.
|
||||
well_state.init(wells.c_wells(), state);
|
||||
|
||||
// Create and run simulator.
|
||||
SimulatorFullyImplicitBlackoil simulator(param,
|
||||
*grid->c_grid(),
|
||||
*new_props,
|
||||
rock_comp->isActive() ? rock_comp.get() : 0,
|
||||
wells,
|
||||
linsolver,
|
||||
grav,
|
||||
outputWriter);
|
||||
simtimer.init(timeMap);
|
||||
SimulatorReport report = simulator.run(simtimer, state, well_state);
|
||||
|
||||
if (output) {
|
||||
report.reportParam(outStream);
|
||||
warnIfUnusedParams(param);
|
||||
}
|
||||
|
||||
std::cout << "\n\n================ End of simulation ===============\n\n";
|
||||
report.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);
|
||||
report.reportParam(tot_os);
|
||||
}
|
||||
#else
|
||||
std::cout << "\n\n================ Starting main simulation loop ===============\n"
|
||||
<< " (number of epochs: "
|
||||
<< (deck->numberOfEpochs()) << ")\n\n" << std::flush;
|
||||
@ -219,7 +299,7 @@ try
|
||||
}
|
||||
SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state);
|
||||
if (output) {
|
||||
epoch_rep.reportParam(epoch_os);
|
||||
epoch_rep.reportParam(outStream);
|
||||
}
|
||||
// Update total timing report and remember step number.
|
||||
rep += epoch_rep;
|
||||
@ -234,7 +314,7 @@ try
|
||||
std::fstream tot_os(filename.c_str(),std::fstream::trunc | std::fstream::out);
|
||||
rep.reportParam(tot_os);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
||||
|
@ -32,9 +32,13 @@
|
||||
#include <opm/core/utility/ErrorMacros.hpp>
|
||||
#include <opm/core/utility/Units.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Utility/PvdoTable.hpp>
|
||||
#include <opm/parser/eclipse/Utility/PvtgTable.hpp>
|
||||
#include <opm/parser/eclipse/Utility/PvdcoTable.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
// Making these typedef to make the code more readable.
|
||||
typedef BlackoilPropsAdFromDeck::ADB ADB;
|
||||
typedef BlackoilPropsAdFromDeck::V V;
|
||||
@ -106,7 +110,8 @@ namespace Opm
|
||||
if (deck.hasField("PVDG")) {
|
||||
if (samples > 0) {
|
||||
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDeadSpline(deck.getPVDG().pvdg_, samples));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDead(deck.getPVDG().pvdg_));
|
||||
}
|
||||
} else if (deck.hasField("PVTG")) {
|
||||
@ -129,6 +134,99 @@ namespace Opm
|
||||
}
|
||||
|
||||
|
||||
/// Constructor wrapping an opm-core black oil interface.
|
||||
BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(Opm::DeckConstPtr newParserDeck,
|
||||
const UnstructuredGrid& grid,
|
||||
const bool init_rock)
|
||||
{
|
||||
if (init_rock){
|
||||
rock_.init(newParserDeck, grid);
|
||||
}
|
||||
|
||||
const int region_number = 0;
|
||||
|
||||
phase_usage_ = phaseUsageFromDeck(newParserDeck);
|
||||
|
||||
// Surface densities. Accounting for different orders in eclipse and our code.
|
||||
if (newParserDeck->hasKeyword("DENSITY")) {
|
||||
const auto keyword = newParserDeck->getKeyword("DENSITY");
|
||||
const auto record = keyword->getRecord(region_number);
|
||||
enum { ECL_oil = 0, ECL_water = 1, ECL_gas = 2 };
|
||||
if (phase_usage_.phase_used[Aqua]) {
|
||||
densities_[phase_usage_.phase_pos[Aqua]] = record->getItem("WATER")->getSIDouble(0);
|
||||
}
|
||||
if (phase_usage_.phase_used[Vapour]) {
|
||||
densities_[phase_usage_.phase_pos[Vapour]] = record->getItem("GAS")->getSIDouble(0);
|
||||
}
|
||||
if (phase_usage_.phase_used[Liquid]) {
|
||||
densities_[phase_usage_.phase_pos[Liquid]] = record->getItem("OIL")->getSIDouble(0);
|
||||
}
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Input is missing DENSITY\n");
|
||||
}
|
||||
|
||||
// Set the properties.
|
||||
props_.resize(phase_usage_.num_phases);
|
||||
// Water PVT
|
||||
if (phase_usage_.phase_used[Aqua]) {
|
||||
if (newParserDeck->hasKeyword("PVTW")) {
|
||||
Opm::PvtwTable pvtwTable(newParserDeck->getKeyword("PVTW"), region_number);
|
||||
|
||||
props_[phase_usage_.phase_pos[Aqua]].reset(new SinglePvtConstCompr(pvtwTable));
|
||||
} else {
|
||||
// Eclipse 100 default.
|
||||
props_[phase_usage_.phase_pos[Aqua]].reset(new SinglePvtConstCompr(0.5*Opm::prefix::centi*Opm::unit::Poise));
|
||||
}
|
||||
}
|
||||
|
||||
// Oil PVT
|
||||
if (phase_usage_.phase_used[Liquid]) {
|
||||
if (newParserDeck->hasKeyword("PVDO")) {
|
||||
Opm::PvdoTable pvdoTable(newParserDeck->getKeyword("PVDO"), region_number);
|
||||
|
||||
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtDead(pvdoTable));
|
||||
}
|
||||
else if (newParserDeck->hasKeyword("PVTO")) {
|
||||
Opm::PvtoTable pvtoTable(newParserDeck->getKeyword("PVTO"), /*tableIdx=*/0);
|
||||
|
||||
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtLiveOil(pvtoTable));
|
||||
} else if (newParserDeck->hasKeyword("PVCDO")) {
|
||||
Opm::PvdcoTable pvdcoTable(newParserDeck->getKeyword("PVDCO"), region_number);
|
||||
|
||||
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtConstCompr(pvdcoTable));
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Input is missing PVDO or PVTO\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Gas PVT
|
||||
if (phase_usage_.phase_used[Vapour]) {
|
||||
if (newParserDeck->hasKeyword("PVDG")) {
|
||||
Opm::PvdoTable pvdgTable(newParserDeck->getKeyword("PVDG"), region_number);
|
||||
|
||||
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDead(pvdgTable));
|
||||
} else if (newParserDeck->hasKeyword("PVTG")) {
|
||||
Opm::PvtgTable pvtgTable(newParserDeck->getKeyword("PVTG"), /*tableIdx=*/0);
|
||||
|
||||
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtLiveGas(pvtgTable));
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Input is missing PVDG or PVTG\n");
|
||||
}
|
||||
}
|
||||
|
||||
SaturationPropsFromDeck<SatFuncGwsegNonuniform>* ptr
|
||||
= new SaturationPropsFromDeck<SatFuncGwsegNonuniform>();
|
||||
satprops_.reset(ptr);
|
||||
ptr->init(newParserDeck, grid, -1);
|
||||
|
||||
if (phase_usage_.num_phases != satprops_->numPhases()) {
|
||||
OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck() - "
|
||||
"Inconsistent number of phases in pvt data (" << phase_usage_.num_phases
|
||||
<< ") and saturation-dependent function data (" << satprops_->numPhases() << ").");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// Rock interface //
|
||||
////////////////////////////
|
||||
|
@ -22,11 +22,14 @@
|
||||
|
||||
#include <opm/autodiff/BlackoilPropsAdInterface.hpp>
|
||||
#include <opm/autodiff/AutoDiffBlock.hpp>
|
||||
|
||||
#include <opm/core/props/BlackoilPhases.hpp>
|
||||
#include <opm/core/props/satfunc/SaturationPropsFromDeck.hpp>
|
||||
#include <opm/core/io/eclipse/EclipseGridParser.hpp>
|
||||
#include <opm/core/props/rock/RockFromDeck.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
@ -52,6 +55,11 @@ namespace Opm
|
||||
const UnstructuredGrid& grid,
|
||||
const bool init_rock = true );
|
||||
|
||||
/// Constructor wrapping an opm-core black oil interface.
|
||||
BlackoilPropsAdFromDeck(Opm::DeckConstPtr newParserDeck,
|
||||
const UnstructuredGrid& grid,
|
||||
const bool init_rock = true );
|
||||
|
||||
////////////////////////////
|
||||
// Rock interface //
|
||||
////////////////////////////
|
||||
|
@ -365,6 +365,7 @@ namespace Opm
|
||||
// fractional_flows);
|
||||
// wells_manager_.applyExplicitReinjectionControls(well_resflows_phase, well_resflows_phase);
|
||||
// }
|
||||
|
||||
bool well_control_passed = !check_well_controls_;
|
||||
int well_control_iteration = 0;
|
||||
do {
|
||||
@ -420,13 +421,13 @@ namespace Opm
|
||||
tstep_os.close();
|
||||
}
|
||||
|
||||
// advance to next timestep before reporting at this location
|
||||
++timer;
|
||||
|
||||
// write an output file for later inspection
|
||||
if (output_) {
|
||||
eclipseWriter_.writeTimeStep(timer, state, well_state);
|
||||
}
|
||||
|
||||
// advance to next timestep before reporting at this location
|
||||
++timer;
|
||||
}
|
||||
|
||||
total_timer.stop();
|
||||
|
334
tests/integration_tests/sim_fibo_ad_test.cpp
Normal file
334
tests/integration_tests/sim_fibo_ad_test.cpp
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
#if HAVE_DYNAMIC_BOOST_TEST
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE SimFiboADTest
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/core/grid.h>
|
||||
#include <opm/core/grid/GridManager.hpp>
|
||||
#include <opm/core/wells.h>
|
||||
#include <opm/core/wells/WellsManager.hpp>
|
||||
#include <opm/core/utility/ErrorMacros.hpp>
|
||||
#include <opm/core/simulator/initState.hpp>
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/core/io/eclipse/EclipseWriter.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/autodiff/SimulatorFullyImplicitBlackoil.hpp>
|
||||
#include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
|
||||
#include <opm/core/utility/share_obj.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
std::vector<BlackoilState> runWithOldParser(const parameter::ParameterGroup& param) {
|
||||
|
||||
boost::scoped_ptr<EclipseGridParser> deck;
|
||||
boost::scoped_ptr<GridManager> grid;
|
||||
boost::scoped_ptr<BlackoilPropertiesInterface> props;
|
||||
boost::scoped_ptr<BlackoilPropsAdInterface> new_props;
|
||||
boost::scoped_ptr<RockCompressibility> rock_comp;
|
||||
BlackoilState state;
|
||||
std::vector<BlackoilState> state_collection;
|
||||
|
||||
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
|
||||
deck.reset(new EclipseGridParser(deck_filename));
|
||||
// Grid init
|
||||
grid.reset(new GridManager(*deck));
|
||||
|
||||
Opm::EclipseWriter outputWriter(param, share_obj(*deck), share_obj(*grid->c_grid()));
|
||||
|
||||
// Rock and fluid init
|
||||
props.reset(new BlackoilPropertiesFromDeck(*deck, *grid->c_grid(), param));
|
||||
new_props.reset(new BlackoilPropsAdFromDeck(*deck, *grid->c_grid()));
|
||||
|
||||
rock_comp.reset(new RockCompressibility(*deck));
|
||||
double gravity[3] = {0.0};
|
||||
gravity[2] = deck->hasField("NOGRAV") ? 0.0 : unit::gravity;
|
||||
|
||||
|
||||
// Init state variables (saturation and pressure).
|
||||
if (param.has("init_saturation")) {
|
||||
initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
|
||||
initBlackoilSurfvol(*grid->c_grid(), *props, state);
|
||||
enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour };
|
||||
const PhaseUsage pu = props->phaseUsage();
|
||||
if (pu.phase_used[Oil] && pu.phase_used[Gas]) {
|
||||
const int np = props->numPhases();
|
||||
const int nc = grid->c_grid()->number_of_cells;
|
||||
for (int c = 0; c < nc; ++c) {
|
||||
state.gasoilratio()[c] = state.surfacevol()[c*np + pu.phase_pos[Gas]]
|
||||
/ state.surfacevol()[c*np + pu.phase_pos[Oil]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
initBlackoilStateFromDeck(*grid->c_grid(), *props, *deck, gravity[2], state);
|
||||
}
|
||||
|
||||
bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
|
||||
const double *grav = use_gravity ? &gravity[0] : 0;
|
||||
|
||||
|
||||
// Linear solver.
|
||||
LinearSolverFactory linsolver(param);
|
||||
|
||||
std::cout << "\n\n================ Starting main simulation loop ===============\n"
|
||||
<< " (number of epochs: "
|
||||
<< (deck->numberOfEpochs()) << ")\n\n" << std::flush;
|
||||
|
||||
SimulatorReport rep;
|
||||
// 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.
|
||||
deck->setCurrentEpoch(deck->numberOfEpochs() - 1);
|
||||
simtimer.init(*deck);
|
||||
const double total_time = simtimer.totalTime();
|
||||
for (int epoch = 0; epoch < deck->numberOfEpochs(); ++epoch) {
|
||||
// Set epoch index.
|
||||
deck->setCurrentEpoch(epoch);
|
||||
|
||||
// Update the timer.
|
||||
if (deck->hasField("TSTEP")) {
|
||||
simtimer.init(*deck);
|
||||
} else {
|
||||
if (epoch != 0) {
|
||||
OPM_THROW(std::runtime_error, "No TSTEP in deck for epoch " << epoch);
|
||||
}
|
||||
simtimer.init(param);
|
||||
}
|
||||
simtimer.setCurrentStepNum(step);
|
||||
simtimer.setTotalTime(total_time);
|
||||
|
||||
// Report on start of epoch.
|
||||
std::cout << "\n\n-------------- Starting epoch " << epoch << " --------------"
|
||||
<< "\n (number of steps: "
|
||||
<< simtimer.numSteps() - step << ")\n\n" << std::flush;
|
||||
|
||||
// Create new wells, well_state
|
||||
WellsManager wells(*deck, *grid->c_grid(), props->permeability());
|
||||
// @@@ HACK: we should really make a new well state and
|
||||
// properly transfer old well state to it every epoch,
|
||||
// since number of wells may change etc.
|
||||
if (epoch == 0) {
|
||||
well_state.init(wells.c_wells(), state);
|
||||
}
|
||||
|
||||
// Create and run simulator.
|
||||
SimulatorFullyImplicitBlackoil simulator(param,
|
||||
*grid->c_grid(),
|
||||
*new_props,
|
||||
rock_comp->isActive() ? rock_comp.get() : 0,
|
||||
wells,
|
||||
linsolver,
|
||||
grav,
|
||||
outputWriter);
|
||||
|
||||
SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state);
|
||||
|
||||
BlackoilState copy = state;
|
||||
state_collection.push_back(copy);
|
||||
// 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);
|
||||
|
||||
return state_collection;
|
||||
}
|
||||
|
||||
|
||||
std::vector<BlackoilState> runWithNewParser(const parameter::ParameterGroup& param) {
|
||||
boost::scoped_ptr<EclipseGridParser> old_deck;
|
||||
boost::scoped_ptr<GridManager> grid;
|
||||
boost::scoped_ptr<BlackoilPropertiesInterface> props;
|
||||
boost::scoped_ptr<BlackoilPropsAdInterface> new_props;
|
||||
boost::scoped_ptr<RockCompressibility> rock_comp;
|
||||
BlackoilState state;
|
||||
std::vector<BlackoilState> state_collection;
|
||||
|
||||
std::string deck_filename = param.get<std::string>("deck_filename");
|
||||
|
||||
old_deck.reset(new EclipseGridParser(deck_filename));
|
||||
// Grid init
|
||||
grid.reset(new GridManager(*old_deck));
|
||||
|
||||
Opm::EclipseWriter outputWriter(param, share_obj(*old_deck), share_obj(*grid->c_grid()));
|
||||
|
||||
// Rock and fluid init
|
||||
props.reset(new BlackoilPropertiesFromDeck(*old_deck, *grid->c_grid(), param));
|
||||
new_props.reset(new BlackoilPropsAdFromDeck(*old_deck, *grid->c_grid()));
|
||||
|
||||
rock_comp.reset(new RockCompressibility(*old_deck));
|
||||
double gravity[3] = {0.0};
|
||||
gravity[2] = old_deck->hasField("NOGRAV") ? 0.0 : unit::gravity;
|
||||
|
||||
|
||||
// Init state variables (saturation and pressure).
|
||||
if (param.has("init_saturation")) {
|
||||
initStateBasic(*grid->c_grid(), *props, param, gravity[2], state);
|
||||
initBlackoilSurfvol(*grid->c_grid(), *props, state);
|
||||
enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour };
|
||||
const PhaseUsage pu = props->phaseUsage();
|
||||
if (pu.phase_used[Oil] && pu.phase_used[Gas]) {
|
||||
const int np = props->numPhases();
|
||||
const int nc = grid->c_grid()->number_of_cells;
|
||||
for (int c = 0; c < nc; ++c) {
|
||||
state.gasoilratio()[c] = state.surfacevol()[c*np + pu.phase_pos[Gas]]
|
||||
/ state.surfacevol()[c*np + pu.phase_pos[Oil]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
initBlackoilStateFromDeck(*grid->c_grid(), *props, *old_deck, gravity[2], state);
|
||||
}
|
||||
|
||||
bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
|
||||
const double *grav = use_gravity ? &gravity[0] : 0;
|
||||
|
||||
|
||||
// Linear solver.
|
||||
LinearSolverFactory linsolver(param);
|
||||
|
||||
std::cout << "\n\n================ Starting main simulation loop ===============\n"
|
||||
<< " (number of epochs: "
|
||||
<< (old_deck->numberOfEpochs()) << ")\n\n" << std::flush;
|
||||
|
||||
SimulatorReport rep;
|
||||
// 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.
|
||||
old_deck->setCurrentEpoch(old_deck->numberOfEpochs() - 1);
|
||||
simtimer.init(*old_deck);
|
||||
const double total_time = simtimer.totalTime();
|
||||
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
DeckConstPtr deck = parser->parseFile(deck_filename);
|
||||
ScheduleConstPtr schedule_deck(new Schedule(deck));
|
||||
|
||||
//In the Schedule Deck, we have the start data as the 0th element.
|
||||
for (size_t epoch = 0; epoch < schedule_deck->getTimeMap()->size() - 1; ++epoch) {
|
||||
// Set epoch index.
|
||||
old_deck->setCurrentEpoch(epoch);
|
||||
|
||||
// Update the timer.
|
||||
if (old_deck->hasField("TSTEP")) {
|
||||
simtimer.init(*old_deck);
|
||||
} else {
|
||||
if (epoch != 0) {
|
||||
OPM_THROW(std::runtime_error, "No TSTEP in deck for epoch " << epoch);
|
||||
}
|
||||
simtimer.init(param);
|
||||
}
|
||||
simtimer.setCurrentStepNum(step);
|
||||
simtimer.setTotalTime(total_time);
|
||||
|
||||
// Report on start of epoch.
|
||||
std::cout << "\n\n-------------- Starting epoch " << epoch << " --------------"
|
||||
<< "\n (number of steps: "
|
||||
<< simtimer.numSteps() - step << ")\n\n" << std::flush;
|
||||
|
||||
// Create new wells, well_state
|
||||
WellsManager wells(*old_deck, *grid->c_grid(), props->permeability());
|
||||
// @@@ HACK: we should really make a new well state and
|
||||
// properly transfer old well state to it every epoch,
|
||||
// since number of wells may change etc.
|
||||
if (epoch == 0) {
|
||||
well_state.init(wells.c_wells(), state);
|
||||
}
|
||||
|
||||
// Create and run simulator.
|
||||
SimulatorFullyImplicitBlackoil simulator(param,
|
||||
*grid->c_grid(),
|
||||
*new_props,
|
||||
rock_comp->isActive() ? rock_comp.get() : 0,
|
||||
wells,
|
||||
linsolver,
|
||||
grav,
|
||||
outputWriter);
|
||||
|
||||
SimulatorReport epoch_rep = simulator.run(simtimer, state, well_state);
|
||||
|
||||
BlackoilState copy = state;
|
||||
state_collection.push_back(copy);
|
||||
// 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);
|
||||
|
||||
return state_collection;
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SPE1_runWithOldAndNewParser_BlackOilStateEqual) {
|
||||
const char* null = 0;
|
||||
const char * argv[] = {"", "deck_filename=non_public/SPE1_opm.DATA", null};
|
||||
|
||||
parameter::ParameterGroup param(2, argv, false);
|
||||
|
||||
BOOST_ASSERT(param.has("deck_filename"));
|
||||
|
||||
std::vector<BlackoilState> runWithOldParserStates = runWithOldParser(param);
|
||||
std::vector<BlackoilState> runWithNewParserStates = runWithNewParser(param);
|
||||
|
||||
std::cout << "======== Checking old parser vs new parser BlackoilState ==========\n\n";
|
||||
for(size_t i=0; i<runWithOldParserStates.size(); i++) {
|
||||
BOOST_CHECK(runWithOldParserStates[i].equals(runWithNewParserStates[i]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user