Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ cmake/CMakeFiles/
*.dat
*.ipynb_checkpoints
*.idea
*.vscode
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fixed r term in source distribution for SNR and Pulsar
* Fixed wrong mass inheritance for secondaries other than nuclei or electron/positron
* Fixed wrong generation of interval ranges in ObserverTimeEvolution
* Improved CMakeLists.txt to better work as submodule on other cpp based projects

### New features:

Expand Down
337 changes: 171 additions & 166 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmake/FindGooglePerfTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# STACKTRACE_LIBRARIES, where to find the stacktrace library.
# PROFILER_LIBRARIES, where to find the profiler library.

FIND_PATH(GOOGLE_PERFTOOLS_INCLUDE_DIR google/heap-profiler.h)
FIND_PATH(GOOGLE_PERFTOOLS_INCLUDE_DIR NAMES google/heap-profiler.h gperftools/heap-profiler.h)

SET(TCMALLOC_NAMES ${TCMALLOC_NAMES} tcmalloc)
FIND_LIBRARY(TCMALLOC_LIBRARY NAMES ${TCMALLOC_NAMES})
Expand Down
72 changes: 36 additions & 36 deletions doc/pages/Cpp-projects.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
## Using CRPropa from C++
Although is highly recommended to use and [to extend](Extending CRPropa) CRPropa with the default Python binding, there is also a possibility to use it within a C++ code when Python or SWIG are not available or desirable.

To include CRPropa classes and definitions it is sufficient to include ``crpropa/CRPropa.h``, example:
To include CRPropa classes and definitions it is sufficient to include ``CRPropa.h``, example:

```c++
#include "crpropa/CRPropa.h"
#include "CRPropa.h"

using namespace crpropa;

int main(void) {

ModuleList sim;
sim.add(new SimplePropagation(1*kpc, 10*Mpc));
sim.add(new Redshift());
sim.add(new PhotoPionProduction(CMB));
sim.add(new PhotoPionProduction(IRB));
sim.add(new PhotoDisintegration(CMB));
sim.add(new PhotoDisintegration(IRB));
sim.add(new NuclearDecay());
sim.add(new ElectronPairProduction(CMB));
sim.add(new ElectronPairProduction(IRB));
sim.add(new MinimumEnergy(1*EeV));

ref_ptr<Observer> obs = new Observer();
obs->add(new Observer1D());
obs->onDetection(new TextOutput("events.txt", Output::Event1D));
obs->onDetection(new TextOutput());
sim.add(obs);

ref_ptr<Source> source = new Source();
source->add(new SourceUniform1D(1*Mpc, 1000*Mpc));
source->add(new SourceRedshift1D());

ref_ptr<SourceComposition> composition =
new SourceComposition(1*EeV, 100*EeV, -1);
composition->add(1, 1, 1);
composition->add(4, 2, 1);
composition->add(14, 7, 1);
composition->add(56, 26, 1);
source->add(composition);

sim.setShowProgress(true);
sim.run(source, 2000, true);

return 0;
ModuleList sim;
sim.add(new SimplePropagation(1*kpc, 10*Mpc));
sim.add(new Redshift());
sim.add(new PhotoPionProduction(new CMB()));
sim.add(new PhotoPionProduction(new IRB_Kneiske04()));
sim.add(new PhotoDisintegration(new CMB()));
sim.add(new PhotoDisintegration(new IRB_Kneiske04()));
sim.add(new NuclearDecay());
sim.add(new ElectronPairProduction(new CMB()));
sim.add(new ElectronPairProduction(new IRB_Kneiske04()));
sim.add(new MinimumEnergy(1*EeV));

ref_ptr<Observer> obs = new Observer();
obs->add(new Observer1D());
obs->onDetection(new TextOutput("events.txt", Output::Event1D));
obs->onDetection(new TextOutput());
sim.add(obs);

ref_ptr<Source> source = new Source();
source->add(new SourceUniform1D(1*Mpc, 1000*Mpc));
source->add(new SourceRedshift1D());

ref_ptr<SourceComposition> composition =
new SourceComposition(1*EeV, 100*EeV, -1);
composition->add(1, 1, 1);
composition->add(4, 2, 1);
composition->add(14, 7, 1);
composition->add(56, 26, 1);
source->add(composition);

sim.setShowProgress(true);
sim.run(source.get(), 2000, true);

return 0;
}
```

Expand Down
16 changes: 8 additions & 8 deletions doc/pages/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ The following packages are provided with the source code and do not need to be i
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local
make
make install
cmake --build .
cmake --install .
```

2. A set of unit tests can be run with ```make test```. If the tests are
successful continue with ```make install``` to install CRPropa at the
2. A set of unit tests can be run with ```ctest```. If the tests are
successful continue with ```cmake --install .``` to install CRPropa at the
specified path, or leave it in the build directory. Make sure the
environment variables are set accordingly: e.g. for an installation under
$HOME/.local and using Python 3 set
Expand All @@ -54,7 +54,7 @@ The following packages are provided with the source code and do not need to be i
export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH
```

However, we highly recommend to use a virtualenv setup to install CRPropa!
However, we highly recommend to use a virtualenv or conda setup to install CRPropa!


### Installation in python virtualenv
Expand Down Expand Up @@ -117,11 +117,11 @@ worthwhile effort afterwards.
mkdir build
cd build
CMAKE_PREFIX_PATH=$CRPROPA_DIR cmake -DCMAKE_INSTALL_PREFIX=$CRPROPA_DIR ..
make
make install
cmake --build .
cmake --install .
```

5. A set of unit tests can be run with ```make test```.
5. A set of unit tests can be run with ```ctest```.

6. (optional) Check the installation.
```python
Expand Down
6 changes: 6 additions & 0 deletions include/crpropa/module/TextOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class TextOutput: public Output {
@param collector object of type ParticleCollector that will store the information
*/
static void load(const std::string &filename, ParticleCollector *collector);
/** Loads a stream to a particle collector.
This is useful for analysis involving, e.g., magnetic lenses.
@param in stream containing the data to be loaded in the same format TextOutput outputs the data
@param collector object of type ParticleCollector that will store the information
*/
static void load(std::istream &in, ParticleCollector *collector);
std::string getDescription() const;

void dumpIndexList(std::vector<int> indicies);
Expand Down
12 changes: 12 additions & 0 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ std::string getDataPath(std::string filename) {
}
}

#ifdef CRPROPA_BINARY_DIR
{
std::string _path = CRPROPA_BINARY_DIR "/data";
if (is_directory(_path)) {
dataPath = _path;
KISS_LOG_INFO
<< "getDataPath: use binary path, " << dataPath << std::endl;
return concat_path(dataPath, filename);
}
}
#endif

dataPath = "data";
KISS_LOG_INFO << "getDataPath: use default, " << dataPath << std::endl;
return removeNullCharacter(concat_path(dataPath, filename));
Expand Down
2 changes: 1 addition & 1 deletion src/magneticField/turbulentField/PlaneWaveTurbulence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#ifdef ENABLE_FAST_WAVES
#include <immintrin.h>
#include <memory.h>
#include <memory>
#endif

namespace crpropa {
Expand Down
27 changes: 16 additions & 11 deletions src/module/TextOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,29 +291,35 @@ void TextOutput::process(Candidate *c) const {
}

void TextOutput::load(const std::string &filename, ParticleCollector *collector){

std::string line;
std::istream *in;
std::ifstream infile(filename.c_str());

Output output;
double lengthScale = output.getLengthScale();
double timeScale = output.getTimeScale();
double energyScale = output.getEnergyScale();

if (!infile.good())
throw std::runtime_error("crpropa::TextOutput: could not open file " + filename);
in = &infile;
if (kiss::ends_with(filename, ".gz")){

if (kiss::ends_with(filename, ".gz")){
#ifdef CRPROPA_HAVE_ZLIB
in = new zstream::igzstream(*in);
#else
throw std::runtime_error("CRPropa was built without Zlib compression!");
#endif
}

while (std::getline(*in, line)) {
load(*in, collector);
infile.close();
}

void TextOutput::load(std::istream &in, ParticleCollector *collector){

std::string line;

Output output;
double lengthScale = output.getLengthScale();
double timeScale = output.getTimeScale();
double energyScale = output.getEnergyScale();

while (std::getline(in, line)) {
std::stringstream stream(line);
if (stream.peek() == '#')
continue;
Expand Down Expand Up @@ -360,7 +366,6 @@ void TextOutput::load(const std::string &filename, ParticleCollector *collector)

collector->process(c);
}
infile.close();
}

std::string TextOutput::getDescription() const {
Expand Down
Loading