Skip to content

Commit 4fa9e7a

Browse files
waltsimsclaude
andauthored
Fix cpp source flags in new API (#698)
* Add CLAUDE.md for Claude Code onboarding Provides build/test commands, architecture overview, and project-specific naming conventions so future Claude Code sessions can be productive immediately. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix CppSimulation source flags to write signal length, not boolean The C++ binary expects p_source_flag / u{x,y,z}_source_flag to contain the number of time steps in the source signal (matching legacy kWaveSimulation.source_p behavior), not just 0/1. Writing a boolean caused the binary to reject valid HDF5 input files with time-varying sources. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add comment clarifying misleading *_source_flag HDF5 field names These fields carry the source signal length, not a boolean — the naming is inherited from the C++ binary's HDF5 API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Use .shape[-1] instead of len([0]) for source flag values Safer for both 1-D and 2-D source arrays and communicates intent more clearly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Walter Simson <waltsims@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2ea27db commit 4fa9e7a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

kwave/solvers/cpp_simulation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,14 @@ def _write_hdf5(self, filepath):
195195
"pml_x_size": pml_x_size,
196196
"pml_y_size": pml_y_size,
197197
"pml_z_size": pml_z_size,
198-
"p_source_flag": int(has_p),
198+
# NOTE: Despite the name "*_source_flag", the C++ binary expects
199+
# the number of time points in the source signal (not a boolean).
200+
# 0 = no source, >0 = number of time steps in the source signal.
201+
"p_source_flag": np.asarray(source.p).shape[-1] if has_p else 0,
199202
"p0_source_flag": int(has_p0),
200-
"ux_source_flag": int(has_ux),
201-
"uy_source_flag": int(has_uy),
202-
"uz_source_flag": int(has_uz),
203+
"ux_source_flag": np.asarray(source.ux).shape[-1] if has_ux else 0,
204+
"uy_source_flag": np.asarray(source.uy).shape[-1] if has_uy else 0,
205+
"uz_source_flag": np.asarray(source.uz).shape[-1] if has_uz else 0,
203206
"sxx_source_flag": 0,
204207
"syy_source_flag": 0,
205208
"szz_source_flag": 0,

0 commit comments

Comments
 (0)