Skip to content

Commit

Permalink
Replace FoX with pugixml
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Mar 3, 2017
1 parent 7927a2d commit 25d646d
Show file tree
Hide file tree
Showing 20 changed files with 15,311 additions and 1,091 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "src/xml/fox"]
path = src/xml/fox
url = https://github.com/mit-crpg/fox.git
34 changes: 11 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(openmc Fortran C)
project(openmc Fortran C CXX)

# Setup output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -225,27 +225,14 @@ if(GIT_SHA1_SUCCESS EQUAL 0)
endif()

#===============================================================================
# FoX Fortran XML Library
# pugixml library
#===============================================================================

# Only initialize git submodules if it is not there. User is responsible
# for future updates of fox xml submodule.
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/xml/fox/.git)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
message("-- Cloning FoX XML git repository...")
execute_process(COMMAND git clone https://github.com/mit-crpg/fox.git src/xml/fox
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(COMMAND git checkout bdc852f4f43d969fb1b179cba79295c1e095a455
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/xml/fox)
else()
message("-- Initializing/Updating FoX XML submodule...")
execute_process(COMMAND git submodule init
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(COMMAND git submodule update
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
endif()
add_subdirectory(src/xml/fox)
add_library(pugixml src/pugixml/pugixml_c.cpp src/pugixml/pugixml.cpp)
set_property(TARGET pugixml PROPERTY CXX_STANDARD 11)

add_library(pugixml_fortran src/pugixml/pugixml_f.F90)
target_link_libraries(pugixml_fortran pugixml)

#===============================================================================
# RPATH information
Expand Down Expand Up @@ -352,11 +339,12 @@ set(LIBOPENMC_FORTRAN_SRC
src/vector_header.F90
src/volume_calc.F90
src/volume_header.F90
src/xml_interface.F90
src/xml/openmc_fox.F90)
src/xml_interface.F90)
add_library(libopenmc STATIC ${LIBOPENMC_FORTRAN_SRC})
set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc)
add_executable(${program} src/main.F90)
set_property(TARGET ${program} libopenmc pugixml_fortran
PROPERTY LINKER_LANGUAGE Fortran)

# target_include_directories was added in CMake 2.8.11 and is the recommended
# way to set include directories. For lesser versions, we revert to set_property
Expand Down Expand Up @@ -388,7 +376,7 @@ endforeach()

# target_link_libraries treats any arguments starting with - but not -l as
# linker flags. Thus, we can pass both linker flags and libraries together.
target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} fox_dom faddeeva)
target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} pugixml_fortran faddeeva)
target_link_libraries(${program} ${ldflags} libopenmc)

#===============================================================================
Expand Down
139 changes: 59 additions & 80 deletions src/cmfd_input.F90
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ subroutine read_cmfd_xml()
logical :: file_exists ! does cmfd.xml exist?
logical :: found
character(MAX_LINE_LEN) :: filename
character(MAX_LINE_LEN) :: temp_str
real(8) :: gs_tol(2)
type(Node), pointer :: doc => null()
type(Node), pointer :: node_mesh => null()
type(XMLDocument) :: doc
type(XMLNode) :: root
type(XMLNode) :: node_mesh

! Read cmfd input file
filename = trim(path_input) // "cmfd.xml"
Expand All @@ -84,13 +84,14 @@ subroutine read_cmfd_xml()
end if

! Parse cmfd.xml file
call open_xmldoc(doc, filename)
call doc % load_file(filename)
root = doc % document_element()

! Get pointer to mesh XML node
call get_node_ptr(doc, "mesh", node_mesh, found = found)
node_mesh = root % child("mesh")

! Check if mesh is there
if (.not.found) then
if (.not. node_mesh % associated()) then
call fatal_error("No CMFD mesh specified in CMFD XML file.")
end if

Expand All @@ -99,8 +100,8 @@ subroutine read_cmfd_xml()

! Get number of energy groups
if (check_for_node(node_mesh, "energy")) then
ng = get_arraysize_double(node_mesh, "energy")
if(.not.allocated(cmfd%egrid)) allocate(cmfd%egrid(ng))
ng = node_word_count(node_mesh, "energy")
if(.not. allocated(cmfd%egrid)) allocate(cmfd%egrid(ng))
call get_node_array(node_mesh, "energy", cmfd%egrid)
cmfd % indices(4) = ng - 1 ! sets energy group dimension
! If using MG mode, check to see if these egrid points at least match
Expand Down Expand Up @@ -137,118 +138,100 @@ subroutine read_cmfd_xml()
if (check_for_node(node_mesh, "map")) then
allocate(cmfd % coremap(cmfd % indices(1), cmfd % indices(2), &
cmfd % indices(3)))
if (get_arraysize_integer(node_mesh, "map") /= &
if (node_word_count(node_mesh, "map") /= &
product(cmfd % indices(1:3))) then
call fatal_error('CMFD coremap not to correct dimensions')
end if
allocate(iarray(get_arraysize_integer(node_mesh, "map")))
allocate(iarray(node_word_count(node_mesh, "map")))
call get_node_array(node_mesh, "map", iarray)
cmfd % coremap = reshape(iarray,(cmfd % indices(1:3)))
cmfd_coremap = .true.
deallocate(iarray)
end if

! Check for normalization constant
if (check_for_node(doc, "norm")) then
call get_node_value(doc, "norm", cmfd % norm)
if (check_for_node(root, "norm")) then
call get_node_value(root, "norm", cmfd % norm)
end if

! Set feedback logical
if (check_for_node(doc, "feedback")) then
call get_node_value(doc, "feedback", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
cmfd_feedback = .true.
if (check_for_node(root, "feedback")) then
call get_node_value(root, "feedback", cmfd_feedback)
end if

! Set downscatter logical
if (check_for_node(doc, "downscatter")) then
call get_node_value(doc, "downscatter", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
cmfd_downscatter = .true.
if (check_for_node(root, "downscatter")) then
call get_node_value(root, "downscatter", cmfd_downscatter)
end if

! Reset dhat parameters
if (check_for_node(doc, "dhat_reset")) then
call get_node_value(doc, "dhat_reset", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
dhat_reset = .true.
if (check_for_node(root, "dhat_reset")) then
call get_node_value(root, "dhat_reset", dhat_reset)
end if

! Set monitoring
if (check_for_node(doc, "power_monitor")) then
call get_node_value(doc, "power_monitor", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
cmfd_power_monitor = .true.
if (check_for_node(root, "power_monitor")) then
call get_node_value(root, "power_monitor", cmfd_power_monitor)
end if

! Output logicals
if (check_for_node(doc, "write_matrices")) then
call get_node_value(doc, "write_matrices", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
cmfd_write_matrices = .true.
if (check_for_node(root, "write_matrices")) then
call get_node_value(root, "write_matrices", cmfd_write_matrices)
end if

! Run an adjoint calc
if (check_for_node(doc, "run_adjoint")) then
call get_node_value(doc, "run_adjoint", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
cmfd_run_adjoint = .true.
if (check_for_node(root, "run_adjoint")) then
call get_node_value(root, "run_adjoint", cmfd_run_adjoint)
end if

! Batch to begin cmfd
if (check_for_node(doc, "begin")) &
call get_node_value(doc, "begin", cmfd_begin)
if (check_for_node(root, "begin")) &
call get_node_value(root, "begin", cmfd_begin)

! Check for cmfd tally resets
if (check_for_node(doc, "tally_reset")) then
n_cmfd_resets = get_arraysize_integer(doc, "tally_reset")
if (check_for_node(root, "tally_reset")) then
n_cmfd_resets = node_word_count(root, "tally_reset")
else
n_cmfd_resets = 0
end if
if (n_cmfd_resets > 0) then
allocate(int_array(n_cmfd_resets))
call get_node_array(doc, "tally_reset", int_array)
call get_node_array(root, "tally_reset", int_array)
do i = 1, n_cmfd_resets
call cmfd_reset % add(int_array(i))
end do
deallocate(int_array)
end if

! Get display
if (check_for_node(doc, "display")) &
call get_node_value(doc, "display", cmfd_display)
if (check_for_node(root, "display")) &
call get_node_value(root, "display", cmfd_display)

! Read in spectral radius estimate and tolerances
if (check_for_node(doc, "spectral")) &
call get_node_value(doc, "spectral", cmfd_spectral)
if (check_for_node(doc, "shift")) &
call get_node_value(doc, "shift", cmfd_shift)
if (check_for_node(doc, "ktol")) &
call get_node_value(doc, "ktol", cmfd_ktol)
if (check_for_node(doc, "stol")) &
call get_node_value(doc, "stol", cmfd_stol)
if (check_for_node(doc, "gauss_seidel_tolerance")) then
n_params = get_arraysize_double(doc, "gauss_seidel_tolerance")
if (check_for_node(root, "spectral")) &
call get_node_value(root, "spectral", cmfd_spectral)
if (check_for_node(root, "shift")) &
call get_node_value(root, "shift", cmfd_shift)
if (check_for_node(root, "ktol")) &
call get_node_value(root, "ktol", cmfd_ktol)
if (check_for_node(root, "stol")) &
call get_node_value(root, "stol", cmfd_stol)
if (check_for_node(root, "gauss_seidel_tolerance")) then
n_params = node_word_count(root, "gauss_seidel_tolerance")
if (n_params /= 2) then
call fatal_error('Gauss Seidel tolerance is not 2 parameters &
&(absolute, relative).')
end if
call get_node_array(doc, "gauss_seidel_tolerance", gs_tol)
call get_node_array(root, "gauss_seidel_tolerance", gs_tol)
cmfd_atoli = gs_tol(1)
cmfd_rtoli = gs_tol(2)
end if

! Create tally objects
call create_cmfd_tally(doc)
call create_cmfd_tally(root)

! Close CMFD XML file
call close_xmldoc(doc)
call doc % clear()

end subroutine read_cmfd_xml

Expand All @@ -261,7 +244,7 @@ end subroutine read_cmfd_xml
! 3: Surface current
!===============================================================================

subroutine create_cmfd_tally(doc)
subroutine create_cmfd_tally(root)

use constants, only: MAX_LINE_LEN
use error, only: fatal_error, warning
Expand All @@ -274,9 +257,8 @@ subroutine create_cmfd_tally(doc)
use tally_initialize, only: add_tallies
use xml_interface

type(Node), pointer :: doc ! pointer to XML doc info
type(XMLNode), intent(in) :: root ! XML root element

character(MAX_LINE_LEN) :: temp_str ! temp string
integer :: i, j ! loop counter
integer :: n ! size of arrays in mesh specification
integer :: ng ! number of energy groups (default 1)
Expand All @@ -287,7 +269,7 @@ subroutine create_cmfd_tally(doc)
type(TallyObject), pointer :: t
type(RegularMesh), pointer :: m
type(TallyFilterContainer) :: filters(N_FILTER_TYPES) ! temporary filters
type(Node), pointer :: node_mesh
type(XMLNode) :: node_mesh

! Set global variables if they are 0 (this can happen if there is no tally
! file)
Expand All @@ -304,10 +286,10 @@ subroutine create_cmfd_tally(doc)
m % type = LATTICE_RECT

! Get pointer to mesh XML node
call get_node_ptr(doc, "mesh", node_mesh)
node_mesh = root % child("mesh")

! Determine number of dimensions for mesh
n = get_arraysize_integer(node_mesh, "dimension")
n = node_word_count(node_mesh, "dimension")
if (n /= 2 .and. n /= 3) then
call fatal_error("Mesh must be two or three dimensions.")
end if
Expand All @@ -330,7 +312,7 @@ subroutine create_cmfd_tally(doc)
m % dimension = iarray3(1:n)

! Read mesh lower-left corner location
if (m % n_dimension /= get_arraysize_double(node_mesh, "lower_left")) then
if (m % n_dimension /= node_word_count(node_mesh, "lower_left")) then
call fatal_error("Number of entries on <lower_left> must be the same as &
&the number of entries on <dimension>.")
end if
Expand All @@ -352,8 +334,8 @@ subroutine create_cmfd_tally(doc)

if (check_for_node(node_mesh, "width")) then
! Check to ensure width has same dimensions
if (get_arraysize_double(node_mesh, "width") /= &
get_arraysize_double(node_mesh, "lower_left")) then
if (node_word_count(node_mesh, "width") /= &
node_word_count(node_mesh, "lower_left")) then
call fatal_error("Number of entries on <width> must be the same as the &
&number of entries on <lower_left>.")
end if
Expand All @@ -370,8 +352,8 @@ subroutine create_cmfd_tally(doc)

elseif (check_for_node(node_mesh, "upper_right")) then
! Check to ensure width has same dimensions
if (get_arraysize_double(node_mesh, "upper_right") /= &
get_arraysize_double(node_mesh, "lower_left")) then
if (node_word_count(node_mesh, "upper_right") /= &
node_word_count(node_mesh, "lower_left")) then
call fatal_error("Number of entries on <upper_right> must be the same &
&as the number of entries on <lower_left>.")
end if
Expand Down Expand Up @@ -404,11 +386,8 @@ subroutine create_cmfd_tally(doc)
t => cmfd_tallies(i)

! Set reset property
if (check_for_node(doc, "reset")) then
call get_node_value(doc, "reset", temp_str)
temp_str = to_lower(temp_str)
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
t % reset = .true.
if (check_for_node(root, "reset")) then
call get_node_value(root, "reset", t % reset)
end if

! Set up mesh filter
Expand All @@ -427,7 +406,7 @@ subroutine create_cmfd_tally(doc)
allocate(EnergyFilter :: filters(n_filters) % obj)
select type (filt => filters(n_filters) % obj)
type is (EnergyFilter)
ng = get_arraysize_double(node_mesh, "energy")
ng = node_word_count(node_mesh, "energy")
filt % n_bins = ng - 1
allocate(filt % bins(ng))
call get_node_array(node_mesh, "energy", filt % bins)
Expand Down Expand Up @@ -492,7 +471,7 @@ subroutine create_cmfd_tally(doc)
allocate(EnergyoutFilter :: filters(n_filters) % obj)
select type (filt => filters(n_filters) % obj)
type is (EnergyoutFilter)
ng = get_arraysize_double(node_mesh, "energy")
ng = node_word_count(node_mesh, "energy")
filt % n_bins = ng - 1
allocate(filt % bins(ng))
call get_node_array(node_mesh, "energy", filt % bins)
Expand Down
5 changes: 3 additions & 2 deletions src/distribution_univariate.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module distribution_univariate
use error, only: fatal_error
use random_lcg, only: prn
use math, only: maxwell_spectrum, watt_spectrum
use pugixml
use string, only: to_lower
use xml_interface

Expand Down Expand Up @@ -265,7 +266,7 @@ end function equiprobable_sample

subroutine distribution_from_xml(dist, node_dist)
class(Distribution), allocatable, intent(inout) :: dist
type(Node), pointer :: node_dist
type(XMLNode), intent(in) :: node_dist

character(MAX_WORD_LEN) :: type
character(MAX_LINE_LEN) :: temp_str
Expand All @@ -279,7 +280,7 @@ subroutine distribution_from_xml(dist, node_dist)

! Determine number of parameters specified
if (check_for_node(node_dist, "parameters")) then
n = get_arraysize_double(node_dist, "parameters")
n = node_word_count(node_dist, "parameters")
else
n = 0
end if
Expand Down
Loading

0 comments on commit 25d646d

Please sign in to comment.