-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMaterial.python.cpp
More file actions
161 lines (138 loc) · 4.77 KB
/
Copy pathMaterial.python.cpp
File metadata and controls
161 lines (138 loc) · 4.77 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
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <string>
// local includes
#include "ENDFtk/Material.hpp"
#include "boost/hana.hpp"
// namespace aliases
namespace python = pybind11;
namespace hana = boost::hana;
inline namespace literals { using namespace hana::literals; }
void wrapMaterial( python::module& module, python::module& ) {
// type aliases
using Material = njoy::ENDFtk::Material;
using MF1 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 1 > >;
using MF2 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 2 > >;
using MF3 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 3 > >;
using MF4 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 4 > >;
using MF5 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 5 > >;
using MF6 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 6 > >;
using MF7 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 7 > >;
using MF8 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 8 > >;
using MF9 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 9 > >;
using MF10 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 10 > >;
using MF12 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 12 > >;
using MF13 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 13 > >;
using MF14 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 14 > >;
using MF15 = std::reference_wrapper< const njoy::ENDFtk::file::Type< 15 > >;
// wrap views created by this section
// create the section
python::class_< Material > material(
module,
"Material",
"Material - nuclear data for a single material"
);
// predefined lambda
auto getFile = [] ( const Material& self, int mf )
-> std::variant< MF1, MF2, MF3, MF4, MF5, MF6, MF7, MF8, MF9, MF10,
MF12, MF13, MF14, MF15 > {
switch ( mf ) {
case 1 : return self.file( 1_c );
case 2 : return self.file( 2_c );
case 3 : return self.file( 3_c );
case 4 : return self.file( 4_c );
case 5 : return self.file( 5_c );
case 6 : return self.file( 6_c );
case 7 : return self.file( 7_c );
case 8 : return self.file( 8_c );
case 9 : return self.file( 9_c );
case 10 : return self.file( 10_c );
case 12 : return self.file( 12_c );
case 13 : return self.file( 13_c );
case 14 : return self.file( 14_c );
case 15 : return self.file( 15_c );
default: throw std::runtime_error(
"Requested file number (" + std::to_string( mf ) +
") does not correspond to a stored file" );
}
};
// wrap the section
material
.def_property_readonly(
"MAT",
&Material::MAT,
"The material number"
)
.def_property_readonly(
"material_number",
&Material::materialNumber,
"The material number"
)
.def(
"has_MF",
&Material::hasMF,
python::arg( "mf" ),
"Return whether or not the material has a file with the given MF number\n\n"
"Arguments:\n"
" self the file\n"
" mf the MF number of the file"
)
.def(
"has_file",
&Material::hasFile,
python::arg( "mf" ),
"Return whether or not the material has a file with the given MF number\n\n"
"Arguments:\n"
" self the file\n"
" mf the MF number of the file"
)
.def(
"MF",
getFile,
python::arg( "mf" ),
"Return the file with the requested MF number\n\n"
"Arguments:\n"
" self the file\n"
" mf the MF number of the file to be returned",
python::return_value_policy::reference_internal
)
.def(
"file",
getFile,
python::arg( "mf" ),
"Return the file with the requested MF number\n\n"
"Arguments:\n"
" self the file\n"
" mf the MF number of the file to be returned",
python::return_value_policy::reference_internal
)
.def_static(
"from_string",
[] ( const std::string& material ) -> Material {
auto begin = material.begin();
auto end = material.end();
long lineNumber = 1;
njoy::ENDFtk::StructureDivision division( begin, end, lineNumber);
return njoy::ENDFtk::Material( division, begin, end, lineNumber );
},
python::arg( "material" ),
"Read the material from a string\n\n"
"An exception is raised if something goes wrong while reading the\n"
"material\n\n"
"Arguments:\n"
" material the string representing the material"
)
.def(
"to_string",
[] ( const Material& self ) -> std::string {
std::string buffer;
auto output = std::back_inserter( buffer );
self.print( output );
return buffer;
},
"The string representation of the material\n\n"
"Arguments:\n"
" self the material"
);
}