Skip to content

Commit

Permalink
Now we can read most files in the current state of dryad
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Nov 13, 2024
1 parent 755b525 commit 586e977
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/dryad/format/gnds/createInterpolationType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace gnds {

return InterpolationType::LinearLinear;
}
else if ( type == "flat" ) {

return InterpolationType::Histogram;
}
else if ( type == "log-log" ) {

return InterpolationType::LogLog;
Expand Down
13 changes: 10 additions & 3 deletions src/dryad/format/gnds/createReactionProduct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,23 @@ namespace gnds {
auto node = distribution.find_child_by_attribute( "label", style.c_str() );
if ( strcmp( node.name(), "angularTwoBody" ) == 0 ) {

// ignore recoil distributions for now
// ignore recoil or regions2d distributions for now
auto recoil = node.child( "recoil" );
if ( ! recoil ) {
auto regions2d = node.child( "regions2d" );
if ( ! recoil && ! regions2d ) {

return ReactionProduct( id, multiplicity, createTwoBodyDistributionData( node ) );
}
}
if ( strcmp( node.name(), "uncorrelated" ) == 0 ) {

return ReactionProduct( id, multiplicity, createUncorrelatedDistributionData( node ) );
// ignore discrete gamma distributions for now
auto discreteGamma = node.child( "energy" ).child( "discreteGamma" );
auto primaryGamma = node.child( "energy" ).child( "primaryGamma" );
if ( ! discreteGamma && ! primaryGamma ) {

return ReactionProduct( id, multiplicity, createUncorrelatedDistributionData( node ) );
}
}
else {

Expand Down
114 changes: 98 additions & 16 deletions src/dryad/format/gnds/createTabulatedCrossSection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// system includes
#include <vector>

#include <iostream>
// other includes
#include "pugixml.hpp"
#include "tools/Log.hpp"
Expand All @@ -19,23 +19,16 @@ namespace format {
namespace gnds {

/**
* @brief Create a TabulatedCrossSection from a GNDS node (XYs1d or regions1d)
* @brief Create a TabulatedCrossSection from a GNDS XYs1d or regions1d node
*/
static TabulatedCrossSection
createTabulatedCrossSection( const pugi::xml_node& xs,
const std::string& style = "eval" ) {

Log::info( "Reading cross section data" );
createTabulatedCrossSectionFromNodes( const pugi::xml_node& node ) {

std::vector< double > energies;
std::vector< double > values;
std::vector< std::size_t > boundaries;
std::vector< InterpolationType > interpolants;

// check that this is a valid q node
throwExceptionOnWrongNode( xs, "crossSection" );

auto node = xs.find_child_by_attribute( "label", style.c_str() );
if ( strcmp( node.name(), "XYs1d" ) == 0 ) {

// read the cross section data
Expand Down Expand Up @@ -92,12 +85,6 @@ namespace gnds {
interpolants.emplace_back( interpolant );
}
}
else if ( strcmp( node.name(), "resonancesWithBackground" ) == 0 ) {

auto resolved = node.child( "background" ).child( "resolvedRegion" );
auto unresolved = node.child( "background" ).child( "unresolvedRegion" );
auto fast = node.child( "background" ).child( "fastRegion" );
}
else {

Log::error( "Expected either an XYs1d node or regions1d node with XYs1d nodes "
Expand All @@ -110,6 +97,101 @@ namespace gnds {
std::move( boundaries ), std::move( interpolants ) );
}

/**
* @brief Create a TabulatedCrossSection from a GNDS cross section node
*/
static TabulatedCrossSection
createTabulatedCrossSection( const pugi::xml_node& xs,
const std::string& style = "eval" ) {

Log::info( "Reading cross section data" );

// check that this is a valid q node
throwExceptionOnWrongNode( xs, "crossSection" );

auto node = xs.find_child_by_attribute( "label", style.c_str() );
if ( strcmp( node.name(), "XYs1d" ) == 0 ) {

// return a cross section
return createTabulatedCrossSectionFromNodes( node );
}
else if ( strcmp( node.name(), "regions1d" ) == 0 ) {

// return a cross section
return createTabulatedCrossSectionFromNodes( node );
}
else if ( strcmp( node.name(), "resonancesWithBackground" ) == 0 ) {

// get the resolved background data
auto resolved = node.child( "background" ).child( "resolvedRegion" );
auto result = createTabulatedCrossSectionFromNodes( resolved.first_child() );

// start to assemble the data together
std::vector< double > energies = result.energies();
std::vector< double > values = result.values();
std::vector< std::size_t > boundaries = result.boundaries();
std::vector< InterpolationType > interpolants = result.interpolants();

// get the unresolved background data
auto unresolved = node.child( "background" ).child( "unresolvedRegion" );
if ( unresolved ) {

result = createTabulatedCrossSectionFromNodes( unresolved.first_child() );

// check for duplicate points at interpolation region boundaries
std::size_t offset = 0;
if ( energies.back() == result.energies().front() &&
values.back() == result.values().front() ) {

offset = 1;
}

// add data
std::size_t size = energies.size();
energies.insert( energies.end(), result.energies().begin() + offset, result.energies().end() + offset );
values.insert( values.end(), result.values().begin() + offset, result.values().end() + offset );
for ( unsigned int i = 0; i < result.numberRegions(); ++i ) {

boundaries.emplace_back( result.boundaries()[i] - offset + size );
interpolants.emplace_back( result.interpolants()[i] );
}
}

// get the fast background data
auto fast = node.child( "background" ).child( "fastRegion" );

result = createTabulatedCrossSectionFromNodes( fast.first_child() );

// check for duplicate points at interpolation region boundaries
std::size_t offset = 0;
if ( energies.back() == result.energies().front() &&
values.back() == result.values().front() ) {

offset = 1;
}

// add data
std::size_t size = energies.size();
energies.insert( energies.end(), result.energies().begin() + offset, result.energies().end() + offset );
values.insert( values.end(), result.values().begin() + offset, result.values().end() + offset );
for ( unsigned int i = 0; i < result.numberRegions(); ++i ) {

boundaries.emplace_back( result.boundaries()[i] - offset + size );
interpolants.emplace_back( result.interpolants()[i] );
}

return TabulatedCrossSection(
std::move( energies ), std::move( values ),
std::move( boundaries ), std::move( interpolants ) );
}
else {

Log::error( "Expected either an XYs1d, regions1d (with XYs1d nodes) or a "
"background node for cross section data" );
throw std::exception();
}
}

} // gnds namespace
} // format namespace
} // dryad namespace
Expand Down
4 changes: 4 additions & 0 deletions src/dryad/format/gnds/createTwoBodyDistributionData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace gnds {
throw std::exception();
}
}
else if ( strcmp( node.name(), "isotropic2d" ) == 0 ) {

return TwoBodyDistributionData( std::move( frame ), IsotropicAngularDistributions() );
}
else if ( strcmp( node.name(), "regions1d" ) == 0 ) {

Log::error( "Mixed Legendre and tabulated angular distribution data is "
Expand Down
3 changes: 2 additions & 1 deletion src/dryad/format/gnds/createUncorrelatedDistributionData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ namespace gnds {
}
else {

Log::error( "Expected an XYs2d node for uncorrelated energy distribution data" );
Log::error( "Expected an XYs2d node for uncorrelated energy distribution data, found \'{}\'",
node.name() );
throw std::exception();
}
}
Expand Down

0 comments on commit 586e977

Please sign in to comment.