Skip to content

Commit 0b595de

Browse files
committed
Various changes to pyclaw. Updates to properly handle restarts using hdf5
1 parent b20bf4f commit 0b595de

File tree

7 files changed

+70
-12
lines changed

7 files changed

+70
-12
lines changed

examples/euler_1d/shocksine.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ def setup(use_petsc=False,iplot=False,htmlplot=False,outdir='./_output',solver_t
5252

5353
if solver_type=='sharpclaw':
5454
solver = pyclaw.SharpClawSolver1D(rs)
55-
solver.time_integrator = 'RK'
55+
solver.time_integrator = 'Euler'
5656
solver.a, solver.b, solver.c = a, b, c
5757
solver.cfl_desired = 0.6
5858
solver.cfl_max = 0.7
59+
60+
solver.weno_order = 2
61+
solver.num_ghost = 2
62+
solver.lim_type = 1
63+
5964
if use_char_decomp:
6065
try:
6166
import sharpclaw1 # Import custom Fortran code

src/pyclaw/classic/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def configuration(parent_package='',top_path=None):
1313
['limiter.f90','philim.f90','flux2.f90','step2ds.f90','step2.f90'],f2py_options=['--quiet'])
1414

1515
config.add_extension('classic3',
16-
['limiter.f90','philim.f90','flux3.f90','step3ds.f90','step3.f90'],f2py_options=['--quiet'],extra_f90_compile_args=['-fopenmp'],libraries=['gomp'])
16+
['limiter.f90','philim.f90','flux3.f90','step3ds.f90','step3.f90'],f2py_options=['--quiet'],extra_f90_compile_args=['-fopenmp -Warray-bounds -fcheck=all'],libraries=['gomp'])
1717

1818
return config
1919

src/pyclaw/classic/solver.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def step(self,solution,take_one_step,tstart,tend):
141141
# Godunov Splitting
142142
if self.source_split == 1:
143143
self.step_source(self,solution.states[0],self.dt)
144-
144+
145145
return True
146146

147147
def _check_cfl_settings(self):
@@ -684,7 +684,7 @@ def step_hyperbolic(self,solution):
684684
if self.dimensional_split:
685685
#Right now only Godunov-dimensional-splitting is implemented.
686686
#Strang-dimensional-splitting could be added following dimsp3.f in Clawpack.
687-
687+
#"""
688688
q, cfl_x = self.fmod.step3ds(maxm,self.nthreads,self.num_ghost,\
689689
mx,my,mz,qold,qnew,self.auxbc,dx,dy,dz,self.dt,self._method,\
690690
self._mthlim,self.aux1,self.aux2,self.aux3,self.work,1,\
@@ -699,6 +699,27 @@ def step_hyperbolic(self,solution):
699699
mx,my,mz,q,q,self.auxbc,dx,dy,dz,self.dt,self._method,\
700700
self._mthlim,self.aux1,self.aux2,self.aux3,self.work,3,\
701701
self.fwave,rpn3,rpt3,rptt3)
702+
#"""
703+
704+
"""
705+
#print "No Dim Splitting..."
706+
# No Dimensional Splitting, Similar to SharpClaw
707+
dq = qnew.copy('F')
708+
dq[...] = 0.
709+
dq, cfl_x = self.fmod.step3ds(maxm,self.nthreads,self.num_ghost,\
710+
mx,my,mz,qold,dq,self.auxbc,dx,dy,dz,self.dt,self._method,\
711+
self._mthlim,self.aux1,self.aux2,self.aux3,self.work,1,\
712+
self.fwave,rpn3,rpt3,rptt3)
713+
dq, cfl_y = self.fmod.step3ds(maxm,self.nthreads,self.num_ghost,\
714+
mx,my,mz,qold,dq,self.auxbc,dx,dy,dz,self.dt,self._method,\
715+
self._mthlim,self.aux1,self.aux2,self.aux3,self.work,2,\
716+
self.fwave,rpn3,rpt3,rptt3)
717+
dq, cfl_z = self.fmod.step3ds(maxm,self.nthreads,self.num_ghost,\
718+
mx,my,mz,qold,dq,self.auxbc,dx,dy,dz,self.dt,self._method,\
719+
self._mthlim,self.aux1,self.aux2,self.aux3,self.work,3,\
720+
self.fwave,rpn3,rpt3,rptt3)
721+
self.qbc += dq
722+
"""
702723

703724
cfl = max(cfl_x,cfl_y,cfl_z)
704725

src/pyclaw/io/hdf5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ def read(solution,frame,path='./',file_prefix='claw',read_aux=True,
193193
state = pyclaw.state.State(pyclaw_patch, \
194194
patch.attrs['num_eqn'],patch.attrs['num_aux'])
195195
state.t = patch.attrs['t']
196-
state.q = patch['q'][:].reshape(state.q.shape,order='F')
196+
state.q = patch['q'][:].ravel(order='F').reshape(state.q.shape,order='F')
197197

198198
# Read in aux if applicable
199199
if read_aux and patch.get('aux',None) is not None:
200-
state.aux = patch['aux'][:].reshape(state.aux.shape,order='F')
200+
state.aux = patch['aux'][:].ravel(order='F').reshape(state.aux.shape,order='F')
201201

202202
solution.states.append(state)
203203
patches.append(pyclaw_patch)

src/pyclaw/sharpclaw/solver.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def step(self,solution,take_one_step,tstart,tend):
284284
Take one step with a Runge-Kutta or multistep method as specified by
285285
`solver.time_integrator`.
286286
"""
287+
287288
state = solution.states[0]
288289
step_index = self.status['numsteps'] + 1
289290
if self.accept_step == True:
@@ -515,9 +516,19 @@ def check_3rd_ord_cond(self,state,step_index,dtFE):
515516
def _set_mthlim(self):
516517
self._mthlim = self.limiters
517518
if not isinstance(self.limiters,list): self._mthlim=[self._mthlim]
518-
if len(self._mthlim)==1: self._mthlim = self._mthlim * self.num_waves
519-
if len(self._mthlim)!=self.num_waves:
520-
raise Exception('Length of solver.limiters is not equal to 1 or to solver.num_waves')
519+
if self.lim_type==1:
520+
if self.char_decomp == 0 or self.char_decomp == 3:
521+
if len(self._mthlim)==1: self._mthlim = self._mthlim * self.num_eqn
522+
if len(self._mthlim)!=self.num_eqn:
523+
raise Exception('Length of solver.limiters is not equal to 1 or to solver.num_eqn')
524+
elif self.char_decomp == 1 or self.char_decomp == 4:
525+
if len(self._mthlim)==1: self._mthlim = self._mthlim * self.num_waves
526+
if len(self._mthlim)!=self.num_waves:
527+
raise Exception('Length of solver.limiters is not equal to 1 or to solver.num_waves')
528+
else:
529+
if len(self._mthlim)==1: self._mthlim = self._mthlim * self.num_waves
530+
if len(self._mthlim)!=self.num_waves:
531+
raise Exception('Length of solver.limiters is not equal to 1 or to solver.num_waves')
521532

522533

523534
def dq(self,state):
@@ -526,7 +537,9 @@ def dq(self,state):
526537
"""
527538

528539
deltaq = self.dq_hyperbolic(state)
529-
540+
541+
#state.q += deltaq
542+
#deltaq[...] = 0.
530543
if self.dq_src is not None:
531544
deltaq+=self.dq_src(self,state,self.dt)
532545

src/pyclaw/solver.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def before_step(solver,solution):
3232
"""
3333
pass
3434

35+
def after_step(solver,solution):
36+
r"""
37+
Dummy routine called after each step
38+
39+
Replace this routine if you want to do something after each time step.
40+
"""
41+
pass
42+
3543
class Solver(object):
3644
r"""
3745
Pyclaw solver superclass.
@@ -85,6 +93,13 @@ class Solver(object):
8593
8694
def before_step(solver,solution)
8795
96+
.. attribute:: after_step
97+
98+
Function called after each time step is taken.
99+
The required signature for this function is:
100+
101+
def after_step(solver,solution)
102+
88103
.. attribute:: dt_variable
89104
90105
Whether to allow the time step to vary, ``default = True``.
@@ -179,6 +194,7 @@ def __init__(self,riemann_solver=None,claw_package=None):
179194
self._use_old_bc_sig = False
180195
self.accept_step = True
181196
self.before_step = None
197+
self.after_step = None
182198

183199
# select package to build solver objects from, by default this will be
184200
# the package that contains the module implementing the derived class
@@ -610,6 +626,9 @@ def evolve_to_time(self,solution,tend=None):
610626
# Note that the solver may alter dt during the step() routine
611627
self.step(solution,take_one_step,tstart,tend)
612628

629+
if self.after_step is not None:
630+
self.after_step(self,solution.states[0])
631+
613632
# Check to make sure that the Courant number was not too large
614633
cfl = self.cfl.get_cached_max()
615634
self.accept_step = self.accept_reject_step(state)
@@ -642,7 +661,7 @@ def evolve_to_time(self,solution,tend=None):
642661
self.status['cflmax'] = \
643662
max(cfl, self.status['cflmax'])
644663
raise Exception('CFL too large, giving up!')
645-
664+
646665
# See if we are finished yet
647666
if solution.t >= tend or take_one_step:
648667
break

src/pyclaw/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def is_valid(self):
189189
valid = False
190190
if self.aux is not None:
191191
if not self.aux.flags['F_CONTIGUOUS']:
192-
logger.debug('q array is not Fortran contiguous.')
192+
logger.debug('aux array is not Fortran contiguous.')
193193
valid = False
194194
return valid
195195

0 commit comments

Comments
 (0)