Compare commits

..

4 Commits

Author SHA1 Message Date
Arne Morten Kvarving
8f297e2079 bump versions for final 2018-10-24 13:35:03 +02:00
Arne Morten Kvarving
1e77807ff0 correct packaging versions 2018-10-04 06:06:01 +02:00
Joakim Hove
a732ddeb50 Merge pull request #512 from joakim-hove/bump-versions
Bump versions to 2018.10-rc1
2018-10-02 15:50:58 +02:00
Joakim Hove
4768b5cd95 Bump versions to 2018.10-rc1 2018-10-02 15:27:41 +02:00
465 changed files with 9248 additions and 52541 deletions

View File

@@ -7,12 +7,6 @@ set(OPM_MACROS_ROOT ${PROJECT_SOURCE_DIR})
option(ENABLE_ECL_INPUT "Enable eclipse input support?" ON)
option(ENABLE_ECL_OUTPUT "Enable eclipse output support?" ON)
option(ENABLE_MOCKSIM "Build the mock simulator for io testing" ON)
option(ENABLE_WELL_TEST "Enable testing of well code when building Schedule object" OFF)
if (ENABLE_WELL_TEST)
add_definitions(-DWELL_TEST)
endif()
# Output implies input
if(ENABLE_ECL_OUTPUT)
@@ -24,7 +18,6 @@ if(NOT ENABLE_ECL_INPUT)
set(ENABLE_ECL_OUTPUT OFF)
endif()
# not the same location as most of the other projects; this hook overrides
macro (dir_hook)
endmacro (dir_hook)
@@ -137,51 +130,33 @@ endmacro (install_hook)
# all setup common to the OPM library modules is done here
include (OpmLibMain)
if (ENABLE_MOCKSIM)
add_library(mocksim
msim/src/msim.cpp)
target_link_libraries(mocksim opmcommon)
target_include_directories(mocksim PUBLIC msim/include)
add_executable(msim examples/msim.cpp)
target_link_libraries(msim mocksim)
set(_libs mocksim opmcommon
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
foreach( test test_msim test_msim_ACTIONX )
opm_add_test(${test} SOURCES tests/msim/${test}
LIBRARIES ${_libs}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
endforeach()
endif()
# Build the compare utilities
if(ENABLE_ECL_INPUT)
add_library(testutil STATIC
examples/test_util/EclFile.cpp
examples/test_util/EclFilesComparator.cpp
examples/test_util/EclOutput.cpp
examples/test_util/EclIntegrationTest.cpp
examples/test_util/EclRegressionTest.cpp
examples/test_util/EclUtil.cpp
examples/test_util/EGrid.cpp
examples/test_util/ERft.cpp
examples/test_util/ERst.cpp
examples/test_util/ESmry.cpp)
foreach(target compareECL convertECL)
add_executable(${target} examples/test_util/${target}.cpp)
target_link_libraries(${target} testutil opmcommon)
install(TARGETS ${target} DESTINATION bin)
endforeach()
examples/test_util/summaryComparator.cpp
examples/test_util/summaryIntegrationTest.cpp
examples/test_util/summaryRegressionTest.cpp)
target_link_libraries(testutil ecl)
add_executable(compareECL examples/test_util/compareECL.cpp)
target_link_libraries(compareECL testutil opmcommon)
# Add the tests
set(_libs testutil opmcommon
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
foreach(test test_EclFilesComparator test_EclIO test_EclRegressionTest
test_EGrid test_ERft test_ERst test_ESmry)
opm_add_test(${test} CONDITION ENABLE_ECL_INPUT
LIBRARIES ${_libs}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
endforeach()
opm_add_test(test_compareSummary CONDITION ENABLE_ECL_INPUT
LIBRARIES ${_libs})
opm_add_test(test_EclFilesComparator CONDITION ENABLE_ECL_INPUT
LIBRARIES ${_libs})
if(HAVE_DYNAMIC_BOOST_TEST)
set_target_properties(test_compareSummary PROPERTIES
COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK)
set_target_properties(test_EclFilesComparator PROPERTIES
COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK)
endif()
install(TARGETS compareECL DESTINATION bin)
endif()
# Install build system files

View File

@@ -45,16 +45,13 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/Deck/DeckRecord.cpp
src/opm/parser/eclipse/Deck/DeckOutput.cpp
src/opm/parser/eclipse/Deck/Section.cpp
src/opm/parser/eclipse/Deck/UDAValue.cpp
src/opm/parser/eclipse/EclipseState/AquiferCT.cpp
src/opm/parser/eclipse/EclipseState/Aquifetp.cpp
src/opm/parser/eclipse/EclipseState/Aquancon.cpp
src/opm/parser/eclipse/EclipseState/checkDeck.cpp
src/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp
src/opm/parser/eclipse/EclipseState/EclipseConfig.cpp
src/opm/parser/eclipse/EclipseState/EclipseState.cpp
src/opm/parser/eclipse/EclipseState/EndpointScaling.cpp
src/opm/parser/eclipse/EclipseState/Edit/EDITNNC.cpp
src/opm/parser/eclipse/EclipseState/Grid/Box.cpp
src/opm/parser/eclipse/EclipseState/Grid/BoxManager.cpp
src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp
@@ -76,43 +73,29 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/EclipseState/IOConfig/IOConfig.cpp
src/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp
src/opm/parser/eclipse/EclipseState/Runspec.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/Actions.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionParser.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Action/ASTNode.cpp
src/opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.cpp
src/opm/parser/eclipse/EclipseState/Schedule/ActionX.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Events.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Group.cpp
src/opm/parser/eclipse/EclipseState/Schedule/GroupTree.cpp
src/opm/parser/eclipse/EclipseState/Schedule/injection.cpp
src/opm/parser/eclipse/EclipseState/Schedule/MessageLimits.cpp
src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp
src/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.cpp
src/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.cpp
src/opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.cpp
src/opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/RFTConfig.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp
src/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp
src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp
src/opm/parser/eclipse/EclipseState/Schedule/TimeMap.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Tuning.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/Connection.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/Well2.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WList.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellEconProductionLimits.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellPolymerProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTracerProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestConfig.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp
src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellEconProductionLimits.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellPolymerProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellTestConfig.cpp
src/opm/parser/eclipse/EclipseState/Schedule/WellTestState.cpp
src/opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.cpp
src/opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.cpp
src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp
@@ -120,30 +103,17 @@ if(ENABLE_ECL_INPUT)
src/opm/parser/eclipse/EclipseState/Tables/JFunc.cpp
src/opm/parser/eclipse/EclipseState/Tables/PvtxTable.cpp
src/opm/parser/eclipse/EclipseState/Tables/SimpleTable.cpp
src/opm/parser/eclipse/EclipseState/Tables/PolyInjTables.cpp
src/opm/parser/eclipse/EclipseState/Tables/TableColumn.cpp
src/opm/parser/eclipse/EclipseState/Tables/TableContainer.cpp
src/opm/parser/eclipse/EclipseState/Tables/TableIndex.cpp
src/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp
src/opm/parser/eclipse/EclipseState/Tables/TableSchema.cpp
src/opm/parser/eclipse/EclipseState/Tables/Tables.cpp
src/opm/parser/eclipse/EclipseState/Tables/Rock2dTable.cpp
src/opm/parser/eclipse/EclipseState/Tables/Rock2dtrTable.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParams.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQWellSet.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQEnums.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp
src/opm/parser/eclipse/EclipseState/UDQConfig.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQ.cpp
src/opm/parser/eclipse/EclipseState/Schedule/UDQExpression.cpp
src/opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.cpp
src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp
src/opm/parser/eclipse/Parser/ErrorGuard.cpp
src/opm/parser/eclipse/Parser/ParseContext.cpp
src/opm/parser/eclipse/Parser/Parser.cpp
src/opm/parser/eclipse/Parser/ParserEnums.cpp
@@ -172,6 +142,7 @@ if(ENABLE_ECL_OUTPUT)
src/opm/output/eclipse/CreateDoubHead.cpp
src/opm/output/eclipse/CreateInteHead.cpp
src/opm/output/eclipse/CreateLogiHead.cpp
src/opm/output/eclipse/WellDataSerializers.cpp
src/opm/output/eclipse/DoubHEAD.cpp
src/opm/output/eclipse/EclipseGridInspector.cpp
src/opm/output/eclipse/EclipseIO.cpp
@@ -182,6 +153,7 @@ if(ENABLE_ECL_OUTPUT)
src/opm/output/eclipse/LogiHEAD.cpp
src/opm/output/eclipse/RestartIO.cpp
src/opm/output/eclipse/Summary.cpp
src/opm/output/eclipse/SummaryState.cpp
src/opm/output/eclipse/Tables.cpp
src/opm/output/eclipse/RegionCache.cpp
src/opm/output/eclipse/RestartValue.cpp
@@ -206,7 +178,6 @@ if(ENABLE_ECL_INPUT)
tests/parser/ACTIONX.cpp
tests/parser/ADDREGTests.cpp
tests/parser/AquiferCTTests.cpp
tests/parser/AquifetpTests.cpp
tests/parser/AqudimsTests.cpp
tests/parser/AquanconTests.cpp
tests/parser/BoxTests.cpp
@@ -235,11 +206,9 @@ if(ENABLE_ECL_INPUT)
tests/parser/MULTREGTScannerTests.cpp
tests/parser/OrderedMapTests.cpp
tests/parser/ParseContextTests.cpp
tests/parser/ParseContext_EXIT1.cpp
tests/parser/PORVTests.cpp
tests/parser/RawKeywordTests.cpp
tests/parser/RestartConfigTests.cpp
tests/parser/RockTableTests.cpp
tests/parser/RunspecTests.cpp
tests/parser/SatfuncPropertyInitializersTests.cpp
tests/parser/ScheduleTests.cpp
@@ -262,18 +231,12 @@ if(ENABLE_ECL_INPUT)
tests/parser/UnitTests.cpp
tests/parser/ValueTests.cpp
tests/parser/WellSolventTests.cpp
tests/parser/WellTracerTests.cpp
tests/parser/WellTests.cpp
tests/parser/WLIST.cpp
tests/parser/WTEST.cpp)
endif()
if(ENABLE_ECL_OUTPUT)
list (APPEND TEST_SOURCE_FILES
tests/test_AggregateWellData.cpp
tests/test_AggregateGroupData.cpp
tests/test_AggregateMSWData.cpp
tests/test_AggregateConnectionData.cpp
tests/test_ArrayDimChecker.cpp
tests/test_CharArrayNullTerm.cpp
tests/test_EclipseIO.cpp
tests/test_DoubHEAD.cpp
@@ -289,6 +252,8 @@ if(ENABLE_ECL_OUTPUT)
tests/test_Wells.cpp
tests/test_WindowedArray.cpp
tests/test_writenumwells.cpp
tests/test_serialize_ICON.cpp
tests/test_serialize_SCON.cpp
)
endif()
@@ -297,7 +262,6 @@ list (APPEND TEST_DATA_FILES
)
if(ENABLE_ECL_OUTPUT)
list (APPEND TEST_DATA_FILES
tests/expect-wdims.err.out
tests/FIRST_SIM.DATA
tests/FIRST_SIM_THPRES.DATA
tests/summary_deck.DATA
@@ -308,30 +272,16 @@ if(ENABLE_ECL_OUTPUT)
tests/summary_deck_non_constant_porosity.DATA
tests/SUMMARY_EFF_FAC.DATA
tests/SPE1CASE1.DATA
tests/SPE1CASE1.SMSPEC
tests/SPE9_CP_PACKED.DATA
tests/SOFR_TEST.DATA
)
endif()
list (APPEND EXAMPLE_SOURCE_FILES
)
if(ENABLE_ECL_INPUT)
list (APPEND TEST_DATA_FILES
tests/ECLFILE.INIT
tests/ECLFILE.FINIT
tests/SPE1CASE1.EGRID
tests/SPE1CASE1.RFT
tests/SPE1_TESTCASE.UNRST
tests/SPE1_TESTCASE.FUNRST
tests/SPE1CASE1.UNSMRY
tests/SPE1CASE1_RST60.SMSPEC
tests/SPE1CASE1_RST60.UNSMRY
)
list (APPEND EXAMPLE_SOURCE_FILES
examples/opmi.cpp
examples/opmpack.cpp
examples/opmhash.cpp
)
endif()
@@ -343,7 +293,6 @@ if(ENABLE_ECL_INPUT)
list (APPEND PROGRAM_SOURCE_FILES
examples/opmi.cpp
examples/opmpack.cpp
examples/opmhash.cpp
)
endif()
@@ -393,7 +342,6 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/Units/UnitSystem.hpp
opm/parser/eclipse/Units/Units.hpp
opm/parser/eclipse/Units/Dimension.hpp
opm/parser/eclipse/Parser/ErrorGuard.hpp
opm/parser/eclipse/Parser/ParserItem.hpp
opm/parser/eclipse/Parser/Parser.hpp
opm/parser/eclipse/Parser/ParserRecord.hpp
@@ -407,7 +355,6 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Util/Value.hpp
opm/parser/eclipse/EclipseState/Util/OrderedMap.hpp
opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp
opm/parser/eclipse/EclipseState/Edit/EDITNNC.hpp
opm/parser/eclipse/EclipseState/Grid/GridDims.hpp
opm/parser/eclipse/EclipseState/Grid/TransMult.hpp
opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp
@@ -427,7 +374,6 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp
opm/parser/eclipse/EclipseState/EndpointScaling.hpp
opm/parser/eclipse/EclipseState/Tables/SimpleTable.hpp
opm/parser/eclipse/EclipseState/Tables/PolyInjTable.hpp
opm/parser/eclipse/EclipseState/Tables/PdvdTable.hpp
opm/parser/eclipse/EclipseState/Tables/TlpmixpaTable.hpp
opm/parser/eclipse/EclipseState/Tables/PvdgTable.hpp
@@ -437,11 +383,8 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Tables/Eqldims.hpp
opm/parser/eclipse/EclipseState/Tables/SpecrockTable.hpp
opm/parser/eclipse/EclipseState/Tables/PlydhflfTable.hpp
opm/parser/eclipse/EclipseState/Tables/PlymwinjTable.hpp
opm/parser/eclipse/EclipseState/Tables/PlyshlogTable.hpp
opm/parser/eclipse/EclipseState/Tables/RsvdTable.hpp
opm/parser/eclipse/EclipseState/Tables/SkprwatTable.hpp
opm/parser/eclipse/EclipseState/Tables/SkprpolyTable.hpp
opm/parser/eclipse/EclipseState/Tables/SpecheatTable.hpp
opm/parser/eclipse/EclipseState/Tables/SgcwmisTable.hpp
opm/parser/eclipse/EclipseState/Tables/Sof2Table.hpp
@@ -479,10 +422,6 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Tables/SgwfnTable.hpp
opm/parser/eclipse/EclipseState/Tables/PvdsTable.hpp
opm/parser/eclipse/EclipseState/Tables/PvtoTable.hpp
opm/parser/eclipse/EclipseState/Tables/Rock2dTable.hpp
opm/parser/eclipse/EclipseState/Tables/Rock2dtrTable.hpp
opm/parser/eclipse/EclipseState/Tables/RockwnodTable.hpp
opm/parser/eclipse/EclipseState/Tables/OverburdTable.hpp
opm/parser/eclipse/EclipseState/Tables/ColumnSchema.hpp
opm/parser/eclipse/EclipseState/Tables/PmiscTable.hpp
opm/parser/eclipse/EclipseState/Tables/RtempvdTable.hpp
@@ -495,32 +434,16 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/EclipseConfig.hpp
opm/parser/eclipse/EclipseState/Aquancon.hpp
opm/parser/eclipse/EclipseState/AquiferCT.hpp
opm/parser/eclipse/EclipseState/Aquifetp.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp
opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp
opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp
opm/parser/eclipse/EclipseState/Schedule/ActionX.hpp
opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp
opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp
opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/Well2.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellEconProductionLimits.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellPolymerProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellTracerProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellTestConfig.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp
opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp
opm/parser/eclipse/EclipseState/Schedule/Well.hpp
opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp
opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp
opm/parser/eclipse/EclipseState/Schedule/RFTConfig.hpp
opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp
opm/parser/eclipse/EclipseState/Schedule/WellEconProductionLimits.hpp
opm/parser/eclipse/EclipseState/Schedule/WellPolymerProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/Tuning.hpp
opm/parser/eclipse/EclipseState/Schedule/Group.hpp
opm/parser/eclipse/EclipseState/Schedule/MessageLimits.hpp
@@ -528,34 +451,30 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp
opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp
opm/parser/eclipse/EclipseState/Schedule/Connection.hpp
opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp
opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.hpp
opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp
opm/parser/eclipse/EclipseState/Schedule/MSW/updatingConnectionsWithSegments.hpp
opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.hpp
opm/parser/eclipse/EclipseState/Schedule/WellTestConfig.hpp
opm/parser/eclipse/EclipseState/Schedule/WellTestState.hpp
opm/parser/eclipse/EclipseState/Schedule/WellConnections.hpp
opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp
opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp
opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp
opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp
opm/parser/eclipse/EclipseState/checkDeck.hpp
opm/parser/eclipse/EclipseState/Runspec.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQEnums.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParams.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQWellSet.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQ.hpp
opm/parser/eclipse/EclipseState/UDQConfig.hpp
opm/parser/eclipse/EclipseState/Schedule/UDQExpression.hpp
opm/parser/eclipse/Deck/DeckItem.hpp
opm/parser/eclipse/Deck/Deck.hpp
opm/parser/eclipse/Deck/Section.hpp
opm/parser/eclipse/Deck/DeckOutput.hpp
opm/parser/eclipse/Deck/DeckKeyword.hpp
opm/parser/eclipse/Deck/DeckRecord.hpp
opm/parser/eclipse/Deck/UDAValue.hpp
opm/parser/eclipse/RawDeck/StarToken.hpp
opm/parser/eclipse/RawDeck/RawEnums.hpp
opm/parser/eclipse/RawDeck/RawRecord.hpp
@@ -568,10 +487,7 @@ if(ENABLE_ECL_OUTPUT)
opm/output/data/Solution.hpp
opm/output/data/Wells.hpp
opm/output/eclipse/VectorItems/connection.hpp
opm/output/eclipse/VectorItems/group.hpp
opm/output/eclipse/VectorItems/intehead.hpp
opm/output/eclipse/VectorItems/logihead.hpp
opm/output/eclipse/VectorItems/msw.hpp
opm/output/eclipse/VectorItems/well.hpp
opm/output/eclipse/AggregateGroupData.hpp
opm/output/eclipse/AggregateConnectionData.hpp
@@ -590,6 +506,7 @@ if(ENABLE_ECL_OUTPUT)
opm/output/eclipse/RestartIO.hpp
opm/output/eclipse/RestartValue.hpp
opm/output/eclipse/Summary.hpp
opm/output/eclipse/SummaryState.hpp
opm/output/eclipse/Tables.hpp
opm/output/eclipse/WindowedArray.hpp
opm/output/eclipse/WriteRestartHelpers.hpp

View File

@@ -49,7 +49,6 @@ list(APPEND EXTRA_TESTS EclipseStateTests)
foreach (test BoxTest
CheckDeckValidity
EclipseGridCreateFromDeck
EDITNNCTests
IncludeTest
IntegrationTests
IOConfigIntegrationTest

View File

@@ -1,6 +1,5 @@
set(genkw_SOURCES src/opm/json/JsonObject.cpp
src/opm/parser/eclipse/Parser/createDefaultKeywordList.cpp
src/opm/parser/eclipse/Deck/UDAValue.cpp
src/opm/parser/eclipse/Deck/Deck.cpp
src/opm/parser/eclipse/Deck/DeckItem.cpp
src/opm/parser/eclipse/Deck/DeckKeyword.cpp
@@ -8,7 +7,6 @@ set(genkw_SOURCES src/opm/json/JsonObject.cpp
src/opm/parser/eclipse/Deck/DeckOutput.cpp
src/opm/parser/eclipse/Generator/KeywordGenerator.cpp
src/opm/parser/eclipse/Generator/KeywordLoader.cpp
src/opm/parser/eclipse/Parser/ErrorGuard.cpp
src/opm/parser/eclipse/Parser/ParseContext.cpp
src/opm/parser/eclipse/Parser/ParserEnums.cpp
src/opm/parser/eclipse/Parser/ParserItem.cpp

View File

@@ -1,46 +0,0 @@
find_library(ALBERTA_LTDL_LIB
NAMES ltdl
PATH_SUFFIXES lib lib32 lib64
)
find_path(ALBERTA_INCLUDE_DIR
NAMES alberta/alberta.h
PATHS ${ALBERTA_ROOT}
PATH_SUFFIXES alberta include NO_DEFAULT_PATH
DOC "Include path of Alberta")
find_path(ALBERTA_INCLUDE_DIR
NAMES
alberta/alberta.h
PATHS /usr/local /opt
PATH_SUFFIXES alberta)
#look for libraries
find_library(ALBERTA_UTIL_LIB
NAMES alberta_util alberta_utilities
PATHS ${ALBERTA_ROOT}
PATH_SUFFIXES lib lib32 lib64
NO_DEFAULT_PATH)
find_library(ALBERTA_UTIL_LIB
NAMES alberta_util alberta_utilities
PATH_SUFFIXES lib lib32 lib64)
foreach(dim RANGE 1 9)
find_library(ALBERTA_${dim}D_LIB alberta_${dim}d
PATHS ${ALBERTA_ROOT}
PATH_SUFFIXES lib lib32 lib64
Cache FILEPATH DOC "Alberta lib for ${dim}D" NO_DEFAULT_PATH)
find_library(ALBERTA_${dim}D_LIB alberta_${dim}d PATH_SUFFIXES lib lib32 lib64)
if(ALBERTA_${dim}D_LIB)
set(ALBERTA_LIBRARIES ${ALBERTA_LIBRARIES} ${ALBERTA_${dim}D_LIB})
endif()
endforeach(dim RANGE 1 9)
if(ALBERTA_LIBRARIES AND ALBERTA_INCLUDE_DIR)
set(ALBERTA_INCLUDE_DIRS ${ALBERTA_INCLUDE_DIR})
set(ALBERTA_LIBRARIES ${ALBERTA_LIBRARIES} ${ALBERTA_UTIL_LIB} ${ALBERTA_LTDL_LIB})
set(ALBERTA_FOUND ON)
set(Alberta_FOUND ON)
set(HAVE_ALBERTA 1)
set(DUNE_ALBERTA_VERSION 0x300)
else()
set(ALBERTA_FOUND OFF)
set(Alberta_FOUND OFF)
endif()

View File

@@ -27,8 +27,7 @@ find_opm_package (
dune-geometry REQUIRED;
dune-uggrid;
MPI;
UG;
Alberta
UG
"
# header to search for
"dune/grid/onedgrid.hh"
@@ -56,8 +55,7 @@ int main (void) {
HAVE_AMIRAMESH;
HAVE_ALBERTA;
HAVE_STDINT_H;
DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS;
DUNE_ALBERTA_VERSION
DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
")
#debug_find_vars ("dune-grid")

View File

@@ -65,7 +65,7 @@ macro (opm_compile_satellites opm satellite excl_all test_regexp)
set_target_properties (${_sat_NAME} PROPERTIES
LINK_FLAGS "${${opm}_LINKER_FLAGS_STR}"
)
if(HAVE_DYNAMIC_BOOST_TEST)
if(HAVE_DYNAMIC_BOOST_TEST AND NOT (${opm} STREQUAL "opm-parser" AND NOT BUILD_SHARED_LIBS))
set_target_properties (${_sat_NAME} PROPERTIES
COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK
)
@@ -192,7 +192,6 @@ endmacro (opm_data satellite target dirname files)
# Parameters:
# TestName Name of test
# ONLY_COMPILE Only build test but do not run it (optional)
# DEFAULT_ENABLE_IF Only enable by default if a given condition is true (optional)
# ALWAYS_ENABLE Force enabling test even if -DBUILD_TESTING=OFF was set (optional)
# EXE_NAME Name of test executable (optional, default: ./bin/${TestName})
# CONDITION Condition to enable test (optional, cmake code)
@@ -219,7 +218,7 @@ macro(opm_add_test TestName)
cmake_parse_arguments(CURTEST
"NO_COMPILE;ONLY_COMPILE;ALWAYS_ENABLE" # flags
"EXE_NAME;PROCESSORS;WORKING_DIRECTORY" # one value args
"CONDITION;DEFAULT_ENABLE_IF;TEST_DEPENDS;DRIVER;DRIVER_ARGS;DEPENDS;TEST_ARGS;SOURCES;LIBRARIES" # multi-value args
"CONDITION;TEST_DEPENDS;DRIVER;DRIVER_ARGS;DEPENDS;TEST_ARGS;SOURCES;LIBRARIES" # multi-value args
${ARGN})
set(BUILD_TESTING "${BUILD_TESTING}")
@@ -267,11 +266,6 @@ macro(opm_add_test TestName)
# case. They can still be build using 'make test-suite' and they can
# be build and run using 'make check'
set(CURTEST_EXCLUDE_FROM_ALL "")
if (NOT "AND OR ${CURTEST_DEFAULT_ENABLE_IF}" STREQUAL "AND OR ")
if (NOT ${CURTEST_DEFAULT_ENABLE_IF})
set(CURTEST_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()
endif()
if (NOT BUILD_TESTING AND NOT CURTEST_ALWAYS_ENABLE)
set(CURTEST_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()
@@ -322,11 +316,6 @@ macro(opm_add_test TestName)
# run-only case occurs if the binary is already compiled by an
# earlier test.)
add_executable("${CURTEST_EXE_NAME}" ${CURTEST_EXCLUDE_FROM_ALL} ${CURTEST_SOURCES})
if(HAVE_DYNAMIC_BOOST_TEST)
set_target_properties (${CURTEST_EXE_NAME} PROPERTIES
COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK
)
endif()
target_link_libraries (${CURTEST_EXE_NAME} ${CURTEST_LIBRARIES})
if(CURTEST_DEPENDS)
@@ -355,12 +344,12 @@ macro(opm_add_test TestName)
# specify the dependencies between the tests
if (CURTEST_TEST_DEPENDS)
set_tests_properties(${_FANCY} PROPERTIES DEPENDS "${CURTEST_TEST_DEPENDS}")
set_tests_properties(${TestName} PROPERTIES DEPENDS "${CURTEST_TEST_DEPENDS}")
endif()
# tell ctest how many cores it should reserve to run the test
if (CURTEST_PROCESSORS)
set_tests_properties(${_FANCY} PROPERTIES PROCESSORS "${CURTEST_PROCESSORS}")
set_tests_properties(${TestName} PROPERTIES PROCESSORS "${CURTEST_PROCESSORS}")
endif()
endif()

2
debian/changelog vendored
View File

@@ -1,4 +1,4 @@
opm-common (2019.04-pre~xenial) xenial; urgency=medium
opm-common (2018.10-rfinal-2~xenial) xenial; urgency=medium
* New release

View File

@@ -5,8 +5,8 @@
Module: opm-common
Description: Open Porous Media Initiative shared infrastructure
Version: 2019.10-pre
Label: 2019.10-pre
Version: 2018.10
Label: 2018.10
Maintainer: opm@opm-project.org
MaintainerName: OPM community
Url: http://opm-project.org

View File

@@ -11,7 +11,7 @@ _ewoms_parameter_completor()
cmd="${COMP_WORDS[0]}"
cur="${COMP_WORDS[COMP_CWORD]}"
fullcmd="$(which "$cmd" 2> /dev/null)"
fullcmd="$(which "$cmd")"
ALL_OPTS=$("$fullcmd" --help 2> /dev/null | grep '^ *--' | sed 's/ *\(--[a-zA-Z0-9\-]*\)=.*/\1=/')
ALL_OPTS=$(echo "$ALL_OPTS" | sed 's/^ *--help.*/--help/')
COMPREPLY=( $(compgen -A file -W "$ALL_OPTS" -- "${cur}") )
@@ -32,7 +32,7 @@ _ewoms_generic_parameter_completor()
cmd="${COMP_WORDS[0]}"
cur="${COMP_WORDS[COMP_CWORD]}"
fullcmd="$(which "$cmd" 2> /dev/null)"
fullcmd="$(which "$cmd")"
if test -z "$fullcmd" || \
! test -x "$fullcmd" || \
(! test -f "$fullcmd" && ! test -h "$fullcmd" ) || \

View File

@@ -1,53 +0,0 @@
/*
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 <opm/output/eclipse/EclipseIO.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/msim/msim.hpp>
int main(int /* argc */, char** argv) {
std::string deck_file = argv[1];
Opm::Parser parser;
Opm::ParseContext parse_context;
Opm::ErrorGuard error_guard;
Opm::Deck deck = parser.parseFile(deck_file, parse_context, error_guard);
Opm::EclipseState state(deck, parse_context, error_guard);
Opm::Schedule schedule(deck, state.getInputGrid(), state.get3DProperties(), state.runspec(), parse_context, error_guard);
Opm::SummaryConfig summary_config(deck, schedule, state.getTableManager(), parse_context, error_guard);
if (error_guard) {
error_guard.dump();
error_guard.terminate();
}
Opm::msim msim(state);
Opm::EclipseIO io(state, state.getInputGrid(), schedule, summary_config);
msim.run(schedule, io);
}

View File

@@ -1,157 +0,0 @@
/*
Copyright 2019 Equinor 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 <getopt.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
struct keyword {
keyword(const std::string& name, const std::string& filename, std::size_t line_number, std::size_t content_hash) :
name(name),
filename(filename),
line_number(line_number),
content_hash(content_hash)
{}
std::string name;
std::string filename;
std::size_t line_number;
std::size_t content_hash;
};
std::vector<keyword> load_deck(const char * deck_file) {
Opm::ParseContext parseContext;
Opm::ErrorGuard errors;
Opm::Parser parser;
std::vector<keyword> keywords;
/* Use the same default ParseContext as flow. */
parseContext.update(Opm::ParseContext::PARSE_RANDOM_SLASH, Opm::InputError::IGNORE);
parseContext.update(Opm::ParseContext::PARSE_MISSING_DIMS_KEYWORD, Opm::InputError::WARN);
parseContext.update(Opm::ParseContext::SUMMARY_UNKNOWN_WELL, Opm::InputError::WARN);
parseContext.update(Opm::ParseContext::SUMMARY_UNKNOWN_GROUP, Opm::InputError::WARN);
auto deck = parser.parseFile(deck_file, parseContext, errors);
for (const auto& kw : deck) {
std::stringstream ss;
ss << kw;
keywords.emplace_back(kw.name(), kw.getFileName(), kw.getLineNumber(), std::hash<std::string>{}(ss.str()));
}
return keywords;
}
std::size_t deck_hash(const std::vector<keyword>& keywords) {
std::stringstream ss;
for (const auto& kw : keywords)
ss << kw.content_hash;
return std::hash<std::string>{}(ss.str());
}
void print_keywords(const std::vector<keyword>& keywords, bool location_info) {
for (const auto& kw : keywords) {
if (location_info)
std::cout << std::setw(8) << std::left << kw.name << " : " << kw.filename << ":" << kw.line_number << " " << kw.content_hash << std::endl;
else
std::cout << std::setw(8) << std::left << kw.name << " : " << kw.content_hash << std::endl;
}
std::cout << std::endl;
std::cout << std::setw(8) << std::left << "Total" << " : " << deck_hash(keywords) << std::endl;
}
void print_help_and_exit() {
const char * help_text = R"(The purpose of the opmhash program is to load a deck and create a summary, by
diffing two such summaries it is simple to determine if two decks are similar.
For each keyword a hash of the normalized content is calculated. The output of
the program will look like this:
RUNSPEC : 13167205945009276792
TITLE : 16047371705964514902
DIMENS : 1264233216877515756
NONNC : 10052807539267647959
OIL : 6013609912232720008
WATER : 14106203893673265964
Total : 7362809723723482303
Where the 'random' integer following each keyword is the hash of the content of
that keyword. The hashing is insensitive to changes in white-space and comments
and file location. At the bottom comes a total hash of the complete content. The
hash of each keyword is insensitive to shuffling of keywords, but the total hash
depends on the keyword order.
Options:
-l : Add filename and linenumber information to each keyword.
-s : Short form - only print the hash of the complete deck.
)";
std::cerr << help_text << std::endl;
exit(1);
}
int main(int argc, char** argv) {
int arg_offset = 1;
bool location_info = false;
bool short_form = false;
while (true) {
int c;
c = getopt(argc, argv, "ls");
if (c == -1)
break;
switch(c) {
case 'l':
location_info = true;
break;
case 's':
short_form = true;
break;
}
}
arg_offset = optind;
if (arg_offset >= argc)
print_help_and_exit();
auto keywords = load_deck(argv[arg_offset]);
if (short_form)
std::cout << deck_hash(keywords) << std::endl;
else
print_keywords(keywords, location_info);
}

View File

@@ -21,7 +21,6 @@
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
@@ -31,16 +30,16 @@
inline void loadDeck( const char * deck_file) {
Opm::ParseContext parseContext;
Opm::ErrorGuard errors;
Opm::Parser parser;
std::cout << "Loading deck: " << deck_file << " ..... "; std::cout.flush();
auto deck = parser.parseFile(deck_file, parseContext, errors);
auto deck = parser.parseFile(deck_file, parseContext);
std::cout << "parse complete - creating EclipseState .... "; std::cout.flush();
Opm::EclipseState state( deck, parseContext, errors );
Opm::Schedule schedule( deck, state.getInputGrid(), state.get3DProperties(), state.runspec(), parseContext, errors);
Opm::SummaryConfig summary( deck, schedule, state.getTableManager( ), parseContext, errors );
Opm::EclipseState state( deck, parseContext );
Opm::Schedule schedule( deck, state.getInputGrid(), state.get3DProperties(), state.runspec().phases(), parseContext);
Opm::SummaryConfig summary( deck, schedule, state.getTableManager( ), parseContext );
std::cout << "complete." << std::endl;
}

View File

@@ -22,7 +22,6 @@
#include <boost/filesystem.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/InputErrorAction.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@@ -30,10 +29,9 @@
inline void pack_deck( const char * deck_file, std::ostream& os) {
Opm::ParseContext parseContext(Opm::InputError::WARN);
Opm::ErrorGuard errors;
Opm::Parser parser;
auto deck = parser.parseFile(deck_file, parseContext, errors);
auto deck = parser.parseFile(deck_file, parseContext);
os << deck;
}

View File

@@ -1,186 +0,0 @@
/*
Copyright 2019 Equinor 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 "EGrid.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <string>
#include <string.h>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <algorithm>
#include <numeric>
EGrid::EGrid(const std::string &filename) : EclFile(filename)
{
EclFile file(filename);
auto gridhead = get<int>("GRIDHEAD");
nijk[0] = gridhead[1];
nijk[1] = gridhead[2];
nijk[2] = gridhead[3];
if (file.hasKey("ACTNUM")) {
auto actnum = get<int>("ACTNUM");
nactive = 0;
for (unsigned int i = 0; i < actnum.size(); i++) {
if (actnum[i] > 0) {
act_index.push_back(nactive);
glob_index.push_back(i);
nactive++;
} else {
act_index.push_back(-1);
}
}
} else {
int nCells = nijk[0] * nijk[1] * nijk[2];
act_index.resize(nCells);
glob_index.resize(nCells);
std::iota(act_index.begin(), act_index.end(), 0);
std::iota(glob_index.begin(), glob_index.end(), 0);
}
coord_array = get<float>("COORD");
zcorn_array = get<float>("ZCORN");
}
int EGrid::global_index(int i, int j, int k) const
{
if (i < 0 || i >= nijk[0] || j < 0 || j >= nijk[1] || k < 0 || k >= nijk[2]) {
OPM_THROW(std::invalid_argument, "i, j or/and k out of range");
}
return i + j * nijk[0] + k * nijk[0] * nijk[1];
}
int EGrid::active_index(int i, int j, int k) const
{
int n = i + j * nijk[0] + k * nijk[0] * nijk[1];
if (i < 0 || i >= nijk[0] || j < 0 || j >= nijk[1] || k < 0 || k >= nijk[2]) {
OPM_THROW(std::invalid_argument, "i, j or/and k out of range");
}
return act_index[n];
}
std::array<int, 3> EGrid::ijk_from_active_index(int actInd) const
{
if (actInd < 0 || actInd >= nactive) {
OPM_THROW(std::invalid_argument, "active index out of range");
}
int _glob = glob_index[actInd];
std::array<int, 3> result;
result[2] = _glob / (nijk[0] * nijk[1]);
int rest = _glob % (nijk[0] * nijk[1]);
result[1] = rest / nijk[0];
result[0] = rest % nijk[0];
return result;
}
std::array<int, 3> EGrid::ijk_from_global_index(int globInd) const
{
if (globInd < 0 || globInd >= nijk[0] * nijk[1] * nijk[2]) {
OPM_THROW(std::invalid_argument, "global index out of range");
}
std::array<int, 3> result;
result[2] = globInd / (nijk[0] * nijk[1]);
int rest = globInd % (nijk[0] * nijk[1]);
result[1] = rest / nijk[0];
result[0] = rest % nijk[0];
return result;
}
void EGrid::getCellCorners(const std::array<int, 3>& ijk,
std::vector<double>& X,
std::vector<double>& Y,
std::vector<double>& Z) const
{
std::vector<int> zind;
std::vector<int> pind;
if (X.size() < 8 || Y.size() < 8 || Z.size() < 8) {
OPM_THROW(std::invalid_argument,
"In routine cellConrner. X, Y and Z should be a vector of size 8");
}
if (ijk[0] < 0 || ijk[0] >= nijk[0] || ijk[1] < 0 || ijk[1] >= nijk[1] || ijk[2] < 0 || ijk[2] >= nijk[2]) {
OPM_THROW(std::invalid_argument, "i, j and/or k out of range");
}
// calculate indices for grid pillars in COORD arrray
pind.push_back(ijk[1]*(nijk[0]+1)*6 + ijk[0]*6);
pind.push_back(pind[0] + 6);
pind.push_back(pind[0] + (nijk[0]+1)*6);
pind.push_back(pind[2] + 6);
// get depths from zcorn array in ZCORN array
zind.push_back(ijk[2]*nijk[0]*nijk[1]*8 + ijk[1]*nijk[0]*4 + ijk[0]*2);
zind.push_back(zind[0] + 1);
zind.push_back(zind[0] + nijk[0]*2);
zind.push_back(zind[2] + 1);
for (int n = 0; n < 4; n++) {
zind.push_back(zind[n] + nijk[0]*nijk[1]*4);
}
for (int n = 0; n< 8; n++){
Z[n] = zcorn_array[zind[n]];
}
for (int n = 0; n < 4; n++) {
double xt = coord_array[pind[n]];
double yt = coord_array[pind[n] + 1];
double zt = coord_array[pind[n] + 2];
double xb = coord_array[pind[n] + 3];
double yb = coord_array[pind[n] + 4];
double zb = coord_array[pind[n]+5];
X[n] = xt + (xb-xt) / (zt-zb) * (zt - Z[n]);
X[n+4] = xt + (xb-xt) / (zt-zb) * (zt-Z[n+4]);
Y[n] = yt+(yb-yt)/(zt-zb)*(zt-Z[n]);
Y[n+4] = yt+(yb-yt)/(zt-zb)*(zt-Z[n+4]);
}
}
void EGrid::getCellCorners(int globindex, std::vector<double>& X,
std::vector<double>& Y, std::vector<double>& Z) const
{
return getCellCorners(ijk_from_global_index(globindex),X,Y,Z);
}

View File

@@ -1,62 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef EGRID_HPP
#define EGRID_HPP
#include "EclFile.hpp"
#include <array>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
class EGrid : public EclFile
{
public:
explicit EGrid(const std::string& filename);
int global_index(int i, int j, int k) const;
int active_index(int i, int j, int k) const;
const std::array<int, 3>& dimension() const { return nijk; }
std::array<int, 3> ijk_from_active_index(int actInd) const;
std::array<int, 3> ijk_from_global_index(int globInd) const;
void getCellCorners(int globindex, std::vector<double>& X, std::vector<double>& Y, std::vector<double>& Z) const;
void getCellCorners(const std::array<int, 3>& ijk, std::vector<double>& X, std::vector<double>& Y, std::vector<double>& Z) const;
int activeCells() const { return nactive; }
int totalNumberOfCells() const { return nijk[0] * nijk[1] * nijk[2]; }
private:
std::array<int, 3> nijk;
int nNNC, nactive;
std::vector<int> act_index;
std::vector<int> glob_index;
std::vector<float> coord_array;
std::vector<float> zcorn_array;
};
#endif

View File

@@ -1,310 +0,0 @@
/*
Copyright 2019 Equinor 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 "ERft.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <string>
#include <string.h>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <algorithm>
ERft::ERft(const std::string &filename) : EclFile(filename)
{
loadData();
std::vector<int> first;
std::vector<int> second;
std::vector<std::string> wellName;
std::vector<RftDate> dates;
auto listOfArrays = getList();
for (size_t i = 0; i < listOfArrays.size(); i++) {
std::string name = std::get<0>(listOfArrays[i]);
if (name == "TIME") {
first.push_back(i);
auto vect1 = get<float>(i);
timeList.push_back(vect1[0]);
}
if (name == "DATE") {
auto vect1 = get<int>(i);
RftDate date(vect1[2],vect1[1],vect1[0]);
dateList.insert(date);
dates.push_back(date);
}
if (name == "WELLETC"){
auto vect1 = get<std::string>(i);
wellList.insert(vect1[1]);
wellName.push_back(vect1[1]);
}
}
for (size_t i = 0; i < first.size(); i++) {
std::pair<int,int> range;
range.first = first[i];
if (i == first.size() - 1) {
range.second = listOfArrays.size();
} else {
range.second = first[i+1];
}
arrIndexRange[i] = range;
}
numReports = first.size();
for (size_t i = 0; i < wellName.size(); i++) {
std::pair<std::string,RftDate> wellDatePair(wellName[i],dates[i]);
reportIndex[wellDatePair] = i;
rftReportList.push_back(wellDatePair);
}
}
bool ERft::hasRft(const std::string& wellName, const RftDate& date) const
{
return reportIndex.find({wellName, date}) != reportIndex.end();
}
bool ERft::hasRft(const std::string& wellName, int year, int month, int day) const
{
RftDate date(year, month, day);
return reportIndex.find({wellName,date}) != reportIndex.end();
}
int ERft::getReportIndex(const std::string& wellName, const RftDate& date) const
{
std::pair<std::string,std::tuple<int,int,int>> wellDatePair(wellName,date);
auto rIndIt = reportIndex.find(wellDatePair);
if (rIndIt == reportIndex.end()) {
int y = std::get<0>(date);
int m = std::get<1>(date);
int d = std::get<2>(date);
std::string dateStr=std::to_string(y) + "/" + std::to_string(m) + "/" + std::to_string(d);
std::string message="RFT data not found for well " + wellName + " at date: " + dateStr;
OPM_THROW(std::invalid_argument, message);
}
return rIndIt->second;
}
bool ERft::hasArray(const std::string& arrayName, const std::string& wellName,
const RftDate& date) const
{
int reportInd = getReportIndex(wellName, date);
auto searchInd = arrIndexRange.find(reportInd);
int fromInd = searchInd->second.first;
int toInd = searchInd->second.second;
auto it = std::find(array_name.begin()+fromInd,array_name.begin()+toInd,arrayName);
return it != array_name.begin() + toInd;
}
int ERft::getArrayIndex(const std::string& name, const std::string& wellName,
const RftDate& date) const
{
int rInd= getReportIndex(wellName, date);
auto searchInd = arrIndexRange.find(rInd);
int fromInd =searchInd->second.first;
int toInd = searchInd->second.second;
auto it=std::find(array_name.begin()+fromInd,array_name.begin()+toInd,name);
if (std::distance(array_name.begin(),it) == toInd) {
int y = std::get<0>(date);
int m = std::get<1>(date);
int d = std::get<2>(date);
std::string dateStr = std::to_string(y) + "/" + std::to_string(m) + "/" + std::to_string(d);
std::string message = "Array " + name + " not found for RFT, well: " + wellName + " date: " + dateStr;
OPM_THROW(std::invalid_argument, message);
}
return std::distance(array_name.begin(),it);
}
template<> const std::vector<float>&
ERft::getRft<float>(const std::string& name, const std::string &wellName,
const RftDate& date) const
{
int arrInd = getArrayIndex(name, wellName, date);
if (array_type[arrInd] != EIOD::REAL) {
std::string message = "Array " + name + " found in RFT file for selected date and well, but called with wrong type";
OPM_THROW(std::runtime_error, message);
}
auto search_array = real_array.find(arrInd);
return search_array->second;
}
template<> const std::vector<double>&
ERft::getRft<double>(const std::string& name, const std::string& wellName,
const RftDate& date) const
{
int arrInd = getArrayIndex(name, wellName, date);
if (array_type[arrInd] != EIOD::DOUB) {
std::string message = "Array " + name + " found in RFT file for selected date and well, but called with wrong type";
OPM_THROW(std::runtime_error, message);
}
auto search_array = doub_array.find(arrInd);
return search_array->second;
}
template<> const std::vector<int>&
ERft::getRft<int>(const std::string& name, const std::string& wellName,
const RftDate& date) const
{
int arrInd = getArrayIndex(name, wellName, date);
if (array_type[arrInd] != EIOD::INTE) {
std::string message = "Array " + name + " found in RFT file for selected date and well, but called with wrong type";
OPM_THROW(std::runtime_error, message);
}
auto search_array = inte_array.find(arrInd);
return search_array->second;
}
template<> const std::vector<bool>&
ERft::getRft<bool>(const std::string& name, const std::string& wellName,
const RftDate& date) const
{
int arrInd = getArrayIndex(name, wellName, date);
if (array_type[arrInd] != EIOD::LOGI) {
std::string message = "Array " + name + " found in RFT file for selected date and well, but called with wrong type";
OPM_THROW(std::runtime_error, message);
}
auto search_array = logi_array.find(arrInd);
return search_array->second;
}
template<> const std::vector<std::string>&
ERft::getRft<std::string>(const std::string& name, const std::string& wellName,
const RftDate& date) const
{
int arrInd = getArrayIndex(name, wellName, date);
if (array_type[arrInd] != EIOD::CHAR) {
std::string message = "Array " + name + " found in RFT file for selected date and well, but called with wrong type";
OPM_THROW(std::runtime_error, message);
}
auto search_array = char_array.find(arrInd);
return search_array->second;
}
template<> const std::vector<int>&
ERft::getRft<int>(const std::string& name, const std::string& wellName,
int year, int month, int day) const
{
return getRft<int>(name, wellName, RftDate{year, month, day});
}
template<> const std::vector<float>&
ERft::getRft<float>(const std::string& name, const std::string& wellName,
int year, int month, int day) const
{
return getRft<float>(name, wellName, RftDate{year, month, day});
}
template<> const std::vector<double>&
ERft::getRft<double>(const std::string& name, const std::string& wellName,
int year, int month, int day) const
{
return getRft<double>(name, wellName, RftDate{year, month, day});
}
template<> const std::vector<std::string>&
ERft::getRft<std::string>(const std::string& name, const std::string& wellName,
int year, int month, int day) const
{
return getRft<std::string>(name, wellName, RftDate{year, month, day});
}
template<> const std::vector<bool>&
ERft::getRft<bool>(const std::string& name, const std::string& wellName,
int year, int month, int day) const
{
return getRft<bool>(name, wellName, RftDate{year, month, day});
}
std::vector<EclFile::EclEntry> ERft::listOfRftArrays(const std::string& wellName,
const RftDate& date) const
{
std::vector<EclEntry> list;
int rInd = getReportIndex(wellName, date);
auto searchInd = arrIndexRange.find(rInd);
for (int i = searchInd->second.first; i < searchInd->second.second; i++) {
list.emplace_back(array_name[i], array_type[i], array_size[i]);
}
return list;
}
std::vector<EclFile::EclEntry> ERft::listOfRftArrays(const std::string& wellName,
int year, int month, int day) const
{
return listOfRftArrays(wellName, RftDate{year, month, day});
}
std::vector<std::string> ERft::listOfWells() const
{
return { this->wellList.begin(), this->wellList.end() };
}
std::vector<ERft::RftDate> ERft::listOfdates() const
{
return { this->dateList.begin(), this->dateList.end() };
}

View File

@@ -1,83 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef ERFT_HPP
#define ERFT_HPP
#include "EclFile.hpp"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
#include <set>
class ERft : public EclFile
{
public:
explicit ERft(const std::string &filename);
using RftDate = std::tuple<int,int,int>;
template <typename T>
const std::vector<T>& getRft(const std::string& name, const std::string& wellName,
const RftDate& date) const;
template <typename T>
const std::vector<T>& getRft(const std::string& name, const std::string& wellName,
int year, int month, int day) const;
std::vector<std::string> listOfWells() const;
std::vector<RftDate> listOfdates() const;
using RftReportList = std::vector<std::pair<std::string, RftDate>>;
const RftReportList& listOfRftReports() const { return rftReportList; }
bool hasRft(const std::string& wellName, const RftDate& date) const;
bool hasRft(const std::string& wellName, int year, int month, int day) const;
std::vector<EclEntry> listOfRftArrays(const std::string& wellName,
const RftDate& date) const;
std::vector<EclEntry> listOfRftArrays(const std::string& wellName,
int year, int month, int day) const;
bool hasArray(const std::string& arrayName, const std::string& wellName,
const RftDate& date) const;
private:
std::map<int, std::pair<int,int>> arrIndexRange;
int numReports;
std::vector<float> timeList;
std::set<std::string> wellList;
std::set<RftDate> dateList;
RftReportList rftReportList;
std::map<std::pair<std::string,RftDate>,int> reportIndex; // mapping report index to wellName and date (tupe)
int getReportIndex(const std::string& wellName, const RftDate& date) const;
int getArrayIndex(const std::string& name, const std::string& wellName,
const RftDate& date) const;
};
#endif

View File

@@ -1,178 +0,0 @@
/*
Copyright 2019 Equinor 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 "ERst.hpp"
#include <string>
#include <string.h>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <algorithm>
ERst::ERst(const std::string& filename) : EclFile(filename)
{
loadData("SEQNUM");
std::vector<int> firstIndex;
for (size_t i = 0; i < array_name.size(); i++) {
if (array_name[i] == "SEQNUM") {
auto seqn = get<int>(i);
seqnum.push_back(seqn[0]);
firstIndex.push_back(i);
}
}
for (size_t i = 0; i < seqnum.size(); i++) {
std::pair<int,int> range;
range.first = firstIndex[i];
if (i != seqnum.size() - 1) {
range.second = firstIndex[i+1];
} else {
range.second = array_name.size();
}
arrIndexRange[seqnum[i]] = range;
}
nReports = seqnum.size();
for (int i = 0; i < nReports; i++) {
reportLoaded[seqnum[i]] = false;
}
};
bool ERst::hasReportStepNumber(int number) const
{
auto search = arrIndexRange.find(number);
return search != arrIndexRange.end();
}
void ERst::loadReportStepNumber(int number)
{
if (!hasReportStepNumber(number)) {
std::string message="Trying to load non existing report step number " + std::to_string(number);
OPM_THROW(std::invalid_argument, message);
}
std::vector<int> arrayIndexList;
arrayIndexList.reserve(arrIndexRange[number].second - arrIndexRange[number].first + 1);
for (int i = arrIndexRange[number].first; i < arrIndexRange[number].second; i++) {
arrayIndexList.push_back(i);
}
loadData(arrayIndexList);
reportLoaded[number] = true;
}
std::vector<EclFile::EclEntry> ERst::listOfRstArrays(int reportStepNumber)
{
std::vector<EclEntry> list;
if (!hasReportStepNumber(reportStepNumber)) {
std::string message = "Trying to get list of arrays from non existing report step number " + std::to_string(reportStepNumber);
OPM_THROW(std::invalid_argument, message);
}
const auto& rng = this->arrIndexRange[reportStepNumber];
list.reserve(rng.second - rng.first);
for (int i = rng.first; i < rng.second; i++) {
list.emplace_back(array_name[i], array_type[i], array_size[i]);
}
return list;
}
int ERst::getArrayIndex(const std::string& name, int number) const
{
if (!hasReportStepNumber(number)) {
std::string message = "Trying to get vector " + name + " from non existing sequence " + std::to_string(number);
OPM_THROW(std::invalid_argument, message);
}
auto search = reportLoaded.find(number);
if (!search->second) {
std::string message = "Data not loaded for sequence " + std::to_string(number);
OPM_THROW(std::runtime_error, message);
}
auto range_it = arrIndexRange.find(number);
std::pair<int,int> indexRange = range_it->second;
auto it = std::find(array_name.begin() + indexRange.first,
array_name.begin() + indexRange.second, name);
if (std::distance(array_name.begin(),it) == indexRange.second) {
std::string message = "Array " + name + " not found in sequence " + std::to_string(number);
OPM_THROW(std::runtime_error, message);
}
return std::distance(array_name.begin(), it);
}
template<>
const std::vector<int>& ERst::getRst<int>(const std::string& name, int reportStepNumber)
{
int ind = getArrayIndex(name, reportStepNumber);
return getImpl(ind, EIOD::INTE, inte_array, "integer");
}
template<>
const std::vector<float>& ERst::getRst<float>(const std::string& name, int reportStepNumber)
{
int ind = getArrayIndex(name, reportStepNumber);
return getImpl(ind, EIOD::REAL, real_array, "float");
}
template<>
const std::vector<double>& ERst::getRst<double>(const std::string& name, int reportStepNumber)
{
int ind = getArrayIndex(name, reportStepNumber);
return getImpl(ind, EIOD::DOUB, doub_array, "double");
}
template<>
const std::vector<bool>& ERst::getRst<bool>(const std::string& name, int reportStepNumber)
{
int ind = getArrayIndex(name, reportStepNumber);
return getImpl(ind, EIOD::LOGI, logi_array, "bool");
}
template<>
const std::vector<std::string>& ERst::getRst<std::string>(const std::string& name, int reportStepNumber)
{
int ind = getArrayIndex(name, reportStepNumber);
return getImpl(ind, EIOD::CHAR, char_array, "string");
}

View File

@@ -1,57 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef ERST_HPP
#define ERST_HPP
#include "EclFile.hpp"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
class ERst : public EclFile
{
public:
explicit ERst(const std::string& filename);
bool hasReportStepNumber(int number) const;
void loadReportStepNumber(int number);
template <typename T>
const std::vector<T>& getRst(const std::string& name, int reportStepNumber);
const std::vector<int>& listOfReportStepNumbers() const { return seqnum; }
std::vector<EclEntry> listOfRstArrays(int reportStepNumber);
private:
int nReports;
std::vector<int> seqnum; // report step numbers, from SEQNUM array in restart file
std::unordered_map<int,bool> reportLoaded;
std::map<int, std::pair<int,int>> arrIndexRange; // mapping report step number to array indeces (start and end)
int getArrayIndex(const std::string& name, int seqnum) const;
};
#endif

View File

@@ -1,431 +0,0 @@
/*
Copyright 2019 Equinor 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 <string>
#include <string.h>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <algorithm>
#include <unistd.h>
#include <limits>
#include <set>
#include "EclFile.hpp"
#include "ESmry.hpp"
/*
KEYWORDS WGNAMES NUMS | PARAM index Corresponding ERT key
------------------------------------------------+--------------------------------------------------
WGOR OP_1 0 | 0 WGOR:OP_1
FOPT +-+-+-+- 0 | 1 FOPT
WWCT OP_1 0 | 2 WWCT:OP_1
WIR OP_1 0 | 3 WIR:OP_1
WGOR WI_1 0 | 4 WWCT:OP_1
WWCT W1_1 0 | 5 WWCT:WI_1
BPR +-+-+- 12675 | 6 BPR:12675, BPR:i,j,k
RPR +-+-+- 1 | 7 RPR:1
FOPT +-+-+- 0 | 8 FOPT
GGPR NORTH 0 | 9 GGPR:NORTH
COPR OP_1 5628 | 10 COPR:OP_1:56286, COPR:OP_1:i,j,k
RXF +-+-+- 32768*R1(R2 + 10) | 11 RXF:2-3
SOFX OP_1 12675 | 12 SOFX:OP_1:12675, SOFX:OP_1:i,j,jk
*/
ESmry::ESmry(const std::string &filename, bool loadBaseRunData)
{
std::string rootN;
std::vector<int> actInd;
bool formatted=false;
char buff[1000];
getcwd( buff, 1000 );
std::string currentWorkingDir(buff);
std::string currentDir=currentWorkingDir;
std::string smspec_filen;
std::string unsmry_filen;
if (filename.substr(filename.length() - 7, 7) == ".SMSPEC") {
rootN = filename.substr(0,filename.length() -7);
} else if (filename.substr(filename.length() -8, 8) == ".FSMSPEC") {
rootN=filename.substr(0,filename.length() -8);
formatted = true;
} else {
rootN = filename;
}
path = currentWorkingDir;
updatePathAndRootName(path, rootN);
if (formatted) {
smspec_filen = path + "/" + rootN + ".FSMSPEC";
unsmry_filen = path + "/" + rootN + ".FUNSMRY";
} else {
smspec_filen = path + "/" + rootN + ".SMSPEC";
unsmry_filen = path + "/" + rootN + ".UNSMRY";
}
std::vector<std::pair<std::string,int>> smryArray;
EclFile smspec1(smspec_filen);
smspec1.loadData(); // loading all data
std::set<std::string> keywList;
std::vector<int> dimens = smspec1.get<int>("DIMENS");
nI = dimens[1];
nJ = dimens[2];
nK = dimens[3];
std::vector<std::string> restartArray = smspec1.get<std::string>("RESTART");
std::vector<std::string> keywords = smspec1.get<std::string>("KEYWORDS");
std::vector<std::string> wgnames = smspec1.get<std::string>("WGNAMES");
std::vector<int> nums = smspec1.get<int>("NUMS");
for (unsigned int i=0; i<keywords.size(); i++) {
std::string str1 = makeKeyString(keywords[i], wgnames[i], nums[i]);
if (str1.length() > 0) {
keywList.insert(str1);
}
}
std::string rstRootN = "";
std::string pathRstFile = path;
getRstString(restartArray, pathRstFile, rstRootN);
smryArray.push_back({smspec_filen, dimens[5]});
// checking if this is a restart run. Supporting nested restarts (restart, from restart, ...)
// std::set keywList is storing keywords from all runs involved
while ((rstRootN != "") && (loadBaseRunData)) {
std::string rstFile=pathRstFile+"/"+rstRootN+".SMSPEC";
EclFile smspec_rst(rstFile);
smspec_rst.loadData();
std::vector<int> dimens = smspec_rst.get<int>("DIMENS");
std::vector<std::string> restartArray = smspec_rst.get<std::string>("RESTART");
std::vector<std::string> keywords = smspec_rst.get<std::string>("KEYWORDS");
std::vector<std::string> wgnames = smspec_rst.get<std::string>("WGNAMES");
std::vector<int> nums = smspec_rst.get<int>("NUMS");
std::vector<std::string> units = smspec_rst.get<std::string>("UNITS");
for (size_t i = 0; i < keywords.size(); i++) {
std::string str1 = makeKeyString(keywords[i], wgnames[i], nums[i]);
if (str1.length() > 0) {
keywList.insert(str1);
}
}
smryArray.push_back({rstFile,dimens[5]});
getRstString(restartArray, pathRstFile, rstRootN);
}
int nFiles = static_cast<int>(smryArray.size());
// arrayInd should hold indices for each vector and runs
// n=file number, i = position in param array in file n (one array pr time step), example arrayInd[n][i] = position in keyword list (std::set)
std::vector<std::vector<int>> arrayInd;
for (int i = 0; i < nFiles; i++){
arrayInd.push_back({});
}
int n = nFiles - 1;
while (n >= 0){
auto smry = smryArray[n];
EclFile smspec(std::get<0>(smry));
smspec.loadData();
std::vector<int> dimens = smspec.get<int>("DIMENS");
nI = dimens[1];
nJ = dimens[2];
nK = dimens[3];
std::vector<std::string> keywords = smspec.get<std::string>("KEYWORDS");
std::vector<std::string> wgnames = smspec.get<std::string>("WGNAMES");
std::vector<int> nums = smspec.get<int>("NUMS");
std::vector<int> tmpVect(keywords.size(), -1);
arrayInd[n]=tmpVect;
std::set<std::string>::iterator it;
for (size_t i=0; i < keywords.size(); i++) {
std::string keyw = makeKeyString(keywords[i], wgnames[i], nums[i]);
it = std::find(keywList.begin(), keywList.end(), keyw);
if (it != keywList.end()){
arrayInd[n][i] = distance(keywList.begin(), it);
}
}
n--;
}
// param array used to stor data for the object, defined in the private section of the class
param.assign(keywList.size(), {});
int fromReportStepNumber = 0;
int reportStepNumber = 0;
int toReportStepNumber;
float time = 0.0;
int step = 0;
n = nFiles - 1;
while (n >= 0){
reportStepNumber = fromReportStepNumber;
if (n > 0) {
auto rstFrom = smryArray[n-1];
toReportStepNumber = std::get<1>(rstFrom);
} else {
toReportStepNumber = std::numeric_limits<int>::max();
}
std::string smspecFile = std::get<0>(smryArray[n]);
std::string unsmryFile = smspecFile.substr(0, smspecFile.size() - 6) + "UNSMRY";
EclFile unsmry(unsmryFile);
unsmry.loadData();
std::vector<EclFile::EclEntry> list1 = unsmry.getList();
// 2 or 3 arrays pr time step.
// If timestep is a report step: MINISTEP, PARAMS and SEQHDR
// else : MINISTEP and PARAMS
// if summary file starts with a SEQHDR, this will be ignored
int i = 0;
if (std::get<0>(list1[0]) == "SEQHDR") {
i = 1;
}
while (i < static_cast<int>(list1.size())){
if (std::get<0>(list1[i]) != "MINISTEP"){
std::string message="Reading summary file, expecting keyword MINISTEP, found '" + std::get<0>(list1[i]) + "'";
throw std::invalid_argument(message);
}
std::vector<int> ministep = unsmry.get<int>(i);
i++;
if (std::get<0>(list1[i]) != "PARAMS") {
std::string message="Reading summary file, expecting keyword PARAMS, found '" + std::get<0>(list1[i]) + "'";
throw std::invalid_argument(message);
}
std::vector<float> tmpData = unsmry.get<float>(i);
time = tmpData[0];
if (time == 0.0) {
seqTime.push_back(time);
seqIndex.push_back(step);
}
i++;
if (i < static_cast<int>(list1.size())){
if (std::get<0>(list1[i]) == "SEQHDR") {
i++;
reportStepNumber++;
seqTime.push_back(time);
seqIndex.push_back(step);
}
} else {
reportStepNumber++;
seqTime.push_back(time);
seqIndex.push_back(step);
}
// adding defaut values (0.0) in case vector not found in this particular summary file
for (size_t i = 0; i < param.size(); i++){
param[i].push_back(0.0);
}
for (size_t j = 0; j < tmpData.size(); j++) {
int ind = arrayInd[n][j];
if (ind > -1) {
param[ind][step] = tmpData[j];
}
}
if (reportStepNumber >= toReportStepNumber) {
i = static_cast<int>(list1.size());
}
step++;
}
fromReportStepNumber = toReportStepNumber;
n--;
}
nVect = keywList.size();
for (auto keyw : keywList){
keyword.push_back(keyw);
}
};
void ESmry::getRstString(const std::vector<std::string>& restartArray, std::string& pathRst, std::string& rootN) const {
rootN = "";
for (auto str : restartArray) {
rootN = rootN + str;
}
updatePathAndRootName(pathRst, rootN);
}
void ESmry::updatePathAndRootName(std::string& dir, std::string& rootN) const {
if (rootN.substr(0,2) == "./") {
rootN = rootN.substr(2, rootN.size() - 2);
}
if (rootN.substr(0,1) == "/") {
int p = rootN.find_last_of("/");
dir = rootN.substr(0, p);
rootN = rootN.substr(p + 1, rootN.size() - p - 1);
} else if (rootN.find_first_of("/") != std::string::npos) {
int p = rootN.find_last_of("/");
dir = dir + "/" + rootN.substr(0, p);
rootN = rootN.substr(p + 1, rootN.size() - p - 1);
};
}
bool ESmry::hasKey(const std::string &key) const
{
return std::find(keyword.begin(), keyword.end(), key) != keyword.end();
}
void ESmry::ijk_from_global_index(int glob,int &i,int &j,int &k)
{
int tmpGlob = glob - 1;
k = 1 + tmpGlob / (nI * nJ);
int rest = tmpGlob % (nI * nJ);
j = 1 + rest / nI;
i = 1 + rest % nI;
}
std::string ESmry::makeKeyString(const std::string &keyword, const std::string &wgname, int num)
{
std::string keyStr;
std::vector<std::string> segmExcep= {"STEPTYPE", "SEPARATE", "SUMTHIN"};
if (keyword.substr(0, 1) == "A") {
keyStr = keyword + ":" + std::to_string(num);
} else if (keyword.substr(0, 1) == "B") {
int _i,_j,_k;
ijk_from_global_index(num, _i, _j, _k);
keyStr = keyword + ":" + std::to_string(_i) + "," + std::to_string(_j) + "," + std::to_string(_k);
} else if (keyword.substr(0, 1) == "C") {
int _i,_j,_k;
if (num > 0) {
ijk_from_global_index(num, _i, _j, _k);
keyStr = keyword + ":" + wgname+ ":" + std::to_string(_i) + "," + std::to_string(_j) + "," + std::to_string(_k);
}
} else if (keyword.substr(0, 1) == "G") {
if ( wgname != ":+:+:+:+") {
keyStr = keyword + ":" + wgname;
}
} else if (keyword.substr(0, 1) == "R" && keyword.substr(2, 1) == "F") {
// NUMS = R1 + 32768*(R2 + 10)
int r2 = 0;
int y = 32768 * (r2 + 10) - num;
while (y <0 ) {
r2++;
y = 32768 * (r2 + 10) - num;
}
r2--;
int r1 = num - 32768 * (r2 + 10);
keyStr = keyword + ":" + std::to_string(r1) + "-" + std::to_string(r2);
} else if (keyword.substr(0, 1) == "R") {
keyStr = keyword + ":" + std::to_string(num);
} else if (keyword.substr(0, 1) == "S") {
auto it = std::find(segmExcep.begin(), segmExcep.end(), keyword);
if (it != segmExcep.end()) {
keyStr = keyword;
} else {
keyStr = keyword + ":" + wgname + ":" + std::to_string(num);
}
} else if (keyword.substr(0,1) == "W") {
if (wgname != ":+:+:+:+") {
keyStr = keyword + ":" + wgname;
}
} else {
keyStr = keyword;
}
return keyStr;
}
const std::vector<float>& ESmry::get(const std::string& name) const
{
auto it = std::find(keyword.begin(), keyword.end(), name);
if (it == keyword.end()) {
std::string message="keyword " + name + " not found ";
OPM_THROW(std::invalid_argument, message);
}
int ind = std::distance(keyword.begin(), it);
return param[ind];
}

View File

@@ -1,60 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef ESMRY_HPP
#define ESMRY_HPP
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
class ESmry
{
public:
explicit ESmry(const std::string& filename, bool loadBaseRunData=false); // filename (smspec file) or file root name
const int numberOfVectors() const { return nVect; }
bool hasKey(const std::string& key) const;
const std::vector<float>& get(const std::string& name) const;
const std::vector<std::string>& keywordList() const { return keyword; }
private:
int nVect, nI, nJ, nK;
std::string path="";
void ijk_from_global_index(int glob, int &i, int &j, int &k);
std::vector<std::vector<float>> param;
std::vector<std::string> keyword;
std::vector<int> seqIndex;
std::vector<float> seqTime;
void getRstString(const std::vector<std::string> &restartArray, std::string &path, std::string &rootN) const;
void updatePathAndRootName(std::string &path, std::string &rootN) const;
std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num);
};
#endif

View File

@@ -1,824 +0,0 @@
/*
Copyright 2019 Equinor 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 "EclFile.hpp"
#include "EclUtil.hpp"
#include <array>
#include <functional>
#include <string>
#include <string.h>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <algorithm>
#include <opm/common/ErrorMacros.hpp>
// anonymous namespace for EclFile
namespace {
bool isFormatted(const std::string& filename)
{
int p = filename.find_last_of(".");
int l = filename.length();
std::string rootN = filename.substr(0,p);
std::string extension = filename.substr(p,l-p);
return extension.substr(1,1) == "F" || extension.substr(1,1) == "A";
}
bool isEOF(std::fstream* fileH)
{
int num;
long int pos = fileH->tellg();
fileH->read(reinterpret_cast<char*>(&num), sizeof(num));
if (fileH->eof()) {
return true;
} else {
fileH->seekg (pos);
return false;
}
}
void readBinaryHeader(std::fstream& fileH, std::string& arrName,
int& size, EIOD::eclArrType &arrType)
{
int bhead;
std::string tmpStrName(8,' ');
std::string tmpStrType(4,' ');
fileH.read(reinterpret_cast<char*>(&bhead), sizeof(bhead));
bhead = EIOD::flipEndianInt(bhead);
if (bhead != 16) {
std::string message="Error reading binary header. Expected 16 bytes of header data, found " + std::to_string(bhead);
OPM_THROW(std::runtime_error, message);
}
fileH.read(&tmpStrName[0], 8);
fileH.read(reinterpret_cast<char*>(&size), sizeof(size));
size = EIOD::flipEndianInt(size);
fileH.read(&tmpStrType[0], 4);
fileH.read(reinterpret_cast<char*>(&bhead), sizeof(bhead));
bhead = EIOD::flipEndianInt(bhead);
if (bhead != 16) {
std::string message="Error reading binary header. Expected 16 bytes of header data, found " + std::to_string(bhead);
OPM_THROW(std::runtime_error, message);
}
arrName = tmpStrName;
if (tmpStrType == "INTE")
arrType = EIOD::INTE;
else if (tmpStrType == "REAL")
arrType = EIOD::REAL;
else if (tmpStrType == "DOUB")
arrType = EIOD::DOUB;
else if (tmpStrType == "CHAR")
arrType = EIOD::CHAR;
else if (tmpStrType =="LOGI")
arrType = EIOD::LOGI;
else if (tmpStrType == "MESS")
arrType = EIOD::MESS;
else
OPM_THROW(std::runtime_error, "Error, unknown array type '" + tmpStrType +"'");
}
unsigned long int sizeOnDiskBinary(int num, EIOD::eclArrType arrType)
{
unsigned long int size = 0;
if (arrType == EIOD::MESS) {
if (num > 0) {
std::string message = "In routine calcSizeOfArray, type MESS can not have size > 0";
OPM_THROW(std::invalid_argument, message);
}
} else {
auto sizeData = EIOD::block_size_data_binary(arrType);
int sizeOfElement = std::get<0>(sizeData);
int maxBlockSize = std::get<1>(sizeData);
int maxNumberOfElements = maxBlockSize / sizeOfElement;
size = num * sizeOfElement;
size = size + ((num-1) / maxNumberOfElements) * 2 * EIOD::sizeOfInte; // 8 byte (two integers) every 1000 element
if (num > 0) {
size = size + 2 * EIOD::sizeOfInte;
}
}
return size;
}
unsigned long int sizeOnDiskFormatted(const int num, EIOD::eclArrType arrType)
{
unsigned long int size = 0;
if (arrType == EIOD::MESS) {
if (num > 0) {
OPM_THROW(std::invalid_argument, "In routine calcSizeOfArray, type MESS can not have size > 0");
}
} else {
auto sizeData = block_size_data_formatted(arrType);
int maxBlockSize = std::get<0>(sizeData);
int nColumns = std::get<1>(sizeData);
int columnWidth = std::get<2>(sizeData);
int nBlocks = num /maxBlockSize;
int sizeOfLastBlock = num % maxBlockSize;
size = 0;
if (nBlocks > 0) {
int nLinesBlock = maxBlockSize / nColumns;
int rest = maxBlockSize % nColumns;
if (rest > 0) {
nLinesBlock++;
}
long int blockSize = maxBlockSize * columnWidth + nLinesBlock;
size = nBlocks * blockSize;
}
int nLines = sizeOfLastBlock / nColumns;
int rest = sizeOfLastBlock % nColumns;
size = size + sizeOfLastBlock * columnWidth + nLines;
if (rest > 0) {
size++;
}
}
return size;
}
template<typename T, typename T2>
std::vector<T> readBinaryArray(std::fstream& fileH, const int size, EIOD::eclArrType type,
std::function<T(T2)>& flip)
{
std::vector<T> arr;
auto sizeData = block_size_data_binary(type);
int sizeOfElement = std::get<0>(sizeData);
int maxBlockSize = std::get<1>(sizeData);
int maxNumberOfElements = maxBlockSize / sizeOfElement;
arr.reserve(size);
int rest = size;
while (rest > 0) {
int dhead;
fileH.read(reinterpret_cast<char*>(&dhead), sizeof(dhead));
dhead = EIOD::flipEndianInt(dhead);
int num = dhead / sizeOfElement;
if ((num > maxNumberOfElements) || (num < 0)) {
OPM_THROW(std::runtime_error, "Error reading binary data, inconsistent header data or incorrect number of elements");
}
for (int i = 0; i < num; i++) {
T2 value;
fileH.read(reinterpret_cast<char*>(&value), sizeOfElement);
arr.push_back(flip(value));
}
rest -= num;
if (( num < maxNumberOfElements && rest != 0) ||
(num == maxNumberOfElements && rest < 0)) {
std::string message = "Error reading binary data, incorrect number of elements";
OPM_THROW(std::runtime_error, message);
}
int dtail;
fileH.read(reinterpret_cast<char*>(&dtail), sizeof(dtail));
dtail = EIOD::flipEndianInt(dtail);
if (dhead != dtail) {
OPM_THROW(std::runtime_error, "Error reading binary data, tail not matching header.");
}
}
return arr;
}
std::vector<int> readBinaryInteArray(std::fstream &fileH, const int size)
{
std::function<int(int)> f = EIOD::flipEndianInt;
return readBinaryArray<int,int>(fileH, size, EIOD::INTE, f);
}
std::vector<float> readBinaryRealArray(std::fstream& fileH, const int size)
{
std::function<float(float)> f = EIOD::flipEndianFloat;
return readBinaryArray<float,float>(fileH, size, EIOD::REAL, f);
}
std::vector<double> readBinaryDoubArray(std::fstream& fileH, const int size)
{
std::function<double(double)> f = EIOD::flipEndianDouble;
return readBinaryArray<double,double>(fileH, size, EIOD::DOUB, f);
}
std::vector<bool> readBinaryLogiArray(std::fstream &fileH, const int size)
{
std::function<bool(unsigned int)> f = [](unsigned int intVal)
{
bool value;
if (intVal == EIOD::true_value) {
value = true;
} else if (intVal == EIOD::false_value) {
value = false;
} else {
OPM_THROW(std::runtime_error, "Error reading logi value");
}
return value;
};
return readBinaryArray<bool,unsigned int>(fileH, size, EIOD::LOGI, f);
}
std::vector<std::string> readBinaryCharArray(std::fstream& fileH, const int size)
{
using Char8 = std::array<char, 8>;
std::function<std::string(Char8)> f = [](const Char8& val)
{
std::string res(val.begin(), val.end());
return EIOD::trimr(res);
};
return readBinaryArray<std::string,Char8>(fileH, size, EIOD::CHAR, f);
}
std::vector<std::string> split_string(const std::string& inputStr)
{
std::istringstream iss(inputStr);
std::vector<std::string> tokens {std::istream_iterator<std::string>{iss},
std::istream_iterator<std::string>{}
};
return tokens;
}
void readFormattedHeader(std::fstream& fileH, std::string& arrName,
int &num, EIOD::eclArrType &arrType)
{
std::string line;
getline(fileH,line);
int p1 = line.find_first_of("'");
int p2 = line.find_first_of("'",p1+1);
int p3 = line.find_first_of("'",p2+1);
int p4 = line.find_first_of("'",p3+1);
if (p1 == -1 || p2 == -1 || p3 == -1 || p4 == -1) {
OPM_THROW(std::runtime_error, "Header name and type should be enclosed with '");
}
arrName = line.substr(p1 + 1, p2 - p1 - 1);
std::string antStr = line.substr(p2 + 1, p3 - p2 - 1);
std::string arrTypeStr = line.substr(p3 + 1, p4 - p3 - 1);
num = std::stoi(antStr);
if (arrTypeStr == "INTE")
arrType = EIOD::INTE;
else if (arrTypeStr == "REAL")
arrType = EIOD::REAL;
else if (arrTypeStr == "DOUB")
arrType = EIOD::DOUB;
else if (arrTypeStr == "CHAR")
arrType = EIOD::CHAR;
else if (arrTypeStr == "LOGI")
arrType = EIOD::LOGI;
else if (arrTypeStr == "MESS")
arrType = EIOD::MESS;
else
OPM_THROW(std::runtime_error, "Error, unknown array type '" + arrTypeStr +"'");
if (arrName.size() != 8) {
OPM_THROW(std::runtime_error, "Header name should be 8 characters");
}
}
template<typename T>
std::vector<T> readFormattedArray(std::fstream& fileH, const int size,
std::function<T(const std::string&)>& process)
{
std::vector<T> arr;
std::vector<std::string> tokens;
std::string line;
int num = 0;
while (num < size) {
if (fileH.eof()) {
OPM_THROW(std::runtime_error, "End of file reached when reading array");
}
getline(fileH, line);
tokens = split_string(line);
for (const std::string& token : tokens) {
arr.push_back(process(token));
}
num = num + tokens.size();
}
return arr;
}
std::vector<int> readFormattedInteArray(std::fstream& fileH, const int size)
{
std::function<int(const std::string&)> f = [](const std::string& val)
{
return std::stoi(val);
};
return readFormattedArray(fileH, size, f);
}
std::vector<std::string> readFormattedCharArray(std::fstream& fileH, const int size)
{
if (!fileH.is_open()) {
OPM_THROW(std::runtime_error, "fstream fileH not open for reading");
}
std::vector<std::string> arr;
int num = 0;
while (num < size) {
std::string line;
getline(fileH, line);
if (line.empty()) {
std::string message="Reading formatted char array, end of file or blank line, read " + std::to_string(arr.size()) + " of " + std::to_string(size) + " elements";
OPM_THROW(std::runtime_error, message);
}
int p1 = line.find_first_of("'");
if (p1 == -1) {
std::string message="Reading formatted char array, all strings must be enclosed by apostrophe (')";
OPM_THROW(std::runtime_error, message);
}
while (p1 > -1) {
int p2 = line.find_first_of("'", p1 + 1);
if (p2 == -1) {
std::string message="Reading formatted char array, all strings must be enclosed by apostrophe (')";
OPM_THROW(std::runtime_error, message);
}
std::string value = line.substr(p1 + 1, p2 - p1 - 1);
if (value.size() != 8) {
std::string message="Reading formatted char array, all strings should have 8 characters";
OPM_THROW(std::runtime_error, message);
}
if (value == " ") {
arr.push_back("");
} else {
arr.push_back(EIOD::trimr(value));
}
num++;
p1 = line.find_first_of("'", p2 + 1);
}
}
return arr;
}
std::vector<float> readFormattedRealArray(std::fstream &fileH, const int size)
{
std::function<float(const std::string&)> f = [](const std::string& val)
{
// tskille: temporary fix, need to be discussed. OPM flow writes numbers
// that are outside valid range for float, and function stof will fail
double dtmpv = std::stod(val);
return dtmpv;
};
return readFormattedArray<float>(fileH, size, f);
}
std::vector<bool> readFormattedLogiArray(std::fstream& fileH, const int size)
{
std::function<bool(const std::string&)> f = [](const std::string& val)
{
if (val == "T") {
return true;
} else if (val == "F") {
return false;
} else {
std::string message="Could not convert '" + val + "' to a bool value ";
OPM_THROW(std::invalid_argument, message);
}
};
return readFormattedArray<bool>(fileH, size, f);
}
std::vector<double> readFormattedDoubArray(std::fstream& fileH, const int size)
{
std::function<double(const std::string&)> f = [](const std::string& value)
{
std::string val(value);
int p1 = val.find_first_of("D");
if (p1 == -1) {
p1 = val.find_first_of("-", 1);
if (p1 > -1) {
val = val.insert(p1,"E");
} else {
p1 = val.find_first_of("+", 1);
if (p1 == -1) {
std::string message="In Routine Read readFormattedDoubArray, could not convert '" + val + "' to double.";
OPM_THROW(std::invalid_argument,message);
}
val = val.insert(p1,"E");
}
} else {
val.replace(p1,1,"E");
}
return std::stod(val);
};
return readFormattedArray<double>(fileH, size, f);
}
} // anonymous namespace
EclFile::EclFile(const std::string& filename) : inputFilename(filename)
{
std::fstream fileH;
formatted = isFormatted(filename);
if (formatted) {
fileH.open(filename, std::ios::in);
} else {
fileH.open(filename, std::ios::in | std::ios::binary);
}
if (!fileH) {
std::string message="Could not open file: " + filename;
OPM_THROW(std::runtime_error, message);
}
int n = 0;
while (!isEOF(&fileH)) {
std::string arrName(8,' ');
EIOD::eclArrType arrType;
int num;
if (formatted) {
readFormattedHeader(fileH,arrName,num,arrType);
} else {
readBinaryHeader(fileH,arrName,num,arrType);
}
array_size.push_back(num);
array_type.push_back(arrType);
array_name.push_back(EIOD::trimr(arrName));
array_index[array_name[n]] = n;
unsigned long int pos = fileH.tellg();
ifStreamPos.push_back(pos);
arrayLoaded.push_back(false);
if (formatted) {
unsigned long int sizeOfNextArray = sizeOnDiskFormatted(num, arrType);
fileH.ignore(sizeOfNextArray);
} else {
unsigned long int sizeOfNextArray = sizeOnDiskBinary(num, arrType);
fileH.ignore(sizeOfNextArray);
}
n++;
};
fileH.close();
}
void EclFile::loadArray(std::fstream& fileH, int arrIndex)
{
fileH.seekg (ifStreamPos[arrIndex], fileH.beg);
if (formatted) {
switch (array_type[arrIndex]) {
case EIOD::INTE:
inte_array[arrIndex] = readFormattedInteArray(fileH, array_size[arrIndex]);
break;
case EIOD::REAL:
real_array[arrIndex] = readFormattedRealArray(fileH, array_size[arrIndex]);
break;
case EIOD::DOUB:
doub_array[arrIndex] = readFormattedDoubArray(fileH, array_size[arrIndex]);
break;
case EIOD::LOGI:
logi_array[arrIndex] = readFormattedLogiArray(fileH, array_size[arrIndex]);
break;
case EIOD::CHAR:
char_array[arrIndex] = readFormattedCharArray(fileH, array_size[arrIndex]);
break;
case EIOD::MESS:
break;
default:
OPM_THROW(std::runtime_error, "Asked to read unexpected array type");
break;
}
} else {
switch (array_type[arrIndex]) {
case EIOD::INTE:
inte_array[arrIndex] = readBinaryInteArray(fileH, array_size[arrIndex]);
break;
case EIOD::REAL:
real_array[arrIndex] = readBinaryRealArray(fileH, array_size[arrIndex]);
break;
case EIOD::DOUB:
doub_array[arrIndex] = readBinaryDoubArray(fileH, array_size[arrIndex]);
break;
case EIOD::LOGI:
logi_array[arrIndex] = readBinaryLogiArray(fileH, array_size[arrIndex]);
break;
case EIOD::CHAR:
char_array[arrIndex] = readBinaryCharArray(fileH, array_size[arrIndex]);
break;
case EIOD::MESS:
break;
default:
OPM_THROW(std::runtime_error, "Asked to read unexpected array type");
break;
}
}
arrayLoaded[arrIndex] = true;
}
void EclFile::loadData()
{
std::fstream fileH;
if (formatted) {
fileH.open(inputFilename, std::ios::in);
} else {
fileH.open(inputFilename, std::ios::in | std::ios::binary);
}
if (!fileH) {
std::string message="Could not open file: '" + inputFilename +"'";
OPM_THROW(std::runtime_error, message);
}
for (size_t i = 0; i < array_name.size(); i++) {
loadArray(fileH, i);
}
fileH.close();
}
void EclFile::loadData(const std::string& name)
{
std::fstream fileH;
if (formatted) {
fileH.open(inputFilename, std::ios::in);
} else {
fileH.open(inputFilename, std::ios::in | std::ios::binary);
}
if (!fileH) {
std::string message="Could not open file: '" + inputFilename +"'";
OPM_THROW(std::runtime_error, message);
}
for (size_t i = 0; i < array_name.size(); i++) {
if (array_name[i] == name) {
loadArray(fileH, i);
}
}
fileH.close();
}
void EclFile::loadData(const std::vector<int>& arrIndex)
{
std::fstream fileH;
if (formatted) {
fileH.open(inputFilename, std::ios::in);
} else {
fileH.open(inputFilename, std::ios::in | std::ios::binary);
}
if (!fileH) {
std::string message="Could not open file: '" + inputFilename +"'";
OPM_THROW(std::runtime_error, message);
}
for (int ind : arrIndex) {
loadArray(fileH, ind);
}
fileH.close();
}
void EclFile::loadData(int arrIndex)
{
std::fstream fileH;
if (formatted) {
fileH.open(inputFilename, std::ios::in);
} else {
fileH.open(inputFilename, std::ios::in | std::ios::binary);
}
if (!fileH) {
std::string message="Could not open file: '" + inputFilename +"'";
OPM_THROW(std::runtime_error, message);
}
loadArray(fileH, arrIndex);
fileH.close();
}
std::vector<EclFile::EclEntry> EclFile::getList() const
{
std::vector<EclEntry> list;
list.reserve(this->array_name.size());
for (size_t i = 0; i < array_name.size(); i++) {
list.emplace_back(array_name[i], array_type[i], array_size[i]);
}
return list;
}
template<>
const std::vector<int>& EclFile::get<int>(int arrIndex)
{
return getImpl(arrIndex, EIOD::INTE, inte_array, "integer");
}
template<>
const std::vector<float>&
EclFile::get<float>(int arrIndex)
{
return getImpl(arrIndex, EIOD::REAL, real_array, "float");
}
template<>
const std::vector<double> &EclFile::get<double>(int arrIndex)
{
return getImpl(arrIndex, EIOD::DOUB, doub_array, "double");
}
template<>
const std::vector<bool>& EclFile::get<bool>(int arrIndex)
{
return getImpl(arrIndex, EIOD::LOGI, logi_array, "bool");
}
template<>
const std::vector<std::string>& EclFile::get<std::string>(int arrIndex)
{
return getImpl(arrIndex, EIOD::CHAR, char_array, "string");
}
bool EclFile::hasKey(const std::string &name) const
{
auto search = array_index.find(name);
return search != array_index.end();
}
template<>
const std::vector<int>& EclFile::get<int>(const std::string& name)
{
auto search = array_index.find(name);
if (search == array_index.end()) {
std::string message="key '"+name + "' not found";
OPM_THROW(std::invalid_argument, message);
}
return getImpl(search->second, EIOD::INTE, inte_array, "integer");
}
template<>
const std::vector<float>& EclFile::get<float>(const std::string& name)
{
auto search = array_index.find(name);
if (search == array_index.end()) {
std::string message="key '"+name + "' not found";
OPM_THROW(std::invalid_argument, message);
}
return getImpl(search->second, EIOD::REAL, real_array, "float");
}
template<>
const std::vector<double>& EclFile::get<double>(const std::string &name)
{
auto search = array_index.find(name);
if (search == array_index.end()) {
std::string message="key '"+name + "' not found";
OPM_THROW(std::invalid_argument, message);
}
return getImpl(search->second, EIOD::DOUB, doub_array, "double");
}
template<>
const std::vector<bool>& EclFile::get<bool>(const std::string &name)
{
auto search = array_index.find(name);
if (search == array_index.end()) {
std::string message="key '"+name + "' not found";
OPM_THROW(std::invalid_argument, message);
}
return getImpl(search->second, EIOD::LOGI, logi_array, "bool");
}
template<>
const std::vector<std::string>& EclFile::get<std::string>(const std::string &name)
{
auto search = array_index.find(name);
if (search == array_index.end()) {
std::string message="key '"+name + "' not found";
OPM_THROW(std::invalid_argument, message);
}
return getImpl(search->second, EIOD::CHAR, char_array, "string");
}

View File

@@ -1,110 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef ECLFILE_HPP
#define ECLFILE_HPP
#include <opm/common/ErrorMacros.hpp>
#include <examples/test_util/data/EclIOdata.hpp>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
#include <unordered_map>
#include <stdio.h>
namespace EIOD = Opm::ecl;
class EclFile
{
public:
explicit EclFile(const std::string& filename);
bool formattedInput() { return formatted; }
void loadData(); // load all data
void loadData(const std::string& arrName); // load all arrays with array name equal to arrName
void loadData(int arrIndex); // load data based on array indices in vector arrIndex
void loadData(const std::vector<int>& arrIndex); // load data based on array indices in vector arrIndex
void clearData()
{
inte_array.clear();
real_array.clear();
doub_array.clear();
logi_array.clear();
char_array.clear();
}
using EclEntry = std::tuple<std::string, EIOD::eclArrType, int>;
std::vector<EclEntry> getList() const;
template <typename T>
const std::vector<T>& get(int arrIndex);
template <typename T>
const std::vector<T>& get(const std::string& name);
bool hasKey(const std::string &name) const;
const std::vector<std::string>& arrayNames() const { return array_name; }
protected:
bool formatted;
std::string inputFilename;
std::unordered_map<int, std::vector<int>> inte_array;
std::unordered_map<int, std::vector<bool>> logi_array;
std::unordered_map<int, std::vector<double>> doub_array;
std::unordered_map<int, std::vector<float>> real_array;
std::unordered_map<int, std::vector<std::string>> char_array;
std::vector<std::string> array_name;
std::vector<EIOD::eclArrType> array_type;
std::vector<int> array_size;
std::vector<unsigned long int> ifStreamPos;
std::map<std::string, int> array_index;
template<class T>
const std::vector<T>& getImpl(int arrIndex, EIOD::eclArrType type,
const std::unordered_map<int, std::vector<T>>& array,
const std::string& typeStr)
{
if (array_type[arrIndex] != type) {
std::string message = "Array with index " + std::to_string(arrIndex) + " is not of type " + typeStr;
OPM_THROW(std::runtime_error, message);
}
if (!arrayLoaded[arrIndex]) {
loadData(arrIndex);
}
return array.find(arrIndex)->second;
}
private:
std::vector<bool> arrayLoaded;
void loadArray(std::fstream& fileH, int arrIndex);
};
#endif

View File

@@ -18,6 +18,7 @@
#include "EclFilesComparator.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/utility/numeric/calculateCellVol.hpp>
#include <stdio.h>
@@ -27,8 +28,13 @@
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <type_traits>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_type.h>
#include <ert/ecl_well/well_info.h>
// helper macro to handle error throws or not
#define HANDLE_ERROR(type, message) \
@@ -42,70 +48,203 @@
}
template <typename T>
void ECLFilesComparator::printValuesForCell(const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const T& value1, const T& value2) const {
namespace {
/*
This is just a basic survival test; we verify that the ERT well
loader which is used in Resinsight can load the well description
from the restart file.
*/
int nActive = -1;
int nTot = -1;
if (grid) {
nActive = grid->activeCells();
nTot = grid->totalNumberOfCells();
void loadWells( const ecl_grid_type * grid , ecl_file_type * rst_file ) {
well_info_type * well_info = well_info_alloc( grid );
well_info_add_UNRST_wells2( well_info , ecl_file_get_global_view( rst_file ), true );
well_info_free( well_info );
}
if (static_cast<int>(kw_size) == nActive) {
auto ijk = grid->ijk_from_active_index(cell);
}
ijk[0]++, ijk[1]++, ijk[2]++;
void ECLFilesComparator::keywordValidForComparing(const std::string& keyword) const {
auto it = std::find(keywords1.begin(), keywords1.end(), keyword);
if (it == keywords1.end()) {
OPM_THROW(std::runtime_error, "Keyword " << keyword << " does not exist in first file.");
}
it = find(keywords2.begin(), keywords2.end(), keyword);
if (it == keywords2.end()) {
OPM_THROW(std::runtime_error, "Keyword " << keyword << " does not exist in second file.");
}
}
unsigned int ECLFilesComparator::getEclKeywordData(ecl_kw_type*& ecl_kw1, ecl_kw_type*& ecl_kw2, const std::string& keyword, int occurrence1, int occurrence2) const {
ecl_kw1 = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), occurrence1);
ecl_kw2 = ecl_file_iget_named_kw(ecl_file2, keyword.c_str(), occurrence2);
const unsigned int numCells1 = ecl_kw_get_size(ecl_kw1);
const unsigned int numCells2 = ecl_kw_get_size(ecl_kw2);
if (numCells1 != numCells2) {
OPM_THROW(std::runtime_error, "For keyword " << keyword << ":"
<< "\nOccurrence in first file " << occurrence1
<< "\nOccurrence in second file " << occurrence2
<< "\nCells in first file: " << numCells1
<< "\nCells in second file: " << numCells2
<< "\nThe number of cells differ.");
}
return numCells1;
}
template <typename T>
void ECLFilesComparator::printValuesForCell(const std::string& /*keyword*/, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const T& value1, const T& value2) const {
if (kw_size == static_cast<size_t>(ecl_grid_get_active_size(ecl_grid1))) {
int i, j, k;
ecl_grid_get_ijk1A(ecl_grid1, cell, &i, &j, &k);
// Coordinates from this function are zero-based, hence incrementing
i++, j++, k++;
std::cout << std::endl
<< "\nKeyword: " << keyword << ", origin " << reference << "\n"
<< "Global index (zero based) = " << cell << "\n"
<< "Grid coordinate = (" << ijk[0] << ", " << ijk[1] << ", " << ijk[2] << ")" << "\n"
<< "Occurrence in first file = " << occurrence1 << "\n"
<< "Occurrence in second file = " << occurrence2 << "\n"
<< "Value index = " << cell << "\n"
<< "Grid coordinate = (" << i << ", " << j << ", " << k << ")" << "\n"
<< "(first value, second value) = (" << value1 << ", " << value2 << ")\n\n";
return;
}
if (static_cast<int>(kw_size) == nTot) {
auto ijk = grid->ijk_from_global_index(cell);
ijk[0]++, ijk[1]++, ijk[2]++;
if (kw_size == static_cast<size_t>(ecl_grid_get_global_size(ecl_grid1))) {
int i, j, k;
ecl_grid_get_ijk1(ecl_grid1, cell, &i, &j, &k);
// Coordinates from this function are zero-based, hence incrementing
i++, j++, k++;
std::cout << std::endl
<< "\nKeyword: " << keyword << ", origin " << reference << "\n\n"
<< "Global index (zero based) = " << cell << "\n"
<< "Grid coordinate = (" << ijk[0] << ", " << ijk[1] << ", " << ijk[2] << ")" << "\n"
<< "Occurrence in first file = " << occurrence1 << "\n"
<< "Occurrence in second file = " << occurrence2 << "\n"
<< "Value index = " << cell << "\n"
<< "Grid coordinate = (" << i << ", " << j << ", " << k << ")" << "\n"
<< "(first value, second value) = (" << value1 << ", " << value2 << ")\n\n";
return;
}
std::cout << std::endl
<< "\nKeyword: " << keyword << ", origin " << reference << "\n\n"
<< "Occurrence in first file = " << occurrence1 << "\n"
<< "Occurrence in second file = " << occurrence2 << "\n"
<< "Value index = " << cell << "\n"
<< "(first value, second value) = (" << value1 << ", " << value2 << ")\n\n";
}
template void ECLFilesComparator::printValuesForCell<bool> (const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const bool& value1, const bool& value2) const;
template void ECLFilesComparator::printValuesForCell<int> (const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const int& value1, const int& value2) const;
template void ECLFilesComparator::printValuesForCell<double> (const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const double& value1, const double& value2) const;
template void ECLFilesComparator::printValuesForCell<std::string>(const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const std::string& value1, const std::string& value2) const;
// Hack to work around case where std::vector<bool>::const_reference is not a bool. If it is we will initialize printValuesForCell<char> otherwise printValuesForCell<std::vector<bool>::const_reference>
using boolConstReference = typename std::vector<bool>::const_reference;
using boolTypeHelper = typename std::remove_const<typename std::remove_reference<boolConstReference>::type>::type;
using boolType = typename std::conditional<std::is_same<boolTypeHelper, bool>::value, char, boolTypeHelper>::type;
template void ECLFilesComparator::printValuesForCell<boolType> (const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const boolType& value1, const boolType& value2) const;
template void ECLFilesComparator::printValuesForCell<bool> (const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const bool& value1, const bool& value2) const;
template void ECLFilesComparator::printValuesForCell<int> (const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const int& value1, const int& value2) const;
template void ECLFilesComparator::printValuesForCell<double> (const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const double& value1, const double& value2) const;
template void ECLFilesComparator::printValuesForCell<std::string>(const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const std::string& value1, const std::string& value2) const;
ECLFilesComparator::ECLFilesComparator(const std::string& basename1,
ECLFilesComparator::ECLFilesComparator(int file_type_arg, const std::string& basename1,
const std::string& basename2,
double absToleranceArg, double relToleranceArg) :
absTolerance(absToleranceArg), relTolerance(relToleranceArg) {
file_type(file_type_arg), absTolerance(absToleranceArg), relTolerance(relToleranceArg) {
rootName1 = basename1;
rootName2 = basename2;
std::string file1, file2;
if (file_type == ECL_UNIFIED_RESTART_FILE) {
file1 = basename1 + ".UNRST";
file2 = basename2 + ".UNRST";
}
else if (file_type == ECL_INIT_FILE) {
file1 = basename1 + ".INIT";
file2 = basename2 + ".INIT";
}
else if (file_type == ECL_RFT_FILE) {
file1 = basename1 + ".RFT";
file2 = basename2 + ".RFT";
}
else {
OPM_THROW(std::invalid_argument, "Unsupported filetype sent to ECLFilesComparator's constructor."
<< "Only unified restart (.UNRST), initial (.INIT) and .RFT files are supported.");
}
ecl_file1 = ecl_file_open(file1.c_str(), 0);
ecl_file2 = ecl_file_open(file2.c_str(), 0);
ecl_grid1 = ecl_grid_load_case(basename1.c_str());
ecl_grid2 = ecl_grid_load_case(basename2.c_str());
if (ecl_file1 == nullptr) {
OPM_THROW(std::invalid_argument, "Error opening first file: " << file1);
}
if (ecl_file2 == nullptr) {
OPM_THROW(std::invalid_argument, "Error opening second file: " << file2);
}
if (ecl_grid1 == nullptr) {
OPM_THROW(std::invalid_argument, "Error opening first grid file: " << basename1);
}
if (ecl_grid2 == nullptr) {
OPM_THROW(std::invalid_argument, "Error opening second grid file. " << basename2);
}
unsigned int numKeywords1 = ecl_file_get_num_distinct_kw(ecl_file1);
unsigned int numKeywords2 = ecl_file_get_num_distinct_kw(ecl_file2);
keywords1.reserve(numKeywords1);
keywords2.reserve(numKeywords2);
for (unsigned int i = 0; i < numKeywords1; ++i) {
std::string keyword(ecl_file_iget_distinct_kw(ecl_file1, i));
keywords1.push_back(keyword);
}
for (unsigned int i = 0; i < numKeywords2; ++i) {
std::string keyword(ecl_file_iget_distinct_kw(ecl_file2, i));
keywords2.push_back(keyword);
}
if (file_type == ECL_UNIFIED_RESTART_FILE) {
loadWells( ecl_grid1 , ecl_file1 );
loadWells( ecl_grid2 , ecl_file2 );
}
}
ECLFilesComparator::~ECLFilesComparator() {
ecl_file_close(ecl_file1);
ecl_file_close(ecl_file2);
ecl_grid_free(ecl_grid1);
ecl_grid_free(ecl_grid2);
}
void ECLFilesComparator::printKeywords() const {
std::cout << "\nKeywords in the first file:\n";
for (const auto& it : keywords1) {
std::cout << std::setw(15) << std::left << it << " of type " << ecl_type_get_name( ecl_file_iget_named_data_type(ecl_file1, it.c_str(), 0)) << std::endl;
}
std::cout << "\nKeywords in second file:\n";
for (const auto& it : keywords2) {
std::cout << std::setw(15) << std::left << it << " of type " << ecl_type_get_name( ecl_file_iget_named_data_type(ecl_file2, it.c_str(), 0)) << std::endl;
}
}
void ECLFilesComparator::printKeywordsDifference() const {
std::vector<std::string> common;
std::vector<std::string> uncommon;
const std::vector<std::string>* keywordsShort = &keywords1;
const std::vector<std::string>* keywordsLong = &keywords2;
if (keywords1.size() > keywords2.size()) {
keywordsLong = &keywords1;
keywordsShort = &keywords2;
}
for (const auto& it : *keywordsLong) {
const auto position = std::find(keywordsShort->begin(), keywordsShort->end(), it);
if (position != keywordsShort->end()) {
common.push_back(*position);
}
else {
uncommon.push_back(it);
}
}
std::cout << "\nCommon keywords for the two cases:\n";
for (const auto& it : common) std::cout << it << std::endl;
std::cout << "\nUncommon keywords for the two cases:\n";
for (const auto& it : uncommon) std::cout << it << std::endl;
}
Deviation ECLFilesComparator::calculateDeviations(double val1, double val2) {
val1 = std::abs(val1);
val2 = std::abs(val2);
@@ -120,15 +259,16 @@ Deviation ECLFilesComparator::calculateDeviations(double val1, double val2) {
}
double ECLFilesComparator::median(std::vector<double> vec) {
if (vec.empty()) {
return 0;
}
else {
size_t n = vec.size() / 2;
size_t n = vec.size()/2;
nth_element(vec.begin(), vec.begin() + n, vec.end());
if (vec.size() % 2 == 0) {
return 0.5 * (vec[n-1] + vec[n]);
return 0.5*(vec[n-1]+vec[n]);
}
else {
return vec[n];
@@ -137,6 +277,7 @@ double ECLFilesComparator::median(std::vector<double> vec) {
}
double ECLFilesComparator::average(const std::vector<double>& vec) {
if (vec.empty()) {
return 0;
@@ -146,3 +287,14 @@ double ECLFilesComparator::average(const std::vector<double>& vec) {
}
double ECLFilesComparator::getCellVolume(const ecl_grid_type* ecl_grid,
const int globalIndex) {
std::vector<double> x(8, 0.0);
std::vector<double> y(8, 0.0);
std::vector<double> z(8, 0.0);
for (int i = 0; i < 8; i++) {
ecl_grid_get_cell_corner_xyz1(ecl_grid, globalIndex, i, &x.data()[i], &y.data()[i], &z.data()[i]);
}
return calculateCellVol(x,y,z);
}

View File

@@ -25,61 +25,103 @@
#include <vector>
#include <string>
#include <examples/test_util/EGrid.hpp>
struct ecl_file_struct; //!< Prototype for eclipse file struct, from ERT library.
typedef struct ecl_file_struct ecl_file_type;
struct ecl_grid_struct; //!< Prototype for eclipse grid struct, from ERT library.
typedef struct ecl_grid_struct ecl_grid_type;
struct ecl_kw_struct; //!< Prototype for eclipse keyword struct, from ERT library.
typedef struct ecl_kw_struct ecl_kw_type;
/*! \brief A class for comparing ECLIPSE files.
\details ECLFilesComparator opens ECLIPSE files
(unified restart, initial and RFT in addition to grid file)
from two simulations. This class has only the functions
printKeywords() and printKeywordsDifference(), in addition to a
couple of get-functions: the comparison logic is implemented in
the subclasses RegressionTest and IntegrationTest. */
class ECLFilesComparator {
public:
ECLFilesComparator(const std::string& basename1,
const std::string& basename2,
double absTolerance, double relTolerance);
private:
int file_type;
double absTolerance = 0;
double relTolerance = 0;
protected:
ecl_file_type* ecl_file1 = nullptr;
ecl_grid_type* ecl_grid1 = nullptr;
ecl_file_type* ecl_file2 = nullptr;
ecl_grid_type* ecl_grid2 = nullptr;
std::vector<std::string> keywords1, keywords2;
bool throwOnError = true; //!< Throw on first error
bool analysis = false; //!< Perform full error analysis
std::map<std::string, std::vector<Deviation>> deviations;
mutable size_t num_errors = 0;
void throwOnErrors(bool dothrow) {
throwOnError = dothrow;
}
//! \brief Checks if the keyword exists in both cases.
//! \param[in] keyword Keyword to check.
//! \details If the keyword does not exist in one of the cases, the function throws an exception.
void keywordValidForComparing(const std::string& keyword) const;
//! \brief Stores keyword data for a given occurrence
//! \param[out] ecl_kw1 Pointer to a ecl_kw_type, which stores keyword data for first case given the occurrence.
//! \param[out] ecl_kw2 Pointer to a ecl_kw_type, which stores keyword data for second case given the occurrence.
//! \param[in] keyword Which keyword to consider.
//! \param[in] occurrence Which keyword occurrence to consider.
//! \details This function stores keyword data for the given keyword and occurrence in #ecl_kw1 and #ecl_kw2, and returns the number of cells (for which the keyword has a value at the occurrence). If the number of cells differ for the two cases, an exception is thrown.
unsigned int getEclKeywordData(ecl_kw_type*& ecl_kw1, ecl_kw_type*& ecl_kw2, const std::string& keyword, int occurrence1, int occurrence2) const;
//! \brief Prints values for a given keyword, occurrence and cell
//! \param[in] keyword Which keyword to consider.
//! \param[in] occurrence Which keyword occurrence to consider.
//! \param[in] cell Which cell occurrence to consider (numbered by global index).
//! \param[in] value1 Value for first file, the data type can be bool, int, double or std::string.
//! \param[in] value2 Value for second file, the data type can be bool, int, double or std::string.
//! \details Templatefunction for printing values when exceptions are thrown. The function is defined for bool, int, double and std::string.
template <typename T>
void printValuesForCell(const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, const T& value1, const T& value2) const;
void doAnalysis(bool analize) {
analysis = analize;
}
public:
//! \brief Open ECLIPSE files and set tolerances and keywords.
//! \param[in] file_type Specifies which filetype to be compared, possible inputs are UNRSTFILE, INITFILE and RFTFILE.
//! \param[in] basename1 Full path without file extension to the first case.
//! \param[in] basename2 Full path without file extension to the second case.
//! \param[in] absTolerance Tolerance for absolute deviation.
//! \param[in] relTolerance Tolerance for relative deviation.
//! \details The content of the ECLIPSE files specified in the input is stored in the ecl_file_type and ecl_grid_type member variables. In addition the keywords and absolute and relative tolerances (member variables) are set. If the constructor is unable to open one of the ECLIPSE files, an exception will be thrown.
ECLFilesComparator(int file_type, const std::string& basename1, const std::string& basename2, double absTolerance, double relTolerance);
//! \brief Closing the ECLIPSE files.
~ECLFilesComparator();
size_t getNoErrors() const {
return num_errors;
}
//! \brief Set whether to throw on errors or not.
void throwOnErrors(bool dothrow) { throwOnError = dothrow; }
//! \brief Returns the absolute tolerance stored as a private member variable in the class
double getAbsTolerance() const {
return absTolerance;
}
//! \brief Returns the relative tolerance stored as a private member variable in the class
double getRelTolerance() const {
return relTolerance;
}
//! \brief Set whether to perform a full error analysis.
void doAnalysis(bool analize) { analysis = analize; }
//! \brief Calculate deviations for two values.
//! \details Using absolute values of the input arguments: If one of the values are non-zero, the Deviation::abs returned is the difference between the two input values. In addition, if both values are non-zero, the Deviation::rel returned is the absolute deviation divided by the largest value.
static Deviation calculateDeviations(double val1, double val2);
//! \brief Calculate median of a vector.
//! \details Returning the median of the input vector, i.e. the middle value of the sorted vector if the number of elements is odd or the mean of the two middle values if the number of elements are even. Copy is intentional.
static double median(std::vector<double> vec);
//! \brief Calculate average of a vector.
//! \details Returning the average of the input vector, i.e. the sum of all values divided by the number of elements.
static double average(const std::vector<double>& vec);
//! \brief Returns the number of errors encountered in the performed comparisons.
size_t getNoErrors() const { return num_errors; }
protected:
std::vector<std::string> keywords1, keywords2;
bool throwOnError = true; //!< Throw on first error
bool analysis = false; //!< Perform full error analysis
std::map<std::string, std::vector<Deviation>> deviations;
mutable size_t num_errors = 0;
//! \brief Returns the ECLIPSE filetype of this
int getFileType() const {return file_type;}
//! \brief Returns the absolute tolerance stored as a private member variable in the class
double getAbsTolerance() const {return absTolerance;}
//! \brief Returns the relative tolerance stored as a private member variable in the class
double getRelTolerance() const {return relTolerance;}
std::string rootName1, rootName2;
//! \brief Print all keywords and their respective Eclipse type for the two input cases.
void printKeywords() const;
//! \brief Print common and uncommon keywords for the two input cases.
void printKeywordsDifference() const;
template <typename T>
void printValuesForCell(const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, EGrid *grid, const T& value1, const T& value2) const;
private:
double absTolerance = 0;
double relTolerance = 0;
//! \brief Calculate deviations for two values.
//! \details Using absolute values of the input arguments: If one of the values are non-zero, the Deviation::abs returned is the difference between the two input values. In addition, if both values are non-zero, the Deviation::rel returned is the absolute deviation divided by the largest value.
static Deviation calculateDeviations(double val1, double val2);
//! \brief Calculate median of a vector.
//! \details Returning the median of the input vector, i.e. the middle value of the sorted vector if the number of elements is odd or the mean of the two middle values if the number of elements are even.
static double median(std::vector<double> vec);
//! \brief Calculate average of a vector.
//! \details Returning the average of the input vector, i.e. the sum of all values divided by the number of elements.
static double average(const std::vector<double>& vec);
//! \brief Obtain the volume of a cell.
static double getCellVolume(const ecl_grid_type* ecl_grid, const int globalIndex);
};
#endif

View File

@@ -0,0 +1,199 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "EclIntegrationTest.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_type.h>
#include <ert/ecl_well/well_info.h>
// helper macro to handle error throws or not
#define HANDLE_ERROR(type, message) \
{ \
if (throwOnError) \
OPM_THROW(type, message); \
else { \
std::cerr << message << std::endl; \
++num_errors; \
} \
}
void ECLIntegrationTest::setCellVolumes() {
double absTolerance = getAbsTolerance();
double relTolerance = getRelTolerance();
const unsigned int globalGridCount1 = ecl_grid_get_global_size(ecl_grid1);
const unsigned int activeGridCount1 = ecl_grid_get_active_size(ecl_grid1);
const unsigned int globalGridCount2 = ecl_grid_get_global_size(ecl_grid2);
const unsigned int activeGridCount2 = ecl_grid_get_active_size(ecl_grid2);
if (globalGridCount1 != globalGridCount2) {
OPM_THROW(std::runtime_error, "In grid file:"
<< "\nCells in first file: " << globalGridCount1
<< "\nCells in second file: " << globalGridCount2
<< "\nThe number of global cells differ.");
}
if (activeGridCount1 != activeGridCount2) {
OPM_THROW(std::runtime_error, "In grid file:"
<< "\nCells in first file: " << activeGridCount1
<< "\nCells in second file: " << activeGridCount2
<< "\nThe number of active cells differ.");
}
for (unsigned int cell = 0; cell < globalGridCount1; ++cell) {
const double cellVolume1 = getCellVolume(ecl_grid1, cell);
const double cellVolume2 = getCellVolume(ecl_grid2, cell);
Deviation dev = calculateDeviations(cellVolume1, cellVolume2);
if (dev.abs > absTolerance && dev.rel > relTolerance) {
int i, j, k;
ecl_grid_get_ijk1(ecl_grid1, cell, &i, &j, &k);
// Coordinates from this function are zero-based, hence incrementing
i++, j++, k++;
OPM_THROW(std::runtime_error, "In grid file: Deviations of cell volume exceed tolerances. "
<< "\nFor cell with coordinate (" << i << ", " << j << ", " << k << "):"
<< "\nCell volume in first file: " << cellVolume1
<< "\nCell volume in second file: " << cellVolume2
<< "\nThe absolute deviation is " << dev.abs << ", and the tolerance limit is " << absTolerance << "."
<< "\nThe relative deviation is " << dev.rel << ", and the tolerance limit is " << relTolerance << ".");
} // The second input case is used as reference.
cellVolumes.push_back(cellVolume2);
}
}
void ECLIntegrationTest::initialOccurrenceCompare(const std::string& keyword) {
ecl_kw_type* ecl_kw1 = nullptr;
ecl_kw_type* ecl_kw2 = nullptr;
const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, 0, 0);
std::vector<double> values1(numCells);
initialCellValues.resize(numCells);
ecl_kw_get_data_as_double(ecl_kw1, values1.data());
ecl_kw_get_data_as_double(ecl_kw2, initialCellValues.data());
// This variable sums up the difference between the keyword value for the first case and the keyword value for the second case, for each cell. The sum is weighted with respect to the cell volume of each cell.
double weightedDifference = 0;
// This variable sums up the keyword value for the first case for each cell. The sum is weighted with respect to the cell volume of each cell.
double weightedTotal = 0;
for (size_t cell = 0; cell < initialCellValues.size(); ++cell) {
weightedTotal += initialCellValues[cell]*cellVolumes[cell];
weightedDifference += std::abs(values1[cell] - initialCellValues[cell])*cellVolumes[cell];
}
if (weightedTotal != 0) {
double ratioValue = weightedDifference/weightedTotal;
if ((ratioValue) > getRelTolerance()) {
OPM_THROW(std::runtime_error, "\nFor keyword " << keyword << " and occurrence 0:"
<< "\nThe ratio of the deviation and the total value is " << ratioValue
<< ", which exceeds the relative tolerance of " << getRelTolerance() << "."
<< "\nSee the docs for more information about how the ratio is computed.");
}
}
}
void ECLIntegrationTest::occurrenceCompare(const std::string& keyword, int occurrence) const {
ecl_kw_type* ecl_kw1 = nullptr;
ecl_kw_type* ecl_kw2 = nullptr;
const unsigned int numCells = getEclKeywordData(ecl_kw1, ecl_kw2, keyword, occurrence, occurrence);
std::vector<double> values1(numCells), values2(numCells);
ecl_kw_get_data_as_double(ecl_kw1, values1.data());
ecl_kw_get_data_as_double(ecl_kw2, values2.data());
// This variable sums up the difference between the keyword value for the first case and the keyword value for the second case, for each cell. The sum is weighted with respect to the cell volume of each cell.
double weightedDifference = 0;
// This variable sums up the difference between the keyword value for the occurrence and the initial keyword value for each cell. The sum is weighted with respect to the cell volume of each cell.
double relativeWeightedTotal = 0;
for (size_t cell = 0; cell < values1.size(); ++cell) {
relativeWeightedTotal += std::abs(values1[cell] - initialCellValues[cell])*cellVolumes[cell];
weightedDifference += std::abs(values1[cell] - values2[cell])*cellVolumes[cell];
}
if (relativeWeightedTotal != 0) {
double ratioValue = weightedDifference/relativeWeightedTotal;
if ((ratioValue) > getRelTolerance()) {
OPM_THROW(std::runtime_error, "\nFor keyword " << keyword << " and occurrence " << occurrence << ":"
<< "\nThe ratio of the deviation and the total value is " << ratioValue
<< ", which exceeds the relative tolerance of " << getRelTolerance() << "."
<< "\nSee the docs for more information about how the ratio is computed.");
}
}
}
ECLIntegrationTest::ECLIntegrationTest(const std::string& basename1,
const std::string& basename2,
double absTolerance, double relTolerance) :
ECLFilesComparator(ECL_UNIFIED_RESTART_FILE, basename1, basename2, absTolerance, relTolerance) {
std::cout << "\nUsing cell volumes and keyword values from case " << basename2
<< " as reference." << std::endl << std::endl;
setCellVolumes();
}
bool ECLIntegrationTest::elementInWhitelist(const std::string& keyword) const {
auto it = std::find(keywordWhitelist.begin(), keywordWhitelist.end(), keyword);
return it != keywordWhitelist.end();
}
void ECLIntegrationTest::equalNumKeywords() const {
if (keywords1.size() != keywords2.size()) {
OPM_THROW(std::runtime_error, "\nKeywords in first file: " << keywords1.size()
<< "\nKeywords in second file: " << keywords2.size()
<< "\nThe number of keywords differ.");
}
}
void ECLIntegrationTest::results() {
for (const auto& it : keywordWhitelist)
resultsForKeyword(it);
}
void ECLIntegrationTest::resultsForKeyword(const std::string& keyword) {
std::cout << "Comparing " << keyword << "...";
keywordValidForComparing(keyword);
const unsigned int occurrences1 = ecl_file_get_num_named_kw(ecl_file1, keyword.c_str());
const unsigned int occurrences2 = ecl_file_get_num_named_kw(ecl_file2, keyword.c_str());
if (occurrences1 != occurrences2) {
OPM_THROW(std::runtime_error, "For keyword " << keyword << ":"
<< "\nKeyword occurrences in first file: " << occurrences1
<< "\nKeyword occurrences in second file: " << occurrences2
<< "\nThe number of occurrences differ.");
}
initialOccurrenceCompare(keyword);
for (unsigned int occurrence = 1; occurrence < occurrences1; ++occurrence) {
occurrenceCompare(keyword, occurrence);
}
std::cout << "done." << std::endl;
}

View File

@@ -0,0 +1,78 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef ECLINTEGRATIONTEST_HPP
#define ECLINTEGRATIONTEST_HPP
#include "EclFilesComparator.hpp"
/*! \brief A class for executing a integration test for two ECLIPSE files.
\details This class inherits from ECLFilesComparator, which opens and closes
the input cases and stores keywordnames. The three public functions
equalNumKeywords(), results() and resultsForKeyword() can be invoked
to compare griddata or keyworddata for all keywords or a given
keyword (resultsForKeyword()).
*/
class ECLIntegrationTest: public ECLFilesComparator {
private:
std::vector<double> cellVolumes; //!< Vector of cell volumes in second input case (indexed by global index)
std::vector<double> initialCellValues; //!< Keyword values for all cells at first occurrence (index by global index)
// These are the only keywords which are compared, since SWAT should be "1 - SOIL - SGAS", this keyword is omitted.
const std::vector<std::string> keywordWhitelist = {"SGAS", "SWAT", "PRESSURE"};
void setCellVolumes();
void initialOccurrenceCompare(const std::string& keyword);
void occurrenceCompare(const std::string& keyword, int occurrence) const;
public:
//! \brief Sets up the integration test.
//! \param[in] basename1 Full path without file extension to the first case.
//! \param[in] basename2 Full path without file extension to the second case.
//! \param[in] absTolerance Tolerance for absolute deviation.
//! \param[in] relTolerance Tolerance for relative deviation.
//! \details This constructor calls the constructor of the superclass, with input filetype unified restart. See the docs for ECLFilesComparator for more information.
ECLIntegrationTest(const std::string& basename1, const std::string& basename2, double absTolerance, double relTolerance);
//! \brief Checks if a keyword is supported for comparison.
//! \param[in] keyword Keyword to check.
bool elementInWhitelist(const std::string& keyword) const;
//! \brief Checks if the number of keywords equal in the two input cases.
//! \param[in] keyword Keyword to check.
void equalNumKeywords() const;
//! \brief Finds deviations for all supported keywords.
//! \details results() loops through all supported keywords for integration test (defined in keywordWhitelist -- this is SGAS, SWAT and PRESSURE) and calls resultsForKeyword() for each keyword.
void results();
//! \brief Finds deviations for a specific keyword.
//! \param[in] keyword Keyword to check.
/*! \details First, resultsForKeyword() checks if the keyword exits in both cases, and if the number of keyword occurrences in the two cases differ. If these tests fail, an exception is thrown. Then deviaitons are calculated as described below for each occurrence, and an exception is thrown if the relative error ratio \f$E\f$ is larger than the relative tolerance.
* Calculation:\n
* Let the keyword values for occurrence \f$n\f$ and cell \f$i\f$ be \f$p_{n,i}\f$ and \f$q_{n,i}\f$ for input case 1 and 2, respectively.
* Consider first the initial occurrence (\f$n=0\f$). The function uses the second cases as reference, and calculates the volume weighted sum of \f$q_{0,i}\f$ over all cells \f$i\f$:
* \f[ S_0 = \sum_{i} q_{0,i} v_i \f]
* where \f$v_{i}\f$ is the volume of cell \f$i\f$ in case 2. Then, the deviations between the cases for each cell are calculated:
* \f[ \Delta = \sum_{i} |p_{0,i} - q_{0,i}| v_i.\f]
* The error ratio is then \f$E = \Delta/S_0\f$.\n
* For all other occurrences \f$n\f$, the deviation value \f$\Delta\f$ is calculated the same way, but the total value \f$S\f$ is calculated relative to the initial occurrence total \f$S_0\f$:
* \f[ S = \sum_{i} |q_{n,i} - q_{0,i}| v_i. \f]
* The error ratio is \f$ E = \Delta/S\f$. */
void resultsForKeyword(const std::string& keyword);
};
#endif

View File

@@ -1,397 +0,0 @@
/*
Copyright 2019 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 "EclOutput.hpp"
#include "EclUtil.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <stdexcept>
#include <typeinfo>
#include <sstream>
#include <stdio.h>
EclOutput::EclOutput(const std::string& inputFile, bool formatted) :
isFormatted(formatted)
{
ofileH.open(inputFile, isFormatted ? std::ios::out : std::ios::out | std::ios::binary);
}
template<>
void EclOutput::write<std::string>(const std::string& name,
const std::vector<std::string>& data)
{
if (isFormatted)
{
writeFormattedHeader(name, data.size(), EIOD::CHAR);
writeFormattedCharArray(data);
}
else
{
writeBinaryHeader(name, data.size(), EIOD::CHAR);
writeBinaryCharArray(data);
}
}
void EclOutput::writeBinaryHeader(const std::string&arrName, int size, EIOD::eclArrType arrType)
{
std::string name = arrName + std::string(8 - arrName.size(),' ');
int flippedSize = EIOD::flipEndianInt(size);
int bhead = EIOD::flipEndianInt(16);
ofileH.write(reinterpret_cast<char*>(&bhead), sizeof(bhead));
ofileH.write(name.c_str(), 8);
ofileH.write(reinterpret_cast<char*>(&flippedSize), sizeof(flippedSize));
switch(arrType) {
case EIOD::INTE:
ofileH.write("INTE", 4);
break;
case EIOD::REAL:
ofileH.write("REAL", 4);
break;
case EIOD::DOUB:
ofileH.write("DOUB", 4);
break;
case EIOD::LOGI:
ofileH.write("LOGI", 4);
break;
case EIOD::CHAR:
ofileH.write("CHAR", 4);
break;
case EIOD::MESS:
ofileH.write("MESS", 4);
break;
}
ofileH.write(reinterpret_cast<char *>(&bhead), sizeof(bhead));
}
template <typename T>
void EclOutput::writeBinaryArray(const std::vector<T>& data)
{
int rest,num,rval;
int dhead;
float value_f;
double value_d;
int intVal;
int n = 0;
int size = data.size();
EIOD::eclArrType arrType = EIOD::MESS;
if (typeid(std::vector<T>) == typeid(std::vector<int>)) {
arrType = EIOD::INTE;
} else if (typeid(std::vector<T>) == typeid(std::vector<float>)) {
arrType = EIOD::REAL;
} else if (typeid(std::vector<T>) == typeid(std::vector<double>)) {
arrType = EIOD::DOUB;
} else if (typeid(std::vector<T>) == typeid(std::vector<bool>)) {
arrType = EIOD::LOGI;
}
auto sizeData = block_size_data_binary(arrType);
int sizeOfElement = std::get<0>(sizeData);
int maxBlockSize = std::get<1>(sizeData);
int maxNumberOfElements = maxBlockSize / sizeOfElement;
if (!ofileH.is_open()) {
OPM_THROW(std::runtime_error, "fstream fileH not open for writing");
}
rest = size * sizeOfElement;
while (rest > 0) {
if (rest > maxBlockSize) {
rest -= maxBlockSize;
num = maxNumberOfElements;
} else {
num = rest / sizeOfElement;
rest = 0;
}
dhead = EIOD::flipEndianInt(num * sizeOfElement);
ofileH.write(reinterpret_cast<char*>(&dhead), sizeof(dhead));
for (int i = 0; i < num; i++) {
if (arrType == EIOD::INTE) {
rval = EIOD::flipEndianInt(data[n]);
ofileH.write(reinterpret_cast<char*>(&rval), sizeof(rval));
} else if (arrType == EIOD::REAL) {
value_f = EIOD::flipEndianFloat(data[n]);
ofileH.write(reinterpret_cast<char*>(&value_f), sizeof(value_f));
} else if (arrType == EIOD::DOUB) {
value_d = EIOD::flipEndianDouble(data[n]);
ofileH.write(reinterpret_cast<char*>(&value_d), sizeof(value_d));
} else if (arrType == EIOD::LOGI) {
intVal = data[n] ? EIOD::true_value : EIOD::false_value;
ofileH.write(reinterpret_cast<char*>(&intVal), sizeOfElement);
} else {
std::cout << "type not supported in write binaryarray" << std::endl;
exit(1);
}
n++;
}
ofileH.write(reinterpret_cast<char*>(&dhead), sizeof(dhead));
}
}
template void EclOutput::writeBinaryArray<int>(const std::vector<int>& data);
template void EclOutput::writeBinaryArray<float>(const std::vector<float>& data);
template void EclOutput::writeBinaryArray<double>(const std::vector<double>& data);
template void EclOutput::writeBinaryArray<bool>(const std::vector<bool>& data);
template void EclOutput::writeBinaryArray<char>(const std::vector<char>& data);
void EclOutput::writeBinaryCharArray(const std::vector<std::string>& data)
{
int num,dhead;
int n = 0;
int size = data.size();
auto sizeData = EIOD::block_size_data_binary(EIOD::CHAR);
int sizeOfElement = std::get<0>(sizeData);
int maxBlockSize = std::get<1>(sizeData);
int maxNumberOfElements = maxBlockSize / sizeOfElement;
int rest = size * sizeOfElement;
if (!ofileH.is_open()) {
OPM_THROW(std::runtime_error,"fstream fileH not open for writing");
}
while (rest > 0) {
if (rest > maxBlockSize) {
rest -= maxBlockSize;
num = maxNumberOfElements;
} else {
num = rest / sizeOfElement;
rest = 0;
}
dhead = EIOD::flipEndianInt(num * sizeOfElement);
ofileH.write(reinterpret_cast<char*>(&dhead), sizeof(dhead));
for (int i = 0; i < num; i++) {
std::string tmpStr = data[n] + std::string(8 - data[n].size(),' ');
ofileH.write(tmpStr.c_str(), sizeOfElement);
n++;
}
ofileH.write(reinterpret_cast<char*>(&dhead), sizeof(dhead));
}
}
void EclOutput::writeFormattedHeader(const std::string& arrName, int size, EIOD::eclArrType arrType)
{
std::string name = arrName + std::string(8 - arrName.size(),' ');
ofileH << " '" << name << "' " << std::setw(11) << size;
switch (arrType) {
case EIOD::INTE:
ofileH << " 'INTE'" << std::endl;
break;
case EIOD::REAL:
ofileH << " 'REAL'" << std::endl;
break;
case EIOD::DOUB:
ofileH << " 'DOUB'" << std::endl;
break;
case EIOD::LOGI:
ofileH << " 'LOGI'" << std::endl;
break;
case EIOD::CHAR:
ofileH << " 'CHAR'" << std::endl;
break;
case EIOD::MESS:
ofileH << " 'MESS'" << std::endl;
break;
}
}
std::string EclOutput::make_real_string(float value) const
{
char buffer [15];
sprintf (buffer, "%10.7E", value);
if (value == 0.0) {
return "0.00000000E+00";
} else {
std::string tmpstr(buffer);
int exp = value < 0.0 ? std::stoi(tmpstr.substr(11, 3)) : std::stoi(tmpstr.substr(10, 3));
if (value < 0.0) {
tmpstr = "-0." + tmpstr.substr(1, 1) + tmpstr.substr(3, 7) + "E";
} else {
tmpstr = "0." + tmpstr.substr(0, 1) + tmpstr.substr(2, 7) +"E";
}
sprintf (buffer, "%+03i", exp+1);
tmpstr = tmpstr+buffer;
return tmpstr;
}
}
std::string EclOutput::make_doub_string(double value) const
{
char buffer [21];
sprintf (buffer, "%19.13E", value);
if (value == 0.0) {
return "0.00000000000000D+00";
} else {
std::string tmpstr(buffer);
int exp = value < 0.0 ? std::stoi(tmpstr.substr(17, 4)) : std::stoi(tmpstr.substr(16, 4));
if (value < 0.0) {
if (abs(exp) < 100) {
tmpstr = "-0." + tmpstr.substr(1, 1) + tmpstr.substr(3, 13) + "D";
} else {
tmpstr = "-0." + tmpstr.substr(1, 1) + tmpstr.substr(3, 13);
}
} else {
if (abs(exp) < 100) {
tmpstr = "0." + tmpstr.substr(0, 1) + tmpstr.substr(2, 13) + "D";
} else {
tmpstr = "0." + tmpstr.substr(0, 1) + tmpstr.substr(2, 13);
}
}
sprintf (buffer, "%+03i", exp+1);
tmpstr = tmpstr + buffer;
return tmpstr;
}
}
template <typename T>
void EclOutput::writeFormattedArray(const std::vector<T>& data)
{
int size = data.size();
int n = 0;
EIOD::eclArrType arrType = EIOD::MESS;
if (typeid(T) == typeid(int)) {
arrType = EIOD::INTE;
} else if (typeid(T) == typeid(float)) {
arrType = EIOD::REAL;
} else if (typeid(T) == typeid(double)) {
arrType = EIOD::DOUB;
} else if (typeid(T) == typeid(bool)) {
arrType = EIOD::LOGI;
}
auto sizeData = EIOD::block_size_data_formatted(arrType);
int maxBlockSize = std::get<0>(sizeData);
int nColumns = std::get<1>(sizeData);
int columnWidth = std::get<2>(sizeData);
for (int i = 0; i < size; i++) {
n++;
switch (arrType) {
case EIOD::INTE:
ofileH << std::setw(columnWidth) << data[i];
break;
case EIOD::REAL:
ofileH << std::setw(columnWidth) << make_real_string(data[i]);
break;
case EIOD::DOUB:
ofileH << std::setw(columnWidth) << make_doub_string(data[i]);
break;
case EIOD::LOGI:
if (data[i]) {
ofileH << " T";
} else {
ofileH << " F";
}
break;
default:
break;
}
if ((n % nColumns) == 0 || (n % maxBlockSize) == 0) {
ofileH << std::endl;
}
if ((n % maxBlockSize) == 0) {
n=0;
}
}
if ((n % nColumns) != 0 && (n % maxBlockSize) != 0) {
ofileH << std::endl;
}
}
template void EclOutput::writeFormattedArray<int>(const std::vector<int>& data);
template void EclOutput::writeFormattedArray<float>(const std::vector<float>& data);
template void EclOutput::writeFormattedArray<double>(const std::vector<double>& data);
template void EclOutput::writeFormattedArray<bool>(const std::vector<bool>& data);
template void EclOutput::writeFormattedArray<char>(const std::vector<char>& data);
void EclOutput::writeFormattedCharArray(const std::vector<std::string>& data)
{
auto sizeData = EIOD::block_size_data_formatted(EIOD::CHAR);
int nColumns = std::get<1>(sizeData);
int size = data.size();
for (int i = 0; i < size; i++) {
std::string str1(8,' ');
str1 = data[i] + std::string(8 - data[i].size(),' ');
ofileH << " '" << str1 << "'";
if ((i+1) % nColumns == 0) {
ofileH << std::endl;
}
}
if ((size % nColumns) != 0) {
ofileH << std::endl;
}
}

View File

@@ -1,94 +0,0 @@
/*
Copyright 2019 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/>.
*/
#ifndef ECL_OUTPUT_HPP
#define ECL_OUTPUT_HPP
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <typeinfo>
#include <examples/test_util/data/EclIOdata.hpp>
namespace EIOD = Opm::ecl;
class EclOutput
{
public:
EclOutput(const std::string& inputFile, bool formatted);
template<typename T>
void write(const std::string& name,
const std::vector<T>& data)
{
EIOD::eclArrType arrType = EIOD::MESS;
if (typeid(T) == typeid(int))
arrType = EIOD::INTE;
else if (typeid(T) == typeid(float))
arrType = EIOD::REAL;
else if (typeid(T) == typeid(double))
arrType = EIOD::DOUB;
else if (typeid(T) == typeid(bool))
arrType = EIOD::LOGI;
else if (typeid(T) == typeid(char))
arrType = EIOD::MESS;
if (isFormatted)
{
writeFormattedHeader(name, data.size(), arrType);
if (arrType != EIOD::MESS)
writeFormattedArray(data);
}
else
{
writeBinaryHeader(name, data.size(), arrType);
if (arrType != EIOD::MESS)
writeBinaryArray(data);
}
}
private:
void writeBinaryHeader(const std::string& arrName, int size, EIOD::eclArrType arrType);
template <typename T>
void writeBinaryArray(const std::vector<T>& data);
void writeBinaryCharArray(const std::vector<std::string>& data);
void writeFormattedHeader(const std::string& arrName, int size, EIOD::eclArrType arrType);
template <typename T>
void writeFormattedArray(const std::vector<T>& data);
void writeFormattedCharArray(const std::vector<std::string>& data);
std::string make_real_string(float value) const;
std::string make_doub_string(double value) const;
std::ofstream ofileH;
bool isFormatted;
};
template<>
void EclOutput::write<std::string>(const std::string& name,
const std::vector<std::string>& data);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
Copyright 2019 Equinor ASA.
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
@@ -21,11 +21,6 @@
#define ECLREGRESSIONTEST_HPP
#include "EclFilesComparator.hpp"
#include "data/EclIOdata.hpp"
namespace EIOD = Opm::ecl;
/*! \brief A class for executing a regression test for two ECLIPSE files.
\details This class inherits from ECLFilesComparator, which opens and
@@ -34,146 +29,65 @@ namespace EIOD = Opm::ecl;
resultsForKeyword() can be invoked to compare griddata
or keyworddata for all keywords or a given keyword (resultsForKeyword()).
*/
class ECLRegressionTest: public ECLFilesComparator {
public:
//! \brief Sets up the regression test.
//! \param[in] basename1 Full path without file extension to the first case.
//! \param[in] basename2 Full path without file extension to the second case.
//! \param[in] absTolerance Tolerance for absolute deviation.
//! \param[in] relTolerance Tolerance for relative deviation.
//! \details This constructor only calls the constructor of the superclass, see the docs for ECLFilesComparator for more information.
ECLRegressionTest(const std::string& basename1, const std::string& basename2, double absTolerance, double relTolerance):
ECLFilesComparator(basename1, basename2, absTolerance, relTolerance) {}
private:
// These vectors store absolute and relative deviations, respecively. Note that they are whiped clean for every new keyword comparison.
std::vector<double> absDeviation, relDeviation;
// Keywords which should not contain negative values, i.e. uses allowNegativeValues = false in deviationsForCell():
const std::vector<std::string> keywordDisallowNegatives = {"SGAS", "SWAT", "PRESSURE"};
~ECLRegressionTest();
// Only compare last occurrence
bool onlyLastOccurrence = false;
//! \brief Option to only compare last occurrence
void setOnlyLastReportNumber(bool onlyLastSequenceArg) {
this->onlyLastSequence = onlyLastSequenceArg;
}
// Accept extra keywords in the restart file of the 'new' simulation.
bool acceptExtraKeywords = false;
int countDev() { return deviations.size(); }
// Accept extra keywords: If this switch is set to true the comparison
// will ignore extra keywords which are only present
// in the new simulation.
// Prints results stored in absDeviation and relDeviation.
void printResultsForKeyword(const std::string& keyword) const;
void setAcceptExtraKeywords(bool acceptExtraKeywordsArg) {
this->acceptExtraKeywords = acceptExtraKeywordsArg;
}
// Function which compares data at specific occurrences and for a specific keyword type. The functions takes two occurrence inputs to also be able to
// compare keywords which are shifted relative to each other in the two files. This is for instance handy when running flow with restart from different timesteps,
// and comparing the last timestep from the two runs.
void boolComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) const;
void charComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) const;
void intComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2) const;
void doubleComparisonForOccurrence(const std::string& keyword, int occurrence1, int occurrence2);
// deviationsForCell throws an exception if both the absolute deviation AND the relative deviation
// are larger than absTolerance and relTolerance, respectively. In addition,
// if allowNegativeValues is passed as false, an exception will be thrown when the absolute value
// of a negative value exceeds absTolerance. If no exceptions are thrown, the absolute and relative deviations are added to absDeviation and relDeviation.
void deviationsForCell(double val1, double val2, const std::string& keyword, int occurrence1, int occurrence2, size_t kw_size, size_t cell, bool allowNegativeValues = true);
public:
//! \brief Sets up the regression test.
//! \param[in] file_type Specifies which filetype to be compared, possible inputs are UNRSTFILE, INITFILE and RFTFILE.
//! \param[in] basename1 Full path without file extension to the first case.
//! \param[in] basename2 Full path without file extension to the second case.
//! \param[in] absTolerance Tolerance for absolute deviation.
//! \param[in] relTolerance Tolerance for relative deviation.
//! \details This constructor only calls the constructor of the superclass, see the docs for ECLFilesComparator for more information.
ECLRegressionTest(int file_type, const std::string& basename1, const std::string& basename2, double absTolerance, double relTolerance):
ECLFilesComparator(file_type, basename1, basename2, absTolerance, relTolerance) {}
void setIntegrationTest(bool inregrationTestArg) {
this->integrationTest = inregrationTestArg;
}
//! \brief Option to only compare last occurrence
void setOnlyLastOccurrence(bool onlyLastOccurrenceArg) {this->onlyLastOccurrence = onlyLastOccurrenceArg;}
void setPrintKeywordOnly(bool printArg) {
this->printKeywordOnly = printArg;
}
// Accept extra keywords: If this switch is set to true the comparison
// of restart files will ignore extra keywords which are only present
// in the new simulation.
void setAcceptExtraKeywords(bool acceptExtraKeywords) { this->acceptExtraKeywords = acceptExtraKeywords; }
void compareSpesificKeyword(std::string keyword) {
this->spesificKeyword = keyword;
}
void compareSpesificRstReportStepNumber(int seqn) {
this->spesificSequence = seqn;
}
void setLoadBaseRunData(bool loadArg) {
this->loadBaseRunData = loadArg;
}
void loadGrids();
void printDeviationReport();
void gridCompare();
void results_rst();
void results_init();
void results_smry();
void results_rft();
private:
bool checkFileName(const std::string& rootName, const std::string& extension, std::string& filename);
// Prints results stored in absDeviation and relDeviation.
void printResultsForKeyword(const std::string& keyword) const;
void printComparisonForKeywordLists(const std::vector<std::string>& arrayList1,
const std::vector<std::string>& arrayList2) const;
void printComparisonForKeywordLists(const std::vector<std::string>& arrayList1,
const std::vector<std::string>& arrayList2,
const std::vector<EIOD::eclArrType>& arrayType1,
const std::vector<EIOD::eclArrType>& arrayType2) const;
void printMissingKeywords(const std::vector<std::string>& arrayList1,
const std::vector<std::string>& arrayList2) const;
void compareKeywords(const std::vector<std::string>& keywords1,
const std::vector<std::string>& keywords2,
const std::string& reference);
void checkSpesificKeyword(std::vector<std::string>& keywords1,
std::vector<std::string>& keywords2,
std::vector<EIOD::eclArrType>& arrayType1,
std::vector<EIOD::eclArrType>& arrayType2,
const std::string& reference);
template <typename T>
void compareVectors(const std::vector<T>& t1, const std::vector<T>& t2,
const std::string& keyword, const std::string& reference);
template <typename T>
void compareFloatingPointVectors(const std::vector<T>& t1, const std::vector<T> &t2,
const std::string& keyword, const std::string& reference);
// deviationsForCell throws an exception if both the absolute deviation AND the relative deviation
// are larger than absTolerance and relTolerance, respectively. In addition,
// if allowNegativeValues is passed as false, an exception will be thrown when the absolute value
// of a negative value exceeds absTolerance. If no exceptions are thrown, the absolute and relative deviations are added to absDeviation and relDeviation.
// void deviationsForCell(double val1, double val2, const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, bool allowNegativeValues = true);
void deviationsForCell(double val1, double val2, const std::string& keyword,
const std::string& reference, size_t kw_size, size_t cell,
bool allowNegativeValues, bool useStrictTol);
template <typename T>
void deviationsForNonFloatingPoints(T val1, T val2, const std::string& keyword,
const std::string& reference,
size_t kw_size, size_t cell);
// These vectors store absolute and relative deviations, respecively. Note that they are whiped clean for every new keyword comparison.
std::vector<double> absDeviation, relDeviation;
// Keywords which should not contain negative values, i.e. uses allowNegativeValues = false in deviationsForCell():
const std::vector<std::string> keywordDisallowNegatives = {"SGAS", "SWAT", "PRESSURE"};
double strictAbsTol = 1e-6;
double strictRelTol = 1e-6;
// keywords that triggers strict tolerances
const std::vector<std::string> keywordsStrictTol = {"COORD", "ZCORN", "PORV", "DEPTH", "DX", "DY", "DZ", "PERMX", "PERMY", "PERMZ", "NTG",
"TRANX", "TRANY", "TRANZ", "TRANNNC", "SGRP", "SWEL", "SCON", "DOUBHEAD"
};
// Only compare last occurrence
bool onlyLastSequence = false;
bool integrationTest = false;
bool printKeywordOnly = false;
bool loadBaseRunData = false;
// spesific keyword to be compared
std::string spesificKeyword;
// spesific restart sequence to be compared
int spesificSequence = -1;
// Accept extra keywords in the restart file of the 'new' simulation.
bool acceptExtraKeywords = false;
EGrid* grid1 = nullptr;
EGrid* grid2 = nullptr;
//! \brief Compares grid properties of the two cases.
// gridCompare() checks if both the number of active and global cells in the two cases are the same. If they are, and volumecheck is true, all cells are looped over to calculate the cell volume deviation for the two cases. If the both the relative and absolute deviation exceeds the tolerances, an exception is thrown.
void gridCompare(const bool volumecheck) const;
//! \brief Calculates deviations for all keywords.
// This function checks if the number of keywords of the two cases are equal, and if it is, resultsForKeyword() is called for every keyword. If not, an exception is thrown.
void results();
//! \brief Calculates deviations for a specific keyword.
//! \param[in] keyword Keyword which should be compared, if this keyword is absent in one of the cases, an exception will be thrown.
//! \details This function loops through every report step and every cell and compares the values for the given keyword from the two input cases. If the absolute or relative deviation between the two values for each step exceeds both the absolute tolerance and the relative tolerance (stored in ECLFilesComparator), an exception is thrown. In addition, some keywords are marked for "disallow negative values" -- these are SGAS, SWAT and PRESSURE. An exception is thrown if a value of one of these keywords is both negative and has an absolute value larger than the absolute tolerance. If no exceptions are thrown, resultsForKeyword() uses the private member funtion printResultsForKeyword to print the average and median deviations.
void resultsForKeyword(const std::string& keyword);
};
#endif

View File

@@ -1,127 +0,0 @@
/*
Copyright 2019 Equinor 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 "EclUtil.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <algorithm>
#include <stdexcept>
namespace EIOD = Opm::ecl;
int Opm::ecl::flipEndianInt(int num)
{
unsigned int tmp = __builtin_bswap32(num);
return static_cast<int>(tmp);
}
float Opm::ecl::flipEndianFloat(float num)
{
float value = num;
char* floatToConvert = reinterpret_cast<char*>(&value);
std::reverse(floatToConvert, floatToConvert+4);
return value;
}
double Opm::ecl::flipEndianDouble(double num)
{
double value = num;
char* doubleToConvert = reinterpret_cast<char*>(&value);
std::reverse(doubleToConvert, doubleToConvert+8);
return value;
}
std::tuple<int, int> Opm::ecl::block_size_data_binary(eclArrType arrType)
{
using BlockSizeTuple = std::tuple<int, int>;
switch (arrType) {
case EIOD::INTE:
return BlockSizeTuple{EIOD::sizeOfInte, EIOD::MaxBlockSizeInte};
break;
case EIOD::REAL:
return BlockSizeTuple{EIOD::sizeOfReal, EIOD::MaxBlockSizeReal};
break;
case EIOD::DOUB:
return BlockSizeTuple{EIOD::sizeOfDoub, EIOD::MaxBlockSizeDoub};
break;
case EIOD::LOGI:
return BlockSizeTuple{EIOD::sizeOfLogi, EIOD::MaxBlockSizeLogi};
break;
case EIOD::CHAR:
return BlockSizeTuple{EIOD::sizeOfChar, EIOD::MaxBlockSizeChar};
break;
case EIOD::MESS:
OPM_THROW(std::invalid_argument, "Type 'MESS' have no associated data");
break;
default:
OPM_THROW(std::invalid_argument, "Unknown field type");
break;
}
}
std::tuple<int, int, int> Opm::ecl::block_size_data_formatted(EIOD::eclArrType arrType)
{
using BlockSizeTuple = std::tuple<int, int, int>;
switch (arrType) {
case EIOD::INTE:
return BlockSizeTuple{EIOD::MaxNumBlockInte, EIOD::numColumnsInte, EIOD::columnWidthInte};
break;
case EIOD::REAL:
return BlockSizeTuple{EIOD::MaxNumBlockReal,EIOD::numColumnsReal, EIOD::columnWidthReal};
break;
case EIOD::DOUB:
return BlockSizeTuple{EIOD::MaxNumBlockDoub,EIOD::numColumnsDoub, EIOD::columnWidthDoub};
break;
case EIOD::LOGI:
return BlockSizeTuple{EIOD::MaxNumBlockLogi,EIOD::numColumnsLogi, EIOD::columnWidthLogi};
break;
case EIOD::CHAR:
return BlockSizeTuple{EIOD::MaxNumBlockChar,EIOD::numColumnsChar, EIOD::columnWidthChar};
break;
case EIOD::MESS:
OPM_THROW(std::invalid_argument, "Type 'MESS' have no associated data") ;
break;
default:
OPM_THROW(std::invalid_argument, "Unknown field type");
break;
}
}
std::string Opm::ecl::trimr(const std::string &str1)
{
if (str1 == " ") {
return "";
} else {
int p = str1.find_last_not_of(" ");
return str1.substr(0,p+1);
}
}

View File

@@ -1,40 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef ECL_UTIL_HPP
#define ECL_UTIL_HPP
#include <string>
#include <tuple>
#include <examples/test_util/data/EclIOdata.hpp>
namespace Opm {
namespace ecl {
int flipEndianInt(int num);
float flipEndianFloat(float num);
double flipEndianDouble(double num);
std::tuple<int, int> block_size_data_binary(eclArrType arrType);
std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);
std::string trimr(const std::string &str1);
}
}
#endif

View File

@@ -1,5 +1,5 @@
/*
Copyright 2019 Equinor ASA.
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
@@ -16,129 +16,221 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "EclIntegrationTest.hpp"
#include "EclRegressionTest.hpp"
#include "summaryIntegrationTest.hpp"
#include "summaryRegressionTest.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <ert/util/util.h>
#include <ert/util/stringlist.h>
#include <ert/ecl/ecl_endian_flip.h>
#include <ert/ecl/ecl_file.h>
#include <iostream>
#include <string>
#include <getopt.h>
static void printHelp() {
std::cout << "\ncompareECL compares ECLIPSE files (restart (.RST), unified restart (.UNRST), initial (.INIT), summary (.SMRY), unified summary (.UNSMRY) or .RFT) and gridsizes (from .EGRID or .GRID file) from two simulations.\n"
<< "The program takes four arguments:\n\n"
<< "1. Case number 1 (full path without extension)\n"
<< "2. Case number 2 (full path without extension)\n"
<< "3. Absolute tolerance\n"
<< "4. Relative tolerance (between 0 and 1)\n\n"
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
<< "-a Run a full analysis of errors.\n"
<< "-h Print help and exit.\n"
<< "-i Execute integration test (regression test is default).\n"
<< " The integration test compares SGAS, SWAT and PRESSURE in unified restart files, and WOPR, WGPR, WWPR and WBHP (all wells) in summary file. \n"
<< "-k Specify specific keyword to compare (capitalized), for examples -k PRESSURE or -k WOPR:A-1H \n"
<< "-l Only do comparison for the last Report Step. This option is only valid for restart files.\n"
<< "-n Do not throw on errors.\n"
<< "-p Print keywords in both cases and exit.\n"
<< "-r compare a spesific report time step number in a restart file.\n"
<< "-t Specify ECLIPSE filetype to compare, (default behaviour is that all files are compared if found). Different possible arguments are:\n"
<< " -t UNRST \t Compare two unified restart files (.UNRST). This the default value, so it is the same as not passing option -t.\n"
<< " -t EGRID \t Compare two EGrid files (.EGRID).\n"
<< " -t INIT \t Compare two initial files (.INIT).\n"
<< " -t RFT \t Compare two RFT files (.RFT).\n"
<< " -t SMRY \t Compare two cases consistent of (unified) summary files.\n"
<< "-x Allow extra keywords in case number 2. These additional keywords (not found in case number1) will be ignored in the comparison.\n"
<< "\nExample usage of the program: \n\n"
<< "compareECL -k PRESSURE <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
<< "compareECL -t INIT -k PORO <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
<< "compareECL -i <path to first casefile> <path to second casefile> 0.01 1e-6\n\n"
<< "Exceptions are thrown (and hence program exits) when deviations are larger than the specified "
<< "tolerances, or when the number of cells does not match -- either in the grid file or for a "
<< "specific keyword. Information about the keyword, keyword occurrence (zero based) and cell "
<< "coordinate is printed when an exception is thrown. For more information about how the cases "
<< "are compared, see the documentation of the EclFilesComparator class.\n\n";
<< "The program takes four arguments:\n\n"
<< "1. Case number 1 (full path without extension)\n"
<< "2. Case number 2 (full path without extension)\n"
<< "3. Absolute tolerance\n"
<< "4. Relative tolerance (between 0 and 1)\n\n"
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
<< "-a Run a full analysis of errors.\n"
<< "-g Will print the vector with the greatest error ratio.\n"
<< "-h Print help and exit.\n"
<< "-i Execute integration test (regression test is default).\n"
<< " The integration test compares SGAS, SWAT and PRESSURE in unified restart files, so this option can not be used in combination with -t.\n"
<< "-I Same as -i, but throws an exception when the number of keywords in the two cases differ. Can not be used in combination with -t.\n"
<< "-k Specify specific keyword to compare (capitalized), for example -k PRESSURE.\n"
<< "-K Will not allow different amount of keywords in the two files. Throws an exception if the amount are different.\n"
<< "-l Only do comparison for the last occurrence. This option is only for the regression test, and can therefore not be used in combination with -i or -I.\n"
<< "-m mainVar. Will calculate the error ratio for one main variable. Valid input is WOPR, WWPR, WGPR or WBHP.\n"
<< "-n Do not throw on errors.\n"
<< "-p Print keywords in both cases and exit. Can not be used in combination with -P.\n"
<< "-P Print common and uncommon keywords in both cases and exit. Can not be used in combination with -p.\n"
<< "-R Will allow comparison between a restarted simulation and a normal simulation for summary regression tests. The files must end at the same time.\n"
<< "-s int Sets the number of spikes that are allowed for each keyword in summary integration tests.\n"
<< "-t Specify ECLIPSE filetype to compare (unified restart is default). Can not be used in combination with -i or -I. Different possible arguments are:\n"
<< " -t UNRST \t Compare two unified restart files (.UNRST). This the default value, so it is the same as not passing option -t.\n"
<< " -t INIT \t Compare two initial files (.INIT).\n"
<< " -t RFT \t Compare two RFT files (.RFT).\n"
<< " -t RST \t Compare two cases consisting of restart files (.Xnnnn).\n"
<< " -t SMRY \t Compare two cases consistent of (unified) summary files.\n"
<< " -t RST1 \t Compare two cases where the first case consists of restart files (.Xnnnn), and the second case consists of a unified restart file (.UNRST).\n"
<< " -t RST2 \t Compare two cases where the first case consists of a unified restart file (.UNRST), and the second case consists of restart files (.Xnnnn).\n"
<< " Note that when dealing with restart files (.Xnnnn), the program concatenates all of them into one unified restart file, which is used for comparison and stored in the same directory as the restart files.\n"
<< " This will overwrite any existing unified restart file in that directory.\n\n"
<< "-v For the rate keywords WOPR, WGPR, WWPR and WBHP. Calculates the error volume of the two summary files. This is printed to screen.\n"
<< "\nExample usage of the program: \n\n"
<< "compareECL -k PRESSURE <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
<< "compareECL -t INIT -k PORO <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
<< "compareECL -i <path to first casefile> <path to second casefile> 0.01 1e-6\n\n"
<< "Exceptions are thrown (and hence program exits) when deviations are larger than the specified "
<< "tolerances, or when the number of cells does not match -- either in the grid file or for a "
<< "specific keyword. Information about the keyword, keyword occurrence (zero based) and cell "
<< "coordinate is printed when an exception is thrown. For more information about how the cases "
<< "are compared, see the documentation of the EclFilesComparator class.\n\n";
}
void splitBasename(const std::string& basename, std::string& path, std::string& filename) {
const size_t lastSlashIndex = basename.find_last_of("/\\");
path = basename.substr(0,lastSlashIndex);
filename = basename.substr(lastSlashIndex+1);
}
// Inspired by the ecl_pack application in the ERT library
void concatenateRestart(const std::string& basename) {
std::string inputPath, inputBase;
splitBasename(basename, inputPath, inputBase);
stringlist_type* inputFiles = stringlist_alloc_new();
const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles);
const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1);
fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP);
int dummy;
ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy);
int reportStep = 0;
for (int i = 0; i < numFiles; ++i) {
ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep);
ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0);
ecl_kw_iset_int(seqnum_kw, 0, reportStep);
ecl_kw_fwrite(seqnum_kw, target);
ecl_file_fwrite_fortio(src_file, target, 0);
ecl_file_close(src_file);
}
fortio_fclose(target);
stringlist_free(inputFiles);
}
//------------------------------------------------//
int main(int argc, char** argv) {
bool integrationTest = false;
bool onlyLastSequence = false;
bool printKeywords = false;
bool specificKeyword = false;
bool specificReportStepNumber = false;
bool specificFileType = false;
bool throwOnError = true;
bool restartFile = false;
bool acceptExtraKeywords = false;
bool analysis = false;
char* keyword = nullptr;
int c = 0;
int reportStepNumber = -1;
std::string fileTypeString;
// Restart is default
ecl_file_enum file_type = ECL_UNIFIED_RESTART_FILE;
// RegressionTest is default
bool integrationTest = false;
bool allowDifferentAmount = true;
bool checkNumKeywords = false;
bool findGreatestErrorRatio = false;
bool findVolumeError = false;
bool onlyLastOccurrence = false;
bool printKeywords = false;
bool printKeywordsDifference = false;
bool restartFile = false;
bool specificKeyword = false;
bool specificFileType = false;
bool allowSpikes = false;
bool throwOnError = true;
bool throwTooGreatErrorRatio = true;
bool acceptExtraKeywords = false;
bool analysis = false;
bool volumecheck = true;
char* keyword = nullptr;
char* fileTypeCstr = nullptr;
const char* mainVariable = nullptr;
int c = 0;
int spikeLimit = -1;
while ((c = getopt(argc, argv, "hik:alnpt:Rr:x")) != -1) {
while ((c = getopt(argc, argv, "hiIk:alnpPt:VRgs:m:vKx")) != -1) {
switch (c) {
case 'a':
analysis = true;
break;
case 'h':
printHelp();
return 0;
case 'i':
integrationTest = true;
break;
case 'k':
specificKeyword = true;
keyword = optarg;
break;
case 'l':
onlyLastSequence = true;
break;
case 'n':
throwOnError = false;
break;
case 'p':
printKeywords = true;
break;
case 'r':
specificReportStepNumber=true;
reportStepNumber = atoi(optarg);
break;
case 'R':
restartFile = true;
break;
case 't':
specificFileType = true;
fileTypeString=optarg;
break;
case 'x':
acceptExtraKeywords = true;
break;
case '?':
if (optopt == 'k' || optopt == 'm' || optopt == 's') {
std::cerr << "Option " << optopt << " requires a keyword as argument, see manual (-h) for more information." << std::endl;
case 'a':
analysis = true;
break;
case 'g':
findGreatestErrorRatio = true;
throwTooGreatErrorRatio = false;
break;
case 'h':
printHelp();
return 0;
case 'i':
integrationTest = true;
break;
case 'I':
integrationTest = true;
checkNumKeywords = true;
break;
case 'k':
specificKeyword = true;
keyword = optarg;
break;
case 'K':
allowDifferentAmount = false;
break;
case 'l':
onlyLastOccurrence = true;
break;
case 'm':
mainVariable = optarg;
break;
case 'n':
throwOnError = false;
break;
case 'p':
printKeywords = true;
break;
case 'P':
printKeywordsDifference = true;
break;
case 'R':
restartFile = true;
break;
case 's':
allowSpikes = true;
spikeLimit = atof(optarg);
break;
case 't':
specificFileType = true;
fileTypeCstr = optarg;
break;
case 'v':
findVolumeError = true;
break;
case 'V':
volumecheck = false;
break;
case 'x':
acceptExtraKeywords = true;
break;
case '?':
if (optopt == 'k' || optopt == 'm' || optopt == 's') {
std::cerr << "Option " << optopt << " requires a keyword as argument, see manual (-h) for more information." << std::endl;
return EXIT_FAILURE;
}
else if (optopt == 't') {
std::cerr << "Option t requires an ECLIPSE filetype as argument, see manual (-h) for more information." << std::endl;
return EXIT_FAILURE;
}
else {
std::cerr << "Unknown option." << std::endl;
return EXIT_FAILURE;
}
default:
return EXIT_FAILURE;
}
else if (optopt == 't') {
std::cerr << "Option t requires an ECLIPSE filetype as argument, see manual (-h) for more information." << std::endl;
return EXIT_FAILURE;
}
else {
std::cerr << "Unknown option." << std::endl;
return EXIT_FAILURE;
}
default:
return EXIT_FAILURE;
}
}
int argOffset = optind;
if ((printKeywords && printKeywordsDifference) ||
(integrationTest && specificFileType) ||
(integrationTest && onlyLastOccurrence)) {
std::cerr << "Error: Options given which can not be combined. "
<< "Please see the manual (-h) for more information." << std::endl;
return EXIT_FAILURE;
}
if (argc != argOffset + 4) {
std::cerr << "Error: The number of options and arguments given is not correct. "
<< "Please run compareECL -h to see manual." << std::endl;
<< "Please run compareECL -h to see manual." << std::endl;
return EXIT_FAILURE;
}
@@ -147,85 +239,142 @@ int main(int argc, char** argv) {
double absTolerance = strtod(argv[argOffset + 2], nullptr);
double relTolerance = strtod(argv[argOffset + 3], nullptr);
std::cout << "Comparing '" << basename1 << "' to '" << basename2 << "'." << std::endl;
try {
ECLRegressionTest comparator(basename1, basename2, absTolerance, relTolerance);
comparator.throwOnErrors(throwOnError);
comparator.doAnalysis(analysis);
comparator.setAcceptExtraKeywords(acceptExtraKeywords);
if (integrationTest) {
comparator.setIntegrationTest(true);
if (specificFileType) {
std::string fileTypeString(fileTypeCstr);
for (auto& ch: fileTypeString) ch = toupper(ch);
if (fileTypeString== "UNRST") {} //Do nothing
else if (fileTypeString == "RST") {
concatenateRestart(basename1);
concatenateRestart(basename2);
}
if (printKeywords) {
comparator.setPrintKeywordOnly(printKeywords);
else if (fileTypeString == "RST1") {
concatenateRestart(basename1);
}
if (onlyLastSequence) {
comparator.setOnlyLastReportNumber(true);
else if (fileTypeString == "RST2") {
concatenateRestart(basename2);
}
if (specificKeyword) {
comparator.compareSpesificKeyword(keyword);
else if (fileTypeString == "INIT") {
file_type = ECL_INIT_FILE;
}
if (specificReportStepNumber) {
comparator.compareSpesificRstReportStepNumber(reportStepNumber);
else if (fileTypeString == "RFT") {
file_type = ECL_RFT_FILE;
}
if (restartFile) {
comparator.setLoadBaseRunData(true);
else if (fileTypeString == "SMRY")
file_type = ECL_SUMMARY_FILE;
else {
std::cerr << "Unknown ECLIPSE filetype specified with option -t. Please run compareECL -h to see manual." << std::endl;
return EXIT_FAILURE;
}
comparator.loadGrids();
if (integrationTest && specificFileType) {
if (fileTypeString=="EGRID" || fileTypeString=="INIT" || fileTypeString=="RFT") {
std::cerr << "Integration test and spesific file type, only valid for UNRST and SMRY" << std::endl;
return EXIT_FAILURE;
}
}
if (specificFileType) {
if (fileTypeString == "EGRID") {
comparator.gridCompare();
} else if (fileTypeString == "INIT") {
comparator.results_init();
} else if (fileTypeString == "UNRST") {
comparator.results_rst();
} else if (fileTypeString == "SMRY") {
comparator.results_smry();
} else if (fileTypeString == "RFT") {
comparator.results_rft();
} else {
std::cerr << "Unknown ECLIPSE filetype specified with option -t. Please run compareECL -h to see manual." << std::endl;
return EXIT_FAILURE;
}
} else if (integrationTest) {
comparator.results_rst();
comparator.results_smry();
} else {
comparator.gridCompare();
comparator.results_init();
comparator.results_rst();
comparator.results_smry();
comparator.results_rft();
}
if (comparator.getNoErrors() > 0)
OPM_THROW(std::runtime_error, comparator.getNoErrors() << " errors encountered in comparisons.");
}
if (restartFile && (file_type != ECL_SUMMARY_FILE || integrationTest)) {
std::cerr << "Error: -R can only be used in for summary regression tests." << std::endl;
return EXIT_FAILURE;
}
std::cout << "Comparing '" << basename1 << "' to '" << basename2 << "'." << std::endl;
try {
if (file_type == ECL_SUMMARY_FILE) {
if(!integrationTest){
SummaryRegressionTest compare(basename1,basename2,absTolerance,relTolerance);
compare.throwOnErrors(throwOnError);
compare.doAnalysis(analysis);
compare.setPrintKeywords(printKeywords);
compare.setIsRestartFile(restartFile);
if(specificKeyword){
compare.getRegressionTest(keyword);
}
else{
compare.setPrintKeywords(printKeywords);
compare.getRegressionTest();
}
} else {
SummaryIntegrationTest compare(basename1,basename2,absTolerance,relTolerance);
compare.throwOnErrors(throwOnError);
compare.setFindVectorWithGreatestErrorRatio(findGreatestErrorRatio);
compare.setAllowSpikes(allowSpikes);
if (mainVariable) {
compare.setOneOfTheMainVariables(true);
std::string str(mainVariable);
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
if(str == "WOPR" ||str=="WWPR" ||str=="WGPR" || str == "WBHP"){
compare.setMainVariable(str);
}else{
throw std::invalid_argument("The input is not a main variable. -m option requires a valid main variable.");
}
}
compare.setFindVolumeError(findVolumeError);
if (spikeLimit != -1) {
compare.setSpikeLimit(spikeLimit);
}
compare.setAllowDifferentAmountOfKeywords(allowDifferentAmount);
compare.setPrintKeywords(printKeywords);
compare.setThrowExceptionForTooGreatErrorRatio(throwTooGreatErrorRatio);
if(specificKeyword){
compare.setPrintSpecificKeyword(specificKeyword);
compare.getIntegrationTest(keyword);
return 0;
}
compare.getIntegrationTest();
}
}
else if (integrationTest) {
ECLIntegrationTest comparator(basename1, basename2, absTolerance, relTolerance);
if (printKeywords) {
comparator.printKeywords();
return 0;
}
if (printKeywordsDifference) {
comparator.printKeywordsDifference();
return 0;
}
if (checkNumKeywords) {
comparator.equalNumKeywords();
}
if (specificKeyword) {
if (comparator.elementInWhitelist(keyword)) {
comparator.resultsForKeyword(keyword);
}
else {
std::cerr << "Keyword " << keyword << " is not supported for the integration test. Use SGAS, SWAT or PRESSURE." << std::endl;
return EXIT_FAILURE;
}
}
else {
comparator.results();
}
}
else {
ECLRegressionTest comparator(file_type, basename1, basename2, absTolerance, relTolerance);
comparator.throwOnErrors(throwOnError);
comparator.doAnalysis(analysis);
comparator.setAcceptExtraKeywords(acceptExtraKeywords);
if (printKeywords) {
comparator.printKeywords();
return 0;
}
if (printKeywordsDifference) {
comparator.printKeywordsDifference();
return 0;
}
if (onlyLastOccurrence) {
comparator.setOnlyLastOccurrence(true);
}
if (specificKeyword) {
comparator.gridCompare(volumecheck);
comparator.resultsForKeyword(keyword);
}
else {
comparator.gridCompare(volumecheck);
comparator.results();
}
if (comparator.getNoErrors() > 0)
OPM_THROW(std::runtime_error, comparator.getNoErrors() << " errors encountered in comparisons.");
}
}
catch (const std::exception& e) {
std::cerr << "Program threw an exception: " << e.what() << std::endl;
return EXIT_FAILURE;
}
std::cout << "\nProgram finished \n" << std::endl;
return 0;
}

View File

@@ -0,0 +1,229 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryRegressionTest.hpp"
#include "summaryIntegrationTest.hpp"
#include <string>
#include <algorithm>
#include <stdexcept>
#include <getopt.h>
void printHelp(){
std::cout << "\n\nThe program can handle both unified and non-unified summary files."<< std::endl;
std::cout <<"In the case of non-unified summary files all the files must be located in the same directory. Only the basename (full path without extension) is needed as input." << std::endl << std::endl;
std::cout << "\nThe program takes four arguments" << std::endl;
std::cout << "1) <path to file1>/<base_name>, basename without extension" << std::endl;
std::cout << "2) <path to file2>/<base_name>, basename without extension" << std::endl;
std::cout << "3) absolute tolerance" << std::endl;
std::cout << "4) relative tolerance (between 0 and 1)" << std::endl;
std::cout << "The program will only throw an exception when both the absolute and relative tolerance are exceeded." << std::endl;
std::cout << "The program is capable of performing both a regression test and an integration test, \nhowever only one type of test at a time. ";
std::cout << "By default the program will run a regression test."<< std::endl;
std::cout << "\nThe program have command line options:" << std::endl;
std::cout << "-a \tRun a full analysis of errors." << std::endl;
std::cout << "-h \t\tPrint help message." << std::endl << std::endl;
std::cout << "For the regression test: " << std::endl;
std::cout << "-r \t\tChoosing regression test (this is default)."<< std::endl;
std::cout << "-k keyword \tSpecify a specific keyword to compare, for example - k WOPR:PRODU1."<< std::endl;
std::cout << "-p \t\tWill print the keywords of the files." << std::endl;
std::cout << "-R \t\tWill allow comparison between a restarted simulation and a normal simulation. The files must end at the same time." << std::endl << std::endl;
std::cout << "For the integration test:"<< std::endl;
std::cout << "-i \t\tChoosing integration test." << std::endl;
std::cout << "-d \t\tThe program will not throw an exception when the volume error ratio exceeds the limit." << std::endl;
std::cout << "-g \t\tWill print the vector with the greatest error ratio." << std::endl;
std::cout << "-k keyword \tSpecify a specific keyword to compare, for example - k WOPR:PRODU1."<< std::endl;
std::cout << "-K \t\tWill not allow different amount of keywords in the two files. Throws an exception if the amount are different." << std::endl;
std::cout << "-m mainVar \tWill calculate the error ratio for one main variable. Valid input is WOPR, WWPR, WGPR or WBHP." << std::endl;
std::cout << "-n \tDo not throw on errors." << std::endl;
std::cout << "-p \t\tWill print the keywords of the files." << std::endl;
std::cout << "-P keyword \tWill print the summary vectors of a specified kewyord, for example -P WOPR:B-3H." << std::endl;
std::cout << "-s int \t\tSets the number of spikes that are allowed for each keyword, for example: -s 5." << std::endl;
std::cout << "-v \t\tFor the rate keywords WOPR, WGPR, WWPR and WBHP. Calculates the error volume of \n\t\tthe two summary files. This is printed to screen." << std::endl;
std::cout << "-V keyword \tWill calculate the error rate for a specific keyword." << std::endl << std::endl;
std::cout << "Suggested combination of command line options:"<< std::endl;
std::cout << " -i -g -m mainVariable, will print the vector which have the greatest error ratio of the main variable of interest.\n"<< std::endl;
}
//---------------------------------------------------
int main (int argc, char ** argv){
//------------------------------------------------
//Defines some constants
bool specificKeyword = false;
bool allowSpikes = false;
bool findVolumeError = false;
bool integrationTest = false;
bool regressionTest = true;
bool allowDifferentAmountOfKeywords = true;
bool printKeywords = false;
bool printSpecificKeyword = false;
bool findVectorWithGreatestErrorRatio = false;
bool oneOfTheMainVariables = false;
bool throwExceptionForTooGreatErrorRatio = true;
bool isRestartFile = false;
bool throwOnError = true;
bool analysis = false;
const char* keyword = nullptr;
const char* mainVariable = nullptr;
int c = 0;
int limit = -1;
//------------------------------------------------
//------------------------------------------------
//For setting the options selected
while ((c = getopt(argc, argv, "dghik:Km:napP:rRs:vV:")) != -1) {
switch (c) {
case 'a':
analysis = true;
break;
case 'd':
throwExceptionForTooGreatErrorRatio = false;
break;
case 'g':
findVectorWithGreatestErrorRatio = true;
throwExceptionForTooGreatErrorRatio = false;
break;
case 'h':
printHelp();
return 0;
case 'i':
integrationTest = true;
regressionTest = false;
break;
case 'k':
specificKeyword = true;
keyword = optarg;
break;
case 'K':
allowDifferentAmountOfKeywords = false;
break;
case 'm':
oneOfTheMainVariables = true;
mainVariable = optarg;
break;
case 'n':
throwOnError = false;
break;
case 'p':
printKeywords = true;
break;
case 'P':
specificKeyword = true;
printSpecificKeyword = true;
keyword = optarg;
break;
case 'r':
integrationTest = false;
regressionTest = true;
break;
case 'R':
isRestartFile = true;
break;
case 's':
allowSpikes = true;
limit = atof(optarg);
break;
case 'v':
findVolumeError = true;
break;
case 'V':
findVolumeError = true;
specificKeyword = true;
keyword = optarg;
break;
case '?':
if (optopt == 'k' || optopt == 'm' || optopt == 'P'
|| optopt == 's' || optopt == 'V') {
std::cout << "Option -"<<optopt<<" requires an keyword." << std::endl;
return EXIT_FAILURE;
}
else {
std::cout << "Unknown option." << std::endl;
return EXIT_FAILURE;
}
default:
return EXIT_FAILURE;
}
}
//------------------------------------------------
int argOffset = optind;
if (argc != argOffset + 4) {
printHelp();
return EXIT_FAILURE;
}
const char * basename1 = argv[argOffset];
const char * basename2 = argv[argOffset+1];
double absoluteTolerance = strtod(argv[argOffset+2], nullptr);
double relativeTolerance = strtod(argv[argOffset+3], nullptr);
std::cout << "Comparing '" << basename1 << "' to '" << basename2 << "'." << std::endl;
try {
if(regressionTest){
SummaryRegressionTest compare(basename1,basename2, absoluteTolerance, relativeTolerance);
compare.throwOnErrors(throwOnError);
compare.doAnalysis(analysis);
if(printKeywords){compare.setPrintKeywords(true);}
if(isRestartFile){compare.setIsRestartFile(true);}
if(specificKeyword){
compare.getRegressionTest(keyword);
}
else{
if(printKeywords){compare.setPrintKeywords(true);}
compare.getRegressionTest();
}
}
if(integrationTest){
SummaryIntegrationTest compare(basename1,basename2, absoluteTolerance, relativeTolerance);
compare.throwOnErrors(throwOnError);
if(findVectorWithGreatestErrorRatio){compare.setFindVectorWithGreatestErrorRatio(true);}
if(allowSpikes){compare.setAllowSpikes(true);}
if(oneOfTheMainVariables){
compare.setOneOfTheMainVariables(true);
std::string str(mainVariable);
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
if(str == "WOPR" ||str=="WWPR" ||str=="WGPR" || str == "WBHP"){
compare.setMainVariable(str);
}else{
throw std::invalid_argument("The input is not a main variable. -m option requires a valid main variable.");
}
}
if(findVolumeError){compare.setFindVolumeError(true);}
if(limit != -1){compare.setSpikeLimit(limit);}
if(!allowDifferentAmountOfKeywords){compare.setAllowDifferentAmountOfKeywords(false);}
if(printKeywords){compare.setPrintKeywords(true);}
if(!throwExceptionForTooGreatErrorRatio){compare.setThrowExceptionForTooGreatErrorRatio(false);}
if(specificKeyword){
if(printSpecificKeyword){compare.setPrintSpecificKeyword(true);}
compare.getIntegrationTest(keyword);
return 0;
}
compare.getIntegrationTest();
}
}
catch(const std::exception& e) {
std::cerr << "Program threw an exception: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return 0;
}

View File

@@ -1,88 +0,0 @@
#include <iostream>
#include <chrono>
#include <tuple>
#include <iomanip>
#include <examples/test_util/EclFile.hpp>
#include <examples/test_util/EclOutput.hpp>
template<typename T>
void write(EclOutput& outFile, EclFile& file1,
const std::string& name, int index)
{
auto vect = file1.get<T>(index);
outFile.write(name, vect);
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "\nInvalid input, need 1 argument which should be the eclipse output file to be converted \n" << std::endl;
exit(1);
}
// start reading
auto start = std::chrono::system_clock::now();
std::string filename = argv[1];
EclFile file1(filename);
file1.loadData();
auto end1 = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds1 = end1 - start;
bool formattedOutput = file1.formattedInput() ? false : true;
int p = filename.find_last_of(".");
int l = filename.length();
std::string rootN = filename.substr(0,p);
std::string extension = filename.substr(p,l-p);
std::string resFile;
if (formattedOutput) {
resFile = rootN + ".F" + extension.substr(1, extension.length() - 1);
} else {
resFile = rootN + "." + extension.substr(2, extension.length() - 2);
}
std::cout << "\033[1;31m" << "\nconverting " << argv[1] << " -> " << resFile << "\033[0m\n" << std::endl;
EclOutput outFile(resFile, formattedOutput);
auto arrayList = file1.getList();
for (size_t index = 0; index < arrayList.size(); index++) {
std::string name = std::get<0>(arrayList[index]);
EIOD::eclArrType arrType = std::get<1>(arrayList[index]);
if (arrType == EIOD::INTE) {
write<int>(outFile, file1, name, index);
} else if (arrType == EIOD::REAL) {
write<float>(outFile, file1, name,index);
} else if (arrType == EIOD::DOUB) {
write<double>(outFile, file1, name, index);
} else if (arrType == EIOD::LOGI) {
write<bool>(outFile, file1, name, index);
} else if (arrType == EIOD::CHAR) {
write<std::string>(outFile, file1, name, index);
} else if (arrType == EIOD::MESS) {
// shold not be any associated data
outFile.write(name,std::vector<char>());
} else {
std::cout << "unknown array type " << std::endl;
exit(1);
}
}
auto end2 = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds2 = end2-end1;
std::cout << "\ntime to load from file : " << argv[1] << ": " << elapsed_seconds1.count() << " seconds" << std::endl;
std::cout << "time to write to file : " << resFile << ": " << elapsed_seconds2.count() << " seconds\n" << std::endl;
return 0;
}

View File

@@ -1,76 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef OPM_ECLIO_DATA_HPP
#define OPM_ECLIO_DATA_HPP
#include <tuple>
namespace Opm {
namespace ecl {
// type MESS have no assisiated data
enum eclArrType {
INTE, REAL, DOUB, CHAR, LOGI, MESS
};
// named constants related to binary file format
const unsigned int true_value = 0xffffffff;
const unsigned int false_value = 0x00000000;
const int sizeOfInte = 4; // number of bytes pr integer (inte) element
const int sizeOfReal = 4; // number of bytes pr float (real) element
const int sizeOfDoub = 8; // number of bytes pr double (doub) element
const int sizeOfLogi = 4; // number of bytes pr bool (logi) element
const int sizeOfChar = 8; // number of bytes pr string (char) element
const int MaxBlockSizeInte = 4000; // Maximum block size for INTE arrays in binary files
const int MaxBlockSizeReal = 4000; // Maximum block size for REAL arrays in binary files
const int MaxBlockSizeDoub = 8000; // Maximum block size for DOUB arrays in binary files
const int MaxBlockSizeLogi = 4000; // Maximum block size for LOGI arrays in binary files
const int MaxBlockSizeChar = 840; // Maximum block size for CHAR arrays in binary files
// named constants related to formatted file file format
const int MaxNumBlockInte = 1000; // maximum number of Inte values in block => hard line shift
const int MaxNumBlockReal = 1000; // maximum number of Real values in block => hard line shift
const int MaxNumBlockDoub = 1000; // maximum number of Doub values in block => hard line shift
const int MaxNumBlockLogi = 1000; // maximum number of Logi values in block => hard line shift
const int MaxNumBlockChar = 105; // maximum number of Char values in block => hard line shift
const int numColumnsInte = 6; // number of columns for Inte values
const int numColumnsReal = 4; // number of columns for Real values
const int numColumnsDoub = 3; // number of columns for Doub values
const int numColumnsLogi = 25; // number of columns for Logi values
const int numColumnsChar = 7; // number of columns for Char values
const int columnWidthInte = 12; // number of characters fore each Inte Element
const int columnWidthReal = 17; // number of characters fore each Inte Element
const int columnWidthDoub = 23; // number of characters fore each Inte Element
const int columnWidthLogi = 3; // number of characters fore each Inte Element
const int columnWidthChar = 11; // number of characters fore each Inte Element
} // ecl
} // Opm
#endif // OPM_ECLIO_DATA_HPP

View File

@@ -0,0 +1,240 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryComparator.hpp"
#include <ert/ecl/ecl_sum.h>
#include <ert/util/stringlist.h>
#include <ert/util/int_vector.h>
#include <ert/util/bool_vector.h>
#include <opm/common/ErrorMacros.hpp>
#include <cmath>
#include <numeric>
SummaryComparator::SummaryComparator(const std::string& basename1,
const std::string& basename2,
double absoluteTol, double relativeTol){
ecl_sum1 = ecl_sum_fread_alloc_case(basename1.c_str(), ":");
ecl_sum2 = ecl_sum_fread_alloc_case(basename2.c_str(), ":");
if (ecl_sum1 == nullptr || ecl_sum2 == nullptr) {
OPM_THROW(std::runtime_error, "Not able to open files");
}
absoluteTolerance = absoluteTol;
relativeTolerance = relativeTol;
keys1 = stringlist_alloc_new();
keys2 = stringlist_alloc_new();
ecl_sum_select_matching_general_var_list( ecl_sum1 , "*" , this->keys1);
stringlist_sort(this->keys1 , nullptr );
ecl_sum_select_matching_general_var_list( ecl_sum2 , "*" , this->keys2);
stringlist_sort(this->keys2 , nullptr );
if(stringlist_get_size(keys1) <= stringlist_get_size(keys2)){
this->keysShort = this->keys1;
this->keysLong = this->keys2;
}else{
this->keysShort = this->keys2;
this->keysLong = this->keys1;
}
}
SummaryComparator::~SummaryComparator(){
ecl_sum_free(ecl_sum1);
ecl_sum_free(ecl_sum2);
stringlist_free(keys1);
stringlist_free(keys2);
}
Deviation SummaryComparator::calculateDeviations(double val1, double val2){
double absDev;
Deviation deviation;
absDev = std::abs(val1 - val2);
deviation.abs = absDev;
if (val1 != 0 || val2 != 0) {
deviation.rel = absDev/double(std::max(std::abs(val1), std::abs(val2)));
}
return deviation;
}
void SummaryComparator::setTimeVecs(std::vector<double> &timeVec1,
std::vector<double> &timeVec2){
timeVec1.reserve(ecl_sum_get_data_length(ecl_sum1));
for (int time_index = 0; time_index < ecl_sum_get_data_length(ecl_sum1); time_index++){
timeVec1.push_back(ecl_sum_iget_sim_days(ecl_sum1 , time_index ));
}
timeVec2.reserve(ecl_sum_get_data_length(ecl_sum2));
for (int time_index = 0; time_index < ecl_sum_get_data_length(ecl_sum2); time_index++){
timeVec2.push_back(ecl_sum_iget_sim_days(ecl_sum2 , time_index ));
}
}
void SummaryComparator::getDataVecs(std::vector<double> &dataVec1,
std::vector<double> &dataVec2,
const char* keyword){
dataVec1.reserve(ecl_sum_get_data_length(ecl_sum1));
for (int time_index = 0; time_index < ecl_sum_get_data_length(ecl_sum1); time_index++){
dataVec1.push_back(ecl_sum_iget(ecl_sum1, time_index, ecl_sum_get_general_var_params_index( ecl_sum1 , keyword )));
}
dataVec2.reserve(ecl_sum_get_data_length(ecl_sum2));
for (int time_index = 0; time_index < ecl_sum_get_data_length(ecl_sum2); time_index++){
dataVec2.push_back(ecl_sum_iget(ecl_sum2, time_index, ecl_sum_get_general_var_params_index( ecl_sum2 , keyword )));
}
}
void SummaryComparator::setDataSets(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2){
if(timeVec1.size() < timeVec2.size()){
ecl_sum_fileShort = this->ecl_sum1;
ecl_sum_fileLong = this->ecl_sum2;
}
else{
ecl_sum_fileShort = this->ecl_sum2;
ecl_sum_fileLong = this->ecl_sum1;
}
}
void SummaryComparator::chooseReference(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const std::vector<double>& dataVec1,
const std::vector<double>& dataVec2){
if(timeVec1.size() <= timeVec2.size()){
referenceVec = &timeVec1; // time vector
referenceDataVec = &dataVec1; //data vector
checkVec = &timeVec2;
checkDataVec = &dataVec2;
}
else{
referenceVec = &timeVec2;
referenceDataVec = &dataVec2;
checkVec = &timeVec1;
checkDataVec = &dataVec1;
}
}
void SummaryComparator::getDeviation(size_t refIndex, size_t &checkIndex, Deviation &dev){
if((*referenceVec)[refIndex] == (*checkVec)[checkIndex]){
dev = SummaryComparator::calculateDeviations((*referenceDataVec)[refIndex], (*checkDataVec)[checkIndex]);
checkIndex++;
return;
}
else if((*referenceVec)[refIndex]<(*checkVec)[checkIndex]){
double value = SummaryComparator::unitStep((*checkDataVec)[checkIndex]);
/*Must be a little careful here. Flow writes out old value first,
than changes value. Say there should be a change in production rate from A to B at timestep 300.
Then the data of time step 300 is A and the next timestep will have value B. Must use the upper limit. */
dev = SummaryComparator::calculateDeviations((*referenceDataVec)[refIndex], value);
checkIndex++;
return;
}
else{
checkIndex++;
getDeviation(refIndex, checkIndex , dev);
}
if(checkIndex == checkVec->size() -1 ){
return;
}
}
void SummaryComparator::printUnits(){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2);
for (int jvar = 0; jvar < stringlist_get_size(keysLong); jvar++){
std::cout << stringlist_iget(keysLong, jvar) << " unit: " << ecl_sum_get_unit(ecl_sum_fileShort, stringlist_iget(keysLong, jvar)) << std::endl;
}
}
//Called only when the keywords are equal in the getDeviations()-function
const char* SummaryComparator::getUnit(const char* keyword){
return ecl_sum_get_unit(ecl_sum_fileShort, keyword);
}
void SummaryComparator::printKeywords(){
int ivar = 0;
std::vector<std::string> noMatchString;
std::cout << "Keywords that are common for the files:" << std::endl;
while(ivar < stringlist_get_size(keysLong)){
const char* keyword = stringlist_iget(keysLong, ivar);
if (stringlist_contains(keysLong, keyword) && stringlist_contains(keysShort, keyword)){
std::cout << keyword << std::endl;
ivar++;
}
else{
noMatchString.push_back(keyword);
ivar++;
}
}
if(noMatchString.size() == 0){
std::cout << "No keywords were different" << std::endl;
return;
}
std::cout << "Keywords that are different: " << std::endl;
for (const auto& it : noMatchString) std::cout << it << std::endl;
std::cout << "\nOf the " << stringlist_get_size(keysLong) << " keywords " << stringlist_get_size(keysLong)-noMatchString.size() << " were equal and " << noMatchString.size() << " were different" << std::endl;
}
void SummaryComparator::printDataOfSpecificKeyword(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const char* keyword){
std::vector<double> dataVec1, dataVec2;
getDataVecs(dataVec1,dataVec2,keyword);
chooseReference(timeVec1, timeVec2,dataVec1,dataVec2);
size_t ivar = 0;
size_t jvar = 0;
const char separator = ' ';
const int numWidth = 14;
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << "Time";
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << "Ref data";
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << "Check data" << std::endl;
while(ivar < referenceVec->size()){
if(ivar == referenceVec->size() || jvar == checkVec->size() ){
break;
}
if((*referenceVec)[ivar] == (*checkVec)[jvar]){
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*referenceVec)[ivar];
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*referenceDataVec)[ivar];
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*checkDataVec)[jvar] << std::endl;
ivar++;
jvar++;
}else if((*referenceVec)[ivar] < (*checkVec)[jvar]){
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*referenceVec)[ivar];
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*referenceDataVec)[ivar];
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << "" << std::endl;
ivar++;
}
else{
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*checkVec)[jvar];
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << "";
std::cout << std::left << std::setw(numWidth) << std::setfill(separator) << (*checkDataVec)[jvar] << std::endl;
jvar++;
}
}
}

View File

@@ -0,0 +1,182 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef SUMMARYCOMPARATOR_HPP
#define SUMMARYCOMPARATOR_HPP
#include "Deviation.hpp"
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
// helper macro to handle error throws or not
#define HANDLE_ERROR(type, message) \
{ \
if (throwOnError) \
OPM_THROW(type, message); \
else \
std::cerr << message << std::endl; \
}
//! \brief Prototyping struct, encapsuling the stringlist libraries.
struct stringlist_struct;
typedef struct stringlist_struct stringlist_type;
//! \brief Prototyping struct, encapsuling the ert libraries.
struct ecl_sum_struct;
typedef struct ecl_sum_struct ecl_sum_type;
class SummaryComparator {
private:
double absoluteTolerance = 0; //!< The maximum absolute deviation that is allowed between two values.
double relativeTolerance = 0; //!< The maximum relative deviation that is allowed between twi values.
protected:
ecl_sum_type * ecl_sum1 = nullptr; //!< Struct that contains file1
ecl_sum_type * ecl_sum2 = nullptr; //!< Struct that contains file2
ecl_sum_type * ecl_sum_fileShort = nullptr; //!< For keeping track of the file with most/fewest timesteps
ecl_sum_type * ecl_sum_fileLong = nullptr; //!< For keeping track of the file with most/fewest timesteps
stringlist_type* keys1 = nullptr; //!< For storing all the keywords of file1
stringlist_type* keys2 = nullptr; //!< For storing all the keywords of file2
stringlist_type * keysShort = nullptr; //!< For keeping track of the file with most/fewest keywords
stringlist_type * keysLong = nullptr; //!< For keeping track of the file with most/fewest keywords
const std::vector<double> * referenceVec = nullptr; //!< For storing the values of each time step for the file containing the fewer time steps.
const std::vector<double> * referenceDataVec = nullptr; //!< For storing the data corresponding to each time step for the file containing the fewer time steps.
const std::vector<double> * checkVec = nullptr; //!< For storing the values of each time step for the file containing the more time steps.
const std::vector<double> * checkDataVec = nullptr; //!< For storing the data values corresponding to each time step for the file containing the more time steps.
bool printKeyword = false; //!< Boolean value for choosing whether to print the keywords or not
bool printSpecificKeyword = false; //!< Boolean value for choosing whether to print the vectors of a keyword or not
bool throwOnError = true; //!< Throw on first error
bool analysis = false; //!< Perform error analysis
std::map<std::string, std::vector<Deviation>> deviations;
//! \brief Calculate deviation between two data values and stores it in a Deviation struct.
//! \param[in] refIndex Index in reference data
//! \param[in] checkindex Index in data to be checked.
//! \param[out] dev Holds the result from the comparison on return.
//! \details Uses the #referenceVec as basis, and checks its values against the values in #checkDataVec. The function is reccursive, and will update the iterative index j of the #checkVec until #checkVec[j] >= #referenceVec[i]. \n When #referenceVec and #checkVec have the same time value (i.e. #referenceVec[i] == #checkVec[j]) a direct comparison is used, \n when this is not the case, when #referenceVec[i] do not excist as an element in #checkVec, a value is generated, either by the principle of unit step or by interpolation.
void getDeviation(size_t refIndex, size_t &checkIndex, Deviation &dev);
//! \brief Figure out which data file contains the most / less timesteps and assign member variable pointers accordingly.
//! \param[in] timeVec1 Data from first file
//! \param[in] timeVec2 Data from second file
//! \details Figure out which data file that contains the more/fewer time steps and assigns the private member variable pointers #ecl_sum_fileShort / #ecl_sum_fileLong to the correct data sets #ecl_sum1 / #ecl_sum2.
void setDataSets(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2);
//! \brief Reads in the time values of each time step.
//! \param[in] timeVec1 Vector for storing the time steps from file1
//! \param[in] timeVec2 Vector for storing the time steps from file2
void setTimeVecs(std::vector<double> &timeVec1,std::vector<double> &timeVec2);
//! \brief Read the data for one specific keyword into two separate vectors.
//! \param[in] dataVec1 Vector for storing the data for one specific keyword from file1
//! \param[in] dataVec2 Vector for storing the data for one specific keyword from file2
//! \details The two data files do not necessarily have the same amount of data values, but the values must correspond to the same interval in time. Thus possible to interpolate values.
void getDataVecs(std::vector<double> &dataVec1,
std::vector<double> &dataVec2, const char* keyword);
//! \brief Sets one data set as a basis and the other as values to check against.
//! \param[in] timeVec1 Used to figure out which dataset that have the more/fewer time steps.
//! \param[in] timeVec2 Used to figure out which dataset that have the more/fewer time steps.
//! \param[in] dataVec1 For assiging the the correct pointer to the data vector.
//! \param[in] dataVec2 For assiging the the correct pointer to the data vector.
//! \details Figures out which time vector that contains the fewer elements. Sets this as #referenceVec and its corresponding data as #referenceDataVec. \n The remaining data set is set as #checkVec (the time vector) and #checkDataVec.
void chooseReference(const std::vector<double> &timeVec1,
const std::vector<double> &timeVec2,
const std::vector<double> &dataVec1,
const std::vector<double> &dataVec2);
//! \brief Returns the relative tolerance.
double getRelTolerance(){return this->relativeTolerance;}
//! \brief Returns the absolute tolerance.
double getAbsTolerance(){return this->absoluteTolerance;}
//! \brief Returns the unit of the values of a keyword
//! \param[in] keyword The keyword of interest.
//! \param[out] ret The unit of the keyword as a const char*.
const char* getUnit(const char* keyword);
//! \brief Prints the units of the files.
void printUnits();
//! \brief Prints the keywords of the files.
//! \details The function prints first the common keywords, than the keywords that are different.
void printKeywords();
//! \brief Prints the summary vectors from the two files.
//! \details The function requires that the summary vectors of the specific file have been read into the member variables referenceVec etc.
void printDataOfSpecificKeyword(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const char* keyword);
public:
//! \brief Creates an SummaryComparator class object
//! \param[in] basename1 Path to file1 without extension.
//! \param[in] basename1 Path to file2 without extension.
//! \param[in] absoluteTolerance The absolute tolerance which is to be used in the test.
//! \param[in] relativeTolerance The relative tolerance which is to be used in the test.
//! \details The constructor creates an object of the class, and openes the files, an exception is thrown if the opening of the files fails. \n It creates stringlists, in which keywords are to be stored, and figures out which keylist that contains the more/less keywords. \n Also the private member variables aboluteTolerance and relativeTolerance are set.
SummaryComparator(const std::string& basename1,
const std::string& basename2,
double absoluteTolerance, double relativeTolerance);
//! \brief Destructor
//! \details The destructor takes care of the allocated memory in which data has been stored.
~SummaryComparator();
//! \brief Calculates the deviation between two values
//! \param[in] val1 The first value of interest.
//! \param[in] val2 The second value if interest.
//! \param[out] ret Returns a Deviation struct.
//! \details The function takes two values, calculates the absolute and relative deviation and returns the result as a Deviation struct.
static Deviation calculateDeviations( double val1, double val2);
//! \brief Sets the private member variable printKeywords
//! \param[in] boolean Boolean value
//! \details The function sets the private member variable printKeywords. When it is true the function printKeywords will be called.
void setPrintKeywords(bool boolean){this->printKeyword = boolean;}
//! \brief Sets the private member variable printSpecificKeyword
//! \param[in] boolean Boolean value
//! \details The function sets the private member variable printSpecificKeyword. When true, the summary vector of the keyword for both files will be printed.
void setPrintSpecificKeyword(bool boolean){this->printSpecificKeyword = boolean;}
//! \brief Unit step function
//! \param[in] value The input value should be the last know value
//! \param[out] ret Return the unit-step-function value.
//! \details In this case: The unit step function is used when the data from the two data set, which is to be compared, don't match in time. \n The unit step function is then to be called on the #checkDataVec 's value at the last time step which is before the time of comparison.
//! \brief Returns a value based on the unit step principle.
static double unitStep(double value){return value;}
//! \brief Set whether to throw on errors or not.
void throwOnErrors(bool dothrow) { throwOnError = dothrow; }
//! \brief Set whether or not to perform error analysis.
void doAnalysis(bool analyse) { analysis = analyse; }
};
#endif

View File

@@ -0,0 +1,389 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryIntegrationTest.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <ert/ecl/ecl_sum.h>
#include <ert/util/stringlist.h>
#include <cmath>
void SummaryIntegrationTest::getIntegrationTest(){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2);
int ivar = 0;
if(!allowDifferentAmountOfKeywords){
if(stringlist_get_size(keysShort) != stringlist_get_size(keysLong)){
OPM_THROW(std::invalid_argument, "Different ammont of keywords in the two summary files.");
}
}
if(printKeyword){
printKeywords();
return;
}
std::string keywordWithGreatestErrorRatio;
double greatestRatio = 0;
//Iterates over all keywords from the restricted file, use iterator "ivar". Searches for a match in the file with more keywords, use the itarator "jvar".
while(ivar < stringlist_get_size(keysShort)){
const char* keyword = stringlist_iget(keysShort, ivar);
if(oneOfTheMainVariables){
std::string keywordString(keyword);
std::string substr = keywordString.substr(0,4);
if(substr!= mainVariable){
ivar++;
continue;
}
}
for (int jvar = 0; jvar < stringlist_get_size(keysLong); jvar++){
if (strcmp(keyword, stringlist_iget(keysLong, jvar)) == 0){ //When the keywords are equal, proceed in comparing summary files.
/* if(!checkUnits(keyword)){
OPM_THROW(std::runtime_error, "For keyword " << keyword << " the unit of the two files is not equal. Not possible to compare.");
} //Comparing the unit of the two vectors.*/
checkForKeyword(timeVec1, timeVec2, keyword);
if(findVectorWithGreatestErrorRatio){
WellProductionVolume volume = getSpecificWellVolume(timeVec1,timeVec2, keyword);
findGreatestErrorRatio(volume,greatestRatio, keyword, keywordWithGreatestErrorRatio);
}
break;
}
//will only enter here if no keyword match
if(jvar == stringlist_get_size(keysLong)-1){
if(!allowDifferentAmountOfKeywords){
OPM_THROW(std::invalid_argument, "No match on keyword");
}
}
}
ivar++;
}
if(findVectorWithGreatestErrorRatio){
std::cout << "The keyword " << keywordWithGreatestErrorRatio << " had the greatest error ratio, which was " << greatestRatio << std::endl;
}
if((findVolumeError || oneOfTheMainVariables) && !findVectorWithGreatestErrorRatio){
evaluateWellProductionVolume();
}
if(allowSpikes){
std::cout << "checkWithSpikes succeeded." << std::endl;
}
}
void SummaryIntegrationTest::getIntegrationTest(const char* keyword){
if(stringlist_contains(keysShort,keyword) && stringlist_contains(keysLong, keyword)){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2);
if(printSpecificKeyword){
printDataOfSpecificKeyword(timeVec1, timeVec2, keyword);
}
if(findVolumeError){
WellProductionVolume volume = getSpecificWellVolume(timeVec1, timeVec2, keyword);
if(volume.error == 0){
std::cout << "For keyword " << keyword << " the total production volume is 0" << std::endl;
}
else{
std::cout << "For keyword " << keyword << " the total production volume is "<< volume.total;
std::cout << ", the error volume is " << volume.error << " the error ratio is " << volume.error/volume.total << std::endl;
}
}
checkForKeyword(timeVec1, timeVec2, keyword);
return;
}
OPM_THROW(std::invalid_argument, "The keyword used is not common for the two files.");
}
void SummaryIntegrationTest::checkForKeyword(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const char* keyword){
std::vector<double> dataVec1, dataVec2;
getDataVecs(dataVec1,dataVec2,keyword);
chooseReference(timeVec1, timeVec2,dataVec1,dataVec2);
if(allowSpikes){
checkWithSpikes(keyword);
}
if(findVolumeError ||oneOfTheMainVariables ){
volumeErrorCheck(keyword);
}
}
int SummaryIntegrationTest::checkDeviation(const Deviation& deviation){
double absTol = getAbsTolerance();
double relTol = getRelTolerance();
if (deviation.rel> relTol && deviation.abs > absTol){
return 1;
}
return 0;
}
void SummaryIntegrationTest::findGreatestErrorRatio(const WellProductionVolume& volume,
double &greatestRatio,
const char* currentKeyword,
std::string &greatestErrorRatio){
if (volume.total != 0 && (volume.total - volume.error > getAbsTolerance()) ){
if(volume.error/volume.total > greatestRatio){
greatestRatio = volume.error/volume.total;
std::string currentKeywordStr(currentKeyword);
greatestErrorRatio = currentKeywordStr;
}
}
}
void SummaryIntegrationTest::volumeErrorCheck(const char* keyword){
const smspec_node_type * node = ecl_sum_get_general_var_node (ecl_sum_fileShort ,keyword);//doesn't matter which ecl_sum_file one uses, the kewyord SHOULD be equal in terms of smspec data.
bool hist = smspec_node_is_historical(node);
/* returns true if the keyword corresponds to a summary vector "history".
E.g. WOPRH, where the last character, 'H', indicates that it is a HISTORY vector.*/
if(hist){
return;//To make sure we do not include history vectors.
}
if (!mainVariable.empty()){
std::string keywordString(keyword);
std::string firstFour = keywordString.substr(0,4);
if(mainVariable == firstFour && firstFour == "WOPR"){
if(firstFour == "WOPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WOP += result;
return;
}
}
if(mainVariable == firstFour && firstFour == "WWPR"){
if(firstFour == "WWPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WWP += result;
return;
}
}
if(mainVariable == firstFour && firstFour == "WGPR"){
if(firstFour == "WGPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WGP += result;
return;
}
}
if(mainVariable == firstFour && firstFour == "WBHP"){
if(firstFour == "WBHP"){
WellProductionVolume result = getWellProductionVolume(keyword);
WBHP += result;
return;
}
}
}
updateVolumeError(keyword);
}
void SummaryIntegrationTest::updateVolumeError(const char* keyword){
std::string keywordString(keyword);
std::string firstFour = keywordString.substr(0,4);
if(firstFour == "WOPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WOP += result;
}
if(firstFour == "WWPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WWP += result;
}
if(firstFour == "WGPR"){
WellProductionVolume result = getWellProductionVolume(keyword);
WGP += result;
}
if(firstFour == "WBHP"){
WellProductionVolume result = getWellProductionVolume(keyword);
WBHP += result;
}
}
WellProductionVolume SummaryIntegrationTest::getWellProductionVolume(const char * keyword){
double total = integrate(*referenceVec, *referenceDataVec);
double error = integrateError(*referenceVec, *referenceDataVec,
*checkVec, *checkDataVec);
WellProductionVolume wPV;
wPV.total = total;
wPV.error = error;
if(wPV.total != 0 && wPV.total-wPV.error > getAbsTolerance()){
if( (wPV.error/wPV.total > getRelTolerance()) && throwExceptionForTooGreatErrorRatio){
OPM_THROW(std::runtime_error, "For the keyword "<< keyword << " the error ratio was " << wPV.error/wPV.total << " which is greater than the tolerance " << getRelTolerance());
}
}
return wPV;
}
void SummaryIntegrationTest::evaluateWellProductionVolume(){
if(mainVariable.empty()){
double ratioWOP, ratioWWP, ratioWGP, ratioWBHP;
ratioWOP = WOP.error/WOP.total;
ratioWWP = WWP.error/WWP.total;
ratioWGP = WGP.error/WGP.total;
ratioWBHP = WBHP.error/WBHP.total;
std::cout << "\n The total oil volume is " << WOP.total << ". The error volume is "<< WOP.error << ". The error ratio is " << ratioWOP << std::endl;
std::cout << "\n The total water volume is " << WWP.total << ". The error volume is "<< WWP.error << ". The error ratio is " << ratioWWP << std::endl;
std::cout << "\n The total gas volume is " << WGP.total <<". The error volume is "<< WGP.error << ". The error ratio is " << ratioWGP << std::endl;
std::cout << "\n The total area under the WBHP curve is " << WBHP.total << ". The area under the error curve is "<< WBHP.error << ". The error ratio is " << ratioWBHP << std::endl << std::endl;
}
if(mainVariable == "WOPR"){
std::cout << "\nThe total oil volume is " << WOP.total << ". The error volume is "<< WOP.error << ". The error ratio is " << WOP.error/WOP.total << std::endl<< std::endl;
}
if(mainVariable == "WWPR"){
std::cout << "\nThe total water volume is " << WWP.total << ". The error volume is "<< WWP.error << ". The error ratio is " << WWP.error/WWP.total << std::endl<< std::endl;
}
if(mainVariable == "WGPR"){
std::cout << "\nThe total gas volume is " << WGP.total <<". The error volume is "<< WGP.error << ". The error ratio is " << WGP.error/WGP.total << std::endl<< std::endl;
}
if(mainVariable == "WBHP"){
std::cout << "\nThe total area under the WBHP curve " << WBHP.total << ". The area under the error curve is "<< WBHP.error << ". The error ratio is " << WBHP.error/WBHP.total << std::endl << std::endl;
}
}
void SummaryIntegrationTest::checkWithSpikes(const char* keyword){
int errorOccurrences = 0;
size_t jvar = 0 ;
bool spikeCurrent = false;
Deviation deviation;
for (size_t ivar = 0; ivar < referenceVec->size(); ivar++){
int errorOccurrencesPrev = errorOccurrences;
bool spikePrev = spikeCurrent;
getDeviation(ivar,jvar, deviation);
errorOccurrences += checkDeviation(deviation);
if (errorOccurrences != errorOccurrencesPrev){
spikeCurrent = true;
} else{
spikeCurrent = false;
}
if(spikePrev&&spikeCurrent){
std::cout << "For keyword " << keyword << " at time step " << (*referenceVec)[ivar] <<std::endl;
OPM_THROW(std::invalid_argument, "For keyword " << keyword << " at time step " << (*referenceVec)[ivar] << ", wwo deviations in a row exceed the limit. Not a spike value. Integration test fails." );
}
if(errorOccurrences > this->spikeLimit){
std::cout << "For keyword " << keyword << std::endl;
OPM_THROW(std::invalid_argument, "For keyword " << keyword << " too many spikes in the vector. Integration test fails.");
}
}
}
WellProductionVolume
SummaryIntegrationTest::getSpecificWellVolume(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const char* keyword){
std::vector<double> dataVec1, dataVec2;
getDataVecs(dataVec1,dataVec2,keyword);
chooseReference(timeVec1, timeVec2,dataVec1,dataVec2);
return getWellProductionVolume(keyword);
}
double SummaryIntegrationTest::integrate(const std::vector<double>& timeVec,
const std::vector<double>& dataVec){
double totalSum = 0;
if(timeVec.size() != dataVec.size()){
OPM_THROW(std::runtime_error, "The size of the time vector does not match the size of the data vector.");
}
for(size_t i = 0; i < timeVec.size()-1; i++){
double width = timeVec[i+1] - timeVec[i];
double height = dataVec[i+1];
totalSum += getRectangleArea(height, width);
}
return totalSum;
}
double SummaryIntegrationTest::integrateError(const std::vector<double>& timeVec1,
const std::vector<double>& dataVec1,
const std::vector<double>& timeVec2,
const std::vector<double>& dataVec2){
// When the data corresponds to a rate the integration will become a Riemann
// sum. This function calculates the Riemann sum of the error. The reason why
// a Riemann sum is used is because of the way the data is written to file.
// When a change occur (e.g. change of a rate), the data (value and time) is
// written to file, THEN the change happens in the simulator, i.e., we will
// notice the change at the next step.
//
// Keep in mind that the summary vector is NOT a continuous curve, only points
// of data (time, value). We have to guess what happens between the data
// points, we do this by saying: "There are no change, the only change happens
// at the data points." As stated above, the value of this constant "height" of
// the rectangle corresponds to the value of the last time step. Thus we have
// to use the "right hand side value of the rectangle as height
//
// someDataVector[ivar] instead of someDataVector[ivar-1]
//
// (which intuition is saying is the correct value to use).
if(timeVec1.size() != dataVec1.size() || timeVec2.size() != dataVec2.size() ){
OPM_THROW(std::runtime_error, "The size of the time vector does not match the size of the data vector.");
}
double errorSum = 0;
double rightEdge, leftEdge, width;
size_t i = 1;
size_t j = 1;
leftEdge = timeVec1[0];
while(i < timeVec1.size()){
if(j == timeVec2.size() ){
break;
}
if(timeVec1[i] == timeVec2[j]){
rightEdge = timeVec1[i];
width = rightEdge - leftEdge;
double dev = std::fabs(dataVec1[i] - dataVec2[j]);
errorSum += getRectangleArea(dev, width);
leftEdge = rightEdge;
i++;
j++;
continue;
}
if(timeVec1[i] < timeVec2[j]){
rightEdge = timeVec1[i];
width = rightEdge - leftEdge;
double value = unitStep(dataVec2[j]);
double dev = std::fabs(dataVec1[i]-value);
errorSum += getRectangleArea(dev, width);
leftEdge = rightEdge;
i++;
continue;
}
if(timeVec2[j] < timeVec1[i]){
rightEdge = timeVec2[j];
width = rightEdge - leftEdge;
double value = unitStep(dataVec1[i]);
double dev = std::fabs(dataVec2[j]-value);
errorSum += getRectangleArea(dev, width);
leftEdge = rightEdge;
j++;
continue;
}
}
return errorSum;
}

View File

@@ -0,0 +1,217 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryComparator.hpp"
//! \brief Struct for storing the total area under a graph.
//! \details Used when plotting summary vector against time. In most cases this represents a volume.
struct WellProductionVolume{
double total=0; //!< The total area under the graph when plotting the summary vector against time. In most cases the total production volume.
double error=0; //!< The total area under the graph when plotting the deviation vector against time. In most cases the total error volume.
//! \brief Overloaded operator
//! \param[in] rhs WellProductionVolume struct
WellProductionVolume& operator+=(const WellProductionVolume& rhs){
this->total += rhs.total;
this->error += rhs.error;
return *this;
}
};
//! \details The class inherits from the SummaryComparator class, which takes care of all file reading. \n The IntegrationTest class compares values from the two different files and throws exceptions when the deviation is unsatisfying.
class SummaryIntegrationTest: public SummaryComparator {
private:
bool allowSpikes = false; //!< Boolean value, when true checkForSpikes is included as a sub test in the integration test. By default: false.
bool findVolumeError = false; //!< Boolean value, when true volumeErrorCheck() is included as a sub test in the integration test. By default: false.
bool allowDifferentAmountOfKeywords = true; //!< Boolean value, when false the integration test will check wheter the two files have the same amount of keywords. \nIf they don't, an exception will be thrown. By default: true.
bool findVectorWithGreatestErrorRatio = false; //!< Boolean value, when true the integration test will find the vector that has the greatest error ratio. By default: false.
bool oneOfTheMainVariables = false; //!< Boolean value, when true the integration test will only check for one of the primary variables (WOPR, WGPR, WWPR. WBHP), which will be specified by user. By default: false.
bool throwExceptionForTooGreatErrorRatio = true; //!< Boolean value, when true any volume error ratio that exceeds the relativeTolerance will cause an exception to be thrown. By default: true.
std::string mainVariable; //!< String variable, where the name of the main variable of interest (one of WOPR, WBHP, WWPR, WGPR) is stored. Can be empty.
int spikeLimit = 13370; //!< The limit for how many spikes to allow in the data set of a certain keyword. By default: Set to a high number, \n should not trig the (if spikeOccurrences > spikeLimit){ // throw exception }.
WellProductionVolume WOP; //!< WellProductionVolume struct for storing the total production volume and total error volume of all the keywords which start with WOPR
WellProductionVolume WWP; //!< WellProductionVolume struct for storing the total production volume and total error volume of all the keywords which start with WWPR
WellProductionVolume WGP;//!< WellProductionVolume struct for storing the total production volume and total error volume of all the keywords which start with WGPR
WellProductionVolume WBHP; //!< WellProductionVolume struct for storing the value of the area under the graph when plotting summary vector/deviation vector against time.This is for keywords starting with WBHP. \nNote: the name of the struct may be misleading, this is not an actual volume.
//! \brief The function gathers the correct data for comparison for a specific keyword
//! \param[in] timeVec1 A std::vector<double> that contains the time steps of file 1.
//! \param[in] timeVec2 A std::vector<double> that contains the time steps of file 2.
//! \param[in] keyword The keyword of interest
//! \details The function requires an outer loop which iterates over the keywords of the files. It prepares an integration test by gathering the data, stroing it into two vectors, \n deciding which is to be used as a reference/basis and calling the test function.
void checkForKeyword(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2, const char* keyword);
//! \brief The function compares the volume error to the total production volume of a certain type of keyword.
//! param[in] keyword The keyword of interest.
//! \details The function takes in a keyword and checks if it is of interest. Only keywords which say something about the well oil production, well water production, \n well gas production and the well BHP are of interest. The function sums up the total production in the cases where it is possible, \n and sums up the error volumes by a trapezoid integration method. The resulting values are stored in member variable structs of type WellProductionVolume, and double variables. For proper use of the function all the keywords of the file should be checked. This is satisfied if it is called by checkForKeyword.
void volumeErrorCheck(const char* keyword);
//! \brief The function calculates the total production volume and total error volume of a specific keyword
//! \param[in] timeVec1 A std::vector<double> that contains the time steps of file 1.
//! \param[in] timeVec2 A std::vector<double> that contains the time steps of file 2.
//! \param[in] keyword The keyword of interest
//! \param[out] ret Returns a WellProductionWolume struct
//! \details The function reads the data from the two files into the member variable vectors (of the super class). It returns a WellProductionVolume struct calculated from the vectors corresponding to the keyword.
WellProductionVolume getSpecificWellVolume(const std::vector<double>& timeVec1,
const std::vector<double>& timeVec2,
const char* keyword);
//! \brief The function is a regression test which allows spikes.
//! \param[in] keyword The keyword of interest, the keyword the summary vectors "belong" to.
//! \details The function requires the protected member variables referenceVec, referenceDataVec, checkVec and checkDataVec to be stored with data, which is staisfied if it is called by checkForKeyword. \n It compares the two vectors value by value, and if the deviation is unsatisfying, the errorOccurrenceCounter is incremented. If the errorOccurrenceCounter becomes greater than the errorOccurrenceLimit, \n a exception is thrown. The function will allow spike values, however, if two values in a row exceed the deviation limit, they are no longer spikes, and an exception is thrown.
void checkWithSpikes(const char* keyword);
//! \brief Caluculates a deviation, throws exceptions and writes and error message.
//! \param[in] deviation Deviation struct
//! \param[out] int Returns 0/1, depending on wheter the deviation exceeded the limit or not.
//! \details The function checks the values of the Deviation struct against the absolute and relative tolerance, which are private member values of the super class. \n When comparing against the relative tolerance an additional term is added, the absolute deviation has to be greater than 1e-6 for the function to throw an exception. \n When the deviations are too great, the function returns 1.
int checkDeviation(const Deviation& deviation);
//! \brief Calculates the keyword's total production volume and error volume
//! \param[in] keyword The keyword of interest.
//! \param[out] wellProductionVolume A struct containing the total production volume and the total error volume.
//! \details The function calculates the total production volume and total error volume of a keyword, by the trapezoid integral method. \n The function throws and exception if the total error volume is negative. The function returns the results as a struct.
WellProductionVolume getWellProductionVolume(const char* keyword);
//! \brief The function function works properly when the private member variables are set (after running the integration test which findVolumeError = true). \n It prints out the total production volume, the total error volume and the error ratio.
void evaluateWellProductionVolume();
//! \brief The function calculates the total production volume and total error volume
//! \param keyword The keyword of interest
//! \details The function uses the data that is stored in the member variable vectors. It calculates the total production volume \n and the total error volume of the specified keyword, and adds the result to the private member WellProductionVolume variables of the class.
void updateVolumeError(const char* keyword);
//! \brief Finds the keyword which has the greates error volume ratio
//! \param[in] volume WellProductionVolume struct which contains the data used for comparison
//! \param[in] greatestRatio Double value taken in by reference. Stores the greatest error ratio value.
//! \param[in] currentKeyword The keyword that is under evaluation
//! \param[in] greatestErrorRatio String which contains the name of the keyword which has the greatest error ratio
//! \details The function requires an outer loop which iterates over the keywords in the files, and calls the function for each keyword. \nThe valiables double greatestRatio and std::string keywordWithTheGreatestErrorRatio must be declared outside the loop. \nWhen the current error ratio is greater than the value stored in greatestRatio, the gratestRatio value is updated with the current error ratio.
void findGreatestErrorRatio(const WellProductionVolume& volume,
double &greatestRatio,
const char* currentKeyword,
std::string &greatestErrorRatio);
#if 0
//! \brief Checks whether the unit of the two data vectors is the same
//! \param[in] keyword The keyword of interest
//! \param[out] boolean True/false, depending on whether the units are equal or not
bool checkUnits(const char* keyword);
#endif
public:
//! \brief Constructor, creates an object of IntegrationTest class.
//! \param[in] basename1 Path to file1 without extension.
//! \param[in] basename1 Path to file2 without extension.
//! \param[in] atol The absolute tolerance which is to be used in the test.
//! \param[in] rtol The relative tolerance which is to be used in the test.
//! \details The constructor calls the constructor of the super class.
SummaryIntegrationTest(const std::string& basename1,
const std::string& basename2,
double atol, double rtol) :
SummaryComparator(basename1, basename2, atol, rtol) {}
//! \brief This function sets the private member variable allowSpikes.
//! \param[in] allowSpikes Boolean value
//! \details When allowSpikes is true, the integration test checkWithSpikes is excecuted.
void setAllowSpikes(bool allowSpikesArg){this->allowSpikes = allowSpikesArg;}
//! \brief This function sets the private member variable findVolumeError.
//! \param[in] findVolumeError Boolean value
//! \details When findVolumeError is true, the integration test volumeErrorCheck and the function evaluateWellProductionVolume are excecuted.
void setFindVolumeError(bool findVolumeErrorArg){this->findVolumeError = findVolumeErrorArg;}
//! \brief This function sets the private member variable oneOfTheMainVariables
//! \param[in] oneOfTheMainVariables Boolean value
//! \details When oneOfTheMainVariables is true, the integration test runs the substest volumeErrorCheckForOneSpecificVariable.
void setOneOfTheMainVariables(bool oneOfTheMainVariablesArg){this->oneOfTheMainVariables = oneOfTheMainVariablesArg;}
//! \brief This function sets the member variable string #mainVariable
//! \param[in] mainVar This is the string should contain one of the main variables. e.g. WOPR
void setMainVariable(std::string mainVar){this->mainVariable = mainVar;}
//! \brief This function sets the private member variable spikeLimit.
//! \param[in] lim The value which the spike limit is to be given.
void setSpikeLimit(int lim){this->spikeLimit = lim;}
//! \brief This function sets the private member variable findVectorWithGreatestErrorRatio
//! \param[in] findVolumeError Boolean value
//! \details When findVectorWithGreatestErrorRatio is true, the integration test will print the vector with the greatest error ratio.
void setFindVectorWithGreatestErrorRatio(bool boolean){this->findVectorWithGreatestErrorRatio = boolean;}
//! \brief This function sets the private member variable allowDifferentAmountsOfKeywords
//! \param[in] boolean Boolean value
//! \details When allowDifferentAmountOfKeywords is false, the amount of kewyord in the two files will be compared. \nIf the number of keywords are different an exception will be thrown.
void setAllowDifferentAmountOfKeywords(bool boolean){this->allowDifferentAmountOfKeywords = boolean;}
//! \brief This function sets the private member variable throwExceptionForTooGreatErrorRatio
//! \param[in] boolean Boolean value
//! \details When throwExceptionForTooGreatErrorRatio is false, the function getWellProductionVolume will throw an exception.
void setThrowExceptionForTooGreatErrorRatio(bool boolean){this->throwExceptionForTooGreatErrorRatio = boolean;}
//! \brief This function executes a integration test for all the keywords. If the two files do not match in amount of keywords, an exception is thrown. \n Uses the boolean member variables to know which tests to execute.
void getIntegrationTest();
//! \brief This function executes a integration test for one specific keyword. If one or both of the files do not have the keyword, an exception is thorwn. \n Uses the boolean member variables to know which tests to execute.
void getIntegrationTest(const char* keyword);
//! \brief This function calculates the area of an rectangle of height height and width time-timePrev
//! \param[in] height The height of the rectangle. See important statement of use below.
//! \param[in] width The width of the rectangle
//! \param[out] area Returns the area of the rectangle
//! \details This function is simple. When using it on a summary vector (data values plotted againt time), calculating the area between the two points i and i+1 note this:\nThe width is time_of_i+1 - time_of_i, the height is data_of_i+1 NOT data_of_i. The upper limit must be used.
static double getRectangleArea(double height, double width){return height*width;}
//! \brief This function calculates the area under a graph by doing a Riemann sum
//! \param[in] timeVec Contains the time values
//! \param[in] dataVec Contains the data values
//! \details The function does a Riemann sum integration of the graph formed
//! by the points (timeVec[i] , dataVec[i]).
//! In the case of a summary vector, the summary vector of quantity
//! corresponding to a rate, is a piecewise continus function consisting
//! of unit step functions. Thus the Riemann sum will become an
//! exact expression for the integral of the graph.
//! Important: For the data values correspoding to time i and i-1,
//! the fixed value of the height of the rectangles in the Riemann sum
//! is set by the data value i. The upper limit must be used.
static double integrate(const std::vector<double>& timeVec,
const std::vector<double>& dataVec);
//! \brief This function calculates the Riemann sum of the error between two graphs.
//! \param[in] timeVec1 Contains the time values of graph 1
//! \param[in] dataVec1 Contains the data values of graph 1
//! \param[in] timeVec2 Contains the time values of graph 2
//! \param[in] dataVec2 Contains the data values of graph 2
//! \details This function takes in two graphs and returns the integrated error.
//! In case of ecl summary vectors: if the vectors correspond to a
//! quantity which is a rate, the vectors will be piecewise
//! continous unit step functions. In this case the error will also
//! be a piecewise continous unit step function. The function uses
//! a Riemann sum when calculating the integral. Thus the integral
//! will become exact. Important: For the data values corresponding
//! to time i and i-1, the fixed value of the height of the rectangles
//! in the Riemann sum is set by the data value i.
//! The upper limit must be used.
static double integrateError(const std::vector<double>& timeVec1,
const std::vector<double>& dataVec1,
const std::vector<double>& timeVec2,
const std::vector<double>& dataVec2);
};

View File

@@ -0,0 +1,171 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryRegressionTest.hpp"
#include <opm/common/ErrorMacros.hpp>
#include <ert/ecl/ecl_sum.h>
#include <ert/util/stringlist.h>
#include <string>
void SummaryRegressionTest::getRegressionTest(){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2); //Figures which dataset that contains more/less values pr keyword vector.
std::cout << "Comparing " << timeVec1.size() << " steps." << std::endl;
int ivar = 0;
if(stringlist_get_size(keysShort) != stringlist_get_size(keysLong)){
int missing_count = 0;
std::cout << "Keywords missing from one case: " << std::endl;
for (int i=0; i < stringlist_get_size( keysLong); i++) {
const char * key = stringlist_iget( keysLong , i );
if (!stringlist_contains( keysShort , key)) {
std::cout << key << " ";
missing_count++;
if ((missing_count % 8) == 0)
std::cout << std::endl;
}
}
std::cout << std::endl;
HANDLE_ERROR(std::runtime_error, "Different amount of keywords in the two summary files.");
}
if(printKeyword){
printKeywords();
}
//Iterates over all keywords from the restricted file, use iterator "ivar". Searches for a match in the file with more keywords, use the iterator "jvar".
bool throwAtEnd = false;
while(ivar < stringlist_get_size(keysShort)){
const char* keyword = stringlist_iget(keysShort, ivar);
std::string keywordString(keyword);
for (int jvar = 0; jvar < stringlist_get_size(keysLong); jvar++){
if (strcmp(keyword, stringlist_iget(keysLong, jvar)) == 0){ //When the keywords are equal, proceed in comparing summary files.
if (isRestartFile && keywordString.substr(3,1)=="T"){
break;
}
throwAtEnd |= !checkForKeyword(timeVec1, timeVec2, keyword);
break;
}
//will only enter here if no keyword match
if(jvar == stringlist_get_size(keysLong)-1){
std::cout << "Could not find keyword: " << stringlist_iget(keysShort, ivar) << std::endl;
OPM_THROW(std::runtime_error, "No match on keyword");
}
}
ivar++;
}
if (analysis) {
std::cout << deviations.size() << " summary keyword"
<< (deviations.size() > 1 ? "s":"") << " exhibit failures" << std::endl;
size_t len = ecl_sum_get_data_length(ecl_sum1);
for (const auto& iter : deviations) {
std::cout << "\t" << iter.first << std::endl;
std::cout << "\t\tFails for " << iter.second.size() << " / " << len << " steps." << std::endl;
std::cout.precision(7);
double absErr = std::max_element(iter.second.begin(), iter.second.end(),
[](const Deviation& a, const Deviation& b)
{
return a.abs < b.abs;
})->abs;
double relErr = std::max_element(iter.second.begin(), iter.second.end(),
[](const Deviation& a, const Deviation& b)
{
return a.rel < b.rel;
})->rel;
std::cout << "\t\tLargest absolute error: "
<< std::scientific << absErr << std::endl;
std::cout << "\t\tLargest relative error: "
<< std::scientific << relErr << std::endl;
}
}
if (throwAtEnd)
OPM_THROW(std::runtime_error, "Regression test failed.");
else if (deviations.empty())
std::cout << "Regression test succeeded." << std::endl;
}
void SummaryRegressionTest::getRegressionTest(const char* keyword){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2); //Figures which dataset that contains more/less values pr keyword vector.
std::string keywordString(keyword);
if(stringlist_contains(keysShort,keyword) && stringlist_contains(keysLong, keyword)){
if (isRestartFile && keywordString.substr(3,1)=="T"){
return;
}
if (checkForKeyword(timeVec1, timeVec2, keyword))
std::cout << "Regression test succeeded." << std::endl;
else
OPM_THROW(std::runtime_error, "Regression test failed");
return;
}
std::cout << "The keyword suggested, " << keyword << ", is not supported by one or both of the summary files. Please use a different keyword." << std::endl;
OPM_THROW(std::runtime_error, "Input keyword from user does not exist in/is not common for the two summary files.");
}
bool SummaryRegressionTest::checkDeviation(Deviation deviation, const char* keyword, int refIndex, int checkIndex){
double absTol = getAbsTolerance();
double relTol = getRelTolerance();
if (deviation.rel > relTol && deviation.abs > absTol){
if (analysis) {
deviations[keyword].push_back(deviation);
} else {
std::cout << "For keyword " << keyword << std::endl;
std::cout << "(days, reference value) and (days, check value) = (" << (*referenceVec)[refIndex] << ", " << (*referenceDataVec)[refIndex]
<< ") and (" << (*checkVec)[checkIndex-1] << ", " << (*checkDataVec)[checkIndex-1] << ")\n";
// -1 in [checkIndex -1] because checkIndex is updated after leaving getDeviation function
std::cout << "The absolute deviation is " << deviation.abs << ". The tolerance limit is " << absTol << std::endl;
std::cout << "The relative deviation is " << deviation.rel << ". The tolerance limit is " << relTol << std::endl;
HANDLE_ERROR(std::runtime_error, "Deviation exceed the limit.");
}
return false;
}
return true;
}
bool SummaryRegressionTest::checkForKeyword(std::vector<double>& timeVec1, std::vector<double>& timeVec2, const char* keyword){
std::vector<double> dataVec1, dataVec2;
getDataVecs(dataVec1,dataVec2,keyword);
chooseReference(timeVec1, timeVec2,dataVec1,dataVec2);
return startTest(keyword);
}
bool SummaryRegressionTest::startTest(const char* keyword){
size_t jvar = 0;
Deviation deviation;
bool result = true;
for (size_t ivar = 0; ivar < referenceVec->size(); ivar++){
getDeviation(ivar, jvar, deviation);//Reads from the protected member variables in the super class.
result = checkDeviation(deviation, keyword,ivar, jvar);
}
return result;
}

View File

@@ -0,0 +1,74 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef SUMMARYREGRESSIONTEST_HPP
#define SUMMARYREGRESSIONTEST_HPP
#include "summaryComparator.hpp"
//! \details The class inherits from the SummaryComparator class, which takes care of all file reading. \n The RegressionTest class compares the values from the two different files and throws exceptions when the deviation is unsatisfying.
class SummaryRegressionTest: public SummaryComparator {
private:
//! \brief Gathers the correct data for comparison for a specific keyword
//! \param[in] timeVec1 The time steps of file 1.
//! \param[in] timeVec2 The time steps of file 2.
//! \param[in] keyword The keyword of interest
//! \details The function prepares a regression test by gathering the data, stroing it into two vectors, \n deciding which is to be used as a reference/basis and calling the test function.
//! \return True if check passed, false otherwise.
bool checkForKeyword(std::vector<double>& timeVec1, std::vector<double>& timeVec2, const char* keyword);
//! \brief The regression test
//! \param[in] keyword The keyword common for both the files. The vectors associated with the keyword are used for comparison.
//! \details Start test uses the private member variables, pointers of std::vector<double> type, which are set to point to the correct vectors in SummaryComparison::chooseReference(...). \n The function iterates over the referenceVev/basis and for each iteration it calculates the deviation with SummaryComparison::getDeviation(..) and stors it in a Deviation struct. \n SummaryComparison::getDeviation takes the int jvar as an reference input, and using it as an iterative index for the values which are to be compared with the basis. \n Thus, by updating the jvar variable every time a deviation is calculated, one keep track jvar and do not have to iterate over already checked values.
bool startTest(const char* keyword);
//! \brief Caluculates a deviation, throws exceptions and writes and error message.
//! \param[in] deviation Deviation struct
//! \param[in] keyword The keyword that the data that are being compared belongs to.
//! \param[in] refIndex The report step of which the deviation originates from in #referenceDataVec.
//! \param[in] checkIndex The report step of which the deviation originates from in #checkDataVec.
//! \details The function checks the values of the Deviation struct against the absolute and relative tolerance, which are private member values of the super class. \n When comparing against the relative tolerance an additional term is added, the absolute deviation has to be greater than 1e-6 for the function to throw an exception. \n When the deviations are too great, the function writes out which keyword, and at what report step the deviation is too great before optionally throwing an exception.
//! \return True if check passed, false otherwise.
bool checkDeviation(Deviation deviation, const char* keyword, int refIndex, int checkIndex);
bool isRestartFile = false; //!< Private member variable, when true the files that are being compared is a restart file vs a normal file
public:
//! \brief Constructor, creates an object of RefressionTest class.
//! \param[in] basename1 Path to file1 without extension.
//! \param[in] basename1 Path to file2 without extension.
//! \param[in] relativeTol The relative tolerance which is to be used in the test.
//! \param[in] absoluteTol The absolute tolerance which is to be used in the test.
//! \details The constructor calls the constructor of the super class.
SummaryRegressionTest(const std::string& basename1,
const std::string& basename2,
double relativeTol, double absoluteTol) :
SummaryComparator(basename1, basename2, relativeTol, absoluteTol) {}
//! \details The function executes a regression test for all the keywords. If the two files do not match in amount of keywords, an exception is thrown.
void getRegressionTest();
//! \details The function executes a regression test for one specific keyword. If one or both of the files do not have the keyword, an exception is thrown.
void getRegressionTest(const char* keyword);///< Regression test for a certain keyword of the files.
//! \brief This function sets the private member variable isRestartFiles
//! \param[in] boolean Boolean value
void setIsRestartFile(bool boolean){this->isRestartFile = boolean;}
};
#endif

View File

@@ -1,2 +1,4 @@
This directory contains the the 1.7.10 version of the cJSON package from https://github.com/DaveGamble/cJSON
This directory contains the cJSON package downloaded unchanged from:
http://sourceforge.net/projects/cjson/. The cJSON package is plain C,
the JsonObject class provides a minimal C++ wrapping of this.

3165
external/cjson/cJSON.c vendored

File diff suppressed because it is too large Load Diff

290
external/cjson/cJSON.h vendored
View File

@@ -1,16 +1,16 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,260 +23,118 @@
#ifndef cJSON__h
#define cJSON__h
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 10
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_False 0
#define cJSON_True 1
#define cJSON_NULL 2
#define cJSON_Number 3
#define cJSON_String 4
#define cJSON_Array 5
#define cJSON_Object 6
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
typedef struct cJSON {
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
/* The type of the item, as above. */
int type;
int type; /* The type of the item, as above. */
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */
double valuedouble; /* The item's number, if type==cJSON_Number */
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
typedef struct cJSON_Hooks {
void *(*malloc_fn)(size_t sz);
void (*free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
extern cJSON *cJSON_Parse(const char *value);
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
extern char *cJSON_Print(cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
extern char *cJSON_PrintUnformatted(cJSON *item);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *c);
extern void cJSON_Delete(cJSON *c);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
extern int cJSON_GetArraySize(cJSON *array);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check if the item is a string and return its valuestring */
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
extern const char *cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/arrray that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
extern cJSON *cJSON_CreateNull(void);
extern cJSON *cJSON_CreateTrue(void);
extern cJSON *cJSON_CreateFalse(void);
extern cJSON *cJSON_CreateBool(int b);
extern cJSON *cJSON_CreateNumber(double num);
extern cJSON *cJSON_CreateString(const char *string);
extern cJSON *cJSON_CreateArray(void);
extern cJSON *cJSON_CreateObject(void);
/* These utilities create an Array of count items. */
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count);
extern cJSON *cJSON_CreateIntArray(int *numbers,int count);
extern cJSON *cJSON_CreateFloatArray(float *numbers,int count);
extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
/* Remove/Detatch items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */
CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
need to be released. With recurse!=0, it will duplicate any children connected to the item.
The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* Macros for creating things quickly. */
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#ifdef __cplusplus
}

View File

@@ -2,10 +2,6 @@
declare -A configurations
declare -A EXTRA_MODULE_FLAGS
EXTRA_MODULE_FLAGS[opm-common]="-DENABLE_WELL_TEST=ON"
EXTRA_MODULE_FLAGS[opm-simulators]="-DBUILD_EBOS_EXTENSIONS=ON -DBUILD_EBOS_DEBUG_EXTENSIONS=ON"
# Parse revisions from trigger comment and setup arrays
# Depends on: 'upstreams', upstreamRev',
# 'downstreams', 'downstreamRev',
@@ -83,26 +79,10 @@ function printHeader {
# $2 = 0 to build and install module, 1 to build and test module
# $3 = Source root of module to build
function build_module {
CMAKE_PARAMS="$1"
DO_TEST_FLAG="$2"
MOD_SRC_DIR="$3"
cmake "$MOD_SRC_DIR" -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$DO_TEST_FLAG -DCMAKE_TOOLCHAIN_FILE=${configurations[$configuration]} $CMAKE_PARAMS
cmake $3 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$2 -DCMAKE_TOOLCHAIN_FILE=${configurations[$configuration]} $1
test $? -eq 0 || exit 1
if test $DO_TEST_FLAG -eq 1
if test $2 -eq 1
then
pushd "$CWD"
cd "$MOD_SRC_DIR"
if test -x "./jenkins/pre-build.sh"; then
echo "Running pre-build script"
if ! "./jenkins/pre-build.sh"; then
exit 1
fi
else
echo "No pre-build script detected"
fi
popd
if [ ! -z $BUILDTHREADS ]
then
cmake --build . -- -j$BUILDTHREADS
@@ -184,7 +164,7 @@ function build_upstreams {
do
echo "Building upstream $upstream=${upstreamRev[$upstream]} configuration=$configuration"
# Build upstream and execute installation
clone_and_build_module $upstream "-DCMAKE_PREFIX_PATH=$WORKSPACE/$configuration/install -DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install ${EXTRA_MODULE_FLAGS[$upstream]}" ${upstreamRev[$upstream]} $WORKSPACE/$configuration
clone_and_build_module $upstream "-DCMAKE_PREFIX_PATH=$WORKSPACE/$configuration/install -DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install" ${upstreamRev[$upstream]} $WORKSPACE/$configuration
test $? -eq 0 || exit 1
done
test $? -eq 0 || exit 1
@@ -199,7 +179,7 @@ function build_downstreams {
do
echo "Building downstream $downstream=${downstreamRev[$downstream]} configuration=$configuration"
# Build downstream and execute installation
clone_and_build_module $downstream "-DCMAKE_PREFIX_PATH=$WORKSPACE/$configuration/install -DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install -DOPM_TESTS_ROOT=$OPM_TESTS_ROOT ${EXTRA_MODULE_FLAGS[$downstream]}" ${downstreamRev[$downstream]} $WORKSPACE/$configuration 1
clone_and_build_module $downstream "-DCMAKE_PREFIX_PATH=$WORKSPACE/$configuration/install -DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install -DOPM_TESTS_ROOT=$OPM_TESTS_ROOT" ${downstreamRev[$downstream]} $WORKSPACE/$configuration 1
test $? -eq 0 || exit 1
# Installation for downstream
@@ -236,7 +216,7 @@ function build_module_full {
mkdir -p $configuration/build-$1
cd $configuration/build-$1
echo "Building main module $1=$sha1 configuration=$configuration"
build_module "-DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install -DOPM_TESTS_ROOT=$OPM_TESTS_ROOT ${EXTRA_MODULE_FLAGS[$1]}" 1 $WORKSPACE
build_module "-DCMAKE_INSTALL_PREFIX=$WORKSPACE/$configuration/install -DOPM_TESTS_ROOT=$OPM_TESTS_ROOT" 1 $WORKSPACE
test $? -eq 0 || exit 1
cmake --build . --target install
test $? -eq 0 || exit 1

View File

@@ -1,52 +0,0 @@
#ifndef ISIM_MAIN_HPP
#define ISIM_MAIN_HPP
#include <functional>
#include <string>
#include <map>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/output/data/Solution.hpp>
#include <opm/output/data/Wells.hpp>
namespace Opm {
class EclipseIO;
class ParseContext;
class Parser;
class msim {
public:
using well_rate_function = double(const EclipseState&, const Schedule&, const data::Solution&, size_t report_step, double seconds_elapsed);
using solution_function = void(const EclipseState&, const Schedule&, data::Solution&, size_t report_step, double seconds_elapsed);
msim(const EclipseState& state);
void well_rate(const std::string& well, data::Rates::opt rate, std::function<well_rate_function> func);
void solution(const std::string& field, std::function<solution_function> func);
void run(Schedule& schedule, EclipseIO& io);
void post_step(Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const;
private:
void run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const;
void run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const;
void output(size_t report_step, bool substep, double seconds_elapsed, const data::Solution& sol, const data::Wells& well_data, EclipseIO& io) const;
void simulate(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const;
EclipseState state;
std::map<std::string, std::map<data::Rates::opt, std::function<well_rate_function>>> well_rates;
std::map<std::string, std::function<solution_function>> solutions;
};
}
#endif

View File

@@ -1,148 +0,0 @@
/*
Copyright 2018 Equinor 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 <iostream>
#include <opm/output/eclipse/EclipseIO.hpp>
#include <opm/output/eclipse/RestartValue.hpp>
#include <opm/output/data/Solution.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionContext.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/msim/msim.hpp>
namespace Opm {
msim::msim(const EclipseState& state) :
state(state)
{}
void msim::run(Schedule& schedule, EclipseIO& io) {
const double week = 7 * 86400;
data::Solution sol;
data::Wells well_data;
io.writeInitial();
for (size_t report_step = 1; report_step < schedule.size(); report_step++) {
double time_step = std::min(week, 0.5*schedule.stepLength(report_step - 1));
run_step(schedule, sol, well_data, report_step, time_step, io);
post_step(schedule, sol, well_data, report_step, io);
}
}
void msim::post_step(Schedule& schedule, data::Solution& /* sol */, data::Wells& /* well_data */, size_t report_step, EclipseIO& io) const {
const auto& actions = schedule.actions();
if (actions.empty())
return;
const SummaryState& summary_state = io.summaryState();
ActionContext context( summary_state );
std::vector<std::string> matching_wells;
auto sim_time = schedule.simTime(report_step);
for (const auto& action : actions.pending(sim_time)) {
if (action->eval(sim_time, context, matching_wells))
schedule.applyAction(report_step, *action, matching_wells);
}
}
void msim::run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const {
this->run_step(schedule, sol, well_data, report_step, schedule.stepLength(report_step - 1), io);
}
void msim::run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const {
double start_time = schedule.seconds(report_step - 1);
double end_time = schedule.seconds(report_step);
double seconds_elapsed = start_time;
while (seconds_elapsed < end_time) {
double time_step = dt;
if ((seconds_elapsed + time_step) > end_time)
time_step = end_time - seconds_elapsed;
this->simulate(schedule, sol, well_data, report_step, seconds_elapsed, time_step);
seconds_elapsed += time_step;
this->output(report_step,
(seconds_elapsed < end_time),
seconds_elapsed,
sol,
well_data,
io);
}
}
void msim::output(size_t report_step, bool /* substep */, double seconds_elapsed, const data::Solution& sol, const data::Wells& well_data, EclipseIO& io) const {
RestartValue value(sol, well_data);
io.writeTimeStep(report_step,
false,
seconds_elapsed,
value,
{},
{},
{});
}
void msim::simulate(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const {
for (const auto& sol_pair : this->solutions) {
auto func = sol_pair.second;
func(this->state, schedule, sol, report_step, seconds_elapsed + time_step);
}
for (const auto& well_pair : this->well_rates) {
const std::string& well_name = well_pair.first;
data::Well& well = well_data[well_name];
for (const auto& rate_pair : well_pair.second) {
auto rate = rate_pair.first;
auto func = rate_pair.second;
well.rates.set(rate, func(this->state, schedule, sol, report_step, seconds_elapsed + time_step));
}
// This is complete bogus; a temporary fix to pass an assert() in the
// the restart output.
well.connections.resize(100);
}
}
void msim::well_rate(const std::string& well, data::Rates::opt rate, std::function<well_rate_function> func) {
this->well_rates[well][rate] = func;
}
void msim::solution(const std::string& field, std::function<solution_function> func) {
this->solutions[field] = func;
}
}

View File

@@ -20,14 +20,12 @@
#ifndef OPM_OUTPUT_WELLS_HPP
#define OPM_OUTPUT_WELLS_HPP
#include <algorithm>
#include <cstddef>
#include <initializer_list>
#include <map>
#include <algorithm>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
namespace Opm {
@@ -58,12 +56,6 @@ namespace Opm {
reservoir_water = (1 << 8),
reservoir_oil = (1 << 9),
reservoir_gas = (1 << 10),
productivity_index_water = (1 << 11),
productivity_index_oil = (1 << 12),
productivity_index_gas = (1 << 13),
well_potential_water = (1 << 14),
well_potential_oil = (1 << 15),
well_potential_gas = (1 << 16),
};
using enum_size = std::underlying_type< opt >::type;
@@ -107,12 +99,6 @@ namespace Opm {
double reservoir_water = 0.0;
double reservoir_oil = 0.0;
double reservoir_gas = 0.0;
double productivity_index_water = 0.0;
double productivity_index_oil = 0.0;
double productivity_index_gas = 0.0;
double well_potential_water = 0.0;
double well_potential_oil = 0.0;
double well_potential_gas = 0.0;
};
struct Connection {
@@ -134,18 +120,6 @@ namespace Opm {
void read(MessageBufferType& buffer);
};
struct Segment {
Rates rates;
double pressure;
std::size_t segNumber;
template <class MessageBufferType>
void write(MessageBufferType& buffer) const;
template <class MessageBufferType>
void read(MessageBufferType& buffer);
};
struct Well {
Rates rates;
double bhp;
@@ -153,7 +127,7 @@ namespace Opm {
double temperature;
int control;
std::vector< Connection > connections;
std::unordered_map<std::size_t, Segment> segments;
inline bool flowing() const noexcept;
template <class MessageBufferType>
void write(MessageBufferType& buffer) const;
@@ -275,12 +249,6 @@ namespace Opm {
case opt::reservoir_water: return this->reservoir_water;
case opt::reservoir_oil: return this->reservoir_oil;
case opt::reservoir_gas: return this->reservoir_gas;
case opt::productivity_index_water: return this->productivity_index_water;
case opt::productivity_index_oil: return this->productivity_index_oil;
case opt::productivity_index_gas: return this->productivity_index_gas;
case opt::well_potential_water: return this->well_potential_water;
case opt::well_potential_oil: return this->well_potential_oil;
case opt::well_potential_gas: return this->well_potential_gas;
}
throw std::invalid_argument(
@@ -318,12 +286,6 @@ namespace Opm {
buffer.write(this->reservoir_water);
buffer.write(this->reservoir_oil);
buffer.write(this->reservoir_gas);
buffer.write(this->productivity_index_water);
buffer.write(this->productivity_index_oil);
buffer.write(this->productivity_index_gas);
buffer.write(this->well_potential_water);
buffer.write(this->well_potential_oil);
buffer.write(this->well_potential_gas);
}
template <class MessageBufferType>
@@ -338,13 +300,6 @@ namespace Opm {
buffer.write(this->effective_Kh);
}
template <class MessageBufferType>
void Segment::write(MessageBufferType& buffer) const {
buffer.write(this->segNumber);
this->rates.write(buffer);
buffer.write(this->pressure);
}
template <class MessageBufferType>
void Well::write(MessageBufferType& buffer) const {
this->rates.write(buffer);
@@ -356,16 +311,6 @@ namespace Opm {
buffer.write(size);
for (const Connection& comp : this->connections)
comp.write(buffer);
{
const auto nSeg =
static_cast<unsigned int>(this->segments.size());
buffer.write(nSeg);
for (const auto& seg : this->segments) {
seg.second.write(buffer);
}
}
}
template <class MessageBufferType>
@@ -382,12 +327,6 @@ namespace Opm {
buffer.read(this->reservoir_water);
buffer.read(this->reservoir_oil);
buffer.read(this->reservoir_gas);
buffer.read(this->productivity_index_water);
buffer.read(this->productivity_index_oil);
buffer.read(this->productivity_index_gas);
buffer.read(this->well_potential_water);
buffer.read(this->well_potential_oil);
buffer.read(this->well_potential_gas);
}
template <class MessageBufferType>
@@ -402,13 +341,6 @@ namespace Opm {
buffer.read(this->effective_Kh);
}
template <class MessageBufferType>
void Segment::read(MessageBufferType& buffer) {
buffer.read(this->segNumber);
this->rates.read(buffer);
buffer.read(this->pressure);
}
template <class MessageBufferType>
void Well::read(MessageBufferType& buffer) {
this->rates.read(buffer);
@@ -416,8 +348,6 @@ namespace Opm {
buffer.read(this->thp);
buffer.read(this->temperature);
buffer.read(this->control);
// Connection information
unsigned int size = 0.0; //this->connections.size();
buffer.read(size);
this->connections.resize(size);
@@ -426,25 +356,9 @@ namespace Opm {
auto& comp = this->connections[ i ];
comp.read(buffer);
}
// Segment information (if applicable)
const auto nSeg = [&buffer]() -> unsigned int
{
auto n = 0u;
buffer.read(n);
return n;
}();
for (auto segID = 0*nSeg; segID < nSeg; ++segID) {
auto seg = Segment{};
seg.read(buffer);
const auto segNumber = seg.segNumber;
this->segments.emplace(segNumber, std::move(seg));
}
}
}} // Opm::data
}
}
#endif //OPM_OUTPUT_WELLS_HPP

View File

@@ -61,6 +61,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
const std::vector<std::string>& restart_field_keys,
const std::map<std::string, size_t>& groupKeyToIndex,
const std::map<std::string, size_t>& fieldKeyToIndex,
const bool ecl_compatible_rst,
const std::size_t simStep,
const Opm::SummaryState& sumState,
const std::vector<int>& inteHead);
@@ -88,16 +89,12 @@ namespace Opm { namespace RestartIO { namespace Helpers {
const std::vector<std::string> restart_group_keys = {"GOPP", "GWPP", "GOPR", "GWPR", "GGPR",
"GVPR", "GWIR", "GGIR", "GWCT", "GGOR",
"GOPT", "GWPT", "GGPT", "GVPT", "GWIT",
"GGIT",
"GOPTH", "GWPTH", "GGPTH",
"GWITH", "GGITH"};
"GGIT"};
const std::vector<std::string> restart_field_keys = {"FOPP", "FWPP", "FOPR", "FWPR", "FGPR",
"FVPR", "FWIR", "FGIR", "FWCT", "FGOR",
"FOPT", "FWPT", "FGPT", "FVPT", "FWIT",
"FGIT",
"FOPTH", "FWPTH", "FGPTH",
"FWITH", "FGITH"};
"FGIT"};
const std::map<std::string, size_t> groupKeyToIndex = {
{"GOPR", 0},
@@ -116,11 +113,6 @@ namespace Opm { namespace RestartIO { namespace Helpers {
{"GGIT", 16},
{"GOPP", 22},
{"GWPP", 23},
{"GOPTH", 135},
{"GWPTH", 139},
{"GWITH", 140},
{"GGPTH", 143},
{"GGITH", 144},
};
const std::map<std::string, size_t> fieldKeyToIndex = {
@@ -140,11 +132,6 @@ namespace Opm { namespace RestartIO { namespace Helpers {
{"FGIT", 16},
{"FOPP", 22},
{"FWPP", 23},
{"FOPTH", 135},
{"FWPTH", 139},
{"FWITH", 140},
{"FGPTH", 143},
{"FGITH", 144},
};
private:

View File

@@ -21,6 +21,8 @@
#define OPM_AGGREGATE_MSW_DATA_HPP
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
#include <opm/output/eclipse/WindowedArray.hpp>
@@ -45,30 +47,17 @@ namespace Opm { namespace RestartIO { namespace Helpers {
int branch;
};
struct SegmentSetSourceSinkTerms {
std::vector<double> qosc;
std::vector<double> qwsc;
std::vector<double> qgsc;
};
struct SegmentSetFlowRates {
std::vector<double> sofr;
std::vector<double> swfr;
std::vector<double> sgfr;
};
class AggregateMSWData
{
public:
explicit AggregateMSWData(const std::vector<int>& inteHead);
void captureDeclaredMSWData(const Opm::Schedule& sched,
const std::size_t rptStep,
const Opm::UnitSystem& units,
const std::vector<int>& inteHead,
const Opm::EclipseGrid& grid,
const Opm::SummaryState& smry,
const Opm::data::WellRates& wr
const ::Opm::SummaryState& smry
);
/// Retrieve Integer Multisegment well data Array.

View File

@@ -52,6 +52,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
void captureDynamicWellData(const Opm::Schedule& sched,
const std::size_t sim_step,
const bool ecl_compatible_rst,
const Opm::data::WellRates& xw,
const Opm::SummaryState& smry);

View File

@@ -53,11 +53,9 @@ namespace Opm { namespace RestartIO {
const double cnvT);
DoubHEAD& timeStamp(const TimeStamp& ts);
DoubHEAD& nextStep(const double nextTimeStep);
DoubHEAD& drsdt(const Schedule& sched,
const std::size_t lookup_step,
const double cnvT);
const std::size_t lookup_step);
const std::vector<double>& data() const
{

View File

@@ -35,13 +35,13 @@
#include <opm/output/data/Solution.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/RestartValue.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
namespace Opm {
class EclipseState;
class SummaryConfig;
class Schedule;
class SummaryState;
/*!
* \brief A class to write the reservoir state and the well state of a
@@ -225,8 +225,6 @@ public:
EclipseIO( const EclipseIO& ) = delete;
~EclipseIO();
const SummaryState& summaryState() const;
private:
class Impl;
std::unique_ptr< Impl > impl;

View File

@@ -1,5 +1,4 @@
/*
Copyright 2019 Equinor.
Copyright 2017 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
@@ -36,8 +35,6 @@ namespace Opm {
public:
/// Constructor.
///
/// Padded table entries set to +1.0e+20.
///
/// \param[in] numTables Number of tables managed by internal
/// buffer. Typically corresponds to maximum value of a region
/// ID vector such as SATNUM, IMBNUM, or PVTNUM.
@@ -60,33 +57,6 @@ namespace Opm {
const std::size_t numRows,
const std::size_t numCols);
/// Constructor.
///
/// \param[in] numTables Number of tables managed by internal
/// buffer. Typically corresponds to maximum value of a region
/// ID vector such as SATNUM, IMBNUM, or PVTNUM.
///
/// \param[in] numPrimary Number of primary look-up keys for the
/// tabular data managed by the internal buffer. Mostly relevant
/// (i.e., greater than one) for miscible oil ("PVTO") or
/// miscible gas ("PVTG") tables and typically corresponds to the
/// number of Rs/Rv entries from the TABDIMS keyword.
///
/// \param[in] numRows Number of rows in each sub-table
/// corresponding to a single primary look-up key. Typically the
/// number of nodes (e.g., NSSFUN or NPPVT) of the corresponding
/// input keyword.
///
/// \param[in] numCols Number of columns in each sub-table (and main
/// table). Typically 5.
///
/// \param[in] fillValue Data element value for padded table entries.
LinearisedOutputTable(const std::size_t numTables,
const std::size_t numPrimary,
const std::size_t numRows,
const std::size_t numCols,
const double fillValue);
/// Retrieve iterator to start of \c numRows (contiguous) column
/// elements of a particular sub-table of a particular main table.
///

View File

@@ -1,5 +1,4 @@
/*
Copyright 2019 Equinor ASA.
Copyright 2016, 2017 Statoil ASA.
This file is part of the Open Porous Media Project (OPM).
@@ -28,49 +27,6 @@ namespace Opm { namespace RestartIO {
class LogiHEAD
{
public:
/// Key characteristics of simulation run's PVT model.
struct PVTModel
{
/// Whether or not simulation run uses a live oil model (with
/// dissolved gas).
bool isLiveOil { false };
/// Whether or not simulation run uses a wet gas model (with
/// vaporised oil).
bool isWetGas { false };
/// Whether or not simulation run uses a constant
/// compressibility oil model (keyword PVCDO).
bool constComprOil { false };
};
/// Key characteristics of simulation model's saturation functions.
struct SatfuncFlags
{
/// Whether or not simulation run uses directionally dependent
/// relative permeability.
bool useDirectionalRelPerm { false };
/// Whether or not simulation run uses reversible relative
/// permeability functions.
bool useReversibleRelPerm { true };
/// Whether or not simulation run uses end-point scaling.
bool useEndScale { false };
/// Whether or not simulation run uses directionally dependent
/// end-point scaling.
bool useDirectionalEPS { false };
/// Whether or not simulation run uses reversible end-point
/// scaling.
bool useReversibleEPS { true };
/// Whether or not simulation run activates the alternative
/// (three-point) end-point scaling feature.
bool useAlternateEPS { false };
};
LogiHEAD();
~LogiHEAD() = default;
@@ -82,24 +38,7 @@ namespace Opm { namespace RestartIO {
LogiHEAD& variousParam(const bool e300_radial,
const bool e100_radial,
const int nswlmx,
const bool enableHyster
);
/// Assign PVT model characteristics.
///
/// \param[in] pvt Current run's PVT model characteristics.
///
/// \return \code *this \endcode.
LogiHEAD& pvtModel(const PVTModel& pvt);
/// Assign saturation function characteristics.
///
/// \param[in] satfunc Current run's saturation function
/// characteristics.
///
/// \return \code *this \endcode.
LogiHEAD& saturationFunction(const SatfuncFlags& satfunc);
const int nswlmx);
const std::vector<bool>& data() const
{

View File

@@ -1,5 +1,4 @@
/*
Copyright (c) 2018 Equinor ASA
Copyright (c) 2016 Statoil ASA
Copyright (c) 2013-2015 Andreas Lauser
Copyright (c) 2013 SINTEF ICT, Applied Mathematics.
@@ -24,38 +23,36 @@
#ifndef RESTART_IO_HPP
#define RESTART_IO_HPP
#include <vector>
#include <map>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
#include <opm/output/data/Cells.hpp>
#include <opm/output/data/Solution.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/RestartValue.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <ert/ecl/EclKW.hpp>
#include <ert/ecl/ecl_rsthead.h>
#include <ert/ecl/ecl_rst_file.h>
#include <ert/util/util.h>
#include <map>
#include <utility>
#include <vector>
namespace Opm {
class EclipseGrid;
class EclipseState;
class Phases;
class Schedule;
class EclipseGrid;
class EclipseState;
class Phases;
class Schedule;
class SummaryState;
} // namespace Opm
namespace RestartIO {
/*
The two free functions RestartIO::save() and RestartIO::load() can
The two loose functions RestartIO::save() and RestartIO::load() can
be used to save and load reservoir and well state from restart
files. Observe that these functions 'just do it', i.e. the checking
of which report step to load from, if output is enabled at all and
@@ -72,30 +69,39 @@ namespace Opm {
load("CASE.X0010" , 99 , ...)
save("CASE.X0010" , 99 , ...)
will read from and write to the file "CASE.X0010" - completely ignoring
will read and write to the file "CASE.X0010" - completely ignoring
the report step argument '99'.
*/
namespace Opm { namespace RestartIO {
void save(const std::string& filename,
int report_step,
double seconds_elapsed,
RestartValue value,
const EclipseState& es,
const EclipseGrid& grid,
const Schedule& schedule,
const SummaryState& sumState,
bool write_double = false);
/*void save(const std::string& filename,
int report_step,
double seconds_elapsed,
data::Solution cells,
data::Wells wells,
const EclipseState& es,
const EclipseGrid& grid,
const Schedule& schedule,
std::map<std::string, std::vector<double>> extra_data = {},
bool write_double = false);
*/
void save(const std::string& filename,
int report_step,
double seconds_elapsed,
RestartValue value,
const EclipseState& es,
const EclipseGrid& grid,
const Schedule& schedule,
const SummaryState& sumState,
bool write_double = false);
std::pair<RestartValue, SummaryState>
load(const std::string& filename,
int report_step,
const std::vector<RestartKey>& solution_keys,
const EclipseState& es,
const EclipseGrid& grid,
const Schedule& schedule,
const std::vector<RestartKey>& extra_keys = {});
RestartValue load( const std::string& filename,
int report_step,
const std::vector<RestartKey>& solution_keys,
const EclipseState& es,
const EclipseGrid& grid,
const Schedule& schedule,
const std::vector<RestartKey>& extra_keys = {});
}} // namespace Opm::RestartIO
#endif // RESTART_IO_HPP
}
}
#endif

View File

@@ -20,15 +20,15 @@
#ifndef OPM_OUTPUT_SUMMARY_HPP
#define OPM_OUTPUT_SUMMARY_HPP
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include <ert/ecl/ecl_sum.h>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/output/eclipse/SummaryState.hpp>
#include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/RegionCache.hpp>
@@ -43,52 +43,35 @@ namespace Opm {
namespace out {
class Summary {
public:
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule& );
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule&, const std::string& );
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule&, const char* basename );
public:
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule& );
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule&, const std::string& );
Summary( const EclipseState&, const SummaryConfig&, const EclipseGrid&, const Schedule&, const char* basename );
void add_timestep(int report_step,
double secs_elapsed,
const EclipseState& es,
const Schedule& schedule,
const data::Wells&,
const std::map<std::string, double>& single_values,
const std::map<std::string, std::vector<double>>& region_values = {},
const std::map<std::pair<std::string, int>, double>& block_values = {});
void add_timestep(int report_step,
double secs_elapsed,
const EclipseState& es,
const Schedule& schedule,
const data::Wells&,
const std::map<std::string, double>& single_values,
const std::map<std::string, std::vector<double>>& region_values = {},
const std::map<std::pair<std::string, int>, double>& block_values = {});
void write();
void eval(SummaryState& summary_state,
int report_step,
double secs_elapsed,
const EclipseState& es,
const Schedule& schedule,
const data::Wells&,
const std::map<std::string, double>& single_values,
const std::map<std::string, std::vector<double>>& region_values = {},
const std::map<std::pair<std::string, int>, double>& block_values = {}) const;
~Summary();
const SummaryState& get_restart_vectors() const;
private:
class keyword_handlers;
~Summary();
const SummaryState& get_restart_vectors() const;
void reset_cumulative_quantities(const SummaryState& rstrt);
void write() const;
private:
void internal_store(const SummaryState& summary_state, int report_step, double seconds_elapsed);
class keyword_handlers;
const EclipseGrid& grid;
out::RegionCache regionCache;
ERT::ert_unique_ptr< ecl_sum_type, ecl_sum_free > ecl_sum;
std::unique_ptr< keyword_handlers > handlers;
double prev_time_elapsed = 0;
SummaryState prev_state;
const EclipseGrid& grid;
out::RegionCache regionCache;
ERT::ert_unique_ptr< ecl_sum_type, ecl_sum_free > ecl_sum;
std::unique_ptr< keyword_handlers > handlers;
double prev_time_elapsed = 0;
SummaryState prev_state;
};
}

View File

@@ -0,0 +1,50 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef SUMMARY_STATE_H
#define SUMMARY_STATE_H
#include <string>
#include <unordered_map>
namespace Opm{
/*
The purpose of this class is to serve as a small container object for
computed, ready to use summary values. The values will typically be used by
the UDQ, WTEST and ACTIONX calculations. Observe that all value *have been
converted to the correct output units*.
*/
class SummaryState {
public:
typedef std::unordered_map<std::string, double>::const_iterator const_iterator;
void add(const std::string& key, double value);
double get(const std::string&) const;
bool has(const std::string& key) const;
const_iterator begin() const;
const_iterator end() const;
private:
std::unordered_map<std::string,double> values;
};
}
#endif

View File

@@ -1,6 +1,4 @@
/*
Copyright 2019 Equinor.
Copyright 2017 Statoil ASA.
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
@@ -44,15 +42,6 @@ namespace Opm {
void addPVTW(const PvtwTable& pvtwTable);
void addDensity(const DensityTable& density);
/// Add normalised PVT function tables to INIT file's TAB vector.
///
/// \param[in] es Valid \c EclipseState object with accurate RUNSPEC
/// information on active phases and table dimensions ("TABDIMS").
///
/// \param[in] logihead Flag specifications identifying which tables
/// to output.
void addPVTTables(const EclipseState& es);
/// Add normalised saturation function tables to INIT file's TAB
/// vector.
///
@@ -112,30 +101,6 @@ namespace Opm {
const bool gas,
const bool oil,
const bool wat);
/// Add gas PVT tables (keywords PVDG and PVTG) to the tabular data
/// (TABDIMS and TAB vectors).
///
/// \param[in] es Valid \c EclipseState object with accurate table
/// dimensions ("TABDIMS" keyword) and an initialised \c
/// TableManager sub-object.
void addGasPVTTables(const EclipseState& es);
/// Add oil PVT tables (keywords PVCDO, PVDO and PVTO) to the
/// tabular data (TABDIMS and TAB vectors).
///
/// \param[in] es Valid \c EclipseState object with accurate table
/// dimensions ("TABDIMS" keyword) and an initialised \c
/// TableManager sub-object.
void addOilPVTTables(const EclipseState& es);
/// Add water PVT tables (keyword PVTW) to the tabular data (TABDIMS
/// and TAB vectors).
///
/// \param[in] es Valid \c EclipseState object with accurate table
/// dimensions ("TABDIMS" keyword) and an initialised \c
/// TableManager sub-object.
void addWaterPVTTables(const EclipseState& es);
};
/// Emit normalised tabular information (TABDIMS and TAB vectors) to

View File

@@ -50,7 +50,7 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
EffectiveKH = 3, // Effective Kh product of connection
item12 = 11, // Connection transmissibility factor
item12 = 11, // Unknown
SegDistEnd = 20, // Distance to end of connection in segment
SegDistStart = 21, // Distance to start of connection in segment
@@ -66,8 +66,6 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
WaterRate = 1, // Surface flow rate (water)
GasRate = 2, // Surface Flow rate (gas)
Pressure = 34, // Connection pressure value
ResVRate = 49, // Reservoir voidage rate
};
} // XConn

View File

@@ -1,37 +0,0 @@
/*
Copyright (c) 2018 Equinor 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/>.
*/
#ifndef OPM_OUTPUT_ECLIPSE_VECTOR_DOUBHEAD_HPP
#define OPM_OUTPUT_ECLIPSE_VECTOR_DOUBHEAD_HPP
#include <vector>
namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems {
// This is a subset of the items in src/opm/output/eclipse/DoubHEAD.cpp .
// Promote items from that list to this in order to make them public.
enum doubhead : std::vector<double>::size_type {
TsInit = 1, // Maximum Length of Next Timestep
TsMaxz = 2, // Maximum Length of Timestep After Next
TsMinz = 3, // Minumum Length of All Timesteps
};
}}}} // Opm::RestartIO::Helpers::VectorItems
#endif // OPM_OUTPUT_ECLIPSE_VECTOR_DOUBHEAD_HPP

View File

@@ -1,67 +0,0 @@
/*
Copyright (c) 2018 Equinor 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/>.
*/
#ifndef OPM_OUTPUT_ECLIPSE_VECTOR_GROUP_HPP
#define OPM_OUTPUT_ECLIPSE_VECTOR_GROUP_HPP
#include <vector>
namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems {
namespace XGroup {
enum index : std::vector<double>::size_type {
OilPrRate = 0, // Group's oil production rate
WatPrRate = 1, // Group's water production rate
GasPrRate = 2, // Group's gas production rate
LiqPrRate = 3, // Group's liquid production rate
WatInjRate = 5, // Group's water injection rate
GasInjRate = 6, // Group's gas injection rate
WatCut = 8, // Group's producing water cut
GORatio = 9, // Group's producing gas/oil ratio
OilPrTotal = 10, // Group's total cumulative oil production
WatPrTotal = 11, // Group's total cumulative water production
GasPrTotal = 12, // Group's total cumulative gas production
VoidPrTotal = 13, // Group's total cumulative reservoir
// voidage production
WatInjTotal = 15, // Group's total cumulative water injection
GasInjTotal = 16, // Group's total cumulative gas injection
OilPrPot = 22, // Group's oil production potential
WatPrPot = 23, // Group's water production potential
HistOilPrTotal = 135, // Group's total cumulative oil
// production (observed/historical rates)
HistWatPrTotal = 139, // Group's total cumulative water
// production (observed/historical rates)
HistWatInjTotal = 140, // Group's total cumulative water
// injection (observed/historical rates)
HistGasPrTotal = 143, // Group's total cumulative gas
// production (observed/historical rates)
HistGasInjTotal = 144, // Group's total cumulative gas injection
// (observed/historical rates)
};
} // XGroup
}}}} // Opm::RestartIO::Helpers::VectorItems
#endif // OPM_OUTPUT_ECLIPSE_VECTOR_GROUP_HPP

View File

@@ -1,48 +0,0 @@
/*
Copyright (c) 2019 Equinor 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/>.
*/
#ifndef OPM_OUTPUT_ECLIPSE_VECTOR_LOGIHEAD_HPP
#define OPM_OUTPUT_ECLIPSE_VECTOR_LOGIHEAD_HPP
#include <vector>
namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems {
// This is a subset of the items in src/opm/output/eclipse/LogiHEAD.cpp .
// Promote items from that list to this in order to make them public.
enum logihead : std::vector<bool>::size_type {
IsLiveOil = 0, // Oil phase w/dissolved gas
IsWetGas = 1, // Gas phase w/vaporised oil
DirKr = 2, // Directional relative permeability
E100RevKr = 3, // Reversible rel. perm. (E100)
E100Radial = 4, // Radial model (E100)
E300Radial = 3, // Radial model (E300, others)
E300RevKr = 4, // Reversible rel. perm. (E300, others)
Hyster = 6, // Enable hysteresis
DualPoro = 14, // Enable dual porosity
EndScale = 16, // Enable end-point scaling
DirEPS = 17, // Directional end-point scaling
RevEPS = 18, // Reversible end-point scaling
AltEPS = 19, // Alternative (3-pt) end-point scaling
ConstCo = 38, // Constant oil compressibility (PVCDO)
HasMSWells = 75, // Whether or not model has MS Wells.
};
}}}} // Opm::RestartIO::Helpers::VectorItems
#endif // OPM_OUTPUT_ECLIPSE_VECTOR_LOGIHEAD_HPP

View File

@@ -1,64 +0,0 @@
/*
Copyright (c) 2018 Equinor 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/>.
*/
#ifndef OPM_OUTPUT_ECLIPSE_VECTOR_MSW_HPP
#define OPM_OUTPUT_ECLIPSE_VECTOR_MSW_HPP
#include <vector>
namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems {
namespace ISeg {
enum index : std::vector<int>::size_type {
SegNo = 0, // Segment number (one-based)
OutSeg = 1, // Outlet segment (one-based)
InSegCurBranch = 2, // Inflow segment current branch (one-based)
BranchNo = 3, // Branch number (one-based)
};
} // ISeg
namespace RSeg {
enum index : std::vector<double>::size_type {
DistOutlet = 0, // Segment's distance to outlet
OutletDepthDiff = 1, // Segment's depth differential to outlet
SegDiam = 2, // Internal diameter of segment
SegRough = 3, // Roughness parameter of segment
SegArea = 4, // Cross-sectional area of segment
SegVolume = 5, // Physical volume of segment
DistBHPRef = 6, // Segment's distance to BHP reference node
DepthBHPRef = 7, // Segment's depth differential to BHP ref. node
TotFlowRate = 8, // Normalised total segment flow rate
WatFlowFract = 9, // Normalised Water flow rate fraction
GasFlowFract = 10, // Normalised Gas flow rate fraction
Pressure = 11, // Segment pressure
item40 = 39, // Unknown
item106 = 105, // Unknown
item107 = 106, // Unknown
item108 = 107, // Unknown
item109 = 108, // Unknown
item110 = 109, // Unknown
item111 = 110, // Unknown
};
} // RSeg
}}}} // Opm::RestartIO::Helpers::VectorItems
#endif // OPM_OUTPUT_ECLIPSE_VECTOR_MSW_HPP

View File

@@ -26,30 +26,25 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
namespace IWell {
enum index : std::vector<int>::size_type {
IHead = 0, // I-location (one-based) of well head
JHead = 1, // J-location (one-based) of well head
FirstK = 2, // Layer ID (one-based) of top/first connection
LastK = 3, // Layer ID (one-based) of bottom/last connection
NConn = 4, // Number of active cells connected to well
Group = 5, // Index (one-based) of well's current group
WType = 6, // Well type (producer vs. injector)
ActWCtrl = 7, // Well's active target control mode (constraint).
IHead = 0, // I-location (one-based) of well head
JHead = 1, // J-location (one-based) of well head
FirstK = 2, // Layer ID (one-based) of top/first connection
LastK = 3, // Layer ID (one-based) of bottom/last connection
NConn = 4, // Number of active cells connected to well
Group = 5, // Index (one-based) of well's current group
WType = 6, // Well type
WCtrl = 7, // Well control
item9 = 8, // Unknown
item11 = 10, // Unknown
VFPTab = 11, // ID (one-based) of well's current VFP table.
item9 = 8, // Unknown
item11 = 10, // Unknown
PredReqWCtrl = 15, // Well's requested control mode from
// simulation deck (WCONINJE, WCONPROD).
VFPTab = 11, // ID (one-based) of well's current VFP table
item18 = 17, // Unknown
XFlow = 22,
item25 = 24, // Unknown
item32 = 31, // Unknown
item48 = 47, // Unknown
HistReqWCtrl = 49, // Well's requested control mode from
// simulation deck (WCONHIST, WCONINJH)
item50 = 49, // Unknown
MsWID = 70, // Multisegment well ID
// Value 0 for regular wells
@@ -120,15 +115,6 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
BHPTarget = 6, // Well's bottom hole pressure target
DatumDepth = 9, // Well's reference depth for BHP
HistLiqRateTarget = 33, // Well's historical/observed liquid
// rate target/limit
HistGasRateTarget = 54, // Well's historical/observed gas rate
// target/limit
HistBHPTarget = 55, // Well's historical/observed bottom
// hole pressure target/limit
};
} // SWell
@@ -155,22 +141,13 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
GasFVF = 34, // Well's producing gas formation volume factor.
item37 = 36, // Unknown
item38 = 37, // Unknown
item37 = 36, // Unknown
item38 = 37, // Unknown
BHPTarget = 41, // Well's current BHP Target/Limit
BHPTarget = 41, // Well's current BHP Target/Limit
HistOilPrTotal = 75, // Well's total cumulative oil production
// (observed/historical rates)
HistWatPrTotal = 76, // Well's total cumulative water
// production (observed/historical rates)
HistGasPrTotal = 77, // Well's total cumulative gas production
// (observed(historical rates)
HistWatInjTotal = 81, // Well's total cumulative water injection
// (observed/historical rates)
HistGasInjTotal = 82, // Well's total cumulative gas injection
// (observed/historical rates)
item82 = 81, // Unknown
item83 = 82, // Unknown
WatVoidPrRate = 122, // Well's voidage production rate
GasVoidPrRate = 123, // Well's voidage production rate

View File

@@ -47,8 +47,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
createDoubHead(const EclipseState& es,
const Schedule& sched,
const std::size_t lookup_step,
const double simTime,
const double nextTimeStep);
const double simTime);
@@ -64,6 +63,17 @@ namespace Opm { namespace RestartIO { namespace Helpers {
createLogiHead(const EclipseState& es);
std::vector<int> serialize_ICON(int lookup_step, // The integer index used to look up dynamic properties, e.g. the number of well.
int ncwmax, // Max number of completions per well, should be entry 17 from createInteHead.
int niconz, // Number of elements per completion in ICON, should be entry 32 from createInteHead.
const std::vector<const Well*>& sched_wells);
std::vector<double> serialize_SCON(int lookup_step, // The integer index used to look up dynamic properties, e.g. the number of well.
int ncwmax, // Max number of completions per well, should be entry 17 from createInteHead.
int nsconz, // Number of elements per completion in SCON, should be entry 33 from createInteHead.
const std::vector<const Well*>& sched_wells,
const UnitSystem& units);
}}} // Opm::RestartIO::Helpers
#endif // OPM_WRITE_RESTART_HELPERS_HPP

View File

@@ -49,7 +49,7 @@
//jal - comment on the following include to avoid duplication
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
#include <opm/output/data/Cells.hpp>
#include <opm/output/data/Solution.hpp>

View File

@@ -147,7 +147,6 @@ namespace Opm {
const std::string& getInputPath() const;
const std::string& getDataFile() const;
void setDataFile(const std::string& dataFile);
std::string makeDeckPath(const std::string& path) const;
iterator begin();
iterator end();

View File

@@ -27,7 +27,6 @@
#include <opm/parser/eclipse/Units/Dimension.hpp>
#include <opm/parser/eclipse/Utility/Typetools.hpp>
#include <opm/parser/eclipse/Deck/UDAValue.hpp>
namespace Opm {
class DeckOutput;
@@ -40,7 +39,6 @@ namespace Opm {
DeckItem( const std::string&, int, size_t size_hint = 8 );
DeckItem( const std::string&, double, size_t size_hint = 8 );
DeckItem( const std::string&, std::string, size_t size_hint = 8 );
DeckItem( const std::string&, UDAValue, size_t size_hint = 8 );
const std::string& name() const;
@@ -60,7 +58,6 @@ namespace Opm {
size_t size() const;
size_t out_size() const;
//template< typename T > T& get( size_t ) ;
template< typename T > const T& get( size_t ) const;
double getSIDouble( size_t ) const;
std::string getTrimmedString( size_t ) const;
@@ -68,15 +65,12 @@ namespace Opm {
template< typename T > const std::vector< T >& getData() const;
const std::vector< double >& getSIDoubleData() const;
void push_back( UDAValue );
void push_back( int );
void push_back( double );
void push_back( std::string );
void push_back( UDAValue, size_t );
void push_back( int, size_t );
void push_back( double, size_t );
void push_back( std::string, size_t );
void push_backDefault( UDAValue );
void push_backDefault( int );
void push_backDefault( double );
void push_backDefault( std::string );
@@ -111,12 +105,11 @@ namespace Opm {
*/
bool operator==(const DeckItem& other) const;
bool operator!=(const DeckItem& other) const;
static bool to_bool(std::string string_value);
private:
mutable std::vector< double > dval;
std::vector< double > dval;
std::vector< int > ival;
std::vector< std::string > sval;
std::vector< UDAValue > uval;
type_tag type = type_tag::unknown;

View File

@@ -1,61 +0,0 @@
/*
Copyright 2019 Equinor 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/>.
*/
#ifndef UDA_VALUE_HPP
#define UDA_VALUE_HPP
#include <stdexcept>
#include <vector>
#include <string>
#include <opm/parser/eclipse/Units/Dimension.hpp>
namespace Opm {
class UDAValue {
public:
UDAValue();
explicit UDAValue(double);
explicit UDAValue(const std::string&);
template<typename T>
T get() const;
template<typename T>
bool is() const;
void set_dim(const Dimension& dim) const;
const Dimension& get_dim() const;
bool operator==(const UDAValue& other) const;
bool operator!=(const UDAValue& other) const;
private:
bool numeric_value;
double double_value;
std::string string_value;
/* This 'mutable' modifier is a hack to avoid tampering with the overall
const-ness of the data in a deck item. */
mutable Dimension dim;
};
}
#endif

View File

@@ -44,22 +44,21 @@ namespace Opm {
struct AquanconOutput{
int aquiferID;
std::vector<size_t> global_index;
std::vector<std::shared_ptr<double>> influx_coeff; // Size = size(global_index)
std::vector<double> influx_coeff; // Size = size(global_index)
std::vector<double> influx_multiplier; // Size = size(global_index)
std::vector<int> reservoir_face_dir; // Size = size(global_index)
std::vector<int> record_index;
};
Aquancon(const EclipseGrid& grid, const Deck& deck);
const std::vector<Aquancon::AquanconOutput>& getAquOutput() const;
private:
std::vector<Aquancon::AquanconOutput> logic_application(const std::vector<Aquancon::AquanconOutput>& original_vector);
void logic_application(std::vector<Aquancon::AquanconOutput>& output_vector);
void collate_function(std::vector<Aquancon::AquanconOutput>& output_vector,
std::vector<Opm::AquanconRecord>& m_aqurecord,
void collate_function(std::vector<Aquancon::AquanconOutput>& output_vector,
std::vector<Opm::AquanconRecord>& m_aqurecord,
std::vector<int> m_aquiferID_per_record, int m_maxAquID);
void convert_record_id_to_aquifer_id(std::vector<int>& record_indices_matching_id, int i,

View File

@@ -25,22 +25,21 @@
This includes the logic for parsing as well as the associated tables. It is meant to be used by opm-grid and opm-simulators in order to
implement the Carter Tracy analytical aquifer model in OPM Flow.
*/
#include <opm/parser/eclipse/Parser/ParserKeywords/A.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/A.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/Aqudims.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableContainer.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/AqutabTable.hpp>
#include <boost/concept_check.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
namespace Opm {
class EclipseState;
class AquiferCT {
public:
@@ -59,10 +58,10 @@ namespace Opm {
k_a , //aquifer permeability
c1, // 0.008527 (METRIC, PVT-M); 0.006328 (FIELD); 3.6 (LAB)
h , //aquifer thickness
p0, //Initial aquifer pressure at datum depth, d0
theta , //angle subtended by the aquifer boundary
c2 ; //6.283 (METRIC, PVT-M); 1.1191 (FIELD); 6.283 (LAB).
std::shared_ptr<double> p0; //Initial aquifer pressure at datum depth, d0
std::vector<double> td, pi;
};
@@ -71,23 +70,23 @@ namespace Opm {
const std::vector<AquiferCT::AQUCT_data>& getAquifers() const;
int getAqInflTabID(size_t aquiferIndex);
int getAqPvtTabID(size_t aquiferIndex);
private:
std::vector<AquiferCT::AQUCT_data> m_aquct;
//Set the default Pd v/s Td tables (constant terminal rate case for an infinite aquifer) as described in
//Van Everdingen, A. & Hurst, W., December, 1949.The Application of the Laplace Transformation to Flow Problems in Reservoirs.
//Set the default Pd v/s Td tables (constant terminal rate case for an infinite aquifer) as described in
//Van Everdingen, A. & Hurst, W., December, 1949.The Application of the Laplace Transformation to Flow Problems in Reservoirs.
//Petroleum Transactions, AIME.
inline void set_default_tables(std::vector<double>& td, std::vector<double>& pi)
{
std::vector<double> default_pressure_ = { 0.112, 0.229, 0.315, 0.376, 0.424, 0.469, 0.503, 0.564, 0.616, 0.659, 0.702, 0.735,
0.772, 0.802, 0.927, 1.02, 1.101, 1.169, 1.275, 1.362, 1.436, 1.5, 1.556, 1.604,
1.651, 1.829, 1.96, 2.067, 2.147, 2.282, 2.388, 2.476, 2.55, 2.615, 2.672, 2.723,
{
std::vector<double> default_pressure_ = { 0.112, 0.229, 0.315, 0.376, 0.424, 0.469, 0.503, 0.564, 0.616, 0.659, 0.702, 0.735,
0.772, 0.802, 0.927, 1.02, 1.101, 1.169, 1.275, 1.362, 1.436, 1.5, 1.556, 1.604,
1.651, 1.829, 1.96, 2.067, 2.147, 2.282, 2.388, 2.476, 2.55, 2.615, 2.672, 2.723,
2.921, 3.064, 3.173, 3.263, 3.406, 3.516, 3.608, 3.684, 3.75, 3.809, 3.86 };
std::vector<double> default_time_ = { 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1,
1.5, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60, 70,
std::vector<double> default_time_ = { 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1,
1.5, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60, 70,
80, 90, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000 };
td = default_time_;

View File

@@ -1,74 +0,0 @@
/*
Copyright (C) 2017 TNO
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/>.
*/
#ifndef OPM_AQUIFERFETP_HPP
#define OPM_AQUIFERFETP_HPP
/*
The Aquiferfetp which stands for AquiferFetkovich is a data container object meant to hold the data for the fetkovich aquifer model.
This includes the logic for parsing as well as the associated tables. It is meant to be used by opm-grid and opm-simulators in order to
implement the Fetkovich analytical aquifer model in OPM Flow.
*/
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/A.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/Aqudims.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableContainer.hpp>
#include <boost/concept_check.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
namespace Opm {
class Aquifetp {
public:
struct AQUFETP_data{
// Aquifer ID
int aquiferID;
// Table IDs
int inftableID, pvttableID;
std::vector<int> cell_id;
// Variables constants
double J, // Specified Productivity Index
rho, // water density in the aquifer
C_t, // total rock compressibility
V0, // initial volume of water in aquifer
d0; // aquifer datum depth
std::shared_ptr<double> p0; //Initial aquifer pressure at datum depth d0 - nullptr if the pressure has been defaulted.
};
Aquifetp(const Deck& deck);
const std::vector<Aquifetp::AQUFETP_data>& getAquifers() const;
int getAqPvtTabID(size_t aquiferIndex);
private:
std::vector<Aquifetp::AQUFETP_data> m_aqufetp;
};
}
#endif

View File

@@ -93,7 +93,6 @@ namespace Opm {
void handleEQUALREGKeyword(const DeckKeyword& deckKeyword );
void handleMULTIREGKeyword(const DeckKeyword& deckKeyword );
void handleOPERATEKeyword( const DeckKeyword& deckKeyword, BoxManager& boxManager);
void handleOPERATERKeyword( const DeckKeyword& deckKeyword);
void loadGridPropertyFromDeckKeyword(const Box& inputBox,
const DeckKeyword& deckKeyword);

View File

@@ -29,13 +29,11 @@
namespace Opm {
class Deck;
class ParseContext;
class ErrorGuard;
class EclipseConfig
{
public:
EclipseConfig(const Deck& deck, const ParseContext& parseContext, ErrorGuard& errors);
EclipseConfig(const Deck& deck);
const InitConfig& init() const;
const IOConfig& io() const;

View File

@@ -23,17 +23,15 @@
#include <memory>
#include <vector>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Edit/EDITNNC.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FaultCollection.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/NNC.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/TransMult.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp>
namespace Opm {
@@ -66,11 +64,9 @@ namespace Opm {
AllProperties = IntProperties | DoubleProperties
};
template<typename T>
EclipseState(const Deck& deck , const ParseContext& parseContext, T&& errors);
EclipseState(const Deck& deck , const ParseContext& parseContext, ErrorGuard& errors);
EclipseState(const Deck& deck);
EclipseState(const Deck& deck , ParseContext parseContext = ParseContext());
const ParseContext& getParseContext() const;
const IOConfig& getIOConfig() const;
IOConfig& getIOConfig();
@@ -89,11 +85,6 @@ namespace Opm {
const NNC& getInputNNC() const;
bool hasInputNNC() const;
/// editing non-neighboring connections
/// the non-standard adjacencies as specified in input deck
const EDITNNC& getInputEDITNNC() const;
bool hasInputEDITNNC() const;
const Eclipse3DProperties& get3DProperties() const;
const TableManager& getTableManager() const;
const EclipseConfig& getEclipseConfig() const;
@@ -121,12 +112,12 @@ namespace Opm {
void complainAboutAmbiguousKeyword(const Deck& deck,
const std::string& keywordName);
ParseContext m_parseContext;
const TableManager m_tables;
Runspec m_runspec;
EclipseConfig m_eclipseConfig;
UnitSystem m_deckUnitSystem;
NNC m_inputNnc;
EDITNNC m_inputEditNnc;
EclipseGrid m_inputGrid;
Eclipse3DProperties m_eclipseProperties;
const SimulationConfig m_simulationConfig;

View File

@@ -1,48 +0,0 @@
/*
Copyright 2018 Equinor 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/>.
*/
#ifndef OPM_COMMON_EDITNNC_HPP
#define OPM_COMMON_EDITNNC_HPP
#include <opm/parser/eclipse/EclipseState/Grid/NNC.hpp>
namespace Opm
{
/// Represents edit information for non-neighboring connections (NNCs, faults, etc.)
class EDITNNC
{
public:
EDITNNC() = default;
/// Construct from input deck
explicit EDITNNC(const Deck& deck);
/// \brief Get an ordered set of EDITNNC
const std::vector<NNCdata>& data() const
{
return m_editnnc;
}
/// \brief Get the number of entries
size_t size() const;
/// \brief Whether EDITNNC was empty.
bool empty() const;
private:
std::vector<NNCdata> m_editnnc;
};
}
#endif // OPM_COMMON_EDITNNC_HPP

View File

@@ -38,7 +38,6 @@ namespace Opm {
class Deck;
class ZcornMapper;
class NNC;
/**
About cell information and dimension: The actual grid
@@ -77,8 +76,6 @@ namespace Opm {
/// explicitly. If a null pointer is passed, every cell is active.
EclipseGrid(const Deck& deck, const int * actnum = nullptr);
static bool hasGDFILE(const Deck& deck);
static bool hasCylindricalKeywords(const Deck& deck);
static bool hasCornerPointKeywords(const Deck&);
static bool hasCartesianKeywords(const Deck&);
@@ -88,8 +85,6 @@ namespace Opm {
size_t activeIndex(size_t i, size_t j, size_t k) const;
size_t activeIndex(size_t globalIndex) const;
void save(const std::string& filename, UnitSystem::UnitType output_units) const;
void addNNC(const NNC& nnc);
/*
Observe that the there is a getGlobalIndex(i,j,k)
implementation in the base class. This method - translating
@@ -112,7 +107,7 @@ namespace Opm {
PinchMode::ModeEnum getMultzOption( ) const;
MinpvMode::ModeEnum getMinpvMode() const;
const std::vector<double>& getMinpvVector( ) const;
double getMinpvValue( ) const;
/*
@@ -181,7 +176,7 @@ namespace Opm {
const ecl_grid_type * c_ptr() const;
private:
std::vector<double> m_minpvVector;
double m_minpvValue;
MinpvMode::ModeEnum m_minpvMode;
Value<double> m_pinch;
PinchMode::ModeEnum m_pinchoutMode;
@@ -205,7 +200,6 @@ namespace Opm {
ert_ptr( ecl_grid_alloc_copy( src.get() ) ) {}
};
grid_ptr m_grid;
void initBinaryGrid(const Deck& deck);
void initCornerPointGrid(const std::array<int,3>& dims ,
const std::vector<double>& coord ,

View File

@@ -52,7 +52,7 @@ private:
void addFaultFaces(const GridDims& grid,
const DeckRecord& faultRecord,
const std::string& faultName);
OrderedMap<std::string, Fault> m_faults;
OrderedMap<Fault> m_faults;
};
}

View File

@@ -65,7 +65,6 @@ namespace Opm {
private:
void init(const DeckKeyword& keyword);
void binary_init(const Deck& deck);
};
}

View File

@@ -141,13 +141,12 @@ namespace Opm {
void handleMULTIPLYRecord( const DeckRecord& record, BoxManager& boxManager);
void handleCOPYRecord( const DeckRecord& record, BoxManager& boxManager);
void handleEQUALSRecord( const DeckRecord& record, BoxManager& boxManager);
void handleOPERATERecord( const DeckRecord& record , BoxManager& boxManager);
void handleEQUALREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty );
void handleADDREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty );
void handleMULTIREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty );
void handleCOPYREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty );
void handleOPERATERRecord( const DeckRecord& record , const GridProperty<int>& regionProperty );
void handleOPERATERecord( const DeckRecord& record , BoxManager& boxManager);
/*
Iterators over initialized properties. The overloaded
operator*() opens the pair which comes natively from the
@@ -185,11 +184,6 @@ namespace Opm {
const std::string& dimString,
const bool defaultInitializable );
void postAddKeyword(const std::string& name,
std::function< std::vector< T >(size_t) > initProcessor,
const std::string& dimString);
GridProperty<T>& getKeyword(const std::string& keyword);
bool addAutoGeneratedKeyword_(const std::string& keywordName) const;
void insertKeyword(const SupportedKeywordInfo& supportedKeyword) const;

View File

@@ -177,91 +177,13 @@ public:
grid and call the cellsEqual( T , std::vector<int>&) overload,
otherwise it will return indexEqual( value );
*/
std::vector<size_t> cellsEqual(T value, const EclipseGrid& grid, bool active = true) const;
std::vector<size_t> cellsEqual(T value, const EclipseGrid& grid, bool active = true) const;
/*
Will return a std::vector<T> of the data in the active cells.
*/
std::vector<T> compressedCopy( const EclipseGrid& grid) const;
/*
The grid properties like PORO and SATNUM can be created in essentially two
ways; either they can be explicitly assigned in the deck as:
PORO
1000*0.15 /
or they can be created indirectly through various mathematical operations
like:
MULTIPLY
TRANX 0.20 /
/
The deckAssigned() property is used so that we can differentiate between
properties which have been explicitly assigned/loaded from the deck, and
those where the default construction has been invoked. This functionality
is implemented purely to support the TRAN? keywords. The transmissibility
is be default calculated by the simulator code, but the TRAN keywords can
be used in the deck to manipulate this calculation in two different ways:
1. TRAN explicitly assigned in GRID section
===========================================
...
TRANX
1000*0.026 /
COPY
'TRANX' 'TRANY' /
/
In this case the simulator should detect that the input deck has TRANX
specified and just use the input values from the deck. This is the
normal handling of keywords, and agrees with e.g. PERMX and PORO. This
also applies when the COPY keyword has been used, as in the case of
'TRANY' above.
2. TRAN modifier present in EDIT section
========================================
The scenario here is that there is no mention of TRANX in the GRID
section, however the EDIT section contains modifiers like this:
MULTIPLY
TRANX 0.25 /
I.e. we request the TRANX values to be reduced with a factor of 0.25. In
this case the simulator should still calculate transmissibility according
to it's normal algorithm, and then subsequently scale that result with a
factor of 0.25.
In this case the input layer needs to autocreate a TRANX keyword,
defaulted to 1.0 and then scale that to 0.25.
Now - the important point is that when doing transmissibility calculations
the simulator must be able to distinguish between cases 1 and 2,
specifically whether the TRANX keyword should be interpreted as absolute
values(case 1) or as a multiplier(case 2). That is the purpose of the
deckAssigned() property. Pseudo code for the transmissibility calculations
in the simulator could be:
const auto& input_tranx = properties.getKeyword("TRANX");
if (input_tranx.deckAssigned()) {
// set simulator internal transmissibilities to values from input_tranx
tranx = input_tranx;
} else {
// Calculate transmissibilities according to normal simulator algorithm
...
...
// Scale transmissibilities with scale factor from input_tranx
tranx *= input_tranx;
}
*/
bool deckAssigned() const;
private:
const DeckItem& getDeckItem( const DeckKeyword& );
void setDataPoint(size_t sourceIdx, size_t targetIdx, const DeckItem& deckItem);
@@ -270,7 +192,6 @@ private:
SupportedKeywordInfo m_kwInfo;
std::vector<T> m_data;
bool m_hasRunPostProcessor = false;
bool assigned = false;
};
// initialize the TEMPI grid property using the temperature vs depth

View File

@@ -50,11 +50,14 @@ namespace Opm {
struct MULTREGTRecord {
class MULTREGTRecord {
public:
MULTREGTRecord(int src, int target, double trans_mult, int directions, MULTREGT::NNCBehaviourEnum nnc_behaviour, const std::string& region_name);
int src_value;
int target_value;
double trans_mult;
int directions;
double trans_mult;
MULTREGT::NNCBehaviourEnum nnc_behaviour;
std::string region_name;
};

View File

@@ -28,10 +28,6 @@ namespace Opm
{
struct NNCdata {
NNCdata(size_t c1, size_t c2, double t)
: cell1(c1), cell2(c2), trans(t)
{}
NNCdata() = default;
size_t cell1;
size_t cell2;
double trans;

View File

@@ -174,7 +174,7 @@ namespace Opm {
void setOutputDir(const std::string& outputDir);
const std::string& getBaseName() const;
void setBaseName(const std::string& baseName);
void setBaseName(std::string baseName);
/// Return a string consisting of outputpath and basename;
/// i.e. /path/to/sim/CASE
@@ -199,8 +199,8 @@ namespace Opm {
std::string m_deck_filename;
bool m_output_enabled = true;
std::string m_output_dir;
bool m_nosim;
std::string m_base_name;
bool m_nosim;
bool ecl_compatible_rst = true;
IOConfig( const GRIDSection&,

View File

@@ -200,8 +200,7 @@ namespace Opm {
class SOLUTIONSection;
class TimeMap;
class Schedule;
class ParseContext;
class ErrorGuard;
/*The IOConfig class holds data about input / ouput configurations
@@ -318,27 +317,19 @@ namespace Opm {
public:
RestartConfig();
template<typename T>
RestartConfig( const Deck&, const ParseContext& parseContext, T&& errors );
RestartConfig( const Deck&, const ParseContext& parseContext, ErrorGuard& errors );
RestartConfig( const Deck& );
explicit RestartConfig( const Deck& );
RestartConfig( const SCHEDULESection& schedule,
const SOLUTIONSection& solution,
const ParseContext& parseContext,
ErrorGuard& errors,
TimeMap timemap );
int getFirstRestartStep() const;
bool getWriteRestartFile(size_t timestep, bool log=true) const;
bool getWriteRestartFile(size_t timestep) const;
const std::map< std::string, int >& getRestartKeywords( size_t timestep ) const;
int getKeyword( const std::string& keyword, size_t timeStep) const;
void overrideRestartWriteInterval(size_t interval);
void handleSolutionSection(const SOLUTIONSection& solutionSection, const ParseContext& parseContext, ErrorGuard& errors);
void handleSolutionSection(const SOLUTIONSection& solutionSection);
void setWriteInitialRestartFile(bool writeInitialRestartFile);
RestartSchedule getNode( size_t timestep ) const;
@@ -365,7 +356,7 @@ namespace Opm {
int m_first_restart_step;
bool m_write_initial_RST_file = false;
void handleScheduleSection( const SCHEDULESection& schedule, const ParseContext& parseContext, ErrorGuard& errors);
void handleScheduleSection( const SCHEDULESection& schedule);
void update( size_t step, const RestartSchedule& rs);
static RestartSchedule rptsched( const DeckKeyword& );

View File

@@ -24,7 +24,7 @@
#include <opm/parser/eclipse/EclipseState/Tables/Tabdims.hpp>
#include <opm/parser/eclipse/EclipseState/EndpointScaling.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParams.hpp>
#include <opm/parser/eclipse/EclipseState/UDQConfig.hpp>
namespace Opm {
class Deck;
@@ -112,73 +112,27 @@ private:
int nLatBranchMax;
};
class EclHysterConfig
{
public:
explicit EclHysterConfig(const Deck& deck);
/*!
* \brief Specify whether hysteresis is enabled or not.
*/
//void setActive(bool yesno);
/*!
* \brief Returns whether hysteresis is enabled (active).
*/
bool active() const;
/*!
* \brief Return the type of the hysteresis model which is used for capillary pressure.
*
* -1: capillary pressure hysteresis is disabled
* 0: use the Killough model for capillary pressure hysteresis
*/
int pcHysteresisModel() const;
/*!
* \brief Return the type of the hysteresis model which is used for relative permeability.
*
* -1: relperm hysteresis is disabled
* 0: use the Carlson model for relative permeability hysteresis
*/
int krHysteresisModel() const;
private:
// enable hysteresis at all
bool activeHyst { false };
// the capillary pressure and the relperm hysteresis models to be used
int pcHystMod { 0 };
int krHystMod { 0 };
};
class Runspec {
public:
explicit Runspec( const Deck& );
public:
explicit Runspec( const Deck& );
const UDQParams& udqParams() const noexcept;
const Phases& phases() const noexcept;
const Tabdims& tabdims() const noexcept;
const EndpointScaling& endpointScaling() const noexcept;
const Welldims& wellDimensions() const noexcept;
const WellSegmentDims& wellSegmentDimensions() const noexcept;
int eclPhaseMask( ) const noexcept;
const EclHysterConfig& hysterPar() const noexcept;
const UDQConfig& udqConfig() const noexcept;
const Phases& phases() const noexcept;
const Tabdims& tabdims() const noexcept;
const EndpointScaling& endpointScaling() const noexcept;
const Welldims& wellDimensions() const noexcept;
const WellSegmentDims& wellSegmentDimensions() const noexcept;
int eclPhaseMask( ) const noexcept;
private:
Phases active_phases;
Tabdims m_tabdims;
EndpointScaling endscale;
Welldims welldims;
WellSegmentDims wsegdims;
UDQParams udq_params;
EclHysterConfig hystpar;
private:
Phases active_phases;
Tabdims m_tabdims;
EndpointScaling endscale;
Welldims welldims;
WellSegmentDims wsegdims;
UDQConfig udq_config;
};
}
#endif // OPM_RUNSPEC_HPP

View File

@@ -1,50 +0,0 @@
/*
Copyright 2018 Equinor 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/>.
*/
#ifndef ActionAST_HPP
#define ActionAST_HPP
#include <string>
#include <vector>
#include <memory>
namespace Opm {
class ActionContext;
class ASTNode;
class ActionAST{
public:
ActionAST() = default;
explicit ActionAST(const std::vector<std::string>& tokens);
bool eval(const ActionContext& context, std::vector<std::string>& matching_wells) const;
private:
/*
The use of a pointer here is to be able to create this class with only a
forward declaration of the ASTNode class. Would have prefered to use a
unique_ptr, but that requires writing custom destructors - the use of a
shared_ptr does not imply any shared ownership.
*/
std::shared_ptr<ASTNode> condition;
};
}
#endif

View File

@@ -1,55 +0,0 @@
/*
Copyright 2018 Equinor 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/>.
*/
#ifndef ActionContext_HPP
#define ActionContext_HPP
#include <string>
#include <map>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
namespace Opm {
class ActionContext {
public:
/*
Observe that the ActionContext takes a copy of the SummaryState object.
*/
explicit ActionContext(const SummaryState& summary_state);
/*
The get methods will first check the internal storage in the 'values' map
and then subsequently query the SummaryState member.
*/
double get(const std::string& func, const std::string& arg) const;
void add(const std::string& func, const std::string& arg, double value);
double get(const std::string& func) const;
void add(const std::string& func, double value);
std::vector<std::string> wells(const std::string& func) const;
private:
SummaryState summary_state;
std::map<std::string, double> values;
};
}
#endif

View File

@@ -1,45 +0,0 @@
/*
Copyright 2018 Equinor 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/>.
*/
#ifndef ActionCOnfig_HPP
#define ActionCOnfig_HPP
#include <string>
#include <ctime>
#include <map>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
namespace Opm {
class Actions {
public:
Actions() = default;
size_t size() const;
bool empty() const;
void add(const ActionX& action);
bool ready(std::time_t sim_time) const;
ActionX& at(const std::string& name);
std::vector<const ActionX *> pending(std::time_t sim_time) const;
private:
std::map<std::string, ActionX> actions;
};
}
#endif

View File

@@ -22,11 +22,6 @@
#define ActionX_HPP_
#include <string>
#include <vector>
#include <ctime>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionAST.hpp>
namespace Opm {
/*
@@ -54,36 +49,21 @@ namespace Opm {
*/
class DeckKeyword;
class ActionContext;
class ActionX {
public:
ActionX(const std::string& name, size_t max_run, double max_wait, std::time_t start_time);
ActionX(const DeckKeyword& kw, std::time_t start_time);
ActionX(const DeckRecord& record, std::time_t start_time);
ActionX(const std::string& name, size_t max_run, double max_wait);
explicit ActionX(const DeckKeyword& kw);
void addKeyword(const DeckKeyword& kw);
bool ready(std::time_t sim_time) const;
bool eval(std::time_t sim_time, const ActionContext& context, std::vector<std::string>& wells) const;
std::string name() const { return this->m_name; }
size_t max_run() const { return this->m_max_run; }
double min_wait() const { return this->m_min_wait; }
std::time_t start_time() const { return this->m_start_time; }
std::vector<DeckKeyword>::const_iterator begin() const;
std::vector<DeckKeyword>::const_iterator end() const;
static bool valid_keyword(const std::string& keyword);
const std::string& name() const;
private:
std::string m_name;
size_t m_max_run = 0;
double m_min_wait = 0.0;
std::time_t m_start_time;
size_t max_run;
double max_wait;
std::vector<DeckKeyword> keywords;
ActionAST condition;
mutable size_t run_count = 0;
mutable std::time_t last_run = 0;
};
}

View File

@@ -1,42 +0,0 @@
/*
Copyright (c) 2019 Equinor 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/>.
*/
#ifndef OPM_ARRAYDIM_CHECKER_HPP
#define OPM_ARRAYDIM_CHECKER_HPP
#include <cstddef>
namespace Opm {
class ErrorGuard;
class EclipseState;
class ParseContext;
class Schedule;
} // Opm
namespace Opm {
int maxGroupSize(const Schedule& sched,
const std::size_t step);
void checkConsistentArrayDimensions(const EclipseState& es,
const Schedule& sched,
const ParseContext& ctxt,
ErrorGuard& guard);
} // Opm
#endif // OPM_ARRAYDIM_CHECKER_HPP

View File

@@ -46,14 +46,13 @@ namespace Opm {
double CF,
double Kh,
double rw,
double r0,
double skin_factor,
const int satTableId,
const WellCompletion::DirectionEnum direction,
const std::size_t seqIndex,
const double segDistStart,
const double segDistEnd,
const bool defaultSatTabId);
const std::size_t seqIndex,
const double segDistStart,
const double segDistEnd,
const bool defaultSatTabId
);
bool attachedToSegment() const;
@@ -70,24 +69,21 @@ namespace Opm {
double CF() const;
double Kh() const;
double rw() const;
double r0() const;
double skinFactor() const;
double wellPi() const;
void setState(WellCompletion::StateEnum state);
void setComplnum(int compnum);
void scaleWellPi(double wellPi);
void updateSegment(int segment_number, double center_depth, std::size_t seqIndex);
const std::size_t& getSeqIndex() const;
const bool& getDefaultSatTabId() const;
const std::size_t& getCompSegSeqIndex() const;
void setCompSegSeqIndex(std::size_t index);
void setDefaultSatTabId(bool id);
const double& getSegDistStart() const;
const double& getSegDistEnd() const;
void setSegDistStart(const double& distStart);
void setSegDistEnd(const double& distEnd);
std::string str() const;
const std::size_t& getSeqIndex() const;
const bool& getDefaultSatTabId() const;
const std::size_t& getCompSegSeqIndex() const;
void setCompSegSeqIndex(std::size_t index);
void setDefaultSatTabId(bool id);
const double& getSegDistStart() const;
const double& getSegDistEnd() const;
void setSegDistStart(const double& distStart);
void setSegDistEnd(const double& distEnd);
bool operator==( const Connection& ) const;
bool operator!=( const Connection& ) const;
@@ -100,15 +96,13 @@ namespace Opm {
double m_CF;
double m_Kh;
double m_rw;
double m_r0;
double m_skin_factor;
std::array<int,3> ijk;
std::size_t m_seqIndex;
double m_segDistStart;
double m_segDistEnd;
bool m_defaultSatTabId;
std::size_t m_compSeg_seqIndex=0;
std::size_t m_seqIndex;
double m_segDistStart;
double m_segDistEnd;
bool m_defaultSatTabId;
std::size_t m_compSeg_seqIndex=0;
// related segment number
// -1 means the completion is not related to segment

View File

@@ -24,7 +24,6 @@
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <utility>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
@@ -89,29 +88,6 @@ class DynamicState {
std::fill_n( this->m_data.begin(), this->initial_range, initial );
}
std::vector<std::pair<std::size_t, T>> unique() {
if (this->m_data.empty())
return {};
auto& current_value = this->m_data[0];
std::size_t current_index = 0;
std::vector<std::pair<std::size_t, T>> result{{current_index, current_value}};
while (true) {
if (this->m_data[current_index] != current_value) {
current_value = this->m_data[current_index];
result.emplace_back(current_index, current_value);
}
current_index++;
if (current_index == this->m_data.size())
break;
}
return result;
}
/**
If the current value has been changed the method will
return true, otherwise it will return false.
@@ -138,70 +114,25 @@ class DynamicState {
this->m_data[index] = value;
}
/// Will return the index of the first occurence of @value, or
/// -1 if @value is not found.
int find(const T& value) const {
auto iter = std::find( m_data.begin() , m_data.end() , value);
if( iter == this->m_data.end() ) return -1;
/*
Will assign all currently equal values starting at index with the new
value. Purpose of the method is to support manipulations of an existing
Schedule object, if e.g. a well is initially closed in the interval
[T1,T2] and then opened at time T1 < Tx < T2 then the open should be
applied for all times in the range [Tx,T2].
*/
void update_equal(size_t index, const T& value) {
if (this->m_data.size() <= index)
throw std::out_of_range("Invalid index for update_equal()");
const T prev_value = this->m_data[index];
if (prev_value == value)
return;
while (true) {
if (this->m_data[index] != prev_value)
break;
this->m_data[index] = value;
index++;
if (index == this->m_data.size())
break;
return std::distance( m_data.begin() , iter );
}
}
/// Will return the index of the first occurence of @value, or
/// -1 if @value is not found.
int find(const T& value) const {
auto iter = std::find( m_data.begin() , m_data.end() , value);
if( iter == this->m_data.end() ) return -1;
return std::distance( m_data.begin() , iter );
}
template<typename P>
int find_if(P&& pred) const {
auto iter = std::find_if(m_data.begin(), m_data.end(), std::forward<P>(pred));
if( iter == this->m_data.end() ) return -1;
return std::distance( m_data.begin() , iter );
}
/// Will return the index of the first value which is != @value, or -1
/// if all values are == @value
int find_not(const T& value) const {
auto iter = std::find_if_not( m_data.begin() , m_data.end() , [&value] (const T& elm) { return value == elm; });
if( iter == this->m_data.end() ) return -1;
return std::distance( m_data.begin() , iter );
}
iterator begin() {
return this->m_data.begin();
}
iterator end() {
return this->m_data.end();
}
iterator begin() {
return this->m_data.begin();
}
iterator end() {
return this->m_data.end();
}
private:
std::vector< T > m_data;

View File

@@ -45,7 +45,7 @@ namespace Opm
WELL_WELSPECS_UPDATE = 2,
//WELL_POLYMER_UPDATE = 4,
WELL_POLYMER_UPDATE = 4,
/*
The NEW_GROUP event is triggered by the WELSPECS and
GRUPTREE keywords.
@@ -61,7 +61,7 @@ namespace Opm
*/
PRODUCTION_UPDATE = 16,
INJECTION_UPDATE = 32,
//POLYMER_UPDATES = 64,
POLYMER_UPDATES = 64,
/*
This event is triggered if the well status is changed

View File

@@ -34,6 +34,7 @@ namespace Opm {
class TimeMap;
class Well;
namespace GroupInjection {
struct InjectionData {
@@ -128,7 +129,7 @@ namespace Opm {
bool hasWell(const std::string& wellName , size_t time_step) const;
const std::set< std::string >& getWells( size_t time_step ) const;
size_t numWells(size_t time_step) const;
void addWell(size_t time_step, const std::string& well_name);
void addWell(size_t time_step, const Well* well);
void delWell(size_t time_step, const std::string& wellName );
private:

View File

@@ -27,46 +27,40 @@
namespace Opm {
class GroupTree {
public:
struct group {
std::string name;
std::string parent;
public:
void update( const std::string& name);
void update( const std::string& name, const std::string& parent);
void updateSeqIndex( const std::string& name, const std::string& other_parent);
bool exists( const std::string& group ) const;
const std::string& parent( const std::string& name ) const;
std::vector< std::string > children( const std::string& parent ) const;
const std::map<const std::string , size_t>& nameSeqIndMap() const;
const std::map<size_t, const std::string >& seqIndNameMap() const;
size_t groupTreeSize();
bool operator==( const GroupTree& ) const;
bool operator!=( const GroupTree& ) const;
bool operator<( const group& rhs ) const;
bool operator==( const std::string& name ) const;
bool operator!=( const std::string& name ) const;
private:
struct group {
std::string name;
std::string parent;
bool operator<( const std::string& name ) const;
bool operator==( const group& rhs ) const;
bool operator!=( const group& rhs ) const;
};
bool operator<( const group& rhs ) const;
bool operator==( const std::string& name ) const;
bool operator!=( const std::string& name ) const;
void update( const std::string& name);
void update( const std::string& name, const std::string& parent);
void updateSeqIndex( const std::string& name, const std::string& other_parent);
bool exists( const std::string& group ) const;
const std::string& parent( const std::string& name ) const;
std::vector< std::string > children( const std::string& parent ) const;
const std::map<std::string , size_t>& nameSeqIndMap() const;
const std::map<size_t, std::string >& seqIndNameMap() const;
bool operator==( const GroupTree& ) const;
bool operator!=( const GroupTree& ) const;
std::vector<GroupTree::group>::const_iterator begin() const;
std::vector<GroupTree::group>::const_iterator end() const;
bool operator<( const std::string& name ) const;
bool operator==( const group& rhs ) const;
bool operator!=( const group& rhs ) const;
};
private:
std::vector< group >::iterator find( const std::string& );
friend bool operator<( const std::string&, const group& );
std::vector< group > groups = { group { "FIELD", "" } };
std::map<std::string , size_t> m_nameSeqIndMap;
std::map<size_t, std::string > m_seqIndNameMap;
std::vector< group > groups = { group { "FIELD", "" } };
friend bool operator<( const std::string&, const group& );
std::vector< group >::iterator find( const std::string& );
std::map<const std::string , size_t> m_nameSeqIndMap;
std::map<size_t, const std::string > m_seqIndNameMap;
};
std::ostream& operator<<(std::ostream& stream, const GroupTree& gt);
}
#endif /* GROUPTREE_HPP */

Some files were not shown because too many files have changed in this diff Show More