Skip to content

Commit

Permalink
Merge pull request #4 from njoy/fix/review
Browse files Browse the repository at this point in the history
Fix/review
  • Loading branch information
whaeck authored May 22, 2024
2 parents 5ff97db + f9e4a4f commit 87ec6a9
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 99 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if( NDItk.python )
python/src/multigroup/Metadata.python.cpp
python/src/multigroup/CrossSection.python.cpp
python/src/multigroup/FluxWeights.python.cpp
python/src/multigroup/Structure.python.cpp
python/src/multigroup/EnergyGroupStructure.python.cpp
python/src/multigroup/ReactionCrossSections.python.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_subdirectory( src/NDItk/base/IntegerListRecord/test )
add_subdirectory( src/NDItk/base/RealListRecord/test )

add_subdirectory( src/NDItk/multigroup/Metadata/test )
add_subdirectory( src/NDItk/multigroup/Structure/test )
add_subdirectory( src/NDItk/multigroup/EnergyGroupStructure/test )
add_subdirectory( src/NDItk/multigroup/FluxWeights/test )
add_subdirectory( src/NDItk/multigroup/CrossSection/test )
add_subdirectory( src/NDItk/multigroup/ReactionCrossSections/test )
Expand Down
3 changes: 1 addition & 2 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ message( STATUS "Adding NDItk Python unit testing" )
add_python_test( multigroup.Metadata multigroup/Test_NDItk_multigroup_Metadata.py )
add_python_test( multigroup.CrossSection multigroup/Test_NDItk_multigroup_CrossSection.py )
add_python_test( multigroup.FluxWeights multigroup/Test_NDItk_multigroup_FluxWeights.py )
add_python_test( multigroup.Structure multigroup/Test_NDItk_multigroup_Structure.py )
add_python_test( multigroup.EnergyGroupStructure multigroup/Test_NDItk_multigroup_EnergyGroupStructure.py )
add_python_test( multigroup.ReactionCrossSections multigroup/Test_NDItk_multigroup_ReactionCrossSections.py )

add_python_test( MultigroupTable Test_NDItk_MultigroupTable.py )

8 changes: 4 additions & 4 deletions python/src/MultigroupTable.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 EnergyGroupStructure = njoy::NDItk::multigroup::EnergyGroupStructure;
using FluxWeights = njoy::NDItk::multigroup::FluxWeights;
using ReactionCrossSections = njoy::NDItk::multigroup::ReactionCrossSections;

Expand All @@ -33,13 +33,13 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
table
.def(

python::init< std::string, std::string, std::string, std::string,
python::init< std::string, std::string, std::string, std::string,
double, double, double, double,
Structure, FluxWeights,
EnergyGroupStructure, 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( "temperature" ), python::arg( "dilution" ),
python::arg( "structure" ), python::arg( "flux" ), python::arg( "xs" ),
"Initialise the table\n\n"
"Arguments:\n"
Expand Down
4 changes: 2 additions & 2 deletions python/src/multigroup.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace multigroup {
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 wrapEnergyGroupStructure( python::module&, python::module& );
void wrapReactionCrossSections( python::module&, python::module& );
}

Expand All @@ -29,6 +29,6 @@ void wrapMultigroup( python::module& module, python::module& viewmodule ) {
multigroup::wrapMetadata( submodule, viewmodule );
multigroup::wrapCrossSection( submodule, viewmodule );
multigroup::wrapFluxWeights( submodule, viewmodule );
multigroup::wrapStructure( submodule, viewmodule );
multigroup::wrapEnergyGroupStructure( submodule, viewmodule );
multigroup::wrapReactionCrossSections( submodule, viewmodule );
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <pybind11/stl.h>

// local includes
#include "NDItk/multigroup/Structure.hpp"
#include "NDItk/multigroup/EnergyGroupStructure.hpp"
#include "tools/views/views-python.hpp"
#include "definitions.hpp"
#include "read.hpp"
Expand All @@ -13,18 +13,18 @@ namespace python = pybind11;

namespace multigroup {

void wrapStructure( python::module& module, python::module& ) {
void wrapEnergyGroupStructure( python::module& module, python::module& ) {

// type aliases
using Record = njoy::NDItk::multigroup::Structure;
using Record = njoy::NDItk::multigroup::EnergyGroupStructure;

// wrap views created by this record

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

module,
"Structure",
"EnergyGroupStructure",
"A group structure record for multigroup neutron and photon data"
);

Expand Down
13 changes: 6 additions & 7 deletions python/test/Test_NDItk_MultigroupTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# local imports
from NDItk import MultigroupTable
from NDItk.multigroup import Structure
from NDItk.multigroup import EnergyGroupStructure
from NDItk.multigroup import FluxWeights
from NDItk.multigroup import ReactionCrossSections
from NDItk.multigroup import CrossSection
Expand Down Expand Up @@ -33,8 +33,8 @@ def verify_chunk( self, chunk ) :
structure = chunk.structure
self.assertEqual( 7, structure.number_groups )
self.assertAlmostEqual( 20, structure.boundaries[0] )
self.assertAlmostEqual( 18, structure.boundaries[1] )
self.assertAlmostEqual( 16, structure.boundaries[2] )
self.assertAlmostEqual( 18.123456789, structure.boundaries[1] )
self.assertAlmostEqual( 16.0000000000001, structure.boundaries[2] )
self.assertAlmostEqual( 14, structure.boundaries[3] )
self.assertAlmostEqual( 10, structure.boundaries[4] )
self.assertAlmostEqual( 5, structure.boundaries[5] )
Expand Down Expand Up @@ -103,15 +103,14 @@ def verify_chunk( self, chunk ) :
chunk = MultigroupTable( zaid = '92235.711nm', libname = 'mendf71x', source = '12/22/2011',
process = '08/07/2013', awr = 233.0248, weight = 235.043937521619,
temperature = 2.53e-8, dilution = 1e+10,
structure = Structure( [ 20., 18., 16., 14., 10., 5, 1, 1e-11 ] ),
structure = EnergyGroupStructure( [ 20., 18.123456789, 16.0000000000001, 14., 10., 5, 1, 1e-11 ] ),
flux = FluxWeights( [ 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 ] ),
xs = ReactionCrossSections(
xs = [ CrossSection( 2, 0., [ 10., 20., 30., 40., 50., 60., 70. ] ),
xs = ReactionCrossSections(
xs = [ CrossSection( 2, 0., [ 10., 20., 30., 40., 50., 60., 70. ] ),
CrossSection( 16, 1.1234567, [ 1., 2., 3., 4., 5., 6., 7. ] ) ] ) )

verify_chunk( self, chunk )

if __name__ == '__main__' :

unittest.main()

10 changes: 5 additions & 5 deletions python/test/multigroup/Test_NDItk_multigroup_CrossSection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
class Test_NDItk_multigroup_CrossSection( unittest.TestCase ) :
"""Unit test for the CrossSection class."""

chunk_values = [ 2, 0, 10., 20., 30., 40., 50., 60., 70. ]
chunk_values = [ 2, 0, 10.0000000000001, 20., 30., 40.12345678, 50., 60., 70. ]
chunk_string = ( ' 2 0\n'
' 10 20 30 40 50\n'
' 10.0000000000001 20 30 40.12345678 50\n'
' 60 70\n' )

def test_component( self ) :
Expand All @@ -22,10 +22,10 @@ def verify_chunk( self, chunk ) :
self.assertEqual( 7, chunk.number_groups )
self.assertEqual( 2, chunk.identifier )
self.assertAlmostEqual( 0, chunk.qvalue )
self.assertAlmostEqual( 10, chunk.cross_sections[0] )
self.assertAlmostEqual( 10.0000000000001, chunk.cross_sections[0] )
self.assertAlmostEqual( 20, chunk.cross_sections[1] )
self.assertAlmostEqual( 30, chunk.cross_sections[2] )
self.assertAlmostEqual( 40, chunk.cross_sections[3] )
self.assertAlmostEqual( 40.12345678, chunk.cross_sections[3] )
self.assertAlmostEqual( 50, chunk.cross_sections[4] )
self.assertAlmostEqual( 60, chunk.cross_sections[5] )
self.assertAlmostEqual( 70, chunk.cross_sections[6] )
Expand All @@ -43,7 +43,7 @@ def verify_chunk( self, chunk ) :

# the data is given explicitly
chunk = CrossSection( reaction = 2, qvalue = 0.0,
values = [ 10., 20., 30., 40., 50., 60., 70. ] )
values = [ 10.0000000000001, 20., 30., 40.12345678, 50., 60., 70. ] )

verify_chunk( self, chunk )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# third party imports

# local imports
from NDItk.multigroup import Structure
from NDItk.multigroup import EnergyGroupStructure

class Test_NDItk_multigroup_Structure( unittest.TestCase ) :
"""Unit test for the Structure class."""
class Test_NDItk_multigroup_EnergyGroupStructure( unittest.TestCase ) :
"""Unit test for the EnergyGroupStructure class."""

chunk_values = [ 20, 18, 16, 14, 10, 5, 1, 1e-11 ]
chunk_string = ( 'e_bounds\n'
Expand Down Expand Up @@ -42,12 +42,12 @@ def verify_chunk( self, chunk ) :
self.assertAlmostEqual( self.chunk_values[index], values[index] )

# the data is given explicitly
chunk = Structure( boundaries = [ 20., 18., 16., 14., 10., 5, 1, 1e-11 ] )
chunk = EnergyGroupStructure( boundaries = [ 20., 18., 16., 14., 10., 5, 1, 1e-11 ] )

verify_chunk( self, chunk )

# the data is read from a string
chunk = Structure.from_string( self.chunk_string, 8 )
chunk = EnergyGroupStructure.from_string( self.chunk_string, 8 )

verify_chunk( self, chunk )

Expand Down
6 changes: 3 additions & 3 deletions src/NDItk/MultigroupTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// other includes
#include "tools/Log.hpp"
#include "NDItk/multigroup/Metadata.hpp"
#include "NDItk/multigroup/Structure.hpp"
#include "NDItk/multigroup/EnergyGroupStructure.hpp"
#include "NDItk/multigroup/FluxWeights.hpp"
#include "NDItk/multigroup/ReactionCrossSections.hpp"

Expand All @@ -21,7 +21,7 @@ class MultigroupTable {
/* fields */

multigroup::Metadata metadata_;
multigroup::Structure structure_;
multigroup::EnergyGroupStructure structure_;
multigroup::FluxWeights weights_;
multigroup::ReactionCrossSections xs_;

Expand All @@ -46,7 +46,7 @@ class MultigroupTable {
/**
* @brief Return the primary group structure record
*/
const multigroup::Structure& structure() const { return this->structure_; }
const multigroup::EnergyGroupStructure& structure() const { return this->structure_; }

/**
* @brief Return the flux weight record
Expand Down
2 changes: 1 addition & 1 deletion src/NDItk/MultigroupTable/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MultigroupTable() : metadata_(), structure_(), weights_(), xs_() {}
MultigroupTable( std::string zaid, std::string libname, std::string source,
std::string process, double awr, double weight, double temperature,
double dilution,
multigroup::Structure structure,
multigroup::EnergyGroupStructure structure,
multigroup::FluxWeights weigths,
multigroup::ReactionCrossSections xs ) :
metadata_( std::move( zaid ), std::move( libname ), std::move( source ),
Expand Down
11 changes: 6 additions & 5 deletions src/NDItk/MultigroupTable/test/MultigroupTable.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ SCENARIO( "MultigroupTable" ) {
double weight = 235.043937521619;
double temperature = 2.53e-8;
double dilution = 1e+10;
multigroup::Structure structure( { 20., 18., 16., 14., 10., 5, 1, 1e-11 } );
multigroup::EnergyGroupStructure structure( { 20., 18.123456789, 16.0000000000001,
14., 10., 5, 1, 1e-11 } );
multigroup::FluxWeights weights( { 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 } );
multigroup::ReactionCrossSections xs( { { 2, 0.0, { 10., 20., 30., 40., 50., 60., 70. } },
{ 16, 1.1234567, { 1., 2., 3., 4., 5., 6., 7. } } } );
Expand Down Expand Up @@ -92,7 +93,7 @@ SCENARIO( "MultigroupTable" ) {
double weight = 235.043937521619;
double temperature = 2.53e-8;
double dilution = 1e+10;
multigroup::Structure structure( { 20., 18., 16., 14., 10., 5, 1, 1e-11 } ); // <-- 7 groups
multigroup::EnergyGroupStructure structure( { 20., 18., 16., 14., 10., 5, 1, 1e-11 } ); // <-- 7 groups
multigroup::FluxWeights weights( { 0.1, 0.2, 0.25, 0.05, 0.15, 0.04 } ); // <-- 6 groups
multigroup::ReactionCrossSections xs( { { 2, 0.0, { 10., 20., 30., 40., 50., 60., 70., 80. } }, // <-- 8 groups
{ 16, 1.1234567, { 1., 2., 3., 4., 5., 6., 7., 8. } } } );
Expand Down Expand Up @@ -130,7 +131,7 @@ std::string chunk() {
"num_reac\n"
" 2\n"
"e_bounds\n"
" 20 18 16 14 10\n"
" 20 18.123456789 16.0000000000001 14 10\n"
" 5 1 1e-11\n"
"wgts\n"
" 0.1 0.2 0.25 0.05 0.15\n"
Expand Down Expand Up @@ -166,8 +167,8 @@ void verifyChunk( const MultigroupTable& chunk ) {
CHECK( 8 == chunk.structure().boundaries().size() );
CHECK( 7 == chunk.structure().numberGroups() );
CHECK_THAT( 20, WithinRel( chunk.structure().boundaries()[0] ) );
CHECK_THAT( 18, WithinRel( chunk.structure().boundaries()[1] ) );
CHECK_THAT( 16, WithinRel( chunk.structure().boundaries()[2] ) );
CHECK_THAT( 18.123456789, WithinRel( chunk.structure().boundaries()[1] ) );
CHECK_THAT( 16.0000000000001, WithinRel( chunk.structure().boundaries()[2] ) );
CHECK_THAT( 14, WithinRel( chunk.structure().boundaries()[3] ) );
CHECK_THAT( 10, WithinRel( chunk.structure().boundaries()[4] ) );
CHECK_THAT( 5, WithinRel( chunk.structure().boundaries()[5] ) );
Expand Down
12 changes: 6 additions & 6 deletions src/NDItk/base/RealListRecord/src/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void write( OutputIterator& iter ) const {

while ( full-- ) {

buffer << " " << x[0];
buffer << ' ' << x[1];
buffer << ' ' << x[2];
buffer << ' ' << x[3];
buffer << ' ' << x[4] << '\n';
buffer << " " << std::setprecision( 15 ) << x[0];
buffer << ' ' << std::setprecision( 15 ) << x[1];
buffer << ' ' << std::setprecision( 15 ) << x[2];
buffer << ' ' << std::setprecision( 15 ) << x[3];
buffer << ' ' << std::setprecision( 15 ) << x[4] << '\n';
x += 5;
}

Expand All @@ -29,7 +29,7 @@ void write( OutputIterator& iter ) const {
buffer << " ";
while ( partial-- ) {

buffer << ' ' << *x;
buffer << ' ' << std::setprecision( 15 ) << *x;
++x;
}
buffer << '\n';
Expand Down
10 changes: 5 additions & 5 deletions src/NDItk/base/RealListRecord/test/RealListRecord.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SCENARIO( "RealListRecord" ) {

WHEN( "the data is given explicitly" ) {

RealListRecord chunk( "e_bounds", { 20., 18., 16., 14., 10., 5, 1, 1e-11 } );
RealListRecord chunk( "e_bounds", { 20.000001, 18.000000001, 16.0000000000001, 14., 10., 5, 1, 1e-11 } );

THEN( "a RealListRecord can be constructed and members can "
"be tested" ) {
Expand Down Expand Up @@ -69,7 +69,7 @@ SCENARIO( "RealListRecord" ) {
std::string chunk() {

return "e_bounds\n"
" 20 18 16 14 10\n"
" 20.000001 18.000000001 16.0000000000001 14 10\n"
" 5 1 1e-11\n";
}

Expand All @@ -79,9 +79,9 @@ void verifyChunk( const RealListRecord& chunk ) {
CHECK( false == chunk.empty() );
CHECK( 8 == chunk.size() );
CHECK( 8 == chunk.values().size() );
CHECK_THAT( 20, WithinRel( chunk.values()[0] ) );
CHECK_THAT( 18, WithinRel( chunk.values()[1] ) );
CHECK_THAT( 16, WithinRel( chunk.values()[2] ) );
CHECK_THAT( 20.000001, WithinRel( chunk.values()[0] ) );
CHECK_THAT( 18.000000001, WithinRel( chunk.values()[1] ) );
CHECK_THAT( 16.0000000000001, WithinRel( chunk.values()[2] ) );
CHECK_THAT( 14, WithinRel( chunk.values()[3] ) );
CHECK_THAT( 10, WithinRel( chunk.values()[4] ) );
CHECK_THAT( 5, WithinRel( chunk.values()[5] ) );
Expand Down
2 changes: 1 addition & 1 deletion src/NDItk/base/SingleRealRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SingleRealRecord : protected SingleValueRecord< SingleRealRecord, double >
void write( OutputIterator& iter ) const {

std::ostringstream buffer;
buffer << " " << std::setprecision( 15 ) << std::right << this->data().value();
buffer << " " << std::setprecision( 15 ) << this->data().value();
for ( auto c : buffer.str() ) { *iter++ = c; }
*iter++ = '\n';
};
Expand Down
2 changes: 1 addition & 1 deletion src/NDItk/fromFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace NDItk {
auto end = content.end();

// read over the first line of the file
while ( ! *iter == '\n' ) {
while ( *iter != '\n' ) {

++iter;
}
Expand Down
8 changes: 8 additions & 0 deletions src/NDItk/multigroup/CrossSection/src/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* The following verification tests are performed:
* - there are at least three values
* - the reaction identifier looks to be an integer
*
* @param[in] data the data values in the cross section subrecord
*/
Expand All @@ -16,4 +17,11 @@ static void verify( const Range& data ) {
Log::info( "Found {} data values", data.size() );
throw std::exception();
}

if ( data[0] - static_cast< int >( std::round( data[0] ) ) != 0 ) {

Log::error( "Expected an integer value for the reaction identifier" );
Log::info( "Found {} as the reaction identifier", data[0] );
throw std::exception();
}
}
3 changes: 2 additions & 1 deletion src/NDItk/multigroup/CrossSection/src/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void write( OutputIterator& iter ) const {
std::ostringstream buffer;

auto x = this->begin();
buffer << " " << x[0] << ' ' << std::setprecision( 15 ) << x[1] << '\n';
buffer << " " << static_cast< int >( std::round( x[0] ) )
<< ' ' << std::setprecision( 15 ) << x[1] << '\n';
x += 2;

auto full = this->numberGroups() / 5;
Expand Down
Loading

0 comments on commit 87ec6a9

Please sign in to comment.