HPCSys-Lab / simwave

Simulates the propagation of the acoustic wave using the finite difference method in 2D and 3D domains.
GNU General Public License v3.0
40 stars 13 forks source link

grid_spacing doesn't accept integers #23

Closed joao-bapdm closed 3 years ago

joao-bapdm commented 3 years ago

Only floats. Otherwise nothing is actually evaluated, as can be seen by running this MWE:

from pywave import *
import numpy as np

# Set reference (numerical) model
c = 2000 * np.ones(shape=(512, 512), dtype=np.float32)
space_model = SpaceModel(
    bbox=(0, 5110, 0, 5110), grid_spacing=(10, 10), velocity_model=c
)
time_model = TimeModel(space_model=space_model, tf=1)
source = Source(space_model, coordinates=[(2560, 2560)])
receiver = Receiver(space_model, coordinates=[(3500, 3500)])
ricker = RickerWavelet(10.0, time_model)
solver = Solver(space_model,
                time_model=time_model,
                sources=source,
                receivers=receiver,
                wavelet=ricker,
                saving_jump=1)
# run the forward
u, rec = solver.forward()
krober10nd commented 3 years ago

bbox is non-mutable because it's a tuple.

but the problem is both bbox and grid_spacing are integers so, it will create an integer when division is performed.

joao-bapdm commented 3 years ago

while we're at it, bbox=(0, 5110, 0, 5110) and grid_spacing=(10, 10) result in a space_model with shape=(511, 511). But if I understand correctly, shape describes the number of grid points, so it should be (512, 512). If bbox was (0, 10, 0, 10) you would still have shape=(2,2).

jaimesouza commented 3 years ago

I have fixed the physical attributes (bounding_box, grid_spacing, damping length, source coordinates) type issue. Now, even if the user pass an integer value, it is converted to float.

jaimesouza commented 3 years ago

while we're at it, bbox=(0, 5110, 0, 5110) and grid_spacing=(10, 10) result in a space_model with shape=(511, 511). But if I understand correctly, shape describes the number of grid points, so it should be (512, 512). If bbox was (0, 10, 0, 10) you would still have shape=(2,2).

Good point.

instead of:

nx = int((xmax - xmin) / x_spacing)

should be:

nx = int((xmax - xmin + x_spacing) / x_spacing)

or just:

nx = int((xmax - xmin) / x_spacing) + 1

jaimesouza commented 3 years ago

while we're at it, bbox=(0, 5110, 0, 5110) and grid_spacing=(10, 10) result in a space_model with shape=(511, 511). But if I understand correctly, shape describes the number of grid points, so it should be (512, 512). If bbox was (0, 10, 0, 10) you would still have shape=(2,2).

Good point.

instead of:

nx = int((xmax - xmin) / x_spacing)

should be:

nx = int((xmax - xmin + x_spacing) / x_spacing)

or just:

nx = int((xmax - xmin) / x_spacing) + 1

Done.