Skip to content
Snippets Groups Projects
Commit fb06788d authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

replace ThirdParty/Core/Faddeeva by external Cerf

this requires some ad-hoc code to work with both the C and the CPP
version of libcerf.
parent 51819887
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ project(BornAgain ...@@ -20,6 +20,7 @@ project(BornAgain
) # LANGUAGES CXX) ) # LANGUAGES CXX)
# TODO modernize FindCerf to get rid of AssertLibraryFunction to restore restriction to CXX # TODO modernize FindCerf to get rid of AssertLibraryFunction to restore restriction to CXX
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
include(CTest) # equivalent to "enable_testing() ??? include(CTest) # equivalent to "enable_testing() ???
......
...@@ -12,7 +12,11 @@ readability-*,-readability-braces-around-statements,modernize-*") ...@@ -12,7 +12,11 @@ readability-*,-readability-braces-around-statements,modernize-*")
endif() endif()
# --- source and include files --------- # --- source and include files ---------
file(GLOB source_files "*/*.cpp") file(GLOB source_files "*/*.cpp" )
if(NOT Cerf_IS_CPP)
file(GLOB s2 "*/*.c" )
list(APPEND source_files ${s2})
endif()
file(GLOB include_files "*/*.h") file(GLOB include_files "*/*.h")
if(BORNAGAIN_PYTHON) if(BORNAGAIN_PYTHON)
...@@ -117,6 +121,9 @@ endif() ...@@ -117,6 +121,9 @@ endif()
# --- making library --------- # --- making library ---------
if(${Cerf_IS_CPP})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERF_AS_CPP=ON")
endif()
add_library(${library_name} SHARED ${source_files}) add_library(${library_name} SHARED ${source_files})
set_target_properties(${library_name} PROPERTIES PREFIX ${libprefix} SUFFIX ${libsuffix}) set_target_properties(${library_name} PROPERTIES PREFIX ${libprefix} SUFFIX ${libsuffix})
...@@ -146,9 +153,9 @@ target_include_directories(${library_name} ...@@ -146,9 +153,9 @@ target_include_directories(${library_name}
PUBLIC ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${FFTW3_INCLUDE_DIR} ${GSL_INCLUDE_DIR} PUBLIC ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${FFTW3_INCLUDE_DIR} ${GSL_INCLUDE_DIR}
${tspectrum_INCLUDE_DIR} ${tspectrum_INCLUDE_DIR}
SYSTEM PUBLIC ${EIGEN3_INCLUDE_DIR} SYSTEM PUBLIC ${EIGEN3_INCLUDE_DIR}
PRIVATE ${Faddeeva_INCLUDE_DIR}) PRIVATE ${Cerf_INCLUDE_DIR})
target_link_libraries(${library_name} ${Boost_LIBRARIES} ${FFTW3_LIBRARIES} ${GSL_LIBRARIES} target_link_libraries(${library_name} ${Boost_LIBRARIES} ${FFTW3_LIBRARIES} ${GSL_LIBRARIES}
${Faddeeva_LIBRARY} ${tspectrum_LIBRARY}) ${tspectrum_LIBRARY} ${Cerf_LIBRARIES})
if(BORNAGAIN_MPI) if(BORNAGAIN_MPI)
add_definitions(-DBORNAGAIN_MPI) add_definitions(-DBORNAGAIN_MPI)
......
...@@ -23,7 +23,20 @@ ...@@ -23,7 +23,20 @@
#include "Core/Multilayer/LayerRoughness.h" #include "Core/Multilayer/LayerRoughness.h"
#include "Core/Multilayer/MultiLayer.h" #include "Core/Multilayer/MultiLayer.h"
#include "Core/SimulationElement/SimulationElement.h" #include "Core/SimulationElement/SimulationElement.h"
#include "Faddeeva.hh"
#ifdef CERF_AS_CPP
#include <cerf.h>
#else
#include "cerfwrap.h"
std::complex<double> cerfcx(std::complex<double> z) {
const double zx = z.real();
const double zy = z.imag();
double vx;
double vy;
wrap_cerfcx(zx, zy, &vx, &vy);
return {vx, vy};
}
#endif
// Diffuse scattering from rough interfaces is modelled after // Diffuse scattering from rough interfaces is modelled after
// Phys. Rev. B, vol. 51 (4), p. 2311 (1995) // Phys. Rev. B, vol. 51 (4), p. 2311 (1995)
...@@ -32,11 +45,11 @@ namespace ...@@ -32,11 +45,11 @@ namespace
{ {
complex_t h_plus(complex_t z) complex_t h_plus(complex_t z)
{ {
return 0.5 * Faddeeva::erfcx(-mul_I(z) / std::sqrt(2.0)); return 0.5 * cerfcx(-mul_I(z) / std::sqrt(2.0));
} }
complex_t h_min(complex_t z) complex_t h_min(complex_t z)
{ {
return 0.5 * Faddeeva::erfcx(mul_I(z) / std::sqrt(2.0)); return 0.5 * cerfcx(mul_I(z) / std::sqrt(2.0));
} }
} // namespace } // namespace
......
#include "cerfwrap.h"
#include <cerf.h>
# if !defined(CMPLX) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7\
)) && !(defined(__ICC) || defined(__INTEL_COMPILER))
# define CMPLX(a,b) __builtin_complex((double) (a), (double) (b))
# endif
# ifdef CMPLX // C11
# define C(a,b) CMPLX(a,b)
# else
# define C(a,b) ((a) + I*(b))
# endif
void wrap_cerfcx(double zx, double zy, double* vx, double* vy)
{
const double _Complex arg = C(zx,zy);
const double _Complex val = cerfcx(arg);
*vx = creal(val);
*vy = cimag(val);
}
#ifdef __cplusplus
extern "C" {
#endif
void wrap_cerfcx(double zx, double zy, double* vx, double* vy);
#ifdef __cplusplus
}
#endif
add_subdirectory(Faddeeva)
add_subdirectory(tspectrum) add_subdirectory(tspectrum)
############################################################################
# CMakeLists.txt file for building libFaddeeva package
############################################################################
set(library_name Faddeeva)
# --- source and include files ---------
set(include_dirs
${CMAKE_CURRENT_SOURCE_DIR}
)
include_directories(${include_dirs})
file(GLOB source_files "*.cc")
file(GLOB include_files "*.hh")
# --- making library ------------
add_library(
${library_name}
STATIC
${source_files} ${include_files}
)
set(${library_name}_INCLUDE_DIR ${include_dirs} CACHE INTERNAL "")
set(${library_name}_LIBRARY ${library_name} CACHE INTERNAL "")
This diff is collapsed.
/* Copyright (c) 2012 Massachusetts Institute of Technology
*
* 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 AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Available at: http://ab-initio.mit.edu/Faddeeva
Header file for Faddeeva.cc; see that file for more information. */
#ifndef FADDEEVA_HH
#define FADDEEVA_HH 1
#include <complex>
namespace Faddeeva {
// compute w(z) = exp(-z^2) erfc(-iz) [ Faddeeva / scaled complex error func ]
extern std::complex<double> w(std::complex<double> z,double relerr=0);
extern double w_im(double x); // special-case code for Im[w(x)] of real x
// Various functions that we can compute with the help of w(z)
// compute erfcx(z) = exp(z^2) erfc(z)
extern std::complex<double> erfcx(std::complex<double> z, double relerr=0);
extern double erfcx(double x); // special case for real x
// compute erf(z), the error function of complex arguments
extern std::complex<double> erf(std::complex<double> z, double relerr=0);
extern double erf(double x); // special case for real x
// compute erfi(z) = -i erf(iz), the imaginary error function
extern std::complex<double> erfi(std::complex<double> z, double relerr=0);
extern double erfi(double x); // special case for real x
// compute erfc(z) = 1 - erf(z), the complementary error function
extern std::complex<double> erfc(std::complex<double> z, double relerr=0);
extern double erfc(double x); // special case for real x
// compute Dawson(z) = sqrt(pi)/2 * exp(-z^2) * erfi(z)
extern std::complex<double> Dawson(std::complex<double> z, double relerr=0);
extern double Dawson(double x); // special case for real x
} // namespace Faddeeva
#endif // FADDEEVA_HH
...@@ -21,7 +21,11 @@ find_library(Cerf_LIBRARIES NAMES cerf) ...@@ -21,7 +21,11 @@ find_library(Cerf_LIBRARIES NAMES cerf)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Cerf DEFAULT_MSG Cerf_LIBRARIES Cerf_INCLUDE_DIR) find_package_handle_standard_args(Cerf DEFAULT_MSG Cerf_LIBRARIES Cerf_INCLUDE_DIR)
if(NOT Cerf_FOUND) if(Cerf_FOUND)
message(STATUS "Found libcerf, version ${Cerf_VERSION}, lib=${Cerf_LIBRARIES},\
include_dir=${Cerf_INCLUDE_DIR}.")
set(Cerf_IS_CPP OFF)
else()
unset(Cerf_FOUND) unset(Cerf_FOUND)
unset(Cerf_LIBRARIES) unset(Cerf_LIBRARIES)
find_library(Cerf_LIBRARIES NAMES cerfcpp) find_library(Cerf_LIBRARIES NAMES cerfcpp)
...@@ -35,11 +39,9 @@ if(NOT Cerf_FOUND) ...@@ -35,11 +39,9 @@ if(NOT Cerf_FOUND)
message(STATUS "Found neither libcerf nor libcerfcpp") message(STATUS "Found neither libcerf nor libcerfcpp")
return() return()
endif() endif()
message(STATUS "Found libcerfcpp") message(STATUS "Found libcerfcpp, version ${Cerf_VERSION}, lib=${Cerf_LIBRARIES},\
include_dir=${Cerf_INCLUDE_DIR}.")
set(Cerf_IS_CPP ON) set(Cerf_IS_CPP ON)
else()
message(STATUS "Found libcerf")
set(Cerf_IS_CPP OFF)
endif() endif()
mark_as_advanced(Cerf_INCLUDE_DIR Cerf_LIBRARIES) mark_as_advanced(Cerf_INCLUDE_DIR Cerf_LIBRARIES)
......
...@@ -5,7 +5,7 @@ find_package(FFTW3 REQUIRED) ...@@ -5,7 +5,7 @@ find_package(FFTW3 REQUIRED)
find_package(GSL REQUIRED) find_package(GSL REQUIRED)
find_package(Cerf REQUIRED) find_package(Cerf REQUIRED)
message(STATUS "Cerf found=${Cerf_FOUND} lib=${Cerf_LIBRARIES} inc=${Cerf_INCLUDE_DIR} version={Cerf_VERSION}")
# --- Eigen3 is a git submodule; throw an error if submodule is not initialized --- # --- Eigen3 is a git submodule; throw an error if submodule is not initialized ---
set(EIGEN3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/ThirdParty/Core/eigen3" CACHE INTERNAL "") set(EIGEN3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/ThirdParty/Core/eigen3" CACHE INTERNAL "")
if( NOT EXISTS "${EIGEN3_INCLUDE_DIR}/.git" ) if( NOT EXISTS "${EIGEN3_INCLUDE_DIR}/.git" )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment