-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from all commits
b877d76
942d614
1efdb7a
f5ab73e
2f74d15
19bf9a7
b2939c1
681ca66
6022b61
7dfe495
62c0ae4
e40a8e1
7b279eb
829dd2d
acfcc95
3f22146
ca8d37f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class GendfDataRecord : protected ListRecord { | ||
|
||
protected: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_ ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_ ); | ||
} | ||
|
||
}; |
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 ) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
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 ) |
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 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really just a wrapped |
||
|
||
// 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"; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
template<> | ||
class GendfType< 3 > : protected GendfBase { | ||
|
||
protected: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
}; |
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." ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
|
||
} |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh. I hate getters (or setters) that start like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like Python where I don't need I usually am with you. This one was because I was thinking of |
||
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 ); | ||
} |
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 ) |
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" ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because that's what it is: a chunk of ENDF data :-p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my Python bindings, I've been using |
||
|
||
// 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"; | ||
|
||
} |
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; | ||
|
||
}; |
There was a problem hiding this comment.
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 ofGendfDataRecord
. I'm not sure it warrants changing everything, though.There was a problem hiding this comment.
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
butGendfType
.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.