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

Adding GENDF Capabilities to ENDFtk #73

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ target_sources( ENDFtk INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/File/src/parse.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Section/src/ctor.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Section/src/findEnd.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Section/src/parse.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Section/src/parse-endf.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Tape/src/createMap.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Tape/src/materialNumber.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ENDFtk/syntaxTree/Tape/src/ctor.hpp"
Expand Down Expand Up @@ -926,10 +926,15 @@ if( NOT is_subproject )
add_subdirectory( src/ENDFtk/section/8/457/DiscreteSpectrum/test )
add_subdirectory( src/ENDFtk/section/Base/test )
add_subdirectory( src/ENDFtk/section/BaseWithoutMT/test )
add_subdirectory( src/ENDFtk/section/GendfBase/test )
add_subdirectory( src/ENDFtk/section/Gendf3/test )
add_subdirectory( src/ENDFtk/section/Gendf6/test )
add_subdirectory( src/ENDFtk/syntaxTree/File/test )
add_subdirectory( src/ENDFtk/syntaxTree/Material/test )
add_subdirectory( src/ENDFtk/syntaxTree/GendfMaterial/test )
add_subdirectory( src/ENDFtk/syntaxTree/Section/test )
add_subdirectory( src/ENDFtk/syntaxTree/Tape/test )
add_subdirectory( src/ENDFtk/GendfDataRecord/test )
endif()
endif()

Expand All @@ -949,4 +954,4 @@ install( DIRECTORY src// DESTINATION include
FILES_MATCHING REGEX ".*\.h[+][+]$|.*\.hxx$|.*\.hpp$|.*\.hh$|.*\.h$" )

INCLUDE(CPack)


2 changes: 2 additions & 0 deletions src/ENDFtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ using TAB1 = TabulationRecord;

#include "ENDFtk/InterpolationSequenceRecord.hpp"

#include "ENDFtk/GendfDataRecord.hpp"

#include "ENDFtk/resonanceParameters.hpp"

#include "ENDFtk/section.hpp"
Expand Down
46 changes: 46 additions & 0 deletions src/ENDFtk/GendfDataRecord.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class GendfDataRecord : protected ListRecord {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer GENDFDataRecord instead of GendfDataRecord. I'm not sure it warrants changing everything, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've debated acronyms in CamelCase for my entire coding career and have never definitively decided which is better. Note that I didn't even stay consistent, as I used GENDFTag but GendfType.

It's pretty trivial to slap a /Gendf/GENDF/ sed command onto these files, so if you feel more settled in this everlasting debate I have with myself.


protected:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to make these members protected.


int num_legendre_;
int num_sigma0_;
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename these and provide public methods to retrieve them. As for renaming, sigma0 is a bit obscure so it my be more appropriate to use dilutions instead. There's also no need to use abbreviations in these names (number instead of num).


public:

/* constructor */
#include "ENDFtk/GendfDataRecord/src/ctor.hpp"

/* getters */
double temperature() const { return this->C1(); };
int NG2() const { return this->L1(); }
int numSecondaryPositions() const { return NG2(); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this->NG2()

int IG2LO() const { return this->L2(); }
int lowestGroup() const { return IG2LO(); };
int IG() const { return this->N2(); }
int group() const { return IG(); }

/*
* @brief Return the flux values.
* @note All GENDF data records (aside from MFD 1&5) include a
* matrix of the flux computed by NJOY for the group,
* given in an NLxNZ matrix. This results in a large degree
* of redundancy.
*/
auto flux() const {
return this->list()
| ranges::view::take_exactly( num_legendre_ * num_sigma0_ );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where you would use those public methods.

}

/*
* @brief Return the non-flux values.
* @note Included in the values is one of:
* - vector cross sections (NLxNZ)
* - ratio and cross sections (both NLxNZ)
* - matrix elements (NLxNZxNG)
Comment on lines +37 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this comment, I assume that there are essentially three types of records, which could all have their own interface? I would surmise that the matrix element one is only used in MFD6 data. Where are the other ones used?

*/
auto values() const {
return this->list()
| ranges::view::drop_exactly( num_legendre_ * num_sigma0_ );
}

};
12 changes: 12 additions & 0 deletions src/ENDFtk/GendfDataRecord/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
template< typename Iterator >
GendfDataRecord( Iterator& it,
const Iterator& end,
long& lineNumber,
int num_legendre,
int num_sigma0,
int MAT,
int MF,
int MT )
: ListRecord( it, end, lineNumber, MAT, MF, MT ),
num_legendre_( num_legendre ),
num_sigma0_( num_sigma0 ) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need a constructor to create this from scratch, especially if we want to create GENDF files. It's better to add it now instead of waiting.

14 changes: 14 additions & 0 deletions src/ENDFtk/GendfDataRecord/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

add_executable( ENDFtk.GendfDataRecord.test GendfDataRecord.test.cpp )
target_compile_options( ENDFtk.GendfDataRecord.test PRIVATE ${${PREFIX}_common_flags}
$<$<BOOL:${strict}>:${${PREFIX}_strict_flags}>$<$<CONFIG:DEBUG>:
${${PREFIX}_DEBUG_flags}
$<$<BOOL:${coverage}>:${${PREFIX}_coverage_flags}>>
$<$<CONFIG:RELEASE>:
${${PREFIX}_RELEASE_flags}
$<$<BOOL:${link_time_optimization}>:${${PREFIX}_link_time_optimization_flags}>
$<$<BOOL:${nonportable_optimization}>:${${PREFIX}_nonportable_optimization_flags}>>

${CXX_appended_flags} ${ENDFtk_appended_flags} )
target_link_libraries( ENDFtk.GendfDataRecord.test PUBLIC ENDFtk )
add_test( NAME ENDFtk.GendfDataRecord COMMAND ENDFtk.GendfDataRecord.test )
46 changes: 46 additions & 0 deletions src/ENDFtk/GendfDataRecord/test/GendfDataRecord.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "ENDFtk.hpp"

using namespace njoy::ENDFtk;


std::string getMFD3Record();


SCENARIO( "reading a GendfDataRecord" ) {
GIVEN( "a string representation" ) {
WHEN( "a valid record is given" ) {

std::string buffer = getMFD3Record();

auto begin = buffer.begin();
auto end = buffer.end();
long int lineNo = 2;

THEN( "the object can be created" ) {
GendfDataRecord record( begin, end, lineNo, 1, 1, 9228, 3, 2 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any kind of data that someone might try to use that would be invalid? We should try and capture that and throw some kind of exception (std::exception is fine). We should also test for that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really just a wrapped ListRecord. I think most of the error handling is covered there.


// check data
CHECK( record.temperature() == Approx(293.6) );
CHECK( record.NG2() == 2 );
CHECK( record.numSecondaryPositions() == 2 );
CHECK( record.IG2LO() == 1 );
CHECK( record.lowestGroup() == 1 );
CHECK( record.IG() == 1 );
CHECK( record.group() == 1);
CHECK( record.flux()[0] == Approx(8.86484e+4) );
CHECK( record.values()[0] == Approx(14.69141) );
}
}
}
}


std::string getMFD3Record() {
return
" 2.936000+2 0.000000+0 2 1 2 19228 3 2 2\n"
" 8.864840+4 1.469141+1 9228 3 2 3\n";
}

9 changes: 9 additions & 0 deletions src/ENDFtk/section.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ class Type;
#include "ENDFtk/section/8.hpp"
#include "ENDFtk/section/12.hpp"
#include "ENDFtk/section/13.hpp"

#include "ENDFtk/section/GendfBase.hpp"

template< int MF, int... OptionalMT >
class GendfType;

#include "ENDFtk/section/Gendf3.hpp"
#include "ENDFtk/section/Gendf6.hpp"

}
Empty file modified src/ENDFtk/section/3.hpp
100755 → 100644
Empty file.
Empty file modified src/ENDFtk/section/Base.hpp
100755 → 100644
Empty file.
29 changes: 29 additions & 0 deletions src/ENDFtk/section/Gendf3.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
template<>
class GendfType< 3 > : protected GendfBase {

protected:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be here with the way the class is currently configured.



public:

/* constructor */
#include "ENDFtk/section/Gendf3/src/ctor.hpp"

/* methods */
#include "ENDFtk/section/Gendf3/src/getCrossSection.hpp"

/* getters inherited from GendfBase */
using GendfBase::legendreOrder;
using GendfBase::numLegendre;
using GendfBase::numSigma0;
using GendfBase::breakupFlag;
using GendfBase::numGroups;
using GendfBase::temperature;

/* getters inherited from Base */
using GendfBase::MT;
using GendfBase::ZA;
using GendfBase::AWR;
using GendfBase::atomicWeightRatio;

};
15 changes: 15 additions & 0 deletions src/ENDFtk/section/Gendf3/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
template< typename BufferIterator >
GendfType( HeadRecord& head,
BufferIterator& begin,
const BufferIterator& end,
long& lineNumber,
int MAT )
: GendfBase( head, begin, end, lineNumber, MAT ) {

// TODO: Add support for ratio quantities
if( data_.at(num_groups_).NG2() == 3 ) {
Log::info( "ENDFtk does not yet support ratio quantities." );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to throw an exception, Log an error. You can provide informational logs afterwards as needed.

The practice we have developed is we log an error when it is initially thrown. If we catch (and possibly re-throw) an exception, then we log an informational message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is done consistently throughout, but I'm happy to change mine. What you are suggesting makes more sense to me, I was just trying to stick to the convention I saw in similar places, which likely was non-conforming.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we've done it up to now is that an error is logged when the original exception is created, logging information later on to indicate where it happened, etc. by catching the exception.

throw std::exception();
}

}
44 changes: 44 additions & 0 deletions src/ENDFtk/section/Gendf3/src/getCrossSection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @brief Return cross section value.
* @param group GENDF group index (1-based, low group = low energy)
* @param order Legendre order
* @param idil Index of dilution (0-based)
*/
double getCrossSection( int group,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. I hate getters (or setters) that start like get... (or set...). The get is unnecessary. You can tell the difference between a getter and a setter based on the function arguments. Granted, this is a matter of opinion (mine, in fact), but it is what we have adopted for NJOY. See Section 6 of our Style Guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like Python where I don't need () on my getters and setters 😄

I usually am with you. This one was because I was thinking of getCrossSectionByGroup versus getCrossSection returning the whole array. I'm pretty sure I wrote those routines into OpenMOC years ago, so they came back to me. I didn't even stick with that naming convention, so I won't argue in favor for get here!

int order,
int idil ) {

// error checking
if( order > legendreOrder() ) {
Log::info( "{} is greater than Legendre order of dataset ({})",
order, legendreOrder() );
throw std::exception();
}
else if( idil >= num_sigma0_ ) {
Log::info( "Index {} exceeds number of dilutions in dataset ({})",
idil, num_sigma0_ );
throw std::exception();
}
else if( group <= 0 or group > num_groups_ ) {
Log::info( "Group {} is invalid with {} groups",
group, num_groups_ );
throw std::exception();
}

// group not in dataset
if( data_.count( group ) == 0 )
return 0.0;

// select dilution and legendre order from dataset
auto data = data_.at(group).values();
return data[numLegendre()*idil + order];

}

/*
* @brief Return cross section value. Assume l=0, idil=0.
* @param group GENDF group index (1-based, low group = low energy)
*/
double getCrossSection( int group ) {
return getCrossSection( group, 0, 0 );
}
14 changes: 14 additions & 0 deletions src/ENDFtk/section/Gendf3/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

add_executable( ENDFtk.section.Gendf3.test Gendf3.test.cpp )
target_compile_options( ENDFtk.section.Gendf3.test PRIVATE ${${PREFIX}_common_flags}
$<$<BOOL:${strict}>:${${PREFIX}_strict_flags}>$<$<CONFIG:DEBUG>:
${${PREFIX}_DEBUG_flags}
$<$<BOOL:${coverage}>:${${PREFIX}_coverage_flags}>>
$<$<CONFIG:RELEASE>:
${${PREFIX}_RELEASE_flags}
$<$<BOOL:${link_time_optimization}>:${${PREFIX}_link_time_optimization_flags}>
$<$<BOOL:${nonportable_optimization}>:${${PREFIX}_nonportable_optimization_flags}>>

${CXX_appended_flags} ${ENDFtk_appended_flags} )
target_link_libraries( ENDFtk.section.Gendf3.test PUBLIC ENDFtk )
add_test( NAME ENDFtk.section.Gendf3 COMMAND ENDFtk.section.Gendf3.test )
84 changes: 84 additions & 0 deletions src/ENDFtk/section/Gendf3/test/Gendf3.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "ENDFtk.hpp"

using namespace njoy::ENDFtk;


std::string getSection();


SCENARIO( "creating a GendfBase object" ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not creating a GendfBase object here. You are creating a GendfType<3>. Yeah, I'm being pedantic. I don't really care what is said here, but we should try to be accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy and paste can be cruel. I'll fix it.

GIVEN( "a string representation of a GendfSection" ) {
WHEN( "a valid section is given" ) {

std::string buffer = getSection();

auto begin = buffer.begin();
auto end = buffer.end();
long lineNo = 0;
int MAT = 9237;
HeadRecord head(begin, end, lineNo);

THEN( "the object can be created" ) {
section::GendfType<3> chunk(head, begin, end, lineNo, MAT );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chunk? I see you've taken after @whaeck in your naming convention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had section, but felt dirty using section as both a namespace and a variable at the same time. And when I looked to other tests for guidance, voila -- I found @whaeck's approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's what it is: a chunk of ENDF data :-p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my Python bindings, I've been using parsec for parsed sections. I'm sure our friends in astrophysics would approve of that.


// head record parameter getters
CHECK( chunk.legendreOrder() == 1 );
CHECK( chunk.numLegendre() == 2 );
CHECK( chunk.numSigma0() == 2 );
CHECK( chunk.breakupFlag() == 0 );
CHECK( chunk.numGroups() == 10 );

// check temperature
CHECK( chunk.temperature() == Approx(293.6) );

// check data
CHECK( chunk.getCrossSection(1) == 0.0 );
CHECK( chunk.getCrossSection(10) == Approx(10.46994) );
CHECK( chunk.getCrossSection(2, 1, 0) == Approx(15.18365) );
CHECK( chunk.getCrossSection(2, 0, 1) == Approx(15.17064) );
CHECK_THROWS( chunk.getCrossSection(1, 3, 0) );
CHECK_THROWS( chunk.getCrossSection(1, 0, 3) );
CHECK_THROWS( chunk.getCrossSection(0) );

}
}
}
}


std::string getSection() {
return
" 9.223800+4 0.000000+0 2 2 0 109237 3 1 1\n"
" 2.936000+2 0.000000+0 2 1 8 29237 3 1 5\n"
" 4.076628+5 4.076628+5 2.707485+5 1.798684+5 1.518365+1 1.518365+19237 3 1 6\n"
" 1.517064+1 1.515778+1 9237 3 1 7\n"
" 2.936000+2 0.000000+0 2 1 8 39237 3 1 8\n"
" 3.325475+5 3.325475+5 2.276034+5 1.557802+5 1.383334+1 1.383334+19237 3 1 9\n"
" 1.383249+1 1.383164+1 9237 3 1 10\n"
" 2.936000+2 0.000000+0 2 1 8 49237 3 1 11\n"
" 2.704187+6 2.704187+6 1.908900+6 1.347643+6 1.250311+1 1.250311+19237 3 1 12\n"
" 1.249862+1 1.249418+1 9237 3 1 13\n"
" 2.936000+2 0.000000+0 2 1 8 59237 3 1 14\n"
" 9.182484+5 9.182484+5 6.589042+5 4.728086+5 1.180808+1 1.180808+19237 3 1 15\n"
" 1.180798+1 1.180788+1 9237 3 1 16\n"
" 2.936000+2 0.000000+0 2 1 8 69237 3 1 17\n"
" 1.831983+6 1.831983+6 1.323545+6 9.562210+5 1.152468+1 1.152468+19237 3 1 18\n"
" 1.152446+1 1.152423+1 9237 3 1 19\n"
" 2.936000+2 0.000000+0 2 1 8 79237 3 1 20\n"
" 1.611270+6 1.611270+6 1.171801+6 8.521988+5 1.125120+1 1.125120+19237 3 1 21\n"
" 1.125110+1 1.125099+1 9237 3 1 22\n"
" 2.936000+2 0.000000+0 2 1 8 89237 3 1 23\n"
" 2.150370+6 2.150370+6 1.573657+6 1.151619+6 1.099457+1 1.099457+19237 3 1 24\n"
" 1.099439+1 1.099421+1 9237 3 1 25\n"
" 2.936000+2 0.000000+0 2 1 8 99237 3 1 26\n"
" 1.677811+6 1.677811+6 1.236346+6 9.110428+5 1.071231+1 1.071231+19237 3 1 27\n"
" 1.071217+1 1.071202+1 9237 3 1 28\n"
" 2.936000+2 0.000000+0 2 1 8 109237 3 1 29\n"
" 9.702869+5 9.702869+5 7.192670+5 5.331894+5 1.046994+1 1.046994+19237 3 1 30\n"
" 1.046982+1 1.046969+1 9237 3 1 31\n"
" 9237 3 099999\n";

}
29 changes: 29 additions & 0 deletions src/ENDFtk/section/Gendf6.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
template<>
class GendfType< 6 > : protected GendfBase {

protected:


public:

/* constructor */
#include "ENDFtk/section/Gendf6/src/ctor.hpp"

/* methods */
#include "ENDFtk/section/Gendf6/src/getMatrixElement.hpp"

/* getters inherited from GendfBase */
using GendfBase::legendreOrder;
using GendfBase::numLegendre;
using GendfBase::numSigma0;
using GendfBase::breakupFlag;
using GendfBase::numGroups;
using GendfBase::temperature;

/* getters inherited from Base */
using GendfBase::MT;
using GendfBase::ZA;
using GendfBase::AWR;
using GendfBase::atomicWeightRatio;

};
Loading