Advanced Computing Platform for Theoretical Physics

commit大文件会使得服务器变得不稳定,请大家尽量只commit代码,不要commit大的文件。

Commit 6f9c30fc authored by Chen Xia's avatar Chen Xia
Browse files

Keep binding

parent 6039e3d7
#include <galprop/CrossSectionData.h>
#include "galpropy.hpp"
void bind_CrossSectionData(py::module_ &m)
{
// TODO make it a map
py::class_<CrossSectionData>(m, "CrossSectionData")
.def(py::init<>())
.def("get", py::overload_cast<int, int, int, int>(
&CrossSectionData::get))
.def("get", py::overload_cast<int, int, int, int>(
&CrossSectionData::get, py::const_))
.def("has", &CrossSectionData::has)
.def("array_size", &CrossSectionData::array_size);
using array_type = std::valarray<double>;
py::class_<CrossSectionData2D>(m, "CrossSectionData2D")
.def(py::init<>())
.def("insert_column", py::overload_cast<
double, const array_type&, const array_type&>(
&CrossSectionData2D::insert_column<array_type>))
// .def("insert_column", py::overload_cast<double, const std::string&>(
// &CrossSectionData2D::insert_column))
.def("loginterp", &CrossSectionData2D::loginterp);
}
#include <galprop/DarkMatter.h>
#include <galprop/DMProductParticle.h>
#include "galpropy.hpp"
void bind_DMProductParticle(py::module_ &m)
{
py::class_<DMProductParticle>(m, "DMProductParticle")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>())
.def("depends_on", &DMProductParticle::depends_on)
.def("fill_source_functions", &DMProductParticle::fill_source_functions)
.def_readwrite("dm", &DMProductParticle::dm);
}
#include <galprop/DarkMatter.h>
#include "galpropy.hpp"
class PyDarkMatterProfile : DarkMatterProfile {
public:
using DarkMatterProfile::DarkMatterProfile;
double dist(double r_rnorm) const override {
PYBIND11_OVERRIDE_PURE(double, DarkMatterProfile, dist, r_rnorm);
}
};
class PyDarkMatter : DarkMatter {
public:
using DarkMatter::DarkMatter;
std::valarray<double> product_spectrum(
IsotopeNumber ison, const std::valarray<double>& ekn) const override {
PYBIND11_OVERRIDE_PURE(std::valarray<double>, DarkMatter,
product_spectrum, ison, ekn);
}
void configure(const config& cfg) override {
PYBIND11_OVERRIDE(void, DarkMatter, configure, cfg);
}
};
void bind_DarkMatter(py::module_ &m)
{
// ------ dark matter profiles ------
py::class_<DarkMatterProfile, PyDarkMatterProfile,
std::shared_ptr<DarkMatterProfile>>(m, "DarkMatterProfile")
.def(py::init<>())
.def_readwrite("rho0", &DarkMatterProfile::rho0);
py::class_<DMProfileGeneral, DarkMatterProfile,
std::shared_ptr<DMProfileGeneral>>(m, "DMProfileGeneral")
.def(py::init<double, double, double, double>())
.def("dist", &DMProfileGeneral::dist)
.def_readwrite("alpha", &DMProfileGeneral::alpha)
.def_readwrite("beta", &DMProfileGeneral::beta)
.def_readwrite("gamma", &DMProfileGeneral::gamma)
.def_readwrite("R_rnorm", &DMProfileGeneral::R_rnorm);
py::class_<DMProfileEinasto, DarkMatterProfile,
std::shared_ptr<DMProfileEinasto>>(m, "DMProfileEinasto")
.def(py::init<double, double>())
.def("dist", &DMProfileEinasto::dist)
.def_readwrite("alpha", &DMProfileEinasto::alpha)
.def_readwrite("R_rnorm", &DMProfileEinasto::R_rnorm);
py::class_<DMProfileBurkert, DarkMatterProfile,
std::shared_ptr<DMProfileBurkert>>(m, "DMProfileBurkert")
.def(py::init<double>())
.def("dist", &DMProfileBurkert::dist)
.def_readwrite("Rcore_rnorm", &DMProfileBurkert::Rcore_rnorm);
// ------ dark matter ------
py::class_<DarkMatter, PyDarkMatter, std::shared_ptr<DarkMatter>>(
m, "DarkMatter")
.def(py::init<>())
.def_readwrite("profile", &DarkMatter::profile)
.def_readwrite("mode", &DarkMatter::mode)
.def_readwrite("mass", &DarkMatter::mass)
.def_readwrite("sigmav", &DarkMatter::sigmav)
.def_readwrite("lifetime", &DarkMatter::lifetime);
py::enum_<BasicDarkMatter::mode_type>(m, "BasicDarkMatterModeType")
.value("annih", BasicDarkMatter::mode_type::annih)
.value("decay", BasicDarkMatter::mode_type::decay);
py::class_<BasicDarkMatter, DarkMatter, std::shared_ptr<BasicDarkMatter>>(
m, "BasicDarkMatter")
.def(py::init<>())
.def("load_dndx", &BasicDarkMatter::load_dndx)
.def("load_dmsp", &BasicDarkMatter::load_dmsp)
.def("product_spectrum", &BasicDarkMatter::product_spectrum)
.def("configure", &BasicDarkMatter::configure)
.def_readwrite("mediator_mass", &BasicDarkMatter::mediator_mass)
.def_readwrite("dndx_data", &BasicDarkMatter::dndx_data);
}
#include <galprop/EnergyLoss.h>
#include "galpropy.hpp"
class PyEnergyLoss : public EnergyLoss
{
public:
using EnergyLoss::EnergyLoss;
int loss(Particle& p, const Galprop& g) override {
PYBIND11_OVERRIDE_PURE(int, EnergyLoss, loss, p, g);
}
};
void bind_EnergyLoss(py::module_ &m)
{
py::class_<ISM_Density>(m, "ISM_Density")
.def(py::init<>())
.def(py::init<const Galaxy&, size_t>())
.def("set", py::overload_cast<const Galaxy&, size_t>(&ISM_Density::set))
.def_readwrite("H2", &ISM_Density::H2)
.def_readwrite("HI", &ISM_Density::HI)
.def_readwrite("HII", &ISM_Density::HII)
.def_readwrite("He_H_ratio", &ISM_Density::He_H_ratio)
.def_readwrite("protium", &ISM_Density::protium)
.def_readwrite("neutral_H", &ISM_Density::neutral_H)
.def_readwrite("neutral_He", &ISM_Density::neutral_He);
py::class_<EnergyLoss, PyEnergyLoss>(m, "EnergyLoss")
.def(py::init<>());
py::class_<ElectronEnergyLoss>(m, "ElectronEnergyLoss")
.def(py::init<>())
.def("loss", &ElectronEnergyLoss::loss)
.def("ionization", &ElectronEnergyLoss::ionization)
.def("coulomb", &ElectronEnergyLoss::coulomb)
.def("bremsstrahlung", &ElectronEnergyLoss::bremsstrahlung)
.def("synchrotron", &ElectronEnergyLoss::synchrotron)
.def("compton", &ElectronEnergyLoss::compton);
py::class_<NucleusEnergyLoss>(m, "NucleusEnergyLoss")
.def(py::init<>())
.def("loss", &NucleusEnergyLoss::loss)
.def("ionization", &NucleusEnergyLoss::ionization)
.def("coulomb", &NucleusEnergyLoss::coulomb);
py::class_<EnergyLossFallback>(m, "EnergyLossFallback")
.def(py::init<>())
.def("loss", &EnergyLossFallback::loss)
.def_readwrite("electron_energy_loss_fallback",
&EnergyLossFallback::electron_energy_loss_fallback)
.def_readwrite("nucleus_energy_loss_fallback",
&EnergyLossFallback::nucleus_energy_loss_fallback);
}
#include <galprop/IsotopeMap.h>
#include "galpropy.hpp"
void bind_IsotopeMap(py::module_ &m)
{
py::class_<IsotopeNumber>(m, "IsotopeNumber")
.def(py::init<>())
.def("packed", py::overload_cast<>(&IsotopeNumber::packed))
.def("packed", py::overload_cast<>(&IsotopeNumber::packed, py::const_))
.def("is", &IsotopeNumber::is)
.def(py::self < py::self);
}
...@@ -27,5 +27,4 @@ void bind_PropelBase(py::module_ &m) ...@@ -27,5 +27,4 @@ void bind_PropelBase(py::module_ &m)
m, "PropelOperatorFallback") m, "PropelOperatorFallback")
.def(py::init<const Galdef&>()) .def(py::init<const Galdef&>())
.def("propel", &PropelOperatorFallback::propel); .def("propel", &PropelOperatorFallback::propel);
} }
#include <galprop/PropelOperatorRedBlack.h>
#include "galpropy.hpp"
void bind_PropelOperatorRedBlack(py::module_ &m)
{
py::class_<PropelOperatorRedBlack>(m, "PropelOperatorRedBlack")
.def(py::init<const Galdef&>())
.def("propel", &PropelOperatorRedBlack::propel)
.def_readwrite("target_relative_diff",
&PropelOperatorRedBlack::target_relative_diff);
}
#include <galprop/SecondaryParticle.h>
#include "galpropy.hpp"
void bind_SecondaryParticle(py::module_ &m) {
py::class_<SecondaryProton, Particle, std::shared_ptr<SecondaryProton>>(
m, "SecondaryProton")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>())
.def("cs_PP", &SecondaryProton::cs_PP)
.def("cs_PHe", &SecondaryProton::cs_PHe);
py::class_<SecondaryAntiproton, Particle,
std::shared_ptr<SecondaryAntiproton>>(m, "SecondaryAntiproton")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>())
.def("cross_section", &SecondaryAntiproton::cross_section);
py::class_<TertiaryAntiproton, Particle,
std::shared_ptr<TertiaryAntiproton>>(m, "TertiaryAntiproton")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>())
.def("cross_section", &TertiaryAntiproton::cross_section);
py::class_<SecondaryPositron, SecondaryAntiproton,
std::shared_ptr<SecondaryPositron>>(m, "SecondaryPositron")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>())
.def("cross_section", &SecondaryPositron::cross_section);
py::class_<SecondaryAntinucleus, Particle,
std::shared_ptr<SecondaryAntinucleus>>(m, "SecondaryAntinucleus")
.def(py::init<std::shared_ptr<const ParticleInfo>,
std::shared_ptr<const Galaxy>,
const std::string &>());
}
...@@ -11,12 +11,19 @@ void bind_Spectrum(py::module_ &); ...@@ -11,12 +11,19 @@ void bind_Spectrum(py::module_ &);
void bind_ParticleLibrary(py::module_ &); void bind_ParticleLibrary(py::module_ &);
void bind_Particle(py::module_ &); void bind_Particle(py::module_ &);
void bind_PrimaryParticle(py::module_ &); void bind_PrimaryParticle(py::module_ &);
void bind_SecondaryParticle(py::module_ &);
void bind_Galdef(py::module_ &); void bind_Galdef(py::module_ &);
void bind_Galaxy(py::module_ &); void bind_Galaxy(py::module_ &);
void bind_GCR(py::module_ &); void bind_GCR(py::module_ &);
void bind_SolarModulation(py::module_ &); void bind_SolarModulation(py::module_ &);
void bind_PropelBase(py::module_ &m); void bind_PropelBase(py::module_ &m);
void bind_PropelOperatorRedBlack(py::module_ &m);
void bind_EnergyLoss(py::module_ &m);
void bind_Galprop(py::module_ &); void bind_Galprop(py::module_ &);
void bind_DarkMatter(py::module_ &);
void bind_DMProductParticle(py::module_ &);
void bind_IsotopeMap(py::module_ &);
void bind_CrossSectionData(py::module_ &);
PYBIND11_MODULE(_bind_galpropcc, m) { PYBIND11_MODULE(_bind_galpropcc, m) {
bind_ErrorLogger(m); bind_ErrorLogger(m);
...@@ -28,10 +35,17 @@ PYBIND11_MODULE(_bind_galpropcc, m) { ...@@ -28,10 +35,17 @@ PYBIND11_MODULE(_bind_galpropcc, m) {
bind_ParticleLibrary(m); bind_ParticleLibrary(m);
bind_Particle(m); bind_Particle(m);
bind_PrimaryParticle(m); bind_PrimaryParticle(m);
bind_SecondaryParticle(m);
bind_Galdef(m); bind_Galdef(m);
bind_Galaxy(m); bind_Galaxy(m);
bind_GCR(m); bind_GCR(m);
bind_SolarModulation(m); bind_SolarModulation(m);
bind_PropelBase(m); bind_PropelBase(m);
bind_PropelOperatorRedBlack(m);
bind_EnergyLoss(m);
bind_Galprop(m); bind_Galprop(m);
bind_DarkMatter(m);
bind_DMProductParticle(m);
bind_IsotopeMap(m);
bind_CrossSectionData(m);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment