Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/distributions part2 #7

Merged
merged 7 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FetchContent_Declare( range-v3

FetchContent_Declare( scion
GIT_REPOSITORY https://github.com/njoy/scion
GIT_TAG ba080204ee9c9db5dc1a453c552c68bcd50b4e9b
GIT_TAG 6079dc15153b1948c772835096662be65b062676
)

FetchContent_Declare( spdlog
Expand Down
4 changes: 4 additions & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ endfunction()
add_subdirectory( src/dryad/id/ElementID/test )

add_subdirectory( src/dryad/LegendreAngularDistribution/test )
add_subdirectory( src/dryad/LegendreAngularDistributions/test )
add_subdirectory( src/dryad/TabulatedAngularDistribution/test )
add_subdirectory( src/dryad/TabulatedAngularDistributions/test )
add_subdirectory( src/dryad/TabulatedEnergyDistribution/test )
add_subdirectory( src/dryad/TabulatedEnergyDistributions/test )
add_subdirectory( src/dryad/TabulatedCrossSection/test )
add_subdirectory( src/dryad/TabulatedMultiplicity/test )
add_subdirectory( src/dryad/ReactionProduct/test )
Expand Down
19 changes: 17 additions & 2 deletions src/dryad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@
#include "dryad/type-aliases.hpp"

// identifiers
#include "dryad/ElementID.hpp"
#include "dryad/ParticleID.hpp"
#include "dryad/ReactionID.hpp"

// components - resonances
#include "dryad/resonances.hpp"
// enumerators
#include "dryad/InteractionType.hpp"
#include "dryad/ReactionType.hpp"

// components
#include "dryad/TabulatedCrossSection.hpp"
#include "dryad/Reaction.hpp"
#include "dryad/ProjectileTarget.hpp"

// components - resonances
#include "dryad/resonances.hpp"

// components - reaction products
#include "dryad/ReactionProduct.hpp"
#include "dryad/TabulatedMultiplicity.hpp"
#include "dryad/LegendreAngularDistribution.hpp"
#include "dryad/LegendreAngularDistributions.hpp"
#include "dryad/TabulatedAngularDistribution.hpp"
#include "dryad/TabulatedAngularDistributions.hpp"
#include "dryad/TabulatedEnergyDistribution.hpp"
#include "dryad/TabulatedEnergyDistributions.hpp"

// formats
#include "dryad/format/endf.hpp"
5 changes: 5 additions & 0 deletions src/dryad/LegendreAngularDistribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ namespace dryad {

public:

/* type aliases */
using LegendreSeries::XType;
using LegendreSeries::YType;

/* constructor */

#include "dryad/LegendreAngularDistribution/src/ctor.hpp"

/* methods */
Expand Down
18 changes: 18 additions & 0 deletions src/dryad/LegendreAngularDistributions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef NJOY_DRYAD_LEGENDREANGULARDISTRIBUTIONS
#define NJOY_DRYAD_LEGENDREANGULARDISTRIBUTIONS

// system includes

// other includes
#include "dryad/base/GridDistributions.hpp"
#include "dryad/LegendreAngularDistribution.hpp"

namespace njoy {
namespace dryad {

using LegendreAngularDistributions = base::GridDistributions< LegendreAngularDistribution >;

} // dryad namespace
} // njoy namespace

#endif
1 change: 1 addition & 0 deletions src/dryad/LegendreAngularDistributions/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( LegendreAngularDistributions LegendreAngularDistributions.test.cpp )
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
using Catch::Matchers::WithinRel;
using Catch::Matchers::WithinAbs;

// what we are testing
#include "dryad/LegendreAngularDistributions.hpp"

// other includes

// convenience typedefs
using namespace njoy::dryad;

SCENARIO( "LegendreAngularDistributions" ) {

GIVEN( "legendre series without boundaries and no jumps" ) {

// note : the Legendre coefficients were chosen so that this
// test case linearises to the previous tabulated version.

WHEN( "the data is given explicitly" ) {

const std::vector< double > energies = { 1., 2., 3., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};
InterpolationType interpolant = InterpolationType::LinearLinear;

LegendreAngularDistributions
chunk( std::move( energies ), std::move( distributions ), interpolant );

THEN( "an InterpolationTableFunction can be constructed and members can be tested" ) {

CHECK( 4 == chunk.numberPoints() );
CHECK( 1 == chunk.numberRegions() );
CHECK( 4 == chunk.grid().size() );
CHECK( 4 == chunk.distributions().size() );
CHECK( 1 == chunk.boundaries().size() );
CHECK( 1 == chunk.interpolants().size() );
CHECK_THAT( 1., WithinRel( chunk.grid()[0] ) );
CHECK_THAT( 2., WithinRel( chunk.grid()[1] ) );
CHECK_THAT( 3., WithinRel( chunk.grid()[2] ) );
CHECK_THAT( 4., WithinRel( chunk.grid()[3] ) );
CHECK( 1 == chunk.distributions()[0].coefficients().size() );
CHECK( 2 == chunk.distributions()[1].coefficients().size() );
CHECK( 2 == chunk.distributions()[2].coefficients().size() );
CHECK( 2 == chunk.distributions()[3].coefficients().size() );
CHECK_THAT( 0.5 , WithinRel( chunk.distributions()[0].coefficients()[0] ) );
CHECK_THAT( 0.5 , WithinRel( chunk.distributions()[1].coefficients()[0] ) );
CHECK_THAT( 0.01, WithinRel( chunk.distributions()[1].coefficients()[1] ) );
CHECK_THAT( 0.5 , WithinRel( chunk.distributions()[2].coefficients()[0] ) );
CHECK_THAT( 0.1 , WithinRel( chunk.distributions()[2].coefficients()[1] ) );
CHECK_THAT( 0.5 , WithinRel( chunk.distributions()[3].coefficients()[0] ) );
CHECK_THAT( 0.4 , WithinRel( chunk.distributions()[3].coefficients()[1] ) );
CHECK( 3 == chunk.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == chunk.interpolants()[0] );
} // THEN

THEN( "an InterpolationTableFunction can be evaluated" ) {

// values of x in the x grid
CHECK_THAT( 0.5 , WithinRel( chunk( 1., -0.5 ) ) );
CHECK_THAT( 0.495, WithinRel( chunk( 2., -0.5 ) ) );
CHECK_THAT( 0.45 , WithinRel( chunk( 3., -0.5 ) ) );
CHECK_THAT( 0.3 , WithinRel( chunk( 4., -0.5 ) ) );

// values of x outside the x grid
CHECK_THAT( 0., WithinRel( chunk( 0., -0.5 ) ) );
CHECK_THAT( 0., WithinRel( chunk( 5., -0.5 ) ) );

// values of x inside the x grid
CHECK_THAT( 0.4975, WithinRel( chunk( 1.5, -0.5 ) ) );
CHECK_THAT( 0.4725, WithinRel( chunk( 2.5, -0.5 ) ) );
CHECK_THAT( 0.375 , WithinRel( chunk( 3.5, -0.5 ) ) );
} // THEN
} // WHEN
} // GIVEN

GIVEN( "invalid data for an InterpolationTableFunction object" ) {

WHEN( "there are not enough values in the x or f(y) grid" ) {

std::vector< double > gempty = {};
std::vector< double > gone = { 1. };
std::vector< LegendreAngularDistribution > dempty = {};
std::vector< LegendreAngularDistribution > done = { { { 0.5 } } };

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( gempty, dempty ) );
CHECK_THROWS( LegendreAngularDistributions( gone, done ) );
CHECK_THROWS( LegendreAngularDistributions( gempty, done ) );
CHECK_THROWS( LegendreAngularDistributions( gone, dempty ) );
} // THEN
} // WHEN

WHEN( "the x and f(y) grid do not have the same number of points" ) {

std::vector< double > grid = { 1., 2., 3., 4. };
std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } }
};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ) ) );
} // THEN
} // WHEN

WHEN( "the boundaries and interpolants do not have the same size" ) {

const std::vector< double > grid = { 1., 2., 3., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};
std::vector< std::size_t > boundaries = { 3 };
std::vector< InterpolationType > interpolants = {};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ),
std::move( boundaries ),
std::move( interpolants ) ) );
} // THEN
} // WHEN

WHEN( "the x grid is not sorted" ) {

const std::vector< double > grid = { 1., 3., 2., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ) ) );
} // THEN
} // WHEN

WHEN( "the x grid contains a triple x value" ) {

const std::vector< double > grid = { 1., 2., 2., 2., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.001 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ) ) );
} // THEN
} // WHEN

WHEN( "the x grid has a jump at the beginning" ) {

const std::vector< double > grid = { 1., 1., 3., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ) ) );
} // THEN
} // WHEN

WHEN( "the x grid has a jump at the end" ) {

const std::vector< double > grid = { 1., 2., 4., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ) ) );
} // THEN
} // WHEN

WHEN( "the last boundary does not point to the last point" ) {

const std::vector< double > grid = { 1., 2., 3., 4. };
const std::vector< LegendreAngularDistribution > distributions = {

{ { 0.5 } },
{ { 0.5, 0.01 } },
{ { 0.5, 0.1 } },
{ { 0.5, 0.4 } }
};
std::vector< std::size_t > boundaries = { 2 };
std::vector< InterpolationType > interpolants = { InterpolationType::LinearLinear };

THEN( "an exception is thrown" ) {

CHECK_THROWS( LegendreAngularDistributions( std::move( grid ),
std::move( distributions ),
std::move( boundaries ),
std::move( interpolants ) ) );
} // THEN
} // WHEN
} // GIVEN
} // SCENARIO
5 changes: 5 additions & 0 deletions src/dryad/TabulatedAngularDistribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ namespace dryad {

public:

/* type aliases */
using InterpolationTable::XType;
using InterpolationTable::YType;

/* constructor */

#include "dryad/TabulatedAngularDistribution/src/ctor.hpp"

/* methods */
Expand Down
18 changes: 18 additions & 0 deletions src/dryad/TabulatedAngularDistributions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef NJOY_DRYAD_TABULATEDANGULARDISTRIBUTIONS
#define NJOY_DRYAD_TABULATEDANGULARDISTRIBUTIONS

// system includes

// other includes
#include "dryad/base/GridDistributions.hpp"
#include "dryad/TabulatedAngularDistribution.hpp"

namespace njoy {
namespace dryad {

using TabulatedAngularDistributions = base::GridDistributions< TabulatedAngularDistribution >;

} // dryad namespace
} // njoy namespace

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( TabulatedAngularDistributions TabulatedAngularDistributions.test.cpp )
Loading