mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #1258 from dr-robertk/PR/make-one-flow-executable
Add a common executable for all flow variants.
This commit is contained in:
commit
060631c5dc
@ -130,9 +130,3 @@ endif (NOT EIGEN3_FOUND)
|
||||
if (HAVE_OPM_DATA)
|
||||
include (${CMAKE_CURRENT_SOURCE_DIR}/compareECLFiles.cmake)
|
||||
endif()
|
||||
|
||||
# create a symbolic link from flow to flow_legacy
|
||||
ADD_CUSTOM_TARGET(flow ALL
|
||||
DEPENDS flow_ebos
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "flow_ebos" "${CMAKE_BINARY_DIR}/bin/flow")
|
||||
install(FILES ${CMAKE_BINARY_DIR}/bin/flow DESTINATION bin)
|
||||
|
@ -112,6 +112,7 @@ list (APPEND EXAMPLE_SOURCE_FILES
|
||||
examples/flow_legacy.cpp
|
||||
examples/flow_reorder.cpp
|
||||
examples/flow_sequential.cpp
|
||||
examples/flow.cpp
|
||||
examples/flow_ebos.cpp
|
||||
examples/flow_ebos_2p.cpp
|
||||
examples/flow_ebos_solvent.cpp
|
||||
@ -135,7 +136,9 @@ list (APPEND PROGRAM_SOURCE_FILES
|
||||
examples/sim_2p_incomp.cpp
|
||||
examples/sim_2p_incomp_ad.cpp
|
||||
examples/sim_2p_comp_reorder.cpp
|
||||
examples/flow.cpp
|
||||
examples/flow_ebos.cpp
|
||||
examples/flow_ebos_2p.cpp
|
||||
examples/flow_ebos_solvent.cpp
|
||||
examples/flow_ebos_polymer.cpp
|
||||
examples/flow_legacy.cpp
|
||||
|
@ -103,19 +103,26 @@ opm_set_test_driver(${PROJECT_SOURCE_DIR}/tests/run-regressionTest.sh "")
|
||||
set(abs_tol 2e-2)
|
||||
set(rel_tol 1e-5)
|
||||
|
||||
add_test_compareECLFiles(spe1 SPE1CASE2 flow ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe1 SPE1CASE2 flow_ebos ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe1_2p SPE1CASE2_2P flow ${abs_tol} ${rel_tol} compareECLFiles "" spe1)
|
||||
add_test_compareECLFiles(spe1_2p SPE1CASE2_2P flow_ebos ${abs_tol} ${rel_tol} compareECLFiles "" spe1)
|
||||
add_test_compareECLFiles(spe1_2p SPE1CASE2_2P flow_ebos_2p ${abs_tol} ${rel_tol} compareECLFiles "" spe1)
|
||||
add_test_compareECLFiles(spe1 SPE1CASE2 flow_legacy ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe1_2p SPE1CASE2_2P flow_legacy ${abs_tol} ${rel_tol} compareECLFiles "" spe1)
|
||||
add_test_compareECLFiles(spe1 SPE1CASE1 flow_sequential ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe3 SPE3CASE1 flow ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe3 SPE3CASE1 flow_ebos ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe3 SPE3CASE1 flow_legacy ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe9 SPE9_CP_SHORT flow ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe9 SPE9_CP_SHORT flow_ebos ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe9group SPE9_CP_GROUP flow ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe9group SPE9_CP_GROUP flow_ebos ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(spe9 SPE9_CP_SHORT flow_legacy ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(msw_2d_h 2D_H__ flow_multisegment ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
#add_test_compareECLFiles(polymer_simple2D 2D_THREEPHASE_POLY_HETER flow ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
add_test_compareECLFiles(polymer_simple2D 2D_THREEPHASE_POLY_HETER flow_polymer ${abs_tol} ${rel_tol} compareECLFiles "")
|
||||
#add_test_compareECLFiles(spe5 SPE5CASE1 flow ${abs_tol} 5e-4 compareECLFiles "" spe5 run.param)
|
||||
add_test_compareECLFiles(spe5 SPE5CASE1 flow_solvent ${abs_tol} 5e-4 compareECLFiles "" spe5 run.param)
|
||||
|
||||
# Restart tests
|
||||
@ -124,7 +131,7 @@ opm_set_test_driver(${PROJECT_SOURCE_DIR}/tests/run-restart-regressionTest.sh ""
|
||||
# Cruder tolerances for the restarted tests
|
||||
set(abs_tol_restart 2e-1)
|
||||
set(rel_tol_restart 4e-5)
|
||||
foreach(sim flow_legacy flow_ebos)
|
||||
foreach(sim flow flow_legacy flow_ebos)
|
||||
add_test_compare_restarted_simulation(spe1 SPE1CASE2_ACTNUM ${sim} ${abs_tol_restart} ${rel_tol_restart})
|
||||
add_test_compare_restarted_simulation(spe9 SPE9_CP_SHORT ${sim} ${abs_tol_restart} ${rel_tol_restart})
|
||||
endforeach()
|
||||
@ -132,7 +139,7 @@ endforeach()
|
||||
# Init tests
|
||||
opm_set_test_driver(${PROJECT_SOURCE_DIR}/tests/run-init-regressionTest.sh "")
|
||||
|
||||
foreach(sim flow_legacy flow_ebos)
|
||||
foreach(sim flow flow_legacy flow_ebos)
|
||||
add_test_compareECLFiles(norne NORNE_ATW2013 ${sim} ${abs_tol} ${rel_tol} compareECLInitFiles /init)
|
||||
endforeach()
|
||||
|
||||
@ -144,7 +151,7 @@ if(MPI_FOUND)
|
||||
set(abs_tol_parallel 0.02)
|
||||
set(rel_tol_parallel 1e-5)
|
||||
|
||||
foreach(sim flow_mpi flow_ebos)
|
||||
foreach(sim flow flow_mpi flow_ebos)
|
||||
add_test_compare_parallel_simulation(spe1 SPE1CASE2 ${sim} ${abs_tol_parallel} ${rel_tol_parallel})
|
||||
add_test_compare_parallel_simulation(spe9 SPE9_CP_SHORT ${sim} ${abs_tol_parallel} ${rel_tol_parallel})
|
||||
endforeach()
|
||||
|
205
examples/flow.cpp
Normal file
205
examples/flow.cpp
Normal file
@ -0,0 +1,205 @@
|
||||
/*
|
||||
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
||||
Copyright 2015, 2017 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/>.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
|
||||
|
||||
// Define making clear that the simulator supports AMG
|
||||
#define FLOW_SUPPORT_AMG 1
|
||||
|
||||
#include <opm/material/densead/Evaluation.hpp>
|
||||
#include <ewoms/models/blackoil/blackoiltwophaseindices.hh>
|
||||
|
||||
#include <opm/autodiff/DuneMatrix.hpp>
|
||||
#include <opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp>
|
||||
#include <opm/autodiff/FlowMainEbos.hpp>
|
||||
|
||||
namespace Ewoms {
|
||||
namespace Properties {
|
||||
|
||||
///////////////////////////////////
|
||||
// Twophase case
|
||||
///////////////////////////////////
|
||||
|
||||
NEW_TYPE_TAG(EclFlowTwoPhaseProblem, INHERITS_FROM(EclFlowProblem));
|
||||
//! The indices required by the model
|
||||
SET_TYPE_PROP(EclFlowTwoPhaseProblem, Indices,
|
||||
Ewoms::BlackOilTwoPhaseIndices<GET_PROP_VALUE(TypeTag, EnableSolvent)?1:0, GET_PROP_VALUE(TypeTag, EnablePolymer)?1:0, /*PVOffset=*/0>);
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// Polymer case
|
||||
///////////////////////////////////
|
||||
|
||||
NEW_TYPE_TAG(EclFlowPolymerProblem, INHERITS_FROM(EclFlowProblem));
|
||||
SET_BOOL_PROP(EclFlowPolymerProblem, EnablePolymer, true);
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// Solvent case
|
||||
///////////////////////////////////
|
||||
|
||||
NEW_TYPE_TAG(EclFlowSolventProblem, INHERITS_FROM(EclFlowProblem));
|
||||
SET_BOOL_PROP(EclFlowSolventProblem, EnableSolvent, true);
|
||||
|
||||
}} // end namespaces
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
boost::filesystem::path simulationCaseName( const std::string& casename ) {
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
const auto exists = []( const fs::path& f ) -> bool {
|
||||
if( !fs::exists( f ) ) return false;
|
||||
|
||||
if( fs::is_regular_file( f ) ) return true;
|
||||
|
||||
return fs::is_symlink( f )
|
||||
&& fs::is_regular_file( fs::read_symlink( f ) );
|
||||
};
|
||||
|
||||
auto simcase = fs::path( casename );
|
||||
|
||||
if( exists( simcase ) ) {
|
||||
return simcase;
|
||||
}
|
||||
|
||||
for( const auto& ext : { std::string("data"), std::string("DATA") } ) {
|
||||
if( exists( simcase.replace_extension( ext ) ) ) {
|
||||
return simcase;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::invalid_argument( "Cannot find input case " + casename );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// MPI setup.
|
||||
// Must ensure an instance of the helper is created to initialise MPI.
|
||||
// For a build without MPI the Dune::FakeMPIHelper is used, so rank will
|
||||
// be 0 and size 1.
|
||||
const Dune::MPIHelper& mpi_helper = Dune::MPIHelper::instance(argc, argv);
|
||||
const bool outputCout = mpi_helper.rank() == 0;
|
||||
|
||||
Opm::ParameterGroup param(argc, argv, false, outputCout);
|
||||
|
||||
// See if a deck was specified on the command line.
|
||||
if (!param.unhandledArguments().empty()) {
|
||||
if (param.unhandledArguments().size() != 1) {
|
||||
std::cerr << "You can only specify a single input deck on the command line.\n";
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
const auto casename = detail::simulationCaseName( param.unhandledArguments()[ 0 ] );
|
||||
param.insertParameter("deck_filename", casename.string() );
|
||||
}
|
||||
}
|
||||
|
||||
// We must have an input deck. Grid and props will be read from that.
|
||||
if (!param.has("deck_filename")) {
|
||||
std::cerr << "This program must be run with an input deck.\n"
|
||||
"Specify the deck filename either\n"
|
||||
" a) as a command line argument by itself\n"
|
||||
" b) as a command line parameter with the syntax deck_filename=<path to your deck>, or\n"
|
||||
" c) as a parameter in a parameter file (.param or .xml) passed to the program.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::string deckFilename = param.get<std::string>("deck_filename");
|
||||
|
||||
// Create Deck and EclipseState.
|
||||
try {
|
||||
Opm::Parser parser;
|
||||
typedef std::pair<std::string, Opm::InputError::Action> ParseModePair;
|
||||
typedef std::vector<ParseModePair> ParseModePairs;
|
||||
ParseModePairs tmp;
|
||||
tmp.push_back(ParseModePair(Opm::ParseContext::PARSE_RANDOM_SLASH, Opm::InputError::IGNORE));
|
||||
tmp.push_back(ParseModePair(Opm::ParseContext::PARSE_MISSING_DIMS_KEYWORD, Opm::InputError::WARN));
|
||||
tmp.push_back(ParseModePair(Opm::ParseContext::SUMMARY_UNKNOWN_WELL, Opm::InputError::WARN));
|
||||
tmp.push_back(ParseModePair(Opm::ParseContext::SUMMARY_UNKNOWN_GROUP, Opm::InputError::WARN));
|
||||
Opm::ParseContext parseContext(tmp);
|
||||
|
||||
std::shared_ptr<Opm::Deck> deck = std::make_shared< Opm::Deck >( parser.parseFile(deckFilename , parseContext) );
|
||||
Opm::checkDeck(*deck, parser);
|
||||
if ( outputCout ) {
|
||||
Opm::MissingFeatures::checkKeywords(*deck);
|
||||
}
|
||||
|
||||
std::shared_ptr<Opm::EclipseState> eclipseState =
|
||||
std::make_shared< Opm::EclipseState > ( *deck, parseContext );
|
||||
|
||||
Opm::Runspec runspec( *deck );
|
||||
const auto& phases = runspec.phases();
|
||||
|
||||
// Twophase case
|
||||
if( phases.size() == 2 ) {
|
||||
Opm::FlowMainEbos<TTAG(EclFlowTwoPhaseProblem)> mainfunc;
|
||||
return mainfunc.execute(argc, argv, deck, eclipseState );
|
||||
}
|
||||
// Polymer case
|
||||
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
||||
Opm::FlowMainEbos<TTAG(EclFlowPolymerProblem)> mainfunc;
|
||||
return mainfunc.execute(argc, argv, deck, eclipseState );
|
||||
|
||||
}
|
||||
// Solvent case
|
||||
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
||||
Opm::FlowMainEbos<TTAG(EclFlowSolventProblem)> mainfunc;
|
||||
return mainfunc.execute(argc, argv, deck, eclipseState );
|
||||
|
||||
}
|
||||
// Blackoil case
|
||||
else if( phases.size() == 3 ) {
|
||||
Opm::FlowMainEbos<TTAG(EclFlowProblem)> mainfunc;
|
||||
return mainfunc.execute(argc, argv, deck, eclipseState );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "No suitable configuration found, valid are Twophase, polymer, solvent, or blackoil" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -75,6 +75,7 @@ namespace Opm
|
||||
public:
|
||||
typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Simulator) EbosSimulator;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, SimulatorParameter) EbosSimulatorParameter;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, ElementMapper) ElementMapper;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
|
||||
@ -90,7 +91,9 @@ namespace Opm
|
||||
/// simulator classes, based on user command-line input. The
|
||||
/// content of this function used to be in the main() function of
|
||||
/// flow.cpp.
|
||||
int execute(int argc, char** argv)
|
||||
int execute(int argc, char** argv,
|
||||
std::shared_ptr<Opm::Deck> deck = std::shared_ptr<Opm::Deck>(),
|
||||
std::shared_ptr<Opm::EclipseState> eclipseState = std::shared_ptr<Opm::EclipseState>() )
|
||||
{
|
||||
try {
|
||||
// we always want to use the default locale, and thus spare us the trouble
|
||||
@ -104,7 +107,7 @@ namespace Opm
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
setupEbosSimulator();
|
||||
setupEbosSimulator( deck, eclipseState );
|
||||
setupOutput();
|
||||
setupLogging();
|
||||
printPRTHeader();
|
||||
@ -180,8 +183,8 @@ namespace Opm
|
||||
|
||||
// Print startup message if on output rank.
|
||||
void printStartupMessage()
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
if (output_cout_) {
|
||||
const int lineLen = 70;
|
||||
const std::string version = moduleVersionName();
|
||||
@ -338,29 +341,29 @@ namespace Opm
|
||||
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true));
|
||||
|
||||
if ( output_cout_ )
|
||||
{
|
||||
{
|
||||
// Read Parameters.
|
||||
OpmLog::debug("\n--------------- Reading parameters ---------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printPRTHeader()
|
||||
{
|
||||
// Print header for PRT file.
|
||||
// Print header for PRT file.
|
||||
if ( output_cout_ ) {
|
||||
const std::string version = moduleVersionName();
|
||||
const double megabyte = 1024 * 1024;
|
||||
unsigned num_cpu = std::thread::hardware_concurrency();
|
||||
unsigned num_cpu = std::thread::hardware_concurrency();
|
||||
struct utsname arch;
|
||||
const char* user = getlogin();
|
||||
const char* user = getlogin();
|
||||
time_t now = std::time(0);
|
||||
struct tm tstruct;
|
||||
char tmstr[80];
|
||||
tstruct = *localtime(&now);
|
||||
strftime(tmstr, sizeof(tmstr), "%d-%m-%Y at %X", &tstruct);
|
||||
const double mem_size = getTotalSystemMemory() / megabyte;
|
||||
const double mem_size = getTotalSystemMemory() / megabyte;
|
||||
std::ostringstream ss;
|
||||
ss << "\n\n\n ######## # ###### # #\n";
|
||||
ss << "\n\n\n ######## # ###### # #\n";
|
||||
ss << " # # # # # # \n";
|
||||
ss << " ##### # # # # # # \n";
|
||||
ss << " # # # # # # # # \n";
|
||||
@ -377,11 +380,11 @@ namespace Opm
|
||||
if (user) {
|
||||
ss << "User = " << user << std::endl;
|
||||
}
|
||||
ss << "Simulation started on " << tmstr << " hrs\n";
|
||||
ss << "Simulation started on " << tmstr << " hrs\n";
|
||||
OpmLog::note(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mergeParallelLogFiles()
|
||||
{
|
||||
// force closing of all log files.
|
||||
@ -406,7 +409,7 @@ namespace Opm
|
||||
detail::ParallelFileMerger(output_path, deck_filename.stem().string()));
|
||||
}
|
||||
|
||||
void setupEbosSimulator()
|
||||
void setupEbosSimulator( std::shared_ptr<Opm::Deck>& dck, std::shared_ptr<Opm::EclipseState>& eclipseState)
|
||||
{
|
||||
std::string progName("flow_ebos");
|
||||
std::string deckFile("--ecl-deck-file-name=");
|
||||
@ -414,9 +417,10 @@ namespace Opm
|
||||
char* ptr[2];
|
||||
ptr[ 0 ] = const_cast< char * > (progName.c_str());
|
||||
ptr[ 1 ] = const_cast< char * > (deckFile.c_str());
|
||||
EbosSimulatorParameter simParam( dck, eclipseState );
|
||||
EbosSimulator::registerParameters();
|
||||
Ewoms::setupParameters_< TypeTag > ( 2, ptr );
|
||||
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
|
||||
ebosSimulator_.reset(new EbosSimulator(simParam, /*verbose=*/false));
|
||||
ebosSimulator_->model().applyInitialSolution();
|
||||
|
||||
// Create a grid with a global view.
|
||||
@ -737,7 +741,7 @@ namespace Opm
|
||||
|
||||
throw std::invalid_argument( "Cannot find input case " + casename );
|
||||
}
|
||||
|
||||
|
||||
unsigned long long getTotalSystemMemory()
|
||||
{
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
@ -955,4 +959,4 @@ namespace Opm
|
||||
};
|
||||
} // namespace Opm
|
||||
|
||||
#endif // OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
|
||||
#endif // OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
|
||||
|
Loading…
Reference in New Issue
Block a user