Skip to content

Commit

Permalink
Use updated opm-common
Browse files Browse the repository at this point in the history
* Update opm-common submodule and use branch development https://github.com/CeetronSolutions/opm-common/tree/development

* Add cmake-format of ThirdParty/custom-opm-common/CMakeLists.txt

* Add boost-test

* Update generated files and simplify CMake configuration

Add -D_USE_MATH_DEFINES to CMake to avoid multiple local defines
Introduce flag CREATE_OPM_COMMON_KEYWORDS used to generate C++ files JSON files. This enables use also in MSVC. Remove obsolete direct include of source files.

* Update generated ESMRY test file

There was a invalid extra : postfix for some keywords like NEWTON and other N* keywords. When creating ESRMY using updated opm-common fix this issue.

* Update URL for custom-opm-common
  • Loading branch information
magnesj authored Jan 22, 2025
1 parent ed66ee9 commit 3f08901
Show file tree
Hide file tree
Showing 141 changed files with 11,620 additions and 9,727 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cmake-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
cd Fwk/AppFwk
find -name CMake*.txt | xargs ~/.local/bin/cmake-format -c ${{ github.workspace }}/cmake/cmake-format.py -i
cd ..
cd ..
~/.local/bin/cmake-format -c ${{ github.workspace }}/cmake/cmake-format.py -i ThirdParty/custom-opm-common/CMakeLists.txt
git diff
- uses: peter-evans/create-pull-request@v7
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ set(UNITY_EXCLUDE_FILES
FileInterface/RifOsduWellLogReader.cpp
FileInterface/RifByteArrayArrowRandomAccessFile.cpp
FileInterface/RifArrowTools.cpp
FileInterface/RifReaderOpmRft.cpp
)

message("Files excluded from UNITY_BUILD : ${UNITY_EXCLUDE_FILES}")
Expand Down
3 changes: 2 additions & 1 deletion ApplicationLibCode/FileInterface/RifOpmRadialGridTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void RifOpmRadialGridTools::lockToHostPillars( cvf::Vec3d& riNode,
std::array<double, 8> cellRadius{};
std::array<double, 8> cellTheta{};
std::array<double, 8> cellZ{};
opmGrid.getRadialCellCorners( ijkCell, cellRadius, cellTheta, cellZ );
bool convertToRadialCoords = false;
opmGrid.getCellCorners( ijkCell, cellRadius, cellTheta, cellZ, convertToRadialCoords );

double maxRadius = *std::max_element( cellRadius.begin(), cellRadius.end() );

Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

#include <QStringList>

#include <iostream>

using namespace Opm;

//--------------------------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "opm/common/utility/OpmInputError.hpp"
#include "opm/input/eclipse/Deck/Deck.hpp"
#include "opm/input/eclipse/Parser/InputErrorAction.hpp"
#include "opm/input/eclipse/Parser/ParseContext.hpp"
#include "opm/input/eclipse/Parser/Parser.hpp"
#include "opm/input/eclipse/Parser/ParserKeywords/G.hpp"
Expand Down Expand Up @@ -115,7 +116,7 @@ std::pair<std::vector<Opm::VFPProdTable>, std::vector<Opm::VFPInjTable>> extract
parser.addParserKeyword( kw );
}

Opm::ParseContext parseContext( Opm::InputError::Action::WARN );
Opm::ParseContext parseContext( Opm::InputErrorAction::WARN );
auto deck = parser.parseFile( dataDeckFilename, parseContext );

{
Expand Down Expand Up @@ -174,7 +175,7 @@ std::map<std::string, std::vector<std::pair<int, int>>> extractWseglink( const s
parser.addParserKeyword( kw3 );

std::stringstream ss;
Opm::ParseContext parseContext( Opm::InputError::Action::WARN );
Opm::ParseContext parseContext( Opm::InputErrorAction::WARN );
auto deck = parser.parseFile( filename, parseContext );

std::string keyword = "WSEGLINK";
Expand Down Expand Up @@ -246,7 +247,7 @@ std::vector<RiaOpmParserTools::AicdTemplateValues> extractWsegAicd( const std::s
parser.addParserKeyword( kw3 );

std::stringstream ss;
Opm::ParseContext parseContext( Opm::InputError::Action::WARN );
Opm::ParseContext parseContext( Opm::InputErrorAction::WARN );
auto deck = parser.parseFile( filename, parseContext );

const std::string keyword = "WSEGAICD";
Expand Down
Binary file not shown.
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,14 @@ option(RESINSIGHT_BUILD_LIBS_FROM_SOURCE "Build opm-common from source" ON)
mark_as_advanced(RESINSIGHT_BUILD_LIBS_FROM_SOURCE)

if((NOT RESINSIGHT_BUILD_LIBS_FROM_SOURCE) AND MSVC)

message(STATUS "Starting download of external library opm-common ...")

# See description of URL here
# https://docs.github.com/en/repositories/releasing-projects-on-github/linking-to-releases
FetchContent_Declare(
ri-dependencies
URL https://github.com/CeetronSolutions/resinsight-dependencies/releases/download/2024.11/custom-opm-common.zip
URL https://github.com/CeetronSolutions/resinsight-dependencies/releases/download/2025.01/custom-opm-common.zip
)
FetchContent_MakeAvailable(ri-dependencies)

Expand All @@ -507,12 +510,21 @@ if((NOT RESINSIGHT_BUILD_LIBS_FROM_SOURCE) AND MSVC)

list(APPEND EXTERNAL_LINK_LIBRARIES custom-opm-common)

message(STATUS "opm-common: Enabled use of precompiled library")
message(STATUS "... completed download of external library opm-common ")
else()
# CREATE_OPM_COMMON_KEYWORDS is used to create c++-code for the keywords in
# opm-common JSON files See description in
# ThirdParty/custom-opm-common/CMakeLists.txt When changing this flag, it is
# required to reopen the Visual Studio project
set(CREATE_OPM_COMMON_KEYWORDS OFF)

add_subdirectory(ThirdParty/custom-opm-common)
add_subdirectory(ThirdParty/custom-opm-common/custom-opm-parser-tests)
list(APPEND OPM_LIBRARIES custom-opm-common)
set_property(TARGET opm-parser-tests PROPERTY FOLDER "Thirdparty/OPM")

if(NOT CREATE_OPM_COMMON_KEYWORDS)
add_subdirectory(ThirdParty/custom-opm-common/custom-opm-parser-tests)
list(APPEND OPM_LIBRARIES custom-opm-common)
set_property(TARGET opm-parser-tests PROPERTY FOLDER "Thirdparty/OPM")
endif()
endif()

list(APPEND OPM_LIBRARIES custom-opm-flowdiagnostics custom-opm-flowdiag-app)
Expand Down
199 changes: 87 additions & 112 deletions ThirdParty/custom-opm-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,139 +7,114 @@ else()
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

if(MSVC)
add_definitions( "/wd4996 /wd4244 /wd4267 /wd4101 /wd4477" )
if(MSVC)
add_definitions(
"/wd4996 /wd4244 /wd4267 /wd4101 /wd4477 /wd4661 -D_USE_MATH_DEFINES"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /permissive-")
endif(MSVC)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-switch -Wno-sign-compare -Wno-deprecated-copy -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-switch -Wno-sign-compare -Wno-deprecated-copy -Wno-missing-field-initializers"
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare -Wno-missing-field-initializers -Wno-deprecated-copy")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-sign-compare -Wno-missing-field-initializers -Wno-deprecated-copy"
)
endif()

project (custom-opm-common)

find_package(Boost)

include_directories(
opm-common
opm-common/external/cjson
generated-opm-common
generated-opm-common/include
)
# Set defines to include required files for ResInsight. Make sure that these
# defines are set before including the opm-common CMakeLists
set(ENABLE_ECL_INPUT true)
set(ENABLE_ECL_OUTPUT true)
set(BUILD_TESTING false)
set(ENABLE_MOCKSIM false)
set(OPM_ENABLE_PYTHON false)
set(OPM_INSTALL_PYTHON false)
set(OPM_ENABLE_EMBEDDED_PYTHON false)
set(OPM_ENABLE_DUNE false)
set(BUILD_EXAMPLES false)

if(CREATE_OPM_COMMON_KEYWORDS)
# In ResInsight, we need a subset of the files in opm-common. We also need to
# generate the keywords. The flag CREATE_OPM_COMMON_KEYWORDS is set in the
# main CMakeLists.txt file. When this flag is set, the opm-common is added to
# the solution. Build a test target to trigger the c++ code generation using
# the tool genkw, use CarfinTest.exe Copy files generated code from
# build/ThirdParty/custom-opm-common/opm-common: copy ParserInit.cpp and
# config.h to source folder ThirdParty/custom-opm-common/generated-opm-common/
# copy the folders "ParserKeywords" and "include" to source folder
# ThirdParty/custom-opm-common/generated-opm-common/
add_subdirectory(opm-common)
message(
STATUS
"opm-common is added to the solution used to create keywords from JSON files"
)

else(CREATE_OPM_COMMON_KEYWORDS)

project(custom-opm-common)

find_package(Boost)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/opm-common/cmake/Modules)

if(NOT cjson_FOUND)
include(DownloadCjson)
endif()

add_definitions(-DFMT_HEADER_ONLY)
include_directories(SYSTEM ../fmtlib/include)
include_directories(${cjson_SOURCE_DIR})
list(APPEND opm-common_SOURCES ${cjson_SOURCE_DIR}/cJSON.c)

# Set defines to include requred files
set(ENABLE_ECL_INPUT true)
#set(ENABLE_ECL_OUTPUT true)
include_directories(
opm-common generated-opm-common generated-opm-common/include
)

add_definitions(-DFMT_HEADER_ONLY)
include_directories(SYSTEM ../fmtlib/include)

include(opm-common/CMakeLists_files.cmake)
include(opm-common/CMakeLists_files.cmake)

set(opm_parser_source_files_short_path
${MAIN_SOURCE_FILES}
)
set(opm_parser_source_files_short_path ${MAIN_SOURCE_FILES})

foreach (file ${opm_parser_source_files_short_path} )
list(APPEND opm_parser_source_files_long_path "opm-common/${file}" )
endforeach()
foreach(file ${opm_parser_source_files_short_path})
list(APPEND opm_parser_source_files_long_path "opm-common/${file}")
endforeach()

set(opm_parser_source_files
${opm_parser_source_files_long_path}
${opm_parser_generated_source_files}
)
set(opm_parser_source_files ${opm_parser_source_files_long_path}
${opm_parser_generated_source_files}
)

# Append generated sources
list(INSERT opm-common_SOURCES 0 generated-opm-common/ParserInit.cpp)
foreach (name A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
list(INSERT opm-common_SOURCES 0 generated-opm-common/ParserKeywords/${name}.cpp)
endforeach()
# Add generated files These files are generated by the parser generator genkw
file(GLOB ALL_FILES_IN_FOLDER generated-opm-common/ParserKeywords/*.cpp)
list(APPEND opm-common_SOURCES ${ALL_FILES_IN_FOLDER})
list(APPEND opm-common_SOURCES generated-opm-common/ParserInit.cpp)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
list(APPEND ADDITIONAL_LINK_LIBRARIES stdc++fs)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
list(APPEND ADDITIONAL_LINK_LIBRARIES stdc++fs)
endif()
endif()
endif()

if(MSVC)
list(APPEND opm-common_SOURCES opm-common/cross-platform/windows/Substitutes.cpp )
endif(MSVC)
add_library(
${PROJECT_NAME} STATIC ${opm_parser_source_files_long_path}
${opm-common_SOURCES}
)

add_library(${PROJECT_NAME}
STATIC
${opm_parser_source_files_long_path}
${opm-common_SOURCES}

## Missing files when only ENABLE_ECL_INPUT is defined
opm-common/src/opm/io/eclipse/EclFile.cpp
opm-common/src/opm/io/eclipse/EclOutput.cpp
opm-common/src/opm/io/eclipse/EclUtil.cpp
opm-common/src/opm/io/eclipse/EGrid.cpp
opm-common/src/opm/io/eclipse/ESmry.cpp
opm-common/src/opm/io/eclipse/ExtESmry.cpp
opm-common/src/opm/io/eclipse/EInit.cpp
opm-common/src/opm/io/eclipse/ERft.cpp

# Required for use of static function RstConnection::inverse_peaceman
opm-common/src/opm/io/eclipse/rst/connection.cpp

# Required for use of RstHeader::restart_info
opm-common/src/opm/io/eclipse/rst/action.cpp
opm-common/src/opm/io/eclipse/rst/aquifer.cpp
opm-common/src/opm/io/eclipse/rst/connection.cpp
opm-common/src/opm/io/eclipse/rst/group.cpp
opm-common/src/opm/io/eclipse/rst/header.cpp
opm-common/src/opm/io/eclipse/rst/network.cpp
opm-common/src/opm/io/eclipse/rst/segment.cpp
opm-common/src/opm/io/eclipse/rst/state.cpp
opm-common/src/opm/io/eclipse/rst/udq.cpp
opm-common/src/opm/io/eclipse/rst/well.cpp
opm-common/src/opm/output/eclipse/InteHEAD.cpp
opm-common/src/opm/output/eclipse/UDQDims.cpp
opm-common/src/opm/output/eclipse/CreateActionRSTDims.cpp

# 2022.06 additional includes
opm-common/src/opm/io/eclipse/ERst.cpp
opm-common/src/opm/io/eclipse/RestartFileView.cpp
opm-common/cross-platform/windows/Substitutes.cpp

)

if(RESINSIGHT_ENABLE_UNITY_BUILD)

set(UNITY_EXCLUDE_FILES
opm-common/src/opm/parser/eclipse/Deck/UDAValue.cpp
opm-common/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp
opm-common/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp
opm-common/src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp
opm-common/src/opm/parser/eclipse/EclipseState/Schedule/MSW/SpiralICD.cpp
opm-common/src/opm/io/eclipse/EclOutput.cpp
opm-common/src/opm/io/eclipse/ESmry.cpp
opm-common/src/opm/io/eclipse/EGrid.cpp
)

foreach(fileToExclude ${UNITY_EXCLUDE_FILES})
set_source_files_properties(${fileToExclude}
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
endforeach(fileToExclude)
endif()
find_path(BOOST_SPIRIT_INCLUDE_DIRS "boost/spirit.hpp"
HINTS ${Boost_INCLUDE_DIRS}
)

find_path(BOOST_SPIRIT_INCLUDE_DIRS "boost/spirit.hpp" HINTS ${Boost_INCLUDE_DIRS})
target_link_libraries(custom-opm-common ${ADDITIONAL_LINK_LIBRARIES})

target_link_libraries(custom-opm-common
${ADDITIONAL_LINK_LIBRARIES}
)
target_include_directories(
custom-opm-common
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/opm-common
${CMAKE_CURRENT_SOURCE_DIR}/generated-opm-common/include
PRIVATE ${BOOST_SPIRIT_INCLUDE_DIRS}
)

target_include_directories(custom-opm-common
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/opm-common
${CMAKE_CURRENT_SOURCE_DIR}/generated-opm-common/include
PRIVATE
${BOOST_SPIRIT_INCLUDE_DIRS}

)
endif(CREATE_OPM_COMMON_KEYWORDS)
Loading

0 comments on commit 3f08901

Please sign in to comment.