Skip to content

Commit

Permalink
Merge pull request #2 from njoy/feature/initial-v2
Browse files Browse the repository at this point in the history
Feature/initial v2
  • Loading branch information
whaeck authored May 21, 2024
2 parents 56f5474 + 2541ff8 commit 71904f0
Show file tree
Hide file tree
Showing 70 changed files with 3,593 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ContinuousIntegration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
which ${{matrix.cxx}}
${{matrix.cxx}} --version
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir bin
run: mkdir bin
- name: cmake
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ cmake_dependent_option(
cmake_dependent_option(
NDItk.python
"Build NDItk python bindings" ON
"NOT ${subproject}" OFF
"NOT ${subproject} OR DEFINED requires.NDItk.python " OFF
)
if ( NDItk.python )
set( require.tools.python CACHE BOOL ON )
endif()

########################################################################
# Dependencies
Expand Down Expand Up @@ -103,7 +106,9 @@ if( NDItk.python )

list( APPEND NDItk_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR} )

include( cmake/unit_testing_python.cmake )
if( NDItk.tests )
include( cmake/unit_testing_python.cmake )
endif()

endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/develop_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include( FetchContent )

FetchContent_Declare( tools
GIT_REPOSITORY https://github.com/njoy/tools
GIT_TAG v0.2.0
GIT_TAG v0.3.0
GIT_SHALLOW TRUE
)

Expand Down
8 changes: 7 additions & 1 deletion cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ FetchContent_Declare( Catch2
GIT_TAG 3f0283de7a9c43200033da996ff9093be3ac84dc # tag: v3.3.2
)

FetchContent_Declare( fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float
GIT_TAG f476bc713fda06fbd34dc621b466745a574b3d4c # tag: v6.1.1
)

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242 # tag: v2.10.4
Expand All @@ -23,14 +28,15 @@ set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )

FetchContent_Declare( tools
GIT_REPOSITORY https://github.com/njoy/tools
GIT_TAG 25c9273d05601a9644feea6d7539250bf1d1c0dc # tag: v0.2.0
GIT_TAG 368dbd9bd44754de616c46ffed0f80d2d16d8360 # tag: v0.3.0
)

#######################################################################
# Load dependencies
#######################################################################

FetchContent_MakeAvailable(
fast_float
spdlog
tools
)
13 changes: 13 additions & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ endfunction()
# Unit testing directories
#######################################################################

add_subdirectory( src/NDItk/base/SingleIntegerRecord/test )
add_subdirectory( src/NDItk/base/SingleRealRecord/test )
add_subdirectory( src/NDItk/base/SingleStringRecord/test )
add_subdirectory( src/NDItk/base/IntegerListRecord/test )
add_subdirectory( src/NDItk/base/RealListRecord/test )

add_subdirectory( src/NDItk/multigroup/Metadata/test )
add_subdirectory( src/NDItk/multigroup/Structure/test )
add_subdirectory( src/NDItk/multigroup/FluxWeights/test )
add_subdirectory( src/NDItk/multigroup/CrossSection/test )
add_subdirectory( src/NDItk/multigroup/ReactionCrossSections/test )

add_subdirectory( src/NDItk/MultigroupTable/test )
7 changes: 7 additions & 0 deletions src/NDItk.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "NDItk/multigroup/Metadata.hpp"
#include "NDItk/multigroup/Structure.hpp"
#include "NDItk/multigroup/FluxWeights.hpp"
#include "NDItk/multigroup/CrossSection.hpp"
#include "NDItk/multigroup/ReactionCrossSections.hpp"

#include "NDItk/MultigroupTable.hpp"
88 changes: 88 additions & 0 deletions src/NDItk/MultigroupTable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef NJOY_NDITK_MULTIGROUP
#define NJOY_NDITK_MULTIGROUP

// system includes

// other includes
#include "tools/Log.hpp"
#include "NDItk/multigroup/Metadata.hpp"
#include "NDItk/multigroup/Structure.hpp"
#include "NDItk/multigroup/FluxWeights.hpp"
#include "NDItk/multigroup/ReactionCrossSections.hpp"

namespace njoy {
namespace NDItk {

/**
* @brief A multigroup NDI table
*/
class MultigroupTable {

/* fields */

multigroup::Metadata metadata_;
multigroup::Structure structure_;
multigroup::FluxWeights weights_;
multigroup::ReactionCrossSections xs_;

/* auxiliary functions */

#include "NDItk/MultigroupTable/src/readRecord.hpp"
#include "NDItk/MultigroupTable/src/verify.hpp"

public:

/* constructor */

#include "NDItk/MultigroupTable/src/ctor.hpp"

/* methods */

/**
* @brief Return the metadata of the table
*/
const multigroup::Metadata& metadata() const { return this->metadata_; }

/**
* @brief Return the primary group structure record
*/
const multigroup::Structure& structure() const { return this->structure_; }

/**
* @brief Return the flux weight record
*/
const multigroup::FluxWeights& flux() const { return this->weights_; }

/**
* @brief Return the reaction cross section record
*/
const multigroup::ReactionCrossSections& reactionCrossSections() const {

return this->xs_;
}

#include "NDItk/MultigroupTable/src/read.hpp"

/**
* @brief Print the NDI table
*
* @param[in] iter the current position in the output
*/
template< typename OutputIterator >
void print( OutputIterator& iter ) const {

this->metadata_.print( iter );
this->structure_.print( iter );
this->weights_.print( iter );
this->xs_.print( iter );
*iter++ = 'e';
*iter++ = 'n';
*iter++ = 'd';
*iter++ = '\n';
};
};

} // NDItk namespace
} // njoy namespace

#endif
36 changes: 36 additions & 0 deletions src/NDItk/MultigroupTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @brief Default constructor
*/
MultigroupTable() : metadata_(), structure_(), weights_(), xs_() {}

/**
* @brief Constructor
*
* @param[in] zaid the zaid of the table
* @param[in] libname the library name
* @param[in] source the source date
* @param[in] process the processing date
* @param[in] awr the atomic weight ratio of the target
* (with respect to the neutron mass)
* @param[in] weight the atomic weight of the target
* @param[in] temperature the temperature of the target
* @param[in] dilution the dilution (aka sigma0)
* @param[in] structure the primary group structure
* @param[in] weights the flux weights
* @param[in] xs the reaction cross section data
*/
MultigroupTable( std::string zaid, std::string libname, std::string source,
std::string process, double awr, double weight, double temperature,
double dilution,
multigroup::Structure structure,
multigroup::FluxWeights weigths,
multigroup::ReactionCrossSections xs ) :
metadata_( std::move( zaid ), std::move( libname ), std::move( source ),
std::move( process ), awr, weight, temperature, dilution,
xs.numberGroups(), xs.numberReactions() ),
structure_( std::move( structure ) ),
weights_( std::move( weigths ) ),
xs_( std::move( xs ) ) {

this->verify();
}
79 changes: 79 additions & 0 deletions src/NDItk/MultigroupTable/src/read.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @brief Read the table data
*
* @param[in] iter the current position in the input
*/
template< typename Iterator >
void read( Iterator& iter, const Iterator& end ) {

std::string keyword;
while ( ( keyword != "end" ) && ( iter != end ) ) {

keyword = njoy::tools::disco::FreeFormatCharacter::read< std::string >( iter, end );

if ( this->metadata_.isMetadataKey( keyword ) ) {

this->metadata_.read( keyword, iter, end );
}
else if ( keyword == this->structure_.keyword() ) {

if ( this->metadata_.numberGroups().has_value() ) {

readRecord( this->structure_, iter, end,
this->metadata_.numberGroups().value() + 1 );
}
else {

Log::error( "Metadata required for the \'\' record was not found", keyword );
Log::info( "Required metadata is missing: number of groups in the primary group structure" );
throw std::exception();
}
}
else if ( keyword == this->weights_.keyword() ) {

if ( this->metadata_.numberGroups().has_value() ) {

readRecord( this->weights_, iter, end, this->metadata_.numberGroups().value() );
}
else {

Log::error( "Metadata required for the \'\' record was not found", keyword );
Log::info( "Required metadata is missing: number of groups in the primary group structure" );
throw std::exception();
}
}
else if ( keyword == this->xs_.keyword() ) {

if ( this->metadata_.numberGroups().has_value() && this->metadata_.numberReactions().has_value() ) {

readRecord( this->xs_, iter, end, this->metadata_.numberReactions().value(), this->metadata_.numberGroups().value() );
}
else {

Log::error( "Metadata required for the \'\' record was not found", keyword );
if ( ! this->metadata_.numberGroups().has_value() ) {

Log::info( "Required metadata is missing: number of groups in the primary group structure" );
}
if ( ! this->metadata_.numberReactions().has_value() ) {

Log::info( "Required metadata is missing: number of reactions" );
}
throw std::exception();
}
}
else {

if ( keyword != "end" ) {

Log::error( "Unknown keyword found: \'{}\'", keyword );
throw std::exception();
}
}

while ( std::isspace( *iter ) && iter != end ) {

++iter;
}
}
};
14 changes: 14 additions & 0 deletions src/NDItk/MultigroupTable/src/readRecord.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @brief A helper function to read a data record
*/
template < typename Record, typename Iterator, typename... Arguments >
static void readRecord( Record& record, Iterator& iter, const Iterator& end,
Arguments... arguments ) {

if ( ! record.empty() ) {

Log::error( "Duplicate keyword found: \'{}\'", record.keyword() );
throw std::exception();
}
record.read( iter, end, arguments... );
}
23 changes: 23 additions & 0 deletions src/NDItk/MultigroupTable/src/verify.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @brief Verify the multigroup data
*
* The following verification tests are performed:
* - the number of groups accross the data is consistent
*/
void verify() {

// consistent group structure
const auto groups = this->metadata().numberGroups().value();
if ( ( this->structure().numberGroups() != groups ) ||
( this->flux().numberGroups() != groups ) ||
( this->reactionCrossSections().numberGroups() != groups ) ) {

Log::error( "Found inconsistent number of primary groups across the table" );
Log::info( "Number of primary groups in the metadata: {}", this->metadata().numberGroups().value() );
Log::info( "Number of primary groups in the structure: {}", this->structure().numberGroups() );
Log::info( "Number of primary groups in the flux weights: {}", this->flux().numberGroups() );
Log::info( "Number of primary groups in the reaction cross section data: {}",
this->reactionCrossSections().numberGroups() );
throw std::exception();
}
};
1 change: 1 addition & 0 deletions src/NDItk/MultigroupTable/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( MultigroupTable MultigroupTable.test.cpp )
Loading

0 comments on commit 71904f0

Please sign in to comment.