-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/initial-python' into fix/review
- Loading branch information
Showing
39 changed files
with
1,427 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// system includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
// local includes | ||
#include "NDItk/MultigroupTable.hpp" | ||
#include "definitions.hpp" | ||
#include "read.hpp" | ||
|
||
// namespace aliases | ||
namespace python = pybind11; | ||
|
||
void wrapMultigroupTable( python::module& module, python::module& ) { | ||
|
||
// type aliases | ||
using Table = njoy::NDItk::MultigroupTable; | ||
using Metadata = njoy::NDItk::multigroup::Metadata; | ||
using Structure = njoy::NDItk::multigroup::Structure; | ||
using FluxWeights = njoy::NDItk::multigroup::FluxWeights; | ||
using ReactionCrossSections = njoy::NDItk::multigroup::ReactionCrossSections; | ||
|
||
// wrap views created by this table | ||
|
||
// create the table | ||
python::class_< Table > table( | ||
|
||
module, | ||
"MultigroupTable", | ||
"A multigroup neutron and photon table" | ||
); | ||
|
||
// wrap the table | ||
table | ||
.def( | ||
|
||
python::init< std::string, std::string, std::string, std::string, | ||
double, double, double, double, | ||
Structure, FluxWeights, | ||
ReactionCrossSections >(), | ||
python::arg( "zaid" ), python::arg( "libname" ), python::arg( "source" ), | ||
python::arg( "process" ), python::arg( "awr" ), python::arg( "weight" ), | ||
python::arg( "temperature" ), python::arg( "dilution" ), | ||
python::arg( "structure" ), python::arg( "flux" ), python::arg( "xs" ), | ||
"Initialise the table\n\n" | ||
"Arguments:\n" | ||
" self the table\n" | ||
" zaid the zaid of the table\n" | ||
" libname the library name\n" | ||
" source the source date\n" | ||
" process the processing date\n" | ||
" awr the atomic weight ratio of the target (with respect\n" | ||
" to the neutron mass)\n" | ||
" weight the atomic weight of the target\n" | ||
" temperature the temperature of the target\n" | ||
" dilution the dilution (aka sigma0)\n" | ||
" structure the primary group structure\n" | ||
" flux the flux weights\n" | ||
" xs the reaction cross section data" | ||
) | ||
.def_property_readonly( | ||
|
||
"metadata", | ||
&Table::metadata, | ||
"The metadata of the table" | ||
) | ||
.def_property_readonly( | ||
|
||
"structure", | ||
&Table::structure, | ||
"The primary group structure record" | ||
) | ||
.def_property_readonly( | ||
|
||
"flux", | ||
&Table::flux, | ||
"The flux weight record" | ||
) | ||
.def_property_readonly( | ||
|
||
"reaction_cross_sections", | ||
&Table::reactionCrossSections, | ||
"The reaction cross section record" | ||
); | ||
|
||
// add standard table definitions | ||
addStandardTableDefinitions< Table >( table ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#ifndef NJOY_NDITK_PYTHON_DEFINITIONS | ||
#define NJOY_NDITK_PYTHON_DEFINITIONS | ||
|
||
// system includes | ||
#include <complex> | ||
|
||
// other includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include "tools/views/views-python.hpp" | ||
#include "NDItk/fromFile.hpp" | ||
|
||
namespace python = pybind11; | ||
|
||
/** | ||
* @brief Add standard subrecord definitions | ||
* | ||
* This adds the following standard properties: | ||
* - values, size, empty | ||
* | ||
* This adds the following standard functions: | ||
* - to_string() | ||
* | ||
* @param[in] record the record to which the definitions have to be added | ||
*/ | ||
template < typename Record, typename Range, typename PythonClass > | ||
void addStandardSubrecordDefinitions( PythonClass& subrecord ) { | ||
|
||
subrecord | ||
.def_property_readonly( | ||
|
||
"values", | ||
[] ( const Record& self ) -> Range | ||
{ return self.values(); }, | ||
"The data values of the subrecord" | ||
) | ||
.def_property_readonly( | ||
|
||
"size", | ||
[] ( const Record& self ) { return self.size(); }, | ||
"The size of the subrecord" | ||
) | ||
.def_property_readonly( | ||
|
||
"empty", | ||
[] ( const Record& self ) { return self.empty(); }, | ||
"Flag indicating whether or not the subrecord is empty" | ||
) | ||
.def( | ||
|
||
"to_string", | ||
[] ( const Record& self ) -> std::string { | ||
|
||
std::string buffer; | ||
auto output = std::back_inserter( buffer ); | ||
self.print( output ); | ||
return buffer; | ||
}, | ||
"Return the string representation of the subrecord\n\n" | ||
"Arguments:\n" | ||
" self the subrecord" | ||
); | ||
} | ||
|
||
/** | ||
* @brief Add standard record definitions | ||
* | ||
* This adds the following standard properties: | ||
* - keyword, values, size, empty | ||
* | ||
* This adds the following standard functions: | ||
* - to_string() | ||
* | ||
* @param[in] record the record to which the definitions have to be added | ||
*/ | ||
template < typename Record, typename Range, typename PythonClass > | ||
void addStandardRecordDefinitions( PythonClass& record ) { | ||
|
||
record | ||
.def_property_readonly( | ||
|
||
"keyword", | ||
[] ( const Record& self ) { return self.keyword(); }, | ||
"The record keyword" | ||
) | ||
.def_property_readonly( | ||
|
||
"values", | ||
[] ( const Record& self ) -> Range | ||
{ return self.values(); }, | ||
"The data values of the record" | ||
) | ||
.def_property_readonly( | ||
|
||
"size", | ||
[] ( const Record& self ) { return self.size(); }, | ||
"The size of the record" | ||
) | ||
.def_property_readonly( | ||
|
||
"empty", | ||
[] ( const Record& self ) { return self.empty(); }, | ||
"Flag indicating whether or not the record is empty" | ||
) | ||
.def( | ||
|
||
"to_string", | ||
[] ( const Record& self ) -> std::string { | ||
|
||
std::string buffer; | ||
auto output = std::back_inserter( buffer ); | ||
self.print( output ); | ||
return buffer; | ||
}, | ||
"Return the string representation of the record\n\n" | ||
"Arguments:\n" | ||
" self the record" | ||
); | ||
} | ||
|
||
/** | ||
* @brief Add standard table definitions | ||
* | ||
* This adds the following standard functions: | ||
* - from_file() | ||
* | ||
* @param[in] table the table to which the definitions have to be added | ||
*/ | ||
template < typename Table, typename PythonClass > | ||
void addStandardTableDefinitions( PythonClass& table ) { | ||
|
||
table | ||
.def_static( | ||
|
||
"from_file", | ||
[] ( const std::string& filename ) -> Table { | ||
|
||
return njoy::NDItk::fromFile< Table >( filename ); | ||
}, | ||
"Read an ACE table from a file\n\n" | ||
"An exception is raised if something goes wrong while reading the\n" | ||
"table\n\n" | ||
"Arguments:\n" | ||
" filename the file name and path" | ||
); | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// system includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
// local includes | ||
|
||
// namespace aliases | ||
namespace python = pybind11; | ||
|
||
namespace multigroup { | ||
|
||
// declarations - NDI records and subrecords | ||
void wrapMetadata( python::module&, python::module& ); | ||
void wrapCrossSection( python::module&, python::module& ); | ||
void wrapFluxWeights( python::module&, python::module& ); | ||
void wrapStructure( python::module&, python::module& ); | ||
void wrapReactionCrossSections( python::module&, python::module& ); | ||
} | ||
|
||
void wrapMultigroup( python::module& module, python::module& viewmodule ) { | ||
|
||
// create the submodule | ||
python::module submodule = module.def_submodule( | ||
|
||
"multigroup", | ||
"Multigroup neutron and photon NDI records and subrecords" | ||
); | ||
|
||
multigroup::wrapMetadata( submodule, viewmodule ); | ||
multigroup::wrapCrossSection( submodule, viewmodule ); | ||
multigroup::wrapFluxWeights( submodule, viewmodule ); | ||
multigroup::wrapStructure( submodule, viewmodule ); | ||
multigroup::wrapReactionCrossSections( submodule, viewmodule ); | ||
} |
Oops, something went wrong.