From cbbce51c3b17792d866f5e153ebbdfa727d45481 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Tue, 15 Dec 2020 06:23:11 -0700 Subject: [PATCH 1/6] Updating to gfortran-9 --- .github/workflows/ContinuousIntegration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index 6a8257b5..c63f4ad8 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -14,8 +14,8 @@ jobs: strategy: matrix: os: [ ubuntu-18.04, macos-10.15 ] - cxx: [ g++-8, clang++ ] - vFortran: [ gfortran-8 ] + cxx: [ g++-9, clang++ ] + vFortran: [ gfortran-9 ] build_type: [ Debug, Release ] steps: From 36b63f96e94f207c447002753b6f8aac1096cfea Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Tue, 15 Dec 2020 06:48:02 -0700 Subject: [PATCH 2/6] Back to using g++-8 and gfortran-8. --- .github/workflows/ContinuousIntegration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index c63f4ad8..6a8257b5 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -14,8 +14,8 @@ jobs: strategy: matrix: os: [ ubuntu-18.04, macos-10.15 ] - cxx: [ g++-9, clang++ ] - vFortran: [ gfortran-9 ] + cxx: [ g++-8, clang++ ] + vFortran: [ gfortran-8 ] build_type: [ Debug, Release ] steps: From 49d70bfb0b06f95f1ce0f747fac0449415460bc2 Mon Sep 17 00:00:00 2001 From: Amelia J Trainer Date: Wed, 13 Jan 2021 11:55:58 -0500 Subject: [PATCH 3/6] Feature/leapr (#127) * Making space for modern THERMR. * Changing NJOY module to call operator instead of instantiation. * adding in LEAPR information to modern/Sequence etc * added leapr info to cmake files * Fixing compilers problems * Changed the cmake release dependencies to be more up to date * Changed NJOY integration files to match those of RECONR * Added RECONR to legacy directory to pass tests * added continuous integration * Adding ContinuousIntegration to the workflows directory [forgot that last time] * Adding in Driver/test resource and Factory/src files * Fixing FetchContent for ENDFtk. Co-authored-by: Jeremy Lloyd Conlin Co-authored-by: Wim Haeck Co-authored-by: Jeremy Lloyd Conlin --- .github/workflows/ContinuousIntegration.yml | 2 +- CMakeLists.txt | 6 +- cmake/develop_dependencies.cmake | 9 +- cmake/release_dependencies.cmake | 8 +- src/main.cpp | 7 +- src/njoy21.hpp | 9 +- src/njoy21/Driver.hpp | 9 +- src/njoy21/Driver/Factory.hpp | 14 +- .../Driver/Factory/src/callOperator.hpp | 24 ++- .../Factory/src/setupLegacyDirectory.hpp | 2 +- .../Driver/Factory/src/setupManager.hpp | 13 +- .../Factory/src/setupModernDirectory.hpp | 5 + src/njoy21/Driver/src/callOperator.hpp | 2 +- src/njoy21/Driver/test/Driver.test.cpp | 4 +- .../test/resources/{input.txt => input.njoy} | 0 src/njoy21/Driver/test/resources/tape20 | 0 src/njoy21/Sequence.hpp | 179 ------------------ src/njoy21/interface.hpp | 21 +- src/njoy21/legacy/Sequence.hpp | 12 +- src/njoy21/legacy/Sequence/Factory.hpp | 52 +---- .../Sequence/Factory/src/callOperator.hpp | 27 +++ .../legacy/Sequence/Factory/src/parse.hpp | 19 ++ src/njoy21/legacy/Sequence/routines.hpp | 11 +- src/njoy21/modern.hpp | 3 + src/njoy21/modern/Sequence.hpp | 37 ++++ src/njoy21/modern/Sequence/Factory.hpp | 20 ++ .../Sequence/Factory/src/callOperator.hpp | 26 +++ .../modern/Sequence/Factory/src/parse.hpp | 15 ++ src/njoy21/modern/Sequence/routines.hpp | 24 +++ .../modern/Sequence/test/CMakeLists.txt | 22 +++ .../modern/Sequence/test/Sequence.test.cpp | 41 ++++ 31 files changed, 346 insertions(+), 277 deletions(-) create mode 100644 src/njoy21/Driver/Factory/src/setupModernDirectory.hpp rename src/njoy21/Driver/test/resources/{input.txt => input.njoy} (100%) mode change 100755 => 100644 src/njoy21/Driver/test/resources/tape20 delete mode 100644 src/njoy21/Sequence.hpp create mode 100644 src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp create mode 100644 src/njoy21/legacy/Sequence/Factory/src/parse.hpp create mode 100644 src/njoy21/modern.hpp create mode 100644 src/njoy21/modern/Sequence.hpp create mode 100644 src/njoy21/modern/Sequence/Factory.hpp create mode 100644 src/njoy21/modern/Sequence/Factory/src/callOperator.hpp create mode 100644 src/njoy21/modern/Sequence/Factory/src/parse.hpp create mode 100644 src/njoy21/modern/Sequence/routines.hpp create mode 100644 src/njoy21/modern/Sequence/test/CMakeLists.txt create mode 100644 src/njoy21/modern/Sequence/test/Sequence.test.cpp diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index 6a8257b5..633b7859 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -34,7 +34,7 @@ jobs: run: cmake -D CMAKE_Fortran_COMPILER=`which ${{matrix.vFortran}}` -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} .. working-directory: ./bin - name: make - run: make -j2 VERBOSE=1 + run: make -j2 working-directory: ./bin - name: ctest run: ctest -j2 -R njoy21* diff --git a/CMakeLists.txt b/CMakeLists.txt index c5493749..b46e4d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,13 @@ set( debug_flags "-O0" "-g" ) # Dependencies ######################################################################## -set( REPOSITORIES "release" +set( REPOSITORIES "develop" CACHE STRING "Options for where to fetch repositories: develop, release, local" ) +message( STATUS "Using ${REPOSITORIES} repositories" ) + if( REPOSITORIES STREQUAL "develop" ) include( cmake/develop_dependencies.cmake ) @@ -59,12 +61,14 @@ target_include_directories( njoy21_library src/ ) target_link_libraries( njoy21_library + INTERFACE leapr INTERFACE ENDFtk INTERFACE dimwits INTERFACE lipservice INTERFACE njoy_c_bindings INTERFACE tclap-adapter INTERFACE utility + INTERFACE nlohmann_json INTERFACE catch-adapter ) diff --git a/cmake/develop_dependencies.cmake b/cmake/develop_dependencies.cmake index 6b57356f..eabd65df 100644 --- a/cmake/develop_dependencies.cmake +++ b/cmake/develop_dependencies.cmake @@ -5,9 +5,15 @@ include( FetchContent ) # Declare project dependencies ####################################################################### +FetchContent_Declare( leapr + GIT_REPOSITORY https://github.com/njoy/leapr + GIT_TAG origin/master + GIT_SHALLOW TRUE + ) + FetchContent_Declare( ENDFtk GIT_REPOSITORY https://github.com/njoy/ENDFtk - GIT_TAG origin/master + GIT_TAG origin/develop GIT_SHALLOW TRUE ) @@ -52,6 +58,7 @@ FetchContent_Declare( utility ####################################################################### FetchContent_MakeAvailable( + leapr ENDFtk dimwits lipservice diff --git a/cmake/release_dependencies.cmake b/cmake/release_dependencies.cmake index 97d52e27..48c92373 100644 --- a/cmake/release_dependencies.cmake +++ b/cmake/release_dependencies.cmake @@ -5,6 +5,11 @@ include( FetchContent ) # Declare project dependencies ####################################################################### +FetchContent_Declare( leapr + GIT_REPOSITORY https://github.com/njoy/leapr + GIT_TAG ff2a1fa90f28e29b5eda100428c35150d1ff89f7 + ) + FetchContent_Declare( catch-adapter GIT_REPOSITORY https://github.com/njoy/catch-adapter GIT_TAG fb84b82ebf7a4789aa43cea560680cf745c6ee4f @@ -22,7 +27,7 @@ FetchContent_Declare( disco FetchContent_Declare( ENDFtk GIT_REPOSITORY https://github.com/njoy/ENDFtk - GIT_TAG b6618b396f51e802b7ee19ba529533c27e6ac302 # tag: v0.1.0 + GIT_TAG d72711722a269919321e3f3df8a8b0cfe23ba6c7 ) FetchContent_Declare( hana-adapter @@ -87,6 +92,7 @@ FetchContent_Declare( utility ####################################################################### FetchContent_MakeAvailable( + leapr catch-adapter dimwits disco diff --git a/src/main.cpp b/src/main.cpp index 69394657..308dc19d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,8 +6,9 @@ int main( int argc, char* argv[] ){ try{ Driver driver( argc, argv ); driver(); - } catch( ... ){ - njoy::Log::info( "Error while running NJOY21"); - return 1; + } catch( std::exception& ex ){ + njoy::Log::info( "Error while running NJOY21:"); + njoy::Log::info( "\t{}", ex.what() ); + return 1; } } diff --git a/src/njoy21.hpp b/src/njoy21.hpp index 73aff0ed..0e219410 100644 --- a/src/njoy21.hpp +++ b/src/njoy21.hpp @@ -3,8 +3,6 @@ #include #include - - #include #include #include @@ -12,8 +10,11 @@ #include #include #include +#include +#include + +#include "nlohmann/json.hpp" -#include "ENDFtk.hpp" #include "dimwits.hpp" #include "Log.hpp" #include "utility.hpp" @@ -25,6 +26,7 @@ #pragma GCC diagnostic pop #include "njoy_c.h" +#include "leapr.hpp" namespace njoy{ namespace njoy21{ @@ -40,6 +42,7 @@ struct CommandLine; #include "njoy21/io.hpp" #include "njoy21/interface.hpp" #include "njoy21/legacy.hpp" +#include "njoy21/modern.hpp" #include "njoy21/Version.hpp" } diff --git a/src/njoy21/Driver.hpp b/src/njoy21/Driver.hpp index b194e36a..95f55779 100644 --- a/src/njoy21/Driver.hpp +++ b/src/njoy21/Driver.hpp @@ -3,10 +3,15 @@ class Driver { std::unique_ptr< io::Manager > manager; Queue queue; + nlohmann::json args; - Driver( std::unique_ptr< io::Manager >&& manager, Queue&& queue ) : + Driver( std::unique_ptr< io::Manager >&& manager, + Queue&& queue, + nlohmann::json&& args ) : manager( std::move(manager) ), - queue( std::move(queue) ){} + queue( std::move(queue) ), + args( std::move( args ) ) + {} #include "njoy21/Driver/Factory.hpp" diff --git a/src/njoy21/Driver/Factory.hpp b/src/njoy21/Driver/Factory.hpp index 017257ba..c6240d5b 100644 --- a/src/njoy21/Driver/Factory.hpp +++ b/src/njoy21/Driver/Factory.hpp @@ -7,21 +7,13 @@ class Factory { #include "njoy21/Driver/Factory/src/setupManager.hpp" #include "njoy21/Driver/Factory/src/setupLegacyDirectory.hpp" + #include "njoy21/Driver/Factory/src/setupModernDirectory.hpp" - static Directory setupModernDirectory( CommandLine& commandLine ){ - return ( commandLine.legacySwitch ) ? Directory() : Directory(); - } - - template< typename First, typename Second, typename... Args > - static void cycle( First&& first, Second&& second, Args&... args ){ - while ( first( args... ) and second( args... ) ){} - } - public: Factory( int argc, char* argv[] ) : commandLine( argc, argv ), - manager( std::make_unique< io::Manager > - ( setupManager( this->commandLine ) ) ), + manager( + std::make_unique< io::Manager > ( setupManager( this->commandLine ) ) ), legacy( setupLegacyDirectory( this->commandLine ) ), modern( setupModernDirectory( this->commandLine ) ){} diff --git a/src/njoy21/Driver/Factory/src/callOperator.hpp b/src/njoy21/Driver/Factory/src/callOperator.hpp index cac23074..bc0b22c5 100644 --- a/src/njoy21/Driver/Factory/src/callOperator.hpp +++ b/src/njoy21/Driver/Factory/src/callOperator.hpp @@ -1,16 +1,21 @@ Driver operator()(){ + + // For passing arbitrary arguments to modules + auto args = nlohmann::json::object(); + auto outputPair = this->manager->output( - static_cast(nullptr) ); + static_cast< modern::Sequence*>(nullptr) ); const auto& output = outputPair.first; // const auto& error = outputPair.second; (*output) << banner; output->flush(); legacy::Sequence::Factory legacyFactory( *(this->manager), this->legacy ); - legacy::Sequence::Factory modernFactory( *(this->manager), this->modern ); //placeholder + modern::Sequence::Factory modernFactory( *(this->manager), this->modern ); auto makeProcessor = []( auto& set, auto& factory ){ return [&]( auto& label, auto& queue ){ + // If the label is among the allowed modules in factory if ( set.count(label) ){ queue.push( factory( label ) ); return true; @@ -20,12 +25,16 @@ Driver operator()(){ }; auto legacyProcessor = makeProcessor( this->legacy, legacyFactory ); auto modernProcessor = makeProcessor( this->modern, modernFactory ); - Queue queue; + + Queue queue; auto label = lipservice::Label::extract( manager->input() ); + auto cycle = [&]( auto& first, auto& second ){ + while( first( label, queue ) and second( label, queue ) ){ } + }; this->legacy.count( label ) ? - cycle( legacyProcessor, modernProcessor, label, queue ) : - cycle( modernProcessor, legacyProcessor, label, queue ); + cycle( legacyProcessor, modernProcessor ) : + cycle( modernProcessor, legacyProcessor ); if ( label != "STOP" ){ Log::error( "Unrecognized routine label on line {}", @@ -35,5 +44,8 @@ Driver operator()(){ } if ( this->commandLine.verifyOnly ){ queue = Queue(); } - return Driver( std::move(this->manager), std::move(queue) ); + + return Driver( std::move( this->manager ), + std::move( queue ), + std::move( args ) ); } diff --git a/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp b/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp index 738a7128..7577bde7 100644 --- a/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp +++ b/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp @@ -2,7 +2,7 @@ static Directory setupLegacyDirectory( CommandLine& commandLine ){ return ( commandLine.legacySwitch ) ? Directory( { "MODER", "RECONR", "BROADR", "PURR", "UNRESR", "ACER", "GASPR", "HEATR", "GROUPR", "VIEWR", "MIXR", "DTFR", - "THERMR", "LEAPR", "RESXSR", "MATXSR", "GAMINR", "PLOTR", + "THERMR", "RESXSR", "MATXSR", "GAMINR", "PLOTR", "COVR", "WIMSR", "POWR", "CCCCR", "ERRORR" } ): Directory( { "MODER", "RECONR", "BROADR", "PURR", "UNRESR", "ACER", "GASPR", "HEATR", "GROUPR", "VIEWR", "MIXR", "DTFR", diff --git a/src/njoy21/Driver/Factory/src/setupManager.hpp b/src/njoy21/Driver/Factory/src/setupManager.hpp index 205c1d14..1216b541 100644 --- a/src/njoy21/Driver/Factory/src/setupManager.hpp +++ b/src/njoy21/Driver/Factory/src/setupManager.hpp @@ -1,14 +1,9 @@ static io::Manager setupManager( CommandLine& commandLine ){ io::Manager::Builder builder; - if ( commandLine.inputPath ){ - builder.input( *(commandLine.inputPath) ); - } - if ( commandLine.outputPath ){ - builder.output( *(commandLine.outputPath) ); - } - if ( commandLine.errorPath ){ - builder.error( *(commandLine.errorPath) ); - } + if ( commandLine.inputPath ){ builder.input( *(commandLine.inputPath) ); } + if ( commandLine.outputPath ){ builder.output( *(commandLine.outputPath) ); } + if ( commandLine.errorPath ){ builder.error( *(commandLine.errorPath) ); } + return builder.construct(); } diff --git a/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp b/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp new file mode 100644 index 00000000..4f364919 --- /dev/null +++ b/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp @@ -0,0 +1,5 @@ +static Directory setupModernDirectory( CommandLine& commandLine ){ + return ( commandLine.legacySwitch ) ? + Directory() : + Directory( { "LEAPR" } ); +} diff --git a/src/njoy21/Driver/src/callOperator.hpp b/src/njoy21/Driver/src/callOperator.hpp index 28988ee7..4aa51ece 100644 --- a/src/njoy21/Driver/src/callOperator.hpp +++ b/src/njoy21/Driver/src/callOperator.hpp @@ -1,7 +1,7 @@ void operator()(){ while ( this->queue.size() ){ auto& routine = *( this->queue.front() ); - routine(); + routine( this->args ); this->queue.pop(); } } diff --git a/src/njoy21/Driver/test/Driver.test.cpp b/src/njoy21/Driver/test/Driver.test.cpp index f4dfbe03..3a74cc51 100644 --- a/src/njoy21/Driver/test/Driver.test.cpp +++ b/src/njoy21/Driver/test/Driver.test.cpp @@ -13,8 +13,8 @@ using namespace njoy::njoy21; SCENARIO("run a simple njoy problem"){ { - std::vector< std::string > args = - { "./njoy21", "--input", "input.txt", "--output", "output.txt" }; + std::vector< std::string > args = { + "./njoy21", "--input", "input.njoy", "--output", "output.txt" }; Driver driver( args.size(), argv(args) ); driver(); } diff --git a/src/njoy21/Driver/test/resources/input.txt b/src/njoy21/Driver/test/resources/input.njoy similarity index 100% rename from src/njoy21/Driver/test/resources/input.txt rename to src/njoy21/Driver/test/resources/input.njoy diff --git a/src/njoy21/Driver/test/resources/tape20 b/src/njoy21/Driver/test/resources/tape20 old mode 100755 new mode 100644 diff --git a/src/njoy21/Sequence.hpp b/src/njoy21/Sequence.hpp deleted file mode 100644 index 556ca467..00000000 --- a/src/njoy21/Sequence.hpp +++ /dev/null @@ -1,179 +0,0 @@ -namespace interface { - -struct Routine { - - struct Sequence { - virtual ~Sequence() = default; - virtual void operator()() = 0; - }; - - virtual ~Routine() = default; - virtual void operator()() = 0; -}; - -} - -namespace legacy { - -struct Sequence : public interface::Routine::Sequence { -protected: - -#define DEFINE_ROUTINE( MODULE ) \ - struct MODULE : public interface::Routine { \ - template< typename Char > \ - MODULE( iRecordStream< Char >& input ){ lipservice::MODULE commands( input ); } \ - void operator()(){ ::MODULE(); } \ - }; - - DEFINE_ROUTINE( MODER ) - DEFINE_ROUTINE( RECONR ) - DEFINE_ROUTINE( BROADR ) - DEFINE_ROUTINE( PURR ) - DEFINE_ROUTINE( UNRESR ) - DEFINE_ROUTINE( ACER ) - DEFINE_ROUTINE( GASPR ) - DEFINE_ROUTINE( HEATR ) - DEFINE_ROUTINE( GROUPR ) - DEFINE_ROUTINE( VIEWR ) - DEFINE_ROUTINE( MIXR ) - DEFINE_ROUTINE( DTFR ) - DEFINE_ROUTINE( THERMR ) - DEFINE_ROUTINE( LEAPR ) - DEFINE_ROUTINE( RESXSR ) - DEFINE_ROUTINE( MATXSR ) - DEFINE_ROUTINE( GAMINR ) - DEFINE_ROUTINE( PLOTR ) - DEFINE_ROUTINE( COVR ) - DEFINE_ROUTINE( WIMSR ) - DEFINE_ROUTINE( POWR ) - DEFINE_ROUTINE( CCCCR ) - DEFINE_ROUTINE( ERRORR ) -#define DEFINE_ROUTINE - - std::vector< std::unique_ptr< interface::Routine > > sequence; - Sequence( std::vector< std::unique_ptr< interface::Routine > >&& sequence ) : - sequence( std::move(sequence) ){} - -public: - struct Factory { - protected: - - template< typename Char> - using parser = - std::function - < std::unique_ptr< interface::Routine >( iRecordStream< Char >& ) >; - - std::unordered_set< std::string >& permittedRoutines; - - template< typename Char > - std::unique_ptr< interface::Routine > - parse( std::string& label, iRecordStream< Char >& input ){ - static const std::unordered_map< std::string, parser > parserMap - { std::make_pair< std::string, parser > - ( "MODER", - []( auto& inputStream ) - { return std::make_unique< MODER >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "RECONR", - []( auto& inputStream ) - { return std::make_unique< RECONR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "BROADR", - []( auto& inputStream ) - { return std::make_unique< BROADR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "PURR", - []( auto& inputStream ) - { return std::make_unique< PURR >( inputStream ); } ) }; - std::make_pair< std::string, parser > - ( "UNRESR", - []( auto& inputStream ) - { return std::make_unique< UNRESR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "ACER", - []( auto& inputStream ) - { return std::make_unique< ACER >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "GASPR", - []( auto& inputStream ) - { return std::make_unique< GASPR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "HEATR", - []( auto& inputStream ) - { return std::make_unique< HEATR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "GROUPR", - []( auto& inputStream ) - { return std::make_unique< GROUPR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "VIEWR", - []( auto& inputStream ) - { return std::make_unique< VIEWR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "MIXR", - []( auto& inputStream ) - { return std::make_unique< MIXR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "DTFR", - []( auto& inputStream ) - { return std::make_unique< DTFR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "THERMR", - []( auto& inputStream ) - { return std::make_unique< THERMR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "LEAPR", - []( auto& inputStream ) - { return std::make_unique< LEAPR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "RESXSR", - []( auto& inputStream ) - { return std::make_unique< RESXSR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "MATXSR", - []( auto& inputStream ) - { return std::make_unique< MATXSR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "GAMINR", - []( auto& inputStream ) - { return std::make_unique< GAMINR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "PLOTR", - []( auto& inputStream ) - { return std::make_unique< PLOTR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "COVR", - []( auto& inputStream ) - { return std::make_unique< COVR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "WIMSR", - []( auto& inputStream ) - { return std::make_unique< WIMSR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "POWR", - []( auto& inputStream ) - { return std::make_unique< POWR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "CCCCR", - []( auto& inputStream ) - { return std::make_unique< CCCCR >( inputStream ); } ), - std::make_pair< std::string, parser > - ( "ERRORR", - []( auto& inputStream ) - { return std::make_unique< ERRORR >( inputStream ); } ), - std::make_pair< std::string, parser > - return parserMap[label]( input ); - } - - public: - Factory( std::unordered_set< std::string >& permittedRoutines ) : - permittedRoutines( permittedRoutines ) {} - - template< typename Char > - std::unique_ptr< interface::Routine::Sequence > - operator()( std::string& label, iRecordStream< Char >& input ){ - } - }; - - -}; diff --git a/src/njoy21/interface.hpp b/src/njoy21/interface.hpp index de5d421e..3c3f8025 100644 --- a/src/njoy21/interface.hpp +++ b/src/njoy21/interface.hpp @@ -4,11 +4,28 @@ struct Routine { struct Sequence { virtual ~Sequence() = default; - virtual void operator()() = 0; + + /* + * Passing a JSON object is intended to give us the flexibility to pass + * whatever arguments we wish in the future. It is the responsibility of the + * underlying module to determine if they want to do anything with those + * arguments. + + * Perhaps this shoud be a variadic template instead of passing a genric + * JSON object + */ + virtual void operator()( const nlohmann::json& ) = 0; }; + std::string name_; + Routine( const std::string& name ): + name_( name ) + {} + virtual ~Routine() = default; - virtual void operator()() = 0; + virtual void operator()( std::ostream&, std::ostream&, + const nlohmann::json& ) = 0; + const std::string name() const { return this->name_; } }; } diff --git a/src/njoy21/legacy/Sequence.hpp b/src/njoy21/legacy/Sequence.hpp index 20559642..6b4d721a 100644 --- a/src/njoy21/legacy/Sequence.hpp +++ b/src/njoy21/legacy/Sequence.hpp @@ -9,14 +9,18 @@ class Sequence : public interface::Routine::Sequence { List sequence; Sequence( io::Manager& manager, List&& sequence ) : - manager( manager ), sequence( std::move(sequence) ){} + manager( manager ), + sequence( std::move(sequence) ) + {} public: #include "njoy21/legacy/Sequence/Factory.hpp" - void operator()(){ - auto fileGaurd = manager.output( this ); - for ( auto& routine : this->sequence ){ (*routine)(); } + void operator()( const nlohmann::json& args ){ + auto fileGuard = manager.output( this ); + for ( auto& routine : this->sequence ){ + (*routine)( std::cout, std::cerr, args ); + } } }; diff --git a/src/njoy21/legacy/Sequence/Factory.hpp b/src/njoy21/legacy/Sequence/Factory.hpp index ca4c9e0e..e319aa6e 100644 --- a/src/njoy21/legacy/Sequence/Factory.hpp +++ b/src/njoy21/legacy/Sequence/Factory.hpp @@ -1,32 +1,14 @@ struct Factory { protected: - using parser = - std::function - < std::unique_ptr< interface::Routine >( lipservice::iRecordStream< char >& ) >; + using parser = std::function < + std::unique_ptr< interface::Routine >( + lipservice::iRecordStream< char >& ) >; io::Manager& manager; std::unordered_set< std::string >& permittedRoutines; - #define PAIR( routine ) \ - std::make_pair< std::string, parser > \ - ( #routine, \ - []( lipservice::iRecordStream< char >& inputStream ) -> std::unique_ptr< interface::Routine > \ - { return std::make_unique< routine >( inputStream ); } ) - - std::unique_ptr< interface::Routine > - parse( std::string& label, lipservice::iRecordStream< char >& input ){ - static const std::unordered_map< std::string, parser > parserMap = - { PAIR( MODER ), PAIR( RECONR ), PAIR( BROADR ), PAIR( PURR ), - PAIR( UNRESR ), PAIR( ACER ), PAIR( GASPR ), PAIR( HEATR ), - PAIR( GROUPR ), PAIR( VIEWR ), PAIR( MIXR ), PAIR( DTFR ), - PAIR( THERMR ), PAIR( LEAPR ), PAIR( RESXSR ), PAIR( MATXSR ), - PAIR( GAMINR ), PAIR( PLOTR ), PAIR( COVR ), PAIR( WIMSR ), - PAIR( POWR ), PAIR( CCCCR ), PAIR( ERRORR ) }; - return parserMap.at( label )( input ); - } - - #undef Pair + #include "njoy21/legacy/Sequence/Factory/src/parse.hpp" public: Factory( io::Manager& manager, @@ -34,29 +16,5 @@ struct Factory { manager( manager ), permittedRoutines( permittedRoutines ){} - std::unique_ptr< interface::Routine::Sequence > - operator()( std::string& label ){ - using TeeBuffer = - utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; - - auto& input = manager.input(); - auto readBuffer = input.rdbuf(); - try { - std::vector< std::unique_ptr< interface::Routine > > sequence; - do { - { - TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); - input.rdbuf( &teeBuffer ); - sequence.push_back( this->parse( label, input ) ); - input.rdbuf( readBuffer ); - } - label = lipservice::Label::extract( input ); - } while ( this->permittedRoutines.count( label ) ); - return std::make_unique< Sequence > - ( Sequence( manager, std::move( sequence ) ) ); - } catch ( std::exception& e ){ - input.rdbuf( readBuffer ); - throw e; - } - } + #include "njoy21/legacy/Sequence/Factory/src/callOperator.hpp" }; diff --git a/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp b/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp new file mode 100644 index 00000000..32121d8d --- /dev/null +++ b/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp @@ -0,0 +1,27 @@ +std::unique_ptr< interface::Routine::Sequence > +operator()( std::string& label ){ + using TeeBuffer = + utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; + + auto& input = manager.input(); + auto readBuffer = input.rdbuf(); + try { + std::vector< std::unique_ptr< interface::Routine > > sequence; + + do { + TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); + input.rdbuf( &teeBuffer ); + sequence.push_back( this->parse( label, input ) ); + input.rdbuf( readBuffer ); + + label = lipservice::Label::extract( input ); + } while ( this->permittedRoutines.count( label ) ); + + return std::make_unique< Sequence >( + Sequence( manager, std::move( sequence ) ) ); + } catch ( std::exception& e ){ + input.rdbuf( readBuffer ); + throw e; + } +} + diff --git a/src/njoy21/legacy/Sequence/Factory/src/parse.hpp b/src/njoy21/legacy/Sequence/Factory/src/parse.hpp new file mode 100644 index 00000000..e7cefefc --- /dev/null +++ b/src/njoy21/legacy/Sequence/Factory/src/parse.hpp @@ -0,0 +1,19 @@ +#define PAIR( routine ) \ + std::make_pair< std::string, parser > \ + ( #routine, \ + []( lipservice::iRecordStream< char >& inputStream ) \ + -> std::unique_ptr< interface::Routine > \ + { return std::make_unique< routine >( inputStream ); } ) + +std::unique_ptr< interface::Routine > +parse( std::string& label, lipservice::iRecordStream< char >& input ){ + static const std::unordered_map< std::string, parser > parserMap = + { PAIR( MODER ), PAIR( RECONR ), PAIR( BROADR ), PAIR( PURR ), + PAIR( UNRESR ), PAIR( ACER ), PAIR( GASPR ), PAIR( HEATR ), + PAIR( GROUPR ), PAIR( VIEWR ), PAIR( MIXR ), PAIR( DTFR ), + PAIR( THERMR ), PAIR( LEAPR ), PAIR( RESXSR ), PAIR( MATXSR ), + PAIR( GAMINR ), PAIR( PLOTR ), PAIR( COVR ), PAIR( WIMSR ), + PAIR( POWR ), PAIR( CCCCR ), PAIR( ERRORR ) }; + return parserMap.at( label )( input ); +} +#undef PAIR diff --git a/src/njoy21/legacy/Sequence/routines.hpp b/src/njoy21/legacy/Sequence/routines.hpp index cf17bc91..a4315fae 100644 --- a/src/njoy21/legacy/Sequence/routines.hpp +++ b/src/njoy21/legacy/Sequence/routines.hpp @@ -1,14 +1,19 @@ template< typename T > static void ignore( T&& ){} -#define DEFINE_ROUTINE( MODULE ) \ +#define DEFINE_ROUTINE( MODULE ) \ struct MODULE : public interface::Routine { \ template< typename Char > \ - MODULE( lipservice::iRecordStream< Char >& stream ){ \ + MODULE( lipservice::iRecordStream< Char >& stream ): \ + interface::Routine( #MODULE ) \ + { \ lipservice::MODULE command( stream ); \ ignore(command); \ } \ - void operator()(){ njoy_c_##MODULE(); } \ + void operator()( std::ostream&, std::ostream&, const nlohmann::json& ){ \ + njoy_c_##MODULE(); \ + } \ + virtual std::string name(){ return #MODULE; } \ }; DEFINE_ROUTINE( MODER ) diff --git a/src/njoy21/modern.hpp b/src/njoy21/modern.hpp new file mode 100644 index 00000000..0943abb4 --- /dev/null +++ b/src/njoy21/modern.hpp @@ -0,0 +1,3 @@ +namespace modern { + #include "njoy21/modern/Sequence.hpp" +} diff --git a/src/njoy21/modern/Sequence.hpp b/src/njoy21/modern/Sequence.hpp new file mode 100644 index 00000000..6077dbcf --- /dev/null +++ b/src/njoy21/modern/Sequence.hpp @@ -0,0 +1,37 @@ +class Sequence : public interface::Routine::Sequence { +protected: +#include "njoy21/modern/Sequence/routines.hpp" + + using List = std::vector< std::unique_ptr< interface::Routine > >; + + /* fields */ + io::Manager& manager; + List sequence; + std::chrono::steady_clock::time_point begin_; + + Sequence( io::Manager& manager, List&& sequence ) : + manager( manager ), + sequence( std::move( sequence ) ), + begin_( std::chrono::steady_clock::now() ) + {} + +public: + + #include "njoy21/modern/Sequence/Factory.hpp" + + void operator()( const nlohmann::json& args ){ + auto fileGuard = manager.output( this ); + + auto& output = *fileGuard.first; + + for ( auto& routine : this->sequence ){ + (*routine)( *fileGuard.first, *fileGuard.second, args ); + + auto timeDiff = std::chrono::duration_cast< std::chrono::milliseconds >( + std::chrono::steady_clock::now() - begin_ ).count() / 1000.0; + + output << fmt::format( "{:s}... {:70.3f} s", routine->name(), timeDiff ) + << std::endl; + } + } +}; diff --git a/src/njoy21/modern/Sequence/Factory.hpp b/src/njoy21/modern/Sequence/Factory.hpp new file mode 100644 index 00000000..1eadb2b8 --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory.hpp @@ -0,0 +1,20 @@ +struct Factory { +protected: + + using parser = std::function < + std::unique_ptr< interface::Routine >( + lipservice::iRecordStream< char >& ) >; + + io::Manager& manager; + const std::unordered_set< std::string > permittedRoutines{ "LEAPR" }; + + #include "njoy21/modern/Sequence/Factory/src/parse.hpp" + +public: + Factory( io::Manager& manager, + std::unordered_set< std::string >& permittedRoutines ) : + manager( manager ), + permittedRoutines( permittedRoutines ){} + + #include "njoy21/modern/Sequence/Factory/src/callOperator.hpp" +}; diff --git a/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp b/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp new file mode 100644 index 00000000..10ceb5a3 --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp @@ -0,0 +1,26 @@ +std::unique_ptr< interface::Routine::Sequence > +operator()( std::string& label ){ + using TeeBuffer = + utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; + + auto& input = manager.input(); + auto readBuffer = input.rdbuf(); + try { + std::vector< std::unique_ptr< interface::Routine > > sequence; + do { + TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); + input.rdbuf( &teeBuffer ); + sequence.push_back( this->parse( label, input ) ); + input.rdbuf( readBuffer ); + + label = lipservice::Label::extract( input ); + } while ( this->permittedRoutines.count( label ) ); + + return std::make_unique< Sequence > + ( Sequence( manager, std::move( sequence ) ) ); + } catch ( std::exception& e ){ + input.rdbuf( readBuffer ); + throw e; + } +} + diff --git a/src/njoy21/modern/Sequence/Factory/src/parse.hpp b/src/njoy21/modern/Sequence/Factory/src/parse.hpp new file mode 100644 index 00000000..5743a491 --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory/src/parse.hpp @@ -0,0 +1,15 @@ +#define PAIR( routine ) \ +std::make_pair< std::string, parser > \ +( #routine, \ + []( lipservice::iRecordStream< char >& inputStream ) \ + -> std::unique_ptr< interface::Routine > \ + { return std::make_unique< routine >( inputStream ); } ) + +std::unique_ptr< interface::Routine > +parse( std::string& label, lipservice::iRecordStream< char >& input ){ + static const std::unordered_map< std::string, parser > parserMap = + { PAIR( LEAPR ) }; + + return parserMap.at( label )( input ); +} +#undef PAIR diff --git a/src/njoy21/modern/Sequence/routines.hpp b/src/njoy21/modern/Sequence/routines.hpp new file mode 100644 index 00000000..02a21783 --- /dev/null +++ b/src/njoy21/modern/Sequence/routines.hpp @@ -0,0 +1,24 @@ +#define DEFINE_ROUTINE( MODULE ) \ + struct MODULE : public interface::Routine { \ + nlohmann::json j##MODULE; \ + \ + template< typename Char > \ + MODULE( lipservice::iRecordStream< Char >& stream ): \ + interface::Routine( #MODULE ) \ + { \ + lipservice::MODULE command( stream ); \ + this->j##MODULE = command; \ + } \ + void operator()( std::ostream& output, \ + std::ostream& error, \ + const nlohmann::json& args ){ \ + njoy::MODULE::MODULE{}( std::move( this->j##MODULE ), \ + output, error, \ + args ); \ + } \ + virtual std::string name(){ return #MODULE; } \ + }; + + //DEFINE_ROUTINE( RECONR ) + DEFINE_ROUTINE( LEAPR ) +#undef DEFINE_ROUTINE diff --git a/src/njoy21/modern/Sequence/test/CMakeLists.txt b/src/njoy21/modern/Sequence/test/CMakeLists.txt new file mode 100644 index 00000000..e52e1725 --- /dev/null +++ b/src/njoy21/modern/Sequence/test/CMakeLists.txt @@ -0,0 +1,22 @@ + +add_executable( njoy21.modern.Sequence.test Sequence.test.cpp ) +target_compile_options( njoy21.modern.Sequence.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${njoy21_appended_flags} ) +target_link_libraries( njoy21.modern.Sequence.test + PUBLIC ENDFtk + PUBLIC RECONR + PUBLIC tclap-adapter + PUBLIC njoy_c_bindings + PUBLIC lipservice + PUBLIC dimwits + PUBLIC utility + ) +add_test( NAME njoy21.modern.Sequence COMMAND njoy21.modern.Sequence.test ) diff --git a/src/njoy21/modern/Sequence/test/Sequence.test.cpp b/src/njoy21/modern/Sequence/test/Sequence.test.cpp new file mode 100644 index 00000000..314c5fb5 --- /dev/null +++ b/src/njoy21/modern/Sequence/test/Sequence.test.cpp @@ -0,0 +1,41 @@ +#define CATCH_CONFIG_MAIN + +#include + +#include "catch.hpp" +#include "njoy21.hpp" + +using namespace njoy::njoy21; + +SCENARIO( "Modern Sequence can be constructed" ){ + + std::string reconrInput( + " 21 22\n" + "'This is a sample Card2'\n" + " 1306 0 0\n" + "0.005 0 0.1 5e-07\n" + "0/\n" ); + + std::istringstream mockInput( reconrInput + "GROUPR\n" ); + + auto cin_buffer = std::cin.rdbuf(); + std::cin.rdbuf( mockInput.rdbuf() ); + + auto manager = io::Manager::Builder().construct(); + + std::ostringstream mockBuffer; + auto buffer_buffer = manager.buffer().rdbuf(); + manager.buffer().rdbuf( mockBuffer.rdbuf() ); + + std::unordered_set< std::string > permittedRoutines = { "RECONR" }; + std::string label("RECONR"); + + modern::Sequence::Factory myFactory( manager, permittedRoutines ); + auto mySequence = myFactory( label ); + + CHECK( label == "GROUPR" ); + CHECK( mockBuffer.str() == reconrInput ); + + std::cin.rdbuf( cin_buffer ); + manager.buffer().rdbuf( buffer_buffer ); +} From 8276b74517c32d40b82080633abdaecdca26de45 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Thu, 21 Jan 2021 13:47:34 -0700 Subject: [PATCH 4/6] Moving find python package CMake command. --- CMakeLists.txt | 2 -- src/njoy21.hpp | 2 ++ tests/CMakeLists.txt | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d4f405e..b46e4d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,6 @@ enable_language( Fortran ) # Project-wide setup ######################################################################## -find_package( Python3 3.5 REQUIRED ) - set( CMAKE_CXX_STANDARD 17 ) set( CMAKE_CXX_STANDARD_REQUIRED YES ) diff --git a/src/njoy21.hpp b/src/njoy21.hpp index 0e219410..e078a1b8 100644 --- a/src/njoy21.hpp +++ b/src/njoy21.hpp @@ -21,7 +21,9 @@ #pragma GCC diagnostic push +#if !defined( __clang__ ) #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #include "lipservice.hpp" #pragma GCC diagnostic pop diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8cf5f1fb..955f9919 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,7 @@ set( RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/resources" ) +find_package( Python3 3.5 REQUIRED ) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/execute.py" "${CMAKE_CURRENT_BINARY_DIR}/execute.py" COPYONLY ) From 5c8954c1b91be87fab94a7a36b8cfe9508caccf7 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Fri, 22 Jan 2021 11:36:21 -0700 Subject: [PATCH 5/6] Updating the execute script for the regression tets --- tests/execute.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/execute.py b/tests/execute.py index d359c867..4f15dba4 100644 --- a/tests/execute.py +++ b/tests/execute.py @@ -5,6 +5,7 @@ import os import re import subprocess +from math import isclose floatPattern = re.compile("""( @@ -45,8 +46,9 @@ def lineEquivalence(ref, trial, n, relativeError=1E-9, absoluteError=1E-10): else: # Look at all the floats on the lines for rF, tF in zip(refFloats, trialFloats): - equal = fuzzyDiff(makeFloat(rF), makeFloat(tF), - relativeError, absoluteError) + equal = isclose( makeFloat(rF), makeFloat(tF), + rel_tol = relativeError, + abs_tol = absoluteError ) if not equal: print("{} and {} are not equal".format( rF[0], tF[0])) @@ -82,6 +84,7 @@ def identicalLines(refLines, trialLines, diffFile, for n, (ref, trial) in enumerate(zip(refLines, trialLines)): equivalent = lineEquivalence(ref, trial, n, relativeError, absoluteError) + if not equivalent: fullEquivalence = False writeDiff(diffFile, ref, trial, n) @@ -112,15 +115,6 @@ def writeDiff(diff_file, refLine, trialLine, lineNumber): diff_file.write("!{}".format(trialLine)) -def fuzzyDiff(a, b, relativeError=1E-9, absoluteError=1E-10): - """ - fuzzDiff will compare to numbers (a and b) to see if they are identical - within the given tolerance. Returns bool. - """ - delta = max(abs(a), abs(b))*relativeError + absoluteError - return (abs(a - b) <= abs(delta)) - - retained_tapes = set(glob.glob('tape*')) reference_tapes = glob.glob('referenceTape*') @@ -152,7 +146,7 @@ def fuzzyDiff(a, b, relativeError=1E-9, absoluteError=1E-10): diff_file.write("--- {} ---\n".format(trial_tape)) identical = identicalLines( - reference_lines, trial_lines, diff_file, 1E-9, 1E-7) + reference_lines, trial_lines, diff_file, 1E-9, 1e-10) should_exit = not identical if should_exit: From 3fba4f33215768f3ad98d400efde4c24213c8595 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Fri, 22 Jan 2021 16:23:10 -0700 Subject: [PATCH 6/6] Starting release notes for v1.3.0. --- ReleaseNotes.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index f8da85c7..020384c2 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,6 +1,20 @@ # Release Notes—NJOY21 Given here are some release notes for NJOY21. Each release is made through a formal [Pull Request](https://github.com/njoy/NJOY21/pulls) made on GitHub. There are links in this document that point to each of those Pull Requests, where you can see in great details the changes that were made. Often the Pull Requests are made in response to an [issue](https://github.com/njoy/NJOY21/issues). In such cases, links to those issues are also given. +## [NJOY21 1.3.0](https://github.com/njoy/NJOY21/pull/143) + +### LEAPR +See [Pull Request #127](https://github.com/njoy/NJOY21/pull/127) + +### RECONR +See [Pull Request #118](https://github.com/njoy/NJOY21/pull/118) + +### THERMR +See [Pull Request #144](https://github.com/njoy/NJOY21/pull/144) + +### Regression Tests +There are a number of [regression tests](https://www.njoy21.io/NJOY2016/testDescription.html) with NJOY21. These are the same as used in NJOY2016. Some of them are no longer valid with NJOY21. With NJOY21, features that are not included in ENDF/B-VII.0 or later, are not going to be supported in NJOY21. There are some regression tests that are no going to be supported in NJOY21. They are: + ## [NJOY21 1.2.2](https://github.com/njoy/NJOY21/pull/142) - Updating Legacy NJOY to NJOY2016.61. See [release 2016.61](https://github.com/njoy/NJOY2016/releases/tag/2016.61) for more information - Adding additional regression tests.