mirror of
https://github.com/cosmo-sims/monofonIC.git
synced 2024-09-19 17:03:45 +02:00
fixed compilation against public class version, which requires also suppressing a lot of warning messages.
This commit is contained in:
parent
62d3b2946b
commit
f9ec42379f
6 changed files with 467 additions and 48 deletions
|
@ -15,21 +15,32 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(PRGNAME monofonIC)
|
||||
project(monofonIC C CXX)
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -Wall -fno-omit-frame-pointer -g -fsanitize=address")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wall -pedantic" CACHE STRING "Flags used by the compiler during Release builds." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native -fno-omit-frame-pointer -Wall -pedantic" CACHE STRING "Flags used by the compiler during RelWithDebInfo builds." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -march=native -DDEBUG -fno-omit-frame-pointer -Wall -pedantic" CACHE STRING "Flags used by the compiler during Debug builds." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_DEBUGSANADD "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address " CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for address." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_DEBUGSANUNDEF "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for undefineds." FORCE)
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Flags used by the compiler during Release builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" CACHE STRING "Flags used by the compiler during RelWithDebInfo builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during Debug builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_DEBUGSANADD "${CMAKE_CXX_FLAGS_DEBUGSANADD}" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for address." FORCE)
|
||||
set(CMAKE_C_FLAGS_DEBUGSANUNDEF "${CMAKE_CXX_FLAGS_DEBUGSANUNDEF}" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for undefineds." FORCE)
|
||||
add_compile_options(
|
||||
$<$<CONFIG:RELEASE>:-Ofast>
|
||||
$<$<CONFIG:RELWITHDEBINFO>:-Ofast>
|
||||
$<$<CONFIG:RELWITHDEBINFO>:-fno-omit-frame-pointer>
|
||||
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
||||
$<$<CONFIG:DEBUG>:-O1>
|
||||
$<$<CONFIG:DEBUG>:-g>
|
||||
$<$<CONFIG:DEBUG>:-DDEBUG>
|
||||
)
|
||||
|
||||
|
||||
##set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -Wall -fno-omit-frame-pointer -g -fsanitize=address")
|
||||
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native -Wall -pedantic" CACHE STRING "Flags used by the compiler during Release builds." FORCE)
|
||||
#set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native -fno-omit-frame-pointer -Wall -pedantic" CACHE STRING "Flags used by the compiler during #RelWithDebInfo builds." FORCE)
|
||||
#set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -march=native -DDEBUG -fno-omit-frame-pointer -Wall -pedantic" CACHE STRING "Flags used by the compiler during Debug builds." FORCE)
|
||||
#set(CMAKE_CXX_FLAGS_DEBUGSANADD "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address " CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for address." FORCE)
|
||||
#set(CMAKE_CXX_FLAGS_DEBUGSANUNDEF "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for undefineds." #FORCE)
|
||||
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Flags used by the compiler during Release builds." FORCE)
|
||||
#set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" CACHE STRING "Flags used by the compiler during RelWithDebInfo builds." FORCE)
|
||||
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during Debug builds." FORCE)
|
||||
#set(CMAKE_C_FLAGS_DEBUGSANADD "${CMAKE_CXX_FLAGS_DEBUGSANADD}" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for address." FORCE)
|
||||
#set(CMAKE_C_FLAGS_DEBUGSANUNDEF "${CMAKE_CXX_FLAGS_DEBUGSANUNDEF}" CACHE STRING "Flags used by the compiler during Debug builds with Sanitizer for undefineds." FORCE)
|
||||
|
||||
set(default_build_type "RelWithDebInfo")
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
|
@ -44,7 +55,6 @@ mark_as_advanced(CMAKE_CXX_FLAGS_DEBUGSANADD CMAKE_CXX_FLAGS_DEBUGSANUNDEF)
|
|||
mark_as_advanced(CMAKE_C_FLAGS_DEBUGSANADD CMAKE_C_FLAGS_DEBUGSANUNDEF)
|
||||
mark_as_advanced(CMAKE_EXECUTABLE_FORMAT CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
||||
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}")
|
||||
|
||||
|
@ -217,6 +227,9 @@ add_executable(${PRGNAME} ${SOURCES} ${PLUGINS})
|
|||
|
||||
set_target_properties(${PRGNAME} PROPERTIES CXX_STANDARD 14)
|
||||
|
||||
# Enable pedantic warnings for C++ files but not C files
|
||||
target_compile_options(${PRGNAME} PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-pedantic>)
|
||||
|
||||
########################################################################################################################
|
||||
# mpi flags and precision set up
|
||||
if(MPI_CXX_FOUND)
|
||||
|
@ -293,10 +306,10 @@ target_link_libraries(${PRGNAME} PRIVATE GSL::gsl)
|
|||
########################################################################################################################
|
||||
# include CLASS
|
||||
option(ENABLE_CLASS "Enable CLASS support (as a submodule)." ON)
|
||||
|
||||
|
||||
if(ENABLE_CLASS)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/external/class.cmake)
|
||||
target_link_libraries(${PRGNAME} PRIVATE class::libclass_cpp)
|
||||
target_link_libraries(${PRGNAME} PRIVATE class::libclass)
|
||||
target_compile_definitions(${PRGNAME} PRIVATE "USE_CLASS")
|
||||
endif()
|
||||
|
||||
|
|
85
external/CLASS_CMakeLists.txt
vendored
Normal file
85
external/CLASS_CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
cmake_minimum_required(VERSION 3.11)
|
||||
project(class)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# Options
|
||||
option(ENABLE_TESTS "compile test executables" OFF)
|
||||
|
||||
# OpenMP
|
||||
find_package(OpenMP)
|
||||
|
||||
# Sources
|
||||
file( GLOB TOOLS_SRC
|
||||
${PROJECT_SOURCE_DIR}/tools/*.c
|
||||
)
|
||||
file( GLOB SOURCE_SRC
|
||||
${PROJECT_SOURCE_DIR}/source/*.c
|
||||
)
|
||||
|
||||
set(CPP_SRC
|
||||
${PROJECT_SOURCE_DIR}/tools/arrays.c
|
||||
${PROJECT_SOURCE_DIR}/tools/hyperspherical.c
|
||||
${PROJECT_SOURCE_DIR}/source/perturbations.c
|
||||
${PROJECT_SOURCE_DIR}/source/primordial.c
|
||||
${PROJECT_SOURCE_DIR}/source/transfer.c
|
||||
${PROJECT_SOURCE_DIR}/source/harmonic.c
|
||||
${PROJECT_SOURCE_DIR}/source/lensing.c
|
||||
)
|
||||
|
||||
set(TESTS
|
||||
test_loops
|
||||
test_loops_omp
|
||||
test_spectra
|
||||
test_transfer
|
||||
test_nonlinear
|
||||
test_perturbations
|
||||
test_thermodynamics
|
||||
test_background
|
||||
test_hyperspherical
|
||||
)
|
||||
|
||||
file( GLOB EXTERNAL_SRC
|
||||
${PROJECT_SOURCE_DIR}/external/RecfastCLASS/*.c
|
||||
${PROJECT_SOURCE_DIR}/external/HyRec2020/*.c
|
||||
${PROJECT_SOURCE_DIR}/external/heating/*.c
|
||||
)
|
||||
set(EXTERNAL_INCLUDE
|
||||
${PROJECT_SOURCE_DIR}/external/RecfastCLASS/
|
||||
${PROJECT_SOURCE_DIR}/external/HyRec2020/
|
||||
${PROJECT_SOURCE_DIR}/external/heating/
|
||||
)
|
||||
|
||||
SET_SOURCE_FILES_PROPERTIES(${CPP_SRC} PROPERTIES LANGUAGE CXX )
|
||||
|
||||
## Main library
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
if(THREADS_HAVE_PTHREAD_ARG)
|
||||
target_compile_options(libclass PUBLIC "-pthread")
|
||||
endif()
|
||||
|
||||
if(CMAKE_THREAD_LIBS_INIT)
|
||||
target_link_libraries(libclass "${CMAKE_THREAD_LIBS_INIT}")
|
||||
endif()
|
||||
|
||||
add_library(libclass STATIC ${TOOLS_SRC} ${SOURCE_SRC} ${EXTERNAL_SRC} )
|
||||
add_library(class::libclass ALIAS libclass)
|
||||
|
||||
target_compile_options(libclass PRIVATE -Wno-write-strings -fpermissive -O3 -g)
|
||||
set_property(TARGET libclass PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
target_compile_definitions(libclass PUBLIC "__CLASSDIR__=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
|
||||
target_include_directories(libclass PUBLIC include ${EXTERNAL_INCLUDE})
|
||||
target_link_libraries(libclass PRIVATE m)
|
||||
if(OpenMP_FOUND)
|
||||
target_link_libraries(libclass PRIVATE OpenMP::OpenMP_C)
|
||||
endif()
|
||||
|
||||
if(ENABLE_HYREC)
|
||||
target_compile_definitions(libclass PUBLIC "HYREC")
|
||||
target_include_directories(libclass PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/HyRec2020)
|
||||
target_include_directories(libclass PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/RecFastCLASS)
|
||||
target_include_directories(libclass PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/heating)
|
||||
endif()
|
||||
|
||||
|
8
external/class.cmake
vendored
8
external/class.cmake
vendored
|
@ -1,9 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.11)
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
class
|
||||
GIT_REPOSITORY https://github.com/ohahn/class_public.git
|
||||
GIT_TAG monofonic_v1
|
||||
GIT_REPOSITORY https://github.com/lesgourg/class_public.git
|
||||
GIT_SHALLOW YES
|
||||
GIT_PROGRESS TRUE
|
||||
USES_TERMINAL_DOWNLOAD TRUE # <---- this is needed only for Ninja
|
||||
|
@ -13,5 +13,7 @@ FetchContent_GetProperties(class)
|
|||
if(NOT class_POPULATED)
|
||||
set(FETCHCONTENT_QUIET OFF)
|
||||
FetchContent_Populate(class)
|
||||
#configure_file(external/CLASS_CMakeLists.txt ${class_SOURCE_DIR}/CMakeLists.txt COPYONLY)
|
||||
file(COPY_FILE external/CLASS_CMakeLists.txt ${class_SOURCE_DIR}/CMakeLists.txt )
|
||||
add_subdirectory(${class_SOURCE_DIR} ${class_BINARY_DIR})
|
||||
endif()
|
||||
|
|
|
@ -134,8 +134,8 @@ public:
|
|||
vsprintf(out, str, argptr);
|
||||
va_end(argptr);
|
||||
std::string out_string = std::string(out);
|
||||
out_string.erase(std::remove(out_string.begin(), out_string.end(), '\n'),
|
||||
out_string.end());
|
||||
// out_string.erase(std::remove(out_string.begin(), out_string.end(), '\n'),
|
||||
// out_string.end());
|
||||
(*this) << out_string << std::endl;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include <ClassEngine.hh>
|
||||
|
||||
#include <general.hh>
|
||||
#include <config_file.hh>
|
||||
#include <transfer_function_plugin.hh>
|
||||
|
@ -32,8 +30,34 @@
|
|||
|
||||
#include <math/interpolate.hh>
|
||||
|
||||
// disable warnings that pop up due to CLASS headers non-compliance.
|
||||
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
||||
#include "class.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "transfer_CLASS.hh"
|
||||
|
||||
|
||||
class transfer_CLASS_plugin : public TransferFunction_plugin
|
||||
{
|
||||
protected:
|
||||
// structs containing all the CLASS parameters
|
||||
struct file_content fc_;
|
||||
struct precision pr_;
|
||||
struct background ba_;
|
||||
struct thermodynamics th_; /* for thermodynamics */
|
||||
struct perturbations pt_; /* for source functions */
|
||||
struct transfer tr_; /* for transfer functions */
|
||||
struct primordial pm_; /* for primordial spectra */
|
||||
struct harmonic sp_; /* for output spectra */
|
||||
struct fourier nl_; /* for non-linear spectra */
|
||||
struct lensing le_; /* for lensed spectra */
|
||||
struct distortions sd_; /* for distortions */
|
||||
struct output op_; /* for output files */
|
||||
|
||||
ClassParams pars_;
|
||||
bool class_dofree_;
|
||||
|
||||
private:
|
||||
|
||||
using TransferFunction_plugin::cosmo_params_;
|
||||
|
@ -43,8 +67,8 @@ private:
|
|||
|
||||
double zstart_, ztarget_, astart_, atarget_, kmax_, kmin_, h_, tnorm_;
|
||||
|
||||
ClassParams pars_;
|
||||
std::unique_ptr<ClassEngine> the_ClassEngine_;
|
||||
|
||||
// std::unique_ptr<ClassEngine> the_ClassEngine_;
|
||||
std::ofstream ofs_class_input_;
|
||||
|
||||
template <typename T>
|
||||
|
@ -74,13 +98,14 @@ private:
|
|||
add_class_parameter("Omega_b", cosmo_params_.get("Omega_b"));
|
||||
add_class_parameter("Omega_cdm", cosmo_params_.get("Omega_c"));
|
||||
add_class_parameter("Omega_k", cosmo_params_.get("Omega_k"));
|
||||
add_class_parameter("Omega_fld", 0.0);
|
||||
add_class_parameter("Omega_scf", 0.0);
|
||||
// add_class_parameter("Omega_fld", 0.0);
|
||||
// add_class_parameter("Omega_scf", 0.0);
|
||||
|
||||
|
||||
// add_class_parameter("fluid_equation_of_state","CLP");
|
||||
// add_class_parameter("w0_fld", -1 );
|
||||
// add_class_parameter("wa_fld", 0. );
|
||||
add_class_parameter("Omega_Lambda", 0.0);
|
||||
add_class_parameter("w0_fld", cosmo_params_.get("w_0") );
|
||||
add_class_parameter("wa_fld", cosmo_params_.get("w_a") );
|
||||
// add_class_parameter("cs2_fld", 1);
|
||||
|
||||
//--- massive neutrinos -------------------------------------------
|
||||
|
@ -128,7 +153,7 @@ private:
|
|||
add_class_parameter("k_per_decade_for_pk", 100);
|
||||
add_class_parameter("k_per_decade_for_bao", 100);
|
||||
add_class_parameter("compute damping scale", "yes");
|
||||
add_class_parameter("tol_perturb_integration", 1.e-8);
|
||||
add_class_parameter("tol_perturbations_integration", 1.e-8);
|
||||
add_class_parameter("tol_background_integration", 1e-9);
|
||||
|
||||
// high precision options from cl_permille.pre:
|
||||
|
@ -139,7 +164,6 @@ private:
|
|||
add_class_parameter("transfer_neglect_delta_k_S_t2", 0.17);
|
||||
add_class_parameter("transfer_neglect_delta_k_S_e", 0.13);
|
||||
add_class_parameter("delta_l_max", 1000);
|
||||
|
||||
int class_verbosity = 0;
|
||||
|
||||
add_class_parameter("background_verbose", class_verbosity);
|
||||
|
@ -147,8 +171,8 @@ private:
|
|||
add_class_parameter("perturbations_verbose", class_verbosity);
|
||||
add_class_parameter("transfer_verbose", class_verbosity);
|
||||
add_class_parameter("primordial_verbose", class_verbosity);
|
||||
add_class_parameter("spectra_verbose", class_verbosity);
|
||||
add_class_parameter("nonlinear_verbose", class_verbosity);
|
||||
add_class_parameter("harmonic_verbose", class_verbosity);
|
||||
add_class_parameter("fourier_verbose", class_verbosity);
|
||||
add_class_parameter("lensing_verbose", class_verbosity);
|
||||
add_class_parameter("output_verbose", class_verbosity);
|
||||
|
||||
|
@ -163,21 +187,250 @@ private:
|
|||
music::ilog << "Computing transfer function via ClassEngine..." << std::endl;
|
||||
double wtime = get_wtime();
|
||||
|
||||
the_ClassEngine_ = std::make_unique<ClassEngine>(pars_, false);
|
||||
//.........................................................................
|
||||
this->setup_class( pars_ );
|
||||
//.........................................................................
|
||||
|
||||
wtime = get_wtime() - wtime;
|
||||
music::ilog << "CLASS took " << wtime << " s." << std::endl;
|
||||
}
|
||||
|
||||
/*! \brief Set up CLASS engine with parameters
|
||||
*
|
||||
* \param pars ClassParams object containing the parameters
|
||||
* \return _SUCCESS_ or _FAILURE_
|
||||
*/
|
||||
int setup_class( const ClassParams &pars )
|
||||
{
|
||||
|
||||
ErrorMsg errmsg;
|
||||
|
||||
//prepare fp structure
|
||||
std::vector<std::string> parNames;
|
||||
size_t n=pars.size();
|
||||
char dummystr[] = "dummy";
|
||||
parser_init(&fc_,n,dummystr, errmsg);
|
||||
|
||||
//config
|
||||
for (size_t i=0;i<pars.size();i++){
|
||||
strcpy(fc_.name[i],pars.key(i).c_str());
|
||||
strcpy(fc_.value[i],pars.value(i).c_str());
|
||||
parNames.push_back(pars.key(i));
|
||||
}
|
||||
|
||||
// if (input_init(&fc_,&pr_,&ba_,&th_,&pt_,&tr_,&pm_,&sp_,&nl_,&le_,&op_,errmsg) == _FAILURE_) {
|
||||
if (input_read_from_file(&fc_, &pr_, &ba_, &th_, &pt_, &tr_, &pm_, &sp_, &nl_, &le_, &sd_, &op_, errmsg) == _FAILURE_){
|
||||
music::elog.Print(" running input_init_from_arguments \n=>%s\n",errmsg);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
// proetction parametres mal defini
|
||||
for (size_t i = 0; i < pars.size(); i++)
|
||||
{
|
||||
if (fc_.read[i] != _TRUE_)
|
||||
throw std::runtime_error(std::string("invalid CLASS parameter: ") + fc_.name[i]);
|
||||
}
|
||||
|
||||
if (background_init(&pr_,&ba_) == _FAILURE_) {
|
||||
music::elog.Print(" running background_init \n=>%s\n",ba_.error_message);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (thermodynamics_init(&pr_,&ba_,&th_) == _FAILURE_) {
|
||||
music::elog.Print(" in thermodynamics_init \n=>%s\n",th_.error_message);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (perturbations_init(&pr_,&ba_,&th_,&pt_) == _FAILURE_) {
|
||||
music::elog.Print(" in perturb_init \n=>%s\n",pt_.error_message);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (primordial_init(&pr_,&pt_,&pm_) == _FAILURE_) {
|
||||
music::elog.Print(" in primordial_init \n=>%s\n",pm_.error_message);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (fourier_init(&pr_,&ba_,&th_,&pt_,&pm_,&nl_) == _FAILURE_) {
|
||||
music::elog.Print(" in fourier_init \n=>%s\n",nl_.error_message);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (transfer_init(&pr_,&ba_,&th_,&pt_,&nl_,&tr_) == _FAILURE_) {
|
||||
music::elog.Print(" in transfer_init \n=>%s\n",tr_.error_message);
|
||||
fourier_free(&nl_);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (harmonic_init(&pr_,&ba_,&pt_,&pm_,&nl_,&tr_,&sp_) == _FAILURE_) {
|
||||
music::elog.Print(" in harmonic_init \n=>%s\n",sp_.error_message);
|
||||
transfer_free(&tr_);
|
||||
fourier_free(&nl_);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (lensing_init(&pr_,&pt_,&sp_,&nl_,&le_) == _FAILURE_) {
|
||||
music::elog.Print(" in lensing_init \n=>%s\n",le_.error_message);
|
||||
harmonic_free(&sp_);
|
||||
transfer_free(&tr_);
|
||||
fourier_free(&nl_);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
if (distortions_init(&pr_, &ba_, &th_, &pt_, &pm_, &sd_) == _FAILURE_)
|
||||
{
|
||||
music::elog.Print(" in distortions_init \n=>%s\n", sd_.error_message);
|
||||
lensing_free(&le_);
|
||||
harmonic_free(&sp_);
|
||||
transfer_free(&tr_);
|
||||
fourier_free(&nl_);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_ = false;
|
||||
return _FAILURE_;
|
||||
}
|
||||
|
||||
class_dofree_=true;
|
||||
return _SUCCESS_;
|
||||
}
|
||||
|
||||
int free_class()
|
||||
{
|
||||
if (class_dofree_) {
|
||||
distortions_free(&sd_);
|
||||
lensing_free(&le_);
|
||||
harmonic_free(&sp_);
|
||||
transfer_free(&tr_);
|
||||
fourier_free(&nl_);
|
||||
primordial_free(&pm_);
|
||||
perturbations_free(&pt_);
|
||||
thermodynamics_free(&th_);
|
||||
background_free(&ba_);
|
||||
class_dofree_=false;
|
||||
}
|
||||
return _SUCCESS_;
|
||||
}
|
||||
|
||||
void call_perturb_sources_at_tau(
|
||||
int index_md,
|
||||
int index_ic,
|
||||
int index_tp,
|
||||
double tau,
|
||||
double * psource
|
||||
) {
|
||||
if (perturbations_sources_at_tau(&pt_, index_md, index_ic, index_tp, tau, psource) == _FAILURE_)
|
||||
{
|
||||
std::cerr << ">>>fail getting Tk type=" << (int)index_tp <<std::endl;
|
||||
throw std::runtime_error(pt_.error_message);
|
||||
}
|
||||
}
|
||||
|
||||
//! run ClassEngine with parameters set up
|
||||
void run_ClassEngine(double z, std::vector<double> &k, std::vector<double> &dc, std::vector<double> &tc, std::vector<double> &db, std::vector<double> &tb,
|
||||
std::vector<double> &dn, std::vector<double> &tn, std::vector<double> &dm, std::vector<double> &tm)
|
||||
int run_ClassEngine(double z, std::vector<double> &k, std::vector<double> &d_cdm, std::vector<double> &t_cdm, std::vector<double> &d_b, std::vector<double> &t_b,
|
||||
std::vector<double> &d_ncdm, std::vector<double> &t_ncdm, std::vector<double> &d_tot, std::vector<double> &t_tot)
|
||||
{
|
||||
k.clear();
|
||||
dc.clear(); db.clear(); dn.clear(); dm.clear();
|
||||
tc.clear(); tb.clear(); tn.clear(); tm.clear();
|
||||
d_cdm.clear(); d_b.clear(); d_ncdm.clear(); d_tot.clear();
|
||||
t_cdm.clear(); t_b.clear(); t_ncdm.clear(); t_tot.clear();
|
||||
|
||||
the_ClassEngine_->getTk(z, k, dc, db, dn, dm, tc, tb, tn, tm);
|
||||
z = std::max(z,1e-10);
|
||||
// the_ClassEngine_->getTk(z, k, dc, db, dn, dm, tc, tb, tn, tm);
|
||||
|
||||
//transform redshift in conformal time
|
||||
double tau;
|
||||
int index;
|
||||
background_tau_of_z(&ba_,z,&tau);
|
||||
if(std::log(tau) < pt_.ln_tau[0]){
|
||||
music::elog << "Asking sources at a z bigger than z_max_pk, something probably went wrong\n";
|
||||
throw std::runtime_error(pt_.error_message);
|
||||
}
|
||||
|
||||
double *pvecback=new double[ba_.bg_size];
|
||||
background_at_tau(&ba_,tau,long_info,inter_normal, &index, pvecback);
|
||||
double fHa = pvecback[ba_.index_bg_f] * (pvecback[ba_.index_bg_a]*pvecback[ba_.index_bg_H]);
|
||||
delete[] pvecback;
|
||||
|
||||
//...
|
||||
// copy transfer func data to temporary
|
||||
const size_t index_md = pt_.index_md_scalars;
|
||||
d_cdm.assign( pt_.k_size[index_md], 0.0 );
|
||||
d_b.assign( pt_.k_size[index_md], 0.0 );
|
||||
d_ncdm.assign( pt_.k_size[index_md], 0.0 );
|
||||
d_tot.assign( pt_.k_size[index_md], 0.0 );
|
||||
t_cdm.assign( pt_.k_size[index_md], 0.0 );
|
||||
t_b.assign( pt_.k_size[index_md], 0.0 );
|
||||
t_ncdm.assign( pt_.k_size[index_md], 0.0 );
|
||||
t_tot.assign( pt_.k_size[index_md], 0.0 );
|
||||
|
||||
if( pt_.ic_size[index_md] > 1 ){
|
||||
std::cerr << ">>>have more than 1 ICs, will use first and ignore others" << std::endl;
|
||||
}
|
||||
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_delta_cdm, tau, &d_cdm[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_delta_b, tau, &d_b[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_delta_ncdm1, tau, &d_ncdm[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_delta_tot, tau, &d_tot[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_theta_b, tau, &t_b[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_theta_ncdm1, tau, &t_ncdm[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_theta_tot, tau, &t_tot[0]);
|
||||
|
||||
//
|
||||
std::vector<double> h_prime(pt_.k_size[index_md],0.0), eta_prime(pt_.k_size[index_md],0.0);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_eta_prime, tau, &eta_prime[0]);
|
||||
call_perturb_sources_at_tau(index_md, 0, pt_.index_tp_h_prime, tau, &h_prime[0]);
|
||||
|
||||
// gauge trafo velocities, store k-vector
|
||||
for (int index_k=0; index_k<pt_.k_size[index_md]; index_k++)
|
||||
{
|
||||
auto ak = pt_.k[index_md][index_k];
|
||||
|
||||
// write data to vectors
|
||||
k.push_back( ak );
|
||||
|
||||
// use the conformal Newtonian gauge for velocities
|
||||
// not correct, but N-body gauge currently not implemented
|
||||
double alphak2 = (h_prime[index_k]+6*eta_prime[index_k])/2;
|
||||
|
||||
t_cdm[index_k] = (-alphak2) / fHa;
|
||||
t_b[index_k] = (-alphak2 + t_b[index_k]) / fHa;
|
||||
t_ncdm[index_k] = (-alphak2 + t_ncdm[index_k]) / fHa;
|
||||
t_tot[index_k] = (-alphak2 + t_tot[index_k]) / fHa;
|
||||
}
|
||||
|
||||
//...
|
||||
|
||||
const double h = cosmo_params_.get("h");
|
||||
|
||||
|
@ -185,16 +438,18 @@ private:
|
|||
{
|
||||
// convert to 'CAMB' format, since we interpolate loglog and
|
||||
// don't want negative numbers...
|
||||
auto ik2 = 1.0 / (k[i] * k[i]) * h * h;
|
||||
dc[i] = -dc[i] * ik2;
|
||||
db[i] = -db[i] * ik2;
|
||||
dn[i] = -dn[i] * ik2;
|
||||
dm[i] = -dm[i] * ik2;
|
||||
tc[i] = -tc[i] * ik2;
|
||||
tb[i] = -tb[i] * ik2;
|
||||
tn[i] = -tn[i] * ik2;
|
||||
tm[i] = -tm[i] * ik2;
|
||||
auto ik2 = 1.0 / (k[i] * k[i]) * h * h;
|
||||
d_cdm[i] = -d_cdm[i] * ik2;
|
||||
d_b[i] = -d_b[i] * ik2;
|
||||
d_ncdm[i] = -d_ncdm[i] * ik2;
|
||||
d_tot[i] = -d_tot[i] * ik2;
|
||||
t_cdm[i] = -t_cdm[i] * ik2;
|
||||
t_b[i] = -t_b[i] * ik2;
|
||||
t_ncdm[i] = -t_ncdm[i] * ik2;
|
||||
t_tot[i] = -t_tot[i] * ik2;
|
||||
}
|
||||
|
||||
return _SUCCESS_;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -231,7 +486,7 @@ public:
|
|||
|
||||
// initialise CLASS and get the normalisation
|
||||
this->init_ClassEngine();
|
||||
double A_s_ = the_ClassEngine_->get_A_s(); // this either the input one, or the one computed from sigma8
|
||||
double A_s_ = pm_.A_s;//the_ClassEngine_->get_A_s(); // this either the input one, or the one computed from sigma8
|
||||
|
||||
// compute the normalisation to interface with MUSIC
|
||||
double k_p = cosmo_params["k_p"] / cosmo_params["h"];
|
||||
|
@ -273,6 +528,7 @@ public:
|
|||
|
||||
~transfer_CLASS_plugin()
|
||||
{
|
||||
this->free_class();
|
||||
}
|
||||
|
||||
inline double compute(double k, tf_type type) const
|
||||
|
|
63
src/plugins/transfer_CLASS.hh
Normal file
63
src/plugins/transfer_CLASS.hh
Normal file
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::string str(const T &x)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << x;
|
||||
return os.str();
|
||||
}
|
||||
// specilization
|
||||
template <>
|
||||
std::string str(const float &x)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << std::setprecision(8) << x;
|
||||
return os.str();
|
||||
}
|
||||
template <>
|
||||
std::string str(const double &x)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << std::setprecision(16) << x;
|
||||
return os.str();
|
||||
}
|
||||
template <>
|
||||
std::string str(const bool &x)
|
||||
{
|
||||
{
|
||||
return x ? "yes" : "no";
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string str(const std::string &x) { return x; }
|
||||
|
||||
std::string str(const char *s) { return std::string(s); }
|
||||
|
||||
class ClassParams{
|
||||
public:
|
||||
|
||||
ClassParams(){};
|
||||
ClassParams( const ClassParams& o):pars(o.pars){};
|
||||
|
||||
//use this to add a CLASS variable
|
||||
template<typename T> unsigned add(const std::string& key,const T& val){
|
||||
pars.push_back(std::make_pair(key,str(val)));
|
||||
return pars.size();
|
||||
}
|
||||
|
||||
//accesors
|
||||
inline unsigned size() const {return pars.size();}
|
||||
inline std::string key(const unsigned& i) const {return pars[i].first;}
|
||||
inline std::string value(const unsigned& i) const {return pars[i].second;}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::string,std::string> > pars;
|
||||
};
|
Loading…
Reference in a new issue