-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef NJOY_DRYAD_FORMAT_ENDF_CREATETABULATEDFORMFACTOR | ||
#define NJOY_DRYAD_FORMAT_ENDF_CREATETABULATEDFORMFACTOR | ||
|
||
// system includes | ||
#include <vector> | ||
|
||
// other includes | ||
#include "tools/Log.hpp" | ||
#include "dryad/format/createVector.hpp" | ||
#include "dryad/format/endf/createBoundaries.hpp" | ||
#include "dryad/format/endf/createInterpolants.hpp" | ||
#include "dryad/TabulatedFormFactor.hpp" | ||
#include "ENDFtk/section/27.hpp" | ||
#include "ENDFtk/tree/Section.hpp" | ||
|
||
namespace njoy { | ||
namespace dryad { | ||
namespace format { | ||
namespace endf { | ||
|
||
/** | ||
* @brief Create a TabulatedFormFactor from a parsed ENDF section | ||
*/ | ||
TabulatedFormFactor | ||
createTabulatedFormFactor( const ENDFtk::section::Type< 27 >& section ) { | ||
|
||
if ( ( section.sectionNumber() != 505 ) && ( section.sectionNumber() != 506 ) ) { | ||
|
||
Log::error( "Tabulated form factors are only defined in MF27 MT505 and MT506, " | ||
"got MT{} instead", section.sectionNumber() ); | ||
throw std::exception(); | ||
} | ||
|
||
try { | ||
|
||
Log::info( "Reading form factor data" ); | ||
auto energies = createVector( section.X() ); | ||
auto values = createVector( section.H() ); | ||
auto boundaries = createBoundaries( section.boundaries() ); | ||
auto interpolants = createInterpolants( section.interpolants() ); | ||
return TabulatedFormFactor( | ||
std::move( energies ), std::move( values ), | ||
std::move( boundaries ), std::move( interpolants ) ); | ||
} | ||
catch ( ... ) { | ||
|
||
Log::info( "Error encountered while creating a tabulated scattering function" ); | ||
throw; | ||
} | ||
} | ||
|
||
/** | ||
* @brief Create a TabulatedFormFactor from an unparsed ENDF section | ||
*/ | ||
TabulatedFormFactor | ||
createTabulatedFormFactor( const ENDFtk::tree::Section& tree ) { | ||
|
||
if ( tree.fileNumber() == 27 ) { | ||
|
||
return createTabulatedFormFactor( tree.parse< 27 >() ); | ||
} | ||
else { | ||
|
||
Log::error( "The MAT{} MF{} MT{} section does not define a " | ||
"tabulated form factor", tree.materialNumber(), | ||
tree.fileNumber(), tree.sectionNumber() ); | ||
throw std::exception(); | ||
} | ||
} | ||
|
||
} // endf namespace | ||
} // format namespace | ||
} // dryad namespace | ||
} // njoy namespace | ||
|
||
#endif |
76 changes: 76 additions & 0 deletions
76
src/dryad/format/endf/createTabulatedScatteringFunction.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef NJOY_DRYAD_FORMAT_ENDF_CREATETABULATEDSCATTERINGFUNCTION | ||
#define NJOY_DRYAD_FORMAT_ENDF_CREATETABULATEDSCATTERINGFUNCTION | ||
|
||
// system includes | ||
#include <vector> | ||
|
||
// other includes | ||
#include "tools/Log.hpp" | ||
#include "dryad/format/createVector.hpp" | ||
#include "dryad/format/endf/createBoundaries.hpp" | ||
#include "dryad/format/endf/createInterpolants.hpp" | ||
#include "dryad/TabulatedScatteringFunction.hpp" | ||
#include "ENDFtk/section/27.hpp" | ||
#include "ENDFtk/tree/Section.hpp" | ||
|
||
namespace njoy { | ||
namespace dryad { | ||
namespace format { | ||
namespace endf { | ||
|
||
/** | ||
* @brief Create a TabulatedScatteringFunction from a parsed ENDF section | ||
*/ | ||
TabulatedScatteringFunction | ||
createTabulatedScatteringFunction( const ENDFtk::section::Type< 27 >& section ) { | ||
|
||
if ( ( section.sectionNumber() != 502 ) && ( section.sectionNumber() != 504 ) ) { | ||
|
||
Log::error( "Tabulated scattering functions are only defined in MF27 MT502 and MT504, " | ||
"got MT{} instead", section.sectionNumber() ); | ||
throw std::exception(); | ||
} | ||
|
||
try { | ||
|
||
Log::info( "Reading scattering function data" ); | ||
auto x = createVector( section.X() ); | ||
auto values = createVector( section.H() ); | ||
auto boundaries = createBoundaries( section.boundaries() ); | ||
auto interpolants = createInterpolants( section.interpolants() ); | ||
return TabulatedScatteringFunction( | ||
std::move( x ), std::move( values ), | ||
std::move( boundaries ), std::move( interpolants ) ); | ||
} | ||
catch ( ... ) { | ||
|
||
Log::info( "Error encountered while creating a tabulated scattering function" ); | ||
throw; | ||
} | ||
} | ||
|
||
/** | ||
* @brief Create a TabulatedScatteringFunction from an unparsed ENDF section | ||
*/ | ||
TabulatedScatteringFunction | ||
createTabulatedScatteringFunction( const ENDFtk::tree::Section& tree ) { | ||
|
||
if ( tree.fileNumber() == 27 ) { | ||
|
||
return createTabulatedScatteringFunction( tree.parse< 27 >() ); | ||
} | ||
else { | ||
|
||
Log::error( "The MAT{} MF{} MT{} section does not define a " | ||
"tabulated scattering function", tree.materialNumber(), | ||
tree.fileNumber(), tree.sectionNumber() ); | ||
throw std::exception(); | ||
} | ||
} | ||
|
||
} // endf namespace | ||
} // format namespace | ||
} // dryad namespace | ||
} // njoy namespace | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/dryad/format/endf/test/createTabulatedFormFactor.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// include Catch2 | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
using Catch::Matchers::WithinRel; | ||
|
||
// what we are testing | ||
#include "dryad/format/endf/createTabulatedFormFactor.hpp" | ||
|
||
// other includes | ||
#include "ENDFtk/tree/fromFile.hpp" | ||
|
||
// convenience typedefs | ||
using namespace njoy::dryad; | ||
|
||
void verifyChunk( const TabulatedFormFactor& ); | ||
|
||
SCENARIO( "createTabulatedFormFactor" ) { | ||
|
||
GIVEN( "ENDF MF3 sections" ) { | ||
|
||
auto tape = njoy::ENDFtk::tree::fromFile( "photoat-001_H_000.endf" ); | ||
auto section = tape.materials().front().section( 27, 505 ); | ||
|
||
WHEN( "a single unparsed MF27 section is given" ) { | ||
|
||
THEN( "it can be converted" ) { | ||
|
||
auto chunk = format::endf::createTabulatedFormFactor( section ); | ||
|
||
verifyChunk( chunk ); | ||
} // THEN | ||
} // WHEN | ||
|
||
WHEN( "a single parsed MF27 section is given" ) { | ||
|
||
THEN( "it can be converted" ) { | ||
|
||
auto chunk = format::endf::createTabulatedFormFactor( section.parse< 27 >() ); | ||
|
||
verifyChunk( chunk ); | ||
} // THEN | ||
} // WHEN | ||
} // GIVEN | ||
} // SCENARIO | ||
|
||
void verifyChunk( const TabulatedFormFactor& chunk ) { | ||
|
||
CHECK( true == chunk.isLinearised() ); | ||
CHECK( 297 == chunk.numberPoints() ); | ||
CHECK( 1 == chunk.numberRegions() ); | ||
CHECK( 297 == chunk.energies().size() ); | ||
CHECK( 297 == chunk.values().size() ); | ||
CHECK( 1 == chunk.boundaries().size() ); | ||
CHECK( 1 == chunk.interpolants().size() ); | ||
CHECK( 296 == chunk.boundaries()[0] ); | ||
CHECK( InterpolationType::LinearLinear == chunk.interpolants()[0] ); | ||
CHECK_THAT( 1, WithinRel( chunk.energies()[0] ) ); | ||
CHECK_THAT( 2, WithinRel( chunk.energies()[1] ) ); | ||
CHECK_THAT( 9549925.86, WithinRel( chunk.energies()[295] ) ); | ||
CHECK_THAT( 10000000, WithinRel( chunk.energies()[296] ) ); | ||
CHECK_THAT( 0, WithinRel( chunk.values()[0] ) ); | ||
CHECK_THAT( 0, WithinRel( chunk.values()[1] ) ); | ||
CHECK_THAT( 8.9767e-15, WithinRel( chunk.values()[295] ) ); | ||
CHECK_THAT( 0, WithinRel( chunk.values()[296] ) ); | ||
} |
65 changes: 65 additions & 0 deletions
65
src/dryad/format/endf/test/createTabulatedScatteringFunction.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// include Catch2 | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
using Catch::Matchers::WithinRel; | ||
|
||
// what we are testing | ||
#include "dryad/format/endf/createTabulatedScatteringFunction.hpp" | ||
|
||
// other includes | ||
#include "ENDFtk/tree/fromFile.hpp" | ||
|
||
// convenience typedefs | ||
using namespace njoy::dryad; | ||
|
||
void verifyChunk( const TabulatedScatteringFunction& ); | ||
|
||
SCENARIO( "createTabulatedScatteringFunction" ) { | ||
|
||
GIVEN( "ENDF MF3 sections" ) { | ||
|
||
auto tape = njoy::ENDFtk::tree::fromFile( "photoat-001_H_000.endf" ); | ||
auto section = tape.materials().front().section( 27, 502 ); | ||
|
||
WHEN( "a single unparsed MF27 section is given" ) { | ||
|
||
THEN( "it can be converted" ) { | ||
|
||
auto chunk = format::endf::createTabulatedScatteringFunction( section ); | ||
|
||
verifyChunk( chunk ); | ||
} // THEN | ||
} // WHEN | ||
|
||
WHEN( "a single parsed MF27 section is given" ) { | ||
|
||
THEN( "it can be converted" ) { | ||
|
||
auto chunk = format::endf::createTabulatedScatteringFunction( section.parse< 27 >() ); | ||
|
||
verifyChunk( chunk ); | ||
} // THEN | ||
} // WHEN | ||
} // GIVEN | ||
} // SCENARIO | ||
|
||
void verifyChunk( const TabulatedScatteringFunction& chunk ) { | ||
|
||
CHECK( true == chunk.isLinearised() ); | ||
CHECK( 1253 == chunk.numberPoints() ); | ||
CHECK( 1 == chunk.numberRegions() ); | ||
CHECK( 1253 == chunk.inverseLengths().size() ); | ||
CHECK( 1253 == chunk.values().size() ); | ||
CHECK( 1 == chunk.boundaries().size() ); | ||
CHECK( 1 == chunk.interpolants().size() ); | ||
CHECK( 1252 == chunk.boundaries()[0] ); | ||
CHECK( InterpolationType::LinearLinear == chunk.interpolants()[0] ); | ||
CHECK_THAT( 0, WithinRel( chunk.inverseLengths()[0] ) ); | ||
CHECK_THAT( 0.001, WithinRel( chunk.inverseLengths()[1] ) ); | ||
CHECK_THAT( 512000000, WithinRel( chunk.inverseLengths()[1251] ) ); | ||
CHECK_THAT( 1e+9, WithinRel( chunk.inverseLengths()[1252] ) ); | ||
CHECK_THAT( 1, WithinRel( chunk.values()[0] ) ); | ||
CHECK_THAT( 1, WithinRel( chunk.values()[1] ) ); | ||
CHECK_THAT( 1.1908e-37, WithinRel( chunk.values()[1251] ) ); | ||
CHECK_THAT( 8.1829e-39, WithinRel( chunk.values()[1252] ) ); | ||
} |
Oops, something went wrong.