Skip to content

Commit 4432b3c

Browse files
committed
Merge branch 'feature/gnds-covariances' into 'develop'
Feature/gnds covariances See merge request njoy/dryad!150
2 parents 7e86582 + 45a5335 commit 4432b3c

17 files changed

+1917
-426
lines changed

cmake/unit_testing.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ add_cpp_test( dryad.ThermalScattering
126126

127127
add_cpp_test( dryad.format.createIndex dryad/format/createIndex.test.cpp )
128128
add_cpp_test( dryad.format.createVector dryad/format/createVector.test.cpp )
129+
add_cpp_test( dryad.format.adjustScatterLevel dryad/format/adjustScatterLevel.test.cpp )
129130

130131
add_cpp_test( dryad.format.ace.createProjectileIdentifier dryad/format/ace/createProjectileIdentifier.test.cpp )
131132
add_cpp_test( dryad.format.ace.createTabulatedScatteringFunction dryad/format/ace/createTabulatedScatteringFunction.test.cpp )
@@ -302,6 +303,7 @@ add_cpp_test( dryad.format.gnds.atomic.createElectronSubshellConfiguration
302303
add_cpp_test( dryad.format.gnds.covariance.createScalingType dryad/format/gnds/covariance/createScalingType.test.cpp )
303304
add_cpp_test( dryad.format.gnds.covariance.createVarianceScaling dryad/format/gnds/covariance/createVarianceScaling.test.cpp )
304305
add_cpp_test( dryad.format.gnds.covariance.createCrossSectionCovarianceMatrix dryad/format/gnds/covariance/createCrossSectionCovarianceMatrix.test.cpp )
306+
add_cpp_test( dryad.format.gnds.covariance.createCovarianceData dryad/format/gnds/covariance/createCovarianceData.test.cpp )
305307
add_cpp_test( dryad.format.gnds.createProjectileTarget dryad/format/gnds/createProjectileTarget.test.cpp )
306308
add_cpp_test( dryad.format.gnds.createProjectileTargetFromFile dryad/format/gnds/createProjectileTargetFromFile.test.cpp )
307309
add_cpp_test( dryad.format.gnds.createAtomicRelaxation dryad/format/gnds/createAtomicRelaxation.test.cpp )
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef NJOY_DRYAD_FORMAT_ADJUSTSCATTERLEVEL
2+
#define NJOY_DRYAD_FORMAT_ADJUSTSCATTERLEVEL
3+
4+
// system includes
5+
6+
// other includes
7+
#include "njoy/dryad/id/ParticleID.hpp"
8+
#include "njoy/dryad/id/ReactionID.hpp"
9+
10+
namespace njoy {
11+
namespace dryad {
12+
namespace format {
13+
14+
/**
15+
* @brief Adjust the scatter level mt number for excited states
16+
*
17+
* @param[in] projectile the projectile identifier
18+
* @param[in] target the target identifier
19+
* @param[in] mt the mt number to adjust
20+
*/
21+
inline int adjustScatterLevel( const id::ParticleID& projectile,
22+
const id::ParticleID& target,
23+
int mt ) {
24+
25+
if ( target.e() > 0 && projectile != id::ParticleID::photon() ) {
26+
27+
int ground = id::ReactionID( projectile, target.groundState(), 2 ).reactionType().mt().value();
28+
int elastic = id::ReactionID( projectile, target, 2 ).reactionType().mt().value();
29+
if ( mt > ground && mt <= elastic ) {
30+
31+
return mt - 1;
32+
}
33+
}
34+
return mt;
35+
};
36+
37+
} // format namespace
38+
} // dryad namespace
39+
} // njoy namespace
40+
41+
#endif

src/njoy/dryad/format/endf/ReactionInformation.hpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// other includes
99
#include "njoy/dryad/id/ReactionID.hpp"
10+
#include "njoy/dryad/format/adjustScatterLevel.hpp"
1011
#include "ENDFtk/Material.hpp"
1112
#include "ENDFtk/tree/Material.hpp"
1213

@@ -303,28 +304,14 @@ namespace endf {
303304

304305
std::vector< id::ReactionID > partials;
305306

306-
auto adjust_scatter_level = [&projectile, &target] ( int mt ) {
307-
308-
if ( target.e() > 0 && projectile != id::ParticleID::photon() ) {
309-
310-
int ground = id::ReactionID( projectile, target.groundState(), 2 ).reactionType().mt().value();
311-
int elastic = id::ReactionID( projectile, target, 2 ).reactionType().mt().value();
312-
if ( mt > ground && mt <= elastic ) {
313-
314-
return mt - 1;
315-
}
316-
}
317-
return mt;
318-
};
319-
320307
if ( mf == 3 && mt == 1 ) {
321308

322309
auto sections = material.file( mf ).sectionNumbers();
323310
for ( auto number : sections ) {
324311

325312
if ( isPrimary( material, number ) ) {
326313

327-
partials.emplace_back( projectile, target, adjust_scatter_level( number ) );
314+
partials.emplace_back( projectile, target, adjustScatterLevel( projectile, target, number ) );
328315
}
329316
}
330317
}
@@ -337,7 +324,7 @@ namespace endf {
337324

338325
if ( isPrimary( material, number ) ) {
339326

340-
partials.emplace_back( projectile, target, adjust_scatter_level( number ) );
327+
partials.emplace_back( projectile, target, adjustScatterLevel( projectile, target, number ) );
341328
}
342329
}
343330
}
@@ -349,7 +336,7 @@ namespace endf {
349336

350337
if ( section.lumpedCovarianceIndex() == mt ) {
351338

352-
partials.emplace_back( projectile, target, adjust_scatter_level( section.MT() ) );
339+
partials.emplace_back( projectile, target, adjustScatterLevel( projectile, target, section.MT() ) );
353340
}
354341
}
355342
std::sort( partials.begin(), partials.end() );
@@ -361,7 +348,7 @@ namespace endf {
361348

362349
if ( material.hasSection( mf, number ) ) {
363350

364-
partials.emplace_back( projectile, target, adjust_scatter_level( number ) );
351+
partials.emplace_back( projectile, target, adjustScatterLevel( projectile, target, number ) );
365352
}
366353
}
367354

src/njoy/dryad/format/endf/covariance/createCrossSectionCovarianceData.hpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,13 @@ namespace covariance {
3939

4040
Log::info( "Reading cross section covariance data" );
4141

42-
auto adjust_scatter_level = [&projectile, &target] ( int mt ) {
43-
44-
if ( target.e() > 0 && projectile != id::ParticleID::photon() ) {
45-
46-
int ground = id::ReactionID( projectile, target.groundState(), 2 ).reactionType().mt().value();
47-
int elastic = id::ReactionID( projectile, target, 2 ).reactionType().mt().value();
48-
if ( mt > ground && mt <= elastic ) {
49-
50-
return mt - 1;
51-
}
52-
}
53-
return mt;
54-
};
55-
5642
std::vector< dryad::covariance::CrossSectionCovarianceMatrix > matrices;
5743
matrices.reserve( material.file( 33 ).sectionNumbers().size() );
5844
for ( auto mt : material.file( 33 ).sectionNumbers() ) {
5945

6046
if ( ! endf::ReactionInformation::isDerived( mt ) ) {
6147

62-
id::ReactionID row( projectile, target, adjust_scatter_level( mt ) );
48+
id::ReactionID row( projectile, target, adjustScatterLevel( projectile, target, mt ) );
6349

6450
auto section = material.section( 33, mt ).parse< 33 >();
6551
for ( const auto& block : section.reactions() ) {
@@ -71,7 +57,7 @@ namespace covariance {
7157

7258
if ( mat1 == 0 || mat1 == mat ) {
7359

74-
id::ReactionID column = id::ReactionID( projectile, target, adjust_scatter_level( mt1 ) );
60+
id::ReactionID column = id::ReactionID( projectile, target, adjustScatterLevel( projectile, target, mt1 ) );
7561
if ( row == column ) {
7662

7763
Log::info( "Reading data for MT{}", mt );

src/njoy/dryad/format/endf/covariance/createCrossSectionCovarianceMatrix.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace covariance {
8282
throw std::exception();
8383
}
8484

85-
// read the scalong information
85+
// read the scaling information
8686
scaling = createVarianceScaling( std::get< ENDFtk::section::CovariancePairs >( component ) );
8787
break;
8888
}

src/njoy/dryad/format/endf/createReaction.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// other includes
99
#include "tools/Log.hpp"
10+
#include "njoy/dryad/format/adjustScatterLevel.hpp"
1011
#include "njoy/dryad/format/endf/ReactionInformation.hpp"
1112
#include "njoy/dryad/format/endf/createTabulatedCrossSection.hpp"
1213
#include "njoy/dryad/format/endf/createMultiplicity.hpp"
@@ -56,22 +57,8 @@ namespace endf {
5657
int mt,
5758
bool normalise ) {
5859

59-
auto adjust_scatter_level = [&projectile, &target] ( int mt ) {
60-
61-
if ( target.e() > 0 && projectile != id::ParticleID::photon() ) {
62-
63-
int ground = id::ReactionID( projectile, target.groundState(), 2 ).reactionType().mt().value();
64-
int elastic = id::ReactionID( projectile, target, 2 ).reactionType().mt().value();
65-
if ( mt > ground && mt <= elastic ) {
66-
67-
return mt - 1;
68-
}
69-
}
70-
return mt;
71-
};
72-
7360
// metadata and miscellaneous information
74-
id::ReactionID id( projectile, target, adjust_scatter_level( mt ) );
61+
id::ReactionID id( projectile, target, adjustScatterLevel( projectile, target, mt ) );
7562

7663
if ( material.hasSection( 3, mt ) ) {
7764

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECOVARIANCEDATA
2+
#define NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECOVARIANCEDATA
3+
4+
// system includes
5+
6+
// other includes
7+
#include "pugixml.hpp"
8+
#include "tools/Log.hpp"
9+
#include "njoy/dryad/id/ParticleID.hpp"
10+
#include "njoy/dryad/id/ReactionID.hpp"
11+
#include "njoy/dryad/covariance/CovarianceData.hpp"
12+
#include "njoy/dryad/format/endf/ReactionInformation.hpp"
13+
#include "njoy/dryad/format/gnds/covariance/createCrossSectionCovarianceMatrix.hpp"
14+
15+
namespace njoy {
16+
namespace dryad {
17+
namespace format {
18+
namespace gnds {
19+
namespace covariance {
20+
21+
/**
22+
* @brief Create covariance data from GNDS covariance sections
23+
*
24+
* @param[in] projectile the projectile identifier
25+
* @param[in] target the target identifier
26+
* @param[in] covariances the GNDS covariance sections node
27+
*/
28+
inline dryad::covariance::CovarianceData
29+
createCovarianceData(
30+
const dryad::id::ParticleID& projectile,
31+
const dryad::id::ParticleID& target,
32+
const pugi::xml_node& covariances ) {
33+
34+
// check that this is a valid covariance sections node
35+
throwExceptionOnWrongNode( covariances, "covarianceSections" );
36+
37+
std::vector< dryad::covariance::CrossSectionCovarianceMatrix > xs_covariances;
38+
39+
for ( pugi::xml_node matrix = covariances.child( "covarianceSection" ); matrix;
40+
matrix = matrix.next_sibling( "covarianceSection" ) ) {
41+
42+
auto row = matrix.child( "rowData" );
43+
auto sum = matrix.child( "sum" );
44+
45+
std::string string = row.attribute( "ENDF_MFMT" ).as_string();
46+
auto iter = std::find( string.begin(), string.end(), ',' );
47+
std::size_t index = std::distance( string.begin(), iter );
48+
49+
auto type = std::stoi( string.substr( 0, index ) );
50+
auto reaction = std::stoi( string.substr( index + 1 ) );
51+
52+
if ( ! endf::ReactionInformation::isDerived( reaction ) ) {
53+
54+
if ( type == 33 ) {
55+
56+
if ( ! sum ) {
57+
58+
auto entries = createCrossSectionCovarianceMatrix( projectile, target, matrix );
59+
std::move( entries.begin(), entries.end(), std::back_inserter( xs_covariances ) );
60+
}
61+
else {
62+
63+
Log::warning( "No explicit covariance components are defined for MT{}, skipping for now", reaction );
64+
}
65+
}
66+
else {
67+
68+
Log::warning( "Covariance matrices for MF{} are not implemented yet, skipping for now", type );
69+
}
70+
}
71+
else {
72+
73+
Log::warning( "Skipping data for derived MT{}", reaction );
74+
}
75+
}
76+
77+
std::optional< dryad::covariance::CrossSectionCovarianceData > xs = std::nullopt;
78+
if ( xs_covariances.size() > 0 ) {
79+
80+
xs = dryad::covariance::CrossSectionCovarianceData( std::move( xs_covariances ) );
81+
}
82+
83+
return dryad::covariance::CovarianceData( std::move( xs ) );
84+
}
85+
86+
} // covariance namespace
87+
} // gnds namespace
88+
} // format namespace
89+
} // dryad namespace
90+
} // njoy namespace
91+
92+
#endif

src/njoy/dryad/format/gnds/covariance/createCrossSectionCovarianceMatrix.hpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
#ifndef NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECrossSectionCovarianceMatrix
2-
#define NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECrossSectionCovarianceMatrix
1+
#ifndef NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECROSSSECTIONCOVARIANCEMATRIX
2+
#define NJOY_DRYAD_FORMAT_GNDS_COVARIANCE_CREATECROSSSECTIONCOVARIANCEMATRIX
33

44
// system includes
55

66
// other includes
7+
#include "pugixml.hpp"
78
#include "tools/Log.hpp"
89
#include "njoy/dryad/id/ParticleID.hpp"
910
#include "njoy/dryad/id/ReactionID.hpp"
1011
#include "njoy/dryad/covariance/CrossSectionCovarianceMatrix.hpp"
12+
#include "njoy/dryad/format/adjustScatterLevel.hpp"
1113
#include "njoy/dryad/format/gnds/readCovarianceMatrix.hpp"
1214
#include "njoy/dryad/format/gnds/covariance/createVarianceScaling.hpp"
1315

@@ -19,8 +21,13 @@ namespace covariance {
1921

2022
/**
2123
* @brief Create a cross section covariance block from a GNDS covariance section
24+
*
25+
* @param[in] projectile the projectile identifier
26+
* @param[in] target the target identifier
27+
* @param[in] covariances the GNDS covariance section node giving a
28+
* cross section covariance matrix
2229
*/
23-
inline dryad::covariance::CrossSectionCovarianceMatrix
30+
inline std::vector< dryad::covariance::CrossSectionCovarianceMatrix >
2431
createCrossSectionCovarianceMatrix(
2532
const dryad::id::ParticleID& projectile,
2633
const dryad::id::ParticleID& target,
@@ -41,7 +48,8 @@ namespace covariance {
4148
std::string reaction = row.attribute( "ENDF_MFMT" ).as_string();
4249
reaction.erase( reaction.begin(),
4350
std::find( reaction.begin(), reaction.end(), ',' ) + 1 );
44-
rowReaction = id::ReactionID( projectile, target, id::ReactionType( projectile, std::stoi( reaction ) ) );
51+
auto mt = adjustScatterLevel( projectile, target, std::stoi( reaction ) );
52+
rowReaction = id::ReactionID( projectile, target, id::ReactionType( projectile, mt ) );
4553
}
4654
else {
4755

@@ -107,31 +115,28 @@ namespace covariance {
107115
}
108116
}
109117

110-
if ( rowStructures.size() == 1 ) {
118+
std::vector< dryad::covariance::CrossSectionCovarianceMatrix > covariances;
119+
for ( std::size_t i = 0; i < rowStructures.size(); i++ ) {
111120

112121
if ( cross ) {
113122

114-
return dryad::covariance::CrossSectionCovarianceMatrix(
115-
dryad::covariance::CrossSectionMetadata( { rowReaction },
116-
std::move( rowStructures.front() ) ),
117-
dryad::covariance::CrossSectionMetadata( { columnReaction },
118-
std::move( columnStructures.front() ) ),
119-
std::move( matrices.front() ), relative );
123+
using CrossSectionMetadata = dryad::covariance::CrossSectionMetadata;
124+
covariances.emplace_back(
125+
CrossSectionMetadata( { rowReaction }, std::move( rowStructures[i] ) ),
126+
CrossSectionMetadata( { columnReaction }, std::move( columnStructures[i] ) ),
127+
std::move( matrices[i] ), relative );
120128
}
121129
else {
122130

123-
return dryad::covariance::CrossSectionCovarianceMatrix(
124-
dryad::covariance::CrossSectionMetadata( { rowReaction },
125-
std::move( rowStructures.front() ) ),
126-
std::move( matrices.front() ),
127-
relative, std::move( scaling ) );
131+
using CrossSectionMetadata = dryad::covariance::CrossSectionMetadata;
132+
covariances.emplace_back(
133+
CrossSectionMetadata( { rowReaction }, std::move( rowStructures[i] ) ),
134+
std::move( matrices[i] ),
135+
relative, scaling );
128136
}
129137
}
130-
else {
131138

132-
Log::error( "Not implemented yet, contact a developer" );
133-
throw std::exception();
134-
}
139+
return covariances;
135140
}
136141

137142
} // covariance namespace

src/njoy/dryad/format/gnds/covariance/createScalingType.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66

77
// other includes
8+
#include "pugixml.hpp"
89
#include "tools/Log.hpp"
910
#include "njoy/dryad/covariance/ScalingType.hpp"
1011

0 commit comments

Comments
 (0)