mirror of
https://github.com/cosmo-sims/monofonIC.git
synced 2024-09-19 17:03:45 +02:00
moved all routines from main.c to the plugin, added external as included path
This commit is contained in:
parent
a787014b5f
commit
0ffa733344
3 changed files with 73 additions and 22 deletions
|
@ -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()
|
||||
endif()
|
||||
|
|
8
external/panphasia_ho/panphasia_functions.h
vendored
8
external/panphasia_ho/panphasia_functions.h
vendored
|
@ -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<double>* *);
|
||||
#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 *);
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
@ -39,12 +39,12 @@
|
|||
|
||||
#include <grid_fft.hh>
|
||||
|
||||
extern "C"{
|
||||
int PANPHASIA_HO_main( const char *descriptor, size_t *ngrid);
|
||||
int parse_and_validate_descriptor_(const char *, int *);
|
||||
extern "C"
|
||||
{
|
||||
#include <panphasia_ho/panphasia_functions.h>
|
||||
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<std::string>("random", "descriptor");
|
||||
grid_res_ = pcf_->get_value<size_t>("setup","GridRes");
|
||||
grid_res_ = pcf_->get_value<size_t>("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<real_t> &g)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue