clawpack / pyclaw

PyClaw is a Python-based interface to the algorithms of Clawpack and SharpClaw. It also contains the PetClaw package, which adds parallelism through PETSc.
http://www.clawpack.com/pyclaw
BSD 3-Clause "New" or "Revised" License
164 stars 99 forks source link

Using step_source with sharpclaw solver fails #692

Closed gridley closed 2 years ago

gridley commented 2 years ago

Hi all,

I get this error when attempting to use step_source in with a sharpclaw solver. Is this functionality supported with sharpclaw?

gpad% python advection_1d.py
Traceback (most recent call last):
  File "/home/gavin/direct_wmp_upscatter/advection_1d.py", line 111, in <module>
    output = run_app_from_main(setup,setplot)
  File "/home/gavin/Code/clawpack/pyclaw/src/pyclaw/util.py", line 120, in run_app_from_main
    claw=application(**app_kwargs)
  File "/home/gavin/direct_wmp_upscatter/advection_1d.py", line 55, in setup
    solver.step_source = force
  File "/home/gavin/Code/clawpack/pyclaw/src/pyclaw/solver.py", line 146, in __setattr__
    raise TypeError("%s has no attribute %s" % (self.__class__,key))
TypeError: <class 'clawpack.pyclaw.sharpclaw.solver.SharpClawSolver1D'> has no attribute step_source
Exception ignored in: <function SharpClawSolver.__del__ at 0x7ff0d5b4f130>
Traceback (most recent call last):
  File "/home/gavin/Code/clawpack/pyclaw/src/pyclaw/sharpclaw/solver.py", line 276, in __del__
    self.fmod.clawparams.dealloc_clawparams()
AttributeError: 'NoneType' object has no attribute 'clawparams'

Should be able to reproduce by simpling setting the step_source attribute on any SharpClaw solver instance. Here's my chunk of code:

    from clawpack import pyclaw
    riemann_solver = riemann.advection_1D

    # solver = pyclaw.ClawSolver1D(riemann_solver)
    solver = pyclaw.SharpClawSolver1D(riemann_solver)
    # solver.weno_order = 5
    # solver.time_integrator = 'SSP104'
    # if time_integrator == 'SSPLMMk3':
    #     solver.lmm_steps = 5
    #     solver.check_lmm_cond = True

    solver.step_source = force
    solver.source_split = 1
ketch commented 2 years ago

@gridley You can't use step_source with SharpClaw. SharpClaw is a method-of-lines discretization and step_source is for operator splitting. You should use dq_src instead, and the function you provide should return the rate of change of q due to the source term. There is an example showing this usage in clawpack/pyclaw/examples/euler_2d/shock_bubble_interaction.py.