Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multigroup part8 #12

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory( src/NDItk/base/SingleStringRecord/test )
add_subdirectory( src/NDItk/base/IntegerListRecord/test )
add_subdirectory( src/NDItk/base/RealListRecord/test )
add_subdirectory( src/NDItk/base/StringListRecord/test )
add_subdirectory( src/NDItk/base/InformationRecord/test )

add_subdirectory( src/NDItk/multigroup/Metadata/test )
add_subdirectory( src/NDItk/multigroup/EnergyGroupStructure/test )
Expand Down
3 changes: 3 additions & 0 deletions python/src/MultigroupTable.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
ReactionCrossSections,
ScatteringMatrix,
std::optional< std::string >,
std::optional< std::string >,
std::optional< double >,
std::optional< TotalCrossSection >,
std::optional< AverageFissionEnergyRelease >,
Expand All @@ -66,6 +67,7 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
python::arg( "structure" ), python::arg( "outgoing" ),
python::arg( "velocities" ), python::arg( "flux" ),
python::arg( "xs" ), python::arg( "scattering" ),
python::arg( "information" ) = std::nullopt,
python::arg( "source" ) = std::nullopt,
python::arg( "weight" ) = std::nullopt,
python::arg( "total" ) = std::nullopt,
Expand Down Expand Up @@ -93,6 +95,7 @@ void wrapMultigroupTable( python::module& module, python::module& ) {
" flux the flux weights\n"
" xs the reaction cross section data\n"
" scattering the scattering matrix\n"
" information the table information line (optional)\n"
" source the source date (optional)\n"
" weight the atomic weight of the target (optional)\n"
" total the total cross section (optional)\n"
Expand Down
15 changes: 14 additions & 1 deletion python/src/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <pybind11/stl.h>
#include "tools/views/views-python.hpp"
#include "NDItk/fromFile.hpp"
#include "NDItk/toFile.hpp"

namespace python = pybind11;

Expand Down Expand Up @@ -142,8 +143,20 @@ void addStandardTableDefinitions( PythonClass& table ) {
"table\n\n"
"Arguments:\n"
" filename the file name and path"
)
.def(

"to_file",
[] ( const Table& self, const std::string& filename ) {

return njoy::NDItk::toFile( self, filename );
},
"Read an ACE table from a file\n\n"
"An exception is raised if something goes wrong while reading the\n"
"table\n\n"
"Arguments:\n"
" filename the file name and path"
);
}

#endif

9 changes: 9 additions & 0 deletions python/src/multigroup/Metadata.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ void wrapMetadata( python::module& module, python::module& ) {
unsigned int, std::map< unsigned int, unsigned int >,
unsigned int, unsigned int,
std::optional< std::string >,
std::optional< std::string >,
std::optional< double >,
std::optional< int >,
std::optional< int > >(),
python::arg( "zaid" ), python::arg( "libname" ),
python::arg( "process" ), python::arg( "awr" ),
python::arg( "temperature" ), python::arg( "dilution" ), python::arg( "groups" ),
python::arg( "outgoing" ), python::arg( "reactions" ), python::arg( "legendre" ),
python::arg( "information" ) = std::nullopt,
python::arg( "source" ) = std::nullopt,
python::arg( "weight" ) = std::nullopt,
python::arg( "upscatter" ) = std::nullopt,
Expand All @@ -62,6 +64,7 @@ void wrapMetadata( python::module& module, python::module& ) {
" outgoing the number of groups in the outgoing group structures\n"
" reactions the number of reactions defined in the table\n"
" legendre the number of Legendre moments in the table\n"
" information the table information line (optional)\n"
" source the source date (optional)\n"
" weight the atomic weight of the target (optional)\n"
" upscatter the number of upscatter groups (optional)\n"
Expand All @@ -73,6 +76,12 @@ void wrapMetadata( python::module& module, python::module& ) {
&Record::zaid,
"The zaid of the table"
)
.def_property_readonly(

"information",
&Record::information,
"The table information line"
)
.def_property_readonly(

"library_name",
Expand Down
11 changes: 10 additions & 1 deletion python/test/Test_NDItk_MultigroupTable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# standard imports
import unittest
import os

# third party imports

Expand Down Expand Up @@ -29,6 +30,7 @@ def verify_chunk( self, chunk ) :
# verify content - metadata
metadata = chunk.metadata
self.assertEqual( '92235.711nm', metadata.zaid )
self.assertEqual( 'this is some information for the table', metadata.information )
self.assertEqual( 'mendf71x', metadata.library_name )
self.assertEqual( '12/22/2011', metadata.source_date )
self.assertEqual( '08/07/2013', metadata.process_date )
Expand Down Expand Up @@ -429,7 +431,8 @@ def verify_chunk( self, chunk ) :
self.assertAlmostEqual( 150, kerma.values[1] )

# the data is given explicitly
chunk = MultigroupTable( zaid = '92235.711nm', libname = 'mendf71x', source = '12/22/2011',
chunk = MultigroupTable( zaid = '92235.711nm', libname = 'mendf71x',
information = 'this is some information for the table', source = '12/22/2011',
process = '08/07/2013', awr = 233.0248, weight = 235.043937521619,
temperature = 2.53e-8, dilution = 1e+10,
structure = EnergyGroupStructure( [ 20., 18.123456789, 16.0000000000001, 14., 10., 5, 1, 1e-11 ] ),
Expand Down Expand Up @@ -501,6 +504,12 @@ def verify_chunk( self, chunk ) :

verify_chunk( self, chunk )

# the data is read from a file
chunk.to_file( 'test.txt' )
chunk = MultigroupTable.from_file( 'test.txt' )
verify_chunk( self, chunk )
os.remove( 'test.txt' )

if __name__ == '__main__' :

unittest.main()
4 changes: 3 additions & 1 deletion src/NDItk/MultigroupTable/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ MultigroupTable() :
* @param[in] total the total cross section
* @param[in] xs the reaction cross section data
* @param[in] scattering the scattering matrix
* @param[in] information the table information line (optional)
* @param[in] source the source date (optional)
* @param[in] weight the atomic weight of the target (optional)
* @param[in] release the average fission energy release data (optional)
Expand All @@ -45,6 +46,7 @@ MultigroupTable( std::string zaid, std::string libname,
multigroup::FluxWeights weigths,
multigroup::ReactionCrossSections xs,
multigroup::ScatteringMatrix scattering,
std::optional< std::string > information = std::nullopt,
std::optional< std::string > source = std::nullopt,
std::optional< double > weight = std::nullopt,
std::optional< multigroup::TotalCrossSection > total = std::nullopt,
Expand All @@ -60,7 +62,7 @@ MultigroupTable( std::string zaid, std::string libname,
std::move( process ), awr, temperature, dilution,
structure.numberGroups(), generateOutgoingStructureMetadata( outgoing ),
xs.numberReactions(), scattering.numberLegendreMoments(),
std::move( source ), std::move( weight ),
std::move( information ), std::move( source ), std::move( weight ),
std::nullopt, std::nullopt ),
primary_structure_( std::move( structure ) ),
velocities_( std::move( velocities ) ),
Expand Down
9 changes: 7 additions & 2 deletions src/NDItk/MultigroupTable/test/MultigroupTable.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SCENARIO( "MultigroupTable" ) {
WHEN( "the data is given explicitly" ) {

std::string zaid = "92235.711nm";
std::string information = "this is some information for the table";
std::string name = "mendf71x";
std::string source = "12/22/2011";
std::string process = "08/07/2013";
Expand Down Expand Up @@ -107,7 +108,7 @@ SCENARIO( "MultigroupTable" ) {
std::move( structure ), std::move( outgoing ),
std::move( velocities ), std::move( weights ),
std::move( xs ), std::move( scattering ),
std::move( source ), weight,
std::move( information ), std::move( source ), weight,
std::move( total ), std::move( release ),
std::move( types ), std::move( transport ),
std::move( production ),
Expand Down Expand Up @@ -174,6 +175,7 @@ SCENARIO( "MultigroupTable" ) {
WHEN( "the number of groups is inconsistent" ) {

std::string zaid = "92235.711nm";
std::string information = "this is some information for the table";
std::string name = "mendf71x";
std::string source = "12/22/2011";
std::string process = "08/07/2013";
Expand Down Expand Up @@ -254,7 +256,7 @@ SCENARIO( "MultigroupTable" ) {
std::move( structure ), {}, std::move( velocities ),
std::move( weights ), std::move( xs ),
std::move( scattering ),
std::move( source ), weight,
std::move( information ), std::move( source ), weight,
std::move( total ), std::move( release ),
std::move( types ), std::move( transport ),
std::move( production ),
Expand All @@ -269,6 +271,8 @@ std::string chunk() {

return "zaid\n"
" 92235.711nm\n"
"info\n"
" this is some information for the table\n"
"library_name\n"
" mendf71x\n"
"date_source\n"
Expand Down Expand Up @@ -391,6 +395,7 @@ void verifyChunk( const MultigroupTable& chunk ) {

// metadata
CHECK( "92235.711nm" == chunk.metadata().zaid() );
CHECK( "this is some information for the table" == chunk.metadata().information() );
CHECK( "mendf71x" == chunk.metadata().libraryName() );
CHECK( "12/22/2011" == chunk.metadata().sourceDate() );
CHECK( "08/07/2013" == chunk.metadata().processDate() );
Expand Down
115 changes: 115 additions & 0 deletions src/NDItk/base/InformationRecord.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#ifndef NJOY_NDITK_BASE_INFORMATIONRECORD
#define NJOY_NDITK_BASE_INFORMATIONRECORD

// system includes
#include <string>
#include <sstream>
#include <iomanip>

// other includes
#include "NDItk/base/SingleValueRecord.hpp"

namespace njoy {
namespace NDItk {
namespace base {

/**
* @brief An NDI record with a line of information
*/
class InformationRecord : protected SingleValueRecord< InformationRecord, std::string > {

friend class SingleValueRecord< InformationRecord, std::string >;
using Parent = SingleValueRecord< InformationRecord, std::string >;

protected:

/**
* @brief Write the record data
*
* This assumes that the record is not empty.
*
* @param[in] iter the current position in the output
*/
template< typename OutputIterator >
void write( OutputIterator& iter ) const {

unsigned int indent = 4;
while ( indent-- ) { *iter++ = ' '; }
for ( auto c : this->data().value() ) { *iter++ = c; }
*iter++ = '\n';
};

using Parent::key;

public:

/* constructor */

/**
* @brief Constructor
*
* @param[in] keyword the keyword of the record
*/
InformationRecord() :
SingleValueRecord( Keyword( "info" ) ) {}

/**
* @brief Constructor
*
* @param[in] keyword the keyword of the record
* @param[in] value the value of the record
*/
InformationRecord( std::string value ) :
SingleValueRecord( Keyword( "info" ), value ) {}

/* methods */

using Parent::keyword;
using Parent::data;
using Parent::empty;
using Parent::print;

/**
* @brief Read the record data
*
* @param[in] iter the current position in the input
*/
template< typename Iterator >
void read( Iterator& iter, const Iterator& end ) {

// move over the first endline
while ( ( iter != end ) && std::isspace( *iter ) && ( *iter != '\n' ) ) {

++iter;
}
if ( *iter != '\n' ) {

Log::error( "The table information line should start on a new line" );
throw std::exception();
}
++iter;
// move over initial white space
while ( ( iter != end ) && std::isspace( *iter ) && ( *iter != '\n' ) ) {

++iter;
}
auto pos = std::find_if( iter, end, [] ( auto&& character )
{ return character == '\n'; } );
if ( pos == iter ) {

Log::error( "There appears to be no table information line" );
throw std::exception();
}
this->data() = std::string( iter, pos );
if ( pos != end ) {

iter = pos + 1;
}
};
};

} // base namespace
} // NDItk namespace
} // njoy namespace

#endif
1 change: 1 addition & 0 deletions src/NDItk/base/InformationRecord/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( base.InformationRecord InformationRecord.test.cpp )
Loading