Skip to content

Commit 12c2600

Browse files
committed
Merge branch 'feature/endf-covariances-part3' into 'develop'
Feature/endf covariances part3 See merge request njoy/dryad!147
2 parents 641fcde + 9aef314 commit 12c2600

File tree

7 files changed

+897
-0
lines changed

7 files changed

+897
-0
lines changed

cmake/unit_testing.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ add_cpp_test( dryad.format.endf.atomic.createElectronSubshellConfiguration
202202
add_cpp_test( dryad.format.endf.covariance.createMatrix dryad/format/endf/covariance/createMatrix.test.cpp )
203203
add_cpp_test( dryad.format.endf.covariance.createVarianceScaling dryad/format/endf/covariance/createVarianceScaling.test.cpp )
204204
add_cpp_test( dryad.format.endf.covariance.createCrossSectionCovarianceMatrix dryad/format/endf/covariance/createCrossSectionCovarianceMatrix.test.cpp )
205+
add_cpp_test( dryad.format.endf.covariance.createCrossSectionCovarianceData dryad/format/endf/covariance/createCrossSectionCovarianceData.test.cpp )
206+
add_cpp_test( dryad.format.endf.covariance.createCovarianceData dryad/format/endf/covariance/createCovarianceData.test.cpp )
205207
add_cpp_test( dryad.format.endf.createTabulatedCrossSection dryad/format/endf/createTabulatedCrossSection.test.cpp )
206208
add_cpp_test( dryad.format.endf.createPolynomialMultiplicity dryad/format/endf/createPolynomialMultiplicity.test.cpp )
207209
add_cpp_test( dryad.format.endf.createTabulatedMultiplicity dryad/format/endf/createTabulatedMultiplicity.test.cpp )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "tools/Log.hpp"
1010
#include "njoy/dryad/covariance/CrossSectionCovarianceData.hpp"
1111
#include "njoy/dryad/format/endf/covariance/createCrossSectionCovarianceMatrix.hpp"
12+
#include "njoy/dryad/format/endf/ReactionInformation.hpp"
1213
#include "ENDFtk/Material.hpp"
1314
#include "ENDFtk/tree/Material.hpp"
1415

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// include Catch2
2+
#include <catch2/catch_test_macros.hpp>
3+
#include <catch2/matchers/catch_matchers_floating_point.hpp>
4+
using Catch::Matchers::WithinRel;
5+
using Catch::Matchers::WithinAbs;
6+
7+
// what we are testing
8+
#include "njoy/dryad/format/endf/covariance/createCovarianceData.hpp"
9+
10+
// other includes
11+
#include "ENDFtk/tree/fromFile.hpp"
12+
13+
// convenience typedefs
14+
using namespace njoy::dryad;
15+
using namespace njoy::ENDFtk;
16+
17+
// include common test verification functions
18+
#include "../test_verification_functions.hpp"
19+
20+
SCENARIO( "createCovarianceData" ) {
21+
22+
GIVEN( "ENDF materials - incident neutrons - single submatrices and "
23+
"linear combinations" ) {
24+
25+
WHEN( "a single ENDF material is given" ) {
26+
27+
using Tape = njoy::ENDFtk::tree::Tape;
28+
auto tape = njoy::ENDFtk::tree::fromFile< Tape >( "n-001_H_001.endf" );
29+
auto material = tape.materials().front();
30+
31+
THEN( "all covariances can be created" ) {
32+
33+
id::ParticleID projectile( "n" );
34+
id::ParticleID target( "H1" );
35+
std::optional< covariance::CovarianceData > covariances =
36+
format::endf::covariance::createCovarianceData( projectile, target, material );
37+
38+
neutron::h1::verifyCrossSectionCovariances( covariances.value().crossSection().value() );
39+
} // THEN
40+
} // WHEN
41+
} // GIVEN
42+
43+
GIVEN( "ENDF materials - incident neutrons - single and multiple submatrices, with "
44+
"lumped covariances" ) {
45+
46+
WHEN( "a single ENDF material is given" ) {
47+
48+
using Tape = njoy::ENDFtk::tree::Tape;
49+
auto tape = njoy::ENDFtk::tree::fromFile< Tape >( "n-003_Li_007.endf" );
50+
auto material = tape.materials().front();
51+
52+
THEN( "all covariances can be created" ) {
53+
54+
id::ParticleID projectile( "n" );
55+
id::ParticleID target( "Li7" );
56+
std::optional< covariance::CovarianceData > covariances =
57+
format::endf::covariance::createCovarianceData( projectile, target, material );
58+
59+
neutron::li7::verifyCrossSectionCovariances( covariances.value().crossSection().value() );
60+
} // THEN
61+
} // WHEN
62+
} // GIVEN
63+
} // SCENARIO
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// include Catch2
2+
#include <catch2/catch_test_macros.hpp>
3+
#include <catch2/matchers/catch_matchers_floating_point.hpp>
4+
using Catch::Matchers::WithinRel;
5+
using Catch::Matchers::WithinAbs;
6+
7+
// what we are testing
8+
#include "njoy/dryad/format/endf/covariance/createCrossSectionCovarianceData.hpp"
9+
10+
// other includes
11+
#include "ENDFtk/tree/fromFile.hpp"
12+
13+
// convenience typedefs
14+
using namespace njoy::dryad;
15+
using namespace njoy::ENDFtk;
16+
17+
// include common test verification functions
18+
#include "../test_verification_functions.hpp"
19+
20+
SCENARIO( "createCrossSectionCovarianceData" ) {
21+
22+
GIVEN( "ENDF materials - incident neutrons - single submatrices and "
23+
"linear combinations" ) {
24+
25+
WHEN( "a single ENDF material is given" ) {
26+
27+
using Tape = njoy::ENDFtk::tree::Tape;
28+
auto tape = njoy::ENDFtk::tree::fromFile< Tape >( "n-001_H_001.endf" );
29+
auto material = tape.materials().front();
30+
31+
THEN( "all covariances can be created" ) {
32+
33+
id::ParticleID projectile( "n" );
34+
id::ParticleID target( "H1" );
35+
std::optional< covariance::CrossSectionCovarianceData > covariances =
36+
format::endf::covariance::createCrossSectionCovarianceData( projectile, target, material );
37+
38+
neutron::h1::verifyCrossSectionCovariances( covariances.value() );
39+
} // THEN
40+
} // WHEN
41+
} // GIVEN
42+
43+
GIVEN( "ENDF materials - incident neutrons - single and multiple submatrices, with "
44+
"lumped covariances" ) {
45+
46+
WHEN( "a single ENDF material is given" ) {
47+
48+
using Tape = njoy::ENDFtk::tree::Tape;
49+
auto tape = njoy::ENDFtk::tree::fromFile< Tape >( "n-003_Li_007.endf" );
50+
auto material = tape.materials().front();
51+
52+
THEN( "all covariances can be created" ) {
53+
54+
id::ParticleID projectile( "n" );
55+
id::ParticleID target( "Li7" );
56+
std::optional< covariance::CrossSectionCovarianceData > covariances =
57+
format::endf::covariance::createCrossSectionCovarianceData( projectile, target, material );
58+
59+
neutron::li7::verifyCrossSectionCovariances( covariances.value() );
60+
} // THEN
61+
} // WHEN
62+
} // GIVEN
63+
} // SCENARIO

test/dryad/format/endf/test.electron.h.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ namespace endf81 {
10351035
verifyElasticDeficitReaction( deficit );
10361036

10371037
CHECK( std::nullopt == H0.resonances() );
1038+
10381039
CHECK( std::nullopt == H0.covarianceData() );
10391040
}
10401041

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,72 @@ namespace h1 {
311311
CHECK( id::ParticleID( "d" ) == deuterium.identifier() );
312312
}
313313

314+
void verifyCrossSectionCovariances( const covariance::CrossSectionCovarianceData& xs ) {
315+
316+
CHECK( false == xs.hasCovarianceMatrix( id::ReactionID( "n,H1->total" ) ) );
317+
CHECK( true == xs.hasCovarianceMatrix( id::ReactionID( "n,H1->capture" ) ) );
318+
CHECK( true == xs.hasCovarianceMatrix( id::ReactionID( "n,H1->n,H1" ) ) );
319+
CHECK( true == xs.hasCovarianceMatrix( id::ReactionID( "n,H1->n,H1" ), id::ReactionID( "n,H1->capture" ) ) );
320+
321+
CHECK( 2 == xs.numberReactions() );
322+
CHECK( 2 == xs.reactionIdentifiers().size() );
323+
CHECK( id::ReactionID( "n,H1->capture" ) == xs.reactionIdentifiers()[0] );
324+
CHECK( id::ReactionID( "n,H1->n,H1" ) == xs.reactionIdentifiers()[1] );
325+
326+
CHECK( 3 == xs.numberCovarianceMatrices() );
327+
CHECK( 3 == xs.covariances().size() );
328+
329+
using CrossSectionCovarianceMatrix = njoy::dryad::covariance::CrossSectionCovarianceMatrix;
330+
auto variant = xs.covarianceMatrix( id::ReactionID( "n,H1->capture" ) );
331+
auto matrix = std::get< CrossSectionCovarianceMatrix >( variant );
332+
CHECK( 1 == matrix.rowMetadata().reactionIdentifiers().size() );
333+
CHECK( id::ReactionID( "n,H1->capture" ) == matrix.rowMetadata().reactionIdentifiers()[0] );
334+
CHECK( 154 == matrix.rowMetadata().energies().size() );
335+
CHECK_THAT( 5e-6, WithinRel( matrix.rowMetadata().energies().front() ) );
336+
CHECK_THAT( 2.025e+7, WithinRel( matrix.rowMetadata().energies().back() ) );
337+
CHECK( matrix.columnMetadata() == matrix.rowMetadata() );
338+
CHECK( 153 == matrix.covariances().rows() );
339+
CHECK( 153 == matrix.covariances().cols() );
340+
CHECK( 4.278572e-4 == matrix.covariances()( 0, 0) );
341+
CHECK( -4.657843e-4 == matrix.covariances()( 0,152) );
342+
CHECK( -4.657843e-4 == matrix.covariances()(152, 0) );
343+
CHECK( 3.473440e-2 == matrix.covariances()(152,152) );
344+
345+
variant = xs.covarianceMatrix( id::ReactionID( "n,H1->n,H1" ) );
346+
matrix = std::get< CrossSectionCovarianceMatrix >( variant );
347+
CHECK( 1 == matrix.rowMetadata().reactionIdentifiers().size() );
348+
CHECK( id::ReactionID( "n,H1->n,H1" ) == matrix.rowMetadata().reactionIdentifiers()[0] );
349+
CHECK( 154 == matrix.rowMetadata().energies().size() );
350+
CHECK_THAT( 5e-6, WithinRel( matrix.rowMetadata().energies().front() ) );
351+
CHECK_THAT( 2.025e+7, WithinRel( matrix.rowMetadata().energies().back() ) );
352+
CHECK( matrix.columnMetadata() == matrix.rowMetadata() );
353+
CHECK( 153 == matrix.covariances().rows() );
354+
CHECK( 153 == matrix.covariances().cols() );
355+
CHECK( 6.954882e-5 == matrix.covariances()( 0, 0) );
356+
CHECK( 2.361196e-6 == matrix.covariances()( 0,152) );
357+
CHECK( 2.361196e-6 == matrix.covariances()(152, 0) );
358+
CHECK( 1.976707e-5 == matrix.covariances()(152,152) );
359+
360+
variant = xs.covarianceMatrix( id::ReactionID( "n,H1->n,H1" ), id::ReactionID( "n,H1->capture" ) );
361+
matrix = std::get< CrossSectionCovarianceMatrix >( variant );
362+
CHECK( 1 == matrix.rowMetadata().reactionIdentifiers().size() );
363+
CHECK( id::ReactionID( "n,H1->n,H1" ) == matrix.rowMetadata().reactionIdentifiers()[0] );
364+
CHECK( 154 == matrix.rowMetadata().energies().size() );
365+
CHECK_THAT( 5e-6, WithinRel( matrix.rowMetadata().energies().front() ) );
366+
CHECK_THAT( 2.025e+7, WithinRel( matrix.rowMetadata().energies().back() ) );
367+
CHECK( 1 == matrix.columnMetadata().reactionIdentifiers().size() );
368+
CHECK( id::ReactionID( "n,H1->capture" ) == matrix.columnMetadata().reactionIdentifiers()[0] );
369+
CHECK( 154 == matrix.columnMetadata().energies().size() );
370+
CHECK_THAT( 5e-6, WithinRel( matrix.columnMetadata().energies().front() ) );
371+
CHECK_THAT( 2.025e+7, WithinRel( matrix.columnMetadata().energies().back() ) );
372+
CHECK( 153 == matrix.covariances().rows() );
373+
CHECK( 153 == matrix.covariances().cols() );
374+
CHECK( 3.076179e-5 == matrix.covariances()( 0, 0) );
375+
CHECK( 1.451485e-4 == matrix.covariances()( 0,152) );
376+
CHECK( 9.693969e-6 == matrix.covariances()(152, 0) );
377+
CHECK( 1.171132e-4 == matrix.covariances()(152,152) );
378+
}
379+
314380
void verifyH1( const ProjectileTarget& H1, bool normalise ) {
315381

316382
verifyDocumentation( H1.documentation() );
@@ -350,6 +416,9 @@ namespace h1 {
350416
CHECK( std::nullopt == H1.resonances() );
351417

352418
CHECK( std::nullopt != H1.covarianceData() );
419+
420+
CHECK( std::nullopt != H1.covarianceData()->crossSection() );
421+
verifyCrossSectionCovariances( H1.covarianceData()->crossSection().value() );
353422
}
354423

355424
} // namespace h1

0 commit comments

Comments
 (0)