Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/review' into feature/multigr…
Browse files Browse the repository at this point in the history
…oup-part2
  • Loading branch information
whaeck committed May 9, 2024
2 parents 891c907 + f9e4a4f commit 3ac9552
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 35 deletions.
6 changes: 3 additions & 3 deletions python/test/Test_NDItk_MultigroupTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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 @@ -116,7 +116,7 @@ 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 = EnergyGroupStructure( [ 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. ] ),
Expand Down
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
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::EnergyGroupStructure 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 @@ -95,7 +96,7 @@ SCENARIO( "MultigroupTable" ) {
double weight = 235.043937521619;
double temperature = 2.53e-8;
double dilution = 1e+10;
multigroup::EnergyGroupStructure 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 @@ -133,7 +134,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 @@ -172,8 +173,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
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
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
33 changes: 26 additions & 7 deletions src/NDItk/multigroup/CrossSection/test/CrossSection.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ std::string chunk();
std::vector< double > data();
void verifyChunk( const CrossSection& );
std::vector< double > dataWithInsufficientLength();
std::vector< double > dataWithNonIntegerIdentifier();

SCENARIO( "CrossSection" ) {

Expand All @@ -27,7 +28,7 @@ SCENARIO( "CrossSection" ) {

int reaction = 2;
double qvalue = 0.0;
std::vector< double > values = { 10., 20., 30., 40., 50., 60., 70. };
std::vector< double > values = { 10.0000000000001, 20., 30., 40.12345678, 50., 60., 70. };

CrossSection chunk( reaction, qvalue, std::move( values ) );

Expand Down Expand Up @@ -94,30 +95,42 @@ SCENARIO( "CrossSection" ) {
CHECK_THROWS( CrossSection( begin, end ) );
} // THEN
} // WHEN

WHEN( "using iterators and the reaction identifier is not an integer" ) {

std::vector< double > values = dataWithNonIntegerIdentifier();
auto begin = values.begin();
auto end = values.end();

THEN( "an exception is thrown" ) {

CHECK_THROWS( CrossSection( begin, end ) );
} // THEN
} // WHEN
} // GIVEN
} // SCENARIO

std::string chunk() {

return " 2 0\n"
" 10 20 30 40 50\n"
" 10.0000000000001 20 30 40.12345678 50\n"
" 60 70\n";
}

std::vector< double > data() {

return { 2, 0,
10, 20, 30, 40, 50, 60, 70 };
10.0000000000001, 20, 30, 40.12345678, 50, 60, 70 };
}

void verifyChunk( const CrossSection& chunk ) {

CHECK_THAT( 2, WithinRel( chunk.values()[0] ) );
CHECK_THAT( 0, WithinRel( chunk.values()[1] ) );
CHECK_THAT( 10, WithinRel( chunk.values()[2] ) );
CHECK_THAT( 10.0000000000001, WithinRel( chunk.values()[2] ) );
CHECK_THAT( 20, WithinRel( chunk.values()[3] ) );
CHECK_THAT( 30, WithinRel( chunk.values()[4] ) );
CHECK_THAT( 40, WithinRel( chunk.values()[5] ) );
CHECK_THAT( 40.12345678, WithinRel( chunk.values()[5] ) );
CHECK_THAT( 50, WithinRel( chunk.values()[6] ) );
CHECK_THAT( 60, WithinRel( chunk.values()[7] ) );
CHECK_THAT( 70, WithinRel( chunk.values()[8] ) );
Expand All @@ -128,10 +141,10 @@ void verifyChunk( const CrossSection& chunk ) {
CHECK( 7 == chunk.numberGroups() );
CHECK( 2 == chunk.identifier() );
CHECK_THAT( 0, WithinRel( chunk.qvalue() ) );
CHECK_THAT( 10, WithinRel( chunk.crossSections()[0] ) );
CHECK_THAT( 10.0000000000001, WithinRel( chunk.crossSections()[0] ) );
CHECK_THAT( 20, WithinRel( chunk.crossSections()[1] ) );
CHECK_THAT( 30, WithinRel( chunk.crossSections()[2] ) );
CHECK_THAT( 40, WithinRel( chunk.crossSections()[3] ) );
CHECK_THAT( 40.12345678, WithinRel( chunk.crossSections()[3] ) );
CHECK_THAT( 50, WithinRel( chunk.crossSections()[4] ) );
CHECK_THAT( 60, WithinRel( chunk.crossSections()[5] ) );
CHECK_THAT( 70, WithinRel( chunk.crossSections()[6] ) );
Expand All @@ -141,3 +154,9 @@ std::vector< double > dataWithInsufficientLength() {

return { 2, 0 };
}

std::vector< double > dataWithNonIntegerIdentifier() {

return { 2.001, 0,
10, 20, 30, 40, 50, 60, 70 };
}
4 changes: 2 additions & 2 deletions src/NDItk/multigroup/EnergyGroupStructure.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef NJOY_NDITK_MULTIGROUP_STRUCTURE
#define NJOY_NDITK_MULTIGROUP_STRUCTURE
#ifndef NJOY_NDITK_MULTIGROUP_ENERGYGROUPSTRUCTURE
#define NJOY_NDITK_MULTIGROUP_ENERGYGROUPSTRUCTURE

// system includes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SCENARIO( "EnergyGroupStructure" ) {

THEN( "an exception is thrown" ) {

std::vector< double > wrong = { 1., 20. };
std::vector< double > wrong = { 3., 1., 20. };

CHECK_THROWS( EnergyGroupStructure( std::move( wrong ) ) );
} // THEN
Expand Down Expand Up @@ -129,7 +129,7 @@ SCENARIO( "EnergyGroupStructure" ) {

THEN( "an exception is thrown" ) {

CHECK_THROWS( chunk.read( iter, end, 2 ) );
CHECK_THROWS( chunk.read( iter, end, 3 ) );
} // THEN
} // WHEN

Expand Down Expand Up @@ -191,7 +191,7 @@ std::string chunkWithInsufficientNumberBoundaries() {
std::string chunkWithNonDescendingBoundaries() {

return "e_bounds\n"
" 1 20\n";
" 3 1 20\n";
}

std::string chunkWithNonUniqueBoundaries() {
Expand Down
8 changes: 4 additions & 4 deletions src/NDItk/multigroup/ReactionCrossSections/src/verify.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @brief Verify the groups structure
* @brief Verify the reaction cross section information
*
* The following verification tests are performed:
* - there are at least two values
* - the boundaries are unique and in descending order
* - there is at least one reaction
* - the number of groups for each reaction is the same
*
* @param[in] boundaries the boundary values to be verified
* @param[in] reactions the reactions to be verified
*/
template < typename Range >
static void verify( const Range& reactions ) {
Expand Down

0 comments on commit 3ac9552

Please sign in to comment.