From b2fda78815282daae7cdff43cf273314b17c48bb Mon Sep 17 00:00:00 2001 From: Mathias Louboutin Date: Tue, 19 Mar 2024 08:36:03 -0400 Subject: [PATCH] fix q padding with non zero t0 --- src/TimeModeling/Modeling/python_interface.jl | 5 ++++- src/TimeModeling/Utils/time_utilities.jl | 3 +++ src/pysource/sensitivity.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TimeModeling/Modeling/python_interface.jl b/src/TimeModeling/Modeling/python_interface.jl index 7e49d9d3a..175212fd6 100644 --- a/src/TimeModeling/Modeling/python_interface.jl +++ b/src/TimeModeling/Modeling/python_interface.jl @@ -23,7 +23,7 @@ function wrapcall_data(func, args...;kw...) # Unlike standard array we want to keep this ordering in julia (time first) so we need to # make a wrapper around the pointer, to flip the dimension the re-permute the dimensions. shot = tup ? out[1] : out - shot = PermutedDimsArray(unsafe_wrap(Array, shot.data, reverse(size(shot))), length(size(shot)):-1:1) + shot = permutedims(unsafe_wrap(Array, shot.data, reverse(size(shot))), length(size(shot)):-1:1) # Check what to return out = tup ? (shot, out[2]) : shot return out @@ -56,6 +56,7 @@ function devito_interface(modelPy::PyObject, srcGeometry::Geometry, srcData::Arr # Interpolate input data to computational grid dtComp = convert(Float32, modelPy."critical_dt") qIn = time_resample(srcData, srcGeometry, dtComp) + qIn = _maybe_pad_t0(qIn, srcGeometry, recGeometry) # Set up coordinates with devito dimensions src_coords = setup_grid(srcGeometry, modelPy.shape) @@ -109,6 +110,7 @@ function devito_interface(modelPy::PyObject, srcGeometry::Geometry, srcData::Arr # Interpolate input data to computational grid dtComp = convert(Float32, modelPy."critical_dt") qIn = time_resample(srcData, srcGeometry, dtComp) + qIn = _maybe_pad_t0(qIn, srcGeometry, recGeometry) # Set up coordinates with devito dimensions #origin = get_origin(modelPy) @@ -167,6 +169,7 @@ function devito_interface(modelPy::PyObject, recGeometry::Geometry, recData::Arr dtComp = convert(Float32, modelPy."critical_dt") dIn = time_resample(recData, recGeometry, dtComp) qIn = time_resample(srcData, recGeometry, dtComp) + qIn, dIn = _maybe_pad_t0(qIn, recGeometry, dIn, recGeometry) # Set up coordinates with devito dimensions rec_coords = setup_grid(recGeometry, modelPy.shape) diff --git a/src/TimeModeling/Utils/time_utilities.jl b/src/TimeModeling/Utils/time_utilities.jl index 2bc79e6b2..3599fdb11 100644 --- a/src/TimeModeling/Utils/time_utilities.jl +++ b/src/TimeModeling/Utils/time_utilities.jl @@ -139,3 +139,6 @@ end _maybe_pad_t0(qIn::judiVector{T, AT}, dObserved::judiVector{T, AT}) where{T<:Number, AT} = _maybe_pad_t0(get_data(qIn), get_data(dObserved)) + +_maybe_pad_t0(qIn::Matrix{T}, qGeom::Geometry, dataGeom::Geometry) where T<:Number = + _maybe_pad_t0(qIn, qGeom, zeros(T, dataGeom.nt[1], 1), dataGeom)[1] \ No newline at end of file diff --git a/src/pysource/sensitivity.py b/src/pysource/sensitivity.py index 009f3bda1..9a5a97763 100644 --- a/src/pysource/sensitivity.py +++ b/src/pysource/sensitivity.py @@ -223,7 +223,7 @@ def inner_grad(u, v): v: TimeFunction Second field """ - return (grad(u, shift=.5).transpose(inner=False) * grad(v, shift=.5))[0] + return grad(u, shift=.5).dot(grad(v, shift=.5)) fwi_src = lambda *ar, **kw: isic_src(*ar, icsign=-1, **kw)