Skip to content

Commit a45d61a

Browse files
author
Matthew Emmett
committed
BoxClaw: Finish move to Fortran based BoxLib.
1 parent 414250e commit a45d61a

File tree

7 files changed

+41
-82
lines changed

7 files changed

+41
-82
lines changed

src/boxclaw/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import os
44
import logging, logging.config
55

6+
import fboxlib
7+
fboxlib.open()
8+
69
# Default logging configuration file
710
_DEFAULT_LOG_CONFIG_PATH = os.path.join(os.path.dirname(__file__),'log.config')
811
del os

src/boxclaw/cfl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import fboxlib
3+
24
class CFL(object):
35
"""Parallel CFL object, responsible for computing the
46
Courant-Friedrichs-Lewy condition across all processes.
@@ -10,14 +12,14 @@ def __init__(self, global_max):
1012

1113
def get_global_max(self):
1214
r"""
13-
Compute the maximum CFL number over all processes for the current step.
15+
Compute the maximum CFL number over all processes for the
16+
current step.
1417
1518
This is used to determine whether the CFL condition was
1619
violated and adjust the timestep.
1720
"""
18-
import boxlib
1921
self._reduce_vec.array = self._local_max
20-
self._global_max = boxlib.bl[0].ReduceRealMax(self._local_max)
22+
self._global_max = fboxlib.reduce_max(self._local_max)
2123
return self._global_max
2224

2325
def get_cached_max(self):
@@ -27,6 +29,4 @@ def set_local_max(self,new_local_max):
2729
self._local_max = new_local_max
2830

2931
def update_global_max(self,new_local_max):
30-
import boxlib
31-
self._global_max = boxlib.bl[0].ReduceRealMax(new_local_max)
32-
32+
self._global_max = fboxlib.reduce_max(new_local_max)

src/boxclaw/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Module for BoxClaw controller class.
33
"""
44

5+
import fboxlib
56
from clawpack import pyclaw
67

78
class Controller(pyclaw.controller.Controller):
@@ -14,8 +15,7 @@ def __init__(self):
1415
self.output_format = 'multifab'
1516

1617
def is_proc_0(self):
17-
import boxlib
18-
return boxlib.rank() == 0
18+
return fboxlib.mpi_rank() == 0
1919

2020
def log_info(self, str):
2121
import logging

src/boxclaw/geometry.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
Module containing BoxClaw geometry.
55
"""
66

7+
import fboxlib
8+
import math
9+
710
from clawpack import pyclaw
811
from clawpack.pyclaw import geometry as pyclaw_geometry
912

@@ -16,43 +19,25 @@ class Patch(pyclaw_geometry.Patch):
1619
__doc__ += pyclaw.util.add_parent_doc(pyclaw_geometry.Patch)
1720

1821
def __deepcopy__(self,memo):
19-
# don't recreate boxarrays
2022
return self
2123

2224
def __init__(self,dimensions):
2325

24-
import boxlib
25-
import numpy as np
26-
2726
super(Patch,self).__init__(dimensions)
2827

29-
self._ba, self._gbox = self._create_boxarray()
30-
31-
is_per = np.asarray(self.num_dim * [ 1 ], np.int32)
32-
rb = boxlib.RealBox(boxlib.lo(self._gbox), boxlib.hi(self._gbox))
33-
self._geom = boxlib.bl[self.num_dim].Geometry(self._gbox, rb, 0, is_per)
28+
self._la = self._create_layout()
3429

35-
# XXX: create a multifab from the boxarray to get geometry information
36-
tmp = boxlib.MultiFab(self._ba)
30+
bxs = self._la.local_boxes
31+
lo, hi = self._la.get_box(bxs[0])
3732

38-
fab = None
39-
for i in range(tmp.size()):
40-
fab = tmp[i]
41-
if fab is not None:
42-
break
43-
44-
assert(fab is not None)
45-
46-
lo = boxlib.lo(fab.box())
47-
hi = boxlib.hi(fab.box())
4833
grid_dimensions = []
4934
for i in range(self.num_dim):
5035
lower = (lo[i]+0) * self.delta[i]
5136
upper = (hi[i]+1) * self.delta[i]
5237
num_cells = hi[i]-lo[i]+1
5338

5439
grid_dimensions.append(pyclaw_geometry.Dimension(lower,upper,
55-
num_cells,name=dimensions[i].name))
40+
num_cells,name=dimensions[i].name))
5641

5742
if lower == self.lower_global[i]:
5843
grid_dimensions[-1].on_lower_boundary = True
@@ -66,17 +51,9 @@ def __init__(self,dimensions):
6651

6752
self.grid = pyclaw_geometry.Grid(grid_dimensions)
6853

69-
del tmp
70-
7154

72-
def _create_boxarray(self):
73-
"""Returns a BoxLib BoxArray."""
74-
75-
# note that boxlib supports more than one box per processor
76-
77-
import boxlib
78-
import math
79-
import numpy as np
55+
def _create_layout(self):
56+
"""Returns a FBoxLib layout."""
8057

8158
dx = self.delta
8259
lg = self.lower_global
@@ -85,12 +62,8 @@ def _create_boxarray(self):
8562
lo = [ int(lg[d]/dx[d]) for d in range(self.num_dim) ]
8663
hi = [ lo[d]+nc[d]-1 for d in range(self.num_dim) ]
8764

88-
box = boxlib.Box(lo, hi)
89-
ba = boxlib.BoxArray([box])
90-
9165
max_sizes = self.num_dim * [ 1 ]
92-
93-
nprocs = boxlib.size()
66+
nprocs = fboxlib.mpi_size()
9467
if (self.num_dim > 1) and (nprocs % 2**self.num_dim == 0):
9568
# divide domain into cubes
9669
nproc_per_dim = nprocs / 2**self.num_dim + 1
@@ -102,14 +75,10 @@ def _create_boxarray(self):
10275
for d in range(1, self.num_dim):
10376
max_sizes[d] = hi[d] - lo[d] + 1
10477

105-
max_sizes = boxlib.bl[self.num_dim].IntVect(*max_sizes)
106-
ba.maxSize(max_sizes)
107-
108-
if boxlib.rank() == 0:
109-
logger.info("max_sizes: " + str(max_sizes))
110-
logger.info("boxarray: " + str(ba))
111-
112-
return ba, box
78+
ba = fboxlib.boxarray(boxes=[[lo, hi]])
79+
ba.maxsize(max_sizes)
80+
la = fboxlib.layout(ba)
81+
return la
11382

11483

11584
class Domain(pyclaw_geometry.Domain):

src/boxclaw/io/multifab.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
frame data.
99
"""
1010

11-
import boxlib
11+
import fboxlib
1212
import pickle
1313
import numpy as np
1414

@@ -56,7 +56,7 @@ def write(solution,frame,path='./',file_prefix='claw',write_aux=False,
5656
if os.path.exists(f):
5757
raise IOError('Cowardly refusing to clobber %s!' % f)
5858

59-
rank = boxlib.rank()
59+
rank = fboxlib.mpi_rank()
6060
if rank==0:
6161
pickle_file = open(pickle_filename,'wb')
6262
# explicitly dumping a dictionary here to help out anybody trying to read the pickle file
@@ -119,27 +119,25 @@ def write(solution,frame,path='./',file_prefix='claw',write_aux=False,
119119

120120
if finest_level == 0:
121121
write('')
122-
write(solution.state.patch._gbox) # grid domain
122+
lo, hi = solution.domain.patch._la.get_box(1)
123+
write(str(lo) + " " + str(hi)) # grid domain XXX
124+
write('')
123125
write(frame) # time step number
124126
write(' '.join(map(str, dx))) # dx
125127
write('0') # cartesian coords
126128
write('0') # boundary data? (0=no)
127129

128130
# now write info for each amr level (only one in this case)
129-
write('0 %d %f' % (mf.size(), solution.state.t))
131+
write('0 %d %f' % (mf.nboxes, solution.state.t))
130132
write(frame)
131-
for i in range(mf.size()):
132-
bx = solution.state.patch._ba.get(i)
133-
lo = bx.smallEnd()
134-
hi = bx.bigEnd()
133+
for i in range(1, mf.nboxes+1):
134+
lo, hi = solution.state.patch._la.get_box(i)
135135
for d in range(solution.state.num_dim):
136136
write("%lf %lf" % (lo[d]*dx[d], (hi[d]+1)*dx[d]))
137137
write("Level_0/Cell")
138138

139139
# write cell data
140-
mf.writeOut(plt_filename + '/Level_0/Cell')
140+
mf.write(plt_filename, 'Level_0/Cell')
141141

142142
if rank==0:
143143
pickle_file.close()
144-
145-

src/boxclaw/state.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import fboxlib
23
import clawpack.pyclaw
34
import numpy as np
45

@@ -19,20 +20,15 @@ def get_auxbc_from_aux(self,num_ghost,auxbc):
1920
def _fill_boundary(self, ncomp, nghost, q, qbc):
2021
mf = self._create_multifab(ncomp, nghost)
2122
self._copy_into_multifab(mf, nghost, q)
22-
mf.FillBoundary()
23-
self.patch._geom.FillPeriodicBoundary(mf)
23+
mf.fill_boundary()
2424
self._copy_outof_multifab(mf, qbc)
2525
del mf
2626

2727
def _create_multifab(self, ncomp, nghost):
28-
import boxlib
29-
return boxlib.MultiFab(self.patch._ba, ncomp, nghost)
28+
return fboxlib.multifab(self.patch._la, ncomp, nghost)
3029

3130
def _get_array(self, mf):
32-
for i in range(mf.size()):
33-
if mf[i] is not None:
34-
return mf[i].get_array()
35-
return None
31+
return mf.fab(1).array
3632

3733
def _copy_into_multifab(self, mf, ng, q):
3834

@@ -51,12 +47,5 @@ def _copy_into_multifab(self, mf, ng, q):
5147
raise Exception("Assumption (1 <= num_dim <= 3) violated.")
5248

5349
def _copy_outof_multifab(self, mf, q):
54-
num_dim = self.patch.num_dim
55-
fab = self._get_array(mf)
50+
fab = self._get_array(mf)
5651
q[...] = np.rollaxis(fab, self.q.ndim-1)
57-
58-
59-
60-
61-
62-

src/boxclaw/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
def boxlib_build_variant_arg_dicts(kernel_languages=('Fortran',)):
66
import itertools
77

8-
# test petsc4py only if it is available
8+
# test fboxlib only if it is available
99
try:
10-
import boxlib
10+
import fboxlib
1111
except ImportError:
1212
return []
1313

0 commit comments

Comments
 (0)