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 part5 #10

Merged
merged 22 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ if( dryad.python )
python/src/TabulatedCrossSection.python.cpp
python/src/TabulatedMultiplicity.python.cpp
python/src/TabulatedAverageEnergy.python.cpp
python/src/IsotropicAngularDistributions.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/TwoBodyDistributionData.python.cpp
python/src/UncorrelatedDistributionData.python.cpp
python/src/ReactionProduct.python.cpp
python/src/Reaction.python.cpp
python/src/ProjectileTarget.python.cpp
Expand Down
4 changes: 2 additions & 2 deletions cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FetchContent_Declare( eigen

FetchContent_Declare( ENDFtk
GIT_REPOSITORY https://github.com/njoy/ENDFtk.git
GIT_TAG 3d077281d1ca862a3561cd0687de845239c9f463 # tag: v1.1.0
GIT_TAG 2a0aeda4642880148ce060f620e50378654d07c9
)

FetchContent_Declare( fast_float
Expand All @@ -42,7 +42,7 @@ FetchContent_Declare( range-v3

FetchContent_Declare( scion
GIT_REPOSITORY https://github.com/njoy/scion
GIT_TAG 6079dc15153b1948c772835096662be65b062676
GIT_TAG fd76c11780fcdde507f8952c8698085cf47b0369
)

FetchContent_Declare( spdlog
Expand Down
2 changes: 2 additions & 0 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ add_python_test( TabulatedAngularDistribution Test_dryad_TabulatedAngularDistri
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( TwoBodyDistributionData Test_dryad_TwoBodyDistributionData.py )
add_python_test( UncorrelatedDistributionData Test_dryad_UncorrelatedDistributionData.py )
add_python_test( ReactionProduct Test_dryad_ReactionProduct.py )

add_python_test( TabulatedCrossSection Test_dryad_TabulatedCrossSection.py )
Expand Down
35 changes: 35 additions & 0 deletions python/src/IsotropicAngularDistributions.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

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

// namespace aliases
namespace python = pybind11;

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

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

// wrap views created by this component

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

module,
"IsotropicAngularDistributions",
"The angular distribution data is fully isotropic"
);

// wrap the component
component
.def(

python::init<>(),
"Initialise the component\n\n"
"Arguments:\n"
" self the component"
);
}
67 changes: 67 additions & 0 deletions python/src/TwoBodyDistributionData.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

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

// namespace aliases
namespace python = pybind11;

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

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

// wrap views created by this component

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

module,
"TwoBodyDistributionData",
"The energy-angle distribution data for a two-body output channel\n\n"
"In this representation, only the angular distributions as a function of\n"
"incident energy is given and the outgoing particle's energy can be derived\n"
"through kinematics.\n\n"
"For incident neutron data, this corresponds with elastic and inelastic\n"
"scattering data given in MF4 (none of these will have corresponding MF5\n"
"data). In the more general MF6 representation, this corresponds with\n"
"LAW = 2 (discrete two-body scattering). This is also the representation for\n"
"elastic scattering data in MF26 for electro-atomic interactions."
);

// wrap the component
component
.def(

python::init< ReferenceFrame, AngularDistributions >(),
python::arg( "frame" ), python::arg( "angle" ),
"Initialise the reaction\n\n"
"Arguments:\n"
" self the reaction product distribution data\n"
" frame the reference frame of the distribution data\n"
" angle the angular distributions"
)
.def_property_readonly(

// static constexpr function needs lambda
"type",
[] ( const Component& self ) { return self.type(); },
"The distribution data type"
)
.def_property_readonly(

"frame",
&Component::frame,
"The reference frame"
)
.def_property_readonly(

"angle",
&Component::angle,
"The angular distributions"
);
}
76 changes: 76 additions & 0 deletions python/src/UncorrelatedDistributionData.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

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

// namespace aliases
namespace python = pybind11;

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

// type aliases
using Component = njoy::dryad::UncorrelatedDistributionData;
using ReferenceFrame = njoy::dryad::ReferenceFrame;
using AngularDistributions = Component::AngularDistributions;
using EnergyDistributions = Component::EnergyDistributions;

// wrap views created by this component

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

module,
"UncorrelatedDistributionData",
"Uncorrelated energy and angle distribution data for a reaction product\n\n"
"In this representation, there is no correlation given between the outgoing\n"
"angle and energy of the reaction product. As a result, the angular and energy\n"
"distributions of the reaction product depend only on the incident energy of the\n"
"projectile.\n\n"
"For incident neutron data, this is used for reactions that have both MF4 and MF5\n"
"data. For reaction products given in MF6, this corresponds to LAW = 1 (continuum\n"
"energy-angle distributions) in which the angular dependence is fully isotropic.\n"
"This is also the representation for Brehmstrahlung and excitation data in MF26\n"
"for electro-atomic interactions."
);

// wrap the component
component
.def(

python::init< ReferenceFrame, AngularDistributions, EnergyDistributions >(),
python::arg( "frame" ), python::arg( "angle" ), python::arg( "energy" ),
"Initialise the reaction\n\n"
"Arguments:\n"
" self the reaction product distribution data\n"
" frame the reference frame of the distribution data\n"
" angle the angular distributions\n"
" energy the energy distributions"
)
.def_property_readonly(

// static constexpr function needs lambda
"type",
[] ( const Component& self ) { return self.type(); },
"The distribution data type"
)
.def_property_readonly(

"frame",
&Component::frame,
"The reference frame"
)
.def_property_readonly(

"angle",
&Component::angle,
"The angular distributions"
)
.def_property_readonly(

"energy",
&Component::energy,
"The energy distributions"
);
}
6 changes: 6 additions & 0 deletions python/src/dryad.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void wrapReactionType( python::module&, python::module& );
void wrapReferenceFrame( python::module&, python::module& );

// declarations - components
void wrapIsotropicAngularDistributions( python::module&, python::module& );
void wrapLegendreAngularDistribution( python::module&, python::module& );
void wrapLegendreAngularDistributions( python::module&, python::module& );
void wrapTabulatedAngularDistribution( python::module&, python::module& );
Expand All @@ -26,6 +27,8 @@ 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 wrapTwoBodyDistributionData( python::module&, python::module& );
void wrapUncorrelatedDistributionData( 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 @@ -63,12 +66,15 @@ PYBIND11_MODULE( dryad, module ) {
// wrap components - reaction products
wrapTabulatedMultiplicity( module, viewmodule );
wrapTabulatedAverageEnergy( module, viewmodule );
wrapIsotropicAngularDistributions( module, viewmodule );
wrapLegendreAngularDistribution( module, viewmodule );
wrapLegendreAngularDistributions( module, viewmodule );
wrapTabulatedAngularDistribution( module, viewmodule );
wrapTabulatedAngularDistributions( module, viewmodule );
wrapTabulatedEnergyDistribution( module, viewmodule );
wrapTabulatedEnergyDistributions( module, viewmodule );
wrapTwoBodyDistributionData( module, viewmodule );
wrapUncorrelatedDistributionData( module, viewmodule );
wrapReactionProduct( module, viewmodule );

// wrap components - reactions
Expand Down
109 changes: 109 additions & 0 deletions python/test/Test_dryad_TwoBodyDistributionData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# standard imports
import unittest
import sys

# third party imports

# local imports
from dryad import TwoBodyDistributionData
from dryad import DistributionDataType
from dryad import ReferenceFrame
from dryad import InterpolationType
from dryad import IsotropicAngularDistributions
from dryad import LegendreAngularDistribution
from dryad import LegendreAngularDistributions
from dryad import TabulatedAngularDistribution
from dryad import TabulatedAngularDistributions

class Test_dryad_TwoBodyDistributionData( unittest.TestCase ) :
"""Unit test for the TwoBodyDistributionData class."""

def test_component( self ) :

def verify_isotropic_chunk( self, chunk ) :

self.assertEqual( DistributionDataType.TwoBody, chunk.type )
self.assertEqual( ReferenceFrame.CentreOfMass, chunk.frame )

self.assertEqual( True, isinstance( chunk.angle, IsotropicAngularDistributions ) )

def verify_legendre_chunk( self, chunk ) :

self.assertEqual( DistributionDataType.TwoBody, chunk.type )
self.assertEqual( ReferenceFrame.CentreOfMass, chunk.frame )

self.assertEqual( True, isinstance( chunk.angle, LegendreAngularDistributions ) )

self.assertEqual( 2, chunk.angle.number_points )
self.assertEqual( 1, chunk.angle.number_regions )
self.assertEqual( 2, len( chunk.angle.grid ) )
self.assertEqual( 2, len( chunk.angle.distributions ) )
self.assertEqual( 1, len( chunk.angle.boundaries ) )
self.assertEqual( 1, len( chunk.angle.interpolants ) )
self.assertAlmostEqual( 1e-5, chunk.angle.grid[0] )
self.assertAlmostEqual( 20. , chunk.angle.grid[1] )
self.assertEqual( 1, len( chunk.angle.distributions[0].coefficients ) )
self.assertEqual( 2, len( chunk.angle.distributions[1].coefficients ) )
self.assertAlmostEqual( 0.5 , chunk.angle.distributions[0].coefficients[0] )
self.assertAlmostEqual( 0.5 , chunk.angle.distributions[1].coefficients[0] )
self.assertAlmostEqual( 0.1, chunk.angle.distributions[1].coefficients[1] )
self.assertEqual( 1, chunk.angle.boundaries[0] )
self.assertEqual( InterpolationType.LinearLinear, chunk.angle.interpolants[0] )

def verify_tabulated_chunk( self, chunk ) :

self.assertEqual( DistributionDataType.TwoBody, chunk.type )
self.assertEqual( ReferenceFrame.CentreOfMass, chunk.frame )

self.assertEqual( True, isinstance( chunk.angle, TabulatedAngularDistributions ) )

self.assertEqual( 2, chunk.angle.number_points )
self.assertEqual( 1, chunk.angle.number_regions )
self.assertEqual( 2, len( chunk.angle.grid ) )
self.assertEqual( 2, len( chunk.angle.distributions ) )
self.assertEqual( 1, len( chunk.angle.boundaries ) )
self.assertEqual( 1, len( chunk.angle.interpolants ) )
self.assertAlmostEqual( 1e-5, chunk.angle.grid[0] )
self.assertAlmostEqual( 20. , chunk.angle.grid[1] )
self.assertEqual( 2, len( chunk.angle.distributions[0].cosines ) )
self.assertEqual( 2, len( chunk.angle.distributions[0].values ) )
self.assertEqual( 2, len( chunk.angle.distributions[1].cosines ) )
self.assertEqual( 2, len( chunk.angle.distributions[1].values ) )
self.assertAlmostEqual( -1. , chunk.angle.distributions[0].cosines[0] )
self.assertAlmostEqual( 1. , chunk.angle.distributions[0].cosines[1] )
self.assertAlmostEqual( 0.5 , chunk.angle.distributions[0].values[0] )
self.assertAlmostEqual( 0.5 , chunk.angle.distributions[0].values[1] )
self.assertAlmostEqual( -1. , chunk.angle.distributions[1].cosines[0] )
self.assertAlmostEqual( 1. , chunk.angle.distributions[1].cosines[1] )
self.assertAlmostEqual( 0.4 , chunk.angle.distributions[1].values[0] )
self.assertAlmostEqual( 0.6 , chunk.angle.distributions[1].values[1] )
self.assertEqual( 1, chunk.angle.boundaries[0] )
self.assertEqual( InterpolationType.LinearLinear, chunk.angle.interpolants[0] )

# the data is given explicitly for isotropic distributions
chunk = TwoBodyDistributionData( frame = ReferenceFrame.CentreOfMass,
angle = IsotropicAngularDistributions() )

verify_isotropic_chunk( self, chunk )

# the data is given explicitly for Legendre distributions
chunk = TwoBodyDistributionData( frame = ReferenceFrame.CentreOfMass,
angle = LegendreAngularDistributions(
[ 1e-5, 20. ],
[ LegendreAngularDistribution( [ 0.5 ] ),
LegendreAngularDistribution( [ 0.5, 0.1 ] ) ] ) )

verify_legendre_chunk( self, chunk )

# the data is given explicitly for tabulated distributions
chunk = TwoBodyDistributionData( frame = ReferenceFrame.CentreOfMass,
angle = TabulatedAngularDistributions(
[ 1e-5, 20. ],
[ TabulatedAngularDistribution( [ -1., +1. ], [ 0.5, 0.5 ] ),
TabulatedAngularDistribution( [ -1., +1. ], [ 0.4, 0.6 ] ) ] ) )

verify_tabulated_chunk( self, chunk )

if __name__ == '__main__' :

unittest.main()
Loading