From 0ffa733344a237b09171ddba961a6db2cf9214f7 Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Fri, 14 May 2021 13:57:57 +0200 Subject: [PATCH] moved all routines from main.c to the plugin, added external as included path --- CMakeLists.txt | 4 +- external/panphasia_ho/panphasia_functions.h | 8 +- src/plugins/random_panphasia_ho.cc | 83 ++++++++++++++++----- 3 files changed, 73 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b6b30f..f0c801f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,7 @@ endif(ENABLE_PANPHASIA) option(ENABLE_PANPHASIA_HO "Enable PANPHASIA-HO random number generator" ON) ######################################################################################################################## # INCLUDES -include_directories(${PROJECT_SOURCE_DIR}/include) +include_directories(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/external) # SOURCES # get all the *.cc files in the subfolders @@ -289,4 +289,4 @@ if(ENABLE_GENERICIO) include(${CMAKE_CURRENT_SOURCE_DIR}/external/genericio.cmake) target_link_libraries(${PRGNAME} PRIVATE genericio::genericio_mpi) target_compile_definitions(${PRGNAME} PRIVATE "ENABLE_GENERICIO") -endif() \ No newline at end of file +endif() diff --git a/external/panphasia_ho/panphasia_functions.h b/external/panphasia_ho/panphasia_functions.h index 01a579e..852f5c8 100644 --- a/external/panphasia_ho/panphasia_functions.h +++ b/external/panphasia_ho/panphasia_functions.h @@ -3,6 +3,7 @@ // By default Panphasia is computed at single // precision. To override this define PAN_DOUBLE +#pragma once #ifndef USE_PRECISION_FLOAT #define PAN_DOUBLE_PRECISION 8 @@ -21,7 +22,7 @@ #endif - +#include "PAN_FFTW3.h" ///////////////////////////////////////////////////////////////////// @@ -89,7 +90,10 @@ int return_binary_tree_cell_lists(size_t level_max, size_t *list_cell_coordinate - +#ifdef __cplusplus +void compute_sph_bessel_coeffs(int, int, int, int, std::complex* *); +#else void compute_sph_bessel_coeffs(int, int, int, int, double complex *); +#endif int PANPHASIA_compute_kspace_field_(size_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, FFTW_COMPLEX *); diff --git a/src/plugins/random_panphasia_ho.cc b/src/plugins/random_panphasia_ho.cc index 41fbeb7..85f7280 100644 --- a/src/plugins/random_panphasia_ho.cc +++ b/src/plugins/random_panphasia_ho.cc @@ -2,17 +2,17 @@ // A software package to generate ICs for cosmological simulations // Copyright (C) 2021 by Oliver Hahn and Adrian Jenkins (this file) // but see distinct licensing for PANPHASIA below -// +// // monofonIC 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. -// +// // monofonIC 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 this program. If not, see . // @@ -39,12 +39,12 @@ #include -extern "C"{ - int PANPHASIA_HO_main( const char *descriptor, size_t *ngrid); - int parse_and_validate_descriptor_(const char *, int *); +extern "C" +{ + #include + extern size_t descriptor_base_size; } - class RNG_panphasia_ho : public RNG_plugin { private: @@ -65,36 +65,83 @@ public: #endif descriptor_string_ = pcf_->get_value("random", "descriptor"); - grid_res_ = pcf_->get_value("setup","GridRes"); + grid_res_ = pcf_->get_value("setup", "GridRes"); panphasia_mode_ = 0; parse_and_validate_descriptor_(descriptor_string_.c_str(), &panphasia_mode_); - if( panphasia_mode_ == 0 ){ + if (panphasia_mode_ == 0) + { std::cout << "PANPHASIA: Old descriptor" << std::endl; - }else if( panphasia_mode_ == 1 ){ + } + else if (panphasia_mode_ == 1) + { std::cout << "PANPHASIA: New descriptor" << std::endl; - PANPHASIA_HO_main(descriptor_string_.c_str(),&grid_res_); - }else{ + + int verbose = 0; + int error; + size_t x0 = 0, y0 = 0, z0 = 0; + size_t rel_level; + int fdim = 1; //Option to scale Fourier grid dimension relative to Panphasia coefficient grid + + //char descriptor[300] = "[Panph6,L20,(424060,82570,148256),S1,KK0,CH-999,Auriga_100_vol2]"; + + PANPHASIA_init_descriptor_(descriptor_string_.c_str(), &verbose); + + printf("Descriptor %s\n ngrid_load %lu\n", descriptor_string_.c_str(), grid_res_); + + // Choose smallest value of level to equal of exceed grid_res_) + + for (rel_level = 0; fdim * (descriptor_base_size << (rel_level + 1)) <= grid_res_; rel_level++) + ; + + printf("Setting relative level = %lu\n", rel_level); + + if ((error = PANPHASIA_init_level_(&rel_level, &x0, &y0, &z0, &verbose))) + { + printf("Abort: PANPHASIA_init_level_ :error code %d\n", error); + abort(); + }; + + //======================= FFTW ============================== + + ptrdiff_t alloc_local, local_n0, local_0_start; + + ptrdiff_t N0 = fdim * (descriptor_base_size << rel_level); + + alloc_local = FFTW_MPI_LOCAL_SIZE_3D(N0, N0, N0 + 2, MPI_COMM_WORLD, &local_n0, &local_0_start); + + FFTW_COMPLEX *Panphasia_White_Noise_Field; + + Panphasia_White_Noise_Field = FFTW_ALLOC_COMPLEX(alloc_local); + + if ((error = PANPHASIA_compute_kspace_field_(rel_level, N0, local_n0, local_0_start, Panphasia_White_Noise_Field))) + { + printf("Error code from PANPHASIA_compute ... %d\n", error); + }; + + fftw_free(Panphasia_White_Noise_Field); + + // PANPHASIA_HO_main(descriptor_string_.c_str(),&grid_res_); + } + else + { std::cout << "PANPHASIA: Something went wrong with descriptor" << std::endl; abort(); } } - ~RNG_panphasia_ho() - { - if( panphasia_mode_ == 0) // old + ~RNG_panphasia_ho() + { + if (panphasia_mode_ == 0) // old { } - - } bool isMultiscale() const { return true; } void Fill_Grid(Grid_FFT &g) { - } };