Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/distributions part3 #8

Merged
merged 12 commits into from
Oct 19, 2024
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ if( dryad.python )
python/src/dryad.python.cpp
python/src/id.python.cpp
python/src/id/ElementID.python.cpp
python/src/DistributionDataType.python.cpp
python/src/InteractionType.python.cpp
python/src/ReactionType.python.cpp
python/src/ReferenceFrame.python.cpp
python/src/TabulatedCrossSection.python.cpp
python/src/TabulatedMultiplicity.python.cpp
python/src/LegendreAngularDistribution.python.cpp
python/src/LegendreAngularDistributions.python.cpp
python/src/TabulatedAngularDistribution.python.cpp
python/src/TabulatedAngularDistributions.python.cpp
python/src/TabulatedEnergyDistribution.python.cpp
python/src/TabulatedEnergyDistributions.python.cpp
python/src/ReactionProduct.python.cpp
python/src/Reaction.python.cpp
python/src/ProjectileTarget.python.cpp
Expand Down
8 changes: 6 additions & 2 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ endfunction()

add_subdirectory( src/dryad/id/ElementID/test )

add_subdirectory( src/dryad/TabulatedMultiplicity/test )
add_subdirectory( src/dryad/LegendreAngularDistribution/test )
add_subdirectory( src/dryad/LegendreAngularDistributions/test )
add_subdirectory( src/dryad/TabulatedAngularDistribution/test )
add_subdirectory( src/dryad/TabulatedAngularDistributions/test )
add_subdirectory( src/dryad/TabulatedEnergyDistribution/test )
add_subdirectory( src/dryad/TabulatedEnergyDistributions/test )
add_subdirectory( src/dryad/TabulatedCrossSection/test )
add_subdirectory( src/dryad/TabulatedMultiplicity/test )
add_subdirectory( src/dryad/TwoBodyDistributionData/test )
add_subdirectory( src/dryad/UncorrelatedDistributionData/test )
add_subdirectory( src/dryad/ReactionProduct/test )

add_subdirectory( src/dryad/TabulatedCrossSection/test )
add_subdirectory( src/dryad/Reaction/test )

add_subdirectory( src/dryad/ProjectileTarget/test )

add_subdirectory( src/dryad/format/test )
Expand Down
20 changes: 13 additions & 7 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ message( STATUS "Adding dryad Python unit testing" )

add_python_test( id.ElementID id/Test_dryad_id_ElementID.py )

add_python_test( TabulatedAngularDistribution Test_dryad_TabulatedAngularDistribution.py )
add_python_test( LegendreAngularDistribution Test_dryad_LegendreAngularDistribution.py )
add_python_test( TabulatedCrossSection Test_dryad_TabulatedCrossSection.py )
add_python_test( TabulatedMultiplicity Test_dryad_TabulatedMultiplicity.py )
add_python_test( ReactionProduct Test_dryad_ReactionProduct.py )
add_python_test( Reaction Test_dryad_Reaction.py )
add_python_test( ProjectileTarget Test_dryad_ProjectileTarget.py )
add_python_test( TabulatedMultiplicity Test_dryad_TabulatedMultiplicity.py )
add_python_test( LegendreAngularDistribution Test_dryad_LegendreAngularDistribution.py )
add_python_test( LegendreAngularDistributions Test_dryad_LegendreAngularDistributions.py )
add_python_test( TabulatedAngularDistribution Test_dryad_TabulatedAngularDistribution.py )
add_python_test( TabulatedAngularDistributions Test_dryad_TabulatedAngularDistributions.py )
add_python_test( TabulatedEnergyDistribution Test_dryad_TabulatedEnergyDistribution.py )
add_python_test( TabulatedEnergyDistributions Test_dryad_TabulatedEnergyDistributions.py )
add_python_test( ReactionProduct Test_dryad_ReactionProduct.py )

add_python_test( TabulatedCrossSection Test_dryad_TabulatedCrossSection.py )
add_python_test( Reaction Test_dryad_Reaction.py )

add_python_test( ProjectileTarget Test_dryad_ProjectileTarget.py )
31 changes: 31 additions & 0 deletions python/src/DistributionDataType.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// local includes
#include "dryad/DistributionDataType.hpp"

// namespace aliases
namespace python = pybind11;

void wrapDistributionDataType( python::module& module, python::module& ) {

// type aliases
using Component = njoy::dryad::DistributionDataType;

// wrap views created by this component

// create the component
python::enum_< Component > component(

module,
"DistributionDataType",
"The distribition data type for a reaction product",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Distribition"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in fix/review

python::arithmetic()
);

// wrap the component
component
.value( "TwoBody", Component::TwoBody )
.value( "Uncorrelated", Component::Uncorrelated );
}
92 changes: 92 additions & 0 deletions python/src/LegendreAngularDistributions.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>

// local includes
#include "definitions.hpp"
#include "dryad/LegendreAngularDistributions.hpp"

// namespace aliases
namespace python = pybind11;

void wrapLegendreAngularDistributions( python::module& module, python::module& ) {

// type aliases
using Component = njoy::dryad::LegendreAngularDistributions;
using LegendreAngularDistribution = njoy::dryad::LegendreAngularDistribution;
using InterpolationType = njoy::dryad::InterpolationType;
using ToleranceConvergence = njoy::dryad::ToleranceConvergence;

// wrap views created by this component

// create the component
python::class_< Component > component(

module,
"LegendreAngularDistributions",
"Angular distribution data given using Legendre expansions"
);

// wrap the component
component
.def(

python::init< std::vector< double >,
std::vector< LegendreAngularDistribution >,
std::vector< std::size_t >,
std::vector< InterpolationType > >(),
python::arg( "grid" ), python::arg( "distributions" ),
python::arg( "boundaries" ), python::arg( "interpolants" ),
"Initialise the angular distributions\n\n"
"Arguments:\n"
" self the angular distribution table\n"
" grid the grid values\n"
" distributions the distributions\n"
" boundaries the boundaries of the interpolation regions\n"
" interpolants the interpolation types of the interpolation regions,\n"
" see InterpolationType for all interpolation types"
)
.def(

python::init< std::vector< double >,
std::vector< LegendreAngularDistribution >,
InterpolationType >(),
python::arg( "grid" ), python::arg( "distributions" ),
python::arg( "interpolant" ) = InterpolationType::LinearLinear,
"Initialise the angular distributions\n\n"
"Arguments:\n"
" self the multiplicity table\n"
" grid the grid values\n"
" distributions the distributions\n"
" interpolant the interpolation type (default lin-lin),\n"
" see InterpolationType for all interpolation types"
)
.def_property_readonly(

"grid",
&Component::grid,
"The grid values for which distributions are given"
)
.def_property_readonly(

"distributions",
&Component::distributions,
"The associated distributions"
)
.def(

"__call__",
[] ( const Component& self, double value, double cosine ) -> decltype(auto)
{ return self( value, cosine ); },
python::arg( "value" ), python::arg( "cosine" ),
"Evaluate the angular distributions\n\n"
"Arguments:\n"
" self the table\n"
" value the grid value\n"
" cosine the cosine value"
);

// add standard tabulated data definitions
addStandardInterpolationTableDefinitions< Component >( component );
}
28 changes: 26 additions & 2 deletions python/src/ReactionProduct.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void wrapReactionProduct( python::module& module, python::module& ) {
using Component = njoy::dryad::ReactionProduct;
using ParticleID = njoy::dryad::id::ParticleID;
using Multiplicity = njoy::dryad::ReactionProduct::Multiplicity;
using DistributionData = njoy::dryad::ReactionProduct::DistributionData;
using ToleranceConvergence = njoy::dryad::ToleranceConvergence;

// wrap views created by this component
Expand All @@ -36,7 +37,18 @@ void wrapReactionProduct( python::module& module, python::module& ) {
"Arguments:\n"
" self the reaction\n"
" id the reaction product identifier\n"
" multiplicity the multiplicity of the reaction product"
" multiplicity the reaction product multiplicity"
)
.def(

python::init< ParticleID, Multiplicity, DistributionData >(),
python::arg( "id" ), python::arg( "multiplicity" ), python::arg( "distribution" ),
"Initialise the reaction\n\n"
"Arguments:\n"
" self the reaction\n"
" id the reaction product identifier\n"
" multiplicity the reaction product multiplicity\n"
" distribution the reaction product distribution data"
)
.def_property_readonly(

Expand All @@ -50,11 +62,23 @@ void wrapReactionProduct( python::module& module, python::module& ) {
&Component::multiplicity,
"The multiplicity"
)
.def_property_readonly(

"distribution_data",
&Component::distributionData,
"The distribution data"
)
.def_property_readonly(

"is_linearised",
&Component::isLinearised,
"Flag indicating whether or not the data is linearised"
"Flag indicating whether or not the reaction product is linearised"
)
.def_property_readonly(

"has_distribution_data",
&Component::hasDistributionData,
"Flag indicating whether or not the reaction product has distribution data"
)
.def(

Expand Down
31 changes: 31 additions & 0 deletions python/src/ReferenceFrame.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// local includes
#include "dryad/ReferenceFrame.hpp"

// namespace aliases
namespace python = pybind11;

void wrapReferenceFrame( python::module& module, python::module& ) {

// type aliases
using Component = njoy::dryad::ReferenceFrame;

// wrap views created by this component

// create the component
python::enum_< Component > component(

module,
"ReferenceFrame",
"The reference frame used to describe data",
python::arithmetic()
);

// wrap the component
component
.value( "Laboratory", Component::Laboratory )
.value( "CentreOfMass", Component::CentreOfMass );
}
92 changes: 92 additions & 0 deletions python/src/TabulatedAngularDistributions.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>

// local includes
#include "definitions.hpp"
#include "dryad/TabulatedAngularDistributions.hpp"

// namespace aliases
namespace python = pybind11;

void wrapTabulatedAngularDistributions( python::module& module, python::module& ) {

// type aliases
using Component = njoy::dryad::TabulatedAngularDistributions;
using TabulatedAngularDistribution = njoy::dryad::TabulatedAngularDistribution;
using InterpolationType = njoy::dryad::InterpolationType;
using ToleranceConvergence = njoy::dryad::ToleranceConvergence;

// wrap views created by this component

// create the component
python::class_< Component > component(

module,
"TabulatedAngularDistributions",
"Angular distribution data given as tables"
);

// wrap the component
component
.def(

python::init< std::vector< double >,
std::vector< TabulatedAngularDistribution >,
std::vector< std::size_t >,
std::vector< InterpolationType > >(),
python::arg( "grid" ), python::arg( "distributions" ),
python::arg( "boundaries" ), python::arg( "interpolants" ),
"Initialise the angular distributions\n\n"
"Arguments:\n"
" self the angular distribution table\n"
" grid the grid values\n"
" distributions the distributions\n"
" boundaries the boundaries of the interpolation regions\n"
" interpolants the interpolation types of the interpolation regions,\n"
" see InterpolationType for all interpolation types"
)
.def(

python::init< std::vector< double >,
std::vector< TabulatedAngularDistribution >,
InterpolationType >(),
python::arg( "grid" ), python::arg( "distributions" ),
python::arg( "interpolant" ) = InterpolationType::LinearLinear,
"Initialise the angular distributions\n\n"
"Arguments:\n"
" self the multiplicity table\n"
" grid the grid values\n"
" distributions the distributions\n"
" interpolant the interpolation type (default lin-lin),\n"
" see InterpolationType for all interpolation types"
)
.def_property_readonly(

"grid",
&Component::grid,
"The grid values for which distributions are given"
)
.def_property_readonly(

"distributions",
&Component::distributions,
"The associated distributions"
)
.def(

"__call__",
[] ( const Component& self, double value, double cosine ) -> decltype(auto)
{ return self( value, cosine ); },
python::arg( "value" ), python::arg( "cosine" ),
"Evaluate the angular distributions\n\n"
"Arguments:\n"
" self the table\n"
" value the grid value\n"
" cosine the cosine value"
);

// add standard tabulated data definitions
addStandardInterpolationTableDefinitions< Component >( component );
}
Loading