Repository navigation
Expand file tree
/
Copy pathData.python.cpp
More file actions
171 lines (147 loc) · 4.62 KB
/
Copy pathData.python.cpp
File metadata and controls
171 lines (147 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
// local includes
#include "ACEtk/Table.hpp"
#include "tools/views/views-python.hpp"
// namespace aliases
namespace python = pybind11;
void wrapData( python::module& module, python::module& ) {
// type aliases
using Component = njoy::ACEtk::Table::Data;
// wrap views created by this component
// create the component
python::class_< Component > component(
module,
"Data",
"The data in an ACE table\n\n"
"The data in an ACE table consists of the following arrays:\n"
" - the IZAW array which contains 16 integer, double pairs\n"
" - the NXS array which contains information needed to properly interpret\n"
" the XSS array\n"
" - the JXS array which contains 32 locators to specific blocks in the\n"
" XSS array (the meaning of the JXS locators depend on the type of the\n"
" ACE table)\n"
" - the XSS array which contains the actual data"
);
// wrap the component
component
.def(
python::init< std::array< int32_t, 16 >&&, std::array< double, 16 >&&,
std::array< int64_t, 16 >&&, std::array< int64_t, 32 >&&,
std::vector< double >&& >(),
python::arg( "iz" ), python::arg( "aw" ), python::arg( "nxs" ),
python::arg( "jxs" ), python::arg( "xss" ),
"Initialise the component\n\n"
"Arguments:\n"
" self the data arrays\n"
" iz the IZ array\n"
" aw the AW array\n"
" nxs the NXS array\n"
" jxs the JXS array\n"
" xss the XSS array"
)
.def_property_readonly(
"iz_array",
python::overload_cast<>( &Component::IZ, python::const_ ),
"The iz array"
)
.def_property_readonly(
"aw_array",
python::overload_cast<>( &Component::AW, python::const_ ),
"The aw array"
)
.def_property_readonly(
"nxs_array",
python::overload_cast<>( &Component::NXS, python::const_ ),
"The nxs array"
)
.def_property_readonly(
"jxs_array",
python::overload_cast<>( &Component::JXS, python::const_ ),
"The jxs array"
)
.def_property_readonly(
"xss_array",
python::overload_cast<>( &Component::XSS, python::const_ ),
"The xss array"
)
.def(
"iz",
python::overload_cast< std::size_t >( &Component::IZ, python::const_ ),
python::arg( "index" ),
"Return a value from the IZ array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)"
)
.def(
"aw",
python::overload_cast< std::size_t >( &Component::AW, python::const_ ),
python::arg( "index" ),
"Return a value from the AW array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)"
)
.def(
"nxs",
python::overload_cast< std::size_t >( &Component::NXS, python::const_ ),
python::arg( "index" ),
"Return a value from the NXS array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)"
)
.def(
"jxs",
python::overload_cast< std::size_t >( &Component::JXS, python::const_ ),
python::arg( "index" ),
"Return a value from the JXS array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)"
)
.def(
"xss",
python::overload_cast< std::size_t >( &Component::XSS, python::const_ ),
python::arg( "index" ),
"Return a value from the XSS array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)"
)
.def(
"xss",
[] ( const Component& self, std::size_t index, std::size_t length ) -> DoubleRange
{ return self.XSS( index, length ); },
python::arg( "index" ), python::arg( "length" ),
"Return a subrange of a given length from the XSS array\n\n"
"Arguments:\n"
" self the data arrays\n"
" index the index (one-based)\n"
" length the length of the subrange"
)
.def_static(
"from_string",
[] ( const std::string& string ) -> Component {
njoy::ACEtk::State< decltype(string.begin()) > state{ 1, string.begin(), string.end() };
return Component( state );
},
python::arg( "string" ),
"Read the ACE data arrays from a string\n\n"
"An exception is raised if something goes wrong while reading the\n"
"data arrays\n\n"
"Arguments:\n"
" string the string representing the ACE data arrays"
)
.def(
"to_string",
[] ( const Component& self ) {
std::ostringstream out;
self.print( out );
return out.str();
},
"Return the string representation of the ACE data arrays"
);
}