From 9a11949f674d60c42f561ec80c2e06702bd776da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 31 Mar 2017 09:13:18 +0200 Subject: [PATCH] Updated opm-flowdiagnostics-applications to SHA afd3f6c454f52dcfa0a6aa96be9823176a6daa48 --- ResInsightVersion.cmake | 2 +- .../CMakeLists_files.cmake | 1 + .../examples/computeLocalSolutions.cpp | 14 ++- .../examples/exampleSetup.hpp | 7 +- .../examples/extractFromRestart.cpp | 74 +++++++++++++ .../opm/utility/ECLFluxCalc.cpp | 17 +-- .../opm/utility/ECLFluxCalc.hpp | 7 +- .../tests/runAcceptanceTest.cpp | 100 ------------------ 8 files changed, 109 insertions(+), 113 deletions(-) create mode 100644 ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/extractFromRestart.cpp diff --git a/ResInsightVersion.cmake b/ResInsightVersion.cmake index aa0cf62172..a1bc942c82 100644 --- a/ResInsightVersion.cmake +++ b/ResInsightVersion.cmake @@ -14,7 +14,7 @@ set(OPM_COMMON_GITHUB_SHA "1216bc052542f24ec6fcfbe1947d52e6300ff754") set(OPM_PARSER_GITHUB_SHA "a3496df501a4369fd827fbf0ff893d03deff425f") set(OPM_FLOWDIAGNOSTICS_SHA "a14dc4ba1302bcc1e0aeb35c5de6b4bd39bce98") -set(OPM_FLOWDIAGNOSTICS_APPLICATIONS_SHA "09057e5767e492fa44c5e9ae78e9e1fcc9694b6c") +set(OPM_FLOWDIAGNOSTICS_APPLICATIONS_SHA "afd3f6c454f52dcfa0a6aa96be9823176a6daa48") # sha for Units.hpp 9a679071dd0066236154852c39a9e0b3c3ac4873 diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/CMakeLists_files.cmake b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/CMakeLists_files.cmake index a75e534b84..568ddf04b3 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/CMakeLists_files.cmake +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/CMakeLists_files.cmake @@ -36,6 +36,7 @@ list (APPEND EXAMPLE_SOURCE_FILES examples/computeLocalSolutions.cpp examples/computeToFandTracers.cpp examples/computeTracers.cpp + examples/extractFromRestart.cpp tests/runAcceptanceTest.cpp tests/runLinearisedCellDataTest.cpp tests/runTransTest.cpp diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/computeLocalSolutions.cpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/computeLocalSolutions.cpp index 729a8e9dcb..8b5e2b7152 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/computeLocalSolutions.cpp +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/computeLocalSolutions.cpp @@ -33,6 +33,7 @@ try { auto& fdTool = setup.toolbox; // Create start sets from injector wells. + using ID = Opm::FlowDiagnostics::CellSetID; std::vector start; for (const auto& well : setup.well_fluxes) { if (!well.is_injector_well) { @@ -48,19 +49,24 @@ try { completion_cells.push_back(cell_index); } } - start.emplace_back(Opm::FlowDiagnostics::CellSetID(well.name), completion_cells); + start.emplace_back(ID(well.name), completion_cells); } // Solve for injection time of flight and tracers. auto sol = fdTool.computeInjectionDiagnostics(start); - // Get local tof for first injector. - const auto& tof = sol.fd.timeOfFlight(start.front().id()); + // Choose injector id, default to first injector. + const std::string id_string = setup.param.getDefault("id", start.front().id().to_string()); + const ID id(id_string); + + // Get local data for injector. + const bool tracer = setup.param.getDefault("tracer", false); + const auto& data = tracer ? sol.fd.concentration(id) : sol.fd.timeOfFlight(id); // Write it to standard out. std::cout.precision(16); - for (auto item : tof) { + for (auto item : data) { std::cout << item.first << " " << item.second << '\n'; } } diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/exampleSetup.hpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/exampleSetup.hpp index ab62d6ff88..5d2f64b4c0 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/exampleSetup.hpp +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/exampleSetup.hpp @@ -124,7 +124,12 @@ namespace example { const auto& ijk = completion.ijk; const int cell_index = G.activeCell(ijk, grid_index); if (cell_index >= 0) { - inflow.emplace(cell_index, completion.reservoir_inflow_rate); + // Since inflow is a std::map, if the key was not + // already present operator[] will insert a + // value-initialized value (as in T() for a type + // T), which is zero for built-in numerical types, + // including double. + inflow[cell_index] += completion.reservoir_inflow_rate; } } } diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/extractFromRestart.cpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/extractFromRestart.cpp new file mode 100644 index 0000000000..4d38286871 --- /dev/null +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/examples/extractFromRestart.cpp @@ -0,0 +1,74 @@ +/* + Copyright 2017 SINTEF DIGITAL, Mathematics and Cybernetics. + Copyright 2016 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 . +*/ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include + + +// Syntax (typical): +// extractFromRestart unrst= step= keyword= grid_id= +int main(int argc, char* argv[]) { + try { + Opm::parameter::ParameterGroup param(argc, argv, + /*verify_commandline_syntax=*/ true, + /*parameter_output=*/ false); + const std::string unrst_file = param.get("unrst"); + const int report_step = param.getDefault("step", int(0)); + const int grid_id = param.getDefault("grid_id", int(0)); + const std::string keyword = param.get("keyword"); + + Opm::ECLResultData restart_file(unrst_file); + + if (!restart_file.selectReportStep(report_step)) { + std::cerr << "Could not find report step " << report_step << "." << std::endl; + exit(-1); + } + + if (restart_file.haveKeywordData(keyword, grid_id)) { + const std::vector& data = restart_file.keywordData(keyword, grid_id); + + std::cout.precision(20); + + // Write out to cout in a matlab-friendly fashion. + std::cout << "kw_" << keyword << " = {" << std::endl + << "'unrst_file=" << unrst_file << "'," << std::endl + << "'step=" << report_step << "'," << std::endl + << "'grid_id=" << grid_id << "'," << std::endl; + std::cout << "["; + std::ostream_iterator out_it(std::cout, ", "); + std::copy(data.begin(), --data.end(), out_it); + std::cout << data.back(); + std::cout << "]" << std::endl; + std::cout << "};" << std::endl; + } + else { + std::cerr << "Could not find the keyword " << keyword + << " in report step " << report_step << "." << std::endl; + exit(-1); + } + } + catch (const std::exception& e) { + std::cerr << "Caught exception: " << e.what() << '\n'; + } +} diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.cpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.cpp index b29636a6c8..91a6e3d3f0 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.cpp +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.cpp @@ -18,6 +18,7 @@ */ #include +#include namespace Opm { @@ -35,14 +36,15 @@ namespace Opm std::vector ECLFluxCalc::flux(const PhaseIndex /* phase */) const { - // Obtain pressure vector. - std::vector pressure = graph_.linearisedCellData("PRESSURE", &ECLUnits::UnitSystem::pressure); + // Obtain dynamic data. + DynamicData dyn_data; + dyn_data.pressure = graph_.linearisedCellData("PRESSURE", &ECLUnits::UnitSystem::pressure); // Compute fluxes per connection. const int num_conn = transmissibility_.size(); std::vector fluxvec(num_conn); for (int conn = 0; conn < num_conn; ++conn) { - fluxvec[conn] = singleFlux(conn, pressure); + fluxvec[conn] = singleFlux(conn, dyn_data); } return fluxvec; } @@ -52,12 +54,15 @@ namespace Opm double ECLFluxCalc::singleFlux(const int connection, - const std::vector& pressure) const + const DynamicData& dyn_data) const { const int c1 = neighbours_[2*connection]; const int c2 = neighbours_[2*connection + 1]; - const double t = transmissibility_[connection]; - return t * (pressure[c1] - pressure[c2]); + const double transmissibility = transmissibility_[connection]; + const double viscosity = 1.0 * prefix::centi * unit::Poise; + const double mobility = 1.0 / viscosity; + const auto& pressure = dyn_data.pressure; + return mobility * transmissibility * (pressure[c1] - pressure[c2]); } diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.hpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.hpp index 76a5409e93..340b1974b0 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.hpp +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/opm/utility/ECLFluxCalc.hpp @@ -48,8 +48,13 @@ namespace Opm std::vector flux(const PhaseIndex phase) const; private: + struct DynamicData + { + std::vector pressure; + }; + double singleFlux(const int connection, - const std::vector& pressure) const; + const DynamicData& dyn_data) const; const ECLGraph& graph_; std::vector neighbours_; diff --git a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/tests/runAcceptanceTest.cpp b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/tests/runAcceptanceTest.cpp index 2d9051cf2e..3b799a11fb 100644 --- a/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/tests/runAcceptanceTest.cpp +++ b/ThirdParty/custom-opm-flowdiag-app/opm-flowdiagnostics-applications/tests/runAcceptanceTest.cpp @@ -48,106 +48,6 @@ #include #include -namespace StringUtils { - namespace { - std::string trim(const std::string& s) - { - const auto anchor_ws = - boost::regex(R"~~(^\s+([^\s]+)\s+$)~~"); - - auto m = boost::smatch{}; - - if (boost::regex_match(s, m, anchor_ws)) { - return m[1]; - } - - return s; - } - - std::vector split(const std::string& s) - { - if (s.empty()) { - // Single element vector whose only element is the empty - // string. - return { "" }; - } - - const auto sep = boost::regex(R"~~([\s,;.|]+)~~"); - - using TI = boost::sregex_token_iterator; - - // vector(begin, end) - // - // Range is every substring (i.e., token) in input string 's' - // that does NOT match 'sep'. - return{ TI(s.begin(), s.end(), sep, -1), TI{} }; - } - } // namespace Anonymous - - template - struct StringTo; - - template <> - struct StringTo - { - static int value(const std::string& s); - }; - - template <> - struct StringTo - { - static double value(const std::string& s); - }; - - template <> - struct StringTo - { - static std::string value(const std::string& s); - }; - - int StringTo::value(const std::string& s) - { - return std::stoi(s); - } - - double StringTo::value(const std::string& s) - { - return std::stod(s); - } - - std::string StringTo::value(const std::string& s) - { - return trim(s); - } - - namespace VectorValue { - template - std::vector get(const std::string& s, std::true_type) - { - return split(s); - } - - template - std::vector get(const std::string& s, std::false_type) - { - const auto tokens = split(s); - - auto ret = std::vector{}; - ret.reserve(tokens.size()); - for (const auto& token : tokens) { - ret.push_back(StringTo::value(token)); - } - - return ret; - } - - template - std::vector get(const std::string& s) - { - return get(s, typename std::is_same::type()); - } - } // namespace VectorValue -} // namespace StringUtils namespace { struct PoreVolume