Merge pull request #3435 from akva2/sync_find_quadmath
sync FindQuadMath with dune
This commit is contained in:
commit
ff2e8c8333
@ -151,6 +151,15 @@ macro (sources_hook)
|
||||
endif()
|
||||
set_source_files_properties(src/opm/input/eclipse/Python/Python.cpp
|
||||
PROPERTIES COMPILE_FLAGS -Wno-shadow)
|
||||
if(QuadMath_FOUND)
|
||||
get_target_property(qm_defs QuadMath::QuadMath INTERFACE_COMPILE_DEFINITIONS)
|
||||
get_target_property(qm_options QuadMath::QuadMath INTERFACE_COMPILE_OPTIONS)
|
||||
set_source_files_properties(src/opm/material/components/CO2.cpp
|
||||
src/opm/material/densead/Evaluation.cpp
|
||||
PROPERTIES COMPILE_DEFINITIONS "${qm_defs}"
|
||||
COMPILE_OPTIONS "${qm_options}")
|
||||
endif()
|
||||
|
||||
endmacro (sources_hook)
|
||||
|
||||
macro (fortran_hook)
|
||||
|
49
cmake/Modules/FindQuadMath.cmake
Normal file
49
cmake/Modules/FindQuadMath.cmake
Normal file
@ -0,0 +1,49 @@
|
||||
# Module that checks whether the compiler supports the
|
||||
# quadruple precision floating point math
|
||||
#
|
||||
# Adds target QuadMath::QuadMath if found
|
||||
#
|
||||
# perform tests
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(CMakePushCheckState)
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES quadmath)
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
||||
set(CMAKE_REQUIRED_FLAGS "-fext-numeric-literals")
|
||||
endif()
|
||||
check_cxx_source_compiles("
|
||||
#include <quadmath.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
__float128 r = 1.0q;
|
||||
r = strtoflt128(\"1.2345678\", NULL);
|
||||
return 0;
|
||||
}" QuadMath_COMPILES)
|
||||
cmake_pop_check_state() # Reset CMAKE_REQUIRED_XXX variables
|
||||
|
||||
if(QuadMath_COMPILES)
|
||||
# Use additional variable for better report message
|
||||
set(QuadMath_VAR "(Supported by compiler)")
|
||||
endif()
|
||||
|
||||
# Report that package was found
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(QuadMath
|
||||
DEFAULT_MSG
|
||||
QuadMath_VAR QuadMath_COMPILES
|
||||
)
|
||||
|
||||
# add imported target for quadmath
|
||||
if(QuadMath_FOUND AND NOT TARGET QuadMath::QuadMath)
|
||||
# Compiler supports QuadMath: Add appropriate linker flag
|
||||
add_library(QuadMath::QuadMath INTERFACE IMPORTED)
|
||||
target_link_libraries(QuadMath::QuadMath INTERFACE quadmath)
|
||||
|
||||
target_compile_definitions(QuadMath::QuadMath INTERFACE
|
||||
_GLIBCXX_USE_FLOAT128 HAVE_QUAD=1
|
||||
)
|
||||
target_compile_options(QuadMath::QuadMath INTERFACE
|
||||
$<$<CXX_COMPILER_ID:GNU>:-fext-numeric-literals>
|
||||
)
|
||||
endif()
|
@ -1,55 +0,0 @@
|
||||
# Module that checks whether the compiler supports the
|
||||
# quadruple precision floating point math
|
||||
#
|
||||
# Sets the following variables:
|
||||
# HAVE_QUAD
|
||||
# QUADMATH_LIBRARIES
|
||||
#
|
||||
# perform tests
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(CMakePushCheckState)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
if(NOT DEFINED USE_QUADMATH OR USE_QUADMATH)
|
||||
if(NOT DEFINED HAVE_EXTENDED_NUMERIC_LITERALS)
|
||||
check_cxx_compiler_flag("-Werror -fext-numeric-literals" HAVE_EXTENDED_NUMERIC_LITERALS)
|
||||
endif()
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
list(APPEND CMAKE_REQUIRED_LIBRARIES "quadmath")
|
||||
CHECK_CXX_SOURCE_COMPILES("
|
||||
#include <quadmath.h>
|
||||
|
||||
int main(void){
|
||||
__float128 foo = sqrtq(123.456);
|
||||
foo = FLT128_MIN;
|
||||
}" QUADMATH_FOUND)
|
||||
cmake_pop_check_state()
|
||||
|
||||
if (QUADMATH_FOUND)
|
||||
set(QUADMATH_LIBRARIES "quadmath")
|
||||
set(HAVE_QUAD "${QUADMATH_FOUND}")
|
||||
if (NOT TARGET QuadMath::QuadMath)
|
||||
add_library(QuadMath::QuadMath INTERFACE IMPORTED)
|
||||
set_target_properties(QuadMath::QuadMath PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES quadmath
|
||||
INTERFACE_COMPILE_DEFINITIONS _GLIBCXX_USE_FLOAT128)
|
||||
if(HAVE_EXTENDED_NUMERIC_LITERALS)
|
||||
set_target_properties(QuadMath::QuadMath PROPERTIES
|
||||
INTERFACE_COMPILE_OPTIONS $<$<CXX_COMPILER_ID:GNU>:-fext-numeric-literals>)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (USE_QUADMATH AND NOT QUADMATH_FOUND)
|
||||
message(STATUS "Quadruple precision math support is unavailable! Skipping it.")
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Quadmath
|
||||
DEFAULT_MSG
|
||||
QUADMATH_LIBRARIES
|
||||
HAVE_QUAD
|
||||
)
|
@ -25,7 +25,7 @@ find_opm_package (
|
||||
ZLIB;
|
||||
ZOLTAN;
|
||||
METIS;
|
||||
Quadmath
|
||||
QuadMath
|
||||
"
|
||||
# header to search for
|
||||
"dune/fem/space/shapefunctionset/legendre.hh"
|
||||
|
@ -142,13 +142,6 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# quadmath must be explicitly enabled
|
||||
# This needs to be in OpmInit as prereqs is called before OpmLibMain is included.
|
||||
option (USE_QUADMATH "Search for high precision floating point library (normally not used)" ON)
|
||||
if (NOT USE_QUADMATH)
|
||||
set (CMAKE_DISABLE_FIND_PACKAGE_QuadMath TRUE)
|
||||
endif ()
|
||||
|
||||
option (USE_SUPERLU "Use SuperLU direct solvers for AMG (if umfpack is not found)" ON)
|
||||
if (NOT USE_SUPERLU)
|
||||
set (CMAKE_DISABLE_FIND_PACKAGE_SuperLU TRUE)
|
||||
|
@ -28,5 +28,6 @@ list(APPEND opm-common_DEPS
|
||||
# cannot format UDQVarType. Hence we use the same version
|
||||
# as the embedded one.
|
||||
"fmt 7.0.3"
|
||||
"QuadMath"
|
||||
)
|
||||
find_package_deps(opm-common)
|
||||
|
@ -981,13 +981,24 @@ private:
|
||||
const Evaluation& temperature,
|
||||
const Evaluation& pressure)
|
||||
{
|
||||
auto tostring = [](const auto& val) -> std::string
|
||||
auto cast = [](const auto d)
|
||||
{
|
||||
if constexpr (DenseAd::is_evaluation<Evaluation>::value)
|
||||
return std::to_string(getValue(val.value()));
|
||||
#if HAVE_QUAD
|
||||
if constexpr (std::is_same_v<decltype(d), const quad>)
|
||||
return static_cast<double>(d);
|
||||
else
|
||||
return std::to_string(getValue(val));
|
||||
#endif
|
||||
return d;
|
||||
};
|
||||
auto tostring = [cast](const auto& val) -> std::string
|
||||
{
|
||||
if constexpr (DenseAd::is_evaluation<Evaluation>::value) {
|
||||
return std::to_string(cast(getValue(val.value())));
|
||||
}
|
||||
else
|
||||
return std::to_string(cast(getValue(val)));
|
||||
};
|
||||
|
||||
return type + " is only implemented for temperatures "
|
||||
"below 623.15K and pressures below 100MPa. (T = " +
|
||||
tostring(temperature) + ", p=" + tostring(pressure);
|
||||
|
@ -166,17 +166,27 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
auto cast = [](const auto d)
|
||||
{
|
||||
#if HAVE_QUAD
|
||||
if constexpr (std::is_same_v<decltype(d), const quad>)
|
||||
return static_cast<double>(d);
|
||||
else
|
||||
#endif
|
||||
return d;
|
||||
};
|
||||
|
||||
std::string msg =
|
||||
std::string("Calculating the ")
|
||||
+ FluidSystem::phaseName(phaseIdx)
|
||||
+ "Phase composition failed. Initial {x} = {";
|
||||
for (const auto& v : xInit)
|
||||
msg += " " + std::to_string(getValue(v));
|
||||
msg += " " + std::to_string(cast(getValue(v)));
|
||||
msg += " }, {fug_t} = {";
|
||||
for (const auto& v : targetFug)
|
||||
msg += " " + std::to_string(getValue(v));
|
||||
msg += " }, p = " + std::to_string(getValue(fluidState.pressure(phaseIdx)))
|
||||
+ ", T = " + std::to_string(getValue(fluidState.temperature(phaseIdx)));
|
||||
msg += " " + std::to_string(cast(getValue(v)));
|
||||
msg += " }, p = " + std::to_string(cast(getValue(fluidState.pressure(phaseIdx))))
|
||||
+ ", T = " + std::to_string(cast(getValue(fluidState.temperature(phaseIdx))));
|
||||
throw NumericalProblem(msg);
|
||||
}
|
||||
|
||||
|
@ -232,12 +232,22 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
auto cast = [](const auto d)
|
||||
{
|
||||
#if HAVE_QUAD
|
||||
if constexpr (std::is_same_v<decltype(d), const quad>)
|
||||
return static_cast<double>(d);
|
||||
else
|
||||
#endif
|
||||
return d;
|
||||
};
|
||||
|
||||
std::string msg = "NcpFlash solver failed: "
|
||||
"{c_alpha^kappa} = {";
|
||||
for (const auto& v : globalMolarities)
|
||||
msg += " " + std::to_string(getValue(v));
|
||||
msg += " " + std::to_string(cast(getValue(v)));
|
||||
msg += " }, T = ";
|
||||
msg += std::to_string(getValue(fluidState.temperature(/*phaseIdx=*/0)));
|
||||
msg += std::to_string(cast(getValue(fluidState.temperature(/*phaseIdx=*/0))));
|
||||
throw NumericalProblem(msg);
|
||||
}
|
||||
|
||||
|
@ -490,12 +490,22 @@ private:
|
||||
Valgrind::CheckDefined(xlH2O);
|
||||
Valgrind::CheckDefined(xlCO2);
|
||||
|
||||
auto tostring = [](const auto& val) -> std::string
|
||||
auto cast = [](const auto d)
|
||||
{
|
||||
#if HAVE_QUAD
|
||||
if constexpr (std::is_same_v<decltype(d), const quad>)
|
||||
return static_cast<double>(d);
|
||||
else
|
||||
#endif
|
||||
return d;
|
||||
};
|
||||
|
||||
auto tostring = [cast](const auto& val) -> std::string
|
||||
{
|
||||
if constexpr (DenseAd::is_evaluation<LhsEval>::value) {
|
||||
return std::to_string(getValue(val.value()));
|
||||
return std::to_string(cast(getValue(val.value())));
|
||||
} else {
|
||||
return std::to_string(val);
|
||||
return std::to_string(cast(val));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <opm/material/components/CO2.hpp>
|
||||
#if HAVE_QUAD
|
||||
#include <opm/material/common/quad.hpp>
|
||||
#endif
|
||||
|
||||
#include "co2tables.inc"
|
||||
|
||||
@ -36,6 +39,7 @@ const UniformTabulated2DFunction<double>&
|
||||
CO2<double>::tabulatedDensity = CO2Tables::tabulatedDensity;
|
||||
template<>
|
||||
const double CO2<double>::brineSalinity = CO2Tables::brineSalinity;
|
||||
|
||||
template<>
|
||||
const UniformTabulated2DFunction<double>&
|
||||
CO2<float>::tabulatedEnthalpy = CO2Tables::tabulatedEnthalpy;
|
||||
@ -45,4 +49,15 @@ CO2<float>::tabulatedDensity = CO2Tables::tabulatedDensity;
|
||||
template<>
|
||||
const float CO2<float>::brineSalinity = CO2Tables::brineSalinity;
|
||||
|
||||
#if HAVE_QUAD
|
||||
template<>
|
||||
const UniformTabulated2DFunction<double>&
|
||||
CO2<quad>::tabulatedEnthalpy = CO2Tables::tabulatedEnthalpy;
|
||||
template<>
|
||||
const UniformTabulated2DFunction<double>&
|
||||
CO2<quad>::tabulatedDensity = CO2Tables::tabulatedDensity;
|
||||
template<>
|
||||
const quad CO2<quad>::brineSalinity = CO2Tables::brineSalinity;
|
||||
#endif
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -24,6 +24,10 @@
|
||||
#include <config.h>
|
||||
#include <opm/material/densead/Evaluation.hpp>
|
||||
|
||||
#if HAVE_QUAD
|
||||
#include <opm/material/common/quad.hpp>
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace Opm {
|
||||
@ -52,13 +56,27 @@ void printEvaluation(std::ostream& os,
|
||||
const Evaluation<T,size1,size2>&, \
|
||||
bool);
|
||||
|
||||
#if HAVE_QUAD
|
||||
#define INSTANCE(size) \
|
||||
INSTANCE_IMPL(double,size,0u) \
|
||||
INSTANCE_IMPL(quad,size,0u) \
|
||||
INSTANCE_IMPL(float,size,0u)
|
||||
#else
|
||||
#define INSTANCE(size) \
|
||||
INSTANCE_IMPL(double,size,0u) \
|
||||
INSTANCE_IMPL(float,size,0u)
|
||||
#endif
|
||||
|
||||
#if HAVE_QUAD
|
||||
#define INSTANCE_DYN(size) \
|
||||
INSTANCE_IMPL(double,-1,size) \
|
||||
INSTANCE_IMPL(quad,-1,size) \
|
||||
INSTANCE_IMPL(float,-1,size)
|
||||
#else
|
||||
#define INSTANCE_DYN(size) \
|
||||
INSTANCE_IMPL(double,-1,size) \
|
||||
INSTANCE_IMPL(float,-1,size)
|
||||
#endif
|
||||
|
||||
INSTANCE(1)
|
||||
INSTANCE(2)
|
||||
|
Loading…
Reference in New Issue
Block a user