Skip to content

Commit 0964ad0

Browse files
committed
Add python bindings
1 parent 177ef05 commit 0964ad0

8 files changed

Lines changed: 199 additions & 6 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ if(ACEtk.python)
168168
python/src/block/PhotoatomicSubshellTransitionData.python.cpp
169169
python/src/block/PhotoatomicSubshellTransitionDataBlock.python.cpp
170170
python/src/block/ElectronTabulatedAngularDistribution.python.cpp
171+
python/src/block/ElectronElasticAngularDistributionBlock.python.cpp
171172
python/src/ContinuousEnergyTable.python.cpp
172173
python/src/DosimetryTable.python.cpp
173174
python/src/ThermalScatteringTable.python.cpp

‎python/src/ACEtk.python.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ namespace block {
110110
void wrapPhotoatomicElectronBremsstrahlungBlock( python::module&, python::module& );
111111
void wrapPhotoelectricCrossSectionBlock( python::module&, python::module& );
112112
void wrapPhotoatomicSubshellTransitionDataBlock( python::module&, python::module& );
113+
void wrapElectronElasticAngularDistributionBlock( python::module&, python::module& );
113114
}
114115

115116
// declarations - ACE table types
@@ -246,6 +247,7 @@ PYBIND11_MODULE( ACEtk, module ) {
246247
block::wrapPhotoatomicElectronBremsstrahlungBlock( module, viewmodule );
247248
block::wrapPhotoelectricCrossSectionBlock( module, viewmodule );
248249
block::wrapPhotoatomicSubshellTransitionDataBlock( module, viewmodule );
250+
block::wrapElectronElasticAngularDistributionBlock( module, viewmodule );
249251

250252
// wrap ACE table types
251253
wrapContinuousEnergyTable( module, viewmodule );
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// system includes
2+
#include <pybind11/pybind11.h>
3+
#include <pybind11/stl.h>
4+
5+
// local includes
6+
#include "ACEtk/block/ElectronElasticAngularDistributionBlock.hpp"
7+
#include "views.hpp"
8+
#include "definitions.hpp"
9+
10+
// namespace aliases
11+
namespace python = pybind11;
12+
13+
namespace block {
14+
15+
void wrapElectronElasticAngularDistributionBlock( python::module& module, python::module& ) {
16+
17+
// type aliases
18+
using Block = njoy::ACEtk::block::ElectronElasticAngularDistributionBlock;
19+
using ElectronTabulatedAngularDistribution = njoy::ACEtk::block::ElectronTabulatedAngularDistribution;
20+
21+
// wrap views created by this block
22+
23+
// create the block
24+
python::class_< Block > block(
25+
26+
module,
27+
"ElectronElasticAngularDistributionBlock",
28+
"The photoatomic and electron ELASI and ELAS block with the elastic scattering\n"
29+
"angular distribution data\n\n"
30+
"The ElectronElasticAngularDistributionBlock class a list of electron energies\n"
31+
"for which angular distribution data is given."
32+
);
33+
34+
// wrap the block
35+
block
36+
.def(
37+
38+
python::init< std::vector< ElectronTabulatedAngularDistribution > >(),
39+
python::arg( "distributions" ),
40+
"Initialise the block\n\n"
41+
"Arguments:\n"
42+
" self the block\n"
43+
" distributions the angular distribution data"
44+
)
45+
.def_property_readonly(
46+
47+
"NA",
48+
&Block::NA,
49+
"The number of available energies"
50+
)
51+
.def_property_readonly(
52+
53+
"number_energy_points",
54+
&Block::numberEnergyPoints,
55+
"The number of available energies"
56+
)
57+
.def(
58+
59+
"LAND",
60+
&Block::LAND,
61+
python::arg( "index" ),
62+
"Return the relative angular distribution locator for an energy index\n\n"
63+
"When the index is out of range an out of range exception is thrown\n"
64+
"(debug mode only).\n\n"
65+
" self the block\n"
66+
" index the index (one-based)"
67+
)
68+
.def(
69+
70+
"angular_distribution_locator",
71+
&Block::angularDistributionLocator,
72+
python::arg( "index" ),
73+
"Return the relative angular distribution locator for an energy index\n\n"
74+
"When the index is out of range an out of range exception is thrown\n"
75+
"(debug mode only).\n\n"
76+
" self the block\n"
77+
" index the index (one-based)"
78+
)
79+
.def_property_readonly(
80+
81+
"energies",
82+
[] ( const Block& self ) -> DoubleRange
83+
{ return self.energies(); },
84+
"The energy values"
85+
)
86+
.def_property_readonly(
87+
88+
"data",
89+
&Block::data,
90+
"The angular distribution data"
91+
)
92+
.def(
93+
94+
"angular_distribution",
95+
&Block::angularDistribution,
96+
python::arg( "index" ),
97+
"Return the angular distribution for an energy index\n\n"
98+
"When the index is out of range an out of range exception is thrown\n"
99+
"(debug mode only).\n\n"
100+
" self the block\n"
101+
" index the index (one-based)"
102+
);
103+
104+
// add standard block definitions
105+
addStandardBlockDefinitions< Block >( block );
106+
}
107+
108+
} // block namespace

‎python/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ add_test( NAME ACEtk.python.block.PhotonuclearSecondaryParticleLocatorBlock COMM
8080
add_test( NAME ACEtk.python.block.PhotoatomicSubshellTransitionData COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicSubshellTransitionData.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
8181
add_test( NAME ACEtk.python.block.PhotoatomicSubshellTransitionDataBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicSubshellTransitionDataBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
8282
add_test( NAME ACEtk.python.block.ElectronTabulatedAngularDistribution COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_ElectronTabulatedAngularDistribution.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
83+
add_test( NAME ACEtk.python.block.ElectronElasticAngularDistributionBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_ElectronElasticAngularDistributionBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# standard imports
2+
import unittest
3+
4+
# third party imports
5+
6+
# local imports
7+
from ACEtk import ElectronElasticAngularDistributionBlock
8+
from ACEtk import ElectronTabulatedAngularDistribution
9+
10+
class Test_ACEtk_ElectronElasticAngularDistributionBlock( unittest.TestCase ) :
11+
"""Unit test for the ElectronElasticAngularDistributionBlock class."""
12+
13+
chunk = [ 1e-11, 1e-6, 1e-3, 1.,
14+
2, 3, 4, 2,
15+
0, 4, 10, 18,
16+
-1.0, 1.0, 0., 1.,
17+
-1.0, 0.0, 1.0, 0., 0.75, 1.,
18+
-1.0, 0.5, 0.7, 1.0, 0., 0.25, 0.5, 1.,
19+
-1.0, 1.0, 0., 1. ]
20+
21+
def test_component( self ) :
22+
23+
def verify_chunk( self, chunk ) :
24+
25+
# verify content
26+
self.assertEqual( False, chunk.empty )
27+
self.assertEqual( 34, chunk.length )
28+
self.assertEqual( "ELAS", chunk.name )
29+
30+
self.assertEqual( 4, chunk.NA )
31+
self.assertEqual( 4, chunk.number_energy_points )
32+
self.assertEqual( 4, len( chunk.energies ) )
33+
self.assertEqual( 4, len( chunk.data ) )
34+
35+
self.assertEqual( 1, chunk.LAND(1) )
36+
self.assertEqual( 5, chunk.LAND(2) )
37+
self.assertEqual( 11, chunk.LAND(3) )
38+
self.assertEqual( 19, chunk.LAND(4) )
39+
self.assertEqual( 1, chunk.angular_distribution_locator(1) )
40+
self.assertEqual( 5, chunk.angular_distribution_locator(2) )
41+
self.assertEqual( 11, chunk.angular_distribution_locator(3) )
42+
self.assertEqual( 19, chunk.angular_distribution_locator(4) )
43+
44+
distribution = chunk.angular_distribution(1)
45+
self.assertEqual( 1e-11, distribution.energy )
46+
self.assertEqual( 2, distribution.number_cosines )
47+
48+
distribution = chunk.angular_distribution(2)
49+
self.assertEqual( 1e-6, distribution.energy )
50+
self.assertEqual( 3, distribution.number_cosines )
51+
52+
distribution = chunk.angular_distribution(3)
53+
self.assertEqual( 1e-3, distribution.energy )
54+
self.assertEqual( 4, distribution.number_cosines )
55+
56+
distribution = chunk.angular_distribution(4)
57+
self.assertEqual( 1., distribution.energy )
58+
self.assertEqual( 2, distribution.number_cosines )
59+
60+
# verify the distributions array
61+
xss = chunk.xss_array
62+
for index in range( chunk.length ) :
63+
64+
self.assertAlmostEqual( self.chunk[index], xss[index] )
65+
66+
# the data is given explicitly
67+
chunk = ElectronElasticAngularDistributionBlock(
68+
distributions = [
69+
ElectronTabulatedAngularDistribution( 1e-11, [ -1.0, 1.0 ], [ 0., 1. ] ),
70+
ElectronTabulatedAngularDistribution( 1e-6, [ -1.0, 0.0, 1.0 ], [ 0., 0.75, 1. ] ),
71+
ElectronTabulatedAngularDistribution( 1e-3, [ -1.0, 0.5, 0.7, 1.0 ], [ 0., 0.25, 0.5, 1. ] ),
72+
ElectronTabulatedAngularDistribution( 1., [ -1.0, 1.0 ], [ 0., 1. ] ) ] )
73+
74+
verify_chunk( self, chunk )
75+
76+
if __name__ == '__main__' :
77+
78+
unittest.main()

‎src/ACEtk/block/ElectronElasticAngularDistributionBlock.hpp‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ namespace block {
1313

1414
/**
1515
* @class
16-
* @brief The continuous energy LSIG and SIG block with the cross section data
16+
* @brief The photoatomic and electron ELASI and ELAS block with the
17+
* elastic scattering angular distribution data
1718
*
18-
* The CrossSectionBlock class contains NXS(4) sets of cross section values,
19-
* one for each reaction number on the MTR block. The order of these cross
20-
* section data sets is the same as the order of the reaction numbers in the
21-
* MTR block.
19+
* The ElectronElasticAngularDistributionBlock class a list of electron energies
20+
* for which angular distribution data is given.
2221
*/
2322
class ElectronElasticAngularDistributionBlock :
2423
protected details::BaseElectronBlockWithLocators<

‎src/ACEtk/block/ElectronElasticAngularDistributionBlock/src/ctor.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ElectronElasticAngularDistributionBlock( ElectronElasticAngularDistributionBlock
66
/**
77
* @brief Constructor
88
*
9-
* @param[in] xs the cross section data
9+
* @param[in] distributions the angular distribution data
1010
*/
1111
ElectronElasticAngularDistributionBlock( std::vector< ElectronTabulatedAngularDistribution > distributions ) :
1212
BaseElectronBlockWithLocators( "ELAS", std::move( distributions ) ) {}

‎src/ACEtk/block/ElectronElasticAngularDistributionBlock/test/ElectronElasticAngularDistributionBlock.test.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ void verifyChunk( const ElectronElasticAngularDistributionBlock& chunk ) {
102102
CHECK( 19 == chunk.angularDistributionLocator(4) );
103103

104104
auto distribution = chunk.angularDistribution(1);
105+
CHECK( 1e-11 == distribution.energy() );
105106
CHECK( 2 == distribution.numberCosines() );
106107

107108
distribution = chunk.angularDistribution(2);
109+
CHECK( 1e-6 == distribution.energy() );
108110
CHECK( 3 == distribution.numberCosines() );
109111

110112
distribution = chunk.angularDistribution(3);
113+
CHECK( 1e-3 == distribution.energy() );
111114
CHECK( 4 == distribution.numberCosines() );
112115

113116
distribution = chunk.angularDistribution(4);
117+
CHECK( 1. == distribution.energy() );
114118
CHECK( 2 == distribution.numberCosines() );
115119
}

0 commit comments

Comments
 (0)