agencyenterprise / neurotechdevkit

Neurotech Development Kit (NDK)
https://agencyenterprise.github.io/neurotechdevkit/
Apache License 2.0
117 stars 10 forks source link

Scenario 2 errors out with a different center-frequency/grid-size due to mismatch in material mask / grid size #128

Closed charlesbmi closed 1 year ago

charlesbmi commented 1 year ago

Describe the bug

Changing the center_frequency to something outside of 5e5 changes the grid size, but the material mask for Scenario 2 is loaded from the data file and not resized to the grid size, so the code errors out.

One option would be to re-interpolate the material masks to the new grid.

Steps to reproduce

Edit plot_scenarios.py to use a different center_frequency (e.g. 1e6), and then run it.

Include a description of your setup including:

Expected results

Steady-state simulation completes successfully.

Actual results

Edit plot_scenarios.py to use a different center_frequency (e.g. 1e6), and then run:

python docs/examples/plot_scenarios.py

Simulating scenario: scenario-2-2d-v0
creating a grid with shape: (901, 681) for extent: [0.225 0.17 ] m
Traceback (most recent call last):
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/pdb.py", line 1723, in main
    pdb._runscript(mainpyfile)
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/pdb.py", line 1583, in _runscript
    self.run(statement)
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/bdb.py", line 598, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/home/ubuntu/neurotechdevkit/docs/examples/plot_scenarios.py", line 37, in <module>
    plot_scenario("scenario-2-2d-v0")
  File "/home/ubuntu/neurotechdevkit/docs/examples/plot_scenarios.py", line 16, in plot_scenario
    result = scenario.simulate_steady_state(
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/site-packages/neurotechdevkit/scenarios/_base.py", line 420, in simulate_steady_state
    self._problem = self._compile_problem(center_frequency)
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/site-packages/neurotechdevkit/scenarios/_scenario_2.py", line 137, in _compile_problem
    return self._compile_scenario_2_problem(extent, center_frequency)
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/site-packages/neurotechdevkit/scenarios/_scenario_2.py", line 67, in _compile_scenario_2_problem
    problem = add_material_fields_to_problem(
  File "/home/ubuntu/micromamba/envs/neurotechdevkit/lib/python3.10/site-packages/neurotechdevkit/scenarios/_utils.py", line 94, in add_material_fields_to_problem
    vp.data[material_mask] = material.vp
IndexError: boolean index did not match indexed array along dimension 0; dimension is 901 but corresponding boolean dimension is 451