-
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.
Reading average energy data from gnds files
- Loading branch information
Showing
3 changed files
with
173 additions
and
60 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,107 @@ | ||
#ifndef NJOY_DRYAD_FORMAT_GNDS_CREATETABULATEDAVERAGEENERGY | ||
#define NJOY_DRYAD_FORMAT_GNDS_CREATETABULATEDAVERAGEENERGY | ||
|
||
// system includes | ||
#include <vector> | ||
|
||
// other includes | ||
#include "pugixml.hpp" | ||
#include "tools/Log.hpp" | ||
#include "dryad/format/gnds/createInterpolationType.hpp" | ||
#include "dryad/format/gnds/readXYs1d.hpp" | ||
#include "dryad/format/gnds/convertEnergies.hpp" | ||
#include "dryad/TabulatedAverageEnergy.hpp" | ||
|
||
namespace njoy { | ||
namespace dryad { | ||
namespace format { | ||
namespace gnds { | ||
|
||
/** | ||
* @brief Create a TabulatedAverageEnergy from a GNDS average node | ||
*/ | ||
static TabulatedAverageEnergy | ||
createTabulatedAverageEnergy( const pugi::xml_node& average, | ||
const std::string& style = "eval" ) { | ||
|
||
std::vector< double > energies; | ||
std::vector< double > values; | ||
std::vector< std::size_t > boundaries; | ||
std::vector< InterpolationType > interpolants; | ||
|
||
// check that this is a valid average energy node | ||
throwExceptionOnWrongNode( average, "averageProductEnergy" ); | ||
|
||
auto node = average.find_child_by_attribute( "label", style.c_str() ); | ||
if ( strcmp( node.name(), "XYs1d" ) == 0 ) { | ||
|
||
// read the average energy data | ||
auto data = readXYs1D( node ); | ||
|
||
// get the interpolation type | ||
auto interpolant = createInterpolationType( std::get< 6 >( data ) ); | ||
|
||
// convert units - if necessary | ||
convertEnergies( std::get< 2 >( data ), std::get< 3 >( data ) ); | ||
|
||
// assign data | ||
energies = std::move( std::get< 2 >( data ) ); | ||
values = std::move( std::get< 4 >( data ) ); | ||
boundaries.emplace_back( energies.size() - 1 ); | ||
interpolants.emplace_back( interpolant ); | ||
} | ||
else if ( strcmp( node.name(), "regions1d" ) == 0 ) { | ||
|
||
// get the units | ||
auto units = readAxes( node.child( "axes" ) ); | ||
|
||
// loop over the children of function1ds | ||
pugi::xml_node function1ds = node.child( "function1ds" ); | ||
for ( pugi::xml_node xys1d = function1ds.child( "XYs1d" ); | ||
xys1d; xys1d = xys1d.next_sibling( "XYs1d" ) ) { | ||
|
||
// read the current interpolation region | ||
auto data = readXYs1D( xys1d, units ); | ||
|
||
// get the interpolation type | ||
auto interpolant = createInterpolationType( std::get< 6 >( data ) ); | ||
|
||
// convert units - if necessary | ||
convertEnergies( std::get< 2 >( data ), std::get< 3 >( data ) ); | ||
|
||
// check for duplicate points at interpolation region boundaries | ||
std::size_t offset = 0; | ||
if ( energies.size() > 0 ) { | ||
|
||
if ( energies.back() == std::get< 2 >( data ).front() && | ||
values.back() == std::get< 4 >( data ).front() ) { | ||
|
||
offset = 1; | ||
} | ||
} | ||
|
||
// grow the data accordingly | ||
energies.insert( energies.end(), std::get< 2 >( data ).begin() + offset, std::get< 2 >( data ).end() ); | ||
values.insert( values.end(), std::get< 4 >( data ).begin() + offset, std::get< 4 >( data ).end() ); | ||
boundaries.emplace_back( energies.size() - 1 ); | ||
interpolants.emplace_back( interpolant ); | ||
} | ||
} | ||
else { | ||
|
||
Log::error( "Expected either an XYs1d node or regions1d node with XYs1d nodes" | ||
"for average energy data" ); | ||
throw std::exception(); | ||
} | ||
|
||
return TabulatedAverageEnergy( | ||
std::move( energies ), std::move( values ), | ||
std::move( boundaries ), std::move( interpolants ) ); | ||
} | ||
|
||
} // gnds 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