question about gauges in 1d

25 views
Skip to first unread message

jerry fox

unread,
Oct 4, 2024, 6:43:52 AM10/4/24
to claw-users
Hi all,
I'm running clawpack 5.11, and successfully ran my 1d simulation. However I ran into problems when I tried to add gauges to my simulation.

If I set up the domain with:

from clawpack import pyclaw
domain = pyclaw.Domain([0], [100], [10])

print(f'lower: {domain.grid.lower}, upper: {domain.grid.upper}, '
          f'num_cells: {domain.grid.num_cells}, delta: {domain.grid.delta}')
print(f'pcenters: {domain.grid.p_centers}')

print(f'centers: {domain.grid.centers}')

I get the expected output:
lower: [0.0], upper: [100.0], num_cells: [10], delta: [10.0]
pcenters: (array([ 5., 15., 25., 35., 45., 55., 65., 75., 85., 95.]),)
centers: [array([ 5., 15., 25., 35., 45., 55., 65., 75., 85., 95.])]

Now, I had setup the solution and obtain the state
# setup solution
solution = pyclaw.Solution(solver.num_eqn, domain)
state = solution.state

Finally, the gauges:
I had obtained the grid via
grid = state.grid

and defined the gauges at positions and pointed solver how to compute gauge values

gauges = [[6], [9], [10],  [16], [95],]
grid.add_gauges(gauges)
solver.compute_gauge_values = gauge_calc_fun

Now, if I print gauges with:
print(f'gauges: {grid.gauges}')

I get this:
gauges: [[1], [1], [1], [2], [10]]

When I try to run claw simulation, I get the expected Exception
IndexError: index 10 is out of bounds for axis 1 with size 10

Now, if my reasoning is correct, the last cell spans from 90 to 100, with its center at 95. The index of the last cell should be 9, not 10. 
Additionally,  first and second  index should be 0, not 1, since the first cell spans from 0-10, with the cell center at 5, while the gauge coordinates are 6 and 9.

Is it possible that there is a bug in Grid::add_gauges function?

Am I missing something here?

best regards,
jerry


David Ketcheson

unread,
Oct 4, 2024, 6:55:41 AM10/4/24
to claw-users
Yep, there is indeed a bug that can result in the index being off by 1 (whenever the location is at the cell center or to the right of it).

You can use that directly (you'll need to reinstall from source) or wait for the next release.  A simple workaround for now is to make sure your gauge location is to the left of the cell center.

Thanks for catching and communicating this!

David

jerry fox

unread,
Oct 4, 2024, 7:36:52 AM10/4/24
to claw-users
Hi, 
Thanks for a quick reply. I'll just change the code while I'm waiting for a next release.

best regards,
jerry
Reply all
Reply to author
Forward
0 new messages