Skip to content

Commit

Permalink
Adding python test for TabulatedAngularDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Jul 18, 2024
1 parent d7b29a0 commit 951ceae
Show file tree
Hide file tree
Showing 8 changed files with 1,615 additions and 34 deletions.
11 changes: 6 additions & 5 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ message( STATUS "Adding dryad Python unit testing" )

add_python_test( id.ElementID id/Test_dryad_id_ElementID.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( TabulatedAngularDistribution Test_dryad_TabulatedAngularDistribution.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 )
11 changes: 11 additions & 0 deletions python/src/TabulatedAngularDistribution.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ void wrapTabulatedAngularDistribution( python::module& module, python::module& )
"upper_cosine_limit",
&Component::upperCosineLimit,
"The upper cosine limit"
)
.def(

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

// add standard tabulated data definitions
Expand Down
11 changes: 11 additions & 0 deletions python/src/TabulatedCrossSection.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ void wrapTabulatedCrossSection( python::module& module, python::module& ) {
"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
Expand Down
11 changes: 11 additions & 0 deletions python/src/TabulatedMultiplicity.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ void wrapTabulatedMultiplicity( python::module& module, python::module& ) {
"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
Expand Down
11 changes: 0 additions & 11 deletions python/src/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ void addStandardTabulatedDefinitions( PythonClass& table ) {
using ToleranceConvergence = njoy::dryad::ToleranceConvergence;

table
.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"
)
.def(

"linearise",
Expand Down
2 changes: 2 additions & 0 deletions python/src/dryad.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void wrapReactionType( python::module&, python::module& );
void wrapID( python::module&, python::module& );

// declarations - components
void wrapTabulatedAngularDistribution( python::module&, python::module& );
void wrapTabulatedCrossSection( python::module&, python::module& );
void wrapTabulatedMultiplicity( python::module&, python::module& );
void wrapReactionProduct( python::module&, python::module& );
Expand Down Expand Up @@ -50,6 +51,7 @@ PYBIND11_MODULE( dryad, module ) {
wrapID( module, viewmodule );

// wrap components
wrapTabulatedAngularDistribution( module, viewmodule );
wrapTabulatedCrossSection( module, viewmodule );
wrapTabulatedMultiplicity( module, viewmodule );
wrapReactionProduct( module, viewmodule );
Expand Down
1,555 changes: 1,555 additions & 0 deletions python/test/Test_dryad_TabulatedAngularDistribution.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ SCENARIO( "TabulatedAngularDistribution" ) {
// values of x in the x grid
CHECK_THAT( 0. , WithinRel( chunk( -1. ) ) );
CHECK_THAT( 0.5, WithinRel( chunk( 0. ) ) );
CHECK_THAT( 0.75, WithinRel( chunk( 0.5 ) ) );
CHECK_THAT( 1. , WithinRel( chunk( 1. ) ) );

// values of x outside the x grid
CHECK_THAT( 0., WithinRel( chunk( -5. ) ) );
CHECK_THAT( 0., WithinRel( chunk( 5. ) ) );

// values of x inside the x grid
CHECK_THAT( 0.25, WithinRel( chunk( -0.5 ) ) );
CHECK_THAT( 0.75, WithinRel( chunk( 0.5 ) ) );
CHECK_THAT( 0.25 , WithinRel( chunk( -0.5 ) ) );
CHECK_THAT( 0.875, WithinRel( chunk( 0.75 ) ) );
} // THEN

THEN( "arithmetic operations can be performed" ) {
Expand Down Expand Up @@ -857,11 +858,11 @@ SCENARIO( "TabulatedAngularDistribution" ) {
CHECK_THAT( 0. , WithinRel( result.cosines()[2] ) );
CHECK_THAT( 0.5, WithinRel( result.cosines()[3] ) );
CHECK_THAT( 1. , WithinRel( result.cosines()[4] ) );
CHECK_THAT( -2., WithinRel( result.values()[0] ) );
CHECK_THAT( -1., WithinRel( result.values()[1] ) );
CHECK_THAT( -2., WithinRel( result.values()[2] ) );
CHECK_THAT( -1., WithinRel( result.values()[3] ) );
CHECK_THAT( 0., WithinRel( result.values()[4] ) );
CHECK_THAT( -2. , WithinRel( result.values()[0] ) );
CHECK_THAT( -1. , WithinRel( result.values()[1] ) );
CHECK_THAT( -2. , WithinRel( result.values()[2] ) );
CHECK_THAT( -1. , WithinRel( result.values()[3] ) );
CHECK_THAT( 0. , WithinRel( result.values()[4] ) );
CHECK( 1 == result.boundaries()[0] );
CHECK( 4 == result.boundaries()[1] );
CHECK( InterpolationType::LinearLinear == result.interpolants()[0] );
Expand Down Expand Up @@ -962,11 +963,11 @@ SCENARIO( "TabulatedAngularDistribution" ) {
CHECK_THAT( 0. , WithinRel( chunk.cosines()[2] ) );
CHECK_THAT( 0.5, WithinRel( chunk.cosines()[3] ) );
CHECK_THAT( 1. , WithinRel( chunk.cosines()[4] ) );
CHECK_THAT( 4., WithinRel( chunk.values()[0] ) );
CHECK_THAT( 3., WithinRel( chunk.values()[1] ) );
CHECK_THAT( 4., WithinRel( chunk.values()[2] ) );
CHECK_THAT( 3., WithinRel( chunk.values()[3] ) );
CHECK_THAT( 2., WithinRel( chunk.values()[4] ) );
CHECK_THAT( 4. , WithinRel( chunk.values()[0] ) );
CHECK_THAT( 3. , WithinRel( chunk.values()[1] ) );
CHECK_THAT( 4. , WithinRel( chunk.values()[2] ) );
CHECK_THAT( 3. , WithinRel( chunk.values()[3] ) );
CHECK_THAT( 2. , WithinRel( chunk.values()[4] ) );
CHECK( 1 == chunk.boundaries()[0] );
CHECK( 4 == chunk.boundaries()[1] );
CHECK( InterpolationType::LinearLinear == chunk.interpolants()[0] );
Expand Down Expand Up @@ -1582,11 +1583,11 @@ SCENARIO( "TabulatedAngularDistribution" ) {
CHECK( 5 == chunk.values().size() );
CHECK( 2 == chunk.boundaries().size() );
CHECK( 2 == chunk.interpolants().size() );
CHECK_THAT( -1. , WithinRel( chunk.cosines()[0] ) );
CHECK_THAT( 0. , WithinRel( chunk.cosines()[1] ) );
CHECK_THAT( 0. , WithinRel( chunk.cosines()[2] ) );
CHECK_THAT( 0.5, WithinRel( chunk.cosines()[3] ) );
CHECK_THAT( 1. , WithinRel( chunk.cosines()[4] ) );
CHECK_THAT( -1. , WithinRel( chunk.cosines()[0] ) );
CHECK_THAT( 0. , WithinRel( chunk.cosines()[1] ) );
CHECK_THAT( 0. , WithinRel( chunk.cosines()[2] ) );
CHECK_THAT( 0.5 , WithinRel( chunk.cosines()[3] ) );
CHECK_THAT( 1. , WithinRel( chunk.cosines()[4] ) );
CHECK_THAT( 0. , WithinRel( chunk.values()[0] ) );
CHECK_THAT( 0.5 , WithinRel( chunk.values()[1] ) );
CHECK_THAT( 1. , WithinRel( chunk.values()[2] ) );
Expand All @@ -1609,7 +1610,7 @@ SCENARIO( "TabulatedAngularDistribution" ) {
WHEN( "the data is given explicitly" ) {

const std::vector< double > x = { -1., 0., 0.5, 1., 1. }; // <-- jump at end
const std::vector< double > y = { 0., 0.5, 0.75, 1., 0.}; // <-- last value is zero
const std::vector< double > y = { 0., 0.5, 0.75, 1., 0. }; // <-- last value is zero
const std::vector< std::size_t > boundaries = { 1, 4 }; // <-- pointing to end
const std::vector< InterpolationType > interpolants = {

Expand Down

0 comments on commit 951ceae

Please sign in to comment.