Skip to content

Commit

Permalink
Start moving surface->summary.h5 to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
smharper committed Jan 19, 2018
1 parent 7af2969 commit 57991b2
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 251 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ add_definitions(-DMAX_COORD=${maxcoord})
set(MPI_ENABLED FALSE)
if($ENV{FC} MATCHES "(mpi[^/]*|ftn)$")
message("-- Detected MPI wrapper: $ENV{FC}")
add_definitions(-DMPI)
add_definitions(-DOPENMC_MPI)
set(MPI_ENABLED TRUE)
endif()

# Check for Fortran 2008 MPI interface
if(MPI_ENABLED AND mpif08)
message("-- Using Fortran 2008 MPI bindings")
add_definitions(-DMPIF08)
add_definitions(-DOPENMC_MPIF08)
endif()

#===============================================================================
Expand Down Expand Up @@ -435,6 +435,7 @@ set(LIBOPENMC_FORTRAN_SRC
src/tallies/trigger_header.F90
)
set(LIBOPENMC_CXX_SRC
src/hdf5_interface.h
src/random_lcg.h
src/random_lcg.cpp
src/surface_header.C
Expand Down
2 changes: 1 addition & 1 deletion src/api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ subroutine openmc_finalize() bind(C)
! Close FORTRAN interface.
call h5close_f(err)

#ifdef MPI
#ifdef OPENMC_MPI
! Free all MPI types
call MPI_TYPE_FREE(MPI_BANK, err)
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/cmfd_execute.F90
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ subroutine calc_fission_source()
real(8) :: hxyz(3) ! cell dimensions of current ijk cell
real(8) :: vol ! volume of cell
real(8),allocatable :: source(:,:,:,:) ! tmp source array for entropy
#ifdef MPI
#ifdef OPENMC_MPI
integer :: mpi_err ! MPI error code
#endif

Expand Down Expand Up @@ -197,7 +197,7 @@ subroutine calc_fission_source()

end if

#ifdef MPI
#ifdef OPENMC_MPI
! Broadcast full source to all procs
call MPI_BCAST(cmfd % cmfd_src, n, MPI_REAL8, 0, mpi_intracomm, mpi_err)
#endif
Expand Down Expand Up @@ -234,7 +234,7 @@ subroutine cmfd_reweight(new_weights)
real(8) :: norm ! normalization factor
logical :: outside ! any source sites outside mesh
logical :: in_mesh ! source site is inside mesh
#ifdef MPI
#ifdef OPENMC_MPI
integer :: mpi_err
#endif

Expand Down Expand Up @@ -291,7 +291,7 @@ subroutine cmfd_reweight(new_weights)
if (.not. cmfd_feedback) return

! Broadcast weight factors to all procs
#ifdef MPI
#ifdef OPENMC_MPI
call MPI_BCAST(cmfd % weightfactors, ng*nx*ny*nz, MPI_REAL8, 0, &
mpi_intracomm, mpi_err)
#endif
Expand Down
18 changes: 9 additions & 9 deletions src/eigenvalue.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ subroutine synchronize_bank()
type(Bank), save, allocatable :: &
& temp_sites(:) ! local array of extra sites on each node

#ifdef MPI
#ifdef OPENMC_MPI
integer :: mpi_err ! MPI error code
integer(8) :: n ! number of sites to send/recv
integer :: neighbor ! processor to send/recv data from
#ifdef MPIF08
#ifdef OPENMC_MPIF08
type(MPI_Request) :: request(20)
#else
integer :: request(20) ! communication request for send/recving sites
Expand All @@ -66,7 +66,7 @@ subroutine synchronize_bank()
! fission bank its own sites starts in order to ensure reproducibility by
! skipping ahead to the proper seed.

#ifdef MPI
#ifdef OPENMC_MPI
start = 0_8
call MPI_EXSCAN(n_bank, start, 1, MPI_INTEGER8, MPI_SUM, &
mpi_intracomm, mpi_err)
Expand Down Expand Up @@ -148,7 +148,7 @@ subroutine synchronize_bank()
! neighboring processors, we have to perform an ALLGATHER to determine the
! indices for all processors

#ifdef MPI
#ifdef OPENMC_MPI
! First do an exclusive scan to get the starting indices for
start = 0_8
call MPI_EXSCAN(index_temp, start, 1, MPI_INTEGER8, MPI_SUM, &
Expand Down Expand Up @@ -191,7 +191,7 @@ subroutine synchronize_bank()
call time_bank_sample % stop()
call time_bank_sendrecv % start()

#ifdef MPI
#ifdef OPENMC_MPI
! ==========================================================================
! SEND BANK SITES TO NEIGHBORS

Expand Down Expand Up @@ -343,14 +343,14 @@ end subroutine shannon_entropy
subroutine calculate_generation_keff()

real(8) :: keff_reduced
#ifdef MPI
#ifdef OPENMC_MPI
integer :: mpi_err ! MPI error code
#endif

! Get keff for this generation by subtracting off the starting value
keff_generation = global_tallies(RESULT_VALUE, K_TRACKLENGTH) - keff_generation

#ifdef MPI
#ifdef OPENMC_MPI
! Combine values across all processors
call MPI_ALLREDUCE(keff_generation, keff_reduced, 1, MPI_REAL8, &
MPI_SUM, mpi_intracomm, mpi_err)
Expand Down Expand Up @@ -584,7 +584,7 @@ subroutine count_source_for_ufs()

real(8) :: total ! total weight in source bank
logical :: sites_outside ! were there sites outside the ufs mesh?
#ifdef MPI
#ifdef OPENMC_MPI
integer :: n ! total number of ufs mesh cells
integer :: mpi_err ! MPI error code
#endif
Expand All @@ -608,7 +608,7 @@ subroutine count_source_for_ufs()
call fatal_error("Source sites outside of the UFS mesh!")
end if

#ifdef MPI
#ifdef OPENMC_MPI
! Send source fraction to all processors
n = product(m % dimension)
call MPI_BCAST(source_frac, n, MPI_REAL8, 0, mpi_intracomm, mpi_err)
Expand Down
4 changes: 2 additions & 2 deletions src/error.F90
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ subroutine fatal_error(message, error_code)
integer :: line_wrap ! length of line
integer :: length ! length of message
integer :: indent ! length of indentation
#ifdef MPI
#ifdef OPENMC_MPI
integer :: mpi_err
#endif

Expand Down Expand Up @@ -180,7 +180,7 @@ subroutine fatal_error(message, error_code)
end if
end do

#ifdef MPI
#ifdef OPENMC_MPI
! Abort MPI
call MPI_ABORT(mpi_intracomm, code, mpi_err)
#endif
Expand Down
1 change: 0 additions & 1 deletion src/geometry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ subroutine distance_to_boundary(p, dist, surface_crossed, lattice_translation, &
real(8) :: surf_uvw(3) ! surface normal direction
logical :: coincident ! is particle on surface?
type(Cell), pointer :: c
class(Surface), pointer :: surf
class(Lattice), pointer :: lat

! inialize distance to infinity (huge)
Expand Down
4 changes: 2 additions & 2 deletions src/hdf5_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function file_create(filename, parallel) result(file_id)
! Setup file access property list with parallel I/O access
call h5pcreate_f(H5P_FILE_ACCESS_F, plist, hdf5_err)
#ifdef PHDF5
#ifdef MPIF08
#ifdef OPENMC_MPIF08
call h5pset_fapl_mpio_f(plist, mpi_intracomm%MPI_VAL, &
MPI_INFO_NULL%MPI_VAL, hdf5_err)
#else
Expand Down Expand Up @@ -174,7 +174,7 @@ function file_open(filename, mode, parallel) result(file_id)
! Setup file access property list with parallel I/O access
call h5pcreate_f(H5P_FILE_ACCESS_F, plist, hdf5_err)
#ifdef PHDF5
#ifdef MPIF08
#ifdef OPENMC_MPIF08
call h5pset_fapl_mpio_f(plist, mpi_intracomm%MPI_VAL, &
MPI_INFO_NULL%MPI_VAL, hdf5_err)
#else
Expand Down
47 changes: 47 additions & 0 deletions src/hdf5_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef HDF5_INTERFACE_H
#define HDF5_INTERFACE_H

#include <array> // For std::array
#include <string.h> // For strlen

#include "hdf5.h"


template<std::size_t array_len> void
write_double_1D(hid_t group_id, char const *name,
std::array<double, array_len> &buffer)
{
hsize_t dims[1]{array_len};
hid_t dataspace = H5Screate_simple(1, dims, NULL);

hid_t dataset = H5Dcreate(group_id, name, H5T_NATIVE_DOUBLE, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&buffer[0]);

H5Sclose(dataspace);
H5Dclose(dataset);
}


void
write_string(hid_t group_id, char const *name, char const *buffer)
{
size_t buffer_len = strlen(buffer);
hid_t datatype = H5Tcopy(H5T_C_S1);
H5Tset_size(datatype, buffer_len);

hid_t dataspace = H5Screate(H5S_SCALAR);

hid_t dataset = H5Dcreate(group_id, name, datatype, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer);

H5Tclose(datatype);
H5Sclose(dataspace);
H5Dclose(dataset);
}

#endif //HDF5_INTERFACE_H
12 changes: 6 additions & 6 deletions src/initialize.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ subroutine openmc_init(intracomm) bind(C)
! Copy the communicator to a new variable. This is done to avoid changing
! the signature of this subroutine. If MPI is being used but no communicator
! was passed, assume MPI_COMM_WORLD.
#ifdef MPI
#ifdef MPIF08
#ifdef OPENMC_MPI
#ifdef OPENMC_MPIF08
type(MPI_Comm), intent(in) :: comm ! MPI intracommunicator
if (present(intracomm)) then
comm % MPI_VAL = intracomm
Expand All @@ -74,7 +74,7 @@ subroutine openmc_init(intracomm) bind(C)
call time_total%start()
call time_initialize%start()

#ifdef MPI
#ifdef OPENMC_MPI
! Setup MPI
call initialize_mpi(comm)
#endif
Expand Down Expand Up @@ -108,23 +108,23 @@ subroutine openmc_init(intracomm) bind(C)

end subroutine openmc_init

#ifdef MPI
#ifdef OPENMC_MPI
!===============================================================================
! INITIALIZE_MPI starts up the Message Passing Interface (MPI) and determines
! the number of processors the problem is being run with as well as the rank of
! each processor.
!===============================================================================

subroutine initialize_mpi(intracomm)
#ifdef MPIF08
#ifdef OPENMC_MPIF08
type(MPI_Comm), intent(in) :: intracomm ! MPI intracommunicator
#else
integer, intent(in) :: intracomm ! MPI intracommunicator
#endif

integer :: mpi_err ! MPI error code
integer :: bank_blocks(5) ! Count for each datatype
#ifdef MPIF08
#ifdef OPENMC_MPIF08
type(MPI_Datatype) :: bank_types(5)
#else
integer :: bank_types(5) ! Datatypes
Expand Down
80 changes: 13 additions & 67 deletions src/input_xml.F90
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ subroutine read_surfaces(node_ptr) bind(C, name='read_surfaces')
implicit none
type(C_PTR) :: node_ptr
end subroutine read_surfaces
end interface
end interface

contains

Expand Down Expand Up @@ -1081,77 +1081,23 @@ subroutine read_geometry_xml()

select type(s)
type is (SurfaceXPlane)
s%x0 = coeffs(1)

! Determine outer surfaces
xmin = min(xmin, s % x0)
xmax = max(xmax, s % x0)
if (xmin == s % x0) i_xmin = i
if (xmax == s % x0) i_xmax = i
xmin = min(xmin, coeffs(1))
xmax = max(xmax, coeffs(1))
if (xmin == coeffs(1)) i_xmin = i
if (xmax == coeffs(1)) i_xmax = i
type is (SurfaceYPlane)
s%y0 = coeffs(1)

! Determine outer surfaces
ymin = min(ymin, s % y0)
ymax = max(ymax, s % y0)
if (ymin == s % y0) i_ymin = i
if (ymax == s % y0) i_ymax = i
ymin = min(ymin, coeffs(1))
ymax = max(ymax, coeffs(1))
if (ymin == coeffs(1)) i_ymin = i
if (ymax == coeffs(1)) i_ymax = i
type is (SurfaceZPlane)
s%z0 = coeffs(1)

! Determine outer surfaces
zmin = min(zmin, s % z0)
zmax = max(zmax, s % z0)
if (zmin == s % z0) i_zmin = i
if (zmax == s % z0) i_zmax = i
type is (SurfacePlane)
s%A = coeffs(1)
s%B = coeffs(2)
s%C = coeffs(3)
s%D = coeffs(4)
type is (SurfaceXCylinder)
s%y0 = coeffs(1)
s%z0 = coeffs(2)
s%r = coeffs(3)
type is (SurfaceYCylinder)
s%x0 = coeffs(1)
s%z0 = coeffs(2)
s%r = coeffs(3)
type is (SurfaceZCylinder)
s%x0 = coeffs(1)
s%y0 = coeffs(2)
s%r = coeffs(3)
type is (SurfaceSphere)
s%x0 = coeffs(1)
s%y0 = coeffs(2)
s%z0 = coeffs(3)
s%r = coeffs(4)
type is (SurfaceXCone)
s%x0 = coeffs(1)
s%y0 = coeffs(2)
s%z0 = coeffs(3)
s%r2 = coeffs(4)
type is (SurfaceYCone)
s%x0 = coeffs(1)
s%y0 = coeffs(2)
s%z0 = coeffs(3)
s%r2 = coeffs(4)
type is (SurfaceZCone)
s%x0 = coeffs(1)
s%y0 = coeffs(2)
s%z0 = coeffs(3)
s%r2 = coeffs(4)
type is (SurfaceQuadric)
s%A = coeffs(1)
s%B = coeffs(2)
s%C = coeffs(3)
s%D = coeffs(4)
s%E = coeffs(5)
s%F = coeffs(6)
s%G = coeffs(7)
s%H = coeffs(8)
s%J = coeffs(9)
s%K = coeffs(10)
zmin = min(zmin, coeffs(1))
zmax = max(zmax, coeffs(1))
if (zmin == coeffs(1)) i_zmin = i
if (zmax == coeffs(1)) i_zmax = i
end select

! No longer need coefficients
Expand Down
Loading

0 comments on commit 57991b2

Please sign in to comment.