Skip to content

Commit

Permalink
Adding bindings for ScatteringMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 17, 2024
1 parent 87085d2 commit 9551662
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ if( NDItk.python )
python/src/multigroup/OutgoingParticleTypes.python.cpp
python/src/multigroup/OutgoingParticleTransportData.python.cpp
python/src/multigroup/LegendreMoment.python.cpp
python/src/multigroup/ScatteringMatrix.python.cpp
)

target_link_libraries( NDItk.python PRIVATE NDItk )
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/EnergyGroupStructure.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void wrapEnergyGroupStructure( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return readWithSubtype< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/FluxWeights.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wrapFluxWeights( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return read< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/HeatingNumbers.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void wrapHeatingNumbers( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return readWithSubtype< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/Kerma.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void wrapKerma( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return readWithSubtype< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wrapOutgoingParticleTransportData( python::module& module, python::module&
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return read< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/OutgoingParticleTypes.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wrapOutgoingParticleTypes( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return read< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
4 changes: 2 additions & 2 deletions python/src/multigroup/ReactionCrossSections.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void wrapReactionCrossSections( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t reactions,
std::size_t groups ) -> Record
[] ( const std::string& string, unsigned int reactions,
unsigned int groups ) -> Record
{ return read< Record >( string, reactions, groups ); },
python::arg( "string" ), python::arg( "reactions" ),
python::arg( "groups" ),
Expand Down
107 changes: 107 additions & 0 deletions python/src/multigroup/ScatteringMatrix.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// local includes
#include "NDItk/multigroup/ScatteringMatrix.hpp"
#include "tools/views/views-python.hpp"
#include "definitions.hpp"
#include "read.hpp"

// namespace aliases
namespace python = pybind11;

namespace multigroup {

void wrapScatteringMatrix( python::module& module, python::module& ) {

// type aliases
using Record = njoy::NDItk::multigroup::ScatteringMatrix;
using LegendreMoment = njoy::NDItk::multigroup::LegendreMoment;

// wrap views created by this record

// create the record
python::class_< Record > record(

module,
"ScatteringMatrix",
"A scattering matrix record for multigroup neutron and photon data"
);

// wrap the record
record
.def(

python::init< std::vector< LegendreMoment > >(),
python::arg( "moments" ),
"Initialise the record\n\n"
"Arguments:\n"
" self the record\n"
" moments the Legendre moments of the scattering matrix"
)
.def_property_readonly(

"number_primary_groups",
&Record::numberPrimaryGroups,
"The number of primary groups defined by this record"
)
.def_property_readonly(

"number_outgoing_groups",
&Record::numberOutgoingGroups,
"The number of outgoing groups defined by this record"
)
.def_property_readonly(

"number_legendre_moments",
&Record::numberLegendreMoments,
"The number of moments defined in this record"
)
.def_property_readonly(

"moments",
&Record::moments,
"The Legendre moments"
)
.def(

"has_moment",
&Record::hasMoment,
python::arg( "order" ),
"Return whether or not a given moment is present\n\n"
" self the record\n"
" order the Legendre order to look for"
)
.def(

"moment",
&Record::moment,
python::arg( "order" ),
"Return the moment for a given order\n\n"
" self the record\n"
" order the Legendre order to look for"
)
.def_static(

"from_string",
[] ( const std::string& string, unsigned int incident,
unsigned int outgoing, unsigned int number ) -> Record
{ return read< Record >( string, incident, outgoing, number ); },
python::arg( "string" ), python::arg( "incident" ),
python::arg( "outgoing" ), python::arg( "number" ),
"Read the record from a string\n\n"
"An exception is raised if something goes wrong while reading the\n"
"record\n\n"
"Arguments:\n"
" string the string representing the record\n"
" incident the number of incident energy groups\n"
" outgoing the number of outgoing energy groups\n"
" number the number of moments"
);

// add standard record definitions
addStandardRecordDefinitions< Record, DoubleRange >( record );
}

} // multigroup namespace
2 changes: 1 addition & 1 deletion python/src/multigroup/TotalCrossSection.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wrapTotalCrossSection( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return read< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/src/multigroup/Velocities.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wrapVelocities( python::module& module, python::module& ) {
.def_static(

"from_string",
[] ( const std::string& string, std::size_t number ) -> Record
[] ( const std::string& string, unsigned int number ) -> Record
{ return read< Record >( string, number ); },
python::arg( "string" ), python::arg( "number" ),
"Read the record from a string\n\n"
Expand Down

0 comments on commit 9551662

Please sign in to comment.