From 9f0600856530b16c4762e774cdc6ad5d545a8436 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 4 Feb 2019 22:51:25 -0600 Subject: [PATCH] Translate several functions in output.F90 to C++ --- include/openmc/output.h | 40 +++++--- src/initialize.cpp | 2 - src/input_xml.F90 | 1 - src/output.F90 | 206 ---------------------------------------- src/output.cpp | 170 +++++++++++++++++++++++++++++++-- src/simulation.cpp | 3 - 6 files changed, 191 insertions(+), 231 deletions(-) diff --git a/include/openmc/output.h b/include/openmc/output.h index 6c8226c65..5c7ebcd59 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -10,42 +10,56 @@ namespace openmc { -//============================================================================== +//! \brief Display the main title banner as well as information about the +//! program developers, version, and date/time which the problem was run. + +void title(); + //! Display a header block. -//! +// //! \param msg The main text of the header //! \param level The lowest verbosity level at which this header is printed -//============================================================================== void header(const char* msg, int level); -//============================================================================== //! Retrieve a time stamp. -//! +// //! \return current time stamp (format: "yyyy-mm-dd hh:mm:ss") -//============================================================================== std::string time_stamp(); -//============================================================================== //! Display the attributes of a particle. -//============================================================================== extern "C" void print_particle(Particle* p); -//============================================================================== //! Display plot information. -//============================================================================== void print_plot(); -//============================================================================== //! Display information regarding cell overlap checking. -//============================================================================== void print_overlap_check(); -extern "C" void title(); +//! Display information about command line usage of OpenMC + +void print_usage(); + +//! Display current version and copright/license information + +void print_version(); + +//! Display header listing what physical values will displayed + +void print_columns(); + +//! Display information about a generation of neutrons + +void print_generation(); + +//! \brief Display last batch's tallied value of the neutron multiplication +//! factor as well as the average value if we're in active batches + +void print_batch_keff(); } // namespace openmc #endif // OPENMC_OUTPUT_H diff --git a/src/initialize.cpp b/src/initialize.cpp index 69986fdc0..e454917d0 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -30,8 +30,6 @@ #include "openmc/timer.h" // data/functions from Fortran side -extern "C" void print_usage(); -extern "C" void print_version(); extern "C" void read_command_line(); extern "C" void read_geometry_xml(); extern "C" void read_materials_xml(); diff --git a/src/input_xml.F90 b/src/input_xml.F90 index d78135d77..1e2a03a45 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -17,7 +17,6 @@ module input_xml use message_passing use mgxs_interface use nuclide_header - use output, only: title, header use photon_header use random_lcg, only: prn use surface_header diff --git a/src/output.F90 b/src/output.F90 index 90d98526e..3f864536f 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -45,73 +45,6 @@ module output contains -!=============================================================================== -! TITLE prints the main title banner as well as information about the program -! developers, version, and date/time which the problem was run. -!=============================================================================== - - subroutine title() bind(C) - -#ifdef _OPENMP - use omp_lib -#endif - - write(UNIT=OUTPUT_UNIT, FMT='(/23(A/))') & - ' %%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%', & - ' %%%%%%%%%%%%%%%%%%%%%%%%', & - ' ############### %%%%%%%%%%%%%%%%%%%%%%%%', & - ' ################## %%%%%%%%%%%%%%%%%%%%%%%', & - ' ################### %%%%%%%%%%%%%%%%%%%%%%%', & - ' #################### %%%%%%%%%%%%%%%%%%%%%%', & - ' ##################### %%%%%%%%%%%%%%%%%%%%%', & - ' ###################### %%%%%%%%%%%%%%%%%%%%', & - ' ####################### %%%%%%%%%%%%%%%%%%', & - ' ####################### %%%%%%%%%%%%%%%%%', & - ' ###################### %%%%%%%%%%%%%%%%%', & - ' #################### %%%%%%%%%%%%%%%%%', & - ' ################# %%%%%%%%%%%%%%%%%', & - ' ############### %%%%%%%%%%%%%%%%', & - ' ############ %%%%%%%%%%%%%%%', & - ' ######## %%%%%%%%%%%%%%', & - ' %%%%%%%%%%%' - - ! Write version information - write(UNIT=OUTPUT_UNIT, FMT=*) & - ' | The OpenMC Monte Carlo Code' - write(UNIT=OUTPUT_UNIT, FMT=*) & - ' Copyright | 2011-2018 MIT and OpenMC contributors' - write(UNIT=OUTPUT_UNIT, FMT=*) & - ' License | http://openmc.readthedocs.io/en/latest/license.html' - write(UNIT=OUTPUT_UNIT, FMT='(11X,"Version | ",I1,".",I2,".",I1)') & - VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE -#ifdef GIT_SHA1 - write(UNIT=OUTPUT_UNIT, FMT='(10X,"Git SHA1 | ",A)') GIT_SHA1 -#endif - - ! Write the date and time - write(UNIT=OUTPUT_UNIT, FMT='(9X,"Date/Time | ",A)') time_stamp() - -#ifdef OPENMC_MPI - ! Write number of processors - write(UNIT=OUTPUT_UNIT, FMT='(5X,"MPI Processes | ",A)') & - trim(to_str(n_procs)) -#endif - -#ifdef _OPENMP - ! Write number of OpenMP threads - write(UNIT=OUTPUT_UNIT, FMT='(4X,"OpenMP Threads | ",A)') & - trim(to_str(omp_get_max_threads())) -#endif - write(UNIT=OUTPUT_UNIT, FMT=*) - - end subroutine title - !=============================================================================== ! TIME_STAMP returns the current date and time in a formatted string !=============================================================================== @@ -166,145 +99,6 @@ contains end subroutine header -!=============================================================================== -! PRINT_VERSION shows the current version as well as copright and license -! information -!=============================================================================== - - subroutine print_version() bind(C) - - if (master) then - write(UNIT=OUTPUT_UNIT, FMT='(1X,A,1X,I1,".",I2,".",I1)') & - "OpenMC version", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE -#ifdef GIT_SHA1 - write(UNIT=OUTPUT_UNIT, FMT='(1X,A,A)') "Git SHA1: ", GIT_SHA1 -#endif - write(UNIT=OUTPUT_UNIT, FMT=*) "Copyright (c) 2011-2018 & - &Massachusetts Institute of Technology and OpenMC contributors" - write(UNIT=OUTPUT_UNIT, FMT=*) "MIT/X license at & - &" - end if - - end subroutine print_version - -!=============================================================================== -! PRINT_USAGE displays information about command line usage of OpenMC -!=============================================================================== - - subroutine print_usage() bind(C) - - if (master) then - write(OUTPUT_UNIT,*) 'Usage: openmc [options] [directory]' - write(OUTPUT_UNIT,*) - write(OUTPUT_UNIT,*) 'Options:' - write(OUTPUT_UNIT,*) ' -c, --volume Run in stochastic volume calculation mode' - write(OUTPUT_UNIT,*) ' -g, --geometry-debug Run with geometry debugging on' - write(OUTPUT_UNIT,*) ' -n, --particles Number of particles per generation' - write(OUTPUT_UNIT,*) ' -p, --plot Run in plotting mode' - write(OUTPUT_UNIT,*) ' -r, --restart Restart a previous run from a state point' - write(OUTPUT_UNIT,*) ' or a particle restart file' - write(OUTPUT_UNIT,*) ' -s, --threads Number of OpenMP threads' - write(OUTPUT_UNIT,*) ' -t, --track Write tracks for all particles' - write(OUTPUT_UNIT,*) ' -v, --version Show version information' - write(OUTPUT_UNIT,*) ' -h, --help Show this message' - end if - - end subroutine print_usage - -!=============================================================================== -! PRINT_COLUMNS displays a header listing what physical values will displayed -! below them -!=============================================================================== - - subroutine print_columns() bind(C) - - write(UNIT=ou, FMT='(2X,A9,3X)', ADVANCE='NO') "Bat./Gen." - write(UNIT=ou, FMT='(A8,3X)', ADVANCE='NO') " k " - if (entropy_on) write(UNIT=ou, FMT='(A8,3X)', ADVANCE='NO') "Entropy " - write(UNIT=ou, FMT='(A20,3X)', ADVANCE='NO') " Average k " - write(UNIT=ou, FMT=*) - - write(UNIT=ou, FMT='(2X,A9,3X)', ADVANCE='NO') "=========" - write(UNIT=ou, FMT='(A8,3X)', ADVANCE='NO') "========" - if (entropy_on) write(UNIT=ou, FMT='(A8,3X)', ADVANCE='NO') "========" - write(UNIT=ou, FMT='(A20,3X)', ADVANCE='NO') "====================" - write(UNIT=ou, FMT=*) - - end subroutine print_columns - -!=============================================================================== -! PRINT_GENERATION displays information for a generation of neutrons. -!=============================================================================== - - subroutine print_generation() bind(C) - - integer :: i ! overall generation - integer :: n ! number of active generations - - ! Determine overall generation and number of active generations - i = overall_generation() - if (current_batch > n_inactive) then - n = gen_per_batch*n_realizations + current_gen - else - n = 0 - end if - - ! write out information about batch and generation - write(UNIT=OUTPUT_UNIT, FMT='(2X,A9)', ADVANCE='NO') & - trim(to_str(current_batch)) // "/" // trim(to_str(current_gen)) - write(UNIT=OUTPUT_UNIT, FMT='(3X,F8.5)', ADVANCE='NO') k_generation(i) - - ! write out entropy info - if (entropy_on) write(UNIT=OUTPUT_UNIT, FMT='(3X, F8.5)', ADVANCE='NO') & - entropy(i) - - if (n > 1) then - write(UNIT=OUTPUT_UNIT, FMT='(3X, F8.5," +/-",F8.5)', ADVANCE='NO') & - keff, keff_std - end if - - ! next line - write(UNIT=OUTPUT_UNIT, FMT=*) - - end subroutine print_generation - -!=============================================================================== -! PRINT_BATCH_KEFF displays the last batch's tallied value of the neutron -! multiplication factor as well as the average value if we're in active batches -!=============================================================================== - - subroutine print_batch_keff() bind(C) - - integer :: i ! overall generation - integer :: n ! number of active generations - - ! Determine overall generation and number of active generations - i = current_batch*gen_per_batch - n = n_realizations*gen_per_batch - - ! write out information batch and option independent output - write(UNIT=OUTPUT_UNIT, FMT='(2X,A9)', ADVANCE='NO') & - trim(to_str(current_batch)) // "/" // trim(to_str(gen_per_batch)) - write(UNIT=OUTPUT_UNIT, FMT='(3X,F8.5)', ADVANCE='NO') & - k_generation(i) - - ! write out entropy info - if (entropy_on) write(UNIT=OUTPUT_UNIT, FMT='(3X, F8.5)', ADVANCE='NO') & - entropy(i) - - ! write out accumulated k-effective if after first active batch - if (n > 1) then - write(UNIT=OUTPUT_UNIT, FMT='(3X, F8.5," +/-",F8.5)', ADVANCE='NO') & - keff, keff_std - else - write(UNIT=OUTPUT_UNIT, FMT='(23X)', ADVANCE='NO') - end if - - ! next line - write(UNIT=OUTPUT_UNIT, FMT=*) - - end subroutine print_batch_keff - !=============================================================================== ! PRINT_RUNTIME displays the total time elapsed for the entire run, for ! initialization, for computation, and for intergeneration synchronization. diff --git a/src/output.cpp b/src/output.cpp index 16b96d4be..0c9d35cef 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -7,20 +7,79 @@ #include #include +#include + #include "openmc/capi.h" #include "openmc/cell.h" #include "openmc/constants.h" +#include "openmc/eigenvalue.h" #include "openmc/geometry.h" #include "openmc/lattice.h" #include "openmc/message_passing.h" #include "openmc/plot.h" #include "openmc/settings.h" +#include "openmc/simulation.h" #include "openmc/surface.h" namespace openmc { //============================================================================== +void title() +{ + std::cout << + " %%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%%%%%%%%%%%%%%\n" << + " ############### %%%%%%%%%%%%%%%%%%%%%%%%\n" << + " ################## %%%%%%%%%%%%%%%%%%%%%%%\n" << + " ################### %%%%%%%%%%%%%%%%%%%%%%%\n" << + " #################### %%%%%%%%%%%%%%%%%%%%%%\n" << + " ##################### %%%%%%%%%%%%%%%%%%%%%\n" << + " ###################### %%%%%%%%%%%%%%%%%%%%\n" << + " ####################### %%%%%%%%%%%%%%%%%%\n" << + " ####################### %%%%%%%%%%%%%%%%%\n" << + " ###################### %%%%%%%%%%%%%%%%%\n" << + " #################### %%%%%%%%%%%%%%%%%\n" << + " ################# %%%%%%%%%%%%%%%%%\n" << + " ############### %%%%%%%%%%%%%%%%\n" << + " ############ %%%%%%%%%%%%%%%\n" << + " ######## %%%%%%%%%%%%%%\n" << + " %%%%%%%%%%%\n"; + + // Write version information + std::cout << + " | The OpenMC Monte Carlo Code\n" << + " Copyright | 2011-2019 MIT and OpenMC contributors\n" << + " License | http://openmc.readthedocs.io/en/latest/license.html\n" << + " Version | " << VERSION_MAJOR << '.' << VERSION_MINOR << '.' + << VERSION_RELEASE << '\n'; +#ifdef GIT_SHA1 + std::cout << " Git SHA1 | " << GIT_SHA1 << '\n'; +#endif + + // Write the date and time + std::cout << " Date/Time | " << time_stamp() << '\n'; + +#ifdef OPENMC_MPI + // Write number of processors + std::cout << " MPI Processes | " << mpi::n_procs << '\n'; +#endif + +#ifdef _OPENMP + // Write number of OpenMP threads + std::cout << " OpenMC Threads | " << omp_get_max_threads() << '\n'; +#endif + std::cout << '\n'; +} + +//============================================================================== + void header(const char* msg, int level) { // Determine how many times to repeat the '=' character. @@ -49,13 +108,9 @@ header(const char* msg, int level) { std::string time_stamp() { - int base_year = 1990; std::stringstream ts; - std::time_t t = std::time(0); // get time now - std::tm* now = std::localtime(&t); - ts << now->tm_year + base_year << "-" << now->tm_mon - << "-" << now->tm_mday << " " << now->tm_hour - << ":" << now->tm_min << ":" << now->tm_sec; + std::time_t t = std::time(nullptr); // get time now + ts << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S"); return ts.str(); } @@ -230,4 +285,107 @@ print_overlap_check() } } +//============================================================================== + +void print_usage() +{ + if (mpi::master) { + std::cout << + "Usage: openmc [options] [directory]\n\n" + "Options:\n" + " -c, --volume Run in stochastic volume calculation mode\n" + " -g, --geometry-debug Run with geometry debugging on\n" + " -n, --particles Number of particles per generation\n" + " -p, --plot Run in plotting mode\n" + " -r, --restart Restart a previous run from a state point\n" + " or a particle restart file\n" + " -s, --threads Number of OpenMP threads\n" + " -t, --track Write tracks for all particles\n" + " -v, --version Show version information\n" + " -h, --help Show this message\n"; + } +} + +//============================================================================== + +void print_version() +{ + if (mpi::master) { + std::cout << "OpenMC version " << VERSION_MAJOR << '.' << VERSION_MINOR + << '.' << VERSION_RELEASE << '\n'; +#ifdef GIT_SHA1 + std::cout << "Git SHA1: " << GIT_SHA1 << '\n'; +#endif + std::cout << "Copyright (c) 2011-2019 Massachusetts Institute of " + "Technology and OpenMC contributors\nMIT/X license at " + "\n"; + } +} + +//============================================================================== + +void print_columns() +{ + if (settings::entropy_on) { + std::cout << + " Bat./Gen. k Entropy Average k \n" + " ========= ======== ======== ====================\n"; + } else { + std::cout << + " Bat./Gen. k Average k\n" + " ========= ======== ====================\n"; + } +} + +//============================================================================== + +void print_generation() +{ + // Determine overall generation and number of active generations + int i = overall_generation() - 1; + int n = simulation::current_batch > settings::n_inactive ? + settings::gen_per_batch*n_realizations + simulation::current_gen : 0; + + // write out information batch and option independent output + std::cout << " " << std::setw(9) << std::to_string(simulation::current_batch) + + "/" + std::to_string(simulation::current_gen) << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::k_generation[i]; + + // write out entropy info + if (settings::entropy_on) std::cout << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::entropy[i]; + + if (n > 1) { + std::cout << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::keff << " +/-" << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::keff_std; + } + std::cout << '\n'; +} + +//============================================================================== + +void print_batch_keff() +{ + // Determine overall generation and number of active generations + int i = simulation::current_batch*settings::gen_per_batch - 1; + int n = n_realizations*settings::gen_per_batch; + + // write out information batch and option independent output + std::cout << " " << std::setw(9) << std::to_string(simulation::current_batch) + + "/" + std::to_string(settings::gen_per_batch) << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::k_generation[i]; + + // write out entropy info + if (settings::entropy_on) std::cout << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::entropy[i]; + + if (n > 1) { + std::cout << " " << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::keff << " +/-" << + std::fixed << std::setw(8) << std::setprecision(5) << simulation::keff_std; + } + std::cout << '\n'; +} + } // namespace openmc diff --git a/src/simulation.cpp b/src/simulation.cpp index dd1a2c2a7..7f4f0dc03 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -31,9 +31,6 @@ extern "C" void allocate_tally_results(); extern "C" void check_triggers(); extern "C" void init_tally_routines(); extern "C" void load_state_point(); -extern "C" void print_batch_keff(); -extern "C" void print_columns(); -extern "C" void print_generation(); extern "C" void print_results(); extern "C" void print_runtime(); extern "C" void setup_active_tallies();