Skip to content

Commit b9792ef

Browse files
committed
Adding the python bindings
1 parent a6d1545 commit b9792ef

7 files changed

Lines changed: 141 additions & 4 deletions

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ if(ACEtk.python)
163163
python/src/block/PhotoatomicElectronSubshellBlock.python.cpp
164164
python/src/block/PhotoatomicElectronCrossSectionBlock.python.cpp
165165
python/src/block/PhotoatomicElectronExcitationBlock.python.cpp
166+
python/src/block/PhotoatomicElectronBremsstrahlungBlock.python.cpp
166167
python/src/ContinuousEnergyTable.python.cpp
167168
python/src/DosimetryTable.python.cpp
168169
python/src/ThermalScatteringTable.python.cpp

‎cmake/unit_testing.cmake‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ add_subdirectory( src/ACEtk/block/PhotonuclearPrincipalCrossSectionBlock/test )
9393
add_subdirectory( src/ACEtk/block/PhotonuclearSecondaryParticleLocatorBlock/test )
9494
add_subdirectory( src/ACEtk/block/PhotoatomicElectronCrossSectionBlock/test )
9595
add_subdirectory( src/ACEtk/block/PhotoatomicElectronExcitationBlock/test )
96+
add_subdirectory( src/ACEtk/block/PhotoatomicElectronBremsstrahlungBlock/test )
9697
add_subdirectory( src/ACEtk/details/verify/CDF/test )
9798
add_subdirectory( src/ACEtk/details/verify/Positive/test )
9899
add_subdirectory( src/ACEtk/details/verify/Sorted/test )

‎python/src/ACEtk.python.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace block {
105105
void wrapPhotoatomicElectronSubshellBlock( python::module&, python::module& );
106106
void wrapPhotoatomicElectronCrossSectionBlock( python::module&, python::module& );
107107
void wrapPhotoatomicElectronExcitationBlock( python::module&, python::module& );
108+
void wrapPhotoatomicElectronBremsstrahlungBlock( python::module&, python::module& );
108109
}
109110

110111
// declarations - ACE table types
@@ -236,6 +237,7 @@ PYBIND11_MODULE( ACEtk, module ) {
236237
block::wrapPhotoatomicElectronSubshellBlock( module, viewmodule );
237238
block::wrapPhotoatomicElectronCrossSectionBlock( module, viewmodule );
238239
block::wrapPhotoatomicElectronExcitationBlock( module, viewmodule );
240+
block::wrapPhotoatomicElectronBremsstrahlungBlock( module, viewmodule );
239241

240242
// wrap ACE table types
241243
wrapContinuousEnergyTable( module, viewmodule );
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// system includes
2+
#include <pybind11/pybind11.h>
3+
#include <pybind11/stl.h>
4+
5+
// local includes
6+
#include "ACEtk/block/PhotoatomicElectronBremsstrahlungBlock.hpp"
7+
#include "views.hpp"
8+
#include "definitions.hpp"
9+
10+
// namespace aliases
11+
namespace python = pybind11;
12+
13+
namespace block {
14+
15+
void wrapPhotoatomicElectronBremsstrahlungBlock( python::module& module, python::module& ) {
16+
17+
// type aliases
18+
using Block = njoy::ACEtk::block::PhotoatomicElectronBremsstrahlungBlock;
19+
20+
// wrap views created by this block
21+
22+
// create the block
23+
python::class_< Block > block(
24+
25+
module,
26+
"PhotoatomicElectronBremsstrahlungBlock",
27+
"The photoatomic BREML block with the average electron energy after Bremsstrahlung\n\n"
28+
"This block is part of the eprdata formats.\n\n"
29+
"The PhotoatomicElectronBremsstrahlungBlock class contains 2 arrays of the same\n"
30+
"length:\n"
31+
" - the energy points\n"
32+
" - the average energy remaining after Bremsstrahlung\n\n"
33+
"The size NBL of each (the total number of energy points) is stored in NXS(12)."
34+
);
35+
36+
// wrap the block
37+
block
38+
.def(
39+
40+
python::init< std::vector< double >, std::vector< double > >(),
41+
python::arg( "energies" ), python::arg( "remaining" ),
42+
"Initialise the block\n\n"
43+
"Arguments:\n"
44+
" self the block\n"
45+
" energies the energy values\n"
46+
" remaining the average energy remaining after Bremsstrahlung"
47+
)
48+
.def_property_readonly(
49+
50+
"NBL",
51+
&Block::NBL,
52+
"The number of energy points"
53+
)
54+
.def_property_readonly(
55+
56+
"number_energy_points",
57+
&Block::numberEnergyPoints,
58+
"The number of energy points"
59+
)
60+
.def_property_readonly(
61+
62+
"energies",
63+
[] ( const Block& self ) -> DoubleRange
64+
{ return self.energies(); },
65+
"The energy values"
66+
)
67+
.def_property_readonly(
68+
69+
"energy_after_bremsstrahlung",
70+
[] ( const Block& self ) -> DoubleRange
71+
{ return self.energyAfterBremsstrahlung(); },
72+
"The average energy remaining after Bremsstrahlung"
73+
);
74+
75+
// add standard block definitions
76+
addStandardBlockDefinitions< Block >( block );
77+
}
78+
79+
} // block namespace

‎python/test/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ add_test( NAME ACEtk.python.block.PhotoatomicElectronShellBlock COMMAND ${PYTHON
7373
add_test( NAME ACEtk.python.block.PhotoatomicElectronSubshellBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicElectronSubshellBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
7474
add_test( NAME ACEtk.python.block.PhotoatomicElectronCrossSectionBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicElectronCrossSectionBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
7575
add_test( NAME ACEtk.python.block.PhotoatomicElectronExcitationBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicElectronExcitationBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
76+
add_test( NAME ACEtk.python.block.PhotoatomicElectronBremsstrahlungBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotoatomicElectronExcitationBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
7677
add_test( NAME ACEtk.python.block.PhotonuclearPrincipalCrossSectionBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotonuclearPrincipalCrossSectionBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
7778
add_test( NAME ACEtk.python.block.PhotonuclearSecondaryParticleLocatorBlock COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/block/Test_ACEtk_PhotonuclearSecondaryParticleLocatorBlock.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
78-
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# standard imports
2+
import unittest
3+
4+
# third party imports
5+
6+
# local imports
7+
from ACEtk import PhotoatomicElectronBremsstrahlungBlock
8+
9+
class Test_ACEtk_PhotoatomicElectronBremsstrahlungBlock( unittest.TestCase ) :
10+
"""Unit test for the PhotoatomicElectronBremsstrahlungBlock class."""
11+
12+
chunk = [ 10., 20., 200.,
13+
1., 2., 3. ]
14+
15+
def test_component( self ) :
16+
17+
def verify_chunk( self, chunk ) :
18+
19+
# verify content
20+
self.assertEqual( False, chunk.empty )
21+
self.assertEqual( 6, chunk.length )
22+
self.assertEqual( "BREML", chunk.name )
23+
24+
self.assertEqual( 6, len( chunk.xss_array ) )
25+
26+
self.assertEqual( 3, chunk.NBL )
27+
self.assertEqual( 3, chunk.number_energy_points )
28+
29+
self.assertEqual( 3, len( chunk.energies ) )
30+
self.assertEqual( 3, len( chunk.energy_after_bremsstrahlung ) )
31+
32+
self.assertAlmostEqual( 10., chunk.energies[0] )
33+
self.assertAlmostEqual( 20., chunk.energies[1] )
34+
self.assertAlmostEqual( 200., chunk.energies[2] )
35+
self.assertAlmostEqual( 1., chunk.energy_after_bremsstrahlung[0] )
36+
self.assertAlmostEqual( 2., chunk.energy_after_bremsstrahlung[1] )
37+
self.assertAlmostEqual( 3., chunk.energy_after_bremsstrahlung[2] )
38+
39+
# verify the xss array
40+
xss = chunk.xss_array
41+
for index in range( chunk.length ) :
42+
43+
self.assertAlmostEqual( self.chunk[index], xss[index] )
44+
45+
# the data is given explicitly
46+
chunk = PhotoatomicElectronBremsstrahlungBlock(
47+
energies = [ 10., 20., 200. ],
48+
remaining = [ 1., 2., 3. ] )
49+
50+
verify_chunk( self, chunk )
51+
52+
if __name__ == '__main__' :
53+
54+
unittest.main()

‎src/ACEtk/block/PhotoatomicElectronBremsstrahlungBlock.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace block {
1212

1313
/**
1414
* @class
15-
* @brief The photoatomic BREML block with the electron Bremsstrahlung energy
16-
* loss data
15+
* @brief The photoatomic BREML block with the average electron energy
16+
* after Bremsstrahlung
1717
*
1818
* This block is part of the eprdata formats.
1919
*
2020
* The PhotoatomicElectronBremsstrahlungBlock class contains 2 arrays of the
2121
* same length:
2222
* - the energy points
23-
* - the average energy remaining after loss to Bremsstrahlung
23+
* - the average energy remaining after Bremsstrahlung
2424
*
2525
* The size NBL of each (the total number of energy points) is stored in NXS(12).
2626
*/

0 commit comments

Comments
 (0)