From faf35d21bcd4b7e8163aa261e5a44ae948e25748 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 12 Apr 2018 07:45:47 -0500 Subject: [PATCH] Move openmc_run to C++ side --- CMakeLists.txt | 5 ++--- src/api.F90 | 1 - src/simulation.F90 | 20 -------------------- src/simulation.cpp | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 src/simulation.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 81c16aa48..d246cf57c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,6 +440,7 @@ set(LIBOPENMC_CXX_SRC src/hdf5_interface.h src/random_lcg.cpp src/random_lcg.h + src/simulation.cpp src/surface.cpp src/surface.h src/xml_interface.h @@ -447,9 +448,7 @@ set(LIBOPENMC_CXX_SRC src/pugixml/pugixml.hpp) add_library(libopenmc SHARED ${LIBOPENMC_FORTRAN_SRC} ${LIBOPENMC_CXX_SRC}) set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc) - add_executable(${program} src/main.cpp) -target_include_directories(${program} PUBLIC include) #=============================================================================== # Add compiler/linker flags @@ -458,7 +457,7 @@ target_include_directories(${program} PUBLIC include) set_property(TARGET ${program} libopenmc pugixml_fortran PROPERTY LINKER_LANGUAGE Fortran) -target_include_directories(libopenmc PUBLIC ${HDF5_INCLUDE_DIRS}) +target_include_directories(libopenmc PUBLIC include ${HDF5_INCLUDE_DIRS}) # The executable and the faddeeva package use only one language. They can be # set via target_compile_options which accepts a list. diff --git a/src/api.F90 b/src/api.F90 index df183c292..d7f3ed023 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -80,7 +80,6 @@ module openmc_api public :: openmc_nuclide_name public :: openmc_plot_geometry public :: openmc_reset - public :: openmc_run public :: openmc_set_seed public :: openmc_simulation_finalize public :: openmc_simulation_init diff --git a/src/simulation.F90 b/src/simulation.F90 index 68debe52b..e9729df03 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -44,7 +44,6 @@ module simulation implicit none private public :: openmc_next_batch - public :: openmc_run public :: openmc_simulation_init public :: openmc_simulation_finalize @@ -54,25 +53,6 @@ module simulation contains -!=============================================================================== -! OPENMC_RUN encompasses all the main logic where iterations are performed -! over the batches, generations, and histories in a fixed source or k-eigenvalue -! calculation. -!=============================================================================== - - function openmc_run() result(err) bind(C) - integer(C_INT) :: err - integer(C_INT) :: status - - call openmc_simulation_init() - do - err = openmc_next_batch(status) - if (status /= 0 .or. err < 0) exit - end do - call openmc_simulation_finalize() - - end function openmc_run - !=============================================================================== ! OPENMC_NEXT_BATCH !=============================================================================== diff --git a/src/simulation.cpp b/src/simulation.cpp new file mode 100644 index 000000000..e9bf81775 --- /dev/null +++ b/src/simulation.cpp @@ -0,0 +1,18 @@ +#include "openmc.h" + +// OPENMC_RUN encompasses all the main logic where iterations are performed +// over the batches, generations, and histories in a fixed source or k-eigenvalue +// calculation. + +int openmc_run() { + openmc_simulation_init(); + + int err = 0; + int status = 0; + while (status == 0 && err == 0) { + err = openmc_next_batch(&status); + } + + openmc_simulation_finalize(); + return err; +}