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 part4 #9

Merged
merged 3 commits into from
Oct 19, 2024
Merged
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if( dryad.python )
python/src/ReferenceFrame.python.cpp
python/src/TabulatedCrossSection.python.cpp
python/src/TabulatedMultiplicity.python.cpp
python/src/TabulatedAverageEnergy.python.cpp
python/src/LegendreAngularDistribution.python.cpp
python/src/LegendreAngularDistributions.python.cpp
python/src/TabulatedAngularDistribution.python.cpp
Expand Down
1 change: 1 addition & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endfunction()
add_subdirectory( src/dryad/id/ElementID/test )

add_subdirectory( src/dryad/TabulatedMultiplicity/test )
add_subdirectory( src/dryad/TabulatedAverageEnergy/test )
add_subdirectory( src/dryad/LegendreAngularDistribution/test )
add_subdirectory( src/dryad/LegendreAngularDistributions/test )
add_subdirectory( src/dryad/TabulatedAngularDistribution/test )
Expand Down
1 change: 1 addition & 0 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ message( STATUS "Adding dryad Python unit testing" )
add_python_test( id.ElementID id/Test_dryad_id_ElementID.py )

add_python_test( TabulatedMultiplicity Test_dryad_TabulatedMultiplicity.py )
add_python_test( TabulatedAverageEnergy Test_dryad_TabulatedAverageEnergy.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 )
Expand Down
13 changes: 13 additions & 0 deletions python/src/ReactionProduct.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ void wrapReactionProduct( python::module& module, python::module& ) {
&Component::multiplicity,
"The multiplicity"
)
.def_property_readonly(

"average_energy",
&Component::averageEnergy,
"The average reaction product energy"
)
.def_property_readonly(

"distribution_data",
Expand All @@ -74,6 +80,13 @@ void wrapReactionProduct( python::module& module, python::module& ) {
&Component::isLinearised,
"Flag indicating whether or not the reaction product is linearised"
)
.def_property_readonly(

"has_average_energy",
&Component::hasAverageEnergy,
"Flag indicating whether or not the reaction product has average reaction "
"product energy data"
)
.def_property_readonly(

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

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

// namespace aliases
namespace python = pybind11;

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

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

// wrap views created by this component

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

module,
"TabulatedAverageEnergy",
"An average reaction product energy table"
);

// wrap the component
component
.def(

python::init< std::vector< double >, std::vector< double >,
std::vector< std::size_t >,
std::vector< InterpolationType > >(),
python::arg( "energies" ), python::arg( "values" ),
python::arg( "boundaries" ), python::arg( "interpolants" ),
"Initialise the average reaction product energy table\n\n"
"Arguments:\n"
" self the average reaction product energy table\n"
" energies the energy values\n"
" values the average energy values\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< double >,
InterpolationType >(),
python::arg( "energies" ), python::arg( "values" ),
python::arg( "interpolant" ) = InterpolationType::LinearLinear,
"Initialise the average reaction product energy table\n\n"
"Arguments:\n"
" self the average reaction product energy table\n"
" energies the energy values\n"
" values the average energy values\n"
" interpolant the interpolation type (default lin-lin),\n"
" see InterpolationType for all interpolation types"
)
.def_property_readonly(

"energies",
&Component::energies,
"The energy values"
)
.def_property_readonly(

"values",
&Component::values,
"The average energy values"
)
.def_property_readonly(

"lower_energy_limit",
&Component::lowerEnergyLimit,
"The lower energy limit"
)
.def_property_readonly(

"upper_energy_limit",
&Component::upperEnergyLimit,
"The upper energy limit"
)
.def(

"__call__",
[] ( const Component& self, double energy ) -> decltype(auto)
{ return self( energy ); },
python::arg( "energy" ),
"Evaluate the table for a given energy value\n\n"
"Arguments:\n"
" self the table\n"
" energy the energy value"
);

// add standard tabulated data definitions
addStandardTabulatedDefinitions< Component >( component );
}
2 changes: 2 additions & 0 deletions python/src/dryad.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void wrapTabulatedEnergyDistribution( python::module&, python::module& );
void wrapTabulatedEnergyDistributions( python::module&, python::module& );
void wrapTabulatedCrossSection( python::module&, python::module& );
void wrapTabulatedMultiplicity( python::module&, python::module& );
void wrapTabulatedAverageEnergy( python::module&, python::module& );
void wrapReactionProduct( python::module&, python::module& );
void wrapReaction( python::module&, python::module& );
void wrapProjectileTarget( python::module&, python::module& );
Expand Down Expand Up @@ -61,6 +62,7 @@ PYBIND11_MODULE( dryad, module ) {

// wrap components - reaction products
wrapTabulatedMultiplicity( module, viewmodule );
wrapTabulatedAverageEnergy( module, viewmodule );
wrapLegendreAngularDistribution( module, viewmodule );
wrapLegendreAngularDistributions( module, viewmodule );
wrapTabulatedAngularDistribution( module, viewmodule );
Expand Down
12 changes: 12 additions & 0 deletions python/test/Test_dryad_ReactionProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ def verify_chunk( self, chunk ) :
self.assertEqual( True, isinstance( chunk.multiplicity, int ) )
self.assertEqual( 1, chunk.multiplicity )

# average reaction product energy
self.assertEqual( None, chunk.average_energy )

# distribution data
self.assertEqual( None, chunk.distribution_data )

# metadata
self.assertEqual( True, chunk.is_linearised )
self.assertEqual( False, chunk.has_average_energy )
self.assertEqual( False, chunk.has_distribution_data )

def verify_tabulated_chunk( self, chunk ) :
Expand Down Expand Up @@ -60,11 +64,15 @@ def verify_tabulated_chunk( self, chunk ) :
self.assertEqual( InterpolationType.LinearLog, chunk.multiplicity.interpolants[1] )
self.assertEqual( False, chunk.multiplicity.is_linearised )

# average reaction product energy
self.assertEqual( None, chunk.average_energy )

# distribution data
self.assertEqual( None, chunk.distribution_data )

# metadata
self.assertEqual( False, chunk.is_linearised )
self.assertEqual( False, chunk.has_average_energy )
self.assertEqual( False, chunk.has_distribution_data )

def verify_tabulated_linearised_chunk( self, chunk ) :
Expand Down Expand Up @@ -110,11 +118,15 @@ def verify_tabulated_linearised_chunk( self, chunk ) :
self.assertEqual( InterpolationType.LinearLinear, chunk.multiplicity.interpolants[1] )
self.assertEqual( True, chunk.multiplicity.is_linearised )

# average reaction product energy
self.assertEqual( None, chunk.average_energy )

# distribution data
self.assertEqual( None, chunk.distribution_data )

# metadata
self.assertEqual( True, chunk.is_linearised )
self.assertEqual( False, chunk.has_average_energy )
self.assertEqual( False, chunk.has_distribution_data )

# the data is given explicitly using an integer multiplicity
Expand Down
Loading