Skip to content

Commit 25d646d

Browse files
committed
Replace FoX with pugixml
1 parent 7927a2d commit 25d646d

20 files changed

Lines changed: 15311 additions & 1091 deletions

‎.gitmodules‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "src/xml/fox"]
2-
path = src/xml/fox
3-
url = https://github.com/mit-crpg/fox.git

‎CMakeLists.txt‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
2-
project(openmc Fortran C)
2+
project(openmc Fortran C CXX)
33

44
# Setup output directories
55
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@@ -225,27 +225,14 @@ if(GIT_SHA1_SUCCESS EQUAL 0)
225225
endif()
226226

227227
#===============================================================================
228-
# FoX Fortran XML Library
228+
# pugixml library
229229
#===============================================================================
230230

231-
# Only initialize git submodules if it is not there. User is responsible
232-
# for future updates of fox xml submodule.
233-
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/xml/fox/.git)
234-
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
235-
message("-- Cloning FoX XML git repository...")
236-
execute_process(COMMAND git clone https://github.com/mit-crpg/fox.git src/xml/fox
237-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
238-
execute_process(COMMAND git checkout bdc852f4f43d969fb1b179cba79295c1e095a455
239-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/xml/fox)
240-
else()
241-
message("-- Initializing/Updating FoX XML submodule...")
242-
execute_process(COMMAND git submodule init
243-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
244-
execute_process(COMMAND git submodule update
245-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
246-
endif()
247-
endif()
248-
add_subdirectory(src/xml/fox)
231+
add_library(pugixml src/pugixml/pugixml_c.cpp src/pugixml/pugixml.cpp)
232+
set_property(TARGET pugixml PROPERTY CXX_STANDARD 11)
233+
234+
add_library(pugixml_fortran src/pugixml/pugixml_f.F90)
235+
target_link_libraries(pugixml_fortran pugixml)
249236

250237
#===============================================================================
251238
# RPATH information
@@ -352,11 +339,12 @@ set(LIBOPENMC_FORTRAN_SRC
352339
src/vector_header.F90
353340
src/volume_calc.F90
354341
src/volume_header.F90
355-
src/xml_interface.F90
356-
src/xml/openmc_fox.F90)
342+
src/xml_interface.F90)
357343
add_library(libopenmc STATIC ${LIBOPENMC_FORTRAN_SRC})
358344
set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc)
359345
add_executable(${program} src/main.F90)
346+
set_property(TARGET ${program} libopenmc pugixml_fortran
347+
PROPERTY LINKER_LANGUAGE Fortran)
360348

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

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

394382
#===============================================================================

‎src/cmfd_input.F90‎

Lines changed: 59 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ subroutine read_cmfd_xml()
6161
logical :: file_exists ! does cmfd.xml exist?
6262
logical :: found
6363
character(MAX_LINE_LEN) :: filename
64-
character(MAX_LINE_LEN) :: temp_str
6564
real(8) :: gs_tol(2)
66-
type(Node), pointer :: doc => null()
67-
type(Node), pointer :: node_mesh => null()
65+
type(XMLDocument) :: doc
66+
type(XMLNode) :: root
67+
type(XMLNode) :: node_mesh
6868

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

8686
! Parse cmfd.xml file
87-
call open_xmldoc(doc, filename)
87+
call doc % load_file(filename)
88+
root = doc % document_element()
8889

8990
! Get pointer to mesh XML node
90-
call get_node_ptr(doc, "mesh", node_mesh, found = found)
91+
node_mesh = root % child("mesh")
9192

9293
! Check if mesh is there
93-
if (.not.found) then
94+
if (.not. node_mesh % associated()) then
9495
call fatal_error("No CMFD mesh specified in CMFD XML file.")
9596
end if
9697

@@ -99,8 +100,8 @@ subroutine read_cmfd_xml()
99100

100101
! Get number of energy groups
101102
if (check_for_node(node_mesh, "energy")) then
102-
ng = get_arraysize_double(node_mesh, "energy")
103-
if(.not.allocated(cmfd%egrid)) allocate(cmfd%egrid(ng))
103+
ng = node_word_count(node_mesh, "energy")
104+
if(.not. allocated(cmfd%egrid)) allocate(cmfd%egrid(ng))
104105
call get_node_array(node_mesh, "energy", cmfd%egrid)
105106
cmfd % indices(4) = ng - 1 ! sets energy group dimension
106107
! If using MG mode, check to see if these egrid points at least match
@@ -137,118 +138,100 @@ subroutine read_cmfd_xml()
137138
if (check_for_node(node_mesh, "map")) then
138139
allocate(cmfd % coremap(cmfd % indices(1), cmfd % indices(2), &
139140
cmfd % indices(3)))
140-
if (get_arraysize_integer(node_mesh, "map") /= &
141+
if (node_word_count(node_mesh, "map") /= &
141142
product(cmfd % indices(1:3))) then
142143
call fatal_error('CMFD coremap not to correct dimensions')
143144
end if
144-
allocate(iarray(get_arraysize_integer(node_mesh, "map")))
145+
allocate(iarray(node_word_count(node_mesh, "map")))
145146
call get_node_array(node_mesh, "map", iarray)
146147
cmfd % coremap = reshape(iarray,(cmfd % indices(1:3)))
147148
cmfd_coremap = .true.
148149
deallocate(iarray)
149150
end if
150151

151152
! Check for normalization constant
152-
if (check_for_node(doc, "norm")) then
153-
call get_node_value(doc, "norm", cmfd % norm)
153+
if (check_for_node(root, "norm")) then
154+
call get_node_value(root, "norm", cmfd % norm)
154155
end if
155156

156157
! Set feedback logical
157-
if (check_for_node(doc, "feedback")) then
158-
call get_node_value(doc, "feedback", temp_str)
159-
temp_str = to_lower(temp_str)
160-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
161-
cmfd_feedback = .true.
158+
if (check_for_node(root, "feedback")) then
159+
call get_node_value(root, "feedback", cmfd_feedback)
162160
end if
163161

164162
! Set downscatter logical
165-
if (check_for_node(doc, "downscatter")) then
166-
call get_node_value(doc, "downscatter", temp_str)
167-
temp_str = to_lower(temp_str)
168-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
169-
cmfd_downscatter = .true.
163+
if (check_for_node(root, "downscatter")) then
164+
call get_node_value(root, "downscatter", cmfd_downscatter)
170165
end if
171166

172167
! Reset dhat parameters
173-
if (check_for_node(doc, "dhat_reset")) then
174-
call get_node_value(doc, "dhat_reset", temp_str)
175-
temp_str = to_lower(temp_str)
176-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
177-
dhat_reset = .true.
168+
if (check_for_node(root, "dhat_reset")) then
169+
call get_node_value(root, "dhat_reset", dhat_reset)
178170
end if
179171

180172
! Set monitoring
181-
if (check_for_node(doc, "power_monitor")) then
182-
call get_node_value(doc, "power_monitor", temp_str)
183-
temp_str = to_lower(temp_str)
184-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
185-
cmfd_power_monitor = .true.
173+
if (check_for_node(root, "power_monitor")) then
174+
call get_node_value(root, "power_monitor", cmfd_power_monitor)
186175
end if
187176

188177
! Output logicals
189-
if (check_for_node(doc, "write_matrices")) then
190-
call get_node_value(doc, "write_matrices", temp_str)
191-
temp_str = to_lower(temp_str)
192-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
193-
cmfd_write_matrices = .true.
178+
if (check_for_node(root, "write_matrices")) then
179+
call get_node_value(root, "write_matrices", cmfd_write_matrices)
194180
end if
195181

196182
! Run an adjoint calc
197-
if (check_for_node(doc, "run_adjoint")) then
198-
call get_node_value(doc, "run_adjoint", temp_str)
199-
temp_str = to_lower(temp_str)
200-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
201-
cmfd_run_adjoint = .true.
183+
if (check_for_node(root, "run_adjoint")) then
184+
call get_node_value(root, "run_adjoint", cmfd_run_adjoint)
202185
end if
203186

204187
! Batch to begin cmfd
205-
if (check_for_node(doc, "begin")) &
206-
call get_node_value(doc, "begin", cmfd_begin)
188+
if (check_for_node(root, "begin")) &
189+
call get_node_value(root, "begin", cmfd_begin)
207190

208191
! Check for cmfd tally resets
209-
if (check_for_node(doc, "tally_reset")) then
210-
n_cmfd_resets = get_arraysize_integer(doc, "tally_reset")
192+
if (check_for_node(root, "tally_reset")) then
193+
n_cmfd_resets = node_word_count(root, "tally_reset")
211194
else
212195
n_cmfd_resets = 0
213196
end if
214197
if (n_cmfd_resets > 0) then
215198
allocate(int_array(n_cmfd_resets))
216-
call get_node_array(doc, "tally_reset", int_array)
199+
call get_node_array(root, "tally_reset", int_array)
217200
do i = 1, n_cmfd_resets
218201
call cmfd_reset % add(int_array(i))
219202
end do
220203
deallocate(int_array)
221204
end if
222205

223206
! Get display
224-
if (check_for_node(doc, "display")) &
225-
call get_node_value(doc, "display", cmfd_display)
207+
if (check_for_node(root, "display")) &
208+
call get_node_value(root, "display", cmfd_display)
226209

227210
! Read in spectral radius estimate and tolerances
228-
if (check_for_node(doc, "spectral")) &
229-
call get_node_value(doc, "spectral", cmfd_spectral)
230-
if (check_for_node(doc, "shift")) &
231-
call get_node_value(doc, "shift", cmfd_shift)
232-
if (check_for_node(doc, "ktol")) &
233-
call get_node_value(doc, "ktol", cmfd_ktol)
234-
if (check_for_node(doc, "stol")) &
235-
call get_node_value(doc, "stol", cmfd_stol)
236-
if (check_for_node(doc, "gauss_seidel_tolerance")) then
237-
n_params = get_arraysize_double(doc, "gauss_seidel_tolerance")
211+
if (check_for_node(root, "spectral")) &
212+
call get_node_value(root, "spectral", cmfd_spectral)
213+
if (check_for_node(root, "shift")) &
214+
call get_node_value(root, "shift", cmfd_shift)
215+
if (check_for_node(root, "ktol")) &
216+
call get_node_value(root, "ktol", cmfd_ktol)
217+
if (check_for_node(root, "stol")) &
218+
call get_node_value(root, "stol", cmfd_stol)
219+
if (check_for_node(root, "gauss_seidel_tolerance")) then
220+
n_params = node_word_count(root, "gauss_seidel_tolerance")
238221
if (n_params /= 2) then
239222
call fatal_error('Gauss Seidel tolerance is not 2 parameters &
240223
&(absolute, relative).')
241224
end if
242-
call get_node_array(doc, "gauss_seidel_tolerance", gs_tol)
225+
call get_node_array(root, "gauss_seidel_tolerance", gs_tol)
243226
cmfd_atoli = gs_tol(1)
244227
cmfd_rtoli = gs_tol(2)
245228
end if
246229

247230
! Create tally objects
248-
call create_cmfd_tally(doc)
231+
call create_cmfd_tally(root)
249232

250233
! Close CMFD XML file
251-
call close_xmldoc(doc)
234+
call doc % clear()
252235

253236
end subroutine read_cmfd_xml
254237

@@ -261,7 +244,7 @@ end subroutine read_cmfd_xml
261244
! 3: Surface current
262245
!===============================================================================
263246

264-
subroutine create_cmfd_tally(doc)
247+
subroutine create_cmfd_tally(root)
265248

266249
use constants, only: MAX_LINE_LEN
267250
use error, only: fatal_error, warning
@@ -274,9 +257,8 @@ subroutine create_cmfd_tally(doc)
274257
use tally_initialize, only: add_tallies
275258
use xml_interface
276259

277-
type(Node), pointer :: doc ! pointer to XML doc info
260+
type(XMLNode), intent(in) :: root ! XML root element
278261

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

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

306288
! Get pointer to mesh XML node
307-
call get_node_ptr(doc, "mesh", node_mesh)
289+
node_mesh = root % child("mesh")
308290

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

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

353335
if (check_for_node(node_mesh, "width")) then
354336
! Check to ensure width has same dimensions
355-
if (get_arraysize_double(node_mesh, "width") /= &
356-
get_arraysize_double(node_mesh, "lower_left")) then
337+
if (node_word_count(node_mesh, "width") /= &
338+
node_word_count(node_mesh, "lower_left")) then
357339
call fatal_error("Number of entries on <width> must be the same as the &
358340
&number of entries on <lower_left>.")
359341
end if
@@ -370,8 +352,8 @@ subroutine create_cmfd_tally(doc)
370352

371353
elseif (check_for_node(node_mesh, "upper_right")) then
372354
! Check to ensure width has same dimensions
373-
if (get_arraysize_double(node_mesh, "upper_right") /= &
374-
get_arraysize_double(node_mesh, "lower_left")) then
355+
if (node_word_count(node_mesh, "upper_right") /= &
356+
node_word_count(node_mesh, "lower_left")) then
375357
call fatal_error("Number of entries on <upper_right> must be the same &
376358
&as the number of entries on <lower_left>.")
377359
end if
@@ -404,11 +386,8 @@ subroutine create_cmfd_tally(doc)
404386
t => cmfd_tallies(i)
405387

406388
! Set reset property
407-
if (check_for_node(doc, "reset")) then
408-
call get_node_value(doc, "reset", temp_str)
409-
temp_str = to_lower(temp_str)
410-
if (trim(temp_str) == 'true' .or. trim(temp_str) == '1') &
411-
t % reset = .true.
389+
if (check_for_node(root, "reset")) then
390+
call get_node_value(root, "reset", t % reset)
412391
end if
413392

414393
! Set up mesh filter
@@ -427,7 +406,7 @@ subroutine create_cmfd_tally(doc)
427406
allocate(EnergyFilter :: filters(n_filters) % obj)
428407
select type (filt => filters(n_filters) % obj)
429408
type is (EnergyFilter)
430-
ng = get_arraysize_double(node_mesh, "energy")
409+
ng = node_word_count(node_mesh, "energy")
431410
filt % n_bins = ng - 1
432411
allocate(filt % bins(ng))
433412
call get_node_array(node_mesh, "energy", filt % bins)
@@ -492,7 +471,7 @@ subroutine create_cmfd_tally(doc)
492471
allocate(EnergyoutFilter :: filters(n_filters) % obj)
493472
select type (filt => filters(n_filters) % obj)
494473
type is (EnergyoutFilter)
495-
ng = get_arraysize_double(node_mesh, "energy")
474+
ng = node_word_count(node_mesh, "energy")
496475
filt % n_bins = ng - 1
497476
allocate(filt % bins(ng))
498477
call get_node_array(node_mesh, "energy", filt % bins)

‎src/distribution_univariate.F90‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module distribution_univariate
55
use error, only: fatal_error
66
use random_lcg, only: prn
77
use math, only: maxwell_spectrum, watt_spectrum
8+
use pugixml
89
use string, only: to_lower
910
use xml_interface
1011

@@ -265,7 +266,7 @@ end function equiprobable_sample
265266

266267
subroutine distribution_from_xml(dist, node_dist)
267268
class(Distribution), allocatable, intent(inout) :: dist
268-
type(Node), pointer :: node_dist
269+
type(XMLNode), intent(in) :: node_dist
269270

270271
character(MAX_WORD_LEN) :: type
271272
character(MAX_LINE_LEN) :: temp_str
@@ -279,7 +280,7 @@ subroutine distribution_from_xml(dist, node_dist)
279280

280281
! Determine number of parameters specified
281282
if (check_for_node(node_dist, "parameters")) then
282-
n = get_arraysize_double(node_dist, "parameters")
283+
n = node_word_count(node_dist, "parameters")
283284
else
284285
n = 0
285286
end if

0 commit comments

Comments
 (0)