diff --git a/CMakeLists.txt b/CMakeLists.txt index 440ec5d..8d2e83f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,8 @@ if( NDItk.python ) python/src/multigroup/AverageFissionEnergyRelease.python.cpp python/src/multigroup/FissionNeutronMultiplicity.python.cpp python/src/multigroup/FissionNeutronProduction.python.cpp + python/src/multigroup/FissionNeutronSpectrumVector.python.cpp + python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp python/src/multigroup/Velocities.python.cpp python/src/multigroup/HeatingNumbers.python.cpp python/src/multigroup/Kerma.python.cpp diff --git a/cmake/unit_testing_python.cmake b/cmake/unit_testing_python.cmake index f54d973..9b57c40 100644 --- a/cmake/unit_testing_python.cmake +++ b/cmake/unit_testing_python.cmake @@ -34,6 +34,8 @@ add_python_test( multigroup.TotalCrossSection multigroup/Test_NDItk_ add_python_test( multigroup.AverageFissionEnergyRelease multigroup/Test_NDItk_multigroup_AverageFissionEnergyRelease.py ) add_python_test( multigroup.FissionNeutronMultiplicity multigroup/Test_NDItk_multigroup_FissionNeutronMultiplicity.py ) add_python_test( multigroup.FissionNeutronProduction multigroup/Test_NDItk_multigroup_FissionNeutronProduction.py ) +add_python_test( multigroup.FissionNeutronSpectrumMatrix multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumMatrix.py ) +add_python_test( multigroup.FissionNeutronSpectrumVector multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumVector.py ) add_python_test( multigroup.Velocities multigroup/Test_NDItk_multigroup_Velocities.py ) add_python_test( multigroup.HeatingNumbers multigroup/Test_NDItk_multigroup_HeatingNumbers.py ) add_python_test( multigroup.Kerma multigroup/Test_NDItk_multigroup_Kerma.py ) diff --git a/python/examples/.ipynb_checkpoints/NDItk-getting-started-example-1-checkpoint.ipynb b/python/examples/.ipynb_checkpoints/NDItk-getting-started-example-1-checkpoint.ipynb new file mode 100644 index 0000000..4896e75 --- /dev/null +++ b/python/examples/.ipynb_checkpoints/NDItk-getting-started-example-1-checkpoint.ipynb @@ -0,0 +1,111 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "f53a715b", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "# a recursive function to find all files with a given extension in a directory\n", + "def getFilesInFolder( directory, extension ) :\n", + "\n", + " files = os.listdir( directory )\n", + " everything = list()\n", + "\n", + " for entry in files :\n", + "\n", + " file = os.path.join( directory, entry )\n", + "\n", + " if os.path.isdir( file ) :\n", + "\n", + " everything += getFilesInFolder( file, extension )\n", + "\n", + " else :\n", + "\n", + " everything.append( file )\n", + "\n", + " return [ file for file in everything if file.endswith( extension ) ]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "74836354", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "FAILED /Users/wim/Projects/libraries/ndi/mt80_30/t20/50118.851nm\n", + "-------------------------\n", + " 1 files\n", + " 1 failed\n", + "elapsed time = 0.000673 s\n", + "-------------------------\n" + ] + } + ], + "source": [ + "import NDItk\n", + "import time\n", + "\n", + "path = '/Users/wim/Projects/libraries/ndi/mt80_30'\n", + "files = getFilesInFolder( path, '1001.851nm' )\n", + "failed = []\n", + "\n", + "start = time.perf_counter()\n", + "for file in files :\n", + "\n", + " try :\n", + "\n", + " table = NDItk.MultigroupTable.from_file( file )\n", + "\n", + " except :\n", + "\n", + " print( 'FAILED', file )\n", + " failed.append( file )\n", + "\n", + "end = time.perf_counter()\n", + "\n", + "print( '-------------------------' )\n", + "print( '{:4} files'.format( len( files ) ) )\n", + "print( '{:4} failed'.format( len( failed ) ) )\n", + "print( 'elapsed time = {:.3} s'.format( end - start ) )\n", + "print( '-------------------------' )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d108125", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/python/examples/NDItk-getting-started-example-1.ipynb b/python/examples/NDItk-getting-started-example-1.ipynb new file mode 100644 index 0000000..4a308f9 --- /dev/null +++ b/python/examples/NDItk-getting-started-example-1.ipynb @@ -0,0 +1,121 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "f53a715b", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "# a recursive function to find all files with a given extension in a directory\n", + "def getFilesInFolder( directory, extension ) :\n", + "\n", + " files = os.listdir( directory )\n", + " everything = list()\n", + "\n", + " for entry in files :\n", + "\n", + " file = os.path.join( directory, entry )\n", + "\n", + " if os.path.isdir( file ) :\n", + "\n", + " everything += getFilesInFolder( file, extension )\n", + "\n", + " else :\n", + "\n", + " everything.append( file )\n", + "\n", + " return [ file for file in everything if file.endswith( extension ) ]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "74836354", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-------------------------\n", + "13455 files\n", + " 0 failed\n", + "elapsed time = 5.79e+02 s\n", + "-------------------------\n" + ] + } + ], + "source": [ + "import NDItk\n", + "import time\n", + "\n", + "path = '/Users/wim/Projects/libraries/ndi/mt80'\n", + "files = getFilesInFolder( path, 'nm' )\n", + "failed = []\n", + "\n", + "start = time.perf_counter()\n", + "for file in files :\n", + "\n", + " try :\n", + "\n", + " table = NDItk.MultigroupTable.from_file( file )\n", + "\n", + " except :\n", + "\n", + " print( 'FAILED', file )\n", + " failed.append( file )\n", + "\n", + "end = time.perf_counter()\n", + "\n", + "print( '-------------------------' )\n", + "print( '{:4} files'.format( len( files ) ) )\n", + "print( '{:4} failed'.format( len( failed ) ) )\n", + "print( 'elapsed time = {:.3} s'.format( end - start ) )\n", + "print( '-------------------------' )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d108125", + "metadata": {}, + "outputs": [], + "source": [ + "import NDItk\n", + "table = NDItk.MultigroupTable.from_file( '/Users/wim/Projects/libraries/ndi/mt80_30/t22/38086.853nm' )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ed6d2e8", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/python/src/multigroup.python.cpp b/python/src/multigroup.python.cpp index becfe1b..c4f1d21 100644 --- a/python/src/multigroup.python.cpp +++ b/python/src/multigroup.python.cpp @@ -23,6 +23,8 @@ namespace multigroup { void wrapAverageFissionEnergyRelease( python::module&, python::module& ); void wrapFissionNeutronMultiplicity( python::module&, python::module& ); void wrapFissionNeutronProduction( python::module&, python::module& ); + void wrapFissionNeutronSpectrumMatrix( python::module&, python::module& ); + void wrapFissionNeutronSpectrumVector( python::module&, python::module& ); void wrapOutgoingParticleTypes( python::module&, python::module& ); void wrapOutgoingParticleTransportData( python::module&, python::module& ); void wrapLegendreMoment( python::module&, python::module& ); @@ -51,6 +53,8 @@ void wrapMultigroup( python::module& module, python::module& viewmodule ) { multigroup::wrapAverageFissionEnergyRelease( submodule, viewmodule ); multigroup::wrapFissionNeutronMultiplicity( submodule, viewmodule ); multigroup::wrapFissionNeutronProduction( submodule, viewmodule ); + multigroup::wrapFissionNeutronSpectrumMatrix( submodule, viewmodule ); + multigroup::wrapFissionNeutronSpectrumVector( submodule, viewmodule ); multigroup::wrapOutgoingParticleTypes( submodule, viewmodule ); multigroup::wrapOutgoingParticleTransportData( submodule, viewmodule ); multigroup::wrapLegendreMoment( submodule, viewmodule ); diff --git a/python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp b/python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp new file mode 100644 index 0000000..a59c7ef --- /dev/null +++ b/python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp @@ -0,0 +1,80 @@ +// system includes +#include +#include + +// local includes +#include "NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp" +#include "tools/views/views-python.hpp" +#include "definitions.hpp" +#include "read.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace multigroup { + +void wrapFissionNeutronSpectrumMatrix( python::module& module, python::module& ) { + + // type aliases + using Record = njoy::NDItk::multigroup::FissionNeutronSpectrumMatrix; + using FissionType = njoy::NDItk::multigroup::FissionType; + + // wrap views created by this record + + // create the record + python::class_< Record > record( + + module, + "FissionNeutronSpectrumMatrix", + "A fission neutron spectrum matrix record for multigroup neutron and photon data" + ); + + // wrap the record + record + .def( + + python::init< FissionType, std::vector< double > >(), + python::arg( "type" ), python::arg( "values" ), + "Initialise the record\n\n" + "Arguments:\n" + " self the record\n" + " values the fission neutron spectrum matrix values" + ) + .def_property_readonly( + + "type", + &Record::type, + "The fission type defined by this record" + ) + .def_property_readonly( + + "number_groups", + &Record::numberGroups, + "The number of groups defined by this record" + ) + .def_property_readonly( + + "matrix", + [] ( const Record& self ) -> DoubleRange2D + { return self.matrix(); }, + "The matrix defined by this record" + ) + .def_static( + + "from_string", + [] ( const std::string& string, unsigned int number ) -> Record + { return readWithFissionSubtype< 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 groups" + ); + + // add standard record definitions + addStandardRecordDefinitions< Record, DoubleRange >( record ); +} + +} // multigroup namespace diff --git a/python/src/multigroup/FissionNeutronSpectrumVector.python.cpp b/python/src/multigroup/FissionNeutronSpectrumVector.python.cpp new file mode 100644 index 0000000..2076373 --- /dev/null +++ b/python/src/multigroup/FissionNeutronSpectrumVector.python.cpp @@ -0,0 +1,73 @@ +// system includes +#include +#include + +// local includes +#include "NDItk/multigroup/FissionNeutronSpectrumVector.hpp" +#include "tools/views/views-python.hpp" +#include "definitions.hpp" +#include "read.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace multigroup { + +void wrapFissionNeutronSpectrumVector( python::module& module, python::module& ) { + + // type aliases + using Record = njoy::NDItk::multigroup::FissionNeutronSpectrumVector; + using FissionType = njoy::NDItk::multigroup::FissionType; + + // wrap views created by this record + + // create the record + python::class_< Record > record( + + module, + "FissionNeutronSpectrumVector", + "A fission neutron spectrum vector record for multigroup neutron and photon data" + ); + + // wrap the record + record + .def( + + python::init< FissionType, std::vector< double > >(), + python::arg( "type" ), python::arg( "values" ), + "Initialise the record\n\n" + "Arguments:\n" + " self the record\n" + " values the fission neutron spectrum vector values" + ) + .def_property_readonly( + + "type", + &Record::type, + "The fission type defined by this record" + ) + .def_property_readonly( + + "number_groups", + &Record::numberGroups, + "The number of groups defined by this record" + ) + .def_static( + + "from_string", + [] ( const std::string& string, unsigned int number ) -> Record + { return readWithFissionSubtype< 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 groups" + ); + + // add standard record definitions + addStandardRecordDefinitions< Record, DoubleRange >( record ); +} + +} // multigroup namespace diff --git a/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumMatrix.py b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumMatrix.py new file mode 100644 index 0000000..6c8751c --- /dev/null +++ b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumMatrix.py @@ -0,0 +1,170 @@ +# standard imports +import unittest + +# third party imports + +# local imports +from NDItk.multigroup import FissionNeutronSpectrumMatrix +from NDItk.multigroup import FissionType + +class Test_NDItk_multigroup_FissionNeutronSpectrumMatrix( unittest.TestCase ) : + """Unit test for the FissionNeutronSpectrumMatrix class.""" + + chunk_values = [ 1, 2, 3, 4, 5, 6, 7, + 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, + 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, + 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, + 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, + 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, + 1.6, 2.6, 3.6, 4.6, 5.6, 6.6, 7.6 ] + chunk_string = ( 'chi_mat_pr\n' + ' 1 2 3 4 5\n' + ' 6 7 1.1 2.1 3.1\n' + ' 4.1 5.1 6.1 7.1 1.2\n' + ' 2.2 3.2 4.2 5.2 6.2\n' + ' 7.2 1.3 2.3 3.3 4.3\n' + ' 5.3 6.3 7.3 1.4 2.4\n' + ' 3.4 4.4 5.4 6.4 7.4\n' + ' 1.5 2.5 3.5 4.5 5.5\n' + ' 6.5 7.5 1.6 2.6 3.6\n' + ' 4.6 5.6 6.6 7.6\n' ) + + def test_component( self ) : + + def verify_chunk( self, chunk ) : + + # verify content + self.assertEqual( FissionType.Prompt, chunk.type ) + self.assertEqual( 7, chunk.number_groups ) + self.assertAlmostEqual( 1, chunk.values[0] ) + self.assertAlmostEqual( 2, chunk.values[1] ) + self.assertAlmostEqual( 3, chunk.values[2] ) + self.assertAlmostEqual( 4, chunk.values[3] ) + self.assertAlmostEqual( 5, chunk.values[4] ) + self.assertAlmostEqual( 6, chunk.values[5] ) + self.assertAlmostEqual( 7, chunk.values[6] ) + self.assertAlmostEqual( 1.1, chunk.values[7] ) + self.assertAlmostEqual( 2.1, chunk.values[8] ) + self.assertAlmostEqual( 3.1, chunk.values[9] ) + self.assertAlmostEqual( 4.1, chunk.values[10] ) + self.assertAlmostEqual( 5.1, chunk.values[11] ) + self.assertAlmostEqual( 6.1, chunk.values[12] ) + self.assertAlmostEqual( 7.1, chunk.values[13] ) + self.assertAlmostEqual( 1.2, chunk.values[14] ) + self.assertAlmostEqual( 2.2, chunk.values[15] ) + self.assertAlmostEqual( 3.2, chunk.values[16] ) + self.assertAlmostEqual( 4.2, chunk.values[17] ) + self.assertAlmostEqual( 5.2, chunk.values[18] ) + self.assertAlmostEqual( 6.2, chunk.values[19] ) + self.assertAlmostEqual( 7.2, chunk.values[20] ) + self.assertAlmostEqual( 1.3, chunk.values[21] ) + self.assertAlmostEqual( 2.3, chunk.values[22] ) + self.assertAlmostEqual( 3.3, chunk.values[23] ) + self.assertAlmostEqual( 4.3, chunk.values[24] ) + self.assertAlmostEqual( 5.3, chunk.values[25] ) + self.assertAlmostEqual( 6.3, chunk.values[26] ) + self.assertAlmostEqual( 7.3, chunk.values[27] ) + self.assertAlmostEqual( 1.4, chunk.values[28] ) + self.assertAlmostEqual( 2.4, chunk.values[29] ) + self.assertAlmostEqual( 3.4, chunk.values[30] ) + self.assertAlmostEqual( 4.4, chunk.values[31] ) + self.assertAlmostEqual( 5.4, chunk.values[32] ) + self.assertAlmostEqual( 6.4, chunk.values[33] ) + self.assertAlmostEqual( 7.4, chunk.values[34] ) + self.assertAlmostEqual( 1.5, chunk.values[35] ) + self.assertAlmostEqual( 2.5, chunk.values[36] ) + self.assertAlmostEqual( 3.5, chunk.values[37] ) + self.assertAlmostEqual( 4.5, chunk.values[38] ) + self.assertAlmostEqual( 5.5, chunk.values[39] ) + self.assertAlmostEqual( 6.5, chunk.values[40] ) + self.assertAlmostEqual( 7.5, chunk.values[41] ) + self.assertAlmostEqual( 1.6, chunk.values[42] ) + self.assertAlmostEqual( 2.6, chunk.values[43] ) + self.assertAlmostEqual( 3.6, chunk.values[44] ) + self.assertAlmostEqual( 4.6, chunk.values[45] ) + self.assertAlmostEqual( 5.6, chunk.values[46] ) + self.assertAlmostEqual( 6.6, chunk.values[47] ) + self.assertAlmostEqual( 7.6, chunk.values[48] ) + + self.assertAlmostEqual( 1, chunk.matrix[0][0] ) + self.assertAlmostEqual( 2, chunk.matrix[0][1] ) + self.assertAlmostEqual( 3, chunk.matrix[0][2] ) + self.assertAlmostEqual( 4, chunk.matrix[0][3] ) + self.assertAlmostEqual( 5, chunk.matrix[0][4] ) + self.assertAlmostEqual( 6, chunk.matrix[0][5] ) + self.assertAlmostEqual( 7, chunk.matrix[0][6] ) + self.assertAlmostEqual( 1.1, chunk.matrix[1][0] ) + self.assertAlmostEqual( 2.1, chunk.matrix[1][1] ) + self.assertAlmostEqual( 3.1, chunk.matrix[1][2] ) + self.assertAlmostEqual( 4.1, chunk.matrix[1][3] ) + self.assertAlmostEqual( 5.1, chunk.matrix[1][4] ) + self.assertAlmostEqual( 6.1, chunk.matrix[1][5] ) + self.assertAlmostEqual( 7.1, chunk.matrix[1][6] ) + self.assertAlmostEqual( 1.2, chunk.matrix[2][0] ) + self.assertAlmostEqual( 2.2, chunk.matrix[2][1] ) + self.assertAlmostEqual( 3.2, chunk.matrix[2][2] ) + self.assertAlmostEqual( 4.2, chunk.matrix[2][3] ) + self.assertAlmostEqual( 5.2, chunk.matrix[2][4] ) + self.assertAlmostEqual( 6.2, chunk.matrix[2][5] ) + self.assertAlmostEqual( 7.2, chunk.matrix[2][6] ) + self.assertAlmostEqual( 1.3, chunk.matrix[3][0] ) + self.assertAlmostEqual( 2.3, chunk.matrix[3][1] ) + self.assertAlmostEqual( 3.3, chunk.matrix[3][2] ) + self.assertAlmostEqual( 4.3, chunk.matrix[3][3] ) + self.assertAlmostEqual( 5.3, chunk.matrix[3][4] ) + self.assertAlmostEqual( 6.3, chunk.matrix[3][5] ) + self.assertAlmostEqual( 7.3, chunk.matrix[3][6] ) + self.assertAlmostEqual( 1.4, chunk.matrix[4][0] ) + self.assertAlmostEqual( 2.4, chunk.matrix[4][1] ) + self.assertAlmostEqual( 3.4, chunk.matrix[4][2] ) + self.assertAlmostEqual( 4.4, chunk.matrix[4][3] ) + self.assertAlmostEqual( 5.4, chunk.matrix[4][4] ) + self.assertAlmostEqual( 6.4, chunk.matrix[4][5] ) + self.assertAlmostEqual( 7.4, chunk.matrix[4][6] ) + self.assertAlmostEqual( 1.5, chunk.matrix[5][0] ) + self.assertAlmostEqual( 2.5, chunk.matrix[5][1] ) + self.assertAlmostEqual( 3.5, chunk.matrix[5][2] ) + self.assertAlmostEqual( 4.5, chunk.matrix[5][3] ) + self.assertAlmostEqual( 5.5, chunk.matrix[5][4] ) + self.assertAlmostEqual( 6.5, chunk.matrix[5][5] ) + self.assertAlmostEqual( 7.5, chunk.matrix[5][6] ) + self.assertAlmostEqual( 1.6, chunk.matrix[6][0] ) + self.assertAlmostEqual( 2.6, chunk.matrix[6][1] ) + self.assertAlmostEqual( 3.6, chunk.matrix[6][2] ) + self.assertAlmostEqual( 4.6, chunk.matrix[6][3] ) + self.assertAlmostEqual( 5.6, chunk.matrix[6][4] ) + self.assertAlmostEqual( 6.6, chunk.matrix[6][5] ) + self.assertAlmostEqual( 7.6, chunk.matrix[6][6] ) + + self.assertEqual( self.chunk_string, chunk.to_string() ) + + # verify the record + self.assertEqual( 'chi_mat_pr', chunk.keyword ) + self.assertEqual( False, chunk.empty ) + self.assertEqual( 49, chunk.size ) + + values = chunk.values + for index in range( chunk.size ) : + + self.assertAlmostEqual( self.chunk_values[index], values[index] ) + + # the data is given explicitly + chunk = FissionNeutronSpectrumMatrix( type = FissionType.Prompt, + values = [ 1, 2, 3, 4, 5, 6, 7, + 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, + 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, + 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, + 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, + 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, + 1.6, 2.6, 3.6, 4.6, 5.6, 6.6, 7.6 ] ) + + verify_chunk( self, chunk ) + + # the data is read from a string + chunk = FissionNeutronSpectrumMatrix.from_string( self.chunk_string, 7 ) + + verify_chunk( self, chunk ) + +if __name__ == '__main__' : + + unittest.main() diff --git a/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumVector.py b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumVector.py new file mode 100644 index 0000000..3a60024 --- /dev/null +++ b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumVector.py @@ -0,0 +1,58 @@ +# standard imports +import unittest + +# third party imports + +# local imports +from NDItk.multigroup import FissionNeutronSpectrumVector +from NDItk.multigroup import FissionType + +class Test_NDItk_multigroup_FissionNeutronSpectrumVector( unittest.TestCase ) : + """Unit test for the FissionNeutronSpectrumVector class.""" + + chunk_values = [ 1, 2, 3, 4, 5, 6, 7 ] + chunk_string = ( 'chi_vec_pr\n' + ' 1 2 3 4 5\n' + ' 6 7\n' ) + + def test_component( self ) : + + def verify_chunk( self, chunk ) : + + # verify content + self.assertEqual( FissionType.Prompt, chunk.type ) + self.assertEqual( 7, chunk.number_groups ) + self.assertAlmostEqual( 1, chunk.values[0] ) + self.assertAlmostEqual( 2, chunk.values[1] ) + self.assertAlmostEqual( 3, chunk.values[2] ) + self.assertAlmostEqual( 4, chunk.values[3] ) + self.assertAlmostEqual( 5, chunk.values[4] ) + self.assertAlmostEqual( 6, chunk.values[5] ) + self.assertAlmostEqual( 7, chunk.values[6] ) + + self.assertEqual( self.chunk_string, chunk.to_string() ) + + # verify the record + self.assertEqual( 'chi_vec_pr', 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] ) + + # the data is given explicitly + chunk = FissionNeutronSpectrumVector( type = FissionType.Prompt, + values = [ 1, 2, 3, 4, 5, 6, 7 ] ) + + verify_chunk( self, chunk ) + + # the data is read from a string + chunk = FissionNeutronSpectrumVector.from_string( self.chunk_string, 7 ) + + verify_chunk( self, chunk ) + +if __name__ == '__main__' : + + unittest.main() diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp index eeefe1a..1340f1a 100644 --- a/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp @@ -6,7 +6,7 @@ * * @param[in,out] iter an iterator to the current position in the input * @param[in,out] end an iterator to the end of the input - * @param[in,out] number the number of fission neutron spectrum vector values + * @param[in,out] number the number of groups */ template< typename Iterator > void read( Iterator& iter, const Iterator& end, std::size_t number ) {