Skip to content

Commit 1d15ca2

Browse files
committed
Made python bindings for the generic ACE table and data
1 parent b0e2040 commit 1d15ca2

6 files changed

Lines changed: 286 additions & 22 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ include_directories( python/src/ )
8484
pybind11_add_module( ACEtk.python
8585
EXCLUDE_FROM_ALL
8686
python/src/ACEtk.python.cpp
87+
python/src/Data.python.cpp
88+
python/src/Table.python.cpp
8789
)
8890
target_link_libraries( ACEtk.python PRIVATE ACEtk )
8991
target_compile_options( ACEtk.python PRIVATE "-fvisibility=hidden" )

‎python/src/ACEtk.python.cpp‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace python = pybind11;
99

1010
// declarations
11-
12-
// declarations
11+
void wrapData( python::module&, python::module& );
12+
void wrapTable( python::module&, python::module& );
1313

1414
/**
1515
* @brief ACEtk python bindings
@@ -19,5 +19,14 @@ namespace python = pybind11;
1919
*/
2020
PYBIND11_MODULE( ACEtk, module ) {
2121

22-
// nothing to see here - for now
22+
// create the views submodule
23+
python::module viewmodule = module.def_submodule(
24+
25+
"sequence",
26+
"sequence - ACE sequences (internal use only)"
27+
);
28+
29+
// wrap generic table components
30+
wrapData( module, viewmodule );
31+
wrapTable( module, viewmodule );
2332
}

‎python/src/Data.python.cpp‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// system includes
2+
#include <pybind11/pybind11.h>
3+
#include <pybind11/stl.h>
4+
5+
// local includes
6+
#include "ACEtk/Table.hpp"
7+
8+
// namespace aliases
9+
namespace python = pybind11;
10+
11+
void wrapData( python::module& module, python::module& ) {
12+
13+
// type aliases
14+
using Component = njoy::ACEtk::Table::Data;
15+
16+
// wrap views created by this component
17+
18+
// create the component
19+
python::class_< Component > component(
20+
21+
module,
22+
"Data",
23+
"The data in an ACE table\n\n"
24+
"The data in an ACE table consists of the following arrays:\n"
25+
" - the IZAW array which contains 16 integer, double pairs\n"
26+
" - the NXS array which contains information needed to properly interpret\n"
27+
" the XSS array\n"
28+
" - the JXS array which contains 32 locators to specific blocks in the\n"
29+
" XSS array (the meaning of the JXS locators depend on the type of the\n"
30+
" ACE table)\n"
31+
" - the XSS array which contains the actual data"
32+
);
33+
34+
// wrap the component
35+
component
36+
.def(
37+
38+
python::init< std::array< int32_t, 16 >&&, std::array< double, 16 >&&,
39+
std::array< int64_t, 16 >&&, std::array< int64_t, 32 >&&,
40+
std::vector< double >&& >(),
41+
python::arg( "iz" ), python::arg( "aw" ), python::arg( "nxs" ),
42+
python::arg( "jxs" ), python::arg( "xss" ),
43+
"Initialise the component\n\n"
44+
"Arguments:\n"
45+
" self the data arrays\n"
46+
" iz the IZ array\n"
47+
" aw the AW array\n"
48+
" nxs the NXS array\n"
49+
" jxs the JXS array\n"
50+
" xss the XSS array"
51+
)
52+
.def_property_readonly(
53+
54+
"iz",
55+
python::overload_cast<>( &Component::IZ, python::const_ ),
56+
"The iz array"
57+
)
58+
.def_property_readonly(
59+
60+
"aw",
61+
python::overload_cast<>( &Component::AW, python::const_ ),
62+
"The aw array"
63+
)
64+
.def_property_readonly(
65+
66+
"nxs",
67+
python::overload_cast<>( &Component::NXS, python::const_ ),
68+
"The nxs array"
69+
)
70+
.def_property_readonly(
71+
72+
"jxs",
73+
python::overload_cast<>( &Component::JXS, python::const_ ),
74+
"The jxs array"
75+
)
76+
.def_property_readonly(
77+
78+
"xss",
79+
python::overload_cast<>( &Component::XSS, python::const_ ),
80+
"The xss array"
81+
)
82+
.def(
83+
84+
"iz",
85+
python::overload_cast< std::size_t >( &Component::IZ, python::const_ ),
86+
python::arg( "index" ),
87+
"Return a value from the IZ array\n\n"
88+
"Arguments:\n"
89+
" self the data arrays\n"
90+
" index the index (one-based)"
91+
)
92+
.def(
93+
94+
"aw",
95+
python::overload_cast< std::size_t >( &Component::AW, python::const_ ),
96+
python::arg( "index" ),
97+
"Return a value from the AW array\n\n"
98+
"Arguments:\n"
99+
" self the data arrays\n"
100+
" index the index (one-based)"
101+
)
102+
.def(
103+
104+
"nxs",
105+
python::overload_cast< std::size_t >( &Component::NXS, python::const_ ),
106+
python::arg( "index" ),
107+
"Return a value from the NXS array\n\n"
108+
"Arguments:\n"
109+
" self the data arrays\n"
110+
" index the index (one-based)"
111+
)
112+
.def(
113+
114+
"jxs",
115+
python::overload_cast< std::size_t >( &Component::JXS, python::const_ ),
116+
python::arg( "index" ),
117+
"Return a value from the JXS array\n\n"
118+
"Arguments:\n"
119+
" self the data arrays\n"
120+
" index the index (one-based)"
121+
)
122+
.def(
123+
124+
"xss",
125+
python::overload_cast< std::size_t >( &Component::XSS, python::const_ ),
126+
python::arg( "index" ),
127+
"Return a value from the XSS array\n\n"
128+
"Arguments:\n"
129+
" self the data arrays\n"
130+
" index the index (one-based)"
131+
);
132+
}

‎python/src/Table.python.cpp‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// system includes
2+
#include <pybind11/pybind11.h>
3+
#include <pybind11/stl.h>
4+
5+
// local includes
6+
#include "ACEtk/Table.hpp"
7+
#include "ACEtk/fromFile.hpp"
8+
9+
// namespace aliases
10+
namespace python = pybind11;
11+
12+
void wrapTable( python::module& module, python::module& ) {
13+
14+
// type aliases
15+
using Component = njoy::ACEtk::Table;
16+
using Header = njoy::ACEtk::Table::Header;
17+
using Data = njoy::ACEtk::Table::Data;
18+
19+
// wrap views created by this component
20+
21+
// create the component
22+
python::class_< Component > component(
23+
24+
module,
25+
"Table",
26+
"A generic ACE table\n\n"
27+
"A Table represents the generic ACE table, which can be of any type\n"
28+
"(e.g. continuous energy, thermal scattering, etc.). It contains a header\n"
29+
"and the actual data of the table (the data being the IZAW, NXS, JXS and XSS\n"
30+
"arrays)."
31+
);
32+
33+
// wrap the component
34+
component
35+
// .def(
36+
//
37+
// python::init< Header&&, Data&& >(),
38+
// python::arg( "header" ), python::arg( "data" ),
39+
// "Initialise the component\n\n"
40+
// "Arguments:\n"
41+
// " self the table\n"
42+
// " header the header information\n"
43+
// " data the ACE data"
44+
// )
45+
.def_property_readonly(
46+
47+
"header",
48+
python::overload_cast<>( &Component::header, python::const_ ),
49+
"The header information"
50+
)
51+
.def_property_readonly(
52+
53+
"data",
54+
python::overload_cast<>( &Component::data, python::const_ ),
55+
"The data arrays"
56+
)
57+
.def_static(
58+
59+
"from_file",
60+
[] ( const std::string& filename ) -> Component {
61+
62+
return njoy::ACEtk::fromFile( filename );
63+
},
64+
"Read an ACE table from a file\n\n"
65+
"An exception is raised if something goes wrong while reading the\n"
66+
"table\n\n"
67+
"Arguments:\n"
68+
" filename the file name and path"
69+
)
70+
.def(
71+
72+
"to_file",
73+
[] ( const Component& self, const std::string& filename ) {
74+
75+
std::ofstream out( filename );
76+
self.print< 1,0,0 >( out );
77+
out.close();
78+
},
79+
"Write the ACE table to a file\n\n"
80+
"Arguments:\n"
81+
" self the tape\n"
82+
" filename the file name and path"
83+
);
84+
}

‎src/ACEtk/Table.hpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace dimwits;
2525

2626
/**
2727
* @class
28-
* @brief The ACE table
28+
* @brief The generic ACE table
2929
*
3030
* The Table class represents the generic ACE table, which can be of any type
3131
* (e.g. continuous energy, thermal scattering, etc.). It contains a header
@@ -49,22 +49,22 @@ class Table {
4949
#include "ACEtk/Table/src/ctor.hpp"
5050

5151
/**
52-
* @brief Return the header
52+
* @brief Return the header information
5353
*/
5454
const auto& header() const { return this->header_; }
5555

5656
/**
57-
* @brief Return the data
57+
* @brief Return the data arrays
5858
*/
5959
const auto& data() const { return this->data_; }
6060

6161
/**
62-
* @brief Return the header
62+
* @brief Return the header information
6363
*/
6464
auto& header() { return this->header_; }
6565

6666
/**
67-
* @brief Return the data
67+
* @brief Return the data arrays
6868
*/
6969
auto& data() { return this->data_; }
7070

0 commit comments

Comments
 (0)