Skip to content

Commit

Permalink
Updating mg table
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 9, 2024
1 parent 2bfc44a commit ce7ff4f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
11 changes: 10 additions & 1 deletion python/src/MultigroupTable.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
using Metadata = njoy::NDItk::multigroup::Metadata;
using EnergyGroupStructure = njoy::NDItk::multigroup::EnergyGroupStructure;
using FluxWeights = njoy::NDItk::multigroup::FluxWeights;
using TotalCrossSection = njoy::NDItk::multigroup::TotalCrossSection;
using ReactionCrossSections = njoy::NDItk::multigroup::ReactionCrossSections;
using AverageFissionEnergyRelease = njoy::NDItk::multigroup::AverageFissionEnergyRelease;

Expand All @@ -39,13 +40,14 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
EnergyGroupStructure,
std::vector< EnergyGroupStructure >,
FluxWeights,
TotalCrossSection,
ReactionCrossSections,
std::optional< AverageFissionEnergyRelease > >(),
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( "outgoing" ),
python::arg( "flux" ), python::arg( "xs" ),
python::arg( "flux" ), python::arg( "total" ), python::arg( "xs" ),
python::arg( "release" ) = std::nullopt,
"Initialise the table\n\n"
"Arguments:\n"
Expand All @@ -62,6 +64,7 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
" structure the primary group structure\n"
" outgoing the outgoing particle group structures\n"
" flux the flux weights\n"
" total the total cross section\n"
" xs the reaction cross section data\n"
" release the average fission energy release data"
)
Expand Down Expand Up @@ -99,6 +102,12 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
&Table::reactionCrossSections,
"The reaction cross section record"
)
.def_property_readonly(

"total_cross_section",
&Table::totalCrossSection,
"The total cross section record"
)
.def_property_readonly(

"average_fission_energy_release",
Expand Down
13 changes: 13 additions & 0 deletions python/test/Test_NDItk_MultigroupTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from NDItk.multigroup import AverageFissionEnergyRelease
from NDItk.multigroup import EnergyGroupStructure
from NDItk.multigroup import FluxWeights
from NDItk.multigroup import TotalCrossSection
from NDItk.multigroup import ReactionCrossSections
from NDItk.multigroup import CrossSection

Expand Down Expand Up @@ -71,6 +72,17 @@ def verify_chunk( self, chunk ) :
self.assertAlmostEqual( 0.04, flux.weights[5] )
self.assertAlmostEqual( 0.06, flux.weights[6] )

# verify content - total cross section
total = chunk.total_cross_section
self.assertEqual( 7, total.number_groups )
self.assertAlmostEqual( 1.10, total.values[0] )
self.assertAlmostEqual( 1.20, total.values[1] )
self.assertAlmostEqual( 1.25, total.values[2] )
self.assertAlmostEqual( 1.05, total.values[3] )
self.assertAlmostEqual( 1.15, total.values[4] )
self.assertAlmostEqual( 1.04, total.values[5] )
self.assertAlmostEqual( 1.06, total.values[6] )

# verify content - reaction cross sections
reactions = chunk.reaction_cross_sections
self.assertEqual( 2, reactions.number_reactions )
Expand Down Expand Up @@ -137,6 +149,7 @@ def verify_chunk( self, chunk ) :
outgoing = [ EnergyGroupStructure( 0, [ 20., 10., 5, 1e-11 ] ),
EnergyGroupStructure( 1001, [ 20., 10., 1e-11 ] )],
flux = FluxWeights( [ 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 ] ),
total = TotalCrossSection( [ 1.1, 1.2, 1.25, 1.05, 1.15, 1.04, 1.06 ] ),
xs = ReactionCrossSections(
xs = [ CrossSection( 2, 0., [ 10., 20., 30., 40., 50., 60., 70. ] ),
CrossSection( 16, 1.1234567, [ 1., 2., 3., 4., 5., 6., 7. ] ) ] ),
Expand Down
11 changes: 11 additions & 0 deletions src/NDItk/MultigroupTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "NDItk/multigroup/EnergyGroupStructure.hpp"
#include "NDItk/multigroup/FluxWeights.hpp"
#include "NDItk/multigroup/ReactionCrossSections.hpp"
#include "NDItk/multigroup/TotalCrossSection.hpp"
#include "NDItk/multigroup/AverageFissionEnergyRelease.hpp"

namespace njoy {
Expand All @@ -26,6 +27,7 @@ class MultigroupTable {
std::vector< multigroup::EnergyGroupStructure > outgoing_structure_;
multigroup::FluxWeights weights_;
multigroup::ReactionCrossSections xs_;
multigroup::TotalCrossSection total_;
multigroup::AverageFissionEnergyRelease release_;

/* auxiliary functions */
Expand Down Expand Up @@ -82,6 +84,14 @@ class MultigroupTable {
*/
const multigroup::FluxWeights& flux() const { return this->weights_; }

/**
* @brief Return the total cross section record
*/
const multigroup::TotalCrossSection& totalCrossSection() const {

return this->total_;
}

/**
* @brief Return the reaction cross section record
*/
Expand Down Expand Up @@ -113,6 +123,7 @@ class MultigroupTable {
this->primary_structure_.print( iter );
for ( const auto& entry : this->outgoing_structure_ ) { entry.print( iter ); }
this->weights_.print( iter );
this->total_.print( iter );
this->xs_.print( iter );
this->release_.print( iter );
base::Keyword( "end" ).print( iter );
Expand Down
7 changes: 5 additions & 2 deletions src/NDItk/MultigroupTable/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @brief Default constructor
*/
MultigroupTable() :
metadata_(), primary_structure_(), outgoing_structure_(), weights_(), xs_(),
release_() {}
metadata_(), primary_structure_(), outgoing_structure_(), weights_(),
total_(), xs_(), release_() {}

/**
* @brief Constructor
Expand All @@ -20,6 +20,7 @@ MultigroupTable() :
* @param[in] structure the primary group structure
* @param[in] outgoing the outgoing particle group structures
* @param[in] weights the flux weights
* @param[in] total the total cross section
* @param[in] xs the reaction cross section data
* @param[in] release the average fission energy release data
*/
Expand All @@ -29,6 +30,7 @@ MultigroupTable( std::string zaid, std::string libname, std::string source,
multigroup::EnergyGroupStructure structure,
std::vector< multigroup::EnergyGroupStructure > outgoing,
multigroup::FluxWeights weigths,
multigroup::TotalCrossSection total,
multigroup::ReactionCrossSections xs,
std::optional< multigroup::AverageFissionEnergyRelease > release = std::nullopt ) :
metadata_( std::move( zaid ), std::move( libname ), std::move( source ),
Expand All @@ -38,6 +40,7 @@ MultigroupTable( std::string zaid, std::string libname, std::string source,
primary_structure_( std::move( structure ) ),
outgoing_structure_( std::move( outgoing ) ),
weights_( std::move( weigths ) ),
total_( std::move( total ) ),
xs_( std::move( xs ) ),
release_( std::move( release.value() ) ) {

Expand Down
13 changes: 13 additions & 0 deletions src/NDItk/MultigroupTable/src/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ void read( Iterator& iter, const Iterator& end ) {
throw std::exception();
}
}
else if ( keyword == this->total_.keyword() ) {

if ( this->metadata_.numberGroups().has_value() ) {

readRecord( this->total_, iter, end, this->metadata_.numberGroups().value() );
}
else {

Log::error( "Metadata required for the \'\' record was not found", keyword );
Log::info( "Required metadata is missing: number of groups in the primary group structure" );
throw std::exception();
}
}
else if ( keyword == this->xs_.keyword() ) {

if ( this->metadata_.numberGroups().has_value() && this->metadata_.numberReactions().has_value() ) {
Expand Down
3 changes: 3 additions & 0 deletions src/NDItk/MultigroupTable/src/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ void verify() {
const auto groups = this->metadata().numberGroups().value();
if ( ( this->structure().numberGroups() != groups ) ||
( this->flux().numberGroups() != groups ) ||
( this->totalCrossSection().numberGroups() != groups ) ||
( this->reactionCrossSections().numberGroups() != groups ) ) {

Log::error( "Found inconsistent number of primary groups across the table" );
Log::info( "Number of primary groups in the metadata: {}", this->metadata().numberGroups().value() );
Log::info( "Number of primary groups in the structure: {}", this->structure().numberGroups() );
Log::info( "Number of primary groups in the flux weights: {}", this->flux().numberGroups() );
Log::info( "Number of primary groups in the total cross section: {}",
this->totalCrossSection().numberGroups() );
Log::info( "Number of primary groups in the reaction cross section data: {}",
this->reactionCrossSections().numberGroups() );
throw std::exception();
Expand Down
24 changes: 22 additions & 2 deletions src/NDItk/MultigroupTable/test/MultigroupTable.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SCENARIO( "MultigroupTable" ) {
{ 1001, { 20., 10., 1e-11 } }
};
multigroup::FluxWeights weights( { 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 } );
multigroup::TotalCrossSection total( { 1.1, 1.2, 1.25, 1.05, 1.15, 1.04, 1.06 } );
multigroup::ReactionCrossSections xs( { { 2, 0.0, { 10., 20., 30., 40., 50., 60., 70. } },
{ 16, 1.1234567, { 1., 2., 3., 4., 5., 6., 7. } } } );
multigroup::AverageFissionEnergyRelease release( 202.827, 181.238898, 4.827645,
Expand All @@ -45,7 +46,7 @@ SCENARIO( "MultigroupTable" ) {
MultigroupTable chunk( std::move( zaid ), std::move( name ), std::move( source ),
std::move( process ), awr, weight, temperature, dilution,
std::move( structure ), std::move( outgoing ), std::move( weights ),
std::move( xs ), std::move( release ) );
std::move( total ), std::move( xs ), std::move( release ) );

THEN( "a MultigroupTable can be constructed and members can "
"be tested" ) {
Expand Down Expand Up @@ -102,14 +103,16 @@ SCENARIO( "MultigroupTable" ) {
double dilution = 1e+10;
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::TotalCrossSection total( { 1.1, 1.2, 1.25, 1.05, 1.15, 1.04 } ); // <-- 5 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. } } } );

THEN( "an exception is thrown" ) {

CHECK_THROWS( MultigroupTable( std::move( zaid ), std::move( name ), std::move( source ),
std::move( process ), awr, weight, temperature, dilution,
std::move( structure ), {}, std::move( weights ), std::move( xs ) ) );
std::move( structure ), {}, std::move( weights ), std::move( total ),
std::move( xs ) ) );
} // THEN
} // WHEN
} // GIVEN
Expand Down Expand Up @@ -151,6 +154,9 @@ std::string chunk() {
"wgts\n"
" 0.1 0.2 0.25 0.05 0.15\n"
" 0.04 0.06\n"
"sig_tot\n"
" 1.1 1.2 1.25 1.05 1.15\n"
" 1.04 1.06\n"
"sig_reac\n"
" 2 0\n"
" 10 20 30 40 50\n"
Expand Down Expand Up @@ -233,6 +239,20 @@ void verifyChunk( const MultigroupTable& chunk ) {
CHECK_THAT( 0.04, WithinRel( chunk.flux().weights()[5] ) );
CHECK_THAT( 0.06, WithinRel( chunk.flux().weights()[6] ) );

// total cross section
CHECK( "sig_tot" == chunk.totalCrossSection().keyword() );
CHECK( false == chunk.totalCrossSection().empty() );
CHECK( 7 == chunk.totalCrossSection().size() );
CHECK( 7 == chunk.totalCrossSection().values().size() );
CHECK( 7 == chunk.totalCrossSection().numberGroups() );
CHECK_THAT( 1.10, WithinRel( chunk.totalCrossSection().values()[0] ) );
CHECK_THAT( 1.20, WithinRel( chunk.totalCrossSection().values()[1] ) );
CHECK_THAT( 1.25, WithinRel( chunk.totalCrossSection().values()[2] ) );
CHECK_THAT( 1.05, WithinRel( chunk.totalCrossSection().values()[3] ) );
CHECK_THAT( 1.15, WithinRel( chunk.totalCrossSection().values()[4] ) );
CHECK_THAT( 1.04, WithinRel( chunk.totalCrossSection().values()[5] ) );
CHECK_THAT( 1.06, WithinRel( chunk.totalCrossSection().values()[6] ) );

// reaction cross sections
CHECK( 18 == chunk.reactionCrossSections().size() );
CHECK( false == chunk.reactionCrossSections().empty() );
Expand Down

0 comments on commit ce7ff4f

Please sign in to comment.