From 211738f5e6a1536a122de4ec5729a86806da6c09 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 16:07:26 -0600 Subject: [PATCH 01/12] More work on Keyword --- src/NDItk/base/Keyword/src/ctor.hpp | 30 ++++++++++- src/NDItk/base/Keyword/test/Keyword.test.cpp | 50 +++++++++++++++++++ .../depletion/ReactionMultiplicities.hpp | 6 ++- .../ReactionMultiplicities/src/ctor.hpp | 29 +++++------ .../ReactionMultiplicities/src/getPostFix.hpp | 8 --- .../test/ReactionMultiplicities.test.cpp | 7 ++- src/NDItk/multigroup/Velocities/src/ctor.hpp | 2 +- .../multigroup/Velocities/src/verify.hpp | 2 +- 8 files changed, 106 insertions(+), 28 deletions(-) delete mode 100644 src/NDItk/depletion/ReactionMultiplicities/src/getPostFix.hpp diff --git a/src/NDItk/base/Keyword/src/ctor.hpp b/src/NDItk/base/Keyword/src/ctor.hpp index 0b1ac95..14513ef 100644 --- a/src/NDItk/base/Keyword/src/ctor.hpp +++ b/src/NDItk/base/Keyword/src/ctor.hpp @@ -29,10 +29,38 @@ Keyword( std::string keyword ) : Keyword( splitKeyword( std::move( keyword ) ) ) {} /** - * @brief Constructor + * @brief Constructor for particle subtypes * * @param[in] subtype the subtype of the record * @param[in] particle the particle identifier */ Keyword( std::string subtype, unsigned int particle ) : Keyword( subtype + "_" + std::to_string( particle ) ) {} + +/** + * @brief Constructor for multiplicity subtypes + * + * @param[in] subtype the subtype of the record + * @param[in] type the multiplicity type + */ +Keyword( std::string subtype, depletion::ReactionMultiplicityType type ) : + Keyword( subtype + + ( type == depletion::ReactionMultiplicityType::All + ? std::string( "_all" ) + : type == depletion::ReactionMultiplicityType::Few + ? std::string( "_few" ) + : std::string( "_rmo" ) ) ) {} + +/** + * @brief Constructor for fission subtypes + * + * @param[in] subtype the subtype of the record + * @param[in] type the fission type + */ +Keyword( std::string subtype, multigroup::FissionType type ) : + Keyword( subtype + + ( type == multigroup::FissionType::Prompt + ? std::string( "_pr" ) + : type == multigroup::FissionType::Delayed + ? std::string( "_del" ) + : std::string( "_tot" ) ) ) {} diff --git a/src/NDItk/base/Keyword/test/Keyword.test.cpp b/src/NDItk/base/Keyword/test/Keyword.test.cpp index eea2837..8d3133e 100644 --- a/src/NDItk/base/Keyword/test/Keyword.test.cpp +++ b/src/NDItk/base/Keyword/test/Keyword.test.cpp @@ -11,6 +11,8 @@ using Catch::Matchers::WithinRel; // convenience typedefs using namespace njoy::NDItk; using Keyword = base::Keyword; +using ReactionMultiplicityType = depletion::ReactionMultiplicityType; +using FissionType = multigroup::FissionType; SCENARIO( "Keyword" ) { @@ -78,6 +80,14 @@ SCENARIO( "Keyword" ) { CHECK( std::nullopt == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "rprod", ReactionMultiplicityType::All ); + CHECK( "rprod_all" == result.keyword() ); + CHECK( "rprod" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( depletion::ReactionMultiplicityType::All == result.multiplicityType() ); + CHECK( std::nullopt == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "rprod_few" ); CHECK( "rprod_few" == result.keyword() ); CHECK( "rprod" == result.subtype() ); @@ -86,6 +96,14 @@ SCENARIO( "Keyword" ) { CHECK( std::nullopt == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "rprod", ReactionMultiplicityType::Few ); + CHECK( "rprod_few" == result.keyword() ); + CHECK( "rprod" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( depletion::ReactionMultiplicityType::Few == result.multiplicityType() ); + CHECK( std::nullopt == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "rprod_rmo" ); CHECK( "rprod_rmo" == result.keyword() ); CHECK( "rprod" == result.subtype() ); @@ -94,6 +112,14 @@ SCENARIO( "Keyword" ) { CHECK( std::nullopt == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "rprod", ReactionMultiplicityType::RMO ); + CHECK( "rprod_rmo" == result.keyword() ); + CHECK( "rprod" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( depletion::ReactionMultiplicityType::RMO == result.multiplicityType() ); + CHECK( std::nullopt == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "nu_pr" ); CHECK( "nu_pr" == result.keyword() ); CHECK( "nu" == result.subtype() ); @@ -102,6 +128,14 @@ SCENARIO( "Keyword" ) { CHECK( multigroup::FissionType::Prompt == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "nu", FissionType::Prompt ); + CHECK( "nu_pr" == result.keyword() ); + CHECK( "nu" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( std::nullopt == result.multiplicityType() ); + CHECK( multigroup::FissionType::Prompt == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "nu_del" ); CHECK( "nu_del" == result.keyword() ); CHECK( "nu" == result.subtype() ); @@ -110,6 +144,14 @@ SCENARIO( "Keyword" ) { CHECK( multigroup::FissionType::Delayed == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "nu", FissionType::Delayed ); + CHECK( "nu_del" == result.keyword() ); + CHECK( "nu" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( std::nullopt == result.multiplicityType() ); + CHECK( multigroup::FissionType::Delayed == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "nu_tot" ); CHECK( "nu_tot" == result.keyword() ); CHECK( "nu" == result.subtype() ); @@ -118,6 +160,14 @@ SCENARIO( "Keyword" ) { CHECK( multigroup::FissionType::Total == result.fissionType() ); CHECK( true == result.hasSubtype() ); + result = Keyword( "nu", FissionType::Total ); + CHECK( "nu_tot" == result.keyword() ); + CHECK( "nu" == result.subtype() ); + CHECK( std::nullopt == result.particle() ); + CHECK( std::nullopt == result.multiplicityType() ); + CHECK( multigroup::FissionType::Total == result.fissionType() ); + CHECK( true == result.hasSubtype() ); + result = Keyword( "num_sec_parts" ); CHECK( "num_sec_parts" == result.keyword() ); CHECK( std::nullopt == result.subtype() ); diff --git a/src/NDItk/depletion/ReactionMultiplicities.hpp b/src/NDItk/depletion/ReactionMultiplicities.hpp index 9faaece..fdb32ba 100644 --- a/src/NDItk/depletion/ReactionMultiplicities.hpp +++ b/src/NDItk/depletion/ReactionMultiplicities.hpp @@ -27,7 +27,6 @@ class ReactionMultiplicities : protected base::IntegerListRecord { /* auxiliary functions */ - #include "NDItk/depletion/ReactionMultiplicities/src/getPostFix.hpp" #include "NDItk/depletion/ReactionMultiplicities/src/verify.hpp" #include "NDItk/depletion/ReactionMultiplicities/src/generateData.hpp" #include "NDItk/depletion/ReactionMultiplicities/src/generateBlocks.hpp" @@ -42,6 +41,11 @@ class ReactionMultiplicities : protected base::IntegerListRecord { /* methods */ + /** + * @brief Return the multiplicity type defined by this record + */ + decltype(auto) type() const { return this->key().multiplicityType(); } + /** * @brief Return the number of reactions defined in this record */ diff --git a/src/NDItk/depletion/ReactionMultiplicities/src/ctor.hpp b/src/NDItk/depletion/ReactionMultiplicities/src/ctor.hpp index 7b0e054..ee67bc2 100644 --- a/src/NDItk/depletion/ReactionMultiplicities/src/ctor.hpp +++ b/src/NDItk/depletion/ReactionMultiplicities/src/ctor.hpp @@ -3,21 +3,22 @@ /** * @brief Private intermediate constructor */ -ReactionMultiplicities( std::string postfix ) : - IntegerListRecord( base::Keyword( postfix.size() > 1 - ? std::string( "rprod_" ) + postfix - : std::string( "rprod" ) ) ) { +ReactionMultiplicities( std::vector< Multiplicities >&& multiplicities, + std::size_t reactions ) : + IntegerListRecord( base::Keyword( "rprod" ), + generateData( std::move( multiplicities ) ) ), + reactions_( reactions ) { + + this->generateBlocks(); } /** * @brief Private intermediate constructor */ -ReactionMultiplicities( std::string postfix, +ReactionMultiplicities( ReactionMultiplicityType type, std::vector< Multiplicities >&& multiplicities, std::size_t reactions ) : - IntegerListRecord( base::Keyword( postfix.size() > 1 - ? std::string( "rprod_" ) + postfix - : std::string( "rprod" ) ), + IntegerListRecord( base::Keyword( "rprod", type ), generateData( std::move( multiplicities ) ) ), reactions_( reactions ) { @@ -29,13 +30,13 @@ ReactionMultiplicities( std::string postfix, /** * @brief Default constructor */ -ReactionMultiplicities() : ReactionMultiplicities( "" ) {} +ReactionMultiplicities() : IntegerListRecord( base::Keyword( "rprod" ) ) {} /** * @brief Default constructor */ -ReactionMultiplicities( const ReactionMultiplicityType& type ) : - ReactionMultiplicities( getPostFix( type ) ) {} +ReactionMultiplicities( ReactionMultiplicityType type ) : + IntegerListRecord( base::Keyword( "rprod", type ) ) {} /** * @brief Constructor @@ -43,7 +44,7 @@ ReactionMultiplicities( const ReactionMultiplicityType& type ) : * @param[in] multiplicities the multiplicity data */ ReactionMultiplicities( std::vector< Multiplicities > multiplicities ) : - ReactionMultiplicities( "", std::move( multiplicities ), + ReactionMultiplicities( std::move( multiplicities ), multiplicities.size() ) {} /** @@ -52,9 +53,9 @@ ReactionMultiplicities( std::vector< Multiplicities > multiplicities ) : * @param[in] type the multiplicity type (all, few or rmo) * @param[in] multiplicities the multiplicity data */ -ReactionMultiplicities( const ReactionMultiplicityType& type, +ReactionMultiplicities( ReactionMultiplicityType type, std::vector< Multiplicities > multiplicities ) : - ReactionMultiplicities( getPostFix( type ), + ReactionMultiplicities( type, std::move( multiplicities ), multiplicities.size() ) {} diff --git a/src/NDItk/depletion/ReactionMultiplicities/src/getPostFix.hpp b/src/NDItk/depletion/ReactionMultiplicities/src/getPostFix.hpp deleted file mode 100644 index 9789d5f..0000000 --- a/src/NDItk/depletion/ReactionMultiplicities/src/getPostFix.hpp +++ /dev/null @@ -1,8 +0,0 @@ -static std::string getPostFix( const ReactionMultiplicityType& type ) { - - return type == ReactionMultiplicityType::All - ? std::string( "all" ) - : type == ReactionMultiplicityType::Few - ? std::string( "few" ) - : std::string( "rmo" ); -} diff --git a/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp b/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp index 86dd793..c023353 100644 --- a/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp +++ b/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp @@ -12,6 +12,7 @@ using Catch::Matchers::WithinRel; using namespace njoy::NDItk; using Multiplicities = depletion::Multiplicities; using ReactionMultiplicities = depletion::ReactionMultiplicities; +using ReactionMultiplicityType = depletion::ReactionMultiplicityType; std::string chunk(); void verifyChunk( const ReactionMultiplicities& ); @@ -88,7 +89,7 @@ SCENARIO( "ReactionMultiplicities" ) { { 16, { 1, 92234 }, { 2, 1 } } }; - ReactionMultiplicities chunk( depletion::ReactionMultiplicityType::All, + ReactionMultiplicities chunk( ReactionMultiplicityType::All, std::move( multiplicities ) ); THEN( "a ReactionMultiplicities can be constructed and members can " @@ -112,7 +113,7 @@ SCENARIO( "ReactionMultiplicities" ) { auto iter = record.begin() + 9; auto end = record.end(); - ReactionMultiplicities chunk( depletion::ReactionMultiplicityType::All ); + ReactionMultiplicities chunk( ReactionMultiplicityType::All ); chunk.read( iter, end, 2 ); THEN( "a ReactionMultiplicities can be constructed and members can " @@ -192,6 +193,7 @@ void verifyChunk( const ReactionMultiplicities& chunk ) { CHECK( false == chunk.empty() ); CHECK( 12 == chunk.size() ); + CHECK( std::nullopt == chunk.type() ); CHECK( 2 == chunk.numberReactions() ); CHECK( true == chunk.hasReaction( 2 ) ); @@ -260,6 +262,7 @@ void verifyChunkWithMultiplicityType( const ReactionMultiplicities& chunk ) { CHECK( false == chunk.empty() ); CHECK( 12 == chunk.size() ); + CHECK( ReactionMultiplicityType::All == chunk.type() ); CHECK( 2 == chunk.numberReactions() ); CHECK( true == chunk.hasReaction( 2 ) ); diff --git a/src/NDItk/multigroup/Velocities/src/ctor.hpp b/src/NDItk/multigroup/Velocities/src/ctor.hpp index bf4cb43..5a8edfa 100644 --- a/src/NDItk/multigroup/Velocities/src/ctor.hpp +++ b/src/NDItk/multigroup/Velocities/src/ctor.hpp @@ -6,7 +6,7 @@ Velocities() : RealListRecord( base::Keyword( "vel" ) ) {} /** * @brief Constructor * - * @param[in] weights the flux weights + * @param[in] values the velocity values */ Velocities( std::vector< double > values ) : RealListRecord( base::Keyword( "vel" ), std::move( values ) ) { diff --git a/src/NDItk/multigroup/Velocities/src/verify.hpp b/src/NDItk/multigroup/Velocities/src/verify.hpp index 0fe06ce..cda7131 100644 --- a/src/NDItk/multigroup/Velocities/src/verify.hpp +++ b/src/NDItk/multigroup/Velocities/src/verify.hpp @@ -1,5 +1,5 @@ /** - * @brief Verify the weights + * @brief Verify the velocities * * The following verification tests are performed: * - there is at least one value From 61644f01db4d01b619e8514fb47c1c08026b9019 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 16:08:47 -0600 Subject: [PATCH 02/12] Adding fission neutron multiplicity and production --- cmake/unit_testing.cmake | 2 + src/NDItk.hpp | 2 + .../multigroup/FissionNeutronMultiplicity.hpp | 59 ++++++++ .../FissionNeutronMultiplicity/src/ctor.hpp | 16 +++ .../FissionNeutronMultiplicity/src/read.hpp | 16 +++ .../FissionNeutronMultiplicity/src/verify.hpp | 18 +++ .../test/CMakeLists.txt | 1 + .../test/FissionNeutronMultiplicity.test.cpp | 129 ++++++++++++++++++ .../multigroup/FissionNeutronProduction.hpp | 59 ++++++++ .../FissionNeutronProduction/src/ctor.hpp | 16 +++ .../FissionNeutronProduction/src/read.hpp | 16 +++ .../FissionNeutronProduction/src/verify.hpp | 18 +++ .../test/CMakeLists.txt | 1 + .../test/FissionNeutronProduction.test.cpp | 129 ++++++++++++++++++ 14 files changed, 482 insertions(+) create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity/test/CMakeLists.txt create mode 100644 src/NDItk/multigroup/FissionNeutronMultiplicity/test/FissionNeutronMultiplicity.test.cpp create mode 100644 src/NDItk/multigroup/FissionNeutronProduction.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronProduction/test/CMakeLists.txt create mode 100644 src/NDItk/multigroup/FissionNeutronProduction/test/FissionNeutronProduction.test.cpp diff --git a/cmake/unit_testing.cmake b/cmake/unit_testing.cmake index bb33417..2f3ad9f 100644 --- a/cmake/unit_testing.cmake +++ b/cmake/unit_testing.cmake @@ -48,6 +48,8 @@ add_subdirectory( src/NDItk/multigroup/AverageFissionEnergyRelease/test ) add_subdirectory( src/NDItk/multigroup/Velocities/test ) add_subdirectory( src/NDItk/multigroup/HeatingNumbers/test ) add_subdirectory( src/NDItk/multigroup/Kerma/test ) +add_subdirectory( src/NDItk/multigroup/FissionNeutronMultiplicity/test ) +add_subdirectory( src/NDItk/multigroup/FissionNeutronProduction/test ) add_subdirectory( src/NDItk/multigroup/OutgoingParticleTypes/test ) add_subdirectory( src/NDItk/multigroup/OutgoingParticleTransportData/test ) add_subdirectory( src/NDItk/multigroup/LegendreMoment/test ) diff --git a/src/NDItk.hpp b/src/NDItk.hpp index 1e1b817..7ef4a92 100644 --- a/src/NDItk.hpp +++ b/src/NDItk.hpp @@ -1,6 +1,8 @@ #include "NDItk/multigroup/AverageFissionEnergyRelease.hpp" #include "NDItk/multigroup/CrossSection.hpp" #include "NDItk/multigroup/EnergyGroupStructure.hpp" +#include "NDItk/multigroup/FissionNeutronMultiplicity.hpp" +#include "NDItk/multigroup/FissionNeutronProduction.hpp" #include "NDItk/multigroup/FluxWeights.hpp" #include "NDItk/multigroup/HeatingNumbers.hpp" #include "NDItk/multigroup/Kerma.hpp" diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp new file mode 100644 index 0000000..d2e4b9f --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp @@ -0,0 +1,59 @@ +#ifndef NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONMULTIPLICITY +#define NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONMULTIPLICITY + +// system includes + +// other includes +#include "tools/Log.hpp" +#include "NDItk/base/RealListRecord.hpp" +#include "NDItk/multigroup/FissionType.hpp" + +namespace njoy { +namespace NDItk { +namespace multigroup { + +/** + * @brief A fission nubar record for multigroup neutron and photon data + */ +class FissionNeutronMultiplicity : protected base::RealListRecord { + + /* fields */ + + /* auxiliary functions */ + + #include "NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp" + +public: + + /* constructor */ + + #include "NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp" + + /* methods */ + + /** + * @brief Return the fission type defined by this record + */ + FissionType type() const { return this->key().fissionType().value(); } + + /** + * @brief Return the number of groups defined by this record + */ + unsigned int numberGroups() const { return this->size(); } + + using base::RealListRecord::keyword; + using base::RealListRecord::values; + using base::RealListRecord::size; + using base::RealListRecord::empty; + using base::RealListRecord::begin; + using base::RealListRecord::end; + using base::RealListRecord::print; + + #include "NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp" +}; + +} // multigroup namespace +} // NDItk namespace +} // njoy namespace + +#endif diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp new file mode 100644 index 0000000..10f6729 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp @@ -0,0 +1,16 @@ +/** + * @brief Default constructor + */ +FissionNeutronMultiplicity( FissionType type ) : RealListRecord( base::Keyword( "nu", type ) ) {} + +/** + * @brief Constructor + * + * @param[in] weights the flux weights + */ +FissionNeutronMultiplicity( FissionType type, + std::vector< double > values ) : + RealListRecord( base::Keyword( "nu", type ), std::move( values ) ) { + + verify( this->values() ); +} diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp new file mode 100644 index 0000000..1b79ef3 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp @@ -0,0 +1,16 @@ +/** + * @brief Read the record data + * + * This function overrides the base record read() function to enable + * verification of the read data. + * + * @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 nu values + */ +template< typename Iterator > +void read( Iterator& iter, const Iterator& end, std::size_t number ) { + + base::RealListRecord::read( iter, end, number ); + verify( this->values() ); +}; diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp new file mode 100644 index 0000000..0d9263d --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp @@ -0,0 +1,18 @@ +/** + * @brief Verify the nu values + * + * The following verification tests are performed: + * - there is at least one value + * + * @param[in] values the nu values to be verified + */ +template < typename Range > +static void verify( const Range& values ) { + + if ( values.size() < 1 ) { + + Log::error( "Expected at least one nu value, found {}", + values.size() ); + throw std::exception(); + } +} diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/test/CMakeLists.txt b/src/NDItk/multigroup/FissionNeutronMultiplicity/test/CMakeLists.txt new file mode 100644 index 0000000..6b079d0 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/test/CMakeLists.txt @@ -0,0 +1 @@ +add_cpp_test( multigroup.FissionNeutronMultiplicity FissionNeutronMultiplicity.test.cpp ) \ No newline at end of file diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/test/FissionNeutronMultiplicity.test.cpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/test/FissionNeutronMultiplicity.test.cpp new file mode 100644 index 0000000..11c5dbe --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/test/FissionNeutronMultiplicity.test.cpp @@ -0,0 +1,129 @@ +// include Catch2 +#include +#include +using Catch::Matchers::WithinRel; + +// what we are testing +#include "NDItk/multigroup/FissionNeutronMultiplicity.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::NDItk; +using FissionNeutronMultiplicity = multigroup::FissionNeutronMultiplicity; +using FissionType = multigroup::FissionType; + +std::string chunk(); +void verifyChunk( const FissionNeutronMultiplicity& ); +std::string chunkWithInsufficientNumberValues(); + +SCENARIO( "FissionNeutronMultiplicity" ) { + + GIVEN( "valid data for a FissionNeutronMultiplicity instance" ) { + + std::string record = chunk(); + + WHEN( "the data is given explicitly" ) { + + std::vector< double > values = { 2., 2.1, 2.2, 2.3, 2.4, 5.0, 7.0 }; + + FissionNeutronMultiplicity chunk( FissionType::Prompt, std::move( values ) ); + + THEN( "a FissionNeutronMultiplicity can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + + WHEN( "the data is read using iterators" ) { + + auto iter = record.begin() + 5; + auto end = record.end(); + + FissionNeutronMultiplicity chunk( FissionType::Prompt ); + chunk.read( iter, end, 7 ); + + THEN( "a FissionNeutronMultiplicity can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data for a FissionNeutronMultiplicity instance" ) { + + WHEN( "the number of weight values is insufficient" ) { + + THEN( "an exception is thrown" ) { + + std::vector< double > empty = {}; + + CHECK_THROWS( FissionNeutronMultiplicity( FissionType::Prompt, std::move( empty ) ) ); + } // THEN + } // WHEN + + WHEN( "reading the data of the record and the number of " + "values is insufficient" ) { + + std::string record = chunkWithInsufficientNumberValues(); + auto iter = record.begin() + 5; + auto end = record.end(); + FissionNeutronMultiplicity chunk( FissionType::Prompt ); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( chunk.read( iter, end, 0 ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return "nu_pr\n" + " 2 2.1 2.2 2.3 2.4\n" + " 5 7\n"; +} + +void verifyChunk( const FissionNeutronMultiplicity& chunk ) { + + CHECK( "nu_pr" == chunk.keyword() ); + CHECK_THAT( 2, WithinRel( chunk.values()[0] ) ); + CHECK_THAT( 2.1, WithinRel( chunk.values()[1] ) ); + CHECK_THAT( 2.2, WithinRel( chunk.values()[2] ) ); + CHECK_THAT( 2.3, WithinRel( chunk.values()[3] ) ); + CHECK_THAT( 2.4, WithinRel( chunk.values()[4] ) ); + CHECK_THAT( 5, WithinRel( chunk.values()[5] ) ); + CHECK_THAT( 7, WithinRel( chunk.values()[6] ) ); + + CHECK( false == chunk.empty() ); + CHECK( 7 == chunk.size() ); + + CHECK( FissionType::Prompt == chunk.type() ); + CHECK( 7 == chunk.numberGroups() ); +} + +std::string chunkWithInsufficientNumberValues() { + + return "nu_pr\n"; +} diff --git a/src/NDItk/multigroup/FissionNeutronProduction.hpp b/src/NDItk/multigroup/FissionNeutronProduction.hpp new file mode 100644 index 0000000..bd04e4b --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction.hpp @@ -0,0 +1,59 @@ +#ifndef NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONPRODUCTION +#define NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONPRODUCTION + +// system includes + +// other includes +#include "tools/Log.hpp" +#include "NDItk/base/RealListRecord.hpp" +#include "NDItk/multigroup/FissionType.hpp" + +namespace njoy { +namespace NDItk { +namespace multigroup { + +/** + * @brief A fission neutron production record for multigroup neutron and photon data + */ +class FissionNeutronProduction : protected base::RealListRecord { + + /* fields */ + + /* auxiliary functions */ + + #include "NDItk/multigroup/FissionNeutronProduction/src/verify.hpp" + +public: + + /* constructor */ + + #include "NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp" + + /* methods */ + + /** + * @brief Return the fission type defined by this record + */ + FissionType type() const { return this->key().fissionType().value(); } + + /** + * @brief Return the number of groups defined by this record + */ + unsigned int numberGroups() const { return this->size(); } + + using base::RealListRecord::keyword; + using base::RealListRecord::values; + using base::RealListRecord::size; + using base::RealListRecord::empty; + using base::RealListRecord::begin; + using base::RealListRecord::end; + using base::RealListRecord::print; + + #include "NDItk/multigroup/FissionNeutronProduction/src/read.hpp" +}; + +} // multigroup namespace +} // NDItk namespace +} // njoy namespace + +#endif diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp new file mode 100644 index 0000000..c1cf1da --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp @@ -0,0 +1,16 @@ +/** + * @brief Default constructor + */ +FissionNeutronProduction( FissionType type ) : RealListRecord( base::Keyword( "nu_sig_f", type ) ) {} + +/** + * @brief Constructor + * + * @param[in] weights the flux weights + */ +FissionNeutronProduction( FissionType type, + std::vector< double > values ) : + RealListRecord( base::Keyword( "nu_sig_f", type ), std::move( values ) ) { + + verify( this->values() ); +} diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp new file mode 100644 index 0000000..1b79ef3 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp @@ -0,0 +1,16 @@ +/** + * @brief Read the record data + * + * This function overrides the base record read() function to enable + * verification of the read data. + * + * @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 nu values + */ +template< typename Iterator > +void read( Iterator& iter, const Iterator& end, std::size_t number ) { + + base::RealListRecord::read( iter, end, number ); + verify( this->values() ); +}; diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp new file mode 100644 index 0000000..b751e39 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp @@ -0,0 +1,18 @@ +/** + * @brief Verify the production values + * + * The following verification tests are performed: + * - there is at least one value + * + * @param[in] values the production values to be verified + */ +template < typename Range > +static void verify( const Range& values ) { + + if ( values.size() < 1 ) { + + Log::error( "Expected at least one production value, found {}", + values.size() ); + throw std::exception(); + } +} diff --git a/src/NDItk/multigroup/FissionNeutronProduction/test/CMakeLists.txt b/src/NDItk/multigroup/FissionNeutronProduction/test/CMakeLists.txt new file mode 100644 index 0000000..445ea49 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction/test/CMakeLists.txt @@ -0,0 +1 @@ +add_cpp_test( multigroup.FissionNeutronProduction FissionNeutronProduction.test.cpp ) \ No newline at end of file diff --git a/src/NDItk/multigroup/FissionNeutronProduction/test/FissionNeutronProduction.test.cpp b/src/NDItk/multigroup/FissionNeutronProduction/test/FissionNeutronProduction.test.cpp new file mode 100644 index 0000000..adad6b3 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronProduction/test/FissionNeutronProduction.test.cpp @@ -0,0 +1,129 @@ +// include Catch2 +#include +#include +using Catch::Matchers::WithinRel; + +// what we are testing +#include "NDItk/multigroup/FissionNeutronProduction.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::NDItk; +using FissionNeutronProduction = multigroup::FissionNeutronProduction; +using FissionType = multigroup::FissionType; + +std::string chunk(); +void verifyChunk( const FissionNeutronProduction& ); +std::string chunkWithInsufficientNumberValues(); + +SCENARIO( "FissionNeutronProduction" ) { + + GIVEN( "valid data for a FissionNeutronProduction instance" ) { + + std::string record = chunk(); + + WHEN( "the data is given explicitly" ) { + + std::vector< double > values = { 2., 2.1, 2.2, 2.3, 2.4, 5.0, 7.0 }; + + FissionNeutronProduction chunk( FissionType::Prompt, std::move( values ) ); + + THEN( "a FissionNeutronProduction can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + + WHEN( "the data is read using iterators" ) { + + auto iter = record.begin() + 11; + auto end = record.end(); + + FissionNeutronProduction chunk( FissionType::Prompt ); + chunk.read( iter, end, 7 ); + + THEN( "a FissionNeutronProduction can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data for a FissionNeutronProduction instance" ) { + + WHEN( "the number of weight values is insufficient" ) { + + THEN( "an exception is thrown" ) { + + std::vector< double > empty = {}; + + CHECK_THROWS( FissionNeutronProduction( FissionType::Prompt, std::move( empty ) ) ); + } // THEN + } // WHEN + + WHEN( "reading the data of the record and the number of " + "values is insufficient" ) { + + std::string record = chunkWithInsufficientNumberValues(); + auto iter = record.begin() + 11; + auto end = record.end(); + FissionNeutronProduction chunk( FissionType::Prompt ); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( chunk.read( iter, end, 0 ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return "nu_sig_f_pr\n" + " 2 2.1 2.2 2.3 2.4\n" + " 5 7\n"; +} + +void verifyChunk( const FissionNeutronProduction& chunk ) { + + CHECK( "nu_sig_f_pr" == chunk.keyword() ); + CHECK_THAT( 2, WithinRel( chunk.values()[0] ) ); + CHECK_THAT( 2.1, WithinRel( chunk.values()[1] ) ); + CHECK_THAT( 2.2, WithinRel( chunk.values()[2] ) ); + CHECK_THAT( 2.3, WithinRel( chunk.values()[3] ) ); + CHECK_THAT( 2.4, WithinRel( chunk.values()[4] ) ); + CHECK_THAT( 5, WithinRel( chunk.values()[5] ) ); + CHECK_THAT( 7, WithinRel( chunk.values()[6] ) ); + + CHECK( false == chunk.empty() ); + CHECK( 7 == chunk.size() ); + + CHECK( FissionType::Prompt == chunk.type() ); + CHECK( 7 == chunk.numberGroups() ); +} + +std::string chunkWithInsufficientNumberValues() { + + return "nu_sig_f_pr\n"; +} From 75377c02db59f2621da835dcd65088f692dc967c Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 16:41:12 -0600 Subject: [PATCH 03/12] Updating documentation --- .../multigroup/AverageFissionEnergyRelease/src/ctor.hpp | 4 ++-- .../multigroup/AverageFissionEnergyRelease/src/read.hpp | 1 - .../multigroup/FissionNeutronMultiplicity/src/ctor.hpp | 6 +++--- .../multigroup/FissionNeutronMultiplicity/src/read.hpp | 2 +- .../multigroup/FissionNeutronMultiplicity/src/verify.hpp | 4 ++-- src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp | 6 +++--- src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp | 2 +- .../multigroup/FissionNeutronProduction/src/verify.hpp | 2 +- src/NDItk/multigroup/HeatingNumbers/src/verify.hpp | 2 +- src/NDItk/multigroup/Kerma/src/verify.hpp | 2 +- src/NDItk/multigroup/LegendreMoment/src/verify.hpp | 4 ++-- src/NDItk/multigroup/OutgoingParticleTypes/src/read.hpp | 2 +- src/NDItk/multigroup/ScatteringMatrix/src/generateData.hpp | 2 +- src/NDItk/multigroup/TotalCrossSection/src/ctor.hpp | 2 +- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/NDItk/multigroup/AverageFissionEnergyRelease/src/ctor.hpp b/src/NDItk/multigroup/AverageFissionEnergyRelease/src/ctor.hpp index 5304ec1..1d04944 100644 --- a/src/NDItk/multigroup/AverageFissionEnergyRelease/src/ctor.hpp +++ b/src/NDItk/multigroup/AverageFissionEnergyRelease/src/ctor.hpp @@ -1,11 +1,11 @@ /** - * @brief Default constructor for the primary group structure + * @brief Default constructor for the average fission energy release */ AverageFissionEnergyRelease() : RealListRecord( base::Keyword( "fiss_q" ) ) {} /** - * @brief Constructor for the primary group structure + * @brief Constructor for the average fission energy release * * @param[in] total the total energy release (including delayed particles * and neutrinos) diff --git a/src/NDItk/multigroup/AverageFissionEnergyRelease/src/read.hpp b/src/NDItk/multigroup/AverageFissionEnergyRelease/src/read.hpp index 60a0d14..3dbb29e 100644 --- a/src/NDItk/multigroup/AverageFissionEnergyRelease/src/read.hpp +++ b/src/NDItk/multigroup/AverageFissionEnergyRelease/src/read.hpp @@ -6,7 +6,6 @@ * * @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 weight values */ template< typename Iterator > void read( Iterator& iter, const Iterator& end ) { diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp index 10f6729..ec5c720 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp @@ -6,11 +6,11 @@ FissionNeutronMultiplicity( FissionType type ) : RealListRecord( base::Keyword( /** * @brief Constructor * - * @param[in] weights the flux weights + * @param[in] nubar the fission neutron multiplicities */ FissionNeutronMultiplicity( FissionType type, - std::vector< double > values ) : - RealListRecord( base::Keyword( "nu", type ), std::move( values ) ) { + std::vector< double > nubar ) : + RealListRecord( base::Keyword( "nu", type ), std::move( nubar ) ) { verify( this->values() ); } diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp index 1b79ef3..c4a355d 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/read.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/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 nu values + * @param[in,out] number the number of fission neutron multiplicity values */ template< typename Iterator > void read( Iterator& iter, const Iterator& end, std::size_t number ) { diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp index 0d9263d..7c09289 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/verify.hpp @@ -4,14 +4,14 @@ * The following verification tests are performed: * - there is at least one value * - * @param[in] values the nu values to be verified + * @param[in] values the fission neutron multiplicity values to be verified */ template < typename Range > static void verify( const Range& values ) { if ( values.size() < 1 ) { - Log::error( "Expected at least one nu value, found {}", + Log::error( "Expected at least one fission neutron multiplicity value, found {}", values.size() ); throw std::exception(); } diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp index c1cf1da..84fb139 100644 --- a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp @@ -6,11 +6,11 @@ FissionNeutronProduction( FissionType type ) : RealListRecord( base::Keyword( "n /** * @brief Constructor * - * @param[in] weights the flux weights + * @param[in] production the fission neutron production values */ FissionNeutronProduction( FissionType type, - std::vector< double > values ) : - RealListRecord( base::Keyword( "nu_sig_f", type ), std::move( values ) ) { + std::vector< double > production ) : + RealListRecord( base::Keyword( "nu_sig_f", type ), std::move( production ) ) { verify( this->values() ); } diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp index 1b79ef3..dc69a85 100644 --- a/src/NDItk/multigroup/FissionNeutronProduction/src/read.hpp +++ b/src/NDItk/multigroup/FissionNeutronProduction/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 nu values + * @param[in,out] number the number of fission neutron production values */ template< typename Iterator > void read( Iterator& iter, const Iterator& end, std::size_t number ) { diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp index b751e39..3682cd7 100644 --- a/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/verify.hpp @@ -11,7 +11,7 @@ static void verify( const Range& values ) { if ( values.size() < 1 ) { - Log::error( "Expected at least one production value, found {}", + Log::error( "Expected at least one fission neutron production value, found {}", values.size() ); throw std::exception(); } diff --git a/src/NDItk/multigroup/HeatingNumbers/src/verify.hpp b/src/NDItk/multigroup/HeatingNumbers/src/verify.hpp index a872c4c..02da954 100644 --- a/src/NDItk/multigroup/HeatingNumbers/src/verify.hpp +++ b/src/NDItk/multigroup/HeatingNumbers/src/verify.hpp @@ -1,5 +1,5 @@ /** - * @brief Verify the weights + * @brief Verify the heating numbers * * The following verification tests are performed: * - there is at least one value diff --git a/src/NDItk/multigroup/Kerma/src/verify.hpp b/src/NDItk/multigroup/Kerma/src/verify.hpp index 1c02cac..7ea2dd6 100644 --- a/src/NDItk/multigroup/Kerma/src/verify.hpp +++ b/src/NDItk/multigroup/Kerma/src/verify.hpp @@ -1,5 +1,5 @@ /** - * @brief Verify the weights + * @brief Verify the kerma values * * The following verification tests are performed: * - there is at least one value diff --git a/src/NDItk/multigroup/LegendreMoment/src/verify.hpp b/src/NDItk/multigroup/LegendreMoment/src/verify.hpp index ba6a4b0..bf94576 100644 --- a/src/NDItk/multigroup/LegendreMoment/src/verify.hpp +++ b/src/NDItk/multigroup/LegendreMoment/src/verify.hpp @@ -1,9 +1,9 @@ /** - * @brief Verify the cross section data values + * @brief Verify the Legendre moment values * * The following verification tests are performed: * - there are at least two values - * - the reaction identifier looks to be an integer + * - the matrix is the correct size * * @param[in] data the data values in the Legendre moment subrecord */ diff --git a/src/NDItk/multigroup/OutgoingParticleTypes/src/read.hpp b/src/NDItk/multigroup/OutgoingParticleTypes/src/read.hpp index 83257b6..3231a9c 100644 --- a/src/NDItk/multigroup/OutgoingParticleTypes/src/read.hpp +++ b/src/NDItk/multigroup/OutgoingParticleTypes/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 velocity values + * @param[in,out] number the number of particle types */ template< typename Iterator > void read( Iterator& iter, const Iterator& end, std::size_t number ) { diff --git a/src/NDItk/multigroup/ScatteringMatrix/src/generateData.hpp b/src/NDItk/multigroup/ScatteringMatrix/src/generateData.hpp index 385e6d0..93a8524 100644 --- a/src/NDItk/multigroup/ScatteringMatrix/src/generateData.hpp +++ b/src/NDItk/multigroup/ScatteringMatrix/src/generateData.hpp @@ -1,7 +1,7 @@ /** * @brief Generate the record's data vector * - * @param[in] xs the cross section data + * @param[in] moments the Legendre moments */ static std::vector< double > generateData( std::vector< LegendreMoment > moments ) { diff --git a/src/NDItk/multigroup/TotalCrossSection/src/ctor.hpp b/src/NDItk/multigroup/TotalCrossSection/src/ctor.hpp index 737eb60..9c7aa6c 100644 --- a/src/NDItk/multigroup/TotalCrossSection/src/ctor.hpp +++ b/src/NDItk/multigroup/TotalCrossSection/src/ctor.hpp @@ -6,7 +6,7 @@ TotalCrossSection() : RealListRecord( base::Keyword( "sig_tot" ) ) {} /** * @brief Constructor * - * @param[in] weights the flux weights + * @param[in] values the total cross section values */ TotalCrossSection( std::vector< double > values ) : RealListRecord( base::Keyword( "sig_tot" ), std::move( values ) ) { From 21bf4817d9ff422fd32ad32a66c5bd0c9a829bcf Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 16:54:22 -0600 Subject: [PATCH 04/12] Updating bindings --- .../src/multigroup/EnergyGroupStructure.python.cpp | 10 +++++----- python/src/multigroup/FluxWeights.python.cpp | 6 +++--- .../Test_NDItk_multigroup_EnergyGroupStructure.py | 4 ++-- .../Test_NDItk_multigroup_FluxWeights.py | 2 +- .../multigroup/EnergyGroupStructure/src/ctor.hpp | 14 +++++++------- .../FissionNeutronMultiplicity/src/ctor.hpp | 6 +++--- .../FissionNeutronProduction/src/ctor.hpp | 6 +++--- src/NDItk/multigroup/FluxWeights/src/ctor.hpp | 6 +++--- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/python/src/multigroup/EnergyGroupStructure.python.cpp b/python/src/multigroup/EnergyGroupStructure.python.cpp index a9b5c45..a97eda4 100644 --- a/python/src/multigroup/EnergyGroupStructure.python.cpp +++ b/python/src/multigroup/EnergyGroupStructure.python.cpp @@ -33,21 +33,21 @@ void wrapEnergyGroupStructure( python::module& module, python::module& ) { .def( python::init< std::vector< double > >(), - python::arg( "boundaries" ), + python::arg( "values" ), "Initialise the record\n\n" "Arguments:\n" - " self the record\n" - " boundaries the group structure boundaries" + " self the record\n" + " values the group structure boundary values" ) .def( python::init< unsigned int, std::vector< double > >(), - python::arg( "particle" ), python::arg( "boundaries" ), + python::arg( "particle" ), python::arg( "values" ), "Initialise the record\n\n" "Arguments:\n" " self the table\n" " particle the secondary particle identifier\n" - " boundaries the group structure boundaries" + " values the group structure boundary values" ) .def_property_readonly( diff --git a/python/src/multigroup/FluxWeights.python.cpp b/python/src/multigroup/FluxWeights.python.cpp index 49d3d96..ca89b64 100644 --- a/python/src/multigroup/FluxWeights.python.cpp +++ b/python/src/multigroup/FluxWeights.python.cpp @@ -33,11 +33,11 @@ void wrapFluxWeights( python::module& module, python::module& ) { .def( python::init< std::vector< double > >(), - python::arg( "weights" ), + python::arg( "values" ), "Initialise the record\n\n" "Arguments:\n" - " self the record\n" - " weights the flux weights" + " self the record\n" + " values the flux weight values" ) .def_property_readonly( diff --git a/python/test/multigroup/Test_NDItk_multigroup_EnergyGroupStructure.py b/python/test/multigroup/Test_NDItk_multigroup_EnergyGroupStructure.py index 7681bd5..7ae2e32 100644 --- a/python/test/multigroup/Test_NDItk_multigroup_EnergyGroupStructure.py +++ b/python/test/multigroup/Test_NDItk_multigroup_EnergyGroupStructure.py @@ -68,7 +68,7 @@ def verify_outgoing_chunk( self, chunk ) : self.assertAlmostEqual( self.chunk_outgoing_values[index], values[index] ) # the data is given explicitly - chunk = EnergyGroupStructure( boundaries = [ 20., 18., 16., 14., 10., 5, 1, 1e-11 ] ) + chunk = EnergyGroupStructure( values = [ 20., 18., 16., 14., 10., 5, 1, 1e-11 ] ) verify_chunk( self, chunk ) @@ -78,7 +78,7 @@ def verify_outgoing_chunk( self, chunk ) : verify_chunk( self, chunk ) # the data is given explicitly for an outgoing particle - chunk = EnergyGroupStructure( particle = 1001, boundaries = [ 20., 10., 1e-11 ] ) + chunk = EnergyGroupStructure( particle = 1001, values = [ 20., 10., 1e-11 ] ) verify_outgoing_chunk( self, chunk ) diff --git a/python/test/multigroup/Test_NDItk_multigroup_FluxWeights.py b/python/test/multigroup/Test_NDItk_multigroup_FluxWeights.py index 221b2f1..235df68 100644 --- a/python/test/multigroup/Test_NDItk_multigroup_FluxWeights.py +++ b/python/test/multigroup/Test_NDItk_multigroup_FluxWeights.py @@ -41,7 +41,7 @@ def verify_chunk( self, chunk ) : self.assertAlmostEqual( self.chunk_values[index], values[index] ) # the data is given explicitly - chunk = FluxWeights( weights = [ 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 ] ) + chunk = FluxWeights( values = [ 0.1, 0.2, 0.25, 0.05, 0.15, 0.04, 0.06 ] ) verify_chunk( self, chunk ) diff --git a/src/NDItk/multigroup/EnergyGroupStructure/src/ctor.hpp b/src/NDItk/multigroup/EnergyGroupStructure/src/ctor.hpp index 342f8cc..313d625 100644 --- a/src/NDItk/multigroup/EnergyGroupStructure/src/ctor.hpp +++ b/src/NDItk/multigroup/EnergyGroupStructure/src/ctor.hpp @@ -14,10 +14,10 @@ EnergyGroupStructure( unsigned int particle ) : /** * @brief Constructor for the primary group structure * - * @param[in] boundaries the group structure boundaries + * @param[in] boundaries the group structure boundary values */ -EnergyGroupStructure( std::vector< double > boundaries ) : - RealListRecord( base::Keyword( "e_bounds" ), std::move( boundaries ) ) { +EnergyGroupStructure( std::vector< double > values ) : + RealListRecord( base::Keyword( "e_bounds" ), std::move( values ) ) { verify( this->values() ); } @@ -25,12 +25,12 @@ EnergyGroupStructure( std::vector< double > boundaries ) : /** * @brief Constructor for a secondary particle group structure * - * @param[in] particle the secondary particle identifier - * @param[in] boundaries the group structure boundaries + * @param[in] particle the secondary particle identifier + * @param[in] values the group structure boundary values */ -EnergyGroupStructure( unsigned int particle, std::vector< double > boundaries ) : +EnergyGroupStructure( unsigned int particle, std::vector< double > values ) : RealListRecord( base::Keyword( "e_bounds", particle ), - std::move( boundaries ) ) { + std::move( values ) ) { verify( this->values() ); } diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp index ec5c720..876f563 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp @@ -6,11 +6,11 @@ FissionNeutronMultiplicity( FissionType type ) : RealListRecord( base::Keyword( /** * @brief Constructor * - * @param[in] nubar the fission neutron multiplicities + * @param[in] values the fission neutron multiplicity values */ FissionNeutronMultiplicity( FissionType type, - std::vector< double > nubar ) : - RealListRecord( base::Keyword( "nu", type ), std::move( nubar ) ) { + std::vector< double > values ) : + RealListRecord( base::Keyword( "nu", type ), std::move( values ) ) { verify( this->values() ); } diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp index 84fb139..7a15d83 100644 --- a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp @@ -6,11 +6,11 @@ FissionNeutronProduction( FissionType type ) : RealListRecord( base::Keyword( "n /** * @brief Constructor * - * @param[in] production the fission neutron production values + * @param[in] values the fission neutron production values */ FissionNeutronProduction( FissionType type, - std::vector< double > production ) : - RealListRecord( base::Keyword( "nu_sig_f", type ), std::move( production ) ) { + std::vector< double > values ) : + RealListRecord( base::Keyword( "nu_sig_f", type ), std::move( values ) ) { verify( this->values() ); } diff --git a/src/NDItk/multigroup/FluxWeights/src/ctor.hpp b/src/NDItk/multigroup/FluxWeights/src/ctor.hpp index 9fa6f28..9ee383e 100644 --- a/src/NDItk/multigroup/FluxWeights/src/ctor.hpp +++ b/src/NDItk/multigroup/FluxWeights/src/ctor.hpp @@ -6,10 +6,10 @@ FluxWeights() : RealListRecord( base::Keyword( "wgts" ) ) {} /** * @brief Constructor * - * @param[in] weights the flux weights + * @param[in] values the flux weight values */ -FluxWeights( std::vector< double > weights ) : - RealListRecord( base::Keyword( "wgts" ), std::move( weights ) ) { +FluxWeights( std::vector< double > values ) : + RealListRecord( base::Keyword( "wgts" ), std::move( values ) ) { verify( this->values() ); } From 9918fab3ebc866de6c79666957274e62b8f4b5ce Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 19:36:33 -0600 Subject: [PATCH 05/12] Adding python bindings --- CMakeLists.txt | 2 + cmake/unit_testing_python.cmake | 2 + .../ReactionMultiplicities.python.cpp | 6 ++ python/src/multigroup.python.cpp | 4 + .../FissionNeutronMultiplicity.python.cpp | 73 +++++++++++++++++++ .../FissionNeutronProduction.python.cpp | 73 +++++++++++++++++++ ..._NDItk_depletion_ReactionMultiplicities.py | 2 + ...k_multigroup_FissionNeutronMultiplicity.py | 58 +++++++++++++++ ...Itk_multigroup_FissionNeutronProduction.py | 58 +++++++++++++++ .../Test_NDItk_multigroup_ScatteringMatrix.py | 1 - .../multigroup/FissionNeutronMultiplicity.hpp | 2 +- .../FissionNeutronMultiplicity/src/ctor.hpp | 5 ++ .../FissionNeutronProduction/src/ctor.hpp | 5 ++ 13 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 python/src/multigroup/FissionNeutronMultiplicity.python.cpp create mode 100644 python/src/multigroup/FissionNeutronProduction.python.cpp create mode 100644 python/test/multigroup/Test_NDItk_multigroup_FissionNeutronMultiplicity.py create mode 100644 python/test/multigroup/Test_NDItk_multigroup_FissionNeutronProduction.py diff --git a/CMakeLists.txt b/CMakeLists.txt index c205b64..440ec5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,8 @@ if( NDItk.python ) python/src/multigroup/ReactionCrossSections.python.cpp python/src/multigroup/TotalCrossSection.python.cpp python/src/multigroup/AverageFissionEnergyRelease.python.cpp + python/src/multigroup/FissionNeutronMultiplicity.python.cpp + python/src/multigroup/FissionNeutronProduction.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 1d09388..f54d973 100644 --- a/cmake/unit_testing_python.cmake +++ b/cmake/unit_testing_python.cmake @@ -32,6 +32,8 @@ add_python_test( multigroup.EnergyGroupStructure multigroup/Test_NDItk_ add_python_test( multigroup.ReactionCrossSections multigroup/Test_NDItk_multigroup_ReactionCrossSections.py ) add_python_test( multigroup.TotalCrossSection multigroup/Test_NDItk_multigroup_TotalCrossSection.py ) 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.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/src/depletion/ReactionMultiplicities.python.cpp b/python/src/depletion/ReactionMultiplicities.python.cpp index c271f68..52e2d97 100644 --- a/python/src/depletion/ReactionMultiplicities.python.cpp +++ b/python/src/depletion/ReactionMultiplicities.python.cpp @@ -52,6 +52,12 @@ void wrapReactionMultiplicities( python::module& module, python::module& ) { " type the multiplicity type (all, few or rmo)\n" " multiplicities the multiplicity data" ) + .def_property_readonly( + + "type", + &Record::type, + "The multiplicity type defined by this record" + ) .def_property_readonly( "number_reactions", diff --git a/python/src/multigroup.python.cpp b/python/src/multigroup.python.cpp index 7cbf996..becfe1b 100644 --- a/python/src/multigroup.python.cpp +++ b/python/src/multigroup.python.cpp @@ -21,6 +21,8 @@ namespace multigroup { void wrapHeatingNumbers( python::module&, python::module& ); void wrapKerma( python::module&, python::module& ); void wrapAverageFissionEnergyRelease( python::module&, python::module& ); + void wrapFissionNeutronMultiplicity( python::module&, python::module& ); + void wrapFissionNeutronProduction( python::module&, python::module& ); void wrapOutgoingParticleTypes( python::module&, python::module& ); void wrapOutgoingParticleTransportData( python::module&, python::module& ); void wrapLegendreMoment( python::module&, python::module& ); @@ -47,6 +49,8 @@ void wrapMultigroup( python::module& module, python::module& viewmodule ) { multigroup::wrapHeatingNumbers( submodule, viewmodule ); multigroup::wrapKerma( submodule, viewmodule ); multigroup::wrapAverageFissionEnergyRelease( submodule, viewmodule ); + multigroup::wrapFissionNeutronMultiplicity( submodule, viewmodule ); + multigroup::wrapFissionNeutronProduction( submodule, viewmodule ); multigroup::wrapOutgoingParticleTypes( submodule, viewmodule ); multigroup::wrapOutgoingParticleTransportData( submodule, viewmodule ); multigroup::wrapLegendreMoment( submodule, viewmodule ); diff --git a/python/src/multigroup/FissionNeutronMultiplicity.python.cpp b/python/src/multigroup/FissionNeutronMultiplicity.python.cpp new file mode 100644 index 0000000..1c9c1b5 --- /dev/null +++ b/python/src/multigroup/FissionNeutronMultiplicity.python.cpp @@ -0,0 +1,73 @@ +// system includes +#include +#include + +// local includes +#include "NDItk/multigroup/FissionNeutronMultiplicity.hpp" +#include "tools/views/views-python.hpp" +#include "definitions.hpp" +#include "read.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace multigroup { + +void wrapFissionNeutronMultiplicity( python::module& module, python::module& ) { + + // type aliases + using Record = njoy::NDItk::multigroup::FissionNeutronMultiplicity; + using FissionType = njoy::NDItk::multigroup::FissionType; + + // wrap views created by this record + + // create the record + python::class_< Record > record( + + module, + "FissionNeutronMultiplicity", + "A fission neutron multiplicity 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 multiplicity 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 fission neutron multiplicity values" + ); + + // add standard record definitions + addStandardRecordDefinitions< Record, DoubleRange >( record ); +} + +} // multigroup namespace diff --git a/python/src/multigroup/FissionNeutronProduction.python.cpp b/python/src/multigroup/FissionNeutronProduction.python.cpp new file mode 100644 index 0000000..e505549 --- /dev/null +++ b/python/src/multigroup/FissionNeutronProduction.python.cpp @@ -0,0 +1,73 @@ +// system includes +#include +#include + +// local includes +#include "NDItk/multigroup/FissionNeutronProduction.hpp" +#include "tools/views/views-python.hpp" +#include "definitions.hpp" +#include "read.hpp" + +// namespace aliases +namespace python = pybind11; + +namespace multigroup { + +void wrapFissionNeutronProduction( python::module& module, python::module& ) { + + // type aliases + using Record = njoy::NDItk::multigroup::FissionNeutronProduction; + using FissionType = njoy::NDItk::multigroup::FissionType; + + // wrap views created by this record + + // create the record + python::class_< Record > record( + + module, + "FissionNeutronProduction", + "A fission neutron production 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 production 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 fission neutron production values" + ); + + // add standard record definitions + addStandardRecordDefinitions< Record, DoubleRange >( record ); +} + +} // multigroup namespace diff --git a/python/test/depletion/Test_NDItk_depletion_ReactionMultiplicities.py b/python/test/depletion/Test_NDItk_depletion_ReactionMultiplicities.py index b377732..ac0ab55 100644 --- a/python/test/depletion/Test_NDItk_depletion_ReactionMultiplicities.py +++ b/python/test/depletion/Test_NDItk_depletion_ReactionMultiplicities.py @@ -37,6 +37,7 @@ def test_component( self ) : def verify_chunk( self, chunk ) : # verify content + self.assertEqual( None, chunk.type ) self.assertEqual( 2, chunk.number_reactions ) self.assertEqual( True, chunk.has_reaction( 2 ) ) @@ -95,6 +96,7 @@ def verify_chunk( self, chunk ) : def verify_chunk_typed( self, chunk ) : # verify content + self.assertEqual( ReactionMultiplicityType.All, chunk.type ) self.assertEqual( 2, chunk.number_reactions ) self.assertEqual( True, chunk.has_reaction( 2 ) ) diff --git a/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronMultiplicity.py b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronMultiplicity.py new file mode 100644 index 0000000..a2ea8af --- /dev/null +++ b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronMultiplicity.py @@ -0,0 +1,58 @@ +# standard imports +import unittest + +# third party imports + +# local imports +from NDItk.multigroup import FissionNeutronMultiplicity +from NDItk.multigroup import FissionType + +class Test_NDItk_multigroup_FissionNeutronMultiplicity( unittest.TestCase ) : + """Unit test for the FissionNeutronMultiplicity class.""" + + chunk_values = [ 2, 2.1, 2.2, 2.3, 2.4, 5, 7 ] + chunk_string = ( 'nu_pr\n' + ' 2 2.1 2.2 2.3 2.4\n' + ' 5 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( 2, chunk.values[0] ) + self.assertAlmostEqual( 2.1, chunk.values[1] ) + self.assertAlmostEqual( 2.2, chunk.values[2] ) + self.assertAlmostEqual( 2.3, chunk.values[3] ) + self.assertAlmostEqual( 2.4, chunk.values[4] ) + self.assertAlmostEqual( 5, chunk.values[5] ) + self.assertAlmostEqual( 7, chunk.values[6] ) + + self.assertEqual( self.chunk_string, chunk.to_string() ) + + # verify the record + self.assertEqual( 'nu_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 = FissionNeutronMultiplicity( type = FissionType.Prompt, + values = [ 2, 2.1, 2.2, 2.3, 2.4, 5, 7 ] ) + + verify_chunk( self, chunk ) + + # the data is read from a string + chunk = FissionNeutronMultiplicity.from_string( self.chunk_string, 7 ) + + verify_chunk( self, chunk ) + +if __name__ == '__main__' : + + unittest.main() diff --git a/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronProduction.py b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronProduction.py new file mode 100644 index 0000000..b3b98e8 --- /dev/null +++ b/python/test/multigroup/Test_NDItk_multigroup_FissionNeutronProduction.py @@ -0,0 +1,58 @@ +# standard imports +import unittest + +# third party imports + +# local imports +from NDItk.multigroup import FissionNeutronProduction +from NDItk.multigroup import FissionType + +class Test_NDItk_multigroup_FissionNeutronProduction( unittest.TestCase ) : + """Unit test for the FissionNeutronProduction class.""" + + chunk_values = [ 2, 2.1, 2.2, 2.3, 2.4, 5, 7 ] + chunk_string = ( 'nu_sig_f_pr\n' + ' 2 2.1 2.2 2.3 2.4\n' + ' 5 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( 2, chunk.values[0] ) + self.assertAlmostEqual( 2.1, chunk.values[1] ) + self.assertAlmostEqual( 2.2, chunk.values[2] ) + self.assertAlmostEqual( 2.3, chunk.values[3] ) + self.assertAlmostEqual( 2.4, chunk.values[4] ) + self.assertAlmostEqual( 5, chunk.values[5] ) + self.assertAlmostEqual( 7, chunk.values[6] ) + + self.assertEqual( self.chunk_string, chunk.to_string() ) + + # verify the record + self.assertEqual( 'nu_sig_f_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 = FissionNeutronProduction( type = FissionType.Prompt, + values = [ 2, 2.1, 2.2, 2.3, 2.4, 5, 7 ] ) + + verify_chunk( self, chunk ) + + # the data is read from a string + chunk = FissionNeutronProduction.from_string( self.chunk_string, 7 ) + + verify_chunk( self, chunk ) + +if __name__ == '__main__' : + + unittest.main() diff --git a/python/test/multigroup/Test_NDItk_multigroup_ScatteringMatrix.py b/python/test/multigroup/Test_NDItk_multigroup_ScatteringMatrix.py index 48389ec..df4ef8a 100644 --- a/python/test/multigroup/Test_NDItk_multigroup_ScatteringMatrix.py +++ b/python/test/multigroup/Test_NDItk_multigroup_ScatteringMatrix.py @@ -191,4 +191,3 @@ def verify_outgoing_chunk( self, chunk ) : if __name__ == '__main__' : unittest.main() - diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp index d2e4b9f..486fdd4 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity.hpp @@ -13,7 +13,7 @@ namespace NDItk { namespace multigroup { /** - * @brief A fission nubar record for multigroup neutron and photon data + * @brief A fission neutron multiplicity record for multigroup neutron and photon data */ class FissionNeutronMultiplicity : protected base::RealListRecord { diff --git a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp index 876f563..ee44caa 100644 --- a/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronMultiplicity/src/ctor.hpp @@ -1,3 +1,8 @@ +/** + * @brief Default constructor + */ +FissionNeutronMultiplicity() : RealListRecord( base::Keyword( "nu" ) ) {} + /** * @brief Default constructor */ diff --git a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp index 7a15d83..aae29bd 100644 --- a/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp +++ b/src/NDItk/multigroup/FissionNeutronProduction/src/ctor.hpp @@ -1,3 +1,8 @@ +/** + * @brief Default constructor + */ +FissionNeutronProduction() : RealListRecord( base::Keyword( "nu_sig_f" ) ) {} + /** * @brief Default constructor */ From 0332067e832ce1865ac0e78a320a3452d8221011 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 4 Jun 2024 20:01:01 -0600 Subject: [PATCH 06/12] Adding the nubar data to the MultigroupTable --- src/NDItk/MultigroupTable.hpp | 8 +++++ src/NDItk/MultigroupTable/src/ctor.hpp | 6 +++- src/NDItk/MultigroupTable/src/read.hpp | 42 ++++++++++++++++++++++++ src/NDItk/MultigroupTable/src/verify.hpp | 10 +++--- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/NDItk/MultigroupTable.hpp b/src/NDItk/MultigroupTable.hpp index 29ea86c..a6d2740 100644 --- a/src/NDItk/MultigroupTable.hpp +++ b/src/NDItk/MultigroupTable.hpp @@ -13,6 +13,8 @@ #include "NDItk/multigroup/ReactionCrossSections.hpp" #include "NDItk/multigroup/TotalCrossSection.hpp" #include "NDItk/multigroup/AverageFissionEnergyRelease.hpp" +#include "NDItk/multigroup/FissionNeutronMultiplicity.hpp" +#include "NDItk/multigroup/FissionNeutronProduction.hpp" #include "NDItk/multigroup/OutgoingParticleTypes.hpp" #include "NDItk/multigroup/OutgoingParticleTransportData.hpp" #include "NDItk/multigroup/HeatingNumbers.hpp" @@ -37,6 +39,9 @@ class MultigroupTable { multigroup::ReactionCrossSections xs_; multigroup::ScatteringMatrix scattering_; multigroup::AverageFissionEnergyRelease release_; + multigroup::FissionNeutronMultiplicity nubar_prompt_; + multigroup::FissionNeutronMultiplicity nubar_delayed_; + multigroup::FissionNeutronMultiplicity nubar_total_; multigroup::HeatingNumbers primary_heating_; multigroup::Kerma primary_kerma_; depletion::ReactionMultiplicities product_multiplicities_all_; @@ -278,6 +283,9 @@ class MultigroupTable { this->xs_.print( iter ); this->scattering_.print( iter ); this->release_.print( iter ); + this->nubar_prompt_.print( iter ); + this->nubar_delayed_.print( iter ); + this->nubar_total_.print( iter ); this->primary_heating_.print( iter ); this->primary_kerma_.print( iter ); this->product_multiplicities_all_.print( iter ); diff --git a/src/NDItk/MultigroupTable/src/ctor.hpp b/src/NDItk/MultigroupTable/src/ctor.hpp index d754ffd..15b20d8 100644 --- a/src/NDItk/MultigroupTable/src/ctor.hpp +++ b/src/NDItk/MultigroupTable/src/ctor.hpp @@ -4,7 +4,11 @@ MultigroupTable() : metadata_(), primary_structure_(), velocities_(), weights_(), total_(), xs_(), scattering_(), - release_(), primary_heating_(), primary_kerma_(), + release_(), + nubar_prompt_( multigroup::FissionType::Prompt ), + nubar_delayed_( multigroup::FissionType::Delayed ), + nubar_total_( multigroup::FissionType::Total ), + primary_heating_(), primary_kerma_(), product_multiplicities_all_( depletion::ReactionMultiplicityType::All ), product_multiplicities_few_( depletion::ReactionMultiplicityType::Few ), product_multiplicities_rmo_( depletion::ReactionMultiplicityType::RMO ), diff --git a/src/NDItk/MultigroupTable/src/read.hpp b/src/NDItk/MultigroupTable/src/read.hpp index 7766c9c..be38d0d 100644 --- a/src/NDItk/MultigroupTable/src/read.hpp +++ b/src/NDItk/MultigroupTable/src/read.hpp @@ -123,6 +123,48 @@ void read( Iterator& iter, const Iterator& end ) { readRecord( this->release_, iter, end ); } + // prompt fission neutorn multiplicity + else if ( keyword == this->nubar_prompt_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->nubar_prompt_, 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(); + } + } + // delayed fission neutorn multiplicity + else if ( keyword == this->nubar_delayed_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->nubar_delayed_, 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(); + } + } + // total fission neutorn multiplicity + else if ( keyword == this->nubar_total_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->nubar_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(); + } + } // primary and outgoing heating keyword else if ( keyword.find( this->primary_heating_.keyword() ) == 0 ) { diff --git a/src/NDItk/MultigroupTable/src/verify.hpp b/src/NDItk/MultigroupTable/src/verify.hpp index cbfc45d..a26b766 100644 --- a/src/NDItk/MultigroupTable/src/verify.hpp +++ b/src/NDItk/MultigroupTable/src/verify.hpp @@ -91,11 +91,11 @@ void verify() { if ( types > 0 ) { if ( ( this->outgoingParticleTypes().numberOutgoingParticles() != types ) || - ( this->outgoingParticleTransportData().numberOutgoingParticles() != types ) || - ( this->outgoing_structure_.size() != types ) || - ( this->outgoing_production_.size() != types ) || - ( this->outgoing_heating_.size() != types ) || - ( this->outgoing_kerma_.size() != types ) ) { + ( ! this->outgoingParticleTransportData().empty() && this->outgoingParticleTransportData().numberOutgoingParticles() != types ) || + ( this->outgoing_structure_.size() && this->outgoing_structure_.size() != types ) || + ( this->outgoing_production_.size() && this->outgoing_production_.size() != types ) || + ( this->outgoing_heating_.size() && this->outgoing_heating_.size() != types ) || + ( this->outgoing_kerma_.size() && this->outgoing_kerma_.size() != types ) ) { Log::error( "Found inconsistent number of outgoing particle types across the table" ); Log::info( "Number of outgoing particles in the metadata: {}", From 466dbaf0848eb6c13f7d25d15ad610e450f6af6f Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 5 Jun 2024 06:19:03 -0600 Subject: [PATCH 07/12] adding fission neutron spectra vector and matrix records --- src/NDItk/MultigroupTable.hpp | 14 +++ src/NDItk/MultigroupTable/src/ctor.hpp | 6 ++ src/NDItk/MultigroupTable/src/read.hpp | 90 ++++++++++++++++++- src/NDItk/MultigroupTable/src/verify.hpp | 51 ++++++----- .../FissionNeutronSpectrumMatrix.hpp | 59 ++++++++++++ .../FissionNeutronSpectrumMatrix/src/ctor.hpp | 21 +++++ .../FissionNeutronSpectrumMatrix/src/read.hpp | 16 ++++ .../src/verify.hpp | 18 ++++ .../FissionNeutronSpectrumVector.hpp | 59 ++++++++++++ .../FissionNeutronSpectrumVector/src/ctor.hpp | 21 +++++ .../FissionNeutronSpectrumVector/src/read.hpp | 16 ++++ .../src/verify.hpp | 18 ++++ 12 files changed, 362 insertions(+), 27 deletions(-) create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/ctor.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/read.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector/src/ctor.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector/src/verify.hpp diff --git a/src/NDItk/MultigroupTable.hpp b/src/NDItk/MultigroupTable.hpp index a6d2740..6958b3c 100644 --- a/src/NDItk/MultigroupTable.hpp +++ b/src/NDItk/MultigroupTable.hpp @@ -15,6 +15,8 @@ #include "NDItk/multigroup/AverageFissionEnergyRelease.hpp" #include "NDItk/multigroup/FissionNeutronMultiplicity.hpp" #include "NDItk/multigroup/FissionNeutronProduction.hpp" +#include "NDItk/multigroup/FissionNeutronSpectrumVector.hpp" +#include "NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp" #include "NDItk/multigroup/OutgoingParticleTypes.hpp" #include "NDItk/multigroup/OutgoingParticleTransportData.hpp" #include "NDItk/multigroup/HeatingNumbers.hpp" @@ -42,6 +44,12 @@ class MultigroupTable { multigroup::FissionNeutronMultiplicity nubar_prompt_; multigroup::FissionNeutronMultiplicity nubar_delayed_; multigroup::FissionNeutronMultiplicity nubar_total_; + multigroup::FissionNeutronSpectrumVector chi_vector_prompt_; + multigroup::FissionNeutronSpectrumVector chi_vector_delayed_; + multigroup::FissionNeutronSpectrumVector chi_vector_total_; + multigroup::FissionNeutronSpectrumMatrix chi_matrix_prompt_; + multigroup::FissionNeutronSpectrumMatrix chi_matrix_delayed_; + multigroup::FissionNeutronSpectrumMatrix chi_matrix_total_; multigroup::HeatingNumbers primary_heating_; multigroup::Kerma primary_kerma_; depletion::ReactionMultiplicities product_multiplicities_all_; @@ -286,6 +294,12 @@ class MultigroupTable { this->nubar_prompt_.print( iter ); this->nubar_delayed_.print( iter ); this->nubar_total_.print( iter ); + this->chi_vector_prompt_.print( iter ); + this->chi_vector_delayed_.print( iter ); + this->chi_vector_total_.print( iter ); + this->chi_matrix_prompt_.print( iter ); + this->chi_matrix_delayed_.print( iter ); + this->chi_matrix_total_.print( iter ); this->primary_heating_.print( iter ); this->primary_kerma_.print( iter ); this->product_multiplicities_all_.print( iter ); diff --git a/src/NDItk/MultigroupTable/src/ctor.hpp b/src/NDItk/MultigroupTable/src/ctor.hpp index 15b20d8..074d6c8 100644 --- a/src/NDItk/MultigroupTable/src/ctor.hpp +++ b/src/NDItk/MultigroupTable/src/ctor.hpp @@ -8,6 +8,12 @@ MultigroupTable() : nubar_prompt_( multigroup::FissionType::Prompt ), nubar_delayed_( multigroup::FissionType::Delayed ), nubar_total_( multigroup::FissionType::Total ), + chi_vector_prompt_( multigroup::FissionType::Prompt ), + chi_vector_delayed_( multigroup::FissionType::Delayed ), + chi_vector_total_( multigroup::FissionType::Total ), + chi_matrix_prompt_( multigroup::FissionType::Prompt ), + chi_matrix_delayed_( multigroup::FissionType::Delayed ), + chi_matrix_total_( multigroup::FissionType::Total ), primary_heating_(), primary_kerma_(), product_multiplicities_all_( depletion::ReactionMultiplicityType::All ), product_multiplicities_few_( depletion::ReactionMultiplicityType::Few ), diff --git a/src/NDItk/MultigroupTable/src/read.hpp b/src/NDItk/MultigroupTable/src/read.hpp index be38d0d..d2ff7fe 100644 --- a/src/NDItk/MultigroupTable/src/read.hpp +++ b/src/NDItk/MultigroupTable/src/read.hpp @@ -123,7 +123,7 @@ void read( Iterator& iter, const Iterator& end ) { readRecord( this->release_, iter, end ); } - // prompt fission neutorn multiplicity + // prompt fission neutron multiplicity else if ( keyword == this->nubar_prompt_.keyword() ) { if ( this->metadata_.numberGroups().has_value() ) { @@ -137,7 +137,7 @@ void read( Iterator& iter, const Iterator& end ) { throw std::exception(); } } - // delayed fission neutorn multiplicity + // delayed fission neutron multiplicity else if ( keyword == this->nubar_delayed_.keyword() ) { if ( this->metadata_.numberGroups().has_value() ) { @@ -151,7 +151,7 @@ void read( Iterator& iter, const Iterator& end ) { throw std::exception(); } } - // total fission neutorn multiplicity + // total fission neutron multiplicity else if ( keyword == this->nubar_total_.keyword() ) { if ( this->metadata_.numberGroups().has_value() ) { @@ -165,6 +165,90 @@ void read( Iterator& iter, const Iterator& end ) { throw std::exception(); } } + // prompt fission neutron spectrum vector + else if ( keyword == this->chi_vector_prompt_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_vector_prompt_, 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(); + } + } + // delayed fission neutron spectrum vector + else if ( keyword == this->chi_vector_delayed_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_vector_delayed_, 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(); + } + } + // total fission neutron spectrum vector + else if ( keyword == this->chi_vector_total_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_vector_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(); + } + } + // prompt fission neutron spectrum matrix + else if ( keyword == this->chi_matrix_prompt_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_matrix_prompt_, 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(); + } + } + // delayed fission neutron spectrum matrix + else if ( keyword == this->chi_matrix_delayed_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_matrix_delayed_, 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(); + } + } + // total fission neutron spectrum matrix + else if ( keyword == this->chi_matrix_total_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->chi_matrix_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(); + } + } // primary and outgoing heating keyword else if ( keyword.find( this->primary_heating_.keyword() ) == 0 ) { diff --git a/src/NDItk/MultigroupTable/src/verify.hpp b/src/NDItk/MultigroupTable/src/verify.hpp index a26b766..16fe7fe 100644 --- a/src/NDItk/MultigroupTable/src/verify.hpp +++ b/src/NDItk/MultigroupTable/src/verify.hpp @@ -87,32 +87,35 @@ void verify() { } // secondary particles - const auto types = this->metadata().numberOutgoingParticles().value(); - if ( types > 0 ) { + if ( this->metadata().numberOutgoingParticles().has_value() ) { - if ( ( this->outgoingParticleTypes().numberOutgoingParticles() != types ) || - ( ! this->outgoingParticleTransportData().empty() && this->outgoingParticleTransportData().numberOutgoingParticles() != types ) || - ( this->outgoing_structure_.size() && this->outgoing_structure_.size() != types ) || - ( this->outgoing_production_.size() && this->outgoing_production_.size() != types ) || - ( this->outgoing_heating_.size() && this->outgoing_heating_.size() != types ) || - ( this->outgoing_kerma_.size() && this->outgoing_kerma_.size() != types ) ) { + const auto types = this->metadata().numberOutgoingParticles().value(); + if ( types > 0 ) { - Log::error( "Found inconsistent number of outgoing particle types across the table" ); - Log::info( "Number of outgoing particles in the metadata: {}", - this->metadata().numberOutgoingParticles().value() ); - Log::info( "Number of types in the outgoing particle types: {}", - this->outgoingParticleTypes().numberOutgoingParticles() ); - Log::info( "Number of types in the outgoing transport data: {}", - this->outgoingParticleTransportData().numberOutgoingParticles() ); - Log::info( "Number of types in the outgoing group structures: {}", - this->outgoing_structure_.size() ); - Log::info( "Number of types in the outgoing production matrices: {}", - this->outgoing_production_.size() ); - Log::info( "Number of types in the outgoing heating numbers: {}", - this->outgoing_heating_.size() ); - Log::info( "Number of types in the outgoing kerma values: {}", - this->outgoing_kerma_.size() ); - throw std::exception(); + if ( ( this->outgoingParticleTypes().numberOutgoingParticles() != types ) || + ( ! this->outgoingParticleTransportData().empty() && this->outgoingParticleTransportData().numberOutgoingParticles() != types ) || + ( this->outgoing_structure_.size() && this->outgoing_structure_.size() != types ) || + ( this->outgoing_production_.size() && this->outgoing_production_.size() != types ) || + ( this->outgoing_heating_.size() && this->outgoing_heating_.size() != types ) || + ( this->outgoing_kerma_.size() && this->outgoing_kerma_.size() != types ) ) { + + Log::error( "Found inconsistent number of outgoing particle types across the table" ); + Log::info( "Number of outgoing particles in the metadata: {}", + this->metadata().numberOutgoingParticles().value() ); + Log::info( "Number of types in the outgoing particle types: {}", + this->outgoingParticleTypes().numberOutgoingParticles() ); + Log::info( "Number of types in the outgoing transport data: {}", + this->outgoingParticleTransportData().numberOutgoingParticles() ); + Log::info( "Number of types in the outgoing group structures: {}", + this->outgoing_structure_.size() ); + Log::info( "Number of types in the outgoing production matrices: {}", + this->outgoing_production_.size() ); + Log::info( "Number of types in the outgoing heating numbers: {}", + this->outgoing_heating_.size() ); + Log::info( "Number of types in the outgoing kerma values: {}", + this->outgoing_kerma_.size() ); + throw std::exception(); + } } } }; diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp new file mode 100644 index 0000000..aecadb9 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp @@ -0,0 +1,59 @@ +#ifndef NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONSPECTRUMMATRIX +#define NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONSPECTRUMMATRIX + +// system includes + +// other includes +#include "tools/Log.hpp" +#include "NDItk/base/RealListRecord.hpp" +#include "NDItk/multigroup/FissionType.hpp" + +namespace njoy { +namespace NDItk { +namespace multigroup { + +/** + * @brief A fission neutron spectrum matrix record for multigroup neutron and photon data + */ +class FissionNeutronSpectrumMatrix : protected base::RealListRecord { + + /* fields */ + + /* auxiliary functions */ + + #include "NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp" + +public: + + /* constructor */ + + #include "NDItk/multigroup/FissionNeutronSpectrumMatrix/src/ctor.hpp" + + /* methods */ + + /** + * @brief Return the fission type defined by this record + */ + FissionType type() const { return this->key().fissionType().value(); } + + /** + * @brief Return the number of groups defined by this record + */ + unsigned int numberGroups() const { return std::sqrt( this->size() ); } + + using base::RealListRecord::keyword; + using base::RealListRecord::values; + using base::RealListRecord::size; + using base::RealListRecord::empty; + using base::RealListRecord::begin; + using base::RealListRecord::end; + using base::RealListRecord::print; + + #include "NDItk/multigroup/FissionNeutronSpectrumMatrix/src/read.hpp" +}; + +} // multigroup namespace +} // NDItk namespace +} // njoy namespace + +#endif diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/ctor.hpp new file mode 100644 index 0000000..e3400d0 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/ctor.hpp @@ -0,0 +1,21 @@ +/** + * @brief Default constructor + */ +FissionNeutronSpectrumMatrix() : RealListRecord( base::Keyword( "chi_mat" ) ) {} + +/** + * @brief Default constructor + */ +FissionNeutronSpectrumMatrix( FissionType type ) : RealListRecord( base::Keyword( "chi_mat", type ) ) {} + +/** + * @brief Constructor + * + * @param[in] values the fission neutron spectrum matrix values + */ +FissionNeutronSpectrumMatrix( FissionType type, + std::vector< double > values ) : + RealListRecord( base::Keyword( "chi_mat", type ), std::move( values ) ) { + + verify( this->values() ); +} diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/read.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/read.hpp new file mode 100644 index 0000000..efd0a53 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/read.hpp @@ -0,0 +1,16 @@ +/** + * @brief Read the record data + * + * This function overrides the base record read() function to enable + * verification of the read data. + * + * @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 groups + */ +template< typename Iterator > +void read( Iterator& iter, const Iterator& end, std::size_t number ) { + + base::RealListRecord::read( iter, end, number * number ); + verify( this->values() ); +}; diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp new file mode 100644 index 0000000..2933b34 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp @@ -0,0 +1,18 @@ +/** + * @brief Verify the fission neutron spectrum vector values + * + * The following verification tests are performed: + * - there is at least one value + * + * @param[in] values the production values to be verified + */ +template < typename Range > +static void verify( const Range& values ) { + + if ( values.size() < 1 ) { + + Log::error( "Expected at least one fission neutron spectrum matrix value, found {}", + values.size() ); + throw std::exception(); + } +} diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector.hpp new file mode 100644 index 0000000..cc14c80 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector.hpp @@ -0,0 +1,59 @@ +#ifndef NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONSPECTRUMVECTOR +#define NJOY_NDITK_MULTIGROUP_FISSIONNEUTRONSPECTRUMVECTOR + +// system includes + +// other includes +#include "tools/Log.hpp" +#include "NDItk/base/RealListRecord.hpp" +#include "NDItk/multigroup/FissionType.hpp" + +namespace njoy { +namespace NDItk { +namespace multigroup { + +/** + * @brief A fission neutron spectrum vector record for multigroup neutron and photon data + */ +class FissionNeutronSpectrumVector : protected base::RealListRecord { + + /* fields */ + + /* auxiliary functions */ + + #include "NDItk/multigroup/FissionNeutronSpectrumVector/src/verify.hpp" + +public: + + /* constructor */ + + #include "NDItk/multigroup/FissionNeutronSpectrumVector/src/ctor.hpp" + + /* methods */ + + /** + * @brief Return the fission type defined by this record + */ + FissionType type() const { return this->key().fissionType().value(); } + + /** + * @brief Return the number of groups defined by this record + */ + unsigned int numberGroups() const { return this->size(); } + + using base::RealListRecord::keyword; + using base::RealListRecord::values; + using base::RealListRecord::size; + using base::RealListRecord::empty; + using base::RealListRecord::begin; + using base::RealListRecord::end; + using base::RealListRecord::print; + + #include "NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp" +}; + +} // multigroup namespace +} // NDItk namespace +} // njoy namespace + +#endif diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/ctor.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/ctor.hpp new file mode 100644 index 0000000..0cfb85c --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/ctor.hpp @@ -0,0 +1,21 @@ +/** + * @brief Default constructor + */ +FissionNeutronSpectrumVector() : RealListRecord( base::Keyword( "chi_vec" ) ) {} + +/** + * @brief Default constructor + */ +FissionNeutronSpectrumVector( FissionType type ) : RealListRecord( base::Keyword( "chi_vec", type ) ) {} + +/** + * @brief Constructor + * + * @param[in] values the fission neutron spectrum vector values + */ +FissionNeutronSpectrumVector( FissionType type, + std::vector< double > values ) : + RealListRecord( base::Keyword( "chi_vec", type ), std::move( values ) ) { + + verify( this->values() ); +} diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp new file mode 100644 index 0000000..eeefe1a --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/read.hpp @@ -0,0 +1,16 @@ +/** + * @brief Read the record data + * + * This function overrides the base record read() function to enable + * verification of the read data. + * + * @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 + */ +template< typename Iterator > +void read( Iterator& iter, const Iterator& end, std::size_t number ) { + + base::RealListRecord::read( iter, end, number ); + verify( this->values() ); +}; diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/verify.hpp new file mode 100644 index 0000000..f800808 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/src/verify.hpp @@ -0,0 +1,18 @@ +/** + * @brief Verify the fission neutron spectrum vector values + * + * The following verification tests are performed: + * - there is at least one value + * + * @param[in] values the fission neutron spectrum values to be verified + */ +template < typename Range > +static void verify( const Range& values ) { + + if ( values.size() < 1 ) { + + Log::error( "Expected at least one fission neutron spectrum vector value, found {}", + values.size() ); + throw std::exception(); + } +} From d27cb45c4a90a8b95b6fdc91fdec9234850441e2 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 5 Jun 2024 09:04:40 -0600 Subject: [PATCH 08/12] Adding C++ tests --- cmake/unit_testing.cmake | 2 + .../FissionNeutronSpectrumMatrix.hpp | 11 + .../src/verify.hpp | 7 + .../test/CMakeLists.txt | 1 + .../FissionNeutronSpectrumMatrix.test.cpp | 235 ++++++++++++++++++ .../test/CMakeLists.txt | 1 + .../FissionNeutronSpectrumVector.test.cpp | 129 ++++++++++ 7 files changed, 386 insertions(+) create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/CMakeLists.txt create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/FissionNeutronSpectrumMatrix.test.cpp create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector/test/CMakeLists.txt create mode 100644 src/NDItk/multigroup/FissionNeutronSpectrumVector/test/FissionNeutronSpectrumVector.test.cpp diff --git a/cmake/unit_testing.cmake b/cmake/unit_testing.cmake index 2f3ad9f..16c15ba 100644 --- a/cmake/unit_testing.cmake +++ b/cmake/unit_testing.cmake @@ -50,6 +50,8 @@ add_subdirectory( src/NDItk/multigroup/HeatingNumbers/test ) add_subdirectory( src/NDItk/multigroup/Kerma/test ) add_subdirectory( src/NDItk/multigroup/FissionNeutronMultiplicity/test ) add_subdirectory( src/NDItk/multigroup/FissionNeutronProduction/test ) +add_subdirectory( src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test ) +add_subdirectory( src/NDItk/multigroup/FissionNeutronSpectrumVector/test ) add_subdirectory( src/NDItk/multigroup/OutgoingParticleTypes/test ) add_subdirectory( src/NDItk/multigroup/OutgoingParticleTransportData/test ) add_subdirectory( src/NDItk/multigroup/LegendreMoment/test ) diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp index aecadb9..97f8e8b 100644 --- a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp @@ -5,6 +5,7 @@ // other includes #include "tools/Log.hpp" +#include "tools/std23/views.hpp" #include "NDItk/base/RealListRecord.hpp" #include "NDItk/multigroup/FissionType.hpp" @@ -41,6 +42,16 @@ class FissionNeutronSpectrumMatrix : protected base::RealListRecord { */ unsigned int numberGroups() const { return std::sqrt( this->size() ); } + /** + * @brief Return the matrix defined by this record + */ + auto matrix() const { + + using namespace njoy::tools; + return this->values() + | std23::views::chunk( this->numberGroups() ); + } + using base::RealListRecord::keyword; using base::RealListRecord::values; using base::RealListRecord::size; diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp index 2933b34..517ebe1 100644 --- a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/src/verify.hpp @@ -15,4 +15,11 @@ static void verify( const Range& values ) { values.size() ); throw std::exception(); } + unsigned int size = std::sqrt( values.size() ); + if ( values.size() != size * size ) { + + Log::error( "Expected an array of size {} but found {} whoich does not represent a matrix", + size * size, values.size() ); + throw std::exception(); + } } diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/CMakeLists.txt b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/CMakeLists.txt new file mode 100644 index 0000000..683e3ef --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/CMakeLists.txt @@ -0,0 +1 @@ +add_cpp_test( multigroup.FissionNeutronSpectrumMatrix FissionNeutronSpectrumMatrix.test.cpp ) \ No newline at end of file diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/FissionNeutronSpectrumMatrix.test.cpp b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/FissionNeutronSpectrumMatrix.test.cpp new file mode 100644 index 0000000..a425658 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumMatrix/test/FissionNeutronSpectrumMatrix.test.cpp @@ -0,0 +1,235 @@ +// include Catch2 +#include +#include +using Catch::Matchers::WithinRel; + +// what we are testing +#include "NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::NDItk; +using FissionNeutronSpectrumMatrix = multigroup::FissionNeutronSpectrumMatrix; +using FissionType = multigroup::FissionType; + +std::string chunk(); +void verifyChunk( const FissionNeutronSpectrumMatrix& ); +std::string chunkWithInsufficientNumberValues(); + +SCENARIO( "FissionNeutronSpectrumMatrix" ) { + + GIVEN( "valid data for a FissionNeutronSpectrumMatrix instance" ) { + + std::string record = chunk(); + + WHEN( "the data is given explicitly" ) { + + std::vector< double > 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 }; + + FissionNeutronSpectrumMatrix chunk( FissionType::Prompt, std::move( values ) ); + + THEN( "a FissionNeutronSpectrumMatrix can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + + WHEN( "the data is read using iterators" ) { + + auto iter = record.begin() + 10; + auto end = record.end(); + + FissionNeutronSpectrumMatrix chunk( FissionType::Prompt ); + chunk.read( iter, end, 7 ); + + THEN( "a FissionNeutronSpectrumMatrix can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data for a FissionNeutronSpectrumMatrix instance" ) { + + WHEN( "the number of weight values is insufficient" ) { + + THEN( "an exception is thrown" ) { + + std::vector< double > empty = {}; + + CHECK_THROWS( FissionNeutronSpectrumMatrix( FissionType::Prompt, std::move( empty ) ) ); + } // THEN + } // WHEN + + WHEN( "reading the data of the record and the number of " + "values is insufficient" ) { + + std::string record = chunkWithInsufficientNumberValues(); + auto iter = record.begin() + 10; + auto end = record.end(); + FissionNeutronSpectrumMatrix chunk( FissionType::Prompt ); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( chunk.read( iter, end, 0 ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return "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"; +} + +void verifyChunk( const FissionNeutronSpectrumMatrix& chunk ) { + + CHECK( "chi_mat_pr" == chunk.keyword() ); + CHECK_THAT( 1, WithinRel( chunk.values()[0] ) ); + CHECK_THAT( 2, WithinRel( chunk.values()[1] ) ); + CHECK_THAT( 3, WithinRel( chunk.values()[2] ) ); + CHECK_THAT( 4, WithinRel( chunk.values()[3] ) ); + CHECK_THAT( 5, WithinRel( chunk.values()[4] ) ); + CHECK_THAT( 6, WithinRel( chunk.values()[5] ) ); + CHECK_THAT( 7, WithinRel( chunk.values()[6] ) ); + CHECK_THAT( 1.1, WithinRel( chunk.values()[7] ) ); + CHECK_THAT( 2.1, WithinRel( chunk.values()[8] ) ); + CHECK_THAT( 3.1, WithinRel( chunk.values()[9] ) ); + CHECK_THAT( 4.1, WithinRel( chunk.values()[10] ) ); + CHECK_THAT( 5.1, WithinRel( chunk.values()[11] ) ); + CHECK_THAT( 6.1, WithinRel( chunk.values()[12] ) ); + CHECK_THAT( 7.1, WithinRel( chunk.values()[13] ) ); + CHECK_THAT( 1.2, WithinRel( chunk.values()[14] ) ); + CHECK_THAT( 2.2, WithinRel( chunk.values()[15] ) ); + CHECK_THAT( 3.2, WithinRel( chunk.values()[16] ) ); + CHECK_THAT( 4.2, WithinRel( chunk.values()[17] ) ); + CHECK_THAT( 5.2, WithinRel( chunk.values()[18] ) ); + CHECK_THAT( 6.2, WithinRel( chunk.values()[19] ) ); + CHECK_THAT( 7.2, WithinRel( chunk.values()[20] ) ); + CHECK_THAT( 1.3, WithinRel( chunk.values()[21] ) ); + CHECK_THAT( 2.3, WithinRel( chunk.values()[22] ) ); + CHECK_THAT( 3.3, WithinRel( chunk.values()[23] ) ); + CHECK_THAT( 4.3, WithinRel( chunk.values()[24] ) ); + CHECK_THAT( 5.3, WithinRel( chunk.values()[25] ) ); + CHECK_THAT( 6.3, WithinRel( chunk.values()[26] ) ); + CHECK_THAT( 7.3, WithinRel( chunk.values()[27] ) ); + CHECK_THAT( 1.4, WithinRel( chunk.values()[28] ) ); + CHECK_THAT( 2.4, WithinRel( chunk.values()[29] ) ); + CHECK_THAT( 3.4, WithinRel( chunk.values()[30] ) ); + CHECK_THAT( 4.4, WithinRel( chunk.values()[31] ) ); + CHECK_THAT( 5.4, WithinRel( chunk.values()[32] ) ); + CHECK_THAT( 6.4, WithinRel( chunk.values()[33] ) ); + CHECK_THAT( 7.4, WithinRel( chunk.values()[34] ) ); + CHECK_THAT( 1.5, WithinRel( chunk.values()[35] ) ); + CHECK_THAT( 2.5, WithinRel( chunk.values()[36] ) ); + CHECK_THAT( 3.5, WithinRel( chunk.values()[37] ) ); + CHECK_THAT( 4.5, WithinRel( chunk.values()[38] ) ); + CHECK_THAT( 5.5, WithinRel( chunk.values()[39] ) ); + CHECK_THAT( 6.5, WithinRel( chunk.values()[40] ) ); + CHECK_THAT( 7.5, WithinRel( chunk.values()[41] ) ); + CHECK_THAT( 1.6, WithinRel( chunk.values()[42] ) ); + CHECK_THAT( 2.6, WithinRel( chunk.values()[43] ) ); + CHECK_THAT( 3.6, WithinRel( chunk.values()[44] ) ); + CHECK_THAT( 4.6, WithinRel( chunk.values()[45] ) ); + CHECK_THAT( 5.6, WithinRel( chunk.values()[46] ) ); + CHECK_THAT( 6.6, WithinRel( chunk.values()[47] ) ); + CHECK_THAT( 7.6, WithinRel( chunk.values()[48] ) ); + + CHECK_THAT( 1, WithinRel( chunk.matrix()[0][0] ) ); + CHECK_THAT( 2, WithinRel( chunk.matrix()[0][1] ) ); + CHECK_THAT( 3, WithinRel( chunk.matrix()[0][2] ) ); + CHECK_THAT( 4, WithinRel( chunk.matrix()[0][3] ) ); + CHECK_THAT( 5, WithinRel( chunk.matrix()[0][4] ) ); + CHECK_THAT( 6, WithinRel( chunk.matrix()[0][5] ) ); + CHECK_THAT( 7, WithinRel( chunk.matrix()[0][6] ) ); + CHECK_THAT( 1.1, WithinRel( chunk.matrix()[1][0] ) ); + CHECK_THAT( 2.1, WithinRel( chunk.matrix()[1][1] ) ); + CHECK_THAT( 3.1, WithinRel( chunk.matrix()[1][2] ) ); + CHECK_THAT( 4.1, WithinRel( chunk.matrix()[1][3] ) ); + CHECK_THAT( 5.1, WithinRel( chunk.matrix()[1][4] ) ); + CHECK_THAT( 6.1, WithinRel( chunk.matrix()[1][5] ) ); + CHECK_THAT( 7.1, WithinRel( chunk.matrix()[1][6] ) ); + CHECK_THAT( 1.2, WithinRel( chunk.matrix()[2][0] ) ); + CHECK_THAT( 2.2, WithinRel( chunk.matrix()[2][1] ) ); + CHECK_THAT( 3.2, WithinRel( chunk.matrix()[2][2] ) ); + CHECK_THAT( 4.2, WithinRel( chunk.matrix()[2][3] ) ); + CHECK_THAT( 5.2, WithinRel( chunk.matrix()[2][4] ) ); + CHECK_THAT( 6.2, WithinRel( chunk.matrix()[2][5] ) ); + CHECK_THAT( 7.2, WithinRel( chunk.matrix()[2][6] ) ); + CHECK_THAT( 1.3, WithinRel( chunk.matrix()[3][0] ) ); + CHECK_THAT( 2.3, WithinRel( chunk.matrix()[3][1] ) ); + CHECK_THAT( 3.3, WithinRel( chunk.matrix()[3][2] ) ); + CHECK_THAT( 4.3, WithinRel( chunk.matrix()[3][3] ) ); + CHECK_THAT( 5.3, WithinRel( chunk.matrix()[3][4] ) ); + CHECK_THAT( 6.3, WithinRel( chunk.matrix()[3][5] ) ); + CHECK_THAT( 7.3, WithinRel( chunk.matrix()[3][6] ) ); + CHECK_THAT( 1.4, WithinRel( chunk.matrix()[4][0] ) ); + CHECK_THAT( 2.4, WithinRel( chunk.matrix()[4][1] ) ); + CHECK_THAT( 3.4, WithinRel( chunk.matrix()[4][2] ) ); + CHECK_THAT( 4.4, WithinRel( chunk.matrix()[4][3] ) ); + CHECK_THAT( 5.4, WithinRel( chunk.matrix()[4][4] ) ); + CHECK_THAT( 6.4, WithinRel( chunk.matrix()[4][5] ) ); + CHECK_THAT( 7.4, WithinRel( chunk.matrix()[4][6] ) ); + CHECK_THAT( 1.5, WithinRel( chunk.matrix()[5][0] ) ); + CHECK_THAT( 2.5, WithinRel( chunk.matrix()[5][1] ) ); + CHECK_THAT( 3.5, WithinRel( chunk.matrix()[5][2] ) ); + CHECK_THAT( 4.5, WithinRel( chunk.matrix()[5][3] ) ); + CHECK_THAT( 5.5, WithinRel( chunk.matrix()[5][4] ) ); + CHECK_THAT( 6.5, WithinRel( chunk.matrix()[5][5] ) ); + CHECK_THAT( 7.5, WithinRel( chunk.matrix()[5][6] ) ); + CHECK_THAT( 1.6, WithinRel( chunk.matrix()[6][0] ) ); + CHECK_THAT( 2.6, WithinRel( chunk.matrix()[6][1] ) ); + CHECK_THAT( 3.6, WithinRel( chunk.matrix()[6][2] ) ); + CHECK_THAT( 4.6, WithinRel( chunk.matrix()[6][3] ) ); + CHECK_THAT( 5.6, WithinRel( chunk.matrix()[6][4] ) ); + CHECK_THAT( 6.6, WithinRel( chunk.matrix()[6][5] ) ); + CHECK_THAT( 7.6, WithinRel( chunk.matrix()[6][6] ) ); + + CHECK( false == chunk.empty() ); + CHECK( 49 == chunk.size() ); + + CHECK( FissionType::Prompt == chunk.type() ); + CHECK( 7 == chunk.numberGroups() ); +} + +std::string chunkWithInsufficientNumberValues() { + + return "chi_mat_pr\n"; +} diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/CMakeLists.txt b/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/CMakeLists.txt new file mode 100644 index 0000000..21546f8 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/CMakeLists.txt @@ -0,0 +1 @@ +add_cpp_test( multigroup.FissionNeutronSpectrumVector FissionNeutronSpectrumVector.test.cpp ) \ No newline at end of file diff --git a/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/FissionNeutronSpectrumVector.test.cpp b/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/FissionNeutronSpectrumVector.test.cpp new file mode 100644 index 0000000..9d15ff7 --- /dev/null +++ b/src/NDItk/multigroup/FissionNeutronSpectrumVector/test/FissionNeutronSpectrumVector.test.cpp @@ -0,0 +1,129 @@ +// include Catch2 +#include +#include +using Catch::Matchers::WithinRel; + +// what we are testing +#include "NDItk/multigroup/FissionNeutronSpectrumVector.hpp" + +// other includes + +// convenience typedefs +using namespace njoy::NDItk; +using FissionNeutronSpectrumVector = multigroup::FissionNeutronSpectrumVector; +using FissionType = multigroup::FissionType; + +std::string chunk(); +void verifyChunk( const FissionNeutronSpectrumVector& ); +std::string chunkWithInsufficientNumberValues(); + +SCENARIO( "FissionNeutronSpectrumVector" ) { + + GIVEN( "valid data for a FissionNeutronSpectrumVector instance" ) { + + std::string record = chunk(); + + WHEN( "the data is given explicitly" ) { + + std::vector< double > values = { 1, 2, 3, 4, 5, 6, 7 }; + + FissionNeutronSpectrumVector chunk( FissionType::Prompt, std::move( values ) ); + + THEN( "a FissionNeutronSpectrumVector can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + + WHEN( "the data is read using iterators" ) { + + auto iter = record.begin() + 10; + auto end = record.end(); + + FissionNeutronSpectrumVector chunk( FissionType::Prompt ); + chunk.read( iter, end, 7 ); + + THEN( "a FissionNeutronSpectrumVector can be constructed and members can " + "be tested" ) { + + verifyChunk( chunk ); + } // THEN + + THEN( "the record can be printed" ) { + + std::string buffer; + auto output = std::back_inserter( buffer ); + chunk.print( output ); + + CHECK( buffer == record ); + } // THEN + } // WHEN + } // GIVEN + + GIVEN( "invalid data for a FissionNeutronSpectrumVector instance" ) { + + WHEN( "the number of weight values is insufficient" ) { + + THEN( "an exception is thrown" ) { + + std::vector< double > empty = {}; + + CHECK_THROWS( FissionNeutronSpectrumVector( FissionType::Prompt, std::move( empty ) ) ); + } // THEN + } // WHEN + + WHEN( "reading the data of the record and the number of " + "values is insufficient" ) { + + std::string record = chunkWithInsufficientNumberValues(); + auto iter = record.begin() + 10; + auto end = record.end(); + FissionNeutronSpectrumVector chunk( FissionType::Prompt ); + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( chunk.read( iter, end, 0 ) ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO + +std::string chunk() { + + return "chi_vec_pr\n" + " 1 2 3 4 5\n" + " 6 7\n"; +} + +void verifyChunk( const FissionNeutronSpectrumVector& chunk ) { + + CHECK( "chi_vec_pr" == chunk.keyword() ); + CHECK_THAT( 1, WithinRel( chunk.values()[0] ) ); + CHECK_THAT( 2, WithinRel( chunk.values()[1] ) ); + CHECK_THAT( 3, WithinRel( chunk.values()[2] ) ); + CHECK_THAT( 4, WithinRel( chunk.values()[3] ) ); + CHECK_THAT( 5, WithinRel( chunk.values()[4] ) ); + CHECK_THAT( 6, WithinRel( chunk.values()[5] ) ); + CHECK_THAT( 7, WithinRel( chunk.values()[6] ) ); + + CHECK( false == chunk.empty() ); + CHECK( 7 == chunk.size() ); + + CHECK( FissionType::Prompt == chunk.type() ); + CHECK( 7 == chunk.numberGroups() ); +} + +std::string chunkWithInsufficientNumberValues() { + + return "chi_vec_pr\n"; +} From e86c286cedd476c4b0a4572036234c1576188238 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 5 Jun 2024 09:27:12 -0600 Subject: [PATCH 09/12] Adding python tests --- CMakeLists.txt | 2 + cmake/unit_testing_python.cmake | 2 + ...getting-started-example-1-checkpoint.ipynb | 111 ++++++++++++ .../NDItk-getting-started-example-1.ipynb | 121 +++++++++++++ python/src/multigroup.python.cpp | 4 + .../FissionNeutronSpectrumMatrix.python.cpp | 80 +++++++++ .../FissionNeutronSpectrumVector.python.cpp | 73 ++++++++ ...multigroup_FissionNeutronSpectrumMatrix.py | 170 ++++++++++++++++++ ...multigroup_FissionNeutronSpectrumVector.py | 58 ++++++ .../FissionNeutronSpectrumVector/src/read.hpp | 2 +- 10 files changed, 622 insertions(+), 1 deletion(-) create mode 100644 python/examples/.ipynb_checkpoints/NDItk-getting-started-example-1-checkpoint.ipynb create mode 100644 python/examples/NDItk-getting-started-example-1.ipynb create mode 100644 python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp create mode 100644 python/src/multigroup/FissionNeutronSpectrumVector.python.cpp create mode 100644 python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumMatrix.py create mode 100644 python/test/multigroup/Test_NDItk_multigroup_FissionNeutronSpectrumVector.py 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 ) { From 3d16db74ea1e346309178c25c263147098f8faec Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 5 Jun 2024 10:01:21 -0600 Subject: [PATCH 10/12] More python --- python/src/MultigroupTable.python.cpp | 44 ++++++++++++++ src/NDItk/MultigroupTable.hpp | 79 ++++++++++++++++++++++++++ src/NDItk/MultigroupTable/src/read.hpp | 42 ++++++++++++++ 3 files changed, 165 insertions(+) diff --git a/python/src/MultigroupTable.python.cpp b/python/src/MultigroupTable.python.cpp index 6ed8480..020b0c0 100644 --- a/python/src/MultigroupTable.python.cpp +++ b/python/src/MultigroupTable.python.cpp @@ -21,6 +21,10 @@ void wrapMultigroupTable( python::module& module, python::module& ) { using TotalCrossSection = njoy::NDItk::multigroup::TotalCrossSection; using ReactionCrossSections = njoy::NDItk::multigroup::ReactionCrossSections; using AverageFissionEnergyRelease = njoy::NDItk::multigroup::AverageFissionEnergyRelease; + using FissionNeutronMultiplicity = njoy::NDItk::multigroup::FissionNeutronMultiplicity; + using FissionNeutronProduction = njoy::NDItk::multigroup::FissionNeutronProduction; + using FissionNeutronSpectrumMatrix = njoy::NDItk::multigroup::FissionNeutronSpectrumMatrix; + using FissionNeutronSpectrumVector = njoy::NDItk::multigroup::FissionNeutronSpectrumVector; using OutgoingParticleTypes = njoy::NDItk::multigroup::OutgoingParticleTypes; using OutgoingParticleTransportData = njoy::NDItk::multigroup::OutgoingParticleTransportData; using HeatingNumbers = njoy::NDItk::multigroup::HeatingNumbers; @@ -155,6 +159,46 @@ void wrapMultigroupTable( python::module& module, python::module& ) { &Table::averageFissionEnergyRelease, "The average fission energy release record" ) + .def( + + "fission_neutron_multiplicity", + &Table::fissionNeutronMultiplicity, + python::arg( "type" ), + "The fission neutron multiplicity record for the requested fission type" + "Arguments:\n" + " self the table\n" + " type the fission type" + ) + .def( + + "fission_neutron_production", + &Table::fissionNeutronProduction, + python::arg( "type" ), + "The fission neutron production record for the requested fission type" + "Arguments:\n" + " self the table\n" + " type the fission type" + ) + .def( + + "fission_neutron_spectrum_matrix", + &Table::fissionNeutronSpectrumMatrix, + python::arg( "type" ), + "The fission neutron spectrum matrix record for the requested fission type" + "Arguments:\n" + " self the table\n" + " type the fission type" + ) + .def( + + "fission_neutron_spectrum_vector", + &Table::fissionNeutronSpectrumVector, + python::arg( "type" ), + "The fission neutron spectrum vector record for the requested fission type" + "Arguments:\n" + " self the table\n" + " type the fission type" + ) .def_property_readonly( "primary_heating_numbers", diff --git a/src/NDItk/MultigroupTable.hpp b/src/NDItk/MultigroupTable.hpp index 6958b3c..cb04fb6 100644 --- a/src/NDItk/MultigroupTable.hpp +++ b/src/NDItk/MultigroupTable.hpp @@ -6,6 +6,7 @@ // other includes #include "tools/Log.hpp" #include "NDItk/depletion/ReactionMultiplicities.hpp" +#include "NDItk/multigroup/FissionType.hpp" #include "NDItk/multigroup/Metadata.hpp" #include "NDItk/multigroup/EnergyGroupStructure.hpp" #include "NDItk/multigroup/Velocities.hpp" @@ -44,6 +45,9 @@ class MultigroupTable { multigroup::FissionNeutronMultiplicity nubar_prompt_; multigroup::FissionNeutronMultiplicity nubar_delayed_; multigroup::FissionNeutronMultiplicity nubar_total_; + multigroup::FissionNeutronProduction production_prompt_; + multigroup::FissionNeutronProduction production_delayed_; + multigroup::FissionNeutronProduction production_total_; multigroup::FissionNeutronSpectrumVector chi_vector_prompt_; multigroup::FissionNeutronSpectrumVector chi_vector_delayed_; multigroup::FissionNeutronSpectrumVector chi_vector_total_; @@ -141,6 +145,78 @@ class MultigroupTable { return this->release_; } + /** + * @brief Return the fission neutron multiplicity record for the requested fission type + */ + const multigroup::FissionNeutronMultiplicity& + fissionNeutronMultiplicity( const multigroup::FissionType& type ) const { + + switch ( type ) { + + case multigroup::FissionType::Prompt : return this->nubar_prompt_; + case multigroup::FissionType::Delayed : return this->nubar_delayed_; + case multigroup::FissionType::Total : return this->nubar_total_; + default : { + + throw std::runtime_error( "This code is unreachable, contact a developer" ); + } + } + } + + /** + * @brief Return the fission neutron production record for the requested fission type + */ + const multigroup::FissionNeutronProduction& + fissionNeutronProduction( const multigroup::FissionType& type ) const { + + switch ( type ) { + + case multigroup::FissionType::Prompt : return this->production_prompt_; + case multigroup::FissionType::Delayed : return this->production_delayed_; + case multigroup::FissionType::Total : return this->production_total_; + default : { + + throw std::runtime_error( "This code is unreachable, contact a developer" ); + } + } + } + + /** + * @brief Return the fission neutron spectrum vector record for the requested fission type + */ + const multigroup::FissionNeutronSpectrumVector& + fissionNeutronSpectrumVector( const multigroup::FissionType& type ) const { + + switch ( type ) { + + case multigroup::FissionType::Prompt : return this->chi_vector_prompt_; + case multigroup::FissionType::Delayed : return this->chi_vector_delayed_; + case multigroup::FissionType::Total : return this->chi_vector_total_; + default : { + + throw std::runtime_error( "This code is unreachable, contact a developer" ); + } + } + } + + /** + * @brief Return the fission neutron spectrum matrix record for the requested fission type + */ + const multigroup::FissionNeutronSpectrumMatrix& + fissionNeutronSpectrumMatrix( const multigroup::FissionType& type ) const { + + switch ( type ) { + + case multigroup::FissionType::Prompt : return this->chi_matrix_prompt_; + case multigroup::FissionType::Delayed : return this->chi_matrix_delayed_; + case multigroup::FissionType::Total : return this->chi_matrix_total_; + default : { + + throw std::runtime_error( "This code is unreachable, contact a developer" ); + } + } + } + /** * @brief Return the primary heating numbers record */ @@ -294,6 +370,9 @@ class MultigroupTable { this->nubar_prompt_.print( iter ); this->nubar_delayed_.print( iter ); this->nubar_total_.print( iter ); + this->production_prompt_.print( iter ); + this->production_delayed_.print( iter ); + this->production_total_.print( iter ); this->chi_vector_prompt_.print( iter ); this->chi_vector_delayed_.print( iter ); this->chi_vector_total_.print( iter ); diff --git a/src/NDItk/MultigroupTable/src/read.hpp b/src/NDItk/MultigroupTable/src/read.hpp index d2ff7fe..5c9fa05 100644 --- a/src/NDItk/MultigroupTable/src/read.hpp +++ b/src/NDItk/MultigroupTable/src/read.hpp @@ -165,6 +165,48 @@ void read( Iterator& iter, const Iterator& end ) { throw std::exception(); } } + // prompt fission neutron production + else if ( keyword == this->production_prompt_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->production_prompt_, 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(); + } + } + // delayed fission neutron production + else if ( keyword == this->production_delayed_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->production_delayed_, 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(); + } + } + // total fission neutron production + else if ( keyword == this->production_total_.keyword() ) { + + if ( this->metadata_.numberGroups().has_value() ) { + + readRecord( this->production_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(); + } + } // prompt fission neutron spectrum vector else if ( keyword == this->chi_vector_prompt_.keyword() ) { From 7ac27e4a7e49de619c62b7afa837f73de986bd14 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 5 Jun 2024 12:19:04 -0600 Subject: [PATCH 11/12] Adding clang format file --- .clang-format | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1c3e885 --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +--- +BasedOnStyle: LLVM +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + BeforeElse: true +ColumnLimit: 100 +EmptyLineAfterAccessModifier: Always +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +InsertBraces: true +PointerAlignment: Left +SpacesInAngles: Always +SpacesInParens: Custom +SpacesInParensOptions: + InConditionalStatements: true + Other: true + From bf7b3b57abc7a9667360086572d2514e439cdfaa Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Tue, 20 Aug 2024 10:36:56 -0600 Subject: [PATCH 12/12] Updating CI to remove failures --- .github/workflows/ContinuousIntegration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index f6e61dc..30a61e7 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -16,8 +16,8 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ ubuntu-20.04, macos-11 ] - cxx: [ clang++, g++-10 ] + os: [ ubuntu-22.04, macos-12 ] + cxx: [ clang++, g++-12 ] build_type: [ Debug, Release ] steps: