-
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.
- Loading branch information
Showing
7 changed files
with
348 additions
and
0 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
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,76 @@ | ||
// system includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
// local includes | ||
#include "NDItk/multigroup/HeatingNumbers.hpp" | ||
#include "tools/views/views-python.hpp" | ||
#include "definitions.hpp" | ||
#include "read.hpp" | ||
|
||
// namespace aliases | ||
namespace python = pybind11; | ||
|
||
namespace multigroup { | ||
|
||
void wrapHeatingNumbers( python::module& module, python::module& ) { | ||
|
||
// type aliases | ||
using Record = njoy::NDItk::multigroup::HeatingNumbers; | ||
|
||
// wrap views created by this record | ||
|
||
// create the record | ||
python::class_< Record > record( | ||
|
||
module, | ||
"HeatingNumbers", | ||
"A heating numbers record for multigroup neutron and photon data" | ||
); | ||
|
||
// wrap the record | ||
record | ||
.def( | ||
|
||
python::init< std::vector< double > >(), | ||
python::arg( "values" ), | ||
"Initialise the record\n\n" | ||
"Arguments:\n" | ||
" self the record\n" | ||
" values the heating numbers" | ||
) | ||
.def( | ||
|
||
python::init< unsigned int, std::vector< double > >(), | ||
python::arg( "particle" ), python::arg( "values" ), | ||
"Initialise the record\n\n" | ||
"Arguments:\n" | ||
" self the table\n" | ||
" particle the secondary particle identifier\n" | ||
" values the heating numbers" | ||
) | ||
.def_property_readonly( | ||
|
||
"number_groups", | ||
&Record::numberGroups, | ||
"The number of groups defined by this record" | ||
) | ||
.def_static( | ||
|
||
"from_string", | ||
[] ( const std::string& string, std::size_t number ) -> Record | ||
{ return readWithSubtype< Record >( string, number ); }, | ||
python::arg( "string" ), 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" | ||
" number the number of heating numbers to be read" | ||
); | ||
|
||
// add standard record definitions | ||
addStandardRecordDefinitions< Record, DoubleRange >( record ); | ||
} | ||
|
||
} // multigroup namespace |
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,76 @@ | ||
// system includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
// local includes | ||
#include "NDItk/multigroup/Kerma.hpp" | ||
#include "tools/views/views-python.hpp" | ||
#include "definitions.hpp" | ||
#include "read.hpp" | ||
|
||
// namespace aliases | ||
namespace python = pybind11; | ||
|
||
namespace multigroup { | ||
|
||
void wrapKerma( python::module& module, python::module& ) { | ||
|
||
// type aliases | ||
using Record = njoy::NDItk::multigroup::Kerma; | ||
|
||
// wrap views created by this record | ||
|
||
// create the record | ||
python::class_< Record > record( | ||
|
||
module, | ||
"Kerma", | ||
"A kerma record for multigroup neutron and photon data" | ||
); | ||
|
||
// wrap the record | ||
record | ||
.def( | ||
|
||
python::init< std::vector< double > >(), | ||
python::arg( "values" ), | ||
"Initialise the record\n\n" | ||
"Arguments:\n" | ||
" self the record\n" | ||
" values the kerma values" | ||
) | ||
.def( | ||
|
||
python::init< unsigned int, std::vector< double > >(), | ||
python::arg( "particle" ), python::arg( "values" ), | ||
"Initialise the record\n\n" | ||
"Arguments:\n" | ||
" self the table\n" | ||
" particle the secondary particle identifier\n" | ||
" values the kerma values" | ||
) | ||
.def_property_readonly( | ||
|
||
"number_groups", | ||
&Record::numberGroups, | ||
"The number of groups defined by this record" | ||
) | ||
.def_static( | ||
|
||
"from_string", | ||
[] ( const std::string& string, std::size_t number ) -> Record | ||
{ return readWithSubtype< Record >( string, number ); }, | ||
python::arg( "string" ), 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" | ||
" number the number of kerma values to be read" | ||
); | ||
|
||
// add standard record definitions | ||
addStandardRecordDefinitions< Record, DoubleRange >( record ); | ||
} | ||
|
||
} // multigroup namespace |
94 changes: 94 additions & 0 deletions
94
python/test/multigroup/Test_NDItk_multigroup_HeatingNumbers.py
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,94 @@ | ||
# standard imports | ||
import unittest | ||
|
||
# third party imports | ||
|
||
# local imports | ||
from NDItk.multigroup import HeatingNumbers | ||
|
||
class Test_NDItk_multigroup_HeatingNumbers( unittest.TestCase ) : | ||
"""Unit test for the HeatingNumbers class.""" | ||
|
||
chunk_values = [ 10, 9, 8, 7, 6, 5, 4 ] | ||
chunk_string = ( 'heating\n' | ||
' 10 9 8 7 6\n' | ||
' 5 4\n' ) | ||
|
||
chunk_outgoing_values = [ 10, 9, 8, 7, 6, 5, 4 ] | ||
chunk_outgoing_string = ( 'heating_1001\n' | ||
' 10 9 8 7 6\n' | ||
' 5 4\n' ) | ||
|
||
def test_component( self ) : | ||
|
||
def verify_chunk( self, chunk ) : | ||
|
||
# verify content | ||
self.assertEqual( 7, chunk.number_groups ) | ||
self.assertAlmostEqual( 10, chunk.values[0] ) | ||
self.assertAlmostEqual( 9, chunk.values[1] ) | ||
self.assertAlmostEqual( 8, chunk.values[2] ) | ||
self.assertAlmostEqual( 7, chunk.values[3] ) | ||
self.assertAlmostEqual( 6, chunk.values[4] ) | ||
self.assertAlmostEqual( 5, chunk.values[5] ) | ||
self.assertAlmostEqual( 4, chunk.values[6] ) | ||
|
||
self.assertEqual( self.chunk_string, chunk.to_string() ) | ||
|
||
# verify the record | ||
self.assertEqual( 'heating', chunk.keyword ) | ||
self.assertEqual( False, chunk.empty ) | ||
self.assertEqual( 7, chunk.size ) | ||
|
||
values = chunk.values | ||
for index in range( chunk.size ) : | ||
|
||
self.assertAlmostEqual( self.chunk_values[index], values[index] ) | ||
|
||
def verify_outgoing_chunk( self, chunk ) : | ||
|
||
# verify content | ||
self.assertEqual( 7, chunk.number_groups ) | ||
self.assertAlmostEqual( 10, chunk.values[0] ) | ||
self.assertAlmostEqual( 9, chunk.values[1] ) | ||
self.assertAlmostEqual( 8, chunk.values[2] ) | ||
self.assertAlmostEqual( 7, chunk.values[3] ) | ||
self.assertAlmostEqual( 6, chunk.values[4] ) | ||
self.assertAlmostEqual( 5, chunk.values[5] ) | ||
self.assertAlmostEqual( 4, chunk.values[6] ) | ||
|
||
self.assertEqual( self.chunk_outgoing_string, chunk.to_string() ) | ||
|
||
# verify the record | ||
self.assertEqual( 'heating_1001', chunk.keyword ) | ||
self.assertEqual( False, chunk.empty ) | ||
self.assertEqual( 7, chunk.size ) | ||
|
||
values = chunk.values | ||
for index in range( chunk.size ) : | ||
|
||
self.assertAlmostEqual( self.chunk_outgoing_values[index], values[index] ) | ||
|
||
# the data is given explicitly | ||
chunk = HeatingNumbers( values = [ 10, 9, 8, 7, 6, 5, 4 ] ) | ||
|
||
verify_chunk( self, chunk ) | ||
|
||
# the data is read from a string | ||
chunk = HeatingNumbers.from_string( self.chunk_string, 7 ) | ||
|
||
verify_chunk( self, chunk ) | ||
|
||
# the data is given explicitly for an outgoing particle | ||
chunk = HeatingNumbers( particle = 1001, values = [ 10, 9, 8, 7, 6, 5, 4 ] ) | ||
|
||
verify_outgoing_chunk( self, chunk ) | ||
|
||
# the data is read from a string for an outgoing particle | ||
chunk = HeatingNumbers.from_string( self.chunk_outgoing_string, 7 ) | ||
|
||
verify_outgoing_chunk( self, chunk ) | ||
|
||
if __name__ == '__main__' : | ||
|
||
unittest.main() |
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,94 @@ | ||
# standard imports | ||
import unittest | ||
|
||
# third party imports | ||
|
||
# local imports | ||
from NDItk.multigroup import Kerma | ||
|
||
class Test_NDItk_multigroup_Kerma( unittest.TestCase ) : | ||
"""Unit test for the Kerma class.""" | ||
|
||
chunk_values = [ 10, 9, 8, 7, 6, 5, 4 ] | ||
chunk_string = ( 'kerma\n' | ||
' 10 9 8 7 6\n' | ||
' 5 4\n' ) | ||
|
||
chunk_outgoing_values = [ 10, 9, 8, 7, 6, 5, 4 ] | ||
chunk_outgoing_string = ( 'kerma_1001\n' | ||
' 10 9 8 7 6\n' | ||
' 5 4\n' ) | ||
|
||
def test_component( self ) : | ||
|
||
def verify_chunk( self, chunk ) : | ||
|
||
# verify content | ||
self.assertEqual( 7, chunk.number_groups ) | ||
self.assertAlmostEqual( 10, chunk.values[0] ) | ||
self.assertAlmostEqual( 9, chunk.values[1] ) | ||
self.assertAlmostEqual( 8, chunk.values[2] ) | ||
self.assertAlmostEqual( 7, chunk.values[3] ) | ||
self.assertAlmostEqual( 6, chunk.values[4] ) | ||
self.assertAlmostEqual( 5, chunk.values[5] ) | ||
self.assertAlmostEqual( 4, chunk.values[6] ) | ||
|
||
self.assertEqual( self.chunk_string, chunk.to_string() ) | ||
|
||
# verify the record | ||
self.assertEqual( 'kerma', chunk.keyword ) | ||
self.assertEqual( False, chunk.empty ) | ||
self.assertEqual( 7, chunk.size ) | ||
|
||
values = chunk.values | ||
for index in range( chunk.size ) : | ||
|
||
self.assertAlmostEqual( self.chunk_values[index], values[index] ) | ||
|
||
def verify_outgoing_chunk( self, chunk ) : | ||
|
||
# verify content | ||
self.assertEqual( 7, chunk.number_groups ) | ||
self.assertAlmostEqual( 10, chunk.values[0] ) | ||
self.assertAlmostEqual( 9, chunk.values[1] ) | ||
self.assertAlmostEqual( 8, chunk.values[2] ) | ||
self.assertAlmostEqual( 7, chunk.values[3] ) | ||
self.assertAlmostEqual( 6, chunk.values[4] ) | ||
self.assertAlmostEqual( 5, chunk.values[5] ) | ||
self.assertAlmostEqual( 4, chunk.values[6] ) | ||
|
||
self.assertEqual( self.chunk_outgoing_string, chunk.to_string() ) | ||
|
||
# verify the record | ||
self.assertEqual( 'kerma_1001', chunk.keyword ) | ||
self.assertEqual( False, chunk.empty ) | ||
self.assertEqual( 7, chunk.size ) | ||
|
||
values = chunk.values | ||
for index in range( chunk.size ) : | ||
|
||
self.assertAlmostEqual( self.chunk_outgoing_values[index], values[index] ) | ||
|
||
# the data is given explicitly | ||
chunk = Kerma( values = [ 10, 9, 8, 7, 6, 5, 4 ] ) | ||
|
||
verify_chunk( self, chunk ) | ||
|
||
# the data is read from a string | ||
chunk = Kerma.from_string( self.chunk_string, 7 ) | ||
|
||
verify_chunk( self, chunk ) | ||
|
||
# the data is given explicitly for an outgoing particle | ||
chunk = Kerma( particle = 1001, values = [ 10, 9, 8, 7, 6, 5, 4 ] ) | ||
|
||
verify_outgoing_chunk( self, chunk ) | ||
|
||
# the data is read from a string for an outgoing particle | ||
chunk = Kerma.from_string( self.chunk_outgoing_string, 7 ) | ||
|
||
verify_outgoing_chunk( self, chunk ) | ||
|
||
if __name__ == '__main__' : | ||
|
||
unittest.main() |