Skip to content

Commit a1ef551

Browse files
committed
Merge branch 'feature/gnds-covariances-part2' into 'develop'
Feature/gnds covariances part2 See merge request njoy/dryad!152
2 parents 4432b3c + 4d6ba65 commit a1ef551

17 files changed

+90
-20
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ namespace gnds {
1919
namespace covariance {
2020

2121
/**
22-
* @brief Create covariance data from GNDS covariance sections
22+
* @brief Create covariance data from GNDS covariance suite
2323
*
2424
* @param[in] projectile the projectile identifier
2525
* @param[in] target the target identifier
26-
* @param[in] covariances the GNDS covariance sections node
26+
* @param[in] covariances the GNDS covariance suite node
2727
*/
2828
inline dryad::covariance::CovarianceData
2929
createCovarianceData(
@@ -32,11 +32,14 @@ namespace covariance {
3232
const pugi::xml_node& covariances ) {
3333

3434
// check that this is a valid covariance sections node
35-
throwExceptionOnWrongNode( covariances, "covarianceSections" );
35+
throwExceptionOnWrongNode( covariances, "covarianceSuite" );
36+
37+
//! @todo verify that the projectile and target are the ones defined in the covariance suite?
3638

3739
std::vector< dryad::covariance::CrossSectionCovarianceMatrix > xs_covariances;
3840

39-
for ( pugi::xml_node matrix = covariances.child( "covarianceSection" ); matrix;
41+
auto node = covariances.child( "covarianceSections" );
42+
for ( pugi::xml_node matrix = node.child( "covarianceSection" ); matrix;
4043
matrix = matrix.next_sibling( "covarianceSection" ) ) {
4144

4245
auto row = matrix.child( "rowData" );

src/njoy/dryad/format/gnds/createProjectileTarget.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// other includes
88
#include "pugixml.hpp"
99
#include "tools/Log.hpp"
10+
#include "njoy/dryad/format/gnds/processExternalFiles.hpp"
1011
#include "njoy/dryad/format/gnds/throwExceptionOnWrongNode.hpp"
1112
#include "njoy/dryad/format/gnds/createParticleIdentifier.hpp"
1213
#include "njoy/dryad/format/gnds/createInteractionType.hpp"
1314
#include "njoy/dryad/format/gnds/createReactions.hpp"
15+
#include "njoy/dryad/format/gnds/covariance/createCovarianceData.hpp"
1416
#include "njoy/dryad/ProjectileTarget.hpp"
1517

1618
namespace njoy {
@@ -27,11 +29,14 @@ namespace gnds {
2729
* @param[in] style the gnds style to process (default is eval)
2830
*/
2931
inline ProjectileTarget
30-
createProjectileTarget( const pugi::xml_document& document,
32+
createProjectileTarget( pugi::xml_document& document,
3133
bool normalise,
3234
const std::string& style = "eval" ) {
3335

36+
processExternalFiles( document );
37+
3438
auto suite = document.child( "reactionSuite" );
39+
auto covsuite = document.child( "covarianceSuite" );
3540

3641
if ( suite ) {
3742

@@ -44,6 +49,10 @@ namespace gnds {
4449
std::vector< Reaction > reactions = createReactions( projectile, target, suite, normalise, style );
4550

4651
std::optional< dryad::covariance::CovarianceData > covariances = std::nullopt;
52+
if ( covsuite ) {
53+
54+
covariances = covariance::createCovarianceData( projectile, target, covsuite );
55+
}
4756

4857
return ProjectileTarget( std::move( projectile ), std::move( target ),
4958
type, std::move( reactions ), std::move( resonances ),
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef NJOY_DRYAD_FORMAT_GNDS_PROCESSEXTERNALFILES
2+
#define NJOY_DRYAD_FORMAT_GNDS_PROCESSEXTERNALFILES
3+
4+
// system includes
5+
6+
// other includes
7+
#include "pugixml.hpp"
8+
#include "tools/Log.hpp"
9+
#include <iostream>
10+
namespace njoy {
11+
namespace dryad {
12+
namespace format {
13+
namespace gnds {
14+
15+
/**
16+
* @brief Add the content of external files to the current document
17+
*
18+
* @param[in] document the gnds xml document
19+
*/
20+
inline void processExternalFiles( pugi::xml_document& document ) {
21+
22+
auto files = document.first_child().child( "externalFiles" );
23+
24+
for ( pugi::xml_node file = files.child( "externalFile" ); file;
25+
file = file.next_sibling( "externalFile" ) ) {
26+
27+
std::string filename = file.attribute( "path" ).as_string();
28+
29+
pugi::xml_document external;
30+
pugi::xml_parse_result result = external.load_file( filename.c_str() );
31+
if ( external ) {
32+
33+
for ( pugi::xml_node node : external.children() ) {
34+
35+
document.append_copy( node );
36+
}
37+
}
38+
else {
39+
40+
Log::error( "The GNDS file \'{}\' does not exist or is not an XML file",
41+
filename );
42+
throw std::exception();
43+
}
44+
}
45+
}
46+
47+
} // gnds namespace
48+
} // format namespace
49+
} // dryad namespace
50+
} // njoy namespace
51+
52+
#endif

test/dryad/format/gnds/covariance/createCovarianceData.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SCENARIO( "createCovarianceData" ) {
2222

2323
pugi::xml_document document;
2424
pugi::xml_parse_result result = document.load_file( "n-001_H_001.endf.gnds-covar.xml" );
25-
pugi::xml_node node = document.child( "covarianceSuite" ).child( "covarianceSections" );
25+
pugi::xml_node node = document.child( "covarianceSuite" );
2626

2727
WHEN( "a single covarianceSections node is given" ) {
2828

@@ -43,7 +43,7 @@ SCENARIO( "createCovarianceData" ) {
4343

4444
pugi::xml_document document;
4545
pugi::xml_parse_result result = document.load_file( "n-003_Li_007.endf.gnds-covar.xml" );
46-
pugi::xml_node node = document.child( "covarianceSuite" ).child( "covarianceSections" );
46+
pugi::xml_node node = document.child( "covarianceSuite" );
4747

4848
WHEN( "a single covarianceSections node is given" ) {
4949

test/dryad/format/gnds/test.neutron.h1.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ namespace h1 {
418418

419419
CHECK( std::nullopt == H1.resonances() );
420420

421-
CHECK( std::nullopt == H1.covarianceData() );
421+
CHECK( std::nullopt != H1.covarianceData() );
422+
423+
CHECK( std::nullopt != H1.covarianceData()->crossSection() );
424+
verifyCrossSectionCovariances( H1.covarianceData()->crossSection().value() );
422425
}
423426

424427
} // namespace h1

test/dryad/format/gnds/test.neutron.li7.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,10 @@ namespace li7 {
18011801

18021802
CHECK( std::nullopt == Li7.resonances() );
18031803

1804-
CHECK( std::nullopt == Li7.covarianceData() );
1804+
CHECK( std::nullopt != Li7.covarianceData() );
1805+
1806+
decltype(auto) xs = Li7.covarianceData()->crossSection().value();
1807+
verifyCrossSectionCovariances( Li7.covarianceData()->crossSection().value() );
18051808
}
18061809

18071810
} // namespace h1

test/resources/n-001_H_001.endf.gnds.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<reactionSuite projectile="n" target="H1" evaluation="ENDF/B-8.1" format="2.0" projectileFrame="lab" interaction="nuclear">
33
<externalFiles>
4-
<externalFile label="covariances" path="Covariances/n-001_H_001.endf.gnds-covar.xml" checksum="868db865a07d6c5499a36a830d14982de18ed2c5" algorithm="sha1"/></externalFiles>
4+
<externalFile label="covariances" path="n-001_H_001.endf.gnds-covar.xml" checksum="868db865a07d6c5499a36a830d14982de18ed2c5" algorithm="sha1"/></externalFiles>
55
<styles>
66
<evaluated label="eval" date="2016-07-01" library="ENDF/B" version="8.1.5">
77
<documentation>

test/resources/n-003_Li_007.endf.gnds.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<reactionSuite projectile="n" target="Li7" evaluation="ENDF/B-8.1" format="2.0" projectileFrame="lab" interaction="nuclear">
33
<externalFiles>
4-
<externalFile label="covariances" path="Covariances/n-003_Li_007.endf.gnds-covar.xml" checksum="b986b4b32941b7abb41b77debed3b1e67963e1c0" algorithm="sha1"/></externalFiles>
4+
<externalFile label="covariances" path="n-003_Li_007.endf.gnds-covar.xml" checksum="b986b4b32941b7abb41b77debed3b1e67963e1c0" algorithm="sha1"/></externalFiles>
55
<styles>
66
<evaluated label="eval" date="1988-08-01" library="ENDF/B" version="8.1.0">
77
<documentation>

test/resources/n-009_F_019.endf.gnds.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<reactionSuite projectile="n" target="F19" evaluation="ENDF/B-8.1" format="2.0" projectileFrame="lab" interaction="nuclear">
33
<externalFiles>
4-
<externalFile label="covariances" path="Covariances/n-009_F_019.endf.gnds-covar.xml" checksum="79ea4a269b15720ed4fb070ca499b75cd371dd11" algorithm="sha1"/></externalFiles>
4+
<externalFile label="covariances" path="n-009_F_019.endf.gnds-covar.xml" checksum="79ea4a269b15720ed4fb070ca499b75cd371dd11" algorithm="sha1"/></externalFiles>
55
<styles>
66
<evaluated label="eval" date="2022-12-01" library="ENDF/B" version="8.1.1">
77
<documentation>

test/resources/n-010_Ne_022.endf.gnds.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<reactionSuite projectile="n" target="Ne22" evaluation="ENDF/B-8.1" format="2.0" projectileFrame="lab" interaction="nuclear">
33
<externalFiles>
4-
<externalFile label="covariances" path="Covariances/n-010_Ne_022.endf.gnds-covar.xml" checksum="58f4eb4be80623aec3d35098b20b8a168578a970" algorithm="sha1"/></externalFiles>
4+
<externalFile label="covariances" path="n-010_Ne_022.endf.gnds-covar.xml" checksum="58f4eb4be80623aec3d35098b20b8a168578a970" algorithm="sha1"/></externalFiles>
55
<styles>
66
<evaluated label="eval" date="2015-12-01" library="ENDF/B" version="8.1.1">
77
<documentation>

0 commit comments

Comments
 (0)