Skip to content

Commit

Permalink
Merge 5c73c8e into be32b0a
Browse files Browse the repository at this point in the history
  • Loading branch information
adundovi committed Sep 23, 2020
2 parents be32b0a + 5c73c8e commit 584d60c
Show file tree
Hide file tree
Showing 23 changed files with 1,783 additions and 643 deletions.
84 changes: 48 additions & 36 deletions CMakeLists.txt
Expand Up @@ -19,13 +19,13 @@ set(CRPROPA_SWIG_DEFINES)
set(CRPROPA_SWIG_INPUTS)

macro(USE_CXX11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif ()
else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
endif()
endmacro(USE_CXX11)
USE_CXX11()

Expand All @@ -36,13 +36,27 @@ if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
message(STATUS "Use --as-needed linker flags!")
endif(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)

SET(USE_SIMD OFF CACHE BOOL "Enable SIMD flags (SSE 1 through 4 + AVX) in GCC. This is necessary for fast plane wave turbulence.")
if(USE_SIMD)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx" ) # TODO: use something like -march=native to automatically enable fma if available?
endif(USE_SIMD)

SET(FAST_WAVES OFF CACHE BOOL "Enable SIMD optimizations for PlaneWaveTurbulence. Requires USE_SIMD to be set as well.")
if(FAST_WAVES)
if(USE_SIMD)
add_definitions(-DFAST_WAVES)
else(USE_SIMD)
message(SEND_ERROR "You've requested the FAST_WAVES implementation, but have not enabled USE_SIMD. PlaneWaveTurbulence will be compiled without the optimization.")
endif(USE_SIMD)
endif(FAST_WAVES)

# Add build type for profiling
SET(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS} -ggdb -fno-omit-frame-pointer")
# Enable extra warnings on debug builds
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wextra")

# Set default build-type to release to enable performance improvements
if (NOT CMAKE_BUILD_TYPE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
Expand Down Expand Up @@ -70,11 +84,10 @@ message(STATUS "CRPropa version: ${GIT_DESC} ${GIT_SHA1} ${GIT_REFSPEC}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/Version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/src/Version.cpp" @ONLY)
list(APPEND CRPROPA_EXTRA_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/src/Version.cpp")



# ----------------------------------------------------------------------------
# Dependencies
# ----------------------------------------------------------------------------

# googletest (provided, see https://code.google.com/p/googletest/wiki/FAQ
# Why is it not recommended use a pre-compiled copy of Google Test?)
option(ENABLE_TESTING "Build tests and enable test target" ON)
Expand Down Expand Up @@ -102,20 +115,17 @@ if(ENABLE_COVERAGE)
add_custom_target(coverage_clean
COMMAND ${LCOV_PATH} --directory . --zerocounters
)
add_custom_target(coverage

add_custom_target(coverage
# generate coverage data
COMMAND ${LCOV_PATH} --directory . --capture --output-file coverage.info VERBATIM

# clean external libs
COMMAND ${LCOV_PATH} --remove coverage.info "/usr/include/*" "/usr/lib/*" "*/libs/gtest/*" "*/libs/eigen3/*" "*/libs/zstream-cpp/*" "*/build/*" -o coverage.info.cleaned VERBATIM

# Generate html output
COMMAND ${GENHTML_PATH} -o coverageReport coverage.info.cleaned VERBATIM
COMMAND echo "Generated coverage report in coverageReport/index.html"
)
)
endif(ENABLE_TESTING)

else(LCOV_PATH AND GENHTML_PATH)
if(NOT LCOV_PATH)
message(WARNING "lcov not found, coverage report generation not possible!")
Expand Down Expand Up @@ -156,7 +166,7 @@ option(ENABLE_GALACTICMAGETICLENS "Galactic Magnetic Lens" ON)
option(INSTALL_EIGEN "Install provided EIGEN headers" OFF)
SET(EIGEN_PATH "" CACHE STRING "Use EIGEN from this path instead of the version shipped with CRPropa")
SET(WITH_GALACTIC_LENSES FALSE)
if (ENABLE_GALACTICMAGETICLENS)
if(ENABLE_GALACTICMAGETICLENS)
SET(WITH_GALACTIC_LENSES TRUE)

if(EIGEN_PATH)
Expand All @@ -183,14 +193,12 @@ if (ENABLE_GALACTICMAGETICLENS)
list(APPEND CRPROPA_EXTRA_SOURCES src/magneticLens/ModelMatrix.cpp)
list(APPEND CRPROPA_EXTRA_SOURCES src/magneticLens/Pixelization.cpp)
list(APPEND CRPROPA_EXTRA_SOURCES src/magneticLens/ParticleMapsContainer.cpp)
endif (ENABLE_GALACTICMAGETICLENS)


endif(ENABLE_GALACTICMAGETICLENS)

# OpenMP (optional for shared memory multiprocessing)
option(ENABLE_OPENMP "OpenMP for multithreading" ON)
if(ENABLE_OPENMP)
include(FindOpenMP)
include(FindOpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Expand Down Expand Up @@ -222,7 +230,7 @@ endif(FFTW3F_FOUND)

# Quimby (optional for SPH magnetic fields)
option(ENABLE_QUIMBY "Quimby Support" ON)
if (ENABLE_QUIMBY)
if(ENABLE_QUIMBY)
find_package(Quimby)
if(QUIMBY_FOUND)
list(APPEND CRPROPA_EXTRA_INCLUDES ${QUIMBY_INCLUDE_DIR})
Expand Down Expand Up @@ -350,7 +358,6 @@ add_library(crpropa SHARED
src/EmissionMap.cpp
src/Geometry.cpp
src/GridTools.cpp
src/GridTurbulence.cpp
src/Module.cpp
src/ModuleList.cpp
src/ParticleID.cpp
Expand All @@ -362,6 +369,7 @@ add_library(crpropa SHARED
src/Random.cpp
src/Source.cpp
src/Variant.cpp
src/module/AdiabaticCooling.cpp
src/module/Boundary.cpp
src/module/BreakCondition.cpp
src/module/DiffusionSDE.cpp
Expand All @@ -382,28 +390,31 @@ add_library(crpropa SHARED
src/module/PhotoPionProduction.cpp
src/module/PhotonEleCa.cpp
src/module/PhotonOutput1D.cpp
src/module/PropagationCK.cpp
src/module/PropagationBP.cpp
src/module/PropagationCK.cpp
src/module/Redshift.cpp
src/module/RestrictToRegion.cpp
src/module/SimplePropagation.cpp
src/module/SynchrotronRadiation.cpp
src/module/TextOutput.cpp
src/module/AdiabaticCooling.cpp
src/module/Tools.cpp
src/magneticField/ArchimedeanSpiralField.cpp
src/magneticField/JF12Field.cpp
src/magneticField/JF12FieldSolenoidal.cpp
src/magneticField/MagneticField.cpp
src/magneticField/MagneticFieldGrid.cpp
src/magneticField/PT11Field.cpp
src/magneticField/turbulentField/GridTurbulence.cpp
src/magneticField/turbulentField/HelicalGridTurbulence.cpp
src/magneticField/turbulentField/PlaneWaveTurbulence.cpp
src/magneticField/turbulentField/SimpleGridTurbulence.cpp
src/magneticField/TF17Field.cpp
src/magneticField/ArchimedeanSpiralField.cpp
src/advectionField/AdvectionField.cpp
src/massDistribution/Nakanishi.cpp
src/massDistribution/Massdistribution.cpp
src/massDistribution/Ferriere.cpp
src/massDistribution/Cordes.cpp
src/massDistribution/ConstantDensity.cpp
src/massDistribution/Cordes.cpp
src/massDistribution/Ferriere.cpp
src/massDistribution/Massdistribution.cpp
src/massDistribution/Nakanishi.cpp

${CRPROPA_EXTRA_SOURCES}
)
Expand All @@ -425,11 +436,9 @@ if(DOXYGEN_FOUND)
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/libs/doxy2swig/doxy2swig.py ${CMAKE_CURRENT_BINARY_DIR}/xml/index.xml -o ${CMAKE_CURRENT_BINARY_DIR}/docstrings_from_doxy.i
DEPENDS doxy
)


else()
else(DOXYGEN_FOUND)
MESSAGE(STATUS "Doxygen not found: cannot build documentation")
endif(DOXYGEN_FOUND )
endif(DOXYGEN_FOUND)



Expand Down Expand Up @@ -458,7 +467,6 @@ if(ENABLE_PYTHON AND PYTHONLIBS_FOUND)
endif(DOXYGEN_FOUND)
endif(SWIG_VERSION VERSION_GREATER 4.0)


# use SWIG's builtin (maybe should be abandoned if everything will be tested and working with -builtin)
option(ENABLE_SWIG_BUILTIN "Use SWIG's -builtin option" OFF)

Expand All @@ -480,7 +488,7 @@ if(ENABLE_PYTHON AND PYTHONLIBS_FOUND)
MESSAGE(STATUS "Found numpy headers in " ${numpyIncludePath})
SET(CMAKE_SWIG_FLAGS -DWITHNUMPY ${CRP})
list(APPEND CRPROPA_SWIG_DEFINES -DWITHNUMPY)
include_directories(${numpyIncludePath})
include_directories(${numpyIncludePath})
else(numpyIncludePath)
MESSAGE(STATUS "Numpy not found.")
endif(numpyIncludePath)
Expand Down Expand Up @@ -576,6 +584,10 @@ if(ENABLE_TESTING)
add_executable(testMagneticField test/testMagneticField.cpp)
target_link_libraries(testMagneticField crpropa gtest gtest_main pthread ${COVERAGE_LIBS})
add_test(testMagneticField testMagneticField)

add_executable(testTurbulentField test/testTurbulentField.cpp)
target_link_libraries(testTurbulentField crpropa gtest gtest_main pthread ${COVERAGE_LIBS})
add_test(testTurbulentField testTurbulentField)

add_executable(testAdvectionField test/testAdvectionField.cpp)
target_link_libraries(testAdvectionField crpropa gtest gtest_main pthread ${COVERAGE_LIBS})
Expand Down
14 changes: 9 additions & 5 deletions include/CRPropa.h
Expand Up @@ -9,7 +9,6 @@
#include "crpropa/Geometry.h"
#include "crpropa/Grid.h"
#include "crpropa/GridTools.h"
#include "crpropa/GridTurbulence.h"
#include "crpropa/Logging.h"
#include "crpropa/Module.h"
#include "crpropa/ModuleList.h"
Expand All @@ -26,6 +25,7 @@
#include "crpropa/Vector3.h"
#include "crpropa/Version.h"

#include "crpropa/module/AdiabaticCooling.h"
#include "crpropa/module/Boundary.h"
#include "crpropa/module/BreakCondition.h"
#include "crpropa/module/DiffusionSDE.h"
Expand All @@ -45,25 +45,29 @@
#include "crpropa/module/PhotoPionProduction.h"
#include "crpropa/module/PhotonEleCa.h"
#include "crpropa/module/PhotonOutput1D.h"
#include "crpropa/module/PropagationCK.h"
#include "crpropa/module/PropagationBP.h"
#include "crpropa/module/PropagationCK.h"
#include "crpropa/module/Redshift.h"
#include "crpropa/module/RestrictToRegion.h"
#include "crpropa/module/SimplePropagation.h"
#include "crpropa/module/SynchrotronRadiation.h"
#include "crpropa/module/TextOutput.h"
#include "crpropa/module/Tools.h"
#include "crpropa/module/AdiabaticCooling.h"

#include "crpropa/magneticField/AMRMagneticField.h"
#include "crpropa/magneticField/ArchimedeanSpiralField.h"
#include "crpropa/magneticField/JF12Field.h"
#include "crpropa/magneticField/JF12FieldSolenoidal.h"
#include "crpropa/magneticField/MagneticField.h"
#include "crpropa/magneticField/MagneticFieldGrid.h"
#include "crpropa/magneticField/PT11Field.h"
#include "crpropa/magneticField/TF17Field.h"
#include "crpropa/magneticField/QuimbyMagneticField.h"
#include "crpropa/magneticField/ArchimedeanSpiralField.h"
#include "crpropa/magneticField/TF17Field.h"
#include "crpropa/magneticField/turbulentField/GridTurbulence.h"
#include "crpropa/magneticField/turbulentField/HelicalGridTurbulence.h"
#include "crpropa/magneticField/turbulentField/PlaneWaveTurbulence.h"
#include "crpropa/magneticField/turbulentField/SimpleGridTurbulence.h"
#include "crpropa/magneticField/turbulentField/TurbulentField.h"

#include "crpropa/advectionField/AdvectionField.h"

Expand Down
64 changes: 62 additions & 2 deletions include/crpropa/Grid.h
Expand Up @@ -34,6 +34,57 @@ inline double round(double r) {
* \addtogroup Core
* @{
*/

/**
@class GridProperties
@brief Combines parameters that uniquely define Grid class
*/
class GridProperties: public Referenced {
public:
size_t Nx, Ny, Nz;
Vector3d origin;
Vector3d spacing;
bool reflective;

/** Constructor for cubic grid
@param origin Position of the lower left front corner of the volume
@param N Number of grid points in one direction
@param spacing Spacing between grid points
*/
GridProperties(Vector3d origin, size_t N, double spacing) :
origin(origin), Nx(N), Ny(N), Nz(N), spacing(Vector3d(spacing)), reflective(false) {
}

/** Constructor for non-cubic grid
@param origin Position of the lower left front corner of the volume
@param Nx Number of grid points in x-direction
@param Ny Number of grid points in y-direction
@param Nz Number of grid points in z-direction
@param spacing Spacing between grid points
*/
GridProperties(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, double spacing) :
origin(origin), Nx(Nx), Ny(Ny), Nz(Nz), spacing(Vector3d(spacing)), reflective(false) {
}

/** Constructor for non-cubic grid with spacing vector
@param origin Position of the lower left front corner of the volume
@param Nx Number of grid points in x-direction
@param Ny Number of grid points in y-direction
@param Nz Number of grid points in z-direction
@param spacing Spacing vector between grid points
*/
GridProperties(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, Vector3d spacing) :
origin(origin), Nx(Nx), Ny(Ny), Nz(Nz), spacing(spacing), reflective(false) {
}

virtual ~GridProperties() {
}

void setReflective(bool b) {
reflective = b;
}
};

/**
@class Grid
@brief Template class for fields on a periodic grid with trilinear interpolation
Expand Down Expand Up @@ -86,12 +137,20 @@ class Grid: public Referenced {
@param Nz Number of grid points in z-direction
@param spacing Spacing vector between grid points
*/
Grid(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, Vector3d spacing) {
Grid(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, Vector3d spacing) {
setOrigin(origin);
setGridSize(Nx, Ny, Nz);
setSpacing(spacing);
setReflective(false);
}
}

/** Constructor for GridProperties
@param p GridProperties instance
*/
Grid(const GridProperties &p) :
origin(p.origin), spacing(p.spacing), reflective(p.reflective) {
setGridSize(p.Nx, p.Ny, p.Nz);
}

void setOrigin(Vector3d origin) {
this->origin = origin;
Expand Down Expand Up @@ -287,6 +346,7 @@ class ScalarGrid: public Grid1f {
}
};


/** @}*/

} // namespace crpropa
Expand Down
14 changes: 14 additions & 0 deletions include/crpropa/GridTools.h
Expand Up @@ -5,6 +5,10 @@
#include "crpropa/magneticField/MagneticField.h"
#include <string>

#ifdef CRPROPA_HAVE_FFTW3F
#include "fftw3.h"
#endif

/**
@file
@brief Grid related functions: load, dump, save, retrieve grid properties ...
Expand Down Expand Up @@ -36,6 +40,8 @@ double meanFieldStrength(ref_ptr<Grid3f> grid);
double rmsFieldStrength(ref_ptr<Grid1f> grid);
/** Evaluate the RMS of all grid points */
double rmsFieldStrength(ref_ptr<Grid3f> grid);
/** Evaluate the RMS of all grid points per axis */
std::array<float, 3> rmsFieldStrengthPerAxis(ref_ptr<Grid3f> grid);

/** Multiply all grid values by a given factor */
void scaleGrid(ref_ptr<Grid1f> grid, double a);
Expand Down Expand Up @@ -80,6 +86,14 @@ void dumpGridToTxt(ref_ptr<Grid3f> grid, std::string filename,
void dumpGridToTxt(ref_ptr<Grid1f> grid, std::string filename,
double conversion = 1);

#ifdef CRPROPA_HAVE_FFTW3F
/**
Calculate the omnidirectional power spectrum E(k) for a given turbulent field
Returns a vector of pairs (k_i, E(k_i))
*/
std::vector<std::pair<int, float>> gridPowerSpectrum(ref_ptr<Grid3f> grid);
#endif // CRPROPA_HAVE_FFTW3F

/** @}*/
} // namespace crpropa

Expand Down

0 comments on commit 584d60c

Please sign in to comment.